@patchstack/connect 0.5.11 → 0.5.12
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/AGENT-INSTALL.md +31 -4
- package/README.md +2 -2
- package/dist/cli.js +136 -173
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/protect.cjs +3 -2
- package/dist/protect.cjs.map +1 -1
- package/dist/protect.js +1 -1
- package/dist/{refresh-manifest-PPV22Q2E.js → refresh-manifest-47HJRCDX.js} +3 -2
- package/dist/refresh-manifest-47HJRCDX.js.map +1 -0
- package/package.json +1 -1
- package/dist/refresh-manifest-PPV22Q2E.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { readFileSync as readFileSync19 } from "fs";
|
|
5
|
-
import
|
|
5
|
+
import path16 from "path";
|
|
6
6
|
import { createRequire as createRequire2 } from "module";
|
|
7
7
|
|
|
8
8
|
// src/safe-file.ts
|
|
@@ -25,9 +25,9 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
|
25
25
|
function pathError(message) {
|
|
26
26
|
return Object.assign(new Error(message), { code: "EINVAL" });
|
|
27
27
|
}
|
|
28
|
-
function existingEntry(
|
|
28
|
+
function existingEntry(path17) {
|
|
29
29
|
try {
|
|
30
|
-
return lstatSync(
|
|
30
|
+
return lstatSync(path17);
|
|
31
31
|
} catch (error) {
|
|
32
32
|
if (error.code === "ENOENT") return null;
|
|
33
33
|
throw error;
|
|
@@ -1488,8 +1488,8 @@ async function readBoundedJson(response, maxBytes = MAX_CONTROL_RESPONSE_BYTES)
|
|
|
1488
1488
|
var TOKEN_SKEW_MS = 6e4;
|
|
1489
1489
|
function buildTokenUrl(manifestEndpoint) {
|
|
1490
1490
|
const url = new URL(manifestEndpoint);
|
|
1491
|
-
const
|
|
1492
|
-
url.pathname =
|
|
1491
|
+
const path17 = url.pathname.replace(/\/$/, "");
|
|
1492
|
+
url.pathname = path17.endsWith("/manifest") ? `${path17.slice(0, -"/manifest".length)}/token` : "/monitor/pulse/token";
|
|
1493
1493
|
url.search = "";
|
|
1494
1494
|
url.hash = "";
|
|
1495
1495
|
return url.toString();
|
|
@@ -1657,8 +1657,8 @@ function authFailureMessage(status, config) {
|
|
|
1657
1657
|
}
|
|
1658
1658
|
function buildRulesUrl(manifestEndpoint, siteUuid) {
|
|
1659
1659
|
const url = new URL(manifestEndpoint);
|
|
1660
|
-
const
|
|
1661
|
-
url.pathname =
|
|
1660
|
+
const path17 = url.pathname.replace(/\/$/, "");
|
|
1661
|
+
url.pathname = path17.endsWith("/manifest") ? `${path17.slice(0, -"/manifest".length)}/rules/${encodeURIComponent(siteUuid)}` : `/monitor/pulse/rules/${encodeURIComponent(siteUuid)}`;
|
|
1662
1662
|
url.search = "";
|
|
1663
1663
|
url.hash = "";
|
|
1664
1664
|
return url.toString();
|
|
@@ -1673,16 +1673,16 @@ function buildSettingsUrl(endpoint, siteUuid) {
|
|
|
1673
1673
|
}
|
|
1674
1674
|
function buildPackageRemovedUrl(manifestEndpoint, siteUuid) {
|
|
1675
1675
|
const url = new URL(manifestEndpoint);
|
|
1676
|
-
const
|
|
1677
|
-
url.pathname =
|
|
1676
|
+
const path17 = url.pathname.replace(/\/$/, "");
|
|
1677
|
+
url.pathname = path17.endsWith("/manifest") ? `${path17.slice(0, -"/manifest".length)}/package-removed/${encodeURIComponent(siteUuid)}` : `/monitor/pulse/package-removed/${encodeURIComponent(siteUuid)}`;
|
|
1678
1678
|
url.search = "";
|
|
1679
1679
|
url.hash = "";
|
|
1680
1680
|
return url.toString();
|
|
1681
1681
|
}
|
|
1682
1682
|
function buildInputMapUrl(manifestEndpoint, siteUuid) {
|
|
1683
1683
|
const url = new URL(manifestEndpoint);
|
|
1684
|
-
const
|
|
1685
|
-
url.pathname =
|
|
1684
|
+
const path17 = url.pathname.replace(/\/$/, "");
|
|
1685
|
+
url.pathname = path17.endsWith("/manifest") ? `${path17.slice(0, -"/manifest".length)}/input-map/${encodeURIComponent(siteUuid)}` : `/monitor/pulse/input-map/${encodeURIComponent(siteUuid)}`;
|
|
1686
1686
|
url.search = "";
|
|
1687
1687
|
url.hash = "";
|
|
1688
1688
|
return url.toString();
|
|
@@ -2336,6 +2336,7 @@ function isUnpublishableHost(hostname) {
|
|
|
2336
2336
|
if (!host.includes(".")) return true;
|
|
2337
2337
|
return RESERVED_SUFFIXES.some((suffix) => host.endsWith(suffix));
|
|
2338
2338
|
}
|
|
2339
|
+
var URL_MAX_LENGTH = 191;
|
|
2339
2340
|
function normaliseSiteUrl(value) {
|
|
2340
2341
|
const trimmed = (value ?? "").trim();
|
|
2341
2342
|
if (trimmed === "") return null;
|
|
@@ -2349,7 +2350,7 @@ function normaliseSiteUrl(value) {
|
|
|
2349
2350
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
|
|
2350
2351
|
if (parsed.hostname === "" || isUnpublishableHost(parsed.hostname)) return null;
|
|
2351
2352
|
const origin = `${parsed.protocol}//${parsed.host}`;
|
|
2352
|
-
return origin.length <=
|
|
2353
|
+
return origin.length <= URL_MAX_LENGTH ? origin : null;
|
|
2353
2354
|
}
|
|
2354
2355
|
var PRODUCTION_URL_SOURCES = [
|
|
2355
2356
|
{
|
|
@@ -2678,10 +2679,10 @@ async function persistTimeout(cwd, timeoutMs) {
|
|
|
2678
2679
|
return writeConfigFile(cwd, { ...existing, timeoutMs });
|
|
2679
2680
|
}
|
|
2680
2681
|
async function persistApiKey(cwd, apiKey) {
|
|
2681
|
-
const { apiKey:
|
|
2682
|
+
const { apiKey: movedKey, pulseAuth: movedPulse, ...publicConfig } = await readConfigFile(cwd);
|
|
2682
2683
|
const existingSecrets = await readSecretFile(cwd);
|
|
2683
2684
|
const target = await writeSecretFile(cwd, { ...existingSecrets, apiKey, pulseAuth: void 0 });
|
|
2684
|
-
if (
|
|
2685
|
+
if (movedKey !== void 0 || movedPulse !== void 0) {
|
|
2685
2686
|
await writeConfigFile(cwd, publicConfig);
|
|
2686
2687
|
}
|
|
2687
2688
|
return target;
|
|
@@ -3460,10 +3461,10 @@ function detectDeploymentShapes(cwd, opts = {}) {
|
|
|
3460
3461
|
boundary = realpathSync3(boundary);
|
|
3461
3462
|
} catch {
|
|
3462
3463
|
}
|
|
3463
|
-
const inProject = (
|
|
3464
|
+
const inProject = (path17) => {
|
|
3464
3465
|
if (opts.followOutside) return true;
|
|
3465
3466
|
try {
|
|
3466
|
-
return isInside(realpathSync3(
|
|
3467
|
+
return isInside(realpathSync3(path17), boundary);
|
|
3467
3468
|
} catch {
|
|
3468
3469
|
return false;
|
|
3469
3470
|
}
|
|
@@ -4100,14 +4101,6 @@ var tanstackSupabaseAdapter = {
|
|
|
4100
4101
|
// src/protect/install/adapters/next.ts
|
|
4101
4102
|
import { existsSync as existsSync5 } from "fs";
|
|
4102
4103
|
import { join as join7 } from "path";
|
|
4103
|
-
function hasNextDep(cwd) {
|
|
4104
|
-
try {
|
|
4105
|
-
const pkg = JSON.parse(read(join7(cwd, "package.json")));
|
|
4106
|
-
return Boolean({ ...pkg.dependencies, ...pkg.devDependencies }.next);
|
|
4107
|
-
} catch {
|
|
4108
|
-
return false;
|
|
4109
|
-
}
|
|
4110
|
-
}
|
|
4111
4104
|
function middlewareInfo(cwd) {
|
|
4112
4105
|
const candidates = ["middleware.ts", "middleware.js", "src/middleware.ts", "src/middleware.js"];
|
|
4113
4106
|
for (const rel of candidates) {
|
|
@@ -4117,7 +4110,7 @@ function middlewareInfo(cwd) {
|
|
|
4117
4110
|
return { relDir: useSrc ? "src" : ".", relFile: useSrc ? "src/middleware.ts" : "middleware.ts", exists: false };
|
|
4118
4111
|
}
|
|
4119
4112
|
function detect2(cwd) {
|
|
4120
|
-
return
|
|
4113
|
+
return hasDependency(cwd, "next");
|
|
4121
4114
|
}
|
|
4122
4115
|
function rulesFile(relDir) {
|
|
4123
4116
|
return relDir === "." ? "patchstack.rules.json" : `${relDir}/patchstack.rules.json`;
|
|
@@ -4171,9 +4164,6 @@ var nextAdapter = {
|
|
|
4171
4164
|
verify: verify2
|
|
4172
4165
|
};
|
|
4173
4166
|
|
|
4174
|
-
// src/protect/install/adapters/sveltekit.ts
|
|
4175
|
-
import { join as join9 } from "path";
|
|
4176
|
-
|
|
4177
4167
|
// src/protect/install/seam.ts
|
|
4178
4168
|
import { existsSync as existsSync6 } from "fs";
|
|
4179
4169
|
import { join as join8, dirname as dirname3 } from "path";
|
|
@@ -4231,12 +4221,7 @@ var SPEC = {
|
|
|
4231
4221
|
seamLabel: "SvelteKit server hook"
|
|
4232
4222
|
};
|
|
4233
4223
|
function detect3(cwd) {
|
|
4234
|
-
|
|
4235
|
-
const pkg = JSON.parse(read(join9(cwd, "package.json")));
|
|
4236
|
-
return Boolean({ ...pkg.dependencies, ...pkg.devDependencies }["@sveltejs/kit"]);
|
|
4237
|
-
} catch {
|
|
4238
|
-
return false;
|
|
4239
|
-
}
|
|
4224
|
+
return hasDependency(cwd, "@sveltejs/kit");
|
|
4240
4225
|
}
|
|
4241
4226
|
function wire3(cwd, opts) {
|
|
4242
4227
|
return wireSeam(cwd, opts, SPEC);
|
|
@@ -4253,7 +4238,6 @@ var sveltekitAdapter = {
|
|
|
4253
4238
|
};
|
|
4254
4239
|
|
|
4255
4240
|
// src/protect/install/adapters/astro.ts
|
|
4256
|
-
import { join as join10 } from "path";
|
|
4257
4241
|
var SPEC2 = {
|
|
4258
4242
|
templateName: "astro-middleware.ts",
|
|
4259
4243
|
candidates: ["src/middleware.ts", "src/middleware.js", "src/middleware/index.ts", "src/middleware/index.js"],
|
|
@@ -4263,12 +4247,7 @@ var SPEC2 = {
|
|
|
4263
4247
|
seamLabel: "Astro middleware"
|
|
4264
4248
|
};
|
|
4265
4249
|
function detect4(cwd) {
|
|
4266
|
-
|
|
4267
|
-
const pkg = JSON.parse(read(join10(cwd, "package.json")));
|
|
4268
|
-
return Boolean({ ...pkg.dependencies, ...pkg.devDependencies }.astro);
|
|
4269
|
-
} catch {
|
|
4270
|
-
return false;
|
|
4271
|
-
}
|
|
4250
|
+
return hasDependency(cwd, "astro");
|
|
4272
4251
|
}
|
|
4273
4252
|
function wire4(cwd, opts) {
|
|
4274
4253
|
return wireSeam(cwd, opts, SPEC2);
|
|
@@ -4312,7 +4291,7 @@ var nuxtAdapter = {
|
|
|
4312
4291
|
|
|
4313
4292
|
// src/protect/install/find-app.ts
|
|
4314
4293
|
import { readFileSync as readFileSync8, readdirSync as readdirSync3, lstatSync as lstatSync2 } from "fs";
|
|
4315
|
-
import { join as
|
|
4294
|
+
import { join as join9, relative as relative3, dirname as dirname4 } from "path";
|
|
4316
4295
|
var SKIP_DIRS2 = /* @__PURE__ */ new Set([
|
|
4317
4296
|
"node_modules",
|
|
4318
4297
|
"patchstack",
|
|
@@ -4344,7 +4323,7 @@ function findAppInstance(cwd, re) {
|
|
|
4344
4323
|
}
|
|
4345
4324
|
for (const name of entries) {
|
|
4346
4325
|
if (SKIP_DIRS2.has(name) || name.startsWith(".")) continue;
|
|
4347
|
-
const p =
|
|
4326
|
+
const p = join9(dir, name);
|
|
4348
4327
|
let st;
|
|
4349
4328
|
try {
|
|
4350
4329
|
st = lstatSync2(p);
|
|
@@ -4403,7 +4382,7 @@ function declaredEntries(cwd) {
|
|
|
4403
4382
|
const paths = /* @__PURE__ */ new Set();
|
|
4404
4383
|
let pkg;
|
|
4405
4384
|
try {
|
|
4406
|
-
pkg = JSON.parse(readFileSync8(
|
|
4385
|
+
pkg = JSON.parse(readFileSync8(join9(cwd, "package.json"), "utf8"));
|
|
4407
4386
|
} catch {
|
|
4408
4387
|
return paths;
|
|
4409
4388
|
}
|
|
@@ -4430,16 +4409,16 @@ function importSpecifier(fromRel, toRel, preserveExtension = false) {
|
|
|
4430
4409
|
|
|
4431
4410
|
// src/protect/install/register.ts
|
|
4432
4411
|
import { existsSync as existsSync9 } from "fs";
|
|
4433
|
-
import { join as
|
|
4412
|
+
import { join as join12, resolve as resolve3 } from "path";
|
|
4434
4413
|
|
|
4435
4414
|
// src/protect/install/generic.ts
|
|
4436
4415
|
import { readFileSync as readFileSync9, existsSync as existsSync8, readdirSync as readdirSync4, lstatSync as lstatSync3 } from "fs";
|
|
4437
|
-
import { join as
|
|
4416
|
+
import { join as join11, dirname as dirname6 } from "path";
|
|
4438
4417
|
|
|
4439
4418
|
// src/protect/install/source-scope.ts
|
|
4440
4419
|
import { execFileSync } from "child_process";
|
|
4441
4420
|
import { existsSync as existsSync7 } from "fs";
|
|
4442
|
-
import { dirname as dirname5, join as
|
|
4421
|
+
import { dirname as dirname5, join as join10, resolve as resolve2 } from "path";
|
|
4443
4422
|
|
|
4444
4423
|
// src/protect/install/node-flags.ts
|
|
4445
4424
|
var flagName = (token) => token.split("=")[0];
|
|
@@ -4729,8 +4708,8 @@ function moduleKindOf(filePath, packageIsModule) {
|
|
|
4729
4708
|
}
|
|
4730
4709
|
function resolvesToGuardModule(specifier, query) {
|
|
4731
4710
|
const resolved = resolve2(dirname5(query.fromFile), specifier);
|
|
4732
|
-
if (withoutModuleExtension(resolved) !==
|
|
4733
|
-
const existing = GUARD_FILENAMES.filter((name) => existsSync7(
|
|
4711
|
+
if (withoutModuleExtension(resolved) !== join10(query.guardDir, "guard")) return false;
|
|
4712
|
+
const existing = GUARD_FILENAMES.filter((name) => existsSync7(join10(query.guardDir, name)));
|
|
4734
4713
|
if (existing.length === 0) return false;
|
|
4735
4714
|
const extension = /(\.[A-Za-z0-9]+)$/.exec(specifier)?.[1] ?? "";
|
|
4736
4715
|
if (!query.strictExtensions) return true;
|
|
@@ -4749,16 +4728,16 @@ function withoutModuleExtension(filePath) {
|
|
|
4749
4728
|
// src/protect/install/generic.ts
|
|
4750
4729
|
function packageIsEsm(cwd) {
|
|
4751
4730
|
try {
|
|
4752
|
-
return JSON.parse(read(
|
|
4731
|
+
return JSON.parse(read(join11(cwd, "package.json"))).type === "module";
|
|
4753
4732
|
} catch {
|
|
4754
4733
|
return false;
|
|
4755
4734
|
}
|
|
4756
4735
|
}
|
|
4757
4736
|
function genericDir(cwd) {
|
|
4758
|
-
return existsSync8(
|
|
4737
|
+
return existsSync8(join11(cwd, "src")) ? "src/patchstack" : "patchstack";
|
|
4759
4738
|
}
|
|
4760
4739
|
function hasTypeScript(cwd) {
|
|
4761
|
-
return existsSync8(
|
|
4740
|
+
return existsSync8(join11(cwd, "tsconfig.json")) || candidateEntries(cwd).some((entry) => /\.tsx?$/.test(entry));
|
|
4762
4741
|
}
|
|
4763
4742
|
function genericGuardTarget(cwd) {
|
|
4764
4743
|
if (hasTypeScript(cwd)) {
|
|
@@ -4772,7 +4751,7 @@ function genericGuardTarget(cwd) {
|
|
|
4772
4751
|
function genericScaffoldFiles(cwd) {
|
|
4773
4752
|
const dir = genericDir(cwd);
|
|
4774
4753
|
const candidates = ["guard.ts", "guard.js", "guard.cjs", "rules.json"];
|
|
4775
|
-
return candidates.map((file) => `${dir}/${file}`).filter((relative8) => existsSync8(
|
|
4754
|
+
return candidates.map((file) => `${dir}/${file}`).filter((relative8) => existsSync8(join11(cwd, relative8)));
|
|
4776
4755
|
}
|
|
4777
4756
|
function scaffoldGeneric(cwd, opts, guardTemplate, guardFile) {
|
|
4778
4757
|
const target = genericGuardTarget(cwd);
|
|
@@ -4780,15 +4759,15 @@ function scaffoldGeneric(cwd, opts, guardTemplate, guardFile) {
|
|
|
4780
4759
|
guardFile ??= target.file;
|
|
4781
4760
|
const templates = templatesDir();
|
|
4782
4761
|
const dir = genericDir(cwd);
|
|
4783
|
-
const dst =
|
|
4762
|
+
const dst = join11(cwd, dir);
|
|
4784
4763
|
ensureProjectDirectorySync(cwd, dst);
|
|
4785
|
-
copyProjectFileSync(cwd,
|
|
4764
|
+
copyProjectFileSync(cwd, join11(templates, guardTemplate), join11(dst, guardFile));
|
|
4786
4765
|
const guardRel = `${dir}/${guardFile}`;
|
|
4787
4766
|
const changed = [guardRel];
|
|
4788
4767
|
if (!opts.demo) bakeSiteUuid(cwd, guardRel);
|
|
4789
|
-
const rulesDst =
|
|
4768
|
+
const rulesDst = join11(dst, "rules.json");
|
|
4790
4769
|
if (opts.demo || !existsSync8(rulesDst)) {
|
|
4791
|
-
copyProjectFileSync(cwd,
|
|
4770
|
+
copyProjectFileSync(cwd, join11(templates, opts.demo ? "demo-rules.json" : "rules.json"), rulesDst);
|
|
4792
4771
|
changed.push(`${dir}/rules.json`);
|
|
4793
4772
|
}
|
|
4794
4773
|
return { changed, dir };
|
|
@@ -4809,25 +4788,17 @@ function candidateEntries(cwd) {
|
|
|
4809
4788
|
"app.ts",
|
|
4810
4789
|
"app.js"
|
|
4811
4790
|
];
|
|
4812
|
-
const hits = names.filter((n) => existsSync8(
|
|
4791
|
+
const hits = names.filter((n) => existsSync8(join11(cwd, n)));
|
|
4813
4792
|
try {
|
|
4814
|
-
const pkg = JSON.parse(read(
|
|
4815
|
-
if (typeof pkg.main === "string" && existsSync8(
|
|
4793
|
+
const pkg = JSON.parse(read(join11(cwd, "package.json")));
|
|
4794
|
+
if (typeof pkg.main === "string" && existsSync8(join11(cwd, pkg.main))) hits.push(pkg.main);
|
|
4816
4795
|
} catch {
|
|
4817
4796
|
}
|
|
4818
4797
|
return [...new Set(hits)];
|
|
4819
4798
|
}
|
|
4820
|
-
function usesExpress(cwd) {
|
|
4821
|
-
try {
|
|
4822
|
-
const pkg = JSON.parse(read(join13(cwd, "package.json")));
|
|
4823
|
-
return Boolean({ ...pkg.dependencies, ...pkg.devDependencies }.express);
|
|
4824
|
-
} catch {
|
|
4825
|
-
return false;
|
|
4826
|
-
}
|
|
4827
|
-
}
|
|
4828
4799
|
function wiringPlan(cwd, dir) {
|
|
4829
4800
|
const entries = candidateEntries(cwd);
|
|
4830
|
-
const express =
|
|
4801
|
+
const express = hasDependency(cwd, "express");
|
|
4831
4802
|
const target = genericGuardTarget(cwd);
|
|
4832
4803
|
const lines = [
|
|
4833
4804
|
`no built-in adapter matched this stack \u2014 scaffolded a generic guard at ${dir}/${target.file} + ${dir}/rules.json.`,
|
|
@@ -4923,9 +4894,9 @@ function escapeForRegExp(value) {
|
|
|
4923
4894
|
function genericVerify(cwd) {
|
|
4924
4895
|
const dir = genericDir(cwd);
|
|
4925
4896
|
const target = genericGuardTarget(cwd);
|
|
4926
|
-
const present2 = GUARD_FILENAMES.find((name) => existsSync8(
|
|
4897
|
+
const present2 = GUARD_FILENAMES.find((name) => existsSync8(join11(cwd, dir, name)));
|
|
4927
4898
|
const scaffolded = present2 !== void 0;
|
|
4928
|
-
const imported = scaffolded && guardIsImported(cwd,
|
|
4899
|
+
const imported = scaffolded && guardIsImported(cwd, join11(cwd, dir, present2));
|
|
4929
4900
|
return {
|
|
4930
4901
|
wired: scaffolded && imported,
|
|
4931
4902
|
checks: [
|
|
@@ -4961,7 +4932,7 @@ var NON_RUNTIME_DIRS = /* @__PURE__ */ new Set([
|
|
|
4961
4932
|
function guardIsImported(cwd, guardPath) {
|
|
4962
4933
|
const guardDir = dirname6(guardPath);
|
|
4963
4934
|
const packageIsModule = packageIsEsm(cwd);
|
|
4964
|
-
const root = existsSync8(
|
|
4935
|
+
const root = existsSync8(join11(cwd, "src")) ? join11(cwd, "src") : cwd;
|
|
4965
4936
|
let found = false;
|
|
4966
4937
|
const walk2 = (d, depth) => {
|
|
4967
4938
|
if (found || depth > 8) return;
|
|
@@ -4974,7 +4945,7 @@ function guardIsImported(cwd, guardPath) {
|
|
|
4974
4945
|
for (const name of entries) {
|
|
4975
4946
|
if (found) return;
|
|
4976
4947
|
if (NON_RUNTIME_DIRS.has(name) || name.startsWith(".")) continue;
|
|
4977
|
-
const p =
|
|
4948
|
+
const p = join11(d, name);
|
|
4978
4949
|
let st;
|
|
4979
4950
|
try {
|
|
4980
4951
|
st = lstatSync3(p);
|
|
@@ -5033,7 +5004,7 @@ function guardTarget(cwd, entryRel, spec) {
|
|
|
5033
5004
|
}
|
|
5034
5005
|
function packageType(cwd) {
|
|
5035
5006
|
try {
|
|
5036
|
-
return JSON.parse(read(
|
|
5007
|
+
return JSON.parse(read(join12(cwd, "package.json"))).type;
|
|
5037
5008
|
} catch {
|
|
5038
5009
|
return void 0;
|
|
5039
5010
|
}
|
|
@@ -5069,8 +5040,8 @@ function bindsGuard(line, maskedLine, importName, call, fileRel, guard) {
|
|
|
5069
5040
|
}
|
|
5070
5041
|
function namesGuardModule(specifier, fileRel, guard) {
|
|
5071
5042
|
return resolvesToGuardModule(specifier, {
|
|
5072
|
-
fromFile:
|
|
5073
|
-
guardDir: resolve3(
|
|
5043
|
+
fromFile: join12(guard.cwd, fileRel),
|
|
5044
|
+
guardDir: resolve3(join12(guard.cwd, guard.guardDir)),
|
|
5074
5045
|
kind: moduleKindOf(fileRel, packageType(guard.cwd) === "module"),
|
|
5075
5046
|
strictExtensions: true
|
|
5076
5047
|
});
|
|
@@ -5089,7 +5060,7 @@ function wireRegister(cwd, opts, spec) {
|
|
|
5089
5060
|
}
|
|
5090
5061
|
const target = guardTarget(cwd, entry.relPath, spec);
|
|
5091
5062
|
const { changed, dir } = scaffoldGeneric(cwd, opts, target.template, target.file);
|
|
5092
|
-
const p =
|
|
5063
|
+
const p = join12(cwd, entry.relPath);
|
|
5093
5064
|
const s = read(p);
|
|
5094
5065
|
const state = wiringState(s, spec, entry.appVar, entry.relPath, { cwd, guardDir: dir });
|
|
5095
5066
|
if (state.importAtTopLevel && state.callInAppScope) {
|
|
@@ -5159,17 +5130,17 @@ function firstStatementLine(lines) {
|
|
|
5159
5130
|
return i;
|
|
5160
5131
|
}
|
|
5161
5132
|
function serverIsGuarded(cwd, spec, server, guardDir) {
|
|
5162
|
-
const source = read(
|
|
5133
|
+
const source = read(join12(cwd, server.relPath));
|
|
5163
5134
|
const state = wiringState(source, spec, server.appVar, server.relPath, { cwd, guardDir });
|
|
5164
5135
|
if (!state.importAtTopLevel || !state.callInAppScope || !state.ordered) return false;
|
|
5165
5136
|
return !spec.callAfter || routesBefore(source, server.appVar, state.callIndex).length === 0;
|
|
5166
5137
|
}
|
|
5167
5138
|
function verifyRegister(cwd, spec) {
|
|
5168
|
-
const dir = existsSync9(
|
|
5139
|
+
const dir = existsSync9(join12(cwd, "src")) ? "src/patchstack" : "patchstack";
|
|
5169
5140
|
const entry = findAppInstance(cwd, spec.appRe);
|
|
5170
5141
|
const target = entry ? guardTarget(cwd, entry.relPath, spec) : null;
|
|
5171
|
-
const scaffolded = target ? existsSync9(
|
|
5172
|
-
const entrySource = entry ? read(
|
|
5142
|
+
const scaffolded = target ? existsSync9(join12(cwd, dir, target.file)) : false;
|
|
5143
|
+
const entrySource = entry ? read(join12(cwd, entry.relPath)) : "";
|
|
5173
5144
|
const state = entry ? wiringState(entrySource, spec, entry.appVar, entry.relPath, { cwd, guardDir: dir }) : { importAtTopLevel: false, callInAppScope: false, ordered: false, callIndex: -1, appIndex: -1 };
|
|
5174
5145
|
const wired = state.importAtTopLevel && state.callInAppScope && state.ordered;
|
|
5175
5146
|
const early = spec.callAfter && entry ? routesBefore(entrySource, entry.appVar, state.callIndex) : [];
|
|
@@ -5260,7 +5231,7 @@ var expressAdapter = {
|
|
|
5260
5231
|
|
|
5261
5232
|
// src/protect/install/reporting.ts
|
|
5262
5233
|
import { existsSync as existsSync10 } from "fs";
|
|
5263
|
-
import { join as
|
|
5234
|
+
import { join as join13 } from "path";
|
|
5264
5235
|
|
|
5265
5236
|
// src/protect/reporting-state.js
|
|
5266
5237
|
var REPORTING_STATES = Object.freeze([
|
|
@@ -5318,7 +5289,7 @@ function explainReportingState(state) {
|
|
|
5318
5289
|
|
|
5319
5290
|
// src/protect/install/reporting.ts
|
|
5320
5291
|
function siteIdentity(cwd, env) {
|
|
5321
|
-
const rc =
|
|
5292
|
+
const rc = join13(cwd, ".patchstackrc.json");
|
|
5322
5293
|
let recorded;
|
|
5323
5294
|
if (existsSync10(rc)) {
|
|
5324
5295
|
try {
|
|
@@ -5838,6 +5809,17 @@ function renderGuideChecklist(state, useColor) {
|
|
|
5838
5809
|
lines.push(" Avoid lockfile / dependency / manifest / npm / UUID when speaking to them.");
|
|
5839
5810
|
lines.push("");
|
|
5840
5811
|
}
|
|
5812
|
+
if (state.siteUuid === null) {
|
|
5813
|
+
lines.push(` ${paint(ANSI.cyan, "\u279C")} ${paint(ANSI.bold, "Nothing is set up yet \u2014 two commands cover the steps below:")}`);
|
|
5814
|
+
if (state.installed?.section !== "dependencies") {
|
|
5815
|
+
lines.push(` ${installCommand(state.packageManager)}`);
|
|
5816
|
+
}
|
|
5817
|
+
lines.push(" npx @patchstack/connect setup");
|
|
5818
|
+
lines.push(" setup provisions the site, adds the widget, installs and verifies runtime protection,");
|
|
5819
|
+
lines.push(" and wires the install and build scans, then prints this checklist again. Anything");
|
|
5820
|
+
lines.push(" still listed there is a step setup could not apply safely, and is yours to finish.");
|
|
5821
|
+
lines.push("");
|
|
5822
|
+
}
|
|
5841
5823
|
if (state.installed?.section === "dependencies") {
|
|
5842
5824
|
lines.push(done(`@patchstack/connect installed (${state.installed.version}, ${state.installed.section})`));
|
|
5843
5825
|
} else if (state.installed !== null) {
|
|
@@ -6004,11 +5986,6 @@ function renderGuideChecklist(state, useColor) {
|
|
|
6004
5986
|
return lines.join("\n");
|
|
6005
5987
|
}
|
|
6006
5988
|
|
|
6007
|
-
// src/login.ts
|
|
6008
|
-
import { mkdtempSync } from "fs";
|
|
6009
|
-
import { tmpdir as tmpdir2 } from "os";
|
|
6010
|
-
import path14 from "path";
|
|
6011
|
-
|
|
6012
5989
|
// src/device-flow.ts
|
|
6013
5990
|
import {
|
|
6014
5991
|
closeSync as closeSync2,
|
|
@@ -6309,7 +6286,7 @@ import { relative as relative4 } from "path";
|
|
|
6309
6286
|
|
|
6310
6287
|
// src/protect/install/runtime/entry.ts
|
|
6311
6288
|
import { existsSync as existsSync13, readFileSync as readFileSync13, realpathSync as realpathSync4, statSync as statSync6 } from "fs";
|
|
6312
|
-
import { join as
|
|
6289
|
+
import { join as join14, resolve as resolve4, sep as sep2 } from "path";
|
|
6313
6290
|
var CONVENTIONAL = [
|
|
6314
6291
|
"server.js",
|
|
6315
6292
|
"server.mjs",
|
|
@@ -6335,15 +6312,15 @@ var CONVENTIONAL = [
|
|
|
6335
6312
|
var LOADABLE = /\.(?:js|mjs|cjs)$/;
|
|
6336
6313
|
function readPackage2(cwd) {
|
|
6337
6314
|
try {
|
|
6338
|
-
const parsed = JSON.parse(readFileSync13(
|
|
6315
|
+
const parsed = JSON.parse(readFileSync13(join14(cwd, "package.json"), "utf8"));
|
|
6339
6316
|
return parsed !== null && typeof parsed === "object" ? parsed : null;
|
|
6340
6317
|
} catch {
|
|
6341
6318
|
return null;
|
|
6342
6319
|
}
|
|
6343
6320
|
}
|
|
6344
|
-
function isFile(
|
|
6321
|
+
function isFile(path17) {
|
|
6345
6322
|
try {
|
|
6346
|
-
return statSync6(
|
|
6323
|
+
return statSync6(path17).isFile();
|
|
6347
6324
|
} catch {
|
|
6348
6325
|
return false;
|
|
6349
6326
|
}
|
|
@@ -6352,14 +6329,14 @@ function loadable(cwd, candidate) {
|
|
|
6352
6329
|
const written = resolve4(cwd, candidate);
|
|
6353
6330
|
if (!LOADABLE.test(written) || !isFile(written)) return null;
|
|
6354
6331
|
let root;
|
|
6355
|
-
let
|
|
6332
|
+
let path17;
|
|
6356
6333
|
try {
|
|
6357
6334
|
root = realpathSync4(cwd);
|
|
6358
|
-
|
|
6335
|
+
path17 = realpathSync4(written);
|
|
6359
6336
|
} catch {
|
|
6360
6337
|
return null;
|
|
6361
6338
|
}
|
|
6362
|
-
if (
|
|
6339
|
+
if (path17 !== root && !path17.startsWith(root + sep2)) return null;
|
|
6363
6340
|
return written;
|
|
6364
6341
|
}
|
|
6365
6342
|
function passable(token) {
|
|
@@ -6405,7 +6382,7 @@ function resolveEntry(cwd) {
|
|
|
6405
6382
|
}
|
|
6406
6383
|
return {
|
|
6407
6384
|
kind: "unavailable",
|
|
6408
|
-
reason: existsSync13(
|
|
6385
|
+
reason: existsSync13(join14(cwd, "package.json")) ? 'no directly loadable entry was found \u2014 declare one as a "start" script of the form `node <file>`, or run the check against a built output' : "there is no package.json here"
|
|
6409
6386
|
};
|
|
6410
6387
|
}
|
|
6411
6388
|
|
|
@@ -6439,8 +6416,8 @@ function preloadPath() {
|
|
|
6439
6416
|
// beside this file, in the repository
|
|
6440
6417
|
];
|
|
6441
6418
|
for (const candidate of candidates) {
|
|
6442
|
-
const
|
|
6443
|
-
if (existsSync14(
|
|
6419
|
+
const path17 = fileURLToPath2(candidate);
|
|
6420
|
+
if (existsSync14(path17)) return path17;
|
|
6444
6421
|
}
|
|
6445
6422
|
return null;
|
|
6446
6423
|
}
|
|
@@ -6787,15 +6764,15 @@ function formatRuntimeCheck(report) {
|
|
|
6787
6764
|
}
|
|
6788
6765
|
|
|
6789
6766
|
// src/map-command.ts
|
|
6790
|
-
import
|
|
6767
|
+
import path14 from "path";
|
|
6791
6768
|
|
|
6792
6769
|
// src/map/ts-loader.ts
|
|
6793
6770
|
import { createRequire } from "module";
|
|
6794
6771
|
import { pathToFileURL } from "url";
|
|
6795
|
-
import { join as
|
|
6772
|
+
import { join as join15 } from "path";
|
|
6796
6773
|
async function loadTypeScript(cwd) {
|
|
6797
6774
|
try {
|
|
6798
|
-
const req = createRequire(pathToFileURL(
|
|
6775
|
+
const req = createRequire(pathToFileURL(join15(cwd, "package.json")));
|
|
6799
6776
|
const resolved = req.resolve("typescript");
|
|
6800
6777
|
const mod = await import(pathToFileURL(resolved).href);
|
|
6801
6778
|
return mod.default ?? mod;
|
|
@@ -7225,7 +7202,7 @@ function dedupeSinks(sinks, owner) {
|
|
|
7225
7202
|
|
|
7226
7203
|
// src/map/module-graph.ts
|
|
7227
7204
|
import { readFileSync as readFileSync14, realpathSync as realpathSync5, statSync as statSync7 } from "fs";
|
|
7228
|
-
import { dirname as dirname8, join as
|
|
7205
|
+
import { dirname as dirname8, join as join16, relative as relative5, resolve as resolvePath } from "path";
|
|
7229
7206
|
var RESOLVE_EXTS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
7230
7207
|
function createModuleGraph(ts, opts) {
|
|
7231
7208
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -7303,7 +7280,7 @@ function resolveRelativeModule(fromFile, spec) {
|
|
|
7303
7280
|
}
|
|
7304
7281
|
candidates.push(base);
|
|
7305
7282
|
for (const e of RESOLVE_EXTS) candidates.push(base + e);
|
|
7306
|
-
for (const e of RESOLVE_EXTS) candidates.push(
|
|
7283
|
+
for (const e of RESOLVE_EXTS) candidates.push(join16(base, "index" + e));
|
|
7307
7284
|
for (const c of candidates) {
|
|
7308
7285
|
try {
|
|
7309
7286
|
if (statSync7(c).isFile()) return c;
|
|
@@ -7332,8 +7309,8 @@ function collectCallees(sf, ts) {
|
|
|
7332
7309
|
}
|
|
7333
7310
|
|
|
7334
7311
|
// src/map/coordinates.ts
|
|
7335
|
-
function runtimeCoordinate(source,
|
|
7336
|
-
if (/\[\d*\]/.test(
|
|
7312
|
+
function runtimeCoordinate(source, path17) {
|
|
7313
|
+
if (/\[\d*\]/.test(path17)) {
|
|
7337
7314
|
return { runtimeParameter: null, runtimeParameterReason: "array traversal: needs an array_key_value rule, not a dotted parameter" };
|
|
7338
7315
|
}
|
|
7339
7316
|
switch (source) {
|
|
@@ -7342,15 +7319,15 @@ function runtimeCoordinate(source, path18) {
|
|
|
7342
7319
|
case "multipart":
|
|
7343
7320
|
case "body":
|
|
7344
7321
|
case "server-fn-data":
|
|
7345
|
-
return { runtimeParameter: `post.${
|
|
7322
|
+
return { runtimeParameter: `post.${path17}` };
|
|
7346
7323
|
case "query":
|
|
7347
|
-
return { runtimeParameter: `get.${
|
|
7324
|
+
return { runtimeParameter: `get.${path17}` };
|
|
7348
7325
|
case "cookie":
|
|
7349
|
-
return { runtimeParameter: `cookie.${
|
|
7326
|
+
return { runtimeParameter: `cookie.${path17}` };
|
|
7350
7327
|
case "file":
|
|
7351
|
-
return { runtimeParameter: `files.${
|
|
7328
|
+
return { runtimeParameter: `files.${path17}` };
|
|
7352
7329
|
case "header":
|
|
7353
|
-
return { runtimeParameter: `server.HTTP_${
|
|
7330
|
+
return { runtimeParameter: `server.HTTP_${path17.toUpperCase().replace(/-/g, "_")}` };
|
|
7354
7331
|
case "route-param":
|
|
7355
7332
|
return { runtimeParameter: null, runtimeParameterReason: "route parameters are not exposed by the runtime resolver" };
|
|
7356
7333
|
default:
|
|
@@ -7382,8 +7359,8 @@ function addressSpaceOf(source) {
|
|
|
7382
7359
|
function isProvenFlow(confidence) {
|
|
7383
7360
|
return confidence === "exact-local" || confidence === "transformed-local";
|
|
7384
7361
|
}
|
|
7385
|
-
function inputIdOf(source,
|
|
7386
|
-
return `${addressSpaceOf(source)}:${
|
|
7362
|
+
function inputIdOf(source, path17) {
|
|
7363
|
+
return `${addressSpaceOf(source)}:${path17}`;
|
|
7387
7364
|
}
|
|
7388
7365
|
function withCoordinates(fields, source) {
|
|
7389
7366
|
return fields.map((f) => {
|
|
@@ -7601,8 +7578,8 @@ function linkFlows(bodyNode, params, inputs, sinks, ts, invocations) {
|
|
|
7601
7578
|
}
|
|
7602
7579
|
const CONTAINER_KEYS = /* @__PURE__ */ new Set([...REQ_SOURCES, "data", "input", "payload"]);
|
|
7603
7580
|
const rootPath = /* @__PURE__ */ new Map();
|
|
7604
|
-
const addRoot = (name,
|
|
7605
|
-
if (!rootPath.has(name)) rootPath.set(name, { path:
|
|
7581
|
+
const addRoot = (name, path17, space) => {
|
|
7582
|
+
if (!rootPath.has(name)) rootPath.set(name, { path: path17, space });
|
|
7606
7583
|
};
|
|
7607
7584
|
for (const p of params ?? []) {
|
|
7608
7585
|
if (!p?.name) continue;
|
|
@@ -7797,8 +7774,8 @@ function dedupeLimitations(list) {
|
|
|
7797
7774
|
function join22(base, seg) {
|
|
7798
7775
|
return base ? `${base}.${seg}` : seg;
|
|
7799
7776
|
}
|
|
7800
|
-
function normalizePath(
|
|
7801
|
-
return
|
|
7777
|
+
function normalizePath(path17) {
|
|
7778
|
+
return path17.replace(/\[\d*\]/g, "").split(".").filter(Boolean).join(".");
|
|
7802
7779
|
}
|
|
7803
7780
|
function fluentChainCalls(call, ts) {
|
|
7804
7781
|
let root = call;
|
|
@@ -8164,7 +8141,7 @@ function handlerEntry(name, kindLabel, params, body, ts, localSinks, bindings, c
|
|
|
8164
8141
|
|
|
8165
8142
|
// src/map/imports.ts
|
|
8166
8143
|
import { readFileSync as readFileSync15 } from "fs";
|
|
8167
|
-
import { join as
|
|
8144
|
+
import { join as join17 } from "path";
|
|
8168
8145
|
var MAX_SITES2 = 5;
|
|
8169
8146
|
var NPM_NAME = /^(?:@[^/@\s~][^/@\s]*\/)?[^/@\s.~][^/@\s]*$/;
|
|
8170
8147
|
function isNpmPackageName(pkg) {
|
|
@@ -8175,7 +8152,7 @@ function readPathAliases(cwd) {
|
|
|
8175
8152
|
for (const name of ["tsconfig.json", "jsconfig.json"]) {
|
|
8176
8153
|
let paths;
|
|
8177
8154
|
try {
|
|
8178
|
-
const raw = readFileSync15(
|
|
8155
|
+
const raw = readFileSync15(join17(cwd, name), "utf8");
|
|
8179
8156
|
const parsed = JSON.parse(stripJsonComments(raw));
|
|
8180
8157
|
paths = parsed.compilerOptions?.paths;
|
|
8181
8158
|
} catch {
|
|
@@ -8662,7 +8639,7 @@ function getStringFlag(flags, name) {
|
|
|
8662
8639
|
|
|
8663
8640
|
// src/build-stamp.ts
|
|
8664
8641
|
import { lstatSync as lstatSync4, readFileSync as readFileSync17, readdirSync as readdirSync6, realpathSync as realpathSync7 } from "fs";
|
|
8665
|
-
import { join as
|
|
8642
|
+
import { join as join18, relative as relative7, sep as sep3 } from "path";
|
|
8666
8643
|
var RULES_FILE_NAMES = /* @__PURE__ */ new Set(["rules.json", "patchstack.rules.json"]);
|
|
8667
8644
|
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage", "tmp", "vendor"]);
|
|
8668
8645
|
var MAX_DEPTH2 = 6;
|
|
@@ -8680,11 +8657,11 @@ function guardImportsRulesFile(dir, rulesName) {
|
|
|
8680
8657
|
}
|
|
8681
8658
|
for (const name of siblings) {
|
|
8682
8659
|
if (!GUARD_SOURCE.test(name)) continue;
|
|
8683
|
-
const
|
|
8660
|
+
const path17 = join18(dir, name);
|
|
8684
8661
|
try {
|
|
8685
|
-
const entry = lstatSync4(
|
|
8662
|
+
const entry = lstatSync4(path17);
|
|
8686
8663
|
if (!entry.isFile() || entry.isSymbolicLink() || entry.size > MAX_GUARD_SOURCE_BYTES) continue;
|
|
8687
|
-
const source = stripComments(readFileSync17(
|
|
8664
|
+
const source = stripComments(readFileSync17(path17, "utf8"));
|
|
8688
8665
|
if (source.includes("@patchstack/connect/protect") && importsRules.test(source)) return true;
|
|
8689
8666
|
} catch {
|
|
8690
8667
|
}
|
|
@@ -8705,9 +8682,9 @@ function findRulesFile(cwd) {
|
|
|
8705
8682
|
} catch {
|
|
8706
8683
|
return { kind: "none" };
|
|
8707
8684
|
}
|
|
8708
|
-
const contained = (
|
|
8685
|
+
const contained = (path17) => {
|
|
8709
8686
|
try {
|
|
8710
|
-
const real = realpathSync7(
|
|
8687
|
+
const real = realpathSync7(path17);
|
|
8711
8688
|
return real === root || real.startsWith(root + sep3);
|
|
8712
8689
|
} catch {
|
|
8713
8690
|
return false;
|
|
@@ -8723,25 +8700,25 @@ function findRulesFile(cwd) {
|
|
|
8723
8700
|
}
|
|
8724
8701
|
for (const name of entries) {
|
|
8725
8702
|
if (name.startsWith(".")) continue;
|
|
8726
|
-
const
|
|
8703
|
+
const path17 = join18(dir, name);
|
|
8727
8704
|
let entry;
|
|
8728
8705
|
try {
|
|
8729
|
-
entry = lstatSync4(
|
|
8706
|
+
entry = lstatSync4(path17);
|
|
8730
8707
|
} catch {
|
|
8731
8708
|
continue;
|
|
8732
8709
|
}
|
|
8733
8710
|
if (entry.isSymbolicLink()) continue;
|
|
8734
8711
|
if (entry.isDirectory()) {
|
|
8735
|
-
if (!SKIP_DIRECTORIES.has(name)) walk2(
|
|
8712
|
+
if (!SKIP_DIRECTORIES.has(name)) walk2(path17, depth + 1);
|
|
8736
8713
|
continue;
|
|
8737
8714
|
}
|
|
8738
8715
|
if (!entry.isFile() || !RULES_FILE_NAMES.has(name)) continue;
|
|
8739
|
-
if (!contained(
|
|
8716
|
+
if (!contained(path17)) continue;
|
|
8740
8717
|
if (!guardImportsRulesFile(dir, name)) continue;
|
|
8741
8718
|
try {
|
|
8742
|
-
if (isRuleBundle(JSON.parse(readFileSync17(
|
|
8719
|
+
if (isRuleBundle(JSON.parse(readFileSync17(path17, "utf8")))) found.push(path17);
|
|
8743
8720
|
} catch {
|
|
8744
|
-
unreadable.push(
|
|
8721
|
+
unreadable.push(path17);
|
|
8745
8722
|
}
|
|
8746
8723
|
}
|
|
8747
8724
|
};
|
|
@@ -8933,7 +8910,7 @@ async function runMap(flags) {
|
|
|
8933
8910
|
const json = JSON.stringify(map, null, 2);
|
|
8934
8911
|
const out = getStringFlag(flags, "out");
|
|
8935
8912
|
if (out) {
|
|
8936
|
-
atomicWriteFileSync(
|
|
8913
|
+
atomicWriteFileSync(path14.resolve(out), json, { encoding: "utf8" });
|
|
8937
8914
|
console.error(`patchstack: wrote ${out}`);
|
|
8938
8915
|
} else if (flags.get("upload") !== true) {
|
|
8939
8916
|
console.log(json);
|
|
@@ -8983,7 +8960,7 @@ async function runMap(flags) {
|
|
|
8983
8960
|
|
|
8984
8961
|
// src/setup.ts
|
|
8985
8962
|
import { readFileSync as readFileSync18 } from "fs";
|
|
8986
|
-
import
|
|
8963
|
+
import path15 from "path";
|
|
8987
8964
|
var SCAN_COMMAND = "patchstack-connect scan";
|
|
8988
8965
|
var MARK_BUILD_COMMAND = "patchstack-connect mark-build";
|
|
8989
8966
|
function setupProtection(cwd) {
|
|
@@ -9008,7 +8985,7 @@ function prependHook(existing, command) {
|
|
|
9008
8985
|
return [command, ...remaining].join(" && ");
|
|
9009
8986
|
}
|
|
9010
8987
|
function wireBuildScripts(cwd, packageManager) {
|
|
9011
|
-
const target =
|
|
8988
|
+
const target = path15.join(cwd, "package.json");
|
|
9012
8989
|
const raw = readFileSync18(target, "utf8");
|
|
9013
8990
|
const pkg = JSON.parse(raw);
|
|
9014
8991
|
const scripts = pkg.scripts ?? {};
|
|
@@ -9276,6 +9253,20 @@ function parseArgs(argv) {
|
|
|
9276
9253
|
flags
|
|
9277
9254
|
};
|
|
9278
9255
|
}
|
|
9256
|
+
function resolveCliConfig(args, extra = {}) {
|
|
9257
|
+
return resolveConfig({
|
|
9258
|
+
cwd: process.cwd(),
|
|
9259
|
+
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
9260
|
+
cliEndpoint: getStringFlag(args.flags, "endpoint"),
|
|
9261
|
+
...extra
|
|
9262
|
+
});
|
|
9263
|
+
}
|
|
9264
|
+
function runningInCi() {
|
|
9265
|
+
return process.env.CI !== void 0 && process.env.CI !== "" && process.env.CI !== "false";
|
|
9266
|
+
}
|
|
9267
|
+
function gitignoreOutcomeLine(ignore) {
|
|
9268
|
+
return ignore.ignored ? " Added to .gitignore." : ` NOT ignored by git \u2014 ${ignore.reason ?? "unknown reason"}. Add it to .gitignore yourself before committing.`;
|
|
9269
|
+
}
|
|
9279
9270
|
async function runInit(args) {
|
|
9280
9271
|
const uuid = args.positional[0];
|
|
9281
9272
|
if (!uuid) {
|
|
@@ -9283,7 +9274,7 @@ async function runInit(args) {
|
|
|
9283
9274
|
console.error("Usage: patchstack-connect init <site-uuid>");
|
|
9284
9275
|
return 1;
|
|
9285
9276
|
}
|
|
9286
|
-
if (
|
|
9277
|
+
if (!isCanonicalUuid(uuid)) {
|
|
9287
9278
|
console.error(`Error: "${uuid}" does not look like a valid UUID.`);
|
|
9288
9279
|
return 1;
|
|
9289
9280
|
}
|
|
@@ -9294,15 +9285,11 @@ async function runInit(args) {
|
|
|
9294
9285
|
return 0;
|
|
9295
9286
|
}
|
|
9296
9287
|
async function runClaim(args) {
|
|
9297
|
-
if (
|
|
9288
|
+
if (runningInCi()) {
|
|
9298
9289
|
console.error("`claim` is interactive and cannot run in CI. Claim the site from a developer machine.");
|
|
9299
9290
|
return 1;
|
|
9300
9291
|
}
|
|
9301
|
-
const config = await
|
|
9302
|
-
cwd: process.cwd(),
|
|
9303
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
9304
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint")
|
|
9305
|
-
});
|
|
9292
|
+
const config = await resolveCliConfig(args);
|
|
9306
9293
|
const siteUuid = config.siteUuid;
|
|
9307
9294
|
if (siteUuid === null) {
|
|
9308
9295
|
console.error("\n No site to claim yet \u2014 run `npx @patchstack/connect scan` first.\n");
|
|
@@ -9317,9 +9304,7 @@ async function runClaim(args) {
|
|
|
9317
9304
|
if (result2.credentialSaved === true) {
|
|
9318
9305
|
const ignore = await secretFileIgnored(process.cwd());
|
|
9319
9306
|
console.log(` A credential for this site was issued and saved to ${SECRET_CONFIG_FILENAME}.`);
|
|
9320
|
-
console.log(
|
|
9321
|
-
ignore.ignored ? " Added to .gitignore." : ` NOT ignored by git \u2014 ${ignore.reason ?? "unknown reason"}. Add it to .gitignore yourself before committing.`
|
|
9322
|
-
);
|
|
9307
|
+
console.log(gitignoreOutcomeLine(ignore));
|
|
9323
9308
|
}
|
|
9324
9309
|
console.log("");
|
|
9325
9310
|
return 0;
|
|
@@ -9395,22 +9380,16 @@ async function runClaim(args) {
|
|
|
9395
9380
|
return 1;
|
|
9396
9381
|
}
|
|
9397
9382
|
async function runLogin(args) {
|
|
9398
|
-
if (
|
|
9383
|
+
if (runningInCi()) {
|
|
9399
9384
|
console.error("`login` is interactive and cannot run in CI. Set PATCHSTACK_PULSE_AUTH instead.");
|
|
9400
9385
|
return 1;
|
|
9401
9386
|
}
|
|
9402
|
-
const config = await
|
|
9403
|
-
cwd: process.cwd(),
|
|
9404
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
9405
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint")
|
|
9406
|
-
});
|
|
9387
|
+
const config = await resolveCliConfig(args);
|
|
9407
9388
|
const approved = async () => {
|
|
9408
9389
|
const ignore = await secretFileIgnored(process.cwd());
|
|
9409
9390
|
console.log(`
|
|
9410
9391
|
\u2713 Credential restored and saved to ${SECRET_CONFIG_FILENAME}.`);
|
|
9411
|
-
console.log(
|
|
9412
|
-
ignore.ignored ? " Added to .gitignore." : ` NOT ignored by git \u2014 ${ignore.reason ?? "unknown reason"}. Add it to .gitignore yourself before committing.`
|
|
9413
|
-
);
|
|
9392
|
+
console.log(gitignoreOutcomeLine(ignore));
|
|
9414
9393
|
console.log(" The previous credential no longer works. Update it anywhere else it was set:");
|
|
9415
9394
|
console.log(" CI secrets, hosting env vars, preview environments, other checkouts.\n");
|
|
9416
9395
|
return 0;
|
|
@@ -9513,10 +9492,7 @@ async function postManifestWithPatience(config, payload) {
|
|
|
9513
9492
|
}
|
|
9514
9493
|
async function runScan(args, options = {}) {
|
|
9515
9494
|
const dryRun = args.flags.get("dry-run") === true;
|
|
9516
|
-
const config = await
|
|
9517
|
-
cwd: process.cwd(),
|
|
9518
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
9519
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint"),
|
|
9495
|
+
const config = await resolveCliConfig(args, {
|
|
9520
9496
|
cliClaimToken: getStringFlag(args.flags, "claim-token"),
|
|
9521
9497
|
// The one command that reports them, so the one command that resolves them.
|
|
9522
9498
|
detectSiteIdentity: true
|
|
@@ -9788,12 +9764,7 @@ async function runDemoCommand(args) {
|
|
|
9788
9764
|
try {
|
|
9789
9765
|
const scenario = resolveDemoScenario(args.positional[0]);
|
|
9790
9766
|
const cwd = process.cwd();
|
|
9791
|
-
const config = await
|
|
9792
|
-
cwd,
|
|
9793
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
9794
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint"),
|
|
9795
|
-
requireSiteUuid: true
|
|
9796
|
-
});
|
|
9767
|
+
const config = await resolveCliConfig(args, { requireSiteUuid: true });
|
|
9797
9768
|
if (config.environment !== "production") {
|
|
9798
9769
|
throw new DemoError(
|
|
9799
9770
|
"The production-backed demo requires PATCHSTACK_ENVIRONMENT=production. Unset the sandbox override and try again."
|
|
@@ -9994,11 +9965,7 @@ function setupOutcome(state, protection, wired) {
|
|
|
9994
9965
|
return lines;
|
|
9995
9966
|
}
|
|
9996
9967
|
async function runStatus(args) {
|
|
9997
|
-
const config = await
|
|
9998
|
-
cwd: process.cwd(),
|
|
9999
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
10000
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint")
|
|
10001
|
-
});
|
|
9968
|
+
const config = await resolveCliConfig(args);
|
|
10002
9969
|
console.log(`Site UUID: ${config.siteUuid ?? "(none yet \u2014 the next `scan` will provision one)"}`);
|
|
10003
9970
|
console.log(
|
|
10004
9971
|
`Endpoint: ${config.endpoint}${config.endpoint === DEFAULT_ENDPOINT ? "" : " (override)"}`
|
|
@@ -10034,11 +10001,7 @@ async function runStatus(args) {
|
|
|
10034
10001
|
return 0;
|
|
10035
10002
|
}
|
|
10036
10003
|
async function runUninstall(args) {
|
|
10037
|
-
const config = await
|
|
10038
|
-
cwd: process.cwd(),
|
|
10039
|
-
cliSiteUuid: getStringFlag(args.flags, "site-uuid"),
|
|
10040
|
-
cliEndpoint: getStringFlag(args.flags, "endpoint")
|
|
10041
|
-
});
|
|
10004
|
+
const config = await resolveCliConfig(args);
|
|
10042
10005
|
if (config.siteUuid === null) {
|
|
10043
10006
|
console.log("No site UUID configured \u2014 there is no site record to signal about.");
|
|
10044
10007
|
console.log('Continue with the local removal steps in AGENT-INSTALL.md ("Uninstalling").');
|
|
@@ -10078,7 +10041,7 @@ function describeStack(stack) {
|
|
|
10078
10041
|
}
|
|
10079
10042
|
function readBuildScript(cwd) {
|
|
10080
10043
|
try {
|
|
10081
|
-
const pkg = JSON.parse(readFileSync19(
|
|
10044
|
+
const pkg = JSON.parse(readFileSync19(path16.join(cwd, "package.json"), "utf8"));
|
|
10082
10045
|
return pkg.scripts?.build;
|
|
10083
10046
|
} catch {
|
|
10084
10047
|
return void 0;
|