@reflag/node-sdk 1.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +835 -0
- package/dist/package.json +49 -0
- package/dist/src/batch-buffer.js +85 -0
- package/dist/src/batch-buffer.js.map +1 -0
- package/dist/src/cache.js +71 -0
- package/dist/src/cache.js.map +1 -0
- package/dist/src/client.js +1141 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/config.js +98 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/edgeClient.js +32 -0
- package/dist/src/edgeClient.js.map +1 -0
- package/dist/src/fetch-http-client.js +85 -0
- package/dist/src/fetch-http-client.js.map +1 -0
- package/dist/src/flusher.js +56 -0
- package/dist/src/flusher.js.map +1 -0
- package/dist/src/inRequestCache.js +72 -0
- package/dist/src/inRequestCache.js.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/periodicallyUpdatingCache.js +78 -0
- package/dist/src/periodicallyUpdatingCache.js.map +1 -0
- package/dist/src/rate-limiter.js +52 -0
- package/dist/src/rate-limiter.js.map +1 -0
- package/dist/src/types.js +6 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.js +207 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/types/src/batch-buffer.d.ts +27 -0
- package/dist/types/src/batch-buffer.d.ts.map +1 -0
- package/dist/types/src/cache.d.ts +16 -0
- package/dist/types/src/cache.d.ts.map +1 -0
- package/dist/types/src/client.d.ts +410 -0
- package/dist/types/src/client.d.ts.map +1 -0
- package/dist/types/src/config.d.ts +20 -0
- package/dist/types/src/config.d.ts.map +1 -0
- package/dist/types/src/edgeClient.d.ts +25 -0
- package/dist/types/src/edgeClient.d.ts.map +1 -0
- package/dist/types/src/fetch-http-client.d.ts +20 -0
- package/dist/types/src/fetch-http-client.d.ts.map +1 -0
- package/dist/types/src/flusher.d.ts +4 -0
- package/dist/types/src/flusher.d.ts.map +1 -0
- package/dist/types/src/inRequestCache.d.ts +7 -0
- package/dist/types/src/inRequestCache.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/periodicallyUpdatingCache.d.ts +16 -0
- package/dist/types/src/periodicallyUpdatingCache.d.ts.map +1 -0
- package/dist/types/src/rate-limiter.d.ts +14 -0
- package/dist/types/src/rate-limiter.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +639 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/utils.d.ts +65 -0
- package/dist/types/src/utils.d.ts.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeoutError = void 0;
|
|
4
|
+
exports.ok = ok;
|
|
5
|
+
exports.idOk = idOk;
|
|
6
|
+
exports.isObject = isObject;
|
|
7
|
+
exports.decorate = decorate;
|
|
8
|
+
exports.applyLogLevel = applyLogLevel;
|
|
9
|
+
exports.decorateLogger = decorateLogger;
|
|
10
|
+
exports.mergeSkipUndefined = mergeSkipUndefined;
|
|
11
|
+
exports.hashObject = hashObject;
|
|
12
|
+
exports.once = once;
|
|
13
|
+
exports.withTimeout = withTimeout;
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
/**
|
|
16
|
+
* Assert that the given condition is `true`.
|
|
17
|
+
*
|
|
18
|
+
* @param condition - The condition to check.
|
|
19
|
+
* @param message - The error message to throw.
|
|
20
|
+
**/
|
|
21
|
+
function ok(condition, message) {
|
|
22
|
+
if (!condition) {
|
|
23
|
+
throw new Error(`validation failed: ${message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Assert that the given values is a valid user/company id
|
|
28
|
+
**/
|
|
29
|
+
function idOk(id, entity) {
|
|
30
|
+
ok((typeof id === "string" && id.length > 0) || typeof id === "number", `${entity} must be a string or number if given`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if the given item is an object.
|
|
34
|
+
*
|
|
35
|
+
* @param item - The item to check.
|
|
36
|
+
* @returns `true` if the item is an object, `false` otherwise.
|
|
37
|
+
**/
|
|
38
|
+
function isObject(item) {
|
|
39
|
+
return (item && typeof item === "object" && !Array.isArray(item)) || false;
|
|
40
|
+
}
|
|
41
|
+
function decorate(prefix, fn) {
|
|
42
|
+
return (message, ...args) => {
|
|
43
|
+
fn(`${prefix} ${message}`, ...args);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function applyLogLevel(logger, logLevel) {
|
|
47
|
+
switch (logLevel === null || logLevel === void 0 ? void 0 : logLevel.toLocaleUpperCase()) {
|
|
48
|
+
case "DEBUG":
|
|
49
|
+
return {
|
|
50
|
+
debug: decorate("[debug]", logger.debug),
|
|
51
|
+
info: decorate("[info]", logger.info),
|
|
52
|
+
warn: decorate("[warn]", logger.warn),
|
|
53
|
+
error: decorate("[error]", logger.error),
|
|
54
|
+
};
|
|
55
|
+
case "INFO":
|
|
56
|
+
return {
|
|
57
|
+
debug: () => void 0,
|
|
58
|
+
info: decorate("[info]", logger.info),
|
|
59
|
+
warn: decorate("[warn]", logger.warn),
|
|
60
|
+
error: decorate("[error]", logger.error),
|
|
61
|
+
};
|
|
62
|
+
case "WARN":
|
|
63
|
+
return {
|
|
64
|
+
debug: () => void 0,
|
|
65
|
+
info: () => void 0,
|
|
66
|
+
warn: decorate("[warn]", logger.warn),
|
|
67
|
+
error: decorate("[error]", logger.error),
|
|
68
|
+
};
|
|
69
|
+
case "ERROR":
|
|
70
|
+
return {
|
|
71
|
+
debug: () => void 0,
|
|
72
|
+
info: () => void 0,
|
|
73
|
+
warn: () => void 0,
|
|
74
|
+
error: decorate("[error]", logger.error),
|
|
75
|
+
};
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`invalid log level: ${logLevel}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Decorate the messages of a given logger with the given prefix.
|
|
82
|
+
*
|
|
83
|
+
* @param prefix - The prefix to add to log messages.
|
|
84
|
+
* @param logger - The logger to decorate.
|
|
85
|
+
* @returns The decorated logger.
|
|
86
|
+
**/
|
|
87
|
+
function decorateLogger(prefix, logger) {
|
|
88
|
+
ok(typeof prefix === "string", "prefix must be a string");
|
|
89
|
+
ok(typeof logger === "object", "logger must be an object");
|
|
90
|
+
return {
|
|
91
|
+
debug: decorate(prefix, logger.debug),
|
|
92
|
+
info: decorate(prefix, logger.info),
|
|
93
|
+
warn: decorate(prefix, logger.warn),
|
|
94
|
+
error: decorate(prefix, logger.error),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Merge two objects, skipping `undefined` values.
|
|
98
|
+
*
|
|
99
|
+
* @param target - The target object.
|
|
100
|
+
* @param source - The source object.
|
|
101
|
+
* @returns The merged object.
|
|
102
|
+
**/
|
|
103
|
+
function mergeSkipUndefined(target, source) {
|
|
104
|
+
const newTarget = Object.assign({}, target);
|
|
105
|
+
for (const key in source) {
|
|
106
|
+
if (source[key] === undefined) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
newTarget[key] = source[key];
|
|
110
|
+
}
|
|
111
|
+
return newTarget;
|
|
112
|
+
}
|
|
113
|
+
function updateSha1Hash(hash, value) {
|
|
114
|
+
if (value === null) {
|
|
115
|
+
hash.update("null");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
switch (typeof value) {
|
|
119
|
+
case "object":
|
|
120
|
+
if (Array.isArray(value)) {
|
|
121
|
+
for (const item of value) {
|
|
122
|
+
updateSha1Hash(hash, item);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
for (const key of Object.keys(value).sort()) {
|
|
127
|
+
hash.update(key);
|
|
128
|
+
updateSha1Hash(hash, value[key]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
case "string":
|
|
133
|
+
hash.update(value);
|
|
134
|
+
break;
|
|
135
|
+
case "number":
|
|
136
|
+
case "boolean":
|
|
137
|
+
case "symbol":
|
|
138
|
+
case "bigint":
|
|
139
|
+
case "function":
|
|
140
|
+
hash.update(value.toString());
|
|
141
|
+
break;
|
|
142
|
+
case "undefined":
|
|
143
|
+
default:
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Hash an object using SHA1.
|
|
149
|
+
*
|
|
150
|
+
* @param obj - The object to hash.
|
|
151
|
+
*
|
|
152
|
+
* @returns The SHA1 hash of the object.
|
|
153
|
+
**/
|
|
154
|
+
function hashObject(obj) {
|
|
155
|
+
ok(isObject(obj), "obj must be an object");
|
|
156
|
+
const hash = (0, crypto_1.createHash)("sha1");
|
|
157
|
+
updateSha1Hash(hash, obj);
|
|
158
|
+
return hash.digest("base64");
|
|
159
|
+
}
|
|
160
|
+
function once(fn) {
|
|
161
|
+
let called = false;
|
|
162
|
+
let returned;
|
|
163
|
+
return function () {
|
|
164
|
+
if (called) {
|
|
165
|
+
return returned;
|
|
166
|
+
}
|
|
167
|
+
returned = fn();
|
|
168
|
+
called = true;
|
|
169
|
+
return returned;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
class TimeoutError extends Error {
|
|
173
|
+
constructor(timeoutMs) {
|
|
174
|
+
super(`Operation timed out after ${timeoutMs}ms`);
|
|
175
|
+
this.name = "TimeoutError";
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.TimeoutError = TimeoutError;
|
|
179
|
+
/**
|
|
180
|
+
* Wraps a promise with a timeout. If the promise doesn't resolve within the specified
|
|
181
|
+
* timeout, it will reject with a timeout error. The original promise will still
|
|
182
|
+
* continue to execute but its result will be ignored.
|
|
183
|
+
*
|
|
184
|
+
* @param promise - The promise to wrap with a timeout
|
|
185
|
+
* @param timeoutMs - The timeout in milliseconds
|
|
186
|
+
* @returns A promise that resolves with the original promise result or rejects with a timeout error
|
|
187
|
+
* @throws {Error} If the timeout is reached before the promise resolves
|
|
188
|
+
**/
|
|
189
|
+
function withTimeout(promise, timeoutMs) {
|
|
190
|
+
ok(timeoutMs > 0, "timeout must be a positive number");
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
const timeoutId = setTimeout(() => {
|
|
193
|
+
reject(new TimeoutError(timeoutMs));
|
|
194
|
+
}, timeoutMs);
|
|
195
|
+
promise
|
|
196
|
+
.then((result) => {
|
|
197
|
+
resolve(result);
|
|
198
|
+
})
|
|
199
|
+
.catch((error) => {
|
|
200
|
+
reject(error);
|
|
201
|
+
})
|
|
202
|
+
.finally(() => {
|
|
203
|
+
clearTimeout(timeoutId);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAUA,gBAIC;AAID,oBAKC;AAQD,4BAEC;AAGD,4BAIC;AAED,sCAiCC;AASD,wCAUC;AAQD,gDAYC;AA0CD,gCAOC;AAED,oBAaC;AAmBD,kCAsBC;AA3ND,mCAA0C;AAI1C;;;;;IAKI;AACJ,SAAgB,EAAE,CAAC,SAAkB,EAAE,OAAe;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AACD;;IAEI;AACJ,SAAgB,IAAI,CAAC,EAAU,EAAE,MAAc;IAC7C,EAAE,CACA,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,EAAE,KAAK,QAAQ,EACnE,GAAG,MAAM,sCAAsC,CAChD,CAAC;AACJ,CAAC;AAED;;;;;IAKI;AACJ,SAA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E;YACZ,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BatchBufferOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A buffer that accumulates items and flushes them in batches.
|
|
4
|
+
* @typeparam T - The type of items to buffer.
|
|
5
|
+
*/
|
|
6
|
+
export default class BatchBuffer<T> {
|
|
7
|
+
private buffer;
|
|
8
|
+
private flushHandler;
|
|
9
|
+
private logger?;
|
|
10
|
+
private maxSize;
|
|
11
|
+
private intervalMs;
|
|
12
|
+
private timer;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new `BatchBuffer` instance.
|
|
15
|
+
* @param options - The options to configure the buffer.
|
|
16
|
+
* @throws If the options are invalid.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: BatchBufferOptions<T>);
|
|
19
|
+
/**
|
|
20
|
+
* Adds an item to the buffer.
|
|
21
|
+
*
|
|
22
|
+
* @param item - The item to add.
|
|
23
|
+
*/
|
|
24
|
+
add(item: T): Promise<void>;
|
|
25
|
+
flush(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=batch-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-buffer.d.ts","sourceRoot":"","sources":["../../../src/batch-buffer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAU,MAAM,SAAS,CAAC;AAGrD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW,CAAC,CAAC;IAChC,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,YAAY,CAAgC;IACpD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAA+B;IAE5C;;;;OAIG;gBACS,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAwB1C;;;;OAIG;IACU,GAAG,CAAC,IAAI,EAAE,CAAC;IAUX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA2BpC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Cache, Logger } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Create a cached function that updates the value asynchronously.
|
|
4
|
+
*
|
|
5
|
+
* The value is updated every `ttl` milliseconds.
|
|
6
|
+
* If the value is older than `staleTtl` milliseconds, a warning is logged.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The type of the value.
|
|
9
|
+
* @param ttl - The time-to-live in milliseconds.
|
|
10
|
+
* @param staleTtl - The time-to-live after which a warning is logged.
|
|
11
|
+
* @param logger - The logger to use.
|
|
12
|
+
* @param fn - The function to call to get the value.
|
|
13
|
+
* @returns The cache object.
|
|
14
|
+
**/
|
|
15
|
+
export default function cache<T>(ttl: number, staleTtl: number, logger: Logger | undefined, fn: () => Promise<T | undefined>): Cache<T>;
|
|
16
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;IAYI;AACJ,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,GAC/B,KAAK,CAAC,CAAC,CAAC,CAkDV"}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import type { FlagDefinition, FlagOverrides, FlagOverridesFn, IdType, TypedFlagKey } from "./types";
|
|
2
|
+
import { ClientOptions, Context, ContextWithTracking, HttpClient, Logger, TrackOptions, TypedFlags } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* The SDK client.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This is the main class for interacting with Reflag.
|
|
8
|
+
* It is used to evaluate flags, update user and company contexts, and track events.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // set the REFLAG_SECRET_KEY environment variable or pass the secret key to the constructor
|
|
13
|
+
* const client = new ReflagClient();
|
|
14
|
+
*
|
|
15
|
+
* // evaluate a flag
|
|
16
|
+
* const isFlagEnabled = client.getFlag("flag-key", {
|
|
17
|
+
* user: { id: "user-id" },
|
|
18
|
+
* company: { id: "company-id" },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
**/
|
|
22
|
+
export declare class ReflagClient {
|
|
23
|
+
private _config;
|
|
24
|
+
httpClient: HttpClient;
|
|
25
|
+
private flagsCache;
|
|
26
|
+
private batchBuffer;
|
|
27
|
+
private rateLimiter;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the logger associated with the client.
|
|
30
|
+
*/
|
|
31
|
+
readonly logger: Logger;
|
|
32
|
+
private initializationFinished;
|
|
33
|
+
private _initialize;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new SDK client.
|
|
36
|
+
* See README for configuration options.
|
|
37
|
+
*
|
|
38
|
+
* @param options - The options for the client or an existing client to clone.
|
|
39
|
+
* @param options.secretKey - The secret key to use for the client.
|
|
40
|
+
* @param options.apiBaseUrl - The base URL to send requests to (optional).
|
|
41
|
+
* @param options.logger - The logger to use for logging (optional).
|
|
42
|
+
* @param options.httpClient - The HTTP client to use for sending requests (optional).
|
|
43
|
+
* @param options.logLevel - The log level to use for logging (optional).
|
|
44
|
+
* @param options.offline - Whether to run in offline mode (optional).
|
|
45
|
+
* @param options.fallbackFlags - The fallback flags to use if the flag is not found (optional).
|
|
46
|
+
* @param options.batchOptions - The options for the batch buffer (optional).
|
|
47
|
+
* @param options.flagOverrides - The flag overrides to use for the client (optional).
|
|
48
|
+
* @param options.configFile - The path to the config file (optional).
|
|
49
|
+
* @param options.flagsFetchRetries - Number of retries for fetching flags (optional, defaults to 3).
|
|
50
|
+
* @param options.fetchTimeoutMs - Timeout for fetching flags (optional, defaults to 10000ms).
|
|
51
|
+
* @param options.cacheStrategy - The cache strategy to use for the client (optional, defaults to "periodically-update").
|
|
52
|
+
*
|
|
53
|
+
* @throws An error if the options are invalid.
|
|
54
|
+
**/
|
|
55
|
+
constructor(options?: ClientOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Sets the flag overrides.
|
|
58
|
+
*
|
|
59
|
+
* @param overrides - The flag overrides.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* The flag overrides are used to override the flag definitions.
|
|
63
|
+
* This is useful for testing or development.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* client.flagOverrides = {
|
|
68
|
+
* "flag-1": true,
|
|
69
|
+
* "flag-2": false,
|
|
70
|
+
* };
|
|
71
|
+
* ```
|
|
72
|
+
**/
|
|
73
|
+
set flagOverrides(overrides: FlagOverridesFn | FlagOverrides);
|
|
74
|
+
/**
|
|
75
|
+
* Clears the flag overrides.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* This is useful for testing or development.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* afterAll(() => {
|
|
83
|
+
* client.clearFlagOverrides();
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
**/
|
|
87
|
+
clearFlagOverrides(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new BoundReflagClient with the user/company/otherContext
|
|
90
|
+
* set to be used in subsequent calls.
|
|
91
|
+
* For example, for evaluating flag targeting or tracking events.
|
|
92
|
+
*
|
|
93
|
+
* @param context - The context to bind the client to.
|
|
94
|
+
* @param context.enableTracking - Whether to enable tracking for the context.
|
|
95
|
+
* @param context.user - The user context.
|
|
96
|
+
* @param context.company - The company context.
|
|
97
|
+
* @param context.other - The other context.
|
|
98
|
+
*
|
|
99
|
+
* @returns A new client bound with the arguments given.
|
|
100
|
+
*
|
|
101
|
+
* @throws An error if the user/company is given but their ID is not a string.
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* The `updateUser` / `updateCompany` methods will automatically be called when
|
|
105
|
+
* the user/company is set respectively.
|
|
106
|
+
**/
|
|
107
|
+
bindClient({ enableTracking, ...context }: ContextWithTracking): BoundReflagClient;
|
|
108
|
+
/**
|
|
109
|
+
* Updates the associated user in Reflag.
|
|
110
|
+
*
|
|
111
|
+
* @param userId - The userId of the user to update.
|
|
112
|
+
* @param options - The options for the user.
|
|
113
|
+
* @param options.attributes - The additional attributes of the user (optional).
|
|
114
|
+
* @param options.meta - The meta context associated with tracking (optional).
|
|
115
|
+
*
|
|
116
|
+
* @throws An error if the company is not set or the options are invalid.
|
|
117
|
+
* @remarks
|
|
118
|
+
* The company must be set using `withCompany` before calling this method.
|
|
119
|
+
* If the user is set, the company will be associated with the user.
|
|
120
|
+
**/
|
|
121
|
+
updateUser(userId: IdType, options?: TrackOptions): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Updates the associated company in Reflag.
|
|
124
|
+
*
|
|
125
|
+
* @param companyId - The companyId of the company to update.
|
|
126
|
+
* @param options - The options for the company.
|
|
127
|
+
* @param options.attributes - The additional attributes of the company (optional).
|
|
128
|
+
* @param options.meta - The meta context associated with tracking (optional).
|
|
129
|
+
* @param options.userId - The userId of the user to associate with the company (optional).
|
|
130
|
+
*
|
|
131
|
+
* @throws An error if the company is not set or the options are invalid.
|
|
132
|
+
* @remarks
|
|
133
|
+
* The company must be set using `withCompany` before calling this method.
|
|
134
|
+
* If the user is set, the company will be associated with the user.
|
|
135
|
+
**/
|
|
136
|
+
updateCompany(companyId: IdType, options?: TrackOptions & {
|
|
137
|
+
userId?: IdType;
|
|
138
|
+
}): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Tracks an event in Reflag.
|
|
141
|
+
|
|
142
|
+
* @param options.companyId - Optional company ID for the event (optional).
|
|
143
|
+
*
|
|
144
|
+
* @throws An error if the user is not set or the event is invalid or the options are invalid.
|
|
145
|
+
* @remarks
|
|
146
|
+
* If the company is set, the event will be associated with the company.
|
|
147
|
+
**/
|
|
148
|
+
track(userId: IdType, event: string, options?: TrackOptions & {
|
|
149
|
+
companyId?: IdType;
|
|
150
|
+
}): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Initializes the client by caching the flags definitions.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Call this method before calling `getFlags` to ensure the flag definitions are cached.
|
|
156
|
+
* The client will ignore subsequent calls to this method.
|
|
157
|
+
**/
|
|
158
|
+
initialize(): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Flushes and completes any in-flight fetches in the flag cache.
|
|
161
|
+
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* It is recommended to call this method when the application is shutting down to ensure all events are sent
|
|
164
|
+
* before the process exits.
|
|
165
|
+
*
|
|
166
|
+
* This method is automatically called when the process exits if `batchOptions.flushOnExit` is `true` in the options (default).
|
|
167
|
+
*/
|
|
168
|
+
flush(): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the flag definitions, including all config values.
|
|
171
|
+
* To evaluate which flags are enabled for a given user/company, use `getFlags`.
|
|
172
|
+
*
|
|
173
|
+
* @returns The flags definitions.
|
|
174
|
+
*/
|
|
175
|
+
getFlagDefinitions(): FlagDefinition[];
|
|
176
|
+
/**
|
|
177
|
+
* Gets the evaluated flags for the current context which includes the user, company, and custom context.
|
|
178
|
+
*
|
|
179
|
+
* @param options - The options for the context.
|
|
180
|
+
* @param options.enableTracking - Whether to enable tracking for the context.
|
|
181
|
+
* @param options.meta - The meta context associated with the context.
|
|
182
|
+
* @param options.user - The user context.
|
|
183
|
+
* @param options.company - The company context.
|
|
184
|
+
* @param options.other - The other context.
|
|
185
|
+
*
|
|
186
|
+
* @returns The evaluated flags.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* Call `initialize` before calling this method to ensure the flag definitions are cached, no flags will be returned otherwise.
|
|
190
|
+
**/
|
|
191
|
+
getFlags({ enableTracking, ...context }: ContextWithTracking): TypedFlags;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the evaluated flag for the current context which includes the user, company, and custom context.
|
|
194
|
+
* Using the `isEnabled` property sends a `check` event to Reflag.
|
|
195
|
+
*
|
|
196
|
+
* @param key - The key of the flag to get.
|
|
197
|
+
* @returns The evaluated flag.
|
|
198
|
+
*
|
|
199
|
+
* @remarks
|
|
200
|
+
* Call `initialize` before calling this method to ensure the flag definitions are cached, no flags will be returned otherwise.
|
|
201
|
+
**/
|
|
202
|
+
getFlag<TKey extends TypedFlagKey>({ enableTracking, ...context }: ContextWithTracking, key: TKey): TypedFlags[TKey];
|
|
203
|
+
/**
|
|
204
|
+
* Gets evaluated flags with the usage of remote context.
|
|
205
|
+
* This method triggers a network request every time it's called.
|
|
206
|
+
*
|
|
207
|
+
* @param userId - The userId of the user to get the flags for.
|
|
208
|
+
* @param companyId - The companyId of the company to get the flags for.
|
|
209
|
+
* @param additionalContext - The additional context to get the flags for.
|
|
210
|
+
*
|
|
211
|
+
* @returns evaluated flags
|
|
212
|
+
*/
|
|
213
|
+
getFlagsRemote(userId?: IdType, companyId?: IdType, additionalContext?: Context): Promise<TypedFlags>;
|
|
214
|
+
/**
|
|
215
|
+
* Gets evaluated flag with the usage of remote context.
|
|
216
|
+
* This method triggers a network request every time it's called.
|
|
217
|
+
*
|
|
218
|
+
* @param key - The key of the flag to get.
|
|
219
|
+
* @param userId - The userId of the user to get the flag for.
|
|
220
|
+
* @param companyId - The companyId of the company to get the flag for.
|
|
221
|
+
* @param additionalContext - The additional context to get the flag for.
|
|
222
|
+
*
|
|
223
|
+
* @returns evaluated flag
|
|
224
|
+
*/
|
|
225
|
+
getFlagRemote<TKey extends TypedFlagKey>(key: TKey, userId?: IdType, companyId?: IdType, additionalContext?: Context): Promise<TypedFlags[TKey]>;
|
|
226
|
+
private buildUrl;
|
|
227
|
+
/**
|
|
228
|
+
* Sends a POST request to the specified path.
|
|
229
|
+
*
|
|
230
|
+
* @param path - The path to send the request to.
|
|
231
|
+
* @param body - The body of the request.
|
|
232
|
+
*
|
|
233
|
+
* @returns A boolean indicating if the request was successful.
|
|
234
|
+
*
|
|
235
|
+
* @throws An error if the path or body is invalid.
|
|
236
|
+
**/
|
|
237
|
+
private post;
|
|
238
|
+
/**
|
|
239
|
+
* Sends a GET request to the specified path.
|
|
240
|
+
*
|
|
241
|
+
* @param path - The path to send the request to.
|
|
242
|
+
* @param retries - Optional number of retries for the request.
|
|
243
|
+
*
|
|
244
|
+
* @returns The response from the server.
|
|
245
|
+
* @throws An error if the path is invalid.
|
|
246
|
+
**/
|
|
247
|
+
private get;
|
|
248
|
+
/**
|
|
249
|
+
* Sends a batch of events to the Reflag API.
|
|
250
|
+
*
|
|
251
|
+
* @param events - The events to send.
|
|
252
|
+
*
|
|
253
|
+
* @throws An error if the send fails.
|
|
254
|
+
**/
|
|
255
|
+
private sendBulkEvents;
|
|
256
|
+
/**
|
|
257
|
+
* Sends a flag event to the Reflag API.
|
|
258
|
+
*
|
|
259
|
+
* Flag events are used to track the evaluation of flag targeting rules.
|
|
260
|
+
* "check" events are sent when a flag's `isEnabled` property is checked.
|
|
261
|
+
* "evaluate" events are sent when a flag's targeting rules are matched against
|
|
262
|
+
* the current context.
|
|
263
|
+
*
|
|
264
|
+
* @param event - The event to send.
|
|
265
|
+
* @param event.action - The action to send.
|
|
266
|
+
* @param event.key - The key of the flag to send.
|
|
267
|
+
* @param event.targetingVersion - The targeting version of the flag to send.
|
|
268
|
+
* @param event.evalResult - The evaluation result of the flag to send.
|
|
269
|
+
* @param event.evalContext - The evaluation context of the flag to send.
|
|
270
|
+
* @param event.evalRuleResults - The evaluation rule results of the flag to send.
|
|
271
|
+
* @param event.evalMissingFields - The evaluation missing fields of the flag to send.
|
|
272
|
+
*
|
|
273
|
+
* @throws An error if the event is invalid.
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* This method is rate-limited to prevent too many events from being sent.
|
|
277
|
+
**/
|
|
278
|
+
private sendFlagEvent;
|
|
279
|
+
/**
|
|
280
|
+
* Updates the context in Reflag (if needed).
|
|
281
|
+
* This method should be used before requesting flags or binding a client.
|
|
282
|
+
*
|
|
283
|
+
* @param options - The options for the context.
|
|
284
|
+
* @param options.enableTracking - Whether to enable tracking for the context.
|
|
285
|
+
* @param options.meta - The meta context associated with the context.
|
|
286
|
+
* @param options.user - The user context.
|
|
287
|
+
* @param options.company - The company context.
|
|
288
|
+
* @param options.other - The other context.
|
|
289
|
+
*/
|
|
290
|
+
private syncContext;
|
|
291
|
+
/**
|
|
292
|
+
* Warns if a flag has targeting rules that require context fields that are missing.
|
|
293
|
+
*
|
|
294
|
+
* @param context - The context.
|
|
295
|
+
* @param flag - The flag to check.
|
|
296
|
+
*/
|
|
297
|
+
private _warnMissingFlagContextFields;
|
|
298
|
+
private _getFlags;
|
|
299
|
+
private _wrapRawFlag;
|
|
300
|
+
private _getFlagsRemote;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* A client bound with a specific user, company, and other context.
|
|
304
|
+
*/
|
|
305
|
+
export declare class BoundReflagClient {
|
|
306
|
+
private readonly _client;
|
|
307
|
+
private readonly _options;
|
|
308
|
+
/**
|
|
309
|
+
* (Internal) Creates a new BoundReflagClient. Use `bindClient` to create a new client bound with a specific context.
|
|
310
|
+
*
|
|
311
|
+
* @param client - The `ReflagClient` to use.
|
|
312
|
+
* @param options - The options for the client.
|
|
313
|
+
* @param options.enableTracking - Whether to enable tracking for the client.
|
|
314
|
+
*
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
317
|
+
constructor(client: ReflagClient, { enableTracking, ...context }: ContextWithTracking);
|
|
318
|
+
/**
|
|
319
|
+
* Gets the "other" context associated with the client.
|
|
320
|
+
*
|
|
321
|
+
* @returns The "other" context or `undefined` if it is not set.
|
|
322
|
+
**/
|
|
323
|
+
get otherContext(): Record<string, any> | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Gets the user associated with the client.
|
|
326
|
+
*
|
|
327
|
+
* @returns The user or `undefined` if it is not set.
|
|
328
|
+
**/
|
|
329
|
+
get user(): {
|
|
330
|
+
[k: string]: any;
|
|
331
|
+
id: string | number | undefined;
|
|
332
|
+
name?: string | undefined;
|
|
333
|
+
email?: string | undefined;
|
|
334
|
+
avatar?: string | undefined;
|
|
335
|
+
} | undefined;
|
|
336
|
+
/**
|
|
337
|
+
* Gets the company associated with the client.
|
|
338
|
+
*
|
|
339
|
+
* @returns The company or `undefined` if it is not set.
|
|
340
|
+
**/
|
|
341
|
+
get company(): {
|
|
342
|
+
[k: string]: any;
|
|
343
|
+
id: string | number | undefined;
|
|
344
|
+
name?: string | undefined;
|
|
345
|
+
avatar?: string | undefined;
|
|
346
|
+
} | undefined;
|
|
347
|
+
/**
|
|
348
|
+
* Get flags for the user/company/other context bound to this client.
|
|
349
|
+
* Meant for use in serialization of flags for transferring to the client-side/browser.
|
|
350
|
+
*
|
|
351
|
+
* @returns Flags for the given user/company and whether each one is enabled or not
|
|
352
|
+
*/
|
|
353
|
+
getFlags(): TypedFlags;
|
|
354
|
+
/**
|
|
355
|
+
* Get a specific flag for the user/company/other context bound to this client.
|
|
356
|
+
* Using the `isEnabled` property sends a `check` event to Reflag.
|
|
357
|
+
*
|
|
358
|
+
* @param key - The key of the flag to get.
|
|
359
|
+
*
|
|
360
|
+
* @returns Flags for the given user/company and whether each one is enabled or not
|
|
361
|
+
*/
|
|
362
|
+
getFlag<TKey extends TypedFlagKey>(key: TKey): TypedFlags[TKey];
|
|
363
|
+
/**
|
|
364
|
+
* Get remotely evaluated flag for the user/company/other context bound to this client.
|
|
365
|
+
*
|
|
366
|
+
* @returns Flags for the given user/company and whether each one is enabled or not
|
|
367
|
+
*/
|
|
368
|
+
getFlagsRemote(): Promise<Record<string, import("./types").Flag<import("./types").EmptyFlagRemoteConfig>>>;
|
|
369
|
+
/**
|
|
370
|
+
* Get remotely evaluated flag for the user/company/other context bound to this client.
|
|
371
|
+
*
|
|
372
|
+
* @param key - The key of the flag to get.
|
|
373
|
+
*
|
|
374
|
+
* @returns Flag for the given user/company and key and whether it's enabled or not
|
|
375
|
+
*/
|
|
376
|
+
getFlagRemote(key: string): Promise<import("./types").Flag<import("./types").EmptyFlagRemoteConfig>>;
|
|
377
|
+
/**
|
|
378
|
+
* Track an event in Reflag.
|
|
379
|
+
*
|
|
380
|
+
* @param event - The event to track.
|
|
381
|
+
* @param options - The options for the event.
|
|
382
|
+
* @param options.attributes - The attributes of the event (optional).
|
|
383
|
+
* @param options.meta - The meta context associated with tracking (optional).
|
|
384
|
+
* @param options.companyId - Optional company ID for the event (optional).
|
|
385
|
+
*
|
|
386
|
+
* @throws An error if the event is invalid or the options are invalid.
|
|
387
|
+
*/
|
|
388
|
+
track(event: string, options?: TrackOptions & {
|
|
389
|
+
companyId?: string;
|
|
390
|
+
}): Promise<void>;
|
|
391
|
+
/**
|
|
392
|
+
* Create a new client bound with the additional context.
|
|
393
|
+
* Note: This performs a shallow merge for user/company/other individually.
|
|
394
|
+
*
|
|
395
|
+
* @param context - The context to bind the client to.
|
|
396
|
+
* @param context.user - The user to bind the client to.
|
|
397
|
+
* @param context.company - The company to bind the client to.
|
|
398
|
+
* @param context.other - The other context to bind the client to.
|
|
399
|
+
* @param context.enableTracking - Whether to enable tracking for the client.
|
|
400
|
+
* @param context.meta - The meta context to bind the client to.
|
|
401
|
+
*
|
|
402
|
+
* @returns new client bound with the additional context
|
|
403
|
+
*/
|
|
404
|
+
bindClient({ user, company, other, enableTracking, meta, }: ContextWithTracking): BoundReflagClient;
|
|
405
|
+
/**
|
|
406
|
+
* Flushes the batch buffer.
|
|
407
|
+
*/
|
|
408
|
+
flush(): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAIV,cAAc,EACd,aAAa,EACb,eAAe,EACf,MAAM,EAEN,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAGL,aAAa,EACb,OAAO,EACP,mBAAmB,EAGnB,UAAU,EACV,MAAM,EAEN,YAAY,EACZ,UAAU,EACX,MAAM,SAAS,CAAC;AAoDjB;;;;;;;;;;;;;;;;;;IAkBI;AACJ,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAab;IACF,UAAU,EAAE,UAAU,CAAC;IAEvB,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,WAAW,CAAoC;IAEvD;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,WAAW,CAYhB;IAEH;;;;;;;;;;;;;;;;;;;;QAoBI;gBACQ,OAAO,GAAE,aAAkB;IAwMvC;;;;;;;;;;;;;;;;QAgBI;IACJ,IAAI,aAAa,CAAC,SAAS,EAAE,eAAe,GAAG,aAAa,EAM3D;IAED;;;;;;;;;;;;QAYI;IACJ,kBAAkB;IAIlB;;;;;;;;;;;;;;;;;;QAkBI;IACG,UAAU,CAAC,EAChB,cAAqB,EACrB,GAAG,OAAO,EACX,EAAE,mBAAmB;IAItB;;;;;;;;;;;;QAYI;IACS,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAuB9D;;;;;;;;;;;;;QAaI;IACS,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,YAAY,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAA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