@datadog/flagging-core 0.1.0-alpha.7 → 0.1.0-alpha.8

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,46 @@
1
+ import type { EvaluationContext, FlagValueType, JsonValue, ResolutionReason } from '@openfeature/web-sdk';
2
+ /**
3
+ * Internal configuration for DatadogProvider.
4
+ */
5
+ export type Configuration = {
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,EACV,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAE7B;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;I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-0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/configuration/configuration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './configuration';
2
+ export * from './wire';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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 { Configuration } from './configuration';
2
+ /**
3
+ * Create configuration from a string created with `configurationToString`.
4
+ */
5
+ export declare function configurationFromString(s: string): Configuration;
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: Configuration): 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,aAAa,EAAiB,MAAM,iBAAiB,CAAA;AAWnE;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,aAAa,CAqBhE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAa1E"}
@@ -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,GAAkB,EAAE,CAAA;QACvC,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,aAA4B;IAChE,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,2 @@
1
+ export * from './configuration';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -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.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "Runtime-agnostic flag-evaluation logic for Datadog Flagging",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,9 +12,6 @@
12
12
  "access": "public",
13
13
  "registry": "https://registry.npmjs.org/"
14
14
  },
15
- "files": [
16
- "dist"
17
- ],
18
15
  "main": "cjs/index.js",
19
16
  "module": "esm/index.js",
20
17
  "types": "cjs/index.d.ts",
@@ -0,0 +1,57 @@
1
+ import type {
2
+ EvaluationContext,
3
+ FlagValueType,
4
+ JsonValue,
5
+ ResolutionReason,
6
+ } from '@openfeature/web-sdk'
7
+
8
+ /**
9
+ * Internal configuration for DatadogProvider.
10
+ */
11
+ export type Configuration = {
12
+ /** @internal */
13
+ precomputed?: PrecomputedConfiguration
14
+ }
15
+
16
+ /** @internal */
17
+ export type PrecomputedConfiguration = {
18
+ response: PrecomputedConfigurationResponse
19
+ context?: EvaluationContext
20
+ fetchedAt?: UnixTimestamp
21
+ }
22
+
23
+ // Fancy way to map FlagValueType to expected FlagValue.
24
+ /** @internal */
25
+ export type FlagTypeToValue<T extends FlagValueType> = {
26
+ ['boolean']: boolean
27
+ ['string']: string
28
+ ['number']: number
29
+ ['object']: JsonValue
30
+ }[T]
31
+
32
+ /** @internal
33
+ * Timestamp in milliseconds since Unix Epoch.
34
+ */
35
+ export type UnixTimestamp = number
36
+
37
+ /** @internal */
38
+ export type PrecomputedConfigurationResponse = {
39
+ data: {
40
+ attributes: {
41
+ /** When configuration was generated. */
42
+ createdAt: number
43
+ flags: Record<string, PrecomputedFlag>
44
+ }
45
+ }
46
+ }
47
+
48
+ /** @internal */
49
+ export type PrecomputedFlag<T extends FlagValueType = FlagValueType> = {
50
+ allocationKey: string
51
+ variationKey: string
52
+ variationType: T
53
+ variationValue: FlagTypeToValue<T>
54
+ reason: ResolutionReason
55
+ doLog: boolean
56
+ extraLogging: Record<string, unknown>
57
+ }
@@ -0,0 +1,2 @@
1
+ export * from './configuration'
2
+ export * from './wire'
@@ -0,0 +1,58 @@
1
+ import type { EvaluationContext } from '@openfeature/web-sdk'
2
+
3
+ import type { Configuration, 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): Configuration {
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: Configuration = {}
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: Configuration): 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
+ }
@@ -0,0 +1,3 @@
1
+ // Build environment placeholders that will be replaced during build
2
+ declare const __BUILD_ENV__SDK_VERSION__: string
3
+ declare const __BUILD_ENV__SDK_SETUP__: string
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './configuration'
2
+
3
+ // Build environment placeholder for testing
4
+ const SDK_VERSION = __BUILD_ENV__SDK_VERSION__
@@ -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
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "types": ["jest", "node"]
5
+ },
6
+ "include": ["./src/**/*.spec.ts", "./src/**/*.test.ts"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1,10 @@
1
+ const path = require('path')
2
+
3
+ const webpackBase = require('../../webpack.base')
4
+
5
+ module.exports = (_env, argv) =>
6
+ webpackBase({
7
+ mode: argv.mode,
8
+ entry: path.resolve(__dirname, 'src/index.ts'),
9
+ filename: 'datadog-flagging-core.js',
10
+ })