@azure/identity-cache-persistence 1.2.2-alpha.20260227.2 → 1.2.2-alpha.20260304.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.
@@ -1,40 +1,31 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.cachePersistencePlugin = void 0;
6
- const provider_js_1 = require("./provider.js");
7
- /**
8
- * A plugin that provides persistent token caching for `@azure/identity`
9
- * credentials. The plugin API is compatible with `@azure/identity` versions
10
- * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
11
- * function, imported from `@azure/identity`.
12
- *
13
- * In order to enable this functionality, you must also pass
14
- * `tokenCachePersistenceOptions` to your credential constructors with an
15
- * `enabled` property set to true.
16
- *
17
- * Example:
18
- *
19
- * ```ts snippet:ReadmeSampleDeviceCodeCredential
20
- * import { DeviceCodeCredential } from "@azure/identity";
21
- *
22
- * const credential = new DeviceCodeCredential({
23
- * tokenCachePersistenceOptions: {
24
- * enabled: true,
25
- * },
26
- * });
27
- *
28
- * // We'll use the Microsoft Graph scope as an example
29
- * const scope = "https://graph.microsoft.com/.default";
30
- *
31
- * // Print out part of the access token
32
- * console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
33
- * ```
34
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var src_exports = {};
19
+ __export(src_exports, {
20
+ cachePersistencePlugin: () => cachePersistencePlugin
21
+ });
22
+ module.exports = __toCommonJS(src_exports);
23
+ var import_provider = require("./provider.js");
35
24
  const cachePersistencePlugin = (context) => {
36
- const { cachePluginControl } = context;
37
- cachePluginControl.setPersistence(provider_js_1.createPersistenceCachePlugin);
25
+ const { cachePluginControl } = context;
26
+ cachePluginControl.setPersistence(import_provider.createPersistenceCachePlugin);
38
27
  };
39
- exports.cachePersistencePlugin = cachePersistencePlugin;
40
- //# sourceMappingURL=index.js.map
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ cachePersistencePlugin
31
+ });
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,+CAA6D;AAuB7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEI,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAA6B,CAAC;IAE7D,kBAAkB,CAAC,cAAc,CAAC,0CAA4B,CAAC,CAAC;AAClE,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:ReadmeSampleDeviceCodeCredential\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n *\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n *\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:ReadmeSampleDeviceCodeCredential\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n *\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n *\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAA6C;AAoDtC,MAAM,yBAAyC,CAAC,YAAY;AACjE,QAAM,EAAE,mBAAmB,IAAI;AAE/B,qBAAmB,eAAe,4CAA4B;AAChE;",
6
+ "names": []
7
+ }
@@ -1,108 +1,105 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.msalPersistencePlatforms = exports.defaultMsalValues = void 0;
6
- const tslib_1 = require("tslib");
7
- /* eslint-disable tsdoc/syntax */
8
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
9
- const msal_node_extensions_1 = require("@azure/msal-node-extensions");
10
- /**
11
- * Local application data folder
12
- * Expected values:
13
- * - Darwin: '/Users/user/'
14
- * - Windows 8+: 'C:\Users\user\AppData\Local'
15
- * - Linux: '/home/user/.local/share'
16
- */
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 __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var platforms_exports = {};
29
+ __export(platforms_exports, {
30
+ defaultMsalValues: () => defaultMsalValues,
31
+ msalPersistencePlatforms: () => msalPersistencePlatforms
32
+ });
33
+ module.exports = __toCommonJS(platforms_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_msal_node_extensions = require("@azure/msal-node-extensions");
17
36
  const localApplicationDataFolder = process.env.APPDATA?.replace?.(/(.Roaming)*$/, "\\Local") ?? process.env.HOME;
18
- /**
19
- * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
20
- * @internal
21
- */
22
- exports.defaultMsalValues = {
23
- tokenCache: {
24
- name: "msal.cache",
25
- // Expected values:
26
- // - Darwin: '/Users/user/.IdentityService'
27
- // - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
28
- // - Linux: '/home/user/.IdentityService'
29
- directory: node_path_1.default.join(localApplicationDataFolder, ".IdentityService"),
30
- },
31
- keyRing: {
32
- label: "MSALCache",
33
- schema: "msal.cache",
34
- collection: "default",
35
- attributes: {
36
- MsalClientID: "Microsoft.Developer.IdentityService",
37
- "Microsoft.Developer.IdentityService": "1.0.0.0",
38
- },
39
- service: "Microsoft.Developer.IdentityService",
40
- account: "MSALCache",
41
- },
42
- keyChain: {
43
- service: "Microsoft.Developer.IdentityService",
44
- account: "MSALCache",
37
+ const defaultMsalValues = {
38
+ tokenCache: {
39
+ name: "msal.cache",
40
+ // Expected values:
41
+ // - Darwin: '/Users/user/.IdentityService'
42
+ // - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
43
+ // - Linux: '/home/user/.IdentityService'
44
+ directory: import_node_path.default.join(localApplicationDataFolder, ".IdentityService")
45
+ },
46
+ keyRing: {
47
+ label: "MSALCache",
48
+ schema: "msal.cache",
49
+ collection: "default",
50
+ attributes: {
51
+ MsalClientID: "Microsoft.Developer.IdentityService",
52
+ "Microsoft.Developer.IdentityService": "1.0.0.0"
45
53
  },
54
+ service: "Microsoft.Developer.IdentityService",
55
+ account: "MSALCache"
56
+ },
57
+ keyChain: {
58
+ service: "Microsoft.Developer.IdentityService",
59
+ account: "MSALCache"
60
+ }
46
61
  };
47
- /**
48
- * Expected responses:
49
- * - Darwin: '/Users/user/.IdentityService/<name>'
50
- * - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
51
- * - Linux: '/home/user/.IdentityService/<name>'
52
- */
53
62
  function getPersistencePath(name) {
54
- return node_path_1.default.join(exports.defaultMsalValues.tokenCache.directory, name);
63
+ return import_node_path.default.join(defaultMsalValues.tokenCache.directory, name);
55
64
  }
56
- /**
57
- * Set of the platforms we attempt to deliver persistence on.
58
- *
59
- * - On Windows we use DPAPI.
60
- * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
61
- * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
62
- *
63
- * Other platforms _are not supported_ at this time.
64
- *
65
- * @internal
66
- */
67
- exports.msalPersistencePlatforms = {
68
- win32: ({ name = exports.defaultMsalValues.tokenCache.name } = {}) => msal_node_extensions_1.FilePersistenceWithDataProtection.create(getPersistencePath(name), msal_node_extensions_1.DataProtectionScope.CurrentUser),
69
- darwin: async (options = {}) => {
70
- const { name, unsafeAllowUnencryptedStorage } = options;
71
- const { service, account } = exports.defaultMsalValues.keyChain;
72
- const persistencePath = getPersistencePath(name || exports.defaultMsalValues.tokenCache.name);
73
- try {
74
- const persistence = await msal_node_extensions_1.KeychainPersistence.create(persistencePath, service, account);
75
- // If we don't encounter an error when trying to read from the keychain, then we should be good to go.
76
- await persistence.load();
77
- return persistence;
78
- }
79
- catch (e) {
80
- // If we got an error while trying to read from the keyring,
81
- // we will proceed only if the user has specified that unencrypted storage is allowed.
82
- if (!unsafeAllowUnencryptedStorage) {
83
- throw new Error("Unable to read from the macOS Keychain.");
84
- }
85
- return msal_node_extensions_1.FilePersistence.create(persistencePath);
86
- }
87
- },
88
- linux: async (options = {}) => {
89
- const { name, unsafeAllowUnencryptedStorage } = options;
90
- const { service, account } = exports.defaultMsalValues.keyRing;
91
- const persistencePath = getPersistencePath(name || exports.defaultMsalValues.tokenCache.name);
92
- try {
93
- const persistence = await msal_node_extensions_1.LibSecretPersistence.create(persistencePath, service, account);
94
- // If we don't encounter an error when trying to read from the keyring, then we should be good to go.
95
- await persistence.load();
96
- return persistence;
97
- }
98
- catch (e) {
99
- // If we got an error while trying to read from the keyring,
100
- // we will proceed only if the user has specified that unencrypted storage is allowed.
101
- if (!unsafeAllowUnencryptedStorage) {
102
- throw new Error("Unable to read from the system keyring (libsecret).");
103
- }
104
- return msal_node_extensions_1.FilePersistence.create(persistencePath);
105
- }
106
- },
65
+ const msalPersistencePlatforms = {
66
+ win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => import_msal_node_extensions.FilePersistenceWithDataProtection.create(
67
+ getPersistencePath(name),
68
+ import_msal_node_extensions.DataProtectionScope.CurrentUser
69
+ ),
70
+ darwin: async (options = {}) => {
71
+ const { name, unsafeAllowUnencryptedStorage } = options;
72
+ const { service, account } = defaultMsalValues.keyChain;
73
+ const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
74
+ try {
75
+ const persistence = await import_msal_node_extensions.KeychainPersistence.create(persistencePath, service, account);
76
+ await persistence.load();
77
+ return persistence;
78
+ } catch (e) {
79
+ if (!unsafeAllowUnencryptedStorage) {
80
+ throw new Error("Unable to read from the macOS Keychain.");
81
+ }
82
+ return import_msal_node_extensions.FilePersistence.create(persistencePath);
83
+ }
84
+ },
85
+ linux: async (options = {}) => {
86
+ const { name, unsafeAllowUnencryptedStorage } = options;
87
+ const { service, account } = defaultMsalValues.keyRing;
88
+ const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
89
+ try {
90
+ const persistence = await import_msal_node_extensions.LibSecretPersistence.create(persistencePath, service, account);
91
+ await persistence.load();
92
+ return persistence;
93
+ } catch (e) {
94
+ if (!unsafeAllowUnencryptedStorage) {
95
+ throw new Error("Unable to read from the system keyring (libsecret).");
96
+ }
97
+ return import_msal_node_extensions.FilePersistence.create(persistencePath);
98
+ }
99
+ }
107
100
  };
108
- //# sourceMappingURL=platforms.js.map
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ defaultMsalValues,
104
+ msalPersistencePlatforms
105
+ });
@@ -1 +1,7 @@
1
- {"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,iCAAiC;AAEjC,kEAA6B;AAE7B,sEAMqC;AAGrC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAC9B,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,cA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AAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/platforms.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAiB;AAEjB,kCAMO;AAUP,MAAM,6BACJ,QAAQ,IAAI,SAAS,UAAU,gBAAgB,SAAS,KAAK,QAAQ,IAAI;AAMpE,MAAM,oBAAoB;AAAA,EAC/B,YAAY;AAAA,IACV,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAKN,WAAW,iBAAAA,QAAK,KAAK,4BAA4B,kBAAkB;AAAA,EACrE;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,YAAY;AAAA,MACV,cAAc;AAAA,MACd,uCAAuC;AAAA,IACzC;AAAA,IACA,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA,EACA,UAAU;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AACF;AAmBA,SAAS,mBAAmB,MAAsB;AAChD,SAAO,iBAAAA,QAAK,KAAK,kBAAkB,WAAW,WAAW,IAAI;AAC/D;AAaO,MAAM,2BAAqF;AAAA,EAChG,OAAO,CAAC,EAAE,OAAO,kBAAkB,WAAW,KAAK,IAAI,CAAC,MACtD,8DAAkC;AAAA,IAChC,mBAAmB,IAAI;AAAA,IACvB,gDAAoB;AAAA,EACtB;AAAA,EAEF,QAAQ,OAAO,UAAkC,CAAC,MAA4B;AAC5E,UAAM,EAAE,MAAM,8BAA8B,IAAI;AAChD,UAAM,EAAE,SAAS,QAAQ,IAAI,kBAAkB;AAC/C,UAAM,kBAAkB,mBAAmB,QAAQ,kBAAkB,WAAW,IAAI;AAEpF,QAAI;AACF,YAAM,cAAc,MAAM,gDAAoB,OAAO,iBAAiB,SAAS,OAAO;AAEtF,YAAM,YAAY,KAAK;AACvB,aAAO;AAAA,IACT,SAAS,GAAQ;AAGf,UAAI,CAAC,+BAA+B;AAClC,cAAM,IAAI,MAAM,yCAAyC;AAAA,MAC3D;AACA,aAAO,4CAAgB,OAAO,eAAe;AAAA,IAC/C;AAAA,EACF;AAAA,EAEA,OAAO,OAAO,UAAkC,CAAC,MAA4B;AAC3E,UAAM,EAAE,MAAM,8BAA8B,IAAI;AAChD,UAAM,EAAE,SAAS,QAAQ,IAAI,kBAAkB;AAC/C,UAAM,kBAAkB,mBAAmB,QAAQ,kBAAkB,WAAW,IAAI;AAEpF,QAAI;AACF,YAAM,cAAc,MAAM,iDAAqB,OAAO,iBAAiB,SAAS,OAAO;AAEvF,YAAM,YAAY,KAAK;AACvB,aAAO;AAAA,IACT,SAAS,GAAQ;AAGf,UAAI,CAAC,+BAA+B;AAClC,cAAM,IAAI,MAAM,qDAAqD;AAAA,MACvE;AACA,aAAO,4CAAgB,OAAO,eAAe;AAAA,IAC/C;AAAA,EACF;AACF;",
6
+ "names": ["path"]
7
+ }
@@ -1,29 +1,44 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createPersistence = createPersistence;
6
- exports.createPersistenceCachePlugin = createPersistenceCachePlugin;
7
- const platforms_js_1 = require("./platforms.js");
8
- const msal_node_extensions_1 = require("@azure/msal-node-extensions");
9
- /**
10
- * This is used to gain access to the underlying Persistence instance, which we use for testing
11
- *
12
- * @returns a raw persistence instance
13
- * @internal
14
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var provider_exports = {};
19
+ __export(provider_exports, {
20
+ createPersistence: () => createPersistence,
21
+ createPersistenceCachePlugin: () => createPersistenceCachePlugin
22
+ });
23
+ module.exports = __toCommonJS(provider_exports);
24
+ var import_platforms = require("./platforms.js");
25
+ var import_msal_node_extensions = require("@azure/msal-node-extensions");
15
26
  async function createPersistence(options) {
16
- const persistence = await platforms_js_1.msalPersistencePlatforms[process.platform]?.(options);
17
- if (persistence === undefined) {
18
- throw new Error("no persistence providers are available on this platform");
19
- }
20
- return persistence;
27
+ const persistence = await import_platforms.msalPersistencePlatforms[process.platform]?.(options);
28
+ if (persistence === void 0) {
29
+ throw new Error("no persistence providers are available on this platform");
30
+ }
31
+ return persistence;
21
32
  }
22
33
  async function createPersistenceCachePlugin(options) {
23
- const persistence = await createPersistence(options ?? {});
24
- return new msal_node_extensions_1.PersistenceCachePlugin(persistence, {
25
- retryNumber: 100,
26
- retryDelay: 50,
27
- });
34
+ const persistence = await createPersistence(options ?? {});
35
+ return new import_msal_node_extensions.PersistenceCachePlugin(persistence, {
36
+ retryNumber: 100,
37
+ retryDelay: 50
38
+ });
28
39
  }
29
- //# sourceMappingURL=provider.js.map
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ createPersistence,
43
+ createPersistenceCachePlugin
44
+ });
@@ -1 +1,7 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAclC,8CAQC;AAED,oEASC;AA9BD,iDAA0D;AAE1D,sEAAqE;AAGrE;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CAAC,OAA+B;IACrE,MAAM,WAAW,GAAG,MAAM,uCAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEhF,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAEM,KAAK,UAAU,4BAA4B,CAChD,OAAgC;IAEhC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE3D,OAAO,IAAI,6CAAsB,CAAC,WAAW,EAAE;QAC7C,WAAW,EAAE,GAAG;QAChB,UAAU,EAAE,EAAE;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/provider.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAyC;AAEzC,kCAAuC;AASvC,eAAsB,kBAAkB,SAAuD;AAC7F,QAAM,cAAc,MAAM,0CAAyB,QAAQ,QAAQ,IAAI,OAAO;AAE9E,MAAI,gBAAgB,QAAW;AAC7B,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AAEA,SAAO;AACT;AAEA,eAAsB,6BACpB,SACsB;AACtB,QAAM,cAAc,MAAM,kBAAkB,WAAW,CAAC,CAAC;AAEzD,SAAO,IAAI,mDAAuB,aAAa;AAAA,IAC7C,aAAa;AAAA,IACb,YAAY;AAAA,EACd,CAAC;AACH;",
6
+ "names": []
7
+ }
package/dist/esm/index.js CHANGED
@@ -1,36 +1,8 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
1
  import { createPersistenceCachePlugin } from "./provider.js";
4
- /**
5
- * A plugin that provides persistent token caching for `@azure/identity`
6
- * credentials. The plugin API is compatible with `@azure/identity` versions
7
- * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`
8
- * function, imported from `@azure/identity`.
9
- *
10
- * In order to enable this functionality, you must also pass
11
- * `tokenCachePersistenceOptions` to your credential constructors with an
12
- * `enabled` property set to true.
13
- *
14
- * Example:
15
- *
16
- * ```ts snippet:ReadmeSampleDeviceCodeCredential
17
- * import { DeviceCodeCredential } from "@azure/identity";
18
- *
19
- * const credential = new DeviceCodeCredential({
20
- * tokenCachePersistenceOptions: {
21
- * enabled: true,
22
- * },
23
- * });
24
- *
25
- * // We'll use the Microsoft Graph scope as an example
26
- * const scope = "https://graph.microsoft.com/.default";
27
- *
28
- * // Print out part of the access token
29
- * console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
30
- * ```
31
- */
32
- export const cachePersistencePlugin = (context) => {
33
- const { cachePluginControl } = context;
34
- cachePluginControl.setPersistence(createPersistenceCachePlugin);
2
+ const cachePersistencePlugin = (context) => {
3
+ const { cachePluginControl } = context;
4
+ cachePluginControl.setPersistence(createPersistenceCachePlugin);
5
+ };
6
+ export {
7
+ cachePersistencePlugin
35
8
  };
36
- //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAuB7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAmB,CAAC,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAA6B,CAAC;IAE7D,kBAAkB,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:ReadmeSampleDeviceCodeCredential\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n *\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n *\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IdentityPlugin, TokenCachePersistenceOptions } from \"@azure/identity\";\nimport { createPersistenceCachePlugin } from \"./provider.js\";\n\n/**\n * Plugin context entries for controlling cache plugins.\n */\ninterface CachePluginControl {\n setPersistence(\n persistenceFactory: (\n options?: TokenCachePersistenceOptions,\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n ) => Promise<import(\"@azure/msal-node\").ICachePlugin>,\n ): void;\n}\n/**\n * Context options passed to a plugin during initialization.\n *\n * Represents a subset of the context defined in `@azure/identity`\n *\n */\ninterface AzurePluginContext {\n cachePluginControl: CachePluginControl;\n}\n\n/**\n * A plugin that provides persistent token caching for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 2.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * In order to enable this functionality, you must also pass\n * `tokenCachePersistenceOptions` to your credential constructors with an\n * `enabled` property set to true.\n *\n * Example:\n *\n * ```ts snippet:ReadmeSampleDeviceCodeCredential\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n *\n * // We'll use the Microsoft Graph scope as an example\n * const scope = \"https://graph.microsoft.com/.default\";\n *\n * // Print out part of the access token\n * console.log((await credential.getToken(scope)).token.substring(0, 10), \"...\");\n * ```\n */\n\nexport const cachePersistencePlugin: IdentityPlugin = (context) => {\n const { cachePluginControl } = context as AzurePluginContext;\n\n cachePluginControl.setPersistence(createPersistenceCachePlugin);\n};\n"],
5
+ "mappings": "AAIA,SAAS,oCAAoC;AAoDtC,MAAM,yBAAyC,CAAC,YAAY;AACjE,QAAM,EAAE,mBAAmB,IAAI;AAE/B,qBAAmB,eAAe,4BAA4B;AAChE;",
6
+ "names": []
7
+ }
@@ -1,104 +1,77 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /* eslint-disable tsdoc/syntax */
4
1
  import path from "node:path";
5
- import { DataProtectionScope, FilePersistence, FilePersistenceWithDataProtection, KeychainPersistence, LibSecretPersistence, } from "@azure/msal-node-extensions";
6
- /**
7
- * Local application data folder
8
- * Expected values:
9
- * - Darwin: '/Users/user/'
10
- * - Windows 8+: 'C:\Users\user\AppData\Local'
11
- * - Linux: '/home/user/.local/share'
12
- */
2
+ import {
3
+ DataProtectionScope,
4
+ FilePersistence,
5
+ FilePersistenceWithDataProtection,
6
+ KeychainPersistence,
7
+ LibSecretPersistence
8
+ } from "@azure/msal-node-extensions";
13
9
  const localApplicationDataFolder = process.env.APPDATA?.replace?.(/(.Roaming)*$/, "\\Local") ?? process.env.HOME;
14
- /**
15
- * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.
16
- * @internal
17
- */
18
- export const defaultMsalValues = {
19
- tokenCache: {
20
- name: "msal.cache",
21
- // Expected values:
22
- // - Darwin: '/Users/user/.IdentityService'
23
- // - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
24
- // - Linux: '/home/user/.IdentityService'
25
- directory: path.join(localApplicationDataFolder, ".IdentityService"),
26
- },
27
- keyRing: {
28
- label: "MSALCache",
29
- schema: "msal.cache",
30
- collection: "default",
31
- attributes: {
32
- MsalClientID: "Microsoft.Developer.IdentityService",
33
- "Microsoft.Developer.IdentityService": "1.0.0.0",
34
- },
35
- service: "Microsoft.Developer.IdentityService",
36
- account: "MSALCache",
37
- },
38
- keyChain: {
39
- service: "Microsoft.Developer.IdentityService",
40
- account: "MSALCache",
10
+ const defaultMsalValues = {
11
+ tokenCache: {
12
+ name: "msal.cache",
13
+ // Expected values:
14
+ // - Darwin: '/Users/user/.IdentityService'
15
+ // - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
16
+ // - Linux: '/home/user/.IdentityService'
17
+ directory: path.join(localApplicationDataFolder, ".IdentityService")
18
+ },
19
+ keyRing: {
20
+ label: "MSALCache",
21
+ schema: "msal.cache",
22
+ collection: "default",
23
+ attributes: {
24
+ MsalClientID: "Microsoft.Developer.IdentityService",
25
+ "Microsoft.Developer.IdentityService": "1.0.0.0"
41
26
  },
27
+ service: "Microsoft.Developer.IdentityService",
28
+ account: "MSALCache"
29
+ },
30
+ keyChain: {
31
+ service: "Microsoft.Developer.IdentityService",
32
+ account: "MSALCache"
33
+ }
42
34
  };
43
- /**
44
- * Expected responses:
45
- * - Darwin: '/Users/user/.IdentityService/<name>'
46
- * - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService\<name>'
47
- * - Linux: '/home/user/.IdentityService/<name>'
48
- */
49
35
  function getPersistencePath(name) {
50
- return path.join(defaultMsalValues.tokenCache.directory, name);
36
+ return path.join(defaultMsalValues.tokenCache.directory, name);
51
37
  }
52
- /**
53
- * Set of the platforms we attempt to deliver persistence on.
54
- *
55
- * - On Windows we use DPAPI.
56
- * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
57
- * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.
58
- *
59
- * Other platforms _are not supported_ at this time.
60
- *
61
- * @internal
62
- */
63
- export const msalPersistencePlatforms = {
64
- win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => FilePersistenceWithDataProtection.create(getPersistencePath(name), DataProtectionScope.CurrentUser),
65
- darwin: async (options = {}) => {
66
- const { name, unsafeAllowUnencryptedStorage } = options;
67
- const { service, account } = defaultMsalValues.keyChain;
68
- const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
69
- try {
70
- const persistence = await KeychainPersistence.create(persistencePath, service, account);
71
- // If we don't encounter an error when trying to read from the keychain, then we should be good to go.
72
- await persistence.load();
73
- return persistence;
74
- }
75
- catch (e) {
76
- // If we got an error while trying to read from the keyring,
77
- // we will proceed only if the user has specified that unencrypted storage is allowed.
78
- if (!unsafeAllowUnencryptedStorage) {
79
- throw new Error("Unable to read from the macOS Keychain.");
80
- }
81
- return FilePersistence.create(persistencePath);
82
- }
83
- },
84
- linux: async (options = {}) => {
85
- const { name, unsafeAllowUnencryptedStorage } = options;
86
- const { service, account } = defaultMsalValues.keyRing;
87
- const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
88
- try {
89
- const persistence = await LibSecretPersistence.create(persistencePath, service, account);
90
- // If we don't encounter an error when trying to read from the keyring, then we should be good to go.
91
- await persistence.load();
92
- return persistence;
93
- }
94
- catch (e) {
95
- // If we got an error while trying to read from the keyring,
96
- // we will proceed only if the user has specified that unencrypted storage is allowed.
97
- if (!unsafeAllowUnencryptedStorage) {
98
- throw new Error("Unable to read from the system keyring (libsecret).");
99
- }
100
- return FilePersistence.create(persistencePath);
101
- }
102
- },
38
+ const msalPersistencePlatforms = {
39
+ win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => FilePersistenceWithDataProtection.create(
40
+ getPersistencePath(name),
41
+ DataProtectionScope.CurrentUser
42
+ ),
43
+ darwin: async (options = {}) => {
44
+ const { name, unsafeAllowUnencryptedStorage } = options;
45
+ const { service, account } = defaultMsalValues.keyChain;
46
+ const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
47
+ try {
48
+ const persistence = await KeychainPersistence.create(persistencePath, service, account);
49
+ await persistence.load();
50
+ return persistence;
51
+ } catch (e) {
52
+ if (!unsafeAllowUnencryptedStorage) {
53
+ throw new Error("Unable to read from the macOS Keychain.");
54
+ }
55
+ return FilePersistence.create(persistencePath);
56
+ }
57
+ },
58
+ linux: async (options = {}) => {
59
+ const { name, unsafeAllowUnencryptedStorage } = options;
60
+ const { service, account } = defaultMsalValues.keyRing;
61
+ const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
62
+ try {
63
+ const persistence = await LibSecretPersistence.create(persistencePath, service, account);
64
+ await persistence.load();
65
+ return persistence;
66
+ } catch (e) {
67
+ if (!unsafeAllowUnencryptedStorage) {
68
+ throw new Error("Unable to read from the system keyring (libsecret).");
69
+ }
70
+ return FilePersistence.create(persistencePath);
71
+ }
72
+ }
73
+ };
74
+ export {
75
+ defaultMsalValues,
76
+ msalPersistencePlatforms
103
77
  };
104
- //# sourceMappingURL=platforms.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"platforms.js","sourceRoot":"","sources":["../../src/platforms.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,iCAAiC;AAEjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAC9B,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAK,CAAC;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,mBAAmB;QACnB,2CAA2C;QAC3C,+DAA+D;QAC/D,yCAAyC;QACzC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,kBAAkB,CAAC;KACrE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,YAAY;QACpB,UAAU,EAAE,SAAS;QACrB,UAAU,EAAE;YACV,YAAY,EAAE,qCAAqC;YACnD,qCAAqC,EAAE,SAAS;SACjD;QACD,OAAO,EAAE,qCAAqC;QAC9C,OAAO,EAAE,WAAW;KACrB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,qCAAqC;QAC9C,OAAO,EAAE,WAAW;KACrB;CACF,CAAC;AAaF;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,IAAI,CAAC,i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iBAAiB,CAAC,OAAO,CAAC;QACvD,MAAM,eAAe,GAAG,kBAAkB,CAAC,IAAI,IAAI,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtF,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACzF,qGAAqG;YACrG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,4DAA4D;YAC5D,sFAAsF;YACtF,IAAI,CAAC,6BAA6B,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACzE,CAAC;YACD,OAAO,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/platforms.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable tsdoc/syntax */\n\nimport path from \"node:path\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport {\n DataProtectionScope,\n FilePersistence,\n FilePersistenceWithDataProtection,\n KeychainPersistence,\n LibSecretPersistence,\n} from \"@azure/msal-node-extensions\";\nimport type { TokenCachePersistenceOptions } from \"@azure/identity\";\n\n/**\n * Local application data folder\n * Expected values:\n * - Darwin: '/Users/user/'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local'\n * - Linux: '/home/user/.local/share'\n */\nconst localApplicationDataFolder =\n process.env.APPDATA?.replace?.(/(.Roaming)*$/, \"\\\\Local\") ?? process.env.HOME!;\n\n/**\n * Dictionary of values that we use as default as we discover, pick and enable the persistence layer.\n * @internal\n */\nexport const defaultMsalValues = {\n tokenCache: {\n name: \"msal.cache\",\n // Expected values:\n // - Darwin: '/Users/user/.IdentityService'\n // - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService'\n // - Linux: '/home/user/.IdentityService'\n directory: path.join(localApplicationDataFolder, \".IdentityService\"),\n },\n keyRing: {\n label: \"MSALCache\",\n schema: \"msal.cache\",\n collection: \"default\",\n attributes: {\n MsalClientID: \"Microsoft.Developer.IdentityService\",\n \"Microsoft.Developer.IdentityService\": \"1.0.0.0\",\n },\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n keyChain: {\n service: \"Microsoft.Developer.IdentityService\",\n account: \"MSALCache\",\n },\n};\n\n/**\n * Options that are used by the underlying MSAL cache provider.\n * @internal\n */\nexport type MsalPersistenceOptions = Omit<TokenCachePersistenceOptions, \"enabled\">;\n\n/**\n * A function that returns a persistent token cache instance.\n */\ntype MsalPersistenceFactory = (options?: MsalPersistenceOptions) => Promise<Persistence>;\n\n/**\n * Expected responses:\n * - Darwin: '/Users/user/.IdentityService/<name>'\n * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'\n * - Linux: '/home/user/.IdentityService/<name>'\n */\nfunction getPersistencePath(name: string): string {\n return path.join(defaultMsalValues.tokenCache.directory, name);\n}\n\n/**\n * Set of the platforms we attempt to deliver persistence on.\n *\n * - On Windows we use DPAPI.\n * - On OSX (Darwin), we try to use the system's Keychain, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n * - On Linux, we try to use the system's Keyring, otherwise if the property `unsafeAllowUnencryptedStorage` is set to true, we use an unencrypted file.\n *\n * Other platforms _are not supported_ at this time.\n *\n * @internal\n */\nexport const msalPersistencePlatforms: Partial<Record<NodeJS.Platform, MsalPersistenceFactory>> = {\n win32: ({ name = defaultMsalValues.tokenCache.name } = {}): Promise<Persistence> =>\n FilePersistenceWithDataProtection.create(\n getPersistencePath(name),\n DataProtectionScope.CurrentUser,\n ),\n\n darwin: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyChain;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await KeychainPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keychain, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the macOS Keychain.\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n\n linux: async (options: MsalPersistenceOptions = {}): Promise<Persistence> => {\n const { name, unsafeAllowUnencryptedStorage } = options;\n const { service, account } = defaultMsalValues.keyRing;\n const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);\n\n try {\n const persistence = await LibSecretPersistence.create(persistencePath, service, account);\n // If we don't encounter an error when trying to read from the keyring, then we should be good to go.\n await persistence.load();\n return persistence;\n } catch (e: any) {\n // If we got an error while trying to read from the keyring,\n // we will proceed only if the user has specified that unencrypted storage is allowed.\n if (!unsafeAllowUnencryptedStorage) {\n throw new Error(\"Unable to read from the system keyring (libsecret).\");\n }\n return FilePersistence.create(persistencePath);\n }\n },\n};\n"],
5
+ "mappings": "AAKA,OAAO,UAAU;AAEjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP,MAAM,6BACJ,QAAQ,IAAI,SAAS,UAAU,gBAAgB,SAAS,KAAK,QAAQ,IAAI;AAMpE,MAAM,oBAAoB;AAAA,EAC/B,YAAY;AAAA,IACV,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAKN,WAAW,KAAK,KAAK,4B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vF,YAAM,YAAY,KAAK;AACvB,aAAO;AAAA,IACT,SAAS,GAAQ;AAGf,UAAI,CAAC,+BAA+B;AAClC,cAAM,IAAI,MAAM,qDAAqD;AAAA,MACvE;AACA,aAAO,gBAAgB,OAAO,eAAe;AAAA,IAC/C;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -1,25 +1,20 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
1
  import { msalPersistencePlatforms } from "./platforms.js";
4
2
  import { PersistenceCachePlugin } from "@azure/msal-node-extensions";
5
- /**
6
- * This is used to gain access to the underlying Persistence instance, which we use for testing
7
- *
8
- * @returns a raw persistence instance
9
- * @internal
10
- */
11
- export async function createPersistence(options) {
12
- const persistence = await msalPersistencePlatforms[process.platform]?.(options);
13
- if (persistence === undefined) {
14
- throw new Error("no persistence providers are available on this platform");
15
- }
16
- return persistence;
3
+ async function createPersistence(options) {
4
+ const persistence = await msalPersistencePlatforms[process.platform]?.(options);
5
+ if (persistence === void 0) {
6
+ throw new Error("no persistence providers are available on this platform");
7
+ }
8
+ return persistence;
17
9
  }
18
- export async function createPersistenceCachePlugin(options) {
19
- const persistence = await createPersistence(options ?? {});
20
- return new PersistenceCachePlugin(persistence, {
21
- retryNumber: 100,
22
- retryDelay: 50,
23
- });
10
+ async function createPersistenceCachePlugin(options) {
11
+ const persistence = await createPersistence(options ?? {});
12
+ return new PersistenceCachePlugin(persistence, {
13
+ retryNumber: 100,
14
+ retryDelay: 50
15
+ });
24
16
  }
25
- //# sourceMappingURL=provider.js.map
17
+ export {
18
+ createPersistence,
19
+ createPersistenceCachePlugin
20
+ };
@@ -1 +1,7 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA+B;IACrE,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEhF,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,OAAgC;IAEhC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE3D,OAAO,IAAI,sBAAsB,CAAC,WAAW,EAAE;QAC7C,WAAW,EAAE,GAAG;QAChB,UAAU,EAAE,EAAE;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/identity/identity-cache-persistence/src/provider.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MsalPersistenceOptions } from \"./platforms.js\";\nimport { msalPersistencePlatforms } from \"./platforms.js\";\nimport type { IPersistence as Persistence } from \"@azure/msal-node-extensions\";\nimport { PersistenceCachePlugin } from \"@azure/msal-node-extensions\";\nimport type { ICachePlugin as CachePlugin } from \"@azure/msal-node\";\n\n/**\n * This is used to gain access to the underlying Persistence instance, which we use for testing\n *\n * @returns a raw persistence instance\n * @internal\n */\nexport async function createPersistence(options: MsalPersistenceOptions): Promise<Persistence> {\n const persistence = await msalPersistencePlatforms[process.platform]?.(options);\n\n if (persistence === undefined) {\n throw new Error(\"no persistence providers are available on this platform\");\n }\n\n return persistence;\n}\n\nexport async function createPersistenceCachePlugin(\n options?: MsalPersistenceOptions,\n): Promise<CachePlugin> {\n const persistence = await createPersistence(options ?? {});\n\n return new PersistenceCachePlugin(persistence, {\n retryNumber: 100,\n retryDelay: 50,\n });\n}\n"],
5
+ "mappings": "AAIA,SAAS,gCAAgC;AAEzC,SAAS,8BAA8B;AASvC,eAAsB,kBAAkB,SAAuD;AAC7F,QAAM,cAAc,MAAM,yBAAyB,QAAQ,QAAQ,IAAI,OAAO;AAE9E,MAAI,gBAAgB,QAAW;AAC7B,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AAEA,SAAO;AACT;AAEA,eAAsB,6BACpB,SACsB;AACtB,QAAM,cAAc,MAAM,kBAAkB,WAAW,CAAC,CAAC;AAEzD,SAAO,IAAI,uBAAuB,aAAa;AAAA,IAC7C,aAAa;AAAA,IACb,YAAY;AAAA,EACd,CAAC;AACH;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/identity-cache-persistence",
3
- "version": "1.2.2-alpha.20260227.2",
3
+ "version": "1.2.2-alpha.20260304.2",
4
4
  "sdk-type": "client",
5
5
  "description": "A secure, persistent token cache for Azure Identity credentials that uses the OS secret-management API",
6
6
  "main": "./dist/commonjs/index.js",
@@ -52,7 +52,6 @@
52
52
  "playwright": "^1.56.1",
53
53
  "prettier": "^3.6.2",
54
54
  "rimraf": "^6.1.0",
55
- "tshy": "^3.0.3",
56
55
  "typescript": "~5.9.3",
57
56
  "vitest": "^4.0.8",
58
57
  "@azure-tools/test-recorder": "^4.1.1",
@@ -61,22 +60,6 @@
61
60
  "@azure/eslint-plugin-azure-sdk": "^3.0.0"
62
61
  },
63
62
  "type": "module",
64
- "tshy": {
65
- "project": "../../../tsconfig.src.build.json",
66
- "exports": {
67
- "./package.json": "./package.json",
68
- ".": "./src/index.ts"
69
- },
70
- "dialects": [
71
- "esm",
72
- "commonjs"
73
- ],
74
- "esmDialects": [
75
- "browser",
76
- "react-native"
77
- ],
78
- "selfLink": false
79
- },
80
63
  "browser": "./dist/browser/index.js",
81
64
  "exports": {
82
65
  "./package.json": "./package.json",