@mx-space/byline-api-client 0.1.2 → 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/README.md +4 -2
- package/dist/index.cjs +12 -22
- package/dist/index.d.cts +23 -37
- package/dist/index.d.ts +23 -37
- package/dist/index.js +12 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -82,8 +82,10 @@ const admin = createClient({ endpoint, apiKey: process.env.BYLINE_API_KEY })
|
|
|
82
82
|
|
|
83
83
|
`posts.create` and `posts.revise` go through the draft and publish-job flow the admin
|
|
84
84
|
uses: they save a draft revision, start a publish job and wait for it. `revise`
|
|
85
|
-
|
|
86
|
-
values.
|
|
85
|
+
writes into the post's working copy on top of its published revision, so fields you
|
|
86
|
+
omit keep their current values. When it publishes, `revise` refuses with
|
|
87
|
+
`DRAFT_WORKING_COPY_AHEAD` (409) if someone has unpublished changes in the working
|
|
88
|
+
copy; pass `{ publish: false }` to write into the working copy without publishing.
|
|
87
89
|
|
|
88
90
|
```ts
|
|
89
91
|
const { postId } = await admin.posts.create(
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/case.ts
|
|
3
3
|
const isPlainObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
4
4
|
const camelcase = (key) => key.replaceAll(/_([\da-z])/gi, (_, char) => char.toUpperCase());
|
|
5
5
|
const splitPath = (path) => path.replaceAll("[]", ".[]").split(".").filter((segment) => segment.length > 0);
|
|
@@ -38,8 +38,7 @@ const walk = (value, tree) => {
|
|
|
38
38
|
return out;
|
|
39
39
|
};
|
|
40
40
|
const camelcaseKeys = (value, preservePaths = []) => walk(value, buildTree(preservePaths));
|
|
41
|
-
|
|
42
|
-
//#region src/error.ts
|
|
41
|
+
// src/error.ts
|
|
43
42
|
var BylineApiError = class extends Error {
|
|
44
43
|
status;
|
|
45
44
|
code;
|
|
@@ -55,8 +54,7 @@ var BylineApiError = class extends Error {
|
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
56
|
const isBylineApiError = (error, code) => error instanceof BylineApiError && (code === void 0 || error.code === code);
|
|
58
|
-
|
|
59
|
-
//#region src/http.ts
|
|
57
|
+
// src/http.ts
|
|
60
58
|
const ENVELOPE_KEYS = /* @__PURE__ */ new Set(["data", "meta"]);
|
|
61
59
|
const isEnvelope = (body) => !!body && typeof body === "object" && !Array.isArray(body) && "data" in body && Object.keys(body).every((key) => ENVELOPE_KEYS.has(key));
|
|
62
60
|
const isBinaryBody = (body) => typeof FormData !== "undefined" && body instanceof FormData || typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer || body instanceof URLSearchParams || typeof body === "string";
|
|
@@ -125,8 +123,7 @@ var HttpCore = class {
|
|
|
125
123
|
return new BylineApiError(status, "HTTP_ERROR", typeof payload === "string" && payload ? payload.slice(0, 500) : `Request failed with status ${status}`, path);
|
|
126
124
|
}
|
|
127
125
|
};
|
|
128
|
-
|
|
129
|
-
//#region src/resources/authors.ts
|
|
126
|
+
// src/resources/authors.ts
|
|
130
127
|
var AuthorsResource = class {
|
|
131
128
|
http;
|
|
132
129
|
constructor(http) {
|
|
@@ -151,8 +148,7 @@ var AuthorsResource = class {
|
|
|
151
148
|
return this.http.request("GET", `/authors/${encodeURIComponent(idOrUsername)}`);
|
|
152
149
|
}
|
|
153
150
|
};
|
|
154
|
-
|
|
155
|
-
//#region src/resources/content.ts
|
|
151
|
+
// src/resources/content.ts
|
|
156
152
|
const CATALOG_PRESERVE = ["components[].propsSchema"];
|
|
157
153
|
var CategoriesResource = class {
|
|
158
154
|
http;
|
|
@@ -247,8 +243,7 @@ var FilesResource = class {
|
|
|
247
243
|
});
|
|
248
244
|
}
|
|
249
245
|
};
|
|
250
|
-
|
|
251
|
-
//#region src/resources/drafts.ts
|
|
246
|
+
// src/resources/drafts.ts
|
|
252
247
|
var DraftsResource = class {
|
|
253
248
|
http;
|
|
254
249
|
constructor(http) {
|
|
@@ -273,8 +268,7 @@ var DraftsResource = class {
|
|
|
273
268
|
return this.http.request("DELETE", `/drafts/${id}`);
|
|
274
269
|
}
|
|
275
270
|
};
|
|
276
|
-
|
|
277
|
-
//#region src/resources/posts.ts
|
|
271
|
+
// src/resources/posts.ts
|
|
278
272
|
const POST_PRESERVE = ["meta"];
|
|
279
273
|
const POST_LIST_PRESERVE = ["[].meta"];
|
|
280
274
|
const DRAFT_CORE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -390,7 +384,8 @@ var PostsResource = class {
|
|
|
390
384
|
refType: "post",
|
|
391
385
|
refId: id,
|
|
392
386
|
baseRevisionId: base.id,
|
|
393
|
-
data: mergeSnapshot(base, toDraftData(input))
|
|
387
|
+
data: mergeSnapshot(base, toDraftData(input)),
|
|
388
|
+
...options.publish === false ? {} : { ifInSync: true }
|
|
394
389
|
});
|
|
395
390
|
return this.finish(draft, options);
|
|
396
391
|
}
|
|
@@ -404,7 +399,6 @@ var PostsResource = class {
|
|
|
404
399
|
branchId: draft.id,
|
|
405
400
|
revisionId: draft.headRevisionId,
|
|
406
401
|
expectedPublishedRevisionId: draft.document.publishedRevisionId,
|
|
407
|
-
confirmDiverged: draft.relationToPublished === "descendant" || draft.relationToPublished === "diverged",
|
|
408
402
|
aiResources: options.aiResources,
|
|
409
403
|
regenerateLockedTranslations: options.regenerateLockedTranslations
|
|
410
404
|
}, options);
|
|
@@ -415,8 +409,7 @@ var PostsResource = class {
|
|
|
415
409
|
};
|
|
416
410
|
}
|
|
417
411
|
};
|
|
418
|
-
|
|
419
|
-
//#region src/resources/tasks.ts
|
|
412
|
+
// src/resources/tasks.ts
|
|
420
413
|
const TERMINAL = /* @__PURE__ */ new Set([
|
|
421
414
|
"completed",
|
|
422
415
|
"partial_failed",
|
|
@@ -469,8 +462,7 @@ var PublishJobsResource = class {
|
|
|
469
462
|
return task;
|
|
470
463
|
}
|
|
471
464
|
};
|
|
472
|
-
|
|
473
|
-
//#region src/resources/users.ts
|
|
465
|
+
// src/resources/users.ts
|
|
474
466
|
var UsersResource = class {
|
|
475
467
|
http;
|
|
476
468
|
constructor(http) {
|
|
@@ -547,8 +539,7 @@ var InvitesResource = class {
|
|
|
547
539
|
return this.http.request("POST", `/invites/${encodeURIComponent(token)}/accept`, { body: input });
|
|
548
540
|
}
|
|
549
541
|
};
|
|
550
|
-
|
|
551
|
-
//#region src/client.ts
|
|
542
|
+
// src/client.ts
|
|
552
543
|
var BylineClient = class {
|
|
553
544
|
http;
|
|
554
545
|
posts;
|
|
@@ -578,7 +569,6 @@ var BylineClient = class {
|
|
|
578
569
|
}
|
|
579
570
|
};
|
|
580
571
|
const createClient = (options) => new BylineClient(options);
|
|
581
|
-
//#endregion
|
|
582
572
|
exports.BylineApiError = BylineApiError;
|
|
583
573
|
exports.BylineClient = BylineClient;
|
|
584
574
|
exports.HttpCore = HttpCore;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const camelcaseKeys: <T>(value: unknown, preservePaths?: readonly string[]) => T;
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/types.d.ts
|
|
1
|
+
export declare const camelcaseKeys: <T>(value: unknown, preservePaths?: readonly string[]) => T;
|
|
5
2
|
interface ApiResponse<T, M = Record<string, unknown>> {
|
|
6
3
|
data: T;
|
|
7
4
|
meta?: M;
|
|
@@ -172,12 +169,13 @@ interface PostImage {
|
|
|
172
169
|
[key: string]: unknown;
|
|
173
170
|
}
|
|
174
171
|
interface Post {
|
|
172
|
+
publicAt?: string | null;
|
|
175
173
|
id: string;
|
|
176
174
|
title: string;
|
|
177
175
|
slug: string;
|
|
178
176
|
text: string;
|
|
179
177
|
content: string | null;
|
|
180
|
-
contentFormat:
|
|
178
|
+
contentFormat: 'lexical';
|
|
181
179
|
summary: string | null;
|
|
182
180
|
images: PostImage[] | null;
|
|
183
181
|
meta: Record<string, unknown> | null;
|
|
@@ -195,7 +193,7 @@ interface Post {
|
|
|
195
193
|
seo: PostSeo | null;
|
|
196
194
|
[key: string]: unknown;
|
|
197
195
|
}
|
|
198
|
-
type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt';
|
|
196
|
+
type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt' | 'publicAt';
|
|
199
197
|
interface PostListQuery {
|
|
200
198
|
page?: number;
|
|
201
199
|
size?: number;
|
|
@@ -208,6 +206,7 @@ interface PostListQuery {
|
|
|
208
206
|
lang?: string;
|
|
209
207
|
}
|
|
210
208
|
interface PostPatch {
|
|
209
|
+
publicAt?: string | null;
|
|
211
210
|
categoryId?: string;
|
|
212
211
|
pinAt?: string | null;
|
|
213
212
|
authors?: string[];
|
|
@@ -216,6 +215,7 @@ interface PostPatch {
|
|
|
216
215
|
seo?: PostSeo | null;
|
|
217
216
|
}
|
|
218
217
|
interface PostWriteInput {
|
|
218
|
+
publicAt?: string | null;
|
|
219
219
|
title: string;
|
|
220
220
|
content: string | LexicalEditorState;
|
|
221
221
|
text?: string;
|
|
@@ -234,10 +234,9 @@ interface PostWriteInput {
|
|
|
234
234
|
createdAt?: string;
|
|
235
235
|
}
|
|
236
236
|
type DraftRefType = 'post';
|
|
237
|
-
type RevisionRelation = 'same' | 'ancestor' | 'descendant' | 'diverged';
|
|
238
237
|
interface RevisionSnapshot {
|
|
239
238
|
content: string | null;
|
|
240
|
-
contentFormat:
|
|
239
|
+
contentFormat: 'lexical';
|
|
241
240
|
images: unknown[] | null;
|
|
242
241
|
meta: Record<string, unknown> | null;
|
|
243
242
|
text: string;
|
|
@@ -256,9 +255,14 @@ interface ContentDocument {
|
|
|
256
255
|
refType: DraftRefType;
|
|
257
256
|
publishedRevisionId: string | null;
|
|
258
257
|
publishAiResources: PublishAiResourceRequest[] | null;
|
|
258
|
+
aiSeo: {
|
|
259
|
+
description: string;
|
|
260
|
+
sourceHash: string;
|
|
261
|
+
} | null;
|
|
259
262
|
createdAt: string;
|
|
260
263
|
updatedAt: string | null;
|
|
261
264
|
}
|
|
265
|
+
type DraftRelation = 'ahead' | 'fresh' | 'in_sync';
|
|
262
266
|
interface DraftBranch {
|
|
263
267
|
id: string;
|
|
264
268
|
documentId: string;
|
|
@@ -269,7 +273,7 @@ interface DraftBranch {
|
|
|
269
273
|
headRevision: ContentRevision;
|
|
270
274
|
baseRevision: ContentRevision;
|
|
271
275
|
publishedRevision: ContentRevision | null;
|
|
272
|
-
|
|
276
|
+
relation: DraftRelation;
|
|
273
277
|
createdAt: string;
|
|
274
278
|
updatedAt: string | null;
|
|
275
279
|
}
|
|
@@ -293,8 +297,9 @@ interface CreateDraftInput {
|
|
|
293
297
|
refId?: string;
|
|
294
298
|
baseRevisionId?: string | null;
|
|
295
299
|
data: DraftWriteData;
|
|
300
|
+
ifInSync?: boolean;
|
|
296
301
|
}
|
|
297
|
-
type PublishAiResource = 'insights' | 'summary' | 'translation' | 'tts';
|
|
302
|
+
type PublishAiResource = 'insights' | 'seo' | 'summary' | 'translation' | 'tts';
|
|
298
303
|
interface PublishAiResourceRequest {
|
|
299
304
|
resource: PublishAiResource;
|
|
300
305
|
mode: 'sync' | 'async';
|
|
@@ -343,7 +348,7 @@ interface Translation {
|
|
|
343
348
|
summary: string | null;
|
|
344
349
|
tags: string[];
|
|
345
350
|
content: string | null;
|
|
346
|
-
contentFormat:
|
|
351
|
+
contentFormat: 'lexical' | null;
|
|
347
352
|
isLocked: boolean;
|
|
348
353
|
aiModel: string | null;
|
|
349
354
|
aiProvider: string | null;
|
|
@@ -414,8 +419,6 @@ interface UploadedFile {
|
|
|
414
419
|
storageBackend?: string;
|
|
415
420
|
storageKey?: string;
|
|
416
421
|
}
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/http.d.ts
|
|
419
422
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
420
423
|
type QueryValue = string | number | boolean | null | undefined | ReadonlyArray<string | number>;
|
|
421
424
|
interface ClientOptions {
|
|
@@ -434,7 +437,7 @@ interface RequestOptions {
|
|
|
434
437
|
preserve?: readonly string[];
|
|
435
438
|
signal?: AbortSignal;
|
|
436
439
|
}
|
|
437
|
-
declare class HttpCore {
|
|
440
|
+
export declare class HttpCore {
|
|
438
441
|
private readonly options;
|
|
439
442
|
readonly endpoint: string;
|
|
440
443
|
private readonly fetchImpl;
|
|
@@ -445,8 +448,6 @@ declare class HttpCore {
|
|
|
445
448
|
private transform;
|
|
446
449
|
private toError;
|
|
447
450
|
}
|
|
448
|
-
//#endregion
|
|
449
|
-
//#region src/resources/authors.d.ts
|
|
450
451
|
declare class AuthorsResource {
|
|
451
452
|
private readonly http;
|
|
452
453
|
constructor(http: HttpCore);
|
|
@@ -454,8 +455,6 @@ declare class AuthorsResource {
|
|
|
454
455
|
listAll(): Promise<Author[]>;
|
|
455
456
|
get(idOrUsername: string): Promise<ApiResponse<Author, Record<string, unknown>>>;
|
|
456
457
|
}
|
|
457
|
-
//#endregion
|
|
458
|
-
//#region src/resources/content.d.ts
|
|
459
458
|
declare class CategoriesResource {
|
|
460
459
|
private readonly http;
|
|
461
460
|
constructor(http: HttpCore);
|
|
@@ -509,8 +508,6 @@ declare class FilesResource {
|
|
|
509
508
|
immutable?: boolean;
|
|
510
509
|
}): Promise<ApiResponse<UploadedFile, Record<string, unknown>>>;
|
|
511
510
|
}
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region src/resources/drafts.d.ts
|
|
514
511
|
declare class DraftsResource {
|
|
515
512
|
private readonly http;
|
|
516
513
|
constructor(http: HttpCore);
|
|
@@ -530,8 +527,6 @@ declare class DraftsResource {
|
|
|
530
527
|
}): Promise<ApiResponse<DraftBranch, Record<string, unknown>>>;
|
|
531
528
|
delete(id: string): Promise<ApiResponse<void, Record<string, unknown>>>;
|
|
532
529
|
}
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region src/resources/tasks.d.ts
|
|
535
530
|
interface WaitForTaskOptions {
|
|
536
531
|
intervalMs?: number;
|
|
537
532
|
timeoutMs?: number;
|
|
@@ -553,8 +548,6 @@ declare class PublishJobsResource {
|
|
|
553
548
|
result: PublishTaskResult;
|
|
554
549
|
}>;
|
|
555
550
|
}
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/resources/posts.d.ts
|
|
558
551
|
interface PostSaveOptions extends WaitForTaskOptions {
|
|
559
552
|
publish?: boolean;
|
|
560
553
|
aiResources?: Array<PublishAiResource | PublishAiResourceRequest>;
|
|
@@ -565,7 +558,7 @@ interface PostSaveResult {
|
|
|
565
558
|
postId: string | null;
|
|
566
559
|
taskId: string | null;
|
|
567
560
|
}
|
|
568
|
-
declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
|
|
561
|
+
export declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
|
|
569
562
|
declare class PostsResource {
|
|
570
563
|
private readonly http;
|
|
571
564
|
private readonly drafts;
|
|
@@ -599,8 +592,6 @@ declare class PostsResource {
|
|
|
599
592
|
revise(id: string, input: Partial<PostWriteInput>, options?: PostSaveOptions): Promise<PostSaveResult>;
|
|
600
593
|
private finish;
|
|
601
594
|
}
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/resources/users.d.ts
|
|
604
595
|
declare class UsersResource {
|
|
605
596
|
private readonly http;
|
|
606
597
|
constructor(http: HttpCore);
|
|
@@ -630,9 +621,7 @@ declare class InvitesResource {
|
|
|
630
621
|
get(token: string): Promise<ApiResponse<PublicInvite, Record<string, unknown>>>;
|
|
631
622
|
accept(token: string, input: AcceptInviteInput): Promise<ApiResponse<UserDetail, Record<string, unknown>>>;
|
|
632
623
|
}
|
|
633
|
-
|
|
634
|
-
//#region src/client.d.ts
|
|
635
|
-
declare class BylineClient {
|
|
624
|
+
export declare class BylineClient {
|
|
636
625
|
readonly http: HttpCore;
|
|
637
626
|
readonly posts: PostsResource;
|
|
638
627
|
readonly drafts: DraftsResource;
|
|
@@ -647,10 +636,8 @@ declare class BylineClient {
|
|
|
647
636
|
readonly files: FilesResource;
|
|
648
637
|
constructor(options: ClientOptions);
|
|
649
638
|
}
|
|
650
|
-
declare const createClient: (options: ClientOptions) => BylineClient;
|
|
651
|
-
|
|
652
|
-
//#region src/error.d.ts
|
|
653
|
-
declare class BylineApiError extends Error {
|
|
639
|
+
export declare const createClient: (options: ClientOptions) => BylineClient;
|
|
640
|
+
export declare class BylineApiError extends Error {
|
|
654
641
|
readonly status: number;
|
|
655
642
|
readonly code: string;
|
|
656
643
|
readonly path: string;
|
|
@@ -658,6 +645,5 @@ declare class BylineApiError extends Error {
|
|
|
658
645
|
readonly name = "BylineApiError";
|
|
659
646
|
constructor(status: number, code: string, message: string, path: string, details?: unknown | undefined);
|
|
660
647
|
}
|
|
661
|
-
declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
|
|
662
|
-
|
|
663
|
-
export { type AcceptInviteInput, type AllowLoginResult, type ApiResponse, type ArticleTranslationMeta, type Author, type AuthorListQuery, type AuthorsResource, BylineApiError, BylineClient, type CategoriesResource, type Category, type CategorySummary, type ClientOptions, type ContentDocument, type ContentRevision, type CreateDraftInput, type CreateInviteInput, type CreatePublishJobInput, type CreatedInvite, type DraftBranch, type DraftRefType, type DraftWriteData, type DraftsResource, type DynamicComponent, type DynamicComponentCatalog, type DynamicComponentsResource, type EntryTranslationMeta, type FileType, type FilesResource, HttpCore, type HttpMethod, type InitUserInput, type Invite, type InviteUserInput, type InvitesResource, type LexicalEditorState, type ManualTranslationInput, type PaginatedMeta, type Pagination, type Post, type PostImage, type PostListQuery, type PostPatch, type PostResponseMeta, type PostSaveOptions, type PostSaveResult, type PostSeo, type PostSortKey, type PostWriteInput, type PostsResource, type ProfileOnlyUserInput, type PublicAuthor, type PublicInvite, type PublishAiResource, type PublishAiResourceRequest, type PublishJobsResource, type PublishTaskResult, type QueryValue, type RegisterDynamicComponentInput, type RequestOptions, type RevisionRelation, type RevisionSnapshot, type Task, type TaskRef, type TaskStatus, type TasksResource, type Translation, type TranslationPatch, type TranslationTaskInput, type TranslationTaskResult, type TranslationsResource, type UpdateDynamicComponentInput, type UploadedFile, type UserDetail, type UserListQuery, type UserListStatus, type UserProfileInput, type UsersResource, type VersionContext, type WaitForTaskOptions, camelcaseKeys, createClient, isBylineApiError, toDraftData };
|
|
648
|
+
export declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
|
|
649
|
+
export type { AcceptInviteInput, AllowLoginResult, ApiResponse, ArticleTranslationMeta, Author, AuthorListQuery, AuthorsResource, CategoriesResource, Category, CategorySummary, ClientOptions, ContentDocument, ContentRevision, CreateDraftInput, CreateInviteInput, CreatePublishJobInput, CreatedInvite, DraftBranch, DraftRefType, DraftRelation, DraftWriteData, DraftsResource, DynamicComponent, DynamicComponentCatalog, DynamicComponentsResource, EntryTranslationMeta, FileType, FilesResource, HttpMethod, InitUserInput, Invite, InviteUserInput, InvitesResource, LexicalEditorState, ManualTranslationInput, PaginatedMeta, Pagination, Post, PostImage, PostListQuery, PostPatch, PostResponseMeta, PostSaveOptions, PostSaveResult, PostSeo, PostSortKey, PostWriteInput, PostsResource, ProfileOnlyUserInput, PublicAuthor, PublicInvite, PublishAiResource, PublishAiResourceRequest, PublishJobsResource, PublishTaskResult, QueryValue, RegisterDynamicComponentInput, RequestOptions, RevisionSnapshot, Task, TaskRef, TaskStatus, TasksResource, Translation, TranslationPatch, TranslationTaskInput, TranslationTaskResult, TranslationsResource, UpdateDynamicComponentInput, UploadedFile, UserDetail, UserListQuery, UserListStatus, UserProfileInput, UsersResource, VersionContext, WaitForTaskOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const camelcaseKeys: <T>(value: unknown, preservePaths?: readonly string[]) => T;
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/types.d.ts
|
|
1
|
+
export declare const camelcaseKeys: <T>(value: unknown, preservePaths?: readonly string[]) => T;
|
|
5
2
|
interface ApiResponse<T, M = Record<string, unknown>> {
|
|
6
3
|
data: T;
|
|
7
4
|
meta?: M;
|
|
@@ -172,12 +169,13 @@ interface PostImage {
|
|
|
172
169
|
[key: string]: unknown;
|
|
173
170
|
}
|
|
174
171
|
interface Post {
|
|
172
|
+
publicAt?: string | null;
|
|
175
173
|
id: string;
|
|
176
174
|
title: string;
|
|
177
175
|
slug: string;
|
|
178
176
|
text: string;
|
|
179
177
|
content: string | null;
|
|
180
|
-
contentFormat:
|
|
178
|
+
contentFormat: 'lexical';
|
|
181
179
|
summary: string | null;
|
|
182
180
|
images: PostImage[] | null;
|
|
183
181
|
meta: Record<string, unknown> | null;
|
|
@@ -195,7 +193,7 @@ interface Post {
|
|
|
195
193
|
seo: PostSeo | null;
|
|
196
194
|
[key: string]: unknown;
|
|
197
195
|
}
|
|
198
|
-
type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt';
|
|
196
|
+
type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt' | 'publicAt';
|
|
199
197
|
interface PostListQuery {
|
|
200
198
|
page?: number;
|
|
201
199
|
size?: number;
|
|
@@ -208,6 +206,7 @@ interface PostListQuery {
|
|
|
208
206
|
lang?: string;
|
|
209
207
|
}
|
|
210
208
|
interface PostPatch {
|
|
209
|
+
publicAt?: string | null;
|
|
211
210
|
categoryId?: string;
|
|
212
211
|
pinAt?: string | null;
|
|
213
212
|
authors?: string[];
|
|
@@ -216,6 +215,7 @@ interface PostPatch {
|
|
|
216
215
|
seo?: PostSeo | null;
|
|
217
216
|
}
|
|
218
217
|
interface PostWriteInput {
|
|
218
|
+
publicAt?: string | null;
|
|
219
219
|
title: string;
|
|
220
220
|
content: string | LexicalEditorState;
|
|
221
221
|
text?: string;
|
|
@@ -234,10 +234,9 @@ interface PostWriteInput {
|
|
|
234
234
|
createdAt?: string;
|
|
235
235
|
}
|
|
236
236
|
type DraftRefType = 'post';
|
|
237
|
-
type RevisionRelation = 'same' | 'ancestor' | 'descendant' | 'diverged';
|
|
238
237
|
interface RevisionSnapshot {
|
|
239
238
|
content: string | null;
|
|
240
|
-
contentFormat:
|
|
239
|
+
contentFormat: 'lexical';
|
|
241
240
|
images: unknown[] | null;
|
|
242
241
|
meta: Record<string, unknown> | null;
|
|
243
242
|
text: string;
|
|
@@ -256,9 +255,14 @@ interface ContentDocument {
|
|
|
256
255
|
refType: DraftRefType;
|
|
257
256
|
publishedRevisionId: string | null;
|
|
258
257
|
publishAiResources: PublishAiResourceRequest[] | null;
|
|
258
|
+
aiSeo: {
|
|
259
|
+
description: string;
|
|
260
|
+
sourceHash: string;
|
|
261
|
+
} | null;
|
|
259
262
|
createdAt: string;
|
|
260
263
|
updatedAt: string | null;
|
|
261
264
|
}
|
|
265
|
+
type DraftRelation = 'ahead' | 'fresh' | 'in_sync';
|
|
262
266
|
interface DraftBranch {
|
|
263
267
|
id: string;
|
|
264
268
|
documentId: string;
|
|
@@ -269,7 +273,7 @@ interface DraftBranch {
|
|
|
269
273
|
headRevision: ContentRevision;
|
|
270
274
|
baseRevision: ContentRevision;
|
|
271
275
|
publishedRevision: ContentRevision | null;
|
|
272
|
-
|
|
276
|
+
relation: DraftRelation;
|
|
273
277
|
createdAt: string;
|
|
274
278
|
updatedAt: string | null;
|
|
275
279
|
}
|
|
@@ -293,8 +297,9 @@ interface CreateDraftInput {
|
|
|
293
297
|
refId?: string;
|
|
294
298
|
baseRevisionId?: string | null;
|
|
295
299
|
data: DraftWriteData;
|
|
300
|
+
ifInSync?: boolean;
|
|
296
301
|
}
|
|
297
|
-
type PublishAiResource = 'insights' | 'summary' | 'translation' | 'tts';
|
|
302
|
+
type PublishAiResource = 'insights' | 'seo' | 'summary' | 'translation' | 'tts';
|
|
298
303
|
interface PublishAiResourceRequest {
|
|
299
304
|
resource: PublishAiResource;
|
|
300
305
|
mode: 'sync' | 'async';
|
|
@@ -343,7 +348,7 @@ interface Translation {
|
|
|
343
348
|
summary: string | null;
|
|
344
349
|
tags: string[];
|
|
345
350
|
content: string | null;
|
|
346
|
-
contentFormat:
|
|
351
|
+
contentFormat: 'lexical' | null;
|
|
347
352
|
isLocked: boolean;
|
|
348
353
|
aiModel: string | null;
|
|
349
354
|
aiProvider: string | null;
|
|
@@ -414,8 +419,6 @@ interface UploadedFile {
|
|
|
414
419
|
storageBackend?: string;
|
|
415
420
|
storageKey?: string;
|
|
416
421
|
}
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/http.d.ts
|
|
419
422
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
420
423
|
type QueryValue = string | number | boolean | null | undefined | ReadonlyArray<string | number>;
|
|
421
424
|
interface ClientOptions {
|
|
@@ -434,7 +437,7 @@ interface RequestOptions {
|
|
|
434
437
|
preserve?: readonly string[];
|
|
435
438
|
signal?: AbortSignal;
|
|
436
439
|
}
|
|
437
|
-
declare class HttpCore {
|
|
440
|
+
export declare class HttpCore {
|
|
438
441
|
private readonly options;
|
|
439
442
|
readonly endpoint: string;
|
|
440
443
|
private readonly fetchImpl;
|
|
@@ -445,8 +448,6 @@ declare class HttpCore {
|
|
|
445
448
|
private transform;
|
|
446
449
|
private toError;
|
|
447
450
|
}
|
|
448
|
-
//#endregion
|
|
449
|
-
//#region src/resources/authors.d.ts
|
|
450
451
|
declare class AuthorsResource {
|
|
451
452
|
private readonly http;
|
|
452
453
|
constructor(http: HttpCore);
|
|
@@ -454,8 +455,6 @@ declare class AuthorsResource {
|
|
|
454
455
|
listAll(): Promise<Author[]>;
|
|
455
456
|
get(idOrUsername: string): Promise<ApiResponse<Author, Record<string, unknown>>>;
|
|
456
457
|
}
|
|
457
|
-
//#endregion
|
|
458
|
-
//#region src/resources/content.d.ts
|
|
459
458
|
declare class CategoriesResource {
|
|
460
459
|
private readonly http;
|
|
461
460
|
constructor(http: HttpCore);
|
|
@@ -509,8 +508,6 @@ declare class FilesResource {
|
|
|
509
508
|
immutable?: boolean;
|
|
510
509
|
}): Promise<ApiResponse<UploadedFile, Record<string, unknown>>>;
|
|
511
510
|
}
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region src/resources/drafts.d.ts
|
|
514
511
|
declare class DraftsResource {
|
|
515
512
|
private readonly http;
|
|
516
513
|
constructor(http: HttpCore);
|
|
@@ -530,8 +527,6 @@ declare class DraftsResource {
|
|
|
530
527
|
}): Promise<ApiResponse<DraftBranch, Record<string, unknown>>>;
|
|
531
528
|
delete(id: string): Promise<ApiResponse<void, Record<string, unknown>>>;
|
|
532
529
|
}
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region src/resources/tasks.d.ts
|
|
535
530
|
interface WaitForTaskOptions {
|
|
536
531
|
intervalMs?: number;
|
|
537
532
|
timeoutMs?: number;
|
|
@@ -553,8 +548,6 @@ declare class PublishJobsResource {
|
|
|
553
548
|
result: PublishTaskResult;
|
|
554
549
|
}>;
|
|
555
550
|
}
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/resources/posts.d.ts
|
|
558
551
|
interface PostSaveOptions extends WaitForTaskOptions {
|
|
559
552
|
publish?: boolean;
|
|
560
553
|
aiResources?: Array<PublishAiResource | PublishAiResourceRequest>;
|
|
@@ -565,7 +558,7 @@ interface PostSaveResult {
|
|
|
565
558
|
postId: string | null;
|
|
566
559
|
taskId: string | null;
|
|
567
560
|
}
|
|
568
|
-
declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
|
|
561
|
+
export declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
|
|
569
562
|
declare class PostsResource {
|
|
570
563
|
private readonly http;
|
|
571
564
|
private readonly drafts;
|
|
@@ -599,8 +592,6 @@ declare class PostsResource {
|
|
|
599
592
|
revise(id: string, input: Partial<PostWriteInput>, options?: PostSaveOptions): Promise<PostSaveResult>;
|
|
600
593
|
private finish;
|
|
601
594
|
}
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/resources/users.d.ts
|
|
604
595
|
declare class UsersResource {
|
|
605
596
|
private readonly http;
|
|
606
597
|
constructor(http: HttpCore);
|
|
@@ -630,9 +621,7 @@ declare class InvitesResource {
|
|
|
630
621
|
get(token: string): Promise<ApiResponse<PublicInvite, Record<string, unknown>>>;
|
|
631
622
|
accept(token: string, input: AcceptInviteInput): Promise<ApiResponse<UserDetail, Record<string, unknown>>>;
|
|
632
623
|
}
|
|
633
|
-
|
|
634
|
-
//#region src/client.d.ts
|
|
635
|
-
declare class BylineClient {
|
|
624
|
+
export declare class BylineClient {
|
|
636
625
|
readonly http: HttpCore;
|
|
637
626
|
readonly posts: PostsResource;
|
|
638
627
|
readonly drafts: DraftsResource;
|
|
@@ -647,10 +636,8 @@ declare class BylineClient {
|
|
|
647
636
|
readonly files: FilesResource;
|
|
648
637
|
constructor(options: ClientOptions);
|
|
649
638
|
}
|
|
650
|
-
declare const createClient: (options: ClientOptions) => BylineClient;
|
|
651
|
-
|
|
652
|
-
//#region src/error.d.ts
|
|
653
|
-
declare class BylineApiError extends Error {
|
|
639
|
+
export declare const createClient: (options: ClientOptions) => BylineClient;
|
|
640
|
+
export declare class BylineApiError extends Error {
|
|
654
641
|
readonly status: number;
|
|
655
642
|
readonly code: string;
|
|
656
643
|
readonly path: string;
|
|
@@ -658,6 +645,5 @@ declare class BylineApiError extends Error {
|
|
|
658
645
|
readonly name = "BylineApiError";
|
|
659
646
|
constructor(status: number, code: string, message: string, path: string, details?: unknown | undefined);
|
|
660
647
|
}
|
|
661
|
-
declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
|
|
662
|
-
|
|
663
|
-
export { type AcceptInviteInput, type AllowLoginResult, type ApiResponse, type ArticleTranslationMeta, type Author, type AuthorListQuery, type AuthorsResource, BylineApiError, BylineClient, type CategoriesResource, type Category, type CategorySummary, type ClientOptions, type ContentDocument, type ContentRevision, type CreateDraftInput, type CreateInviteInput, type CreatePublishJobInput, type CreatedInvite, type DraftBranch, type DraftRefType, type DraftWriteData, type DraftsResource, type DynamicComponent, type DynamicComponentCatalog, type DynamicComponentsResource, type EntryTranslationMeta, type FileType, type FilesResource, HttpCore, type HttpMethod, type InitUserInput, type Invite, type InviteUserInput, type InvitesResource, type LexicalEditorState, type ManualTranslationInput, type PaginatedMeta, type Pagination, type Post, type PostImage, type PostListQuery, type PostPatch, type PostResponseMeta, type PostSaveOptions, type PostSaveResult, type PostSeo, type PostSortKey, type PostWriteInput, type PostsResource, type ProfileOnlyUserInput, type PublicAuthor, type PublicInvite, type PublishAiResource, type PublishAiResourceRequest, type PublishJobsResource, type PublishTaskResult, type QueryValue, type RegisterDynamicComponentInput, type RequestOptions, type RevisionRelation, type RevisionSnapshot, type Task, type TaskRef, type TaskStatus, type TasksResource, type Translation, type TranslationPatch, type TranslationTaskInput, type TranslationTaskResult, type TranslationsResource, type UpdateDynamicComponentInput, type UploadedFile, type UserDetail, type UserListQuery, type UserListStatus, type UserProfileInput, type UsersResource, type VersionContext, type WaitForTaskOptions, camelcaseKeys, createClient, isBylineApiError, toDraftData };
|
|
648
|
+
export declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
|
|
649
|
+
export type { AcceptInviteInput, AllowLoginResult, ApiResponse, ArticleTranslationMeta, Author, AuthorListQuery, AuthorsResource, CategoriesResource, Category, CategorySummary, ClientOptions, ContentDocument, ContentRevision, CreateDraftInput, CreateInviteInput, CreatePublishJobInput, CreatedInvite, DraftBranch, DraftRefType, DraftRelation, DraftWriteData, DraftsResource, DynamicComponent, DynamicComponentCatalog, DynamicComponentsResource, EntryTranslationMeta, FileType, FilesResource, HttpMethod, InitUserInput, Invite, InviteUserInput, InvitesResource, LexicalEditorState, ManualTranslationInput, PaginatedMeta, Pagination, Post, PostImage, PostListQuery, PostPatch, PostResponseMeta, PostSaveOptions, PostSaveResult, PostSeo, PostSortKey, PostWriteInput, PostsResource, ProfileOnlyUserInput, PublicAuthor, PublicInvite, PublishAiResource, PublishAiResourceRequest, PublishJobsResource, PublishTaskResult, QueryValue, RegisterDynamicComponentInput, RequestOptions, RevisionSnapshot, Task, TaskRef, TaskStatus, TasksResource, Translation, TranslationPatch, TranslationTaskInput, TranslationTaskResult, TranslationsResource, UpdateDynamicComponentInput, UploadedFile, UserDetail, UserListQuery, UserListStatus, UserProfileInput, UsersResource, VersionContext, WaitForTaskOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/case.ts
|
|
2
2
|
const isPlainObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
3
3
|
const camelcase = (key) => key.replaceAll(/_([\da-z])/gi, (_, char) => char.toUpperCase());
|
|
4
4
|
const splitPath = (path) => path.replaceAll("[]", ".[]").split(".").filter((segment) => segment.length > 0);
|
|
@@ -37,8 +37,7 @@ const walk = (value, tree) => {
|
|
|
37
37
|
return out;
|
|
38
38
|
};
|
|
39
39
|
const camelcaseKeys = (value, preservePaths = []) => walk(value, buildTree(preservePaths));
|
|
40
|
-
|
|
41
|
-
//#region src/error.ts
|
|
40
|
+
// src/error.ts
|
|
42
41
|
var BylineApiError = class extends Error {
|
|
43
42
|
status;
|
|
44
43
|
code;
|
|
@@ -54,8 +53,7 @@ var BylineApiError = class extends Error {
|
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
55
|
const isBylineApiError = (error, code) => error instanceof BylineApiError && (code === void 0 || error.code === code);
|
|
57
|
-
|
|
58
|
-
//#region src/http.ts
|
|
56
|
+
// src/http.ts
|
|
59
57
|
const ENVELOPE_KEYS = /* @__PURE__ */ new Set(["data", "meta"]);
|
|
60
58
|
const isEnvelope = (body) => !!body && typeof body === "object" && !Array.isArray(body) && "data" in body && Object.keys(body).every((key) => ENVELOPE_KEYS.has(key));
|
|
61
59
|
const isBinaryBody = (body) => typeof FormData !== "undefined" && body instanceof FormData || typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer || body instanceof URLSearchParams || typeof body === "string";
|
|
@@ -124,8 +122,7 @@ var HttpCore = class {
|
|
|
124
122
|
return new BylineApiError(status, "HTTP_ERROR", typeof payload === "string" && payload ? payload.slice(0, 500) : `Request failed with status ${status}`, path);
|
|
125
123
|
}
|
|
126
124
|
};
|
|
127
|
-
|
|
128
|
-
//#region src/resources/authors.ts
|
|
125
|
+
// src/resources/authors.ts
|
|
129
126
|
var AuthorsResource = class {
|
|
130
127
|
http;
|
|
131
128
|
constructor(http) {
|
|
@@ -150,8 +147,7 @@ var AuthorsResource = class {
|
|
|
150
147
|
return this.http.request("GET", `/authors/${encodeURIComponent(idOrUsername)}`);
|
|
151
148
|
}
|
|
152
149
|
};
|
|
153
|
-
|
|
154
|
-
//#region src/resources/content.ts
|
|
150
|
+
// src/resources/content.ts
|
|
155
151
|
const CATALOG_PRESERVE = ["components[].propsSchema"];
|
|
156
152
|
var CategoriesResource = class {
|
|
157
153
|
http;
|
|
@@ -246,8 +242,7 @@ var FilesResource = class {
|
|
|
246
242
|
});
|
|
247
243
|
}
|
|
248
244
|
};
|
|
249
|
-
|
|
250
|
-
//#region src/resources/drafts.ts
|
|
245
|
+
// src/resources/drafts.ts
|
|
251
246
|
var DraftsResource = class {
|
|
252
247
|
http;
|
|
253
248
|
constructor(http) {
|
|
@@ -272,8 +267,7 @@ var DraftsResource = class {
|
|
|
272
267
|
return this.http.request("DELETE", `/drafts/${id}`);
|
|
273
268
|
}
|
|
274
269
|
};
|
|
275
|
-
|
|
276
|
-
//#region src/resources/posts.ts
|
|
270
|
+
// src/resources/posts.ts
|
|
277
271
|
const POST_PRESERVE = ["meta"];
|
|
278
272
|
const POST_LIST_PRESERVE = ["[].meta"];
|
|
279
273
|
const DRAFT_CORE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -389,7 +383,8 @@ var PostsResource = class {
|
|
|
389
383
|
refType: "post",
|
|
390
384
|
refId: id,
|
|
391
385
|
baseRevisionId: base.id,
|
|
392
|
-
data: mergeSnapshot(base, toDraftData(input))
|
|
386
|
+
data: mergeSnapshot(base, toDraftData(input)),
|
|
387
|
+
...options.publish === false ? {} : { ifInSync: true }
|
|
393
388
|
});
|
|
394
389
|
return this.finish(draft, options);
|
|
395
390
|
}
|
|
@@ -403,7 +398,6 @@ var PostsResource = class {
|
|
|
403
398
|
branchId: draft.id,
|
|
404
399
|
revisionId: draft.headRevisionId,
|
|
405
400
|
expectedPublishedRevisionId: draft.document.publishedRevisionId,
|
|
406
|
-
confirmDiverged: draft.relationToPublished === "descendant" || draft.relationToPublished === "diverged",
|
|
407
401
|
aiResources: options.aiResources,
|
|
408
402
|
regenerateLockedTranslations: options.regenerateLockedTranslations
|
|
409
403
|
}, options);
|
|
@@ -414,8 +408,7 @@ var PostsResource = class {
|
|
|
414
408
|
};
|
|
415
409
|
}
|
|
416
410
|
};
|
|
417
|
-
|
|
418
|
-
//#region src/resources/tasks.ts
|
|
411
|
+
// src/resources/tasks.ts
|
|
419
412
|
const TERMINAL = /* @__PURE__ */ new Set([
|
|
420
413
|
"completed",
|
|
421
414
|
"partial_failed",
|
|
@@ -468,8 +461,7 @@ var PublishJobsResource = class {
|
|
|
468
461
|
return task;
|
|
469
462
|
}
|
|
470
463
|
};
|
|
471
|
-
|
|
472
|
-
//#region src/resources/users.ts
|
|
464
|
+
// src/resources/users.ts
|
|
473
465
|
var UsersResource = class {
|
|
474
466
|
http;
|
|
475
467
|
constructor(http) {
|
|
@@ -546,8 +538,7 @@ var InvitesResource = class {
|
|
|
546
538
|
return this.http.request("POST", `/invites/${encodeURIComponent(token)}/accept`, { body: input });
|
|
547
539
|
}
|
|
548
540
|
};
|
|
549
|
-
|
|
550
|
-
//#region src/client.ts
|
|
541
|
+
// src/client.ts
|
|
551
542
|
var BylineClient = class {
|
|
552
543
|
http;
|
|
553
544
|
posts;
|
|
@@ -577,5 +568,4 @@ var BylineClient = class {
|
|
|
577
568
|
}
|
|
578
569
|
};
|
|
579
570
|
const createClient = (options) => new BylineClient(options);
|
|
580
|
-
//#endregion
|
|
581
571
|
export { BylineApiError, BylineClient, HttpCore, camelcaseKeys, createClient, isBylineApiError, toDraftData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mx-space/byline-api-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Typed fetch client for the Byline headless CMS API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"byline",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"tsdown": "0.
|
|
47
|
+
"tsdown": "0.23.1",
|
|
48
48
|
"typescript": "6.0.3",
|
|
49
49
|
"vitest": "5.0.5"
|
|
50
50
|
},
|