@ledgerhq/context-module 0.0.0-develop-20260105001119 → 0.0.0-develop-20260107000932

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.
Files changed (79) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  8. package/lib/cjs/src/config/di/configTypes.js +1 -1
  9. package/lib/cjs/src/config/di/configTypes.js.map +2 -2
  10. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +1 -1
  11. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
  12. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  13. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  14. package/lib/cjs/src/di.js +1 -1
  15. package/lib/cjs/src/di.js.map +3 -3
  16. package/lib/cjs/src/shared/utils/NullLoggerFactory.js +2 -0
  17. package/lib/cjs/src/shared/utils/NullLoggerFactory.js.map +7 -0
  18. package/lib/cjs/src/shared/utils/NullLoggerFactory.test.js +2 -0
  19. package/lib/cjs/src/shared/utils/NullLoggerFactory.test.js.map +7 -0
  20. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  21. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  22. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  23. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  24. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  25. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  26. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  27. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  28. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  29. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  30. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  31. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  32. package/lib/esm/package.json +1 -1
  33. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  34. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  35. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  36. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  37. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  38. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  39. package/lib/esm/src/config/di/configTypes.js +1 -1
  40. package/lib/esm/src/config/di/configTypes.js.map +2 -2
  41. package/lib/esm/src/di.js +1 -1
  42. package/lib/esm/src/di.js.map +3 -3
  43. package/lib/esm/src/shared/utils/NullLoggerFactory.js +2 -0
  44. package/lib/esm/src/shared/utils/NullLoggerFactory.js.map +7 -0
  45. package/lib/esm/src/shared/utils/NullLoggerFactory.test.js +2 -0
  46. package/lib/esm/src/shared/utils/NullLoggerFactory.test.js.map +7 -0
  47. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  48. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  49. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  50. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  51. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  52. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  53. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  54. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  55. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  56. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  57. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  58. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  59. package/lib/types/src/ContextModuleBuilder.d.ts +9 -1
  60. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  61. package/lib/types/src/config/di/configTypes.d.ts +1 -0
  62. package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
  63. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +2 -0
  64. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
  65. package/lib/types/src/config/model/ContextModuleConfig.d.ts +2 -0
  66. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  67. package/lib/types/src/di.d.ts.map +1 -1
  68. package/lib/types/src/shared/utils/NullLoggerFactory.d.ts +3 -0
  69. package/lib/types/src/shared/utils/NullLoggerFactory.d.ts.map +1 -0
  70. package/lib/types/src/shared/utils/NullLoggerFactory.test.d.ts +2 -0
  71. package/lib/types/src/shared/utils/NullLoggerFactory.test.d.ts.map +1 -0
  72. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +3 -1
  73. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -1
  74. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +3 -1
  75. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -1
  76. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +3 -2
  77. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -1
  78. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  79. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/domain/DefaultSolanaContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(mockDataSource, config, mockCertLoader);\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,gCACzBC,EAAmC,6CAMnCC,EAAyC,4DAEzC,YAAS,2BAA4B,IAAM,CACzC,IAAIC,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CACV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAe,gBAAc,IAC/B,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EAEnBJ,EAAiB,CACf,qBAAsB,KAAG,GAAG,CAC9B,EAEAC,EAAiB,CACf,gBAAiB,KAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMI,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/B,OAAO,IAAI,2BAAyBN,EAAgBO,EAAQN,CAAc,CAC5E,KAEA,YAAS,YAAa,IAAM,IAC1B,MAAG,gDAAiD,IAAM,CACxD,MAAMO,EAASH,EAAW,MAAM,KAEhC,UACEG,EAAO,UACL,CACE,gBAAiB,QACnB,EACA,qBAAmB,YACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,KAED,MAAG,yDAA0D,IAAM,CACjE,MAAMA,EAASH,EAAW,MAAM,KAEhC,UACEG,EAAO,UACL,CAAE,gBAAi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,MAAMO,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,KAE/D,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_SolanaContextTypes", "import_SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport { NullLoggerFactory } from \"@/shared/utils/NullLoggerFactory\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n NullLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,gCACzBC,EAAmC,6CACnCC,EAAkC,4CAMlCC,EAAyC,4DAEzC,YAAS,2BAA4B,IAAM,CACzC,IAAIC,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CACV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAe,gBAAc,IAC/B,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EAEnBJ,EAAiB,CACf,qBAAsB,KAAG,GAAG,CAC9B,EAEAC,EAAiB,CACf,gBAAiB,KAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMI,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/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AAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,KAED,YAAS,2BAA4B,IAAM,IACzC,MAAG,8CAA+C,IAAM,CACtD,MAAMK,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,KAEtC,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,KAED,MAAG,qDAAsD,IAAM,CAE7D,MAAMO,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,KAE/D,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_SolanaContextTypes", "import_NullLoggerFactory", "import_SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var L=(n,t)=>{for(var e in t)r(n,e,{get:t[e],enumerable:!0})},I=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of d(t))!y.call(n,a)&&a!==e&&r(n,a,{get:()=>t[a],enumerable:!(o=u(t,a))||o.enumerable});return n};var T=n=>I(r({},"__esModule",{value:!0}),n),S=(n,t,e,o)=>{for(var a=o>1?void 0:o?u(t,e):t,p=n.length-1,c;p>=0;p--)(c=n[p])&&(a=(o?c(t,e,a):c(a))||a);return o&&a&&r(t,e,a),a},f=(n,t)=>(e,o)=>t(e,o,n);var R={};L(R,{SolanaLifiContextLoader:()=>i});module.exports=T(R);var s=require("inversify"),l=require("../../shared/model/SolanaContextTypes"),m=require("../../solanaLifi/di/solanaLifiTypes");let i=class{constructor(t){this.dataSource=t}canHandle(t,e){if(e!==l.SolanaContextTypes.SOLANA_LIFI)return!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const o=t.templateId;return typeof o=="string"&&o.length>0}return!1}async loadField(t){const{templateId:e}=t;return(await this.dataSource.getTransactionDescriptorsPayload({templateId:e})).caseOf({Left:a=>({type:l.SolanaContextTypes.ERROR,error:a}),Right:a=>({type:l.SolanaContextTypes.SOLANA_LIFI,payload:this.pluckTransactionData(a)})})}pluckTransactionData(t){return{...t.descriptors}}};i=S([(0,s.injectable)(),f(0,(0,s.inject)(m.lifiTypes.SolanaLifiDataSource))],i);0&&(module.exports={SolanaLifiContextLoader});
1
+ "use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var y=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},x=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of m(t))!L.call(o,a)&&a!==e&&l(o,a,{get:()=>t[a],enumerable:!(i=u(t,a))||i.enumerable});return o};var T=o=>x(l({},"__esModule",{value:!0}),o),f=(o,t,e,i)=>{for(var a=i>1?void 0:i?u(t,e):t,p=o.length-1,c;p>=0;p--)(c=o[p])&&(a=(i?c(t,e,a):c(a))||a);return i&&a&&l(t,e,a),a},d=(o,t)=>(e,i)=>t(e,i,o);var F={};y(F,{SolanaLifiContextLoader:()=>n});module.exports=T(F);var r=require("inversify"),g=require("../../config/di/configTypes"),s=require("../../shared/model/SolanaContextTypes"),S=require("../../solanaLifi/di/solanaLifiTypes");let n=class{constructor(t,e){this.dataSource=t;this.logger=e("SolanaLifiContextLoader")}logger;canHandle(t,e){if(e!==s.SolanaContextTypes.SOLANA_LIFI)return!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const i=t.templateId;return typeof i=="string"&&i.length>0}return!1}async loadField(t){this.logger.debug("[loadField] Loading solana Lifi context",{data:{input:t}});const{templateId:e}=t;return(await this.dataSource.getTransactionDescriptorsPayload({templateId:e})).caseOf({Left:a=>(this.logger.error("[loadField] Error loading solana Lifi context",{data:{error:a}}),{type:s.SolanaContextTypes.ERROR,error:a}),Right:a=>(this.logger.debug("[loadField] Successfully loaded solana Lifi context",{data:{payload:this.pluckTransactionData(a)}}),{type:s.SolanaContextTypes.SOLANA_LIFI,payload:this.pluckTransactionData(a)})})}pluckTransactionData(t){return{...t.descriptors}}};n=f([(0,r.injectable)(),d(0,(0,r.inject)(S.lifiTypes.SolanaLifiDataSource)),d(1,(0,r.inject)(g.configTypes.ContextModuleLoggerFactory))],n);0&&(module.exports={SolanaLifiContextLoader});
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\ntype SolanaLifiFieldInput = SolanaTransactionContext & {\n templateId: string;\n};\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaLifiFieldInput,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n ) {}\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaLifiFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) return false;\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n return typeof templateId === \"string\" && templateId.length > 0;\n }\n\n return false;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaLifiFieldInput,\n ): Promise<SolanaLifiContextResult> {\n const { templateId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => ({\n type: SolanaContextTypes.ERROR,\n error,\n }),\n Right: (value): SolanaLifiContextResult => ({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: this.pluckTransactionData(value),\n }),\n });\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n return {\n ...tokenData.descriptors,\n };\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAGnCC,EAIO,6CAMPC,EAA0B,2CAOnB,IAAMC,EAAN,KAOP,CACE,YAEmBC,EACjB,CADiB,gBAAAA,CAChB,CAEI,UACLC,EACAC,EAC+B,CAC/B,GAAIA,IAAiB,qBAAmB,YAAa,MAAO,GAE5D,GAAI,OAAOD,GAAU,UAAYA,IAAU,MAAQ,eAAgBA,EAAO,CACxE,MAAME,EAAcF,EAAkC,WACtD,OAAO,OAAOE,GAAe,UAAYA,EAAW,OAAS,CAC/D,CAEA,MAAO,EACT,CAEA,MAAa,UACXC,EACkC,CAClC,KAAM,CAAE,WAAAD,CAAW,EAAIC,EAMvB,OAJgB,MAAM,KAAK,WAAW,iCAAiC,CACrE,WAAAD,CACF,CAAC,GAEc,OAAO,CACpB,KAAOE,IAAoC,CACzC,KAAM,qBAAmB,MACzB,MAAAA,CACF,GACA,MAAQC,IAAoC,CAC1C,KAAM,qBAAmB,YACzB,QAAS,KAAK,qBAAqBA,CAAK,CAC1C,EACF,CAAC,CACH,CAEQ,qBACNC,EACiC,CACjC,MAAO,CACL,GAAGA,EAAU,WACf,CACF,CACF,EAvDaR,EAANS,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,YAAU,oBAAoB,IAT7BV",
6
- "names": ["SolanaLifiContextLoader_exports", "__export", "SolanaLifiContextLoader", "__toCommonJS", "import_inversify", "import_SolanaContextTypes", "import_solanaLifiTypes", "SolanaLifiContextLoader", "dataSource", "field", "expectedType", "templateId", "solanaTokenContextInput", "error", "value", "tokenData", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\ntype SolanaLifiFieldInput = SolanaTransactionContext & {\n templateId: string;\n};\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaLifiFieldInput,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaLifiContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaLifiFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) return false;\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n return typeof templateId === \"string\" && templateId.length > 0;\n }\n\n return false;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaLifiFieldInput,\n ): Promise<SolanaLifiContextResult> {\n this.logger.debug(\"[loadField] Loading solana Lifi context\", {\n data: { input: solanaTokenContextInput },\n });\n const { templateId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => {\n this.logger.error(\"[loadField] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana Lifi context\",\n {\n data: { payload: this.pluckTransactionData(value) },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: this.pluckTransactionData(value),\n };\n },\n });\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n return {\n ...tokenData.descriptors,\n };\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAIO,6CAMPC,EAA0B,2CAOnB,IAAMC,EAAN,KAOP,CAGE,YAEmBC,EAEjBC,EACA,CAHiB,gBAAAD,EAIjB,KAAK,OAASC,EAAc,yBAAyB,CACvD,CATQ,OAWD,UACLC,EACAC,EAC+B,CAC/B,GAAIA,IAAiB,qBAAmB,YAAa,MAAO,GAE5D,GAAI,OAAOD,GAAU,UAAYA,IAAU,MAAQ,eAAgBA,EAAO,CACxE,MAAME,EAAcF,EAAkC,WACtD,OAAO,OAAOE,GAAe,UAAYA,EAAW,OAAS,CAC/D,CAEA,MAAO,EACT,CAEA,MAAa,UACXC,EACkC,CAClC,KAAK,OAAO,MAAM,0CAA2C,CAC3D,KAAM,CAAE,MAAOA,CAAwB,CACzC,CAAC,EACD,KAAM,CAAE,WAAAD,CAAW,EAAIC,EAMvB,OAJgB,MAAM,KAAK,WAAW,iCAAiC,CACrE,WAAAD,CACF,CAAC,GAEc,OAAO,CACpB,KAAOE,IACL,KAAK,OAAO,MAAM,gDAAiD,CACjE,KAAM,CAAE,MAAAA,CAAM,CAChB,CAAC,EAEM,CACL,KAAM,qBAAmB,MACzB,MAAAA,CACF,GAEF,MAAQC,IACN,KAAK,OAAO,MACV,sDACA,CACE,KAAM,CAAE,QAAS,KAAK,qBAAqBA,CAAK,CAAE,CACpD,CACF,EAEO,CACL,KAAM,qBAAmB,YACzB,QAAS,KAAK,qBAAqBA,CAAK,CAC1C,EAEJ,CAAC,CACH,CAEQ,qBACNC,EACiC,CACjC,MAAO,CACL,GAAGA,EAAU,WACf,CACF,CACF,EA/EaT,EAANU,EAAA,IADN,cAAW,EAYPC,EAAA,eAAO,YAAU,oBAAoB,GAErCA,EAAA,eAAO,cAAY,0BAA0B,IAbrCX",
6
+ "names": ["SolanaLifiContextLoader_exports", "__export", "SolanaLifiContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_SolanaContextTypes", "import_solanaLifiTypes", "SolanaLifiContextLoader", "dataSource", "loggerFactory", "field", "expectedType", "templateId", "solanaTokenContextInput", "error", "value", "tokenData", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=require("purify-ts"),a=require("vitest"),t=require("../../shared/model/SolanaContextTypes"),d=require("./SolanaLifiContextLoader");(0,a.describe)("SolanaLifiContextLoader",()=>{let o;const c={swap:{programId:"SomeProgram",accounts:[],data:"abc123"},bridge:{programId:"AnotherProgram",accounts:[],data:"def456"}},i={descriptors:c};(0,a.beforeEach)(()=>{a.vi.restoreAllMocks(),o={getTransactionDescriptorsPayload:a.vi.fn()}});const r=()=>new d.SolanaLifiContextLoader(o);(0,a.describe)("canHandle",()=>{(0,a.it)("returns true when templateId is provided",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!0)}),(0,a.it)("returns false when templateId is missing or falsy",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:""},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({templateId:void 0},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1)})}),(0,a.describe)("loadField",()=>{(0,a.it)("returns an error when datasource returns Left(error)",async()=>{const e=r(),n=new Error("boom");a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,l.Left)(n));const s={templateId:"tpl-err",deviceModelId:"nanoS"},p=await e.loadField(s);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,a.expect)(p).toEqual({type:t.SolanaContextTypes.ERROR,error:n})}),(0,a.it)("returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)",async()=>{const e=r();a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,l.Right)(i));const n={templateId:"tpl-ok",deviceModelId:"nanoS"},s=await e.loadField(n);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,a.expect)(s).toEqual({type:t.SolanaContextTypes.SOLANA_LIFI,payload:c})})}),(0,a.describe)("pluckTransactionData (private)",()=>{(0,a.it)("simply returns the descriptors object from the response",()=>{const e=r(),s=e.pluckTransactionData.bind(e)(i);(0,a.expect)(s).toEqual(c)})})});
1
+ "use strict";var l=require("purify-ts"),a=require("vitest"),t=require("../../shared/model/SolanaContextTypes"),d=require("../../shared/utils/NullLoggerFactory"),p=require("./SolanaLifiContextLoader");(0,a.describe)("SolanaLifiContextLoader",()=>{let o;const c={swap:{programId:"SomeProgram",accounts:[],data:"abc123"},bridge:{programId:"AnotherProgram",accounts:[],data:"def456"}},i={descriptors:c};(0,a.beforeEach)(()=>{a.vi.restoreAllMocks(),o={getTransactionDescriptorsPayload:a.vi.fn()}});const r=()=>new p.SolanaLifiContextLoader(o,d.NullLoggerFactory);(0,a.describe)("canHandle",()=>{(0,a.it)("returns true when templateId is provided",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!0)}),(0,a.it)("returns false when templateId is missing or falsy",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:""},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({templateId:void 0},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1)})}),(0,a.describe)("loadField",()=>{(0,a.it)("returns an error when datasource returns Left(error)",async()=>{const e=r(),n=new Error("boom");a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,l.Left)(n));const s={templateId:"tpl-err",deviceModelId:"nanoS"},u=await e.loadField(s);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,a.expect)(u).toEqual({type:t.SolanaContextTypes.ERROR,error:n})}),(0,a.it)("returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)",async()=>{const e=r();a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,l.Right)(i));const n={templateId:"tpl-ok",deviceModelId:"nanoS"},s=await e.loadField(n);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,a.expect)(s).toEqual({type:t.SolanaContextTypes.SOLANA_LIFI,payload:c})})}),(0,a.describe)("pluckTransactionData (private)",()=>{(0,a.it)("simply returns the descriptors object from the response",()=>{const e=r(),s=e.pluckTransactionData.bind(e)(i);(0,a.expect)(s).toEqual(c)})})});
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n\n const descriptors: SolanaTransactionDescriptorList = {\n // Shape not important for the loader: it's plucked verbatim\n swap: { programId: \"SomeProgram\", accounts: [], data: \"abc123\" } as any,\n bridge: {\n programId: \"AnotherProgram\",\n accounts: [],\n data: \"def456\",\n } as any,\n };\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n descriptors,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n });\n\n const makeLoader = () => new SolanaLifiContextLoader(mockDataSource);\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: descriptors,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"simply returns the descriptors object from the response\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result = pluck(txDescriptorsResponse);\n\n expect(result).toEqual(descriptors);\n });\n });\n});\n"],
5
- "mappings": "aAIA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAErDC,EAGO,6CAMPC,EAAwC,wCAExC,YAAS,0BAA2B,IAA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CACF,CAAC,CACH,CAAC,KAED,MAAG,oFAAqF,SAAY,CAClG,MAAMD,EAASD,EAAW,EAC1B,KAAG,MACDH,EACA,kCACF,EAAE,qBAAkB,SAAME,CAAqB,CAAC,EAChD,MAAMI,EAAQ,CAAE,WAAY,SAAU,cAAe,OAAe,EAC9DC,EAAS,MAAMH,EAAO,UAAUE,CAAK,KAE3C,UACEN,EAAe,gCACjB,EAAE,qBAAqB,CACrB,WAAY,QACd,CAAC,KACD,UAAOO,CAAM,EAAE,QAAQ,CACrB,KAAM,qBAAmB,YACzB,QAASN,CACX,CAAC,CACH,CAAC,CACH,CAAC,KAED,YAAS,iCAAkC,IAAM,IAC/C,MAAG,0DAA2D,IAAM,CAClE,MAAMG,EAASD,EAAW,EAGpBI,EAFSH,EAAe,qBAAqB,KAAKA,CAAM,EAEzCF,CAAqB,KAE1C,UAAOK,CAAM,EAAE,QAAQN,CAAW,CACpC,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_vitest", "import_SolanaContextTypes", "import_SolanaLifiContextLoader", "mockDataSource", "descriptors", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { NullLoggerFactory } from \"@/shared/utils/NullLoggerFactory\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n\n const descriptors: SolanaTransactionDescriptorList = {\n // Shape not important for the loader: it's plucked verbatim\n swap: { programId: \"SomeProgram\", accounts: [], data: \"abc123\" } as any,\n bridge: {\n programId: \"AnotherProgram\",\n accounts: [],\n data: \"def456\",\n } as any,\n };\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n descriptors,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n });\n\n const makeLoader = () =>\n new SolanaLifiContextLoader(mockDataSource, NullLoggerFactory);\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: descriptors,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"simply returns the descriptors object from the response\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result = pluck(txDescriptorsResponse);\n\n expect(result).toEqual(descriptors);\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAErDC,EAGO,6CACPC,EAAkC,4CAMlCC,EAAwC,wCAExC,YAAS,0BAA2B,IAAM,CACxC,IAAIC,EAEJ,MAAMC,EAA+C,CAEnD,KAAM,CAAE,UAAW,cAAe,SAAU,CAAC,EAAG,KAAM,QAAS,EAC/D,OAAQ,CACN,UAAW,iBACX,SAAU,CAAC,EACX,KAAM,QACR,CACF,EAEMC,EAA2D,CAC/D,YAAAD,CACF,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EACnBD,EAAiB,CACf,iCAAkC,KAAG,GAAG,CAC1C,CACF,CAAC,EAED,MAAMG,EAAa,IACjB,IAAI,0BAAwBH,EAAgB,mBAAiB,KAE/D,YAAS,YAAa,IAAM,IAC1B,MAAG,2CAA4C,IAAM,CACnD,MAAMI,EAASD,EAAW,KAE1B,UACEC,EAAO,UACL,CACE,WAAY,UACZ,cAAe,OACjB,EACA,qBAAmB,WACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,KAED,MAAG,oDAAqD,IAAM,CAC5D,MAAMA,EAASD,EAAW,KAE1B,UACEC,EAAO,UACL,CAAE,WAAY,EAAG,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_ts", "import_vitest", "import_SolanaContextTypes", "import_NullLoggerFactory", "import_SolanaLifiContextLoader", "mockDataSource", "descriptors", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var t in e)s(n,t,{get:e[t],enumerable:!0})},g=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of S(e))!I.call(n,a)&&a!==t&&s(n,a,{get:()=>e[a],enumerable:!(o=k(e,a))||o.enumerable});return n};var x=n=>g(s({},"__esModule",{value:!0}),n),f=(n,e,t,o)=>{for(var a=o>1?void 0:o?k(e,t):e,l=n.length-1,i;l>=0;l--)(i=n[l])&&(a=(o?i(e,t,a):i(a))||a);return o&&a&&s(e,t,a),a},c=(n,e)=>(t,o)=>e(t,o,n);var D={};C(D,{SolanaTokenContextLoader:()=>p});module.exports=x(D);var r=require("inversify"),u=require("../../config/di/configTypes"),m=require("../../pki/di/pkiTypes"),T=require("../../pki/model/KeyUsage"),d=require("../../shared/model/SolanaContextTypes"),y=require("../../solanaToken/di/solanaTokenTypes");let p=class{constructor(e,t,o){this.dataSource=e;this.config=t;this._certificateLoader=o}canHandle(e,t){if(t!==d.SolanaContextTypes.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const o=e.tokenInternalId;return typeof o=="string"&&o.length>0}async loadField(e){const{tokenInternalId:t,deviceModelId:o}=e,a=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),l=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:T.KeyUsage.CoinMeta,targetDevice:o});return a.caseOf({Left:i=>({type:d.SolanaContextTypes.ERROR,error:i}),Right:i=>({type:d.SolanaContextTypes.SOLANA_TOKEN,payload:this.pluckTokenData(i),certificate:l})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};p=f([(0,r.injectable)(),c(0,(0,r.inject)(y.solanaTokenTypes.SolanaTokenDataSource)),c(1,(0,r.inject)(u.configTypes.Config)),c(2,(0,r.inject)(m.pkiTypes.PkiCertificateLoader))],p);0&&(module.exports={SolanaTokenContextLoader});
1
+ "use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!S.call(n,o)&&o!==t&&c(n,o,{get:()=>e[o],enumerable:!(a=k(e,o))||a.enumerable});return n};var x=n=>I(c({},"__esModule",{value:!0}),n),g=(n,e,t,a)=>{for(var o=a>1?void 0:a?k(e,t):e,l=n.length-1,r;l>=0;l--)(r=n[l])&&(o=(a?r(e,t,o):r(o))||o);return a&&o&&c(e,t,o),o},d=(n,e)=>(t,a)=>e(t,a,n);var h={};C(h,{SolanaTokenContextLoader:()=>s});module.exports=x(h);var i=require("inversify"),u=require("../../config/di/configTypes"),f=require("../../pki/di/pkiTypes"),m=require("../../pki/model/KeyUsage"),p=require("../../shared/model/SolanaContextTypes"),y=require("../../solanaToken/di/solanaTokenTypes");let s=class{constructor(e,t,a,o){this.dataSource=e;this.config=t;this._certificateLoader=a;this.logger=o("SolanaTokenContextLoader")}logger;canHandle(e,t){if(t!==p.SolanaContextTypes.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const a=e.tokenInternalId;return typeof a=="string"&&a.length>0}async loadField(e){this.logger.debug("[loadField] Loading solana token context",{data:{input:e}});const{tokenInternalId:t,deviceModelId:a}=e,o=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),l=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:m.KeyUsage.CoinMeta,targetDevice:a});return o.caseOf({Left:r=>(this.logger.error("[loadField] Error loading solana token context",{data:{error:r}}),{type:p.SolanaContextTypes.ERROR,error:r}),Right:r=>(this.logger.debug("[loadField] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(r),certificate:l}}),{type:p.SolanaContextTypes.SOLANA_TOKEN,payload:this.pluckTokenData(r),certificate:l})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};s=g([(0,i.injectable)(),d(0,(0,i.inject)(y.solanaTokenTypes.SolanaTokenDataSource)),d(1,(0,i.inject)(u.configTypes.Config)),d(2,(0,i.inject)(f.pkiTypes.PkiCertificateLoader)),d(3,(0,i.inject)(u.configTypes.ContextModuleLoggerFactory))],s);0&&(module.exports={SolanaTokenContextLoader});
2
2
  //# sourceMappingURL=SolanaTokenContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaToken/domain/SolanaTokenContextLoader.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\ntype SolanaTokenFieldInput = SolanaTransactionContext & {\n deviceModelId: DeviceModelId;\n tokenInternalId: string;\n};\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTokenFieldInput,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTokenFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTokenFieldInput,\n ): Promise<SolanaTokenContextResult> {\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => ({\n type: SolanaContextTypes.ERROR,\n error,\n }),\n Right: (value): SolanaTokenContextResult => ({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n }),\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.descriptor.signatures[signatureKind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AM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,IAZ5BhB",
6
- "names": ["SolanaTokenContextLoader_exports", "__export", "SolanaTokenContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_SolanaContextTypes", "import_solanaTokenTypes", "SolanaTokenContextLoader", "dataSource", "config", "_certificateLoader", "field", "expectedType", "tokenInternalId", "solanaTokenContextInput", "deviceModelId", "payload", "certificate", "error", "value", "tokenData", "signatureKind", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import {\n DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\ntype SolanaTokenFieldInput = SolanaTransactionContext & {\n deviceModelId: DeviceModelId;\n tokenInternalId: string;\n};\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTokenFieldInput,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaTokenContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTokenFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTokenFieldInput,\n ): Promise<SolanaTokenContextResult> {\n this.logger.debug(\"[loadField] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => {\n this.logger.error(\"[loadField] Error loading solana token context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n };\n },\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.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AK,EAClC,YAAAF,CACF,EAEJ,CAAC,CACH,CAEQ,eAAeG,EAA+C,CACpE,MAAMC,EAAgB,KAAK,OAAO,IAAI,MAAQ,OAC9C,MAAO,CACL,sBAAuB,CACrB,KAAMD,EAAU,WAAW,KAC3B,UAAWA,EAAU,WAAW,WAAWC,CAAa,CAC1D,CACF,CACF,CACF,EApGaf,EAANgB,EAAA,IADN,cAAW,EAYPC,EAAA,eAAO,mBAAiB,qBAAqB,GAE7CA,EAAA,eAAO,cAAY,MAAM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAhBrCjB",
6
+ "names": ["SolanaTokenContextLoader_exports", "__export", "SolanaTokenContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_SolanaContextTypes", "import_solanaTokenTypes", "SolanaTokenContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "field", "expectedType", "tokenInternalId", "solanaTokenContextInput", "deviceModelId", "payload", "certificate", "error", "value", "tokenData", "signatureKind", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),e=require("vitest"),u=require("../../pki/model/KeyUsage"),n=require("../../shared/model/SolanaContextTypes"),f=require("./SolanaTokenContextLoader");(0,e.describe)("SolanaTokenContextLoader",()=>{let s,d;const i=new Uint8Array([240,202,204,26]),t={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},c={tokenInternalId:"token-1",deviceModelId:p.DeviceModelId.FLEX};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),s={getTokenInfosPayload:e.vi.fn()},d={loadCertificate:e.vi.fn()}});const r=a=>{const o={cal:{mode:a}};return new f.SolanaTokenContextLoader(s,o,d)};(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when tokenInternalId is provided",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!0)}),(0,e.it)("returns false when tokenInternalId is missing or falsy",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:""},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1),(0,e.expect)(a.canHandle({tokenInternalId:void 0},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1),(0,e.expect)(a.canHandle({},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1)})}),(0,e.describe)("loadField",()=>{(0,e.it)("returns an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const a=r("prod"),o=new Error("datasource failed");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(o)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const k=await a.loadField(c);(0,e.expect)(s.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),(0,e.expect)(d.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:u.KeyUsage.CoinMeta,targetDevice:c.deviceModelId}),(0,e.expect)(k).toEqual({type:n.SolanaContextTypes.ERROR,error:o})}),(0,e.it)("returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate",async()=>{const a=r("");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const o=await a.loadField({...c,tokenInternalId:"token-2"});(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:i}})}),(0,e.it)("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const a=r("test");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:i});const o=await a.loadField({...c,tokenInternalId:"token-3"});(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:i}})}),(0,e.it)("works even if certificate loader returns undefined (certificate omitted)",async()=>{const a=r("prod");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const o=await a.loadField(c);(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),(0,e.describe)("pluckTokenData (private)",()=>{(0,e.it)("picks the signature for the configured mode",()=>{const a=r("test"),k=a.pluckTokenData.bind(a)(t);(0,e.expect)(k).toEqual({solanaTokenDescriptor:{data:t.descriptor.data,signature:"test-sig"}})}),(0,e.it)("falls back to 'prod' when config.cal.mode is falsy",()=>{const o=r(void 0).pluckTokenData(t);(0,e.expect)(o).toEqual({solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}})})})});
1
+ "use strict";var k=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),e=require("vitest"),u=require("../../pki/model/KeyUsage"),n=require("../../shared/model/SolanaContextTypes"),f=require("../../shared/utils/NullLoggerFactory"),y=require("./SolanaTokenContextLoader");(0,e.describe)("SolanaTokenContextLoader",()=>{let s,d;const i=new Uint8Array([240,202,204,26]),t={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},c={tokenInternalId:"token-1",deviceModelId:k.DeviceModelId.FLEX};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),s={getTokenInfosPayload:e.vi.fn()},d={loadCertificate:e.vi.fn()}});const r=a=>{const o={cal:{mode:a}};return new y.SolanaTokenContextLoader(s,o,d,f.NullLoggerFactory)};(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when tokenInternalId is provided",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!0)}),(0,e.it)("returns false when tokenInternalId is missing or falsy",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:""},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1),(0,e.expect)(a.canHandle({tokenInternalId:void 0},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1),(0,e.expect)(a.canHandle({},n.SolanaContextTypes.SOLANA_TOKEN)).toBe(!1)})}),(0,e.describe)("loadField",()=>{(0,e.it)("returns an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const a=r("prod"),o=new Error("datasource failed");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(o)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const p=await a.loadField(c);(0,e.expect)(s.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),(0,e.expect)(d.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:u.KeyUsage.CoinMeta,targetDevice:c.deviceModelId}),(0,e.expect)(p).toEqual({type:n.SolanaContextTypes.ERROR,error:o})}),(0,e.it)("returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate",async()=>{const a=r("");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const o=await a.loadField({...c,tokenInternalId:"token-2"});(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:i}})}),(0,e.it)("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const a=r("test");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:i});const o=await a.loadField({...c,tokenInternalId:"token-3"});(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:i}})}),(0,e.it)("works even if certificate loader returns undefined (certificate omitted)",async()=>{const a=r("prod");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Right)(t)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const o=await a.loadField(c);(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),(0,e.describe)("pluckTokenData (private)",()=>{(0,e.it)("picks the signature for the configured mode",()=>{const a=r("test"),p=a.pluckTokenData.bind(a)(t);(0,e.expect)(p).toEqual({solanaTokenDescriptor:{data:t.descriptor.data,signature:"test-sig"}})}),(0,e.it)("falls back to 'prod' when config.cal.mode is falsy",()=>{const o=r(void 0).pluckTokenData(t);(0,e.expect)(o).toEqual({solanaTokenDescriptor:{data:t.descriptor.data,signature:"prod-sig"}})})})});
2
2
  //# sourceMappingURL=SolanaTokenContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaToken/domain/SolanaTokenContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\n\nimport { SolanaTokenContextLoader } from \"./SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(mockDataSource, config, mockCertLoader);\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,gCACzBC,EAAmC,6CAOnCC,EAAyC,yCAEzC,YAAS,2BAA4B,IAAM,CACzC,IAAIC,EACAC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,CACP,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,CAAE,eAAgB,EAAG,QAASD,CAAM,CACnD,CAAC,CACH,CAAC,KAED,MAAG,2EAA4E,SAAY,CACzF,MAAMM,EAASH,EAAW,MAAM,EAEhC,KAAG,MAAML,EAAgB,sBAAsB,EAAE,qBAC/C,SAAMG,CAAiB,CACzB,EACA,KAAG,MAAMF,EAAgB,iBAAiB,EAAE,kBAAkB,MAAS,EAEvE,MAAMS,EAAS,MAAMF,EAAO,UAAUJ,CAAO,KAE7C,UAAOM,CAAM,EAAE,QAAQ,CACrB,KAAM,qBAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,KAED,YAAS,2BAA4B,IAAM,IACzC,MAAG,8CAA+C,IAAM,CACtD,MAAMK,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,KAEtC,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,KAED,MAAG,qDAAsD,IAAM,CAE7D,MAAMO,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,KAE/D,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_SolanaContextTypes", "import_SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport { NullLoggerFactory } from \"@/shared/utils/NullLoggerFactory\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\n\nimport { SolanaTokenContextLoader } from \"./SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n NullLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,gCACzBC,EAAmC,6CACnCC,EAAkC,4CAOlCC,EAAyC,yCAEzC,YAAS,2BAA4B,IAAM,CACzC,IAAIC,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CAEV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAe,gBAAc,IAC/B,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EAEnBJ,EAAiB,CACf,qBAAsB,KAAG,GAAG,CAC9B,EAEAC,EAAiB,CACf,gBAAiB,KAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMI,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/B,OAAO,IAAI,2BACTN,EACAO,EACAN,EACA,mBACF,CACF,KAEA,YAAS,YAAa,IAAM,IAC1B,MAAG,gDAAiD,IAAM,CACxD,MAAMO,EAASH,EAAW,MAAM,KAEhC,UACEG,EAAO,UACL,CACE,gBAAiB,QACnB,EACA,qBAAmB,YACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,KAED,MAAG,yDAA0D,IAAM,CACjE,MAAMA,EAASH,EAAW,MAAM,KAEhC,UACEG,EAAO,UACL,CAAE,gBAAiB,EAAG,EACtB,qBAAmB,YACrB,CACF,EAAE,KAAK,EAAK,KACZ,UACEA,EAAO,UACL,CAAE,gBAAi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BAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_SolanaContextTypes", "import_NullLoggerFactory", "import_SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
7
7
  }
@@ -58,5 +58,5 @@
58
58
  "watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
59
59
  "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
60
60
  },
61
- "version": "0.0.0-develop-20260105001119"
61
+ "version": "0.0.0-develop-20260107000932"
62
62
  }
@@ -1,2 +1,2 @@
1
- import{DefaultContextModule as t}from"./DefaultContextModule";const o="https://crypto-assets-service.api.ledger.com/v1",r="https://web3checks-backend.api.ledger.com/v3",n="https://nft.api.live.ledger.com",a={cal:{url:o,mode:"prod",branch:"main"},web3checks:{url:r},metadataServiceDomain:{url:n},defaultLoaders:!0,customLoaders:[],defaultFieldLoaders:!0,customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0};class s{config=a;originToken;constructor({originToken:e}={}){this.originToken=e}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}build(){const e={...this.config,originToken:this.originToken};return new t(e)}}export{s as ContextModuleBuilder,a as DEFAULT_CONFIG};
1
+ import{NullLoggerFactory as o}from"./shared/utils/NullLoggerFactory";import{DefaultContextModule as r}from"./DefaultContextModule";const i="https://crypto-assets-service.api.ledger.com/v1",n="https://web3checks-backend.api.ledger.com/v3",a="https://nft.api.live.ledger.com",s={cal:{url:i,mode:"prod",branch:"main"},web3checks:{url:n},metadataServiceDomain:{url:a},defaultLoaders:!0,customLoaders:[],defaultFieldLoaders:!0,customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,loggerFactory:o};class g{config=s;originToken;constructor({originToken:e,loggerFactory:t}={}){this.originToken=e,t&&(this.config.loggerFactory=t)}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){const e={...this.config,originToken:this.originToken};return new r(e)}}export{g as ContextModuleBuilder,s as DEFAULT_CONFIG};
2
2
  //# sourceMappingURL=ContextModuleBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ContextModuleBuilder.ts"],
4
- "sourcesContent": ["import { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n defaultFieldLoaders: true,\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private originToken?: string;\n\n constructor({ originToken }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
5
- "mappings": "AAYA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BC,EAAsC,CACjD,IAAK,CACH,IAAKH,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,sBAAuB,CACrB,IAAKC,CACP,EACA,eAAgB,GAChB,cAAe,CAAC,EAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuB,OACvB,mBAAoB,MACtB,EAEO,MAAME,CAAqB,CACxB,OAA8BD,EAC9B,YAER,YAAY,CAAE,YAAAE,CAAY,EAAkC,CAAC,EAAG,CAC9D,KAAK,YAAcA,CACrB,CAOA,sBAAuB,CACrB,YAAK,OAAO,eAAiB,GACtB,IACT,CAQA,UAAUC,EAAuB,CAC/B,YAAK,OAAO,cAAc,KAAKA,CAAM,EAC9B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,gBAAgBA,EAA6B,CAC3C,YAAK,OAAO,mBAAqBA,EAC1B,IACT,CAQA,aAAaC,EAAmC,CAC9C,YAAK,OAAO,IAAMA,EACX,IACT,CAQA,yBACEC,EACA,CACA,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAOA,OAAuB,CACrB,MAAMC,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIZ,EAAqBY,CAAM,CACxC,CACF",
6
- "names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "config"]
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { NullLoggerFactory } from \"./shared/utils/NullLoggerFactory\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n defaultFieldLoaders: true,\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n loggerFactory: NullLoggerFactory,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private originToken?: string;\n\n constructor({\n originToken,\n loggerFactory,\n }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\n\n if (loggerFactory) {\n this.config.loggerFactory = loggerFactory;\n }\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Set a custom logger factory\n *\n * @param loggerFactory\n * @returns this\n */\n setLoggerFactory(loggerFactory: (tag: string) => LoggerPublisherService) {\n this.config.loggerFactory = loggerFactory;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
5
+ "mappings": "AAWA,OAAS,qBAAAA,MAAyB,mCAIlC,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BC,EAAsC,CACjD,IAAK,CACH,IAAKH,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,sBAAuB,CACrB,IAAKC,CACP,EACA,eAAgB,GAChB,cAAe,CAAC,EAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuB,OACvB,mBAAoB,OACpB,cAAeJ,CACjB,EAEO,MAAMM,CAAqB,CACxB,OAA8BD,EAC9B,YAER,YAAY,CACV,YAAAE,EACA,cAAAC,CACF,EAAkC,CAAC,EAAG,CACpC,KAAK,YAAcD,EAEfC,IACF,KAAK,OAAO,cAAgBA,EAEhC,CAOA,sBAAuB,CACrB,YAAK,OAAO,eAAiB,GACtB,IACT,CAQA,UAAUC,EAAuB,CAC/B,YAAK,OAAO,cAAc,KAAKA,CAAM,EAC9B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,gBAAgBA,EAA6B,CAC3C,YAAK,OAAO,mBAAqBA,EAC1B,IACT,CAQA,aAAaC,EAAmC,CAC9C,YAAK,OAAO,IAAMA,EACX,IACT,CAQA,yBACEC,EACA,CACA,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,iBAAiBL,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,MAAMM,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIb,EAAqBa,CAAM,CACxC,CACF",
6
+ "names": ["NullLoggerFactory", "DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "config"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{configTypes as s}from"./config/di/configTypes";import{ContextModuleBuilder as a}from"./ContextModuleBuilder";import{DefaultContextModule as u}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const i={url:"https://cal/v1",mode:"prod",branch:"main"},r={url:"https://web3checks/v1"},c={originToken:"test"};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new a(c).build();expect(e).toBeInstanceOf(u)}),it("should return a custom context module",()=>{const n=new a(c),e={load:vi.fn(),canHandle:vi.fn()},t=n.removeDefaultLoaders().addLoader(e).build();expect(t).toBeInstanceOf(u)}),it("should return a custom context module with a custom typed data loader",()=>{const n=new a(c),e={load:vi.fn()},t=n.removeDefaultLoaders().addTypedDataLoader(e).build();expect(t).toBeInstanceOf(u),expect(t._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new a(c).setCalConfig(i).setWeb3ChecksConfig(r).build(),t=e._container.get(s.Config);expect(e).toBeInstanceOf(u),expect(t.cal).toEqual(i),expect(t.web3checks).toEqual(r)}),it("should not throw an error if origin token is provided",()=>{const n=new a(c);expect(()=>n.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const n=new a(c),e={url:"https://custom-metadata-service.com/v3"},t=n.setMetadataServiceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const n=new a(c),e={url:"https://override-metadata-service.com/v1"},o=n.setMetadataServiceConfig(e).build()._container.get(s.Config);expect(o.metadataServiceDomain.url).toBe(e.url),expect(o.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const n=new a(c),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},t=n.setCalConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const n=new a(c),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},o=n.setCalConfig(e).build()._container.get(s.Config);expect(o.cal.url).toBe(e.url),expect(o.cal.mode).toBe(e.mode),expect(o.cal.branch).toBe(e.branch),expect(o.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const n=new a(c),e={url:"https://custom-web3checks-service.com/v4"},t=n.setWeb3ChecksConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const n=new a(c),e={url:"https://override-web3checks-service.com/v2"},o=n.setWeb3ChecksConfig(e).build()._container.get(s.Config);expect(o.web3checks.url).toBe(e.url),expect(o.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const n=new a(c),e={proxy:"safe"},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const n=new a(c),e={proxy:"default"},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const n=new a(c),e={proxy:"safe"},o=n.setDatasourceConfig(e).build()._container.get(s.Config);expect(o.datasource?.proxy).toBe("safe"),expect(o.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const n=new a(c),e={},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBeUndefined()})})});
1
+ import{configTypes as s}from"./config/di/configTypes";import{ContextModuleBuilder as r}from"./ContextModuleBuilder";import{DefaultContextModule as a}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const i={url:"https://cal/v1",mode:"prod",branch:"main"},u={url:"https://web3checks/v1"},c={originToken:"test"};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new r(c).build();expect(e).toBeInstanceOf(a)}),it("should return a custom context module",()=>{const t=new r(c),e={load:vi.fn(),canHandle:vi.fn()},o=t.removeDefaultLoaders().addLoader(e).build();expect(o).toBeInstanceOf(a)}),it("should return a custom context module with a custom typed data loader",()=>{const t=new r(c),e={load:vi.fn()},o=t.removeDefaultLoaders().addTypedDataLoader(e).build();expect(o).toBeInstanceOf(a),expect(o._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new r(c).setCalConfig(i).setWeb3ChecksConfig(u).build(),o=e._container.get(s.Config);expect(e).toBeInstanceOf(a),expect(o.cal).toEqual(i),expect(o.web3checks).toEqual(u)}),it("should not throw an error if origin token is provided",()=>{const t=new r(c);expect(()=>t.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const t=new r(c),e={url:"https://custom-metadata-service.com/v3"},o=t.setMetadataServiceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const t=new r(c),e={url:"https://override-metadata-service.com/v1"},n=t.setMetadataServiceConfig(e).build()._container.get(s.Config);expect(n.metadataServiceDomain.url).toBe(e.url),expect(n.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const t=new r(c),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},o=t.setCalConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const t=new r(c),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},n=t.setCalConfig(e).build()._container.get(s.Config);expect(n.cal.url).toBe(e.url),expect(n.cal.mode).toBe(e.mode),expect(n.cal.branch).toBe(e.branch),expect(n.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const t=new r(c),e={url:"https://custom-web3checks-service.com/v4"},o=t.setWeb3ChecksConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const t=new r(c),e={url:"https://override-web3checks-service.com/v2"},n=t.setWeb3ChecksConfig(e).build()._container.get(s.Config);expect(n.web3checks.url).toBe(e.url),expect(n.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const t=new r(c),e={proxy:"safe"},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const t=new r(c),e={proxy:"default"},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const t=new r(c),e={proxy:"safe"},n=t.setDatasourceConfig(e).build()._container.get(s.Config);expect(n.datasource?.proxy).toBe("safe"),expect(n.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const t=new r(c),e={},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBeUndefined()})}),describe("loggerFactory",()=>{it("should set the loggerFactory when provided in the constructor",()=>{const t=vi.fn(),o=new r({...c,loggerFactory:t}).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.loggerFactory).toBe(t)}),it("should set the loggerFactory via setLoggerFactory",()=>{const t=vi.fn(),o=new r(c).setLoggerFactory(t).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.loggerFactory).toBe(t)}),it("should override constructor loggerFactory with setLoggerFactory",()=>{const t=vi.fn(),e=vi.fn(),l=new r({...c,loggerFactory:t}).setLoggerFactory(e).build()._container.get(s.Config);expect(l.loggerFactory).toBe(e),expect(l.loggerFactory).not.toBe(t)})})});
2
2
  //# sourceMappingURL=ContextModuleBuilder.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ContextModuleBuilder.test.ts"],
4
- "sourcesContent": ["import { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n});\n"],
5
- "mappings": "AAEA,OAAS,eAAAA,MAAmB,0BAS5B,OAAS,wBAAAC,MAA4B,yBACr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J,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,KAAK,MAAM,CAC9C,CAAC,EAED,GAAG,6DAA8D,IAAM,CACrE,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,SACT,EAEMP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,KAAK,SAAS,CACjD,CAAC,EAED,GAAG,uDAAwD,IAAM,CAC/D,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,MACT,EAKMJ,EAHMF,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EAEP,WACA,IAAyBb,EAAY,MAAM,EAE7C,OAAOS,EAAO,YAAY,KAAK,EAAE,KAAK,MAAM,EAC5C,OAAOA,EAAO,UAAU,EAAE,IAAI,cAAc,CAC9C,CAAC,EAED,GAAG,+CAAgD,IAAM,CACvD,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAAC,EAEzDP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,cAAc,CACjD,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig"]
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n\n describe(\"loggerFactory\", () => {\n it(\"should set the loggerFactory when provided in the constructor\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory,\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should set the loggerFactory via setLoggerFactory\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.setLoggerFactory(loggerFactory).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should override constructor loggerFactory with setLoggerFactory\", () => {\n const constructorLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n const overrideLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory: constructorLoggerFactory,\n });\n\n const res = contextModuleBuilder\n .setLoggerFactory(overrideLoggerFactory)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.loggerFactory).toBe(overrideLoggerFactory);\n expect(config.loggerFactory).not.toBe(constructorLoggerFactory);\n });\n });\n});\n"],
5
+ "mappings": "AAGA,OAAS,eAAAA,MAAmB,0BAS5B,OAAS,wBAAAC,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACMC,EAA0B,CAC9B,IAAK,uBACP,EACMC,EAAmD,CACvD,YAAa,MACf,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,yCAA0C,IAAM,CAGjD,MAAMC,EAFuB,IAAIL,EAAqBI,CAAkB,EAEvC,MAAM,EAEvC,OAAOC,CAAG,EAAE,eAAeJ,CAAoB,CACjD,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChD,MAAMK,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEG,EAA8B,CAClC,KAAM,GAAG,GAAG,EACZ,UAAW,GAAG,GAAG,CACnB,EAEMF,EAAMC,EACT,qBAAqB,EACrB,UAAUC,CAAY,EACtB,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeJ,CAAoB,CACjD,CAAC,EAED,GAAG,wEAAyE,IAAM,CAChF,MAAMK,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEG,EAAe,CAAE,KAAM,GAAG,GAAG,CAAE,EAE/BF,EAAMC,EACT,qBAAqB,EACrB,mBAAmBC,CAAY,EAC/B,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeJ,CAAoB,EAE/C,OAAOI,EAAI,gBAAmB,EAAE,KAAKE,CAAY,CACnD,CAAC,EAED,GAAG,6DAA8D,IAAM,CAGrE,MAAMF,EAFuB,IAAIL,EAAqBI,CAAkB,EAGrE,aAAaF,CAAgB,EAC7B,oBAAoBC,CAAuB,EAC3C,MAAM,EAEHK,EAAUH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QI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,cAAc,CACjD,CAAC,CACH,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,gEAAiE,IAAM,CACxE,MAAMK,EAAyD,GAAG,GAAG,EAO/DR,EALuB,IAAIL,EAAqB,CACpD,GAAGI,EACH,cAAAS,CACF,CAAC,EAEgC,MAAM,EACjCL,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,aAAa,EAAE,KAAKK,CAAa,CACjD,CAAC,EAED,GAAG,oDAAqD,IAAM,CAC5D,MAAMA,EAAyD,GAAG,GAAG,EAI/DR,EAFuB,IAAIL,EAAqBI,CAAkB,EAEvC,iBAAiBS,CAAa,EAAE,MAAM,EACjEL,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,aAAa,EAAE,KAAKK,CAAa,CACjD,CAAC,EAED,GAAG,kEAAmE,IAAM,CAC1E,MAAMC,EACJ,GAAG,GAAG,EACFC,EACJ,GAAG,GAAG,EAUFP,EARuB,IAAIR,EAAqB,CACpD,GAAGI,EACH,cAAeU,CACjB,CAAC,EAGE,iBAAiBC,CAAqB,EACtC,MAAM,EAEP,WACA,IAAyBhB,EAAY,MAAM,EAE7C,OAAOS,EAAO,aAAa,EAAE,KAAKO,CAAqB,EACvD,OAAOP,EAAO,aAAa,EAAE,IAAI,KAAKM,CAAwB,CAChE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{DefaultContextModule as d}from"./DefaultContextModule";const u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken"};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const a=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(a).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const n=new d({...l,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},s=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},s=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),n={type:o.TOKEN,payload:"first-payload"},a={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(n)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),n={type:o.ERROR,error:new Error("first-error")},a={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
1
+ import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{NullLoggerFactory as x}from"./shared/utils/NullLoggerFactory";import{DefaultContextModule as d}from"./DefaultContextModule";const u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken",loggerFactory:x};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const a=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(a).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const n=new d({...l,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},s=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},s=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),n={type:o.TOKEN,payload:"first-payload"},a={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(n)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),n={type:o.ERROR,error:new Error("first-error")},a={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
2
2
  //# sourceMappingURL=DefaultContextModule.test.js.map