@ms-cloudpack/remote-cache 0.6.3 → 0.6.5

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.
@@ -1,21 +1,19 @@
1
1
  import {
2
+ __commonJS,
3
+ __esm,
4
+ __export,
5
+ __name,
6
+ __require,
7
+ __toCommonJS,
2
8
  esm_node_exports,
9
+ init_esbuildCjsShims,
3
10
  init_esm_node,
4
11
  init_tslib_es6,
5
12
  require_dist,
6
13
  require_dist2,
7
14
  require_dist3,
8
15
  tslib_es6_exports
9
- } from "./chunk-4P62L7ZZ.js";
10
- import {
11
- __commonJS,
12
- __esm,
13
- __export,
14
- __name,
15
- __require,
16
- __toCommonJS,
17
- init_esbuildCjsShims
18
- } from "./chunk-TQLTL4XO.js";
16
+ } from "./chunk-OPD65OLQ.js";
19
17
 
20
18
  // ../../node_modules/.store/xml2js-npm-0.5.0-06e57a2771/package/lib/defaults.js
21
19
  var require_defaults = __commonJS({
@@ -6069,7 +6067,7 @@ var require_dist4 = __commonJS({
6069
6067
  "use strict";
6070
6068
  init_esbuildCjsShims();
6071
6069
  Object.defineProperty(exports, "__esModule", { value: true });
6072
- var coreUtil = require_dist3();
6070
+ var coreUtil = require_dist2();
6073
6071
  var _AzureKeyCredential = class _AzureKeyCredential {
6074
6072
  /**
6075
6073
  * The value of the key to be used in authentication
@@ -20927,13 +20925,13 @@ var require_dist6 = __commonJS({
20927
20925
  var util = __require("util");
20928
20926
  var tslib = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
20929
20927
  var xml2js = require_xml2js();
20930
- var coreUtil = require_dist3();
20931
- var logger$1 = require_dist();
20928
+ var coreUtil = require_dist2();
20929
+ var logger$1 = require_dist3();
20932
20930
  var coreAuth = require_dist4();
20933
20931
  var os = __require("os");
20934
20932
  var http = __require("http");
20935
20933
  var https = __require("https");
20936
- var abortController = require_dist2();
20934
+ var abortController = require_dist();
20937
20935
  var tunnel = require_package();
20938
20936
  var stream = __require("stream");
20939
20937
  var FormData = require_form_data();
@@ -25487,9 +25485,9 @@ var require_dist8 = __commonJS({
25487
25485
  "use strict";
25488
25486
  init_esbuildCjsShims();
25489
25487
  Object.defineProperty(exports, "__esModule", { value: true });
25490
- var logger$1 = require_dist();
25491
- var abortController = require_dist2();
25492
- var coreUtil = require_dist3();
25488
+ var logger$1 = require_dist3();
25489
+ var abortController = require_dist();
25490
+ var coreUtil = require_dist2();
25493
25491
  var logger = logger$1.createClientLogger("core-lro");
25494
25492
  var POLL_INTERVAL_IN_MS = 2e3;
25495
25493
  var terminalStates = ["succeeded", "canceled", "failed"];
@@ -26538,8 +26536,8 @@ var require_dist9 = __commonJS({
26538
26536
  var coreHttp = require_dist6();
26539
26537
  var tslib = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
26540
26538
  var coreTracing = require_dist5();
26541
- var logger$1 = require_dist();
26542
- var abortController = require_dist2();
26539
+ var logger$1 = require_dist3();
26540
+ var abortController = require_dist();
26543
26541
  var os = __require("os");
26544
26542
  var crypto = __require("crypto");
26545
26543
  var stream = __require("stream");
@@ -1,12 +1,3 @@
1
- import {
2
- init_esm_node,
3
- init_tslib_es6,
4
- require_dist,
5
- require_dist2,
6
- require_dist3,
7
- tslib_es6_exports,
8
- v4_default
9
- } from "./chunk-4P62L7ZZ.js";
10
1
  import {
11
2
  __commonJS,
12
3
  __esm,
@@ -15,8 +6,15 @@ import {
15
6
  __require,
16
7
  __toCommonJS,
17
8
  __toESM,
18
- init_esbuildCjsShims
19
- } from "./chunk-TQLTL4XO.js";
9
+ init_esbuildCjsShims,
10
+ init_esm_node,
11
+ init_tslib_es6,
12
+ require_dist,
13
+ require_dist2,
14
+ require_dist3,
15
+ tslib_es6_exports,
16
+ v4_default
17
+ } from "./chunk-OPD65OLQ.js";
20
18
 
21
19
  // ../../node_modules/.store/@azure-msal-node-npm-2.6.2-9183813942/package/dist/cache/serializer/Serializer.mjs
22
20
  var _Serializer, Serializer;
@@ -16524,10 +16522,10 @@ var require_dist8 = __commonJS({
16524
16522
  "use strict";
16525
16523
  init_esbuildCjsShims();
16526
16524
  Object.defineProperty(exports, "__esModule", { value: true });
16527
- var logger$1 = require_dist();
16528
- var coreUtil = require_dist3();
16525
+ var logger$1 = require_dist3();
16526
+ var coreUtil = require_dist2();
16529
16527
  var os = __require("os");
16530
- var abortController = require_dist2();
16528
+ var abortController = require_dist();
16531
16529
  var httpsProxyAgent = require_dist4();
16532
16530
  var httpProxyAgent = require_dist6();
16533
16531
  var coreTracing = require_dist7();
@@ -18555,7 +18553,7 @@ var require_dist9 = __commonJS({
18555
18553
  init_esbuildCjsShims();
18556
18554
  Object.defineProperty(exports, "__esModule", { value: true });
18557
18555
  var coreRestPipeline = require_dist8();
18558
- var logger$1 = require_dist();
18556
+ var logger$1 = require_dist3();
18559
18557
  function encodeByteArray(value) {
18560
18558
  const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer);
18561
18559
  return bufferValue.toString("base64");
@@ -20641,9 +20639,9 @@ var require_dist10 = __commonJS({
20641
20639
  init_esbuildCjsShims();
20642
20640
  Object.defineProperty(exports, "__esModule", { value: true });
20643
20641
  var msalCommon = (init_dist2(), __toCommonJS(dist_exports));
20644
- var logger$o = require_dist();
20645
- var abortController = require_dist2();
20646
- var coreUtil = require_dist3();
20642
+ var logger$o = require_dist3();
20643
+ var abortController = require_dist();
20644
+ var coreUtil = require_dist2();
20647
20645
  var coreClient = require_dist9();
20648
20646
  var coreRestPipeline = require_dist8();
20649
20647
  var coreTracing = require_dist7();
@@ -24221,52 +24219,47 @@ var tokenCachePersistenceOptions = {
24221
24219
  enabled: true,
24222
24220
  name: "cloudpack"
24223
24221
  };
24224
- function getCredentialInternal(loginMethod, authenticationRecord) {
24222
+ function getCredentialInternal(loginMethod, authenticationRecord, tenantId) {
24225
24223
  switch (loginMethod) {
24226
24224
  case "interactive":
24227
24225
  return new import_identity3.InteractiveBrowserCredential({
24228
24226
  redirectUri: "http://localhost:1337",
24229
24227
  authenticationRecord,
24230
- tokenCachePersistenceOptions
24228
+ tokenCachePersistenceOptions,
24229
+ tenantId
24231
24230
  });
24232
24231
  case "device-code":
24233
24232
  return new import_identity3.DeviceCodeCredential({
24234
24233
  authenticationRecord,
24235
- tokenCachePersistenceOptions
24234
+ tokenCachePersistenceOptions,
24235
+ tenantId
24236
24236
  });
24237
24237
  default:
24238
24238
  throw new Error(`Invalid login method: ${loginMethod}`);
24239
24239
  }
24240
24240
  }
24241
24241
  __name(getCredentialInternal, "getCredentialInternal");
24242
- async function getCredential(loginMethod, cachePath) {
24242
+ async function getCredential(loginMethod, cachePath, tenantId) {
24243
24243
  if (loginMethod == "azure-cli") {
24244
24244
  return new import_identity3.AzureCliCredential();
24245
24245
  }
24246
24246
  (0, import_identity3.useIdentityPlugin)(import_identity_cache_persistence.cachePersistencePlugin);
24247
- let authenticationRecord = getAuthenticationRecord(cachePath);
24248
- const credential = getCredentialInternal(loginMethod, authenticationRecord);
24249
- if (!authenticationRecord) {
24250
- console.warn("Cloudpack requires authentication to access Azure resources.");
24251
- if (loginMethod == "interactive") {
24252
- console.warn(
24253
- "Prepare to sign in \u2013 we're launching a browser page for you. Simply follow the instructions on the login page to seamlessly complete the authentication process."
24254
- );
24255
- }
24256
- const storageScope = "https://storage.azure.com/.default";
24257
- authenticationRecord = await credential.authenticate(storageScope);
24258
- const token = await credential.getToken(storageScope);
24259
- const storageCustomCredential = {
24260
- getToken: async () => {
24261
- return Promise.resolve(token);
24262
- }
24263
- };
24264
- if (authenticationRecord) {
24265
- saveAuthenticationRecord(cachePath, authenticationRecord);
24266
- }
24267
- return storageCustomCredential;
24247
+ const credential = getCredentialInternal(loginMethod, getAuthenticationRecord(cachePath), tenantId);
24248
+ if (loginMethod == "interactive") {
24249
+ console.warn(
24250
+ "Prepare to sign in \u2013 we may launch a browser page for you. Simply follow the instructions on the login page to seamlessly complete the authentication process."
24251
+ );
24252
+ }
24253
+ const storageScope = "https://storage.azure.com/.default";
24254
+ const authenticationRecord = await credential.authenticate(storageScope);
24255
+ const token = await credential.getToken(storageScope);
24256
+ const storageCustomCredential = {
24257
+ getToken: () => Promise.resolve(token)
24258
+ };
24259
+ if (authenticationRecord) {
24260
+ saveAuthenticationRecord(cachePath, authenticationRecord);
24268
24261
  }
24269
- return credential;
24262
+ return storageCustomCredential;
24270
24263
  }
24271
24264
  __name(getCredential, "getCredential");
24272
24265
  export {
@@ -1,15 +1,14 @@
1
1
  import {
2
2
  createBlobStorageUrl
3
- } from "./chunk-R2VDVRDZ.js";
3
+ } from "./chunk-5BUSQ7SW.js";
4
4
  import {
5
5
  require_dist
6
- } from "./chunk-KFSFZYG6.js";
7
- import "./chunk-4P62L7ZZ.js";
6
+ } from "./chunk-YAIY33BG.js";
8
7
  import {
9
8
  __name,
10
9
  __toESM,
11
10
  init_esbuildCjsShims
12
- } from "./chunk-TQLTL4XO.js";
11
+ } from "./chunk-OPD65OLQ.js";
13
12
 
14
13
  // src/getListOfBlobs.ts
15
14
  init_esbuildCjsShims();
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
+ import {
2
+ require_dist
3
+ } from "./chunk-YAIY33BG.js";
1
4
  import {
2
5
  __name,
6
+ __toESM,
3
7
  init_esbuildCjsShims
4
- } from "./chunk-TQLTL4XO.js";
8
+ } from "./chunk-OPD65OLQ.js";
5
9
 
6
10
  // src/index.ts
7
11
  init_esbuildCjsShims();
@@ -78,32 +82,77 @@ var blockListIsInvalidRetryPolicy = {
78
82
 
79
83
  // src/createRemoteCacheClient.ts
80
84
  import { RetryManager } from "@ms-cloudpack/retry";
85
+
86
+ // src/error/transformError.ts
87
+ init_esbuildCjsShims();
88
+
89
+ // src/error/RemoteCacheError.ts
90
+ init_esbuildCjsShims();
91
+ var _RemoteCacheError = class _RemoteCacheError extends Error {
92
+ constructor(code, message) {
93
+ super(message);
94
+ this._code = code;
95
+ }
96
+ get code() {
97
+ return this._code;
98
+ }
99
+ };
100
+ __name(_RemoteCacheError, "RemoteCacheError");
101
+ var RemoteCacheError = _RemoteCacheError;
102
+
103
+ // src/error/isRestError.ts
104
+ init_esbuildCjsShims();
105
+ var import_storage_blob = __toESM(require_dist(), 1);
106
+ function isRestError(error) {
107
+ return error instanceof import_storage_blob.RestError;
108
+ }
109
+ __name(isRestError, "isRestError");
110
+
111
+ // src/error/transformError.ts
112
+ function transformError(error) {
113
+ if (isRestError(error) && error.statusCode === 401 || error instanceof Error && error.name === "AuthenticationRequiredError") {
114
+ return new RemoteCacheError("AUTH_ERROR", "Authentication failed. Please check your credentials and try again.");
115
+ }
116
+ if (isRestError(error) && error.code === "REQUEST_SEND_ERROR") {
117
+ return new RemoteCacheError("CONNECTION_ERROR", "Connection failed. Please check your connection.");
118
+ }
119
+ return error;
120
+ }
121
+ __name(transformError, "transformError");
122
+
123
+ // src/createRemoteCacheClient.ts
81
124
  async function createRemoteCacheClient(params) {
82
125
  const { context, options } = params;
83
- const { container, loginMethod, storageAccount, cachePath } = options;
84
- const { getCredential } = await import("./getCredential-QMMPE77Q.js");
85
- const { AzureRemoteCacheClient } = await import("./AzureRemoteCacheClient-NEV2XCF7.js");
86
- const { ReporterDecorator } = await import("./ReporterDecorator-SNBYNGOT.js");
87
- const { getListOfBlobs } = await import("./getListOfBlobs-E5OFG2MF.js");
88
- const credential = await getCredential(loginMethod, cachePath);
89
- const remoteCacheClientOptions = {
90
- storageAccount,
91
- container,
92
- credential
93
- };
94
- const client = new ReporterDecorator(
95
- new RetryDecorator({
96
- retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
97
- cacheClient: new InMemoryDecorator({
98
- cacheClient: new AzureRemoteCacheClient(remoteCacheClientOptions),
99
- getList: () => getListOfBlobs(remoteCacheClientOptions)
100
- })
101
- }),
102
- context
103
- );
104
- return client;
126
+ const { container, loginMethod, storageAccount, cachePath, tenantId } = options;
127
+ const { getCredential } = await import("./getCredential-FIEDCLGJ.js");
128
+ const { AzureRemoteCacheClient } = await import("./AzureRemoteCacheClient-NBBUAAXL.js");
129
+ const { ReporterDecorator } = await import("./ReporterDecorator-YCOIU5LI.js");
130
+ const { getListOfBlobs } = await import("./getListOfBlobs-VRDJ4A5S.js");
131
+ try {
132
+ const credential = await getCredential(loginMethod, cachePath, tenantId);
133
+ const remoteCacheClientOptions = {
134
+ storageAccount,
135
+ container,
136
+ credential
137
+ };
138
+ const listOfBlobs = await getListOfBlobs(remoteCacheClientOptions);
139
+ const client = new ReporterDecorator(
140
+ new RetryDecorator({
141
+ retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
142
+ cacheClient: new InMemoryDecorator({
143
+ cacheClient: new AzureRemoteCacheClient(remoteCacheClientOptions),
144
+ getList: () => Promise.resolve(listOfBlobs)
145
+ })
146
+ }),
147
+ context
148
+ );
149
+ return client;
150
+ } catch (error) {
151
+ throw transformError(error);
152
+ }
105
153
  }
106
154
  __name(createRemoteCacheClient, "createRemoteCacheClient");
107
155
  export {
156
+ RemoteCacheError,
108
157
  createRemoteCacheClient
109
158
  };
@@ -6,5 +6,5 @@ import type { LoginMethod } from '../types/LoginMethod.js';
6
6
  * Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.
7
7
  * If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.
8
8
  */
9
- export declare function getCredential(loginMethod: LoginMethod, cachePath: string): Promise<TokenCredential>;
9
+ export declare function getCredential(loginMethod: LoginMethod, cachePath: string, tenantId?: string): Promise<TokenCredential>;
10
10
  //# sourceMappingURL=getCredential.d.ts.map
@@ -8,6 +8,7 @@ export interface CreateRemoteCacheClientParams {
8
8
  container: string;
9
9
  loginMethod: LoginMethod;
10
10
  cachePath: string;
11
+ tenantId?: string;
11
12
  };
12
13
  context: {
13
14
  reporter: TaskReporter;
@@ -0,0 +1,10 @@
1
+ export type RemoteCacheErrorType = 'CONNECTION_ERROR' | 'AUTH_ERROR';
2
+ /**
3
+ * An error thrown by a remote cache client.
4
+ */
5
+ export declare class RemoteCacheError extends Error {
6
+ private _code;
7
+ constructor(code: RemoteCacheErrorType, message: string);
8
+ get code(): RemoteCacheErrorType;
9
+ }
10
+ //# sourceMappingURL=RemoteCacheError.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { RestError } from '@azure/storage-blob';
2
+ export declare function isRestError(error: unknown): error is RestError;
3
+ //# sourceMappingURL=isRestError.d.ts.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Transforms an error into a RemoteCacheError if it is a known error type.
3
+ * @param error - The error to transform.
4
+ * @returns - The transformed error or the original error if it is not a known error type.
5
+ */
6
+ export declare function transformError(error: unknown): unknown;
7
+ //# sourceMappingURL=transformError.d.ts.map
package/lib/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export { createRemoteCacheClient, type CreateRemoteCacheClientParams } from './c
2
2
  export type { RemoteCacheClient, RemoteCacheClientUploadOperationOptions as RemoteCacheClientDownloadOperationOptions, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult, } from './types/RemoteCacheClient.js';
3
3
  export type { LoginMethod } from './types/LoginMethod.js';
4
4
  export type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
5
+ export { RemoteCacheError } from './error/RemoteCacheError.js';
6
+ export type { RemoteCacheErrorType } from './error/RemoteCacheError.js';
5
7
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/remote-cache",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@azure/msal-node-extensions": "^1.0.10",
31
31
  "@ms-cloudpack/retry": "^0.1.1",
32
- "@ms-cloudpack/task-reporter": "^0.12.0",
32
+ "@ms-cloudpack/task-reporter": "^0.13.1",
33
33
  "@ms-cloudpack/telemetry": "^0.5.1"
34
34
  },
35
35
  "devDependencies": {
@@ -1,65 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
- }) : x)(function(x) {
11
- if (typeof require !== "undefined")
12
- return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __esm = (fn, res) => function __init() {
16
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
- };
18
- var __commonJS = (cb, mod) => function __require2() {
19
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
- };
21
- var __export = (target, all) => {
22
- for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
24
- };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") {
27
- for (let key of __getOwnPropNames(from))
28
- if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
- }
31
- return to;
32
- };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
- // If the importer is in node compatibility mode or this is not an ESM
35
- // file that has been converted to a CommonJS file using a Babel-
36
- // compatible transform (i.e. "__esModule" has not been set), then set
37
- // "default" to the CommonJS "module.exports" for node compatibility.
38
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
- mod
40
- ));
41
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
-
43
- // ../../scripts/esbuildCjsShims.js
44
- import { createRequire } from "node:module";
45
- import path from "node:path";
46
- import url from "node:url";
47
- var init_esbuildCjsShims = __esm({
48
- "../../scripts/esbuildCjsShims.js"() {
49
- "use strict";
50
- globalThis.require = createRequire(import.meta.url);
51
- globalThis.__filename = url.fileURLToPath(import.meta.url);
52
- globalThis.__dirname = path.dirname(__filename);
53
- }
54
- });
55
-
56
- export {
57
- __name,
58
- __require,
59
- __esm,
60
- __commonJS,
61
- __export,
62
- __toESM,
63
- __toCommonJS,
64
- init_esbuildCjsShims
65
- };