@metronome/sdk 0.1.0-beta.9 → 0.1.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.
- package/CHANGELOG.md +179 -0
- package/README.md +30 -46
- package/_shims/index.d.ts +2 -0
- package/_shims/index.js +5 -1
- package/_shims/index.mjs +5 -1
- package/core.d.ts +19 -5
- package/core.d.ts.map +1 -1
- package/core.js +23 -14
- package/core.js.map +1 -1
- package/core.mjs +24 -15
- package/core.mjs.map +1 -1
- package/index.d.mts +3 -2
- package/index.d.ts +3 -2
- package/index.d.ts.map +1 -1
- package/index.js +6 -3
- package/index.js.map +1 -1
- package/index.mjs +6 -3
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/pagination.d.ts +1 -0
- package/pagination.d.ts.map +1 -1
- package/pagination.js +3 -0
- package/pagination.js.map +1 -1
- package/pagination.mjs +3 -0
- package/pagination.mjs.map +1 -1
- package/resource.d.ts +1 -1
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/shared.d.ts +473 -37
- package/resources/shared.d.ts.map +1 -1
- package/resources/v1/alerts.d.ts +26 -2
- package/resources/v1/alerts.d.ts.map +1 -1
- package/resources/v1/alerts.js +19 -0
- package/resources/v1/alerts.js.map +1 -1
- package/resources/v1/alerts.mjs +19 -0
- package/resources/v1/alerts.mjs.map +1 -1
- package/resources/v1/audit-logs.d.ts +8 -0
- package/resources/v1/audit-logs.d.ts.map +1 -1
- package/resources/v1/audit-logs.js.map +1 -1
- package/resources/v1/audit-logs.mjs.map +1 -1
- package/resources/v1/billable-metrics.d.ts +58 -3
- package/resources/v1/billable-metrics.d.ts.map +1 -1
- package/resources/v1/billable-metrics.js +41 -0
- package/resources/v1/billable-metrics.js.map +1 -1
- package/resources/v1/billable-metrics.mjs +41 -0
- package/resources/v1/billable-metrics.mjs.map +1 -1
- package/resources/v1/contracts/contracts.d.ts +1478 -102
- package/resources/v1/contracts/contracts.d.ts.map +1 -1
- package/resources/v1/contracts/contracts.js +180 -3
- package/resources/v1/contracts/contracts.js.map +1 -1
- package/resources/v1/contracts/contracts.mjs +180 -3
- package/resources/v1/contracts/contracts.mjs.map +1 -1
- package/resources/v1/contracts/index.d.ts +2 -2
- package/resources/v1/contracts/index.d.ts.map +1 -1
- package/resources/v1/contracts/index.js.map +1 -1
- package/resources/v1/contracts/index.mjs.map +1 -1
- package/resources/v1/contracts/named-schedules.d.ts +21 -0
- package/resources/v1/contracts/named-schedules.d.ts.map +1 -1
- package/resources/v1/contracts/named-schedules.js +21 -0
- package/resources/v1/contracts/named-schedules.js.map +1 -1
- package/resources/v1/contracts/named-schedules.mjs +21 -0
- package/resources/v1/contracts/named-schedules.mjs.map +1 -1
- package/resources/v1/contracts/products.d.ts +51 -3
- package/resources/v1/contracts/products.d.ts.map +1 -1
- package/resources/v1/contracts/products.js +33 -0
- package/resources/v1/contracts/products.js.map +1 -1
- package/resources/v1/contracts/products.mjs +33 -0
- package/resources/v1/contracts/products.mjs.map +1 -1
- package/resources/v1/contracts/rate-cards/index.d.ts +1 -1
- package/resources/v1/contracts/rate-cards/index.d.ts.map +1 -1
- package/resources/v1/contracts/rate-cards/index.js.map +1 -1
- package/resources/v1/contracts/rate-cards/index.mjs.map +1 -1
- package/resources/v1/contracts/rate-cards/named-schedules.d.ts +25 -0
- package/resources/v1/contracts/rate-cards/named-schedules.d.ts.map +1 -1
- package/resources/v1/contracts/rate-cards/named-schedules.js +25 -0
- package/resources/v1/contracts/rate-cards/named-schedules.js.map +1 -1
- package/resources/v1/contracts/rate-cards/named-schedules.mjs +25 -0
- package/resources/v1/contracts/rate-cards/named-schedules.mjs.map +1 -1
- package/resources/v1/contracts/rate-cards/product-orders.d.ts +30 -0
- package/resources/v1/contracts/rate-cards/product-orders.d.ts.map +1 -1
- package/resources/v1/contracts/rate-cards/product-orders.js +30 -0
- package/resources/v1/contracts/rate-cards/product-orders.js.map +1 -1
- package/resources/v1/contracts/rate-cards/product-orders.mjs +30 -0
- package/resources/v1/contracts/rate-cards/product-orders.mjs.map +1 -1
- package/resources/v1/contracts/rate-cards/rate-cards.d.ts +107 -10
- package/resources/v1/contracts/rate-cards/rate-cards.d.ts.map +1 -1
- package/resources/v1/contracts/rate-cards/rate-cards.js +71 -0
- package/resources/v1/contracts/rate-cards/rate-cards.js.map +1 -1
- package/resources/v1/contracts/rate-cards/rate-cards.mjs +71 -0
- package/resources/v1/contracts/rate-cards/rate-cards.mjs.map +1 -1
- package/resources/v1/contracts/rate-cards/rates.d.ts +102 -14
- package/resources/v1/contracts/rate-cards/rates.d.ts.map +1 -1
- package/resources/v1/contracts/rate-cards/rates.js +68 -0
- package/resources/v1/contracts/rate-cards/rates.js.map +1 -1
- package/resources/v1/contracts/rate-cards/rates.mjs +68 -0
- package/resources/v1/contracts/rate-cards/rates.mjs.map +1 -1
- package/resources/v1/credit-grants.d.ts +77 -2
- package/resources/v1/credit-grants.d.ts.map +1 -1
- package/resources/v1/credit-grants.js +39 -2
- package/resources/v1/credit-grants.js.map +1 -1
- package/resources/v1/credit-grants.mjs +39 -2
- package/resources/v1/credit-grants.mjs.map +1 -1
- package/resources/v1/custom-fields.d.ts +51 -7
- package/resources/v1/custom-fields.d.ts.map +1 -1
- package/resources/v1/custom-fields.js +35 -0
- package/resources/v1/custom-fields.js.map +1 -1
- package/resources/v1/custom-fields.mjs +35 -0
- package/resources/v1/custom-fields.mjs.map +1 -1
- package/resources/v1/customers/alerts.d.ts +28 -0
- package/resources/v1/customers/alerts.d.ts.map +1 -1
- package/resources/v1/customers/alerts.js +23 -0
- package/resources/v1/customers/alerts.js.map +1 -1
- package/resources/v1/customers/alerts.mjs +23 -0
- package/resources/v1/customers/alerts.mjs.map +1 -1
- package/resources/v1/customers/billing-config.d.ts +31 -0
- package/resources/v1/customers/billing-config.d.ts.map +1 -1
- package/resources/v1/customers/billing-config.js +27 -0
- package/resources/v1/customers/billing-config.js.map +1 -1
- package/resources/v1/customers/billing-config.mjs +27 -0
- package/resources/v1/customers/billing-config.mjs.map +1 -1
- package/resources/v1/customers/commits.d.ts +94 -7
- package/resources/v1/customers/commits.d.ts.map +1 -1
- package/resources/v1/customers/commits.js +56 -1
- package/resources/v1/customers/commits.js.map +1 -1
- package/resources/v1/customers/commits.mjs +56 -1
- package/resources/v1/customers/commits.mjs.map +1 -1
- package/resources/v1/customers/credits.d.ts +73 -3
- package/resources/v1/customers/credits.d.ts.map +1 -1
- package/resources/v1/customers/credits.js +41 -1
- package/resources/v1/customers/credits.js.map +1 -1
- package/resources/v1/customers/credits.mjs +41 -1
- package/resources/v1/customers/credits.mjs.map +1 -1
- package/resources/v1/customers/customers.d.ts +186 -9
- package/resources/v1/customers/customers.d.ts.map +1 -1
- package/resources/v1/customers/customers.js +106 -1
- package/resources/v1/customers/customers.js.map +1 -1
- package/resources/v1/customers/customers.mjs +106 -1
- package/resources/v1/customers/customers.mjs.map +1 -1
- package/resources/v1/customers/index.d.ts +1 -1
- package/resources/v1/customers/index.d.ts.map +1 -1
- package/resources/v1/customers/index.js.map +1 -1
- package/resources/v1/customers/index.mjs.map +1 -1
- package/resources/v1/customers/invoices.d.ts +144 -52
- package/resources/v1/customers/invoices.d.ts.map +1 -1
- package/resources/v1/customers/invoices.js +49 -0
- package/resources/v1/customers/invoices.js.map +1 -1
- package/resources/v1/customers/invoices.mjs +49 -0
- package/resources/v1/customers/invoices.mjs.map +1 -1
- package/resources/v1/customers/named-schedules.d.ts +21 -0
- package/resources/v1/customers/named-schedules.d.ts.map +1 -1
- package/resources/v1/customers/named-schedules.js +21 -0
- package/resources/v1/customers/named-schedules.js.map +1 -1
- package/resources/v1/customers/named-schedules.mjs +21 -0
- package/resources/v1/customers/named-schedules.mjs.map +1 -1
- package/resources/v1/customers/plans.d.ts +46 -1
- package/resources/v1/customers/plans.d.ts.map +1 -1
- package/resources/v1/customers/plans.js +43 -0
- package/resources/v1/customers/plans.js.map +1 -1
- package/resources/v1/customers/plans.mjs +43 -0
- package/resources/v1/customers/plans.mjs.map +1 -1
- package/resources/v1/dashboards.d.ts +30 -2
- package/resources/v1/dashboards.d.ts.map +1 -1
- package/resources/v1/dashboards.js +26 -0
- package/resources/v1/dashboards.js.map +1 -1
- package/resources/v1/dashboards.mjs +26 -0
- package/resources/v1/dashboards.mjs.map +1 -1
- package/resources/v1/index.d.ts +3 -3
- package/resources/v1/index.d.ts.map +1 -1
- package/resources/v1/index.js.map +1 -1
- package/resources/v1/index.mjs.map +1 -1
- package/resources/v1/invoices.d.ts +14 -0
- package/resources/v1/invoices.d.ts.map +1 -1
- package/resources/v1/invoices.js +14 -0
- package/resources/v1/invoices.js.map +1 -1
- package/resources/v1/invoices.mjs +14 -0
- package/resources/v1/invoices.mjs.map +1 -1
- package/resources/v1/plans.d.ts +47 -4
- package/resources/v1/plans.d.ts.map +1 -1
- package/resources/v1/plans.js +27 -0
- package/resources/v1/plans.js.map +1 -1
- package/resources/v1/plans.mjs +27 -0
- package/resources/v1/plans.mjs.map +1 -1
- package/resources/v1/pricing-units.d.ts +8 -0
- package/resources/v1/pricing-units.d.ts.map +1 -1
- package/resources/v1/pricing-units.js.map +1 -1
- package/resources/v1/pricing-units.mjs.map +1 -1
- package/resources/v1/services.d.ts +5 -0
- package/resources/v1/services.d.ts.map +1 -1
- package/resources/v1/services.js +5 -0
- package/resources/v1/services.js.map +1 -1
- package/resources/v1/services.mjs +5 -0
- package/resources/v1/services.mjs.map +1 -1
- package/resources/v1/usage.d.ts +161 -3
- package/resources/v1/usage.d.ts.map +1 -1
- package/resources/v1/usage.js +46 -0
- package/resources/v1/usage.js.map +1 -1
- package/resources/v1/usage.mjs +46 -0
- package/resources/v1/usage.mjs.map +1 -1
- package/resources/v1/v1.d.ts +6 -6
- package/resources/v1/v1.d.ts.map +1 -1
- package/resources/v1/v1.js.map +1 -1
- package/resources/v1/v1.mjs.map +1 -1
- package/resources/v2/contracts.d.ts +2923 -207
- package/resources/v2/contracts.d.ts.map +1 -1
- package/resources/v2/contracts.js +90 -2
- package/resources/v2/contracts.js.map +1 -1
- package/resources/v2/contracts.mjs +90 -2
- package/resources/v2/contracts.mjs.map +1 -1
- package/resources/webhooks.js +5 -5
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +5 -5
- package/resources/webhooks.mjs.map +1 -1
- package/src/_shims/auto/runtime-bun.ts +1 -1
- package/src/_shims/auto/runtime-node.ts +1 -1
- package/src/_shims/auto/runtime.ts +1 -1
- package/src/_shims/auto/types-node.ts +1 -1
- package/src/_shims/bun-runtime.ts +2 -2
- package/src/_shims/index.d.ts +5 -3
- package/src/_shims/index.js +5 -1
- package/src/_shims/index.mjs +6 -2
- package/src/_shims/node-runtime.ts +3 -3
- package/src/_shims/registry.ts +1 -1
- package/src/_shims/web-runtime.ts +3 -3
- package/src/core.ts +46 -18
- package/src/error.ts +1 -1
- package/src/index.ts +22 -16
- package/src/internal/qs/formats.ts +1 -1
- package/src/internal/qs/index.ts +3 -3
- package/src/internal/qs/stringify.ts +3 -3
- package/src/internal/qs/utils.ts +2 -2
- package/src/pagination.ts +5 -1
- package/src/resource.ts +2 -2
- package/src/resources/index.ts +4 -4
- package/src/resources/shared.ts +539 -40
- package/src/resources/v1/alerts.ts +29 -5
- package/src/resources/v1/audit-logs.ts +12 -4
- package/src/resources/v1/billable-metrics.ts +57 -8
- package/src/resources/v1/contracts/contracts.ts +1643 -124
- package/src/resources/v1/contracts/index.ts +8 -4
- package/src/resources/v1/contracts/named-schedules.ts +23 -2
- package/src/resources/v1/contracts/products.ts +53 -9
- package/src/resources/v1/contracts/rate-cards/index.ts +6 -4
- package/src/resources/v1/contracts/rate-cards/named-schedules.ts +27 -2
- package/src/resources/v1/contracts/rate-cards/product-orders.ts +33 -3
- package/src/resources/v1/contracts/rate-cards/rate-cards.ts +113 -20
- package/src/resources/v1/contracts/rate-cards/rates.ts +86 -18
- package/src/resources/v1/contracts/rate-cards.ts +1 -1
- package/src/resources/v1/contracts.ts +1 -1
- package/src/resources/v1/credit-grants.ts +82 -10
- package/src/resources/v1/custom-fields.ts +57 -9
- package/src/resources/v1/customers/alerts.ts +32 -3
- package/src/resources/v1/customers/billing-config.ts +34 -2
- package/src/resources/v1/customers/commits.ts +97 -10
- package/src/resources/v1/customers/credits.ts +76 -6
- package/src/resources/v1/customers/customers.ts +208 -27
- package/src/resources/v1/customers/index.ts +10 -8
- package/src/resources/v1/customers/invoices.ts +123 -57
- package/src/resources/v1/customers/named-schedules.ts +23 -2
- package/src/resources/v1/customers/plans.ts +48 -5
- package/src/resources/v1/customers.ts +1 -1
- package/src/resources/v1/dashboards.ts +30 -4
- package/src/resources/v1/index.ts +20 -14
- package/src/resources/v1/invoices.ts +16 -2
- package/src/resources/v1/plans.ts +45 -10
- package/src/resources/v1/pricing-units.ts +12 -4
- package/src/resources/v1/services.ts +7 -2
- package/src/resources/v1/usage.ts +187 -6
- package/src/resources/v1/v1.ts +39 -27
- package/src/resources/v1.ts +1 -1
- package/src/resources/v2/contracts.ts +3397 -235
- package/src/resources/v2/index.ts +2 -2
- package/src/resources/v2/v2.ts +3 -3
- package/src/resources/v2.ts +1 -1
- package/src/resources/webhooks.ts +7 -7
- package/src/resources.ts +1 -1
- package/src/shims/node.ts +3 -3
- package/src/shims/web.ts +3 -3
- package/src/uploads.ts +4 -4
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
package/resources/webhooks.js
CHANGED
|
@@ -64,18 +64,18 @@ class Webhooks extends resource_1.APIResource {
|
|
|
64
64
|
const msgDate = (0, core_1.getRequiredHeader)(headers, 'Date');
|
|
65
65
|
const msgSignature = (0, core_1.getRequiredHeader)(headers, 'Metronome-Webhook-Signature');
|
|
66
66
|
const now = Date.now();
|
|
67
|
-
const
|
|
68
|
-
if (isNaN(
|
|
67
|
+
const timestampMs = Math.floor(new Date(msgDate).valueOf());
|
|
68
|
+
if (isNaN(timestampMs)) {
|
|
69
69
|
throw new Error(`Invalid timestamp header: ${msgDate}`);
|
|
70
70
|
}
|
|
71
71
|
if (typeof body !== 'string') {
|
|
72
72
|
throw new Error('Webhook body must be passed as the raw JSON string sent from the server (do not parse it first).');
|
|
73
73
|
}
|
|
74
|
-
const
|
|
75
|
-
if (now -
|
|
74
|
+
const webhook_tolerance_in_ms = 5 * 60 * 1000; // 5 minutes
|
|
75
|
+
if (now - timestampMs > webhook_tolerance_in_ms) {
|
|
76
76
|
throw new Error('Webhook timestamp is too old');
|
|
77
77
|
}
|
|
78
|
-
if (
|
|
78
|
+
if (timestampMs > now + webhook_tolerance_in_ms) {
|
|
79
79
|
throw new Error('Webhook timestamp is too new');
|
|
80
80
|
}
|
|
81
81
|
const expectedSignature = this.signPayload(body, { date: msgDate, secret });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,6CAA0C;AAC1C,mCAAoC;AACpC,qCAAyD;AAEzD,MAAa,QAAS,SAAQ,sBAAW;IACvC;;OAEG;IACH,MAAM,CACJ,OAAe,EACf,OAAoB,EACpB,SAAoC,IAAI,CAAC,OAAO,CAAC,aAAa;QAE9D,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAEO,cAAc,CAAC,MAAiC;QACtD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,IAAI,KAAK,CACb,0KAA0K,CAC3K,CAAC;SACH;QAED,OAAO;IACT,CAAC;IAEO,WAAW,CAAC,OAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAoC;QACrF,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,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AAE,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE;YACzF,SAAS;YACT,OAAO;SACR;QAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;CACF;AAjHD,4BAiHC"}
|
package/resources/webhooks.mjs
CHANGED
|
@@ -61,18 +61,18 @@ export class Webhooks extends APIResource {
|
|
|
61
61
|
const msgDate = getRequiredHeader(headers, 'Date');
|
|
62
62
|
const msgSignature = getRequiredHeader(headers, 'Metronome-Webhook-Signature');
|
|
63
63
|
const now = Date.now();
|
|
64
|
-
const
|
|
65
|
-
if (isNaN(
|
|
64
|
+
const timestampMs = Math.floor(new Date(msgDate).valueOf());
|
|
65
|
+
if (isNaN(timestampMs)) {
|
|
66
66
|
throw new Error(`Invalid timestamp header: ${msgDate}`);
|
|
67
67
|
}
|
|
68
68
|
if (typeof body !== 'string') {
|
|
69
69
|
throw new Error('Webhook body must be passed as the raw JSON string sent from the server (do not parse it first).');
|
|
70
70
|
}
|
|
71
|
-
const
|
|
72
|
-
if (now -
|
|
71
|
+
const webhook_tolerance_in_ms = 5 * 60 * 1000; // 5 minutes
|
|
72
|
+
if (now - timestampMs > webhook_tolerance_in_ms) {
|
|
73
73
|
throw new Error('Webhook timestamp is too old');
|
|
74
74
|
}
|
|
75
|
-
if (
|
|
75
|
+
if (timestampMs > now + webhook_tolerance_in_ms) {
|
|
76
76
|
throw new Error('Webhook timestamp is too new');
|
|
77
77
|
}
|
|
78
78
|
const expectedSignature = this.signPayload(body, { date: msgDate, secret });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,sFAAsF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KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5D,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;SACzD;QAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAC;SACH;QAED,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;QAC3D,IAAI,GAAG,GAAG,WAAW,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,IAAI,WAAW,GAAG,GAAG,GAAG,uBAAuB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE;YACzF,SAAS;YACT,OAAO;SACR;QAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;CACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { type Shims } from
|
|
5
|
-
import { getRuntime as getWebRuntime } from
|
|
4
|
+
import { type Shims } from "./registry.js";
|
|
5
|
+
import { getRuntime as getWebRuntime } from "./web-runtime.js";
|
|
6
6
|
import { ReadStream as FsReadStream } from 'node:fs';
|
|
7
7
|
|
|
8
8
|
export function getRuntime(): Shims {
|
package/src/_shims/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { manual } from
|
|
5
|
-
import * as auto from "./auto/types";
|
|
6
|
-
import { type RequestOptions } from
|
|
4
|
+
import { manual } from "./manual-types.js";
|
|
5
|
+
import * as auto from "./auto/types.js";
|
|
6
|
+
import { type RequestOptions } from "../core.js";
|
|
7
7
|
|
|
8
8
|
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
|
|
9
9
|
|
|
@@ -79,3 +79,5 @@ export function fileFromPath(path: string, options?: FileFromPathOptions): Promi
|
|
|
79
79
|
export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
|
|
80
80
|
|
|
81
81
|
export function isFsReadStream(value: any): value is FsReadStream;
|
|
82
|
+
|
|
83
|
+
export const init: () => void;
|
package/src/_shims/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const shims = require('./registry');
|
|
5
5
|
const auto = require('@metronome/sdk/_shims/auto/runtime');
|
|
6
|
-
|
|
6
|
+
exports.init = () => {
|
|
7
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
|
8
|
+
};
|
|
7
9
|
for (const property of Object.keys(shims)) {
|
|
8
10
|
Object.defineProperty(exports, property, {
|
|
9
11
|
get() {
|
|
@@ -11,3 +13,5 @@ for (const property of Object.keys(shims)) {
|
|
|
11
13
|
},
|
|
12
14
|
});
|
|
13
15
|
}
|
|
16
|
+
|
|
17
|
+
exports.init();
|
package/src/_shims/index.mjs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
4
|
import * as shims from './registry.mjs';
|
|
5
|
-
import * as auto from "./auto/runtime";
|
|
6
|
-
|
|
5
|
+
import * as auto from "./auto/runtime.mjs";
|
|
6
|
+
export const init = () => {
|
|
7
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
|
8
|
+
};
|
|
7
9
|
export * from './registry.mjs';
|
|
10
|
+
|
|
11
|
+
init();
|
|
@@ -10,9 +10,9 @@ import { ReadStream as FsReadStream } from 'node:fs';
|
|
|
10
10
|
import { type Agent } from 'node:http';
|
|
11
11
|
import { FormDataEncoder } from 'form-data-encoder';
|
|
12
12
|
import { Readable } from 'node:stream';
|
|
13
|
-
import { type RequestOptions } from
|
|
14
|
-
import { MultipartBody } from
|
|
15
|
-
import { type Shims } from
|
|
13
|
+
import { type RequestOptions } from "../core.js";
|
|
14
|
+
import { MultipartBody } from "./MultipartBody.js";
|
|
15
|
+
import { type Shims } from "./registry.js";
|
|
16
16
|
import { ReadableStream } from 'node:stream/web';
|
|
17
17
|
|
|
18
18
|
type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
|
package/src/_shims/registry.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { MultipartBody } from
|
|
5
|
-
import { type RequestOptions } from
|
|
6
|
-
import { type Shims } from
|
|
4
|
+
import { MultipartBody } from "./MultipartBody.js";
|
|
5
|
+
import { type RequestOptions } from "../core.js";
|
|
6
|
+
import { type Shims } from "./registry.js";
|
|
7
7
|
|
|
8
8
|
export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims {
|
|
9
9
|
const recommendation =
|
package/src/core.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { VERSION } from
|
|
1
|
+
import { VERSION } from "./version.js";
|
|
2
2
|
import {
|
|
3
3
|
MetronomeError,
|
|
4
4
|
APIError,
|
|
5
5
|
APIConnectionError,
|
|
6
6
|
APIConnectionTimeoutError,
|
|
7
7
|
APIUserAbortError,
|
|
8
|
-
} from
|
|
8
|
+
} from "./error.js";
|
|
9
9
|
import {
|
|
10
10
|
kind as shimsKind,
|
|
11
11
|
type Readable,
|
|
@@ -16,18 +16,37 @@ import {
|
|
|
16
16
|
type RequestInit,
|
|
17
17
|
type Response,
|
|
18
18
|
type HeadersInit,
|
|
19
|
-
|
|
19
|
+
init,
|
|
20
|
+
} from "./_shims/index.js";
|
|
21
|
+
|
|
22
|
+
// try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881
|
|
23
|
+
init();
|
|
24
|
+
|
|
20
25
|
export { type Response };
|
|
21
|
-
import { BlobLike, isBlobLike, isMultipartBody } from
|
|
26
|
+
import { BlobLike, isBlobLike, isMultipartBody } from "./uploads.js";
|
|
22
27
|
export {
|
|
23
28
|
maybeMultipartFormRequestOptions,
|
|
24
29
|
multipartFormRequestOptions,
|
|
25
30
|
createForm,
|
|
26
31
|
type Uploadable,
|
|
27
|
-
} from
|
|
32
|
+
} from "./uploads.js";
|
|
28
33
|
|
|
29
34
|
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
30
35
|
|
|
36
|
+
/**
|
|
37
|
+
* An alias to the builtin `Array` type so we can
|
|
38
|
+
* easily alias it in import statements if there are name clashes.
|
|
39
|
+
*/
|
|
40
|
+
type _Array<T> = Array<T>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An alias to the builtin `Record` type so we can
|
|
44
|
+
* easily alias it in import statements if there are name clashes.
|
|
45
|
+
*/
|
|
46
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
47
|
+
|
|
48
|
+
export type { _Array as Array, _Record as Record };
|
|
49
|
+
|
|
31
50
|
type PromiseOrValue<T> = T | Promise<T>;
|
|
32
51
|
|
|
33
52
|
type APIResponseProps = {
|
|
@@ -151,6 +170,7 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
151
170
|
|
|
152
171
|
export abstract class APIClient {
|
|
153
172
|
baseURL: string;
|
|
173
|
+
#baseURLOverridden: boolean;
|
|
154
174
|
maxRetries: number;
|
|
155
175
|
timeout: number;
|
|
156
176
|
httpAgent: Agent | undefined;
|
|
@@ -160,18 +180,21 @@ export abstract class APIClient {
|
|
|
160
180
|
|
|
161
181
|
constructor({
|
|
162
182
|
baseURL,
|
|
183
|
+
baseURLOverridden,
|
|
163
184
|
maxRetries = 2,
|
|
164
185
|
timeout = 60000, // 1 minute
|
|
165
186
|
httpAgent,
|
|
166
187
|
fetch: overriddenFetch,
|
|
167
188
|
}: {
|
|
168
189
|
baseURL: string;
|
|
190
|
+
baseURLOverridden: boolean;
|
|
169
191
|
maxRetries?: number | undefined;
|
|
170
192
|
timeout: number | undefined;
|
|
171
193
|
httpAgent: Agent | undefined;
|
|
172
194
|
fetch: Fetch | undefined;
|
|
173
195
|
}) {
|
|
174
196
|
this.baseURL = baseURL;
|
|
197
|
+
this.#baseURLOverridden = baseURLOverridden;
|
|
175
198
|
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
|
|
176
199
|
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
177
200
|
this.httpAgent = httpAgent;
|
|
@@ -194,7 +217,7 @@ export abstract class APIClient {
|
|
|
194
217
|
protected defaultHeaders(opts: FinalRequestOptions): Headers {
|
|
195
218
|
return {
|
|
196
219
|
Accept: 'application/json',
|
|
197
|
-
'Content-Type': 'application/json',
|
|
220
|
+
...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
|
|
198
221
|
'User-Agent': this.getUserAgent(),
|
|
199
222
|
...getPlatformHeaders(),
|
|
200
223
|
...this.authHeaders(opts),
|
|
@@ -276,12 +299,12 @@ export abstract class APIClient {
|
|
|
276
299
|
return null;
|
|
277
300
|
}
|
|
278
301
|
|
|
279
|
-
buildRequest<Req>(
|
|
280
|
-
|
|
302
|
+
async buildRequest<Req>(
|
|
303
|
+
inputOptions: FinalRequestOptions<Req>,
|
|
281
304
|
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
282
|
-
): { req: RequestInit; url: string; timeout: number } {
|
|
283
|
-
options = { ...
|
|
284
|
-
const { method, path, query, headers: headers = {} } = options;
|
|
305
|
+
): Promise<{ req: RequestInit; url: string; timeout: number }> {
|
|
306
|
+
const options = { ...inputOptions };
|
|
307
|
+
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
|
|
285
308
|
|
|
286
309
|
const body =
|
|
287
310
|
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
|
|
@@ -291,7 +314,7 @@ export abstract class APIClient {
|
|
|
291
314
|
: null;
|
|
292
315
|
const contentLength = this.calculateContentLength(body);
|
|
293
316
|
|
|
294
|
-
const url = this.buildURL(path!, query);
|
|
317
|
+
const url = this.buildURL(path!, query, defaultBaseURL);
|
|
295
318
|
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
296
319
|
options.timeout = options.timeout ?? this.timeout;
|
|
297
320
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
|
|
@@ -308,8 +331,8 @@ export abstract class APIClient {
|
|
|
308
331
|
}
|
|
309
332
|
|
|
310
333
|
if (this.idempotencyHeader && method !== 'get') {
|
|
311
|
-
if (!
|
|
312
|
-
headers[this.idempotencyHeader] =
|
|
334
|
+
if (!inputOptions.idempotencyKey) inputOptions.idempotencyKey = this.defaultIdempotencyKey();
|
|
335
|
+
headers[this.idempotencyHeader] = inputOptions.idempotencyKey;
|
|
313
336
|
}
|
|
314
337
|
|
|
315
338
|
const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
|
|
@@ -366,7 +389,7 @@ export abstract class APIClient {
|
|
|
366
389
|
getHeader(headers, 'x-stainless-timeout') === undefined &&
|
|
367
390
|
options.timeout
|
|
368
391
|
) {
|
|
369
|
-
reqHeaders['x-stainless-timeout'] = String(options.timeout);
|
|
392
|
+
reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
|
|
370
393
|
}
|
|
371
394
|
|
|
372
395
|
this.validateHeaders(reqHeaders, headers);
|
|
@@ -427,7 +450,9 @@ export abstract class APIClient {
|
|
|
427
450
|
|
|
428
451
|
await this.prepareOptions(options);
|
|
429
452
|
|
|
430
|
-
const { req, url, timeout } = this.buildRequest(options, {
|
|
453
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
454
|
+
retryCount: maxRetries - retriesRemaining,
|
|
455
|
+
});
|
|
431
456
|
|
|
432
457
|
await this.prepareRequest(req, { url, options });
|
|
433
458
|
|
|
@@ -484,11 +509,12 @@ export abstract class APIClient {
|
|
|
484
509
|
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
485
510
|
}
|
|
486
511
|
|
|
487
|
-
buildURL<Req>(path: string, query: Req | null | undefined): string {
|
|
512
|
+
buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string {
|
|
513
|
+
const baseURL = (!this.#baseURLOverridden && defaultBaseURL) || this.baseURL;
|
|
488
514
|
const url =
|
|
489
515
|
isAbsoluteURL(path) ?
|
|
490
516
|
new URL(path)
|
|
491
|
-
: new URL(
|
|
517
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
492
518
|
|
|
493
519
|
const defaultQuery = this.defaultQuery();
|
|
494
520
|
if (!isEmptyObj(defaultQuery)) {
|
|
@@ -773,6 +799,7 @@ export type RequestOptions<
|
|
|
773
799
|
query?: Req | undefined;
|
|
774
800
|
body?: Req | null | undefined;
|
|
775
801
|
headers?: Headers | undefined;
|
|
802
|
+
defaultBaseURL?: string | undefined;
|
|
776
803
|
|
|
777
804
|
maxRetries?: number;
|
|
778
805
|
stream?: boolean | undefined;
|
|
@@ -794,6 +821,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
|
|
|
794
821
|
query: true,
|
|
795
822
|
body: true,
|
|
796
823
|
headers: true,
|
|
824
|
+
defaultBaseURL: true,
|
|
797
825
|
|
|
798
826
|
maxRetries: true,
|
|
799
827
|
stream: true,
|
package/src/error.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type Agent } from
|
|
4
|
-
import * as qs from
|
|
5
|
-
import * as Core from
|
|
6
|
-
import * as Errors from
|
|
7
|
-
import * as Pagination from
|
|
8
|
-
import { type CursorPageParams, CursorPageResponse } from
|
|
9
|
-
import * as Uploads from
|
|
10
|
-
import * as API from
|
|
11
|
-
import { V1 } from
|
|
12
|
-
import { V2 } from
|
|
13
|
-
|
|
14
|
-
import { Webhooks } from './resources/webhooks';
|
|
3
|
+
import { type Agent } from "./_shims/index.js";
|
|
4
|
+
import * as qs from "./internal/qs.js";
|
|
5
|
+
import * as Core from "./core.js";
|
|
6
|
+
import * as Errors from "./error.js";
|
|
7
|
+
import * as Pagination from "./pagination.js";
|
|
8
|
+
import { type CursorPageParams, CursorPageResponse } from "./pagination.js";
|
|
9
|
+
import * as Uploads from "./uploads.js";
|
|
10
|
+
import * as API from "./resources/index.js";
|
|
11
|
+
import { V1 } from "./resources/v1/v1.js";
|
|
12
|
+
import { V2 } from "./resources/v2/v2.js";
|
|
15
13
|
|
|
16
14
|
export interface ClientOptions {
|
|
17
15
|
/**
|
|
@@ -37,6 +35,8 @@ export interface ClientOptions {
|
|
|
37
35
|
*
|
|
38
36
|
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
39
37
|
* much longer than this timeout before the promise succeeds or fails.
|
|
38
|
+
*
|
|
39
|
+
* @unit milliseconds
|
|
40
40
|
*/
|
|
41
41
|
timeout?: number | undefined;
|
|
42
42
|
|
|
@@ -124,6 +124,7 @@ export class Metronome extends Core.APIClient {
|
|
|
124
124
|
|
|
125
125
|
super({
|
|
126
126
|
baseURL: options.baseURL!,
|
|
127
|
+
baseURLOverridden: baseURL ? baseURL !== 'https://api.metronome.com' : false,
|
|
127
128
|
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
128
129
|
httpAgent: options.httpAgent,
|
|
129
130
|
maxRetries: options.maxRetries,
|
|
@@ -140,6 +141,13 @@ export class Metronome extends Core.APIClient {
|
|
|
140
141
|
v1: API.V1 = new API.V1(this);
|
|
141
142
|
webhooks: API.Webhooks = new API.Webhooks(this);
|
|
142
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Check whether the base URL is set to its default.
|
|
146
|
+
*/
|
|
147
|
+
#baseURLOverridden(): boolean {
|
|
148
|
+
return this.baseURL !== 'https://api.metronome.com';
|
|
149
|
+
}
|
|
150
|
+
|
|
143
151
|
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
144
152
|
return this._options.defaultQuery;
|
|
145
153
|
}
|
|
@@ -192,8 +200,6 @@ export declare namespace Metronome {
|
|
|
192
200
|
|
|
193
201
|
export { V1 as V1 };
|
|
194
202
|
|
|
195
|
-
export { Webhooks as Webhooks };
|
|
196
|
-
|
|
197
203
|
export type BaseUsageFilter = API.BaseUsageFilter;
|
|
198
204
|
export type Commit = API.Commit;
|
|
199
205
|
export type ContractWithoutAmendments = API.ContractWithoutAmendments;
|
|
@@ -212,7 +218,7 @@ export declare namespace Metronome {
|
|
|
212
218
|
export type Tier = API.Tier;
|
|
213
219
|
}
|
|
214
220
|
|
|
215
|
-
export { toFile, fileFromPath } from
|
|
221
|
+
export { toFile, fileFromPath } from "./uploads.js";
|
|
216
222
|
export {
|
|
217
223
|
MetronomeError,
|
|
218
224
|
APIError,
|
|
@@ -227,6 +233,6 @@ export {
|
|
|
227
233
|
InternalServerError,
|
|
228
234
|
PermissionDeniedError,
|
|
229
235
|
UnprocessableEntityError,
|
|
230
|
-
} from
|
|
236
|
+
} from "./error.js";
|
|
231
237
|
|
|
232
238
|
export default Metronome;
|
package/src/internal/qs/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { default_format, formatters, RFC1738, RFC3986 } from
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from "./formats.js";
|
|
2
2
|
|
|
3
3
|
const formats = {
|
|
4
4
|
formatters,
|
|
@@ -7,7 +7,7 @@ const formats = {
|
|
|
7
7
|
default: default_format,
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export { stringify } from
|
|
10
|
+
export { stringify } from "./stringify.js";
|
|
11
11
|
export { formats };
|
|
12
12
|
|
|
13
|
-
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from "./types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { encode, is_buffer, maybe_map } from
|
|
2
|
-
import { default_format, formatters } from
|
|
3
|
-
import type { NonNullableProperties, StringifyOptions } from
|
|
1
|
+
import { encode, is_buffer, maybe_map } from "./utils.js";
|
|
2
|
+
import { default_format, formatters } from "./formats.js";
|
|
3
|
+
import type { NonNullableProperties, StringifyOptions } from "./types.js";
|
|
4
4
|
|
|
5
5
|
const has = Object.prototype.hasOwnProperty;
|
|
6
6
|
|
package/src/internal/qs/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RFC1738 } from
|
|
2
|
-
import type { DefaultEncoder, Format } from
|
|
1
|
+
import { RFC1738 } from "./formats.js";
|
|
2
|
+
import type { DefaultEncoder, Format } from "./types.js";
|
|
3
3
|
|
|
4
4
|
const has = Object.prototype.hasOwnProperty;
|
|
5
5
|
const is_array = Array.isArray;
|
package/src/pagination.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from
|
|
3
|
+
import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from "./core.js";
|
|
4
4
|
|
|
5
5
|
export interface CursorPageResponse<Item> {
|
|
6
6
|
/**
|
|
@@ -53,6 +53,10 @@ export class CursorPage<Item> extends AbstractPage<Item> implements CursorPageRe
|
|
|
53
53
|
return this.data ?? [];
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
override hasNextPage(): boolean {
|
|
57
|
+
return this.nextPageInfo() != null;
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
// @deprecated Please use `nextPageInfo()` instead
|
|
57
61
|
nextPageParams(): Partial<CursorPageParams> | null {
|
|
58
62
|
const info = this.nextPageInfo();
|
package/src/resource.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type { Metronome } from
|
|
3
|
+
import type { Metronome } from "./index.js";
|
|
4
4
|
|
|
5
|
-
export class APIResource {
|
|
5
|
+
export abstract class APIResource {
|
|
6
6
|
protected _client: Metronome;
|
|
7
7
|
|
|
8
8
|
constructor(client: Metronome) {
|
package/src/resources/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export * from
|
|
4
|
-
export { V1 } from
|
|
5
|
-
export { V2 } from
|
|
6
|
-
export { Webhooks } from
|
|
3
|
+
export * from "./shared.js";
|
|
4
|
+
export { V1 } from "./v1/v1.js";
|
|
5
|
+
export { V2 } from "./v2/v2.js";
|
|
6
|
+
export { Webhooks } from "./webhooks.js";
|