@mx-space/api-client 1.21.2 → 2.1.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/dist/index.cjs CHANGED
@@ -246,6 +246,83 @@ var AIController = class {
246
246
  async getDeepReading(articleId) {
247
247
  return this.proxy("deep-readings").article(articleId).get();
248
248
  }
249
+ /**
250
+ * Get translation for an article
251
+ * @support core >= 9.4.0
252
+ */
253
+ async getTranslation({ articleId, lang }) {
254
+ return this.proxy.translations.article(articleId).get({ params: { lang } });
255
+ }
256
+ /**
257
+ * Get available translation languages for an article
258
+ * @support core >= 9.4.0
259
+ */
260
+ async getAvailableLanguages(articleId) {
261
+ return this.proxy.translations.article(articleId).languages.get();
262
+ }
263
+ /**
264
+ * Get URL for streaming summary generation (SSE)
265
+ *
266
+ * @see AISummaryStreamEvent for event types
267
+ * @support core >= 9.4.0
268
+ */
269
+ getSummaryGenerateUrl({ articleId, lang }) {
270
+ const baseUrl = this.client.endpoint;
271
+ const params = new URLSearchParams();
272
+ if (lang) params.set("lang", lang);
273
+ const query = params.toString();
274
+ return `${baseUrl}/${this.base}/summaries/article/${articleId}/generate${query ? `?${query}` : ""}`;
275
+ }
276
+ /**
277
+ * Stream summary generation using fetch
278
+ *
279
+ * @see AISummaryStreamEvent for event types
280
+ * @support core >= 9.4.0
281
+ */
282
+ async streamSummaryGenerate({ articleId, lang }, fetchOptions) {
283
+ const url = this.getSummaryGenerateUrl({
284
+ articleId,
285
+ lang
286
+ });
287
+ return fetch(url, {
288
+ ...fetchOptions,
289
+ headers: {
290
+ Accept: "text/event-stream",
291
+ ...fetchOptions?.headers
292
+ }
293
+ });
294
+ }
295
+ /**
296
+ * Get URL for streaming translation generation (SSE)
297
+ *
298
+ * @see AITranslationStreamEvent for event types
299
+ * @support core >= 9.4.0
300
+ */
301
+ getTranslationGenerateUrl({ articleId, lang }) {
302
+ const baseUrl = this.client.endpoint;
303
+ const params = new URLSearchParams();
304
+ params.set("lang", lang);
305
+ return `${baseUrl}/${this.base}/translations/article/${articleId}/generate?${params.toString()}`;
306
+ }
307
+ /**
308
+ * Stream translation generation using fetch
309
+ *
310
+ * @see AITranslationStreamEvent for event types
311
+ * @support core >= 9.4.0
312
+ */
313
+ async streamTranslationGenerate({ articleId, lang }, fetchOptions) {
314
+ const url = this.getTranslationGenerateUrl({
315
+ articleId,
316
+ lang
317
+ });
318
+ return fetch(url, {
319
+ ...fetchOptions,
320
+ headers: {
321
+ Accept: "text/event-stream",
322
+ ...fetchOptions?.headers
323
+ }
324
+ });
325
+ }
249
326
  };
250
327
 
251
328
  //#endregion
@@ -432,11 +509,12 @@ var NoteController = class {
432
509
  * @param options 可选参数:password, single, lang
433
510
  */
434
511
  getNoteByNid(nid, options) {
435
- const { password, single, lang } = options || {};
512
+ const { password, single, lang, prefer } = options || {};
436
513
  return this.proxy.nid(nid.toString()).get({ params: {
437
514
  password,
438
515
  single: single ? "1" : void 0,
439
- lang
516
+ lang,
517
+ prefer
440
518
  } });
441
519
  }
442
520
  /**
@@ -484,6 +562,81 @@ var NoteController = class {
484
562
  }
485
563
  };
486
564
 
565
+ //#endregion
566
+ //#region controllers/owner.ts
567
+ var UserController = class {
568
+ constructor(client) {
569
+ this.client = client;
570
+ this.base = "owner";
571
+ this.name = ["owner"];
572
+ autoBind(this);
573
+ }
574
+ get proxy() {
575
+ return this.client.proxy(this.base);
576
+ }
577
+ get authProxy() {
578
+ return this.client.proxy("auth");
579
+ }
580
+ normalizeToken(token) {
581
+ const normalized = token?.trim();
582
+ if (!normalized) return;
583
+ return normalized.replace(/^bearer\s+/i, "");
584
+ }
585
+ /**
586
+ * @deprecated Use `getOwnerInfo()` instead.
587
+ */
588
+ getMasterInfo() {
589
+ return this.getOwnerInfo();
590
+ }
591
+ getOwnerInfo() {
592
+ return this.proxy.get();
593
+ }
594
+ login(username, password, options) {
595
+ return this.authProxy("sign-in").username.post({ data: {
596
+ username,
597
+ password,
598
+ ...options
599
+ } });
600
+ }
601
+ logout() {
602
+ return this.authProxy("sign-out").post();
603
+ }
604
+ /**
605
+ * Better Auth raw session (`/auth/get-session`).
606
+ */
607
+ getAuthSession(options) {
608
+ return this.authProxy("get-session").get({ params: options });
609
+ }
610
+ /**
611
+ * Core session summary (`/auth/session`).
612
+ */
613
+ getSession() {
614
+ return this.authProxy.session.get();
615
+ }
616
+ getProviders() {
617
+ return this.authProxy.providers.get();
618
+ }
619
+ getAllowLoginMethods() {
620
+ return this.proxy("allow-login").get();
621
+ }
622
+ listSessions() {
623
+ return this.authProxy("list-sessions").get();
624
+ }
625
+ revokeSession(token) {
626
+ return this.authProxy("revoke-session").post({ data: { token } });
627
+ }
628
+ revokeSessions() {
629
+ return this.authProxy("revoke-sessions").post();
630
+ }
631
+ revokeOtherSessions() {
632
+ return this.authProxy("revoke-other-sessions").post();
633
+ }
634
+ checkTokenValid(token) {
635
+ const normalized = this.normalizeToken(token);
636
+ return this.proxy.check_logged.get({ params: normalized ? { token: normalized } : void 0 });
637
+ }
638
+ };
639
+
487
640
  //#endregion
488
641
  //#region controllers/page.ts
489
642
  var PageController = class {
@@ -520,8 +673,8 @@ var PageController = class {
520
673
  * @param slug 路径
521
674
  * @returns
522
675
  */
523
- getBySlug(slug) {
524
- return this.proxy.slug(slug).get({});
676
+ getBySlug(slug, options) {
677
+ return this.proxy.slug(slug).get({ params: options?.prefer ? { prefer: options.prefer } : void 0 });
525
678
  }
526
679
  };
527
680
 
@@ -559,7 +712,12 @@ var PostController = class {
559
712
  }
560
713
  getPost(idOrCategoryName, slug, options) {
561
714
  if (arguments.length == 1) return this.proxy(idOrCategoryName).get();
562
- else return this.proxy(idOrCategoryName)(slug).get({ params: options?.lang ? { lang: options.lang } : void 0 });
715
+ else {
716
+ const params = {};
717
+ if (options?.lang) params.lang = options.lang;
718
+ if (options?.prefer) params.prefer = options.prefer;
719
+ return this.proxy(idOrCategoryName)(slug).get({ params: Object.keys(params).length ? params : void 0 });
720
+ }
563
721
  }
564
722
  /**
565
723
  * 获取最新的文章
@@ -769,35 +927,6 @@ var TopicController = class extends BaseCrudController {
769
927
  }
770
928
  };
771
929
 
772
- //#endregion
773
- //#region controllers/user.ts
774
- var UserController = class {
775
- constructor(client) {
776
- this.client = client;
777
- this.base = "master";
778
- this.name = ["user", "master"];
779
- autoBind(this);
780
- }
781
- get proxy() {
782
- return this.client.proxy(this.base);
783
- }
784
- getMasterInfo() {
785
- return this.proxy.get();
786
- }
787
- login(username, password) {
788
- return this.proxy.login.post({ data: {
789
- username,
790
- password
791
- } });
792
- }
793
- loginWithToken(token) {
794
- return this.proxy.login.put({ params: token ? { token: `bearer ${token.replace(/^bearer\s/i, "")}` } : void 0 });
795
- }
796
- checkTokenValid(token) {
797
- return this.proxy.check_logged.get({ params: { token: `bearer ${token.replace(/^bearer\s/i, "")}` } });
798
- }
799
- };
800
-
801
930
  //#endregion
802
931
  //#region controllers/index.ts
803
932
  const allControllers = [
@@ -840,9 +969,8 @@ const allControllerNames = [
840
969
  "snippet",
841
970
  "serverless",
842
971
  "subscribe",
843
- "user",
972
+ "owner",
844
973
  "friend",
845
- "master",
846
974
  "shorthand"
847
975
  ];
848
976
 
@@ -1043,9 +1171,9 @@ let TimelineType = /* @__PURE__ */ function(TimelineType) {
1043
1171
 
1044
1172
  //#endregion
1045
1173
  //#region ../../apps/core/src/constants/db.constant.ts
1046
- const POST_COLLECTION_NAME = "posts";
1047
1174
  const NOTE_COLLECTION_NAME = "notes";
1048
1175
  const PAGE_COLLECTION_NAME = "pages";
1176
+ const POST_COLLECTION_NAME = "posts";
1049
1177
  const RECENTLY_COLLECTION_NAME = "recentlies";
1050
1178
  let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes) {
1051
1179
  CollectionRefTypes[CollectionRefTypes["Post"] = POST_COLLECTION_NAME] = "Post";
@@ -1110,7 +1238,7 @@ let SnippetType = /* @__PURE__ */ function(SnippetType) {
1110
1238
 
1111
1239
  //#endregion
1112
1240
  //#region ../../apps/core/src/modules/subscribe/subscribe.constant.ts
1113
- const SubscribePostCreateBit = Math.trunc(1);
1241
+ const SubscribePostCreateBit = 1;
1114
1242
  const SubscribeNoteCreateBit = 2;
1115
1243
  const SubscribeSayCreateBit = 4;
1116
1244
  const SubscribeRecentCreateBit = 8;