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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Precedence (highest wins):
Environment variables:

- `PATCHSTACK_SITE_UUID` — the site UUID from your Patchstack dashboard
- `PATCHSTACK_ENDPOINT` — override the API endpoint (default `http://api.patchstack.com/monitor/pulse/manifest`)
- `PATCHSTACK_ENDPOINT` — override the API endpoint (default `https://api.patchstack.com/monitor/pulse/manifest`)
- `PATCHSTACK_TIMEOUT_MS` — request timeout in milliseconds (default `30000`)

`.patchstackrc.json` example:
Expand Down
6 changes: 3 additions & 3 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.

4 changes: 2 additions & 2 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ function compareSegments(a, b) {
}

// src/client.ts
var DEFAULT_ENDPOINT = "http://api.patchstack.com/monitor/pulse/manifest";
var DEFAULT_ENDPOINT = "https://api.patchstack.com/monitor/pulse/manifest";
var DEFAULT_TIMEOUT_MS = 3e4;
function buildEndpointUrl(base, siteUuid) {
const trimmed = base.replace(/\/$/, "");
return siteUuid !== void 0 && siteUuid !== null && siteUuid.length > 0 ? `${trimmed}/${encodeURIComponent(siteUuid)}` : trimmed;
}
function buildClaimUrl(endpoint, siteUuid) {
const origin = new URL(endpoint).origin;
return `${origin}/claim?site=${encodeURIComponent(siteUuid)}`;
return `${origin}/monitor/claim?site=${encodeURIComponent(siteUuid)}`;
}
async function postManifest(config, payload) {
const url = buildEndpointUrl(config.endpoint, config.siteUuid);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ interface NormalizeResult {
declare function buildWirePayload(manifest: Manifest): NormalizeResult;
declare function compareVersions(a: string, b: string): number;

declare const DEFAULT_ENDPOINT = "http://api.patchstack.com/monitor/pulse/manifest";
declare const DEFAULT_ENDPOINT = "https://api.patchstack.com/monitor/pulse/manifest";
declare function buildEndpointUrl(base: string, siteUuid?: string | null): string;
/**
* Build the claim URL for a site. The claim page lives on the same origin as
* the API endpoint, at `/claim?site=<uuid>`. Using the API endpoint's origin
* (rather than a hard-coded https://app.patchstack.com) means staging, ngrok
* tunnels and local dev environments all produce a claim URL on the same host
* the connector is already talking to.
* the API endpoint, at `/monitor/claim?site=<uuid>`. Using the API endpoint's
* origin (rather than a hard-coded https://api.patchstack.com) means staging,
* ngrok tunnels and local dev environments all produce a claim URL on the same
* host the connector is already talking to.
*/
declare function buildClaimUrl(endpoint: string, siteUuid: string): string;
declare function postManifest(config: Config, payload: WirePayload): Promise<StoreManifestResponse>;
Expand Down
10 changes: 5 additions & 5 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ interface NormalizeResult {
declare function buildWirePayload(manifest: Manifest): NormalizeResult;
declare function compareVersions(a: string, b: string): number;

declare const DEFAULT_ENDPOINT = "http://api.patchstack.com/monitor/pulse/manifest";
declare const DEFAULT_ENDPOINT = "https://api.patchstack.com/monitor/pulse/manifest";
declare function buildEndpointUrl(base: string, siteUuid?: string | null): string;
/**
* Build the claim URL for a site. The claim page lives on the same origin as
* the API endpoint, at `/claim?site=<uuid>`. Using the API endpoint's origin
* (rather than a hard-coded https://app.patchstack.com) means staging, ngrok
* tunnels and local dev environments all produce a claim URL on the same host
* the connector is already talking to.
* the API endpoint, at `/monitor/claim?site=<uuid>`. Using the API endpoint's
* origin (rather than a hard-coded https://api.patchstack.com) means staging,
* ngrok tunnels and local dev environments all produce a claim URL on the same
* host the connector is already talking to.
*/
declare function buildClaimUrl(endpoint: string, siteUuid: string): string;
declare function postManifest(config: Config, payload: WirePayload): Promise<StoreManifestResponse>;
Expand Down
4 changes: 2 additions & 2 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.

2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options (for scan and status):

Environment:
PATCHSTACK_SITE_UUID Site UUID
PATCHSTACK_ENDPOINT API endpoint (default: http://api.patchstack.com/monitor/pulse/manifest)
PATCHSTACK_ENDPOINT API endpoint (default: https://api.patchstack.com/monitor/pulse/manifest)
PATCHSTACK_TIMEOUT_MS Request timeout in ms (default: 30000)

Precedence: CLI flag > environment variable > .patchstackrc.json.
Expand Down
12 changes: 6 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PatchstackError, type Config, type StoreManifestResponse } from './types.js';
import type { WirePayload } from './normalize.js';

export const DEFAULT_ENDPOINT = 'http://api.patchstack.com/monitor/pulse/manifest';
export const DEFAULT_ENDPOINT = 'https://api.patchstack.com/monitor/pulse/manifest';
export const DEFAULT_TIMEOUT_MS = 30_000;

export function buildEndpointUrl(base: string, siteUuid?: string | null): string {
Expand All @@ -13,14 +13,14 @@ export function buildEndpointUrl(base: string, siteUuid?: string | null): string

/**
* Build the claim URL for a site. The claim page lives on the same origin as
* the API endpoint, at `/claim?site=<uuid>`. Using the API endpoint's origin
* (rather than a hard-coded https://app.patchstack.com) means staging, ngrok
* tunnels and local dev environments all produce a claim URL on the same host
* the connector is already talking to.
* the API endpoint, at `/monitor/claim?site=<uuid>`. Using the API endpoint's
* origin (rather than a hard-coded https://api.patchstack.com) means staging,
* ngrok tunnels and local dev environments all produce a claim URL on the same
* host the connector is already talking to.
*/
export function buildClaimUrl(endpoint: string, siteUuid: string): string {
const origin = new URL(endpoint).origin;
return `${origin}/claim?site=${encodeURIComponent(siteUuid)}`;
return `${origin}/monitor/claim?site=${encodeURIComponent(siteUuid)}`;
}

export async function postManifest(
Expand Down
14 changes: 7 additions & 7 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ describe('buildEndpointUrl', () => {
});

describe('buildClaimUrl', () => {
it('uses the API endpoint origin plus /claim?site=<uuid>', () => {
it('uses the API endpoint origin plus /monitor/claim?site=<uuid>', () => {
expect(
buildClaimUrl('https://app.patchstack.com/monitor/pulse/manifest', 'abc-def'),
).toBe('https://app.patchstack.com/claim?site=abc-def');
).toBe('https://app.patchstack.com/monitor/claim?site=abc-def');
});

it('preserves staging origins (ngrok)', () => {
expect(
buildClaimUrl('https://3ad1-18-170-248-162.ngrok-free.app/monitor/pulse/manifest', 'xyz'),
).toBe('https://3ad1-18-170-248-162.ngrok-free.app/claim?site=xyz');
).toBe('https://3ad1-18-170-248-162.ngrok-free.app/monitor/claim?site=xyz');
});

it('drops the manifest path from the API endpoint', () => {
expect(
buildClaimUrl('https://example.com/some/deep/path', 'abc'),
).toBe('https://example.com/claim?site=abc');
).toBe('https://example.com/monitor/claim?site=abc');
});

it('handles a trailing slash on the endpoint', () => {
expect(
buildClaimUrl('https://example.com/monitor/pulse/manifest/', 'abc'),
).toBe('https://example.com/claim?site=abc');
).toBe('https://example.com/monitor/claim?site=abc');
});

it('url-encodes the uuid', () => {
expect(buildClaimUrl('https://example.com/x', 'a b')).toBe(
'https://example.com/claim?site=a%20b',
'https://example.com/monitor/claim?site=a%20b',
);
});

it('preserves the scheme (http vs https) of the API endpoint', () => {
expect(buildClaimUrl('http://localhost:8001/monitor/pulse/manifest', 'abc')).toBe(
'http://localhost:8001/claim?site=abc',
'http://localhost:8001/monitor/claim?site=abc',
);
});
});
Expand Down
Loading