@metamask/ramps-controller 17.1.0 → 18.0.0

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.
@@ -1,26 +1,94 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHeadlessAllProvidersEnabled = exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = void 0;
3
+ exports.normalizeHeadlessProviderId = exports.getHeadlessProviderAllowlist = exports.isHeadlessAllProvidersEnabled = exports.HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = void 0;
4
4
  /**
5
5
  * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers
6
- * expansion. A boolean flag: `true` widens the headless fiat quote path to
7
- * every provider class (native, in-app WebView aggregator, and
8
- * external-browser / custom-action); `false` or missing keeps the native-only
9
- * default. Exported so the flag registry and every consumer stay in sync on
10
- * the exact key string.
6
+ * expansion. Accepts two value forms:
7
+ *
8
+ * - The literal boolean `true` widens the headless fiat quote path to every
9
+ * provider class (native, in-app WebView aggregator, and external-browser /
10
+ * custom-action) with no provider restriction.
11
+ * - An object payload `{ enabled: true, featureVersion: "1", providerIds?: string[] }`
12
+ * widens the same way, and additionally restricts the widened quote pick to
13
+ * the listed provider ids (see {@link getHeadlessProviderAllowlist}).
14
+ *
15
+ * `false`, a missing flag, or any other value keeps the native-only default.
16
+ * Clients that only understand the boolean form coerce the object payload to
17
+ * "disabled" (native-only), so serving the object form can never turn the
18
+ * feature on for a client that cannot parse it. Exported so the flag registry
19
+ * and every consumer stay in sync on the exact key string.
11
20
  */
12
21
  exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders';
22
+ /**
23
+ * Contract version of the object payload. An enabled payload whose
24
+ * `featureVersion` differs (or is absent) fails closed, so the payload's
25
+ * meaning can change in a future client without old clients misreading it.
26
+ * Mirrors the platform pattern used by `assetsUnifyState`.
27
+ */
28
+ exports.HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = '1';
29
+ /**
30
+ * Resolves the flag value with `localOverrides` (written by dev-only override
31
+ * screens) merged over `remoteFeatureFlags`, because not every published
32
+ * `RemoteFeatureFlagController` version folds overrides into
33
+ * `remoteFeatureFlags` state; when a version already does, the merge is a
34
+ * no-op.
35
+ *
36
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
37
+ * relevant subset of it).
38
+ * @returns The merged flag value, or `undefined` when absent.
39
+ */
40
+ function resolveFlagValue(remoteFeatureFlagState) {
41
+ const flags = {
42
+ ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
43
+ ...(remoteFeatureFlagState?.localOverrides ?? {}),
44
+ };
45
+ return flags[exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY];
46
+ }
47
+ /**
48
+ * Whether a flag value is the object payload form: a plain object (not an
49
+ * array) whose `enabled` is the literal boolean `true`. Anything else,
50
+ * including `{ enabled: false }` and objects without `enabled`, is not an
51
+ * enabled payload, so the flag fails closed.
52
+ *
53
+ * @param value - The merged flag value.
54
+ * @returns Whether the value is an enabled object payload.
55
+ */
56
+ function isEnabledPayload(value) {
57
+ return (typeof value === 'object' &&
58
+ value !== null &&
59
+ !Array.isArray(value) &&
60
+ value.enabled === true &&
61
+ value.featureVersion === exports.HEADLESS_ALL_PROVIDERS_FEATURE_VERSION);
62
+ }
63
+ /**
64
+ * Coerces a payload field into a provider-id list: keeps only string entries,
65
+ * trims them, and drops empties. An empty or malformed level is treated as
66
+ * "not provided" so resolution falls through to the next level rather than
67
+ * restricting to nothing; to force "nothing eligible" list a nonexistent id.
68
+ *
69
+ * @param value - The candidate `providerIds` / surface entry value.
70
+ * @returns The non-empty coerced list, or `undefined`.
71
+ */
72
+ function coerceProviderIdList(value) {
73
+ if (!Array.isArray(value)) {
74
+ return undefined;
75
+ }
76
+ const ids = value
77
+ .filter((entry) => typeof entry === 'string')
78
+ .map((entry) => entry.trim())
79
+ .filter((entry) => entry !== '');
80
+ return ids.length > 0 ? ids : undefined;
81
+ }
13
82
  /**
14
83
  * Whether the Headless Buy all-providers feature flag is enabled.
15
84
  *
16
85
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
17
86
  * so the controller's quote widening and UI availability gates resolve the
18
- * flag identically. `localOverrides` (written by dev-only override screens)
19
- * are merged over `remoteFeatureFlags`, because not every published
20
- * `RemoteFeatureFlagController` version folds overrides into
21
- * `remoteFeatureFlags` state; when a version already does, the merge is a
22
- * no-op. Coerces defensively: only the literal boolean `true` enables, and
23
- * any other value (missing, string, object) resolves to `false`.
87
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
88
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
89
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
90
+ * enables; any other value (missing, string, number, array, `{ enabled:
91
+ * false }`) resolves to `false`.
24
92
  *
25
93
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
26
94
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -29,11 +97,48 @@ exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders';
29
97
  * quote path.
30
98
  */
31
99
  function isHeadlessAllProvidersEnabled(remoteFeatureFlagState) {
32
- const flags = {
33
- ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
34
- ...(remoteFeatureFlagState?.localOverrides ?? {}),
35
- };
36
- return flags[exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;
100
+ const value = resolveFlagValue(remoteFeatureFlagState);
101
+ return value === true || isEnabledPayload(value);
37
102
  }
38
103
  exports.isHeadlessAllProvidersEnabled = isHeadlessAllProvidersEnabled;
104
+ /**
105
+ * The provider-id allowlist carried by the flag's object payload, or
106
+ * `undefined` when the widened pick should not be restricted.
107
+ *
108
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
109
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
110
+ * malformed payload, and empty or all-invalid lists all resolve to
111
+ * `undefined`; unknown keys and non-string entries are ignored.
112
+ *
113
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
114
+ * relevant subset of it). May be `null`/`undefined` before the controller is
115
+ * initialized.
116
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
117
+ * for no restriction.
118
+ */
119
+ function getHeadlessProviderAllowlist(remoteFeatureFlagState) {
120
+ const value = resolveFlagValue(remoteFeatureFlagState);
121
+ if (!isEnabledPayload(value)) {
122
+ return undefined;
123
+ }
124
+ return coerceProviderIdList(value.providerIds);
125
+ }
126
+ exports.getHeadlessProviderAllowlist = getHeadlessProviderAllowlist;
127
+ /**
128
+ * Normalizes a provider id for allowlist matching only: trims, strips the
129
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
130
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
131
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
132
+ * can use either id form. Not exported from the package index.
133
+ *
134
+ * @param id - A provider id in either the prefixed or bare form.
135
+ * @returns The normalized id used for allowlist comparison.
136
+ */
137
+ function normalizeHeadlessProviderId(id) {
138
+ return id
139
+ .trim()
140
+ .replace(/^\/providers\//u, '')
141
+ .toLowerCase();
142
+ }
143
+ exports.normalizeHeadlessProviderId = normalizeHeadlessProviderId;
39
144
  //# sourceMappingURL=featureFlags.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.cjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACU,QAAA,qCAAqC,GAChD,2BAA2B,CAAC;AAa9B;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,6BAA6B,CAC3C,sBAAqE;IAErE,MAAM,KAAK,GAAiB;QAC1B,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,IAAI,EAAE,CAAC;QACrD,GAAG,CAAC,sBAAsB,EAAE,cAAc,IAAI,EAAE,CAAC;KAClD,CAAC;IACF,OAAO,KAAK,CAAC,6CAAqC,CAAC,KAAK,IAAI,CAAC;AAC/D,CAAC;AARD,sEAQC","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\n\n/**\n * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers\n * expansion. A boolean flag: `true` widens the headless fiat quote path to\n * every provider class (native, in-app WebView aggregator, and\n * external-browser / custom-action); `false` or missing keeps the native-only\n * default. Exported so the flag registry and every consumer stay in sync on\n * the exact key string.\n */\nexport const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY =\n 'moneyHeadlessAllProviders';\n\n/**\n * The subset of `RemoteFeatureFlagController` state that\n * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can\n * pass the whole controller state (or `undefined` before initialization)\n * without depending on a specific controller version.\n */\nexport type HeadlessFeatureFlagsLookup = {\n remoteFeatureFlags?: FeatureFlags;\n localOverrides?: FeatureFlags;\n};\n\n/**\n * Whether the Headless Buy all-providers feature flag is enabled.\n *\n * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}\n * so the controller's quote widening and UI availability gates resolve the\n * flag identically. `localOverrides` (written by dev-only override screens)\n * are merged over `remoteFeatureFlags`, because not every published\n * `RemoteFeatureFlagController` version folds overrides into\n * `remoteFeatureFlags` state; when a version already does, the merge is a\n * no-op. Coerces defensively: only the literal boolean `true` enables, and\n * any other value (missing, string, object) resolves to `false`.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns Whether all provider classes are enabled for the headless fiat\n * quote path.\n */\nexport function isHeadlessAllProvidersEnabled(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): boolean {\n const flags: FeatureFlags = {\n ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),\n ...(remoteFeatureFlagState?.localOverrides ?? {}),\n };\n return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;\n}\n"]}
1
+ {"version":3,"file":"featureFlags.cjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,qCAAqC,GAChD,2BAA2B,CAAC;AAE9B;;;;;GAKG;AACU,QAAA,sCAAsC,GAAG,GAAG,CAAC;AAa1D;;;;;;;;;;GAUG;AACH,SAAS,gBAAgB,CACvB,sBAAqE;IAErE,MAAM,KAAK,GAAiB;QAC1B,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,IAAI,EAAE,CAAC;QACrD,GAAG,CAAC,sBAAsB,EAAE,cAAc,IAAI,EAAE,CAAC;KAClD,CAAC;IACF,OAAO,KAAK,CAAC,6CAAqC,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,KAAuB;IAG/C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,KAAK,CAAC,OAAO,KAAK,IAAI;QACtB,KAAK,CAAC,cAAc,KAAK,8CAAsC,CAChE,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAAC,KAAuB;IACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,GAAG,GAAG,KAAK;SACd,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;SAC7D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;IACnC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,6BAA6B,CAC3C,sBAAqE;IAErE,MAAM,KAAK,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACvD,OAAO,KAAK,KAAK,IAAI,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AALD,sEAKC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,4BAA4B,CAC1C,sBAAqE;IAErE,MAAM,KAAK,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACvD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AARD,oEAQC;AAED;;;;;;;;;GASG;AACH,SAAgB,2BAA2B,CAAC,EAAU;IACpD,OAAO,EAAE;SACN,IAAI,EAAE;SACN,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,WAAW,EAAE,CAAC;AACnB,CAAC;AALD,kEAKC","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers\n * expansion. Accepts two value forms:\n *\n * - The literal boolean `true` widens the headless fiat quote path to every\n * provider class (native, in-app WebView aggregator, and external-browser /\n * custom-action) with no provider restriction.\n * - An object payload `{ enabled: true, featureVersion: \"1\", providerIds?: string[] }`\n * widens the same way, and additionally restricts the widened quote pick to\n * the listed provider ids (see {@link getHeadlessProviderAllowlist}).\n *\n * `false`, a missing flag, or any other value keeps the native-only default.\n * Clients that only understand the boolean form coerce the object payload to\n * \"disabled\" (native-only), so serving the object form can never turn the\n * feature on for a client that cannot parse it. Exported so the flag registry\n * and every consumer stay in sync on the exact key string.\n */\nexport const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY =\n 'moneyHeadlessAllProviders';\n\n/**\n * Contract version of the object payload. An enabled payload whose\n * `featureVersion` differs (or is absent) fails closed, so the payload's\n * meaning can change in a future client without old clients misreading it.\n * Mirrors the platform pattern used by `assetsUnifyState`.\n */\nexport const HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = '1';\n\n/**\n * The subset of `RemoteFeatureFlagController` state that\n * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can\n * pass the whole controller state (or `undefined` before initialization)\n * without depending on a specific controller version.\n */\nexport type HeadlessFeatureFlagsLookup = {\n remoteFeatureFlags?: FeatureFlags;\n localOverrides?: FeatureFlags;\n};\n\n/**\n * Resolves the flag value with `localOverrides` (written by dev-only override\n * screens) merged over `remoteFeatureFlags`, because not every published\n * `RemoteFeatureFlagController` version folds overrides into\n * `remoteFeatureFlags` state; when a version already does, the merge is a\n * no-op.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it).\n * @returns The merged flag value, or `undefined` when absent.\n */\nfunction resolveFlagValue(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): Json | undefined {\n const flags: FeatureFlags = {\n ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),\n ...(remoteFeatureFlagState?.localOverrides ?? {}),\n };\n return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY];\n}\n\n/**\n * Whether a flag value is the object payload form: a plain object (not an\n * array) whose `enabled` is the literal boolean `true`. Anything else,\n * including `{ enabled: false }` and objects without `enabled`, is not an\n * enabled payload, so the flag fails closed.\n *\n * @param value - The merged flag value.\n * @returns Whether the value is an enabled object payload.\n */\nfunction isEnabledPayload(value: Json | undefined): value is {\n [key: string]: Json;\n} {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n value.enabled === true &&\n value.featureVersion === HEADLESS_ALL_PROVIDERS_FEATURE_VERSION\n );\n}\n\n/**\n * Coerces a payload field into a provider-id list: keeps only string entries,\n * trims them, and drops empties. An empty or malformed level is treated as\n * \"not provided\" so resolution falls through to the next level rather than\n * restricting to nothing; to force \"nothing eligible\" list a nonexistent id.\n *\n * @param value - The candidate `providerIds` / surface entry value.\n * @returns The non-empty coerced list, or `undefined`.\n */\nfunction coerceProviderIdList(value: Json | undefined): string[] | undefined {\n if (!Array.isArray(value)) {\n return undefined;\n }\n const ids = value\n .filter((entry): entry is string => typeof entry === 'string')\n .map((entry) => entry.trim())\n .filter((entry) => entry !== '');\n return ids.length > 0 ? ids : undefined;\n}\n\n/**\n * Whether the Headless Buy all-providers feature flag is enabled.\n *\n * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}\n * so the controller's quote widening and UI availability gates resolve the\n * flag identically. `localOverrides` are merged over `remoteFeatureFlags`\n * (see {@link resolveFlagValue}). Coerces defensively: only the literal\n * boolean `true` or an object payload whose `enabled` is the literal `true`\n * enables; any other value (missing, string, number, array, `{ enabled:\n * false }`) resolves to `false`.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns Whether all provider classes are enabled for the headless fiat\n * quote path.\n */\nexport function isHeadlessAllProvidersEnabled(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): boolean {\n const value = resolveFlagValue(remoteFeatureFlagState);\n return value === true || isEnabledPayload(value);\n}\n\n/**\n * The provider-id allowlist carried by the flag's object payload, or\n * `undefined` when the widened pick should not be restricted.\n *\n * Returns the payload's top-level `providerIds` when non-empty and valid, or\n * `undefined` (no restriction). The boolean `true` form, a disabled or\n * malformed payload, and empty or all-invalid lists all resolve to\n * `undefined`; unknown keys and non-string entries are ignored.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns The provider ids the widened pick is restricted to, or `undefined`\n * for no restriction.\n */\nexport function getHeadlessProviderAllowlist(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n return coerceProviderIdList(value.providerIds);\n}\n\n/**\n * Normalizes a provider id for allowlist matching only: trims, strips the\n * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`\n * and `moonpay` match each other. Quote and catalog provider ids are matched\n * as-is everywhere else; this exists solely so LaunchDarkly payload authors\n * can use either id form. Not exported from the package index.\n *\n * @param id - A provider id in either the prefixed or bare form.\n * @returns The normalized id used for allowlist comparison.\n */\nexport function normalizeHeadlessProviderId(id: string): string {\n return id\n .trim()\n .replace(/^\\/providers\\//u, '')\n .toLowerCase();\n}\n"]}
@@ -1,13 +1,29 @@
1
1
  import type { FeatureFlags } from "@metamask/remote-feature-flag-controller";
2
2
  /**
3
3
  * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers
4
- * expansion. A boolean flag: `true` widens the headless fiat quote path to
5
- * every provider class (native, in-app WebView aggregator, and
6
- * external-browser / custom-action); `false` or missing keeps the native-only
7
- * default. Exported so the flag registry and every consumer stay in sync on
8
- * the exact key string.
4
+ * expansion. Accepts two value forms:
5
+ *
6
+ * - The literal boolean `true` widens the headless fiat quote path to every
7
+ * provider class (native, in-app WebView aggregator, and external-browser /
8
+ * custom-action) with no provider restriction.
9
+ * - An object payload `{ enabled: true, featureVersion: "1", providerIds?: string[] }`
10
+ * widens the same way, and additionally restricts the widened quote pick to
11
+ * the listed provider ids (see {@link getHeadlessProviderAllowlist}).
12
+ *
13
+ * `false`, a missing flag, or any other value keeps the native-only default.
14
+ * Clients that only understand the boolean form coerce the object payload to
15
+ * "disabled" (native-only), so serving the object form can never turn the
16
+ * feature on for a client that cannot parse it. Exported so the flag registry
17
+ * and every consumer stay in sync on the exact key string.
9
18
  */
10
19
  export declare const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = "moneyHeadlessAllProviders";
20
+ /**
21
+ * Contract version of the object payload. An enabled payload whose
22
+ * `featureVersion` differs (or is absent) fails closed, so the payload's
23
+ * meaning can change in a future client without old clients misreading it.
24
+ * Mirrors the platform pattern used by `assetsUnifyState`.
25
+ */
26
+ export declare const HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = "1";
11
27
  /**
12
28
  * The subset of `RemoteFeatureFlagController` state that
13
29
  * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can
@@ -23,12 +39,11 @@ export type HeadlessFeatureFlagsLookup = {
23
39
  *
24
40
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
25
41
  * so the controller's quote widening and UI availability gates resolve the
26
- * flag identically. `localOverrides` (written by dev-only override screens)
27
- * are merged over `remoteFeatureFlags`, because not every published
28
- * `RemoteFeatureFlagController` version folds overrides into
29
- * `remoteFeatureFlags` state; when a version already does, the merge is a
30
- * no-op. Coerces defensively: only the literal boolean `true` enables, and
31
- * any other value (missing, string, object) resolves to `false`.
42
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
43
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
44
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
45
+ * enables; any other value (missing, string, number, array, `{ enabled:
46
+ * false }`) resolves to `false`.
32
47
  *
33
48
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
34
49
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -37,4 +52,31 @@ export type HeadlessFeatureFlagsLookup = {
37
52
  * quote path.
38
53
  */
39
54
  export declare function isHeadlessAllProvidersEnabled(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): boolean;
55
+ /**
56
+ * The provider-id allowlist carried by the flag's object payload, or
57
+ * `undefined` when the widened pick should not be restricted.
58
+ *
59
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
60
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
61
+ * malformed payload, and empty or all-invalid lists all resolve to
62
+ * `undefined`; unknown keys and non-string entries are ignored.
63
+ *
64
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
65
+ * relevant subset of it). May be `null`/`undefined` before the controller is
66
+ * initialized.
67
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
68
+ * for no restriction.
69
+ */
70
+ export declare function getHeadlessProviderAllowlist(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string[] | undefined;
71
+ /**
72
+ * Normalizes a provider id for allowlist matching only: trims, strips the
73
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
74
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
75
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
76
+ * can use either id form. Not exported from the package index.
77
+ *
78
+ * @param id - A provider id in either the prefixed or bare form.
79
+ * @returns The normalized id used for allowlist comparison.
80
+ */
81
+ export declare function normalizeHeadlessProviderId(id: string): string;
40
82
  //# sourceMappingURL=featureFlags.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.d.cts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAMT"}
1
+ {"version":3,"file":"featureFlags.d.cts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAG7E;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAgEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAGT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,MAAM,EAAE,GAAG,SAAS,CAMtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAK9D"}
@@ -1,13 +1,29 @@
1
1
  import type { FeatureFlags } from "@metamask/remote-feature-flag-controller";
2
2
  /**
3
3
  * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers
4
- * expansion. A boolean flag: `true` widens the headless fiat quote path to
5
- * every provider class (native, in-app WebView aggregator, and
6
- * external-browser / custom-action); `false` or missing keeps the native-only
7
- * default. Exported so the flag registry and every consumer stay in sync on
8
- * the exact key string.
4
+ * expansion. Accepts two value forms:
5
+ *
6
+ * - The literal boolean `true` widens the headless fiat quote path to every
7
+ * provider class (native, in-app WebView aggregator, and external-browser /
8
+ * custom-action) with no provider restriction.
9
+ * - An object payload `{ enabled: true, featureVersion: "1", providerIds?: string[] }`
10
+ * widens the same way, and additionally restricts the widened quote pick to
11
+ * the listed provider ids (see {@link getHeadlessProviderAllowlist}).
12
+ *
13
+ * `false`, a missing flag, or any other value keeps the native-only default.
14
+ * Clients that only understand the boolean form coerce the object payload to
15
+ * "disabled" (native-only), so serving the object form can never turn the
16
+ * feature on for a client that cannot parse it. Exported so the flag registry
17
+ * and every consumer stay in sync on the exact key string.
9
18
  */
10
19
  export declare const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = "moneyHeadlessAllProviders";
20
+ /**
21
+ * Contract version of the object payload. An enabled payload whose
22
+ * `featureVersion` differs (or is absent) fails closed, so the payload's
23
+ * meaning can change in a future client without old clients misreading it.
24
+ * Mirrors the platform pattern used by `assetsUnifyState`.
25
+ */
26
+ export declare const HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = "1";
11
27
  /**
12
28
  * The subset of `RemoteFeatureFlagController` state that
13
29
  * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can
@@ -23,12 +39,11 @@ export type HeadlessFeatureFlagsLookup = {
23
39
  *
24
40
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
25
41
  * so the controller's quote widening and UI availability gates resolve the
26
- * flag identically. `localOverrides` (written by dev-only override screens)
27
- * are merged over `remoteFeatureFlags`, because not every published
28
- * `RemoteFeatureFlagController` version folds overrides into
29
- * `remoteFeatureFlags` state; when a version already does, the merge is a
30
- * no-op. Coerces defensively: only the literal boolean `true` enables, and
31
- * any other value (missing, string, object) resolves to `false`.
42
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
43
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
44
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
45
+ * enables; any other value (missing, string, number, array, `{ enabled:
46
+ * false }`) resolves to `false`.
32
47
  *
33
48
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
34
49
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -37,4 +52,31 @@ export type HeadlessFeatureFlagsLookup = {
37
52
  * quote path.
38
53
  */
39
54
  export declare function isHeadlessAllProvidersEnabled(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): boolean;
55
+ /**
56
+ * The provider-id allowlist carried by the flag's object payload, or
57
+ * `undefined` when the widened pick should not be restricted.
58
+ *
59
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
60
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
61
+ * malformed payload, and empty or all-invalid lists all resolve to
62
+ * `undefined`; unknown keys and non-string entries are ignored.
63
+ *
64
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
65
+ * relevant subset of it). May be `null`/`undefined` before the controller is
66
+ * initialized.
67
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
68
+ * for no restriction.
69
+ */
70
+ export declare function getHeadlessProviderAllowlist(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string[] | undefined;
71
+ /**
72
+ * Normalizes a provider id for allowlist matching only: trims, strips the
73
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
74
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
75
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
76
+ * can use either id form. Not exported from the package index.
77
+ *
78
+ * @param id - A provider id in either the prefixed or bare form.
79
+ * @returns The normalized id used for allowlist comparison.
80
+ */
81
+ export declare function normalizeHeadlessProviderId(id: string): string;
40
82
  //# sourceMappingURL=featureFlags.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.d.mts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAMT"}
1
+ {"version":3,"file":"featureFlags.d.mts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAG7E;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAgEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAGT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,MAAM,EAAE,GAAG,SAAS,CAMtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAK9D"}
@@ -1,23 +1,91 @@
1
1
  /**
2
2
  * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers
3
- * expansion. A boolean flag: `true` widens the headless fiat quote path to
4
- * every provider class (native, in-app WebView aggregator, and
5
- * external-browser / custom-action); `false` or missing keeps the native-only
6
- * default. Exported so the flag registry and every consumer stay in sync on
7
- * the exact key string.
3
+ * expansion. Accepts two value forms:
4
+ *
5
+ * - The literal boolean `true` widens the headless fiat quote path to every
6
+ * provider class (native, in-app WebView aggregator, and external-browser /
7
+ * custom-action) with no provider restriction.
8
+ * - An object payload `{ enabled: true, featureVersion: "1", providerIds?: string[] }`
9
+ * widens the same way, and additionally restricts the widened quote pick to
10
+ * the listed provider ids (see {@link getHeadlessProviderAllowlist}).
11
+ *
12
+ * `false`, a missing flag, or any other value keeps the native-only default.
13
+ * Clients that only understand the boolean form coerce the object payload to
14
+ * "disabled" (native-only), so serving the object form can never turn the
15
+ * feature on for a client that cannot parse it. Exported so the flag registry
16
+ * and every consumer stay in sync on the exact key string.
8
17
  */
9
18
  export const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders';
19
+ /**
20
+ * Contract version of the object payload. An enabled payload whose
21
+ * `featureVersion` differs (or is absent) fails closed, so the payload's
22
+ * meaning can change in a future client without old clients misreading it.
23
+ * Mirrors the platform pattern used by `assetsUnifyState`.
24
+ */
25
+ export const HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = '1';
26
+ /**
27
+ * Resolves the flag value with `localOverrides` (written by dev-only override
28
+ * screens) merged over `remoteFeatureFlags`, because not every published
29
+ * `RemoteFeatureFlagController` version folds overrides into
30
+ * `remoteFeatureFlags` state; when a version already does, the merge is a
31
+ * no-op.
32
+ *
33
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
34
+ * relevant subset of it).
35
+ * @returns The merged flag value, or `undefined` when absent.
36
+ */
37
+ function resolveFlagValue(remoteFeatureFlagState) {
38
+ const flags = {
39
+ ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
40
+ ...(remoteFeatureFlagState?.localOverrides ?? {}),
41
+ };
42
+ return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY];
43
+ }
44
+ /**
45
+ * Whether a flag value is the object payload form: a plain object (not an
46
+ * array) whose `enabled` is the literal boolean `true`. Anything else,
47
+ * including `{ enabled: false }` and objects without `enabled`, is not an
48
+ * enabled payload, so the flag fails closed.
49
+ *
50
+ * @param value - The merged flag value.
51
+ * @returns Whether the value is an enabled object payload.
52
+ */
53
+ function isEnabledPayload(value) {
54
+ return (typeof value === 'object' &&
55
+ value !== null &&
56
+ !Array.isArray(value) &&
57
+ value.enabled === true &&
58
+ value.featureVersion === HEADLESS_ALL_PROVIDERS_FEATURE_VERSION);
59
+ }
60
+ /**
61
+ * Coerces a payload field into a provider-id list: keeps only string entries,
62
+ * trims them, and drops empties. An empty or malformed level is treated as
63
+ * "not provided" so resolution falls through to the next level rather than
64
+ * restricting to nothing; to force "nothing eligible" list a nonexistent id.
65
+ *
66
+ * @param value - The candidate `providerIds` / surface entry value.
67
+ * @returns The non-empty coerced list, or `undefined`.
68
+ */
69
+ function coerceProviderIdList(value) {
70
+ if (!Array.isArray(value)) {
71
+ return undefined;
72
+ }
73
+ const ids = value
74
+ .filter((entry) => typeof entry === 'string')
75
+ .map((entry) => entry.trim())
76
+ .filter((entry) => entry !== '');
77
+ return ids.length > 0 ? ids : undefined;
78
+ }
10
79
  /**
11
80
  * Whether the Headless Buy all-providers feature flag is enabled.
12
81
  *
13
82
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
14
83
  * so the controller's quote widening and UI availability gates resolve the
15
- * flag identically. `localOverrides` (written by dev-only override screens)
16
- * are merged over `remoteFeatureFlags`, because not every published
17
- * `RemoteFeatureFlagController` version folds overrides into
18
- * `remoteFeatureFlags` state; when a version already does, the merge is a
19
- * no-op. Coerces defensively: only the literal boolean `true` enables, and
20
- * any other value (missing, string, object) resolves to `false`.
84
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
85
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
86
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
87
+ * enables; any other value (missing, string, number, array, `{ enabled:
88
+ * false }`) resolves to `false`.
21
89
  *
22
90
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
23
91
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -26,10 +94,45 @@ export const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders'
26
94
  * quote path.
27
95
  */
28
96
  export function isHeadlessAllProvidersEnabled(remoteFeatureFlagState) {
29
- const flags = {
30
- ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
31
- ...(remoteFeatureFlagState?.localOverrides ?? {}),
32
- };
33
- return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;
97
+ const value = resolveFlagValue(remoteFeatureFlagState);
98
+ return value === true || isEnabledPayload(value);
99
+ }
100
+ /**
101
+ * The provider-id allowlist carried by the flag's object payload, or
102
+ * `undefined` when the widened pick should not be restricted.
103
+ *
104
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
105
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
106
+ * malformed payload, and empty or all-invalid lists all resolve to
107
+ * `undefined`; unknown keys and non-string entries are ignored.
108
+ *
109
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
110
+ * relevant subset of it). May be `null`/`undefined` before the controller is
111
+ * initialized.
112
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
113
+ * for no restriction.
114
+ */
115
+ export function getHeadlessProviderAllowlist(remoteFeatureFlagState) {
116
+ const value = resolveFlagValue(remoteFeatureFlagState);
117
+ if (!isEnabledPayload(value)) {
118
+ return undefined;
119
+ }
120
+ return coerceProviderIdList(value.providerIds);
121
+ }
122
+ /**
123
+ * Normalizes a provider id for allowlist matching only: trims, strips the
124
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
125
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
126
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
127
+ * can use either id form. Not exported from the package index.
128
+ *
129
+ * @param id - A provider id in either the prefixed or bare form.
130
+ * @returns The normalized id used for allowlist comparison.
131
+ */
132
+ export function normalizeHeadlessProviderId(id) {
133
+ return id
134
+ .trim()
135
+ .replace(/^\/providers\//u, '')
136
+ .toLowerCase();
34
137
  }
35
138
  //# sourceMappingURL=featureFlags.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.mjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAChD,2BAA2B,CAAC;AAa9B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,sBAAqE;IAErE,MAAM,KAAK,GAAiB;QAC1B,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,IAAI,EAAE,CAAC;QACrD,GAAG,CAAC,sBAAsB,EAAE,cAAc,IAAI,EAAE,CAAC;KAClD,CAAC;IACF,OAAO,KAAK,CAAC,qCAAqC,CAAC,KAAK,IAAI,CAAC;AAC/D,CAAC","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\n\n/**\n * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers\n * expansion. A boolean flag: `true` widens the headless fiat quote path to\n * every provider class (native, in-app WebView aggregator, and\n * external-browser / custom-action); `false` or missing keeps the native-only\n * default. Exported so the flag registry and every consumer stay in sync on\n * the exact key string.\n */\nexport const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY =\n 'moneyHeadlessAllProviders';\n\n/**\n * The subset of `RemoteFeatureFlagController` state that\n * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can\n * pass the whole controller state (or `undefined` before initialization)\n * without depending on a specific controller version.\n */\nexport type HeadlessFeatureFlagsLookup = {\n remoteFeatureFlags?: FeatureFlags;\n localOverrides?: FeatureFlags;\n};\n\n/**\n * Whether the Headless Buy all-providers feature flag is enabled.\n *\n * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}\n * so the controller's quote widening and UI availability gates resolve the\n * flag identically. `localOverrides` (written by dev-only override screens)\n * are merged over `remoteFeatureFlags`, because not every published\n * `RemoteFeatureFlagController` version folds overrides into\n * `remoteFeatureFlags` state; when a version already does, the merge is a\n * no-op. Coerces defensively: only the literal boolean `true` enables, and\n * any other value (missing, string, object) resolves to `false`.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns Whether all provider classes are enabled for the headless fiat\n * quote path.\n */\nexport function isHeadlessAllProvidersEnabled(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): boolean {\n const flags: FeatureFlags = {\n ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),\n ...(remoteFeatureFlagState?.localOverrides ?? {}),\n };\n return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;\n}\n"]}
1
+ {"version":3,"file":"featureFlags.mjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAChD,2BAA2B,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAa1D;;;;;;;;;;GAUG;AACH,SAAS,gBAAgB,CACvB,sBAAqE;IAErE,MAAM,KAAK,GAAiB;QAC1B,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,IAAI,EAAE,CAAC;QACrD,GAAG,CAAC,sBAAsB,EAAE,cAAc,IAAI,EAAE,CAAC;KAClD,CAAC;IACF,OAAO,KAAK,CAAC,qCAAqC,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,KAAuB;IAG/C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,KAAK,CAAC,OAAO,KAAK,IAAI;QACtB,KAAK,CAAC,cAAc,KAAK,sCAAsC,CAChE,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAAC,KAAuB;IACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,GAAG,GAAG,KAAK;SACd,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;SAC7D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;IACnC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,sBAAqE;IAErE,MAAM,KAAK,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACvD,OAAO,KAAK,KAAK,IAAI,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,4BAA4B,CAC1C,sBAAqE;IAErE,MAAM,KAAK,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACvD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAU;IACpD,OAAO,EAAE;SACN,IAAI,EAAE;SACN,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,WAAW,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Remote (LaunchDarkly) feature flag key for the Headless Buy all-providers\n * expansion. Accepts two value forms:\n *\n * - The literal boolean `true` widens the headless fiat quote path to every\n * provider class (native, in-app WebView aggregator, and external-browser /\n * custom-action) with no provider restriction.\n * - An object payload `{ enabled: true, featureVersion: \"1\", providerIds?: string[] }`\n * widens the same way, and additionally restricts the widened quote pick to\n * the listed provider ids (see {@link getHeadlessProviderAllowlist}).\n *\n * `false`, a missing flag, or any other value keeps the native-only default.\n * Clients that only understand the boolean form coerce the object payload to\n * \"disabled\" (native-only), so serving the object form can never turn the\n * feature on for a client that cannot parse it. Exported so the flag registry\n * and every consumer stay in sync on the exact key string.\n */\nexport const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY =\n 'moneyHeadlessAllProviders';\n\n/**\n * Contract version of the object payload. An enabled payload whose\n * `featureVersion` differs (or is absent) fails closed, so the payload's\n * meaning can change in a future client without old clients misreading it.\n * Mirrors the platform pattern used by `assetsUnifyState`.\n */\nexport const HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = '1';\n\n/**\n * The subset of `RemoteFeatureFlagController` state that\n * {@link isHeadlessAllProvidersEnabled} reads. Structural so consumers can\n * pass the whole controller state (or `undefined` before initialization)\n * without depending on a specific controller version.\n */\nexport type HeadlessFeatureFlagsLookup = {\n remoteFeatureFlags?: FeatureFlags;\n localOverrides?: FeatureFlags;\n};\n\n/**\n * Resolves the flag value with `localOverrides` (written by dev-only override\n * screens) merged over `remoteFeatureFlags`, because not every published\n * `RemoteFeatureFlagController` version folds overrides into\n * `remoteFeatureFlags` state; when a version already does, the merge is a\n * no-op.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it).\n * @returns The merged flag value, or `undefined` when absent.\n */\nfunction resolveFlagValue(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): Json | undefined {\n const flags: FeatureFlags = {\n ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),\n ...(remoteFeatureFlagState?.localOverrides ?? {}),\n };\n return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY];\n}\n\n/**\n * Whether a flag value is the object payload form: a plain object (not an\n * array) whose `enabled` is the literal boolean `true`. Anything else,\n * including `{ enabled: false }` and objects without `enabled`, is not an\n * enabled payload, so the flag fails closed.\n *\n * @param value - The merged flag value.\n * @returns Whether the value is an enabled object payload.\n */\nfunction isEnabledPayload(value: Json | undefined): value is {\n [key: string]: Json;\n} {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n value.enabled === true &&\n value.featureVersion === HEADLESS_ALL_PROVIDERS_FEATURE_VERSION\n );\n}\n\n/**\n * Coerces a payload field into a provider-id list: keeps only string entries,\n * trims them, and drops empties. An empty or malformed level is treated as\n * \"not provided\" so resolution falls through to the next level rather than\n * restricting to nothing; to force \"nothing eligible\" list a nonexistent id.\n *\n * @param value - The candidate `providerIds` / surface entry value.\n * @returns The non-empty coerced list, or `undefined`.\n */\nfunction coerceProviderIdList(value: Json | undefined): string[] | undefined {\n if (!Array.isArray(value)) {\n return undefined;\n }\n const ids = value\n .filter((entry): entry is string => typeof entry === 'string')\n .map((entry) => entry.trim())\n .filter((entry) => entry !== '');\n return ids.length > 0 ? ids : undefined;\n}\n\n/**\n * Whether the Headless Buy all-providers feature flag is enabled.\n *\n * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}\n * so the controller's quote widening and UI availability gates resolve the\n * flag identically. `localOverrides` are merged over `remoteFeatureFlags`\n * (see {@link resolveFlagValue}). Coerces defensively: only the literal\n * boolean `true` or an object payload whose `enabled` is the literal `true`\n * enables; any other value (missing, string, number, array, `{ enabled:\n * false }`) resolves to `false`.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns Whether all provider classes are enabled for the headless fiat\n * quote path.\n */\nexport function isHeadlessAllProvidersEnabled(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): boolean {\n const value = resolveFlagValue(remoteFeatureFlagState);\n return value === true || isEnabledPayload(value);\n}\n\n/**\n * The provider-id allowlist carried by the flag's object payload, or\n * `undefined` when the widened pick should not be restricted.\n *\n * Returns the payload's top-level `providerIds` when non-empty and valid, or\n * `undefined` (no restriction). The boolean `true` form, a disabled or\n * malformed payload, and empty or all-invalid lists all resolve to\n * `undefined`; unknown keys and non-string entries are ignored.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @returns The provider ids the widened pick is restricted to, or `undefined`\n * for no restriction.\n */\nexport function getHeadlessProviderAllowlist(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n return coerceProviderIdList(value.providerIds);\n}\n\n/**\n * Normalizes a provider id for allowlist matching only: trims, strips the\n * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`\n * and `moonpay` match each other. Quote and catalog provider ids are matched\n * as-is everywhere else; this exists solely so LaunchDarkly payload authors\n * can use either id form. Not exported from the package index.\n *\n * @param id - A provider id in either the prefixed or bare form.\n * @returns The normalized id used for allowlist comparison.\n */\nexport function normalizeHeadlessProviderId(id: string): string {\n return id\n .trim()\n .replace(/^\\/providers\\//u, '')\n .toLowerCase();\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTransakPhoneRegisteredError = exports.getTransakApiMessage = exports.TransakOrderIdTransformer = exports.TransakEnvironment = exports.TransakService = exports.TransakApiError = exports.normalizeToTypedError = exports.extractExplicitTypedError = exports.getErrorMessage = exports.isInAppOnlyQuote = exports.isCustomActionQuote = exports.isExternalBrowserQuote = exports.isFiatDepositAvailable = exports.regionHasProviderForAsset = exports.getProvidersServingAsset = exports.providerServesAsset = exports.isHeadlessAllProvidersEnabled = exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = exports.createRequestSelector = exports.RAMPS_ERROR_CODES = exports.createErrorState = exports.createSuccessState = exports.createLoadingState = exports.isCacheExpired = exports.createCacheKey = exports.DEFAULT_REQUEST_CACHE_MAX_SIZE = exports.DEFAULT_REQUEST_CACHE_TTL = exports.RequestStatus = exports.RAMPS_SDK_VERSION = exports.RampsOrderStatus = exports.RampsApiService = exports.RampsEnvironment = exports.RampsService = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RampsController = void 0;
3
+ exports.isTransakPhoneRegisteredError = exports.getTransakApiMessage = exports.TransakOrderIdTransformer = exports.TransakEnvironment = exports.TransakService = exports.TransakApiError = exports.normalizeToTypedError = exports.extractExplicitTypedError = exports.getErrorMessage = exports.isInAppOnlyQuote = exports.isCustomActionQuote = exports.isExternalBrowserQuote = exports.isFiatDepositAvailable = exports.regionHasProviderForAsset = exports.getProvidersServingAsset = exports.providerServesAsset = exports.isHeadlessAllProvidersEnabled = exports.getHeadlessProviderAllowlist = exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = exports.HEADLESS_ALL_PROVIDERS_FEATURE_VERSION = exports.createRequestSelector = exports.RAMPS_ERROR_CODES = exports.createErrorState = exports.createSuccessState = exports.createLoadingState = exports.isCacheExpired = exports.createCacheKey = exports.DEFAULT_REQUEST_CACHE_MAX_SIZE = exports.DEFAULT_REQUEST_CACHE_TTL = exports.RequestStatus = exports.RAMPS_SDK_VERSION = exports.RampsOrderStatus = exports.RampsApiService = exports.RampsEnvironment = exports.RampsService = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RampsController = void 0;
4
4
  var RampsController_js_1 = require("./RampsController.cjs");
5
5
  Object.defineProperty(exports, "RampsController", { enumerable: true, get: function () { return RampsController_js_1.RampsController; } });
6
6
  Object.defineProperty(exports, "getDefaultRampsControllerState", { enumerable: true, get: function () { return RampsController_js_1.getDefaultRampsControllerState; } });
@@ -26,7 +26,9 @@ Object.defineProperty(exports, "RAMPS_ERROR_CODES", { enumerable: true, get: fun
26
26
  var selectors_js_1 = require("./selectors.cjs");
27
27
  Object.defineProperty(exports, "createRequestSelector", { enumerable: true, get: function () { return selectors_js_1.createRequestSelector; } });
28
28
  var featureFlags_js_1 = require("./featureFlags.cjs");
29
+ Object.defineProperty(exports, "HEADLESS_ALL_PROVIDERS_FEATURE_VERSION", { enumerable: true, get: function () { return featureFlags_js_1.HEADLESS_ALL_PROVIDERS_FEATURE_VERSION; } });
29
30
  Object.defineProperty(exports, "MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY", { enumerable: true, get: function () { return featureFlags_js_1.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY; } });
31
+ Object.defineProperty(exports, "getHeadlessProviderAllowlist", { enumerable: true, get: function () { return featureFlags_js_1.getHeadlessProviderAllowlist; } });
30
32
  Object.defineProperty(exports, "isHeadlessAllProvidersEnabled", { enumerable: true, get: function () { return featureFlags_js_1.isHeadlessAllProvidersEnabled; } });
31
33
  var providerAvailability_js_1 = require("./providerAvailability.cjs");
32
34
  Object.defineProperty(exports, "providerServesAsset", { enumerable: true, get: function () { return providerAvailability_js_1.providerServesAsset; } });