@azure/msal-node-extensions 1.0.0-alpha.8 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +208 -42
- package/bin/arm64/dpapi.node +0 -0
- package/bin/ia32/dpapi.node +0 -0
- package/bin/x64/dpapi.node +0 -0
- package/dist/{dpapi-addon/Dpapi.d.ts → Dpapi.d.ts} +4 -4
- package/dist/Dpapi.esm.js +24 -0
- package/dist/Dpapi.esm.js.map +1 -0
- package/dist/Dpapi.js +24 -0
- package/dist/Dpapi.js.map +1 -0
- package/dist/broker/NativeBrokerPlugin.d.ts +20 -0
- package/dist/broker/NativeBrokerPlugin.esm.js +408 -0
- package/dist/broker/NativeBrokerPlugin.esm.js.map +1 -0
- package/dist/broker/NativeBrokerPlugin.js +410 -0
- package/dist/broker/NativeBrokerPlugin.js.map +1 -0
- package/dist/error/NativeAuthError.d.ts +6 -0
- package/dist/error/NativeAuthError.esm.js +20 -0
- package/dist/error/NativeAuthError.esm.js.map +1 -0
- package/dist/error/NativeAuthError.js +22 -0
- package/dist/error/NativeAuthError.js.map +1 -0
- package/dist/error/PersistenceError.d.ts +21 -0
- package/{src/error/PersistenceError.ts → dist/error/PersistenceError.esm.js} +88 -70
- package/dist/error/PersistenceError.esm.js.map +1 -0
- package/dist/error/PersistenceError.js +91 -0
- package/dist/error/PersistenceError.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +12 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +24 -6
- package/dist/index.js.map +1 -0
- package/dist/lock/CrossPlatformLock.esm.js +94 -0
- package/dist/lock/CrossPlatformLock.esm.js.map +1 -0
- package/dist/lock/CrossPlatformLock.js +96 -0
- package/dist/lock/CrossPlatformLock.js.map +1 -0
- package/dist/lock/CrossPlatformLockOptions.d.ts +1 -1
- package/dist/packageMetadata.d.ts +2 -0
- package/dist/packageMetadata.esm.js +8 -0
- package/dist/packageMetadata.esm.js.map +1 -0
- package/dist/packageMetadata.js +11 -0
- package/dist/packageMetadata.js.map +1 -0
- package/{src/persistence/BasePersistence.ts → dist/persistence/BasePersistence.esm.js} +35 -40
- package/dist/persistence/BasePersistence.esm.js.map +1 -0
- package/dist/persistence/BasePersistence.js +38 -0
- package/dist/persistence/BasePersistence.js.map +1 -0
- package/dist/persistence/DataProtectionScope.d.ts +5 -4
- package/{src/persistence/DataProtectionScope.ts → dist/persistence/DataProtectionScope.esm.js} +23 -19
- package/dist/persistence/DataProtectionScope.esm.js.map +1 -0
- package/dist/persistence/DataProtectionScope.js +26 -0
- package/dist/persistence/DataProtectionScope.js.map +1 -0
- package/dist/persistence/FilePersistence.d.ts +1 -0
- package/dist/persistence/FilePersistence.esm.js +173 -0
- package/dist/persistence/FilePersistence.esm.js.map +1 -0
- package/dist/persistence/FilePersistence.js +175 -0
- package/dist/persistence/FilePersistence.js.map +1 -0
- package/dist/persistence/FilePersistenceWithDataProtection.esm.js +84 -0
- package/dist/persistence/FilePersistenceWithDataProtection.esm.js.map +1 -0
- package/dist/persistence/FilePersistenceWithDataProtection.js +86 -0
- package/dist/persistence/FilePersistenceWithDataProtection.js.map +1 -0
- package/dist/persistence/IPersistenceConfiguration.d.ts +10 -0
- package/dist/persistence/KeychainPersistence.d.ts +2 -2
- package/dist/persistence/KeychainPersistence.esm.js +90 -0
- package/dist/persistence/KeychainPersistence.esm.js.map +1 -0
- package/dist/persistence/KeychainPersistence.js +92 -0
- package/dist/persistence/KeychainPersistence.js.map +1 -0
- package/dist/persistence/LibSecretPersistence.d.ts +2 -2
- package/dist/persistence/LibSecretPersistence.esm.js +91 -0
- package/dist/persistence/LibSecretPersistence.esm.js.map +1 -0
- package/dist/persistence/LibSecretPersistence.js +93 -0
- package/dist/persistence/LibSecretPersistence.js.map +1 -0
- package/dist/persistence/PersistenceCachePlugin.d.ts +1 -1
- package/{src/persistence/PersistenceCachePlugin.ts → dist/persistence/PersistenceCachePlugin.esm.js} +97 -104
- package/dist/persistence/PersistenceCachePlugin.esm.js.map +1 -0
- package/dist/persistence/PersistenceCachePlugin.js +101 -0
- package/dist/persistence/PersistenceCachePlugin.js.map +1 -0
- package/dist/persistence/PersistenceCreator.d.ts +5 -0
- package/dist/persistence/PersistenceCreator.esm.js +63 -0
- package/dist/persistence/PersistenceCreator.esm.js.map +1 -0
- package/dist/persistence/PersistenceCreator.js +65 -0
- package/dist/persistence/PersistenceCreator.js.map +1 -0
- package/dist/utils/Constants.d.ts +29 -0
- package/dist/utils/Constants.esm.js +62 -0
- package/dist/utils/Constants.esm.js.map +1 -0
- package/dist/utils/Constants.js +66 -0
- package/dist/utils/Constants.js.map +1 -0
- package/dist/utils/Environment.d.ts +16 -0
- package/dist/utils/Environment.esm.js +94 -0
- package/dist/utils/Environment.esm.js.map +1 -0
- package/dist/utils/Environment.js +96 -0
- package/dist/utils/Environment.js.map +1 -0
- package/dist/utils/TypeGuards.d.ts +5 -0
- package/dist/utils/TypeGuards.esm.js +16 -0
- package/dist/utils/TypeGuards.esm.js.map +1 -0
- package/dist/utils/TypeGuards.js +18 -0
- package/dist/utils/TypeGuards.js.map +1 -0
- package/package.json +70 -52
- package/CHANGELOG.json +0 -146
- package/binding.gyp +0 -29
- package/changelog.md +0 -68
- package/dist/msal-node-extensions.cjs.development.js +0 -687
- package/dist/msal-node-extensions.cjs.development.js.map +0 -1
- package/dist/msal-node-extensions.cjs.production.min.js +0 -2
- package/dist/msal-node-extensions.cjs.production.min.js.map +0 -1
- package/dist/msal-node-extensions.esm.js +0 -692
- package/dist/msal-node-extensions.esm.js.map +0 -1
- package/src/dpapi-addon/Dpapi.ts +0 -12
- package/src/dpapi-addon/dpapi_addon.h +0 -6
- package/src/dpapi-addon/dpapi_not_supported.cpp +0 -19
- package/src/dpapi-addon/dpapi_win.cpp +0 -114
- package/src/dpapi-addon/main.cpp +0 -32
- package/src/index.ts +0 -13
- package/src/lock/CrossPlatformLock.ts +0 -89
- package/src/lock/CrossPlatformLockOptions.ts +0 -15
- package/src/persistence/FilePersistence.ts +0 -140
- package/src/persistence/FilePersistenceWithDataProtection.ts +0 -92
- package/src/persistence/IPersistence.ts +0 -17
- package/src/persistence/KeychainPersistence.ts +0 -86
- package/src/persistence/LibSecretPersistence.ts +0 -87
- package/src/utils/Constants.ts +0 -35
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
throw PersistenceError.createCachePersistenceError(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
await persistenceValidator.delete();
|
|
35
|
-
return true;
|
|
36
|
-
} catch (e) {
|
|
37
|
-
throw PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { PersistenceError } from '../error/PersistenceError.esm.js';
|
|
4
|
+
import { Constants } from '../utils/Constants.esm.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
8
|
+
* Licensed under the MIT License.
|
|
9
|
+
*/
|
|
10
|
+
class BasePersistence {
|
|
11
|
+
async verifyPersistence() {
|
|
12
|
+
// We are using a different location for the test to avoid overriding the functional cache
|
|
13
|
+
const persistenceValidator = await this.createForPersistenceValidation();
|
|
14
|
+
try {
|
|
15
|
+
await persistenceValidator.save(Constants.PERSISTENCE_TEST_DATA);
|
|
16
|
+
const retrievedDummyData = await persistenceValidator.load();
|
|
17
|
+
if (!retrievedDummyData) {
|
|
18
|
+
throw PersistenceError.createCachePersistenceError("Persistence check failed. Data was written but it could not be read. " +
|
|
19
|
+
"Possible cause: on Linux, LibSecret is installed but D-Bus isn't running \
|
|
20
|
+
because it cannot be started over SSH.");
|
|
21
|
+
}
|
|
22
|
+
if (retrievedDummyData !== Constants.PERSISTENCE_TEST_DATA) {
|
|
23
|
+
throw PersistenceError.createCachePersistenceError(`Persistence check failed. Data written ${Constants.PERSISTENCE_TEST_DATA} is different \
|
|
24
|
+
from data read ${retrievedDummyData}`);
|
|
25
|
+
}
|
|
26
|
+
await persistenceValidator.delete();
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
41
33
|
}
|
|
34
|
+
|
|
35
|
+
export { BasePersistence };
|
|
36
|
+
//# sourceMappingURL=BasePersistence.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasePersistence.esm.js","sources":["../../src/persistence/BasePersistence.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;MAMmB,eAAe,CAAA;AAG1B,IAAA,MAAM,iBAAiB,GAAA;;AAE1B,QAAA,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC;QAEzE,IAAI;YACA,MAAM,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEjE,YAAA,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,CAAC;YAE7D,IAAI,CAAC,kBAAkB,EAAE;AACrB,gBAAA,MAAM,gBAAgB,CAAC,2BAA2B,CAC9C,uEAAuE;AACvE,oBAAA;AACuC,2DAAA,CAC1C,CAAC;AACL,aAAA;AAED,YAAA,IAAI,kBAAkB,KAAK,SAAS,CAAC,qBAAqB,EAAE;AACxD,gBAAA,MAAM,gBAAgB,CAAC,2BAA2B,CAC9C,CAA0C,uCAAA,EAAA,SAAS,CAAC,qBAAqB,CAAA;qCACxD,kBAAkB,CAAA,CAAE,CACxC,CAAC;AACL,aAAA;AACD,YAAA,MAAM,oBAAoB,CAAC,MAAM,EAAE,CAAC;AACpC,YAAA,OAAO,IAAI,CAAC;AACf,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACR,MAAM,gBAAgB,CAAC,2BAA2B,CAAC,+CAA+C,CAAC,CAAA,CAAE,CAAC,CAAC;AAC1G,SAAA;KACJ;AAEJ;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var PersistenceError = require('../error/PersistenceError.js');
|
|
6
|
+
var Constants = require('../utils/Constants.js');
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
+
* Licensed under the MIT License.
|
|
11
|
+
*/
|
|
12
|
+
class BasePersistence {
|
|
13
|
+
async verifyPersistence() {
|
|
14
|
+
// We are using a different location for the test to avoid overriding the functional cache
|
|
15
|
+
const persistenceValidator = await this.createForPersistenceValidation();
|
|
16
|
+
try {
|
|
17
|
+
await persistenceValidator.save(Constants.Constants.PERSISTENCE_TEST_DATA);
|
|
18
|
+
const retrievedDummyData = await persistenceValidator.load();
|
|
19
|
+
if (!retrievedDummyData) {
|
|
20
|
+
throw PersistenceError.PersistenceError.createCachePersistenceError("Persistence check failed. Data was written but it could not be read. " +
|
|
21
|
+
"Possible cause: on Linux, LibSecret is installed but D-Bus isn't running \
|
|
22
|
+
because it cannot be started over SSH.");
|
|
23
|
+
}
|
|
24
|
+
if (retrievedDummyData !== Constants.Constants.PERSISTENCE_TEST_DATA) {
|
|
25
|
+
throw PersistenceError.PersistenceError.createCachePersistenceError(`Persistence check failed. Data written ${Constants.Constants.PERSISTENCE_TEST_DATA} is different \
|
|
26
|
+
from data read ${retrievedDummyData}`);
|
|
27
|
+
}
|
|
28
|
+
await persistenceValidator.delete();
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw PersistenceError.PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.BasePersistence = BasePersistence;
|
|
38
|
+
//# sourceMappingURL=BasePersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasePersistence.js","sources":["../../src/persistence/BasePersistence.ts"],"sourcesContent":[null],"names":["Constants","PersistenceError"],"mappings":";;;;;;;AAAA;;;AAGG;MAMmB,eAAe,CAAA;AAG1B,IAAA,MAAM,iBAAiB,GAAA;;AAE1B,QAAA,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC;QAEzE,IAAI;YACA,MAAM,oBAAoB,CAAC,IAAI,CAACA,mBAAS,CAAC,qBAAqB,CAAC,CAAC;AAEjE,YAAA,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,CAAC;YAE7D,IAAI,CAAC,kBAAkB,EAAE;AACrB,gBAAA,MAAMC,iCAAgB,CAAC,2BAA2B,CAC9C,uEAAuE;AACvE,oBAAA;AACuC,2DAAA,CAC1C,CAAC;AACL,aAAA;AAED,YAAA,IAAI,kBAAkB,KAAKD,mBAAS,CAAC,qBAAqB,EAAE;AACxD,gBAAA,MAAMC,iCAAgB,CAAC,2BAA2B,CAC9C,CAA0C,uCAAA,EAAAD,mBAAS,CAAC,qBAAqB,CAAA;qCACxD,kBAAkB,CAAA,CAAE,CACxC,CAAC;AACL,aAAA;AACD,YAAA,MAAM,oBAAoB,CAAC,MAAM,EAAE,CAAC;AACpC,YAAA,OAAO,IAAI,CAAC;AACf,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACR,MAAMC,iCAAgB,CAAC,2BAA2B,CAAC,+CAA+C,CAAC,CAAA,CAAE,CAAC,CAAC;AAC1G,SAAA;KACJ;AAEJ;;;;"}
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* application on the computer can unprotect, access, and modify the data.
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
CurrentUser
|
|
14
|
-
LocalMachine
|
|
15
|
-
}
|
|
12
|
+
export declare const DataProtectionScope: {
|
|
13
|
+
readonly CurrentUser: "CurrentUser";
|
|
14
|
+
readonly LocalMachine: "LocalMachine";
|
|
15
|
+
};
|
|
16
|
+
export type DataProtectionScope = typeof DataProtectionScope[keyof typeof DataProtectionScope];
|
package/{src/persistence/DataProtectionScope.ts → dist/persistence/DataProtectionScope.esm.js}
RENAMED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Specifies the scope of the data protection - either the current user or the local
|
|
9
|
+
* machine.
|
|
10
|
+
*
|
|
11
|
+
* You do not need a key to protect or unprotect the data.
|
|
12
|
+
* If you set the Scope to CurrentUser, only applications running on your credentials can
|
|
13
|
+
* unprotect the data; however, that means that any application running on your credentials
|
|
14
|
+
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
|
|
15
|
+
* application on the computer can unprotect, access, and modify the data.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
const DataProtectionScope = {
|
|
19
|
+
CurrentUser: "CurrentUser",
|
|
20
|
+
LocalMachine: "LocalMachine",
|
|
21
|
+
};
|
|
5
22
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* machine.
|
|
9
|
-
*
|
|
10
|
-
* You do not need a key to protect or unprotect the data.
|
|
11
|
-
* If you set the Scope to CurrentUser, only applications running on your credentials can
|
|
12
|
-
* unprotect the data; however, that means that any application running on your credentials
|
|
13
|
-
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
|
|
14
|
-
* application on the computer can unprotect, access, and modify the data.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export enum DataProtectionScope {
|
|
18
|
-
CurrentUser = "CurrentUser",
|
|
19
|
-
LocalMachine = "LocalMachine",
|
|
20
|
-
}
|
|
23
|
+
export { DataProtectionScope };
|
|
24
|
+
//# sourceMappingURL=DataProtectionScope.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataProtectionScope.esm.js","sources":["../../src/persistence/DataProtectionScope.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAEH;;;;;;;;;;AAUG;AACU,MAAA,mBAAmB,GAAG;AAC/B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,YAAY,EAAE,cAAc;;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Specifies the scope of the data protection - either the current user or the local
|
|
11
|
+
* machine.
|
|
12
|
+
*
|
|
13
|
+
* You do not need a key to protect or unprotect the data.
|
|
14
|
+
* If you set the Scope to CurrentUser, only applications running on your credentials can
|
|
15
|
+
* unprotect the data; however, that means that any application running on your credentials
|
|
16
|
+
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
|
|
17
|
+
* application on the computer can unprotect, access, and modify the data.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
const DataProtectionScope = {
|
|
21
|
+
CurrentUser: "CurrentUser",
|
|
22
|
+
LocalMachine: "LocalMachine",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.DataProtectionScope = DataProtectionScope;
|
|
26
|
+
//# sourceMappingURL=DataProtectionScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataProtectionScope.js","sources":["../../src/persistence/DataProtectionScope.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;AAEH;;;;;;;;;;AAUG;AACU,MAAA,mBAAmB,GAAG;AAC/B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,YAAY,EAAE,cAAc;;;;;"}
|
|
@@ -11,6 +11,7 @@ import { BasePersistence } from "./BasePersistence";
|
|
|
11
11
|
export declare class FilePersistence extends BasePersistence implements IPersistence {
|
|
12
12
|
private filePath;
|
|
13
13
|
private logger;
|
|
14
|
+
private constructor();
|
|
14
15
|
static create(fileLocation: string, loggerOptions?: LoggerOptions): Promise<FilePersistence>;
|
|
15
16
|
save(contents: string): Promise<void>;
|
|
16
17
|
saveBuffer(contents: Uint8Array): Promise<void>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { promises } from 'fs';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import { ErrorCodes, Constants } from '../utils/Constants.esm.js';
|
|
6
|
+
import { PersistenceError } from '../error/PersistenceError.esm.js';
|
|
7
|
+
import { Logger, LogLevel } from '@azure/msal-common';
|
|
8
|
+
import { BasePersistence } from './BasePersistence.esm.js';
|
|
9
|
+
import { isNodeError } from '../utils/TypeGuards.esm.js';
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
13
|
+
* Licensed under the MIT License.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Reads and writes data to file specified by file location. File contents are not
|
|
17
|
+
* encrypted.
|
|
18
|
+
*
|
|
19
|
+
* If file or directory has not been created, it FilePersistence.create() will create
|
|
20
|
+
* file and any directories in the path recursively.
|
|
21
|
+
*/
|
|
22
|
+
class FilePersistence extends BasePersistence {
|
|
23
|
+
constructor(fileLocation, loggerOptions) {
|
|
24
|
+
super();
|
|
25
|
+
this.logger = new Logger(loggerOptions || FilePersistence.createDefaultLoggerOptions());
|
|
26
|
+
this.filePath = fileLocation;
|
|
27
|
+
}
|
|
28
|
+
static async create(fileLocation, loggerOptions) {
|
|
29
|
+
const filePersistence = new FilePersistence(fileLocation, loggerOptions);
|
|
30
|
+
await filePersistence.createCacheFile();
|
|
31
|
+
return filePersistence;
|
|
32
|
+
}
|
|
33
|
+
async save(contents) {
|
|
34
|
+
try {
|
|
35
|
+
await promises.writeFile(this.getFilePath(), contents, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (isNodeError(err)) {
|
|
39
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async saveBuffer(contents) {
|
|
47
|
+
try {
|
|
48
|
+
await promises.writeFile(this.getFilePath(), contents);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (isNodeError(err)) {
|
|
52
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async load() {
|
|
60
|
+
try {
|
|
61
|
+
return await promises.readFile(this.getFilePath(), "utf-8");
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (isNodeError(err)) {
|
|
65
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async loadBuffer() {
|
|
73
|
+
try {
|
|
74
|
+
return await promises.readFile(this.getFilePath());
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (isNodeError(err)) {
|
|
78
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async delete() {
|
|
86
|
+
try {
|
|
87
|
+
await promises.unlink(this.getFilePath());
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (isNodeError(err)) {
|
|
92
|
+
if (err.code === Constants.ENOENT_ERROR) {
|
|
93
|
+
// file does not exist, so it was not deleted
|
|
94
|
+
this.logger.warning("Cache file does not exist, so it could not be deleted");
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getFilePath() {
|
|
105
|
+
return this.filePath;
|
|
106
|
+
}
|
|
107
|
+
async reloadNecessary(lastSync) {
|
|
108
|
+
return lastSync < await this.timeLastModified();
|
|
109
|
+
}
|
|
110
|
+
getLogger() {
|
|
111
|
+
return this.logger;
|
|
112
|
+
}
|
|
113
|
+
createForPersistenceValidation() {
|
|
114
|
+
const testCacheFileLocation = `${dirname(this.filePath)}/test.cache`;
|
|
115
|
+
return FilePersistence.create(testCacheFileLocation);
|
|
116
|
+
}
|
|
117
|
+
static createDefaultLoggerOptions() {
|
|
118
|
+
return {
|
|
119
|
+
loggerCallback: () => {
|
|
120
|
+
// allow users to not set loggerCallback
|
|
121
|
+
},
|
|
122
|
+
piiLoggingEnabled: false,
|
|
123
|
+
logLevel: LogLevel.Info
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async timeLastModified() {
|
|
127
|
+
try {
|
|
128
|
+
const stats = await promises.stat(this.filePath);
|
|
129
|
+
return stats.mtime.getTime();
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
if (isNodeError(err)) {
|
|
133
|
+
if (err.code === Constants.ENOENT_ERROR) {
|
|
134
|
+
// file does not exist, so it's never been modified
|
|
135
|
+
this.logger.verbose("Cache file does not exist");
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async createCacheFile() {
|
|
146
|
+
await this.createFileDirectory();
|
|
147
|
+
// File is created only if it does not exist
|
|
148
|
+
const fileHandle = await promises.open(this.filePath, "a");
|
|
149
|
+
await fileHandle.close();
|
|
150
|
+
this.logger.info(`File created at ${this.filePath}`);
|
|
151
|
+
}
|
|
152
|
+
async createFileDirectory() {
|
|
153
|
+
try {
|
|
154
|
+
await promises.mkdir(dirname(this.filePath), { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (isNodeError(err)) {
|
|
158
|
+
if (err.code === Constants.EEXIST_ERROR) {
|
|
159
|
+
this.logger.info(`Directory ${dirname(this.filePath)} already exists`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { FilePersistence };
|
|
173
|
+
//# sourceMappingURL=FilePersistence.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilePersistence.esm.js","sources":["../../src/persistence/FilePersistence.ts"],"sourcesContent":[null],"names":["fs"],"mappings":";;;;;;;;;;AAAA;;;AAGG;AAWH;;;;;;AAMG;AACG,MAAO,eAAgB,SAAQ,eAAe,CAAA;IAKhD,WAAoB,CAAA,YAAoB,EAAE,aAA6B,EAAA;AACnE,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,IAAI,eAAe,CAAC,0BAA0B,EAAE,CAAC,CAAC;AACxF,QAAA,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;KAChC;AAEM,IAAA,aAAa,MAAM,CAAC,YAAoB,EAAE,aAA6B,EAAA;QAC1E,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AACzE,QAAA,MAAM,eAAe,CAAC,eAAe,EAAE,CAAC;AACxC,QAAA,OAAO,eAAe,CAAC;KAC1B;IAEM,MAAM,IAAI,CAAC,QAAgB,EAAA;QAC9B,IAAI;AACA,YAAA,MAAMA,QAAE,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC7D,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;AAClB,gBAAA,MAAM,gBAAgB,CAAC,qBAAqB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KACxD;AAEO,IAAA,MAAM,mBAAmB,GAAA;QAC7B,IAAI;AACA,YAAA,MAAMA,QAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;AAC7D,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;AAClB,gBAAA,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,YAAY,EAAE;AACrC,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAa,UAAA,EAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA,gBAAA,CAAkB,CAAC,CAAC;AAC3E,iBAAA;AAAM,qBAAA;AACH,oBAAA,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7F,iBAAA;AACJ,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;AACJ;;;;"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
|
|
2
|
+
'use strict';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var Constants = require('../utils/Constants.js');
|
|
8
|
+
var PersistenceError = require('../error/PersistenceError.js');
|
|
9
|
+
var msalCommon = require('@azure/msal-common');
|
|
10
|
+
var BasePersistence = require('./BasePersistence.js');
|
|
11
|
+
var TypeGuards = require('../utils/TypeGuards.js');
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
|
+
* Licensed under the MIT License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Reads and writes data to file specified by file location. File contents are not
|
|
19
|
+
* encrypted.
|
|
20
|
+
*
|
|
21
|
+
* If file or directory has not been created, it FilePersistence.create() will create
|
|
22
|
+
* file and any directories in the path recursively.
|
|
23
|
+
*/
|
|
24
|
+
class FilePersistence extends BasePersistence.BasePersistence {
|
|
25
|
+
constructor(fileLocation, loggerOptions) {
|
|
26
|
+
super();
|
|
27
|
+
this.logger = new msalCommon.Logger(loggerOptions || FilePersistence.createDefaultLoggerOptions());
|
|
28
|
+
this.filePath = fileLocation;
|
|
29
|
+
}
|
|
30
|
+
static async create(fileLocation, loggerOptions) {
|
|
31
|
+
const filePersistence = new FilePersistence(fileLocation, loggerOptions);
|
|
32
|
+
await filePersistence.createCacheFile();
|
|
33
|
+
return filePersistence;
|
|
34
|
+
}
|
|
35
|
+
async save(contents) {
|
|
36
|
+
try {
|
|
37
|
+
await fs.promises.writeFile(this.getFilePath(), contents, "utf-8");
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (TypeGuards.isNodeError(err)) {
|
|
41
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async saveBuffer(contents) {
|
|
49
|
+
try {
|
|
50
|
+
await fs.promises.writeFile(this.getFilePath(), contents);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (TypeGuards.isNodeError(err)) {
|
|
54
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async load() {
|
|
62
|
+
try {
|
|
63
|
+
return await fs.promises.readFile(this.getFilePath(), "utf-8");
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (TypeGuards.isNodeError(err)) {
|
|
67
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async loadBuffer() {
|
|
75
|
+
try {
|
|
76
|
+
return await fs.promises.readFile(this.getFilePath());
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (TypeGuards.isNodeError(err)) {
|
|
80
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async delete() {
|
|
88
|
+
try {
|
|
89
|
+
await fs.promises.unlink(this.getFilePath());
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (TypeGuards.isNodeError(err)) {
|
|
94
|
+
if (err.code === Constants.Constants.ENOENT_ERROR) {
|
|
95
|
+
// file does not exist, so it was not deleted
|
|
96
|
+
this.logger.warning("Cache file does not exist, so it could not be deleted");
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
getFilePath() {
|
|
107
|
+
return this.filePath;
|
|
108
|
+
}
|
|
109
|
+
async reloadNecessary(lastSync) {
|
|
110
|
+
return lastSync < await this.timeLastModified();
|
|
111
|
+
}
|
|
112
|
+
getLogger() {
|
|
113
|
+
return this.logger;
|
|
114
|
+
}
|
|
115
|
+
createForPersistenceValidation() {
|
|
116
|
+
const testCacheFileLocation = `${path.dirname(this.filePath)}/test.cache`;
|
|
117
|
+
return FilePersistence.create(testCacheFileLocation);
|
|
118
|
+
}
|
|
119
|
+
static createDefaultLoggerOptions() {
|
|
120
|
+
return {
|
|
121
|
+
loggerCallback: () => {
|
|
122
|
+
// allow users to not set loggerCallback
|
|
123
|
+
},
|
|
124
|
+
piiLoggingEnabled: false,
|
|
125
|
+
logLevel: msalCommon.LogLevel.Info
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async timeLastModified() {
|
|
129
|
+
try {
|
|
130
|
+
const stats = await fs.promises.stat(this.filePath);
|
|
131
|
+
return stats.mtime.getTime();
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (TypeGuards.isNodeError(err)) {
|
|
135
|
+
if (err.code === Constants.Constants.ENOENT_ERROR) {
|
|
136
|
+
// file does not exist, so it's never been modified
|
|
137
|
+
this.logger.verbose("Cache file does not exist");
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async createCacheFile() {
|
|
148
|
+
await this.createFileDirectory();
|
|
149
|
+
// File is created only if it does not exist
|
|
150
|
+
const fileHandle = await fs.promises.open(this.filePath, "a");
|
|
151
|
+
await fileHandle.close();
|
|
152
|
+
this.logger.info(`File created at ${this.filePath}`);
|
|
153
|
+
}
|
|
154
|
+
async createFileDirectory() {
|
|
155
|
+
try {
|
|
156
|
+
await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
if (TypeGuards.isNodeError(err)) {
|
|
160
|
+
if (err.code === Constants.Constants.EEXIST_ERROR) {
|
|
161
|
+
this.logger.info(`Directory ${path.dirname(this.filePath)} already exists`);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.FilePersistence = FilePersistence;
|
|
175
|
+
//# sourceMappingURL=FilePersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilePersistence.js","sources":["../../src/persistence/FilePersistence.ts"],"sourcesContent":[null],"names":["BasePersistence","Logger","fs","isNodeError","PersistenceError","ErrorCodes","Constants","dirname","LogLevel"],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAWH;;;;;;AAMG;AACG,MAAO,eAAgB,SAAQA,+BAAe,CAAA;IAKhD,WAAoB,CAAA,YAAoB,EAAE,aAA6B,EAAA;AACnE,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,IAAIC,iBAAM,CAAC,aAAa,IAAI,eAAe,CAAC,0BAA0B,EAAE,CAAC,CAAC;AACxF,QAAA,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;KAChC;AAEM,IAAA,aAAa,MAAM,CAAC,YAAoB,EAAE,aAA6B,EAAA;QAC1E,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AACzE,QAAA,MAAM,eAAe,CAAC,eAAe,EAAE,CAAC;AACxC,QAAA,OAAO,eAAe,CAAC;KAC1B;IAEM,MAAM,IAAI,CAAC,QAAgB,EAAA;QAC9B,IAAI;AACA,YAAA,MAAMC,WAAE,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC7D,SAAA;AAA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