@blocklet/did-space-js 1.1.2 → 1.1.3

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.
@@ -19,6 +19,9 @@ class SpaceClient {
19
19
  this.options.endpoint = this.options.endpoint
20
20
  ? this.normalizeEndpoint(this.options.endpoint)
21
21
  : this.options.endpoint;
22
+ this.options.wallet =
23
+ this.options.wallet ||
24
+ (this.options.auth && 'wallet' in this.options.auth ? this.options.auth.wallet : undefined);
22
25
  }
23
26
  /**
24
27
  *
@@ -47,7 +47,7 @@ class BaseCommand extends stream_1.EventEmitter {
47
47
  }) {
48
48
  const endpoint = this.context.endpoint || this.context?.auth?.endpoint;
49
49
  if (endpoint) {
50
- return endpoint;
50
+ return (0, libs_1.normalizeEndpoint)(endpoint);
51
51
  }
52
52
  if (strict) {
53
53
  if (this.context.auth || this.context.url) {
@@ -63,11 +63,11 @@ class BaseCommand extends stream_1.EventEmitter {
63
63
  getRequestUrl(key, type = 'object') {
64
64
  // 优先使用 context.endpoint
65
65
  if (this.context.endpoint) {
66
- return (0, ufo_1.joinURL)(this.context.endpoint, type, this.getKey(key));
66
+ return (0, ufo_1.joinURL)((0, libs_1.normalizeEndpoint)(this.context.endpoint), type, this.getKey(key));
67
67
  }
68
68
  // 检查 auth 中是否有 endpoint(类型安全检查)
69
69
  if (this.context.auth && 'endpoint' in this.context.auth && this.context.auth.endpoint) {
70
- return (0, ufo_1.joinURL)(this.context.auth.endpoint, type, this.getKey(key));
70
+ return (0, ufo_1.joinURL)((0, libs_1.normalizeEndpoint)(this.context.auth.endpoint), type, this.getKey(key));
71
71
  }
72
72
  // 使用 auth + url 组合
73
73
  if (this.context.auth && this.context.url) {
@@ -33,8 +33,9 @@ class PutNftObjectCommand extends base_1.BaseCommand {
33
33
  return didObjectURL.toString();
34
34
  }
35
35
  getDisplayUrl() {
36
+ const endpoint = this.getEndpoint();
36
37
  // @ts-expect-error
37
- return (0, ufo_1.joinURL)(this.context.endpoint.replace(/\/api\/space.*/, ''), 'resolve', (0, libs_1.toABTDid)(this.input.did), 'display');
38
+ return (0, ufo_1.joinURL)(endpoint.replace(/\/api\/space.*/, ''), 'resolve', (0, libs_1.toABTDid)(this.input.did), 'display');
38
39
  }
39
40
  async getStreams() {
40
41
  const writeStream = (0, fs_extra_1.createWriteStream)(this.tempCacheObjectKey);
@@ -6,7 +6,7 @@ const security_1 = require("../../security");
6
6
  class ListObjectCommand extends base_1.BaseCommand {
7
7
  async getAxiosRequestConfig() {
8
8
  const url = this.getRequestUrl(this.input.key, 'list/');
9
- const requestHeaders = await this.getRequestHeaders();
9
+ const requestHeaders = this.getRequestHeaders();
10
10
  const method = 'GET';
11
11
  const { headers } = await (0, security_1.signRequest)({
12
12
  url,
@@ -15,7 +15,7 @@ class ListObjectsCommand extends base_1.BaseCommand {
15
15
  async getAxiosRequestConfig() {
16
16
  // TODO: 此处应该有 joi 校验
17
17
  const options = (0, pick_1.default)(this.input, ['recursive', 'ignoreDirectories']);
18
- const url = (0, ufo_1.withQuery)(await this.getRequestUrl(this.input.key, 'lists/'), options);
18
+ const url = (0, ufo_1.withQuery)(this.getRequestUrl(this.input.key, 'lists/'), options);
19
19
  const requestHeaders = this.getRequestHeaders();
20
20
  const method = 'GET';
21
21
  debug('getAxiosRequestConfig.$url', url);
@@ -11,8 +11,9 @@ class HeadSpaceCommand extends base_1.BaseCommand {
11
11
  return Promise.resolve(null);
12
12
  }
13
13
  getUrl() {
14
- if (this.context.endpoint) {
15
- const array = this.context.endpoint.split('/');
14
+ const endpoint = this.context.endpoint || this.context?.auth?.endpoint;
15
+ if (endpoint) {
16
+ const array = (0, libs_1.normalizeEndpoint)(endpoint).split('/');
16
17
  const lastIndexOfApp = array.lastIndexOf('app');
17
18
  const url = array.filter((_, i) => i < lastIndexOfApp).join('/');
18
19
  return (0, ufo_1.withQuery)(url, {
@@ -38,6 +38,13 @@ export interface CommandOutput<D = any> {
38
38
  response?: Response;
39
39
  }
40
40
  export interface SpaceClientOptionsEndpointAuth {
41
+ /**
42
+ *
43
+ * @description current blocklet's wallet
44
+ * @type {WalletObject}
45
+ * @memberof SpaceClientOptionsEndpointAuth
46
+ */
47
+ wallet: WalletObject;
41
48
  /**
42
49
  *
43
50
  * @description spaces endpoint
@@ -73,7 +80,7 @@ export interface SpaceClientOptions {
73
80
  * @type {WalletObject}
74
81
  * @memberof SpaceClientOptions
75
82
  */
76
- wallet: WalletObject;
83
+ wallet?: WalletObject;
77
84
  /**
78
85
  * @recommend use `auth` field instead
79
86
  * @description spaces endpoint
@@ -16,7 +16,7 @@ declare function signRequest({ url, method, data, headers, wallet, delegation, t
16
16
  headers: {
17
17
  [key: string]: string;
18
18
  };
19
- wallet: WalletObject;
19
+ wallet?: WalletObject;
20
20
  delegation?: string;
21
21
  throwError?: true | false;
22
22
  }): Promise<{
@@ -65,7 +65,7 @@ async function signRequest({ url, method, data, headers, wallet, delegation, thr
65
65
  if (!(0, isObject_1.default)(data)) {
66
66
  error = new Error(`data(${data}) is not an object`);
67
67
  }
68
- if (!wallet) {
68
+ if (typeof wallet === 'undefined' || !wallet) {
69
69
  error = new Error('wallet is required');
70
70
  }
71
71
  if (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/did-space-js",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,8 +33,8 @@
33
33
  "@arcblock/jwt": "^1.20.15",
34
34
  "@arcblock/validator": "^1.20.15",
35
35
  "@blocklet/env": "^1.16.45",
36
- "@did-space/constants": "^1.1.2",
37
- "@did-space/core": "^1.1.2",
36
+ "@did-space/constants": "^1.1.3",
37
+ "@did-space/core": "^1.1.3",
38
38
  "@ocap/mcrypto": "^1.20.15",
39
39
  "@ocap/util": "^1.20.15",
40
40
  "@ocap/wallet": "^1.20.15",
@@ -78,5 +78,5 @@
78
78
  "ts-jest": "^28.0.8",
79
79
  "typescript": "^4.9.5"
80
80
  },
81
- "gitHead": "922e4725da8965f66033b82f9ba28d1d691f9cc5"
81
+ "gitHead": "dc3562763fae2d20d878e85d97919837fadbb132"
82
82
  }