@commet/node 7.6.0 → 7.8.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 +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +115 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -213,7 +213,7 @@ var PaymentsResource = class {
|
|
|
213
213
|
async create(params, options) {
|
|
214
214
|
return this.httpClient.post("/payments", params, options);
|
|
215
215
|
}
|
|
216
|
-
/** Charge a customer's vaulted payment method off-session. Calculates tax, generates an invoice, and sends a receipt.
|
|
216
|
+
/** Charge a customer's vaulted payment method off-session. Calculates tax, generates an invoice, and sends a receipt. Requires the customer to have a subscription in active, trialing, or past_due state. */
|
|
217
217
|
async charge(params, options) {
|
|
218
218
|
return this.httpClient.post("/payments/charge", params, options);
|
|
219
219
|
}
|
|
@@ -572,7 +572,7 @@ var SubscriptionsResource = class {
|
|
|
572
572
|
options
|
|
573
573
|
);
|
|
574
574
|
}
|
|
575
|
-
/** Preview proration details for an immediate plan change (an upgrade or a longer interval) without applying it. Returns credit, charge, and net amount. Downgrades — a cheaper plan in the same group, or a shorter interval — are scheduled for the end of the current period instead of being prorated, so they return a 400 with code `plan_change_scheduled`; apply those via the change-plan endpoint. */
|
|
575
|
+
/** Preview proration details for an immediate plan change (an upgrade or a longer interval) without applying it. Returns credit, charge, and net amount. The target plan must belong to the same plan group as the current plan, otherwise a 400 with code `plans_not_in_same_group` is returned. A change between two free plans has nothing to prorate and returns a zero-amount estimate. Downgrades — a cheaper plan in the same group, or a shorter interval — are scheduled for the end of the current period instead of being prorated, so they return a 400 with code `plan_change_scheduled`; apply those via the change-plan endpoint. */
|
|
576
576
|
async previewChange(params, options) {
|
|
577
577
|
const { id, ...rest } = params;
|
|
578
578
|
return this.httpClient.post(
|
|
@@ -833,8 +833,8 @@ var CommetValidationError = class extends CommetError {
|
|
|
833
833
|
};
|
|
834
834
|
|
|
835
835
|
// src/version.ts
|
|
836
|
-
var API_VERSION = "2026-
|
|
837
|
-
var SDK_VERSION = "7.
|
|
836
|
+
var API_VERSION = "2026-07-11";
|
|
837
|
+
var SDK_VERSION = "7.8.0";
|
|
838
838
|
|
|
839
839
|
// src/utils/telemetry.ts
|
|
840
840
|
var registeredIntegrations = /* @__PURE__ */ new Set();
|
|
@@ -1158,6 +1158,116 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
1158
1158
|
_CommetHTTPClient.BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
1159
1159
|
var CommetHTTPClient = _CommetHTTPClient;
|
|
1160
1160
|
|
|
1161
|
+
// src/utils/update-check.ts
|
|
1162
|
+
var NPM_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40commet%2Fnode/dist-tags";
|
|
1163
|
+
var UPDATE_CHECK_TIMEOUT_MS = 3e3;
|
|
1164
|
+
var UPDATE_CHECK_STATE_KEY = Symbol.for("@commet/node.update-check");
|
|
1165
|
+
function parseVersion(version) {
|
|
1166
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
|
|
1167
|
+
version
|
|
1168
|
+
);
|
|
1169
|
+
if (!match) return null;
|
|
1170
|
+
const numbers = [
|
|
1171
|
+
Number(match[1]),
|
|
1172
|
+
Number(match[2]),
|
|
1173
|
+
Number(match[3])
|
|
1174
|
+
];
|
|
1175
|
+
if (!numbers.every(Number.isSafeInteger)) return null;
|
|
1176
|
+
return {
|
|
1177
|
+
numbers,
|
|
1178
|
+
prereleaseIdentifiers: match[4] ? match[4].split(".") : []
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
function compareNumericIdentifier(latest, installed) {
|
|
1182
|
+
const normalizedLatest = latest.replace(/^0+(?=\d)/, "");
|
|
1183
|
+
const normalizedInstalled = installed.replace(/^0+(?=\d)/, "");
|
|
1184
|
+
if (normalizedLatest.length > normalizedInstalled.length) return 1;
|
|
1185
|
+
if (normalizedLatest.length < normalizedInstalled.length) return -1;
|
|
1186
|
+
if (normalizedLatest > normalizedInstalled) return 1;
|
|
1187
|
+
if (normalizedLatest < normalizedInstalled) return -1;
|
|
1188
|
+
return 0;
|
|
1189
|
+
}
|
|
1190
|
+
function comparePrereleaseIdentifier(latest, installed) {
|
|
1191
|
+
const latestIsNumber = /^\d+$/.test(latest);
|
|
1192
|
+
const installedIsNumber = /^\d+$/.test(installed);
|
|
1193
|
+
if (latestIsNumber && installedIsNumber) {
|
|
1194
|
+
return compareNumericIdentifier(latest, installed);
|
|
1195
|
+
}
|
|
1196
|
+
if (latestIsNumber) return -1;
|
|
1197
|
+
if (installedIsNumber) return 1;
|
|
1198
|
+
if (latest > installed) return 1;
|
|
1199
|
+
if (latest < installed) return -1;
|
|
1200
|
+
return 0;
|
|
1201
|
+
}
|
|
1202
|
+
function comparePrereleaseVersions(latest, installed) {
|
|
1203
|
+
if (latest.length === 0) return installed.length === 0 ? 0 : 1;
|
|
1204
|
+
if (installed.length === 0) return -1;
|
|
1205
|
+
const identifierCount = Math.max(latest.length, installed.length);
|
|
1206
|
+
for (let index = 0; index < identifierCount; index++) {
|
|
1207
|
+
const latestIdentifier = latest[index];
|
|
1208
|
+
const installedIdentifier = installed[index];
|
|
1209
|
+
if (latestIdentifier === void 0) return -1;
|
|
1210
|
+
if (installedIdentifier === void 0) return 1;
|
|
1211
|
+
const comparison = comparePrereleaseIdentifier(
|
|
1212
|
+
latestIdentifier,
|
|
1213
|
+
installedIdentifier
|
|
1214
|
+
);
|
|
1215
|
+
if (comparison !== 0) return comparison;
|
|
1216
|
+
}
|
|
1217
|
+
return 0;
|
|
1218
|
+
}
|
|
1219
|
+
function isNewerVersion(latest, installed) {
|
|
1220
|
+
const latestVersion = parseVersion(latest);
|
|
1221
|
+
const installedVersion = parseVersion(installed);
|
|
1222
|
+
if (!latestVersion || !installedVersion) return false;
|
|
1223
|
+
for (let index = 0; index < latestVersion.numbers.length; index++) {
|
|
1224
|
+
if (latestVersion.numbers[index] > installedVersion.numbers[index]) {
|
|
1225
|
+
return true;
|
|
1226
|
+
}
|
|
1227
|
+
if (latestVersion.numbers[index] < installedVersion.numbers[index]) {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return comparePrereleaseVersions(
|
|
1232
|
+
latestVersion.prereleaseIdentifiers,
|
|
1233
|
+
installedVersion.prereleaseIdentifiers
|
|
1234
|
+
) > 0;
|
|
1235
|
+
}
|
|
1236
|
+
function claimSdkUpdateCheck() {
|
|
1237
|
+
if (Reflect.get(globalThis, UPDATE_CHECK_STATE_KEY) === true) return false;
|
|
1238
|
+
Reflect.set(globalThis, UPDATE_CHECK_STATE_KEY, true);
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
function shouldCheckForSdkUpdates() {
|
|
1242
|
+
if (process.env.NODE_ENV !== "development") return false;
|
|
1243
|
+
if (process.env.CI) return false;
|
|
1244
|
+
return process.env.COMMET_NO_UPDATE_CHECK !== "1";
|
|
1245
|
+
}
|
|
1246
|
+
async function checkForSdkUpdate(installedVersion) {
|
|
1247
|
+
try {
|
|
1248
|
+
const response = await fetch(NPM_DIST_TAGS_URL, {
|
|
1249
|
+
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS)
|
|
1250
|
+
});
|
|
1251
|
+
if (!response.ok) return;
|
|
1252
|
+
const distTags = await response.json();
|
|
1253
|
+
if (typeof distTags !== "object" || distTags === null || !("latest" in distTags) || typeof distTags.latest !== "string" || !isNewerVersion(distTags.latest, installedVersion)) {
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
console.warn(
|
|
1257
|
+
`[Commet] @commet/node ${installedVersion} is out of date. The latest version is ${distTags.latest}.
|
|
1258
|
+
Update with: npm install @commet/node@latest`
|
|
1259
|
+
);
|
|
1260
|
+
} catch {
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
function scheduleSdkUpdateCheck() {
|
|
1264
|
+
if (!shouldCheckForSdkUpdates() || !claimSdkUpdateCheck()) return;
|
|
1265
|
+
const scheduledCheck = setImmediate(() => {
|
|
1266
|
+
void checkForSdkUpdate(SDK_VERSION);
|
|
1267
|
+
});
|
|
1268
|
+
scheduledCheck.unref();
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1161
1271
|
// src/client.ts
|
|
1162
1272
|
var Commet = class extends GeneratedResources {
|
|
1163
1273
|
constructor(config) {
|
|
@@ -1174,6 +1284,7 @@ var Commet = class extends GeneratedResources {
|
|
|
1174
1284
|
this.initResources(this.httpClient);
|
|
1175
1285
|
this.usage = new UsageResource(this.httpClient);
|
|
1176
1286
|
this.webhooks = new Webhooks(this.httpClient);
|
|
1287
|
+
scheduleSdkUpdateCheck();
|
|
1177
1288
|
}
|
|
1178
1289
|
};
|
|
1179
1290
|
function createCommet(_billingConfig, options) {
|