@paragraphcms/client 1.0.0 → 1.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/README.md +10 -1
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +86 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -291,8 +291,11 @@ await client.media.upload({
|
|
|
291
291
|
|
|
292
292
|
```ts
|
|
293
293
|
client.members.list(query?, options?)
|
|
294
|
+
client.members.get(memberId, options?)
|
|
294
295
|
client.authors.list(query?, options?)
|
|
296
|
+
client.authors.get(authorId, options?)
|
|
295
297
|
client.reviewers.list(query?, options?)
|
|
298
|
+
client.reviewers.get(reviewerId, options?)
|
|
296
299
|
```
|
|
297
300
|
|
|
298
301
|
Supported `sort` fields:
|
|
@@ -301,7 +304,10 @@ Supported `sort` fields:
|
|
|
301
304
|
- `email`
|
|
302
305
|
- `created_at`
|
|
303
306
|
|
|
304
|
-
|
|
307
|
+
Notes:
|
|
308
|
+
|
|
309
|
+
- `members.get()`, `authors.get()`, and `reviewers.get()` are SDK convenience lookups built on top of the paginated list endpoints because the HTTP API does not expose `/members/{id}`, `/authors/{id}`, or `/reviewers/{id}` endpoints.
|
|
310
|
+
- `authors` and `reviewers` are aliases of the member listing endpoints exposed by the API.
|
|
305
311
|
|
|
306
312
|
### Statuses
|
|
307
313
|
|
|
@@ -358,10 +364,13 @@ Supported `sort` fields for `dataModels.list()`:
|
|
|
358
364
|
|
|
359
365
|
```ts
|
|
360
366
|
client.locales.list(options?)
|
|
367
|
+
client.locales.get(code, options?)
|
|
361
368
|
client.locales.create(body, options?)
|
|
362
369
|
client.locales.delete(code, options?)
|
|
363
370
|
```
|
|
364
371
|
|
|
372
|
+
`locales.get()` is an SDK convenience lookup over `locales.list()` because the HTTP API exposes locale listing and deletion by code, but not a dedicated locale detail endpoint.
|
|
373
|
+
|
|
365
374
|
### AI
|
|
366
375
|
|
|
367
376
|
```ts
|
package/dist/client.d.ts
CHANGED
|
@@ -33,12 +33,15 @@ export declare class Client {
|
|
|
33
33
|
};
|
|
34
34
|
readonly members: {
|
|
35
35
|
list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
|
|
36
|
+
get: (memberId: string, options?: RequestOptions) => Promise<Member>;
|
|
36
37
|
};
|
|
37
38
|
readonly authors: {
|
|
38
39
|
list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
|
|
40
|
+
get: (authorId: string, options?: RequestOptions) => Promise<Member>;
|
|
39
41
|
};
|
|
40
42
|
readonly reviewers: {
|
|
41
43
|
list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
|
|
44
|
+
get: (reviewerId: string, options?: RequestOptions) => Promise<Member>;
|
|
42
45
|
};
|
|
43
46
|
readonly statuses: {
|
|
44
47
|
list: (query?: StatusListQuery, options?: RequestOptions) => Promise<ListResponse<Status>>;
|
|
@@ -65,6 +68,7 @@ export declare class Client {
|
|
|
65
68
|
};
|
|
66
69
|
readonly locales: {
|
|
67
70
|
list: (options?: RequestOptions) => Promise<Locale[]>;
|
|
71
|
+
get: (code: string, options?: RequestOptions) => Promise<Locale>;
|
|
68
72
|
create: (body: CreateLocaleRequest, options?: RequestOptions) => Promise<LocaleMutationResult>;
|
|
69
73
|
delete: (code: string, options?: RequestOptions) => Promise<DeleteByCodeResult>;
|
|
70
74
|
};
|
|
@@ -77,6 +81,9 @@ export declare class Client {
|
|
|
77
81
|
getInfo(options?: RequestOptions): Promise<ApiInfo>;
|
|
78
82
|
private requestData;
|
|
79
83
|
private requestList;
|
|
84
|
+
private findListItem;
|
|
85
|
+
private findArrayItem;
|
|
86
|
+
private createLookupError;
|
|
80
87
|
private requestJson;
|
|
81
88
|
}
|
|
82
89
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAEhB,OAAO,EACP,aAAa,EACb,UAAU,EACV,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,4BAA4B,EAC5B,mBAAmB,EACnB,SAAS,EACT,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,KAAK,EACL,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,MAAM,EACN,oBAAoB,EACpB,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,eAAe,EACf,IAAI,EACJ,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EAEtB,cAAc,EACd,MAAM,EACN,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAEhB,OAAO,EACP,aAAa,EACb,UAAU,EACV,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,4BAA4B,EAC5B,mBAAmB,EACnB,SAAS,EACT,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,K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B;gBAEU,OAAO,EAAE,aAAa;IAiBlC,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc;IAIhC,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,WAAW;YAWL,YAAY;YA4CZ,aAAa;IA0B3B,OAAO,CAAC,iBAAiB;IAsBzB,OAAO,CAAC,WAAW;CA2HpB"}
|
package/dist/client.js
CHANGED
|
@@ -2,6 +2,17 @@ import { ParagraphApiError, ParagraphClientError, } from "./errors.js";
|
|
|
2
2
|
import { RequestRateLimiter } from "./rate-limiter.js";
|
|
3
3
|
const DEFAULT_BASE_URL = "https://api.paragraphcms.com/v1";
|
|
4
4
|
const DEFAULT_REQUESTS_PER_SECOND = 5;
|
|
5
|
+
const LOOKUP_PAGE_SIZE = 100;
|
|
6
|
+
function resolveFetchImplementation(customFetch) {
|
|
7
|
+
const fetchImpl = customFetch ?? globalThis.fetch;
|
|
8
|
+
if (typeof fetchImpl !== "function") {
|
|
9
|
+
throw new ParagraphClientError("No fetch implementation available. Pass `fetch` in the client options.");
|
|
10
|
+
}
|
|
11
|
+
if (fetchImpl === globalThis.fetch) {
|
|
12
|
+
return globalThis.fetch.bind(globalThis);
|
|
13
|
+
}
|
|
14
|
+
return fetchImpl;
|
|
15
|
+
}
|
|
5
16
|
function normalizeBaseUrl(baseUrl) {
|
|
6
17
|
const trimmed = baseUrl.trim().replace(/\/+$/, "");
|
|
7
18
|
if (!trimmed) {
|
|
@@ -286,18 +297,33 @@ export class Client {
|
|
|
286
297
|
query,
|
|
287
298
|
options,
|
|
288
299
|
}),
|
|
300
|
+
get: (memberId, options) => this.findListItem("/members", (member) => member.id === memberId, options, {
|
|
301
|
+
code: "member_not_found",
|
|
302
|
+
message: "Member not found.",
|
|
303
|
+
details: { memberId },
|
|
304
|
+
}),
|
|
289
305
|
};
|
|
290
306
|
authors = {
|
|
291
307
|
list: (query, options) => this.requestList("GET", "/authors", {
|
|
292
308
|
query,
|
|
293
309
|
options,
|
|
294
310
|
}),
|
|
311
|
+
get: (authorId, options) => this.findListItem("/authors", (author) => author.id === authorId, options, {
|
|
312
|
+
code: "author_not_found",
|
|
313
|
+
message: "Author not found.",
|
|
314
|
+
details: { authorId },
|
|
315
|
+
}),
|
|
295
316
|
};
|
|
296
317
|
reviewers = {
|
|
297
318
|
list: (query, options) => this.requestList("GET", "/reviewers", {
|
|
298
319
|
query,
|
|
299
320
|
options,
|
|
300
321
|
}),
|
|
322
|
+
get: (reviewerId, options) => this.findListItem("/reviewers", (reviewer) => reviewer.id === reviewerId, options, {
|
|
323
|
+
code: "reviewer_not_found",
|
|
324
|
+
message: "Reviewer not found.",
|
|
325
|
+
details: { reviewerId },
|
|
326
|
+
}),
|
|
301
327
|
};
|
|
302
328
|
statuses = {
|
|
303
329
|
list: (query, options) => this.requestList("GET", "/statuses", {
|
|
@@ -371,6 +397,11 @@ export class Client {
|
|
|
371
397
|
list: (options) => this.requestData("GET", "/locales", {
|
|
372
398
|
options,
|
|
373
399
|
}),
|
|
400
|
+
get: (code, options) => this.findArrayItem("/locales", (locale) => locale.code === code, options, {
|
|
401
|
+
code: "locale_not_found",
|
|
402
|
+
message: "Locale not found.",
|
|
403
|
+
details: { code },
|
|
404
|
+
}),
|
|
374
405
|
create: (body, options) => this.requestData("POST", "/locales", {
|
|
375
406
|
body,
|
|
376
407
|
options,
|
|
@@ -397,13 +428,9 @@ export class Client {
|
|
|
397
428
|
if (!options.apiKey.trim()) {
|
|
398
429
|
throw new ParagraphClientError("`apiKey` is required.");
|
|
399
430
|
}
|
|
400
|
-
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
401
|
-
if (typeof fetchImpl !== "function") {
|
|
402
|
-
throw new ParagraphClientError("No fetch implementation available. Pass `fetch` in the client options.");
|
|
403
|
-
}
|
|
404
431
|
this.apiKey = options.apiKey.trim();
|
|
405
432
|
this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
|
|
406
|
-
this.fetchImpl =
|
|
433
|
+
this.fetchImpl = resolveFetchImplementation(options.fetch);
|
|
407
434
|
this.defaultHeaders = new Headers(options.headers);
|
|
408
435
|
this.timeoutMs = options.timeoutMs;
|
|
409
436
|
this.limiter = new RequestRateLimiter(options.maxRequestsPerSecond ?? DEFAULT_REQUESTS_PER_SECOND);
|
|
@@ -417,6 +444,58 @@ export class Client {
|
|
|
417
444
|
requestList(method, path, config) {
|
|
418
445
|
return this.requestJson(method, path, config);
|
|
419
446
|
}
|
|
447
|
+
async findListItem(path, predicate, options, error) {
|
|
448
|
+
let page = 1;
|
|
449
|
+
while (true) {
|
|
450
|
+
const response = await this.requestList("GET", path, {
|
|
451
|
+
query: {
|
|
452
|
+
page,
|
|
453
|
+
limit: LOOKUP_PAGE_SIZE,
|
|
454
|
+
},
|
|
455
|
+
options,
|
|
456
|
+
});
|
|
457
|
+
const match = response.data.find(predicate);
|
|
458
|
+
if (match) {
|
|
459
|
+
return match;
|
|
460
|
+
}
|
|
461
|
+
if (!response.meta.has_next_page) {
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
page += 1;
|
|
465
|
+
}
|
|
466
|
+
throw this.createLookupError("GET", path, {
|
|
467
|
+
query: {
|
|
468
|
+
page,
|
|
469
|
+
limit: LOOKUP_PAGE_SIZE,
|
|
470
|
+
},
|
|
471
|
+
code: error.code,
|
|
472
|
+
message: error.message,
|
|
473
|
+
details: error.details,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
async findArrayItem(path, predicate, options, error) {
|
|
477
|
+
const items = await this.requestData("GET", path, {
|
|
478
|
+
options,
|
|
479
|
+
});
|
|
480
|
+
const match = items.find(predicate);
|
|
481
|
+
if (match) {
|
|
482
|
+
return match;
|
|
483
|
+
}
|
|
484
|
+
throw this.createLookupError("GET", path, {
|
|
485
|
+
code: error.code,
|
|
486
|
+
message: error.message,
|
|
487
|
+
details: error.details,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
createLookupError(method, path, config) {
|
|
491
|
+
return new ParagraphApiError({
|
|
492
|
+
status: 404,
|
|
493
|
+
code: config.code,
|
|
494
|
+
message: config.message,
|
|
495
|
+
details: config.details,
|
|
496
|
+
request: createRequestDescriptor(method, buildUrl(this.baseUrl, path, config.query)),
|
|
497
|
+
});
|
|
498
|
+
}
|
|
420
499
|
requestJson(method, path, config) {
|
|
421
500
|
const url = buildUrl(this.baseUrl, path, config?.query);
|
|
422
501
|
const request = createRequestDescriptor(method, url);
|
|
@@ -448,7 +527,8 @@ export class Client {
|
|
|
448
527
|
}
|
|
449
528
|
const requestSignal = createRequestSignal(config?.options?.signal, timeoutMs);
|
|
450
529
|
try {
|
|
451
|
-
const
|
|
530
|
+
const fetchImpl = this.fetchImpl;
|
|
531
|
+
const response = await fetchImpl(url, {
|
|
452
532
|
method,
|
|
453
533
|
headers,
|
|
454
534
|
body,
|