td-feature-node 0.0.0-stage → 0.0.2

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.
Files changed (49) hide show
  1. package/README.md +174 -2
  2. package/dist/client.d.ts +29 -0
  3. package/dist/client.js +206 -0
  4. package/dist/common/coercion.d.ts +4 -0
  5. package/dist/common/coercion.js +32 -0
  6. package/dist/common/config.d.ts +8 -0
  7. package/dist/common/config.js +172 -0
  8. package/dist/common/json.d.ts +7 -0
  9. package/dist/common/json.js +59 -0
  10. package/dist/core/config-snapshot.d.ts +15 -0
  11. package/dist/core/config-snapshot.js +58 -0
  12. package/dist/core/http-transport.d.ts +13 -0
  13. package/dist/core/http-transport.js +181 -0
  14. package/dist/core/request-operation.d.ts +16 -0
  15. package/dist/core/request-operation.js +73 -0
  16. package/dist/core/request-scheduler.d.ts +16 -0
  17. package/dist/core/request-scheduler.js +111 -0
  18. package/dist/core/request.d.ts +10 -0
  19. package/dist/core/request.js +72 -0
  20. package/dist/core/response.d.ts +5 -0
  21. package/dist/core/response.js +198 -0
  22. package/dist/core/result-cache.d.ts +14 -0
  23. package/dist/core/result-cache.js +70 -0
  24. package/dist/core/retry.d.ts +6 -0
  25. package/dist/core/retry.js +49 -0
  26. package/dist/core/stream-decoder.d.ts +10 -0
  27. package/dist/core/stream-decoder.js +29 -0
  28. package/dist/errors.d.ts +17 -0
  29. package/dist/errors.js +16 -0
  30. package/dist/evaluation.d.ts +10 -0
  31. package/dist/evaluation.js +9 -0
  32. package/dist/feature.d.ts +31 -0
  33. package/dist/feature.js +57 -0
  34. package/dist/index.d.ts +9 -0
  35. package/dist/index.js +11 -0
  36. package/dist/report/event.d.ts +3 -0
  37. package/dist/report/event.js +86 -0
  38. package/dist/report/expose-reporter.d.ts +40 -0
  39. package/dist/report/expose-reporter.js +285 -0
  40. package/dist/report/exposure-dedup.d.ts +16 -0
  41. package/dist/report/exposure-dedup.js +45 -0
  42. package/dist/report/owned-collection-adapter.d.ts +22 -0
  43. package/dist/report/owned-collection-adapter.js +243 -0
  44. package/dist/report/thinking-data-adapter.d.ts +11 -0
  45. package/dist/report/thinking-data-adapter.js +54 -0
  46. package/dist/types.d.ts +134 -0
  47. package/dist/types.js +9 -0
  48. package/npm-shrinkwrap.json +665 -0
  49. package/package.json +46 -4
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThinkingDataAdapter = void 0;
4
+ exports.createThinkingDataAdapter = createThinkingDataAdapter;
5
+ /** Converts SDK-owned exposure fields to the official Node track({ ... }) API. */
6
+ class ThinkingDataAdapter {
7
+ constructor(analytics) {
8
+ this.analytics = analytics;
9
+ if (!analytics ||
10
+ typeof analytics.track !== 'function' ||
11
+ typeof analytics.flush !== 'function' ||
12
+ typeof analytics.close !== 'function') {
13
+ throw new Error('A ThinkingData track/flush/close instance is required');
14
+ }
15
+ }
16
+ track(event, onFailure) {
17
+ let calling = true;
18
+ let localError;
19
+ const params = {
20
+ event: event.event,
21
+ properties: event.properties,
22
+ callback(error) {
23
+ if (!error)
24
+ return;
25
+ if (calling)
26
+ localError = error;
27
+ else if (onFailure)
28
+ onFailure(error);
29
+ },
30
+ };
31
+ if (event.accountId !== null)
32
+ params.accountId = event.accountId;
33
+ if (event.distinctId !== null)
34
+ params.distinctId = event.distinctId;
35
+ // Native track returns after buffering. Batch callbacks are not per-event
36
+ // acknowledgements, so waiting for one here would prevent batching.
37
+ const result = this.analytics.track(params);
38
+ calling = false;
39
+ if (localError)
40
+ throw localError;
41
+ return result;
42
+ }
43
+ flush() {
44
+ return this.analytics.flush();
45
+ }
46
+ close() {
47
+ return this.analytics.close();
48
+ }
49
+ }
50
+ exports.ThinkingDataAdapter = ThinkingDataAdapter;
51
+ /** Adapt an existing collection SDK instance; its lifecycle stays caller-owned. */
52
+ function createThinkingDataAdapter(analytics) {
53
+ return new ThinkingDataAdapter(analytics);
54
+ }
@@ -0,0 +1,134 @@
1
+ export type JsonValue = null | boolean | number | string | JsonValue[] | JsonObject;
2
+ export interface JsonObject {
3
+ [key: string]: JsonValue;
4
+ }
5
+ export interface FeatureRequest {
6
+ readonly accountId?: string | null;
7
+ readonly distinctId?: string | null;
8
+ readonly featureKeys?: ReadonlyArray<string> | null;
9
+ readonly customParams?: JsonObject | null;
10
+ }
11
+ export interface ExperimentInfo {
12
+ readonly experimentId: string | null;
13
+ readonly experimentGroupId: string | null;
14
+ readonly isControlGroup: boolean;
15
+ readonly bucketId: Readonly<{
16
+ [key: string]: string | null;
17
+ }> | null;
18
+ readonly featureList: ReadonlyArray<string | null> | null;
19
+ /** Optional metadata, emitted only when present; remote parsing does not invent it. */
20
+ readonly featureKey?: string | null;
21
+ readonly featureVersion?: string | null;
22
+ readonly splitMode?: string | null;
23
+ readonly assignmentSource?: string | null;
24
+ }
25
+ /** Structural subset of the native AbortSignal. */
26
+ export interface AbortSignalLike {
27
+ readonly aborted: boolean;
28
+ addEventListener(type: 'abort', listener: () => void): void;
29
+ removeEventListener(type: 'abort', listener: () => void): void;
30
+ }
31
+ export interface FetchOptions {
32
+ readonly signal?: AbortSignalLike;
33
+ }
34
+ export type ExposureValue = null | boolean | number | string | Date | ExposureValue[] | ExposureProperties;
35
+ export interface ExposureProperties {
36
+ [key: string]: ExposureValue;
37
+ }
38
+ export interface ExposureEvent {
39
+ readonly accountId: string | null;
40
+ readonly distinctId: string | null;
41
+ readonly event: 'te_experiment_exposure';
42
+ readonly properties: ExposureProperties;
43
+ }
44
+ export type ExposureSubmission = void | boolean | PromiseLike<void | boolean>;
45
+ /** Injected adapters remain caller-owned. Promise completion means submission, not ingestion. */
46
+ export interface ExposureAdapter {
47
+ track(event: ExposureEvent, onFailure?: (error: Error) => void): ExposureSubmission;
48
+ flush(): void | PromiseLike<void>;
49
+ close?(): void | PromiseLike<void>;
50
+ }
51
+ export interface ThinkingDataTrackEvent {
52
+ accountId?: string;
53
+ distinctId?: string;
54
+ event: string;
55
+ properties: ExposureProperties;
56
+ callback?: (error?: Error | null) => void;
57
+ }
58
+ /** Structural API of the official Node collection SDK. */
59
+ export interface ThinkingDataAnalytics {
60
+ track(event: ThinkingDataTrackEvent): ExposureSubmission;
61
+ flush(callback?: (error?: Error | null) => void): void | PromiseLike<void>;
62
+ close(): void | PromiseLike<void>;
63
+ }
64
+ /** Evaluation mode identifiers. LOCAL is reserved for a later implementation. */
65
+ export declare const SplitMode: Readonly<{
66
+ readonly REMOTE: "REMOTE";
67
+ /** Reserved; selecting LOCAL currently fails during initialization. */
68
+ readonly LOCAL: "LOCAL";
69
+ }>;
70
+ export type SplitMode = (typeof SplitMode)[keyof typeof SplitMode];
71
+ /** Client options. Durations are in milliseconds; sizes are bytes. */
72
+ export interface ClientOptions {
73
+ readonly appId: string;
74
+ /** Shared HTTP(S) base URL for RCC and SDK-owned collection. RCC preserves path prefixes. */
75
+ readonly serverUrl: string;
76
+ /** Evaluation mode selected at initialization. Defaults to REMOTE; LOCAL is not implemented. */
77
+ readonly splitMode?: SplitMode;
78
+ readonly timeout?: number;
79
+ readonly maxHttpConnections?: number;
80
+ readonly maxDecompressedResponseBytes?: number;
81
+ /** Extra HTTP attempts; defaults to zero (automatic retries disabled). */
82
+ readonly retryTimes?: number;
83
+ readonly retryInterval?: number;
84
+ readonly retryStrategy?: 'FIXED_INTERVAL' | 'EXPONENTIAL_BACKOFF';
85
+ readonly retryJitter?: boolean;
86
+ /** Retry wait limit in milliseconds; a longer Retry-After stops retries. */
87
+ readonly maxRetryInterval?: number;
88
+ /** Active fetch pipelines, including retry backoff and RCC decoding. */
89
+ readonly maxConcurrentRequests?: number;
90
+ /** Waiting fetch capacity; defaults to zero. Unavailable slots reject QUEUE_FULL. */
91
+ readonly maxQueueSize?: number;
92
+ readonly enableCache?: boolean;
93
+ /** Fallback TTL in seconds when RCC returns a non-positive TTL, as in Java. */
94
+ readonly cacheExpireTime?: number;
95
+ readonly maxCacheSize?: number;
96
+ readonly autoExposure?: boolean;
97
+ readonly exposureDedupMaxSize?: number;
98
+ readonly exposureDedupExpireSeconds?: number;
99
+ readonly exposureQueueCapacity?: number;
100
+ /** SDK-owned collector batch threshold; caller-owned instances keep their own settings. */
101
+ readonly exposureBatchSize?: number;
102
+ /** Maximum buffering time for a partial SDK-owned batch, in milliseconds. */
103
+ readonly exposureFlushIntervalMillis?: number;
104
+ readonly exposureFlushTimeoutMillis?: number;
105
+ /** Caller-owned adapter; mutually exclusive with tdAnalytics. */
106
+ readonly exposureAdapter?: ExposureAdapter;
107
+ /** Caller-owned official Batch/AsyncBatch/Debug instance. */
108
+ readonly tdAnalytics?: ThinkingDataAnalytics;
109
+ /** Explicit PEM CA trust list for RCC/owned collection HTTPS; replaces default roots. */
110
+ readonly tlsCa?: string | ReadonlyArray<string>;
111
+ }
112
+ export interface ResolvedClientOptions extends ClientOptions {
113
+ readonly splitMode: SplitMode;
114
+ readonly timeout: number;
115
+ readonly maxHttpConnections: number;
116
+ readonly maxDecompressedResponseBytes: number;
117
+ readonly retryTimes: number;
118
+ readonly retryInterval: number;
119
+ readonly retryStrategy: 'FIXED_INTERVAL' | 'EXPONENTIAL_BACKOFF';
120
+ readonly retryJitter: boolean;
121
+ readonly maxRetryInterval: number;
122
+ readonly maxConcurrentRequests: number;
123
+ readonly maxQueueSize: number;
124
+ readonly enableCache: boolean;
125
+ readonly cacheExpireTime: number;
126
+ readonly maxCacheSize: number;
127
+ readonly autoExposure: boolean;
128
+ readonly exposureDedupMaxSize: number;
129
+ readonly exposureDedupExpireSeconds: number;
130
+ readonly exposureQueueCapacity: number;
131
+ readonly exposureBatchSize: number;
132
+ readonly exposureFlushIntervalMillis: number;
133
+ readonly exposureFlushTimeoutMillis: number;
134
+ }
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SplitMode = void 0;
4
+ /** Evaluation mode identifiers. LOCAL is reserved for a later implementation. */
5
+ exports.SplitMode = Object.freeze({
6
+ REMOTE: 'REMOTE',
7
+ /** Reserved; selecting LOCAL currently fails during initialization. */
8
+ LOCAL: 'LOCAL',
9
+ });