@mx-space/byline-api-client 0.1.2 → 0.2.1

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
@@ -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
- branches from the post's published revision, so fields you omit keep their current
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
- //#region src/case.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#region src/case.d.ts
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,14 @@ 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;
176
+ url?: string;
178
177
  text: string;
179
178
  content: string | null;
180
- contentFormat: string;
179
+ contentFormat: 'lexical';
181
180
  summary: string | null;
182
181
  images: PostImage[] | null;
183
182
  meta: Record<string, unknown> | null;
@@ -195,7 +194,7 @@ interface Post {
195
194
  seo: PostSeo | null;
196
195
  [key: string]: unknown;
197
196
  }
198
- type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt';
197
+ type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt' | 'publicAt';
199
198
  interface PostListQuery {
200
199
  page?: number;
201
200
  size?: number;
@@ -208,6 +207,7 @@ interface PostListQuery {
208
207
  lang?: string;
209
208
  }
210
209
  interface PostPatch {
210
+ publicAt?: string | null;
211
211
  categoryId?: string;
212
212
  pinAt?: string | null;
213
213
  authors?: string[];
@@ -216,6 +216,7 @@ interface PostPatch {
216
216
  seo?: PostSeo | null;
217
217
  }
218
218
  interface PostWriteInput {
219
+ publicAt?: string | null;
219
220
  title: string;
220
221
  content: string | LexicalEditorState;
221
222
  text?: string;
@@ -234,10 +235,9 @@ interface PostWriteInput {
234
235
  createdAt?: string;
235
236
  }
236
237
  type DraftRefType = 'post';
237
- type RevisionRelation = 'same' | 'ancestor' | 'descendant' | 'diverged';
238
238
  interface RevisionSnapshot {
239
239
  content: string | null;
240
- contentFormat: string;
240
+ contentFormat: 'lexical';
241
241
  images: unknown[] | null;
242
242
  meta: Record<string, unknown> | null;
243
243
  text: string;
@@ -256,9 +256,14 @@ interface ContentDocument {
256
256
  refType: DraftRefType;
257
257
  publishedRevisionId: string | null;
258
258
  publishAiResources: PublishAiResourceRequest[] | null;
259
+ aiSeo: {
260
+ description: string;
261
+ sourceHash: string;
262
+ } | null;
259
263
  createdAt: string;
260
264
  updatedAt: string | null;
261
265
  }
266
+ type DraftRelation = 'ahead' | 'fresh' | 'in_sync';
262
267
  interface DraftBranch {
263
268
  id: string;
264
269
  documentId: string;
@@ -269,7 +274,7 @@ interface DraftBranch {
269
274
  headRevision: ContentRevision;
270
275
  baseRevision: ContentRevision;
271
276
  publishedRevision: ContentRevision | null;
272
- relationToPublished: RevisionRelation | null;
277
+ relation: DraftRelation;
273
278
  createdAt: string;
274
279
  updatedAt: string | null;
275
280
  }
@@ -293,8 +298,9 @@ interface CreateDraftInput {
293
298
  refId?: string;
294
299
  baseRevisionId?: string | null;
295
300
  data: DraftWriteData;
301
+ ifInSync?: boolean;
296
302
  }
297
- type PublishAiResource = 'insights' | 'summary' | 'translation' | 'tts';
303
+ type PublishAiResource = 'insights' | 'seo' | 'summary' | 'translation' | 'tts';
298
304
  interface PublishAiResourceRequest {
299
305
  resource: PublishAiResource;
300
306
  mode: 'sync' | 'async';
@@ -343,7 +349,7 @@ interface Translation {
343
349
  summary: string | null;
344
350
  tags: string[];
345
351
  content: string | null;
346
- contentFormat: string | null;
352
+ contentFormat: 'lexical' | null;
347
353
  isLocked: boolean;
348
354
  aiModel: string | null;
349
355
  aiProvider: string | null;
@@ -414,8 +420,6 @@ interface UploadedFile {
414
420
  storageBackend?: string;
415
421
  storageKey?: string;
416
422
  }
417
- //#endregion
418
- //#region src/http.d.ts
419
423
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
420
424
  type QueryValue = string | number | boolean | null | undefined | ReadonlyArray<string | number>;
421
425
  interface ClientOptions {
@@ -434,7 +438,7 @@ interface RequestOptions {
434
438
  preserve?: readonly string[];
435
439
  signal?: AbortSignal;
436
440
  }
437
- declare class HttpCore {
441
+ export declare class HttpCore {
438
442
  private readonly options;
439
443
  readonly endpoint: string;
440
444
  private readonly fetchImpl;
@@ -445,8 +449,6 @@ declare class HttpCore {
445
449
  private transform;
446
450
  private toError;
447
451
  }
448
- //#endregion
449
- //#region src/resources/authors.d.ts
450
452
  declare class AuthorsResource {
451
453
  private readonly http;
452
454
  constructor(http: HttpCore);
@@ -454,8 +456,6 @@ declare class AuthorsResource {
454
456
  listAll(): Promise<Author[]>;
455
457
  get(idOrUsername: string): Promise<ApiResponse<Author, Record<string, unknown>>>;
456
458
  }
457
- //#endregion
458
- //#region src/resources/content.d.ts
459
459
  declare class CategoriesResource {
460
460
  private readonly http;
461
461
  constructor(http: HttpCore);
@@ -509,8 +509,6 @@ declare class FilesResource {
509
509
  immutable?: boolean;
510
510
  }): Promise<ApiResponse<UploadedFile, Record<string, unknown>>>;
511
511
  }
512
- //#endregion
513
- //#region src/resources/drafts.d.ts
514
512
  declare class DraftsResource {
515
513
  private readonly http;
516
514
  constructor(http: HttpCore);
@@ -530,8 +528,6 @@ declare class DraftsResource {
530
528
  }): Promise<ApiResponse<DraftBranch, Record<string, unknown>>>;
531
529
  delete(id: string): Promise<ApiResponse<void, Record<string, unknown>>>;
532
530
  }
533
- //#endregion
534
- //#region src/resources/tasks.d.ts
535
531
  interface WaitForTaskOptions {
536
532
  intervalMs?: number;
537
533
  timeoutMs?: number;
@@ -553,8 +549,6 @@ declare class PublishJobsResource {
553
549
  result: PublishTaskResult;
554
550
  }>;
555
551
  }
556
- //#endregion
557
- //#region src/resources/posts.d.ts
558
552
  interface PostSaveOptions extends WaitForTaskOptions {
559
553
  publish?: boolean;
560
554
  aiResources?: Array<PublishAiResource | PublishAiResourceRequest>;
@@ -565,7 +559,7 @@ interface PostSaveResult {
565
559
  postId: string | null;
566
560
  taskId: string | null;
567
561
  }
568
- declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
562
+ export declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
569
563
  declare class PostsResource {
570
564
  private readonly http;
571
565
  private readonly drafts;
@@ -583,6 +577,7 @@ declare class PostsResource {
583
577
  }): Promise<ApiResponse<Post, PostResponseMeta>>;
584
578
  getPath(slug: string): Promise<ApiResponse<{
585
579
  path: string;
580
+ url?: string;
586
581
  }, Record<string, unknown>>>;
587
582
  findBySlug(slug: string, options?: {
588
583
  lang?: string;
@@ -599,8 +594,6 @@ declare class PostsResource {
599
594
  revise(id: string, input: Partial<PostWriteInput>, options?: PostSaveOptions): Promise<PostSaveResult>;
600
595
  private finish;
601
596
  }
602
- //#endregion
603
- //#region src/resources/users.d.ts
604
597
  declare class UsersResource {
605
598
  private readonly http;
606
599
  constructor(http: HttpCore);
@@ -630,9 +623,7 @@ declare class InvitesResource {
630
623
  get(token: string): Promise<ApiResponse<PublicInvite, Record<string, unknown>>>;
631
624
  accept(token: string, input: AcceptInviteInput): Promise<ApiResponse<UserDetail, Record<string, unknown>>>;
632
625
  }
633
- //#endregion
634
- //#region src/client.d.ts
635
- declare class BylineClient {
626
+ export declare class BylineClient {
636
627
  readonly http: HttpCore;
637
628
  readonly posts: PostsResource;
638
629
  readonly drafts: DraftsResource;
@@ -647,10 +638,8 @@ declare class BylineClient {
647
638
  readonly files: FilesResource;
648
639
  constructor(options: ClientOptions);
649
640
  }
650
- declare const createClient: (options: ClientOptions) => BylineClient;
651
- //#endregion
652
- //#region src/error.d.ts
653
- declare class BylineApiError extends Error {
641
+ export declare const createClient: (options: ClientOptions) => BylineClient;
642
+ export declare class BylineApiError extends Error {
654
643
  readonly status: number;
655
644
  readonly code: string;
656
645
  readonly path: string;
@@ -658,6 +647,5 @@ declare class BylineApiError extends Error {
658
647
  readonly name = "BylineApiError";
659
648
  constructor(status: number, code: string, message: string, path: string, details?: unknown | undefined);
660
649
  }
661
- declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
662
- //#endregion
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 };
650
+ export declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
651
+ 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
- //#region src/case.d.ts
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,14 @@ 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;
176
+ url?: string;
178
177
  text: string;
179
178
  content: string | null;
180
- contentFormat: string;
179
+ contentFormat: 'lexical';
181
180
  summary: string | null;
182
181
  images: PostImage[] | null;
183
182
  meta: Record<string, unknown> | null;
@@ -195,7 +194,7 @@ interface Post {
195
194
  seo: PostSeo | null;
196
195
  [key: string]: unknown;
197
196
  }
198
- type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt';
197
+ type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt' | 'publicAt';
199
198
  interface PostListQuery {
200
199
  page?: number;
201
200
  size?: number;
@@ -208,6 +207,7 @@ interface PostListQuery {
208
207
  lang?: string;
209
208
  }
210
209
  interface PostPatch {
210
+ publicAt?: string | null;
211
211
  categoryId?: string;
212
212
  pinAt?: string | null;
213
213
  authors?: string[];
@@ -216,6 +216,7 @@ interface PostPatch {
216
216
  seo?: PostSeo | null;
217
217
  }
218
218
  interface PostWriteInput {
219
+ publicAt?: string | null;
219
220
  title: string;
220
221
  content: string | LexicalEditorState;
221
222
  text?: string;
@@ -234,10 +235,9 @@ interface PostWriteInput {
234
235
  createdAt?: string;
235
236
  }
236
237
  type DraftRefType = 'post';
237
- type RevisionRelation = 'same' | 'ancestor' | 'descendant' | 'diverged';
238
238
  interface RevisionSnapshot {
239
239
  content: string | null;
240
- contentFormat: string;
240
+ contentFormat: 'lexical';
241
241
  images: unknown[] | null;
242
242
  meta: Record<string, unknown> | null;
243
243
  text: string;
@@ -256,9 +256,14 @@ interface ContentDocument {
256
256
  refType: DraftRefType;
257
257
  publishedRevisionId: string | null;
258
258
  publishAiResources: PublishAiResourceRequest[] | null;
259
+ aiSeo: {
260
+ description: string;
261
+ sourceHash: string;
262
+ } | null;
259
263
  createdAt: string;
260
264
  updatedAt: string | null;
261
265
  }
266
+ type DraftRelation = 'ahead' | 'fresh' | 'in_sync';
262
267
  interface DraftBranch {
263
268
  id: string;
264
269
  documentId: string;
@@ -269,7 +274,7 @@ interface DraftBranch {
269
274
  headRevision: ContentRevision;
270
275
  baseRevision: ContentRevision;
271
276
  publishedRevision: ContentRevision | null;
272
- relationToPublished: RevisionRelation | null;
277
+ relation: DraftRelation;
273
278
  createdAt: string;
274
279
  updatedAt: string | null;
275
280
  }
@@ -293,8 +298,9 @@ interface CreateDraftInput {
293
298
  refId?: string;
294
299
  baseRevisionId?: string | null;
295
300
  data: DraftWriteData;
301
+ ifInSync?: boolean;
296
302
  }
297
- type PublishAiResource = 'insights' | 'summary' | 'translation' | 'tts';
303
+ type PublishAiResource = 'insights' | 'seo' | 'summary' | 'translation' | 'tts';
298
304
  interface PublishAiResourceRequest {
299
305
  resource: PublishAiResource;
300
306
  mode: 'sync' | 'async';
@@ -343,7 +349,7 @@ interface Translation {
343
349
  summary: string | null;
344
350
  tags: string[];
345
351
  content: string | null;
346
- contentFormat: string | null;
352
+ contentFormat: 'lexical' | null;
347
353
  isLocked: boolean;
348
354
  aiModel: string | null;
349
355
  aiProvider: string | null;
@@ -414,8 +420,6 @@ interface UploadedFile {
414
420
  storageBackend?: string;
415
421
  storageKey?: string;
416
422
  }
417
- //#endregion
418
- //#region src/http.d.ts
419
423
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
420
424
  type QueryValue = string | number | boolean | null | undefined | ReadonlyArray<string | number>;
421
425
  interface ClientOptions {
@@ -434,7 +438,7 @@ interface RequestOptions {
434
438
  preserve?: readonly string[];
435
439
  signal?: AbortSignal;
436
440
  }
437
- declare class HttpCore {
441
+ export declare class HttpCore {
438
442
  private readonly options;
439
443
  readonly endpoint: string;
440
444
  private readonly fetchImpl;
@@ -445,8 +449,6 @@ declare class HttpCore {
445
449
  private transform;
446
450
  private toError;
447
451
  }
448
- //#endregion
449
- //#region src/resources/authors.d.ts
450
452
  declare class AuthorsResource {
451
453
  private readonly http;
452
454
  constructor(http: HttpCore);
@@ -454,8 +456,6 @@ declare class AuthorsResource {
454
456
  listAll(): Promise<Author[]>;
455
457
  get(idOrUsername: string): Promise<ApiResponse<Author, Record<string, unknown>>>;
456
458
  }
457
- //#endregion
458
- //#region src/resources/content.d.ts
459
459
  declare class CategoriesResource {
460
460
  private readonly http;
461
461
  constructor(http: HttpCore);
@@ -509,8 +509,6 @@ declare class FilesResource {
509
509
  immutable?: boolean;
510
510
  }): Promise<ApiResponse<UploadedFile, Record<string, unknown>>>;
511
511
  }
512
- //#endregion
513
- //#region src/resources/drafts.d.ts
514
512
  declare class DraftsResource {
515
513
  private readonly http;
516
514
  constructor(http: HttpCore);
@@ -530,8 +528,6 @@ declare class DraftsResource {
530
528
  }): Promise<ApiResponse<DraftBranch, Record<string, unknown>>>;
531
529
  delete(id: string): Promise<ApiResponse<void, Record<string, unknown>>>;
532
530
  }
533
- //#endregion
534
- //#region src/resources/tasks.d.ts
535
531
  interface WaitForTaskOptions {
536
532
  intervalMs?: number;
537
533
  timeoutMs?: number;
@@ -553,8 +549,6 @@ declare class PublishJobsResource {
553
549
  result: PublishTaskResult;
554
550
  }>;
555
551
  }
556
- //#endregion
557
- //#region src/resources/posts.d.ts
558
552
  interface PostSaveOptions extends WaitForTaskOptions {
559
553
  publish?: boolean;
560
554
  aiResources?: Array<PublishAiResource | PublishAiResourceRequest>;
@@ -565,7 +559,7 @@ interface PostSaveResult {
565
559
  postId: string | null;
566
560
  taskId: string | null;
567
561
  }
568
- declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
562
+ export declare const toDraftData: (input: Partial<PostWriteInput>) => DraftWriteData;
569
563
  declare class PostsResource {
570
564
  private readonly http;
571
565
  private readonly drafts;
@@ -583,6 +577,7 @@ declare class PostsResource {
583
577
  }): Promise<ApiResponse<Post, PostResponseMeta>>;
584
578
  getPath(slug: string): Promise<ApiResponse<{
585
579
  path: string;
580
+ url?: string;
586
581
  }, Record<string, unknown>>>;
587
582
  findBySlug(slug: string, options?: {
588
583
  lang?: string;
@@ -599,8 +594,6 @@ declare class PostsResource {
599
594
  revise(id: string, input: Partial<PostWriteInput>, options?: PostSaveOptions): Promise<PostSaveResult>;
600
595
  private finish;
601
596
  }
602
- //#endregion
603
- //#region src/resources/users.d.ts
604
597
  declare class UsersResource {
605
598
  private readonly http;
606
599
  constructor(http: HttpCore);
@@ -630,9 +623,7 @@ declare class InvitesResource {
630
623
  get(token: string): Promise<ApiResponse<PublicInvite, Record<string, unknown>>>;
631
624
  accept(token: string, input: AcceptInviteInput): Promise<ApiResponse<UserDetail, Record<string, unknown>>>;
632
625
  }
633
- //#endregion
634
- //#region src/client.d.ts
635
- declare class BylineClient {
626
+ export declare class BylineClient {
636
627
  readonly http: HttpCore;
637
628
  readonly posts: PostsResource;
638
629
  readonly drafts: DraftsResource;
@@ -647,10 +638,8 @@ declare class BylineClient {
647
638
  readonly files: FilesResource;
648
639
  constructor(options: ClientOptions);
649
640
  }
650
- declare const createClient: (options: ClientOptions) => BylineClient;
651
- //#endregion
652
- //#region src/error.d.ts
653
- declare class BylineApiError extends Error {
641
+ export declare const createClient: (options: ClientOptions) => BylineClient;
642
+ export declare class BylineApiError extends Error {
654
643
  readonly status: number;
655
644
  readonly code: string;
656
645
  readonly path: string;
@@ -658,6 +647,5 @@ declare class BylineApiError extends Error {
658
647
  readonly name = "BylineApiError";
659
648
  constructor(status: number, code: string, message: string, path: string, details?: unknown | undefined);
660
649
  }
661
- declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
662
- //#endregion
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 };
650
+ export declare const isBylineApiError: (error: unknown, code?: string) => error is BylineApiError;
651
+ 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
- //#region src/case.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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.1.2",
3
+ "version": "0.2.1",
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.22.8",
47
+ "tsdown": "0.23.1",
48
48
  "typescript": "6.0.3",
49
49
  "vitest": "5.0.5"
50
50
  },