@schematichq/schematic-js 1.2.1 → 1.2.3
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 +36 -2
- package/dist/schematic.browser.js +2 -2
- package/dist/schematic.cjs.js +317 -19
- package/dist/schematic.d.ts +133 -4
- package/dist/schematic.esm.js +317 -19
- package/package.json +10 -9
package/dist/schematic.d.ts
CHANGED
|
@@ -61,6 +61,12 @@ export declare interface CheckFlagResponseData {
|
|
|
61
61
|
* @memberof CheckFlagResponseData
|
|
62
62
|
*/
|
|
63
63
|
featureUsage?: number | null;
|
|
64
|
+
/**
|
|
65
|
+
* If an event-based numeric feature entitlement rule was matched, the event used to track its usage
|
|
66
|
+
* @type {string}
|
|
67
|
+
* @memberof CheckFlagResponseData
|
|
68
|
+
*/
|
|
69
|
+
featureUsageEvent?: string | null;
|
|
64
70
|
/**
|
|
65
71
|
* For event-based feature entitlement rules, the period over which usage is tracked (current_month, current_day, current_week, all_time)
|
|
66
72
|
* @type {string}
|
|
@@ -130,6 +136,8 @@ export declare type CheckFlagReturn = {
|
|
|
130
136
|
featureAllocation?: number;
|
|
131
137
|
/** If a numeric feature entitlement rule was matched, the company's usage */
|
|
132
138
|
featureUsage?: number;
|
|
139
|
+
/** Event representing the feature usage */
|
|
140
|
+
featureUsageEvent?: string;
|
|
133
141
|
/** For event-based feature entitlement rules, the period over which usage is tracked (current_month, current_day, current_week, all_time) */
|
|
134
142
|
featureUsagePeriod?: UsagePeriod;
|
|
135
143
|
/** For event-based feature entitlement rules, when the usage period will reset */
|
|
@@ -208,7 +216,92 @@ declare type Event_2 = {
|
|
|
208
216
|
};
|
|
209
217
|
export { Event_2 as Event }
|
|
210
218
|
|
|
211
|
-
export declare type EventBody = EventBodyIdentify | EventBodyTrack;
|
|
219
|
+
export declare type EventBody = EventBodyIdentify | EventBodyTrack | EventBodyFlagCheck;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Schematic API
|
|
223
|
+
* Schematic API
|
|
224
|
+
*
|
|
225
|
+
* The version of the OpenAPI document: 0.1
|
|
226
|
+
*
|
|
227
|
+
*
|
|
228
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
229
|
+
* https://openapi-generator.tech
|
|
230
|
+
* Do not edit the class manually.
|
|
231
|
+
*/
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
* @export
|
|
235
|
+
* @interface EventBodyFlagCheck
|
|
236
|
+
*/
|
|
237
|
+
export declare interface EventBodyFlagCheck {
|
|
238
|
+
/**
|
|
239
|
+
* Schematic company ID (starting with 'comp_') of the company evaluated, if any
|
|
240
|
+
* @type {string}
|
|
241
|
+
* @memberof EventBodyFlagCheck
|
|
242
|
+
*/
|
|
243
|
+
companyId?: string | null;
|
|
244
|
+
/**
|
|
245
|
+
* Report an error that occurred during the flag check
|
|
246
|
+
* @type {string}
|
|
247
|
+
* @memberof EventBodyFlagCheck
|
|
248
|
+
*/
|
|
249
|
+
error?: string | null;
|
|
250
|
+
/**
|
|
251
|
+
* Schematic flag ID (starting with 'flag_') for the flag matching the key, if any
|
|
252
|
+
* @type {string}
|
|
253
|
+
* @memberof EventBodyFlagCheck
|
|
254
|
+
*/
|
|
255
|
+
flagId?: string | null;
|
|
256
|
+
/**
|
|
257
|
+
* The key of the flag being checked
|
|
258
|
+
* @type {string}
|
|
259
|
+
* @memberof EventBodyFlagCheck
|
|
260
|
+
*/
|
|
261
|
+
flagKey: string;
|
|
262
|
+
/**
|
|
263
|
+
* The reason why the value was returned
|
|
264
|
+
* @type {string}
|
|
265
|
+
* @memberof EventBodyFlagCheck
|
|
266
|
+
*/
|
|
267
|
+
reason: string;
|
|
268
|
+
/**
|
|
269
|
+
* Key-value pairs used to to identify company for which the flag was checked
|
|
270
|
+
* @type {{ [key: string]: string; }}
|
|
271
|
+
* @memberof EventBodyFlagCheck
|
|
272
|
+
*/
|
|
273
|
+
reqCompany?: {
|
|
274
|
+
[key: string]: string;
|
|
275
|
+
} | null;
|
|
276
|
+
/**
|
|
277
|
+
* Key-value pairs used to to identify user for which the flag was checked
|
|
278
|
+
* @type {{ [key: string]: string; }}
|
|
279
|
+
* @memberof EventBodyFlagCheck
|
|
280
|
+
*/
|
|
281
|
+
reqUser?: {
|
|
282
|
+
[key: string]: string;
|
|
283
|
+
} | null;
|
|
284
|
+
/**
|
|
285
|
+
* Schematic rule ID (starting with 'rule_') of the rule that matched for the flag, if any
|
|
286
|
+
* @type {string}
|
|
287
|
+
* @memberof EventBodyFlagCheck
|
|
288
|
+
*/
|
|
289
|
+
ruleId?: string | null;
|
|
290
|
+
/**
|
|
291
|
+
* Schematic user ID (starting with 'user_') of the user evaluated, if any
|
|
292
|
+
* @type {string}
|
|
293
|
+
* @memberof EventBodyFlagCheck
|
|
294
|
+
*/
|
|
295
|
+
userId?: string | null;
|
|
296
|
+
/**
|
|
297
|
+
* The value of the flag for the given company and/or user
|
|
298
|
+
* @type {boolean}
|
|
299
|
+
* @memberof EventBodyFlagCheck
|
|
300
|
+
*/
|
|
301
|
+
value: boolean;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export declare function EventBodyFlagCheckToJSON(json: any): EventBodyFlagCheck;
|
|
212
305
|
|
|
213
306
|
export declare type EventBodyIdentify = {
|
|
214
307
|
company?: {
|
|
@@ -227,7 +320,7 @@ export declare type EventBodyTrack = SchematicContext & {
|
|
|
227
320
|
traits?: Traits;
|
|
228
321
|
};
|
|
229
322
|
|
|
230
|
-
export declare type EventType = "identify" | "track";
|
|
323
|
+
export declare type EventType = "identify" | "track" | "flag_check";
|
|
231
324
|
|
|
232
325
|
export declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
233
326
|
|
|
@@ -261,6 +354,8 @@ export declare class Schematic {
|
|
|
261
354
|
private apiUrl;
|
|
262
355
|
private conn;
|
|
263
356
|
private context;
|
|
357
|
+
private debugEnabled;
|
|
358
|
+
private offlineEnabled;
|
|
264
359
|
private eventQueue;
|
|
265
360
|
private eventUrl;
|
|
266
361
|
private flagCheckListeners;
|
|
@@ -270,6 +365,7 @@ export declare class Schematic {
|
|
|
270
365
|
private storage;
|
|
271
366
|
private useWebSocket;
|
|
272
367
|
private checks;
|
|
368
|
+
private featureUsageEventMap;
|
|
273
369
|
private webSocketUrl;
|
|
274
370
|
constructor(apiKey: string, options?: SchematicOptions);
|
|
275
371
|
/**
|
|
@@ -280,6 +376,20 @@ export declare class Schematic {
|
|
|
280
376
|
* In REST mode, makes an API call for each check.
|
|
281
377
|
*/
|
|
282
378
|
checkFlag(options: CheckOptions): Promise<boolean>;
|
|
379
|
+
/**
|
|
380
|
+
* Helper function to log debug messages
|
|
381
|
+
* Only logs if debug mode is enabled
|
|
382
|
+
*/
|
|
383
|
+
private debug;
|
|
384
|
+
/**
|
|
385
|
+
* Helper function to check if client is in offline mode
|
|
386
|
+
*/
|
|
387
|
+
private isOffline;
|
|
388
|
+
/**
|
|
389
|
+
* Submit a flag check event
|
|
390
|
+
* Records data about a flag check for analytics
|
|
391
|
+
*/
|
|
392
|
+
private submitFlagCheckEvent;
|
|
283
393
|
/**
|
|
284
394
|
* Helper method for falling back to REST API when WebSocket connection fails
|
|
285
395
|
*/
|
|
@@ -287,6 +397,7 @@ export declare class Schematic {
|
|
|
287
397
|
/**
|
|
288
398
|
* Make an API call to fetch all flag values for a given context.
|
|
289
399
|
* Recommended for use in REST mode only.
|
|
400
|
+
* In offline mode, returns an empty object.
|
|
290
401
|
*/
|
|
291
402
|
checkFlags: (context?: SchematicContext) => Promise<Record<string, boolean>>;
|
|
292
403
|
/**
|
|
@@ -302,13 +413,21 @@ export declare class Schematic {
|
|
|
302
413
|
* 2. Send the context to the server
|
|
303
414
|
* 3. Wait for initial flag values to be returned
|
|
304
415
|
* The promise resolves when initial flag values are received.
|
|
416
|
+
* In offline mode, this will just set the context locally without connecting.
|
|
305
417
|
*/
|
|
306
418
|
setContext: (context: SchematicContext) => Promise<void>;
|
|
307
419
|
/**
|
|
308
420
|
* Send a track event
|
|
309
421
|
* Track usage for a company and/or user.
|
|
422
|
+
* Optimistically updates feature usage flags if tracking a featureUsageEvent.
|
|
310
423
|
*/
|
|
311
424
|
track: (body: EventBodyTrack) => Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Optimistically update feature usage flags associated with a tracked event
|
|
427
|
+
* This updates flags in memory with updated usage counts and value/featureUsageExceeded flags
|
|
428
|
+
* before the network request completes
|
|
429
|
+
*/
|
|
430
|
+
private optimisticallyUpdateFeatureUsage;
|
|
312
431
|
/**
|
|
313
432
|
* Event processing
|
|
314
433
|
*/
|
|
@@ -322,6 +441,7 @@ export declare class Schematic {
|
|
|
322
441
|
*/
|
|
323
442
|
/**
|
|
324
443
|
* If using websocket mode, close the connection when done.
|
|
444
|
+
* In offline mode, this is a no-op.
|
|
325
445
|
*/
|
|
326
446
|
cleanup: () => Promise<void>;
|
|
327
447
|
private wsConnect;
|
|
@@ -332,13 +452,15 @@ export declare class Schematic {
|
|
|
332
452
|
getIsPending: () => boolean;
|
|
333
453
|
addIsPendingListener: (listener: PendingListenerFn) => () => void;
|
|
334
454
|
private setIsPending;
|
|
335
|
-
getFlagCheck: (flagKey: string) => CheckFlagReturn;
|
|
336
|
-
getFlagValue: (flagKey: string) => boolean;
|
|
455
|
+
getFlagCheck: (flagKey: string) => CheckFlagReturn | undefined;
|
|
456
|
+
getFlagValue: (flagKey: string) => boolean | undefined;
|
|
337
457
|
/** Register an event listener that will be notified with the boolean value for a given flag when this value changes */
|
|
338
458
|
addFlagValueListener: (flagKey: string, listener: FlagValueListenerFn) => () => void;
|
|
339
459
|
/** Register an event listener that will be notified with the full flag check response for a given flag whenever this value changes */
|
|
340
460
|
addFlagCheckListener: (flagKey: string, listener: FlagCheckListenerFn) => () => void;
|
|
341
461
|
private notifyFlagCheckListeners;
|
|
462
|
+
/** Add or update a CheckFlagReturn in the featureUsageEventMap */
|
|
463
|
+
private updateFeatureUsageEventMap;
|
|
342
464
|
private notifyFlagValueListeners;
|
|
343
465
|
}
|
|
344
466
|
|
|
@@ -353,8 +475,15 @@ export declare type SchematicOptions = {
|
|
|
353
475
|
additionalHeaders?: Record<string, string>;
|
|
354
476
|
/** Optionally provide a custom API URL */
|
|
355
477
|
apiUrl?: string;
|
|
478
|
+
/** Enable debug mode to log flag check results and events to the console.
|
|
479
|
+
* Can also be enabled at runtime via URL query parameter "schematic_debug=true" */
|
|
480
|
+
debug?: boolean;
|
|
356
481
|
/** Optionally provide a custom event URL */
|
|
357
482
|
eventUrl?: string;
|
|
483
|
+
/** Enable offline mode to prevent all network requests.
|
|
484
|
+
* When enabled, events are only logged not sent, and flag checks return fallback values.
|
|
485
|
+
* Can also be enabled at runtime via URL query parameter "schematic_offline=true" */
|
|
486
|
+
offline?: boolean;
|
|
358
487
|
/** Optionally provide a custom storage persister for client-side storage */
|
|
359
488
|
storage?: StoragePersister;
|
|
360
489
|
/** Use a WebSocket connection for real-time flag checks; if using this, run the cleanup function to close the connection */
|