@ms-cloudpack/remote-cache 0.7.0 → 0.7.2

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.
@@ -19849,15 +19849,15 @@ var require_dist9 = __commonJS({
19849
19849
  let isAbsolutePath = false;
19850
19850
  let requestUrl = replaceAll(baseUri, urlReplacements);
19851
19851
  if (operationSpec.path) {
19852
- let path2 = replaceAll(operationSpec.path, urlReplacements);
19853
- if (operationSpec.path === "/{nextLink}" && path2.startsWith("/")) {
19854
- path2 = path2.substring(1);
19852
+ let path3 = replaceAll(operationSpec.path, urlReplacements);
19853
+ if (operationSpec.path === "/{nextLink}" && path3.startsWith("/")) {
19854
+ path3 = path3.substring(1);
19855
19855
  }
19856
- if (isAbsoluteUrl(path2)) {
19857
- requestUrl = path2;
19856
+ if (isAbsoluteUrl(path3)) {
19857
+ requestUrl = path3;
19858
19858
  isAbsolutePath = true;
19859
19859
  } else {
19860
- requestUrl = appendPath(requestUrl, path2);
19860
+ requestUrl = appendPath(requestUrl, path3);
19861
19861
  }
19862
19862
  }
19863
19863
  const { queryParams, sequenceParams } = calculateQueryParameters(operationSpec, operationArguments, fallbackObject);
@@ -19908,9 +19908,9 @@ var require_dist9 = __commonJS({
19908
19908
  }
19909
19909
  const searchStart = pathToAppend.indexOf("?");
19910
19910
  if (searchStart !== -1) {
19911
- const path2 = pathToAppend.substring(0, searchStart);
19911
+ const path3 = pathToAppend.substring(0, searchStart);
19912
19912
  const search = pathToAppend.substring(searchStart + 1);
19913
- newPath = newPath + path2;
19913
+ newPath = newPath + path3;
19914
19914
  if (search) {
19915
19915
  parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;
19916
19916
  }
@@ -20379,13 +20379,13 @@ var require_package19 = __commonJS({
20379
20379
  var require_package20 = __commonJS({
20380
20380
  "../../node_modules/.store/open-npm-8.4.2-1f763e8b75/package/index.js"(exports, module) {
20381
20381
  init_esbuildCjsShims();
20382
- var path2 = __require("path");
20382
+ var path3 = __require("path");
20383
20383
  var childProcess = __require("child_process");
20384
20384
  var { promises: fs, constants: fsConstants } = __require("fs");
20385
20385
  var isWsl = require_package18();
20386
20386
  var isDocker = require_package17();
20387
20387
  var defineLazyProperty = require_package19();
20388
- var localXdgOpenPath = path2.join(__dirname, "xdg-open");
20388
+ var localXdgOpenPath = path3.join(__dirname, "xdg-open");
20389
20389
  var { platform, arch } = process;
20390
20390
  var hasContainerEnv = /* @__PURE__ */ __name(() => {
20391
20391
  try {
@@ -20649,7 +20649,7 @@ var require_dist10 = __commonJS({
20649
20649
  var coreTracing = require_dist7();
20650
20650
  var fs = __require("fs");
20651
20651
  var os = __require("os");
20652
- var path2 = __require("path");
20652
+ var path3 = __require("path");
20653
20653
  var promises = __require("fs/promises");
20654
20654
  var https2 = __require("https");
20655
20655
  var child_process = __require("child_process");
@@ -21672,7 +21672,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
21672
21672
  const vsCodeFolder = "Code";
21673
21673
  const homedir = os.homedir();
21674
21674
  function loadProperty(...pathSegments) {
21675
- const fullPath = path2.join(...pathSegments, vsCodeFolder, ...settingsPath);
21675
+ const fullPath = path3.join(...pathSegments, vsCodeFolder, ...settingsPath);
21676
21676
  const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: "utf8" }));
21677
21677
  return settings[property];
21678
21678
  }
@@ -22070,8 +22070,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
22070
22070
  });
22071
22071
  }
22072
22072
  __name(prepareRequestOptions$2, "prepareRequestOptions$2");
22073
- function readFileAsync$1(path3, options) {
22074
- return new Promise((resolve, reject) => fs.readFile(path3, options, (err, data) => {
22073
+ function readFileAsync$1(path4, options) {
22074
+ return new Promise((resolve, reject) => fs.readFile(path4, options, (err, data) => {
22075
22075
  if (err) {
22076
22076
  reject(err);
22077
22077
  }
@@ -24057,7 +24057,7 @@ var require_dist11 = __commonJS({
24057
24057
  init_esbuildCjsShims();
24058
24058
  Object.defineProperty(exports, "__esModule", { value: true });
24059
24059
  var tslib = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
24060
- var path2 = __require("path");
24060
+ var path3 = __require("path");
24061
24061
  var msalNodeExtensions = __require("@azure/msal-node-extensions");
24062
24062
  function _interopNamespaceDefault(e) {
24063
24063
  var n = /* @__PURE__ */ Object.create(null);
@@ -24078,7 +24078,7 @@ var require_dist11 = __commonJS({
24078
24078
  return Object.freeze(n);
24079
24079
  }
24080
24080
  __name(_interopNamespaceDefault, "_interopNamespaceDefault");
24081
- var path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path2);
24081
+ var path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path3);
24082
24082
  var _a;
24083
24083
  var _b;
24084
24084
  var _c;
@@ -24216,11 +24216,115 @@ function saveAuthenticationRecord(cachePath, authRecord) {
24216
24216
  }
24217
24217
  __name(saveAuthenticationRecord, "saveAuthenticationRecord");
24218
24218
 
24219
- // src/authentication/getCredential.ts
24219
+ // src/authentication/tokenCachePersistenceOptions.ts
24220
+ init_esbuildCjsShims();
24220
24221
  var tokenCachePersistenceOptions = {
24221
24222
  enabled: true,
24222
24223
  name: "cloudpack"
24223
24224
  };
24225
+
24226
+ // src/authentication/lock-file/tryCleaningLockFile.ts
24227
+ init_esbuildCjsShims();
24228
+
24229
+ // src/utils/isProcessRunning.ts
24230
+ init_esbuildCjsShims();
24231
+ function isProcessRunning(pid) {
24232
+ try {
24233
+ process.kill(pid, 0);
24234
+ return true;
24235
+ } catch (error) {
24236
+ if (error instanceof Error && "code" in error && error.code === "EPERM") {
24237
+ console.log(
24238
+ `Permission issue indicates that process ${pid} exists but user doesn't have permission to signal it.`
24239
+ );
24240
+ return true;
24241
+ } else if (error instanceof Error && "code" in error && error.code === "ESRCH") {
24242
+ console.log(`Process ${pid} does not exist.`);
24243
+ return false;
24244
+ } else {
24245
+ throw error;
24246
+ }
24247
+ }
24248
+ }
24249
+ __name(isProcessRunning, "isProcessRunning");
24250
+
24251
+ // src/authentication/lock-file/deleteAuthenticationLockFile.ts
24252
+ init_esbuildCjsShims();
24253
+ import { unlinkSync } from "fs";
24254
+
24255
+ // src/authentication/lock-file/getAuthenticationLockFilePath.ts
24256
+ init_esbuildCjsShims();
24257
+ import path2 from "path";
24258
+ function getAuthenticationLockFilePath() {
24259
+ var _a, _b;
24260
+ const localApplicationDataFolder = ((_b = (_a = process.env.APPDATA) == null ? void 0 : _a.replace) == null ? void 0 : _b.call(_a, /(.Roaming)*$/, "\\Local")) ?? (process.env.HOME || "");
24261
+ return path2.join(localApplicationDataFolder, ".IdentityService", tokenCachePersistenceOptions.name + ".lockfile");
24262
+ }
24263
+ __name(getAuthenticationLockFilePath, "getAuthenticationLockFilePath");
24264
+
24265
+ // src/authentication/lock-file/deleteAuthenticationLockFile.ts
24266
+ function deleteAuthenticationLockFile() {
24267
+ const lockFilePath = getAuthenticationLockFilePath();
24268
+ try {
24269
+ unlinkSync(lockFilePath);
24270
+ return true;
24271
+ } catch (error) {
24272
+ const errorCode = error instanceof Error && "code" in error ? error.code : void 0;
24273
+ switch (errorCode) {
24274
+ case "ENOENT":
24275
+ console.error(`Error: File ${lockFilePath} not found.`);
24276
+ break;
24277
+ case "EACCES":
24278
+ case "EPERM":
24279
+ console.error(`Error: Permission denied to delete ${lockFilePath}.`);
24280
+ break;
24281
+ case "EBUSY":
24282
+ console.error(`Error: ${lockFilePath} is currently in use and cannot be deleted.`);
24283
+ break;
24284
+ default:
24285
+ console.error(`Error deleting file ${lockFilePath}`, error);
24286
+ }
24287
+ }
24288
+ return false;
24289
+ }
24290
+ __name(deleteAuthenticationLockFile, "deleteAuthenticationLockFile");
24291
+
24292
+ // src/authentication/lock-file/doesLockFileExist.ts
24293
+ init_esbuildCjsShims();
24294
+ import { existsSync as existsSync3 } from "fs";
24295
+ function doesLockFileExist() {
24296
+ const lockFilePath = getAuthenticationLockFilePath();
24297
+ return existsSync3(lockFilePath);
24298
+ }
24299
+ __name(doesLockFileExist, "doesLockFileExist");
24300
+
24301
+ // src/authentication/lock-file/readAuthenticationLockFile.ts
24302
+ init_esbuildCjsShims();
24303
+ import { readFileSync as readFileSync2 } from "fs";
24304
+ function readAuthenticationLockFile() {
24305
+ const lockFilePath = getAuthenticationLockFilePath();
24306
+ const fileContent = readFileSync2(lockFilePath, "utf8");
24307
+ return parseInt(fileContent);
24308
+ }
24309
+ __name(readAuthenticationLockFile, "readAuthenticationLockFile");
24310
+
24311
+ // src/authentication/lock-file/tryCleaningLockFile.ts
24312
+ function tryCleaningLockFile() {
24313
+ if (!doesLockFileExist()) {
24314
+ return true;
24315
+ }
24316
+ const pid = readAuthenticationLockFile();
24317
+ console.log(`Process ID in the lock file: ${pid}`);
24318
+ if (!isProcessRunning(pid) && deleteAuthenticationLockFile()) {
24319
+ console.log("Auth lock file is deleted successfully");
24320
+ return true;
24321
+ }
24322
+ console.log("Auth lock file is not deleted.");
24323
+ return false;
24324
+ }
24325
+ __name(tryCleaningLockFile, "tryCleaningLockFile");
24326
+
24327
+ // src/authentication/getCredential.ts
24224
24328
  function getCredentialInternal(loginMethod, authenticationRecord, tenantId) {
24225
24329
  switch (loginMethod) {
24226
24330
  case "interactive":
@@ -24252,6 +24356,7 @@ async function getCredential(loginMethod, cachePath, tenantId) {
24252
24356
  "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."
24253
24357
  );
24254
24358
  }
24359
+ tryCleaningLockFile();
24255
24360
  const storageScope = "https://storage.azure.com/.default";
24256
24361
  const authenticationRecord = await credential.authenticate(storageScope);
24257
24362
  const token = await credential.getToken(storageScope);
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ import { RetryManager } from "@ms-cloudpack/retry";
81
81
  async function createRemoteCacheClient(params) {
82
82
  const { context, options } = params;
83
83
  const { container, loginMethod, storageAccount, cachePath, tenantId } = options;
84
- const { getCredential } = await import("./getCredential-DHB4UIE2.js");
84
+ const { getCredential } = await import("./getCredential-2R4O36RK.js");
85
85
  const { AzureRemoteCacheClient } = await import("./AzureRemoteCacheClient-NEV2XCF7.js");
86
86
  const { ReporterDecorator } = await import("./ReporterDecorator-SNBYNGOT.js");
87
87
  const { getListOfBlobs } = await import("./getListOfBlobs-E5OFG2MF.js");
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Deletes the authentication lock file.
3
+ * If the file does not exist or is currently in use, cannot be deleted due to permission issues, it logs an error message.
4
+ * @returns - true if the file was successfully deleted, false otherwise.
5
+ */
6
+ export declare function deleteAuthenticationLockFile(): boolean;
7
+ //# sourceMappingURL=deleteAuthenticationLockFile.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if the authentication lock file exists.
3
+ * @returns - true if the authentication lock file exists, false otherwise.
4
+ */
5
+ export declare function doesLockFileExist(): boolean;
6
+ //# sourceMappingURL=doesLockFileExist.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @returns The file path of the authentication lock file.
3
+ * Expected responses:
4
+ * - Darwin: '/Users/user/.IdentityService/cloudpack.lockfile'
5
+ * - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\cloudpack.lockfile'
6
+ * - Linux: '/home/user/.IdentityService/cloudpack.lockfile'
7
+ *
8
+ * The lock file is generated by the @azure/identity and msal-node-extensions packages. Unfortunately, these packages do not provide an API to retrieve the lock file path directly. Therefore, we've implemented a function to obtain their lock file path, albeit without a formal contract.
9
+ */
10
+ export declare function getAuthenticationLockFilePath(): string;
11
+ //# sourceMappingURL=getAuthenticationLockFilePath.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Reads the authentication lock file and parse the content to int.
3
+ * @returns - The process ID stored in the authentication lock file.
4
+ */
5
+ export declare function readAuthenticationLockFile(): number;
6
+ //# sourceMappingURL=readAuthenticationLockFile.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tries to clean the authentication lock file by deleting it if the other process is not running.
3
+ * @returns - true if the lock file is deleted successfully, false otherwise.
4
+ */
5
+ export declare function tryCleaningLockFile(): boolean;
6
+ //# sourceMappingURL=tryCleaningLockFile.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { type TokenCachePersistenceOptions } from '@azure/identity';
2
+ /**
3
+ * The options for token cache persistence.
4
+ * This will be used by the token cache plugin.
5
+ */
6
+ export declare const tokenCachePersistenceOptions: TokenCachePersistenceOptions & {
7
+ name: string;
8
+ };
9
+ //# sourceMappingURL=tokenCachePersistenceOptions.d.ts.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if a process with the given PID is running.
3
+ * @param pid - The process ID to check.
4
+ * @returns - true if the process is running, false otherwise.
5
+ */
6
+ export declare function isProcessRunning(pid: number): boolean;
7
+ //# sourceMappingURL=isProcessRunning.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/remote-cache",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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.13.1",
32
+ "@ms-cloudpack/task-reporter": "^0.14.0",
33
33
  "@ms-cloudpack/telemetry": "^0.5.1"
34
34
  },
35
35
  "devDependencies": {