@metamask-previews/remote-feature-flag-controller 6.1.1-preview-abca9bcea → 7.0.0-preview-0a30e47

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 (96) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/client-config-api-service/{abstract-client-config-api-service.d.mts → abstract-client-config-api-service.d.ts} +3 -3
  3. package/dist/client-config-api-service/abstract-client-config-api-service.d.ts.map +1 -0
  4. package/dist/client-config-api-service/abstract-client-config-api-service.js +2 -0
  5. package/dist/client-config-api-service/abstract-client-config-api-service.js.map +1 -0
  6. package/dist/client-config-api-service/{client-config-api-service.d.cts → client-config-api-service.d.ts} +5 -5
  7. package/dist/client-config-api-service/client-config-api-service.d.ts.map +1 -0
  8. package/dist/client-config-api-service/client-config-api-service.js +86 -0
  9. package/dist/client-config-api-service/client-config-api-service.js.map +1 -0
  10. package/dist/{constants.d.cts → constants.d.ts} +1 -1
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/{constants.mjs → constants.js} +1 -1
  13. package/dist/constants.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +5 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/{remote-feature-flag-controller-method-action-types.d.cts → remote-feature-flag-controller-method-action-types.d.ts} +2 -2
  19. package/dist/remote-feature-flag-controller-method-action-types.d.ts.map +1 -0
  20. package/dist/{remote-feature-flag-controller-method-action-types.mjs → remote-feature-flag-controller-method-action-types.js} +1 -1
  21. package/dist/remote-feature-flag-controller-method-action-types.js.map +1 -0
  22. package/dist/{remote-feature-flag-controller-types.d.mts → remote-feature-flag-controller-types.d.ts} +2 -2
  23. package/dist/remote-feature-flag-controller-types.d.ts.map +1 -0
  24. package/dist/{remote-feature-flag-controller-types.mjs → remote-feature-flag-controller-types.js} +1 -1
  25. package/dist/remote-feature-flag-controller-types.js.map +1 -0
  26. package/dist/{remote-feature-flag-controller.d.cts → remote-feature-flag-controller.d.ts} +8 -8
  27. package/dist/remote-feature-flag-controller.d.ts.map +1 -0
  28. package/dist/remote-feature-flag-controller.js +470 -0
  29. package/dist/{remote-feature-flag-controller.cjs.map → remote-feature-flag-controller.js.map} +1 -1
  30. package/dist/utils/{user-segmentation-utils.d.cts → user-segmentation-utils.d.ts} +3 -3
  31. package/dist/utils/user-segmentation-utils.d.ts.map +1 -0
  32. package/dist/utils/{user-segmentation-utils.mjs → user-segmentation-utils.js} +5 -5
  33. package/dist/utils/user-segmentation-utils.js.map +1 -0
  34. package/dist/utils/{version.d.cts → version.d.ts} +4 -4
  35. package/dist/utils/version.d.ts.map +1 -0
  36. package/dist/utils/{version.mjs → version.js} +2 -2
  37. package/dist/utils/version.js.map +1 -0
  38. package/package.json +16 -20
  39. package/dist/client-config-api-service/abstract-client-config-api-service.cjs +0 -3
  40. package/dist/client-config-api-service/abstract-client-config-api-service.cjs.map +0 -1
  41. package/dist/client-config-api-service/abstract-client-config-api-service.d.cts +0 -17
  42. package/dist/client-config-api-service/abstract-client-config-api-service.d.cts.map +0 -1
  43. package/dist/client-config-api-service/abstract-client-config-api-service.d.mts.map +0 -1
  44. package/dist/client-config-api-service/abstract-client-config-api-service.mjs +0 -2
  45. package/dist/client-config-api-service/abstract-client-config-api-service.mjs.map +0 -1
  46. package/dist/client-config-api-service/client-config-api-service.cjs +0 -94
  47. package/dist/client-config-api-service/client-config-api-service.cjs.map +0 -1
  48. package/dist/client-config-api-service/client-config-api-service.d.cts.map +0 -1
  49. package/dist/client-config-api-service/client-config-api-service.d.mts +0 -108
  50. package/dist/client-config-api-service/client-config-api-service.d.mts.map +0 -1
  51. package/dist/client-config-api-service/client-config-api-service.mjs +0 -90
  52. package/dist/client-config-api-service/client-config-api-service.mjs.map +0 -1
  53. package/dist/constants.cjs +0 -8
  54. package/dist/constants.cjs.map +0 -1
  55. package/dist/constants.d.cts.map +0 -1
  56. package/dist/constants.d.mts +0 -5
  57. package/dist/constants.d.mts.map +0 -1
  58. package/dist/constants.mjs.map +0 -1
  59. package/dist/index.cjs +0 -15
  60. package/dist/index.cjs.map +0 -1
  61. package/dist/index.d.cts +0 -8
  62. package/dist/index.d.cts.map +0 -1
  63. package/dist/index.d.mts +0 -8
  64. package/dist/index.d.mts.map +0 -1
  65. package/dist/index.mjs +0 -5
  66. package/dist/index.mjs.map +0 -1
  67. package/dist/remote-feature-flag-controller-method-action-types.cjs +0 -7
  68. package/dist/remote-feature-flag-controller-method-action-types.cjs.map +0 -1
  69. package/dist/remote-feature-flag-controller-method-action-types.d.cts.map +0 -1
  70. package/dist/remote-feature-flag-controller-method-action-types.d.mts +0 -62
  71. package/dist/remote-feature-flag-controller-method-action-types.d.mts.map +0 -1
  72. package/dist/remote-feature-flag-controller-method-action-types.mjs.map +0 -1
  73. package/dist/remote-feature-flag-controller-types.cjs +0 -32
  74. package/dist/remote-feature-flag-controller-types.cjs.map +0 -1
  75. package/dist/remote-feature-flag-controller-types.d.cts +0 -64
  76. package/dist/remote-feature-flag-controller-types.d.cts.map +0 -1
  77. package/dist/remote-feature-flag-controller-types.d.mts.map +0 -1
  78. package/dist/remote-feature-flag-controller-types.mjs.map +0 -1
  79. package/dist/remote-feature-flag-controller.cjs +0 -453
  80. package/dist/remote-feature-flag-controller.d.cts.map +0 -1
  81. package/dist/remote-feature-flag-controller.d.mts +0 -113
  82. package/dist/remote-feature-flag-controller.d.mts.map +0 -1
  83. package/dist/remote-feature-flag-controller.mjs +0 -448
  84. package/dist/remote-feature-flag-controller.mjs.map +0 -1
  85. package/dist/utils/user-segmentation-utils.cjs +0 -107
  86. package/dist/utils/user-segmentation-utils.cjs.map +0 -1
  87. package/dist/utils/user-segmentation-utils.d.cts.map +0 -1
  88. package/dist/utils/user-segmentation-utils.d.mts +0 -34
  89. package/dist/utils/user-segmentation-utils.d.mts.map +0 -1
  90. package/dist/utils/user-segmentation-utils.mjs.map +0 -1
  91. package/dist/utils/version.cjs +0 -78
  92. package/dist/utils/version.cjs.map +0 -1
  93. package/dist/utils/version.d.cts.map +0 -1
  94. package/dist/utils/version.d.mts +0 -26
  95. package/dist/utils/version.d.mts.map +0 -1
  96. package/dist/utils/version.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { sha256, bytesToHex } from "@metamask/utils";
2
- import { validate as uuidValidate, version as uuidVersion } from "uuid";
1
+ import { sha256, bytesToHex } from '@metamask/utils';
2
+ import { validate as uuidValidate, version as uuidVersion } from 'uuid';
3
3
  /**
4
4
  * Converts a UUID string to a BigInt by removing dashes and converting to hexadecimal.
5
5
  *
@@ -40,7 +40,7 @@ export async function calculateThresholdForFlag(segmentationId, featureFlagName)
40
40
  const hashBigInt = BigInt(hash);
41
41
  const maxValue = BigInt(`0x${'f'.repeat(64)}`);
42
42
  // Use BigInt division first, then convert to number to maintain precision
43
- return Number((hashBigInt * BigInt(1000000)) / maxValue) / 1000000;
43
+ return Number((hashBigInt * BigInt(1_000_000)) / maxValue) / 1_000_000;
44
44
  }
45
45
  /**
46
46
  * Generates a deterministic random number between 0 and 1 based on a metaMetricsId.
@@ -84,7 +84,7 @@ export function generateDeterministicRandomNumber(metaMetricsId) {
84
84
  maxValue = BigInt(`0x${'f'.repeat(cleanId.length)}`);
85
85
  }
86
86
  // Use BigInt division first, then convert to number to maintain precision
87
- return Number((idValue * BigInt(1000000)) / maxValue) / 1000000;
87
+ return Number((idValue * BigInt(1_000_000)) / maxValue) / 1_000_000;
88
88
  }
89
89
  /**
90
90
  * Type guard to check if a value is a feature flag with scope.
@@ -98,4 +98,4 @@ export const isFeatureFlagWithScopeValue = (featureFlag) => {
98
98
  featureFlag !== null &&
99
99
  'scope' in featureFlag);
100
100
  };
101
- //# sourceMappingURL=user-segmentation-utils.mjs.map
101
+ //# sourceMappingURL=user-segmentation-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-segmentation-utils.js","sourceRoot":"","sources":["../../src/utils/user-segmentation-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAA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C,CAAC;QACxD,CAAC;QAED,OAAO,GAAG,MAAM,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;QACjC,QAAQ,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,0EAA0E;IAC1E,OAAO,MAAM,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,SAAS,CAAC;AACtE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,WAAiB,EACqB,EAAE;IACxC,OAAO,CACL,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,KAAK,IAAI;QACpB,OAAO,IAAI,WAAW,CACvB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { sha256, bytesToHex } from '@metamask/utils';\nimport { validate as uuidValidate, version as uuidVersion } from 'uuid';\n\nimport type { FeatureFlagScopeValue } from '../remote-feature-flag-controller-types.js';\n\n/**\n * Converts a UUID string to a BigInt by removing dashes and converting to hexadecimal.\n *\n * @param uuid - The UUID string to convert\n * @returns The UUID as a BigInt value\n */\nfunction uuidStringToBigInt(uuid: string): bigint {\n return BigInt(`0x${uuid.replace(/-/gu, '')}`);\n}\n\nconst MIN_UUID_V4 = '00000000-0000-4000-8000-000000000000';\nconst MAX_UUID_V4 = 'ffffffff-ffff-4fff-bfff-ffffffffffff';\nconst MIN_UUID_V4_BIGINT = uuidStringToBigInt(MIN_UUID_V4);\nconst MAX_UUID_V4_BIGINT = uuidStringToBigInt(MAX_UUID_V4);\nconst UUID_V4_VALUE_RANGE_BIGINT = MAX_UUID_V4_BIGINT - MIN_UUID_V4_BIGINT;\n\n/**\n * Calculates a deterministic threshold value between 0 and 1 for A/B testing.\n * This function hashes the segmentation ID combined with the feature flag name\n * to ensure consistent group assignment across sessions while varying across different flags.\n *\n * @param segmentationId - The identifier used for threshold segmentation (must be non-empty)\n * @param featureFlagName - The feature flag name to create unique threshold per flag\n * @returns A promise that resolves to a number between 0 and 1\n * @throws Error if segmentationId is empty\n */\nexport async function calculateThresholdForFlag(\n segmentationId: string,\n featureFlagName: string,\n): Promise<number> {\n if (!segmentationId) {\n throw new Error('Segmentation ID cannot be empty');\n }\n\n if (!featureFlagName) {\n throw new Error('Feature flag name cannot be empty');\n }\n\n const seed = segmentationId + featureFlagName;\n\n // Hash the combined seed\n const encoder = new TextEncoder();\n const hashBuffer = await sha256(encoder.encode(seed));\n\n // Convert hash bytes directly to 0-1 range\n const hash = bytesToHex(hashBuffer);\n const hashBigInt = BigInt(hash);\n const maxValue = BigInt(`0x${'f'.repeat(64)}`);\n\n // Use BigInt division first, then convert to number to maintain precision\n return Number((hashBigInt * BigInt(1_000_000)) / maxValue) / 1_000_000;\n}\n\n/**\n * Generates a deterministic random number between 0 and 1 based on a metaMetricsId.\n * This is useful for A/B testing and feature flag rollouts where we want\n * consistent group assignment for the same user.\n *\n * @param metaMetricsId - The unique identifier used to generate the deterministic random number. Must be either:\n * - A UUIDv4 string (e.g., '123e4567-e89b-12d3-a456-426614174000'\n * - A hex string with '0x' prefix (e.g., '0x86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d136420')\n * @returns A number between 0 and 1, deterministically generated from the input ID.\n * The same input will always produce the same output.\n */\nexport function generateDeterministicRandomNumber(\n metaMetricsId: string,\n): number {\n if (!metaMetricsId) {\n throw new Error('MetaMetrics ID cannot be empty');\n }\n\n let idValue: bigint;\n let maxValue: bigint;\n\n // uuidv4 format\n if (uuidValidate(metaMetricsId)) {\n if (uuidVersion(metaMetricsId) !== 4) {\n throw new Error(\n `Invalid UUID version. Expected v4, got v${uuidVersion(metaMetricsId)}`,\n );\n }\n idValue = uuidStringToBigInt(metaMetricsId) - MIN_UUID_V4_BIGINT;\n maxValue = UUID_V4_VALUE_RANGE_BIGINT;\n } else {\n // hex format with 0x prefix\n if (!metaMetricsId.startsWith('0x')) {\n throw new Error('Hex ID must start with 0x prefix');\n }\n\n const cleanId = metaMetricsId.slice(2);\n const EXPECTED_HEX_LENGTH = 64; // 32 bytes = 64 hex characters\n\n if (cleanId.length !== EXPECTED_HEX_LENGTH) {\n throw new Error(\n `Invalid hex ID length. Expected ${EXPECTED_HEX_LENGTH} characters, got ${cleanId.length}`,\n );\n }\n\n if (!/^[0-9a-f]+$/iu.test(cleanId)) {\n throw new Error('Hex ID contains invalid characters');\n }\n\n idValue = BigInt(`0x${cleanId}`);\n maxValue = BigInt(`0x${'f'.repeat(cleanId.length)}`);\n }\n\n // Use BigInt division first, then convert to number to maintain precision\n return Number((idValue * BigInt(1_000_000)) / maxValue) / 1_000_000;\n}\n\n/**\n * Type guard to check if a value is a feature flag with scope.\n * Used to validate feature flag objects that contain scope-based configurations.\n *\n * @param featureFlag - The value to check if it's a feature flag with scope\n * @returns True if the value is a feature flag with scope, false otherwise\n */\nexport const isFeatureFlagWithScopeValue = (\n featureFlag: Json,\n): featureFlag is FeatureFlagScopeValue => {\n return (\n typeof featureFlag === 'object' &&\n featureFlag !== null &&\n 'scope' in featureFlag\n );\n};\n"]}
@@ -1,11 +1,11 @@
1
- import type { Json, SemVerVersion } from "@metamask/utils";
2
- import type { MultiVersionFeatureFlagValue } from "../remote-feature-flag-controller-types.cjs";
1
+ import type { Json, SemVerVersion } from '@metamask/utils';
2
+ import type { MultiVersionFeatureFlagValue } from '../remote-feature-flag-controller-types.js';
3
3
  /**
4
4
  * Constants for MultiVersionFeatureFlagValue property names
5
5
  * to ensure consistency across validation, type checking, and other usage.
6
6
  */
7
7
  export declare const MULTI_VERSION_FLAG_KEYS: {
8
- readonly VERSIONS: "versions";
8
+ readonly VERSIONS: 'versions';
9
9
  };
10
10
  /**
11
11
  * Checks if a feature flag value is a multi-version gated flag (contains versions object with valid SemVer keys).
@@ -23,4 +23,4 @@ export declare function isVersionFeatureFlag(value: Json): value is MultiVersion
23
23
  * @returns The selected version value, or null if no version requirements are met
24
24
  */
25
25
  export declare function getVersionData(multiVersionFlag: MultiVersionFeatureFlagValue, currentAppVersion: SemVerVersion): Json | null;
26
- //# sourceMappingURL=version.d.cts.map
26
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,uBAAuB;aAClC,QAAQ,EAAE,UAAU;CACZ,CAAC;AAEX;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,IAAI,GACV,KAAK,IAAI,4BAA4B,CAuBvC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,gBAAgB,EAAE,4BAA4B,EAC9C,iBAAiB,EAAE,aAAa,GAC/B,IAAI,GAAG,IAAI,CAcb"}
@@ -1,4 +1,4 @@
1
- import { gtVersion, isValidSemVerVersion } from "@metamask/utils";
1
+ import { gtVersion, isValidSemVerVersion } from '@metamask/utils';
2
2
  /**
3
3
  * Constants for MultiVersionFeatureFlagValue property names
4
4
  * to ensure consistency across validation, type checking, and other usage.
@@ -70,4 +70,4 @@ function getObjectEntries(input) {
70
70
  // Use cast to preserve index type. Object.entries always widens to string.
71
71
  return Object.entries(input);
72
72
  }
73
- //# sourceMappingURL=version.mjs.map
73
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAKlE;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,QAAQ,EAAE,U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ACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,gBAAgB,CACvB,cAA6B,EAC7B,eAA8B;IAE9B,OAAO,CACL,cAAc,KAAK,eAAe;QAClC,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC,CAC3C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAAY;IAEZ,2EAA2E;IAC3E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAwC,CAAC;AACtE,CAAC","sourcesContent":["import { gtVersion, isValidSemVerVersion } from '@metamask/utils';\nimport type { Json, SemVerVersion } from '@metamask/utils';\n\nimport type { MultiVersionFeatureFlagValue } from '../remote-feature-flag-controller-types.js';\n\n/**\n * Constants for MultiVersionFeatureFlagValue property names\n * to ensure consistency across validation, type checking, and other usage.\n */\nexport const MULTI_VERSION_FLAG_KEYS = {\n VERSIONS: 'versions',\n} as const;\n\n/**\n * Checks if a feature flag value is a multi-version gated flag (contains versions object with valid SemVer keys).\n *\n * @param value - The feature flag value to check\n * @returns true if the value is a multi-version feature flag with valid SemVer version keys, false otherwise\n */\nexport function isVersionFeatureFlag(\n value: Json,\n): value is MultiVersionFeatureFlagValue {\n if (\n typeof value !== 'object' ||\n value === null ||\n Array.isArray(value) ||\n !(MULTI_VERSION_FLAG_KEYS.VERSIONS in value)\n ) {\n return false;\n }\n\n const versions = value[MULTI_VERSION_FLAG_KEYS.VERSIONS];\n\n if (\n typeof versions !== 'object' ||\n versions === null ||\n Array.isArray(versions)\n ) {\n return false;\n }\n\n // Validate that all version keys are valid SemVer versions\n const versionKeys = Object.keys(versions);\n return versionKeys.every((versionKey) => isValidSemVerVersion(versionKey));\n}\n\n/**\n * Selects the appropriate version value from a multi-version feature flag based on current app version.\n * Returns the value from the highest version that the app version meets or exceeds.\n *\n * @param multiVersionFlag - The multi-version feature flag\n * @param currentAppVersion - The current application version\n * @returns The selected version value, or null if no version requirements are met\n */\nexport function getVersionData(\n multiVersionFlag: MultiVersionFeatureFlagValue,\n currentAppVersion: SemVerVersion,\n): Json | null {\n const sortedVersions = getObjectEntries(multiVersionFlag.versions).sort(\n ([versionA], [versionB]) => {\n return isVersionAtLeast(versionA, versionB) ? -1 : 1;\n },\n );\n\n for (const [version, data] of sortedVersions) {\n if (isVersionAtLeast(currentAppVersion, version)) {\n return data;\n }\n }\n\n return null;\n}\n\n/**\n * Compares two semantic version strings.\n * Both versions are expected to be valid SemVer format (e.g., \"13.9.5\").\n *\n * @param currentVersion - The current version (e.g., \"13.9.5\")\n * @param requiredVersion - The required minimum version (e.g., \"13.10.0\")\n * @returns true if currentVersion >= requiredVersion, false otherwise\n */\nfunction isVersionAtLeast(\n currentVersion: SemVerVersion,\n requiredVersion: SemVerVersion,\n): boolean {\n return (\n currentVersion === requiredVersion ||\n gtVersion(currentVersion, requiredVersion)\n );\n}\n\n/**\n * A utility function that calls `Object.entries` while preserving the index type.\n *\n * @param input - The object to get the entries of.\n * @returns - The object entries.\n */\nfunction getObjectEntries<Input extends Record<string, unknown>>(\n input: Input,\n): [keyof Input, Input[keyof Input]][] {\n // Use cast to preserve index type. Object.entries always widens to string.\n return Object.entries(input) as [keyof Input, Input[keyof Input]][];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/remote-feature-flag-controller",
3
- "version": "6.1.1-preview-abca9bcea",
3
+ "version": "7.0.0-preview-0a30e47",
4
4
  "description": "The RemoteFeatureFlagController manages the retrieval and caching of remote feature flags",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,9 +32,11 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/remote-feature-flag-controller",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/remote-feature-flag-controller",
47
42
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -55,27 +50,28 @@
55
50
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
56
51
  },
57
52
  "dependencies": {
58
- "@metamask/base-controller": "^9.1.0",
59
- "@metamask/controller-utils": "^12.3.0",
60
- "@metamask/messenger": "^2.0.0",
53
+ "@metamask/base-controller": "^10.0.0",
54
+ "@metamask/controller-utils": "^13.0.0",
55
+ "@metamask/messenger": "^3.0.0",
61
56
  "@metamask/utils": "^11.12.0",
62
- "uuid": "^8.3.2"
57
+ "uuid": "^9.0.1"
63
58
  },
64
59
  "devDependencies": {
65
60
  "@lavamoat/allow-scripts": "^3.0.4",
66
61
  "@metamask/auto-changelog": "^6.1.0",
67
- "@ts-bridge/cli": "^0.6.4",
68
62
  "@types/jest": "^30.0.0",
63
+ "@typescript/native": "npm:typescript@^7.0.2",
69
64
  "deepmerge": "^4.2.2",
70
65
  "jest": "^30.4.2",
71
66
  "nock": "^13.3.1",
67
+ "rimraf": "^5.0.5",
72
68
  "ts-jest": "^29.4.11",
73
69
  "tsx": "^4.20.5",
74
70
  "typedoc": "^0.25.13",
75
71
  "typedoc-plugin-missing-exports": "^2.0.0",
76
- "typescript": "~5.3.3"
72
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
77
73
  },
78
74
  "engines": {
79
- "node": "^18.18 || >=20"
75
+ "node": "^22.14.0 || ^24"
80
76
  }
81
77
  }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=abstract-client-config-api-service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-client-config-api-service.cjs","sourceRoot":"","sources":["../../src/client-config-api-service/abstract-client-config-api-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\n\nimport type { ServiceResponse } from '../remote-feature-flag-controller-types.js';\n\n/**\n * A service object responsible for fetching feature flags.\n */\nexport type AbstractClientConfigApiService = Partial<\n Pick<ServicePolicy, 'onBreak' | 'onDegraded'>\n> & {\n /**\n * Fetches feature flags from the API with specific client, distribution, and\n * environment parameters. Provides structured error handling, including\n * fallback to cached data if available.\n *\n * @returns An object of feature flags and their boolean values or a\n * structured error object.\n */\n fetchRemoteFeatureFlags(): Promise<ServiceResponse>;\n};\n"]}
@@ -1,17 +0,0 @@
1
- import type { ServicePolicy } from "@metamask/controller-utils";
2
- import type { ServiceResponse } from "../remote-feature-flag-controller-types.cjs";
3
- /**
4
- * A service object responsible for fetching feature flags.
5
- */
6
- export type AbstractClientConfigApiService = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
7
- /**
8
- * Fetches feature flags from the API with specific client, distribution, and
9
- * environment parameters. Provides structured error handling, including
10
- * fallback to cached data if available.
11
- *
12
- * @returns An object of feature flags and their boolean values or a
13
- * structured error object.
14
- */
15
- fetchRemoteFeatureFlags(): Promise<ServiceResponse>;
16
- };
17
- //# sourceMappingURL=abstract-client-config-api-service.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-client-config-api-service.d.cts","sourceRoot":"","sources":["../../src/client-config-api-service/abstract-client-config-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,oDAAmD;AAElF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,OAAO,CAClD,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAC9C,GAAG;IACF;;;;;;;OAOG;IACH,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-client-config-api-service.d.mts","sourceRoot":"","sources":["../../src/client-config-api-service/abstract-client-config-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,oDAAmD;AAElF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,OAAO,CAClD,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAC9C,GAAG;IACF;;;;;;;OAOG;IACH,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=abstract-client-config-api-service.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-client-config-api-service.mjs","sourceRoot":"","sources":["../../src/client-config-api-service/abstract-client-config-api-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\n\nimport type { ServiceResponse } from '../remote-feature-flag-controller-types.js';\n\n/**\n * A service object responsible for fetching feature flags.\n */\nexport type AbstractClientConfigApiService = Partial<\n Pick<ServicePolicy, 'onBreak' | 'onDegraded'>\n> & {\n /**\n * Fetches feature flags from the API with specific client, distribution, and\n * environment parameters. Provides structured error handling, including\n * fallback to cached data if available.\n *\n * @returns An object of feature flags and their boolean values or a\n * structured error object.\n */\n fetchRemoteFeatureFlags(): Promise<ServiceResponse>;\n};\n"]}
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _ClientConfigApiService_instances, _ClientConfigApiService_fetch, _ClientConfigApiService_policy, _ClientConfigApiService_client, _ClientConfigApiService_distribution, _ClientConfigApiService_environment, _ClientConfigApiService_flattenFeatureFlags;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ClientConfigApiService = void 0;
16
- const controller_utils_1 = require("@metamask/controller-utils");
17
- const constants_js_1 = require("../constants.cjs");
18
- /**
19
- * This service is responsible for fetching feature flags from the ClientConfig API.
20
- */
21
- class ClientConfigApiService {
22
- constructor({ fetch: fetchFunction, retries = controller_utils_1.DEFAULT_MAX_RETRIES, maximumConsecutiveFailures = controller_utils_1.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = controller_utils_1.DEFAULT_CIRCUIT_BREAK_DURATION, onBreak, onDegraded, config, }) {
23
- _ClientConfigApiService_instances.add(this);
24
- _ClientConfigApiService_fetch.set(this, void 0);
25
- _ClientConfigApiService_policy.set(this, void 0);
26
- _ClientConfigApiService_client.set(this, void 0);
27
- _ClientConfigApiService_distribution.set(this, void 0);
28
- _ClientConfigApiService_environment.set(this, void 0);
29
- __classPrivateFieldSet(this, _ClientConfigApiService_fetch, fetchFunction, "f");
30
- __classPrivateFieldSet(this, _ClientConfigApiService_client, config.client, "f");
31
- __classPrivateFieldSet(this, _ClientConfigApiService_distribution, config.distribution, "f");
32
- __classPrivateFieldSet(this, _ClientConfigApiService_environment, config.environment, "f");
33
- __classPrivateFieldSet(this, _ClientConfigApiService_policy, (0, controller_utils_1.createServicePolicy)({
34
- maxRetries: retries,
35
- maxConsecutiveFailures: maximumConsecutiveFailures,
36
- circuitBreakDuration,
37
- }), "f");
38
- if (onBreak) {
39
- __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onBreak(onBreak);
40
- }
41
- if (onDegraded) {
42
- __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onDegraded(onDegraded);
43
- }
44
- }
45
- /**
46
- * Listens for when the request to the API fails too many times in a row.
47
- *
48
- * @param args - The same arguments that {@link ServicePolicy.onBreak}
49
- * takes.
50
- * @returns What {@link ServicePolicy.onBreak} returns.
51
- */
52
- onBreak(...args) {
53
- return __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onBreak(...args);
54
- }
55
- /**
56
- * Listens for when the API is degraded.
57
- *
58
- * @param args - The same arguments that {@link ServicePolicy.onDegraded}
59
- * takes.
60
- * @returns What {@link ServicePolicy.onDegraded} returns.
61
- */
62
- onDegraded(...args) {
63
- return __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onDegraded(...args);
64
- }
65
- /**
66
- * Fetches feature flags from the API with specific client, distribution, and environment parameters.
67
- * Provides structured error handling, including fallback to cached data if available.
68
- *
69
- * @returns An object of feature flags and their boolean values or a structured error object.
70
- */
71
- async fetchRemoteFeatureFlags() {
72
- const url = `${constants_js_1.BASE_URL}/flags?client=${__classPrivateFieldGet(this, _ClientConfigApiService_client, "f")}&distribution=${__classPrivateFieldGet(this, _ClientConfigApiService_distribution, "f")}&environment=${__classPrivateFieldGet(this, _ClientConfigApiService_environment, "f")}`;
73
- const response = await __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").execute(() => __classPrivateFieldGet(this, _ClientConfigApiService_fetch, "f").call(this, url, { cache: 'no-cache' }));
74
- if (!response.ok) {
75
- throw new Error('Failed to fetch remote feature flags');
76
- }
77
- const data = await response.json();
78
- if (!Array.isArray(data)) {
79
- throw new Error('Feature flags api did not return an array');
80
- }
81
- const remoteFeatureFlags = __classPrivateFieldGet(this, _ClientConfigApiService_instances, "m", _ClientConfigApiService_flattenFeatureFlags).call(this, data);
82
- return {
83
- remoteFeatureFlags,
84
- cacheTimestamp: Date.now(),
85
- };
86
- }
87
- }
88
- exports.ClientConfigApiService = ClientConfigApiService;
89
- _ClientConfigApiService_fetch = new WeakMap(), _ClientConfigApiService_policy = new WeakMap(), _ClientConfigApiService_client = new WeakMap(), _ClientConfigApiService_distribution = new WeakMap(), _ClientConfigApiService_environment = new WeakMap(), _ClientConfigApiService_instances = new WeakSet(), _ClientConfigApiService_flattenFeatureFlags = function _ClientConfigApiService_flattenFeatureFlags(responseData) {
90
- return responseData.reduce((acc, curr) => {
91
- return { ...acc, ...curr };
92
- }, {});
93
- };
94
- //# sourceMappingURL=client-config-api-service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-config-api-service.cjs","sourceRoot":"","sources":["../../src/client-config-api-service/client-config-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAKoC;AAIpC,mDAA2C;AAW3C;;GAEG;AACH,MAAa,sBAAsB;IAwFjC,YAAY,EACV,KAAK,EAAE,aAAa,EACpB,OAAO,GAAG,sCAAmB,EAC7B,0BAA0B,GAAG,mDAAgC,EAC7D,oBAAoB,GAAG,iDAA8B,EACrD,OAAO,EACP,UAAU,EACV,MAAM,GAaP;;QA3GQ,gDAAqB;QAErB,iDAAuB;QAEvB,iDAAoB;QAEpB,uDAA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CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,kBAAkB,GAAG,uBAAA,IAAI,sFAAqB,MAAzB,IAAI,EAAsB,IAAI,CAAC,CAAC;QAE3D,OAAO;YACL,kBAAkB;YAClB,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;SAC3B,CAAC;IACJ,CAAC;CAgBF;AApMD,wDAoMC;gZALsB,YAA6B;IAChD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACvC,OAAO,EAAE,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAC7B,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { IDisposable } from 'cockatiel';\n\nimport { BASE_URL } from '../constants.js';\nimport type {\n FeatureFlags,\n ClientType,\n DistributionType,\n EnvironmentType,\n ServiceResponse,\n ApiDataResponse,\n} from '../remote-feature-flag-controller-types.js';\nimport type { AbstractClientConfigApiService } from './abstract-client-config-api-service.js';\n\n/**\n * This service is responsible for fetching feature flags from the ClientConfig API.\n */\nexport class ClientConfigApiService implements AbstractClientConfigApiService {\n readonly #fetch: typeof fetch;\n\n readonly #policy: ServicePolicy;\n\n readonly #client: ClientType;\n\n readonly #distribution: DistributionType;\n\n readonly #environment: EnvironmentType;\n\n /**\n * Constructs a new ClientConfigApiService object.\n *\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further fetch\n * attempts.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n * @param args.config - The configuration object, includes client,\n * distribution, and environment.\n * @param args.config.client - The client type (e.g., 'extension', 'mobile').\n * @param args.config.distribution - The distribution type (e.g., 'main',\n * 'flask').\n * @param args.config.environment - The environment type (e.g., 'prod', 'rc',\n * 'dev').\n */\n constructor(args: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n });\n\n /**\n * Constructs a new ClientConfigApiService object.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further fetch\n * attempts.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.config - The configuration object, includes client,\n * distribution, and environment.\n * @param args.config.client - The client type (e.g., 'extension', 'mobile').\n * @param args.config.distribution - The distribution type (e.g., 'main',\n * 'flask').\n * @param args.config.environment - The environment type (e.g., 'prod', 'rc',\n * 'dev').\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n });\n\n constructor({\n fetch: fetchFunction,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n onBreak,\n onDegraded,\n config,\n }: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n }) {\n this.#fetch = fetchFunction;\n this.#client = config.client;\n this.#distribution = config.distribution;\n this.#environment = config.environment;\n\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(...args: Parameters<ServicePolicy['onBreak']>): IDisposable {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): IDisposable {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Fetches feature flags from the API with specific client, distribution, and environment parameters.\n * Provides structured error handling, including fallback to cached data if available.\n *\n * @returns An object of feature flags and their boolean values or a structured error object.\n */\n public async fetchRemoteFeatureFlags(): Promise<ServiceResponse> {\n const url = `${BASE_URL}/flags?client=${this.#client}&distribution=${\n this.#distribution\n }&environment=${this.#environment}`;\n\n const response = await this.#policy.execute(() =>\n this.#fetch(url, { cache: 'no-cache' }),\n );\n\n if (!response.ok) {\n throw new Error('Failed to fetch remote feature flags');\n }\n\n const data = await response.json();\n\n if (!Array.isArray(data)) {\n throw new Error('Feature flags api did not return an array');\n }\n\n const remoteFeatureFlags = this.#flattenFeatureFlags(data);\n\n return {\n remoteFeatureFlags,\n cacheTimestamp: Date.now(),\n };\n }\n\n /**\n * Flattens an array of feature flag objects into a single feature flags object.\n *\n * @param responseData - Array of objects containing feature flag key-value pairs\n * @returns A single object containing all feature flags merged together\n * @example\n * // Input: [{ flag1: true }, { flag2: [] }]\n * // Output: { flag1: true, flag2: [] }\n */\n #flattenFeatureFlags(responseData: ApiDataResponse): FeatureFlags {\n return responseData.reduce((acc, curr) => {\n return { ...acc, ...curr };\n }, {});\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-config-api-service.d.cts","sourceRoot":"","sources":["../../src/client-config-api-service/client-config-api-service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAG7C,OAAO,KAAK,EAEV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EAEhB,oDAAmD;AACpD,OAAO,KAAK,EAAE,8BAA8B,EAAE,iDAAgD;AAE9F;;GAEG;AACH,qBAAa,sBAAuB,YAAW,8BAA8B;;IAW3E;;;;;;;;;;;;;;;;;;;;;OAqBG;gBACS,IAAI,EAAE;QAChB,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,MAAM,EAAE;YACN,MAAM,EAAE,UAAU,CAAC;YACnB,YAAY,EAAE,gBAAgB,CAAC;YAC/B,WAAW,EAAE,eAAe,CAAC;SAC9B,CAAC;KACH;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;gBAES,IAAI,EAAE;QAChB,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,MAAM,EAAE;YACN,MAAM,EAAE,UAAU,CAAC;YACnB,YAAY,EAAE,gBAAgB,CAAC;YAC/B,WAAW,EAAE,eAAe,CAAC;SAC9B,CAAC;KACH;IAyCD;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAAG,WAAW;IAInE;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,GAAG,WAAW;IAIzE;;;;;OAKG;IACU,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC;CAyCjE"}
@@ -1,108 +0,0 @@
1
- import type { ServicePolicy } from "@metamask/controller-utils";
2
- import type { IDisposable } from "cockatiel";
3
- import type { ClientType, DistributionType, EnvironmentType, ServiceResponse } from "../remote-feature-flag-controller-types.mjs";
4
- import type { AbstractClientConfigApiService } from "./abstract-client-config-api-service.mjs";
5
- /**
6
- * This service is responsible for fetching feature flags from the ClientConfig API.
7
- */
8
- export declare class ClientConfigApiService implements AbstractClientConfigApiService {
9
- #private;
10
- /**
11
- * Constructs a new ClientConfigApiService object.
12
- *
13
- * @param args - The arguments.
14
- * @param args.fetch - A function that can be used to make an HTTP request.
15
- * If your JavaScript environment supports `fetch` natively, you'll probably
16
- * want to pass that; otherwise you can pass an equivalent (such as `fetch`
17
- * via `node-fetch`).
18
- * @param args.retries - Number of retry attempts for each fetch request.
19
- * @param args.maximumConsecutiveFailures - The maximum number of consecutive
20
- * failures allowed before breaking the circuit and pausing further fetch
21
- * attempts.
22
- * @param args.circuitBreakDuration - The amount of time to wait when the
23
- * circuit breaks from too many consecutive failures.
24
- * @param args.config - The configuration object, includes client,
25
- * distribution, and environment.
26
- * @param args.config.client - The client type (e.g., 'extension', 'mobile').
27
- * @param args.config.distribution - The distribution type (e.g., 'main',
28
- * 'flask').
29
- * @param args.config.environment - The environment type (e.g., 'prod', 'rc',
30
- * 'dev').
31
- */
32
- constructor(args: {
33
- fetch: typeof fetch;
34
- retries?: number;
35
- maximumConsecutiveFailures?: number;
36
- circuitBreakDuration?: number;
37
- config: {
38
- client: ClientType;
39
- distribution: DistributionType;
40
- environment: EnvironmentType;
41
- };
42
- });
43
- /**
44
- * Constructs a new ClientConfigApiService object.
45
- *
46
- * @deprecated This signature is deprecated; please use the `onBreak` and
47
- * `onDegraded` methods instead.
48
- * @param args - The arguments.
49
- * @param args.fetch - A function that can be used to make an HTTP request.
50
- * If your JavaScript environment supports `fetch` natively, you'll probably
51
- * want to pass that; otherwise you can pass an equivalent (such as `fetch`
52
- * via `node-fetch`).
53
- * @param args.retries - Number of retry attempts for each fetch request.
54
- * @param args.maximumConsecutiveFailures - The maximum number of consecutive
55
- * failures allowed before breaking the circuit and pausing further fetch
56
- * attempts.
57
- * @param args.circuitBreakDuration - The amount of time to wait when the
58
- * circuit breaks from too many consecutive failures.
59
- * @param args.onBreak - Callback for when the circuit breaks, useful
60
- * for capturing metrics about network failures.
61
- * @param args.onDegraded - Callback for when the API responds successfully
62
- * but takes too long to respond (5 seconds or more).
63
- * @param args.config - The configuration object, includes client,
64
- * distribution, and environment.
65
- * @param args.config.client - The client type (e.g., 'extension', 'mobile').
66
- * @param args.config.distribution - The distribution type (e.g., 'main',
67
- * 'flask').
68
- * @param args.config.environment - The environment type (e.g., 'prod', 'rc',
69
- * 'dev').
70
- */
71
- constructor(args: {
72
- fetch: typeof fetch;
73
- retries?: number;
74
- maximumConsecutiveFailures?: number;
75
- circuitBreakDuration?: number;
76
- onBreak?: () => void;
77
- onDegraded?: () => void;
78
- config: {
79
- client: ClientType;
80
- distribution: DistributionType;
81
- environment: EnvironmentType;
82
- };
83
- });
84
- /**
85
- * Listens for when the request to the API fails too many times in a row.
86
- *
87
- * @param args - The same arguments that {@link ServicePolicy.onBreak}
88
- * takes.
89
- * @returns What {@link ServicePolicy.onBreak} returns.
90
- */
91
- onBreak(...args: Parameters<ServicePolicy['onBreak']>): IDisposable;
92
- /**
93
- * Listens for when the API is degraded.
94
- *
95
- * @param args - The same arguments that {@link ServicePolicy.onDegraded}
96
- * takes.
97
- * @returns What {@link ServicePolicy.onDegraded} returns.
98
- */
99
- onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): IDisposable;
100
- /**
101
- * Fetches feature flags from the API with specific client, distribution, and environment parameters.
102
- * Provides structured error handling, including fallback to cached data if available.
103
- *
104
- * @returns An object of feature flags and their boolean values or a structured error object.
105
- */
106
- fetchRemoteFeatureFlags(): Promise<ServiceResponse>;
107
- }
108
- //# sourceMappingURL=client-config-api-service.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-config-api-service.d.mts","sourceRoot":"","sources":["../../src/client-config-api-service/client-config-api-service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAG7C,OAAO,KAAK,EAEV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EAEhB,oDAAmD;AACpD,OAAO,KAAK,EAAE,8BAA8B,EAAE,iDAAgD;AAE9F;;GAEG;AACH,qBAAa,sBAAuB,YAAW,8BAA8B;;IAW3E;;;;;;;;;;;;;;;;;;;;;OAqBG;gBACS,IAAI,EAAE;QAChB,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,MAAM,EAAE;YACN,MAAM,EAAE,UAAU,CAAC;YACnB,YAAY,EAAE,gBAAgB,CAAC;YAC/B,WAAW,EAAE,eAAe,CAAC;SAC9B,CAAC;KACH;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;gBAES,IAAI,EAAE;QAChB,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,MAAM,EAAE;YACN,MAAM,EAAE,UAAU,CAAC;YACnB,YAAY,EAAE,gBAAgB,CAAC;YAC/B,WAAW,EAAE,eAAe,CAAC;SAC9B,CAAC;KACH;IAyCD;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAAG,WAAW;IAInE;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,GAAG,WAAW;IAIzE;;;;;OAKG;IACU,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC;CAyCjE"}
@@ -1,90 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _ClientConfigApiService_instances, _ClientConfigApiService_fetch, _ClientConfigApiService_policy, _ClientConfigApiService_client, _ClientConfigApiService_distribution, _ClientConfigApiService_environment, _ClientConfigApiService_flattenFeatureFlags;
13
- import { createServicePolicy, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES } from "@metamask/controller-utils";
14
- import { BASE_URL } from "../constants.mjs";
15
- /**
16
- * This service is responsible for fetching feature flags from the ClientConfig API.
17
- */
18
- export class ClientConfigApiService {
19
- constructor({ fetch: fetchFunction, retries = DEFAULT_MAX_RETRIES, maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, onBreak, onDegraded, config, }) {
20
- _ClientConfigApiService_instances.add(this);
21
- _ClientConfigApiService_fetch.set(this, void 0);
22
- _ClientConfigApiService_policy.set(this, void 0);
23
- _ClientConfigApiService_client.set(this, void 0);
24
- _ClientConfigApiService_distribution.set(this, void 0);
25
- _ClientConfigApiService_environment.set(this, void 0);
26
- __classPrivateFieldSet(this, _ClientConfigApiService_fetch, fetchFunction, "f");
27
- __classPrivateFieldSet(this, _ClientConfigApiService_client, config.client, "f");
28
- __classPrivateFieldSet(this, _ClientConfigApiService_distribution, config.distribution, "f");
29
- __classPrivateFieldSet(this, _ClientConfigApiService_environment, config.environment, "f");
30
- __classPrivateFieldSet(this, _ClientConfigApiService_policy, createServicePolicy({
31
- maxRetries: retries,
32
- maxConsecutiveFailures: maximumConsecutiveFailures,
33
- circuitBreakDuration,
34
- }), "f");
35
- if (onBreak) {
36
- __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onBreak(onBreak);
37
- }
38
- if (onDegraded) {
39
- __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onDegraded(onDegraded);
40
- }
41
- }
42
- /**
43
- * Listens for when the request to the API fails too many times in a row.
44
- *
45
- * @param args - The same arguments that {@link ServicePolicy.onBreak}
46
- * takes.
47
- * @returns What {@link ServicePolicy.onBreak} returns.
48
- */
49
- onBreak(...args) {
50
- return __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onBreak(...args);
51
- }
52
- /**
53
- * Listens for when the API is degraded.
54
- *
55
- * @param args - The same arguments that {@link ServicePolicy.onDegraded}
56
- * takes.
57
- * @returns What {@link ServicePolicy.onDegraded} returns.
58
- */
59
- onDegraded(...args) {
60
- return __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").onDegraded(...args);
61
- }
62
- /**
63
- * Fetches feature flags from the API with specific client, distribution, and environment parameters.
64
- * Provides structured error handling, including fallback to cached data if available.
65
- *
66
- * @returns An object of feature flags and their boolean values or a structured error object.
67
- */
68
- async fetchRemoteFeatureFlags() {
69
- const url = `${BASE_URL}/flags?client=${__classPrivateFieldGet(this, _ClientConfigApiService_client, "f")}&distribution=${__classPrivateFieldGet(this, _ClientConfigApiService_distribution, "f")}&environment=${__classPrivateFieldGet(this, _ClientConfigApiService_environment, "f")}`;
70
- const response = await __classPrivateFieldGet(this, _ClientConfigApiService_policy, "f").execute(() => __classPrivateFieldGet(this, _ClientConfigApiService_fetch, "f").call(this, url, { cache: 'no-cache' }));
71
- if (!response.ok) {
72
- throw new Error('Failed to fetch remote feature flags');
73
- }
74
- const data = await response.json();
75
- if (!Array.isArray(data)) {
76
- throw new Error('Feature flags api did not return an array');
77
- }
78
- const remoteFeatureFlags = __classPrivateFieldGet(this, _ClientConfigApiService_instances, "m", _ClientConfigApiService_flattenFeatureFlags).call(this, data);
79
- return {
80
- remoteFeatureFlags,
81
- cacheTimestamp: Date.now(),
82
- };
83
- }
84
- }
85
- _ClientConfigApiService_fetch = new WeakMap(), _ClientConfigApiService_policy = new WeakMap(), _ClientConfigApiService_client = new WeakMap(), _ClientConfigApiService_distribution = new WeakMap(), _ClientConfigApiService_environment = new WeakMap(), _ClientConfigApiService_instances = new WeakSet(), _ClientConfigApiService_flattenFeatureFlags = function _ClientConfigApiService_flattenFeatureFlags(responseData) {
86
- return responseData.reduce((acc, curr) => {
87
- return { ...acc, ...curr };
88
- }, {});
89
- };
90
- //# sourceMappingURL=client-config-api-service.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-config-api-service.mjs","sourceRoot":"","sources":["../../src/client-config-api-service/client-config-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,gCAAgC,EAChC,mBAAmB,EACpB,mCAAmC;AAIpC,OAAO,EAAE,QAAQ,EAAE,yBAAwB;AAW3C;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAwFjC,YAAY,EACV,KAAK,EAAE,aAAa,EACpB,OAAO,GAAG,mBAAmB,EAC7B,0BAA0B,GAAG,gCAAgC,EAC7D,oBAAoB,GAAG,8BAA8B,EACrD,OAAO,EACP,UAAU,EACV,MAAM,GAaP;;QA3GQ,gDAAqB;QAErB,iDAAuB;QAEvB,iDAAoB;QAEpB,uDAAgC;QAEhC,sDAA8B;QAoGrC,uBAAA,IAAI,iCAAU,aAAa,MAAA,CAAC;QAC5B,uBAAA,IAAI,kCAAW,MAAM,CAAC,MAAM,MAAA,CAAC;QAC7B,uBAAA,IAAI,wCAAiB,MAAM,CAAC,YAAY,MAAA,CAAC;QACzC,uBAAA,IAAI,uCAAgB,MAAM,CAAC,WAAW,MAAA,CAAC;QAEvC,uBAAA,IAAI,kCAAW,mBAAmB,CAAC;YAC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AAC;QAC/D,CAAC;QAED,MAAM,kBAAkB,GAAG,uBAAA,IAAI,sFAAqB,MAAzB,IAAI,EAAsB,IAAI,CAAC,CAAC;QAE3D,OAAO;YACL,kBAAkB;YAClB,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;SAC3B,CAAC;IACJ,CAAC;CAgBF;gZALsB,YAA6B;IAChD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACvC,OAAO,EAAE,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAC7B,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { IDisposable } from 'cockatiel';\n\nimport { BASE_URL } from '../constants.js';\nimport type {\n FeatureFlags,\n ClientType,\n DistributionType,\n EnvironmentType,\n ServiceResponse,\n ApiDataResponse,\n} from '../remote-feature-flag-controller-types.js';\nimport type { AbstractClientConfigApiService } from './abstract-client-config-api-service.js';\n\n/**\n * This service is responsible for fetching feature flags from the ClientConfig API.\n */\nexport class ClientConfigApiService implements AbstractClientConfigApiService {\n readonly #fetch: typeof fetch;\n\n readonly #policy: ServicePolicy;\n\n readonly #client: ClientType;\n\n readonly #distribution: DistributionType;\n\n readonly #environment: EnvironmentType;\n\n /**\n * Constructs a new ClientConfigApiService object.\n *\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further fetch\n * attempts.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n * @param args.config - The configuration object, includes client,\n * distribution, and environment.\n * @param args.config.client - The client type (e.g., 'extension', 'mobile').\n * @param args.config.distribution - The distribution type (e.g., 'main',\n * 'flask').\n * @param args.config.environment - The environment type (e.g., 'prod', 'rc',\n * 'dev').\n */\n constructor(args: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n });\n\n /**\n * Constructs a new ClientConfigApiService object.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further fetch\n * attempts.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.config - The configuration object, includes client,\n * distribution, and environment.\n * @param args.config.client - The client type (e.g., 'extension', 'mobile').\n * @param args.config.distribution - The distribution type (e.g., 'main',\n * 'flask').\n * @param args.config.environment - The environment type (e.g., 'prod', 'rc',\n * 'dev').\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n });\n\n constructor({\n fetch: fetchFunction,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n onBreak,\n onDegraded,\n config,\n }: {\n fetch: typeof fetch;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n config: {\n client: ClientType;\n distribution: DistributionType;\n environment: EnvironmentType;\n };\n }) {\n this.#fetch = fetchFunction;\n this.#client = config.client;\n this.#distribution = config.distribution;\n this.#environment = config.environment;\n\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(...args: Parameters<ServicePolicy['onBreak']>): IDisposable {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(...args: Parameters<ServicePolicy['onDegraded']>): IDisposable {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Fetches feature flags from the API with specific client, distribution, and environment parameters.\n * Provides structured error handling, including fallback to cached data if available.\n *\n * @returns An object of feature flags and their boolean values or a structured error object.\n */\n public async fetchRemoteFeatureFlags(): Promise<ServiceResponse> {\n const url = `${BASE_URL}/flags?client=${this.#client}&distribution=${\n this.#distribution\n }&environment=${this.#environment}`;\n\n const response = await this.#policy.execute(() =>\n this.#fetch(url, { cache: 'no-cache' }),\n );\n\n if (!response.ok) {\n throw new Error('Failed to fetch remote feature flags');\n }\n\n const data = await response.json();\n\n if (!Array.isArray(data)) {\n throw new Error('Feature flags api did not return an array');\n }\n\n const remoteFeatureFlags = this.#flattenFeatureFlags(data);\n\n return {\n remoteFeatureFlags,\n cacheTimestamp: Date.now(),\n };\n }\n\n /**\n * Flattens an array of feature flag objects into a single feature flags object.\n *\n * @param responseData - Array of objects containing feature flag key-value pairs\n * @returns A single object containing all feature flags merged together\n * @example\n * // Input: [{ flag1: true }, { flag2: [] }]\n * // Output: { flag1: true, flag2: [] }\n */\n #flattenFeatureFlags(responseData: ApiDataResponse): FeatureFlags {\n return responseData.reduce((acc, curr) => {\n return { ...acc, ...curr };\n }, {});\n }\n}\n"]}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BASE_URL = void 0;
4
- /**
5
- * ClientConfig API base URL.
6
- */
7
- exports.BASE_URL = 'https://client-config.api.cx.metamask.io/v1';
8
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,QAAQ,GAAG,6CAA6C,CAAC","sourcesContent":["/**\n * ClientConfig API base URL.\n */\nexport const BASE_URL = 'https://client-config.api.cx.metamask.io/v1';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,gDAAgD,CAAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * ClientConfig API base URL.
3
- */
4
- export declare const BASE_URL = "https://client-config.api.cx.metamask.io/v1";
5
- //# sourceMappingURL=constants.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,gDAAgD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,6CAA6C,CAAC","sourcesContent":["/**\n * ClientConfig API base URL.\n */\nexport const BASE_URL = 'https://client-config.api.cx.metamask.io/v1';\n"]}