{"version":3,"file":"getLocale.cjs","sourceRoot":"","sources":["../../src/restricted/getLocale.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAS9E,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAkBpC;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAI7B,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,EAA+B,EAAE,EAAE;IAC1E,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,iBAAiB,CAAC,WAAW,CAAC;QACpD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEF,MAAM,WAAW,GAA4C;IAC3D,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,UAAU,EAAE,UAAU;IACtB,oBAAoB,EAApB,4BAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,EAAE,cAAc,EAAwB;IACxE,OAAO,KAAK,UAAU,cAAc,CAClC,KAA0D;QAE1D,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAND,8CAMC","sourcesContent":["import type {\n  PermissionSpecificationBuilder,\n  ValidPermissionSpecification,\n  RestrictedMethodOptions,\n  RestrictedMethodParameters,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport type {\n  GetLocaleResult,\n  GetPreferencesResult,\n} from '@metamask/snaps-sdk';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_getLocale';\n\nexport type GetLocaleMethodHooks = {\n  getPreferences: () => GetPreferencesResult;\n};\n\ntype SpecificationBuilderOptions = {\n  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n  methodHooks: GetLocaleMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n  permissionType: PermissionType.RestrictedMethod;\n  targetName: typeof methodName;\n  methodImplementation: ReturnType<typeof getImplementation>;\n  allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_getLocale` permission.\n * `snap_getLocale` allows snaps to get the user selected locale.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getLocale` permission.\n * @deprecated - To be removed in favor of `snap_getPreferences`.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n  PermissionType.RestrictedMethod,\n  SpecificationBuilderOptions,\n  Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n  return {\n    permissionType: PermissionType.RestrictedMethod,\n    targetName: methodName,\n    allowedCaveats,\n    methodImplementation: getImplementation(methodHooks),\n    subjectTypes: [SubjectType.Snap],\n  };\n};\n\nconst methodHooks: MethodHooksObject<GetLocaleMethodHooks> = {\n  getPreferences: true,\n};\n\n/**\n * Get the user's locale setting. You can use this method to localize text in\n * your Snap.\n *\n * Note that this method is deprecated. We recommend using\n * [`snap_getPreferences`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getpreferences)\n * instead, which provides access to the user's locale as well as other\n * preferences.\n *\n * @internal\n */\nexport const getLocaleBuilder = Object.freeze({\n  targetName: methodName,\n  specificationBuilder,\n  methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getLocale`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getPreferences - A function that returns the user selected preferences.\n * @returns The user selected locale.\n */\nexport function getImplementation({ getPreferences }: GetLocaleMethodHooks) {\n  return async function implementation(\n    _args: RestrictedMethodOptions<RestrictedMethodParameters>,\n  ): Promise<GetLocaleResult> {\n    return getPreferences().locale;\n  };\n}\n"]}