@metamask/snaps-controllers 12.3.1 → 13.0.0

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 (88) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/cronjob/CronjobController.cjs +250 -276
  3. package/dist/cronjob/CronjobController.cjs.map +1 -1
  4. package/dist/cronjob/CronjobController.d.cts +61 -78
  5. package/dist/cronjob/CronjobController.d.cts.map +1 -1
  6. package/dist/cronjob/CronjobController.d.mts +61 -78
  7. package/dist/cronjob/CronjobController.d.mts.map +1 -1
  8. package/dist/cronjob/CronjobController.mjs +251 -277
  9. package/dist/cronjob/CronjobController.mjs.map +1 -1
  10. package/dist/cronjob/utils.cjs +79 -0
  11. package/dist/cronjob/utils.cjs.map +1 -0
  12. package/dist/cronjob/utils.d.cts +25 -0
  13. package/dist/cronjob/utils.d.cts.map +1 -0
  14. package/dist/cronjob/utils.d.mts +25 -0
  15. package/dist/cronjob/utils.d.mts.map +1 -0
  16. package/dist/cronjob/utils.mjs +75 -0
  17. package/dist/cronjob/utils.mjs.map +1 -0
  18. package/dist/insights/SnapInsightsController.cjs +199 -149
  19. package/dist/insights/SnapInsightsController.cjs.map +1 -1
  20. package/dist/insights/SnapInsightsController.mjs +198 -148
  21. package/dist/insights/SnapInsightsController.mjs.map +1 -1
  22. package/dist/interface/SnapInterfaceController.cjs +160 -101
  23. package/dist/interface/SnapInterfaceController.cjs.map +1 -1
  24. package/dist/interface/SnapInterfaceController.mjs +160 -101
  25. package/dist/interface/SnapInterfaceController.mjs.map +1 -1
  26. package/dist/multichain/MultichainRouter.cjs +117 -114
  27. package/dist/multichain/MultichainRouter.cjs.map +1 -1
  28. package/dist/multichain/MultichainRouter.mjs +117 -114
  29. package/dist/multichain/MultichainRouter.mjs.map +1 -1
  30. package/dist/services/AbstractExecutionService.cjs +131 -139
  31. package/dist/services/AbstractExecutionService.cjs.map +1 -1
  32. package/dist/services/AbstractExecutionService.mjs +131 -139
  33. package/dist/services/AbstractExecutionService.mjs.map +1 -1
  34. package/dist/services/ProxyPostMessageStream.cjs +19 -26
  35. package/dist/services/ProxyPostMessageStream.cjs.map +1 -1
  36. package/dist/services/ProxyPostMessageStream.mjs +19 -26
  37. package/dist/services/ProxyPostMessageStream.mjs.map +1 -1
  38. package/dist/services/iframe/IframeExecutionService.cjs +1 -0
  39. package/dist/services/iframe/IframeExecutionService.cjs.map +1 -1
  40. package/dist/services/iframe/IframeExecutionService.mjs +1 -0
  41. package/dist/services/iframe/IframeExecutionService.mjs.map +1 -1
  42. package/dist/services/offscreen/OffscreenExecutionService.cjs +3 -16
  43. package/dist/services/offscreen/OffscreenExecutionService.cjs.map +1 -1
  44. package/dist/services/offscreen/OffscreenExecutionService.mjs +3 -16
  45. package/dist/services/offscreen/OffscreenExecutionService.mjs.map +1 -1
  46. package/dist/services/proxy/ProxyExecutionService.cjs +4 -17
  47. package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -1
  48. package/dist/services/proxy/ProxyExecutionService.mjs +4 -17
  49. package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
  50. package/dist/services/webview/WebViewExecutionService.cjs +6 -19
  51. package/dist/services/webview/WebViewExecutionService.cjs.map +1 -1
  52. package/dist/services/webview/WebViewExecutionService.mjs +6 -19
  53. package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
  54. package/dist/services/webview/WebViewMessageStream.cjs +13 -26
  55. package/dist/services/webview/WebViewMessageStream.cjs.map +1 -1
  56. package/dist/services/webview/WebViewMessageStream.mjs +13 -26
  57. package/dist/services/webview/WebViewMessageStream.mjs.map +1 -1
  58. package/dist/snaps/SnapController.cjs +1370 -1161
  59. package/dist/snaps/SnapController.cjs.map +1 -1
  60. package/dist/snaps/SnapController.d.cts +4 -4
  61. package/dist/snaps/SnapController.d.cts.map +1 -1
  62. package/dist/snaps/SnapController.d.mts +4 -4
  63. package/dist/snaps/SnapController.d.mts.map +1 -1
  64. package/dist/snaps/SnapController.mjs +1370 -1161
  65. package/dist/snaps/SnapController.mjs.map +1 -1
  66. package/dist/snaps/Timer.cjs +4 -0
  67. package/dist/snaps/Timer.cjs.map +1 -1
  68. package/dist/snaps/Timer.mjs +4 -0
  69. package/dist/snaps/Timer.mjs.map +1 -1
  70. package/dist/snaps/location/http.cjs +20 -4
  71. package/dist/snaps/location/http.cjs.map +1 -1
  72. package/dist/snaps/location/http.mjs +20 -4
  73. package/dist/snaps/location/http.mjs.map +1 -1
  74. package/dist/snaps/location/local.cjs +4 -17
  75. package/dist/snaps/location/local.cjs.map +1 -1
  76. package/dist/snaps/location/local.mjs +4 -17
  77. package/dist/snaps/location/local.mjs.map +1 -1
  78. package/dist/snaps/location/npm.cjs +28 -48
  79. package/dist/snaps/location/npm.cjs.map +1 -1
  80. package/dist/snaps/location/npm.d.cts.map +1 -1
  81. package/dist/snaps/location/npm.d.mts.map +1 -1
  82. package/dist/snaps/location/npm.mjs +28 -48
  83. package/dist/snaps/location/npm.mjs.map +1 -1
  84. package/dist/snaps/registry/json.cjs +173 -166
  85. package/dist/snaps/registry/json.cjs.map +1 -1
  86. package/dist/snaps/registry/json.mjs +172 -165
  87. package/dist/snaps/registry/json.mjs.map +1 -1
  88. package/package.json +9 -9
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Timer = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  class Timer {
6
+ // TODO: Either fix this lint violation or explain why it's necessary to
7
+ // ignore.
8
+ // eslint-disable-next-line no-restricted-syntax
9
+ state;
6
10
  /**
7
11
  * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately
8
12
  * If `ms` is +Infinity the timer never finishes.
@@ -1 +1 @@
1
- {"version":3,"file":"Timer.cjs","sourceRoot":"","sources":["../../src/snaps/Timer.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAIzC,MAAa,KAAK;IAoBhB;;;;;;OAMG;IACH,YAAY,EAAU;QACpB,IAA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AI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;QAExE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACvE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,OAAc,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,UAAU;YACjB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC7C,CAAC,CAAC,SAAS;SAChB,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF;AAzJD,sBAyJC","sourcesContent":["import { assert } from '@metamask/utils';\n\nexport type TimerStatus = 'stopped' | 'paused' | 'running' | 'finished';\n\nexport class Timer {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private state:\n | { value: 'stopped'; remaining: number }\n | {\n value: 'paused';\n remaining: number;\n callback: () => void;\n }\n | {\n value: 'running';\n remaining: number;\n callback: () => void;\n start: number;\n timeout?: unknown;\n }\n | { value: 'finished'; remaining: number };\n\n /**\n * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately\n * If `ms` is +Infinity the timer never finishes.\n *\n * @throws {@link TypeError}. If `ms` is NaN or negative.\n * @param ms - The number of milliseconds before the callback is called after started.\n */\n constructor(ms: number) {\n assert(\n !Number.isNaN(ms),\n new TypeError(\"Can't start a timer with NaN time\"),\n );\n assert(ms >= 0, new TypeError(\"Can't start a timer with negative time\"));\n this.state = { value: 'stopped', remaining: ms };\n }\n\n get status(): TimerStatus {\n return this.state.value;\n }\n\n get remaining(): number {\n return this.state.remaining;\n }\n\n /**\n * Cancels the currently running timer and marks it finished.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n cancel() {\n assert(\n this.status === 'paused' || this.status === 'running',\n new Error('Tried to cancel a not running Timer'),\n );\n this.onFinish(false);\n }\n\n /**\n * Marks the timer as finished prematurely and triggers the callback.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n finish() {\n assert(\n this.status !== 'finished',\n new Error('Tried to finish a finished Timer.'),\n );\n this.onFinish(true);\n }\n\n /**\n * Pauses a currently running timer, allowing it to resume later.\n *\n * @throws {@link Error}. If it wasn't running.\n */\n pause() {\n assert(\n this.state.value === 'running',\n new Error('Tried to pause a not running Timer'),\n );\n\n const { callback, start, timeout, remaining } = this.state;\n\n timeout !== undefined && clearTimeout(timeout as any);\n this.state = {\n value: 'paused',\n callback,\n remaining: remaining - (Date.now() - start),\n };\n }\n\n /**\n * Starts the timer.\n *\n * @param callback - The function that will be called after the timer finishes.\n * @throws {@link Error}. If it was already started.\n */\n start(callback: () => void) {\n assert(\n this.state.value === 'stopped',\n new Error('Tried to start an already running Timer'),\n );\n\n const { remaining } = this.state;\n this.state = { value: 'paused', remaining, callback };\n this.resume();\n }\n\n /**\n * Resumes a currently paused timer.\n *\n * @throws {@link Error}. If it wasn't paused.\n */\n resume() {\n assert(\n this.state.value === 'paused',\n new Error('Tried to resume not paused Timer'),\n );\n const { remaining, callback } = this.state;\n const start = Date.now();\n\n let timeout: unknown;\n // setTimeout returns immediately on +Infinity which we use\n if (remaining !== Number.POSITIVE_INFINITY) {\n timeout = setTimeout(() => this.onFinish(true), remaining);\n }\n\n this.state = { value: 'running', callback, remaining, start, timeout };\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private onFinish(shouldCall: boolean) {\n assert(this.state.value === 'running' || this.state.value === 'paused');\n\n if (this.state.value === 'running' && this.state.timeout !== undefined) {\n clearTimeout(this.state.timeout as any);\n }\n\n const { callback, remaining } = this.state;\n this.state = {\n value: 'finished',\n remaining:\n this.state.value === 'running'\n ? remaining - (Date.now() - this.state.start)\n : remaining,\n };\n\n if (shouldCall) {\n callback();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Timer.cjs","sourceRoot":"","sources":["../../src/snaps/Timer.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAIzC,MAAa,KAAK;IAChB,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,KAAK,CAcgC;IAE7C;;;;;;OAMG;IACH,YAAY,EAAU;QACpB,IAAA,cAAM,EACJ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EACjB,IAAI,SAAS,CAAC,mCAAmC,CAAC,CACnD,CAAC;QACF,IAAA,cAAM,EAAC,EAAE,IAAI,CAAC,EAAE,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACnD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,IAAA,cAAM,EACJ,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EACrD,IAAI,KAAK,CAAC,qCAAqC,CAAC,CACjD,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,IAAA,cAAM,EACJ,IAAI,CAAC,MAAM,KAAK,UAAU,EAC1B,IAAI,KAAK,CAAC,mCAAmC,CAAC,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S,KAAK,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAC3C,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACzE,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,QAAQ,CAAC,UAAmB;QAClC,IAAA,cAAM,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;QAExE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACvE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,OAAc,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,UAAU;YACjB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC7C,CAAC,CAAC,SAAS;SAChB,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF;AAzJD,sBAyJC","sourcesContent":["import { assert } from '@metamask/utils';\n\nexport type TimerStatus = 'stopped' | 'paused' | 'running' | 'finished';\n\nexport class Timer {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private state:\n | { value: 'stopped'; remaining: number }\n | {\n value: 'paused';\n remaining: number;\n callback: () => void;\n }\n | {\n value: 'running';\n remaining: number;\n callback: () => void;\n start: number;\n timeout?: unknown;\n }\n | { value: 'finished'; remaining: number };\n\n /**\n * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately\n * If `ms` is +Infinity the timer never finishes.\n *\n * @throws {@link TypeError}. If `ms` is NaN or negative.\n * @param ms - The number of milliseconds before the callback is called after started.\n */\n constructor(ms: number) {\n assert(\n !Number.isNaN(ms),\n new TypeError(\"Can't start a timer with NaN time\"),\n );\n assert(ms >= 0, new TypeError(\"Can't start a timer with negative time\"));\n this.state = { value: 'stopped', remaining: ms };\n }\n\n get status(): TimerStatus {\n return this.state.value;\n }\n\n get remaining(): number {\n return this.state.remaining;\n }\n\n /**\n * Cancels the currently running timer and marks it finished.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n cancel() {\n assert(\n this.status === 'paused' || this.status === 'running',\n new Error('Tried to cancel a not running Timer'),\n );\n this.onFinish(false);\n }\n\n /**\n * Marks the timer as finished prematurely and triggers the callback.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n finish() {\n assert(\n this.status !== 'finished',\n new Error('Tried to finish a finished Timer.'),\n );\n this.onFinish(true);\n }\n\n /**\n * Pauses a currently running timer, allowing it to resume later.\n *\n * @throws {@link Error}. If it wasn't running.\n */\n pause() {\n assert(\n this.state.value === 'running',\n new Error('Tried to pause a not running Timer'),\n );\n\n const { callback, start, timeout, remaining } = this.state;\n\n timeout !== undefined && clearTimeout(timeout as any);\n this.state = {\n value: 'paused',\n callback,\n remaining: remaining - (Date.now() - start),\n };\n }\n\n /**\n * Starts the timer.\n *\n * @param callback - The function that will be called after the timer finishes.\n * @throws {@link Error}. If it was already started.\n */\n start(callback: () => void) {\n assert(\n this.state.value === 'stopped',\n new Error('Tried to start an already running Timer'),\n );\n\n const { remaining } = this.state;\n this.state = { value: 'paused', remaining, callback };\n this.resume();\n }\n\n /**\n * Resumes a currently paused timer.\n *\n * @throws {@link Error}. If it wasn't paused.\n */\n resume() {\n assert(\n this.state.value === 'paused',\n new Error('Tried to resume not paused Timer'),\n );\n const { remaining, callback } = this.state;\n const start = Date.now();\n\n let timeout: unknown;\n // setTimeout returns immediately on +Infinity which we use\n if (remaining !== Number.POSITIVE_INFINITY) {\n timeout = setTimeout(() => this.onFinish(true), remaining);\n }\n\n this.state = { value: 'running', callback, remaining, start, timeout };\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private onFinish(shouldCall: boolean) {\n assert(this.state.value === 'running' || this.state.value === 'paused');\n\n if (this.state.value === 'running' && this.state.timeout !== undefined) {\n clearTimeout(this.state.timeout as any);\n }\n\n const { callback, remaining } = this.state;\n this.state = {\n value: 'finished',\n remaining:\n this.state.value === 'running'\n ? remaining - (Date.now() - this.state.start)\n : remaining,\n };\n\n if (shouldCall) {\n callback();\n }\n }\n}\n"]}
@@ -1,5 +1,9 @@
1
1
  import { assert } from "@metamask/utils";
2
2
  export class Timer {
3
+ // TODO: Either fix this lint violation or explain why it's necessary to
4
+ // ignore.
5
+ // eslint-disable-next-line no-restricted-syntax
6
+ state;
3
7
  /**
4
8
  * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately
5
9
  * If `ms` is +Infinity the timer never finishes.
@@ -1 +1 @@
1
- {"version":3,"file":"Timer.mjs","sourceRoot":"","sources":["../../src/snaps/Timer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAIzC,MAAM,OAAO,KAAK;IAoBhB;;;;;;OAMG;IACH,YAAY,EAAU;QACpB,MAAM,CACJ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EACjB,IAAI,SAAS,CAAC,mCAAmC,CAAC,CACnD,CAAC;QACF,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,IAA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AC,KAAK,CAAC,OAAc,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,UAAU;YACjB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC7C,CAAC,CAAC,SAAS;SAChB,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF","sourcesContent":["import { assert } from '@metamask/utils';\n\nexport type TimerStatus = 'stopped' | 'paused' | 'running' | 'finished';\n\nexport class Timer {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private state:\n | { value: 'stopped'; remaining: number }\n | {\n value: 'paused';\n remaining: number;\n callback: () => void;\n }\n | {\n value: 'running';\n remaining: number;\n callback: () => void;\n start: number;\n timeout?: unknown;\n }\n | { value: 'finished'; remaining: number };\n\n /**\n * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately\n * If `ms` is +Infinity the timer never finishes.\n *\n * @throws {@link TypeError}. If `ms` is NaN or negative.\n * @param ms - The number of milliseconds before the callback is called after started.\n */\n constructor(ms: number) {\n assert(\n !Number.isNaN(ms),\n new TypeError(\"Can't start a timer with NaN time\"),\n );\n assert(ms >= 0, new TypeError(\"Can't start a timer with negative time\"));\n this.state = { value: 'stopped', remaining: ms };\n }\n\n get status(): TimerStatus {\n return this.state.value;\n }\n\n get remaining(): number {\n return this.state.remaining;\n }\n\n /**\n * Cancels the currently running timer and marks it finished.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n cancel() {\n assert(\n this.status === 'paused' || this.status === 'running',\n new Error('Tried to cancel a not running Timer'),\n );\n this.onFinish(false);\n }\n\n /**\n * Marks the timer as finished prematurely and triggers the callback.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n finish() {\n assert(\n this.status !== 'finished',\n new Error('Tried to finish a finished Timer.'),\n );\n this.onFinish(true);\n }\n\n /**\n * Pauses a currently running timer, allowing it to resume later.\n *\n * @throws {@link Error}. If it wasn't running.\n */\n pause() {\n assert(\n this.state.value === 'running',\n new Error('Tried to pause a not running Timer'),\n );\n\n const { callback, start, timeout, remaining } = this.state;\n\n timeout !== undefined && clearTimeout(timeout as any);\n this.state = {\n value: 'paused',\n callback,\n remaining: remaining - (Date.now() - start),\n };\n }\n\n /**\n * Starts the timer.\n *\n * @param callback - The function that will be called after the timer finishes.\n * @throws {@link Error}. If it was already started.\n */\n start(callback: () => void) {\n assert(\n this.state.value === 'stopped',\n new Error('Tried to start an already running Timer'),\n );\n\n const { remaining } = this.state;\n this.state = { value: 'paused', remaining, callback };\n this.resume();\n }\n\n /**\n * Resumes a currently paused timer.\n *\n * @throws {@link Error}. If it wasn't paused.\n */\n resume() {\n assert(\n this.state.value === 'paused',\n new Error('Tried to resume not paused Timer'),\n );\n const { remaining, callback } = this.state;\n const start = Date.now();\n\n let timeout: unknown;\n // setTimeout returns immediately on +Infinity which we use\n if (remaining !== Number.POSITIVE_INFINITY) {\n timeout = setTimeout(() => this.onFinish(true), remaining);\n }\n\n this.state = { value: 'running', callback, remaining, start, timeout };\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private onFinish(shouldCall: boolean) {\n assert(this.state.value === 'running' || this.state.value === 'paused');\n\n if (this.state.value === 'running' && this.state.timeout !== undefined) {\n clearTimeout(this.state.timeout as any);\n }\n\n const { callback, remaining } = this.state;\n this.state = {\n value: 'finished',\n remaining:\n this.state.value === 'running'\n ? remaining - (Date.now() - this.state.start)\n : remaining,\n };\n\n if (shouldCall) {\n callback();\n }\n }\n}\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QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACzE,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,QAAQ,CAAC,UAAmB;QAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;QAExE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACvE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,OAAc,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,UAAU;YACjB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC7C,CAAC,CAAC,SAAS;SAChB,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF","sourcesContent":["import { assert } from '@metamask/utils';\n\nexport type TimerStatus = 'stopped' | 'paused' | 'running' | 'finished';\n\nexport class Timer {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private state:\n | { value: 'stopped'; remaining: number }\n | {\n value: 'paused';\n remaining: number;\n callback: () => void;\n }\n | {\n value: 'running';\n remaining: number;\n callback: () => void;\n start: number;\n timeout?: unknown;\n }\n | { value: 'finished'; remaining: number };\n\n /**\n * If `ms` is smaller or equal to zero (including -Infinity), the callback is added to the event loop and executed async immediately\n * If `ms` is +Infinity the timer never finishes.\n *\n * @throws {@link TypeError}. If `ms` is NaN or negative.\n * @param ms - The number of milliseconds before the callback is called after started.\n */\n constructor(ms: number) {\n assert(\n !Number.isNaN(ms),\n new TypeError(\"Can't start a timer with NaN time\"),\n );\n assert(ms >= 0, new TypeError(\"Can't start a timer with negative time\"));\n this.state = { value: 'stopped', remaining: ms };\n }\n\n get status(): TimerStatus {\n return this.state.value;\n }\n\n get remaining(): number {\n return this.state.remaining;\n }\n\n /**\n * Cancels the currently running timer and marks it finished.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n cancel() {\n assert(\n this.status === 'paused' || this.status === 'running',\n new Error('Tried to cancel a not running Timer'),\n );\n this.onFinish(false);\n }\n\n /**\n * Marks the timer as finished prematurely and triggers the callback.\n *\n * @throws {@link Error}. If it wasn't running or paused.\n */\n finish() {\n assert(\n this.status !== 'finished',\n new Error('Tried to finish a finished Timer.'),\n );\n this.onFinish(true);\n }\n\n /**\n * Pauses a currently running timer, allowing it to resume later.\n *\n * @throws {@link Error}. If it wasn't running.\n */\n pause() {\n assert(\n this.state.value === 'running',\n new Error('Tried to pause a not running Timer'),\n );\n\n const { callback, start, timeout, remaining } = this.state;\n\n timeout !== undefined && clearTimeout(timeout as any);\n this.state = {\n value: 'paused',\n callback,\n remaining: remaining - (Date.now() - start),\n };\n }\n\n /**\n * Starts the timer.\n *\n * @param callback - The function that will be called after the timer finishes.\n * @throws {@link Error}. If it was already started.\n */\n start(callback: () => void) {\n assert(\n this.state.value === 'stopped',\n new Error('Tried to start an already running Timer'),\n );\n\n const { remaining } = this.state;\n this.state = { value: 'paused', remaining, callback };\n this.resume();\n }\n\n /**\n * Resumes a currently paused timer.\n *\n * @throws {@link Error}. If it wasn't paused.\n */\n resume() {\n assert(\n this.state.value === 'paused',\n new Error('Tried to resume not paused Timer'),\n );\n const { remaining, callback } = this.state;\n const start = Date.now();\n\n let timeout: unknown;\n // setTimeout returns immediately on +Infinity which we use\n if (remaining !== Number.POSITIVE_INFINITY) {\n timeout = setTimeout(() => this.onFinish(true), remaining);\n }\n\n this.state = { value: 'running', callback, remaining, start, timeout };\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private onFinish(shouldCall: boolean) {\n assert(this.state.value === 'running' || this.state.value === 'paused');\n\n if (this.state.value === 'running' && this.state.timeout !== undefined) {\n clearTimeout(this.state.timeout as any);\n }\n\n const { callback, remaining } = this.state;\n this.state = {\n value: 'finished',\n remaining:\n this.state.value === 'running'\n ? remaining - (Date.now() - this.state.start)\n : remaining,\n };\n\n if (shouldCall) {\n callback();\n }\n }\n}\n"]}
@@ -4,11 +4,27 @@ exports.HttpLocation = void 0;
4
4
  const snaps_utils_1 = require("@metamask/snaps-utils");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  class HttpLocation {
7
+ // TODO: Either fix this lint violation or explain why it's necessary to
8
+ // ignore.
9
+ // eslint-disable-next-line no-restricted-syntax
10
+ cache = new Map();
11
+ // TODO: Either fix this lint violation or explain why it's necessary to
12
+ // ignore.
13
+ // eslint-disable-next-line no-restricted-syntax
14
+ validatedManifest;
15
+ // TODO: Either fix this lint violation or explain why it's necessary to
16
+ // ignore.
17
+ // eslint-disable-next-line no-restricted-syntax
18
+ url;
19
+ // TODO: Either fix this lint violation or explain why it's necessary to
20
+ // ignore.
21
+ // eslint-disable-next-line no-restricted-syntax
22
+ fetchFn;
23
+ // TODO: Either fix this lint violation or explain why it's necessary to
24
+ // ignore.
25
+ // eslint-disable-next-line no-restricted-syntax
26
+ fetchOptions;
7
27
  constructor(url, opts = {}) {
8
- // TODO: Either fix this lint violation or explain why it's necessary to
9
- // ignore.
10
- // eslint-disable-next-line no-restricted-syntax
11
- this.cache = new Map();
12
28
  (0, utils_1.assertStruct)(url.toString(), snaps_utils_1.HttpSnapIdStruct, 'Invalid Snap Id: ');
13
29
  this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);
14
30
  this.fetchOptions = opts.fetchOptions;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AAiD,CAClD,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,WAAW,CAAC,IAAY;QAC9B,IAAA,cAAM,EAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAvGD,oCAuGC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport type HttpOptions = {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n};\n\nexport class HttpLocation implements SnapLocation {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly cache = new Map<string, VirtualFile>();\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly url: URL;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchFn: typeof fetch;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this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GAAG,IAAI,yBAAW,CAAC;YAC5B,KAAK,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,EAAE,aAAa,EAAE;SACxB,CAAC,CAAC;QACH,IAAA,cAAM,EACJ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAC7B,iDAAiD,CAClD,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,WAAW,CAAC,IAAY;QAC9B,IAAA,cAAM,EAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAvGD,oCAuGC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport type HttpOptions = {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n};\n\nexport class HttpLocation implements SnapLocation {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly cache = new Map<string, VirtualFile>();\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly url: URL;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchFn: typeof fetch;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
@@ -1,11 +1,27 @@
1
1
  import { VirtualFile, HttpSnapIdStruct, NpmSnapFileNames, createSnapManifest, normalizeRelative, parseJson } from "@metamask/snaps-utils";
2
2
  import { assert, assertStruct } from "@metamask/utils";
3
3
  export class HttpLocation {
4
+ // TODO: Either fix this lint violation or explain why it's necessary to
5
+ // ignore.
6
+ // eslint-disable-next-line no-restricted-syntax
7
+ cache = new Map();
8
+ // TODO: Either fix this lint violation or explain why it's necessary to
9
+ // ignore.
10
+ // eslint-disable-next-line no-restricted-syntax
11
+ validatedManifest;
12
+ // TODO: Either fix this lint violation or explain why it's necessary to
13
+ // ignore.
14
+ // eslint-disable-next-line no-restricted-syntax
15
+ url;
16
+ // TODO: Either fix this lint violation or explain why it's necessary to
17
+ // ignore.
18
+ // eslint-disable-next-line no-restricted-syntax
19
+ fetchFn;
20
+ // TODO: Either fix this lint violation or explain why it's necessary to
21
+ // ignore.
22
+ // eslint-disable-next-line no-restricted-syntax
23
+ fetchOptions;
4
24
  constructor(url, opts = {}) {
5
- // TODO: Either fix this lint violation or explain why it's necessary to
6
- // ignore.
7
- // eslint-disable-next-line no-restricted-syntax
8
- this.cache = new Map();
9
25
  assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');
10
26
  this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);
11
27
  this.fetchOptions = opts.fetchOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"http.mjs","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EA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AAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,WAAW,CAAC,IAAY;QAC9B,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport type HttpOptions = {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n};\n\nexport class HttpLocation implements SnapLocation {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly cache = new Map<string, VirtualFile>();\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly url: URL;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchFn: typeof fetch;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
1
+ {"version":3,"file":"http.mjs","sourceRoot":"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QAAQ,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC;YAC5B,KAAK,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,EAAE,aAAa,EAAE;SACxB,CAAC,CAAC;QACH,MAAM,CACJ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAC7B,iDAAiD,CAClD,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,WAAW,CAAC,IAAY;QAC9B,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport type HttpOptions = {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n};\n\nexport class HttpLocation implements SnapLocation {\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly cache = new Map<string, VirtualFile>();\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly url: URL;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchFn: typeof fetch;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
@@ -1,42 +1,29 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _LocalLocation_http;
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.LocalLocation = void 0;
16
4
  const snaps_utils_1 = require("@metamask/snaps-utils");
17
5
  const utils_1 = require("@metamask/utils");
18
6
  const http_1 = require("./http.cjs");
19
7
  class LocalLocation {
8
+ #http;
20
9
  constructor(url, opts = {}) {
21
- _LocalLocation_http.set(this, void 0);
22
10
  (0, utils_1.assertStruct)(url.toString(), snaps_utils_1.LocalSnapIdStruct, 'Invalid Snap Id');
23
11
  // TODO(ritave): Write deepMerge() which merges fetchOptions.
24
12
  (0, utils_1.assert)(opts.fetchOptions === undefined, 'Currently adding fetch options to local: is unsupported.');
25
- __classPrivateFieldSet(this, _LocalLocation_http, new http_1.HttpLocation(new URL(url.toString().slice(snaps_utils_1.SnapIdPrefixes.local.length)), { ...opts, fetchOptions: { cache: 'no-cache' } }), "f");
13
+ this.#http = new http_1.HttpLocation(new URL(url.toString().slice(snaps_utils_1.SnapIdPrefixes.local.length)), { ...opts, fetchOptions: { cache: 'no-cache' } });
26
14
  }
27
15
  async manifest() {
28
- const vfile = await __classPrivateFieldGet(this, _LocalLocation_http, "f").manifest();
16
+ const vfile = await this.#http.manifest();
29
17
  return convertCanonical(vfile);
30
18
  }
31
19
  async fetch(path) {
32
- return convertCanonical(await __classPrivateFieldGet(this, _LocalLocation_http, "f").fetch(path));
20
+ return convertCanonical(await this.#http.fetch(path));
33
21
  }
34
22
  get shouldAlwaysReload() {
35
23
  return true;
36
24
  }
37
25
  }
38
26
  exports.LocalLocation = LocalLocation;
39
- _LocalLocation_http = new WeakMap();
40
27
  /**
41
28
  * Converts vfiles with canonical `http:` paths into `local:` paths.
42
29
  *
@@ -1 +1 @@
1
- {"version":3,"file":"local.cjs","sourceRoot":"","sources":["../../../src/snaps/location/local.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAA0E;AAC1E,2CAAuD;AAGvD,qCAAsC;AAGtC,MAAa,aAAa;IAGxB,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAFnC,sCAAoB;QAG3B,IAAA,oBAAY,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,+BAAiB,EAAE,iBAAiB,CAAC,CAAC;QACnE,6DAA6D;QAC7D,IAAA,cAAM,EACJ,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,0DAA0D,CAC3D,CAAC;QAEF,uBAAA,IAAI,uBAAS,IAAI,mBAAY,CAC3B,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,4BAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC1D,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACjD,MAAA,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,MAAM,uBAAA,IAAI,2BAAM,CAAC,QAAQ,EAAE,CAAC;QAE1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,MAAM,uBAAA,IAAI,2BAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9BD,sCA8BC;;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAA0B;IAE1B,IAAA,cAAM,EAAC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { LocalSnapIdStruct, SnapIdPrefixes } from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { HttpOptions } from './http';\nimport { HttpLocation } from './http';\nimport type { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n readonly #http: HttpLocation;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n // TODO(ritave): Write deepMerge() which merges fetchOptions.\n assert(\n opts.fetchOptions === undefined,\n 'Currently adding fetch options to local: is unsupported.',\n );\n\n this.#http = new HttpLocation(\n new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n { ...opts, fetchOptions: { cache: 'no-cache' } },\n );\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n const vfile = await this.#http.manifest();\n\n return convertCanonical(vfile);\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n return convertCanonical(await this.#http.fetch(path));\n }\n\n get shouldAlwaysReload() {\n return true;\n }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n assert(vfile.data.canonicalPath !== undefined);\n vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n return vfile;\n}\n"]}
1
+ {"version":3,"file":"local.cjs","sourceRoot":"","sources":["../../../src/snaps/location/local.ts"],"names":[],"mappings":";;;AACA,uDAA0E;AAC1E,2CAAuD;AAGvD,qCAAsC;AAGtC,MAAa,aAAa;IACf,KAAK,CAAe;IAE7B,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAC1C,IAAA,oBAAY,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,+BAAiB,EAAE,iBAAiB,CAAC,CAAC;QACnE,6DAA6D;QAC7D,IAAA,cAAM,EACJ,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,0DAA0D,CAC3D,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAY,CAC3B,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,4BAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC1D,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACjD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAE1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9BD,sCA8BC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAA0B;IAE1B,IAAA,cAAM,EAAC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { LocalSnapIdStruct, SnapIdPrefixes } from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { HttpOptions } from './http';\nimport { HttpLocation } from './http';\nimport type { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n readonly #http: HttpLocation;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n // TODO(ritave): Write deepMerge() which merges fetchOptions.\n assert(\n opts.fetchOptions === undefined,\n 'Currently adding fetch options to local: is unsupported.',\n );\n\n this.#http = new HttpLocation(\n new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n { ...opts, fetchOptions: { cache: 'no-cache' } },\n );\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n const vfile = await this.#http.manifest();\n\n return convertCanonical(vfile);\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n return convertCanonical(await this.#http.fetch(path));\n }\n\n get shouldAlwaysReload() {\n return true;\n }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n assert(vfile.data.canonicalPath !== undefined);\n vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n return vfile;\n}\n"]}
@@ -1,38 +1,25 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _LocalLocation_http;
13
1
  import { LocalSnapIdStruct, SnapIdPrefixes } from "@metamask/snaps-utils";
14
2
  import { assert, assertStruct } from "@metamask/utils";
15
3
  import { HttpLocation } from "./http.mjs";
16
4
  export class LocalLocation {
5
+ #http;
17
6
  constructor(url, opts = {}) {
18
- _LocalLocation_http.set(this, void 0);
19
7
  assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');
20
8
  // TODO(ritave): Write deepMerge() which merges fetchOptions.
21
9
  assert(opts.fetchOptions === undefined, 'Currently adding fetch options to local: is unsupported.');
22
- __classPrivateFieldSet(this, _LocalLocation_http, new HttpLocation(new URL(url.toString().slice(SnapIdPrefixes.local.length)), { ...opts, fetchOptions: { cache: 'no-cache' } }), "f");
10
+ this.#http = new HttpLocation(new URL(url.toString().slice(SnapIdPrefixes.local.length)), { ...opts, fetchOptions: { cache: 'no-cache' } });
23
11
  }
24
12
  async manifest() {
25
- const vfile = await __classPrivateFieldGet(this, _LocalLocation_http, "f").manifest();
13
+ const vfile = await this.#http.manifest();
26
14
  return convertCanonical(vfile);
27
15
  }
28
16
  async fetch(path) {
29
- return convertCanonical(await __classPrivateFieldGet(this, _LocalLocation_http, "f").fetch(path));
17
+ return convertCanonical(await this.#http.fetch(path));
30
18
  }
31
19
  get shouldAlwaysReload() {
32
20
  return true;
33
21
  }
34
22
  }
35
- _LocalLocation_http = new WeakMap();
36
23
  /**
37
24
  * Converts vfiles with canonical `http:` paths into `local:` paths.
38
25
  *
@@ -1 +1 @@
1
- {"version":3,"file":"local.mjs","sourceRoot":"","sources":["../../../src/snaps/location/local.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,8BAA8B;AAC1E,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,wBAAwB;AAGvD,OAAO,EAAE,YAAY,EAAE,mBAAe;AAGtC,MAAM,OAAO,aAAa;IAGxB,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAFnC,sCAAoB;QAG3B,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QACnE,6DAA6D;QAC7D,MAAM,CACJ,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,0DAA0D,CAC3D,CAAC;QAEF,uBAAA,IAAI,uBAAS,IAAI,YAAY,CAC3B,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC1D,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACjD,MAAA,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,MAAM,uBAAA,IAAI,2BAAM,CAAC,QAAQ,EAAE,CAAC;QAE1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,MAAM,uBAAA,IAAI,2BAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { LocalSnapIdStruct, SnapIdPrefixes } from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { HttpOptions } from './http';\nimport { HttpLocation } from './http';\nimport type { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n readonly #http: HttpLocation;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n // TODO(ritave): Write deepMerge() which merges fetchOptions.\n assert(\n opts.fetchOptions === undefined,\n 'Currently adding fetch options to local: is unsupported.',\n );\n\n this.#http = new HttpLocation(\n new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n { ...opts, fetchOptions: { cache: 'no-cache' } },\n );\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n const vfile = await this.#http.manifest();\n\n return convertCanonical(vfile);\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n return convertCanonical(await this.#http.fetch(path));\n }\n\n get shouldAlwaysReload() {\n return true;\n }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n assert(vfile.data.canonicalPath !== undefined);\n vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n return vfile;\n}\n"]}
1
+ {"version":3,"file":"local.mjs","sourceRoot":"","sources":["../../../src/snaps/location/local.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,8BAA8B;AAC1E,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,wBAAwB;AAGvD,OAAO,EAAE,YAAY,EAAE,mBAAe;AAGtC,MAAM,OAAO,aAAa;IACf,KAAK,CAAe;IAE7B,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAC1C,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QACnE,6DAA6D;QAC7D,MAAM,CACJ,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,0DAA0D,CAC3D,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAC3B,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC1D,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACjD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAE1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { LocalSnapIdStruct, SnapIdPrefixes } from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { HttpOptions } from './http';\nimport { HttpLocation } from './http';\nimport type { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n readonly #http: HttpLocation;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n // TODO(ritave): Write deepMerge() which merges fetchOptions.\n assert(\n opts.fetchOptions === undefined,\n 'Currently adding fetch options to local: is unsupported.',\n );\n\n this.#http = new HttpLocation(\n new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n { ...opts, fetchOptions: { cache: 'no-cache' } },\n );\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n const vfile = await this.#http.manifest();\n\n return convertCanonical(vfile);\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n return convertCanonical(await this.#http.fetch(path));\n }\n\n get shouldAlwaysReload() {\n return true;\n }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n assert(vfile.data.canonicalPath !== undefined);\n vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n return vfile;\n}\n"]}
@@ -1,24 +1,11 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
- var _BaseNpmLocation_instances, _BaseNpmLocation_validatedManifest, _BaseNpmLocation_files, _BaseNpmLocation_lazyInit;
17
5
  Object.defineProperty(exports, "__esModule", { value: true });
18
6
  exports.getNpmCanonicalBasePath = exports.fetchNpmMetadata = exports.NpmLocation = exports.TARBALL_SIZE_SAFETY_LIMIT = exports.BaseNpmLocation = exports.DEFAULT_NPM_REGISTRY = void 0;
19
7
  const snaps_utils_1 = require("@metamask/snaps-utils");
20
8
  const utils_1 = require("@metamask/utils");
21
- const browserify_zlib_1 = require("browserify-zlib");
22
9
  const concat_stream_1 = __importDefault(require("concat-stream"));
23
10
  const get_npm_tarball_url_1 = __importDefault(require("get-npm-tarball-url"));
24
11
  const readable_stream_1 = require("readable-stream");
@@ -27,10 +14,10 @@ const tar_stream_1 = require("tar-stream");
27
14
  exports.DEFAULT_NPM_REGISTRY = new URL('https://registry.npmjs.org');
28
15
  // Base class for NPM implementation, useful for extending with custom NPM fetching logic
29
16
  class BaseNpmLocation {
17
+ meta;
18
+ #validatedManifest;
19
+ #files;
30
20
  constructor(url, opts = {}) {
31
- _BaseNpmLocation_instances.add(this);
32
- _BaseNpmLocation_validatedManifest.set(this, void 0);
33
- _BaseNpmLocation_files.set(this, void 0);
34
21
  const allowCustomRegistries = opts.allowCustomRegistries ?? false;
35
22
  const fetchFunction = opts.fetch ?? globalThis.fetch.bind(undefined);
36
23
  const requestedRange = opts.versionRange ?? snaps_utils_1.DEFAULT_REQUESTED_SNAP_VERSION;
@@ -74,22 +61,22 @@ class BaseNpmLocation {
74
61
  };
75
62
  }
76
63
  async manifest() {
77
- if (__classPrivateFieldGet(this, _BaseNpmLocation_validatedManifest, "f")) {
78
- return __classPrivateFieldGet(this, _BaseNpmLocation_validatedManifest, "f").clone();
64
+ if (this.#validatedManifest) {
65
+ return this.#validatedManifest.clone();
79
66
  }
80
67
  const vfile = await this.fetch('snap.manifest.json');
81
68
  const result = (0, snaps_utils_1.parseJson)(vfile.toString());
82
69
  vfile.result = (0, snaps_utils_1.createSnapManifest)(result);
83
- __classPrivateFieldSet(this, _BaseNpmLocation_validatedManifest, vfile, "f");
70
+ this.#validatedManifest = vfile;
84
71
  return this.manifest();
85
72
  }
86
73
  async fetch(path) {
87
74
  const relativePath = (0, snaps_utils_1.normalizeRelative)(path);
88
- if (!__classPrivateFieldGet(this, _BaseNpmLocation_files, "f")) {
89
- await __classPrivateFieldGet(this, _BaseNpmLocation_instances, "m", _BaseNpmLocation_lazyInit).call(this);
90
- (0, utils_1.assert)(__classPrivateFieldGet(this, _BaseNpmLocation_files, "f") !== undefined);
75
+ if (!this.#files) {
76
+ await this.#lazyInit();
77
+ (0, utils_1.assert)(this.#files !== undefined);
91
78
  }
92
- const vfile = __classPrivateFieldGet(this, _BaseNpmLocation_files, "f").get(relativePath);
79
+ const vfile = this.#files.get(relativePath);
93
80
  (0, utils_1.assert)(vfile !== undefined, new TypeError(`File "${path}" not found in package.`));
94
81
  return vfile.clone();
95
82
  }
@@ -106,23 +93,23 @@ class BaseNpmLocation {
106
93
  get versionRange() {
107
94
  return this.meta.requestedRange;
108
95
  }
96
+ async #lazyInit() {
97
+ (0, utils_1.assert)(this.#files === undefined);
98
+ const resolvedVersion = await this.meta.resolveVersion(this.meta.requestedRange);
99
+ const { tarballURL, targetVersion } = await resolveNpmVersion(this.meta.packageName, resolvedVersion, this.meta.registry, this.meta.fetch);
100
+ if (!(0, snaps_utils_1.isValidUrl)(tarballURL) || !tarballURL.toString().endsWith('.tgz')) {
101
+ throw new Error(`Failed to find valid tarball URL in NPM metadata for package "${this.meta.packageName}".`);
102
+ }
103
+ // Override the tarball hostname/protocol with registryUrl hostname/protocol
104
+ const newTarballUrl = new URL(tarballURL);
105
+ newTarballUrl.hostname = this.meta.registry.hostname;
106
+ newTarballUrl.protocol = this.meta.registry.protocol;
107
+ const files = await this.fetchNpmTarball(newTarballUrl);
108
+ this.#files = files;
109
+ this.meta.version = targetVersion;
110
+ }
109
111
  }
110
112
  exports.BaseNpmLocation = BaseNpmLocation;
111
- _BaseNpmLocation_validatedManifest = new WeakMap(), _BaseNpmLocation_files = new WeakMap(), _BaseNpmLocation_instances = new WeakSet(), _BaseNpmLocation_lazyInit = async function _BaseNpmLocation_lazyInit() {
112
- (0, utils_1.assert)(__classPrivateFieldGet(this, _BaseNpmLocation_files, "f") === undefined);
113
- const resolvedVersion = await this.meta.resolveVersion(this.meta.requestedRange);
114
- const { tarballURL, targetVersion } = await resolveNpmVersion(this.meta.packageName, resolvedVersion, this.meta.registry, this.meta.fetch);
115
- if (!(0, snaps_utils_1.isValidUrl)(tarballURL) || !tarballURL.toString().endsWith('.tgz')) {
116
- throw new Error(`Failed to find valid tarball URL in NPM metadata for package "${this.meta.packageName}".`);
117
- }
118
- // Override the tarball hostname/protocol with registryUrl hostname/protocol
119
- const newTarballUrl = new URL(tarballURL);
120
- newTarballUrl.hostname = this.meta.registry.hostname;
121
- newTarballUrl.protocol = this.meta.registry.protocol;
122
- const files = await this.fetchNpmTarball(newTarballUrl);
123
- __classPrivateFieldSet(this, _BaseNpmLocation_files, files, "f");
124
- this.meta.version = targetVersion;
125
- };
126
113
  // Safety limit for tarballs, 250 MB in bytes
127
114
  exports.TARBALL_SIZE_SAFETY_LIMIT = 262144000;
128
115
  // Main NPM implementation, contains a browser tarball fetching implementation.
@@ -153,16 +140,9 @@ class NpmLocation extends BaseNpmLocation {
153
140
  // The "gz" in "tgz" stands for "gzip". The tarball needs to be decompressed
154
141
  // before we can actually grab any files from it.
155
142
  // To prevent recursion-based zip bombs, we should not allow recursion here.
156
- // If native decompression stream is available we use that, otherwise fallback to zlib.
157
- if ('pipeThrough' in body && 'DecompressionStream' in globalThis) {
158
- const decompressionStream = new DecompressionStream('gzip');
159
- const decompressedStream = body.pipeThrough(decompressionStream);
160
- (0, readable_stream_1.pipeline)(getNodeStream(decompressedStream), tarballStream, (error) => {
161
- error ? reject(error) : resolve(files);
162
- });
163
- return;
164
- }
165
- (0, readable_stream_1.pipeline)(getNodeStream(body), (0, browserify_zlib_1.createGunzip)(), tarballStream, (error) => {
143
+ const decompressionStream = new DecompressionStream('gzip');
144
+ const decompressedStream = body.pipeThrough(decompressionStream);
145
+ (0, readable_stream_1.pipeline)(getNodeStream(decompressedStream), tarballStream, (error) => {
166
146
  error ? reject(error) : resolve(files);
167
147
  });
168
148
  });