@ones-open/node-sdk 0.0.4-16596.20 → 0.0.4-16644.216
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 +134 -51
- package/dist/index.js +134 -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,88 @@
|
|
|
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;
|
|
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}`;
|
|
9
48
|
};
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|
|
13
79
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
80
|
+
const oauth = {
|
|
81
|
+
getAccessTokenByInstallationInfo
|
|
16
82
|
};
|
|
17
|
-
const getAppId = getApplicationId;
|
|
18
83
|
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
19
84
|
__proto__: null,
|
|
20
|
-
|
|
21
|
-
getApplicationId,
|
|
22
|
-
getInstanceId,
|
|
23
|
-
getPlatformAPIHost,
|
|
24
|
-
getPlatformApiHost
|
|
85
|
+
oauth
|
|
25
86
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
26
87
|
var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
|
|
27
88
|
EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
|
|
@@ -123,24 +184,37 @@ const createErrorResult = (code, message, error) => {
|
|
|
123
184
|
}, error);
|
|
124
185
|
};
|
|
125
186
|
const fetch$1 = Fetch.create();
|
|
187
|
+
const buildAuthHeaders$1 = () => {
|
|
188
|
+
const token = getONESHostedToken();
|
|
189
|
+
if (token) {
|
|
190
|
+
return {
|
|
191
|
+
Authorization: `Bearer ${token}`
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return {};
|
|
195
|
+
};
|
|
126
196
|
const fetchBase$1 = (path, params, config) => {
|
|
127
|
-
return Promise.all([
|
|
128
|
-
let [base,
|
|
129
|
-
if (base &&
|
|
130
|
-
|
|
197
|
+
return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
|
|
198
|
+
let [base, appId] = _ref;
|
|
199
|
+
if (base && appId) {
|
|
200
|
+
var _config$headers;
|
|
201
|
+
const url = `${base}/hosted_ability/storage/${appId}${path}`;
|
|
131
202
|
const data = {
|
|
132
|
-
...params
|
|
133
|
-
instance_id
|
|
203
|
+
...params
|
|
134
204
|
};
|
|
135
205
|
return fetch$1({
|
|
136
206
|
...config,
|
|
207
|
+
headers: {
|
|
208
|
+
...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
|
|
209
|
+
...buildAuthHeaders$1()
|
|
210
|
+
},
|
|
137
211
|
url,
|
|
138
212
|
data
|
|
139
213
|
});
|
|
140
214
|
}
|
|
141
215
|
throw new Error(JSON.stringify({
|
|
142
216
|
base,
|
|
143
|
-
|
|
217
|
+
appId
|
|
144
218
|
}));
|
|
145
219
|
}).then((response) => {
|
|
146
220
|
return response.data;
|
|
@@ -157,22 +231,22 @@ const fetchBase$1 = (path, params, config) => {
|
|
|
157
231
|
});
|
|
158
232
|
};
|
|
159
233
|
const fetchPost = (params) => {
|
|
160
|
-
return fetchBase$1(
|
|
234
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
161
235
|
method: "post"
|
|
162
236
|
});
|
|
163
237
|
};
|
|
164
238
|
const fetchDelete$1 = (params) => {
|
|
165
|
-
return fetchBase$1(
|
|
239
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
166
240
|
method: "delete"
|
|
167
241
|
});
|
|
168
242
|
};
|
|
169
243
|
const fetchQuery = (params) => {
|
|
170
|
-
return fetchBase$1(
|
|
244
|
+
return fetchBase$1(`/entity_data/get_many`, params, {
|
|
171
245
|
method: "post"
|
|
172
246
|
});
|
|
173
247
|
};
|
|
174
248
|
const fetchCount = (params) => {
|
|
175
|
-
return fetchBase$1(
|
|
249
|
+
return fetchBase$1(`/entity_data/count`, params, {
|
|
176
250
|
method: "post"
|
|
177
251
|
});
|
|
178
252
|
};
|
|
@@ -190,12 +264,12 @@ const defaultEntityQueryIndex = defaultEntityQuery.index;
|
|
|
190
264
|
const defaultEntityQueryWhere = defaultEntityQuery.where;
|
|
191
265
|
class EntityQueryClass {
|
|
192
266
|
constructor(name) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
267
|
+
this._name = "";
|
|
268
|
+
this._cursor = [defaultEntityQueryCursor];
|
|
269
|
+
this._limit = [defaultEntityQueryLimit];
|
|
270
|
+
this._sort = [defaultEntityQuerySort];
|
|
271
|
+
this._index = [defaultEntityQueryIndex];
|
|
272
|
+
this._where = [defaultEntityQueryWhere];
|
|
199
273
|
this._name = name;
|
|
200
274
|
}
|
|
201
275
|
cursor(cursor) {
|
|
@@ -289,7 +363,7 @@ class EntityQueryClass {
|
|
|
289
363
|
}
|
|
290
364
|
class EntityClass {
|
|
291
365
|
constructor(name) {
|
|
292
|
-
|
|
366
|
+
this._name = "";
|
|
293
367
|
this._name = name;
|
|
294
368
|
}
|
|
295
369
|
async get(key) {
|
|
@@ -395,31 +469,38 @@ var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
|
|
|
395
469
|
return ObjectErrorCode2;
|
|
396
470
|
})(ObjectErrorCode || {});
|
|
397
471
|
class ObjectError {
|
|
398
|
-
/**
|
|
399
|
-
* @description 错误载荷
|
|
400
|
-
*/
|
|
401
472
|
constructor(result) {
|
|
402
|
-
|
|
473
|
+
this.err_msg = "";
|
|
403
474
|
this.code = result.code;
|
|
404
475
|
this.err_msg = result.err_msg;
|
|
405
476
|
this.err_values = result.err_values;
|
|
406
477
|
}
|
|
407
478
|
}
|
|
408
479
|
const fetch = Fetch.create();
|
|
480
|
+
const buildAuthHeaders = () => {
|
|
481
|
+
const token = getONESHostedToken();
|
|
482
|
+
if (token) {
|
|
483
|
+
return {
|
|
484
|
+
Authorization: `Bearer ${token}`
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
return {};
|
|
488
|
+
};
|
|
409
489
|
const fetchBase = (path, params) => {
|
|
410
|
-
return Promise.all([
|
|
411
|
-
let [base,
|
|
412
|
-
if (base &&
|
|
413
|
-
const url = `${base}${path}`;
|
|
490
|
+
return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
|
|
491
|
+
let [base, appId] = _ref;
|
|
492
|
+
if (base && appId) {
|
|
493
|
+
const url = `${base}/hosted_ability/storage/${appId}${path}`;
|
|
414
494
|
const data = {
|
|
415
|
-
...params
|
|
416
|
-
instance_id
|
|
495
|
+
...params
|
|
417
496
|
};
|
|
418
|
-
return fetch.post(url, data
|
|
497
|
+
return fetch.post(url, data, {
|
|
498
|
+
headers: buildAuthHeaders()
|
|
499
|
+
});
|
|
419
500
|
}
|
|
420
501
|
throw new Error(JSON.stringify({
|
|
421
502
|
base,
|
|
422
|
-
|
|
503
|
+
appId
|
|
423
504
|
}));
|
|
424
505
|
}).then((response) => {
|
|
425
506
|
return response.data;
|
|
@@ -436,16 +517,16 @@ const fetchBase = (path, params) => {
|
|
|
436
517
|
});
|
|
437
518
|
};
|
|
438
519
|
const fetchUpload = (params) => {
|
|
439
|
-
return fetchBase(
|
|
520
|
+
return fetchBase(`/object/get_upload_policy_info`, params);
|
|
440
521
|
};
|
|
441
522
|
const fetchDownload = (params) => {
|
|
442
|
-
return fetchBase(
|
|
523
|
+
return fetchBase(`/object/get_download_pre_signed_url`, params);
|
|
443
524
|
};
|
|
444
525
|
const fetchDelete = (params) => {
|
|
445
|
-
return fetchBase(
|
|
526
|
+
return fetchBase(`/object/delete`, params);
|
|
446
527
|
};
|
|
447
528
|
const fetchMetadata = (params) => {
|
|
448
|
-
return fetchBase(
|
|
529
|
+
return fetchBase(`/object/get_metadata`, params);
|
|
449
530
|
};
|
|
450
531
|
const object = {
|
|
451
532
|
ObjectError,
|
|
@@ -455,7 +536,8 @@ const object = {
|
|
|
455
536
|
object_key: key
|
|
456
537
|
});
|
|
457
538
|
if (result.code === "OK") {
|
|
458
|
-
|
|
539
|
+
var _result$data;
|
|
540
|
+
if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
|
|
459
541
|
const {
|
|
460
542
|
url,
|
|
461
543
|
fields
|
|
@@ -536,5 +618,6 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
536
618
|
object
|
|
537
619
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
538
620
|
exports.ErrorCode = ErrorCode;
|
|
539
|
-
exports.env = index$
|
|
621
|
+
exports.env = index$2;
|
|
622
|
+
exports.oauth = index$1;
|
|
540
623
|
exports.storage = index;
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,86 @@
|
|
|
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;
|
|
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}`;
|
|
7
46
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
}
|
|
11
77
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
78
|
+
const oauth = {
|
|
79
|
+
getAccessTokenByInstallationInfo
|
|
14
80
|
};
|
|
15
|
-
const getAppId = getApplicationId;
|
|
16
81
|
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
17
82
|
__proto__: null,
|
|
18
|
-
|
|
19
|
-
getApplicationId,
|
|
20
|
-
getInstanceId,
|
|
21
|
-
getPlatformAPIHost,
|
|
22
|
-
getPlatformApiHost
|
|
83
|
+
oauth
|
|
23
84
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
24
85
|
var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
|
|
25
86
|
EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
|
|
@@ -121,24 +182,37 @@ const createErrorResult = (code, message, error) => {
|
|
|
121
182
|
}, error);
|
|
122
183
|
};
|
|
123
184
|
const fetch$1 = Fetch.create();
|
|
185
|
+
const buildAuthHeaders$1 = () => {
|
|
186
|
+
const token = getONESHostedToken();
|
|
187
|
+
if (token) {
|
|
188
|
+
return {
|
|
189
|
+
Authorization: `Bearer ${token}`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return {};
|
|
193
|
+
};
|
|
124
194
|
const fetchBase$1 = (path, params, config) => {
|
|
125
|
-
return Promise.all([
|
|
126
|
-
let [base,
|
|
127
|
-
if (base &&
|
|
128
|
-
|
|
195
|
+
return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
|
|
196
|
+
let [base, appId] = _ref;
|
|
197
|
+
if (base && appId) {
|
|
198
|
+
var _config$headers;
|
|
199
|
+
const url = `${base}/hosted_ability/storage/${appId}${path}`;
|
|
129
200
|
const data = {
|
|
130
|
-
...params
|
|
131
|
-
instance_id
|
|
201
|
+
...params
|
|
132
202
|
};
|
|
133
203
|
return fetch$1({
|
|
134
204
|
...config,
|
|
205
|
+
headers: {
|
|
206
|
+
...(_config$headers = config === null || config === void 0 ? void 0 : config.headers) !== null && _config$headers !== void 0 ? _config$headers : {},
|
|
207
|
+
...buildAuthHeaders$1()
|
|
208
|
+
},
|
|
135
209
|
url,
|
|
136
210
|
data
|
|
137
211
|
});
|
|
138
212
|
}
|
|
139
213
|
throw new Error(JSON.stringify({
|
|
140
214
|
base,
|
|
141
|
-
|
|
215
|
+
appId
|
|
142
216
|
}));
|
|
143
217
|
}).then((response) => {
|
|
144
218
|
return response.data;
|
|
@@ -155,22 +229,22 @@ const fetchBase$1 = (path, params, config) => {
|
|
|
155
229
|
});
|
|
156
230
|
};
|
|
157
231
|
const fetchPost = (params) => {
|
|
158
|
-
return fetchBase$1(
|
|
232
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
159
233
|
method: "post"
|
|
160
234
|
});
|
|
161
235
|
};
|
|
162
236
|
const fetchDelete$1 = (params) => {
|
|
163
|
-
return fetchBase$1(
|
|
237
|
+
return fetchBase$1(`/entity_data`, params, {
|
|
164
238
|
method: "delete"
|
|
165
239
|
});
|
|
166
240
|
};
|
|
167
241
|
const fetchQuery = (params) => {
|
|
168
|
-
return fetchBase$1(
|
|
242
|
+
return fetchBase$1(`/entity_data/get_many`, params, {
|
|
169
243
|
method: "post"
|
|
170
244
|
});
|
|
171
245
|
};
|
|
172
246
|
const fetchCount = (params) => {
|
|
173
|
-
return fetchBase$1(
|
|
247
|
+
return fetchBase$1(`/entity_data/count`, params, {
|
|
174
248
|
method: "post"
|
|
175
249
|
});
|
|
176
250
|
};
|
|
@@ -188,12 +262,12 @@ const defaultEntityQueryIndex = defaultEntityQuery.index;
|
|
|
188
262
|
const defaultEntityQueryWhere = defaultEntityQuery.where;
|
|
189
263
|
class EntityQueryClass {
|
|
190
264
|
constructor(name) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
265
|
+
this._name = "";
|
|
266
|
+
this._cursor = [defaultEntityQueryCursor];
|
|
267
|
+
this._limit = [defaultEntityQueryLimit];
|
|
268
|
+
this._sort = [defaultEntityQuerySort];
|
|
269
|
+
this._index = [defaultEntityQueryIndex];
|
|
270
|
+
this._where = [defaultEntityQueryWhere];
|
|
197
271
|
this._name = name;
|
|
198
272
|
}
|
|
199
273
|
cursor(cursor) {
|
|
@@ -287,7 +361,7 @@ class EntityQueryClass {
|
|
|
287
361
|
}
|
|
288
362
|
class EntityClass {
|
|
289
363
|
constructor(name) {
|
|
290
|
-
|
|
364
|
+
this._name = "";
|
|
291
365
|
this._name = name;
|
|
292
366
|
}
|
|
293
367
|
async get(key) {
|
|
@@ -393,31 +467,38 @@ var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
|
|
|
393
467
|
return ObjectErrorCode2;
|
|
394
468
|
})(ObjectErrorCode || {});
|
|
395
469
|
class ObjectError {
|
|
396
|
-
/**
|
|
397
|
-
* @description 错误载荷
|
|
398
|
-
*/
|
|
399
470
|
constructor(result) {
|
|
400
|
-
|
|
471
|
+
this.err_msg = "";
|
|
401
472
|
this.code = result.code;
|
|
402
473
|
this.err_msg = result.err_msg;
|
|
403
474
|
this.err_values = result.err_values;
|
|
404
475
|
}
|
|
405
476
|
}
|
|
406
477
|
const fetch = Fetch.create();
|
|
478
|
+
const buildAuthHeaders = () => {
|
|
479
|
+
const token = getONESHostedToken();
|
|
480
|
+
if (token) {
|
|
481
|
+
return {
|
|
482
|
+
Authorization: `Bearer ${token}`
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return {};
|
|
486
|
+
};
|
|
407
487
|
const fetchBase = (path, params) => {
|
|
408
|
-
return Promise.all([
|
|
409
|
-
let [base,
|
|
410
|
-
if (base &&
|
|
411
|
-
const url = `${base}${path}`;
|
|
488
|
+
return Promise.all([getONESHostedBaseUrl(), getONESHostedAppID()]).then((_ref) => {
|
|
489
|
+
let [base, appId] = _ref;
|
|
490
|
+
if (base && appId) {
|
|
491
|
+
const url = `${base}/hosted_ability/storage/${appId}${path}`;
|
|
412
492
|
const data = {
|
|
413
|
-
...params
|
|
414
|
-
instance_id
|
|
493
|
+
...params
|
|
415
494
|
};
|
|
416
|
-
return fetch.post(url, data
|
|
495
|
+
return fetch.post(url, data, {
|
|
496
|
+
headers: buildAuthHeaders()
|
|
497
|
+
});
|
|
417
498
|
}
|
|
418
499
|
throw new Error(JSON.stringify({
|
|
419
500
|
base,
|
|
420
|
-
|
|
501
|
+
appId
|
|
421
502
|
}));
|
|
422
503
|
}).then((response) => {
|
|
423
504
|
return response.data;
|
|
@@ -434,16 +515,16 @@ const fetchBase = (path, params) => {
|
|
|
434
515
|
});
|
|
435
516
|
};
|
|
436
517
|
const fetchUpload = (params) => {
|
|
437
|
-
return fetchBase(
|
|
518
|
+
return fetchBase(`/object/get_upload_policy_info`, params);
|
|
438
519
|
};
|
|
439
520
|
const fetchDownload = (params) => {
|
|
440
|
-
return fetchBase(
|
|
521
|
+
return fetchBase(`/object/get_download_pre_signed_url`, params);
|
|
441
522
|
};
|
|
442
523
|
const fetchDelete = (params) => {
|
|
443
|
-
return fetchBase(
|
|
524
|
+
return fetchBase(`/object/delete`, params);
|
|
444
525
|
};
|
|
445
526
|
const fetchMetadata = (params) => {
|
|
446
|
-
return fetchBase(
|
|
527
|
+
return fetchBase(`/object/get_metadata`, params);
|
|
447
528
|
};
|
|
448
529
|
const object = {
|
|
449
530
|
ObjectError,
|
|
@@ -453,7 +534,8 @@ const object = {
|
|
|
453
534
|
object_key: key
|
|
454
535
|
});
|
|
455
536
|
if (result.code === "OK") {
|
|
456
|
-
|
|
537
|
+
var _result$data;
|
|
538
|
+
if ((_result$data = result.data) !== null && _result$data !== void 0 && _result$data.url) {
|
|
457
539
|
const {
|
|
458
540
|
url,
|
|
459
541
|
fields
|
|
@@ -535,6 +617,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
535
617
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
536
618
|
export {
|
|
537
619
|
ErrorCode,
|
|
538
|
-
index$
|
|
620
|
+
index$2 as env,
|
|
621
|
+
index$1 as oauth,
|
|
539
622
|
index as storage
|
|
540
623
|
};
|
|
@@ -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;AA2F5B,eAAO,MAAM,KAAK,EAAE,WAEnB,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"}
|