@metamask-previews/ramps-controller 17.0.0-preview-6f52159 → 17.0.0-preview-1ccf11bcb

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.
@@ -160,7 +160,10 @@ exports.getHeadlessProviderAllowlist = getHeadlessProviderAllowlist;
160
160
  * @returns The normalized id used for allowlist comparison.
161
161
  */
162
162
  function normalizeHeadlessProviderId(id) {
163
- return id.trim().replace(/^\/providers\//u, '').toLowerCase();
163
+ return id
164
+ .trim()
165
+ .replace(/^\/providers\//u, '')
166
+ .toLowerCase();
164
167
  }
165
168
  exports.normalizeHeadlessProviderId = normalizeHeadlessProviderId;
166
169
  //# sourceMappingURL=featureFlags.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.cjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,qCAAqC,GAChD,2BAA2B,CAAC;AAE9B;;;;GAIG;AACU,QAAA,2BAA2B,GAAG;IACzC,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAClB,CAAC;AAmBX;;;;;;;;;;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,CACvB,CAAC;AACJ,CAAC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AG,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAxBD,oEAwBC;AAED;;;;;;;;;GASG;AACH,SAAgB,2BAA2B,CAAC,EAAU;IACpD,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAChE,CAAC;AAFD,kEAEC","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, providerIds?: string[], surfaces?:\n * Record<string, string[]> }` widens the same way, and additionally\n * restricts the widened quote pick to the listed provider ids (see\n * {@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 * Canonical surface keys accepted in the flag payload's `surfaces` map. A\n * surface entry overrides the top-level `providerIds` list for quote requests\n * tagged with that surface.\n */\nexport const HEADLESS_ALLOWLIST_SURFACES = {\n MONEY: 'money',\n PERPS: 'perps',\n PREDICTIONS: 'predictions',\n} as const;\n\n/**\n * A canonical surface key of the flag payload's `surfaces` map.\n */\nexport type HeadlessAllowlistSurface =\n (typeof HEADLESS_ALLOWLIST_SURFACES)[keyof typeof HEADLESS_ALLOWLIST_SURFACES];\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 );\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 * Resolution, most specific first:\n *\n * 1. When `surface` is given and the payload's `surfaces[surface]` is a\n * non-empty valid list, that list wins.\n * 2. Otherwise the payload's top-level `providerIds`, when non-empty and\n * valid.\n * 3. Otherwise `undefined` (no restriction). The boolean `true` form, a\n * disabled or malformed payload, and empty or all-invalid lists all land\n * here; unknown keys and non-string entries are ignored.\n *\n * Note that `surfaces` entries only apply to quote requests tagged with a\n * `surface`; a request without one (for example MM Pay's `getRampsQuote`)\n * resolves the top-level `providerIds` list only.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @param surface - Optional consumer surface key; canonical values are the\n * {@link HEADLESS_ALLOWLIST_SURFACES} members.\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 surface?: string,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n\n if (surface !== undefined) {\n const { surfaces } = value;\n if (\n typeof surfaces === 'object' &&\n surfaces !== null &&\n !Array.isArray(surfaces)\n ) {\n const surfaceList = coerceProviderIdList(surfaces[surface]);\n if (surfaceList) {\n return surfaceList;\n }\n }\n }\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.trim().replace(/^\\/providers\\//u, '').toLowerCase();\n}\n"]}
1
+ {"version":3,"file":"featureFlags.cjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,qCAAqC,GAChD,2BAA2B,CAAC;AAE9B;;;;GAIG;AACU,QAAA,2BAA2B,GAAG;IACzC,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAClB,CAAC;AAmBX;;;;;;;;;;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;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AAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAC3B,IACE,OAAO,QAAQ,KAAK,QAAQ;YAC5B,QAAQ,KAAK,IAAI;YACjB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EACxB,CAAC;YACD,MAAM,WAAW,GAAG,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAxBD,oEAwBC;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, providerIds?: string[], surfaces?:\n * Record<string, string[]> }` widens the same way, and additionally\n * restricts the widened quote pick to the listed provider ids (see\n * {@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 * Canonical surface keys accepted in the flag payload's `surfaces` map. A\n * surface entry overrides the top-level `providerIds` list for quote requests\n * tagged with that surface.\n */\nexport const HEADLESS_ALLOWLIST_SURFACES = {\n MONEY: 'money',\n PERPS: 'perps',\n PREDICTIONS: 'predictions',\n} as const;\n\n/**\n * A canonical surface key of the flag payload's `surfaces` map.\n */\nexport type HeadlessAllowlistSurface =\n (typeof HEADLESS_ALLOWLIST_SURFACES)[keyof typeof HEADLESS_ALLOWLIST_SURFACES];\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 );\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 * Resolution, most specific first:\n *\n * 1. When `surface` is given and the payload's `surfaces[surface]` is a\n * non-empty valid list, that list wins.\n * 2. Otherwise the payload's top-level `providerIds`, when non-empty and\n * valid.\n * 3. Otherwise `undefined` (no restriction). The boolean `true` form, a\n * disabled or malformed payload, and empty or all-invalid lists all land\n * here; unknown keys and non-string entries are ignored.\n *\n * Note that `surfaces` entries only apply to quote requests tagged with a\n * `surface`; a request without one (for example MM Pay's `getRampsQuote`)\n * resolves the top-level `providerIds` list only.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @param surface - Optional consumer surface key; canonical values are the\n * {@link HEADLESS_ALLOWLIST_SURFACES} members.\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 surface?: string,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n\n if (surface !== undefined) {\n const { surfaces } = value;\n if (\n typeof surfaces === 'object' &&\n surfaces !== null &&\n !Array.isArray(surfaces)\n ) {\n const surfaceList = coerceProviderIdList(surfaces[surface]);\n if (surfaceList) {\n return surfaceList;\n }\n }\n }\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 +1 @@
1
- {"version":3,"file":"featureFlags.d.cts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;;CAI9B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAClC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;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,EACrE,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,EAAE,GAAG,SAAS,CAqBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAK9D"}
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.d.mts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;;CAI9B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AA+DF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,EACrE,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,EAAE,GAAG,SAAS,CAqBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE9D"}
1
+ {"version":3,"file":"featureFlags.d.mts","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qCAAqC,8BACrB,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;;CAI9B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AA+DF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,EACrE,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,EAAE,GAAG,SAAS,CAqBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAK9D"}
@@ -155,6 +155,9 @@ export function getHeadlessProviderAllowlist(remoteFeatureFlagState, surface) {
155
155
  * @returns The normalized id used for allowlist comparison.
156
156
  */
157
157
  export function normalizeHeadlessProviderId(id) {
158
- return id.trim().replace(/^\/providers\//u, '').toLowerCase();
158
+ return id
159
+ .trim()
160
+ .replace(/^\/providers\//u, '')
161
+ .toLowerCase();
159
162
  }
160
163
  //# sourceMappingURL=featureFlags.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlags.mjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,C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ACH,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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,4BAA4B,CAC1C,sBAAqE,EACrE,OAAgB;IAEhB,MAAM,KAAK,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACvD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAC3B,IACE,OAAO,QAAQ,KAAK,QAAQ;YAC5B,QAAQ,KAAK,IAAI;YACjB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EACxB,CAAC;YACD,MAAM,WAAW,GAAG,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAU;IACpD,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAChE,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, providerIds?: string[], surfaces?:\n * Record<string, string[]> }` widens the same way, and additionally\n * restricts the widened quote pick to the listed provider ids (see\n * {@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 * Canonical surface keys accepted in the flag payload's `surfaces` map. A\n * surface entry overrides the top-level `providerIds` list for quote requests\n * tagged with that surface.\n */\nexport const HEADLESS_ALLOWLIST_SURFACES = {\n MONEY: 'money',\n PERPS: 'perps',\n PREDICTIONS: 'predictions',\n} as const;\n\n/**\n * A canonical surface key of the flag payload's `surfaces` map.\n */\nexport type HeadlessAllowlistSurface =\n (typeof HEADLESS_ALLOWLIST_SURFACES)[keyof typeof HEADLESS_ALLOWLIST_SURFACES];\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 );\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 * Resolution, most specific first:\n *\n * 1. When `surface` is given and the payload's `surfaces[surface]` is a\n * non-empty valid list, that list wins.\n * 2. Otherwise the payload's top-level `providerIds`, when non-empty and\n * valid.\n * 3. Otherwise `undefined` (no restriction). The boolean `true` form, a\n * disabled or malformed payload, and empty or all-invalid lists all land\n * here; unknown keys and non-string entries are ignored.\n *\n * Note that `surfaces` entries only apply to quote requests tagged with a\n * `surface`; a request without one (for example MM Pay's `getRampsQuote`)\n * resolves the top-level `providerIds` list only.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @param surface - Optional consumer surface key; canonical values are the\n * {@link HEADLESS_ALLOWLIST_SURFACES} members.\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 surface?: string,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n\n if (surface !== undefined) {\n const { surfaces } = value;\n if (\n typeof surfaces === 'object' &&\n surfaces !== null &&\n !Array.isArray(surfaces)\n ) {\n const surfaceList = coerceProviderIdList(surfaces[surface]);\n if (surfaceList) {\n return surfaceList;\n }\n }\n }\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.trim().replace(/^\\/providers\\//u, '').toLowerCase();\n}\n"]}
1
+ {"version":3,"file":"featureFlags.mjs","sourceRoot":"","sources":["../src/featureFlags.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAChD,2BAA2B,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAClB,CAAC;AAmBX;;;;;;;;;;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,CACvB,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;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;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, providerIds?: string[], surfaces?:\n * Record<string, string[]> }` widens the same way, and additionally\n * restricts the widened quote pick to the listed provider ids (see\n * {@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 * Canonical surface keys accepted in the flag payload's `surfaces` map. A\n * surface entry overrides the top-level `providerIds` list for quote requests\n * tagged with that surface.\n */\nexport const HEADLESS_ALLOWLIST_SURFACES = {\n MONEY: 'money',\n PERPS: 'perps',\n PREDICTIONS: 'predictions',\n} as const;\n\n/**\n * A canonical surface key of the flag payload's `surfaces` map.\n */\nexport type HeadlessAllowlistSurface =\n (typeof HEADLESS_ALLOWLIST_SURFACES)[keyof typeof HEADLESS_ALLOWLIST_SURFACES];\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 );\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 * Resolution, most specific first:\n *\n * 1. When `surface` is given and the payload's `surfaces[surface]` is a\n * non-empty valid list, that list wins.\n * 2. Otherwise the payload's top-level `providerIds`, when non-empty and\n * valid.\n * 3. Otherwise `undefined` (no restriction). The boolean `true` form, a\n * disabled or malformed payload, and empty or all-invalid lists all land\n * here; unknown keys and non-string entries are ignored.\n *\n * Note that `surfaces` entries only apply to quote requests tagged with a\n * `surface`; a request without one (for example MM Pay's `getRampsQuote`)\n * resolves the top-level `providerIds` list only.\n *\n * @param remoteFeatureFlagState - `RemoteFeatureFlagController` state (or the\n * relevant subset of it). May be `null`/`undefined` before the controller is\n * initialized.\n * @param surface - Optional consumer surface key; canonical values are the\n * {@link HEADLESS_ALLOWLIST_SURFACES} members.\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 surface?: string,\n): string[] | undefined {\n const value = resolveFlagValue(remoteFeatureFlagState);\n if (!isEnabledPayload(value)) {\n return undefined;\n }\n\n if (surface !== undefined) {\n const { surfaces } = value;\n if (\n typeof surfaces === 'object' &&\n surfaces !== null &&\n !Array.isArray(surfaces)\n ) {\n const surfaceList = coerceProviderIdList(surfaces[surface]);\n if (surfaceList) {\n return surfaceList;\n }\n }\n }\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/ramps-controller",
3
- "version": "17.0.0-preview-6f52159",
3
+ "version": "17.0.0-preview-1ccf11bcb",
4
4
  "description": "A controller for managing cryptocurrency on/off ramps functionality",
5
5
  "keywords": [
6
6
  "Ethereum",