@aicloud360/dsh-cloud-disk-api-provider 0.1.1-alpha.7 → 0.1.1-alpha.8

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/lib/index.js CHANGED
@@ -173,8 +173,8 @@ function installCloudDiskRpc(ctx) {
173
173
  ok: true,
174
174
  value: pageView(page)
175
175
  };
176
- } catch {
177
- return signal.aborted ? cancelled() : internalFailure("cloud disk listing failed");
176
+ } catch (error) {
177
+ return signal.aborted ? cancelled() : internalFailure(error instanceof CloudDiskError ? error.message : "cloud disk listing failed");
178
178
  }
179
179
  }
180
180
  case "browse/search": {
@@ -268,6 +268,7 @@ var DirectCloudDiskProvider = class {
268
268
  */
269
269
  async getUser(signal) {
270
270
  const auth = await this.authenticate(signal);
271
+ await this.signingSecret();
271
272
  const result = await this.call(this.getInput({
272
273
  method: "User.getUserDetail",
273
274
  access_token: auth.accessToken,
@@ -355,8 +356,7 @@ var DirectCloudDiskProvider = class {
355
356
  };
356
357
  }
357
358
  async signed(auth, method, extra) {
358
- const secret = await this.options.credentials.resolve(this.options.signingSecretRef);
359
- if (secret === void 0) throw signingSecretMissing();
359
+ const secret = await this.signingSecret();
360
360
  const input = {
361
361
  access_token: auth.accessToken,
362
362
  method,
@@ -369,6 +369,11 @@ var DirectCloudDiskProvider = class {
369
369
  sub_channel: this.options.subChannel
370
370
  };
371
371
  }
372
+ async signingSecret() {
373
+ const secret = await this.options.credentials.resolve(this.options.signingSecretRef);
374
+ if (secret === void 0) throw signingSecretMissing();
375
+ return secret;
376
+ }
372
377
  getInput(params, accessToken) {
373
378
  return {
374
379
  method: "GET",
@@ -411,7 +416,7 @@ var DirectCloudDiskProvider = class {
411
416
  }
412
417
  }
413
418
  data(result, subject) {
414
- if (result.errno !== 0) throw failed(`CloudDisk ${subject} failed`);
419
+ if (result.errno !== 0) throw apiFailure(subject, result.errno);
415
420
  return result.data;
416
421
  }
417
422
  page(value, path, parentId, page) {
@@ -486,6 +491,9 @@ function networkFailed() {
486
491
  function failed(message) {
487
492
  return new CloudDiskError(message, "CLOUD_DISK_PROVIDER_FAILED");
488
493
  }
494
+ function apiFailure(subject, errno) {
495
+ return failed(`CloudDisk ${subject} failed with API errno ${typeof errno === "number" && Number.isSafeInteger(errno) ? String(errno) : typeof errno === "string" && /^-?\d{1,10}$/u.test(errno) ? errno : "unknown"}`);
496
+ }
489
497
  function invalidResponse(subject) {
490
498
  return failed(`CloudDisk ${subject} response is invalid`);
491
499
  }
@@ -86,6 +86,7 @@ export declare class DirectCloudDiskProvider implements CloudDiskProvider {
86
86
  search(request: CloudDiskSearchRequest, signal?: AbortSignal): Promise<CloudDiskPage>;
87
87
  private authenticate;
88
88
  private signed;
89
+ private signingSecret;
89
90
  private getInput;
90
91
  private postInput;
91
92
  private call;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aicloud360/dsh-cloud-disk-api-provider",
3
3
  "description": "Direct Host-side HTTP provider adapter for the native CloudDisk capability seam",
4
- "version": "0.1.1-alpha.7",
4
+ "version": "0.1.1-alpha.8",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org"
@@ -39,6 +39,6 @@
39
39
  "./package.json": "./package.json"
40
40
  },
41
41
  "dependencies": {
42
- "@aicloud360/dsh-cloud-disk": "0.1.1-alpha.7"
42
+ "@aicloud360/dsh-cloud-disk": "0.1.1-alpha.8"
43
43
  }
44
44
  }