@gamepropel/sdk-crazygames 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -2
- package/SERVER_HANDOFF.md +29 -0
- package/VALIDATION.md +39 -0
- package/dist/commonjs/index.js +5 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +1 -0
- package/dist/index.js +2224 -0
- package/dist/index.js.map +1 -0
- package/dist/types/crazygames/src/ads.d.ts +26 -0
- package/dist/types/crazygames/src/host.d.ts +37 -0
- package/dist/types/crazygames/src/index.d.ts +68 -0
- package/dist/types/crazygames/src/storage.d.ts +10 -0
- package/dist/types/crazygames/src/transport.d.ts +8 -0
- package/dist/types/rest-api/src/browser-storage.d.ts +42 -0
- package/dist/types/rest-api/src/core-client.d.ts +250 -0
- package/dist/types/rest-api/src/dda.d.ts +22 -0
- package/dist/types/rest-api/src/event-queue-store.d.ts +20 -0
- package/dist/types/rest-api/src/http-url.d.ts +8 -0
- package/dist/types/rest-api/src/sha256.d.ts +1 -0
- package/dist/types/rest-api/src/types.d.ts +244 -0
- package/dist/types/rest-api/src/utf8.d.ts +2 -0
- package/package.json +34 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { GameAlgoRestClient } from "../../rest-api/src/core-client.ts";
|
|
2
|
+
import type { ConfigResponse, FetchConfigOptions, GameAlgoRestClientOptions, JsonValue } from "../../rest-api/src/types.ts";
|
|
3
|
+
import { type GamePropelCrazyGamesAdSpace } from "./ads.ts";
|
|
4
|
+
import { type CrazyGamesHost, type CrazyGamesAdType } from "./host.ts";
|
|
5
|
+
import { type GamePropelCrazyGamesStorageOptions } from "./storage.ts";
|
|
6
|
+
export declare const GAMEPROPEL_CRAZYGAMES_SDK_VERSION = "1.0.0";
|
|
7
|
+
export declare const GAMEPROPEL_CRAZYGAMES_CAPABILITIES: Readonly<{
|
|
8
|
+
config: true;
|
|
9
|
+
parameterExperiments: true;
|
|
10
|
+
remoteScripts: false;
|
|
11
|
+
multiplayer: false;
|
|
12
|
+
rewardedAds: true;
|
|
13
|
+
midgameAds: true;
|
|
14
|
+
impressionRevenue: false;
|
|
15
|
+
}>;
|
|
16
|
+
export type GamePropelCrazyGamesClientOptions = Omit<GameAlgoRestClientOptions, "platform" | "sdkVersion" | "fetchImpl" | "scriptRuntime" | "scriptRuntimeBinaryPath" | "eventPersistOnEnqueue"> & {
|
|
17
|
+
crazyGames?: CrazyGamesHost;
|
|
18
|
+
fetchImpl?: typeof fetch;
|
|
19
|
+
browserStorage?: GamePropelCrazyGamesStorageOptions;
|
|
20
|
+
hostInitTimeoutMs?: number;
|
|
21
|
+
requestTimeoutMs?: number;
|
|
22
|
+
adTimeoutMs?: number;
|
|
23
|
+
autoLifecycle?: boolean;
|
|
24
|
+
autoSessionLifecycle?: boolean;
|
|
25
|
+
};
|
|
26
|
+
type RefreshOptions = FetchConfigOptions & {
|
|
27
|
+
preloadConfigFiles?: boolean | string[];
|
|
28
|
+
};
|
|
29
|
+
/** Independent HTML5 v3 adapter. Initialization awaits the official portal SDK. */
|
|
30
|
+
export declare class GamePropelCrazyGamesClient extends GameAlgoRestClient {
|
|
31
|
+
private readonly host;
|
|
32
|
+
private readonly transport;
|
|
33
|
+
private readonly ads;
|
|
34
|
+
private readonly win;
|
|
35
|
+
private readonly doc;
|
|
36
|
+
private readonly releases;
|
|
37
|
+
private readonly autoSessionLifecycle;
|
|
38
|
+
private readonly preload;
|
|
39
|
+
private readonly deviceOverrides;
|
|
40
|
+
private closed;
|
|
41
|
+
private endedSessionId?;
|
|
42
|
+
private readonly onVisibility;
|
|
43
|
+
private readonly onPageHide;
|
|
44
|
+
private readonly onPageShow;
|
|
45
|
+
private readonly onOnline;
|
|
46
|
+
static init(options: GamePropelCrazyGamesClientOptions): Promise<GamePropelCrazyGamesClient>;
|
|
47
|
+
private constructor();
|
|
48
|
+
createAdSpace(options: {
|
|
49
|
+
adType: CrazyGamesAdType;
|
|
50
|
+
}): GamePropelCrazyGamesAdSpace;
|
|
51
|
+
getForegroundTimeMs(): number;
|
|
52
|
+
flush(): Promise<void>;
|
|
53
|
+
fetchConfig(options?: FetchConfigOptions): Promise<ConfigResponse>;
|
|
54
|
+
refresh(options?: RefreshOptions): Promise<void>;
|
|
55
|
+
protected defaultDeviceContext(): Record<string, JsonValue>;
|
|
56
|
+
protected onConfigReady(): void;
|
|
57
|
+
close(): void;
|
|
58
|
+
private listen;
|
|
59
|
+
private endSession;
|
|
60
|
+
private resume;
|
|
61
|
+
private flushInBackground;
|
|
62
|
+
}
|
|
63
|
+
export declare function initGamePropelCrazyGames(options: GamePropelCrazyGamesClientOptions): Promise<GamePropelCrazyGamesClient>;
|
|
64
|
+
export { GamePropelCrazyGamesStorage } from "./storage.ts";
|
|
65
|
+
export type { GamePropelCrazyGamesStorageOptions } from "./storage.ts";
|
|
66
|
+
export type { GamePropelCrazyGamesAdSpace, GamePropelCrazyGamesAdCallbacks } from "./ads.ts";
|
|
67
|
+
export type { CrazyGamesHost, CrazyGamesAdType, CrazyGamesAdError } from "./host.ts";
|
|
68
|
+
export type { ConfigResponse, EventPayload, EventBatchResponse, JsonValue, TrackEventOptions, GameAlgoStorage } from "../../rest-api/src/types.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type GameAlgoBrowserStorageOptions } from "../../rest-api/src/browser-storage.ts";
|
|
2
|
+
export type GamePropelCrazyGamesStorageOptions = Pick<GameAlgoBrowserStorageOptions, "indexedDB" | "logger">;
|
|
3
|
+
/** Device-local telemetry, isolated from the portal's game-progress Data Module. */
|
|
4
|
+
export declare class GamePropelCrazyGamesStorage {
|
|
5
|
+
private readonly storage;
|
|
6
|
+
constructor(options?: GamePropelCrazyGamesStorageOptions);
|
|
7
|
+
getItem(key: string): Promise<string | undefined>;
|
|
8
|
+
setItem(key: string, value: string): Promise<void>;
|
|
9
|
+
removeItem(key: string): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GameAlgoFetch } from "../../rest-api/src/types.ts";
|
|
2
|
+
export declare class CrazyGamesTransport {
|
|
3
|
+
private readonly pending;
|
|
4
|
+
private closed;
|
|
5
|
+
readonly fetch: GameAlgoFetch;
|
|
6
|
+
constructor(browserFetch: typeof fetch, timeoutMs?: number);
|
|
7
|
+
close(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { GameAlgoStorage } from "./types.ts";
|
|
2
|
+
export type GameAlgoBrowserStorageOptions = {
|
|
3
|
+
databaseName?: string;
|
|
4
|
+
storeName?: string;
|
|
5
|
+
indexedDB?: IDBFactory | null;
|
|
6
|
+
/** null disables localStorage fallback, e.g. when a portal syncs it as a cloud save. */
|
|
7
|
+
localStorage?: Storage | null;
|
|
8
|
+
/** Optional diagnostics omit keys and stored values. */
|
|
9
|
+
logger?: ((message: string) => void) | false;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Browser storage with IndexedDB as the durable primary and localStorage as a
|
|
13
|
+
* compatibility fallback. Raw Game Keys are never written by the SDK.
|
|
14
|
+
*/
|
|
15
|
+
export declare class GameAlgoBrowserStorage implements GameAlgoStorage {
|
|
16
|
+
private readonly databaseName;
|
|
17
|
+
private readonly storeName;
|
|
18
|
+
private readonly indexedDB?;
|
|
19
|
+
private readonly localStorage?;
|
|
20
|
+
private readonly memory;
|
|
21
|
+
private databasePromise?;
|
|
22
|
+
private readonly logger?;
|
|
23
|
+
private operationSequence;
|
|
24
|
+
constructor(options?: GameAlgoBrowserStorageOptions);
|
|
25
|
+
getItem(key: string): Promise<string | undefined>;
|
|
26
|
+
/** @internal Queue commits cannot treat an in-memory fallback as durable. */
|
|
27
|
+
getItemDurably(key: string): Promise<string | undefined>;
|
|
28
|
+
private readItem;
|
|
29
|
+
setItem(key: string, value: string): Promise<void>;
|
|
30
|
+
/** @internal Retain dirty chunks when both persistent stores are unavailable. */
|
|
31
|
+
setItemDurably(key: string, value: string): Promise<void>;
|
|
32
|
+
private writeItem;
|
|
33
|
+
removeItem(key: string): Promise<void>;
|
|
34
|
+
/** @internal Do not clean up chunks before their directory removal commits. */
|
|
35
|
+
removeItemDurably(key: string): Promise<void>;
|
|
36
|
+
private deleteItem;
|
|
37
|
+
private database;
|
|
38
|
+
private readIndexedDB;
|
|
39
|
+
private writeIndexedDB;
|
|
40
|
+
private deleteIndexedDB;
|
|
41
|
+
private observe;
|
|
42
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { ConfigFileResponse, ConfigResponse, ContextIdentifierResponse, EventBatchResponse, EventQuotaConfig, ExperimentAssignment, FetchConfigOptions, GameAlgoExecutionResult, GameAlgoRestClientOptions, GameAlgoScriptRuntime, GameAlgoSnapshot, GameAlgoStorage, GameAlgoUserIdentity, GameEvent, JsonValue, Platform, TrackEventOptions, UserAttributionInput, UserAttributionResponse } from "./types.ts";
|
|
2
|
+
import type { GameAlgoDDAOptions } from "./types.ts";
|
|
3
|
+
import { GameAlgoDDAController } from "./dda.ts";
|
|
4
|
+
type RefreshOptions = FetchConfigOptions & {
|
|
5
|
+
preloadConfigFiles?: boolean | string[];
|
|
6
|
+
};
|
|
7
|
+
export declare class GameAlgoApiError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
constructor(status: number, message: string, code?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class GameAlgoRestClient {
|
|
13
|
+
private readonly baseUrl;
|
|
14
|
+
private readonly gameKey;
|
|
15
|
+
private readonly sdkVersion;
|
|
16
|
+
private readonly appVersion?;
|
|
17
|
+
private readonly accountUserId?;
|
|
18
|
+
private readonly accountUserCreatedAt?;
|
|
19
|
+
private readonly experimentIntegrationVersion;
|
|
20
|
+
private readonly platform;
|
|
21
|
+
private readonly timezone;
|
|
22
|
+
private readonly isDebug;
|
|
23
|
+
private readonly fetchImpl;
|
|
24
|
+
private readonly now;
|
|
25
|
+
private readonly storage?;
|
|
26
|
+
private readonly scriptRuntime;
|
|
27
|
+
private readonly logger?;
|
|
28
|
+
private readonly snapshotCacheKey;
|
|
29
|
+
private readonly legacySnapshotCacheKey;
|
|
30
|
+
private readonly attributionAckCacheKey;
|
|
31
|
+
private readonly userIdKey;
|
|
32
|
+
private readonly userCreatedAtKey;
|
|
33
|
+
private readonly userCreatedLocalAtKey;
|
|
34
|
+
private cachedConfig;
|
|
35
|
+
private snapshot;
|
|
36
|
+
private currentIdentity;
|
|
37
|
+
private readyPromise;
|
|
38
|
+
private didLogUserId;
|
|
39
|
+
private didMigrateLegacyIdentity;
|
|
40
|
+
private readonly ddaControllers;
|
|
41
|
+
readonly config: GameAlgoConfigReader;
|
|
42
|
+
readonly tracker: GameAlgoEventTracker;
|
|
43
|
+
constructor(options: GameAlgoRestClientOptions);
|
|
44
|
+
waitForReady(timeoutMs?: number): Promise<boolean>;
|
|
45
|
+
executor(key: string): GameAlgoExperimentExecutor;
|
|
46
|
+
dda(key: string, options?: GameAlgoDDAOptions): GameAlgoDDAController;
|
|
47
|
+
userIdentity(explicitUserId?: string): Promise<GameAlgoUserIdentity>;
|
|
48
|
+
configureAdjustServerCallbackParams(setCallbackParam: (key: string, value: string) => void | Promise<void>, explicitUserId?: string): Promise<void>;
|
|
49
|
+
protected defaultDeviceContext(): Record<string, JsonValue>;
|
|
50
|
+
/** Platform hook for a fresh server context, with the identity that created it. */
|
|
51
|
+
protected onConfigReady(_config: ConfigResponse, _identity: {
|
|
52
|
+
userId: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
isDebug: boolean;
|
|
55
|
+
}): void;
|
|
56
|
+
fetchConfig(options?: FetchConfigOptions): Promise<ConfigResponse>;
|
|
57
|
+
fetchConfigFile(name: string): Promise<ConfigFileResponse>;
|
|
58
|
+
private fetchScriptFile;
|
|
59
|
+
uploadEvents(events: GameEvent[]): Promise<EventBatchResponse>;
|
|
60
|
+
private reportSdkDiagnostic;
|
|
61
|
+
setAttribution(input: UserAttributionInput): Promise<UserAttributionResponse>;
|
|
62
|
+
setAdjustAdid(value: string | null, observedAt?: string): Promise<ContextIdentifierResponse>;
|
|
63
|
+
setFirebaseAppInstanceId(value: string | null, observedAt?: string): Promise<ContextIdentifierResponse>;
|
|
64
|
+
setGoogleAdvertisingId(value: string | null, observedAt?: string): Promise<ContextIdentifierResponse>;
|
|
65
|
+
setIdfa(value: string | null, observedAt?: string): Promise<ContextIdentifierResponse>;
|
|
66
|
+
setIdfv(value: string | null, observedAt?: string): Promise<ContextIdentifierResponse>;
|
|
67
|
+
private setContextIdentifier;
|
|
68
|
+
clearConfigCache(): void;
|
|
69
|
+
snapshotValue(): GameAlgoSnapshot;
|
|
70
|
+
private initialize;
|
|
71
|
+
protected refresh(options: RefreshOptions): Promise<void>;
|
|
72
|
+
private loadPersistedSnapshot;
|
|
73
|
+
private persistSnapshot;
|
|
74
|
+
private migrateLegacyIdentity;
|
|
75
|
+
private url;
|
|
76
|
+
private requestJson;
|
|
77
|
+
private request;
|
|
78
|
+
private logUserId;
|
|
79
|
+
private logAssignments;
|
|
80
|
+
private log;
|
|
81
|
+
}
|
|
82
|
+
export declare class GameAlgoEventTracker {
|
|
83
|
+
private readonly uploadEvents;
|
|
84
|
+
private readonly reportDiagnostic?;
|
|
85
|
+
private readonly platform;
|
|
86
|
+
private readonly sdkVersion;
|
|
87
|
+
private readonly appVersion?;
|
|
88
|
+
private readonly maxBatchSize;
|
|
89
|
+
private readonly maxBatchBytes?;
|
|
90
|
+
private readonly queueLimit;
|
|
91
|
+
private readonly persistOnEnqueue;
|
|
92
|
+
private readonly flushIntervalMs;
|
|
93
|
+
private readonly now;
|
|
94
|
+
private readonly storage?;
|
|
95
|
+
private readonly persistenceKey?;
|
|
96
|
+
private readonly milestonePersistenceKey?;
|
|
97
|
+
private readonly milestoneRestorePromise;
|
|
98
|
+
private readonly restorePromise;
|
|
99
|
+
private userId?;
|
|
100
|
+
private sessionId;
|
|
101
|
+
private contextId?;
|
|
102
|
+
private timezone?;
|
|
103
|
+
private userCreatedAt?;
|
|
104
|
+
private accountUserId?;
|
|
105
|
+
private isDebug;
|
|
106
|
+
private currentExperiments;
|
|
107
|
+
private queue;
|
|
108
|
+
private retryBatch;
|
|
109
|
+
private inflightBatch;
|
|
110
|
+
private readonly urgentEventIds;
|
|
111
|
+
private readonly urgentFlushes;
|
|
112
|
+
private readonly pendingIdentityAds;
|
|
113
|
+
private timersStopped;
|
|
114
|
+
private readonly onAdIdentityState?;
|
|
115
|
+
private restored;
|
|
116
|
+
private flushTimer?;
|
|
117
|
+
private activeFlush?;
|
|
118
|
+
private sessionStartMs?;
|
|
119
|
+
private sessionDurationTimer?;
|
|
120
|
+
private sampledForegroundTimeMs;
|
|
121
|
+
private sessionForegroundStartMs;
|
|
122
|
+
private sessionDurationSampleAt;
|
|
123
|
+
private sessionDurationVisible?;
|
|
124
|
+
private sessionDurationWasVisible;
|
|
125
|
+
private sessionHasEnd;
|
|
126
|
+
private consecutiveFailures;
|
|
127
|
+
private hasPersistedQueue;
|
|
128
|
+
private queueRestorePending;
|
|
129
|
+
private incrementalQueue?;
|
|
130
|
+
private queuePersistActive?;
|
|
131
|
+
private queuePersistRevision;
|
|
132
|
+
private readonly customCounts;
|
|
133
|
+
private readonly ordinaryCounts;
|
|
134
|
+
private eventQuota?;
|
|
135
|
+
private readonly diagnosticKeys;
|
|
136
|
+
private diagnosticCount;
|
|
137
|
+
private readonly reachedMilestoneKeys;
|
|
138
|
+
private readonly pendingMilestoneKeys;
|
|
139
|
+
private milestonePersistPromise;
|
|
140
|
+
private queuePersistPromise;
|
|
141
|
+
constructor(options: {
|
|
142
|
+
uploadEvents: (events: GameEvent[]) => Promise<EventBatchResponse>;
|
|
143
|
+
reportDiagnostic?: (diagnostic: Record<string, unknown>) => Promise<void>;
|
|
144
|
+
platform: Platform;
|
|
145
|
+
sdkVersion: string;
|
|
146
|
+
appVersion?: string;
|
|
147
|
+
timezone?: string;
|
|
148
|
+
isDebug: boolean;
|
|
149
|
+
flushIntervalMs: number;
|
|
150
|
+
maxBatchSize: number;
|
|
151
|
+
maxBatchBytes?: number;
|
|
152
|
+
queueLimit: number;
|
|
153
|
+
persistOnEnqueue?: boolean;
|
|
154
|
+
now: () => number;
|
|
155
|
+
storage?: GameAlgoStorage;
|
|
156
|
+
persistenceKey?: string;
|
|
157
|
+
onAdIdentityState?: (state: "buffered" | "released", count: number) => void;
|
|
158
|
+
});
|
|
159
|
+
identify(userId: string, sessionId?: string, userCreatedAt?: string, accountUserId?: string): void;
|
|
160
|
+
newSession(sessionId?: string): void;
|
|
161
|
+
currentSessionId(): string;
|
|
162
|
+
waitForRestore(): Promise<void>;
|
|
163
|
+
setContextId(contextId: string): void;
|
|
164
|
+
bindSessionContext(sessionId: string, contextId: string): void;
|
|
165
|
+
setDebug(isDebug: boolean): void;
|
|
166
|
+
setTimezone(timezone?: string): void;
|
|
167
|
+
setAssignments(assignments: ExperimentAssignment[]): void;
|
|
168
|
+
setEventQuota(quota?: EventQuotaConfig): void;
|
|
169
|
+
markSessionStarted(): void;
|
|
170
|
+
/** Sampled web foreground milliseconds since tracker creation. Pure memory read. */
|
|
171
|
+
getForegroundTimeMs(): number;
|
|
172
|
+
/** @internal Read live visibility on every sample; no resume notification is required. */
|
|
173
|
+
setSessionDurationVisibility(visible: () => boolean): void;
|
|
174
|
+
/** @internal Lifecycle callbacks can observe a boundary, but never gate future samples. */
|
|
175
|
+
observeSessionDurationVisibility(): void;
|
|
176
|
+
private resetSessionDuration;
|
|
177
|
+
private sampleSessionDuration;
|
|
178
|
+
private sessionDuration;
|
|
179
|
+
track(eventType: string, payload?: JsonValue, options?: TrackEventOptions): boolean;
|
|
180
|
+
private prepareMilestone;
|
|
181
|
+
private rememberMilestone;
|
|
182
|
+
private rememberBoundMilestones;
|
|
183
|
+
private consumeCustomEventQuota;
|
|
184
|
+
private mergeCustomCountBucket;
|
|
185
|
+
private consumeOrdinaryEventQuota;
|
|
186
|
+
private mergeOrdinaryCountBucket;
|
|
187
|
+
private reportContextQuotaDiagnostic;
|
|
188
|
+
private reportQuotaDiagnostic;
|
|
189
|
+
trackEvent(type: string, payload?: JsonValue, options?: TrackEventOptions): boolean;
|
|
190
|
+
trackSessionEnd(payload?: JsonValue): boolean;
|
|
191
|
+
/** SDK lifecycle snapshot: retain the live session and bypass gameplay quotas. */
|
|
192
|
+
trackSessionEndSnapshot(payload?: JsonValue): boolean;
|
|
193
|
+
trackLevelStart(payload?: JsonValue): boolean;
|
|
194
|
+
trackLevelEnd(payload?: JsonValue): boolean;
|
|
195
|
+
trackMilestone(milestoneType: string, milestonePoint: string, payload?: JsonValue): boolean;
|
|
196
|
+
/** Track a registered placement; static fields are resolved by the server. */
|
|
197
|
+
trackAdPlacement(adPlacementId: string, revenue: number, payload?: JsonValue): boolean;
|
|
198
|
+
trackAdPlacement(adPlacementId: string, revenue: number, network?: string, payload?: JsonValue): boolean;
|
|
199
|
+
trackPurchase(productId?: string, revenue?: number, currency?: string, payload?: JsonValue): boolean;
|
|
200
|
+
flush(): Promise<EventBatchResponse[]>;
|
|
201
|
+
private drain;
|
|
202
|
+
/** H5 critical events start uploading without waiting for browser storage or
|
|
203
|
+
* an ordinary batch. Each event stays queued until the HTTP request succeeds.
|
|
204
|
+
* Separate lanes keep a pending ad request from blocking session_end. */
|
|
205
|
+
flushUrgent(): Promise<EventBatchResponse[]>;
|
|
206
|
+
private urgentCandidates;
|
|
207
|
+
private drainUrgent;
|
|
208
|
+
close(): void;
|
|
209
|
+
private enqueue;
|
|
210
|
+
private startTimer;
|
|
211
|
+
private restorePersistedQueue;
|
|
212
|
+
private restorePersistedMilestones;
|
|
213
|
+
private persistReachedMilestones;
|
|
214
|
+
private persistPendingQueue;
|
|
215
|
+
private clearPersistedQueue;
|
|
216
|
+
}
|
|
217
|
+
export declare class GameAlgoExperimentExecutor {
|
|
218
|
+
private readonly key;
|
|
219
|
+
private readonly snapshotProvider;
|
|
220
|
+
private readonly scriptRuntime;
|
|
221
|
+
private readonly logger?;
|
|
222
|
+
constructor(key: string, snapshotProvider: () => GameAlgoSnapshot, scriptRuntime: GameAlgoScriptRuntime, logger?: (message: string) => void);
|
|
223
|
+
get isReady(): boolean;
|
|
224
|
+
assignment(): ExperimentAssignment | undefined;
|
|
225
|
+
variant(defaultValue?: string): string;
|
|
226
|
+
config<T extends JsonValue>(defaultValue: T): JsonValue | T;
|
|
227
|
+
value<T extends JsonValue>(path: string, defaultValue: T): JsonValue | T;
|
|
228
|
+
string(path: string, defaultValue?: string): string;
|
|
229
|
+
number(path: string, defaultValue?: number): number;
|
|
230
|
+
bool(path: string, defaultValue?: boolean): boolean;
|
|
231
|
+
execute(state: JsonValue): Promise<GameAlgoExecutionResult | undefined>;
|
|
232
|
+
private log;
|
|
233
|
+
}
|
|
234
|
+
export declare class GameAlgoConfigReader {
|
|
235
|
+
private readonly snapshotProvider;
|
|
236
|
+
constructor(snapshotProvider: () => GameAlgoSnapshot);
|
|
237
|
+
file(name: string): ConfigFileResponse | undefined;
|
|
238
|
+
jsonFile<T extends JsonValue>(name: string, defaultValue: T): JsonValue | T;
|
|
239
|
+
value<T extends JsonValue>(path: string, defaultValue: T, fileName?: string): JsonValue | T;
|
|
240
|
+
string(path: string, defaultValue?: string, fileName?: string): string;
|
|
241
|
+
number(path: string, defaultValue?: number, fileName?: string): number;
|
|
242
|
+
bool(path: string, defaultValue?: boolean, fileName?: string): boolean;
|
|
243
|
+
private defaultJsonSource;
|
|
244
|
+
}
|
|
245
|
+
export declare function createEvent(input: Omit<GameEvent, "eventId" | "timestamp" | "createdLocalAt"> & {
|
|
246
|
+
eventId?: string;
|
|
247
|
+
timestamp?: string;
|
|
248
|
+
createdLocalAt?: string;
|
|
249
|
+
}): GameEvent;
|
|
250
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GameAlgoDDADecision, GameAlgoDDAOptions, GameAlgoDDAScriptState, GameAlgoExecutionResult, GameAlgoStorage, JsonValue } from "./types.ts";
|
|
2
|
+
type DDAExecutor = {
|
|
3
|
+
execute(state: JsonValue): Promise<GameAlgoExecutionResult | undefined>;
|
|
4
|
+
};
|
|
5
|
+
export declare class GameAlgoDDAController {
|
|
6
|
+
private readonly executor;
|
|
7
|
+
private readonly storage?;
|
|
8
|
+
private readonly storageKey;
|
|
9
|
+
private readonly recentWindowSize;
|
|
10
|
+
private readonly logger?;
|
|
11
|
+
private readonly statePromise;
|
|
12
|
+
private writeTail;
|
|
13
|
+
constructor(executor: DDAExecutor, storage: GameAlgoStorage | undefined, storageKey: string, options?: GameAlgoDDAOptions, logger?: (message: string) => void);
|
|
14
|
+
recordBehavior(type: string, amount?: number): Promise<void>;
|
|
15
|
+
completeStep(stepId?: string): Promise<void>;
|
|
16
|
+
reset(scope?: "all" | "current" | "recent"): Promise<void>;
|
|
17
|
+
snapshot(context?: JsonValue): Promise<GameAlgoDDAScriptState>;
|
|
18
|
+
decide(context?: JsonValue): Promise<GameAlgoDDADecision>;
|
|
19
|
+
private loadState;
|
|
20
|
+
private mutate;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GameAlgoStorage, GameEvent } from "./types.ts";
|
|
2
|
+
/** Copy-on-write event chunks; the small directory is committed last. */
|
|
3
|
+
export declare class IncrementalEventQueue {
|
|
4
|
+
private readonly prefix;
|
|
5
|
+
private chunks;
|
|
6
|
+
private locations;
|
|
7
|
+
private contexts;
|
|
8
|
+
private dirty;
|
|
9
|
+
private revision;
|
|
10
|
+
private sequence;
|
|
11
|
+
private reloadAfterFailure;
|
|
12
|
+
private readonly storage;
|
|
13
|
+
private readonly key;
|
|
14
|
+
constructor(storage: GameAlgoStorage, key: string);
|
|
15
|
+
reset(): void;
|
|
16
|
+
load(stored?: string): Promise<GameEvent[]>;
|
|
17
|
+
private upsert;
|
|
18
|
+
save(events: GameEvent[]): Promise<boolean>;
|
|
19
|
+
private saveCurrent;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type HttpBaseUrl = {
|
|
2
|
+
origin: string;
|
|
3
|
+
pathname: string;
|
|
4
|
+
href: string;
|
|
5
|
+
};
|
|
6
|
+
/** API endpoints only need HTTP(S) origins and a preserved deployment prefix. */
|
|
7
|
+
export declare function parseHttpBaseUrl(value: string): HttpBaseUrl;
|
|
8
|
+
export declare function resolveHttpUrl(value: string, base: HttpBaseUrl): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sha256HexSync(input: string): string;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
/** `web` is the historical wire value for TapTap H5, not a generic minigame host. */
|
|
5
|
+
export type Platform = "ios" | "android" | "maker" | "web" | "wechat" | "crazygames";
|
|
6
|
+
export type GameEnvironment = "test" | "live";
|
|
7
|
+
export type ExperimentAssignment = {
|
|
8
|
+
key: string;
|
|
9
|
+
experimentId: string;
|
|
10
|
+
variant: string;
|
|
11
|
+
config: JsonValue;
|
|
12
|
+
script?: ScriptFileRef;
|
|
13
|
+
};
|
|
14
|
+
export type ConfigFileRef = {
|
|
15
|
+
versionId?: string;
|
|
16
|
+
name: string;
|
|
17
|
+
url: string;
|
|
18
|
+
hash: string;
|
|
19
|
+
contentType?: string;
|
|
20
|
+
updatedAt?: string;
|
|
21
|
+
};
|
|
22
|
+
export type ScriptFileRef = ConfigFileRef & {
|
|
23
|
+
versionId: string;
|
|
24
|
+
};
|
|
25
|
+
export type ConfigResponse = {
|
|
26
|
+
contextId: string;
|
|
27
|
+
gameId: string;
|
|
28
|
+
environment: GameEnvironment;
|
|
29
|
+
configVersion: string;
|
|
30
|
+
ttlSeconds: number;
|
|
31
|
+
serverTime: string;
|
|
32
|
+
/** Absent/false disables Maker/H5 TapDB identity linking; never restored as startup permission. */
|
|
33
|
+
tapdbContextLinkEnabled?: boolean;
|
|
34
|
+
eventQuota?: EventQuotaConfig;
|
|
35
|
+
experiments: ExperimentAssignment[];
|
|
36
|
+
configFiles: ConfigFileRef[];
|
|
37
|
+
};
|
|
38
|
+
export type EventQuotaConfig = {
|
|
39
|
+
mode: "off" | "shadow" | "enforce";
|
|
40
|
+
policyVersion: number;
|
|
41
|
+
ordinaryEventLimit: number;
|
|
42
|
+
quotaDate: string;
|
|
43
|
+
resetAt: string;
|
|
44
|
+
exemptEventTypes: string[];
|
|
45
|
+
};
|
|
46
|
+
export type FetchConfigOptions = {
|
|
47
|
+
userId?: string;
|
|
48
|
+
userCreatedAt?: string;
|
|
49
|
+
userCreatedLocalAt?: string;
|
|
50
|
+
accountUserId?: string;
|
|
51
|
+
accountUserCreatedAt?: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
platform?: Platform;
|
|
54
|
+
sdkVersion?: string;
|
|
55
|
+
appVersion?: string;
|
|
56
|
+
experimentIntegrationVersion?: number;
|
|
57
|
+
deviceId?: string;
|
|
58
|
+
timezone?: string;
|
|
59
|
+
device?: Record<string, JsonValue>;
|
|
60
|
+
isDebug?: boolean;
|
|
61
|
+
forceRefresh?: boolean;
|
|
62
|
+
};
|
|
63
|
+
export type ConfigFileResponse = {
|
|
64
|
+
name: string;
|
|
65
|
+
content: string;
|
|
66
|
+
contentType: string;
|
|
67
|
+
etag?: string;
|
|
68
|
+
};
|
|
69
|
+
export type GameEvent = {
|
|
70
|
+
eventId?: string;
|
|
71
|
+
contextId: string;
|
|
72
|
+
userId: string;
|
|
73
|
+
sessionId: string;
|
|
74
|
+
eventType: string;
|
|
75
|
+
isDebug?: boolean;
|
|
76
|
+
timestamp?: string;
|
|
77
|
+
createdLocalAt?: string;
|
|
78
|
+
accountUserId?: string;
|
|
79
|
+
payload?: EventPayload;
|
|
80
|
+
};
|
|
81
|
+
export type EventPayloadValue = string | number | boolean | null;
|
|
82
|
+
export type EventPayload = Record<string, EventPayloadValue>;
|
|
83
|
+
export type EventBatchResponse = {
|
|
84
|
+
ok: boolean;
|
|
85
|
+
accepted: number;
|
|
86
|
+
rejected?: EventBatchRejection[];
|
|
87
|
+
};
|
|
88
|
+
export type EventBatchRejection = {
|
|
89
|
+
index: number;
|
|
90
|
+
eventId?: string;
|
|
91
|
+
code?: string;
|
|
92
|
+
reason?: string;
|
|
93
|
+
quotaDate?: string;
|
|
94
|
+
limit?: number;
|
|
95
|
+
resetAt?: string;
|
|
96
|
+
};
|
|
97
|
+
export type AttributionStatus = "attributed" | "organic" | "unknown" | string;
|
|
98
|
+
export type UserAttributionInput = {
|
|
99
|
+
userId?: string;
|
|
100
|
+
userCreatedAt?: string;
|
|
101
|
+
sessionId?: string;
|
|
102
|
+
contextId?: string;
|
|
103
|
+
platform?: Platform;
|
|
104
|
+
provider: string;
|
|
105
|
+
status?: AttributionStatus;
|
|
106
|
+
attribution: Record<string, JsonValue>;
|
|
107
|
+
attributedAt?: string;
|
|
108
|
+
attributionHash?: string;
|
|
109
|
+
};
|
|
110
|
+
export type UserAttributionResponse = {
|
|
111
|
+
ok: boolean;
|
|
112
|
+
accepted: number;
|
|
113
|
+
attributionHash: string;
|
|
114
|
+
};
|
|
115
|
+
export type ContextIdentifierType = "adjust_adid" | "firebase_app_instance_id" | "gaid" | "idfa" | "idfv" | "oaid" | "caid";
|
|
116
|
+
export type ContextIdentifierResponse = {
|
|
117
|
+
ok: boolean;
|
|
118
|
+
accepted: number;
|
|
119
|
+
identifierHash: string;
|
|
120
|
+
};
|
|
121
|
+
export type GameAlgoRestClientOptions = {
|
|
122
|
+
baseUrl: string;
|
|
123
|
+
gameKey: string;
|
|
124
|
+
userId?: string;
|
|
125
|
+
userCreatedAt?: string;
|
|
126
|
+
userCreatedLocalAt?: string;
|
|
127
|
+
accountUserId?: string;
|
|
128
|
+
accountUserCreatedAt?: string;
|
|
129
|
+
sessionId?: string;
|
|
130
|
+
sdkVersion?: string;
|
|
131
|
+
appVersion?: string;
|
|
132
|
+
experimentIntegrationVersion?: number;
|
|
133
|
+
platform?: Platform;
|
|
134
|
+
deviceId?: string;
|
|
135
|
+
device?: Record<string, JsonValue>;
|
|
136
|
+
preloadConfigFiles?: boolean | string[];
|
|
137
|
+
isDebug?: boolean;
|
|
138
|
+
timezone?: string;
|
|
139
|
+
eventFlushIntervalMs?: number;
|
|
140
|
+
eventMaxBatchSize?: number;
|
|
141
|
+
/** Optional UTF-8 byte budget for one `{ events }` request body. */
|
|
142
|
+
eventMaxBatchBytes?: number;
|
|
143
|
+
eventQueueLimit?: number;
|
|
144
|
+
/** Persist every queued event immediately. Recommended for browser runtimes. */
|
|
145
|
+
eventPersistOnEnqueue?: boolean;
|
|
146
|
+
fetchImpl?: GameAlgoFetch;
|
|
147
|
+
now?: () => number;
|
|
148
|
+
storage?: GameAlgoStorage;
|
|
149
|
+
scriptRuntime?: GameAlgoScriptRuntime;
|
|
150
|
+
/** Node/Server path to the canonical GameAlgo script runtime executable. */
|
|
151
|
+
scriptRuntimeBinaryPath?: string;
|
|
152
|
+
logger?: GameAlgoLogger;
|
|
153
|
+
cacheKey?: string;
|
|
154
|
+
};
|
|
155
|
+
export type GameAlgoSnapshot = {
|
|
156
|
+
config?: ConfigResponse;
|
|
157
|
+
configFiles: Map<string, ConfigFileResponse>;
|
|
158
|
+
updatedAt: number;
|
|
159
|
+
userId?: string;
|
|
160
|
+
};
|
|
161
|
+
export type GameAlgoUserIdentity = {
|
|
162
|
+
userId: string;
|
|
163
|
+
userCreatedAt: string;
|
|
164
|
+
userCreatedLocalAt: string;
|
|
165
|
+
};
|
|
166
|
+
export type TrackEventOptions = {
|
|
167
|
+
userId?: string;
|
|
168
|
+
sessionId?: string;
|
|
169
|
+
contextId?: string;
|
|
170
|
+
isDebug?: boolean;
|
|
171
|
+
timestamp?: string;
|
|
172
|
+
createdLocalAt?: string;
|
|
173
|
+
};
|
|
174
|
+
export type GameAlgoStorage = {
|
|
175
|
+
getItem(key: string): string | undefined | null | Promise<string | undefined | null>;
|
|
176
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
177
|
+
removeItem?(key: string): void | Promise<void>;
|
|
178
|
+
};
|
|
179
|
+
export type GameAlgoLogger = false | ((message: string) => void);
|
|
180
|
+
export type GameAlgoExecutionResult = {
|
|
181
|
+
payload: JsonValue;
|
|
182
|
+
diagnostics: JsonValue;
|
|
183
|
+
assignment: ExperimentAssignment;
|
|
184
|
+
};
|
|
185
|
+
export type GameAlgoScriptInput = {
|
|
186
|
+
state: JsonValue;
|
|
187
|
+
config: JsonValue;
|
|
188
|
+
meta: {
|
|
189
|
+
gameId: string;
|
|
190
|
+
userId: string;
|
|
191
|
+
environment: GameEnvironment;
|
|
192
|
+
strategy: string;
|
|
193
|
+
experimentId: string;
|
|
194
|
+
variant: string;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
export type GameAlgoScriptRuntime = {
|
|
198
|
+
prepare?(script: string): void | Promise<void>;
|
|
199
|
+
execute(script: string, input: GameAlgoScriptInput): JsonValue | Promise<JsonValue>;
|
|
200
|
+
};
|
|
201
|
+
export type GameAlgoDDAAdjustment = "increase" | "keep" | "decrease";
|
|
202
|
+
export type GameAlgoDDAOptions = {
|
|
203
|
+
recentWindowSize?: number;
|
|
204
|
+
storageKey?: string;
|
|
205
|
+
};
|
|
206
|
+
export type GameAlgoDDAStep = {
|
|
207
|
+
stepId?: string;
|
|
208
|
+
behaviors: Record<string, number>;
|
|
209
|
+
};
|
|
210
|
+
export type GameAlgoDDAScriptState = {
|
|
211
|
+
context: JsonValue;
|
|
212
|
+
behavior: {
|
|
213
|
+
current: Record<string, number>;
|
|
214
|
+
recent: Record<string, number>;
|
|
215
|
+
lifetime: Record<string, number>;
|
|
216
|
+
recentSteps: GameAlgoDDAStep[];
|
|
217
|
+
completedSteps: number;
|
|
218
|
+
windowSize: number;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
export type GameAlgoDDADecision = {
|
|
222
|
+
adjustment: GameAlgoDDAAdjustment;
|
|
223
|
+
payload: JsonValue;
|
|
224
|
+
diagnostics: JsonValue;
|
|
225
|
+
assignment?: ExperimentAssignment;
|
|
226
|
+
isFallback: boolean;
|
|
227
|
+
};
|
|
228
|
+
/** Minimal transport contract shared by browsers, Node and sandboxed minigames. */
|
|
229
|
+
export type GameAlgoHttpRequest = {
|
|
230
|
+
method?: string;
|
|
231
|
+
headers?: Record<string, string>;
|
|
232
|
+
body?: string;
|
|
233
|
+
keepalive?: boolean;
|
|
234
|
+
};
|
|
235
|
+
export type GameAlgoHttpResponse = {
|
|
236
|
+
ok: boolean;
|
|
237
|
+
status: number;
|
|
238
|
+
headers: {
|
|
239
|
+
get(name: string): string | null;
|
|
240
|
+
};
|
|
241
|
+
text(): Promise<string>;
|
|
242
|
+
json(): Promise<unknown>;
|
|
243
|
+
};
|
|
244
|
+
export type GameAlgoFetch = (url: string, init?: GameAlgoHttpRequest) => Promise<GameAlgoHttpResponse>;
|