@metamask/ramps-controller 17.1.0 → 17.2.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,116 @@
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.getHeadlessAllProvidersMinimumVersion = 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
+ * The `minimumVersion` carried by an enabled payload, or `undefined` for the
65
+ * boolean form, a disabled payload, or a malformed field. This package cannot
66
+ * compare app versions itself; mobile validates the value through its shared
67
+ * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`
68
+ * wrapper provides the server-side gate.
69
+ *
70
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
71
+ * relevant subset of it).
72
+ * @returns The minimum app version the payload declares, or `undefined`.
73
+ */
74
+ function getHeadlessAllProvidersMinimumVersion(remoteFeatureFlagState) {
75
+ const value = resolveFlagValue(remoteFeatureFlagState);
76
+ if (!isEnabledPayload(value)) {
77
+ return undefined;
78
+ }
79
+ const { minimumVersion } = value;
80
+ return typeof minimumVersion === 'string' && minimumVersion.trim() !== ''
81
+ ? minimumVersion
82
+ : undefined;
83
+ }
84
+ exports.getHeadlessAllProvidersMinimumVersion = getHeadlessAllProvidersMinimumVersion;
85
+ /**
86
+ * Coerces a payload field into a provider-id list: keeps only string entries,
87
+ * trims them, and drops empties. An empty or malformed level is treated as
88
+ * "not provided" so resolution falls through to the next level rather than
89
+ * restricting to nothing; to force "nothing eligible" list a nonexistent id.
90
+ *
91
+ * @param value - The candidate `providerIds` / surface entry value.
92
+ * @returns The non-empty coerced list, or `undefined`.
93
+ */
94
+ function coerceProviderIdList(value) {
95
+ if (!Array.isArray(value)) {
96
+ return undefined;
97
+ }
98
+ const ids = value
99
+ .filter((entry) => typeof entry === 'string')
100
+ .map((entry) => entry.trim())
101
+ .filter((entry) => entry !== '');
102
+ return ids.length > 0 ? ids : undefined;
103
+ }
13
104
  /**
14
105
  * Whether the Headless Buy all-providers feature flag is enabled.
15
106
  *
16
107
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
17
108
  * 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`.
109
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
110
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
111
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
112
+ * enables; any other value (missing, string, number, array, `{ enabled:
113
+ * false }`) resolves to `false`.
24
114
  *
25
115
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
26
116
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -29,11 +119,48 @@ exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders';
29
119
  * quote path.
30
120
  */
31
121
  function isHeadlessAllProvidersEnabled(remoteFeatureFlagState) {
32
- const flags = {
33
- ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
34
- ...(remoteFeatureFlagState?.localOverrides ?? {}),
35
- };
36
- return flags[exports.MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;
122
+ const value = resolveFlagValue(remoteFeatureFlagState);
123
+ return value === true || isEnabledPayload(value);
37
124
  }
38
125
  exports.isHeadlessAllProvidersEnabled = isHeadlessAllProvidersEnabled;
126
+ /**
127
+ * The provider-id allowlist carried by the flag's object payload, or
128
+ * `undefined` when the widened pick should not be restricted.
129
+ *
130
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
131
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
132
+ * malformed payload, and empty or all-invalid lists all resolve to
133
+ * `undefined`; unknown keys and non-string entries are ignored.
134
+ *
135
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
136
+ * relevant subset of it). May be `null`/`undefined` before the controller is
137
+ * initialized.
138
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
139
+ * for no restriction.
140
+ */
141
+ function getHeadlessProviderAllowlist(remoteFeatureFlagState) {
142
+ const value = resolveFlagValue(remoteFeatureFlagState);
143
+ if (!isEnabledPayload(value)) {
144
+ return undefined;
145
+ }
146
+ return coerceProviderIdList(value.providerIds);
147
+ }
148
+ exports.getHeadlessProviderAllowlist = getHeadlessProviderAllowlist;
149
+ /**
150
+ * Normalizes a provider id for allowlist matching only: trims, strips the
151
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
152
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
153
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
154
+ * can use either id form. Not exported from the package index.
155
+ *
156
+ * @param id - A provider id in either the prefixed or bare form.
157
+ * @returns The normalized id used for allowlist comparison.
158
+ */
159
+ function normalizeHeadlessProviderId(id) {
160
+ return id
161
+ .trim()
162
+ .replace(/^\/providers\//u, '')
163
+ .toLowerCase();
164
+ }
165
+ exports.normalizeHeadlessProviderId = normalizeHeadlessProviderId;
39
166
  //# 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;;;;;;;;;;GAUG;AACH,SAAgB,qCAAqC,CACnD,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,MAAM,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IACjC,OAAO,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE;QACvE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAXD,sFAWC;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 * The `minimumVersion` carried by an enabled payload, or `undefined` for the\n * boolean form, a disabled payload, or a malformed field. This package cannot\n * compare app versions itself; mobile validates the value through its shared\n * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`\n * wrapper provides the server-side gate.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it).\n * @returns The minimum app version the payload declares, or `undefined`.\n */\nexport function getHeadlessAllProvidersMinimumVersion(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): string | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n const { minimumVersion } = value;\n return typeof minimumVersion === 'string' && minimumVersion.trim() !== ''\n ? minimumVersion\n : undefined;\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
@@ -18,17 +34,28 @@ export type HeadlessFeatureFlagsLookup = {
18
34
  remoteFeatureFlags?: FeatureFlags;
19
35
  localOverrides?: FeatureFlags;
20
36
  };
37
+ /**
38
+ * The `minimumVersion` carried by an enabled payload, or `undefined` for the
39
+ * boolean form, a disabled payload, or a malformed field. This package cannot
40
+ * compare app versions itself; mobile validates the value through its shared
41
+ * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`
42
+ * wrapper provides the server-side gate.
43
+ *
44
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
45
+ * relevant subset of it).
46
+ * @returns The minimum app version the payload declares, or `undefined`.
47
+ */
48
+ export declare function getHeadlessAllProvidersMinimumVersion(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string | undefined;
21
49
  /**
22
50
  * Whether the Headless Buy all-providers feature flag is enabled.
23
51
  *
24
52
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
25
53
  * 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`.
54
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
55
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
56
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
57
+ * enables; any other value (missing, string, number, array, `{ enabled:
58
+ * false }`) resolves to `false`.
32
59
  *
33
60
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
34
61
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -37,4 +64,31 @@ export type HeadlessFeatureFlagsLookup = {
37
64
  * quote path.
38
65
  */
39
66
  export declare function isHeadlessAllProvidersEnabled(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): boolean;
67
+ /**
68
+ * The provider-id allowlist carried by the flag's object payload, or
69
+ * `undefined` when the widened pick should not be restricted.
70
+ *
71
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
72
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
73
+ * malformed payload, and empty or all-invalid lists all resolve to
74
+ * `undefined`; unknown keys and non-string entries are ignored.
75
+ *
76
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
77
+ * relevant subset of it). May be `null`/`undefined` before the controller is
78
+ * initialized.
79
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
80
+ * for no restriction.
81
+ */
82
+ export declare function getHeadlessProviderAllowlist(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string[] | undefined;
83
+ /**
84
+ * Normalizes a provider id for allowlist matching only: trims, strips the
85
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
86
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
87
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
88
+ * can use either id form. Not exported from the package index.
89
+ *
90
+ * @param id - A provider id in either the prefixed or bare form.
91
+ * @returns The normalized id used for allowlist comparison.
92
+ */
93
+ export declare function normalizeHeadlessProviderId(id: string): string;
40
94
  //# 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;AA4CF;;;;;;;;;;GAUG;AACH,wBAAgB,qCAAqC,CACnD,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,MAAM,GAAG,SAAS,CASpB;AAsBD;;;;;;;;;;;;;;;;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
@@ -18,17 +34,28 @@ export type HeadlessFeatureFlagsLookup = {
18
34
  remoteFeatureFlags?: FeatureFlags;
19
35
  localOverrides?: FeatureFlags;
20
36
  };
37
+ /**
38
+ * The `minimumVersion` carried by an enabled payload, or `undefined` for the
39
+ * boolean form, a disabled payload, or a malformed field. This package cannot
40
+ * compare app versions itself; mobile validates the value through its shared
41
+ * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`
42
+ * wrapper provides the server-side gate.
43
+ *
44
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
45
+ * relevant subset of it).
46
+ * @returns The minimum app version the payload declares, or `undefined`.
47
+ */
48
+ export declare function getHeadlessAllProvidersMinimumVersion(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string | undefined;
21
49
  /**
22
50
  * Whether the Headless Buy all-providers feature flag is enabled.
23
51
  *
24
52
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
25
53
  * 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`.
54
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
55
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
56
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
57
+ * enables; any other value (missing, string, number, array, `{ enabled:
58
+ * false }`) resolves to `false`.
32
59
  *
33
60
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
34
61
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -37,4 +64,31 @@ export type HeadlessFeatureFlagsLookup = {
37
64
  * quote path.
38
65
  */
39
66
  export declare function isHeadlessAllProvidersEnabled(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): boolean;
67
+ /**
68
+ * The provider-id allowlist carried by the flag's object payload, or
69
+ * `undefined` when the widened pick should not be restricted.
70
+ *
71
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
72
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
73
+ * malformed payload, and empty or all-invalid lists all resolve to
74
+ * `undefined`; unknown keys and non-string entries are ignored.
75
+ *
76
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
77
+ * relevant subset of it). May be `null`/`undefined` before the controller is
78
+ * initialized.
79
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
80
+ * for no restriction.
81
+ */
82
+ export declare function getHeadlessProviderAllowlist(remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined): string[] | undefined;
83
+ /**
84
+ * Normalizes a provider id for allowlist matching only: trims, strips the
85
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
86
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
87
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
88
+ * can use either id form. Not exported from the package index.
89
+ *
90
+ * @param id - A provider id in either the prefixed or bare form.
91
+ * @returns The normalized id used for allowlist comparison.
92
+ */
93
+ export declare function normalizeHeadlessProviderId(id: string): string;
40
94
  //# 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;AA4CF;;;;;;;;;;GAUG;AACH,wBAAgB,qCAAqC,CACnD,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,MAAM,GAAG,SAAS,CASpB;AAsBD;;;;;;;;;;;;;;;;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,112 @@
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
+ * The `minimumVersion` carried by an enabled payload, or `undefined` for the
62
+ * boolean form, a disabled payload, or a malformed field. This package cannot
63
+ * compare app versions itself; mobile validates the value through its shared
64
+ * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`
65
+ * wrapper provides the server-side gate.
66
+ *
67
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
68
+ * relevant subset of it).
69
+ * @returns The minimum app version the payload declares, or `undefined`.
70
+ */
71
+ export function getHeadlessAllProvidersMinimumVersion(remoteFeatureFlagState) {
72
+ const value = resolveFlagValue(remoteFeatureFlagState);
73
+ if (!isEnabledPayload(value)) {
74
+ return undefined;
75
+ }
76
+ const { minimumVersion } = value;
77
+ return typeof minimumVersion === 'string' && minimumVersion.trim() !== ''
78
+ ? minimumVersion
79
+ : undefined;
80
+ }
81
+ /**
82
+ * Coerces a payload field into a provider-id list: keeps only string entries,
83
+ * trims them, and drops empties. An empty or malformed level is treated as
84
+ * "not provided" so resolution falls through to the next level rather than
85
+ * restricting to nothing; to force "nothing eligible" list a nonexistent id.
86
+ *
87
+ * @param value - The candidate `providerIds` / surface entry value.
88
+ * @returns The non-empty coerced list, or `undefined`.
89
+ */
90
+ function coerceProviderIdList(value) {
91
+ if (!Array.isArray(value)) {
92
+ return undefined;
93
+ }
94
+ const ids = value
95
+ .filter((entry) => typeof entry === 'string')
96
+ .map((entry) => entry.trim())
97
+ .filter((entry) => entry !== '');
98
+ return ids.length > 0 ? ids : undefined;
99
+ }
10
100
  /**
11
101
  * Whether the Headless Buy all-providers feature flag is enabled.
12
102
  *
13
103
  * Owns the key lookup and coercion for {@link MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY}
14
104
  * 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`.
105
+ * flag identically. `localOverrides` are merged over `remoteFeatureFlags`
106
+ * (see {@link resolveFlagValue}). Coerces defensively: only the literal
107
+ * boolean `true` or an object payload whose `enabled` is the literal `true`
108
+ * enables; any other value (missing, string, number, array, `{ enabled:
109
+ * false }`) resolves to `false`.
21
110
  *
22
111
  * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
23
112
  * relevant subset of it). May be `null`/`undefined` before the controller is
@@ -26,10 +115,45 @@ export const MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY = 'moneyHeadlessAllProviders'
26
115
  * quote path.
27
116
  */
28
117
  export function isHeadlessAllProvidersEnabled(remoteFeatureFlagState) {
29
- const flags = {
30
- ...(remoteFeatureFlagState?.remoteFeatureFlags ?? {}),
31
- ...(remoteFeatureFlagState?.localOverrides ?? {}),
32
- };
33
- return flags[MONEY_HEADLESS_ALL_PROVIDERS_FLAG_KEY] === true;
118
+ const value = resolveFlagValue(remoteFeatureFlagState);
119
+ return value === true || isEnabledPayload(value);
120
+ }
121
+ /**
122
+ * The provider-id allowlist carried by the flag's object payload, or
123
+ * `undefined` when the widened pick should not be restricted.
124
+ *
125
+ * Returns the payload's top-level `providerIds` when non-empty and valid, or
126
+ * `undefined` (no restriction). The boolean `true` form, a disabled or
127
+ * malformed payload, and empty or all-invalid lists all resolve to
128
+ * `undefined`; unknown keys and non-string entries are ignored.
129
+ *
130
+ * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the
131
+ * relevant subset of it). May be `null`/`undefined` before the controller is
132
+ * initialized.
133
+ * @returns The provider ids the widened pick is restricted to, or `undefined`
134
+ * for no restriction.
135
+ */
136
+ export function getHeadlessProviderAllowlist(remoteFeatureFlagState) {
137
+ const value = resolveFlagValue(remoteFeatureFlagState);
138
+ if (!isEnabledPayload(value)) {
139
+ return undefined;
140
+ }
141
+ return coerceProviderIdList(value.providerIds);
142
+ }
143
+ /**
144
+ * Normalizes a provider id for allowlist matching only: trims, strips the
145
+ * canonical `/providers/` path prefix, and lowercases, so `/providers/moonpay`
146
+ * and `moonpay` match each other. Quote and catalog provider ids are matched
147
+ * as-is everywhere else; this exists solely so LaunchDarkly payload authors
148
+ * can use either id form. Not exported from the package index.
149
+ *
150
+ * @param id - A provider id in either the prefixed or bare form.
151
+ * @returns The normalized id used for allowlist comparison.
152
+ */
153
+ export function normalizeHeadlessProviderId(id) {
154
+ return id
155
+ .trim()
156
+ .replace(/^\/providers\//u, '')
157
+ .toLowerCase();
34
158
  }
35
159
  //# 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;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qCAAqC,CACnD,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,MAAM,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IACjC,OAAO,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE;QACvE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,SAAS,CAAC;AAChB,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 * The `minimumVersion` carried by an enabled payload, or `undefined` for the\n * boolean form, a disabled payload, or a malformed field. This package cannot\n * compare app versions itself; mobile validates the value through its shared\n * `validatedVersionGatedFeatureFlag` util, and the LaunchDarkly `versions`\n * wrapper provides the server-side gate.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it).\n * @returns The minimum app version the payload declares, or `undefined`.\n */\nexport function getHeadlessAllProvidersMinimumVersion(\n remoteFeatureFlagState: HeadlessFeatureFlagsLookup | null | undefined,\n): string | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n const { minimumVersion } = value;\n return typeof minimumVersion === 'string' && minimumVersion.trim() !== ''\n ? minimumVersion\n : undefined;\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"]}