@paragraphcms/client 1.2.0 → 1.4.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 +5 -1
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +56 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@ const client = new Client({
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
const pages = await client.pages.list({
|
|
32
|
-
limit: 20,
|
|
33
32
|
include_content: false,
|
|
34
33
|
sort: "-updated_at",
|
|
35
34
|
});
|
|
@@ -199,12 +198,14 @@ Returns the public `/v1` info payload:
|
|
|
199
198
|
client.pages.list(query?, options?)
|
|
200
199
|
client.pages.create(body?, options?)
|
|
201
200
|
client.pages.get(pageId, query?, options?)
|
|
201
|
+
client.pages.getBySlug(slug, options?)
|
|
202
202
|
client.pages.update(pageId, body, options?)
|
|
203
203
|
client.pages.delete(pageId, options?)
|
|
204
204
|
client.pages.restore(pageId, options?)
|
|
205
205
|
client.pages.permanentlyDelete(pageId, options?)
|
|
206
206
|
client.pages.duplicate(pageId, options?)
|
|
207
207
|
client.pages.createTranslation(pageId, body, options?)
|
|
208
|
+
client.page.getBySlug(slug, options?)
|
|
208
209
|
```
|
|
209
210
|
|
|
210
211
|
Supported `sort` fields for `pages.list()`:
|
|
@@ -217,9 +218,12 @@ Supported `sort` fields for `pages.list()`:
|
|
|
217
218
|
|
|
218
219
|
Notes:
|
|
219
220
|
|
|
221
|
+
- If you omit both `limit` and `page`, `pages.list()` returns the full matching result set.
|
|
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
|
|
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>;
|
|
@@ -79,8 +83,10 @@ export declare class Client {
|
|
|
79
83
|
};
|
|
80
84
|
constructor(options: ClientOptions);
|
|
81
85
|
getInfo(options?: RequestOptions): Promise<ApiInfo>;
|
|
86
|
+
private listPages;
|
|
82
87
|
private requestData;
|
|
83
88
|
private requestList;
|
|
89
|
+
private getPageBySlug;
|
|
84
90
|
private findListItem;
|
|
85
91
|
private findArrayItem;
|
|
86
92
|
private createLookupError;
|
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;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,QAAQ,CAAC,KAAK;uBACG,aAAa,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,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,QAAQ,CAAC,KAAK;uBACG,aAAa,YAAY,cAAc;wBAG9C,iBAAi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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;YAIlB,SAAS;IAiDvB,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
|
@@ -219,10 +219,7 @@ export class Client {
|
|
|
219
219
|
timeoutMs;
|
|
220
220
|
limiter;
|
|
221
221
|
pages = {
|
|
222
|
-
list: (query, options) => this.
|
|
223
|
-
query,
|
|
224
|
-
options,
|
|
225
|
-
}),
|
|
222
|
+
list: (query, options) => this.listPages(query, options),
|
|
226
223
|
create: (body = {}, options) => this.requestData("POST", "/pages", {
|
|
227
224
|
body,
|
|
228
225
|
options,
|
|
@@ -231,6 +228,7 @@ export class Client {
|
|
|
231
228
|
query,
|
|
232
229
|
options,
|
|
233
230
|
}),
|
|
231
|
+
getBySlug: (slug, options) => this.getPageBySlug(slug, options),
|
|
234
232
|
update: (pageId, body, options) => this.requestData("PATCH", `/pages/${pageId}`, {
|
|
235
233
|
body,
|
|
236
234
|
options,
|
|
@@ -252,6 +250,9 @@ export class Client {
|
|
|
252
250
|
options,
|
|
253
251
|
}),
|
|
254
252
|
};
|
|
253
|
+
page = {
|
|
254
|
+
getBySlug: (slug, options) => this.pages.getBySlug(slug, options),
|
|
255
|
+
};
|
|
255
256
|
collections = {
|
|
256
257
|
list: (query, options) => this.requestList("GET", "/collections", {
|
|
257
258
|
query,
|
|
@@ -438,17 +439,66 @@ export class Client {
|
|
|
438
439
|
getInfo(options) {
|
|
439
440
|
return this.requestData("GET", "", { options });
|
|
440
441
|
}
|
|
442
|
+
async listPages(query, options) {
|
|
443
|
+
const response = await this.requestList("GET", "/pages", {
|
|
444
|
+
query,
|
|
445
|
+
options,
|
|
446
|
+
});
|
|
447
|
+
if (query?.limit !== undefined ||
|
|
448
|
+
query?.page !== undefined ||
|
|
449
|
+
!response.meta.has_next_page) {
|
|
450
|
+
return response;
|
|
451
|
+
}
|
|
452
|
+
const items = [...response.data];
|
|
453
|
+
let nextPage = response.meta.page + 1;
|
|
454
|
+
let lastMeta = response.meta;
|
|
455
|
+
while (lastMeta.has_next_page) {
|
|
456
|
+
const nextResponse = await this.requestList("GET", "/pages", {
|
|
457
|
+
query: {
|
|
458
|
+
...(query ?? {}),
|
|
459
|
+
page: nextPage,
|
|
460
|
+
limit: lastMeta.limit,
|
|
461
|
+
},
|
|
462
|
+
options,
|
|
463
|
+
});
|
|
464
|
+
items.push(...nextResponse.data);
|
|
465
|
+
lastMeta = nextResponse.meta;
|
|
466
|
+
nextPage = lastMeta.page + 1;
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
data: items,
|
|
470
|
+
meta: {
|
|
471
|
+
page: 1,
|
|
472
|
+
limit: items.length,
|
|
473
|
+
total_items: items.length,
|
|
474
|
+
total_pages: items.length > 0 ? 1 : 0,
|
|
475
|
+
has_next_page: false,
|
|
476
|
+
has_prev_page: false,
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
441
480
|
requestData(method, path, config) {
|
|
442
481
|
return this.requestJson(method, path, config).then((response) => response.data);
|
|
443
482
|
}
|
|
444
483
|
requestList(method, path, config) {
|
|
445
484
|
return this.requestJson(method, path, config);
|
|
446
485
|
}
|
|
447
|
-
async
|
|
486
|
+
async getPageBySlug(slug, options) {
|
|
487
|
+
const page = await this.findListItem("/pages", (item) => item.slug === slug, options, {
|
|
488
|
+
code: "page_not_found",
|
|
489
|
+
message: "Page not found.",
|
|
490
|
+
details: { slug },
|
|
491
|
+
}, {
|
|
492
|
+
slug,
|
|
493
|
+
});
|
|
494
|
+
return this.pages.get(page.id, undefined, options);
|
|
495
|
+
}
|
|
496
|
+
async findListItem(path, predicate, options, error, query) {
|
|
448
497
|
let page = 1;
|
|
449
498
|
while (true) {
|
|
450
499
|
const response = await this.requestList("GET", path, {
|
|
451
500
|
query: {
|
|
501
|
+
...(query ?? {}),
|
|
452
502
|
page,
|
|
453
503
|
limit: LOOKUP_PAGE_SIZE,
|
|
454
504
|
},
|
|
@@ -465,6 +515,7 @@ export class Client {
|
|
|
465
515
|
}
|
|
466
516
|
throw this.createLookupError("GET", path, {
|
|
467
517
|
query: {
|
|
518
|
+
...(query ?? {}),
|
|
468
519
|
page,
|
|
469
520
|
limit: LOOKUP_PAGE_SIZE,
|
|
470
521
|
},
|