@mx-space/api-client 3.1.0 → 3.5.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.mjs CHANGED
@@ -33,7 +33,6 @@ const attachRawFromOneToAnthor = (from, to) => {
33
33
  });
34
34
  });
35
35
  };
36
-
37
36
  //#endregion
38
37
  //#region utils/camelcase-keys.ts
39
38
  /**
@@ -55,14 +54,12 @@ function camelcase(str) {
55
54
  });
56
55
  }
57
56
  const isMongoId = (id) => id.length === 24 && /^[\dA-F]{24}$/i.test(id);
58
-
59
57
  //#endregion
60
58
  //#region utils/path.ts
61
59
  const resolveFullPath = (endpoint, path) => {
62
60
  if (!path.startsWith("/")) path = `/${path}`;
63
61
  return `${endpoint}${path}`;
64
62
  };
65
-
66
63
  //#endregion
67
64
  //#region utils/auto-bind.ts
68
65
  const getAllProperties = (object) => {
@@ -86,7 +83,6 @@ function autoBind(self, { include, exclude } = {}) {
86
83
  }
87
84
  return self;
88
85
  }
89
-
90
86
  //#endregion
91
87
  //#region controllers/ack.ts
92
88
  /**
@@ -112,7 +108,6 @@ var AckController = class {
112
108
  } });
113
109
  }
114
110
  };
115
-
116
111
  //#endregion
117
112
  //#region controllers/activity.ts
118
113
  /**
@@ -139,7 +134,17 @@ var ActivityController = class {
139
134
  * @support core >= 5.0.0
140
135
  */
141
136
  getPresence(roomName) {
142
- return this.proxy.presence.get({ params: { room_name: roomName } });
137
+ return this.proxy.presence.get({
138
+ params: { room_name: roomName },
139
+ transformResponse: (data) => {
140
+ const payload = data;
141
+ return {
142
+ ...camelcaseKeys(Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "data" && key !== "readers"))),
143
+ data: Object.fromEntries(Object.entries(payload.data ?? {}).map(([identity, value]) => [identity, camelcaseKeys(value)])),
144
+ readers: Object.fromEntries(Object.entries(payload.readers ?? {}).map(([id, value]) => [id, camelcaseKeys(value)]))
145
+ };
146
+ }
147
+ });
143
148
  }
144
149
  /**
145
150
  *
@@ -166,7 +171,6 @@ var ActivityController = class {
166
171
  return this.proxy(`last-year`).publication.get();
167
172
  }
168
173
  };
169
-
170
174
  //#endregion
171
175
  //#region controllers/aggregate.ts
172
176
  var AggregateController = class {
@@ -217,7 +221,6 @@ var AggregateController = class {
217
221
  return this.proxy.stat.get();
218
222
  }
219
223
  };
220
-
221
224
  //#endregion
222
225
  //#region controllers/ai.ts
223
226
  /**
@@ -249,7 +252,7 @@ var AIController = class {
249
252
  });
250
253
  }
251
254
  /**
252
- * Core >= 8.3.0
255
+ * @deprecated Feature removed from core; see ai-insights equivalent.
253
256
  * @param articleId
254
257
  */
255
258
  async getDeepReading(articleId) {
@@ -332,8 +335,49 @@ var AIController = class {
332
335
  }
333
336
  });
334
337
  }
338
+ /**
339
+ * Get cached AI insights for an article
340
+ * @support core >= 11.3.0
341
+ */
342
+ async getInsights({ articleId, lang = "zh", onlyDb }) {
343
+ return this.proxy.insights.article(articleId).get({ params: {
344
+ lang,
345
+ onlyDb
346
+ } });
347
+ }
348
+ /**
349
+ * Get URL for streaming insights generation (SSE)
350
+ *
351
+ * @see AIInsightsStreamEvent for event types
352
+ * @support core >= 11.3.0
353
+ */
354
+ getInsightsGenerateUrl({ articleId, lang }) {
355
+ const baseUrl = this.client.endpoint;
356
+ const params = new URLSearchParams();
357
+ if (lang) params.set("lang", lang);
358
+ const query = params.toString();
359
+ return `${baseUrl}/${this.base}/insights/article/${articleId}/generate${query ? `?${query}` : ""}`;
360
+ }
361
+ /**
362
+ * Stream insights generation using fetch
363
+ *
364
+ * @see AIInsightsStreamEvent for event types
365
+ * @support core >= 11.3.0
366
+ */
367
+ async streamInsightsGenerate({ articleId, lang }, fetchOptions) {
368
+ const url = this.getInsightsGenerateUrl({
369
+ articleId,
370
+ lang
371
+ });
372
+ return fetch(url, {
373
+ ...fetchOptions,
374
+ headers: {
375
+ Accept: "text/event-stream",
376
+ ...fetchOptions?.headers
377
+ }
378
+ });
379
+ }
335
380
  };
336
-
337
381
  //#endregion
338
382
  //#region core/error.ts
339
383
  var RequestError = class extends Error {
@@ -344,7 +388,6 @@ var RequestError = class extends Error {
344
388
  this.raw = raw;
345
389
  }
346
390
  };
347
-
348
391
  //#endregion
349
392
  //#region models/category.ts
350
393
  let CategoryType = /* @__PURE__ */ function(CategoryType) {
@@ -352,7 +395,6 @@ let CategoryType = /* @__PURE__ */ function(CategoryType) {
352
395
  CategoryType[CategoryType["Tag"] = 1] = "Tag";
353
396
  return CategoryType;
354
397
  }({});
355
-
356
398
  //#endregion
357
399
  //#region controllers/category.ts
358
400
  var CategoryController = class {
@@ -366,10 +408,10 @@ var CategoryController = class {
366
408
  return this.client.proxy(this.base);
367
409
  }
368
410
  getAllCategories() {
369
- return this.proxy.get({ params: { type: CategoryType.Category } });
411
+ return this.proxy.get({ params: { type: 0 } });
370
412
  }
371
413
  getAllTags() {
372
- return this.proxy.get({ params: { type: CategoryType.Tag } });
414
+ return this.proxy.get({ params: { type: 1 } });
373
415
  }
374
416
  async getCategoryDetail(ids) {
375
417
  if (typeof ids === "string") {
@@ -393,7 +435,6 @@ var CategoryController = class {
393
435
  return await this.proxy(name).get({ params: { tag: 1 } });
394
436
  }
395
437
  };
396
-
397
438
  //#endregion
398
439
  //#region controllers/comment.ts
399
440
  var CommentController = class {
@@ -416,11 +457,13 @@ var CommentController = class {
416
457
  * 获取文章的评论列表
417
458
  * @param refId 文章 Id
418
459
  */
419
- getByRefId(refId, pagination = {}) {
420
- const { page, size } = pagination;
460
+ getByRefId(refId, params = {}) {
461
+ const { page, size, sort, around } = params;
421
462
  return this.proxy.ref(refId).get({ params: {
422
463
  page: page || 1,
423
- size: size || 10
464
+ size: size || 10,
465
+ ...sort ? { sort } : {},
466
+ ...around ? { around } : {}
424
467
  } });
425
468
  }
426
469
  getThreadReplies(rootCommentId, params = {}) {
@@ -445,7 +488,6 @@ var CommentController = class {
445
488
  return this.proxy.reader.reply(commentId).post({ data });
446
489
  }
447
490
  };
448
-
449
491
  //#endregion
450
492
  //#region controllers/base.ts
451
493
  var BaseCrudController = class {
@@ -475,7 +517,6 @@ var BaseCrudController = class {
475
517
  } });
476
518
  }
477
519
  };
478
-
479
520
  //#endregion
480
521
  //#region controllers/link.ts
481
522
  var LinkController = class extends BaseCrudController {
@@ -494,7 +535,6 @@ var LinkController = class extends BaseCrudController {
494
535
  return await this.proxy.audit.post({ data });
495
536
  }
496
537
  };
497
-
498
538
  //#endregion
499
539
  //#region controllers/note.ts
500
540
  var NoteController = class {
@@ -590,7 +630,6 @@ var NoteController = class {
590
630
  } });
591
631
  }
592
632
  };
593
-
594
633
  //#endregion
595
634
  //#region controllers/owner.ts
596
635
  var UserController = class {
@@ -665,7 +704,6 @@ var UserController = class {
665
704
  return this.proxy.check_logged.get({ params: normalized ? { token: normalized } : void 0 });
666
705
  }
667
706
  };
668
-
669
707
  //#endregion
670
708
  //#region controllers/page.ts
671
709
  var PageController = class {
@@ -706,7 +744,6 @@ var PageController = class {
706
744
  return this.proxy.slug(slug).get({ params: options?.prefer ? { prefer: options.prefer } : void 0 });
707
745
  }
708
746
  };
709
-
710
747
  //#endregion
711
748
  //#region controllers/post.ts
712
749
  var PostController = class {
@@ -758,7 +795,6 @@ var PostController = class {
758
795
  return this.proxy("get-url")(slug).get();
759
796
  }
760
797
  };
761
-
762
798
  //#endregion
763
799
  //#region controllers/project.ts
764
800
  var ProjectController = class extends BaseCrudController {
@@ -770,7 +806,6 @@ var ProjectController = class extends BaseCrudController {
770
806
  autoBind(this);
771
807
  }
772
808
  };
773
-
774
809
  //#endregion
775
810
  //#region controllers/recently.ts
776
811
  let RecentlyAttitudeResultEnum = /* @__PURE__ */ function(RecentlyAttitudeResultEnum) {
@@ -817,7 +852,6 @@ var RecentlyController = class {
817
852
  return this.proxy.attitude(id).get({ params: { attitude } });
818
853
  }
819
854
  };
820
-
821
855
  //#endregion
822
856
  //#region controllers/say.ts
823
857
  var SayController = class extends BaseCrudController {
@@ -838,7 +872,6 @@ var SayController = class extends BaseCrudController {
838
872
  return this.proxy.random.get();
839
873
  }
840
874
  };
841
-
842
875
  //#endregion
843
876
  //#region controllers/search.ts
844
877
  var SearchController = class {
@@ -864,7 +897,6 @@ var SearchController = class {
864
897
  } });
865
898
  }
866
899
  };
867
-
868
900
  //#endregion
869
901
  //#region controllers/severless.ts
870
902
  var ServerlessController = class {
@@ -881,7 +913,6 @@ var ServerlessController = class {
881
913
  return this.proxy(reference)(name).get();
882
914
  }
883
915
  };
884
-
885
916
  //#endregion
886
917
  //#region controllers/snippet.ts
887
918
  var SnippetController = class {
@@ -898,7 +929,6 @@ var SnippetController = class {
898
929
  return this.proxy(reference)(name).get();
899
930
  }
900
931
  };
901
-
902
932
  //#endregion
903
933
  //#region controllers/subscribe.ts
904
934
  var SubscribeController = class {
@@ -930,7 +960,6 @@ var SubscribeController = class {
930
960
  } });
931
961
  }
932
962
  };
933
-
934
963
  //#endregion
935
964
  //#region controllers/topic.ts
936
965
  var TopicController = class extends BaseCrudController {
@@ -948,7 +977,6 @@ var TopicController = class extends BaseCrudController {
948
977
  return this.proxy.slug(slug).get();
949
978
  }
950
979
  };
951
-
952
980
  //#endregion
953
981
  //#region controllers/index.ts
954
982
  const allControllers = [
@@ -995,7 +1023,6 @@ const allControllerNames = [
995
1023
  "friend",
996
1024
  "shorthand"
997
1025
  ];
998
-
999
1026
  //#endregion
1000
1027
  //#region core/attach-request.ts
1001
1028
  function attachRequestMethod(target) {
@@ -1025,7 +1052,6 @@ function handleSearchParams(obj) {
1025
1052
  });
1026
1053
  return search.toString();
1027
1054
  }
1028
-
1029
1055
  //#endregion
1030
1056
  //#region core/client.ts
1031
1057
  const methodPrefix = "_$";
@@ -1113,14 +1139,15 @@ var HTTPClient = class {
1113
1139
  return path.startsWith("/") ? path : `/${path}`;
1114
1140
  }
1115
1141
  };
1116
- if (methods.includes(name)) return async (options) => {
1142
+ if (methods.includes(name)) return async (options = {}) => {
1117
1143
  const url = resolveFullPath(that.endpoint, route.join("/"));
1118
1144
  route.length = 0;
1145
+ const { transformResponse: perRequestTransformResponse, ...requestOptions } = options;
1119
1146
  let res;
1120
1147
  try {
1121
1148
  res = await manager.request({
1122
1149
  method: name,
1123
- ...options,
1150
+ ...requestOptions,
1124
1151
  url
1125
1152
  });
1126
1153
  } catch (error) {
@@ -1135,7 +1162,8 @@ var HTTPClient = class {
1135
1162
  }
1136
1163
  const data = that.options.getDataFromResponse(res);
1137
1164
  if (!data) return null;
1138
- const cameledObject = (Array.isArray(data) || isPlainObject(data)) && that.options.transformResponse ? that.options.transformResponse(data) : data;
1165
+ const responseTransformer = perRequestTransformResponse === void 0 ? that.options.transformResponse : perRequestTransformResponse || void 0;
1166
+ const cameledObject = (Array.isArray(data) || isPlainObject(data)) && responseTransformer ? responseTransformer(data) : data;
1139
1167
  let nextObject = cameledObject;
1140
1168
  if (cameledObject && typeof cameledObject === "object") {
1141
1169
  nextObject = Array.isArray(cameledObject) ? [...cameledObject] : { ...cameledObject };
@@ -1182,7 +1210,6 @@ function createClient(adapter) {
1182
1210
  return client;
1183
1211
  };
1184
1212
  }
1185
-
1186
1213
  //#endregion
1187
1214
  //#region models/aggregate.ts
1188
1215
  let TimelineType = /* @__PURE__ */ function(TimelineType) {
@@ -1190,7 +1217,6 @@ let TimelineType = /* @__PURE__ */ function(TimelineType) {
1190
1217
  TimelineType[TimelineType["Note"] = 1] = "Note";
1191
1218
  return TimelineType;
1192
1219
  }({});
1193
-
1194
1220
  //#endregion
1195
1221
  //#region ../../apps/core/src/constants/db.constant.ts
1196
1222
  const NOTE_COLLECTION_NAME = "notes";
@@ -1204,7 +1230,6 @@ let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes) {
1204
1230
  CollectionRefTypes[CollectionRefTypes["Recently"] = RECENTLY_COLLECTION_NAME] = "Recently";
1205
1231
  return CollectionRefTypes;
1206
1232
  }({});
1207
-
1208
1233
  //#endregion
1209
1234
  //#region models/comment.ts
1210
1235
  let CommentState = /* @__PURE__ */ function(CommentState) {
@@ -1213,7 +1238,6 @@ let CommentState = /* @__PURE__ */ function(CommentState) {
1213
1238
  CommentState[CommentState["Junk"] = 2] = "Junk";
1214
1239
  return CommentState;
1215
1240
  }({});
1216
-
1217
1241
  //#endregion
1218
1242
  //#region models/link.ts
1219
1243
  let LinkType = /* @__PURE__ */ function(LinkType) {
@@ -1229,7 +1253,6 @@ let LinkState = /* @__PURE__ */ function(LinkState) {
1229
1253
  LinkState[LinkState["Reject"] = 4] = "Reject";
1230
1254
  return LinkState;
1231
1255
  }({});
1232
-
1233
1256
  //#endregion
1234
1257
  //#region models/page.ts
1235
1258
  let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
@@ -1238,7 +1261,6 @@ let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
1238
1261
  EnumPageType["frame"] = "frame";
1239
1262
  return EnumPageType;
1240
1263
  }({});
1241
-
1242
1264
  //#endregion
1243
1265
  //#region models/recently.ts
1244
1266
  let RecentlyRefTypes = /* @__PURE__ */ function(RecentlyRefTypes) {
@@ -1258,7 +1280,6 @@ let RecentlyTypeEnum = /* @__PURE__ */ function(RecentlyTypeEnum) {
1258
1280
  RecentlyTypeEnum["Code"] = "code";
1259
1281
  return RecentlyTypeEnum;
1260
1282
  }({});
1261
-
1262
1283
  //#endregion
1263
1284
  //#region models/snippet.ts
1264
1285
  let SnippetType = /* @__PURE__ */ function(SnippetType) {
@@ -1268,7 +1289,6 @@ let SnippetType = /* @__PURE__ */ function(SnippetType) {
1268
1289
  SnippetType["YAML"] = "yaml";
1269
1290
  return SnippetType;
1270
1291
  }({});
1271
-
1272
1292
  //#endregion
1273
1293
  //#region ../../apps/core/src/modules/subscribe/subscribe.constant.ts
1274
1294
  const SubscribePostCreateBit = 1;
@@ -1277,16 +1297,14 @@ const SubscribeSayCreateBit = 4;
1277
1297
  const SubscribeRecentCreateBit = 8;
1278
1298
  const SubscribeAllBit = 15;
1279
1299
  const SubscribeTypeToBitMap = {
1280
- post_c: SubscribePostCreateBit,
1281
- note_c: SubscribeNoteCreateBit,
1282
- say_c: SubscribeSayCreateBit,
1283
- recently_c: SubscribeRecentCreateBit,
1284
- all: SubscribeAllBit
1300
+ post_c: 1,
1301
+ note_c: 2,
1302
+ say_c: 4,
1303
+ recently_c: 8,
1304
+ all: 15
1285
1305
  };
1286
-
1287
1306
  //#endregion
1288
1307
  //#region index.ts
1289
1308
  var api_client_default = createClient;
1290
-
1291
1309
  //#endregion
1292
- export { AIController, AckController, ActivityController, AggregateController, CategoryController, CategoryType, CollectionRefTypes, CommentController, CommentState, EnumPageType, LinkController, LinkState, LinkType, NoteController, PageController, PostController, ProjectController, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, RecentlyRefTypes, RecentlyTypeEnum, RequestError, SayController, SearchController, ServerlessController, SnippetController, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, SubscribeTypeToBitMap, TimelineType, TopicController, UserController, allControllerNames, allControllers, createClient, api_client_default as default, camelcaseKeys as simpleCamelcaseKeys };
1310
+ export { AIController, AckController, ActivityController, AggregateController, CategoryController, CategoryType, CollectionRefTypes, CommentController, CommentState, EnumPageType, LinkController, LinkState, LinkType, NoteController, PageController, PostController, ProjectController, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, RecentlyRefTypes, RecentlyTypeEnum, RequestError, SayController, SearchController, ServerlessController, SnippetController, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, SubscribeTypeToBitMap, TimelineType, TopicController, UserController, allControllerNames, allControllers, createClient, api_client_default as default, camelcaseKeys as simpleCamelcaseKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mx-space/api-client",
3
- "version": "3.1.0",
3
+ "version": "3.5.0",
4
4
  "description": "A api client for mx-space server@next",
5
5
  "type": "module",
6
6
  "engines": {
@@ -53,15 +53,15 @@
53
53
  "@types/cors": "2.8.19",
54
54
  "@types/express": "5.0.6",
55
55
  "abort-controller": "3.0.0",
56
- "axios": "^1.13.3",
56
+ "axios": "^1.15.0",
57
57
  "camelcase-keys": "^10.0.2",
58
58
  "cors": "2.8.6",
59
- "es-toolkit": "1.45.0",
60
- "express": "4.21.2",
59
+ "es-toolkit": "1.45.1",
60
+ "express": "5.2.1",
61
61
  "form-data": "4.0.5",
62
- "tsdown": "0.21.0-beta.2",
62
+ "tsdown": "0.21.9",
63
63
  "umi-request": "1.4.0",
64
- "vite": "^7.3.1",
65
- "vitest": "4.0.18"
64
+ "vite": "^8.0.8",
65
+ "vitest": "4.1.4"
66
66
  }
67
67
  }