@ones-open/node-sdk 0.0.4-16596.20 → 0.0.4-1720.217
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 +131 -51
- package/dist/index.js +131 -51
- package/dist/types/packages/node/index.d.ts +2 -0
- package/dist/types/packages/node/index.d.ts.map +1 -1
- package/dist/types/packages/node/oauth/index.d.ts +4 -0
- package/dist/types/packages/node/oauth/index.d.ts.map +1 -0
- package/dist/types/packages/node/oauth/types.d.ts +28 -0
- package/dist/types/packages/node/oauth/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/entity/types.d.ts +20 -20
- package/dist/types/packages/node/storage/entity/error/consts.d.ts +29 -29
- package/dist/types/packages/node/storage/entity/fetch/index.d.ts.map +1 -1
- package/dist/types/packages/node/storage/entity/index.d.ts +1 -1
- package/dist/types/packages/node/storage/entity/query/types.d.ts +52 -52
- package/dist/types/packages/node/storage/entity/result/types.d.ts +12 -12
- package/dist/types/packages/node/storage/entity/sort/consts.d.ts +3 -3
- package/dist/types/packages/node/storage/entity/types.d.ts +29 -29
- package/dist/types/packages/node/storage/entity/where/index.d.ts +1 -1
- package/dist/types/packages/node/storage/object/error/consts.d.ts +4 -4
- package/dist/types/packages/node/storage/object/error/index.d.ts +4 -4
- package/dist/types/packages/node/storage/object/fetch/index.d.ts.map +1 -1
- package/dist/types/packages/node/storage/object/index.d.ts +1 -1
- package/dist/types/packages/node/storage/object/result/types.d.ts +3 -3
- package/dist/types/packages/node/storage/object/types.d.ts +17 -17
- package/dist/types/packages/strict/env/index.d.ts +12 -28
- package/dist/types/packages/strict/env/index.d.ts.map +1 -1
- package/dist/types/packages/strict/result/types.d.ts +6 -6
- 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
|
|
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
|
|
8
|
-
return
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
15
|
-
|
|
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
|
-
|
|
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([
|
|
128
|
-
let [base,
|
|
129
|
-
if (base &&
|
|
130
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
236
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
166
237
|
method: "delete"
|
|
167
238
|
});
|
|
168
239
|
};
|
|
169
240
|
const fetchQuery = (params) => {
|
|
170
|
-
return fetchBase$1(
|
|
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(
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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([
|
|
411
|
-
let [base,
|
|
412
|
-
if (base &&
|
|
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
|
-
|
|
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(
|
|
517
|
+
return fetchBase(`/object/get_upload_policy_info`, params);
|
|
440
518
|
};
|
|
441
519
|
const fetchDownload = (params) => {
|
|
442
|
-
return fetchBase(
|
|
520
|
+
return fetchBase(`/object/get_download_pre_signed_url`, params);
|
|
443
521
|
};
|
|
444
522
|
const fetchDelete = (params) => {
|
|
445
|
-
return fetchBase(
|
|
523
|
+
return fetchBase(`/object/delete`, params);
|
|
446
524
|
};
|
|
447
525
|
const fetchMetadata = (params) => {
|
|
448
|
-
return fetchBase(
|
|
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
|
-
|
|
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$
|
|
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
|
|
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
|
|
6
|
-
return
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
13
|
-
|
|
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
|
-
|
|
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([
|
|
126
|
-
let [base,
|
|
127
|
-
if (base &&
|
|
128
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
234
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
164
235
|
method: "delete"
|
|
165
236
|
});
|
|
166
237
|
};
|
|
167
238
|
const fetchQuery = (params) => {
|
|
168
|
-
return fetchBase$1(
|
|
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(
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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([
|
|
409
|
-
let [base,
|
|
410
|
-
if (base &&
|
|
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
|
-
|
|
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(
|
|
515
|
+
return fetchBase(`/object/get_upload_policy_info`, params);
|
|
438
516
|
};
|
|
439
517
|
const fetchDownload = (params) => {
|
|
440
|
-
return fetchBase(
|
|
518
|
+
return fetchBase(`/object/get_download_pre_signed_url`, params);
|
|
441
519
|
};
|
|
442
520
|
const fetchDelete = (params) => {
|
|
443
|
-
return fetchBase(
|
|
521
|
+
return fetchBase(`/object/delete`, params);
|
|
444
522
|
};
|
|
445
523
|
const fetchMetadata = (params) => {
|
|
446
|
-
return fetchBase(
|
|
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
|
-
|
|
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$
|
|
617
|
+
index$2 as env,
|
|
618
|
+
index$1 as oauth,
|
|
539
619
|
index as storage
|
|
540
620
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * as env from '../../packages/strict/env';
|
|
2
|
+
export * as oauth from './oauth';
|
|
2
3
|
export * as storage from './storage';
|
|
3
4
|
export { ErrorCode } from '../../packages/strict/error';
|
|
4
5
|
export type { Entity, EntityBatchSetItem, EntityQuery, EntityListResultData, EntityError, ObjectError, ObjectStoreUploadResult, ObjectStoreDownloadResult, } from './storage';
|
|
6
|
+
export type { InstallationInfo, OAuthClient } from './oauth';
|
|
5
7
|
//# 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;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;AAClB,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -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"}
|