Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 45 additions & 29 deletions dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cli.js.map

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ __export(src_exports, {
buildWirePayload: () => buildWirePayload,
compareVersions: () => compareVersions,
detectLockfile: () => detectLockfile,
persistSiteUuid: () => persistSiteUuid,
postManifest: () => postManifest,
resolveConfig: () => resolveConfig,
scanAndReport: () => scanAndReport,
Expand Down Expand Up @@ -430,7 +431,7 @@ var DEFAULT_ENDPOINT = "https://app.patchstack.com/monitor/pulse/manifest";
var DEFAULT_TIMEOUT_MS = 3e4;
function buildEndpointUrl(base, siteUuid) {
const trimmed = base.replace(/\/$/, "");
return `${trimmed}/${encodeURIComponent(siteUuid)}`;
return siteUuid !== void 0 && siteUuid !== null && siteUuid.length > 0 ? `${trimmed}/${encodeURIComponent(siteUuid)}` : trimmed;
}
async function postManifest(config, payload) {
const url = buildEndpointUrl(config.endpoint, config.siteUuid);
Expand Down Expand Up @@ -508,26 +509,34 @@ async function resolveConfig(options) {
const siteUuid = options.cliSiteUuid ?? fromEnv.siteUuid ?? fromFile.siteUuid ?? null;
const endpoint = options.cliEndpoint ?? fromEnv.endpoint ?? fromFile.endpoint ?? DEFAULT_ENDPOINT;
const timeoutMs = fromEnv.timeoutMs ?? fromFile.timeoutMs ?? DEFAULT_TIMEOUT_MS;
if (siteUuid === null || siteUuid.length === 0) {
if (siteUuid !== null && siteUuid.length > 0 && !isUuid(siteUuid)) {
throw new PatchstackError(
"No site UUID configured. Run `patchstack-connect init <site-uuid>` or set PATCHSTACK_SITE_UUID.",
"CONFIG_MISSING"
`Site UUID "${siteUuid}" does not look like a valid UUID.`,
"CONFIG_INVALID"
);
}
if (!isUuid(siteUuid)) {
if (options.requireSiteUuid && (siteUuid === null || siteUuid.length === 0)) {
throw new PatchstackError(
`Site UUID "${siteUuid}" does not look like a valid UUID.`,
"CONFIG_INVALID"
"No site UUID configured. Run `patchstack-connect scan` to provision one, or set PATCHSTACK_SITE_UUID.",
"CONFIG_MISSING"
);
}
return { siteUuid, endpoint, timeoutMs };
return {
siteUuid: siteUuid === null || siteUuid.length === 0 ? null : siteUuid,
endpoint,
timeoutMs
};
}
async function writeConfigFile(cwd, config) {
const target = import_node_path4.default.join(cwd, CONFIG_FILENAME);
const content = JSON.stringify(config, null, 2) + "\n";
await (0, import_promises4.writeFile)(target, content, "utf8");
return target;
}
async function persistSiteUuid(cwd, siteUuid) {
const existing = await readConfigFile(cwd);
return writeConfigFile(cwd, { ...existing, siteUuid });
}
async function readConfigFile(cwd) {
const target = import_node_path4.default.join(cwd, CONFIG_FILENAME);
let raw;
Expand Down Expand Up @@ -583,6 +592,9 @@ async function scanAndReport(options = {}) {
const manifest = await scanLockfile(cwd);
const { payload, stats } = buildWirePayload(manifest);
const response = await postManifest(config, payload);
if (config.siteUuid === null && response.uuid !== void 0 && response.uuid.length > 0) {
await persistSiteUuid(cwd, response.uuid);
}
return {
manifest,
response,
Expand All @@ -599,6 +611,7 @@ async function scanAndReport(options = {}) {
buildWirePayload,
compareVersions,
detectLockfile,
persistSiteUuid,
postManifest,
resolveConfig,
scanAndReport,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ interface Manifest {
packages: PackageEntry[];
}
interface Config {
siteUuid: string;
/**
* The site UUID. `null` means we don't have one yet — `postManifest` will then
* post to the bare endpoint, the server will provision a fresh site, and the
* UUID it returns should be persisted via `persistSiteUuid()`.
*/
siteUuid: string | null;
endpoint: string;
timeoutMs: number;
}
interface StoreManifestResponse {
/** The UUID of the site the manifest was stored against. Always returned. */
uuid?: string;
stored: boolean;
manifest_id?: number;
checksum?: string;
Expand Down Expand Up @@ -60,7 +67,7 @@ declare function buildWirePayload(manifest: Manifest): NormalizeResult;
declare function compareVersions(a: string, b: string): number;

declare const DEFAULT_ENDPOINT = "https://app.patchstack.com/monitor/pulse/manifest";
declare function buildEndpointUrl(base: string, siteUuid: string): string;
declare function buildEndpointUrl(base: string, siteUuid?: string | null): string;
declare function postManifest(config: Config, payload: WirePayload): Promise<StoreManifestResponse>;

interface ConfigFile {
Expand All @@ -72,9 +79,21 @@ interface ResolveConfigOptions {
cwd: string;
cliSiteUuid?: string;
cliEndpoint?: string;
/**
* When true, resolveConfig throws CONFIG_MISSING if no site UUID is configured.
* Defaults to false: callers that can run without a UUID (the first `scan` after
* `npm install`) just get `siteUuid: null` back and learn the UUID from the
* server response.
*/
requireSiteUuid?: boolean;
}
declare function resolveConfig(options: ResolveConfigOptions): Promise<Config>;
declare function writeConfigFile(cwd: string, config: ConfigFile): Promise<string>;
/**
* Merge a new siteUuid into the existing `.patchstackrc.json` (or create it).
* Preserves any `endpoint` / `timeoutMs` the user already wrote.
*/
declare function persistSiteUuid(cwd: string, siteUuid: string): Promise<string>;

interface ScanAndReportOptions {
cwd?: string;
Expand All @@ -89,4 +108,4 @@ interface ScanAndReportResult {
}
declare function scanAndReport(options?: ScanAndReportOptions): Promise<ScanAndReportResult>;

export { type Config, DEFAULT_ENDPOINT, type Ecosystem, type Manifest, type PackageEntry, PatchstackError, type ScanAndReportOptions, type ScanAndReportResult, type StoreManifestResponse, buildEndpointUrl, buildWirePayload, compareVersions, detectLockfile, postManifest, resolveConfig, scanAndReport, scanLockfile, writeConfigFile };
export { type Config, DEFAULT_ENDPOINT, type Ecosystem, type Manifest, type PackageEntry, PatchstackError, type ScanAndReportOptions, type ScanAndReportResult, type StoreManifestResponse, buildEndpointUrl, buildWirePayload, compareVersions, detectLockfile, persistSiteUuid, postManifest, resolveConfig, scanAndReport, scanLockfile, writeConfigFile };
25 changes: 22 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ interface Manifest {
packages: PackageEntry[];
}
interface Config {
siteUuid: string;
/**
* The site UUID. `null` means we don't have one yet — `postManifest` will then
* post to the bare endpoint, the server will provision a fresh site, and the
* UUID it returns should be persisted via `persistSiteUuid()`.
*/
siteUuid: string | null;
endpoint: string;
timeoutMs: number;
}
interface StoreManifestResponse {
/** The UUID of the site the manifest was stored against. Always returned. */
uuid?: string;
stored: boolean;
manifest_id?: number;
checksum?: string;
Expand Down Expand Up @@ -60,7 +67,7 @@ declare function buildWirePayload(manifest: Manifest): NormalizeResult;
declare function compareVersions(a: string, b: string): number;

declare const DEFAULT_ENDPOINT = "https://app.patchstack.com/monitor/pulse/manifest";
declare function buildEndpointUrl(base: string, siteUuid: string): string;
declare function buildEndpointUrl(base: string, siteUuid?: string | null): string;
declare function postManifest(config: Config, payload: WirePayload): Promise<StoreManifestResponse>;

interface ConfigFile {
Expand All @@ -72,9 +79,21 @@ interface ResolveConfigOptions {
cwd: string;
cliSiteUuid?: string;
cliEndpoint?: string;
/**
* When true, resolveConfig throws CONFIG_MISSING if no site UUID is configured.
* Defaults to false: callers that can run without a UUID (the first `scan` after
* `npm install`) just get `siteUuid: null` back and learn the UUID from the
* server response.
*/
requireSiteUuid?: boolean;
}
declare function resolveConfig(options: ResolveConfigOptions): Promise<Config>;
declare function writeConfigFile(cwd: string, config: ConfigFile): Promise<string>;
/**
* Merge a new siteUuid into the existing `.patchstackrc.json` (or create it).
* Preserves any `endpoint` / `timeoutMs` the user already wrote.
*/
declare function persistSiteUuid(cwd: string, siteUuid: string): Promise<string>;

interface ScanAndReportOptions {
cwd?: string;
Expand All @@ -89,4 +108,4 @@ interface ScanAndReportResult {
}
declare function scanAndReport(options?: ScanAndReportOptions): Promise<ScanAndReportResult>;

export { type Config, DEFAULT_ENDPOINT, type Ecosystem, type Manifest, type PackageEntry, PatchstackError, type ScanAndReportOptions, type ScanAndReportResult, type StoreManifestResponse, buildEndpointUrl, buildWirePayload, compareVersions, detectLockfile, postManifest, resolveConfig, scanAndReport, scanLockfile, writeConfigFile };
export { type Config, DEFAULT_ENDPOINT, type Ecosystem, type Manifest, type PackageEntry, PatchstackError, type ScanAndReportOptions, type ScanAndReportResult, type StoreManifestResponse, buildEndpointUrl, buildWirePayload, compareVersions, detectLockfile, persistSiteUuid, postManifest, resolveConfig, scanAndReport, scanLockfile, writeConfigFile };
28 changes: 20 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading
Loading