@datadog/flagging-core 0.1.0-alpha.1 → 0.1.0-alpha.11
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/cjs/configuration/configuration.d.ts +46 -0
- package/cjs/configuration/configuration.d.ts.map +1 -0
- package/cjs/configuration/configuration.js +3 -0
- package/cjs/configuration/configuration.js.map +1 -0
- package/cjs/configuration/index.d.ts +3 -0
- package/cjs/configuration/index.d.ts.map +1 -0
- package/cjs/configuration/index.js +19 -0
- package/cjs/configuration/index.js.map +1 -0
- package/cjs/configuration/wire.d.ts +12 -0
- package/cjs/configuration/wire.d.ts.map +1 -0
- package/cjs/configuration/wire.js +45 -0
- package/cjs/configuration/wire.js.map +1 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +20 -0
- package/cjs/index.js.map +1 -0
- package/jest.config.js +15 -0
- package/package.json +17 -19
- package/src/configuration/configuration.ts +52 -0
- package/src/configuration/index.ts +2 -0
- package/src/configuration/wire.ts +58 -0
- package/src/global.d.ts +3 -0
- package/src/index.ts +4 -0
- package/tsconfig.cjs.json +13 -0
- package/tsconfig.esm.json +13 -0
- package/tsconfig.json +12 -0
- package/tsconfig.test.json +8 -0
- package/dist/index.d.mts +0 -59
- package/dist/index.d.ts +0 -59
- package/dist/index.js +0 -63
- package/dist/index.mjs +0 -35
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { EvaluationContext, FlagValueType, JsonValue, ResolutionReason } from '@openfeature/web-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Internal flags configuration for DatadogProvider.
|
|
4
|
+
*/
|
|
5
|
+
export type FlagsConfiguration = {
|
|
6
|
+
/** @internal */
|
|
7
|
+
precomputed?: PrecomputedConfiguration;
|
|
8
|
+
};
|
|
9
|
+
/** @internal */
|
|
10
|
+
export type PrecomputedConfiguration = {
|
|
11
|
+
response: PrecomputedConfigurationResponse;
|
|
12
|
+
context?: EvaluationContext;
|
|
13
|
+
fetchedAt?: UnixTimestamp;
|
|
14
|
+
};
|
|
15
|
+
/** @internal */
|
|
16
|
+
export type FlagTypeToValue<T extends FlagValueType> = {
|
|
17
|
+
['boolean']: boolean;
|
|
18
|
+
['string']: string;
|
|
19
|
+
['number']: number;
|
|
20
|
+
['object']: JsonValue;
|
|
21
|
+
}[T];
|
|
22
|
+
/** @internal
|
|
23
|
+
* Timestamp in milliseconds since Unix Epoch.
|
|
24
|
+
*/
|
|
25
|
+
export type UnixTimestamp = number;
|
|
26
|
+
/** @internal */
|
|
27
|
+
export type PrecomputedConfigurationResponse = {
|
|
28
|
+
data: {
|
|
29
|
+
attributes: {
|
|
30
|
+
/** When configuration was generated. */
|
|
31
|
+
createdAt: number;
|
|
32
|
+
flags: Record<string, PrecomputedFlag>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** @internal */
|
|
37
|
+
export type PrecomputedFlag<T extends FlagValueType = FlagValueType> = {
|
|
38
|
+
allocationKey: string;
|
|
39
|
+
variationKey: string;
|
|
40
|
+
variationType: T;
|
|
41
|
+
variationValue: FlagTypeToValue<T>;
|
|
42
|
+
reason: ResolutionReason;
|
|
43
|
+
doLog: boolean;
|
|
44
|
+
extraLogging: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEzG;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB;IAChB,WAAW,CAAC,EAAE,wBAAwB,CAAA;CACvC,CAAA;AAED,gBAAgB;AAChB,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,gCAAgC,CAAA;IAC1C,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,SAAS,CAAC,EAAE,aAAa,CAAA;CAC1B,CAAA;AAGD,gBAAgB;AAChB,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,aAAa,IAAI;IACrD,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IACpB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAClB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAClB,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CACtB,CAAC,CAAC,CAAC,CAAA;AAEJ;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAElC,gBAAgB;AAChB,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE;QACJ,UAAU,EAAE;YACV,wCAAwC;YACxC,SAAS,EAAE,MAAM,CAAA;YACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;SACvC,CAAA;KACF,CAAA;CACF,CAAA;AAED,gBAAgB;AAChB,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI;IACrE,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,CAAC,CAAA;IAChB,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IAClC,MAAM,EAAE,gBAAgB,CAAA;IACxB,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACtC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/configuration/configuration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./configuration"), exports);
|
|
18
|
+
__exportStar(require("./wire"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,yCAAsB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlagsConfiguration } from './configuration';
|
|
2
|
+
/**
|
|
3
|
+
* Create configuration from a string created with `configurationToString`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function configurationFromString(s: string): FlagsConfiguration;
|
|
6
|
+
/**
|
|
7
|
+
* Serialize configuration to string that can be deserialized with
|
|
8
|
+
* `configurationFromString`. The serialized string format is
|
|
9
|
+
* unspecified.
|
|
10
|
+
*/
|
|
11
|
+
export declare function configurationToString(configuration: FlagsConfiguration): string;
|
|
12
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../src/configuration/wire.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAA;AAWxE;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAqBrE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAa/E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configurationFromString = configurationFromString;
|
|
4
|
+
exports.configurationToString = configurationToString;
|
|
5
|
+
/**
|
|
6
|
+
* Create configuration from a string created with `configurationToString`.
|
|
7
|
+
*/
|
|
8
|
+
function configurationFromString(s) {
|
|
9
|
+
try {
|
|
10
|
+
const wire = JSON.parse(s);
|
|
11
|
+
if (wire.version !== 1) {
|
|
12
|
+
// Unknown version
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const configuration = {};
|
|
16
|
+
if (wire.precomputed) {
|
|
17
|
+
configuration.precomputed = {
|
|
18
|
+
...wire.precomputed,
|
|
19
|
+
response: JSON.parse(wire.precomputed.response),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return configuration;
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serialize configuration to string that can be deserialized with
|
|
30
|
+
* `configurationFromString`. The serialized string format is
|
|
31
|
+
* unspecified.
|
|
32
|
+
*/
|
|
33
|
+
function configurationToString(configuration) {
|
|
34
|
+
const wire = {
|
|
35
|
+
version: 1,
|
|
36
|
+
};
|
|
37
|
+
if (configuration.precomputed) {
|
|
38
|
+
wire.precomputed = {
|
|
39
|
+
...configuration.precomputed,
|
|
40
|
+
response: JSON.stringify(configuration.precomputed),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(wire);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=wire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/configuration/wire.ts"],"names":[],"mappings":";;AAgBA,0DAqBC;AAOD,sDAaC;AA5CD;;GAEG;AACH,SAAgB,uBAAuB,CAAC,CAAS;IAC/C,IAAI,CAAC;QACH,MAAM,IAAI,GAAsB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAE7C,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;YACvB,kBAAkB;YAClB,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,aAAa,GAAuB,EAAE,CAAA;QAC5C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,aAAa,CAAC,WAAW,GAAG;gBAC1B,GAAG,IAAI,CAAC,WAAW;gBACnB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;aAChD,CAAA;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,aAAiC;IACrE,MAAM,IAAI,GAAsB;QAC9B,OAAO,EAAE,CAAC;KACX,CAAA;IAED,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,aAAa,CAAC,WAAW;YAC5B,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC;SACpD,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC"}
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./configuration"), exports);
|
|
18
|
+
// Build environment placeholder for testing
|
|
19
|
+
const SDK_VERSION = "dev";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAE/B,4CAA4C;AAC5C,MAAM,WAAW,GAAG,0BAA0B,CAAA"}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.ts$': [
|
|
6
|
+
'ts-jest',
|
|
7
|
+
{
|
|
8
|
+
tsconfig: 'tsconfig.test.json',
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
},
|
|
12
|
+
testMatch: ['**/*.spec.ts', '**/*.test.ts'],
|
|
13
|
+
moduleFileExtensions: ['ts', 'js', 'json'],
|
|
14
|
+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/flagging-core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"description": "Runtime-agnostic flag-evaluation logic for Datadog Flagging",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,37 +9,35 @@
|
|
|
9
9
|
"directory": "packages/core"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
|
-
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
17
|
-
"main": "./dist/index.js",
|
|
18
|
-
"module": "./dist/index.mjs",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
|
-
"exports": {
|
|
21
|
-
".": {
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
|
-
"import": "./dist/index.mjs",
|
|
24
|
-
"require": "./dist/index.js"
|
|
25
|
-
}
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
14
|
},
|
|
15
|
+
"main": "cjs/index.js",
|
|
16
|
+
"module": "esm/index.js",
|
|
17
|
+
"types": "cjs/index.d.ts",
|
|
27
18
|
"scripts": {
|
|
28
|
-
"build": "tsup src/index.ts --dts --format cjs,esm",
|
|
29
19
|
"prepack": "yarn build",
|
|
30
|
-
"
|
|
20
|
+
"pack": "yarn pack",
|
|
21
|
+
"build": "run-p build:cjs build:esm",
|
|
22
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
|
|
23
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
|
|
24
|
+
"replace-build-env": "node ../../scripts/build/replace-build-env.js",
|
|
25
|
+
"clean": "rm -rf dist cjs esm",
|
|
31
26
|
"test": "jest --passWithNoTests",
|
|
32
27
|
"typecheck": "tsc --noEmit"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
30
|
+
"@openfeature/core": "^1.8.1",
|
|
31
|
+
"@openfeature/web-sdk": "^1.5.0",
|
|
35
32
|
"@types/jest": "^29.4.0",
|
|
36
33
|
"@types/node": "^20.0.0",
|
|
37
34
|
"jest": "^30.0.4",
|
|
35
|
+
"npm-run-all": "^4.1.5",
|
|
38
36
|
"ts-jest": "^29.4.0",
|
|
39
|
-
"
|
|
37
|
+
"ts-loader": "^9.5.2",
|
|
40
38
|
"typescript": "^5.5.0"
|
|
41
39
|
},
|
|
42
|
-
"
|
|
40
|
+
"peerDependencies": {
|
|
43
41
|
"@openfeature/core": "^1.8.1",
|
|
44
42
|
"@openfeature/web-sdk": "^1.5.0"
|
|
45
43
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { EvaluationContext, FlagValueType, JsonValue, ResolutionReason } from '@openfeature/web-sdk'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal flags configuration for DatadogProvider.
|
|
5
|
+
*/
|
|
6
|
+
export type FlagsConfiguration = {
|
|
7
|
+
/** @internal */
|
|
8
|
+
precomputed?: PrecomputedConfiguration
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export type PrecomputedConfiguration = {
|
|
13
|
+
response: PrecomputedConfigurationResponse
|
|
14
|
+
context?: EvaluationContext
|
|
15
|
+
fetchedAt?: UnixTimestamp
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Fancy way to map FlagValueType to expected FlagValue.
|
|
19
|
+
/** @internal */
|
|
20
|
+
export type FlagTypeToValue<T extends FlagValueType> = {
|
|
21
|
+
['boolean']: boolean
|
|
22
|
+
['string']: string
|
|
23
|
+
['number']: number
|
|
24
|
+
['object']: JsonValue
|
|
25
|
+
}[T]
|
|
26
|
+
|
|
27
|
+
/** @internal
|
|
28
|
+
* Timestamp in milliseconds since Unix Epoch.
|
|
29
|
+
*/
|
|
30
|
+
export type UnixTimestamp = number
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export type PrecomputedConfigurationResponse = {
|
|
34
|
+
data: {
|
|
35
|
+
attributes: {
|
|
36
|
+
/** When configuration was generated. */
|
|
37
|
+
createdAt: number
|
|
38
|
+
flags: Record<string, PrecomputedFlag>
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
export type PrecomputedFlag<T extends FlagValueType = FlagValueType> = {
|
|
45
|
+
allocationKey: string
|
|
46
|
+
variationKey: string
|
|
47
|
+
variationType: T
|
|
48
|
+
variationValue: FlagTypeToValue<T>
|
|
49
|
+
reason: ResolutionReason
|
|
50
|
+
doLog: boolean
|
|
51
|
+
extraLogging: Record<string, unknown>
|
|
52
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { EvaluationContext } from '@openfeature/web-sdk'
|
|
2
|
+
|
|
3
|
+
import type { FlagsConfiguration, UnixTimestamp } from './configuration'
|
|
4
|
+
|
|
5
|
+
type ConfigurationWire = {
|
|
6
|
+
version: 1
|
|
7
|
+
precomputed?: {
|
|
8
|
+
context?: EvaluationContext
|
|
9
|
+
response: string
|
|
10
|
+
fetchedAt?: UnixTimestamp
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create configuration from a string created with `configurationToString`.
|
|
16
|
+
*/
|
|
17
|
+
export function configurationFromString(s: string): FlagsConfiguration {
|
|
18
|
+
try {
|
|
19
|
+
const wire: ConfigurationWire = JSON.parse(s)
|
|
20
|
+
|
|
21
|
+
if (wire.version !== 1) {
|
|
22
|
+
// Unknown version
|
|
23
|
+
return {}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const configuration: FlagsConfiguration = {}
|
|
27
|
+
if (wire.precomputed) {
|
|
28
|
+
configuration.precomputed = {
|
|
29
|
+
...wire.precomputed,
|
|
30
|
+
response: JSON.parse(wire.precomputed.response),
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return configuration
|
|
35
|
+
} catch {
|
|
36
|
+
return {}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Serialize configuration to string that can be deserialized with
|
|
42
|
+
* `configurationFromString`. The serialized string format is
|
|
43
|
+
* unspecified.
|
|
44
|
+
*/
|
|
45
|
+
export function configurationToString(configuration: FlagsConfiguration): string {
|
|
46
|
+
const wire: ConfigurationWire = {
|
|
47
|
+
version: 1,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (configuration.precomputed) {
|
|
51
|
+
wire.precomputed = {
|
|
52
|
+
...configuration.precomputed,
|
|
53
|
+
response: JSON.stringify(configuration.precomputed),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return JSON.stringify(wire)
|
|
58
|
+
}
|
package/src/global.d.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"target": "es2018",
|
|
6
|
+
"outDir": "cjs",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*"],
|
|
12
|
+
"exclude": ["**/*.test.ts", "**/*.spec.ts", "test/**/*"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "es2020",
|
|
5
|
+
"target": "es2018",
|
|
6
|
+
"outDir": "esm",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*"],
|
|
12
|
+
"exclude": ["**/*.test.ts", "**/*.spec.ts", "test/**/*"]
|
|
13
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"rootDir": "./src/",
|
|
7
|
+
"outDir": "./dist/",
|
|
8
|
+
"types": ["jest", "node"]
|
|
9
|
+
},
|
|
10
|
+
"include": ["./src/**/*.ts", "./src/**/*.d.ts"],
|
|
11
|
+
"exclude": ["./src/**/*.spec.ts", "./src/**/*.specHelper.ts"]
|
|
12
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { FlagValueType, JsonValue, ResolutionReason, EvaluationContext } from '@openfeature/web-sdk';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Internal configuration for DatadogProvider.
|
|
5
|
-
*/
|
|
6
|
-
type Configuration = {
|
|
7
|
-
/** @internal */
|
|
8
|
-
precomputed?: PrecomputedConfiguration;
|
|
9
|
-
};
|
|
10
|
-
/** @internal */
|
|
11
|
-
type PrecomputedConfiguration = {
|
|
12
|
-
response: PrecomputedConfigurationResponse;
|
|
13
|
-
context?: EvaluationContext;
|
|
14
|
-
fetchedAt?: UnixTimestamp;
|
|
15
|
-
};
|
|
16
|
-
/** @internal */
|
|
17
|
-
type FlagTypeToValue<T extends FlagValueType> = {
|
|
18
|
-
['boolean']: boolean;
|
|
19
|
-
['string']: string;
|
|
20
|
-
['number']: number;
|
|
21
|
-
['object']: JsonValue;
|
|
22
|
-
}[T];
|
|
23
|
-
/** @internal
|
|
24
|
-
* Timestamp in milliseconds since Unix Epoch.
|
|
25
|
-
*/
|
|
26
|
-
type UnixTimestamp = number;
|
|
27
|
-
/** @internal */
|
|
28
|
-
type PrecomputedConfigurationResponse = {
|
|
29
|
-
data: {
|
|
30
|
-
attributes: {
|
|
31
|
-
/** When configuration was generated. */
|
|
32
|
-
createdAt: number;
|
|
33
|
-
flags: Record<string, PrecomputedFlag>;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/** @internal */
|
|
38
|
-
type PrecomputedFlag<T extends FlagValueType = FlagValueType> = {
|
|
39
|
-
allocationKey: string;
|
|
40
|
-
variationKey: string;
|
|
41
|
-
variationType: T;
|
|
42
|
-
variationValue: FlagTypeToValue<T>;
|
|
43
|
-
reason: ResolutionReason;
|
|
44
|
-
doLog: boolean;
|
|
45
|
-
extraLogging: Record<string, unknown>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Create configuration from a string created with `configurationToString`.
|
|
50
|
-
*/
|
|
51
|
-
declare function configurationFromString(s: string): Configuration;
|
|
52
|
-
/**
|
|
53
|
-
* Serialize configuration to string that can be deserialized with
|
|
54
|
-
* `configurationFromString`. The serialized string format is
|
|
55
|
-
* unspecified.
|
|
56
|
-
*/
|
|
57
|
-
declare function configurationToString(configuration: Configuration): string;
|
|
58
|
-
|
|
59
|
-
export { type Configuration, type FlagTypeToValue, type PrecomputedConfiguration, type PrecomputedConfigurationResponse, type PrecomputedFlag, type UnixTimestamp, configurationFromString, configurationToString };
|
package/dist/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { FlagValueType, JsonValue, ResolutionReason, EvaluationContext } from '@openfeature/web-sdk';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Internal configuration for DatadogProvider.
|
|
5
|
-
*/
|
|
6
|
-
type Configuration = {
|
|
7
|
-
/** @internal */
|
|
8
|
-
precomputed?: PrecomputedConfiguration;
|
|
9
|
-
};
|
|
10
|
-
/** @internal */
|
|
11
|
-
type PrecomputedConfiguration = {
|
|
12
|
-
response: PrecomputedConfigurationResponse;
|
|
13
|
-
context?: EvaluationContext;
|
|
14
|
-
fetchedAt?: UnixTimestamp;
|
|
15
|
-
};
|
|
16
|
-
/** @internal */
|
|
17
|
-
type FlagTypeToValue<T extends FlagValueType> = {
|
|
18
|
-
['boolean']: boolean;
|
|
19
|
-
['string']: string;
|
|
20
|
-
['number']: number;
|
|
21
|
-
['object']: JsonValue;
|
|
22
|
-
}[T];
|
|
23
|
-
/** @internal
|
|
24
|
-
* Timestamp in milliseconds since Unix Epoch.
|
|
25
|
-
*/
|
|
26
|
-
type UnixTimestamp = number;
|
|
27
|
-
/** @internal */
|
|
28
|
-
type PrecomputedConfigurationResponse = {
|
|
29
|
-
data: {
|
|
30
|
-
attributes: {
|
|
31
|
-
/** When configuration was generated. */
|
|
32
|
-
createdAt: number;
|
|
33
|
-
flags: Record<string, PrecomputedFlag>;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/** @internal */
|
|
38
|
-
type PrecomputedFlag<T extends FlagValueType = FlagValueType> = {
|
|
39
|
-
allocationKey: string;
|
|
40
|
-
variationKey: string;
|
|
41
|
-
variationType: T;
|
|
42
|
-
variationValue: FlagTypeToValue<T>;
|
|
43
|
-
reason: ResolutionReason;
|
|
44
|
-
doLog: boolean;
|
|
45
|
-
extraLogging: Record<string, unknown>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Create configuration from a string created with `configurationToString`.
|
|
50
|
-
*/
|
|
51
|
-
declare function configurationFromString(s: string): Configuration;
|
|
52
|
-
/**
|
|
53
|
-
* Serialize configuration to string that can be deserialized with
|
|
54
|
-
* `configurationFromString`. The serialized string format is
|
|
55
|
-
* unspecified.
|
|
56
|
-
*/
|
|
57
|
-
declare function configurationToString(configuration: Configuration): string;
|
|
58
|
-
|
|
59
|
-
export { type Configuration, type FlagTypeToValue, type PrecomputedConfiguration, type PrecomputedConfigurationResponse, type PrecomputedFlag, type UnixTimestamp, configurationFromString, configurationToString };
|
package/dist/index.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
configurationFromString: () => configurationFromString,
|
|
24
|
-
configurationToString: () => configurationToString
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
// src/configuration/wire.ts
|
|
29
|
-
function configurationFromString(s) {
|
|
30
|
-
try {
|
|
31
|
-
const wire = JSON.parse(s);
|
|
32
|
-
if (wire.version !== 1) {
|
|
33
|
-
return {};
|
|
34
|
-
}
|
|
35
|
-
const configuration = {};
|
|
36
|
-
if (wire.precomputed) {
|
|
37
|
-
configuration.precomputed = {
|
|
38
|
-
...wire.precomputed,
|
|
39
|
-
response: JSON.parse(wire.precomputed.response)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return configuration;
|
|
43
|
-
} catch (e) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function configurationToString(configuration) {
|
|
48
|
-
const wire = {
|
|
49
|
-
version: 1
|
|
50
|
-
};
|
|
51
|
-
if (configuration.precomputed) {
|
|
52
|
-
wire.precomputed = {
|
|
53
|
-
...configuration.precomputed,
|
|
54
|
-
response: JSON.stringify(configuration.precomputed)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return JSON.stringify(wire);
|
|
58
|
-
}
|
|
59
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
-
0 && (module.exports = {
|
|
61
|
-
configurationFromString,
|
|
62
|
-
configurationToString
|
|
63
|
-
});
|
package/dist/index.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// src/configuration/wire.ts
|
|
2
|
-
function configurationFromString(s) {
|
|
3
|
-
try {
|
|
4
|
-
const wire = JSON.parse(s);
|
|
5
|
-
if (wire.version !== 1) {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
const configuration = {};
|
|
9
|
-
if (wire.precomputed) {
|
|
10
|
-
configuration.precomputed = {
|
|
11
|
-
...wire.precomputed,
|
|
12
|
-
response: JSON.parse(wire.precomputed.response)
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return configuration;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function configurationToString(configuration) {
|
|
21
|
-
const wire = {
|
|
22
|
-
version: 1
|
|
23
|
-
};
|
|
24
|
-
if (configuration.precomputed) {
|
|
25
|
-
wire.precomputed = {
|
|
26
|
-
...configuration.precomputed,
|
|
27
|
-
response: JSON.stringify(configuration.precomputed)
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return JSON.stringify(wire);
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
configurationFromString,
|
|
34
|
-
configurationToString
|
|
35
|
-
};
|