@solvapay/init 0.5.0 → 0.6.0-preview-7c1def75e5173f539a8bb4ea312cdeb445ae654c
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/dist/index.cjs +103 -1
- package/dist/index.d.cts +21 -7
- package/dist/index.d.ts +21 -7
- package/dist/index.js +99 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,10 +32,12 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
SOLVAPAY_PRODUCT_REF_PLACEHOLDER: () => SOLVAPAY_PRODUCT_REF_PLACEHOLDER2,
|
|
34
34
|
askKeepConfiguredProduct: () => askKeepConfiguredProduct,
|
|
35
|
+
compareStable: () => compareStable,
|
|
35
36
|
createInitSession: () => createInitSession,
|
|
36
37
|
detectPackageManager: () => detectPackageManager,
|
|
37
38
|
ensureEnvInGitignore: () => ensureEnvInGitignore,
|
|
38
39
|
ensureNodeProject: () => ensureNodeProject,
|
|
40
|
+
findOutdatedSolvapayPackages: () => findOutdatedSolvapayPackages,
|
|
39
41
|
formatConfiguredProductLabel: () => formatConfiguredProductLabel,
|
|
40
42
|
getInstallCommand: () => getInstallCommand,
|
|
41
43
|
getSolvaPayBasePackages: () => getSolvaPayBasePackages,
|
|
@@ -48,6 +50,8 @@ __export(index_exports, {
|
|
|
48
50
|
readSolvaPaySecretKeyFromEnv: () => readSolvaPaySecretKeyFromEnv,
|
|
49
51
|
runDoctorInDirectory: () => runDoctorInDirectory,
|
|
50
52
|
runInitInDirectory: () => runInitInDirectory,
|
|
53
|
+
solvapayDependencies: () => solvapayDependencies,
|
|
54
|
+
upgradeCommand: () => upgradeCommand,
|
|
51
55
|
verifyProductRef: () => verifyProductRef,
|
|
52
56
|
verifySecretKey: () => verifySecretKey,
|
|
53
57
|
waitForEnter: () => waitForEnter,
|
|
@@ -1165,6 +1169,83 @@ var runInitInDirectory = async ({
|
|
|
1165
1169
|
// src/run-doctor.ts
|
|
1166
1170
|
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
1167
1171
|
var import_core3 = require("@solvapay/core");
|
|
1172
|
+
|
|
1173
|
+
// src/sdk-versions.ts
|
|
1174
|
+
var import_promises6 = require("fs/promises");
|
|
1175
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
1176
|
+
var REGISTRY = "https://registry.npmjs.org";
|
|
1177
|
+
var readJson = async (file) => {
|
|
1178
|
+
try {
|
|
1179
|
+
return JSON.parse(await (0, import_promises6.readFile)(file, "utf8"));
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
if (error.code === "ENOENT") return null;
|
|
1182
|
+
throw error;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
var solvapayDependencies = async (cwd) => {
|
|
1186
|
+
const pkg = await readJson(import_node_path3.default.join(cwd, "package.json"));
|
|
1187
|
+
if (!pkg) return null;
|
|
1188
|
+
const names = /* @__PURE__ */ new Set([
|
|
1189
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
1190
|
+
...Object.keys(pkg.devDependencies ?? {})
|
|
1191
|
+
]);
|
|
1192
|
+
return [...names].filter((name) => name.startsWith("@solvapay/")).sort();
|
|
1193
|
+
};
|
|
1194
|
+
var fetchDistTags = async (name) => {
|
|
1195
|
+
const url = `${REGISTRY}/-/package/${name}/dist-tags`;
|
|
1196
|
+
let response;
|
|
1197
|
+
try {
|
|
1198
|
+
response = await fetch(url, {
|
|
1199
|
+
headers: { accept: "application/json" },
|
|
1200
|
+
signal: AbortSignal.timeout(1e4)
|
|
1201
|
+
});
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
throw new Error(
|
|
1204
|
+
`Could not reach ${url}: ${error instanceof Error ? error.message : String(error)}`
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
if (!response.ok) throw new Error(`${url} answered ${response.status}`);
|
|
1208
|
+
return await response.json();
|
|
1209
|
+
};
|
|
1210
|
+
var isPreview = (version) => version.includes("-");
|
|
1211
|
+
var compareStable = (a, b) => {
|
|
1212
|
+
const pa = a.split(".").map(Number);
|
|
1213
|
+
const pb = b.split(".").map(Number);
|
|
1214
|
+
for (let i = 0; i < 3; i++) {
|
|
1215
|
+
const x = pa[i] ?? 0;
|
|
1216
|
+
const y = pb[i] ?? 0;
|
|
1217
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
1218
|
+
}
|
|
1219
|
+
return 0;
|
|
1220
|
+
};
|
|
1221
|
+
var findOutdatedSolvapayPackages = async (cwd, names, distTags = fetchDistTags) => {
|
|
1222
|
+
const outdated = [];
|
|
1223
|
+
for (const name of names) {
|
|
1224
|
+
const installedPkg = await readJson(
|
|
1225
|
+
import_node_path3.default.join(cwd, "node_modules", ...name.split("/"), "package.json")
|
|
1226
|
+
);
|
|
1227
|
+
if (!installedPkg || typeof installedPkg.version !== "string") {
|
|
1228
|
+
throw new Error(
|
|
1229
|
+
`${name} is in package.json but not installed. Run your package manager's install first.`
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
const installed = installedPkg.version;
|
|
1233
|
+
const tag = isPreview(installed) ? "preview" : "latest";
|
|
1234
|
+
const wanted = (await distTags(name))[tag];
|
|
1235
|
+
if (typeof wanted !== "string") throw new Error(`npm has no '${tag}' tag for ${name}`);
|
|
1236
|
+
const behind = isPreview(installed) ? installed !== wanted : compareStable(installed, wanted) < 0;
|
|
1237
|
+
if (behind) outdated.push({ name, installed, wanted, tag });
|
|
1238
|
+
}
|
|
1239
|
+
return outdated;
|
|
1240
|
+
};
|
|
1241
|
+
var upgradeCommand = (packageManager, outdated) => {
|
|
1242
|
+
const specs = outdated.map((o) => `${o.name}@${o.wanted}`).join(" ");
|
|
1243
|
+
if (packageManager === "pnpm") return `pnpm add --save-exact ${specs}`;
|
|
1244
|
+
if (packageManager === "yarn") return `yarn add --exact ${specs}`;
|
|
1245
|
+
return `npm install --save-exact ${specs}`;
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
// src/run-doctor.ts
|
|
1168
1249
|
var DEFAULT_API_BASE_URL2 = "https://api.solvapay.com";
|
|
1169
1250
|
var DEV_API_BASE_URL2 = "https://api-dev.solvapay.com";
|
|
1170
1251
|
var preferEnv = (processValue, fileValue) => {
|
|
@@ -1187,9 +1268,25 @@ var printCheck = (check) => {
|
|
|
1187
1268
|
process.stdout.write(`${mark} ${check.name}: ${check.detail}
|
|
1188
1269
|
`);
|
|
1189
1270
|
};
|
|
1271
|
+
var checkSdkVersions = async (cwd, distTags) => {
|
|
1272
|
+
const name = "@solvapay/* versions";
|
|
1273
|
+
try {
|
|
1274
|
+
const names = await solvapayDependencies(cwd);
|
|
1275
|
+
if (names === null) return { name, ok: true, detail: `no package.json in ${cwd}, nothing to check` };
|
|
1276
|
+
if (names.length === 0) return { name, ok: true, detail: "no @solvapay/* dependencies" };
|
|
1277
|
+
const outdated = await findOutdatedSolvapayPackages(cwd, names, distTags);
|
|
1278
|
+
if (outdated.length === 0) return { name, ok: true, detail: `${names.length} package(s) match npm` };
|
|
1279
|
+
const behind = outdated.map((o) => `${o.name} ${o.installed} (npm ${o.tag} ${o.wanted})`).join(", ");
|
|
1280
|
+
const command = upgradeCommand(await detectPackageManager(cwd), outdated);
|
|
1281
|
+
return { name, ok: false, detail: `behind npm: ${behind}. Upgrade with: ${command}` };
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
return { name, ok: false, detail: error instanceof Error ? error.message : String(error) };
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1190
1286
|
var runDoctorInDirectory = async ({
|
|
1191
1287
|
cwd,
|
|
1192
|
-
options = {}
|
|
1288
|
+
options = {},
|
|
1289
|
+
distTags = fetchDistTags
|
|
1193
1290
|
}) => {
|
|
1194
1291
|
const checks = [];
|
|
1195
1292
|
const apiBaseUrl = await resolveApiBaseUrl2(cwd, options);
|
|
@@ -1289,6 +1386,7 @@ SolvaPay doctor \u2014 ${apiBaseUrl}
|
|
|
1289
1386
|
});
|
|
1290
1387
|
}
|
|
1291
1388
|
}
|
|
1389
|
+
checks.push(await checkSdkVersions(cwd, distTags));
|
|
1292
1390
|
const debugRaw = process.env.SOLVAPAY_DEBUG;
|
|
1293
1391
|
checks.push({
|
|
1294
1392
|
name: "SOLVAPAY_DEBUG defaults",
|
|
@@ -1312,10 +1410,12 @@ ${import_chalk2.default.red("Doctor found problems. Fix the \u2717 items above,
|
|
|
1312
1410
|
0 && (module.exports = {
|
|
1313
1411
|
SOLVAPAY_PRODUCT_REF_PLACEHOLDER,
|
|
1314
1412
|
askKeepConfiguredProduct,
|
|
1413
|
+
compareStable,
|
|
1315
1414
|
createInitSession,
|
|
1316
1415
|
detectPackageManager,
|
|
1317
1416
|
ensureEnvInGitignore,
|
|
1318
1417
|
ensureNodeProject,
|
|
1418
|
+
findOutdatedSolvapayPackages,
|
|
1319
1419
|
formatConfiguredProductLabel,
|
|
1320
1420
|
getInstallCommand,
|
|
1321
1421
|
getSolvaPayBasePackages,
|
|
@@ -1328,6 +1428,8 @@ ${import_chalk2.default.red("Doctor found problems. Fix the \u2717 items above,
|
|
|
1328
1428
|
readSolvaPaySecretKeyFromEnv,
|
|
1329
1429
|
runDoctorInDirectory,
|
|
1330
1430
|
runInitInDirectory,
|
|
1431
|
+
solvapayDependencies,
|
|
1432
|
+
upgradeCommand,
|
|
1331
1433
|
verifyProductRef,
|
|
1332
1434
|
verifySecretKey,
|
|
1333
1435
|
waitForEnter,
|
package/dist/index.d.cts
CHANGED
|
@@ -169,6 +169,23 @@ type RunInitInDirectoryOptions = {
|
|
|
169
169
|
};
|
|
170
170
|
declare const runInitInDirectory: ({ cwd, options, skipSdkInstall, }: RunInitInDirectoryOptions) => Promise<void>;
|
|
171
171
|
|
|
172
|
+
type DistTags = Record<string, string | undefined>;
|
|
173
|
+
type FetchDistTags = (name: string) => Promise<DistTags>;
|
|
174
|
+
type OutdatedPackage = {
|
|
175
|
+
name: string;
|
|
176
|
+
installed: string;
|
|
177
|
+
wanted: string;
|
|
178
|
+
tag: 'latest' | 'preview';
|
|
179
|
+
};
|
|
180
|
+
/** `@solvapay/*` names in dependencies and devDependencies, or `null` without a package.json. */
|
|
181
|
+
declare const solvapayDependencies: (cwd: string) => Promise<string[] | null>;
|
|
182
|
+
/** -1, 0 or 1 for two plain `x.y.z` versions. */
|
|
183
|
+
declare const compareStable: (a: string, b: string) => number;
|
|
184
|
+
/** Each declared `@solvapay/*` package whose installed version is behind npm. */
|
|
185
|
+
declare const findOutdatedSolvapayPackages: (cwd: string, names: string[], distTags?: FetchDistTags) => Promise<OutdatedPackage[]>;
|
|
186
|
+
/** The install command that pins each package exactly, for the project's package manager. */
|
|
187
|
+
declare const upgradeCommand: (packageManager: PackageManager, outdated: OutdatedPackage[]) => string;
|
|
188
|
+
|
|
172
189
|
type DoctorCommandOptions = {
|
|
173
190
|
/** Target api-dev.solvapay.com (same as `solvapay init --dev`). */
|
|
174
191
|
dev?: boolean;
|
|
@@ -176,6 +193,8 @@ type DoctorCommandOptions = {
|
|
|
176
193
|
type RunDoctorInDirectoryOptions = {
|
|
177
194
|
cwd: string;
|
|
178
195
|
options?: DoctorCommandOptions;
|
|
196
|
+
/** npm dist-tag lookup, injectable for tests. */
|
|
197
|
+
distTags?: FetchDistTags;
|
|
179
198
|
};
|
|
180
199
|
type DoctorCheckResult = {
|
|
181
200
|
name: string;
|
|
@@ -187,11 +206,6 @@ type DoctorReport = {
|
|
|
187
206
|
checks: DoctorCheckResult[];
|
|
188
207
|
apiBaseUrl: string;
|
|
189
208
|
};
|
|
190
|
-
|
|
191
|
-
* Diagnose SolvaPay credentials + product readiness for the current project.
|
|
192
|
-
* Exits non-zero (via `report.ok === false`) when any hard check fails so it
|
|
193
|
-
* can gate CI / pre-deploy.
|
|
194
|
-
*/
|
|
195
|
-
declare const runDoctorInDirectory: ({ cwd, options, }: RunDoctorInDirectoryOptions) => Promise<DoctorReport>;
|
|
209
|
+
declare const runDoctorInDirectory: ({ cwd, options, distTags, }: RunDoctorInDirectoryOptions) => Promise<DoctorReport>;
|
|
196
210
|
|
|
197
|
-
export { type DoctorCheckResult, type DoctorCommandOptions, type DoctorReport, type EnsureNodeProjectResult, type EnvWriteResult, type ExchangeResponse, type GitignoreEnvResult, type InitCommandOptions, type InitSessionResponse, type InstallResult, type ListProductsResult, type PackageManager, type PickResult, type ProductSummary, type RunDoctorInDirectoryOptions, type RunInitInDirectoryOptions, SOLVAPAY_PRODUCT_REF_PLACEHOLDER, type VerifiedProductSummary, type VerifyProductRefResult, askKeepConfiguredProduct, createInitSession, detectPackageManager, ensureEnvInGitignore, ensureNodeProject, formatConfiguredProductLabel, getInstallCommand, getSolvaPayBasePackages, installSolvaPaySdk, listProducts, openAuthUrl, pickProductInteractive, readSolvaPayApiBaseUrlFromEnv, readSolvaPayProductRefFromEnv, readSolvaPaySecretKeyFromEnv, runDoctorInDirectory, runInitInDirectory, verifyProductRef, verifySecretKey, waitForEnter, waitForExchange, writeSolvaPayApiBaseUrlToEnv, writeSolvaPayProductRefToEnv, writeSolvaPaySecretToEnv };
|
|
211
|
+
export { type DistTags, type DoctorCheckResult, type DoctorCommandOptions, type DoctorReport, type EnsureNodeProjectResult, type EnvWriteResult, type ExchangeResponse, type FetchDistTags, type GitignoreEnvResult, type InitCommandOptions, type InitSessionResponse, type InstallResult, type ListProductsResult, type OutdatedPackage, type PackageManager, type PickResult, type ProductSummary, type RunDoctorInDirectoryOptions, type RunInitInDirectoryOptions, SOLVAPAY_PRODUCT_REF_PLACEHOLDER, type VerifiedProductSummary, type VerifyProductRefResult, askKeepConfiguredProduct, compareStable, createInitSession, detectPackageManager, ensureEnvInGitignore, ensureNodeProject, findOutdatedSolvapayPackages, formatConfiguredProductLabel, getInstallCommand, getSolvaPayBasePackages, installSolvaPaySdk, listProducts, openAuthUrl, pickProductInteractive, readSolvaPayApiBaseUrlFromEnv, readSolvaPayProductRefFromEnv, readSolvaPaySecretKeyFromEnv, runDoctorInDirectory, runInitInDirectory, solvapayDependencies, upgradeCommand, verifyProductRef, verifySecretKey, waitForEnter, waitForExchange, writeSolvaPayApiBaseUrlToEnv, writeSolvaPayProductRefToEnv, writeSolvaPaySecretToEnv };
|
package/dist/index.d.ts
CHANGED
|
@@ -169,6 +169,23 @@ type RunInitInDirectoryOptions = {
|
|
|
169
169
|
};
|
|
170
170
|
declare const runInitInDirectory: ({ cwd, options, skipSdkInstall, }: RunInitInDirectoryOptions) => Promise<void>;
|
|
171
171
|
|
|
172
|
+
type DistTags = Record<string, string | undefined>;
|
|
173
|
+
type FetchDistTags = (name: string) => Promise<DistTags>;
|
|
174
|
+
type OutdatedPackage = {
|
|
175
|
+
name: string;
|
|
176
|
+
installed: string;
|
|
177
|
+
wanted: string;
|
|
178
|
+
tag: 'latest' | 'preview';
|
|
179
|
+
};
|
|
180
|
+
/** `@solvapay/*` names in dependencies and devDependencies, or `null` without a package.json. */
|
|
181
|
+
declare const solvapayDependencies: (cwd: string) => Promise<string[] | null>;
|
|
182
|
+
/** -1, 0 or 1 for two plain `x.y.z` versions. */
|
|
183
|
+
declare const compareStable: (a: string, b: string) => number;
|
|
184
|
+
/** Each declared `@solvapay/*` package whose installed version is behind npm. */
|
|
185
|
+
declare const findOutdatedSolvapayPackages: (cwd: string, names: string[], distTags?: FetchDistTags) => Promise<OutdatedPackage[]>;
|
|
186
|
+
/** The install command that pins each package exactly, for the project's package manager. */
|
|
187
|
+
declare const upgradeCommand: (packageManager: PackageManager, outdated: OutdatedPackage[]) => string;
|
|
188
|
+
|
|
172
189
|
type DoctorCommandOptions = {
|
|
173
190
|
/** Target api-dev.solvapay.com (same as `solvapay init --dev`). */
|
|
174
191
|
dev?: boolean;
|
|
@@ -176,6 +193,8 @@ type DoctorCommandOptions = {
|
|
|
176
193
|
type RunDoctorInDirectoryOptions = {
|
|
177
194
|
cwd: string;
|
|
178
195
|
options?: DoctorCommandOptions;
|
|
196
|
+
/** npm dist-tag lookup, injectable for tests. */
|
|
197
|
+
distTags?: FetchDistTags;
|
|
179
198
|
};
|
|
180
199
|
type DoctorCheckResult = {
|
|
181
200
|
name: string;
|
|
@@ -187,11 +206,6 @@ type DoctorReport = {
|
|
|
187
206
|
checks: DoctorCheckResult[];
|
|
188
207
|
apiBaseUrl: string;
|
|
189
208
|
};
|
|
190
|
-
|
|
191
|
-
* Diagnose SolvaPay credentials + product readiness for the current project.
|
|
192
|
-
* Exits non-zero (via `report.ok === false`) when any hard check fails so it
|
|
193
|
-
* can gate CI / pre-deploy.
|
|
194
|
-
*/
|
|
195
|
-
declare const runDoctorInDirectory: ({ cwd, options, }: RunDoctorInDirectoryOptions) => Promise<DoctorReport>;
|
|
209
|
+
declare const runDoctorInDirectory: ({ cwd, options, distTags, }: RunDoctorInDirectoryOptions) => Promise<DoctorReport>;
|
|
196
210
|
|
|
197
|
-
export { type DoctorCheckResult, type DoctorCommandOptions, type DoctorReport, type EnsureNodeProjectResult, type EnvWriteResult, type ExchangeResponse, type GitignoreEnvResult, type InitCommandOptions, type InitSessionResponse, type InstallResult, type ListProductsResult, type PackageManager, type PickResult, type ProductSummary, type RunDoctorInDirectoryOptions, type RunInitInDirectoryOptions, SOLVAPAY_PRODUCT_REF_PLACEHOLDER, type VerifiedProductSummary, type VerifyProductRefResult, askKeepConfiguredProduct, createInitSession, detectPackageManager, ensureEnvInGitignore, ensureNodeProject, formatConfiguredProductLabel, getInstallCommand, getSolvaPayBasePackages, installSolvaPaySdk, listProducts, openAuthUrl, pickProductInteractive, readSolvaPayApiBaseUrlFromEnv, readSolvaPayProductRefFromEnv, readSolvaPaySecretKeyFromEnv, runDoctorInDirectory, runInitInDirectory, verifyProductRef, verifySecretKey, waitForEnter, waitForExchange, writeSolvaPayApiBaseUrlToEnv, writeSolvaPayProductRefToEnv, writeSolvaPaySecretToEnv };
|
|
211
|
+
export { type DistTags, type DoctorCheckResult, type DoctorCommandOptions, type DoctorReport, type EnsureNodeProjectResult, type EnvWriteResult, type ExchangeResponse, type FetchDistTags, type GitignoreEnvResult, type InitCommandOptions, type InitSessionResponse, type InstallResult, type ListProductsResult, type OutdatedPackage, type PackageManager, type PickResult, type ProductSummary, type RunDoctorInDirectoryOptions, type RunInitInDirectoryOptions, SOLVAPAY_PRODUCT_REF_PLACEHOLDER, type VerifiedProductSummary, type VerifyProductRefResult, askKeepConfiguredProduct, compareStable, createInitSession, detectPackageManager, ensureEnvInGitignore, ensureNodeProject, findOutdatedSolvapayPackages, formatConfiguredProductLabel, getInstallCommand, getSolvaPayBasePackages, installSolvaPaySdk, listProducts, openAuthUrl, pickProductInteractive, readSolvaPayApiBaseUrlFromEnv, readSolvaPayProductRefFromEnv, readSolvaPaySecretKeyFromEnv, runDoctorInDirectory, runInitInDirectory, solvapayDependencies, upgradeCommand, verifyProductRef, verifySecretKey, waitForEnter, waitForExchange, writeSolvaPayApiBaseUrlToEnv, writeSolvaPayProductRefToEnv, writeSolvaPaySecretToEnv };
|
package/dist/index.js
CHANGED
|
@@ -1108,6 +1108,83 @@ import {
|
|
|
1108
1108
|
evaluateProductReadiness,
|
|
1109
1109
|
SOLVAPAY_PRODUCT_REF_PLACEHOLDER as SOLVAPAY_PRODUCT_REF_PLACEHOLDER3
|
|
1110
1110
|
} from "@solvapay/core";
|
|
1111
|
+
|
|
1112
|
+
// src/sdk-versions.ts
|
|
1113
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1114
|
+
import path3 from "path";
|
|
1115
|
+
var REGISTRY = "https://registry.npmjs.org";
|
|
1116
|
+
var readJson = async (file) => {
|
|
1117
|
+
try {
|
|
1118
|
+
return JSON.parse(await readFile3(file, "utf8"));
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
if (error.code === "ENOENT") return null;
|
|
1121
|
+
throw error;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
var solvapayDependencies = async (cwd) => {
|
|
1125
|
+
const pkg = await readJson(path3.join(cwd, "package.json"));
|
|
1126
|
+
if (!pkg) return null;
|
|
1127
|
+
const names = /* @__PURE__ */ new Set([
|
|
1128
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
1129
|
+
...Object.keys(pkg.devDependencies ?? {})
|
|
1130
|
+
]);
|
|
1131
|
+
return [...names].filter((name) => name.startsWith("@solvapay/")).sort();
|
|
1132
|
+
};
|
|
1133
|
+
var fetchDistTags = async (name) => {
|
|
1134
|
+
const url = `${REGISTRY}/-/package/${name}/dist-tags`;
|
|
1135
|
+
let response;
|
|
1136
|
+
try {
|
|
1137
|
+
response = await fetch(url, {
|
|
1138
|
+
headers: { accept: "application/json" },
|
|
1139
|
+
signal: AbortSignal.timeout(1e4)
|
|
1140
|
+
});
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
throw new Error(
|
|
1143
|
+
`Could not reach ${url}: ${error instanceof Error ? error.message : String(error)}`
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
if (!response.ok) throw new Error(`${url} answered ${response.status}`);
|
|
1147
|
+
return await response.json();
|
|
1148
|
+
};
|
|
1149
|
+
var isPreview = (version) => version.includes("-");
|
|
1150
|
+
var compareStable = (a, b) => {
|
|
1151
|
+
const pa = a.split(".").map(Number);
|
|
1152
|
+
const pb = b.split(".").map(Number);
|
|
1153
|
+
for (let i = 0; i < 3; i++) {
|
|
1154
|
+
const x = pa[i] ?? 0;
|
|
1155
|
+
const y = pb[i] ?? 0;
|
|
1156
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
1157
|
+
}
|
|
1158
|
+
return 0;
|
|
1159
|
+
};
|
|
1160
|
+
var findOutdatedSolvapayPackages = async (cwd, names, distTags = fetchDistTags) => {
|
|
1161
|
+
const outdated = [];
|
|
1162
|
+
for (const name of names) {
|
|
1163
|
+
const installedPkg = await readJson(
|
|
1164
|
+
path3.join(cwd, "node_modules", ...name.split("/"), "package.json")
|
|
1165
|
+
);
|
|
1166
|
+
if (!installedPkg || typeof installedPkg.version !== "string") {
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
`${name} is in package.json but not installed. Run your package manager's install first.`
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
const installed = installedPkg.version;
|
|
1172
|
+
const tag = isPreview(installed) ? "preview" : "latest";
|
|
1173
|
+
const wanted = (await distTags(name))[tag];
|
|
1174
|
+
if (typeof wanted !== "string") throw new Error(`npm has no '${tag}' tag for ${name}`);
|
|
1175
|
+
const behind = isPreview(installed) ? installed !== wanted : compareStable(installed, wanted) < 0;
|
|
1176
|
+
if (behind) outdated.push({ name, installed, wanted, tag });
|
|
1177
|
+
}
|
|
1178
|
+
return outdated;
|
|
1179
|
+
};
|
|
1180
|
+
var upgradeCommand = (packageManager, outdated) => {
|
|
1181
|
+
const specs = outdated.map((o) => `${o.name}@${o.wanted}`).join(" ");
|
|
1182
|
+
if (packageManager === "pnpm") return `pnpm add --save-exact ${specs}`;
|
|
1183
|
+
if (packageManager === "yarn") return `yarn add --exact ${specs}`;
|
|
1184
|
+
return `npm install --save-exact ${specs}`;
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
// src/run-doctor.ts
|
|
1111
1188
|
var DEFAULT_API_BASE_URL2 = "https://api.solvapay.com";
|
|
1112
1189
|
var DEV_API_BASE_URL2 = "https://api-dev.solvapay.com";
|
|
1113
1190
|
var preferEnv = (processValue, fileValue) => {
|
|
@@ -1130,9 +1207,25 @@ var printCheck = (check) => {
|
|
|
1130
1207
|
process.stdout.write(`${mark} ${check.name}: ${check.detail}
|
|
1131
1208
|
`);
|
|
1132
1209
|
};
|
|
1210
|
+
var checkSdkVersions = async (cwd, distTags) => {
|
|
1211
|
+
const name = "@solvapay/* versions";
|
|
1212
|
+
try {
|
|
1213
|
+
const names = await solvapayDependencies(cwd);
|
|
1214
|
+
if (names === null) return { name, ok: true, detail: `no package.json in ${cwd}, nothing to check` };
|
|
1215
|
+
if (names.length === 0) return { name, ok: true, detail: "no @solvapay/* dependencies" };
|
|
1216
|
+
const outdated = await findOutdatedSolvapayPackages(cwd, names, distTags);
|
|
1217
|
+
if (outdated.length === 0) return { name, ok: true, detail: `${names.length} package(s) match npm` };
|
|
1218
|
+
const behind = outdated.map((o) => `${o.name} ${o.installed} (npm ${o.tag} ${o.wanted})`).join(", ");
|
|
1219
|
+
const command = upgradeCommand(await detectPackageManager(cwd), outdated);
|
|
1220
|
+
return { name, ok: false, detail: `behind npm: ${behind}. Upgrade with: ${command}` };
|
|
1221
|
+
} catch (error) {
|
|
1222
|
+
return { name, ok: false, detail: error instanceof Error ? error.message : String(error) };
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1133
1225
|
var runDoctorInDirectory = async ({
|
|
1134
1226
|
cwd,
|
|
1135
|
-
options = {}
|
|
1227
|
+
options = {},
|
|
1228
|
+
distTags = fetchDistTags
|
|
1136
1229
|
}) => {
|
|
1137
1230
|
const checks = [];
|
|
1138
1231
|
const apiBaseUrl = await resolveApiBaseUrl2(cwd, options);
|
|
@@ -1232,6 +1325,7 @@ SolvaPay doctor \u2014 ${apiBaseUrl}
|
|
|
1232
1325
|
});
|
|
1233
1326
|
}
|
|
1234
1327
|
}
|
|
1328
|
+
checks.push(await checkSdkVersions(cwd, distTags));
|
|
1235
1329
|
const debugRaw = process.env.SOLVAPAY_DEBUG;
|
|
1236
1330
|
checks.push({
|
|
1237
1331
|
name: "SOLVAPAY_DEBUG defaults",
|
|
@@ -1254,10 +1348,12 @@ ${chalk2.red("Doctor found problems. Fix the \u2717 items above, then re-run.")}
|
|
|
1254
1348
|
export {
|
|
1255
1349
|
SOLVAPAY_PRODUCT_REF_PLACEHOLDER2 as SOLVAPAY_PRODUCT_REF_PLACEHOLDER,
|
|
1256
1350
|
askKeepConfiguredProduct,
|
|
1351
|
+
compareStable,
|
|
1257
1352
|
createInitSession,
|
|
1258
1353
|
detectPackageManager,
|
|
1259
1354
|
ensureEnvInGitignore,
|
|
1260
1355
|
ensureNodeProject,
|
|
1356
|
+
findOutdatedSolvapayPackages,
|
|
1261
1357
|
formatConfiguredProductLabel,
|
|
1262
1358
|
getInstallCommand,
|
|
1263
1359
|
getSolvaPayBasePackages,
|
|
@@ -1270,6 +1366,8 @@ export {
|
|
|
1270
1366
|
readSolvaPaySecretKeyFromEnv,
|
|
1271
1367
|
runDoctorInDirectory,
|
|
1272
1368
|
runInitInDirectory,
|
|
1369
|
+
solvapayDependencies,
|
|
1370
|
+
upgradeCommand,
|
|
1273
1371
|
verifyProductRef,
|
|
1274
1372
|
verifySecretKey,
|
|
1275
1373
|
waitForEnter,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solvapay/init",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-preview-7c1def75e5173f539a8bb4ea312cdeb445ae654c",
|
|
4
4
|
"description": "Shared primitives for SolvaPay CLI tooling (browser auth, env writers, product picker, install runner). Consumed by `solvapay` and `create-solvapay`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|