Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/client.d.ts
Original file line number Diff line number Diff line change
@@ -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?: {
Expand All @@ -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, };
4 changes: 2 additions & 2 deletions dist/server.d.ts
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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, };
3 changes: 3 additions & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,8 @@ export interface ActivationCodeData {
}
export interface ServerData {
activationCodeData?: ActivationCodeData | null;
connectPluginVersion?: string;
connectState?: ConnectState;
description?: string;
deviceCount?: number;
expireTime?: number;
Expand Down
44 changes: 41 additions & 3 deletions src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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'
Expand All @@ -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',
})
})
})
28 changes: 25 additions & 3 deletions src/__tests__/useSharedCallback.test.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
AccountKeyActionTypes,
PurchaseActionTypes,
ServerActionTypes,
ConnectState,
ServerState,
ServerData,
UserInfo,
Expand Down Expand Up @@ -209,6 +210,7 @@ export type {
AccountKeyActionTypes,
PurchaseActionTypes,
ServerActionTypes,
ConnectState,
ServerState,
ServerData,
UserInfo,
Expand Down
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
AccountKeyActionTypes,
PurchaseActionTypes,
ServerActionTypes,
ConnectState,
ServerState,
ServerData,
UserInfo,
Expand Down Expand Up @@ -109,6 +110,7 @@ export type {
AccountKeyActionTypes,
PurchaseActionTypes,
ServerActionTypes,
ConnectState,
ServerState,
ServerData,
UserInfo,
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -90,6 +97,8 @@ export interface ActivationCodeData {

export interface ServerData {
activationCodeData?: ActivationCodeData | null;
connectPluginVersion?: string;
connectState?: ConnectState;
description?: string;
deviceCount?: number;
expireTime?: number;
Expand Down