@drip-apex/app-sdk 0.0.0-stage → 0.1.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.
@@ -0,0 +1,200 @@
1
+ /** Writes must atomically replace the value, or reject without changing it. */
2
+ export interface ApexStorage {
3
+ get(key: string): Promise<string | null>;
4
+ set(key: string, value: string): Promise<void>;
5
+ }
6
+ export type ApexChange = {
7
+ type: 'changed';
8
+ keys: string[];
9
+ } | {
10
+ type: 'stopped';
11
+ code: string;
12
+ };
13
+ export type ApexReason = 'fresh' | 'cached' | 'default' | 'stale';
14
+ export interface ApexVariation {
15
+ id: string;
16
+ index: number;
17
+ isControl: boolean;
18
+ kind: string;
19
+ value: unknown;
20
+ reason: ApexReason;
21
+ }
22
+ export interface ApexSubscription {
23
+ cancel(): void;
24
+ }
25
+ export interface ApexFlagOptions {
26
+ exposure?: 'auto' | 'manual';
27
+ }
28
+ export type ApexAppState = 'foreground' | 'background';
29
+ export type ApexPlatform = 'ios' | 'android' | 'web';
30
+ export interface ApexObjectOptions<T> extends ApexFlagOptions {
31
+ validate?: (value: unknown) => value is T;
32
+ }
33
+ export interface ApexOptions {
34
+ publishableKey: string;
35
+ shopId: string;
36
+ environment?: string;
37
+ qaMode?: boolean;
38
+ flushIntervalSeconds?: number;
39
+ batchSize?: number;
40
+ queueCapacity?: number;
41
+ queueRetentionHours?: number;
42
+ refreshJitterSeconds?: readonly [number, number];
43
+ initTimeoutMs?: number;
44
+ platform?: ApexPlatform;
45
+ appVersion?: string;
46
+ applicationId?: string;
47
+ screen?: () => string | undefined;
48
+ storage?: ApexStorage;
49
+ fetch?: typeof fetch;
50
+ logger?: (line: string) => void;
51
+ baseUrl?: string;
52
+ }
53
+ type Row = Record<string, unknown>;
54
+ /** One server-computed evaluation context. Await ready before using its durable identity. */
55
+ export declare class ApexClient {
56
+ readonly sdkVersion: string;
57
+ readonly ready: Promise<void>;
58
+ private readonly options;
59
+ private readonly storage;
60
+ private readonly namespace;
61
+ private readonly batchSize;
62
+ private readonly capacity;
63
+ private readonly retention;
64
+ private readonly flushInterval;
65
+ private readonly platform;
66
+ private device;
67
+ private identity;
68
+ private assignmentIdentity;
69
+ private assignments;
70
+ private assignmentsLoaded;
71
+ private cache;
72
+ private fetchedAt;
73
+ private fromCache;
74
+ private events;
75
+ private durableEvents;
76
+ private queueRevision;
77
+ private durableQueueRevision;
78
+ private queueWriter;
79
+ private queueWaiters;
80
+ private queueDropLogs;
81
+ private queueActions;
82
+ private session;
83
+ private backgroundAt;
84
+ private appState;
85
+ private lastBackground;
86
+ private lastForeground;
87
+ private foregroundPending;
88
+ private shellListener;
89
+ private settleFirstAssignment;
90
+ private warnings;
91
+ private failureLogs;
92
+ private exposures;
93
+ private pendingExposures;
94
+ private handlers;
95
+ private stopped;
96
+ private generation;
97
+ private identityRevision;
98
+ private identityPending;
99
+ private networkingSuspended;
100
+ private networkRevision;
101
+ private identityWriteWarned;
102
+ private identifyWaiters;
103
+ private assignFailures;
104
+ private eventFailures;
105
+ private assignNotBefore;
106
+ private eventsNotBefore;
107
+ private flushing;
108
+ private serial;
109
+ private timers;
110
+ private requests;
111
+ private assignmentRequests;
112
+ private readonly visibility;
113
+ private readonly pause;
114
+ private readonly resume;
115
+ /** Drive lifecycle explicitly when the shell cannot expose its events. */
116
+ setAppState(state: ApexAppState): void;
117
+ constructor(options: ApexOptions);
118
+ /** Durable anonymous identity for registering/looking up a QA device. */
119
+ get deviceId(): string;
120
+ get userId(): string;
121
+ private log;
122
+ private logFailure;
123
+ private logDeliveryFailure;
124
+ private initialize;
125
+ private task;
126
+ private queueTask;
127
+ private persistQueue;
128
+ private replaceQueue;
129
+ private read;
130
+ private write;
131
+ private schedule;
132
+ private cancelTimer;
133
+ private jitter;
134
+ private emit;
135
+ onChange(handler: (change: ApexChange) => void): ApexSubscription;
136
+ private stop;
137
+ private cleanup;
138
+ private removeShellListener;
139
+ /** Retire this context before replacing it. Completes outstanding storage operations. */
140
+ shutdown(): Promise<void>;
141
+ identify(userId: string | null, _attributes?: Record<string, string>): Promise<void>;
142
+ refresh(): Promise<void>;
143
+ private send;
144
+ private fatal;
145
+ private requestAssignments;
146
+ private trimCache;
147
+ private keyed;
148
+ private changed;
149
+ private reason;
150
+ flag(key: string, defaultValue: boolean, opts?: ApexFlagOptions): boolean;
151
+ flag(key: string, defaultValue: string, opts?: ApexFlagOptions): string;
152
+ flag(key: string, defaultValue: number, opts?: ApexFlagOptions): number;
153
+ flag(key: string, defaultValue: boolean | string | number, opts?: ApexFlagOptions): boolean | string | number;
154
+ flagObject<T>(key: string, defaultValue: T, opts?: ApexObjectOptions<T>): T;
155
+ variation(key: string): ApexVariation | null;
156
+ private warn;
157
+ logExposure(key: string): void;
158
+ private expose;
159
+ private validProperties;
160
+ track(event: string, properties?: Row): Promise<void>;
161
+ trackPurchase(orderId: string, revenue: number, currency: string, properties?: Row): Promise<void>;
162
+ private event;
163
+ private retained;
164
+ private prune;
165
+ private capacityStart;
166
+ private enqueue;
167
+ flush(): Promise<void>;
168
+ private scheduleFlush;
169
+ private deliveryKey;
170
+ private flushLocked;
171
+ private retryDelay;
172
+ }
173
+ /** Shared facade. Configure once in app initialization. Instance users can construct ApexClient. */
174
+ export declare class Apex {
175
+ static readonly sdkVersion: string;
176
+ private static client;
177
+ private static configuring;
178
+ private static configureSequence;
179
+ private static pendingHandlers;
180
+ private static snapshot;
181
+ static configure(options: ApexOptions): Promise<void>;
182
+ static get deviceId(): string | undefined;
183
+ static get userId(): string | undefined;
184
+ static identify(userId: string | null, attributes?: Record<string, string>): Promise<void>;
185
+ static flag(key: string, defaultValue: boolean, opts?: ApexFlagOptions): boolean;
186
+ static flag(key: string, defaultValue: string, opts?: ApexFlagOptions): string;
187
+ static flag(key: string, defaultValue: number, opts?: ApexFlagOptions): number;
188
+ static flag(key: string, defaultValue: boolean | string | number, opts?: ApexFlagOptions): boolean | string | number;
189
+ static flagObject<T>(key: string, defaultValue: T, opts?: ApexObjectOptions<T>): T;
190
+ static variation(key: string): ApexVariation | null;
191
+ static logExposure(key: string): void;
192
+ static track(event: string, properties?: Row): Promise<void>;
193
+ static trackPurchase(orderId: string, revenue: number, currency: string, properties?: Row): Promise<void>;
194
+ static onChange(handler: (change: ApexChange) => void): ApexSubscription;
195
+ static refresh(): Promise<void>;
196
+ static flush(): Promise<void>;
197
+ static setAppState(state: ApexAppState): void;
198
+ static shutdown(): Promise<void>;
199
+ }
200
+ export {};
@@ -0,0 +1,200 @@
1
+ /** Writes must atomically replace the value, or reject without changing it. */
2
+ export interface ApexStorage {
3
+ get(key: string): Promise<string | null>;
4
+ set(key: string, value: string): Promise<void>;
5
+ }
6
+ export type ApexChange = {
7
+ type: 'changed';
8
+ keys: string[];
9
+ } | {
10
+ type: 'stopped';
11
+ code: string;
12
+ };
13
+ export type ApexReason = 'fresh' | 'cached' | 'default' | 'stale';
14
+ export interface ApexVariation {
15
+ id: string;
16
+ index: number;
17
+ isControl: boolean;
18
+ kind: string;
19
+ value: unknown;
20
+ reason: ApexReason;
21
+ }
22
+ export interface ApexSubscription {
23
+ cancel(): void;
24
+ }
25
+ export interface ApexFlagOptions {
26
+ exposure?: 'auto' | 'manual';
27
+ }
28
+ export type ApexAppState = 'foreground' | 'background';
29
+ export type ApexPlatform = 'ios' | 'android' | 'web';
30
+ export interface ApexObjectOptions<T> extends ApexFlagOptions {
31
+ validate?: (value: unknown) => value is T;
32
+ }
33
+ export interface ApexOptions {
34
+ publishableKey: string;
35
+ shopId: string;
36
+ environment?: string;
37
+ qaMode?: boolean;
38
+ flushIntervalSeconds?: number;
39
+ batchSize?: number;
40
+ queueCapacity?: number;
41
+ queueRetentionHours?: number;
42
+ refreshJitterSeconds?: readonly [number, number];
43
+ initTimeoutMs?: number;
44
+ platform?: ApexPlatform;
45
+ appVersion?: string;
46
+ applicationId?: string;
47
+ screen?: () => string | undefined;
48
+ storage?: ApexStorage;
49
+ fetch?: typeof fetch;
50
+ logger?: (line: string) => void;
51
+ baseUrl?: string;
52
+ }
53
+ type Row = Record<string, unknown>;
54
+ /** One server-computed evaluation context. Await ready before using its durable identity. */
55
+ export declare class ApexClient {
56
+ readonly sdkVersion: string;
57
+ readonly ready: Promise<void>;
58
+ private readonly options;
59
+ private readonly storage;
60
+ private readonly namespace;
61
+ private readonly batchSize;
62
+ private readonly capacity;
63
+ private readonly retention;
64
+ private readonly flushInterval;
65
+ private readonly platform;
66
+ private device;
67
+ private identity;
68
+ private assignmentIdentity;
69
+ private assignments;
70
+ private assignmentsLoaded;
71
+ private cache;
72
+ private fetchedAt;
73
+ private fromCache;
74
+ private events;
75
+ private durableEvents;
76
+ private queueRevision;
77
+ private durableQueueRevision;
78
+ private queueWriter;
79
+ private queueWaiters;
80
+ private queueDropLogs;
81
+ private queueActions;
82
+ private session;
83
+ private backgroundAt;
84
+ private appState;
85
+ private lastBackground;
86
+ private lastForeground;
87
+ private foregroundPending;
88
+ private shellListener;
89
+ private settleFirstAssignment;
90
+ private warnings;
91
+ private failureLogs;
92
+ private exposures;
93
+ private pendingExposures;
94
+ private handlers;
95
+ private stopped;
96
+ private generation;
97
+ private identityRevision;
98
+ private identityPending;
99
+ private networkingSuspended;
100
+ private networkRevision;
101
+ private identityWriteWarned;
102
+ private identifyWaiters;
103
+ private assignFailures;
104
+ private eventFailures;
105
+ private assignNotBefore;
106
+ private eventsNotBefore;
107
+ private flushing;
108
+ private serial;
109
+ private timers;
110
+ private requests;
111
+ private assignmentRequests;
112
+ private readonly visibility;
113
+ private readonly pause;
114
+ private readonly resume;
115
+ /** Drive lifecycle explicitly when the shell cannot expose its events. */
116
+ setAppState(state: ApexAppState): void;
117
+ constructor(options: ApexOptions);
118
+ /** Durable anonymous identity for registering/looking up a QA device. */
119
+ get deviceId(): string;
120
+ get userId(): string;
121
+ private log;
122
+ private logFailure;
123
+ private logDeliveryFailure;
124
+ private initialize;
125
+ private task;
126
+ private queueTask;
127
+ private persistQueue;
128
+ private replaceQueue;
129
+ private read;
130
+ private write;
131
+ private schedule;
132
+ private cancelTimer;
133
+ private jitter;
134
+ private emit;
135
+ onChange(handler: (change: ApexChange) => void): ApexSubscription;
136
+ private stop;
137
+ private cleanup;
138
+ private removeShellListener;
139
+ /** Retire this context before replacing it. Completes outstanding storage operations. */
140
+ shutdown(): Promise<void>;
141
+ identify(userId: string | null, _attributes?: Record<string, string>): Promise<void>;
142
+ refresh(): Promise<void>;
143
+ private send;
144
+ private fatal;
145
+ private requestAssignments;
146
+ private trimCache;
147
+ private keyed;
148
+ private changed;
149
+ private reason;
150
+ flag(key: string, defaultValue: boolean, opts?: ApexFlagOptions): boolean;
151
+ flag(key: string, defaultValue: string, opts?: ApexFlagOptions): string;
152
+ flag(key: string, defaultValue: number, opts?: ApexFlagOptions): number;
153
+ flag(key: string, defaultValue: boolean | string | number, opts?: ApexFlagOptions): boolean | string | number;
154
+ flagObject<T>(key: string, defaultValue: T, opts?: ApexObjectOptions<T>): T;
155
+ variation(key: string): ApexVariation | null;
156
+ private warn;
157
+ logExposure(key: string): void;
158
+ private expose;
159
+ private validProperties;
160
+ track(event: string, properties?: Row): Promise<void>;
161
+ trackPurchase(orderId: string, revenue: number, currency: string, properties?: Row): Promise<void>;
162
+ private event;
163
+ private retained;
164
+ private prune;
165
+ private capacityStart;
166
+ private enqueue;
167
+ flush(): Promise<void>;
168
+ private scheduleFlush;
169
+ private deliveryKey;
170
+ private flushLocked;
171
+ private retryDelay;
172
+ }
173
+ /** Shared facade. Configure once in app initialization. Instance users can construct ApexClient. */
174
+ export declare class Apex {
175
+ static readonly sdkVersion: string;
176
+ private static client;
177
+ private static configuring;
178
+ private static configureSequence;
179
+ private static pendingHandlers;
180
+ private static snapshot;
181
+ static configure(options: ApexOptions): Promise<void>;
182
+ static get deviceId(): string | undefined;
183
+ static get userId(): string | undefined;
184
+ static identify(userId: string | null, attributes?: Record<string, string>): Promise<void>;
185
+ static flag(key: string, defaultValue: boolean, opts?: ApexFlagOptions): boolean;
186
+ static flag(key: string, defaultValue: string, opts?: ApexFlagOptions): string;
187
+ static flag(key: string, defaultValue: number, opts?: ApexFlagOptions): number;
188
+ static flag(key: string, defaultValue: boolean | string | number, opts?: ApexFlagOptions): boolean | string | number;
189
+ static flagObject<T>(key: string, defaultValue: T, opts?: ApexObjectOptions<T>): T;
190
+ static variation(key: string): ApexVariation | null;
191
+ static logExposure(key: string): void;
192
+ static track(event: string, properties?: Row): Promise<void>;
193
+ static trackPurchase(orderId: string, revenue: number, currency: string, properties?: Row): Promise<void>;
194
+ static onChange(handler: (change: ApexChange) => void): ApexSubscription;
195
+ static refresh(): Promise<void>;
196
+ static flush(): Promise<void>;
197
+ static setAppState(state: ApexAppState): void;
198
+ static shutdown(): Promise<void>;
199
+ }
200
+ export {};