@commet/node 7.7.0 → 7.9.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/README.md +4 -0
- package/dist/index.d.mts +57 -11
- package/dist/index.d.ts +57 -11
- package/dist/index.js +134 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -440,7 +440,7 @@ var PlansResource = class {
|
|
|
440
440
|
options
|
|
441
441
|
);
|
|
442
442
|
}
|
|
443
|
-
/** Configure a plan's regional pricing for one currency. Sending only currency and exchangeRate derives every regional value (base price, included balance, feature overage, intro offer) from the USD value
|
|
443
|
+
/** Configure a plan's regional pricing for one currency. USD configures the United States variant; exchangeRate acts as its price multiplier. Sending only currency and exchangeRate derives every regional value (base price, included balance, feature overage, intro offer) from the default USD value. Optional per-price and per-feature overrides are stored as manual values. */
|
|
444
444
|
async setRegionalPricing(params, options) {
|
|
445
445
|
const { id, ...rest } = params;
|
|
446
446
|
return this.httpClient.put(`/plans/${id}/regional`, rest, options);
|
|
@@ -482,20 +482,31 @@ var PromoCodesResource = class {
|
|
|
482
482
|
return this.httpClient.get(`/promo-codes/${id}`, void 0, options);
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
|
-
* Create a new promo code. Optionally restrict to specific plans.
|
|
485
|
+
* Create a new promo code. Optionally restrict it to specific plans and a billing interval.
|
|
486
486
|
*
|
|
487
487
|
* **100% discounts are not supported.** Percentage codes must be strictly less than 100% (`discountValue` < 10000 basis points). For full waivers, use an introductory offer on the plan instead. At checkout, any code — percentage or fixed amount — that would reduce the total below the currency's minimum charge ($0.50 USD equivalent) is silently dropped.
|
|
488
488
|
*/
|
|
489
489
|
async create(params, options) {
|
|
490
490
|
return this.httpClient.post("/promo-codes", params, options);
|
|
491
491
|
}
|
|
492
|
-
/** Update a promo code's redemption limits, expiration, active status, or plan restrictions. */
|
|
492
|
+
/** Update a promo code's billing interval, redemption limits, expiration, active status, or plan restrictions. */
|
|
493
493
|
async update(params, options) {
|
|
494
494
|
const { id, ...rest } = params;
|
|
495
495
|
return this.httpClient.put(`/promo-codes/${id}`, rest, options);
|
|
496
496
|
}
|
|
497
497
|
};
|
|
498
498
|
|
|
499
|
+
// src/resources/provisioning.ts
|
|
500
|
+
var ProvisioningResource = class {
|
|
501
|
+
constructor(httpClient) {
|
|
502
|
+
this.httpClient = httpClient;
|
|
503
|
+
}
|
|
504
|
+
/** Issue a fresh claim link for an organization that was provisioned headlessly and has not been claimed yet. Any previously issued link stops working. */
|
|
505
|
+
async createClaimLink(options) {
|
|
506
|
+
return this.httpClient.post("/claim-link", {}, options);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
499
510
|
// src/resources/quota.ts
|
|
500
511
|
var QuotaResource = class {
|
|
501
512
|
constructor(httpClient) {
|
|
@@ -679,9 +690,9 @@ var TestClockResource = class {
|
|
|
679
690
|
async advance(params, options) {
|
|
680
691
|
return this.httpClient.post("/test-clock", params, options);
|
|
681
692
|
}
|
|
682
|
-
/** Discovers customers due for billing at the org's current (simulated) time and enqueues a billing cycle for each — renewals, expired trials, pending cancellations. Enqueueing is asynchronous. Sandbox only. */
|
|
683
|
-
async processBilling() {
|
|
684
|
-
return this.httpClient.post("/test-clock/process-billing", {});
|
|
693
|
+
/** Discovers customers due for billing at the org's current (simulated) time and enqueues a billing cycle for each — renewals, expired trials, pending cancellations. Also fires any dunning retry whose scheduled time has passed. Enqueueing is asynchronous. Sandbox only. */
|
|
694
|
+
async processBilling(options) {
|
|
695
|
+
return this.httpClient.post("/test-clock/process-billing", {}, options);
|
|
685
696
|
}
|
|
686
697
|
};
|
|
687
698
|
|
|
@@ -727,6 +738,7 @@ var GeneratedResources = class {
|
|
|
727
738
|
this.plans = new PlansResource(http);
|
|
728
739
|
this.portal = new PortalResource(http);
|
|
729
740
|
this.promoCodes = new PromoCodesResource(http);
|
|
741
|
+
this.provisioning = new ProvisioningResource(http);
|
|
730
742
|
this.quota = new QuotaResource(http);
|
|
731
743
|
this.seats = new SeatsResource(http);
|
|
732
744
|
this.subscriptions = new SubscriptionsResource(http);
|
|
@@ -771,6 +783,10 @@ var UsageResource = class {
|
|
|
771
783
|
async check(params, options) {
|
|
772
784
|
return this.httpClient.post("/usage/check", params, options);
|
|
773
785
|
}
|
|
786
|
+
/** Set a metered feature's usage to an exact value for the current period. */
|
|
787
|
+
async set(params, options) {
|
|
788
|
+
return this.httpClient.put("/usage", params, options);
|
|
789
|
+
}
|
|
774
790
|
};
|
|
775
791
|
|
|
776
792
|
// src/resources/webhooks.ts
|
|
@@ -880,7 +896,7 @@ var CommetValidationError = class extends CommetError {
|
|
|
880
896
|
|
|
881
897
|
// src/version.ts
|
|
882
898
|
var API_VERSION = "2026-07-11";
|
|
883
|
-
var SDK_VERSION = "7.
|
|
899
|
+
var SDK_VERSION = "7.9.0";
|
|
884
900
|
|
|
885
901
|
// src/utils/telemetry.ts
|
|
886
902
|
var registeredIntegrations = /* @__PURE__ */ new Set();
|
|
@@ -1204,6 +1220,116 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
1204
1220
|
_CommetHTTPClient.BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
1205
1221
|
var CommetHTTPClient = _CommetHTTPClient;
|
|
1206
1222
|
|
|
1223
|
+
// src/utils/update-check.ts
|
|
1224
|
+
var NPM_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40commet%2Fnode/dist-tags";
|
|
1225
|
+
var UPDATE_CHECK_TIMEOUT_MS = 3e3;
|
|
1226
|
+
var UPDATE_CHECK_STATE_KEY = Symbol.for("@commet/node.update-check");
|
|
1227
|
+
function parseVersion(version) {
|
|
1228
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
|
|
1229
|
+
version
|
|
1230
|
+
);
|
|
1231
|
+
if (!match) return null;
|
|
1232
|
+
const numbers = [
|
|
1233
|
+
Number(match[1]),
|
|
1234
|
+
Number(match[2]),
|
|
1235
|
+
Number(match[3])
|
|
1236
|
+
];
|
|
1237
|
+
if (!numbers.every(Number.isSafeInteger)) return null;
|
|
1238
|
+
return {
|
|
1239
|
+
numbers,
|
|
1240
|
+
prereleaseIdentifiers: match[4] ? match[4].split(".") : []
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
function compareNumericIdentifier(latest, installed) {
|
|
1244
|
+
const normalizedLatest = latest.replace(/^0+(?=\d)/, "");
|
|
1245
|
+
const normalizedInstalled = installed.replace(/^0+(?=\d)/, "");
|
|
1246
|
+
if (normalizedLatest.length > normalizedInstalled.length) return 1;
|
|
1247
|
+
if (normalizedLatest.length < normalizedInstalled.length) return -1;
|
|
1248
|
+
if (normalizedLatest > normalizedInstalled) return 1;
|
|
1249
|
+
if (normalizedLatest < normalizedInstalled) return -1;
|
|
1250
|
+
return 0;
|
|
1251
|
+
}
|
|
1252
|
+
function comparePrereleaseIdentifier(latest, installed) {
|
|
1253
|
+
const latestIsNumber = /^\d+$/.test(latest);
|
|
1254
|
+
const installedIsNumber = /^\d+$/.test(installed);
|
|
1255
|
+
if (latestIsNumber && installedIsNumber) {
|
|
1256
|
+
return compareNumericIdentifier(latest, installed);
|
|
1257
|
+
}
|
|
1258
|
+
if (latestIsNumber) return -1;
|
|
1259
|
+
if (installedIsNumber) return 1;
|
|
1260
|
+
if (latest > installed) return 1;
|
|
1261
|
+
if (latest < installed) return -1;
|
|
1262
|
+
return 0;
|
|
1263
|
+
}
|
|
1264
|
+
function comparePrereleaseVersions(latest, installed) {
|
|
1265
|
+
if (latest.length === 0) return installed.length === 0 ? 0 : 1;
|
|
1266
|
+
if (installed.length === 0) return -1;
|
|
1267
|
+
const identifierCount = Math.max(latest.length, installed.length);
|
|
1268
|
+
for (let index = 0; index < identifierCount; index++) {
|
|
1269
|
+
const latestIdentifier = latest[index];
|
|
1270
|
+
const installedIdentifier = installed[index];
|
|
1271
|
+
if (latestIdentifier === void 0) return -1;
|
|
1272
|
+
if (installedIdentifier === void 0) return 1;
|
|
1273
|
+
const comparison = comparePrereleaseIdentifier(
|
|
1274
|
+
latestIdentifier,
|
|
1275
|
+
installedIdentifier
|
|
1276
|
+
);
|
|
1277
|
+
if (comparison !== 0) return comparison;
|
|
1278
|
+
}
|
|
1279
|
+
return 0;
|
|
1280
|
+
}
|
|
1281
|
+
function isNewerVersion(latest, installed) {
|
|
1282
|
+
const latestVersion = parseVersion(latest);
|
|
1283
|
+
const installedVersion = parseVersion(installed);
|
|
1284
|
+
if (!latestVersion || !installedVersion) return false;
|
|
1285
|
+
for (let index = 0; index < latestVersion.numbers.length; index++) {
|
|
1286
|
+
if (latestVersion.numbers[index] > installedVersion.numbers[index]) {
|
|
1287
|
+
return true;
|
|
1288
|
+
}
|
|
1289
|
+
if (latestVersion.numbers[index] < installedVersion.numbers[index]) {
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return comparePrereleaseVersions(
|
|
1294
|
+
latestVersion.prereleaseIdentifiers,
|
|
1295
|
+
installedVersion.prereleaseIdentifiers
|
|
1296
|
+
) > 0;
|
|
1297
|
+
}
|
|
1298
|
+
function claimSdkUpdateCheck() {
|
|
1299
|
+
if (Reflect.get(globalThis, UPDATE_CHECK_STATE_KEY) === true) return false;
|
|
1300
|
+
Reflect.set(globalThis, UPDATE_CHECK_STATE_KEY, true);
|
|
1301
|
+
return true;
|
|
1302
|
+
}
|
|
1303
|
+
function shouldCheckForSdkUpdates() {
|
|
1304
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
1305
|
+
if (process.env.CI) return false;
|
|
1306
|
+
return process.env.COMMET_NO_UPDATE_CHECK !== "1";
|
|
1307
|
+
}
|
|
1308
|
+
async function checkForSdkUpdate(installedVersion) {
|
|
1309
|
+
try {
|
|
1310
|
+
const response = await fetch(NPM_DIST_TAGS_URL, {
|
|
1311
|
+
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS)
|
|
1312
|
+
});
|
|
1313
|
+
if (!response.ok) return;
|
|
1314
|
+
const distTags = await response.json();
|
|
1315
|
+
if (typeof distTags !== "object" || distTags === null || !("latest" in distTags) || typeof distTags.latest !== "string" || !isNewerVersion(distTags.latest, installedVersion)) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
console.warn(
|
|
1319
|
+
`[Commet] @commet/node ${installedVersion} is out of date. The latest version is ${distTags.latest}.
|
|
1320
|
+
Update with: npm install @commet/node@latest`
|
|
1321
|
+
);
|
|
1322
|
+
} catch {
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
function scheduleSdkUpdateCheck() {
|
|
1326
|
+
if (!shouldCheckForSdkUpdates() || !claimSdkUpdateCheck()) return;
|
|
1327
|
+
const scheduledCheck = setImmediate(() => {
|
|
1328
|
+
void checkForSdkUpdate(SDK_VERSION);
|
|
1329
|
+
});
|
|
1330
|
+
scheduledCheck.unref();
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1207
1333
|
// src/client.ts
|
|
1208
1334
|
var Commet = class extends GeneratedResources {
|
|
1209
1335
|
constructor(config) {
|
|
@@ -1220,6 +1346,7 @@ var Commet = class extends GeneratedResources {
|
|
|
1220
1346
|
this.initResources(this.httpClient);
|
|
1221
1347
|
this.usage = new UsageResource(this.httpClient);
|
|
1222
1348
|
this.webhooks = new Webhooks(this.httpClient);
|
|
1349
|
+
scheduleSdkUpdateCheck();
|
|
1223
1350
|
}
|
|
1224
1351
|
};
|
|
1225
1352
|
function createCommet(_billingConfig, options) {
|