diff --git a/dist/client.d.ts b/dist/client.d.ts index 677a547..f03b7d2 100644 --- a/dist/client.d.ts +++ b/dist/client.d.ts @@ -1,4 +1,4 @@ -import type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload } from "./types.js"; +import type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ConnectState, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload } from "./types.js"; export declare const createCallback: (config: CallbackConfig) => { send: (url: string, payload: SendPayloads, redirectType?: "newTab" | "replace" | null, sendType?: string, sender?: string) => void; parse: (data: string, options?: { @@ -19,4 +19,4 @@ export declare const useCallback: (config: CallbackConfig) => { watcher: (options?: WatcherOptions) => QueryPayloads | undefined; generateUrl: (url: string, payload: SendPayloads, sendType?: string, sender?: string) => string; }; -export type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload, }; +export type { CallbackConfig, QueryPayloads, SendPayloads, WatcherOptions, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ConnectState, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload, }; diff --git a/dist/server.d.ts b/dist/server.d.ts index 35e9a93..3266842 100644 --- a/dist/server.d.ts +++ b/dist/server.d.ts @@ -1,4 +1,4 @@ -import type { CallbackConfig, QueryPayloads, SendPayloads, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload } from "./types.js"; +import type { CallbackConfig, QueryPayloads, SendPayloads, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ConnectState, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload } from "./types.js"; /** * Server-safe factory that exposes only parse and generateUrl. * @@ -11,4 +11,4 @@ export declare const createServerCallback: (config: CallbackConfig) => { }) => QueryPayloads; generateUrl: (url: string, payload: SendPayloads, sendType?: string, sender?: string) => string; }; -export type { CallbackConfig, QueryPayloads, SendPayloads, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload, }; +export type { CallbackConfig, QueryPayloads, SendPayloads, SignIn, SignOut, OemSignOut, Troubleshoot, Recover, Replace, TrialExtend, TrialStart, Purchase, Redeem, Renew, Upgrade, UpdateOs, DowngradeOs, Manage, MyKeys, LinkKey, Activate, AccountActionTypes, AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, ConnectState, ServerState, ServerData, UserInfo, ExternalSignIn, ExternalSignOut, ExternalKeyActions, ExternalUpdateOsAction, ServerPayload, ServerTroubleshoot, ExternalActions, UpcActions, ExternalPayload, UpcPayload, }; diff --git a/dist/types.d.ts b/dist/types.d.ts index 8d608b4..41c313a 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -21,6 +21,7 @@ export type AccountKeyActionTypes = Recover | Replace | TrialExtend | TrialStart export type PurchaseActionTypes = Purchase | Redeem | Renew | Upgrade | Activate; export type ServerActionTypes = AccountActionTypes | AccountKeyActionTypes | PurchaseActionTypes; export type ServerState = "BASIC" | "PLUS" | "PRO" | "TRIAL" | "EEXPIRED" | "ENOKEYFILE" | "EGUID" | "EGUID1" | "ETRIAL" | "ENOKEYFILE2" | "ENOKEYFILE1" | "ENOFLASH" | "ENOFLASH1" | "ENOFLASH2" | "ENOFLASH3" | "ENOFLASH4" | "ENOFLASH5" | "ENOFLASH6" | "ENOFLASH7" | "EBLACKLISTED" | "EBLACKLISTED1" | "EBLACKLISTED2" | "ENOCONN" | "STARTER" | "UNLEASHED" | "LIFETIME" | "STALE" | undefined; +export type ConnectState = "PRE_INIT" | "CONNECTING" | "CONNECTED" | "PING_FAILURE" | "ERROR_RETRYING"; export interface ActivationCodeData { __typename?: "ActivationCode"; background?: string | null; @@ -37,6 +38,8 @@ export interface ActivationCodeData { } export interface ServerData { activationCodeData?: ActivationCodeData | null; + connectPluginVersion?: string; + connectState?: ConnectState; description?: string; deviceCount?: number; expireTime?: number; diff --git a/src/__tests__/server.test.ts b/src/__tests__/server.test.ts index c3be895..65102aa 100644 --- a/src/__tests__/server.test.ts +++ b/src/__tests__/server.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest' import { createServerCallback } from '../server' -import type { ExternalSignOut } from '../types' +import type { ServerPayload } from '../types' describe('createServerCallback (server entry)', () => { const config = { @@ -9,7 +9,18 @@ describe('createServerCallback (server entry)', () => { it('should round-trip data via generateUrl and parse without using window', () => { const { parse, generateUrl } = createServerCallback(config) - const testActions: ExternalSignOut[] = [{ type: 'signOut' }] + const testActions: ServerPayload[] = [ + { + type: 'signIn', + server: { + connectPluginVersion: '2024.05.06.1049', + connectState: 'CONNECTED', + guid: 'test-guid', + registered: false, + state: 'ENOCONN', + }, + }, + ] const targetUrl = 'http://test.com/c' const sendType = 'forUpc' const sender = 'http://sender.com' @@ -29,5 +40,32 @@ describe('createServerCallback (server entry)', () => { type: sendType, }) }) -}) + it('should default sender to an empty string when generateUrl omits it', () => { + const { parse, generateUrl } = createServerCallback(config) + const testActions: ServerPayload[] = [ + { + type: 'signIn', + server: { + connectPluginVersion: '2024.05.06.1049', + connectState: 'CONNECTED', + guid: 'test-guid', + registered: false, + state: 'ENOCONN', + }, + }, + ] + + const generatedUrl = generateUrl('http://test.com/c', testActions, 'forUpc') + const url = new URL(generatedUrl) + const encryptedData = url.hash.startsWith('#data=') + ? url.hash.slice('#data='.length) + : url.searchParams.get('data') || '' + + expect(parse(encryptedData)).toEqual({ + actions: testActions, + sender: '', + type: 'forUpc', + }) + }) +}) diff --git a/src/__tests__/useSharedCallback.test.ts b/src/__tests__/useSharedCallback.test.ts index 1c49a8e..1a49e00 100644 --- a/src/__tests__/useSharedCallback.test.ts +++ b/src/__tests__/useSharedCallback.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' import AES from 'crypto-js/aes.js' import Utf8 from 'crypto-js/enc-utf8.js' -import type { ExternalSignOut } from '../types' +import type { ExternalSignOut, ServerPayload } from '../types' let useCallback: any @@ -216,7 +216,18 @@ describe('useCallback', () => { describe('parse function', () => { it('should correctly parse valid encrypted data', () => { const callback = useCallback(mockConfig) - const testActions: ExternalSignOut[] = [{ type: 'signOut' }] + const testActions: ServerPayload[] = [ + { + type: 'signIn', + server: { + connectPluginVersion: '2024.05.06.1049', + connectState: 'CONNECTED', + guid: 'test-guid', + registered: false, + state: 'ENOCONN', + }, + }, + ] const testData = { actions: testActions, sender: 'http://test.com/Tools', @@ -560,7 +571,18 @@ describe('useCallback', () => { describe('generateUrl function', () => { it('should generate a URL with encrypted data', () => { const callback = useCallback(mockConfig) - const testActions: ExternalSignOut[] = [{ type: 'signOut' }] + const testActions: ServerPayload[] = [ + { + type: 'signIn', + server: { + connectPluginVersion: '2024.05.06.1049', + connectState: 'CONNECTED', + guid: 'test-guid', + registered: false, + state: 'ENOCONN', + }, + }, + ] const targetUrl = 'http://test.com/c' const sendType = 'forUpc' const sender = 'http://test.com/Tools' diff --git a/src/client.ts b/src/client.ts index 9ae4ef7..c3553bb 100644 --- a/src/client.ts +++ b/src/client.ts @@ -25,6 +25,7 @@ import type { AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, + ConnectState, ServerState, ServerData, UserInfo, @@ -209,6 +210,7 @@ export type { AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, + ConnectState, ServerState, ServerData, UserInfo, diff --git a/src/server.ts b/src/server.ts index f0d2e5a..b76e95f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -24,6 +24,7 @@ import type { AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, + ConnectState, ServerState, ServerData, UserInfo, @@ -109,6 +110,7 @@ export type { AccountKeyActionTypes, PurchaseActionTypes, ServerActionTypes, + ConnectState, ServerState, ServerData, UserInfo, diff --git a/src/types.ts b/src/types.ts index 5837527..9e64557 100644 --- a/src/types.ts +++ b/src/types.ts @@ -73,6 +73,13 @@ export type ServerState = | "STALE" | undefined; +export type ConnectState = + | "PRE_INIT" + | "CONNECTING" + | "CONNECTED" + | "PING_FAILURE" + | "ERROR_RETRYING"; + export interface ActivationCodeData { __typename?: "ActivationCode"; background?: string | null; @@ -90,6 +97,8 @@ export interface ActivationCodeData { export interface ServerData { activationCodeData?: ActivationCodeData | null; + connectPluginVersion?: string; + connectState?: ConnectState; description?: string; deviceCount?: number; expireTime?: number;