@metamask-previews/claims-controller 0.2.0-preview-7cfbb337 → 0.2.0-preview-bea9ae5
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.cjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+
|
|
1
|
+
{"version":3,"file":"ClaimsService.cjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+CAIqB;AA8DrB,MAAa,aAAa;IASxB,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAuB;QARzD,SAAI,GAAG,wBAAY,CAAC,CAAC,sCAAsC;QAE3D,qCAAU;QAEV,uCAAqB;QAErB,2CAAmC;QAG1C,uBAAA,IAAI,sBAAQ,GAAG,MAAA,CAAC;QAChB,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,wBAAU,aAAa,MAAA,CAAC;QAE5B,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,4BAA4B,EAC3C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,YAAY,EAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,eAAe,EAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,oBAAoB,EACnC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;QACF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E,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,gCAAW,CAAC,IAAI,CAC5C,yCAAyC,CAC1C,CAAC;QACF,OAAO;YACL,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,OAAO,GAAG,8BAAkB,CAAC,uBAAA,IAAI,0BAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;CACF;AAhKD,sCAgKC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\n }\n\n /**\n * Get the claim by id.\n *\n * @param id - The id of the claim to get.\n * @returns The claim by id.\n */\n async getClaimById(id: string): Promise<Claim> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\n }\n\n /**\n * Generate a message to be signed by the user for the claim request.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The message for the claim signature.\n */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\n }\n\n /**\n * Get the URL for the claims API for the current environment.\n *\n * @returns The URL for the claims API for the current environment.\n */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|
package/dist/ClaimsService.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Messenger } from "@metamask/messenger";
|
|
2
2
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
3
3
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { SERVICE_NAME } from "./constants.cjs";
|
|
5
|
+
import type { Env } from "./constants.cjs";
|
|
5
6
|
import type { Claim, ClaimsConfigurationsResponse, GenerateSignatureMessageResponse } from "./types.cjs";
|
|
6
7
|
export type ClaimsServiceFetchClaimsConfigurationsAction = {
|
|
7
8
|
type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.d.cts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAGL,
|
|
1
|
+
{"version":3,"file":"ClaimsService.d.cts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAGL,YAAY,EACb,wBAAoB;AACrB,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AACvC,OAAO,KAAK,EACV,KAAK,EACL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AAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,sBAAsB,CAAC;IAClC,aAAa,EAAE,OAAO,KAAK,CAAC;CAC7B,CAAC;AAEF,qBAAa,aAAa;;IACxB,QAAQ,CAAC,IAAI,mBAAgB;gBAQjB,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,mBAAmB;IA+BlE;;;;OAIG;IACG,yBAAyB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAiBxE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAenC;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAe9C;;;;;;OAMG;IACG,gCAAgC,CACpC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,GAAG,GACjB,OAAO,CAAC,gCAAgC,CAAC;IAyB5C;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAS1D;;;;OAIG;IACH,eAAe,IAAI,MAAM;CAG1B"}
|
package/dist/ClaimsService.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Messenger } from "@metamask/messenger";
|
|
2
2
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
3
3
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { SERVICE_NAME } from "./constants.mjs";
|
|
5
|
+
import type { Env } from "./constants.mjs";
|
|
5
6
|
import type { Claim, ClaimsConfigurationsResponse, GenerateSignatureMessageResponse } from "./types.mjs";
|
|
6
7
|
export type ClaimsServiceFetchClaimsConfigurationsAction = {
|
|
7
8
|
type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.d.mts","sourceRoot":"","sources":["../src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I,MAAM;CAG1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.mjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"ClaimsService.mjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACb,wBAAoB;AA8DrB,MAAM,OAAO,aAAa;IASxB,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAuB;QARzD,SAAI,GAAG,YAAY,CAAC,CAAC,sCAAsC;QAE3D,qCAAU;QAEV,uCAAqB;QAErB,2CAAmC;QAG1C,uBAAA,IAAI,sBAAQ,GAAG,MAAA,CAAC;QAChB,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,wBAAU,aAAa,MAAA,CAAC;QAE5B,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,4BAA4B,EAC3C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,YAAY,EAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,eAAe,EAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,oBAAoB,EACnC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,G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AED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,gCAAW,CAAC,IAAI,CAC5C,yCAAyC,CAC1C,CAAC;QACF,OAAO;YACL,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,OAAO,GAAG,kBAAkB,CAAC,uBAAA,IAAI,0BAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\n }\n\n /**\n * Get the claim by id.\n *\n * @param id - The id of the claim to get.\n * @returns The claim by id.\n */\n async getClaimById(id: string): Promise<Claim> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\n }\n\n /**\n * Generate a message to be signed by the user for the claim request.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The message for the claim signature.\n */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\n }\n\n /**\n * Get the URL for the claims API for the current environment.\n *\n * @returns The URL for the claims API for the current environment.\n */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|