@paragraphcms/client 1.1.0 → 1.3.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
@@ -199,12 +199,14 @@ Returns the public `/v1` info payload:
199
199
  client.pages.list(query?, options?)
200
200
  client.pages.create(body?, options?)
201
201
  client.pages.get(pageId, query?, options?)
202
+ client.pages.getBySlug(slug, options?)
202
203
  client.pages.update(pageId, body, options?)
203
204
  client.pages.delete(pageId, options?)
204
205
  client.pages.restore(pageId, options?)
205
206
  client.pages.permanentlyDelete(pageId, options?)
206
207
  client.pages.duplicate(pageId, options?)
207
208
  client.pages.createTranslation(pageId, body, options?)
209
+ client.page.getBySlug(slug, options?)
208
210
  ```
209
211
 
210
212
  Supported `sort` fields for `pages.list()`:
@@ -220,6 +222,8 @@ Notes:
220
222
  - `label_id` is passed as `string[]` in the SDK and serialized to the API CSV format automatically.
221
223
  - `content` is present in page list results only when `include_content: true`.
222
224
  - Page responses should be treated as Tiptap JSON arrays. `content_format` is no longer required in the response shape.
225
+ - `pages.getBySlug()` is an SDK convenience lookup built on top of `pages.list({ slug })`, and then fetches the full page details by ID.
226
+ - `page.getBySlug()` is a short alias for the same lookup.
223
227
 
224
228
  ### Collections
225
229
 
@@ -291,8 +295,11 @@ await client.media.upload({
291
295
 
292
296
  ```ts
293
297
  client.members.list(query?, options?)
298
+ client.members.get(memberId, options?)
294
299
  client.authors.list(query?, options?)
300
+ client.authors.get(authorId, options?)
295
301
  client.reviewers.list(query?, options?)
302
+ client.reviewers.get(reviewerId, options?)
296
303
  ```
297
304
 
298
305
  Supported `sort` fields:
@@ -301,7 +308,10 @@ Supported `sort` fields:
301
308
  - `email`
302
309
  - `created_at`
303
310
 
304
- `authors` and `reviewers` are aliases of the member listing endpoints exposed by the API.
311
+ Notes:
312
+
313
+ - `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.
314
+ - `authors` and `reviewers` are aliases of the member listing endpoints exposed by the API.
305
315
 
306
316
  ### Statuses
307
317
 
@@ -358,10 +368,13 @@ Supported `sort` fields for `dataModels.list()`:
358
368
 
359
369
  ```ts
360
370
  client.locales.list(options?)
371
+ client.locales.get(code, options?)
361
372
  client.locales.create(body, options?)
362
373
  client.locales.delete(code, options?)
363
374
  ```
364
375
 
376
+ `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.
377
+
365
378
  ### AI
366
379
 
367
380
  ```ts
package/dist/client.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare class Client {
10
10
  list: (query?: PageListQuery, options?: RequestOptions) => Promise<ListResponse<PageSummary>>;
11
11
  create: (body?: CreatePageRequest, options?: RequestOptions) => Promise<PageMutationResult>;
12
12
  get: (pageId: string, query?: GetPageQuery, options?: RequestOptions) => Promise<Page>;
13
+ getBySlug: (slug: string, options?: RequestOptions) => Promise<Page>;
13
14
  update: (pageId: string, body: UpdatePageRequest, options?: RequestOptions) => Promise<PageMutationResult>;
14
15
  delete: (pageId: string, options?: RequestOptions) => Promise<DeleteResult>;
15
16
  restore: (pageId: string, options?: RequestOptions) => Promise<PageRestoreResult>;
@@ -17,6 +18,9 @@ export declare class Client {
17
18
  duplicate: (pageId: string, options?: RequestOptions) => Promise<PageMutationResult>;
18
19
  createTranslation: (pageId: string, body: CreatePageTranslationRequest, options?: RequestOptions) => Promise<PageMutationResult>;
19
20
  };
21
+ readonly page: {
22
+ getBySlug: (slug: string, options?: RequestOptions) => Promise<Page>;
23
+ };
20
24
  readonly collections: {
21
25
  list: (query?: CollectionListQuery, options?: RequestOptions) => Promise<ListResponse<Collection>>;
22
26
  create: (body: CreateCollectionRequest, options?: RequestOptions) => Promise<CollectionMutationResult>;
@@ -33,12 +37,15 @@ export declare class Client {
33
37
  };
34
38
  readonly members: {
35
39
  list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
40
+ get: (memberId: string, options?: RequestOptions) => Promise<Member>;
36
41
  };
37
42
  readonly authors: {
38
43
  list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
44
+ get: (authorId: string, options?: RequestOptions) => Promise<Member>;
39
45
  };
40
46
  readonly reviewers: {
41
47
  list: (query?: MemberListQuery, options?: RequestOptions) => Promise<ListResponse<Member>>;
48
+ get: (reviewerId: string, options?: RequestOptions) => Promise<Member>;
42
49
  };
43
50
  readonly statuses: {
44
51
  list: (query?: StatusListQuery, options?: RequestOptions) => Promise<ListResponse<Status>>;
@@ -65,6 +72,7 @@ export declare class Client {
65
72
  };
66
73
  readonly locales: {
67
74
  list: (options?: RequestOptions) => Promise<Locale[]>;
75
+ get: (code: string, options?: RequestOptions) => Promise<Locale>;
68
76
  create: (body: CreateLocaleRequest, options?: RequestOptions) => Promise<LocaleMutationResult>;
69
77
  delete: (code: string, options?: RequestOptions) => Promise<DeleteByCodeResult>;
70
78
  };
@@ -77,6 +85,10 @@ export declare class Client {
77
85
  getInfo(options?: RequestOptions): Promise<ApiInfo>;
78
86
  private requestData;
79
87
  private requestList;
88
+ private getPageBySlug;
89
+ private findListItem;
90
+ private findArrayItem;
91
+ private createLookupError;
80
92
  private requestJson;
81
93
  }
82
94
  //# 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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hC,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,WAAW;CA2HpB"}
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;AA6SpB,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,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M/C,kBAAkB,YACd,cAAc;uBAMX,MAAM,YAAY,cAAc;0BAKpC,MAAM,QACT,kBAAkB,YACd,cAAc;wBAWlB,oBAAoB,YAChB,cAAc;0BAMR,MAAM,YAAY,cAAc;MAIlD;IAEF,QAAQ,CAAC,UAAU;uBACF,kBAAkB,YAAY,cAAc;uBAMnD,sBAAsB,YAClB,cAAc;2BAUP,MAAM,YAAY,cAAc;8BASpC,MAAM,QACb,sBAAsB,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,aAAa;YAqBb,YAAY;YA+CZ,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") {
@@ -230,6 +231,7 @@ export class Client {
230
231
  query,
231
232
  options,
232
233
  }),
234
+ getBySlug: (slug, options) => this.getPageBySlug(slug, options),
233
235
  update: (pageId, body, options) => this.requestData("PATCH", `/pages/${pageId}`, {
234
236
  body,
235
237
  options,
@@ -251,6 +253,9 @@ export class Client {
251
253
  options,
252
254
  }),
253
255
  };
256
+ page = {
257
+ getBySlug: (slug, options) => this.pages.getBySlug(slug, options),
258
+ };
254
259
  collections = {
255
260
  list: (query, options) => this.requestList("GET", "/collections", {
256
261
  query,
@@ -296,18 +301,33 @@ export class Client {
296
301
  query,
297
302
  options,
298
303
  }),
304
+ get: (memberId, options) => this.findListItem("/members", (member) => member.id === memberId, options, {
305
+ code: "member_not_found",
306
+ message: "Member not found.",
307
+ details: { memberId },
308
+ }),
299
309
  };
300
310
  authors = {
301
311
  list: (query, options) => this.requestList("GET", "/authors", {
302
312
  query,
303
313
  options,
304
314
  }),
315
+ get: (authorId, options) => this.findListItem("/authors", (author) => author.id === authorId, options, {
316
+ code: "author_not_found",
317
+ message: "Author not found.",
318
+ details: { authorId },
319
+ }),
305
320
  };
306
321
  reviewers = {
307
322
  list: (query, options) => this.requestList("GET", "/reviewers", {
308
323
  query,
309
324
  options,
310
325
  }),
326
+ get: (reviewerId, options) => this.findListItem("/reviewers", (reviewer) => reviewer.id === reviewerId, options, {
327
+ code: "reviewer_not_found",
328
+ message: "Reviewer not found.",
329
+ details: { reviewerId },
330
+ }),
311
331
  };
312
332
  statuses = {
313
333
  list: (query, options) => this.requestList("GET", "/statuses", {
@@ -381,6 +401,11 @@ export class Client {
381
401
  list: (options) => this.requestData("GET", "/locales", {
382
402
  options,
383
403
  }),
404
+ get: (code, options) => this.findArrayItem("/locales", (locale) => locale.code === code, options, {
405
+ code: "locale_not_found",
406
+ message: "Locale not found.",
407
+ details: { code },
408
+ }),
384
409
  create: (body, options) => this.requestData("POST", "/locales", {
385
410
  body,
386
411
  options,
@@ -423,6 +448,70 @@ export class Client {
423
448
  requestList(method, path, config) {
424
449
  return this.requestJson(method, path, config);
425
450
  }
451
+ async getPageBySlug(slug, options) {
452
+ const page = await this.findListItem("/pages", (item) => item.slug === slug, options, {
453
+ code: "page_not_found",
454
+ message: "Page not found.",
455
+ details: { slug },
456
+ }, {
457
+ slug,
458
+ });
459
+ return this.pages.get(page.id, undefined, options);
460
+ }
461
+ async findListItem(path, predicate, options, error, query) {
462
+ let page = 1;
463
+ while (true) {
464
+ const response = await this.requestList("GET", path, {
465
+ query: {
466
+ ...(query ?? {}),
467
+ page,
468
+ limit: LOOKUP_PAGE_SIZE,
469
+ },
470
+ options,
471
+ });
472
+ const match = response.data.find(predicate);
473
+ if (match) {
474
+ return match;
475
+ }
476
+ if (!response.meta.has_next_page) {
477
+ break;
478
+ }
479
+ page += 1;
480
+ }
481
+ throw this.createLookupError("GET", path, {
482
+ query: {
483
+ ...(query ?? {}),
484
+ page,
485
+ limit: LOOKUP_PAGE_SIZE,
486
+ },
487
+ code: error.code,
488
+ message: error.message,
489
+ details: error.details,
490
+ });
491
+ }
492
+ async findArrayItem(path, predicate, options, error) {
493
+ const items = await this.requestData("GET", path, {
494
+ options,
495
+ });
496
+ const match = items.find(predicate);
497
+ if (match) {
498
+ return match;
499
+ }
500
+ throw this.createLookupError("GET", path, {
501
+ code: error.code,
502
+ message: error.message,
503
+ details: error.details,
504
+ });
505
+ }
506
+ createLookupError(method, path, config) {
507
+ return new ParagraphApiError({
508
+ status: 404,
509
+ code: config.code,
510
+ message: config.message,
511
+ details: config.details,
512
+ request: createRequestDescriptor(method, buildUrl(this.baseUrl, path, config.query)),
513
+ });
514
+ }
426
515
  requestJson(method, path, config) {
427
516
  const url = buildUrl(this.baseUrl, path, config?.query);
428
517
  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.3.0",
4
4
  "description": "Official Paragraph CMS TypeScript client for the Paragraph CMS v1 API.",
5
5
  "license": "ISC",
6
6
  "author": "Paragraph CMS",