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

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
@@ -4,24 +4,16 @@ const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty")
4
4
  const lodashEs = require("lodash-es");
5
5
  const Fetch = require("axios");
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
9
  };
10
- const getPlatformAPIHost = getPlatformApiHost;
11
- const getInstanceId = () => {
12
- return "instanceId";
10
+ const getONESHostedAppID = () => {
11
+ return process.env.ONES_HOSTED_APP_ID;
13
12
  };
14
- const getApplicationId = () => {
15
- return "applicationId";
16
- };
17
- const getAppId = getApplicationId;
18
13
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
19
14
  __proto__: null,
20
- getAppId,
21
- getApplicationId,
22
- getInstanceId,
23
- getPlatformAPIHost,
24
- getPlatformApiHost
15
+ getONESHostedAppID,
16
+ getONESHostedBaseUrl
25
17
  }, Symbol.toStringTag, { value: "Module" }));
26
18
  var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
27
19
  EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
@@ -123,24 +115,37 @@ const createErrorResult = (code, message, error) => {
123
115
  }, error);
124
116
  };
125
117
  const fetch$1 = Fetch.create();
118
+ const buildAuthHeaders$1 = () => {
119
+ const token = process.env.ONES_HOSTED_TOKEN;
120
+ if (token) {
121
+ return {
122
+ Authorization: `Bearer ${token}`
123
+ };
124
+ }
125
+ return {};
126
+ };
126
127
  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}`;
128
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
129
+ let [base, appId] = _ref;
130
+ if (base && appId) {
131
+ var _config$headers;
132
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
131
133
  const data = {
132
- ...params,
133
- instance_id
134
+ ...params
134
135
  };
135
136
  return fetch$1({
136
137
  ...config,
138
+ headers: {
139
+ ...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
140
+ ...buildAuthHeaders$1()
141
+ },
137
142
  url,
138
143
  data
139
144
  });
140
145
  }
141
146
  throw new Error(JSON.stringify({
142
147
  base,
143
- instance_id
148
+ appId
144
149
  }));
145
150
  }).then((response) => {
146
151
  return response.data;
@@ -157,22 +162,22 @@ const fetchBase$1 = (path, params, config) => {
157
162
  });
158
163
  };
159
164
  const fetchPost = (params) => {
160
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
165
+ return fetchBase$1(`/entity_data`, params, {
161
166
  method: "post"
162
167
  });
163
168
  };
164
169
  const fetchDelete$1 = (params) => {
165
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
170
+ return fetchBase$1(`/entity_data`, params, {
166
171
  method: "delete"
167
172
  });
168
173
  };
169
174
  const fetchQuery = (params) => {
170
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
175
+ return fetchBase$1(`/entity_data/get_many`, params, {
171
176
  method: "post"
172
177
  });
173
178
  };
174
179
  const fetchCount = (params) => {
175
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
180
+ return fetchBase$1(`/entity_data/count`, params, {
176
181
  method: "post"
177
182
  });
178
183
  };
@@ -406,20 +411,30 @@ class ObjectError {
406
411
  }
407
412
  }
408
413
  const fetch = Fetch.create();
414
+ const buildAuthHeaders = () => {
415
+ const token = process.env.ONES_HOSTED_TOKEN;
416
+ if (token) {
417
+ return {
418
+ Authorization: `Bearer ${token}`
419
+ };
420
+ }
421
+ return {};
422
+ };
409
423
  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}`;
424
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
425
+ let [base, appId] = _ref;
426
+ if (base && appId) {
427
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
414
428
  const data = {
415
- ...params,
416
- instance_id
429
+ ...params
417
430
  };
418
- return fetch.post(url, data);
431
+ return fetch.post(url, data, {
432
+ headers: buildAuthHeaders()
433
+ });
419
434
  }
420
435
  throw new Error(JSON.stringify({
421
436
  base,
422
- instance_id
437
+ appId
423
438
  }));
424
439
  }).then((response) => {
425
440
  return response.data;
@@ -436,16 +451,16 @@ const fetchBase = (path, params) => {
436
451
  });
437
452
  };
438
453
  const fetchUpload = (params) => {
439
- return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
454
+ return fetchBase(`/object/get_upload_policy_info`, params);
440
455
  };
441
456
  const fetchDownload = (params) => {
442
- return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
457
+ return fetchBase(`/object/get_download_pre_signed_url`, params);
443
458
  };
444
459
  const fetchDelete = (params) => {
445
- return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
460
+ return fetchBase(`/object/delete`, params);
446
461
  };
447
462
  const fetchMetadata = (params) => {
448
- return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
463
+ return fetchBase(`/object/get_metadata`, params);
449
464
  };
450
465
  const object = {
451
466
  ObjectError,
@@ -455,7 +470,8 @@ const object = {
455
470
  object_key: key
456
471
  });
457
472
  if (result.code === "OK") {
458
- if (result.data) {
473
+ var _result$data;
474
+ if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
459
475
  const {
460
476
  url,
461
477
  fields
package/dist/index.js CHANGED
@@ -2,24 +2,16 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
2
  import { isNull, isUndefined, isSymbol, set } from "lodash-es";
3
3
  import Fetch, { AxiosError } from "axios";
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
7
  };
8
- const getPlatformAPIHost = getPlatformApiHost;
9
- const getInstanceId = () => {
10
- return "instanceId";
8
+ const getONESHostedAppID = () => {
9
+ return process.env.ONES_HOSTED_APP_ID;
11
10
  };
12
- const getApplicationId = () => {
13
- return "applicationId";
14
- };
15
- const getAppId = getApplicationId;
16
11
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17
12
  __proto__: null,
18
- getAppId,
19
- getApplicationId,
20
- getInstanceId,
21
- getPlatformAPIHost,
22
- getPlatformApiHost
13
+ getONESHostedAppID,
14
+ getONESHostedBaseUrl
23
15
  }, Symbol.toStringTag, { value: "Module" }));
24
16
  var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
25
17
  EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
@@ -121,24 +113,37 @@ const createErrorResult = (code, message, error) => {
121
113
  }, error);
122
114
  };
123
115
  const fetch$1 = Fetch.create();
116
+ const buildAuthHeaders$1 = () => {
117
+ const token = process.env.ONES_HOSTED_TOKEN;
118
+ if (token) {
119
+ return {
120
+ Authorization: `Bearer ${token}`
121
+ };
122
+ }
123
+ return {};
124
+ };
124
125
  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}`;
126
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
127
+ let [base, appId] = _ref;
128
+ if (base && appId) {
129
+ var _config$headers;
130
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
129
131
  const data = {
130
- ...params,
131
- instance_id
132
+ ...params
132
133
  };
133
134
  return fetch$1({
134
135
  ...config,
136
+ headers: {
137
+ ...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
138
+ ...buildAuthHeaders$1()
139
+ },
135
140
  url,
136
141
  data
137
142
  });
138
143
  }
139
144
  throw new Error(JSON.stringify({
140
145
  base,
141
- instance_id
146
+ appId
142
147
  }));
143
148
  }).then((response) => {
144
149
  return response.data;
@@ -155,22 +160,22 @@ const fetchBase$1 = (path, params, config) => {
155
160
  });
156
161
  };
157
162
  const fetchPost = (params) => {
158
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
163
+ return fetchBase$1(`/entity_data`, params, {
159
164
  method: "post"
160
165
  });
161
166
  };
162
167
  const fetchDelete$1 = (params) => {
163
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
168
+ return fetchBase$1(`/entity_data`, params, {
164
169
  method: "delete"
165
170
  });
166
171
  };
167
172
  const fetchQuery = (params) => {
168
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
173
+ return fetchBase$1(`/entity_data/get_many`, params, {
169
174
  method: "post"
170
175
  });
171
176
  };
172
177
  const fetchCount = (params) => {
173
- return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
178
+ return fetchBase$1(`/entity_data/count`, params, {
174
179
  method: "post"
175
180
  });
176
181
  };
@@ -404,20 +409,30 @@ class ObjectError {
404
409
  }
405
410
  }
406
411
  const fetch = Fetch.create();
412
+ const buildAuthHeaders = () => {
413
+ const token = process.env.ONES_HOSTED_TOKEN;
414
+ if (token) {
415
+ return {
416
+ Authorization: `Bearer ${token}`
417
+ };
418
+ }
419
+ return {};
420
+ };
407
421
  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}`;
422
+ return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
423
+ let [base, appId] = _ref;
424
+ if (base && appId) {
425
+ const url = `${base}/hosted_ability/storage/${appId}${path}`;
412
426
  const data = {
413
- ...params,
414
- instance_id
427
+ ...params
415
428
  };
416
- return fetch.post(url, data);
429
+ return fetch.post(url, data, {
430
+ headers: buildAuthHeaders()
431
+ });
417
432
  }
418
433
  throw new Error(JSON.stringify({
419
434
  base,
420
- instance_id
435
+ appId
421
436
  }));
422
437
  }).then((response) => {
423
438
  return response.data;
@@ -434,16 +449,16 @@ const fetchBase = (path, params) => {
434
449
  });
435
450
  };
436
451
  const fetchUpload = (params) => {
437
- return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
452
+ return fetchBase(`/object/get_upload_policy_info`, params);
438
453
  };
439
454
  const fetchDownload = (params) => {
440
- return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
455
+ return fetchBase(`/object/get_download_pre_signed_url`, params);
441
456
  };
442
457
  const fetchDelete = (params) => {
443
- return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
458
+ return fetchBase(`/object/delete`, params);
444
459
  };
445
460
  const fetchMetadata = (params) => {
446
- return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
461
+ return fetchBase(`/object/get_metadata`, params);
447
462
  };
448
463
  const object = {
449
464
  ObjectError,
@@ -453,7 +468,8 @@ const object = {
453
468
  object_key: key
454
469
  });
455
470
  if (result.code === "OK") {
456
- if (result.data) {
471
+ var _result$data;
472
+ if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
457
473
  const {
458
474
  url,
459
475
  fields
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/entity/fetch/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,oBAAoB,EAEpB,qBAAqB,EAErB,mBAAmB,EAEnB,oBAAoB,EAErB,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AA8CvB,eAAO,MAAM,SAAS,EAAE,mBAQvB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAQzB,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,oBAYxB,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,oBAQxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/entity/fetch/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,oBAAoB,EAEpB,qBAAqB,EAErB,mBAAmB,EAEnB,oBAAoB,EAErB,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AA2DvB,eAAO,MAAM,SAAS,EAAE,mBAIvB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAIzB,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,oBAYxB,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,oBAIxB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/object/fetch/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,qBAAqB,EAErB,uBAAuB,EAEvB,qBAAqB,EAErB,uBAAuB,EAExB,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AAyCvB,eAAO,MAAM,WAAW,EAAE,qBAKzB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,uBAK3B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAKzB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,uBAK3B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/object/fetch/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,qBAAqB,EAErB,uBAAuB,EAEvB,qBAAqB,EAErB,uBAAuB,EAExB,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AAwDvB,eAAO,MAAM,WAAW,EAAE,qBAKzB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,uBAK3B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,qBAEzB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,uBAE3B,CAAA"}
@@ -1,35 +1,13 @@
1
1
  /**
2
2
  * @description 获取开放平台 host
3
- * @alias getPlatformApiHost
4
- * @alias getPlatformAPIHost
5
- * @returns platformApiHost
3
+ * @alias getONESHostedBaseUrl
4
+ * @returns onesHostedBaseUrl
6
5
  */
7
- export declare const getPlatformApiHost: () => string;
8
- /**
9
- * @description 获取开放平台 host
10
- * @alias getPlatformApiHost
11
- * @alias getPlatformAPIHost
12
- * @returns platformApiHost
13
- */
14
- export declare const getPlatformAPIHost: () => string;
6
+ export declare const getONESHostedBaseUrl: () => string | undefined;
15
7
  /**
16
8
  * @description 获取插件实例 ID
17
- * @alias getInstanceId
18
- * @returns instanceId
19
- */
20
- export declare const getInstanceId: () => string;
21
- /**
22
- * @description 获取插件 ID
23
- * @alias getApplicationId
24
- * @alias getAppId
25
- * @returns applicationId
26
- */
27
- export declare const getApplicationId: () => string;
28
- /**
29
- * @description 获取插件 ID
30
- * @alias getApplicationId
31
- * @alias getAppId
32
- * @returns applicationId
9
+ * @alias getONESHostedAppID
10
+ * @returns onesHostedAppID
33
11
  */
34
- export declare const getAppId: () => string;
12
+ export declare const getONESHostedAppID: () => string | undefined;
35
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/strict/env/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,cAE9B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,cAAqB,CAAA;AAEpD;;;;GAIG;AACH,eAAO,MAAM,aAAa,cAEzB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,cAE5B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,cAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/strict/env/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,0BAEhC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,0BAE9B,CAAA"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@ones-open/node-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-12558.84+c79bb0ae",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
8
+ "types": "./dist/types/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/types/index.d.ts",
@@ -50,5 +50,5 @@
50
50
  "devDependencies": {
51
51
  "@types/lodash-es": "^4.17.12"
52
52
  },
53
- "gitHead": "0db71cc49790a372abd7e85daa6c6b0cefe7b175"
53
+ "gitHead": "c79bb0ae3da527e8799b0c527a4e7db2e8ca564a"
54
54
  }