@metamask-previews/shield-controller 6.0.1-preview-3866c0ff1 → 6.0.1-preview-e3275932a

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 (97) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/ShieldController-method-action-types.cjs +7 -0
  3. package/dist/ShieldController-method-action-types.cjs.map +1 -0
  4. package/dist/{ShieldController-method-action-types.d.ts → ShieldController-method-action-types.d.cts} +2 -2
  5. package/dist/ShieldController-method-action-types.d.cts.map +1 -0
  6. package/dist/ShieldController-method-action-types.d.mts +51 -0
  7. package/dist/ShieldController-method-action-types.d.mts.map +1 -0
  8. package/dist/{ShieldController-method-action-types.js → ShieldController-method-action-types.mjs} +1 -1
  9. package/dist/ShieldController-method-action-types.mjs.map +1 -0
  10. package/dist/ShieldController.cjs +294 -0
  11. package/dist/ShieldController.cjs.map +1 -0
  12. package/dist/{ShieldController.d.ts → ShieldController.d.cts} +10 -10
  13. package/dist/ShieldController.d.cts.map +1 -0
  14. package/dist/ShieldController.d.mts +106 -0
  15. package/dist/ShieldController.d.mts.map +1 -0
  16. package/dist/ShieldController.mjs +290 -0
  17. package/dist/ShieldController.mjs.map +1 -0
  18. package/dist/constants.cjs +51 -0
  19. package/dist/constants.cjs.map +1 -0
  20. package/dist/{constants.d.ts → constants.d.cts} +1 -1
  21. package/dist/constants.d.cts.map +1 -0
  22. package/dist/constants.d.mts +35 -0
  23. package/dist/constants.d.mts.map +1 -0
  24. package/dist/{constants.js → constants.mjs} +1 -1
  25. package/dist/constants.mjs.map +1 -0
  26. package/dist/index.cjs +16 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/{index.d.ts → index.d.cts} +9 -9
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +9 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/index.mjs +4 -0
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/logger.cjs +8 -0
  35. package/dist/logger.cjs.map +1 -0
  36. package/dist/logger.d.cts +5 -0
  37. package/dist/logger.d.cts.map +1 -0
  38. package/dist/logger.d.mts +5 -0
  39. package/dist/logger.d.mts.map +1 -0
  40. package/dist/logger.mjs +5 -0
  41. package/dist/logger.mjs.map +1 -0
  42. package/dist/polling-with-policy.cjs +77 -0
  43. package/dist/polling-with-policy.cjs.map +1 -0
  44. package/dist/{polling-with-policy.d.ts → polling-with-policy.d.cts} +2 -2
  45. package/dist/polling-with-policy.d.cts.map +1 -0
  46. package/dist/polling-with-policy.d.mts +9 -0
  47. package/dist/polling-with-policy.d.mts.map +1 -0
  48. package/dist/polling-with-policy.mjs +73 -0
  49. package/dist/polling-with-policy.mjs.map +1 -0
  50. package/dist/shield-api-service-method-action-types.cjs +7 -0
  51. package/dist/shield-api-service-method-action-types.cjs.map +1 -0
  52. package/dist/{shield-api-service-method-action-types.d.ts → shield-api-service-method-action-types.d.cts} +2 -2
  53. package/dist/shield-api-service-method-action-types.d.cts.map +1 -0
  54. package/dist/shield-api-service-method-action-types.d.mts +48 -0
  55. package/dist/shield-api-service-method-action-types.d.mts.map +1 -0
  56. package/dist/{shield-api-service-method-action-types.js → shield-api-service-method-action-types.mjs} +1 -1
  57. package/dist/shield-api-service-method-action-types.mjs.map +1 -0
  58. package/dist/shield-api-service.cjs +371 -0
  59. package/dist/shield-api-service.cjs.map +1 -0
  60. package/dist/{shield-api-service.d.ts → shield-api-service.d.cts} +14 -14
  61. package/dist/shield-api-service.d.cts.map +1 -0
  62. package/dist/shield-api-service.d.mts +164 -0
  63. package/dist/shield-api-service.d.mts.map +1 -0
  64. package/dist/{shield-api-service.js → shield-api-service.mjs} +105 -94
  65. package/dist/shield-api-service.mjs.map +1 -0
  66. package/dist/types.cjs +5 -0
  67. package/dist/types.cjs.map +1 -0
  68. package/dist/{types.d.ts → types.d.cts} +4 -4
  69. package/dist/types.d.cts.map +1 -0
  70. package/dist/types.d.mts +34 -0
  71. package/dist/types.d.mts.map +1 -0
  72. package/dist/{types.js → types.mjs} +1 -1
  73. package/dist/types.mjs.map +1 -0
  74. package/package.json +17 -13
  75. package/dist/ShieldController-method-action-types.d.ts.map +0 -1
  76. package/dist/ShieldController-method-action-types.js.map +0 -1
  77. package/dist/ShieldController.d.ts.map +0 -1
  78. package/dist/ShieldController.js +0 -290
  79. package/dist/ShieldController.js.map +0 -1
  80. package/dist/constants.d.ts.map +0 -1
  81. package/dist/constants.js.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js +0 -4
  84. package/dist/index.js.map +0 -1
  85. package/dist/logger.d.ts +0 -4
  86. package/dist/logger.d.ts.map +0 -1
  87. package/dist/logger.js +0 -5
  88. package/dist/logger.js.map +0 -1
  89. package/dist/polling-with-policy.d.ts.map +0 -1
  90. package/dist/polling-with-policy.js +0 -62
  91. package/dist/polling-with-policy.js.map +0 -1
  92. package/dist/shield-api-service-method-action-types.d.ts.map +0 -1
  93. package/dist/shield-api-service-method-action-types.js.map +0 -1
  94. package/dist/shield-api-service.d.ts.map +0 -1
  95. package/dist/shield-api-service.js.map +0 -1
  96. package/dist/types.d.ts.map +0 -1
  97. package/dist/types.js.map +0 -1
@@ -0,0 +1,77 @@
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
+ var _PollingWithCockatielPolicy_instances, _PollingWithCockatielPolicy_policy, _PollingWithCockatielPolicy_requestEntry, _PollingWithCockatielPolicy_addNewRequestEntry, _PollingWithCockatielPolicy_cleanup, _PollingWithCockatielPolicy_shouldRetry;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PollingWithCockatielPolicy = void 0;
16
+ const controller_utils_1 = require("@metamask/controller-utils");
17
+ const cockatiel_1 = require("cockatiel");
18
+ class PollingWithCockatielPolicy {
19
+ constructor(policyOptions = {}) {
20
+ _PollingWithCockatielPolicy_instances.add(this);
21
+ _PollingWithCockatielPolicy_policy.set(this, void 0);
22
+ _PollingWithCockatielPolicy_requestEntry.set(this, new Map());
23
+ const shouldRetryFunc = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_shouldRetry).bind(this);
24
+ const retryFilterPolicy = (0, cockatiel_1.handleWhen)(shouldRetryFunc);
25
+ __classPrivateFieldSet(this, _PollingWithCockatielPolicy_policy, (0, controller_utils_1.createServicePolicy)({
26
+ ...policyOptions,
27
+ retryFilterPolicy,
28
+ }), "f");
29
+ }
30
+ async start(requestId, requestFn) {
31
+ const abortController = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_addNewRequestEntry).call(this, requestId);
32
+ try {
33
+ const result = await __classPrivateFieldGet(this, _PollingWithCockatielPolicy_policy, "f").execute(async ({ signal }) => {
34
+ return requestFn(signal);
35
+ }, abortController.signal);
36
+ return result;
37
+ }
38
+ catch (error) {
39
+ if (abortController.signal.aborted) {
40
+ throw new Error('Request cancelled');
41
+ }
42
+ throw error;
43
+ }
44
+ finally {
45
+ // Only cleanup if this abort controller is still active. If a new request with the same
46
+ // requestId started while this one was running, it would have replaced with a new abort controller.
47
+ // We must not delete the new request's controller when this older request finishes.
48
+ if (abortController === __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").get(requestId)) {
49
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_cleanup).call(this, requestId);
50
+ }
51
+ }
52
+ }
53
+ abortPendingRequest(requestId) {
54
+ const abortController = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").get(requestId);
55
+ abortController?.abort();
56
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_cleanup).call(this, requestId);
57
+ }
58
+ }
59
+ exports.PollingWithCockatielPolicy = PollingWithCockatielPolicy;
60
+ _PollingWithCockatielPolicy_policy = new WeakMap(), _PollingWithCockatielPolicy_requestEntry = new WeakMap(), _PollingWithCockatielPolicy_instances = new WeakSet(), _PollingWithCockatielPolicy_addNewRequestEntry = function _PollingWithCockatielPolicy_addNewRequestEntry(requestId) {
61
+ // abort the previous request if it exists
62
+ this.abortPendingRequest(requestId);
63
+ // create a new abort controller for the new request
64
+ const abortController = new AbortController();
65
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").set(requestId, abortController);
66
+ return abortController;
67
+ }, _PollingWithCockatielPolicy_cleanup = function _PollingWithCockatielPolicy_cleanup(requestId) {
68
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").delete(requestId);
69
+ }, _PollingWithCockatielPolicy_shouldRetry = function _PollingWithCockatielPolicy_shouldRetry(error) {
70
+ if (error instanceof controller_utils_1.HttpError) {
71
+ // Note: we don't retry on 5xx errors, only on 4xx errors.
72
+ // but we won't retry on 400 coz it means that the request body is invalid.
73
+ return error.httpStatus > 400 && error.httpStatus < 500;
74
+ }
75
+ return false;
76
+ };
77
+ //# sourceMappingURL=polling-with-policy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-with-policy.cjs","sourceRoot":"","sources":["../src/polling-with-policy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAA4E;AAK5E,yCAAuC;AAMvC,MAAa,0BAA0B;IAKrC,YAAY,gBAA4C,EAAE;;QAJjD,qDAAuB;QAEvB,mDAAgB,IAAI,GAAG,EAA2B,EAAC;QAG1D,MAAM,eAAe,GAAG,uBAAA,IAAI,sFAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,iBAAiB,GAAG,IAAA,sBAAU,EAAC,eAAe,CAAC,CAAC;QACtD,uBAAA,IAAI,sCAAW,IAAA,sCAAmB,EAAC;YACjC,GAAG,aAAa;YAChB,iBAAiB;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CACT,SAAiB,EACjB,SAAgC;QAEhC,MAAM,eAAe,GAAG,uBAAA,IAAI,6FAAoB,MAAxB,IAAI,EAAqB,SAAS,CAAC,CAAC;QAE5D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,uBAAA,IAAI,0CAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC7D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;YAC3B,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACvC,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,wFAAwF;YACxF,oGAAoG;YACpG,oFAAoF;YACpF,IAAI,eAAe,KAAK,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1D,uBAAA,IAAI,kFAAS,MAAb,IAAI,EAAU,SAAS,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,SAAiB;QACnC,MAAM,eAAe,GAAG,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1D,eAAe,EAAE,KAAK,EAAE,CAAC;QACzB,uBAAA,IAAI,kFAAS,MAAb,IAAI,EAAU,SAAS,CAAC,CAAC;IAC3B,CAAC;CAwBF;AApED,gEAoEC;8QAtBqB,SAAiB;IACnC,0CAA0C;IAC1C,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAEpC,oDAAoD;IACpD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACnD,OAAO,eAAe,CAAC;AACzB,CAAC,qFAEQ,SAAiB;IACxB,uBAAA,IAAI,gDAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC,6FAEY,KAAY;IACvB,IAAI,KAAK,YAAY,4BAAS,EAAE,CAAC;QAC/B,0DAA0D;QAC1D,2EAA2E;QAC3E,OAAO,KAAK,CAAC,UAAU,GAAG,GAAG,IAAI,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { handleWhen } from 'cockatiel';\n\nexport type RequestFn<ReturnType> = (\n signal: AbortSignal,\n) => Promise<ReturnType>;\n\nexport class PollingWithCockatielPolicy {\n readonly #policy: ServicePolicy;\n\n readonly #requestEntry = new Map<string, AbortController>();\n\n constructor(policyOptions: CreateServicePolicyOptions = {}) {\n const shouldRetryFunc = this.#shouldRetry.bind(this);\n const retryFilterPolicy = handleWhen(shouldRetryFunc);\n this.#policy = createServicePolicy({\n ...policyOptions,\n retryFilterPolicy,\n });\n }\n\n async start<ReturnType>(\n requestId: string,\n requestFn: RequestFn<ReturnType>,\n ): Promise<ReturnType> {\n const abortController = this.#addNewRequestEntry(requestId);\n\n try {\n const result = await this.#policy.execute(async ({ signal }) => {\n return requestFn(signal);\n }, abortController.signal);\n return result;\n } catch (error) {\n if (abortController.signal.aborted) {\n throw new Error('Request cancelled');\n }\n throw error;\n } finally {\n // Only cleanup if this abort controller is still active. If a new request with the same\n // requestId started while this one was running, it would have replaced with a new abort controller.\n // We must not delete the new request's controller when this older request finishes.\n if (abortController === this.#requestEntry.get(requestId)) {\n this.#cleanup(requestId);\n }\n }\n }\n\n abortPendingRequest(requestId: string): void {\n const abortController = this.#requestEntry.get(requestId);\n abortController?.abort();\n this.#cleanup(requestId);\n }\n\n #addNewRequestEntry(requestId: string): AbortController {\n // abort the previous request if it exists\n this.abortPendingRequest(requestId);\n\n // create a new abort controller for the new request\n const abortController = new AbortController();\n this.#requestEntry.set(requestId, abortController);\n return abortController;\n }\n\n #cleanup(requestId: string): void {\n this.#requestEntry.delete(requestId);\n }\n\n #shouldRetry(error: Error): boolean {\n if (error instanceof HttpError) {\n // Note: we don't retry on 5xx errors, only on 4xx errors.\n // but we won't retry on 400 coz it means that the request body is invalid.\n return error.httpStatus > 400 && error.httpStatus < 500;\n }\n return false;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CreateServicePolicyOptions } from '@metamask/controller-utils';
1
+ import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
2
2
  export type RequestFn<ReturnType> = (signal: AbortSignal) => Promise<ReturnType>;
3
3
  export declare class PollingWithCockatielPolicy {
4
4
  #private;
@@ -6,4 +6,4 @@ export declare class PollingWithCockatielPolicy {
6
6
  start<ReturnType>(requestId: string, requestFn: RequestFn<ReturnType>): Promise<ReturnType>;
7
7
  abortPendingRequest(requestId: string): void;
8
8
  }
9
- //# sourceMappingURL=polling-with-policy.d.ts.map
9
+ //# sourceMappingURL=polling-with-policy.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-with-policy.d.cts","sourceRoot":"","sources":["../src/polling-with-policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAE3B,mCAAmC;AAGpC,MAAM,MAAM,SAAS,CAAC,UAAU,IAAI,CAClC,MAAM,EAAE,WAAW,KAChB,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,qBAAa,0BAA0B;;gBAKzB,aAAa,GAAE,0BAA+B;IASpD,KAAK,CAAC,UAAU,EACpB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,GAC/B,OAAO,CAAC,UAAU,CAAC;IAuBtB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CA4B7C"}
@@ -0,0 +1,9 @@
1
+ import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
2
+ export type RequestFn<ReturnType> = (signal: AbortSignal) => Promise<ReturnType>;
3
+ export declare class PollingWithCockatielPolicy {
4
+ #private;
5
+ constructor(policyOptions?: CreateServicePolicyOptions);
6
+ start<ReturnType>(requestId: string, requestFn: RequestFn<ReturnType>): Promise<ReturnType>;
7
+ abortPendingRequest(requestId: string): void;
8
+ }
9
+ //# sourceMappingURL=polling-with-policy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-with-policy.d.mts","sourceRoot":"","sources":["../src/polling-with-policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAE3B,mCAAmC;AAGpC,MAAM,MAAM,SAAS,CAAC,UAAU,IAAI,CAClC,MAAM,EAAE,WAAW,KAChB,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,qBAAa,0BAA0B;;gBAKzB,aAAa,GAAE,0BAA+B;IASpD,KAAK,CAAC,UAAU,EACpB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,GAC/B,OAAO,CAAC,UAAU,CAAC;IAuBtB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CA4B7C"}
@@ -0,0 +1,73 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ 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");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _PollingWithCockatielPolicy_instances, _PollingWithCockatielPolicy_policy, _PollingWithCockatielPolicy_requestEntry, _PollingWithCockatielPolicy_addNewRequestEntry, _PollingWithCockatielPolicy_cleanup, _PollingWithCockatielPolicy_shouldRetry;
13
+ import { createServicePolicy, HttpError } from "@metamask/controller-utils";
14
+ import { handleWhen } from "cockatiel";
15
+ export class PollingWithCockatielPolicy {
16
+ constructor(policyOptions = {}) {
17
+ _PollingWithCockatielPolicy_instances.add(this);
18
+ _PollingWithCockatielPolicy_policy.set(this, void 0);
19
+ _PollingWithCockatielPolicy_requestEntry.set(this, new Map());
20
+ const shouldRetryFunc = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_shouldRetry).bind(this);
21
+ const retryFilterPolicy = handleWhen(shouldRetryFunc);
22
+ __classPrivateFieldSet(this, _PollingWithCockatielPolicy_policy, createServicePolicy({
23
+ ...policyOptions,
24
+ retryFilterPolicy,
25
+ }), "f");
26
+ }
27
+ async start(requestId, requestFn) {
28
+ const abortController = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_addNewRequestEntry).call(this, requestId);
29
+ try {
30
+ const result = await __classPrivateFieldGet(this, _PollingWithCockatielPolicy_policy, "f").execute(async ({ signal }) => {
31
+ return requestFn(signal);
32
+ }, abortController.signal);
33
+ return result;
34
+ }
35
+ catch (error) {
36
+ if (abortController.signal.aborted) {
37
+ throw new Error('Request cancelled');
38
+ }
39
+ throw error;
40
+ }
41
+ finally {
42
+ // Only cleanup if this abort controller is still active. If a new request with the same
43
+ // requestId started while this one was running, it would have replaced with a new abort controller.
44
+ // We must not delete the new request's controller when this older request finishes.
45
+ if (abortController === __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").get(requestId)) {
46
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_cleanup).call(this, requestId);
47
+ }
48
+ }
49
+ }
50
+ abortPendingRequest(requestId) {
51
+ const abortController = __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").get(requestId);
52
+ abortController?.abort();
53
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_instances, "m", _PollingWithCockatielPolicy_cleanup).call(this, requestId);
54
+ }
55
+ }
56
+ _PollingWithCockatielPolicy_policy = new WeakMap(), _PollingWithCockatielPolicy_requestEntry = new WeakMap(), _PollingWithCockatielPolicy_instances = new WeakSet(), _PollingWithCockatielPolicy_addNewRequestEntry = function _PollingWithCockatielPolicy_addNewRequestEntry(requestId) {
57
+ // abort the previous request if it exists
58
+ this.abortPendingRequest(requestId);
59
+ // create a new abort controller for the new request
60
+ const abortController = new AbortController();
61
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").set(requestId, abortController);
62
+ return abortController;
63
+ }, _PollingWithCockatielPolicy_cleanup = function _PollingWithCockatielPolicy_cleanup(requestId) {
64
+ __classPrivateFieldGet(this, _PollingWithCockatielPolicy_requestEntry, "f").delete(requestId);
65
+ }, _PollingWithCockatielPolicy_shouldRetry = function _PollingWithCockatielPolicy_shouldRetry(error) {
66
+ if (error instanceof HttpError) {
67
+ // Note: we don't retry on 5xx errors, only on 4xx errors.
68
+ // but we won't retry on 400 coz it means that the request body is invalid.
69
+ return error.httpStatus > 400 && error.httpStatus < 500;
70
+ }
71
+ return false;
72
+ };
73
+ //# sourceMappingURL=polling-with-policy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-with-policy.mjs","sourceRoot":"","sources":["../src/polling-with-policy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;AAK5E,OAAO,EAAE,UAAU,EAAE,kBAAkB;AAMvC,MAAM,OAAO,0BAA0B;IAKrC,YAAY,gBAA4C,EAAE;;QAJjD,qDAAuB;QAEvB,mDAAgB,IAAI,GAAG,EAA2B,EAAC;QAG1D,MAAM,eAAe,GAAG,uBAAA,IAAI,sFAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,iBAAiB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;QACtD,uBAAA,IAAI,sCAAW,mBAAmB,CAAC;YACjC,GAAG,aAAa;YAChB,iBAAiB;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CACT,SAAiB,EACjB,SAAgC;QAEhC,MAAM,eAAe,GAAG,uBAAA,IAAI,6FAAoB,MAAxB,IAAI,EAAqB,SAAS,CAAC,CAAC;QAE5D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,uBAAA,IAAI,0CAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC7D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;YAC3B,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACvC,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,wFAAwF;YACxF,oGAAoG;YACpG,oFAAoF;YACpF,IAAI,eAAe,KAAK,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1D,uBAAA,IAAI,kFAAS,MAAb,IAAI,EAAU,SAAS,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,SAAiB;QACnC,MAAM,eAAe,GAAG,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1D,eAAe,EAAE,KAAK,EAAE,CAAC;QACzB,uBAAA,IAAI,kFAAS,MAAb,IAAI,EAAU,SAAS,CAAC,CAAC;IAC3B,CAAC;CAwBF;8QAtBqB,SAAiB;IACnC,0CAA0C;IAC1C,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAEpC,oDAAoD;IACpD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,uBAAA,IAAI,gDAAc,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACnD,OAAO,eAAe,CAAC;AACzB,CAAC,qFAEQ,SAAiB;IACxB,uBAAA,IAAI,gDAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC,6FAEY,KAAY;IACvB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,0DAA0D;QAC1D,2EAA2E;QAC3E,OAAO,KAAK,CAAC,UAAU,GAAG,GAAG,IAAI,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { handleWhen } from 'cockatiel';\n\nexport type RequestFn<ReturnType> = (\n signal: AbortSignal,\n) => Promise<ReturnType>;\n\nexport class PollingWithCockatielPolicy {\n readonly #policy: ServicePolicy;\n\n readonly #requestEntry = new Map<string, AbortController>();\n\n constructor(policyOptions: CreateServicePolicyOptions = {}) {\n const shouldRetryFunc = this.#shouldRetry.bind(this);\n const retryFilterPolicy = handleWhen(shouldRetryFunc);\n this.#policy = createServicePolicy({\n ...policyOptions,\n retryFilterPolicy,\n });\n }\n\n async start<ReturnType>(\n requestId: string,\n requestFn: RequestFn<ReturnType>,\n ): Promise<ReturnType> {\n const abortController = this.#addNewRequestEntry(requestId);\n\n try {\n const result = await this.#policy.execute(async ({ signal }) => {\n return requestFn(signal);\n }, abortController.signal);\n return result;\n } catch (error) {\n if (abortController.signal.aborted) {\n throw new Error('Request cancelled');\n }\n throw error;\n } finally {\n // Only cleanup if this abort controller is still active. If a new request with the same\n // requestId started while this one was running, it would have replaced with a new abort controller.\n // We must not delete the new request's controller when this older request finishes.\n if (abortController === this.#requestEntry.get(requestId)) {\n this.#cleanup(requestId);\n }\n }\n }\n\n abortPendingRequest(requestId: string): void {\n const abortController = this.#requestEntry.get(requestId);\n abortController?.abort();\n this.#cleanup(requestId);\n }\n\n #addNewRequestEntry(requestId: string): AbortController {\n // abort the previous request if it exists\n this.abortPendingRequest(requestId);\n\n // create a new abort controller for the new request\n const abortController = new AbortController();\n this.#requestEntry.set(requestId, abortController);\n return abortController;\n }\n\n #cleanup(requestId: string): void {\n this.#requestEntry.delete(requestId);\n }\n\n #shouldRetry(error: Error): boolean {\n if (error instanceof HttpError) {\n // Note: we don't retry on 5xx errors, only on 4xx errors.\n // but we won't retry on 400 coz it means that the request body is invalid.\n return error.httpStatus > 400 && error.httpStatus < 500;\n }\n return false;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=shield-api-service-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield-api-service-method-action-types.cjs","sourceRoot":"","sources":["../src/shield-api-service-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ShieldApiService } from './shield-api-service.js';\n\n/**\n * Checks the coverage of a transaction.\n *\n * @param req - The coverage check request.\n * @returns The coverage result.\n */\nexport type ShieldApiServiceCheckCoverageAction = {\n type: `ShieldApiService:checkCoverage`;\n handler: ShieldApiService['checkCoverage'];\n};\n\n/**\n * Checks the coverage of a signature request.\n *\n * @param req - The signature coverage check request.\n * @returns The coverage result.\n */\nexport type ShieldApiServiceCheckSignatureCoverageAction = {\n type: `ShieldApiService:checkSignatureCoverage`;\n handler: ShieldApiService['checkSignatureCoverage'];\n};\n\n/**\n * Logs a signed signature request.\n *\n * @param req - The log signature request.\n */\nexport type ShieldApiServiceLogSignatureAction = {\n type: `ShieldApiService:logSignature`;\n handler: ShieldApiService['logSignature'];\n};\n\n/**\n * Logs a submitted transaction.\n *\n * @param req - The log transaction request.\n */\nexport type ShieldApiServiceLogTransactionAction = {\n type: `ShieldApiService:logTransaction`;\n handler: ShieldApiService['logTransaction'];\n};\n\n/**\n * Union of all ShieldApiService action types.\n */\nexport type ShieldApiServiceMethodActions =\n | ShieldApiServiceCheckCoverageAction\n | ShieldApiServiceCheckSignatureCoverageAction\n | ShieldApiServiceLogSignatureAction\n | ShieldApiServiceLogTransactionAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { ShieldApiService } from './shield-api-service.js';
5
+ import type { ShieldApiService } from "./shield-api-service.cjs";
6
6
  /**
7
7
  * Checks the coverage of a transaction.
8
8
  *
@@ -45,4 +45,4 @@ export type ShieldApiServiceLogTransactionAction = {
45
45
  * Union of all ShieldApiService action types.
46
46
  */
47
47
  export type ShieldApiServiceMethodActions = ShieldApiServiceCheckCoverageAction | ShieldApiServiceCheckSignatureCoverageAction | ShieldApiServiceLogSignatureAction | ShieldApiServiceLogTransactionAction;
48
- //# sourceMappingURL=shield-api-service-method-action-types.d.ts.map
48
+ //# sourceMappingURL=shield-api-service-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield-api-service-method-action-types.d.cts","sourceRoot":"","sources":["../src/shield-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,iCAAgC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,mCAAmC,GACnC,4CAA4C,GAC5C,kCAAkC,GAClC,oCAAoC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ShieldApiService } from "./shield-api-service.mjs";
6
+ /**
7
+ * Checks the coverage of a transaction.
8
+ *
9
+ * @param req - The coverage check request.
10
+ * @returns The coverage result.
11
+ */
12
+ export type ShieldApiServiceCheckCoverageAction = {
13
+ type: `ShieldApiService:checkCoverage`;
14
+ handler: ShieldApiService['checkCoverage'];
15
+ };
16
+ /**
17
+ * Checks the coverage of a signature request.
18
+ *
19
+ * @param req - The signature coverage check request.
20
+ * @returns The coverage result.
21
+ */
22
+ export type ShieldApiServiceCheckSignatureCoverageAction = {
23
+ type: `ShieldApiService:checkSignatureCoverage`;
24
+ handler: ShieldApiService['checkSignatureCoverage'];
25
+ };
26
+ /**
27
+ * Logs a signed signature request.
28
+ *
29
+ * @param req - The log signature request.
30
+ */
31
+ export type ShieldApiServiceLogSignatureAction = {
32
+ type: `ShieldApiService:logSignature`;
33
+ handler: ShieldApiService['logSignature'];
34
+ };
35
+ /**
36
+ * Logs a submitted transaction.
37
+ *
38
+ * @param req - The log transaction request.
39
+ */
40
+ export type ShieldApiServiceLogTransactionAction = {
41
+ type: `ShieldApiService:logTransaction`;
42
+ handler: ShieldApiService['logTransaction'];
43
+ };
44
+ /**
45
+ * Union of all ShieldApiService action types.
46
+ */
47
+ export type ShieldApiServiceMethodActions = ShieldApiServiceCheckCoverageAction | ShieldApiServiceCheckSignatureCoverageAction | ShieldApiServiceLogSignatureAction | ShieldApiServiceLogTransactionAction;
48
+ //# sourceMappingURL=shield-api-service-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield-api-service-method-action-types.d.mts","sourceRoot":"","sources":["../src/shield-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,iCAAgC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,mCAAmC,GACnC,4CAA4C,GAC5C,kCAAkC,GAClC,oCAAoC,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=shield-api-service-method-action-types.js.map
6
+ //# sourceMappingURL=shield-api-service-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield-api-service-method-action-types.mjs","sourceRoot":"","sources":["../src/shield-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ShieldApiService } from './shield-api-service.js';\n\n/**\n * Checks the coverage of a transaction.\n *\n * @param req - The coverage check request.\n * @returns The coverage result.\n */\nexport type ShieldApiServiceCheckCoverageAction = {\n type: `ShieldApiService:checkCoverage`;\n handler: ShieldApiService['checkCoverage'];\n};\n\n/**\n * Checks the coverage of a signature request.\n *\n * @param req - The signature coverage check request.\n * @returns The coverage result.\n */\nexport type ShieldApiServiceCheckSignatureCoverageAction = {\n type: `ShieldApiService:checkSignatureCoverage`;\n handler: ShieldApiService['checkSignatureCoverage'];\n};\n\n/**\n * Logs a signed signature request.\n *\n * @param req - The log signature request.\n */\nexport type ShieldApiServiceLogSignatureAction = {\n type: `ShieldApiService:logSignature`;\n handler: ShieldApiService['logSignature'];\n};\n\n/**\n * Logs a submitted transaction.\n *\n * @param req - The log transaction request.\n */\nexport type ShieldApiServiceLogTransactionAction = {\n type: `ShieldApiService:logTransaction`;\n handler: ShieldApiService['logTransaction'];\n};\n\n/**\n * Union of all ShieldApiService action types.\n */\nexport type ShieldApiServiceMethodActions =\n | ShieldApiServiceCheckCoverageAction\n | ShieldApiServiceCheckSignatureCoverageAction\n | ShieldApiServiceLogSignatureAction\n | ShieldApiServiceLogTransactionAction;\n"]}