@pcific/sdk 0.1.0 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PCIFIC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/auth.d.ts CHANGED
@@ -18,4 +18,3 @@ export interface ResolvedPcificAuth {
18
18
  * Empty PCIFIC_MODE ("") is treated as unset.
19
19
  */
20
20
  export declare function resolvePcificAuth(options?: ResolvePcificAuthOptions): ResolvedPcificAuth;
21
- //# sourceMappingURL=auth.d.ts.map
package/dist/auth.js CHANGED
@@ -83,4 +83,3 @@ export function resolvePcificAuth(options = {}) {
83
83
  source: explicitTest ? "testKey" : "PCIFIC_TEST_KEY",
84
84
  };
85
85
  }
86
- //# sourceMappingURL=auth.js.map
package/dist/client.d.ts CHANGED
@@ -322,4 +322,3 @@ export declare class PcificClient {
322
322
  };
323
323
  }
324
324
  export declare function createPcificClient(options?: PcificClientOptions): PcificClient;
325
- //# sourceMappingURL=client.d.ts.map
package/dist/client.js CHANGED
@@ -605,4 +605,3 @@ export class PcificClient {
605
605
  export function createPcificClient(options = {}) {
606
606
  return new PcificClient(options);
607
607
  }
608
- //# sourceMappingURL=client.js.map
package/dist/errors.d.ts CHANGED
@@ -49,4 +49,3 @@ export declare class PcificStreamError extends Error {
49
49
  payload?: JsonValue;
50
50
  });
51
51
  }
52
- //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js CHANGED
@@ -46,4 +46,3 @@ export class PcificStreamError extends Error {
46
46
  this.payload = options.payload;
47
47
  }
48
48
  }
49
- //# sourceMappingURL=errors.js.map
@@ -5734,4 +5734,3 @@ export interface PcificPaths {
5734
5734
  };
5735
5735
  };
5736
5736
  }
5737
- //# sourceMappingURL=generated-types.d.ts.map
@@ -3,4 +3,3 @@
3
3
  * Do not edit manually; run `npx tsx scripts/generate-sdk-types.ts` to regenerate.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=generated-types.js.map
package/dist/http.d.ts CHANGED
@@ -48,4 +48,3 @@ export declare class PcificHttpClient {
48
48
  requestStream(params: InternalRequestParams): Promise<ReadableStream<Uint8Array>>;
49
49
  }
50
50
  export {};
51
- //# sourceMappingURL=http.d.ts.map
package/dist/http.js CHANGED
@@ -261,4 +261,3 @@ export class PcificHttpClient {
261
261
  return response.body;
262
262
  }
263
263
  }
264
- //# sourceMappingURL=http.js.map
package/dist/index.d.ts CHANGED
@@ -7,4 +7,3 @@ export { normalizeUpload, serializeFormData, type NormalizedUpload, type UploadF
7
7
  export { parseSseStream, type SseFrame } from "./sse.js";
8
8
  export { clearJwksCache, parseMessageCheckReceipt, signRequest, verifyMessageCheckReceipt, verifyPixelTraceManifest, verifyWebhookSignature, type Ed25519Jwk, type JsonWebKeySet, type ParsedMcr1Receipt, type SignRequestOptions, type VerifyMessageCheckReceiptOptions, type VerifyMessageCheckReceiptResult, type VerifyPixelTraceManifestOptions, type VerifyPixelTraceManifestResult, type VerifyWebhookSignatureOptions, type VerifyWebhookSignatureResult, } from "./verify.js";
9
9
  export type { Error as PcificErrorResponse, OrbitCancelled, OrbitFailed, OrbitListing, OrbitQuestions, OrbitWorking, PcificPaths, SafeguardDone, SafeguardFailed, SafeguardWorking, ToolError, WebhookEvent, } from "./generated-types.js";
10
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -5,4 +5,3 @@ export { PcificHttpClient } from "./http.js";
5
5
  export { normalizeUpload, serializeFormData, } from "./multipart.js";
6
6
  export { parseSseStream } from "./sse.js";
7
7
  export { clearJwksCache, parseMessageCheckReceipt, signRequest, verifyMessageCheckReceipt, verifyPixelTraceManifest, verifyWebhookSignature, } from "./verify.js";
8
- //# sourceMappingURL=index.js.map
package/dist/json.d.ts CHANGED
@@ -9,4 +9,3 @@ export declare function isNumber(value: JsonValue | undefined): value is number;
9
9
  export declare function isBoolean(value: JsonValue | undefined): value is boolean;
10
10
  export declare function isJsonObject(value: JsonValue | undefined): value is JsonObject;
11
11
  export declare function parseJsonValue(text: string): JsonValue;
12
- //# sourceMappingURL=json.d.ts.map
package/dist/json.js CHANGED
@@ -14,4 +14,3 @@ export function parseJsonValue(text) {
14
14
  // SAFETY: JSON.parse returns only JSON primitives, arrays, or plain objects matching JsonValue.
15
15
  return JSON.parse(text);
16
16
  }
17
- //# sourceMappingURL=json.js.map
package/dist/kit.d.ts ADDED
@@ -0,0 +1,220 @@
1
+ export declare const DEFAULT_PCIFIC_KIT_BASE_URL = "https://business.pcific.ai";
2
+ export declare const PCIFIC_KIT_TOOLS: readonly ["orbit", "safeguard", "ask", "pixel-trace", "trust", "chat"];
3
+ export type PcificKitTool = (typeof PCIFIC_KIT_TOOLS)[number];
4
+ export type PcificKitTagName = `pcific-${PcificKitTool}`;
5
+ export type PcificKitLauncherCorner = "bottom-right" | "bottom-left" | "top-right" | "top-left";
6
+ export type PcificKitLauncher = PcificKitLauncherCorner | "inline";
7
+ export type PcificKitThemeMode = "auto" | "light" | "dark";
8
+ export type PcificKitOnOff = "on" | "off";
9
+ export declare const PCIFIC_KIT_FONTS: readonly ["business", "inherit", "Inter", "Work Sans", "Georgia", "Arial", "Verdana", "Times New Roman", "Courier New", "system-ui", "sans-serif", "serif", "monospace"];
10
+ export type PcificKitFont = (typeof PCIFIC_KIT_FONTS)[number];
11
+ export interface PcificKitTheme {
12
+ accent?: string;
13
+ background?: string;
14
+ surface?: string;
15
+ text?: string;
16
+ mutedText?: string;
17
+ border?: string;
18
+ mode?: PcificKitThemeMode;
19
+ radius?: number;
20
+ font?: PcificKitFont;
21
+ density?: "comfortable" | "compact";
22
+ launcher?: {
23
+ corner?: PcificKitLauncherCorner;
24
+ offset?: number;
25
+ label?: string;
26
+ };
27
+ }
28
+ export interface PcificChatMessage {
29
+ id: string;
30
+ text: string;
31
+ senderId: string;
32
+ senderName?: string;
33
+ createdAt?: string;
34
+ warn?: boolean;
35
+ label?: string | null;
36
+ }
37
+ export interface PcificChatSendPayload {
38
+ text: string;
39
+ maskedText: string;
40
+ verdict: string;
41
+ enforce: boolean;
42
+ checkId: string;
43
+ receipt: string | null;
44
+ }
45
+ export type PcificResultEventDetail = Record<string, string | string[]>;
46
+ export interface PcificStateEventDetail {
47
+ type: "pcific:state";
48
+ state: string;
49
+ label: string;
50
+ link?: string;
51
+ }
52
+ export interface PcificProblemEventDetail {
53
+ message: string;
54
+ }
55
+ export interface PcificCapabilitiesEventDetail {
56
+ type: "pcific:capabilities";
57
+ states: Array<{
58
+ id: string;
59
+ label: string;
60
+ }>;
61
+ acts: Array<{
62
+ id: string;
63
+ label: string;
64
+ }>;
65
+ }
66
+ export interface PcificMessageSentEventDetail extends PcificChatSendPayload {
67
+ message: PcificChatMessage | null;
68
+ }
69
+ export interface PcificMessageBlockedEventDetail {
70
+ verdict: string;
71
+ }
72
+ export interface PcificKitEventDetailMap {
73
+ "pcific:result": PcificResultEventDetail;
74
+ "pcific:state": PcificStateEventDetail;
75
+ "pcific:problem": PcificProblemEventDetail;
76
+ "pcific:capabilities": PcificCapabilitiesEventDetail;
77
+ "pcific:message-sent": PcificMessageSentEventDetail;
78
+ "pcific:message-blocked": PcificMessageBlockedEventDetail;
79
+ }
80
+ export type PcificKitEventMap = {
81
+ [K in keyof PcificKitEventDetailMap]: CustomEvent<PcificKitEventDetailMap[K]>;
82
+ };
83
+ export type PcificKitEventName = keyof PcificKitEventMap;
84
+ export interface PcificTagCommonAttributes {
85
+ session?: string;
86
+ read?: string;
87
+ fill?: string;
88
+ form?: string;
89
+ accent?: string;
90
+ mode?: PcificKitThemeMode;
91
+ radius?: number | string;
92
+ font?: PcificKitFont;
93
+ theme?: string;
94
+ logo?: string;
95
+ launcher?: PcificKitLauncher;
96
+ simulate?: boolean | "";
97
+ title?: string;
98
+ }
99
+ export interface PcificOrbitAttributes extends PcificTagCommonAttributes {
100
+ "pixel-trace"?: PcificKitOnOff;
101
+ safeguard?: PcificKitOnOff;
102
+ faq?: PcificKitOnOff;
103
+ price?: PcificKitOnOff;
104
+ "edit-chat"?: PcificKitOnOff;
105
+ }
106
+ export interface PcificSafeguardAttributes extends PcificTagCommonAttributes {
107
+ }
108
+ export interface PcificAskAttributes extends PcificTagCommonAttributes {
109
+ "item-id"?: string;
110
+ }
111
+ export interface PcificPixelTraceAttributes extends PcificTagCommonAttributes {
112
+ }
113
+ export interface PcificTrustAttributes extends PcificTagCommonAttributes {
114
+ }
115
+ export interface PcificChatAttributes extends PcificTagCommonAttributes {
116
+ "messages-url"?: string;
117
+ "send-url"?: string;
118
+ "session-url"?: string;
119
+ "poll-seconds"?: number | string;
120
+ }
121
+ export interface PcificTagAttributes extends PcificOrbitAttributes, PcificAskAttributes, PcificChatAttributes {
122
+ }
123
+ export interface PcificKitElement extends HTMLElement {
124
+ simulate(action: string): void;
125
+ }
126
+ export interface PcificChatElement extends PcificKitElement {
127
+ pushMessage(message: PcificChatMessage): void;
128
+ refresh(): void;
129
+ }
130
+ export interface PcificKitElementMap {
131
+ "pcific-orbit": PcificKitElement;
132
+ "pcific-safeguard": PcificKitElement;
133
+ "pcific-ask": PcificKitElement;
134
+ "pcific-pixel-trace": PcificKitElement;
135
+ "pcific-trust": PcificKitElement;
136
+ "pcific-chat": PcificChatElement;
137
+ }
138
+ export interface LoadPcificKitOptions {
139
+ /** Base origin serving `/static/templates/kit.js`. Defaults to `https://business.pcific.ai`. */
140
+ baseUrl?: string;
141
+ /** Maximum milliseconds to wait for the Kit script to load. Defaults to 15000. */
142
+ timeoutMs?: number;
143
+ /** When true, resolves as a no-op during SSR instead of throwing `PcificConfigError`. */
144
+ ignoreSsr?: boolean;
145
+ }
146
+ export interface PcificKitHandle {
147
+ readonly baseUrl: string;
148
+ readonly scriptUrl: string;
149
+ load(): Promise<void>;
150
+ onEvent: typeof onPcificEvent;
151
+ }
152
+ export interface KitScriptNode extends EventTarget {
153
+ type: string;
154
+ src: string;
155
+ getAttribute(name: string): string | null;
156
+ setAttribute(name: string, value: string): void;
157
+ }
158
+ export interface KitDocumentLike {
159
+ readonly head: {
160
+ appendChild(node: KitScriptNode): KitScriptNode;
161
+ } | null;
162
+ readonly documentElement: {
163
+ appendChild(node: KitScriptNode): KitScriptNode;
164
+ } | null;
165
+ createElement(tagName: "script"): KitScriptNode;
166
+ querySelectorAll(selector: string): ArrayLike<KitScriptNode>;
167
+ }
168
+ export interface KitCustomElementsLike {
169
+ get(name: string): CustomElementConstructor | undefined;
170
+ whenDefined?(name: string): Promise<CustomElementConstructor>;
171
+ }
172
+ export declare function getPcificKitScriptUrl(baseUrl?: string): string;
173
+ /**
174
+ * Idempotently loads the PCIFIC Kit web components script in browser environments.
175
+ * Safe against concurrent calls and duplicate script tags.
176
+ */
177
+ export declare function loadPcificKit(options?: LoadPcificKitOptions): Promise<void>;
178
+ /**
179
+ * Attaches a typed listener for any PCIFIC custom event (`pcific:result`, `pcific:state`,
180
+ * `pcific:problem`, etc.) and returns a cleanup function that removes it.
181
+ */
182
+ export declare function onPcificEvent<K extends PcificKitEventName>(element: EventTarget, eventName: K, handler: (detail: PcificKitEventDetailMap[K], event: CustomEvent<PcificKitEventDetailMap[K]>) => void, options?: AddEventListenerOptions | boolean): () => void;
183
+ /**
184
+ * Creates a reusable handle configured with a baseUrl for loading PCIFIC Kit
185
+ * and subscribing to typed web component events.
186
+ */
187
+ export declare function createPcificKit(options?: LoadPcificKitOptions): PcificKitHandle;
188
+ /** Clears internal in-flight script cache. Intended for test isolation. */
189
+ export declare function resetPcificKitLoader(): void;
190
+ export interface PcificIntrinsicElementBase {
191
+ id?: string;
192
+ class?: string;
193
+ className?: string;
194
+ style?: string | Record<string, string | number | undefined>;
195
+ slot?: string;
196
+ hidden?: boolean;
197
+ "aria-label"?: string;
198
+ children?: unknown;
199
+ ref?: unknown;
200
+ }
201
+ declare global {
202
+ interface HTMLElementTagNameMap {
203
+ "pcific-orbit": PcificKitElement;
204
+ "pcific-safeguard": PcificKitElement;
205
+ "pcific-ask": PcificKitElement;
206
+ "pcific-pixel-trace": PcificKitElement;
207
+ "pcific-trust": PcificKitElement;
208
+ "pcific-chat": PcificChatElement;
209
+ }
210
+ namespace JSX {
211
+ interface IntrinsicElements {
212
+ "pcific-orbit": PcificIntrinsicElementBase & PcificOrbitAttributes;
213
+ "pcific-safeguard": PcificIntrinsicElementBase & PcificSafeguardAttributes;
214
+ "pcific-ask": PcificIntrinsicElementBase & PcificAskAttributes;
215
+ "pcific-pixel-trace": PcificIntrinsicElementBase & PcificPixelTraceAttributes;
216
+ "pcific-trust": PcificIntrinsicElementBase & PcificTrustAttributes;
217
+ "pcific-chat": PcificIntrinsicElementBase & PcificChatAttributes;
218
+ }
219
+ }
220
+ }
package/dist/kit.js ADDED
@@ -0,0 +1,208 @@
1
+ import { PcificConfigError } from "./errors.js";
2
+ export const DEFAULT_PCIFIC_KIT_BASE_URL = "https://business.pcific.ai";
3
+ const DEFAULT_LOAD_TIMEOUT_MS = 15_000;
4
+ const KIT_SCRIPT_PATH = "/static/templates/kit.js";
5
+ export const PCIFIC_KIT_TOOLS = [
6
+ "orbit",
7
+ "safeguard",
8
+ "ask",
9
+ "pixel-trace",
10
+ "trust",
11
+ "chat",
12
+ ];
13
+ export const PCIFIC_KIT_FONTS = [
14
+ "business",
15
+ "inherit",
16
+ "Inter",
17
+ "Work Sans",
18
+ "Georgia",
19
+ "Arial",
20
+ "Verdana",
21
+ "Times New Roman",
22
+ "Courier New",
23
+ "system-ui",
24
+ "sans-serif",
25
+ "serif",
26
+ "monospace",
27
+ ];
28
+ const inflightLoads = new Map();
29
+ function readBrowserGlobals() {
30
+ // SAFETY: globalThis may provide document and customElements in browser runtimes and omit them in SSR/Node.
31
+ return globalThis;
32
+ }
33
+ function normalizeBaseUrl(rawBaseUrl) {
34
+ const candidate = (rawBaseUrl ?? DEFAULT_PCIFIC_KIT_BASE_URL).trim();
35
+ if (!candidate) {
36
+ throw new PcificConfigError("PCIFIC Kit baseUrl cannot be empty.", {
37
+ code: "INVALID_KIT_BASE_URL",
38
+ tryThis: `Pass a valid http(s) baseUrl or omit it to use ${DEFAULT_PCIFIC_KIT_BASE_URL}.`,
39
+ });
40
+ }
41
+ let parsed;
42
+ try {
43
+ parsed = new URL(candidate);
44
+ }
45
+ catch {
46
+ throw new PcificConfigError(`Invalid PCIFIC Kit baseUrl "${candidate}".`, {
47
+ code: "INVALID_KIT_BASE_URL",
48
+ tryThis: `Pass a valid http(s) origin such as "${DEFAULT_PCIFIC_KIT_BASE_URL}".`,
49
+ });
50
+ }
51
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
52
+ throw new PcificConfigError(`Unsupported PCIFIC Kit baseUrl protocol "${parsed.protocol}".`, {
53
+ code: "INVALID_KIT_BASE_URL",
54
+ tryThis: `Use an https:// or http:// origin such as "${DEFAULT_PCIFIC_KIT_BASE_URL}".`,
55
+ });
56
+ }
57
+ return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
58
+ }
59
+ export function getPcificKitScriptUrl(baseUrl) {
60
+ return `${normalizeBaseUrl(baseUrl)}${KIT_SCRIPT_PATH}`;
61
+ }
62
+ function findExistingKitScript(doc, scriptUrl) {
63
+ const scripts = doc.querySelectorAll("script[src]");
64
+ for (const node of Array.from(scripts)) {
65
+ const attrSrc = node.getAttribute("src");
66
+ if (attrSrc === scriptUrl || node.src === scriptUrl) {
67
+ return node;
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ /**
73
+ * Idempotently loads the PCIFIC Kit web components script in browser environments.
74
+ * Safe against concurrent calls and duplicate script tags.
75
+ */
76
+ export function loadPcificKit(options = {}) {
77
+ const scriptUrl = getPcificKitScriptUrl(options.baseUrl);
78
+ const timeoutMs = options.timeoutMs ?? DEFAULT_LOAD_TIMEOUT_MS;
79
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
80
+ return Promise.reject(new PcificConfigError("PCIFIC Kit timeoutMs must be a positive number.", {
81
+ code: "INVALID_KIT_TIMEOUT",
82
+ tryThis: "Pass a positive number of milliseconds for timeoutMs, or omit it to use 15000.",
83
+ }));
84
+ }
85
+ const globals = readBrowserGlobals();
86
+ const doc = globals.document;
87
+ const registry = globals.customElements;
88
+ if (!doc || !registry) {
89
+ if (options.ignoreSsr) {
90
+ return Promise.resolve();
91
+ }
92
+ return Promise.reject(new PcificConfigError("loadPcificKit() can only run in a browser environment with document and customElements.", {
93
+ code: "PCIFIC_KIT_BROWSER_ONLY",
94
+ tryThis: "Call loadPcificKit() inside a client-side effect (such as useEffect or onMount), or pass { ignoreSsr: true } if calling during SSR.",
95
+ }));
96
+ }
97
+ if (registry.get("pcific-orbit")) {
98
+ return Promise.resolve();
99
+ }
100
+ const inflight = inflightLoads.get(scriptUrl);
101
+ if (inflight) {
102
+ return inflight;
103
+ }
104
+ const existing = findExistingKitScript(doc, scriptUrl);
105
+ if (existing?.getAttribute("data-pcific-kit-loaded") === "true") {
106
+ return Promise.resolve();
107
+ }
108
+ const loadPromise = new Promise((resolve, reject) => {
109
+ const script = existing ?? doc.createElement("script");
110
+ let settled = false;
111
+ const cleanup = () => {
112
+ clearTimeout(timer);
113
+ script.removeEventListener("load", onLoad);
114
+ script.removeEventListener("error", onError);
115
+ };
116
+ const fail = (error) => {
117
+ if (settled)
118
+ return;
119
+ settled = true;
120
+ cleanup();
121
+ inflightLoads.delete(scriptUrl);
122
+ reject(error);
123
+ };
124
+ const succeed = () => {
125
+ if (settled)
126
+ return;
127
+ settled = true;
128
+ cleanup();
129
+ script.setAttribute("data-pcific-kit-loaded", "true");
130
+ inflightLoads.delete(scriptUrl);
131
+ resolve();
132
+ };
133
+ const onLoad = () => {
134
+ if (registry.get("pcific-orbit")) {
135
+ succeed();
136
+ return;
137
+ }
138
+ if (registry.whenDefined) {
139
+ registry.whenDefined("pcific-orbit").then(() => succeed(), () => succeed());
140
+ return;
141
+ }
142
+ succeed();
143
+ };
144
+ const onError = () => {
145
+ fail(new PcificConfigError(`Failed to load PCIFIC Kit script from ${scriptUrl}.`, {
146
+ code: "PCIFIC_KIT_LOAD_FAILED",
147
+ tryThis: `Check that ${scriptUrl} is reachable and allowed by your Content-Security-Policy.`,
148
+ }));
149
+ };
150
+ const timer = setTimeout(() => {
151
+ fail(new PcificConfigError(`Timed out after ${timeoutMs}ms waiting for PCIFIC Kit script (${scriptUrl}).`, {
152
+ code: "PCIFIC_KIT_LOAD_TIMEOUT",
153
+ tryThis: "Check network connectivity or raise timeoutMs, then retry loadPcificKit().",
154
+ }));
155
+ }, timeoutMs);
156
+ script.addEventListener("load", onLoad, { once: true });
157
+ script.addEventListener("error", onError, { once: true });
158
+ if (!existing) {
159
+ script.type = "module";
160
+ script.src = scriptUrl;
161
+ script.setAttribute("data-pcific-kit", "true");
162
+ const target = doc.head ?? doc.documentElement;
163
+ if (!target) {
164
+ fail(new PcificConfigError("Cannot mount PCIFIC Kit script: document has no head or root element.", {
165
+ code: "PCIFIC_KIT_NO_DOCUMENT_TARGET",
166
+ tryThis: "Call loadPcificKit() after the page document has been initialized.",
167
+ }));
168
+ return;
169
+ }
170
+ target.appendChild(script);
171
+ }
172
+ });
173
+ inflightLoads.set(scriptUrl, loadPromise);
174
+ return loadPromise;
175
+ }
176
+ /**
177
+ * Attaches a typed listener for any PCIFIC custom event (`pcific:result`, `pcific:state`,
178
+ * `pcific:problem`, etc.) and returns a cleanup function that removes it.
179
+ */
180
+ export function onPcificEvent(element, eventName, handler, options) {
181
+ const listener = (rawEvent) => {
182
+ // SAFETY: The listener is registered specifically for eventName, which PCIFIC Kit dispatches as CustomEvent<PcificKitEventDetailMap[K]>.
183
+ const customEvent = rawEvent;
184
+ handler(customEvent.detail, customEvent);
185
+ };
186
+ element.addEventListener(eventName, listener, options);
187
+ return () => {
188
+ element.removeEventListener(eventName, listener, options);
189
+ };
190
+ }
191
+ /**
192
+ * Creates a reusable handle configured with a baseUrl for loading PCIFIC Kit
193
+ * and subscribing to typed web component events.
194
+ */
195
+ export function createPcificKit(options = {}) {
196
+ const baseUrl = normalizeBaseUrl(options.baseUrl);
197
+ const scriptUrl = `${baseUrl}${KIT_SCRIPT_PATH}`;
198
+ return {
199
+ baseUrl,
200
+ scriptUrl,
201
+ load: () => loadPcificKit({ ...options, baseUrl }),
202
+ onEvent: onPcificEvent,
203
+ };
204
+ }
205
+ /** Clears internal in-flight script cache. Intended for test isolation. */
206
+ export function resetPcificKitLoader() {
207
+ inflightLoads.clear();
208
+ }
@@ -21,4 +21,3 @@ export declare function serializeFormData(formData: FormData): Promise<{
21
21
  body: Uint8Array;
22
22
  contentType: string;
23
23
  }>;
24
- //# sourceMappingURL=multipart.d.ts.map
package/dist/multipart.js CHANGED
@@ -59,4 +59,3 @@ export async function serializeFormData(formData) {
59
59
  const body = new Uint8Array(await response.arrayBuffer());
60
60
  return { body, contentType };
61
61
  }
62
- //# sourceMappingURL=multipart.js.map
package/dist/sse.d.ts CHANGED
@@ -10,4 +10,3 @@ export interface SseFrame<T extends JsonValue = JsonValue> {
10
10
  * handling arbitrary chunk splits, multi-byte UTF-8 sequences, CRLF/LF line endings, and comments.
11
11
  */
12
12
  export declare function parseSseStream<T extends JsonValue = JsonValue>(stream: ReadableStream<Uint8Array>): AsyncGenerator<SseFrame<T>, void, undefined>;
13
- //# sourceMappingURL=sse.d.ts.map
package/dist/sse.js CHANGED
@@ -97,4 +97,3 @@ export async function* parseSseStream(stream) {
97
97
  reader.releaseLock();
98
98
  }
99
99
  }
100
- //# sourceMappingURL=sse.js.map
package/dist/verify.d.ts CHANGED
@@ -112,4 +112,3 @@ export declare function parseMessageCheckReceipt(receipt: string): ParsedMcr1Rec
112
112
  * via POST /api/v1/message-check/receipts/verify (client.messageCheck.verifyReceiptOnline).
113
113
  */
114
114
  export declare function verifyMessageCheckReceipt(options: VerifyMessageCheckReceiptOptions): Promise<VerifyMessageCheckReceiptResult>;
115
- //# sourceMappingURL=verify.d.ts.map
package/dist/verify.js CHANGED
@@ -504,4 +504,3 @@ export async function verifyMessageCheckReceipt(options) {
504
504
  claims: claimsJson,
505
505
  };
506
506
  }
507
- //# sourceMappingURL=verify.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pcific/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official zero-dependency TypeScript SDK for the PCIFIC API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,31 +15,36 @@
15
15
  "types": "./dist/verify.d.ts",
16
16
  "import": "./dist/verify.js"
17
17
  },
18
+ "./kit": {
19
+ "types": "./dist/kit.d.ts",
20
+ "import": "./dist/kit.js"
21
+ },
18
22
  "./types": {
19
23
  "types": "./dist/generated-types.d.ts",
20
24
  "import": "./dist/generated-types.js"
21
25
  }
22
26
  },
23
27
  "files": [
24
- "dist"
28
+ "dist",
29
+ "LICENSE"
25
30
  ],
26
31
  "engines": {
27
32
  "node": ">=20.0.0"
28
33
  },
29
34
  "repository": {
30
35
  "type": "git",
31
- "url": "https://github.com/PcificLtd/pcific-kit.git",
36
+ "url": "git+https://github.com/PcificLtd/pcific-kit.git",
32
37
  "directory": "sdk"
33
38
  },
34
39
  "dependencies": {},
35
40
  "devDependencies": {
36
- "@types/node": "^22.20.5",
37
- "typescript": "^5.8.3",
38
- "vitest": "^5.0.5"
41
+ "@types/node": "^22.15.0",
42
+ "typescript": "^5.8.0",
43
+ "vitest": "^3.1.0"
39
44
  },
40
45
  "scripts": {
41
46
  "build": "tsc -p tsconfig.build.json",
42
- "test": "vitest run",
43
- "typecheck": "tsc -p tsconfig.build.json --noEmit"
47
+ "typecheck": "tsc -p tsconfig.build.json --noEmit",
48
+ "test": "vitest run"
44
49
  }
45
50
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;CAClF;AAgDD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,kBAAkB,CAoE5F"}
package/dist/auth.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],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