@ones-open/node-sdk 0.0.3 → 0.0.4-10114.223

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.
Files changed (31) hide show
  1. package/dist/index.cjs +131 -51
  2. package/dist/index.js +131 -51
  3. package/dist/types/packages/node/event/index.d.ts +2 -0
  4. package/dist/types/packages/node/event/index.d.ts.map +1 -0
  5. package/dist/types/packages/node/event/types.d.ts +22 -0
  6. package/dist/types/packages/node/event/types.d.ts.map +1 -0
  7. package/dist/types/packages/node/index.d.ts +3 -0
  8. package/dist/types/packages/node/index.d.ts.map +1 -1
  9. package/dist/types/packages/node/oauth/index.d.ts +4 -0
  10. package/dist/types/packages/node/oauth/index.d.ts.map +1 -0
  11. package/dist/types/packages/node/oauth/types.d.ts +28 -0
  12. package/dist/types/packages/node/oauth/types.d.ts.map +1 -0
  13. package/dist/types/packages/node/storage/entity/entity/types.d.ts +20 -20
  14. package/dist/types/packages/node/storage/entity/error/consts.d.ts +29 -29
  15. package/dist/types/packages/node/storage/entity/fetch/index.d.ts.map +1 -1
  16. package/dist/types/packages/node/storage/entity/index.d.ts +1 -1
  17. package/dist/types/packages/node/storage/entity/query/types.d.ts +52 -52
  18. package/dist/types/packages/node/storage/entity/result/types.d.ts +12 -12
  19. package/dist/types/packages/node/storage/entity/sort/consts.d.ts +3 -3
  20. package/dist/types/packages/node/storage/entity/types.d.ts +29 -29
  21. package/dist/types/packages/node/storage/entity/where/index.d.ts +1 -1
  22. package/dist/types/packages/node/storage/object/error/consts.d.ts +4 -4
  23. package/dist/types/packages/node/storage/object/error/index.d.ts +4 -4
  24. package/dist/types/packages/node/storage/object/fetch/index.d.ts.map +1 -1
  25. package/dist/types/packages/node/storage/object/index.d.ts +1 -1
  26. package/dist/types/packages/node/storage/object/result/types.d.ts +3 -3
  27. package/dist/types/packages/node/storage/object/types.d.ts +17 -17
  28. package/dist/types/packages/strict/env/index.d.ts +12 -28
  29. package/dist/types/packages/strict/env/index.d.ts.map +1 -1
  30. package/dist/types/packages/strict/result/types.d.ts +6 -6
  31. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -1,27 +1,85 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty");
4
- const lodashEs = require("lodash-es");
3
+ const node_crypto = require("node:crypto");
5
4
  const Fetch = require("axios");
5
+ const lodashEs = require("lodash-es");
6
6
  const _sortInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/sort");
7
- const getPlatformApiHost = () => {
8
- return "platformApiHost";
7
+ const getONESHostedBaseUrl = () => {
8
+ return process.env.ONES_HOSTED_BASE_URL;
9
+ };
10
+ const getONESHostedAppID = () => {
11
+ return process.env.ONES_HOSTED_APP_ID;
9
12
  };
10
- const getPlatformAPIHost = getPlatformApiHost;
11
- const getInstanceId = () => {
12
- return "instanceId";
13
+ const getONESHostedToken = () => {
14
+ return process.env.ONES_HOSTED_TOKEN;
15
+ };
16
+ const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17
+ __proto__: null,
18
+ getONESHostedAppID,
19
+ getONESHostedBaseUrl,
20
+ getONESHostedToken
21
+ }, Symbol.toStringTag, { value: "Module" }));
22
+ const ASSERTION_TTL_SECONDS = 24 * 60 * 60;
23
+ const ASSERTION_JTI_LENGTH = 16;
24
+ const TOKEN_GRANT_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
25
+ const fetch$2 = Fetch.create();
26
+ const buildJWTAssertion = (installationInfo, userID) => {
27
+ const now = Math.floor(Date.now() / 1e3);
28
+ const header = {
29
+ alg: "HS256",
30
+ typ: "JWT"
31
+ };
32
+ const payload = {
33
+ uid: userID,
34
+ rsh: "",
35
+ iss: installationInfo.installation_id,
36
+ sub: installationInfo.installation_id,
37
+ aud: "oauth",
38
+ exp: now + ASSERTION_TTL_SECONDS,
39
+ iat: now,
40
+ jti: node_crypto.randomUUID().replace(/-/g, "").slice(0, ASSERTION_JTI_LENGTH)
41
+ };
42
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
43
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
44
+ const signingInput = `${encodedHeader}.${encodedPayload}`;
45
+ const signKey = Buffer.from(installationInfo.shared_secret, "base64");
46
+ const signature = node_crypto.createHmac("sha256", signKey).update(signingInput).digest("base64url");
47
+ return `${signingInput}.${signature}`;
13
48
  };
14
- const getApplicationId = () => {
15
- return "applicationId";
49
+ const getAccessTokenByInstallationInfo = async function(installationInfo) {
50
+ let userID = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
51
+ const assertion = buildJWTAssertion(installationInfo, userID);
52
+ const tokenURL = new URL("/oauth2/token", installationInfo.ones_base_url);
53
+ const formData = new URLSearchParams();
54
+ formData.set("grant_type", TOKEN_GRANT_TYPE);
55
+ formData.set("client_id", installationInfo.installation_id);
56
+ formData.set("assertion", assertion);
57
+ try {
58
+ const response = await fetch$2.post(tokenURL.toString(), formData.toString(), {
59
+ headers: {
60
+ "Content-Type": "application/x-www-form-urlencoded"
61
+ }
62
+ });
63
+ const token = response.data;
64
+ if (!token.access_token) {
65
+ throw new Error("failed to get access token: empty access_token in response");
66
+ }
67
+ return token.access_token;
68
+ } catch (error) {
69
+ if (error instanceof Fetch.AxiosError) {
70
+ var _error$response, _error$response$statu, _error$response2, _error$response3;
71
+ const status = (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status;
72
+ const statusText = (_error$response$statu = (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.statusText) !== null && _error$response$statu !== void 0 ? _error$response$statu : "";
73
+ const data = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data;
74
+ const responseText = typeof data === "string" ? data : JSON.stringify(data);
75
+ throw new Error(`failed to get access token: ${status !== null && status !== void 0 ? status : "unknown"} ${statusText}, response: ${responseText}`);
76
+ }
77
+ throw error;
78
+ }
16
79
  };
17
- const getAppId = getApplicationId;
18
80
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
19
81
  __proto__: null,
20
- getAppId,
21
- getApplicationId,
22
- getInstanceId,
23
- getPlatformAPIHost,
24
- getPlatformApiHost
82
+ getAccessTokenByInstallationInfo
25
83
  }, Symbol.toStringTag, { value: "Module" }));
26
84
  var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
27
85
  EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
@@ -123,24 +181,37 @@ const createErrorResult = (code, message, error) => {
123
181
  }, error);
124
182
  };
125
183
  const fetch$1 = Fetch.create();
184
+ const buildAuthHeaders$1 = () => {
185
+ const token = getONESHostedToken();
186
+ if (token) {
187
+ return {
188
+ Authorization: `Bearer ${token}`
189
+ };
190
+ }
191
+ return {};
192
+ };
126
193
  const fetchBase$1 = (path, params, config) => {
127
- return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
128
- let [base, instance_id] = _ref;
129
- if (base && instance_id) {
130
- const url = `${base}${path}`;
194
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
195
+ let [base, appId] = _ref;
196
+ if (base && appId) {
197
+ var _config$headers;
198
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
131
199
  const data = {
132
- ...params,
133
- instance_id
200
+ ...params
134
201
  };
135
202
  return fetch$1({
136
203
  ...config,
204
+ headers: {
205
+ ...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
206
+ ...buildAuthHeaders$1()
207
+ },
137
208
  url,
138
209
  data
139
210
  });
140
211
  }
141
212
  throw new Error(JSON.stringify({
142
213
  base,
143
- instance_id
214
+ appId
144
215
  }));
145
216
  }).then((response) => {
146
217
  return response.data;
@@ -157,22 +228,22 @@ const fetchBase$1 = (path, params, config) => {
157
228
  });
158
229
  };
159
230
  const fetchPost = (params) => {
160
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
231
+ return fetchBase$1(`/entity_data`, params, {
161
232
  method: "post"
162
233
  });
163
234
  };
164
235
  const fetchDelete$1 = (params) => {
165
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
236
+ return fetchBase$1(`/entity_data`, params, {
166
237
  method: "delete"
167
238
  });
168
239
  };
169
240
  const fetchQuery = (params) => {
170
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
241
+ return fetchBase$1(`/entity_data/get_many`, params, {
171
242
  method: "post"
172
243
  });
173
244
  };
174
245
  const fetchCount = (params) => {
175
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
246
+ return fetchBase$1(`/entity_data/count`, params, {
176
247
  method: "post"
177
248
  });
178
249
  };
@@ -190,12 +261,12 @@ const defaultEntityQueryIndex = defaultEntityQuery.index;
190
261
  const defaultEntityQueryWhere = defaultEntityQuery.where;
191
262
  class EntityQueryClass {
192
263
  constructor(name) {
193
- _defineProperty(this, "_name", "");
194
- _defineProperty(this, "_cursor", [defaultEntityQueryCursor]);
195
- _defineProperty(this, "_limit", [defaultEntityQueryLimit]);
196
- _defineProperty(this, "_sort", [defaultEntityQuerySort]);
197
- _defineProperty(this, "_index", [defaultEntityQueryIndex]);
198
- _defineProperty(this, "_where", [defaultEntityQueryWhere]);
264
+ this._name = "";
265
+ this._cursor = [defaultEntityQueryCursor];
266
+ this._limit = [defaultEntityQueryLimit];
267
+ this._sort = [defaultEntityQuerySort];
268
+ this._index = [defaultEntityQueryIndex];
269
+ this._where = [defaultEntityQueryWhere];
199
270
  this._name = name;
200
271
  }
201
272
  cursor(cursor) {
@@ -289,7 +360,7 @@ class EntityQueryClass {
289
360
  }
290
361
  class EntityClass {
291
362
  constructor(name) {
292
- _defineProperty(this, "_name", "");
363
+ this._name = "";
293
364
  this._name = name;
294
365
  }
295
366
  async get(key) {
@@ -395,31 +466,38 @@ var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
395
466
  return ObjectErrorCode2;
396
467
  })(ObjectErrorCode || {});
397
468
  class ObjectError {
398
- /**
399
- * @description 错误载荷
400
- */
401
469
  constructor(result) {
402
- _defineProperty(this, "err_msg", "");
470
+ this.err_msg = "";
403
471
  this.code = result.code;
404
472
  this.err_msg = result.err_msg;
405
473
  this.err_values = result.err_values;
406
474
  }
407
475
  }
408
476
  const fetch = Fetch.create();
477
+ const buildAuthHeaders = () => {
478
+ const token = getONESHostedToken();
479
+ if (token) {
480
+ return {
481
+ Authorization: `Bearer ${token}`
482
+ };
483
+ }
484
+ return {};
485
+ };
409
486
  const fetchBase = (path, params) => {
410
- return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
411
- let [base, instance_id] = _ref;
412
- if (base && instance_id) {
413
- const url = `${base}${path}`;
487
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
488
+ let [base, appId] = _ref;
489
+ if (base && appId) {
490
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
414
491
  const data = {
415
- ...params,
416
- instance_id
492
+ ...params
417
493
  };
418
- return fetch.post(url, data);
494
+ return fetch.post(url, data, {
495
+ headers: buildAuthHeaders()
496
+ });
419
497
  }
420
498
  throw new Error(JSON.stringify({
421
499
  base,
422
- instance_id
500
+ appId
423
501
  }));
424
502
  }).then((response) => {
425
503
  return response.data;
@@ -436,16 +514,16 @@ const fetchBase = (path, params) => {
436
514
  });
437
515
  };
438
516
  const fetchUpload = (params) => {
439
- return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
517
+ return fetchBase(`/object/get_upload_policy_info`, params);
440
518
  };
441
519
  const fetchDownload = (params) => {
442
- return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
520
+ return fetchBase(`/object/get_download_pre_signed_url`, params);
443
521
  };
444
522
  const fetchDelete = (params) => {
445
- return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
523
+ return fetchBase(`/object/delete`, params);
446
524
  };
447
525
  const fetchMetadata = (params) => {
448
- return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
526
+ return fetchBase(`/object/get_metadata`, params);
449
527
  };
450
528
  const object = {
451
529
  ObjectError,
@@ -455,7 +533,8 @@ const object = {
455
533
  object_key: key
456
534
  });
457
535
  if (result.code === "OK") {
458
- if (result.data) {
536
+ var _result$data;
537
+ if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
459
538
  const {
460
539
  url,
461
540
  fields
@@ -536,5 +615,6 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
536
615
  object
537
616
  }, Symbol.toStringTag, { value: "Module" }));
538
617
  exports.ErrorCode = ErrorCode;
539
- exports.env = index$1;
618
+ exports.env = index$2;
619
+ exports.oauth = index$1;
540
620
  exports.storage = index;
package/dist/index.js CHANGED
@@ -1,25 +1,83 @@
1
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
- import { isNull, isUndefined, isSymbol, set } from "lodash-es";
1
+ import { randomUUID, createHmac } from "node:crypto";
3
2
  import Fetch, { AxiosError } from "axios";
3
+ import { isNull, isUndefined, isSymbol, set } from "lodash-es";
4
4
  import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
5
- const getPlatformApiHost = () => {
6
- return "platformApiHost";
5
+ const getONESHostedBaseUrl = () => {
6
+ return process.env.ONES_HOSTED_BASE_URL;
7
+ };
8
+ const getONESHostedAppID = () => {
9
+ return process.env.ONES_HOSTED_APP_ID;
7
10
  };
8
- const getPlatformAPIHost = getPlatformApiHost;
9
- const getInstanceId = () => {
10
- return "instanceId";
11
+ const getONESHostedToken = () => {
12
+ return process.env.ONES_HOSTED_TOKEN;
13
+ };
14
+ const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
15
+ __proto__: null,
16
+ getONESHostedAppID,
17
+ getONESHostedBaseUrl,
18
+ getONESHostedToken
19
+ }, Symbol.toStringTag, { value: "Module" }));
20
+ const ASSERTION_TTL_SECONDS = 24 * 60 * 60;
21
+ const ASSERTION_JTI_LENGTH = 16;
22
+ const TOKEN_GRANT_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
23
+ const fetch$2 = Fetch.create();
24
+ const buildJWTAssertion = (installationInfo, userID) => {
25
+ const now = Math.floor(Date.now() / 1e3);
26
+ const header = {
27
+ alg: "HS256",
28
+ typ: "JWT"
29
+ };
30
+ const payload = {
31
+ uid: userID,
32
+ rsh: "",
33
+ iss: installationInfo.installation_id,
34
+ sub: installationInfo.installation_id,
35
+ aud: "oauth",
36
+ exp: now + ASSERTION_TTL_SECONDS,
37
+ iat: now,
38
+ jti: randomUUID().replace(/-/g, "").slice(0, ASSERTION_JTI_LENGTH)
39
+ };
40
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
41
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
42
+ const signingInput = `${encodedHeader}.${encodedPayload}`;
43
+ const signKey = Buffer.from(installationInfo.shared_secret, "base64");
44
+ const signature = createHmac("sha256", signKey).update(signingInput).digest("base64url");
45
+ return `${signingInput}.${signature}`;
11
46
  };
12
- const getApplicationId = () => {
13
- return "applicationId";
47
+ const getAccessTokenByInstallationInfo = async function(installationInfo) {
48
+ let userID = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
49
+ const assertion = buildJWTAssertion(installationInfo, userID);
50
+ const tokenURL = new URL("/oauth2/token", installationInfo.ones_base_url);
51
+ const formData = new URLSearchParams();
52
+ formData.set("grant_type", TOKEN_GRANT_TYPE);
53
+ formData.set("client_id", installationInfo.installation_id);
54
+ formData.set("assertion", assertion);
55
+ try {
56
+ const response = await fetch$2.post(tokenURL.toString(), formData.toString(), {
57
+ headers: {
58
+ "Content-Type": "application/x-www-form-urlencoded"
59
+ }
60
+ });
61
+ const token = response.data;
62
+ if (!token.access_token) {
63
+ throw new Error("failed to get access token: empty access_token in response");
64
+ }
65
+ return token.access_token;
66
+ } catch (error) {
67
+ if (error instanceof AxiosError) {
68
+ var _error$response, _error$response$statu, _error$response2, _error$response3;
69
+ const status = (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status;
70
+ const statusText = (_error$response$statu = (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.statusText) !== null && _error$response$statu !== void 0 ? _error$response$statu : "";
71
+ const data = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data;
72
+ const responseText = typeof data === "string" ? data : JSON.stringify(data);
73
+ throw new Error(`failed to get access token: ${status !== null && status !== void 0 ? status : "unknown"} ${statusText}, response: ${responseText}`);
74
+ }
75
+ throw error;
76
+ }
14
77
  };
15
- const getAppId = getApplicationId;
16
78
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17
79
  __proto__: null,
18
- getAppId,
19
- getApplicationId,
20
- getInstanceId,
21
- getPlatformAPIHost,
22
- getPlatformApiHost
80
+ getAccessTokenByInstallationInfo
23
81
  }, Symbol.toStringTag, { value: "Module" }));
24
82
  var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
25
83
  EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
@@ -121,24 +179,37 @@ const createErrorResult = (code, message, error) => {
121
179
  }, error);
122
180
  };
123
181
  const fetch$1 = Fetch.create();
182
+ const buildAuthHeaders$1 = () => {
183
+ const token = getONESHostedToken();
184
+ if (token) {
185
+ return {
186
+ Authorization: `Bearer ${token}`
187
+ };
188
+ }
189
+ return {};
190
+ };
124
191
  const fetchBase$1 = (path, params, config) => {
125
- return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
126
- let [base, instance_id] = _ref;
127
- if (base && instance_id) {
128
- const url = `${base}${path}`;
192
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
193
+ let [base, appId] = _ref;
194
+ if (base && appId) {
195
+ var _config$headers;
196
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
129
197
  const data = {
130
- ...params,
131
- instance_id
198
+ ...params
132
199
  };
133
200
  return fetch$1({
134
201
  ...config,
202
+ headers: {
203
+ ...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
204
+ ...buildAuthHeaders$1()
205
+ },
135
206
  url,
136
207
  data
137
208
  });
138
209
  }
139
210
  throw new Error(JSON.stringify({
140
211
  base,
141
- instance_id
212
+ appId
142
213
  }));
143
214
  }).then((response) => {
144
215
  return response.data;
@@ -155,22 +226,22 @@ const fetchBase$1 = (path, params, config) => {
155
226
  });
156
227
  };
157
228
  const fetchPost = (params) => {
158
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
229
+ return fetchBase$1(`/entity_data`, params, {
159
230
  method: "post"
160
231
  });
161
232
  };
162
233
  const fetchDelete$1 = (params) => {
163
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
234
+ return fetchBase$1(`/entity_data`, params, {
164
235
  method: "delete"
165
236
  });
166
237
  };
167
238
  const fetchQuery = (params) => {
168
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
239
+ return fetchBase$1(`/entity_data/get_many`, params, {
169
240
  method: "post"
170
241
  });
171
242
  };
172
243
  const fetchCount = (params) => {
173
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
244
+ return fetchBase$1(`/entity_data/count`, params, {
174
245
  method: "post"
175
246
  });
176
247
  };
@@ -188,12 +259,12 @@ const defaultEntityQueryIndex = defaultEntityQuery.index;
188
259
  const defaultEntityQueryWhere = defaultEntityQuery.where;
189
260
  class EntityQueryClass {
190
261
  constructor(name) {
191
- _defineProperty(this, "_name", "");
192
- _defineProperty(this, "_cursor", [defaultEntityQueryCursor]);
193
- _defineProperty(this, "_limit", [defaultEntityQueryLimit]);
194
- _defineProperty(this, "_sort", [defaultEntityQuerySort]);
195
- _defineProperty(this, "_index", [defaultEntityQueryIndex]);
196
- _defineProperty(this, "_where", [defaultEntityQueryWhere]);
262
+ this._name = "";
263
+ this._cursor = [defaultEntityQueryCursor];
264
+ this._limit = [defaultEntityQueryLimit];
265
+ this._sort = [defaultEntityQuerySort];
266
+ this._index = [defaultEntityQueryIndex];
267
+ this._where = [defaultEntityQueryWhere];
197
268
  this._name = name;
198
269
  }
199
270
  cursor(cursor) {
@@ -287,7 +358,7 @@ class EntityQueryClass {
287
358
  }
288
359
  class EntityClass {
289
360
  constructor(name) {
290
- _defineProperty(this, "_name", "");
361
+ this._name = "";
291
362
  this._name = name;
292
363
  }
293
364
  async get(key) {
@@ -393,31 +464,38 @@ var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
393
464
  return ObjectErrorCode2;
394
465
  })(ObjectErrorCode || {});
395
466
  class ObjectError {
396
- /**
397
- * @description 错误载荷
398
- */
399
467
  constructor(result) {
400
- _defineProperty(this, "err_msg", "");
468
+ this.err_msg = "";
401
469
  this.code = result.code;
402
470
  this.err_msg = result.err_msg;
403
471
  this.err_values = result.err_values;
404
472
  }
405
473
  }
406
474
  const fetch = Fetch.create();
475
+ const buildAuthHeaders = () => {
476
+ const token = getONESHostedToken();
477
+ if (token) {
478
+ return {
479
+ Authorization: `Bearer ${token}`
480
+ };
481
+ }
482
+ return {};
483
+ };
407
484
  const fetchBase = (path, params) => {
408
- return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
409
- let [base, instance_id] = _ref;
410
- if (base && instance_id) {
411
- const url = `${base}${path}`;
485
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
486
+ let [base, appId] = _ref;
487
+ if (base && appId) {
488
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
412
489
  const data = {
413
- ...params,
414
- instance_id
490
+ ...params
415
491
  };
416
- return fetch.post(url, data);
492
+ return fetch.post(url, data, {
493
+ headers: buildAuthHeaders()
494
+ });
417
495
  }
418
496
  throw new Error(JSON.stringify({
419
497
  base,
420
- instance_id
498
+ appId
421
499
  }));
422
500
  }).then((response) => {
423
501
  return response.data;
@@ -434,16 +512,16 @@ const fetchBase = (path, params) => {
434
512
  });
435
513
  };
436
514
  const fetchUpload = (params) => {
437
- return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
515
+ return fetchBase(`/object/get_upload_policy_info`, params);
438
516
  };
439
517
  const fetchDownload = (params) => {
440
- return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
518
+ return fetchBase(`/object/get_download_pre_signed_url`, params);
441
519
  };
442
520
  const fetchDelete = (params) => {
443
- return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
521
+ return fetchBase(`/object/delete`, params);
444
522
  };
445
523
  const fetchMetadata = (params) => {
446
- return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
524
+ return fetchBase(`/object/get_metadata`, params);
447
525
  };
448
526
  const object = {
449
527
  ObjectError,
@@ -453,7 +531,8 @@ const object = {
453
531
  object_key: key
454
532
  });
455
533
  if (result.code === "OK") {
456
- if (result.data) {
534
+ var _result$data;
535
+ if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
457
536
  const {
458
537
  url,
459
538
  fields
@@ -535,6 +614,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
535
614
  }, Symbol.toStringTag, { value: "Module" }));
536
615
  export {
537
616
  ErrorCode,
538
- index$1 as env,
617
+ index$2 as env,
618
+ index$1 as oauth,
539
619
  index as storage
540
620
  };
@@ -0,0 +1,2 @@
1
+ export type * from './types';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/node/event/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @description ONES 事件回调 HTTP 请求体
3
+ */
4
+ export interface EventBody<EventData = unknown> {
5
+ /**
6
+ * @description 事件 ID(在 ONES 实例内唯一)
7
+ */
8
+ eventID: string;
9
+ /**
10
+ * @description 事件类型(如 ones:project:issue:created)
11
+ */
12
+ eventType: string;
13
+ /**
14
+ * @description 事件发生时间戳(毫秒)
15
+ */
16
+ timestamp: number;
17
+ /**
18
+ * @description 事件数据载荷
19
+ */
20
+ eventData: EventData;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/packages/node/event/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,SAAS,GAAG,OAAO;IAC5C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;CACrB"}
@@ -1,5 +1,8 @@
1
1
  export * as env from '../../packages/strict/env';
2
+ export * as oauth from './oauth';
2
3
  export * as storage from './storage';
4
+ export type * from './event';
3
5
  export { ErrorCode } from '../../packages/strict/error';
4
6
  export type { Entity, EntityBatchSetItem, EntityQuery, EntityListResultData, EntityError, ObjectError, ObjectStoreUploadResult, ObjectStoreDownloadResult, } from './storage';
7
+ export type { InstallationInfo, OAuthClient } from './oauth';
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packages/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,YAAY,EACV,MAAM,EACN,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packages/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA;AACpC,mBAAmB,SAAS,CAAA;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,YAAY,EACV,MAAM,EACN,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,WAAW,CAAA;AAClB,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { OAuthClient } from './types';
2
+ export type * from './types';
3
+ export declare const getAccessTokenByInstallationInfo: OAuthClient['getAccessTokenByInstallationInfo'];
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/node/oauth/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAoB,WAAW,EAAE,MAAM,SAAS,CAAA;AAE5D,mBAAmB,SAAS,CAAA;AAiD5B,eAAO,MAAM,gCAAgC,EAAE,WAAW,CAAC,kCAAkC,CAsC1F,CAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @description Installation callback data used for token exchange
3
+ */
4
+ export interface InstallationInfo {
5
+ /**
6
+ * @description Installation ID of the app
7
+ */
8
+ installation_id: string;
9
+ /**
10
+ * @description Base64 encoded installation shared secret
11
+ */
12
+ shared_secret: string;
13
+ /**
14
+ * @description ONES base URL of the installation
15
+ */
16
+ ones_base_url: string;
17
+ }
18
+ export interface OAuthClient {
19
+ /**
20
+ * @description Exchange installation info for an OAuth access token
21
+ * @param installationInfo Installation callback data
22
+ * @param userID User ID in the installation organization.
23
+ * Empty string means requesting token as the app itself.
24
+ * @returns Access token
25
+ */
26
+ getAccessTokenByInstallationInfo(installationInfo: InstallationInfo, userID?: string): Promise<string>;
27
+ }
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/packages/node/oauth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,gCAAgC,CAC9B,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAAA;CACnB"}