@paragraphcms/client 1.1.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 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
- `authors` and `reviewers` are aliases of the member listing endpoints exposed by the API.
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
@@ -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,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B,YAClB,cAAc;8BAUJ,MAAM,YAAY,cAAc;MAQtD;IAEF,QAAQ,CAAC,OAAO;yBACG,cAAc;oBAInB,MAAM,YAAY,cAAc;uBAYpC,mBAAmB,YACf,cAAc;uBAMX,MAAM,YAAY,cAAc;MAQ/C;IAEF,QAAQ,CAAC,EAAE;iCAED,mBAAmB,YACf,cAAc;wCAWlB,mBAAmB,YACf,cAAc;gCAWlB,sBAAsB,YAClB,cAAc;MAM1B;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,7 @@ 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;
5
6
  function resolveFetchImplementation(customFetch) {
6
7
  const fetchImpl = customFetch ?? globalThis.fetch;
7
8
  if (typeof fetchImpl !== "function") {
@@ -296,18 +297,33 @@ export class Client {
296
297
  query,
297
298
  options,
298
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
+ }),
299
305
  };
300
306
  authors = {
301
307
  list: (query, options) => this.requestList("GET", "/authors", {
302
308
  query,
303
309
  options,
304
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
+ }),
305
316
  };
306
317
  reviewers = {
307
318
  list: (query, options) => this.requestList("GET", "/reviewers", {
308
319
  query,
309
320
  options,
310
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
+ }),
311
327
  };
312
328
  statuses = {
313
329
  list: (query, options) => this.requestList("GET", "/statuses", {
@@ -381,6 +397,11 @@ export class Client {
381
397
  list: (options) => this.requestData("GET", "/locales", {
382
398
  options,
383
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
+ }),
384
405
  create: (body, options) => this.requestData("POST", "/locales", {
385
406
  body,
386
407
  options,
@@ -423,6 +444,58 @@ export class Client {
423
444
  requestList(method, path, config) {
424
445
  return this.requestJson(method, path, config);
425
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
+ }
426
499
  requestJson(method, path, config) {
427
500
  const url = buildUrl(this.baseUrl, path, config?.query);
428
501
  const request = createRequestDescriptor(method, url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paragraphcms/client",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Official Paragraph CMS TypeScript client for the Paragraph CMS v1 API.",
5
5
  "license": "ISC",
6
6
  "author": "Paragraph CMS",