@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.mjs
CHANGED
|
@@ -394,7 +394,7 @@ var PlansResource = class {
|
|
|
394
394
|
options
|
|
395
395
|
);
|
|
396
396
|
}
|
|
397
|
-
/** 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
|
|
397
|
+
/** 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. */
|
|
398
398
|
async setRegionalPricing(params, options) {
|
|
399
399
|
const { id, ...rest } = params;
|
|
400
400
|
return this.httpClient.put(`/plans/${id}/regional`, rest, options);
|
|
@@ -436,20 +436,31 @@ var PromoCodesResource = class {
|
|
|
436
436
|
return this.httpClient.get(`/promo-codes/${id}`, void 0, options);
|
|
437
437
|
}
|
|
438
438
|
/**
|
|
439
|
-
* Create a new promo code. Optionally restrict to specific plans.
|
|
439
|
+
* Create a new promo code. Optionally restrict it to specific plans and a billing interval.
|
|
440
440
|
*
|
|
441
441
|
* **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.
|
|
442
442
|
*/
|
|
443
443
|
async create(params, options) {
|
|
444
444
|
return this.httpClient.post("/promo-codes", params, options);
|
|
445
445
|
}
|
|
446
|
-
/** Update a promo code's redemption limits, expiration, active status, or plan restrictions. */
|
|
446
|
+
/** Update a promo code's billing interval, redemption limits, expiration, active status, or plan restrictions. */
|
|
447
447
|
async update(params, options) {
|
|
448
448
|
const { id, ...rest } = params;
|
|
449
449
|
return this.httpClient.put(`/promo-codes/${id}`, rest, options);
|
|
450
450
|
}
|
|
451
451
|
};
|
|
452
452
|
|
|
453
|
+
// src/resources/provisioning.ts
|
|
454
|
+
var ProvisioningResource = class {
|
|
455
|
+
constructor(httpClient) {
|
|
456
|
+
this.httpClient = httpClient;
|
|
457
|
+
}
|
|
458
|
+
/** Issue a fresh claim link for an organization that was provisioned headlessly and has not been claimed yet. Any previously issued link stops working. */
|
|
459
|
+
async createClaimLink(options) {
|
|
460
|
+
return this.httpClient.post("/claim-link", {}, options);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
453
464
|
// src/resources/quota.ts
|
|
454
465
|
var QuotaResource = class {
|
|
455
466
|
constructor(httpClient) {
|
|
@@ -633,9 +644,9 @@ var TestClockResource = class {
|
|
|
633
644
|
async advance(params, options) {
|
|
634
645
|
return this.httpClient.post("/test-clock", params, options);
|
|
635
646
|
}
|
|
636
|
-
/** 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. */
|
|
637
|
-
async processBilling() {
|
|
638
|
-
return this.httpClient.post("/test-clock/process-billing", {});
|
|
647
|
+
/** 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. */
|
|
648
|
+
async processBilling(options) {
|
|
649
|
+
return this.httpClient.post("/test-clock/process-billing", {}, options);
|
|
639
650
|
}
|
|
640
651
|
};
|
|
641
652
|
|
|
@@ -681,6 +692,7 @@ var GeneratedResources = class {
|
|
|
681
692
|
this.plans = new PlansResource(http);
|
|
682
693
|
this.portal = new PortalResource(http);
|
|
683
694
|
this.promoCodes = new PromoCodesResource(http);
|
|
695
|
+
this.provisioning = new ProvisioningResource(http);
|
|
684
696
|
this.quota = new QuotaResource(http);
|
|
685
697
|
this.seats = new SeatsResource(http);
|
|
686
698
|
this.subscriptions = new SubscriptionsResource(http);
|
|
@@ -725,6 +737,10 @@ var UsageResource = class {
|
|
|
725
737
|
async check(params, options) {
|
|
726
738
|
return this.httpClient.post("/usage/check", params, options);
|
|
727
739
|
}
|
|
740
|
+
/** Set a metered feature's usage to an exact value for the current period. */
|
|
741
|
+
async set(params, options) {
|
|
742
|
+
return this.httpClient.put("/usage", params, options);
|
|
743
|
+
}
|
|
728
744
|
};
|
|
729
745
|
|
|
730
746
|
// src/resources/webhooks.ts
|
|
@@ -834,7 +850,7 @@ var CommetValidationError = class extends CommetError {
|
|
|
834
850
|
|
|
835
851
|
// src/version.ts
|
|
836
852
|
var API_VERSION = "2026-07-11";
|
|
837
|
-
var SDK_VERSION = "7.
|
|
853
|
+
var SDK_VERSION = "7.9.0";
|
|
838
854
|
|
|
839
855
|
// src/utils/telemetry.ts
|
|
840
856
|
var registeredIntegrations = /* @__PURE__ */ new Set();
|
|
@@ -1158,6 +1174,116 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
1158
1174
|
_CommetHTTPClient.BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
1159
1175
|
var CommetHTTPClient = _CommetHTTPClient;
|
|
1160
1176
|
|
|
1177
|
+
// src/utils/update-check.ts
|
|
1178
|
+
var NPM_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40commet%2Fnode/dist-tags";
|
|
1179
|
+
var UPDATE_CHECK_TIMEOUT_MS = 3e3;
|
|
1180
|
+
var UPDATE_CHECK_STATE_KEY = Symbol.for("@commet/node.update-check");
|
|
1181
|
+
function parseVersion(version) {
|
|
1182
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
|
|
1183
|
+
version
|
|
1184
|
+
);
|
|
1185
|
+
if (!match) return null;
|
|
1186
|
+
const numbers = [
|
|
1187
|
+
Number(match[1]),
|
|
1188
|
+
Number(match[2]),
|
|
1189
|
+
Number(match[3])
|
|
1190
|
+
];
|
|
1191
|
+
if (!numbers.every(Number.isSafeInteger)) return null;
|
|
1192
|
+
return {
|
|
1193
|
+
numbers,
|
|
1194
|
+
prereleaseIdentifiers: match[4] ? match[4].split(".") : []
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
function compareNumericIdentifier(latest, installed) {
|
|
1198
|
+
const normalizedLatest = latest.replace(/^0+(?=\d)/, "");
|
|
1199
|
+
const normalizedInstalled = installed.replace(/^0+(?=\d)/, "");
|
|
1200
|
+
if (normalizedLatest.length > normalizedInstalled.length) return 1;
|
|
1201
|
+
if (normalizedLatest.length < normalizedInstalled.length) return -1;
|
|
1202
|
+
if (normalizedLatest > normalizedInstalled) return 1;
|
|
1203
|
+
if (normalizedLatest < normalizedInstalled) return -1;
|
|
1204
|
+
return 0;
|
|
1205
|
+
}
|
|
1206
|
+
function comparePrereleaseIdentifier(latest, installed) {
|
|
1207
|
+
const latestIsNumber = /^\d+$/.test(latest);
|
|
1208
|
+
const installedIsNumber = /^\d+$/.test(installed);
|
|
1209
|
+
if (latestIsNumber && installedIsNumber) {
|
|
1210
|
+
return compareNumericIdentifier(latest, installed);
|
|
1211
|
+
}
|
|
1212
|
+
if (latestIsNumber) return -1;
|
|
1213
|
+
if (installedIsNumber) return 1;
|
|
1214
|
+
if (latest > installed) return 1;
|
|
1215
|
+
if (latest < installed) return -1;
|
|
1216
|
+
return 0;
|
|
1217
|
+
}
|
|
1218
|
+
function comparePrereleaseVersions(latest, installed) {
|
|
1219
|
+
if (latest.length === 0) return installed.length === 0 ? 0 : 1;
|
|
1220
|
+
if (installed.length === 0) return -1;
|
|
1221
|
+
const identifierCount = Math.max(latest.length, installed.length);
|
|
1222
|
+
for (let index = 0; index < identifierCount; index++) {
|
|
1223
|
+
const latestIdentifier = latest[index];
|
|
1224
|
+
const installedIdentifier = installed[index];
|
|
1225
|
+
if (latestIdentifier === void 0) return -1;
|
|
1226
|
+
if (installedIdentifier === void 0) return 1;
|
|
1227
|
+
const comparison = comparePrereleaseIdentifier(
|
|
1228
|
+
latestIdentifier,
|
|
1229
|
+
installedIdentifier
|
|
1230
|
+
);
|
|
1231
|
+
if (comparison !== 0) return comparison;
|
|
1232
|
+
}
|
|
1233
|
+
return 0;
|
|
1234
|
+
}
|
|
1235
|
+
function isNewerVersion(latest, installed) {
|
|
1236
|
+
const latestVersion = parseVersion(latest);
|
|
1237
|
+
const installedVersion = parseVersion(installed);
|
|
1238
|
+
if (!latestVersion || !installedVersion) return false;
|
|
1239
|
+
for (let index = 0; index < latestVersion.numbers.length; index++) {
|
|
1240
|
+
if (latestVersion.numbers[index] > installedVersion.numbers[index]) {
|
|
1241
|
+
return true;
|
|
1242
|
+
}
|
|
1243
|
+
if (latestVersion.numbers[index] < installedVersion.numbers[index]) {
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
return comparePrereleaseVersions(
|
|
1248
|
+
latestVersion.prereleaseIdentifiers,
|
|
1249
|
+
installedVersion.prereleaseIdentifiers
|
|
1250
|
+
) > 0;
|
|
1251
|
+
}
|
|
1252
|
+
function claimSdkUpdateCheck() {
|
|
1253
|
+
if (Reflect.get(globalThis, UPDATE_CHECK_STATE_KEY) === true) return false;
|
|
1254
|
+
Reflect.set(globalThis, UPDATE_CHECK_STATE_KEY, true);
|
|
1255
|
+
return true;
|
|
1256
|
+
}
|
|
1257
|
+
function shouldCheckForSdkUpdates() {
|
|
1258
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
1259
|
+
if (process.env.CI) return false;
|
|
1260
|
+
return process.env.COMMET_NO_UPDATE_CHECK !== "1";
|
|
1261
|
+
}
|
|
1262
|
+
async function checkForSdkUpdate(installedVersion) {
|
|
1263
|
+
try {
|
|
1264
|
+
const response = await fetch(NPM_DIST_TAGS_URL, {
|
|
1265
|
+
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS)
|
|
1266
|
+
});
|
|
1267
|
+
if (!response.ok) return;
|
|
1268
|
+
const distTags = await response.json();
|
|
1269
|
+
if (typeof distTags !== "object" || distTags === null || !("latest" in distTags) || typeof distTags.latest !== "string" || !isNewerVersion(distTags.latest, installedVersion)) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
console.warn(
|
|
1273
|
+
`[Commet] @commet/node ${installedVersion} is out of date. The latest version is ${distTags.latest}.
|
|
1274
|
+
Update with: npm install @commet/node@latest`
|
|
1275
|
+
);
|
|
1276
|
+
} catch {
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
function scheduleSdkUpdateCheck() {
|
|
1280
|
+
if (!shouldCheckForSdkUpdates() || !claimSdkUpdateCheck()) return;
|
|
1281
|
+
const scheduledCheck = setImmediate(() => {
|
|
1282
|
+
void checkForSdkUpdate(SDK_VERSION);
|
|
1283
|
+
});
|
|
1284
|
+
scheduledCheck.unref();
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1161
1287
|
// src/client.ts
|
|
1162
1288
|
var Commet = class extends GeneratedResources {
|
|
1163
1289
|
constructor(config) {
|
|
@@ -1174,6 +1300,7 @@ var Commet = class extends GeneratedResources {
|
|
|
1174
1300
|
this.initResources(this.httpClient);
|
|
1175
1301
|
this.usage = new UsageResource(this.httpClient);
|
|
1176
1302
|
this.webhooks = new Webhooks(this.httpClient);
|
|
1303
|
+
scheduleSdkUpdateCheck();
|
|
1177
1304
|
}
|
|
1178
1305
|
};
|
|
1179
1306
|
function createCommet(_billingConfig, options) {
|