@pcific/sdk 0.0.0-stage → 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/dist/client.js ADDED
@@ -0,0 +1,607 @@
1
+ import { resolvePcificAuth } from "./auth.js";
2
+ import { PcificStreamError } from "./errors.js";
3
+ import { PcificHttpClient } from "./http.js";
4
+ import { isJsonObject, isString } from "./json.js";
5
+ import { normalizeUpload } from "./multipart.js";
6
+ import { parseSseStream } from "./sse.js";
7
+ import { verifyMessageCheckReceipt, verifyPixelTraceManifest, } from "./verify.js";
8
+ const DEFAULT_AI_NOTICE_TTL_MS = 5 * 60 * 1000;
9
+ const ORBIT_TERMINAL_STATUSES = new Set(["listing", "questions", "failed", "cancelled"]);
10
+ const SAFEGUARD_TERMINAL_STATUSES = new Set(["done", "questions", "failed"]);
11
+ function encodePathSegment(segment) {
12
+ return encodeURIComponent(segment);
13
+ }
14
+ function isStringId(value) {
15
+ return typeof value === "string";
16
+ }
17
+ function isRawListingJson(value) {
18
+ return typeof value === "string";
19
+ }
20
+ export class PcificClient {
21
+ mode;
22
+ http;
23
+ aiNoticeCache = new Map();
24
+ defaultAiNoticeTtlMs;
25
+ constructor(options = {}) {
26
+ const auth = resolvePcificAuth(options);
27
+ this.mode = auth.mode;
28
+ this.defaultAiNoticeTtlMs = options.aiNoticeTtlMs ?? DEFAULT_AI_NOTICE_TTL_MS;
29
+ this.http = new PcificHttpClient({
30
+ apiKey: auth.apiKey,
31
+ baseUrl: options.baseUrl,
32
+ signingSecret: options.signingSecret,
33
+ marketplaceId: options.marketplaceId,
34
+ testAiStub: options.testAiStub,
35
+ fetch: options.fetch,
36
+ maxRetries: options.maxRetries,
37
+ baseDelayMs: options.baseDelayMs,
38
+ maxDelayMs: options.maxDelayMs,
39
+ sleep: options.sleep,
40
+ now: options.now,
41
+ random: options.random,
42
+ });
43
+ }
44
+ /**
45
+ * Reads and caches the shop's aiNotice from GET /api/v1/marketplace/settings.
46
+ * Explicitly preserves "" (empty string) as a cached valid value (never treating "" as a cache miss).
47
+ */
48
+ async getAiNotice(options = {}) {
49
+ const cacheKey = options.marketplaceId ?? this.http.config.marketplaceId ?? "__default__";
50
+ const nowMs = this.http.config.now();
51
+ const ttlMs = options.ttlMs ?? this.defaultAiNoticeTtlMs;
52
+ if (!options.forceRefresh && this.aiNoticeCache.has(cacheKey)) {
53
+ const entry = this.aiNoticeCache.get(cacheKey);
54
+ if (entry.expiresAt > nowMs) {
55
+ return entry.value;
56
+ }
57
+ }
58
+ const settings = await this.account.getSettings(options);
59
+ const notice = isString(settings.aiNotice) ? settings.aiNotice : "";
60
+ this.aiNoticeCache.set(cacheKey, { value: notice, expiresAt: nowMs + ttlMs });
61
+ return notice;
62
+ }
63
+ invalidateAiNoticeCache(marketplaceId) {
64
+ if (marketplaceId === undefined) {
65
+ this.aiNoticeCache.clear();
66
+ return;
67
+ }
68
+ this.aiNoticeCache.delete(marketplaceId);
69
+ }
70
+ // --- Images ----------------------------------------------------------------
71
+ images = {
72
+ upload: async (files, options) => {
73
+ const formData = new FormData();
74
+ files.forEach((file, index) => {
75
+ const normalized = normalizeUpload(file, `photo-${index + 1}.jpg`, "image/jpeg");
76
+ formData.append("photos", normalized.blob, normalized.filename);
77
+ });
78
+ return this.http.requestJson({
79
+ ...options,
80
+ method: "POST",
81
+ path: "/api/v1/images",
82
+ formData,
83
+ });
84
+ },
85
+ get: (id, options) => this.http.requestJson({
86
+ ...options,
87
+ method: "GET",
88
+ path: `/api/v1/images/${encodePathSegment(id)}`,
89
+ }),
90
+ delete: (id, options) => this.http.requestVoid({
91
+ ...options,
92
+ method: "DELETE",
93
+ path: `/api/v1/images/${encodePathSegment(id)}`,
94
+ }),
95
+ };
96
+ // --- Orbit -----------------------------------------------------------------
97
+ orbit = {
98
+ createListing: (input, options) => this.http.requestJson({
99
+ ...options,
100
+ method: "POST",
101
+ path: "/api/v1/listings",
102
+ jsonBody: input,
103
+ }),
104
+ getListing: (id, options) => this.http.requestJson({
105
+ ...options,
106
+ method: "GET",
107
+ path: `/api/v1/listings/${encodePathSegment(id)}`,
108
+ }),
109
+ streamListing: async function* (idOrInput, options) {
110
+ const stream = isStringId(idOrInput)
111
+ ? await this.http.requestStream({
112
+ ...options,
113
+ method: "GET",
114
+ path: `/api/v1/listings/${encodePathSegment(idOrInput)}`,
115
+ })
116
+ : await this.http.requestStream({
117
+ ...options,
118
+ method: "POST",
119
+ path: "/api/v1/listings",
120
+ jsonBody: idOrInput,
121
+ });
122
+ yield* parseSseStream(stream);
123
+ }.bind(this),
124
+ waitForListing: async (idOrInput, options = {}) => {
125
+ if (options.mode !== "poll") {
126
+ let lastSnapshot;
127
+ for await (const frame of this.orbit.streamListing(idOrInput, options)) {
128
+ if (frame.event === "status" && isJsonObject(frame.data)) {
129
+ lastSnapshot = frame.data;
130
+ options.onStatus?.(frame.data);
131
+ }
132
+ else if (frame.event === "done") {
133
+ return frame.data;
134
+ }
135
+ else if (frame.event === "error") {
136
+ if (isJsonObject(frame.data) && "status" in frame.data) {
137
+ return frame.data;
138
+ }
139
+ throw new PcificStreamError(isJsonObject(frame.data) && isString(frame.data.error)
140
+ ? frame.data.error
141
+ : "Orbit stream failed.", {
142
+ code: isJsonObject(frame.data) && isString(frame.data.code) ? frame.data.code : undefined,
143
+ tryThis: isJsonObject(frame.data) && isString(frame.data.tryThis) ? frame.data.tryThis : undefined,
144
+ payload: frame.data,
145
+ });
146
+ }
147
+ }
148
+ if (lastSnapshot)
149
+ return lastSnapshot;
150
+ throw new PcificStreamError("Orbit event stream closed before reaching a terminal state.");
151
+ }
152
+ const id = isStringId(idOrInput)
153
+ ? idOrInput
154
+ : String((await this.orbit.createListing(idOrInput, options)).runId ?? "");
155
+ const pollIntervalMs = options.pollIntervalMs ?? 1000;
156
+ const timeoutMs = options.timeoutMs ?? 180_000;
157
+ const deadline = this.http.config.now() + timeoutMs;
158
+ while (true) {
159
+ const snapshot = await this.orbit.getListing(id, options);
160
+ options.onStatus?.(snapshot);
161
+ const status = isString(snapshot.status) ? snapshot.status : "";
162
+ if (ORBIT_TERMINAL_STATUSES.has(status) && snapshot.processing !== true) {
163
+ return snapshot;
164
+ }
165
+ if (this.http.config.now() >= deadline) {
166
+ return snapshot;
167
+ }
168
+ await this.http.config.sleep(pollIntervalMs);
169
+ }
170
+ },
171
+ answerQuestions: (id, answers, options) => this.http.requestJson({
172
+ ...options,
173
+ method: "POST",
174
+ path: `/api/v1/listings/${encodePathSegment(id)}/answers`,
175
+ jsonBody: { answers },
176
+ }),
177
+ retry: (id, options) => this.http.requestJson({
178
+ ...options,
179
+ method: "POST",
180
+ path: `/api/v1/listings/${encodePathSegment(id)}/retry`,
181
+ }),
182
+ cancel: (id, options) => this.http.requestJson({
183
+ ...options,
184
+ method: "POST",
185
+ path: `/api/v1/listings/${encodePathSegment(id)}/cancel`,
186
+ }),
187
+ publish: (id, options) => this.http.requestJson({
188
+ ...options,
189
+ method: "POST",
190
+ path: `/api/v1/listings/${encodePathSegment(id)}/publish`,
191
+ }),
192
+ check: (id, options) => this.http.requestJson({
193
+ ...options,
194
+ method: "POST",
195
+ path: `/api/v1/listings/${encodePathSegment(id)}/check`,
196
+ }),
197
+ submitEdits: (id, item, options) => this.http.requestJson({
198
+ ...options,
199
+ method: "POST",
200
+ path: `/api/v1/listings/${encodePathSegment(id)}/edits`,
201
+ jsonBody: { item },
202
+ }),
203
+ chat: (id, input, options) => this.http.requestJson({
204
+ ...options,
205
+ method: "POST",
206
+ path: `/api/v1/listings/${encodePathSegment(id)}/chat`,
207
+ jsonBody: input,
208
+ }),
209
+ reportOutcome: (id, input, options) => this.http.requestJson({
210
+ ...options,
211
+ method: "POST",
212
+ path: `/api/v1/listings/${encodePathSegment(id)}/outcome`,
213
+ jsonBody: input,
214
+ }),
215
+ getSettings: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/orbit/settings" }),
216
+ updateSettings: (settings, options) => this.http.requestJson({
217
+ ...options,
218
+ method: "PUT",
219
+ path: "/api/v1/orbit/settings",
220
+ jsonBody: settings,
221
+ }),
222
+ };
223
+ // --- Safeguard -------------------------------------------------------------
224
+ safeguard = {
225
+ createReview: (input, options) => this.http.requestJson({
226
+ ...options,
227
+ method: "POST",
228
+ path: "/api/v1/safeguard/reviews",
229
+ jsonBody: input,
230
+ }),
231
+ getReview: (id, options) => this.http.requestJson({
232
+ ...options,
233
+ method: "GET",
234
+ path: `/api/v1/safeguard/reviews/${encodePathSegment(id)}`,
235
+ }),
236
+ streamReview: async function* (idOrInput, options) {
237
+ const stream = isStringId(idOrInput)
238
+ ? await this.http.requestStream({
239
+ ...options,
240
+ method: "GET",
241
+ path: `/api/v1/safeguard/reviews/${encodePathSegment(idOrInput)}`,
242
+ })
243
+ : await this.http.requestStream({
244
+ ...options,
245
+ method: "POST",
246
+ path: "/api/v1/safeguard/reviews",
247
+ jsonBody: idOrInput,
248
+ });
249
+ yield* parseSseStream(stream);
250
+ }.bind(this),
251
+ waitForReview: async (idOrInput, options = {}) => {
252
+ if (options.mode !== "poll") {
253
+ let lastSnapshot;
254
+ for await (const frame of this.safeguard.streamReview(idOrInput, options)) {
255
+ if (frame.event === "status" && isJsonObject(frame.data)) {
256
+ lastSnapshot = frame.data;
257
+ options.onStatus?.(frame.data);
258
+ }
259
+ else if (frame.event === "done") {
260
+ return frame.data;
261
+ }
262
+ else if (frame.event === "error") {
263
+ if (isJsonObject(frame.data) && "status" in frame.data) {
264
+ return frame.data;
265
+ }
266
+ throw new PcificStreamError(isJsonObject(frame.data) && isString(frame.data.error)
267
+ ? frame.data.error
268
+ : "Safeguard stream failed.", {
269
+ code: isJsonObject(frame.data) && isString(frame.data.code) ? frame.data.code : undefined,
270
+ tryThis: isJsonObject(frame.data) && isString(frame.data.tryThis) ? frame.data.tryThis : undefined,
271
+ payload: frame.data,
272
+ });
273
+ }
274
+ }
275
+ if (lastSnapshot)
276
+ return lastSnapshot;
277
+ throw new PcificStreamError("Safeguard event stream closed before reaching a terminal state.");
278
+ }
279
+ const id = isStringId(idOrInput)
280
+ ? idOrInput
281
+ : String((await this.safeguard.createReview(idOrInput, options)).reviewId ?? "");
282
+ const pollIntervalMs = options.pollIntervalMs ?? 1000;
283
+ const timeoutMs = options.timeoutMs ?? 180_000;
284
+ const deadline = this.http.config.now() + timeoutMs;
285
+ while (true) {
286
+ const snapshot = await this.safeguard.getReview(id, options);
287
+ options.onStatus?.(snapshot);
288
+ const status = isString(snapshot.status) ? snapshot.status : "";
289
+ if (SAFEGUARD_TERMINAL_STATUSES.has(status)) {
290
+ return snapshot;
291
+ }
292
+ if (this.http.config.now() >= deadline) {
293
+ return snapshot;
294
+ }
295
+ await this.http.config.sleep(pollIntervalMs);
296
+ }
297
+ },
298
+ answerQuestions: (id, answers, options) => this.http.requestJson({
299
+ ...options,
300
+ method: "POST",
301
+ path: `/api/v1/safeguard/reviews/${encodePathSegment(id)}/answers`,
302
+ jsonBody: { answers },
303
+ }),
304
+ retry: (id, options) => this.http.requestJson({
305
+ ...options,
306
+ method: "POST",
307
+ path: `/api/v1/safeguard/reviews/${encodePathSegment(id)}/retry`,
308
+ }),
309
+ getSettings: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/safeguard/settings" }),
310
+ updateSettings: (settings, options) => this.http.requestJson({
311
+ ...options,
312
+ method: "PUT",
313
+ path: "/api/v1/safeguard/settings",
314
+ jsonBody: settings,
315
+ }),
316
+ };
317
+ // --- Ask PCIFIC ------------------------------------------------------------
318
+ askPcific = {
319
+ ask: (input, options) => this.http.requestJson({
320
+ ...options,
321
+ method: "POST",
322
+ path: "/api/v1/ask-pcific",
323
+ jsonBody: input,
324
+ }),
325
+ askStream: async function* (input, options) {
326
+ const stream = await this.http.requestStream({
327
+ ...options,
328
+ method: "POST",
329
+ path: "/api/v1/ask-pcific",
330
+ jsonBody: input,
331
+ });
332
+ yield* parseSseStream(stream);
333
+ }.bind(this),
334
+ getSettings: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/ask-pcific/settings" }),
335
+ updateSettings: (settings, options) => this.http.requestJson({
336
+ ...options,
337
+ method: "PUT",
338
+ path: "/api/v1/ask-pcific/settings",
339
+ jsonBody: settings,
340
+ }),
341
+ };
342
+ // --- PixelTrace ------------------------------------------------------------
343
+ pixelTrace = {
344
+ createCapture: (input, options) => this.http.requestJson({
345
+ ...options,
346
+ method: "POST",
347
+ path: "/api/v1/pixel-trace/captures",
348
+ jsonBody: input,
349
+ }),
350
+ getCapture: (captureId, options) => this.http.requestJson({
351
+ ...options,
352
+ method: "GET",
353
+ path: `/api/v1/pixel-trace/captures/${encodePathSegment(captureId)}`,
354
+ }),
355
+ completeCapture: (captureId, input = {}, options) => this.http.requestJson({
356
+ ...options,
357
+ method: "POST",
358
+ path: `/api/v1/pixel-trace/captures/${encodePathSegment(captureId)}/complete`,
359
+ jsonBody: input,
360
+ }),
361
+ publishCapture: (captureId, input = {}, options) => this.pixelTrace.completeCapture(captureId, input, options),
362
+ retractCapture: (captureId, options) => this.http.requestJson({
363
+ ...options,
364
+ method: "POST",
365
+ path: `/api/v1/pixel-trace/captures/${encodePathSegment(captureId)}/retract`,
366
+ }),
367
+ checkPhoto: async (photo, options) => {
368
+ const normalized = normalizeUpload(photo, "photo.jpg", "image/jpeg");
369
+ const bytes = new Uint8Array(await normalized.blob.arrayBuffer());
370
+ return this.http.requestJson({
371
+ ...options,
372
+ method: "POST",
373
+ path: "/api/v1/pixel-trace/check",
374
+ binaryBody: { bytes, contentType: normalized.contentType },
375
+ });
376
+ },
377
+ getCertificate: (code, options) => this.http.requestJson({
378
+ ...options,
379
+ method: "GET",
380
+ path: `/api/v1/pixel-trace/certificates/${encodePathSegment(code)}`,
381
+ auth: false,
382
+ }),
383
+ getJwks: (options) => this.http.requestJson({
384
+ ...options,
385
+ method: "GET",
386
+ path: "/api/v1/pixel-trace/jwks.json",
387
+ auth: false,
388
+ }),
389
+ verifyManifest: (input) => verifyPixelTraceManifest({
390
+ ...input,
391
+ jwksUrl: input.jwksUrl ?? `${this.http.config.baseUrl}/api/v1/pixel-trace/jwks.json`,
392
+ fetch: this.http.config.fetch,
393
+ }),
394
+ uploadTestPhoto: async (captureId, photo, options) => {
395
+ const normalized = normalizeUpload(photo, "photo.jpg", "image/jpeg");
396
+ const bytes = new Uint8Array(await normalized.blob.arrayBuffer());
397
+ return this.http.requestJson({
398
+ ...options,
399
+ method: "POST",
400
+ path: `/api/v1/pixel-trace/captures/${encodePathSegment(captureId)}/test-photos`,
401
+ binaryBody: { bytes, contentType: normalized.contentType },
402
+ });
403
+ },
404
+ confirmTestCapture: (captureId, input = {}, options) => this.http.requestJson({
405
+ ...options,
406
+ method: "POST",
407
+ path: `/api/v1/pixel-trace/captures/${encodePathSegment(captureId)}/test-confirm`,
408
+ jsonBody: input,
409
+ }),
410
+ };
411
+ // --- Message Check ---------------------------------------------------------
412
+ messageCheck = {
413
+ check: (input, options) => {
414
+ const body = { text: input.text };
415
+ if (input.conversationId !== undefined)
416
+ body.conversationId = input.conversationId;
417
+ if (input.sender !== undefined)
418
+ body.sender = input.sender;
419
+ if (input.context !== undefined)
420
+ body.context = input.context;
421
+ if (input.confirmToken !== undefined)
422
+ body.confirmToken = input.confirmToken;
423
+ if (input.metadata !== undefined)
424
+ body.metadata = input.metadata;
425
+ return this.http.requestJson({
426
+ ...options,
427
+ method: "POST",
428
+ path: "/api/v1/message-check",
429
+ jsonBody: body,
430
+ });
431
+ },
432
+ present: (input, options) => this.http.requestJson({
433
+ ...options,
434
+ method: "POST",
435
+ path: "/api/v1/message-check/present",
436
+ jsonBody: input,
437
+ }),
438
+ verifyReceiptOnline: (input, options) => {
439
+ const body = {
440
+ receipt: input.receipt,
441
+ text: input.text,
442
+ };
443
+ if (input.maskedText !== undefined)
444
+ body.maskedText = input.maskedText;
445
+ if (input.conversationId !== undefined)
446
+ body.conversationId = input.conversationId;
447
+ if (input.senderId !== undefined)
448
+ body.senderId = input.senderId;
449
+ return this.http.requestJson({
450
+ ...options,
451
+ method: "POST",
452
+ path: "/api/v1/message-check/receipts/verify",
453
+ jsonBody: body,
454
+ });
455
+ },
456
+ verifyReceiptOffline: (input) => verifyMessageCheckReceipt({
457
+ ...input,
458
+ jwksUrl: input.jwksUrl ?? `${this.http.config.baseUrl}/.well-known/jwks.json`,
459
+ fetch: this.http.config.fetch,
460
+ }),
461
+ getPolicy: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/message-check/policy" }),
462
+ updatePolicy: (policy, options) => this.http.requestJson({
463
+ ...options,
464
+ method: "PUT",
465
+ path: "/api/v1/message-check/policy",
466
+ jsonBody: policy,
467
+ }),
468
+ listFlags: (query, options) => this.http.requestJson({
469
+ ...options,
470
+ method: "GET",
471
+ path: "/api/v1/message-check/flags",
472
+ query,
473
+ }),
474
+ reviewFlag: (id, review, options) => this.http.requestJson({
475
+ ...options,
476
+ method: "PUT",
477
+ path: `/api/v1/message-check/flags/${encodePathSegment(id)}/review`,
478
+ jsonBody: { review },
479
+ }),
480
+ };
481
+ // --- Dispute Pack ----------------------------------------------------------
482
+ disputePack = {
483
+ pushListing: (input, options) => {
484
+ const formData = new FormData();
485
+ formData.append("listingRef", input.listingRef);
486
+ formData.append("listing", isRawListingJson(input.listing) ? input.listing : JSON.stringify(input.listing));
487
+ if (input.occurredAt !== undefined) {
488
+ formData.append("occurredAt", input.occurredAt);
489
+ }
490
+ if (input.photos) {
491
+ input.photos.forEach((photo, index) => {
492
+ const normalized = normalizeUpload(photo, `photo-${index + 1}.jpg`, "image/jpeg");
493
+ formData.append("photos", normalized.blob, normalized.filename);
494
+ });
495
+ }
496
+ return this.http.requestJson({
497
+ ...options,
498
+ method: "POST",
499
+ path: "/api/v1/dispute-pack/listings",
500
+ formData,
501
+ });
502
+ },
503
+ captureListing: (input, options) => this.http.requestJson({
504
+ ...options,
505
+ method: "POST",
506
+ path: "/api/v1/dispute-pack/listings/capture",
507
+ jsonBody: input,
508
+ }),
509
+ recordSale: (input, options) => this.http.requestJson({
510
+ ...options,
511
+ method: "POST",
512
+ path: "/api/v1/dispute-pack/sales",
513
+ jsonBody: {
514
+ listingRef: input.listingRef,
515
+ buyerId: input.buyerId,
516
+ orderId: input.orderId,
517
+ soldAt: input.soldAt,
518
+ price: {
519
+ amount: input.price.amount,
520
+ currency: input.price.currency,
521
+ },
522
+ },
523
+ }),
524
+ recordMessage: (input, options) => {
525
+ const body = {
526
+ listingRef: input.listingRef,
527
+ buyerId: input.buyerId,
528
+ role: input.role,
529
+ messageId: input.messageId,
530
+ sentAt: input.sentAt,
531
+ text: input.text,
532
+ };
533
+ if (input.attachments !== undefined)
534
+ body.attachments = input.attachments;
535
+ return this.http.requestJson({
536
+ ...options,
537
+ method: "POST",
538
+ path: "/api/v1/dispute-pack/messages",
539
+ jsonBody: body,
540
+ });
541
+ },
542
+ recordTracking: (input, options) => this.http.requestJson({
543
+ ...options,
544
+ method: "POST",
545
+ path: "/api/v1/dispute-pack/tracking",
546
+ jsonBody: input,
547
+ }),
548
+ createDispute: (input, options) => this.http.requestJson({
549
+ ...options,
550
+ method: "POST",
551
+ path: "/api/v1/dispute-pack/disputes",
552
+ jsonBody: input,
553
+ }),
554
+ getDispute: (id, query, options) => this.http.requestJson({
555
+ ...options,
556
+ method: "GET",
557
+ path: `/api/v1/dispute-pack/disputes/${encodePathSegment(id)}`,
558
+ query,
559
+ }),
560
+ getDisputePdf: (id, query, options) => this.http.requestBinary({
561
+ ...options,
562
+ method: "GET",
563
+ path: `/api/v1/dispute-pack/disputes/${encodePathSegment(id)}/pdf`,
564
+ query,
565
+ accept: "application/pdf",
566
+ }),
567
+ releaseDispute: (id, input, options) => this.http.requestJson({
568
+ ...options,
569
+ method: "POST",
570
+ path: `/api/v1/dispute-pack/disputes/${encodePathSegment(id)}/release`,
571
+ jsonBody: input,
572
+ }),
573
+ };
574
+ // --- Embed -----------------------------------------------------------------
575
+ embed = {
576
+ createSession: (input, options) => this.http.requestJson({
577
+ ...options,
578
+ method: "POST",
579
+ path: "/api/v1/embed-sessions",
580
+ jsonBody: input,
581
+ }),
582
+ getBranding: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/embed/branding" }),
583
+ updateBranding: (branding, options) => this.http.requestJson({
584
+ ...options,
585
+ method: "PUT",
586
+ path: "/api/v1/embed/branding",
587
+ jsonBody: branding,
588
+ }),
589
+ };
590
+ // --- Account ---------------------------------------------------------------
591
+ account = {
592
+ getKey: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/key" }),
593
+ getMe: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/me" }),
594
+ getUsage: (query, options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/usage", query }),
595
+ listMarketplaces: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/marketplaces" }),
596
+ getSettings: (options) => this.http.requestJson({ ...options, method: "GET", path: "/api/v1/marketplace/settings" }),
597
+ updateSettings: (settings, options) => this.http.requestJson({
598
+ ...options,
599
+ method: "PUT",
600
+ path: "/api/v1/marketplace/settings",
601
+ jsonBody: settings,
602
+ }),
603
+ };
604
+ }
605
+ export function createPcificClient(options = {}) {
606
+ return new PcificClient(options);
607
+ }
@@ -0,0 +1,51 @@
1
+ import type { JsonValue } from "./json.js";
2
+ export interface PcificProblem {
3
+ path?: string;
4
+ where?: string;
5
+ problem?: string;
6
+ tryThis?: string;
7
+ category?: string;
8
+ }
9
+ export interface PcificApiErrorInit {
10
+ status: number;
11
+ code: string;
12
+ error: string;
13
+ tryThis: string;
14
+ where?: string;
15
+ retryable?: boolean;
16
+ problems?: PcificProblem[];
17
+ requestId?: string;
18
+ existingId?: string;
19
+ rawBody?: JsonValue;
20
+ }
21
+ export declare class PcificConfigError extends Error {
22
+ readonly code: string;
23
+ readonly tryThis: string;
24
+ constructor(message: string, options?: {
25
+ code?: string;
26
+ tryThis?: string;
27
+ });
28
+ }
29
+ export declare class PcificApiError extends Error {
30
+ readonly status: number;
31
+ readonly code: string;
32
+ readonly error: string;
33
+ readonly tryThis: string;
34
+ readonly where?: string;
35
+ readonly retryable: boolean;
36
+ readonly problems: PcificProblem[];
37
+ readonly requestId?: string;
38
+ readonly existingId?: string;
39
+ readonly rawBody?: JsonValue;
40
+ constructor(init: PcificApiErrorInit);
41
+ }
42
+ export declare class PcificStreamError extends Error {
43
+ readonly code?: string;
44
+ readonly tryThis?: string;
45
+ readonly payload?: JsonValue;
46
+ constructor(message: string, options?: {
47
+ code?: string;
48
+ tryThis?: string;
49
+ payload?: JsonValue;
50
+ });
51
+ }