@ledgerhq/context-module 0.0.0-develop-20260409001459 → 0.0.0-develop-20260411001650

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 (37) hide show
  1. package/README.md +10 -0
  2. package/lib/cjs/package.json +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  4. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  5. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  6. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  7. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  8. package/lib/cjs/src/reporter/data/BlindSigningReporterDatasource.js +1 -1
  9. package/lib/cjs/src/reporter/data/BlindSigningReporterDatasource.js.map +1 -1
  10. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.js +1 -1
  11. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.js.map +2 -2
  12. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.test.js +1 -1
  13. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.test.js.map +2 -2
  14. package/lib/cjs/src/reporter/data/dto/BlindSigningEventDto.js.map +1 -1
  15. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.test.js +1 -1
  16. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.test.js.map +2 -2
  17. package/lib/esm/package.json +1 -1
  18. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  19. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  20. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  21. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  22. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.js +1 -1
  23. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.js.map +2 -2
  24. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.test.js +1 -1
  25. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.test.js.map +2 -2
  26. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.test.js +1 -1
  27. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.test.js.map +2 -2
  28. package/lib/types/src/ContextModuleBuilder.d.ts +7 -0
  29. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  30. package/lib/types/src/config/model/ContextModuleConfig.d.ts +1 -0
  31. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  32. package/lib/types/src/reporter/data/BlindSigningReporterDatasource.d.ts +18 -2
  33. package/lib/types/src/reporter/data/BlindSigningReporterDatasource.d.ts.map +1 -1
  34. package/lib/types/src/reporter/data/dto/BlindSigningEventDto.d.ts +2 -2
  35. package/lib/types/src/reporter/data/dto/BlindSigningEventDto.d.ts.map +1 -1
  36. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  37. package/package.json +3 -3
package/README.md CHANGED
@@ -74,6 +74,16 @@ const contextModule = new ContextModuleBuilder({
74
74
  .build();
75
75
  ```
76
76
 
77
+ You can set a source identifier that will be included in blind signing reports. This helps distinguish which integration triggered a blind signing event. The default value is `"third-party"`.
78
+
79
+ ```ts
80
+ const contextModule = new ContextModuleBuilder({
81
+ originToken: "origin-token", // replace with your origin token
82
+ })
83
+ .setAppSource("my-app-name")
84
+ .build();
85
+ ```
86
+
77
87
  It is also possible to instantiate the context module without the default loaders.
78
88
 
79
89
  ```ts
@@ -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-20260409001459"
61
+ "version": "0.0.0-develop-20260411001650"
62
62
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!g.call(t,r)&&r!==o&&n(t,r,{get:()=>e[r],enumerable:!(i=u(e,r))||i.enumerable});return t};var f=t=>l(n({},"__esModule",{value:!0}),t);var y={};C(y,{ContextModuleBuilder:()=>M,DEFAULT_CONFIG:()=>s});module.exports=f(y);var a=require("@ledgerhq/device-management-kit"),d=require("./DefaultContextModule");const p="https://crypto-assets-service.api.ledger.com/v1",m="https://web3checks-backend.api.ledger.com/v3",L="https://nft.api.live.ledger.com",h="https://blind-signing-reporting.api.ledger.com",s=Object.freeze({cal:Object.freeze({url:p,mode:"prod",branch:"main"}),web3checks:Object.freeze({url:m}),metadataServiceDomain:Object.freeze({url:L}),reporter:Object.freeze({url:h}),datasource:Object.freeze({proxy:"default"})}),x={defaultLoaders:!0,defaultFieldLoaders:!0,customLoaders:[],customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,customBlindSigningReporter:void 0,customTrustedNameDataSource:void 0};class M{config;constructor({originToken:e,loggerFactory:o}){this.config={...s,...x,customLoaders:[],customFieldLoaders:[],originToken:e??"",loggerFactory:o??a.noopLoggerFactory}}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}setReporterConfig(e){return this.config.reporter=e,this}setBlindSigningReporter(e){return this.config.customBlindSigningReporter=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){return new d.DefaultContextModule(this.config)}}0&&(module.exports={ContextModuleBuilder,DEFAULT_CONFIG});
1
+ "use strict";var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},f=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!g.call(t,r)&&r!==o&&n(t,r,{get:()=>e[r],enumerable:!(i=u(e,r))||i.enumerable});return t};var l=t=>f(n({},"__esModule",{value:!0}),t);var S={};C(S,{ContextModuleBuilder:()=>M,DEFAULT_CONFIG:()=>d});module.exports=l(S);var a=require("@ledgerhq/device-management-kit"),s=require("./DefaultContextModule");const p="https://crypto-assets-service.api.ledger.com/v1",m="https://web3checks-backend.api.ledger.com/v3",h="https://nft.api.live.ledger.com",L="https://ingest.aws.stg.ldg-tech.com/ingest/v1",d=Object.freeze({cal:Object.freeze({url:p,mode:"prod",branch:"main"}),web3checks:Object.freeze({url:m}),metadataServiceDomain:Object.freeze({url:h}),reporter:Object.freeze({url:L}),datasource:Object.freeze({proxy:"default"}),appSource:"third-party"}),x={defaultLoaders:!0,defaultFieldLoaders:!0,customLoaders:[],customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,customBlindSigningReporter:void 0,customTrustedNameDataSource:void 0};class M{config;constructor({originToken:e,loggerFactory:o}){this.config={...d,...x,customLoaders:[],customFieldLoaders:[],originToken:e??"",loggerFactory:o??a.noopLoggerFactory}}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}setReporterConfig(e){return this.config.reporter=e,this}setAppSource(e){return this.config.appSource=e,this}setBlindSigningReporter(e){return this.config.customBlindSigningReporter=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){return new s.DefaultContextModule(this.config)}}0&&(module.exports={ContextModuleBuilder,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 {\n type LoggerPublisherService,\n noopLoggerFactory,\n} 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 ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type BlindSigningReporter } from \"./reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\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\";\nconst DEFAULT_REPORTER_URL = \"https://blind-signing-reporting.api.ledger.com\";\n\n/**\n * Default configuration for the context module\n *\n * @note This configuration is frozen to prevent modifications after construction\n * and can be used by external packages to get a default configuration.\n */\nexport const DEFAULT_CONFIG: Readonly<ContextModuleConfig> = Object.freeze({\n cal: Object.freeze({\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n }),\n web3checks: Object.freeze({\n url: DEFAULT_WEB3_CHECKS_URL,\n }),\n metadataServiceDomain: Object.freeze({\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n }),\n reporter: Object.freeze({\n url: DEFAULT_REPORTER_URL,\n }),\n datasource: Object.freeze({ proxy: \"default\" }),\n});\n\n/**\n * Default loader configuration for the context module\n *\n * @note This configuration is internal and will be the default configuration for the context module.\n */\nconst DEFAULT_LOADER_CONFIG: ContextModuleLoaderConfig = {\n defaultLoaders: true,\n defaultFieldLoaders: true,\n customLoaders: [],\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n customBlindSigningReporter: undefined,\n customTrustedNameDataSource: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleServiceConfig & ContextModuleLoaderConfig;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...DEFAULT_LOADER_CONFIG,\n customLoaders: [],\n customFieldLoaders: [],\n originToken: originToken ?? \"\",\n loggerFactory: loggerFactory ?? noopLoggerFactory,\n } as ContextModuleServiceConfig & ContextModuleLoaderConfig;\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 reporter configuration\n *\n * @param reporterConfig\n * @returns this\n */\n setReporterConfig(reporterConfig: ContextModuleReporterConfig) {\n this.config.reporter = reporterConfig;\n return this;\n }\n\n /**\n * Set a custom blind signing reporter\n *\n * @param reporter reporter to use for blind signing events\n * @returns this\n */\n setBlindSigningReporter(reporter: BlindSigningReporter) {\n this.config.customBlindSigningReporter = reporter;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\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 return new DefaultContextModule(this.config);\n }\n}\n"],
5
- "mappings": "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iD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,kBAAkBC,EAA6C,CAC7D,YAAK,OAAO,SAAWA,EAChB,IACT,CAQA,wBAAwBC,EAAgC,CACtD,YAAK,OAAO,2BAA6BA,EAClC,IACT,CAQA,yBAAyBC,EAAmC,CAC1D,YAAK,OAAO,4BAA8BA,EACnC,IACT,CAQA,iBAAiBR,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,OAAO,IAAI,uBAAqB,KAAK,MAAM,CAC7C,CACF",
6
- "names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "DEFAULT_CONFIG", "__toCommonJS", "import_device_management_kit", "import_DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_REPORTER_URL", "DEFAULT_LOADER_CONFIG", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "reporterConfig", "reporter", "dataSource"]
4
+ "sourcesContent": ["import {\n type LoggerPublisherService,\n noopLoggerFactory,\n} 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 ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type BlindSigningReporter } from \"./reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\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\";\nconst DEFAULT_REPORTER_URL = \"https://ingest.aws.stg.ldg-tech.com/ingest/v1\";\n\n/**\n * Default configuration for the context module\n *\n * @note This configuration is frozen to prevent modifications after construction\n * and can be used by external packages to get a default configuration.\n */\nexport const DEFAULT_CONFIG: Readonly<ContextModuleConfig> = Object.freeze({\n cal: Object.freeze({\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n }),\n web3checks: Object.freeze({\n url: DEFAULT_WEB3_CHECKS_URL,\n }),\n metadataServiceDomain: Object.freeze({\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n }),\n reporter: Object.freeze({\n url: DEFAULT_REPORTER_URL,\n }),\n datasource: Object.freeze({ proxy: \"default\" }),\n appSource: \"third-party\",\n});\n\n/**\n * Default loader configuration for the context module\n *\n * @note This configuration is internal and will be the default configuration for the context module.\n */\nconst DEFAULT_LOADER_CONFIG: ContextModuleLoaderConfig = {\n defaultLoaders: true,\n defaultFieldLoaders: true,\n customLoaders: [],\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n customBlindSigningReporter: undefined,\n customTrustedNameDataSource: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleServiceConfig & ContextModuleLoaderConfig;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...DEFAULT_LOADER_CONFIG,\n customLoaders: [],\n customFieldLoaders: [],\n originToken: originToken ?? \"\",\n loggerFactory: loggerFactory ?? noopLoggerFactory,\n } as ContextModuleServiceConfig & ContextModuleLoaderConfig;\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 reporter configuration\n *\n * @param reporterConfig\n * @returns this\n */\n setReporterConfig(reporterConfig: ContextModuleReporterConfig) {\n this.config.reporter = reporterConfig;\n return this;\n }\n\n /**\n * Set the app source identifier included in blind signing reports\n *\n * @param appSource\n * @returns this\n */\n setAppSource(appSource: string) {\n this.config.appSource = appSource;\n return this;\n }\n\n /**\n * Set a custom blind signing reporter\n *\n * @param reporter reporter to use for blind signing events\n * @returns this\n */\n setBlindSigningReporter(reporter: BlindSigningReporter) {\n this.config.customBlindSigningReporter = reporter;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\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 return new DefaultContextModule(this.config);\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAGO,2CAmBPC,EAAqC,kCAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAClCC,EAAuB,gDAQhBP,EAAgD,OAAO,OAAO,CACzE,IAAK,OAAO,OAAO,CACjB,IAAKI,EACL,KAAM,OACN,OAAQ,MACV,CAAC,EACD,WAAY,OAAO,OAAO,CACxB,IAAKC,CACP,CAAC,EACD,sBAAuB,OAAO,OAAO,CACnC,IAAKC,CACP,CAAC,EACD,SAAU,OAAO,OAAO,CACtB,IAAKC,CACP,CAAC,EACD,WAAY,OAAO,OAAO,CAAE,MAAO,SAAU,CAAC,EAC9C,UAAW,aACb,CAAC,EAOKC,EAAmD,CACvD,eAAgB,GAChB,oBAAqB,GACrB,cAAe,CAAC,EAChB,mBAAoB,CAAC,EACrB,sBAAuB,OACvB,mBAAoB,OACpB,2BAA4B,OAC5B,4BAA6B,MAC/B,EAEO,MAAMT,CAAqB,CACxB,OAER,YAAY,CAAE,YAAAU,EAAa,cAAAC,CAAc,EAAiC,CACxE,KAAK,OAAS,CACZ,GAAGV,EACH,GAAGQ,EACH,cAAe,CAAC,EAChB,mBAAoB,CAAC,EACrB,YAAaC,GAAe,GAC5B,cAAeC,GAAiB,mBAClC,CACF,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,kBAAkBC,EAA6C,CAC7D,YAAK,OAAO,SAAWA,EAChB,IACT,CAQA,aAAaC,EAAmB,CAC9B,YAAK,OAAO,UAAYA,EACjB,IACT,CAQA,wBAAwBC,EAAgC,CACtD,YAAK,OAAO,2BAA6BA,EAClC,IACT,CAQA,yBAAyBC,EAAmC,CAC1D,YAAK,OAAO,4BAA8BA,EACnC,IACT,CAQA,iBAAiBT,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,OAAO,IAAI,uBAAqB,KAAK,MAAM,CAC7C,CACF",
6
+ "names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "DEFAULT_CONFIG", "__toCommonJS", "import_device_management_kit", "import_DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_REPORTER_URL", "DEFAULT_LOADER_CONFIG", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "reporterConfig", "appSource", "reporter", "dataSource"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=require("./shared/model/ClearSignContext"),l=require("./DefaultContextModule");const x=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),s=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},d={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"},reporter:{url:"https://reporter.com"},datasource:{proxy:"default"},originToken:"originToken",loggerFactory:x};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new l.DefaultContextModule(d).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new l.DefaultContextModule(d).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new l.DefaultContextModule({...d,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 l.DefaultContextModule({...d,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.ClearSignContextType.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.ClearSignContextType.NFT,payload:"payload2"}]);const n=new l.DefaultContextModule({...d,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},r=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o.ClearSignContextType)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o.ClearSignContextType)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(r).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.ClearSignContextType.TOKEN,payload:"payload1"}]);const t=new l.DefaultContextModule({...d,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.ClearSignContextType.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.ClearSignContextType.TOKEN])}),it("should call the typed data loader",async()=>{await new l.DefaultContextModule({...d,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=s();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.ClearSignContextType.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.ClearSignContextType.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=s(),t={type:o.ClearSignContextType.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},r=await n.getFieldContext(a,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(r).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=s(),t=s(),n={type:o.ClearSignContextType.TOKEN,payload:"first-payload"},a={type:o.ClearSignContextType.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 r=new l.DefaultContextModule({...d,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await r.getFieldContext(c,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.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=s(),t=s(),n={type:o.ClearSignContextType.ERROR,error:new Error("first-error")},a={type:o.ClearSignContextType.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 r=new l.DefaultContextModule({...d,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await r.getFieldContext(c,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=s(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.ClearSignContextType.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
1
+ "use strict";var o=require("./shared/model/ClearSignContext"),l=require("./DefaultContextModule");const x=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),s=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},d={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"},reporter:{url:"https://reporter.com"},datasource:{proxy:"default"},appSource:"third-party",originToken:"originToken",loggerFactory:x};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new l.DefaultContextModule(d).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new l.DefaultContextModule(d).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new l.DefaultContextModule({...d,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 l.DefaultContextModule({...d,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.ClearSignContextType.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.ClearSignContextType.NFT,payload:"payload2"}]);const n=new l.DefaultContextModule({...d,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},r=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o.ClearSignContextType)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o.ClearSignContextType)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(r).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.ClearSignContextType.TOKEN,payload:"payload1"}]);const t=new l.DefaultContextModule({...d,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.ClearSignContextType.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.ClearSignContextType.TOKEN])}),it("should call the typed data loader",async()=>{await new l.DefaultContextModule({...d,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=s();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.ClearSignContextType.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.ClearSignContextType.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=s(),t={type:o.ClearSignContextType.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},r=await n.getFieldContext(a,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(r).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=s(),t=s(),n={type:o.ClearSignContextType.TOKEN,payload:"first-payload"},a={type:o.ClearSignContextType.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 r=new l.DefaultContextModule({...d,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await r.getFieldContext(c,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.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=s(),t=s(),n={type:o.ClearSignContextType.ERROR,error:new Error("first-error")},a={type:o.ClearSignContextType.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 r=new l.DefaultContextModule({...d,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await r.getFieldContext(c,o.ClearSignContextType.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=s(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new l.DefaultContextModule({...d,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.ClearSignContextType.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.ClearSignContextType.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
2
2
  //# sourceMappingURL=DefaultContextModule.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.test.ts"],
4
- "sourcesContent": ["import {\n type ContextModuleLoaderConfig,\n type ContextModuleServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleServiceConfig &\n ContextModuleLoaderConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n reporter: {\n url: \"https://reporter.com\",\n },\n datasource: {\n proxy: \"default\",\n },\n originToken: \"originToken\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
5
- "mappings": "aAMA,IAAAA,EAGO,2CAGPC,EAAqC,kCAErC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH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B,EACrCkB,EAAY,IAAI,MAAM,mBAAmB,EAE/C,GAAG,MAAMR,EAAa,WAAW,EAAE,gBAAgB,EAAI,EACvD,GAAG,MAAMA,EAAa,WAAW,EAAE,kBAAkBQ,CAAS,EAE9D,MAAMV,EAAgB,IAAI,uBAAqB,CAC7C,GAAGN,EACH,mBAAoB,CAACQ,CAAW,CAClC,CAAC,EAEKC,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAGpD,MAAM,OACJH,EAAc,gBAAgBG,EAAW,uBAAqB,KAAK,CACrE,EAAE,QAAQ,QAAQ,mBAAmB,EAErC,OAAOD,EAAY,SAAS,EAAE,qBAC5BC,EACA,uBAAqB,KACvB,EACA,OAAOD,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n type ContextModuleLoaderConfig,\n type ContextModuleServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleServiceConfig &\n ContextModuleLoaderConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n reporter: {\n url: \"https://reporter.com\",\n },\n datasource: {\n proxy: \"default\",\n },\n appSource: \"third-party\",\n originToken: \"originToken\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
5
+ "mappings": "aAMA,IAAAA,EAGO,2CAGPC,EAAqC,kCAErC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,u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G,MAAMA,EAAa,WAAW,EAAE,kBAAkBQ,CAAS,EAE9D,MAAMV,EAAgB,IAAI,uBAAqB,CAC7C,GAAGN,EACH,mBAAoB,CAACQ,CAAW,CAClC,CAAC,EAEKC,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAGpD,MAAM,OACJH,EAAc,gBAAgBG,EAAW,uBAAqB,KAAK,CACrE,EAAE,QAAQ,QAAQ,mBAAmB,EAErC,OAAOD,EAAY,SAAS,EAAE,qBAC5BC,EACA,uBAAqB,KACvB,EACA,OAAOD,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_ClearSignContext", "import_DefaultContextModule", "mockLoggerFactory", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/config/model/ContextModuleConfig.ts"],
4
- "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type BlindSigningReporter } from \"@/reporter/domain/BlindSigningReporter\";\nimport { type ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"@/solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"@/typed-data/domain/TypedDataContextLoader\";\n\nexport type ContextModuleCalMode = \"prod\" | \"test\";\nexport type ContextModuleCalBranch = \"next\" | \"main\" | \"demo\";\n\nexport type ContextModuleCalConfig = {\n url: string;\n mode: ContextModuleCalMode;\n branch: ContextModuleCalBranch;\n};\n\nexport type ContextModuleWeb3ChecksConfig = {\n url: string;\n};\n\nexport type ContextModuleMetadataServiceConfig = {\n url: string;\n};\n\nexport type ContextModuleReporterConfig = {\n url: string;\n};\n\nexport type ContextModuleDatasourceConfig = {\n proxy?: \"safe\" | \"default\";\n};\n\nexport type ContextModuleConfig = {\n cal: ContextModuleCalConfig;\n web3checks: ContextModuleWeb3ChecksConfig;\n metadataServiceDomain: ContextModuleMetadataServiceConfig;\n reporter: ContextModuleReporterConfig;\n datasource: ContextModuleDatasourceConfig;\n};\n\nexport type ContextModuleServiceConfig = ContextModuleConfig & {\n originToken: string;\n loggerFactory: (tag: string) => LoggerPublisherService;\n};\n\nexport type ContextModuleLoaderConfig = {\n defaultLoaders: boolean;\n defaultFieldLoaders: boolean;\n customFieldLoaders: ContextFieldLoader[];\n customLoaders: ContextLoader[];\n customTypedDataLoader?: TypedDataContextLoader;\n customSolanaLoader?: SolanaContextLoader;\n customBlindSigningReporter?: BlindSigningReporter;\n customTrustedNameDataSource?: TrustedNameDataSource;\n};\n"],
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type BlindSigningReporter } from \"@/reporter/domain/BlindSigningReporter\";\nimport { type ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"@/solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"@/typed-data/domain/TypedDataContextLoader\";\n\nexport type ContextModuleCalMode = \"prod\" | \"test\";\nexport type ContextModuleCalBranch = \"next\" | \"main\" | \"demo\";\n\nexport type ContextModuleCalConfig = {\n url: string;\n mode: ContextModuleCalMode;\n branch: ContextModuleCalBranch;\n};\n\nexport type ContextModuleWeb3ChecksConfig = {\n url: string;\n};\n\nexport type ContextModuleMetadataServiceConfig = {\n url: string;\n};\n\nexport type ContextModuleReporterConfig = {\n url: string;\n};\n\nexport type ContextModuleDatasourceConfig = {\n proxy?: \"safe\" | \"default\";\n};\n\nexport type ContextModuleConfig = {\n cal: ContextModuleCalConfig;\n web3checks: ContextModuleWeb3ChecksConfig;\n metadataServiceDomain: ContextModuleMetadataServiceConfig;\n reporter: ContextModuleReporterConfig;\n datasource: ContextModuleDatasourceConfig;\n appSource: string;\n};\n\nexport type ContextModuleServiceConfig = ContextModuleConfig & {\n originToken: string;\n loggerFactory: (tag: string) => LoggerPublisherService;\n};\n\nexport type ContextModuleLoaderConfig = {\n defaultLoaders: boolean;\n defaultFieldLoaders: boolean;\n customFieldLoaders: ContextFieldLoader[];\n customLoaders: ContextLoader[];\n customTypedDataLoader?: TypedDataContextLoader;\n customSolanaLoader?: SolanaContextLoader;\n customBlindSigningReporter?: BlindSigningReporter;\n customTrustedNameDataSource?: TrustedNameDataSource;\n};\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["ContextModuleConfig_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var m=(i,r,o,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of g(r))!a.call(i,t)&&t!==o&&n(i,t,{get:()=>r[t],enumerable:!(e=p(r,t))||e.enumerable});return i};var d=i=>m(n({},"__esModule",{value:!0}),i);var l={};module.exports=d(l);
1
+ "use strict";var t=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(i,n,g,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of l(n))!d.call(i,e)&&e!==g&&t(i,e,{get:()=>n[e],enumerable:!(r=o(n,e))||r.enumerable});return i};var a=i=>p(t({},"__esModule",{value:!0}),i);var s={};module.exports=a(s);
2
2
  //# sourceMappingURL=BlindSigningReporterDatasource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/reporter/data/BlindSigningReporterDatasource.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nimport { type BlindSigningEventDto } from \"./dto/BlindSigningEventDto\";\n\nexport type BlindSigningReportParams = BlindSigningEventDto;\n\nexport interface BlindSigningReporterDatasource {\n report(params: BlindSigningReportParams): Promise<Either<Error, void>>;\n}\n"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nimport {\n type BlindSigningMethod,\n type BlindSignReason,\n type ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { type BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\n\nexport type BlindSigningReportEthContext = {\n clearSigningType: ClearSigningType;\n partialContextErrors: number;\n};\n\nexport type BlindSigningReportParams = {\n signatureId: string;\n signingMethod: BlindSigningMethod;\n isBlindSign: boolean;\n chainId: number | null;\n targetAddress: string | null;\n blindSignReason: BlindSignReason | null;\n modelId: BlindSigningModelId;\n signerAppVersion: string;\n deviceVersion: string | null;\n ethContext: BlindSigningReportEthContext | null;\n};\n\nexport interface BlindSigningReporterDatasource {\n report(params: BlindSigningReportParams): Promise<Either<Error, void>>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["BlindSigningReporterDatasource_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.create;var n=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var S=(e,r)=>{for(var o in r)n(e,o,{get:r[o],enumerable:!0})},E=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of C(r))!x.call(e,i)&&i!==o&&n(e,i,{get:()=>r[i],enumerable:!(t=d(r,i))||t.enumerable});return e};var c=(e,r,o)=>(o=e!=null?y(_(e)):{},E(r||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),P=e=>E(n({},"__esModule",{value:!0}),e),l=(e,r,o,t)=>{for(var i=t>1?void 0:t?d(r,o):r,f=e.length-1,g;f>=0;f--)(g=e[f])&&(i=(t?g(r,o,i):g(i))||i);return t&&i&&n(r,o,i),i},u=(e,r)=>(o,t)=>r(o,t,e);var T={};S(T,{HttpBlindSigningReporterDatasource:()=>m});module.exports=P(T);var R=c(require("axios")),p=require("inversify"),s=require("purify-ts"),h=require("../../config/di/configTypes"),a=require("../../shared/constant/HttpHeaders"),v=c(require("../../../package.json"));let m=class{constructor(r){this.config=r}async report(r){try{await R.default.request({method:"POST",url:`${this.config.reporter.url}/v1/blind-signing-events`,data:r,headers:{[a.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${v.default.version}`,[a.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})}catch{return(0,s.Left)(new Error("[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event"))}return(0,s.Right)(void 0)}};m=l([(0,p.injectable)(),u(0,(0,p.inject)(h.configTypes.Config))],m);0&&(module.exports={HttpBlindSigningReporterDatasource});
1
+ "use strict";var C=Object.create;var n=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var x=(e,r)=>{for(var o in r)n(e,o,{get:r[o],enumerable:!0})},d=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of v(r))!_.call(e,i)&&i!==o&&n(e,i,{get:()=>r[i],enumerable:!(t=g(r,i))||t.enumerable});return e};var E=(e,r,o)=>(o=e!=null?C(S(e)):{},d(r||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),P=e=>d(n({},"__esModule",{value:!0}),e),l=(e,r,o,t)=>{for(var i=t>1?void 0:t?g(r,o):r,c=e.length-1,f;c>=0;c--)(f=e[c])&&(i=(t?f(r,o,i):f(i))||i);return t&&i&&n(r,o,i),i},u=(e,r)=>(o,t)=>r(o,t,e);var T={};x(T,{HttpBlindSigningReporterDatasource:()=>m});module.exports=P(T);var h=E(require("axios")),p=require("inversify"),s=require("purify-ts"),R=require("../../config/di/configTypes"),a=require("../../shared/constant/HttpHeaders"),y=E(require("../../../package.json"));let m=class{constructor(r){this.config=r}async report(r){try{await h.default.request({method:"POST",url:`${this.config.reporter.url}/blind-signing-events`,data:{...r,source:this.config.appSource},headers:{[a.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${y.default.version}`,[a.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})}catch{return(0,s.Left)(new Error("[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event"))}return(0,s.Right)(void 0)}};m=l([(0,p.injectable)(),u(0,(0,p.inject)(R.configTypes.Config))],m);0&&(module.exports={HttpBlindSigningReporterDatasource});
2
2
  //# sourceMappingURL=HttpBlindSigningReporterDatasource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/reporter/data/HttpBlindSigningReporterDatasource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n type BlindSigningReporterDatasource,\n type BlindSigningReportParams,\n} from \"./BlindSigningReporterDatasource\";\n\n@injectable()\nexport class HttpBlindSigningReporterDatasource\n implements BlindSigningReporterDatasource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n ) {}\n\n async report(params: BlindSigningReportParams): Promise<Either<Error, void>> {\n try {\n await axios.request({\n method: \"POST\",\n url: `${this.config.reporter.url}/v1/blind-signing-events`,\n data: params,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event\",\n ),\n );\n }\n\n return Right(undefined);\n }\n}\n"],
5
- "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAyC,qBAEzCC,EAA4B,mCAE5BC,EAGO,yCACPC,EAAoB,iCAQb,IAAMC,EAAN,KAEP,CACE,YAEmBC,EACjB,CADiB,YAAAA,CAChB,CAEH,MAAM,OAAOC,EAAgE,CAC3E,GAAI,CACF,MAAM,EAAAC,QAAM,QAAQ,CAClB,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,SAAS,GAAG,2BAChC,KAAMD,EACN,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAE,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,CACH,MAAiB,CACf,SAAO,QACL,IAAI,MACF,0FACF,CACF,CACF,CAEA,SAAO,SAAM,MAAS,CACxB,CACF,EA7BaJ,EAANK,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,IAJjBN",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n type BlindSigningReporterDatasource,\n type BlindSigningReportParams,\n} from \"./BlindSigningReporterDatasource\";\n\n@injectable()\nexport class HttpBlindSigningReporterDatasource\n implements BlindSigningReporterDatasource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n ) {}\n\n async report(params: BlindSigningReportParams): Promise<Either<Error, void>> {\n try {\n await axios.request({\n method: \"POST\",\n url: `${this.config.reporter.url}/blind-signing-events`,\n data: { ...params, source: this.config.appSource },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event\",\n ),\n );\n }\n\n return Right(undefined);\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAyC,qBAEzCC,EAA4B,mCAE5BC,EAGO,yCACPC,EAAoB,iCAQb,IAAMC,EAAN,KAEP,CACE,YAEmBC,EACjB,CADiB,YAAAA,CAChB,CAEH,MAAM,OAAOC,EAAgE,CAC3E,GAAI,CACF,MAAM,EAAAC,QAAM,QAAQ,CAClB,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,SAAS,GAAG,wBAChC,KAAM,CAAE,GAAGD,EAAQ,OAAQ,KAAK,OAAO,SAAU,EACjD,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAE,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,CACH,MAAiB,CACf,SAAO,QACL,IAAI,MACF,0FACF,CACF,CACF,CAEA,SAAO,SAAM,MAAS,CACxB,CACF,EA7BaJ,EAANK,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,IAJjBN",
6
6
  "names": ["HttpBlindSigningReporterDatasource_exports", "__export", "HttpBlindSigningReporterDatasource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpBlindSigningReporterDatasource", "config", "params", "axios", "PACKAGE", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var v=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of h(t))!R.call(e,s)&&s!==o&&l(e,s,{get:()=>t[s],enumerable:!(n=S(t,s))||n.enumerable});return e};var u=(e,t,o)=>(o=e!=null?m(E(e)):{},v(t||!e||!e.__esModule?l(o,"default",{value:e,enumerable:!0}):o,e));var r=u(require("axios")),c=require("purify-ts"),i=require("../../reporter/data/HttpBlindSigningReporterDatasource"),a=require("../../reporter/model/BlindSigningEvent"),p=require("../../reporter/model/BlindSigningModelId"),d=require("../../shared/constant/HttpHeaders"),g=u(require("../../../package.json"));vi.mock("axios");describe("HttpBlindSigningReporterDatasource",()=>{const e={reporter:{url:"https://reporter.test"},originToken:"originToken"},t={signatureId:"a3f8Kb-1738850400000",signingMethod:a.BlindSigningMethod.ETH_SIGN_TRANSACTION,source:"ledger_wallet",isBlindSign:!0,chainId:1,targetAddress:"0xdAC17F958D2ee523a2206206994597C13D831ec7",blindSignReason:a.BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,modelId:p.BlindSigningModelId.NANO_X,signerAppVersion:"1.12.1",deviceVersion:"2.2.3",ethContext:{clearSigningType:a.ClearSigningType.EIP7730,partialContextErrors:0}};beforeEach(()=>{vi.resetAllMocks()}),describe("report",()=>{it("should return Right(undefined) on success",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}});const n=await new i.HttpBlindSigningReporterDatasource(e).report(t);expect(n).toEqual((0,c.Right)(void 0))}),it("should return Left(Error) when the request fails",async()=>{vi.spyOn(r.default,"request").mockRejectedValueOnce(new Error("network error"));const n=await new i.HttpBlindSigningReporterDatasource(e).report(t);expect(n).toEqual((0,c.Left)(new Error("[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event")))}),it("should call axios with the correct URL and method",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:`${e.reporter.url}/v1/blind-signing-events`}))}),it("should call axios with the correct headers",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({headers:{[d.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${g.default.version}`,[d.LEDGER_ORIGIN_TOKEN_HEADER]:e.originToken}}))}),it("should call axios with the event payload as data",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({data:t}))})})});
1
+ "use strict";var m=Object.create;var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var v=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of h(t))!R.call(e,s)&&s!==o&&l(e,s,{get:()=>t[s],enumerable:!(n=S(t,s))||n.enumerable});return e};var p=(e,t,o)=>(o=e!=null?m(E(e)):{},v(t||!e||!e.__esModule?l(o,"default",{value:e,enumerable:!0}):o,e));var r=p(require("axios")),c=require("purify-ts"),i=require("../../reporter/data/HttpBlindSigningReporterDatasource"),a=require("../../reporter/model/BlindSigningEvent"),u=require("../../reporter/model/BlindSigningModelId"),d=require("../../shared/constant/HttpHeaders"),g=p(require("../../../package.json"));vi.mock("axios");describe("HttpBlindSigningReporterDatasource",()=>{const e={reporter:{url:"https://reporter.test"},originToken:"originToken",appSource:"third-party"},t={signatureId:"a3f8Kb-1738850400000",signingMethod:a.BlindSigningMethod.ETH_SIGN_TRANSACTION,isBlindSign:!0,chainId:1,targetAddress:"0xdAC17F958D2ee523a2206206994597C13D831ec7",blindSignReason:a.BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,modelId:u.BlindSigningModelId.NANO_X,signerAppVersion:"1.12.1",deviceVersion:"2.2.3",ethContext:{clearSigningType:a.ClearSigningType.EIP7730,partialContextErrors:0}};beforeEach(()=>{vi.resetAllMocks()}),describe("report",()=>{it("should return Right(undefined) on success",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}});const n=await new i.HttpBlindSigningReporterDatasource(e).report(t);expect(n).toEqual((0,c.Right)(void 0))}),it("should return Left(Error) when the request fails",async()=>{vi.spyOn(r.default,"request").mockRejectedValueOnce(new Error("network error"));const n=await new i.HttpBlindSigningReporterDatasource(e).report(t);expect(n).toEqual((0,c.Left)(new Error("[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event")))}),it("should call axios with the correct URL and method",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:`${e.reporter.url}/blind-signing-events`}))}),it("should call axios with the correct headers",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({headers:{[d.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${g.default.version}`,[d.LEDGER_ORIGIN_TOKEN_HEADER]:e.originToken}}))}),it("should call axios with the event payload and injected source as data",async()=>{vi.spyOn(r.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpBlindSigningReporterDatasource(e).report(t),expect(r.default.request).toHaveBeenCalledWith(expect.objectContaining({data:{...t,source:e.appSource}}))})})});
2
2
  //# sourceMappingURL=HttpBlindSigningReporterDatasource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/reporter/data/HttpBlindSigningReporterDatasource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type BlindSigningReportParams } from \"@/reporter/data/BlindSigningReporterDatasource\";\nimport { HttpBlindSigningReporterDatasource } from \"@/reporter/data/HttpBlindSigningReporterDatasource\";\nimport {\n BlindSigningMethod,\n BlindSignReason,\n ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpBlindSigningReporterDatasource\", () => {\n const config = {\n reporter: {\n url: \"https://reporter.test\",\n },\n originToken: \"originToken\",\n } as ContextModuleServiceConfig;\n\n const params: BlindSigningReportParams = {\n signatureId: \"a3f8Kb-1738850400000\",\n signingMethod: BlindSigningMethod.ETH_SIGN_TRANSACTION,\n source: \"ledger_wallet\",\n isBlindSign: true,\n chainId: 1,\n targetAddress: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n blindSignReason: BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,\n modelId: BlindSigningModelId.NANO_X,\n signerAppVersion: \"1.12.1\",\n deviceVersion: \"2.2.3\",\n ethContext: {\n clearSigningType: ClearSigningType.EIP7730,\n partialContextErrors: 0,\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"report\", () => {\n it(\"should return Right(undefined) on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n const result = await dataSource.report(params);\n\n // THEN\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"should return Left(Error) when the request fails\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"network error\"),\n );\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n const result = await dataSource.report(params);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event\",\n ),\n ),\n );\n });\n\n it(\"should call axios with the correct URL and method\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: `${config.reporter!.url}/v1/blind-signing-events`,\n }),\n );\n });\n\n it(\"should call axios with the correct headers\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should call axios with the event payload as data\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n data: params,\n }),\n );\n });\n });\n});\n"],
5
- "mappings": "wdAAA,IAAAA,EAAkB,oBAClB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O,SAAU,GAAG,0BAC9B,CAAC,CACH,CACF,CAAC,EAED,GAAG,6CAA8C,SAAY,CAE3D,GAAG,MAAM,EAAAE,QAAO,SAAS,EAAE,sBAAsB,CAAE,KAAM,CAAC,CAAE,CAAC,EAI7D,MADmB,IAAI,qCAAmCF,CAAM,EAC/C,OAAOC,CAAM,EAG9B,OAAO,EAAAC,QAAM,OAAO,EAAE,qBACpB,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAE,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAGJ,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,EAED,GAAG,mDAAoD,SAAY,CAEjE,GAAG,MAAM,EAAAE,QAAO,SAAS,EAAE,sBAAsB,CAAE,KAAM,CAAC,CAAE,CAAC,EAI7D,MADmB,IAAI,qCAAmCF,CAAM,EAC/C,OAAOC,CAAM,EAG9B,OAAO,EAAAC,QAAM,OAAO,EAAE,qBACpB,OAAO,iBAAiB,CACtB,KAAMD,CACR,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type BlindSigningReportParams } from \"@/reporter/data/BlindSigningReporterDatasource\";\nimport { HttpBlindSigningReporterDatasource } from \"@/reporter/data/HttpBlindSigningReporterDatasource\";\nimport {\n BlindSigningMethod,\n BlindSignReason,\n ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpBlindSigningReporterDatasource\", () => {\n const config = {\n reporter: {\n url: \"https://reporter.test\",\n },\n originToken: \"originToken\",\n appSource: \"third-party\",\n } as ContextModuleServiceConfig;\n\n const params: BlindSigningReportParams = {\n signatureId: \"a3f8Kb-1738850400000\",\n signingMethod: BlindSigningMethod.ETH_SIGN_TRANSACTION,\n isBlindSign: true,\n chainId: 1,\n targetAddress: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n blindSignReason: BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,\n modelId: BlindSigningModelId.NANO_X,\n signerAppVersion: \"1.12.1\",\n deviceVersion: \"2.2.3\",\n ethContext: {\n clearSigningType: ClearSigningType.EIP7730,\n partialContextErrors: 0,\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"report\", () => {\n it(\"should return Right(undefined) on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n const result = await dataSource.report(params);\n\n // THEN\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"should return Left(Error) when the request fails\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"network error\"),\n );\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n const result = await dataSource.report(params);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpBlindSigningReporterDatasource: Failed to report blind signing event\",\n ),\n ),\n );\n });\n\n it(\"should call axios with the correct URL and method\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: `${config.reporter!.url}/blind-signing-events`,\n }),\n );\n });\n\n it(\"should call axios with the correct headers\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should call axios with the event payload and injected source as data\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpBlindSigningReporterDatasource(config);\n await dataSource.report(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n data: { ...params, source: config.appSource },\n }),\n );\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAAkB,oBAClBC,EAA4B,qBAI5BC,EAAmD,8DACnDC,EAIO,8CACPC,EAAoC,gDACpCC,EAGO,yCACPC,EAAoB,iCAEpB,GAAG,KAAK,OAAO,EAEf,SAAS,qCAAsC,IAAM,CACnD,MAAMC,EAAS,CACb,SAAU,CACR,IAAK,uBACP,EACA,YAAa,cACb,UAAW,aACb,EAEMC,EAAmC,CACvC,YAAa,uBACb,cAAe,qBAAmB,qBAClC,YAAa,GACb,QAAS,EACT,cAAe,6CACf,gBAAiB,kBAAgB,yBACjC,QAAS,sBAAoB,OAC7B,iBAAkB,SAClB,cAAe,QACf,WAAY,CACV,iBAAkB,mBAAiB,QACnC,qBAAsB,CACxB,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,SAAU,IAAM,CACvB,GAAG,4CAA6C,SAAY,CAE1D,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,sBAAsB,CAAE,KAAM,CAAC,CAAE,CAAC,EAI7D,MAAMC,EAAS,MADI,IAAI,qCAAmCH,CAAM,EAChC,OAAOC,CAAM,EAG7C,OAAOE,CAAM,EAAE,WAAQ,SAAM,MAAS,CAAC,CACzC,CAAC,E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names": ["import_axios", "import_purify_ts", "import_HttpBlindSigningReporterDatasource", "import_BlindSigningEvent", "import_BlindSigningModelId", "import_HttpHeaders", "import_package", "config", "params", "axios", "result", "PACKAGE"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/reporter/data/dto/BlindSigningEventDto.ts"],
4
- "sourcesContent": ["import {\n type BlindSigningMethod,\n type BlindSigningPlatform,\n type BlindSignReason,\n type ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { type BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\n\nexport type BlindSigningEventEthContextDto = {\n clearSigningType: ClearSigningType;\n partialContextErrors: number;\n};\n\nexport type BlindSigningEventDto = {\n signatureId: string;\n signingMethod: BlindSigningMethod;\n source: string;\n isBlindSign?: boolean;\n chainId: number | null;\n targetAddress: string | null;\n blindSignReason: BlindSignReason;\n modelId: BlindSigningModelId;\n signerAppVersion: string;\n deviceVersion: string | null;\n ethContext: BlindSigningEventEthContextDto | null;\n platform?: BlindSigningPlatform;\n appVersion?: string;\n platformOS?: string;\n platformVersion?: string;\n liveAppContext?: string | null;\n sessionId?: string | null;\n};\n"],
4
+ "sourcesContent": ["import {\n type BlindSigningMethod,\n type BlindSigningPlatform,\n type BlindSignReason,\n type ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { type BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\n\nexport type BlindSigningEventEthContextDto = {\n clearSigningType: ClearSigningType;\n partialContextErrors: number;\n};\n\nexport type BlindSigningEventDto = {\n signatureId: string;\n signingMethod: BlindSigningMethod;\n source: string;\n isBlindSign: boolean;\n chainId: number | null;\n targetAddress: string | null;\n blindSignReason: BlindSignReason | null;\n modelId: BlindSigningModelId;\n signerAppVersion: string;\n deviceVersion: string | null;\n ethContext: BlindSigningEventEthContextDto | null;\n platform?: BlindSigningPlatform;\n appVersion?: string;\n platformOS?: string;\n platformVersion?: string;\n liveAppContext?: string | null;\n sessionId?: string | null;\n};\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["BlindSigningEventDto_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("purify-ts"),r=require("../../reporter/model/BlindSigningEvent"),d=require("../../reporter/model/BlindSigningModelId"),i=require("./DefaultBlindSigningReporter");describe("DefaultBlindSigningReporter",()=>{const n={signatureId:"a3f8Kb-1738850400000",signingMethod:r.BlindSigningMethod.ETH_SIGN_TRANSACTION,source:"ledger_wallet",isBlindSign:!0,chainId:1,targetAddress:"0xdAC17F958D2ee523a2206206994597C13D831ec7",blindSignReason:r.BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,modelId:d.BlindSigningModelId.NANO_X,signerAppVersion:"1.12.1",deviceVersion:"2.2.3",ethContext:{clearSigningType:r.ClearSigningType.EIP7730,partialContextErrors:0}};it("should delegate to the datasource and return Right on success",async()=>{const t={report:vi.fn().mockResolvedValueOnce((0,e.Right)(void 0))},a=await new i.DefaultBlindSigningReporter(t).report(n);expect(t.report).toHaveBeenCalledWith(n),expect(a).toEqual((0,e.Right)(void 0))}),it("should delegate to the datasource and return Left on failure",async()=>{const t=new Error("report failed"),o={report:vi.fn().mockResolvedValueOnce((0,e.Left)(t))},l=await new i.DefaultBlindSigningReporter(o).report(n);expect(o.report).toHaveBeenCalledWith(n),expect(l).toEqual((0,e.Left)(t))})});
1
+ "use strict";var e=require("purify-ts"),r=require("../../reporter/model/BlindSigningEvent"),d=require("../../reporter/model/BlindSigningModelId"),i=require("./DefaultBlindSigningReporter");describe("DefaultBlindSigningReporter",()=>{const n={signatureId:"a3f8Kb-1738850400000",signingMethod:r.BlindSigningMethod.ETH_SIGN_TRANSACTION,isBlindSign:!0,chainId:1,targetAddress:"0xdAC17F958D2ee523a2206206994597C13D831ec7",blindSignReason:r.BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,modelId:d.BlindSigningModelId.NANO_X,signerAppVersion:"1.12.1",deviceVersion:"2.2.3",ethContext:{clearSigningType:r.ClearSigningType.EIP7730,partialContextErrors:0}};it("should delegate to the datasource and return Right on success",async()=>{const t={report:vi.fn().mockResolvedValueOnce((0,e.Right)(void 0))},a=await new i.DefaultBlindSigningReporter(t).report(n);expect(t.report).toHaveBeenCalledWith(n),expect(a).toEqual((0,e.Right)(void 0))}),it("should delegate to the datasource and return Left on failure",async()=>{const t=new Error("report failed"),o={report:vi.fn().mockResolvedValueOnce((0,e.Left)(t))},s=await new i.DefaultBlindSigningReporter(o).report(n);expect(o.report).toHaveBeenCalledWith(n),expect(s).toEqual((0,e.Left)(t))})});
2
2
  //# sourceMappingURL=DefaultBlindSigningReporter.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/reporter/domain/DefaultBlindSigningReporter.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type BlindSigningReporterDatasource } from \"@/reporter/data/BlindSigningReporterDatasource\";\nimport {\n BlindSigningMethod,\n BlindSignReason,\n ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\n\nimport { DefaultBlindSigningReporter } from \"./DefaultBlindSigningReporter\";\n\ndescribe(\"DefaultBlindSigningReporter\", () => {\n const params = {\n signatureId: \"a3f8Kb-1738850400000\",\n signingMethod: BlindSigningMethod.ETH_SIGN_TRANSACTION,\n source: \"ledger_wallet\",\n isBlindSign: true,\n chainId: 1,\n targetAddress: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n blindSignReason: BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,\n modelId: BlindSigningModelId.NANO_X,\n signerAppVersion: \"1.12.1\",\n deviceVersion: \"2.2.3\",\n ethContext: {\n clearSigningType: ClearSigningType.EIP7730,\n partialContextErrors: 0,\n },\n };\n\n it(\"should delegate to the datasource and return Right on success\", async () => {\n // GIVEN\n const dataSource: BlindSigningReporterDatasource = {\n report: vi.fn().mockResolvedValueOnce(Right(undefined)),\n };\n const reporter = new DefaultBlindSigningReporter(dataSource);\n\n // WHEN\n const result = await reporter.report(params);\n\n // THEN\n expect(dataSource.report).toHaveBeenCalledWith(params);\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"should delegate to the datasource and return Left on failure\", async () => {\n // GIVEN\n const error = new Error(\"report failed\");\n const dataSource: BlindSigningReporterDatasource = {\n report: vi.fn().mockResolvedValueOnce(Left(error)),\n };\n const reporter = new DefaultBlindSigningReporter(dataSource);\n\n // WHEN\n const result = await reporter.report(params);\n\n // THEN\n expect(dataSource.report).toHaveBeenCalledWith(params);\n expect(result).toEqual(Left(error));\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA4B,qBAG5BC,EAIO,8CACPC,EAAoC,gDAEpCC,EAA4C,yCAE5C,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAS,CACb,YAAa,uBACb,cAAe,qBAAmB,qBAClC,OAAQ,gBACR,YAAa,GACb,QAAS,EACT,cAAe,6CACf,gBAAiB,kBAAgB,yBACjC,QAAS,sBAAoB,OAC7B,iBAAkB,SAClB,cAAe,QACf,WAAY,CACV,iBAAkB,mBAAiB,QACnC,qBAAsB,CACxB,CACF,EAEA,GAAG,gEAAiE,SAAY,CAE9E,MAAMC,EAA6C,CACjD,OAAQ,GAAG,GAAG,EAAE,yBAAsB,SAAM,MAAS,CAAC,CACxD,EAIMC,EAAS,MAHE,IAAI,8BAA4BD,CAAU,EAG7B,OAAOD,CAAM,EAG3C,OAAOC,EAAW,MAAM,EAAE,qBAAqBD,CAAM,EACrD,OAAOE,CAAM,EAAE,WAAQ,SAAM,MAAS,CAAC,CACzC,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMC,EAAQ,IAAI,MAAM,eAAe,EACjCF,EAA6C,CACjD,OAAQ,GAAG,GAAG,EAAE,yBAAsB,QAAKE,CAAK,CAAC,CACnD,EAIMD,EAAS,MAHE,IAAI,8BAA4BD,CAAU,EAG7B,OAAOD,CAAM,EAG3C,OAAOC,EAAW,MAAM,EAAE,qBAAqBD,CAAM,EACrD,OAAOE,CAAM,EAAE,WAAQ,QAAKC,CAAK,CAAC,CACpC,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type BlindSigningReporterDatasource } from \"@/reporter/data/BlindSigningReporterDatasource\";\nimport {\n BlindSigningMethod,\n BlindSignReason,\n ClearSigningType,\n} from \"@/reporter/model/BlindSigningEvent\";\nimport { BlindSigningModelId } from \"@/reporter/model/BlindSigningModelId\";\n\nimport { DefaultBlindSigningReporter } from \"./DefaultBlindSigningReporter\";\n\ndescribe(\"DefaultBlindSigningReporter\", () => {\n const params = {\n signatureId: \"a3f8Kb-1738850400000\",\n signingMethod: BlindSigningMethod.ETH_SIGN_TRANSACTION,\n isBlindSign: true,\n chainId: 1,\n targetAddress: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n blindSignReason: BlindSignReason.NO_CLEAR_SIGNING_CONTEXT,\n modelId: BlindSigningModelId.NANO_X,\n signerAppVersion: \"1.12.1\",\n deviceVersion: \"2.2.3\",\n ethContext: {\n clearSigningType: ClearSigningType.EIP7730,\n partialContextErrors: 0,\n },\n };\n\n it(\"should delegate to the datasource and return Right on success\", async () => {\n // GIVEN\n const dataSource: BlindSigningReporterDatasource = {\n report: vi.fn().mockResolvedValueOnce(Right(undefined)),\n };\n const reporter = new DefaultBlindSigningReporter(dataSource);\n\n // WHEN\n const result = await reporter.report(params);\n\n // THEN\n expect(dataSource.report).toHaveBeenCalledWith(params);\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"should delegate to the datasource and return Left on failure\", async () => {\n // GIVEN\n const error = new Error(\"report failed\");\n const dataSource: BlindSigningReporterDatasource = {\n report: vi.fn().mockResolvedValueOnce(Left(error)),\n };\n const reporter = new DefaultBlindSigningReporter(dataSource);\n\n // WHEN\n const result = await reporter.report(params);\n\n // THEN\n expect(dataSource.report).toHaveBeenCalledWith(params);\n expect(result).toEqual(Left(error));\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA4B,qBAG5BC,EAIO,8CACPC,EAAoC,gDAEpCC,EAA4C,yCAE5C,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAS,CACb,YAAa,uBACb,cAAe,qBAAmB,qBAClC,YAAa,GACb,QAAS,EACT,cAAe,6CACf,gBAAiB,kBAAgB,yBACjC,QAAS,sBAAoB,OAC7B,iBAAkB,SAClB,cAAe,QACf,WAAY,CACV,iBAAkB,mBAAiB,QACnC,qBAAsB,CACxB,CACF,EAEA,GAAG,gEAAiE,SAAY,CAE9E,MAAMC,EAA6C,CACjD,OAAQ,GAAG,GAAG,EAAE,yBAAsB,SAAM,MAAS,CAAC,CACxD,EAIMC,EAAS,MAHE,IAAI,8BAA4BD,CAAU,EAG7B,OAAOD,CAAM,EAG3C,OAAOC,EAAW,MAAM,EAAE,qBAAqBD,CAAM,EACrD,OAAOE,CAAM,EAAE,WAAQ,SAAM,MAAS,CAAC,CACzC,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMC,EAAQ,IAAI,MAAM,eAAe,EACjCF,EAA6C,CACjD,OAAQ,GAAG,GAAG,EAAE,yBAAsB,QAAKE,CAAK,CAAC,CACnD,EAIMD,EAAS,MAHE,IAAI,8BAA4BD,CAAU,EAG7B,OAAOD,CAAM,EAG3C,OAAOC,EAAW,MAAM,EAAE,qBAAqBD,CAAM,EACrD,OAAOE,CAAM,EAAE,WAAQ,QAAKC,CAAK,CAAC,CACpC,CAAC,CACH,CAAC",
6
6
  "names": ["import_purify_ts", "import_BlindSigningEvent", "import_BlindSigningModelId", "import_DefaultBlindSigningReporter", "params", "dataSource", "result", "error"]
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-20260409001459"
61
+ "version": "0.0.0-develop-20260411001650"
62
62
  }
@@ -1,2 +1,2 @@
1
- import{noopLoggerFactory as o}from"@ledgerhq/device-management-kit";import{DefaultContextModule as r}from"./DefaultContextModule";const n="https://crypto-assets-service.api.ledger.com/v1",i="https://web3checks-backend.api.ledger.com/v3",a="https://nft.api.live.ledger.com",d="https://blind-signing-reporting.api.ledger.com",s=Object.freeze({cal:Object.freeze({url:n,mode:"prod",branch:"main"}),web3checks:Object.freeze({url:i}),metadataServiceDomain:Object.freeze({url:a}),reporter:Object.freeze({url:d}),datasource:Object.freeze({proxy:"default"})}),u={defaultLoaders:!0,defaultFieldLoaders:!0,customLoaders:[],customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,customBlindSigningReporter:void 0,customTrustedNameDataSource:void 0};class l{config;constructor({originToken:e,loggerFactory:t}){this.config={...s,...u,customLoaders:[],customFieldLoaders:[],originToken:e??"",loggerFactory:t??o}}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}setReporterConfig(e){return this.config.reporter=e,this}setBlindSigningReporter(e){return this.config.customBlindSigningReporter=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){return new r(this.config)}}export{l as ContextModuleBuilder,s as DEFAULT_CONFIG};
1
+ import{noopLoggerFactory as o}from"@ledgerhq/device-management-kit";import{DefaultContextModule as r}from"./DefaultContextModule";const n="https://crypto-assets-service.api.ledger.com/v1",i="https://web3checks-backend.api.ledger.com/v3",a="https://nft.api.live.ledger.com",s="https://ingest.aws.stg.ldg-tech.com/ingest/v1",d=Object.freeze({cal:Object.freeze({url:n,mode:"prod",branch:"main"}),web3checks:Object.freeze({url:i}),metadataServiceDomain:Object.freeze({url:a}),reporter:Object.freeze({url:s}),datasource:Object.freeze({proxy:"default"}),appSource:"third-party"}),u={defaultLoaders:!0,defaultFieldLoaders:!0,customLoaders:[],customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,customBlindSigningReporter:void 0,customTrustedNameDataSource:void 0};class f{config;constructor({originToken:e,loggerFactory:t}){this.config={...d,...u,customLoaders:[],customFieldLoaders:[],originToken:e??"",loggerFactory:t??o}}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}setReporterConfig(e){return this.config.reporter=e,this}setAppSource(e){return this.config.appSource=e,this}setBlindSigningReporter(e){return this.config.customBlindSigningReporter=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){return new r(this.config)}}export{f as ContextModuleBuilder,d 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 {\n type LoggerPublisherService,\n noopLoggerFactory,\n} 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 ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type BlindSigningReporter } from \"./reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\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\";\nconst DEFAULT_REPORTER_URL = \"https://blind-signing-reporting.api.ledger.com\";\n\n/**\n * Default configuration for the context module\n *\n * @note This configuration is frozen to prevent modifications after construction\n * and can be used by external packages to get a default configuration.\n */\nexport const DEFAULT_CONFIG: Readonly<ContextModuleConfig> = Object.freeze({\n cal: Object.freeze({\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n }),\n web3checks: Object.freeze({\n url: DEFAULT_WEB3_CHECKS_URL,\n }),\n metadataServiceDomain: Object.freeze({\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n }),\n reporter: Object.freeze({\n url: DEFAULT_REPORTER_URL,\n }),\n datasource: Object.freeze({ proxy: \"default\" }),\n});\n\n/**\n * Default loader configuration for the context module\n *\n * @note This configuration is internal and will be the default configuration for the context module.\n */\nconst DEFAULT_LOADER_CONFIG: ContextModuleLoaderConfig = {\n defaultLoaders: true,\n defaultFieldLoaders: true,\n customLoaders: [],\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n customBlindSigningReporter: undefined,\n customTrustedNameDataSource: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleServiceConfig & ContextModuleLoaderConfig;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...DEFAULT_LOADER_CONFIG,\n customLoaders: [],\n customFieldLoaders: [],\n originToken: originToken ?? \"\",\n loggerFactory: loggerFactory ?? noopLoggerFactory,\n } as ContextModuleServiceConfig & ContextModuleLoaderConfig;\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 reporter configuration\n *\n * @param reporterConfig\n * @returns this\n */\n setReporterConfig(reporterConfig: ContextModuleReporterConfig) {\n this.config.reporter = reporterConfig;\n return this;\n }\n\n /**\n * Set a custom blind signing reporter\n *\n * @param reporter reporter to use for blind signing events\n * @returns this\n */\n setBlindSigningReporter(reporter: BlindSigningReporter) {\n this.config.customBlindSigningReporter = reporter;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\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 return new DefaultContextModule(this.config);\n }\n}\n"],
5
- "mappings": "AAAA,OAEE,qBAAAA,MACK,kCAmBP,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAClCC,EAAuB,iDAQhBC,EAAgD,OAAO,OAAO,CACzE,IAAK,OAAO,OAAO,CACjB,IAAKJ,EACL,KAAM,OACN,OAAQ,MACV,CAAC,EACD,WAAY,OAAO,OAAO,CACxB,IAAKC,CACP,CAAC,EACD,sBAAuB,OAAO,OAAO,CACnC,IAAKC,CACP,CAAC,EACD,SAAU,OAAO,OAAO,CACtB,IAAKC,CACP,CAAC,EACD,WAAY,OAAO,OAAO,CAAE,MAAO,SAAU,CAAC,CAChD,CAAC,EAOKE,EAAmD,CACvD,eAAgB,GAChB,oBAAqB,GACrB,c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AULT_CONFIG", "DEFAULT_LOADER_CONFIG", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "reporterConfig", "reporter", "dataSource"]
4
+ "sourcesContent": ["import {\n type LoggerPublisherService,\n noopLoggerFactory,\n} 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 ContextModuleLoaderConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleReporterConfig,\n type ContextModuleServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type BlindSigningReporter } from \"./reporter/domain/BlindSigningReporter\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\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\";\nconst DEFAULT_REPORTER_URL = \"https://ingest.aws.stg.ldg-tech.com/ingest/v1\";\n\n/**\n * Default configuration for the context module\n *\n * @note This configuration is frozen to prevent modifications after construction\n * and can be used by external packages to get a default configuration.\n */\nexport const DEFAULT_CONFIG: Readonly<ContextModuleConfig> = Object.freeze({\n cal: Object.freeze({\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n }),\n web3checks: Object.freeze({\n url: DEFAULT_WEB3_CHECKS_URL,\n }),\n metadataServiceDomain: Object.freeze({\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n }),\n reporter: Object.freeze({\n url: DEFAULT_REPORTER_URL,\n }),\n datasource: Object.freeze({ proxy: \"default\" }),\n appSource: \"third-party\",\n});\n\n/**\n * Default loader configuration for the context module\n *\n * @note This configuration is internal and will be the default configuration for the context module.\n */\nconst DEFAULT_LOADER_CONFIG: ContextModuleLoaderConfig = {\n defaultLoaders: true,\n defaultFieldLoaders: true,\n customLoaders: [],\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n customBlindSigningReporter: undefined,\n customTrustedNameDataSource: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleServiceConfig & ContextModuleLoaderConfig;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...DEFAULT_LOADER_CONFIG,\n customLoaders: [],\n customFieldLoaders: [],\n originToken: originToken ?? \"\",\n loggerFactory: loggerFactory ?? noopLoggerFactory,\n } as ContextModuleServiceConfig & ContextModuleLoaderConfig;\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 reporter configuration\n *\n * @param reporterConfig\n * @returns this\n */\n setReporterConfig(reporterConfig: ContextModuleReporterConfig) {\n this.config.reporter = reporterConfig;\n return this;\n }\n\n /**\n * Set the app source identifier included in blind signing reports\n *\n * @param appSource\n * @returns this\n */\n setAppSource(appSource: string) {\n this.config.appSource = appSource;\n return this;\n }\n\n /**\n * Set a custom blind signing reporter\n *\n * @param reporter reporter to use for blind signing events\n * @returns this\n */\n setBlindSigningReporter(reporter: BlindSigningReporter) {\n this.config.customBlindSigningReporter = reporter;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\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 return new DefaultContextModule(this.config);\n }\n}\n"],
5
+ "mappings": "AAAA,OAEE,qBAAAA,MACK,kCAmBP,OAAS,wBAAAC,MAA4B,yBAErC,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AA6C,CAC7D,YAAK,OAAO,SAAWA,EAChB,IACT,CAQA,aAAaC,EAAmB,CAC9B,YAAK,OAAO,UAAYA,EACjB,IACT,CAQA,wBAAwBC,EAAgC,CACtD,YAAK,OAAO,2BAA6BA,EAClC,IACT,CAQA,yBAAyBC,EAAmC,CAC1D,YAAK,OAAO,4BAA8BA,EACnC,IACT,CAQA,iBAAiBT,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,OAAO,IAAIT,EAAqB,KAAK,MAAM,CAC7C,CACF",
6
+ "names": ["noopLoggerFactory", "DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_REPORTER_URL", "DEFAULT_CONFIG", "DEFAULT_LOADER_CONFIG", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "reporterConfig", "appSource", "reporter", "dataSource"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{DefaultContextModule as d}from"./DefaultContextModule";const x=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),s=()=>({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"},reporter:{url:"https://reporter.com"},datasource:{proxy:"default"},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"},r=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(r).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=s();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=s(),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"},r=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(r).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=s(),t=s(),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 r=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await r.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=s(),t=s(),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 r=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await r.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=s(),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{DefaultContextModule as d}from"./DefaultContextModule";const x=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),s=()=>({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"},reporter:{url:"https://reporter.com"},datasource:{proxy:"default"},appSource:"third-party",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"},r=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(r).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=s();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=s(),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"},r=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(r).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=s(),t=s(),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 r=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await r.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=s(),t=s(),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 r=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await r.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=s(),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