@ms-cloudpack/remote-cache 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AzureRemoteCacheClient.d.ts +1 -1
- package/lib/AzureRemoteCacheClient.d.ts.map +1 -1
- package/lib/AzureRemoteCacheClient.js +2 -4
- package/lib/AzureRemoteCacheClient.js.map +1 -1
- package/lib/authentication/KeyRingLocalTokenCache.d.ts +14 -0
- package/lib/authentication/KeyRingLocalTokenCache.d.ts.map +1 -0
- package/lib/authentication/KeyRingLocalTokenCache.js +37 -0
- package/lib/authentication/KeyRingLocalTokenCache.js.map +1 -0
- package/lib/authentication/acquireSasToken.d.ts +3 -0
- package/lib/authentication/acquireSasToken.d.ts.map +1 -0
- package/lib/authentication/acquireSasToken.js +27 -0
- package/lib/authentication/acquireSasToken.js.map +1 -0
- package/lib/authentication/createBlobStorageUrl.d.ts +2 -0
- package/lib/authentication/createBlobStorageUrl.d.ts.map +1 -0
- package/lib/authentication/createBlobStorageUrl.js +4 -0
- package/lib/authentication/createBlobStorageUrl.js.map +1 -0
- package/lib/authentication/getAuthenticatedConnectionString.d.ts +3 -0
- package/lib/authentication/getAuthenticatedConnectionString.d.ts.map +1 -0
- package/lib/authentication/getAuthenticatedConnectionString.js +21 -0
- package/lib/authentication/getAuthenticatedConnectionString.js.map +1 -0
- package/lib/authentication/getCredential.d.ts +1 -7
- package/lib/authentication/getCredential.d.ts.map +1 -1
- package/lib/authentication/getCredential.js +7 -41
- package/lib/authentication/getCredential.js.map +1 -1
- package/lib/authentication/getSasToken.d.ts +12 -0
- package/lib/authentication/getSasToken.d.ts.map +1 -0
- package/lib/authentication/getSasToken.js +16 -0
- package/lib/authentication/getSasToken.js.map +1 -0
- package/lib/authentication/isExpired.d.ts +2 -0
- package/lib/authentication/isExpired.d.ts.map +1 -0
- package/lib/authentication/isExpired.js +10 -0
- package/lib/authentication/isExpired.js.map +1 -0
- package/lib/createRemoteCacheClient.d.ts +4 -10
- package/lib/createRemoteCacheClient.d.ts.map +1 -1
- package/lib/createRemoteCacheClient.js +10 -11
- package/lib/createRemoteCacheClient.js.map +1 -1
- package/lib/decorators/RetryDecorator.d.ts +1 -1
- package/lib/decorators/RetryDecorator.d.ts.map +1 -1
- package/lib/decorators/RetryDecorator.js.map +1 -1
- package/lib/getListOfBlobs.d.ts +1 -1
- package/lib/getListOfBlobs.d.ts.map +1 -1
- package/lib/getListOfBlobs.js +2 -3
- package/lib/getListOfBlobs.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types/ConnectionStringOptions.d.ts +13 -0
- package/lib/types/ConnectionStringOptions.d.ts.map +1 -0
- package/lib/types/ConnectionStringOptions.js +2 -0
- package/lib/types/ConnectionStringOptions.js.map +1 -0
- package/lib/types/LocalTokenCacheProvider.d.ts +6 -0
- package/lib/types/LocalTokenCacheProvider.d.ts.map +1 -0
- package/lib/types/LocalTokenCacheProvider.js +2 -0
- package/lib/types/LocalTokenCacheProvider.js.map +1 -0
- package/lib/types/RemoteCacheClientOptions.d.ts +1 -3
- package/lib/types/RemoteCacheClientOptions.d.ts.map +1 -1
- package/lib/types/RemoteCacheClientOptions.js.map +1 -1
- package/package.json +7 -6
- package/lib/authentication/getAuthenticationRecord.d.ts +0 -7
- package/lib/authentication/getAuthenticationRecord.d.ts.map +0 -1
- package/lib/authentication/getAuthenticationRecord.js +0 -17
- package/lib/authentication/getAuthenticationRecord.js.map +0 -1
- package/lib/authentication/getAuthenticationRecordPath.d.ts +0 -7
- package/lib/authentication/getAuthenticationRecordPath.d.ts.map +0 -1
- package/lib/authentication/getAuthenticationRecordPath.js +0 -10
- package/lib/authentication/getAuthenticationRecordPath.js.map +0 -1
- package/lib/authentication/saveAuthenticationRecord.d.ts +0 -9
- package/lib/authentication/saveAuthenticationRecord.d.ts.map +0 -1
- package/lib/authentication/saveAuthenticationRecord.js +0 -17
- package/lib/authentication/saveAuthenticationRecord.js.map +0 -1
- package/lib/createBlobStorageUrl.d.ts +0 -2
- package/lib/createBlobStorageUrl.d.ts.map +0 -1
- package/lib/createBlobStorageUrl.js +0 -4
- package/lib/createBlobStorageUrl.js.map +0 -1
- package/lib/retry/RetryManager.d.ts +0 -20
- package/lib/retry/RetryManager.d.ts.map +0 -1
- package/lib/retry/RetryManager.js +0 -47
- package/lib/retry/RetryManager.js.map +0 -1
|
@@ -3,7 +3,7 @@ import type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheC
|
|
|
3
3
|
export declare class AzureRemoteCacheClient implements RemoteCacheClient {
|
|
4
4
|
private readonly logger;
|
|
5
5
|
private readonly config;
|
|
6
|
-
constructor({ container,
|
|
6
|
+
constructor({ container, connectionString }: RemoteCacheClientOptions);
|
|
7
7
|
/**
|
|
8
8
|
* Uploads the folder to the remote cache.
|
|
9
9
|
* @param folderName - The name of the folder to upload.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AzureRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,yCAAyC,EAC1C,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"AzureRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,yCAAyC,EAC1C,MAAM,8BAA8B,CAAC;AAEtC,qBAAa,sBAAuB,YAAW,iBAAiB;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsD;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAIrB;gBAEU,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,wBAAwB;IAcrE;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,yCAAyC;IAS/F;;;;;OAKG;IACG,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,iCAAiC;CAY7E"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { makeLogger, put, fetch } from 'backfill/lib/api.js';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
4
3
|
export class AzureRemoteCacheClient {
|
|
5
|
-
constructor({ container,
|
|
4
|
+
constructor({ container, connectionString }) {
|
|
6
5
|
this.logger = makeLogger('mute', process.stdout, process.stderr);
|
|
7
6
|
this.config = {
|
|
8
7
|
incrementalCaching: true,
|
|
@@ -10,8 +9,7 @@ export class AzureRemoteCacheClient {
|
|
|
10
9
|
cacheStorageConfig: {
|
|
11
10
|
provider: 'azure-blob',
|
|
12
11
|
options: {
|
|
13
|
-
connectionString
|
|
14
|
-
credential,
|
|
12
|
+
connectionString,
|
|
15
13
|
container,
|
|
16
14
|
},
|
|
17
15
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AzureRemoteCacheClient.js","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"AzureRemoteCacheClient.js","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAOhC,MAAM,OAAO,sBAAsB;IAQjC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAA4B;QAPpD,WAAM,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAQ3E,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,IAAI;YACxB,mBAAmB,EAAE,EAAE;YACvB,kBAAkB,EAAE;gBAClB,QAAQ,EAAE,YAAY;gBACtB,OAAO,EAAE;oBACP,gBAAgB;oBAChB,SAAS;iBACV;aACF;SACF,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAA6C;QAC7F,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,WAAW,CAAC;SACpB;QAED,MAAM,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QACtF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,EAAqC;QAC1E,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YACpB,OAAO,eAAe,CAAC;SACxB;QAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,WAAW,CAAC;SACpB;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { makeLogger, put, fetch } from 'backfill/lib/api.js';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport type { AzureBlobCacheStorageConfig } from 'backfill-config';\nimport { existsSync } from 'fs';\nimport type {\n RemoteCacheClient,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientDownloadOperationOptions,\n} from './types/RemoteCacheClient.js';\n\nexport class AzureRemoteCacheClient implements RemoteCacheClient {\n private readonly logger = makeLogger('mute', process.stdout, process.stderr);\n private readonly config: {\n cacheStorageConfig: AzureBlobCacheStorageConfig;\n incrementalCaching: boolean;\n internalCacheFolder: string;\n };\n\n constructor({ container, connectionString }: RemoteCacheClientOptions) {\n this.config = {\n incrementalCaching: true,\n internalCacheFolder: '', // not used by azure-blob\n cacheStorageConfig: {\n provider: 'azure-blob',\n options: {\n connectionString,\n container,\n },\n },\n };\n }\n\n /**\n * Uploads the folder to the remote cache.\n * @param folderName - The name of the folder to upload.\n * @param path - The path to the folder to upload.\n * @param globMatches - The glob pattern to use when uploading the folder.\n * @returns - A promise that resolves when the folder has been uploaded.\n */\n async uploadFolder({ folderName, path, globMatches }: RemoteCacheClientDownloadOperationOptions) {\n if (!existsSync(path)) {\n return 'not-found';\n }\n\n await put(path, folderName, this.logger, { ...this.config, outputGlob: globMatches });\n return 'success';\n }\n\n /**\n * Downloads the folder from the remote cache.\n * @param folderName - The name of the folder to download.\n * @param path - The path to download the folder to.\n * @returns - A promise that resolves when the folder has been downloaded.\n */\n async downloadFolder({ folderName, path }: RemoteCacheClientOperationOptions) {\n if (existsSync(path)) {\n return 'already-exist';\n }\n\n const result = await fetch(path, folderName, this.logger, this.config);\n if (!result) {\n return 'not-found';\n }\n\n return 'success';\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';
|
|
2
|
+
/**
|
|
3
|
+
* This class is responsible to read and store tokens in a key ring provided by operating system.
|
|
4
|
+
*/
|
|
5
|
+
export declare class KeyRingLocalTokenCache implements LocalTokenCacheProvider {
|
|
6
|
+
private readonly service;
|
|
7
|
+
private readonly key;
|
|
8
|
+
private readonly entry;
|
|
9
|
+
constructor(service: string, key: string);
|
|
10
|
+
get(): string | undefined;
|
|
11
|
+
set(value: string): void;
|
|
12
|
+
delete(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=KeyRingLocalTokenCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyRingLocalTokenCache.d.ts","sourceRoot":"","sources":["../../src/authentication/KeyRingLocalTokenCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAGnF;;GAEG;AACH,qBAAa,sBAAuB,YAAW,uBAAuB;IAIlE,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAGX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM;IAK9B,GAAG;IAiBH,GAAG,CAAC,KAAK,EAAE,MAAM;IAIjB,MAAM;CAOP"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Entry } from '@napi-rs/keyring';
|
|
2
|
+
/**
|
|
3
|
+
* This class is responsible to read and store tokens in a key ring provided by operating system.
|
|
4
|
+
*/
|
|
5
|
+
export class KeyRingLocalTokenCache {
|
|
6
|
+
constructor(service, key) {
|
|
7
|
+
this.service = service;
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.entry = new Entry(service, key);
|
|
10
|
+
}
|
|
11
|
+
get() {
|
|
12
|
+
try {
|
|
13
|
+
const result = this.entry.getPassword();
|
|
14
|
+
console.debug(`KeyRingLocalTokenCache.get service:${this.service} key:${this.key} result:${result}`);
|
|
15
|
+
if (!result) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// If the entry does not exist getPassword might throw an error, return undefined.
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
set(value) {
|
|
26
|
+
this.entry.setPassword(value);
|
|
27
|
+
}
|
|
28
|
+
delete() {
|
|
29
|
+
try {
|
|
30
|
+
this.entry.deletePassword();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// If the entry does not exist deletePassword might throw an error, do nothing.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=KeyRingLocalTokenCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyRingLocalTokenCache.js","sourceRoot":"","sources":["../../src/authentication/KeyRingLocalTokenCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAGjC,YACmB,OAAe,EACf,GAAW;QADX,YAAO,GAAP,OAAO,CAAQ;QACf,QAAG,GAAH,GAAG,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,GAAG;QACD,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YAExC,OAAO,CAAC,KAAK,CAAC,sCAAsC,IAAI,CAAC,OAAO,QAAQ,IAAI,CAAC,GAAG,WAAW,MAAM,EAAE,CAAC,CAAC;YAErG,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,SAAS,CAAC;aAClB;YAED,OAAO,MAAM,CAAC;SACf;QAAC,MAAM;YACN,kFAAkF;YAClF,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,IAAI;YACF,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;SAC7B;QAAC,MAAM;YACN,+EAA+E;SAChF;IACH,CAAC;CACF","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport { Entry } from '@napi-rs/keyring';\n\n/**\n * This class is responsible to read and store tokens in a key ring provided by operating system.\n */\nexport class KeyRingLocalTokenCache implements LocalTokenCacheProvider {\n private readonly entry: Entry;\n\n constructor(\n private readonly service: string,\n private readonly key: string,\n ) {\n this.entry = new Entry(service, key);\n }\n\n get() {\n try {\n const result = this.entry.getPassword();\n\n console.debug(`KeyRingLocalTokenCache.get service:${this.service} key:${this.key} result:${result}`);\n\n if (!result) {\n return undefined;\n }\n\n return result;\n } catch {\n // If the entry does not exist getPassword might throw an error, return undefined.\n return undefined;\n }\n }\n\n set(value: string) {\n this.entry.setPassword(value);\n }\n\n delete() {\n try {\n this.entry.deletePassword();\n } catch {\n // If the entry does not exist deletePassword might throw an error, do nothing.\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';
|
|
2
|
+
export declare function acquireSasToken({ storageAccount: account, container, permissions, loginMethod, tokenExpiresInMs, }: ConnectionStringOptions): Promise<string>;
|
|
3
|
+
//# sourceMappingURL=acquireSasToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquireSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAInF,wBAAsB,eAAe,CAAC,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,GACjB,EAAE,uBAAuB,mBAgCzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BlobServiceClient, ContainerSASPermissions, SASProtocol, generateBlobSASQueryParameters, } from '@azure/storage-blob';
|
|
2
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
3
|
+
import { getCredential } from './getCredential.js';
|
|
4
|
+
export async function acquireSasToken({ storageAccount: account, container, permissions, loginMethod, tokenExpiresInMs, }) {
|
|
5
|
+
const credential = getCredential(loginMethod);
|
|
6
|
+
const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);
|
|
7
|
+
const containerClient = blobStorage.getContainerClient(container);
|
|
8
|
+
const startsOn = new Date(); // now
|
|
9
|
+
const hourInMs = 3600000;
|
|
10
|
+
const dayInMs = 24 * hourInMs;
|
|
11
|
+
const expiresInMs = 7 * dayInMs; // 7 days (maximum allowed by Azure)
|
|
12
|
+
if (tokenExpiresInMs && tokenExpiresInMs > expiresInMs) {
|
|
13
|
+
console.warn('Maximum allowed token expiration is 7 days. Using 7 days instead.');
|
|
14
|
+
tokenExpiresInMs = expiresInMs;
|
|
15
|
+
}
|
|
16
|
+
const expiresOn = new Date(startsOn.valueOf() + (tokenExpiresInMs ?? expiresInMs));
|
|
17
|
+
const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);
|
|
18
|
+
const sasQueryParams = generateBlobSASQueryParameters({
|
|
19
|
+
containerName: containerClient.containerName,
|
|
20
|
+
permissions: ContainerSASPermissions.from(permissions),
|
|
21
|
+
expiresOn,
|
|
22
|
+
startsOn,
|
|
23
|
+
protocol: SASProtocol.Https,
|
|
24
|
+
}, userDelegationKey, account);
|
|
25
|
+
return sasQueryParams.toString();
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=acquireSasToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquireSasToken.js","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,GACQ;IACxB,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IACrF,MAAM,eAAe,GAAG,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAElE,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC;IACzB,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,CAAC;IAC9B,MAAM,WAAW,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,oCAAoC;IAErE,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,WAAW,EAAE;QACtD,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;QAClF,gBAAgB,GAAG,WAAW,CAAC;KAChC;IAED,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,gBAAgB,IAAI,WAAW,CAAC,CAAC,CAAC;IAEnF,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEtF,MAAM,cAAc,GAAG,8BAA8B,CACnD;QACE,aAAa,EAAE,eAAe,CAAC,aAAa;QAC5C,WAAW,EAAE,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC;QACtD,SAAS;QACT,QAAQ;QACR,QAAQ,EAAE,WAAW,CAAC,KAAK;KAC5B,EACD,iBAAiB,EACjB,OAAO,CACR,CAAC;IAEF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import {\n BlobServiceClient,\n ContainerSASPermissions,\n SASProtocol,\n generateBlobSASQueryParameters,\n} from '@azure/storage-blob';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport { getCredential } from './getCredential.js';\n\nexport async function acquireSasToken({\n storageAccount: account,\n container,\n permissions,\n loginMethod,\n tokenExpiresInMs,\n}: ConnectionStringOptions) {\n const credential = getCredential(loginMethod);\n const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);\n const containerClient = blobStorage.getContainerClient(container);\n\n const startsOn = new Date(); // now\n const hourInMs = 3600000;\n const dayInMs = 24 * hourInMs;\n const expiresInMs = 7 * dayInMs; // 7 days (maximum allowed by Azure)\n\n if (tokenExpiresInMs && tokenExpiresInMs > expiresInMs) {\n console.warn('Maximum allowed token expiration is 7 days. Using 7 days instead.');\n tokenExpiresInMs = expiresInMs;\n }\n\n const expiresOn = new Date(startsOn.valueOf() + (tokenExpiresInMs ?? expiresInMs));\n\n const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);\n\n const sasQueryParams = generateBlobSASQueryParameters(\n {\n containerName: containerClient.containerName,\n permissions: ContainerSASPermissions.from(permissions),\n expiresOn,\n startsOn,\n protocol: SASProtocol.Https,\n },\n userDelegationKey,\n account,\n );\n\n return sasQueryParams.toString();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBlobStorageUrl.d.ts","sourceRoot":"","sources":["../../src/authentication/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,UAEnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBlobStorageUrl.js","sourceRoot":"","sources":["../../src/authentication/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,WAAW,OAAO,wBAAwB,CAAC;AACpD,CAAC","sourcesContent":["export function createBlobStorageUrl(account: string) {\n return `https://${account}.blob.core.windows.net`;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticatedConnectionString.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAenF,wBAAsB,gCAAgC,CAAC,uBAAuB,EAAE,uBAAuB,mBAWtG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
2
|
+
import { getSasToken } from './getSasToken.js';
|
|
3
|
+
import { acquireSasToken } from './acquireSasToken.js';
|
|
4
|
+
import { isExpired } from './isExpired.js';
|
|
5
|
+
import { ContainerSASPermissions } from '@azure/storage-blob';
|
|
6
|
+
async function createLocalTokenCacheLazy({ storageAccount, container, permissions }) {
|
|
7
|
+
const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');
|
|
8
|
+
const service = `cloudpack-cache-${storageAccount}`;
|
|
9
|
+
const key = `container:${container};permission:${ContainerSASPermissions.from(permissions).toString()}`;
|
|
10
|
+
return new KeyRingLocalTokenCache(service, key);
|
|
11
|
+
}
|
|
12
|
+
export async function getAuthenticatedConnectionString(connectionStringOptions) {
|
|
13
|
+
// No need to cache tokens if the user is NOT running in interactive mode.
|
|
14
|
+
const tokenCache = connectionStringOptions.loginMethod == 'interactive' || connectionStringOptions.loginMethod == 'azure-cli'
|
|
15
|
+
? await createLocalTokenCacheLazy(connectionStringOptions)
|
|
16
|
+
: undefined;
|
|
17
|
+
const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });
|
|
18
|
+
const { storageAccount } = connectionStringOptions;
|
|
19
|
+
return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=getAuthenticatedConnectionString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthenticatedConnectionString.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,KAAK,UAAU,yBAAyB,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAA2B;IAC1G,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IAE/E,MAAM,OAAO,GAAG,mBAAmB,cAAc,EAAE,CAAC;IACpD,MAAM,GAAG,GAAG,aAAa,SAAS,eAAe,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IAExG,OAAO,IAAI,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,uBAAgD;IACrG,0EAA0E;IAC1E,MAAM,UAAU,GACd,uBAAuB,CAAC,WAAW,IAAI,aAAa,IAAI,uBAAuB,CAAC,WAAW,IAAI,WAAW;QACxG,CAAC,CAAC,MAAM,yBAAyB,CAAC,uBAAuB,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5G,MAAM,EAAE,cAAc,EAAE,GAAG,uBAAuB,CAAC;IACnD,OAAO,gBAAgB,oBAAoB,CAAC,cAAc,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAClG,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { getSasToken } from './getSasToken.js';\nimport { acquireSasToken } from './acquireSasToken.js';\nimport { isExpired } from './isExpired.js';\nimport { ContainerSASPermissions } from '@azure/storage-blob';\n\nasync function createLocalTokenCacheLazy({ storageAccount, container, permissions }: ConnectionStringOptions) {\n const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');\n\n const service = `cloudpack-cache-${storageAccount}`;\n const key = `container:${container};permission:${ContainerSASPermissions.from(permissions).toString()}`;\n\n return new KeyRingLocalTokenCache(service, key);\n}\n\nexport async function getAuthenticatedConnectionString(connectionStringOptions: ConnectionStringOptions) {\n // No need to cache tokens if the user is NOT running in interactive mode.\n const tokenCache =\n connectionStringOptions.loginMethod == 'interactive' || connectionStringOptions.loginMethod == 'azure-cli'\n ? await createLocalTokenCacheLazy(connectionStringOptions)\n : undefined;\n\n const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });\n\n const { storageAccount } = connectionStringOptions;\n return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;\n}\n"]}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential } from '@azure/identity';
|
|
2
2
|
import type { LoginMethod } from '../types/LoginMethod.js';
|
|
3
|
-
|
|
4
|
-
* Gets a credential for the given login method.
|
|
5
|
-
* If the login method is 'azure-cli', it will return an AzureCliCredential.
|
|
6
|
-
* Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.
|
|
7
|
-
* If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getCredential(loginMethod: LoginMethod, cachePath: string): Promise<InteractiveBrowserCredential | DeviceCodeCredential | AzureCliCredential>;
|
|
3
|
+
export declare function getCredential(loginMethod: LoginMethod): InteractiveBrowserCredential | DeviceCodeCredential | AzureCliCredential;
|
|
10
4
|
//# sourceMappingURL=getCredential.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AACzG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,4EAcrD"}
|
|
@@ -1,51 +1,17 @@
|
|
|
1
|
-
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential
|
|
2
|
-
|
|
3
|
-
import { getAuthenticationRecord } from './getAuthenticationRecord.js';
|
|
4
|
-
import { saveAuthenticationRecord } from './saveAuthenticationRecord.js';
|
|
5
|
-
const tokenCachePersistenceOptions = {
|
|
6
|
-
enabled: true,
|
|
7
|
-
name: 'cloudpack',
|
|
8
|
-
};
|
|
9
|
-
function getCredentialInternal(loginMethod, authenticationRecord) {
|
|
1
|
+
import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential } from '@azure/identity';
|
|
2
|
+
export function getCredential(loginMethod) {
|
|
10
3
|
switch (loginMethod) {
|
|
11
4
|
case 'interactive':
|
|
12
5
|
return new InteractiveBrowserCredential({
|
|
13
6
|
redirectUri: 'http://localhost:1337',
|
|
14
|
-
authenticationRecord,
|
|
15
|
-
tokenCachePersistenceOptions,
|
|
16
7
|
});
|
|
17
8
|
case 'device-code':
|
|
18
|
-
return new DeviceCodeCredential(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
9
|
+
return new DeviceCodeCredential();
|
|
10
|
+
case 'azure-cli':
|
|
11
|
+
return new AzureCliCredential();
|
|
22
12
|
default:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Gets a credential for the given login method.
|
|
28
|
-
* If the login method is 'azure-cli', it will return an AzureCliCredential.
|
|
29
|
-
* Otherwise, it will return an InteractiveBrowserCredential or a DeviceCodeCredential with persistent token settings.
|
|
30
|
-
* If an authentication record has never been saved before, it will authenticate the credential and save the authentication record.
|
|
31
|
-
*/
|
|
32
|
-
export async function getCredential(loginMethod, cachePath) {
|
|
33
|
-
if (loginMethod == 'azure-cli') {
|
|
34
|
-
return new AzureCliCredential();
|
|
35
|
-
}
|
|
36
|
-
useIdentityPlugin(cachePersistencePlugin);
|
|
37
|
-
let authenticationRecord = getAuthenticationRecord(cachePath);
|
|
38
|
-
const credential = getCredentialInternal(loginMethod, authenticationRecord);
|
|
39
|
-
if (!authenticationRecord) {
|
|
40
|
-
console.warn('Cloudpack requires authentication to access Azure resources.');
|
|
41
|
-
if (loginMethod == 'interactive') {
|
|
42
|
-
console.warn("Prepare to sign in – we're launching a browser page for you. Simply follow the instructions on the login page to seamlessly complete the authentication process.");
|
|
43
|
-
}
|
|
44
|
-
authenticationRecord = await credential.authenticate('https://storage.azure.com/.default');
|
|
45
|
-
if (authenticationRecord) {
|
|
46
|
-
saveAuthenticationRecord(cachePath, authenticationRecord);
|
|
47
|
-
}
|
|
13
|
+
console.warn('Unknown login method. Using azure-cli as fallback.');
|
|
14
|
+
return new AzureCliCredential();
|
|
48
15
|
}
|
|
49
|
-
return credential;
|
|
50
16
|
}
|
|
51
17
|
//# sourceMappingURL=getCredential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAGzG,MAAM,UAAU,aAAa,CAAC,WAAwB;IACpD,QAAQ,WAAW,EAAE;QACnB,KAAK,aAAa;YAChB,OAAO,IAAI,4BAA4B,CAAC;gBACtC,WAAW,EAAE,uBAAuB;aACrC,CAAC,CAAC;QACL,KAAK,aAAa;YAChB,OAAO,IAAI,oBAAoB,EAAE,CAAC;QACpC,KAAK,WAAW;YACd,OAAO,IAAI,kBAAkB,EAAE,CAAC;QAClC;YACE,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;YACnE,OAAO,IAAI,kBAAkB,EAAE,CAAC;KACnC;AACH,CAAC","sourcesContent":["import { AzureCliCredential, DeviceCodeCredential, InteractiveBrowserCredential } from '@azure/identity';\nimport type { LoginMethod } from '../types/LoginMethod.js';\n\nexport function getCredential(loginMethod: LoginMethod) {\n switch (loginMethod) {\n case 'interactive':\n return new InteractiveBrowserCredential({\n redirectUri: 'http://localhost:1337',\n });\n case 'device-code':\n return new DeviceCodeCredential();\n case 'azure-cli':\n return new AzureCliCredential();\n default:\n console.warn('Unknown login method. Using azure-cli as fallback.');\n return new AzureCliCredential();\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';
|
|
2
|
+
import type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';
|
|
3
|
+
export interface GetSasTokenOptions {
|
|
4
|
+
connectionStringOptions: ConnectionStringOptions;
|
|
5
|
+
}
|
|
6
|
+
export interface GetSasTokenDependencies {
|
|
7
|
+
tokenCache?: LocalTokenCacheProvider;
|
|
8
|
+
acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;
|
|
9
|
+
isExpired: (token: string) => boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getSasToken({ connectionStringOptions }: GetSasTokenOptions, { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=getSasToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,uBAAuB,EAAE,uBAAuB,CAAC;CAClD;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,eAAe,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC;AAED,wBAAsB,WAAW,CAC/B,EAAE,uBAAuB,EAAE,EAAE,kBAAkB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,uBAAuB,mBAepE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export async function getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired }) {
|
|
2
|
+
try {
|
|
3
|
+
const localToken = tokenCache?.get();
|
|
4
|
+
if (localToken && !isExpired(localToken)) {
|
|
5
|
+
return localToken;
|
|
6
|
+
}
|
|
7
|
+
const token = await acquireSasToken(connectionStringOptions);
|
|
8
|
+
tokenCache?.set(token);
|
|
9
|
+
return token;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error(`Failed to get SAS token for storage account.`, error);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getSasToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSasToken.js","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAAE,uBAAuB,EAAsB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAA2B;IAEnE,IAAI;QACF,MAAM,UAAU,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC;QACrC,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YACxC,OAAO,UAAU,CAAC;SACnB;QAED,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,uBAAuB,CAAC,CAAC;QAC7D,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;QACrE,MAAM,KAAK,CAAC;KACb;AACH,CAAC","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\n\nexport interface GetSasTokenOptions {\n connectionStringOptions: ConnectionStringOptions;\n}\n\nexport interface GetSasTokenDependencies {\n tokenCache?: LocalTokenCacheProvider;\n acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;\n isExpired: (token: string) => boolean;\n}\n\nexport async function getSasToken(\n { connectionStringOptions }: GetSasTokenOptions,\n { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies,\n) {\n try {\n const localToken = tokenCache?.get();\n if (localToken && !isExpired(localToken)) {\n return localToken;\n }\n\n const token = await acquireSasToken(connectionStringOptions);\n tokenCache?.set(token);\n return token;\n } catch (error) {\n console.error(`Failed to get SAS token for storage account.`, error);\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isExpired.d.ts","sourceRoot":"","sources":["../../src/authentication/isExpired.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,WAQzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isExpired.js","sourceRoot":"","sources":["../../src/authentication/isExpired.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,MAAM,EAAE,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,IAAI,CAAC;KACb;IACD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,MAAM,GAAG,GAAG,CAAC;AACtB,CAAC","sourcesContent":["export function isExpired(sasToken: string) {\n const se = new URLSearchParams(sasToken).get('se');\n if (!se) {\n return true;\n }\n const expiry = new Date(se);\n const now = new Date();\n return expiry < now;\n}\n"]}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
|
|
2
3
|
import type { RemoteCacheClient } from './types/RemoteCacheClient.js';
|
|
3
4
|
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
options: {
|
|
7
|
-
storageAccount: string;
|
|
8
|
-
container: string;
|
|
9
|
-
loginMethod: LoginMethod;
|
|
10
|
-
cachePath: string;
|
|
11
|
-
};
|
|
5
|
+
export declare function createRemoteCacheClient(options: {
|
|
6
|
+
connectionStringOptions: ConnectionStringOptions;
|
|
12
7
|
context: {
|
|
13
8
|
reporter: TaskReporter;
|
|
14
9
|
telemetryClient: TelemetryClient;
|
|
15
10
|
};
|
|
16
|
-
}
|
|
17
|
-
export declare function createRemoteCacheClient(params: CreateRemoteCacheClientParams): Promise<RemoteCacheClient>;
|
|
11
|
+
}): Promise<RemoteCacheClient>;
|
|
18
12
|
//# sourceMappingURL=createRemoteCacheClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAMhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAItE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,OAAO,EAAE;QACP,QAAQ,EAAE,YAAY,CAAC;QACvB,eAAe,EAAE,eAAe,CAAC;KAClC,CAAC;CACH,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuB7B"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';
|
|
2
|
+
import { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';
|
|
2
3
|
import { InMemoryDecorator } from './decorators/InMemoryDecorator.js';
|
|
3
4
|
import { ReporterDecorator } from './decorators/ReporterDecorator.js';
|
|
4
5
|
import { getListOfBlobs } from './getListOfBlobs.js';
|
|
5
6
|
import { RetryDecorator } from './decorators/RetryDecorator.js';
|
|
6
7
|
import { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';
|
|
7
|
-
import { RetryManager } from '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const remoteCacheClientOptions = {
|
|
14
|
-
storageAccount,
|
|
8
|
+
import { RetryManager } from '@ms-cloudpack/retry';
|
|
9
|
+
export async function createRemoteCacheClient(options) {
|
|
10
|
+
const { connectionStringOptions, context } = options;
|
|
11
|
+
const { container } = connectionStringOptions;
|
|
12
|
+
const connectionString = await getAuthenticatedConnectionString(connectionStringOptions);
|
|
13
|
+
const cacheClientOptions = {
|
|
15
14
|
container,
|
|
16
|
-
|
|
15
|
+
connectionString,
|
|
17
16
|
};
|
|
18
17
|
const client = new ReporterDecorator(new RetryDecorator({
|
|
19
18
|
retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
|
|
20
19
|
cacheClient: new InMemoryDecorator({
|
|
21
|
-
cacheClient: new AzureRemoteCacheClient(
|
|
22
|
-
getList: () => getListOfBlobs(
|
|
20
|
+
cacheClient: new AzureRemoteCacheClient(cacheClientOptions),
|
|
21
|
+
getList: () => getListOfBlobs(cacheClientOptions),
|
|
23
22
|
}),
|
|
24
23
|
}), context);
|
|
25
24
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAM7C;IACC,MAAM,EAAE,uBAAuB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACrD,MAAM,EAAE,SAAS,EAAE,GAAG,uBAAuB,CAAC;IAE9C,MAAM,gBAAgB,GAAG,MAAM,gCAAgC,CAAC,uBAAuB,CAAC,CAAC;IAEzF,MAAM,kBAAkB,GAAG;QACzB,SAAS;QACT,gBAAgB;KACjB,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAClC,IAAI,cAAc,CAAC;QACjB,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,6BAA6B,CAAC,CAAC;QAC/D,WAAW,EAAE,IAAI,iBAAiB,CAAC;YACjC,WAAW,EAAE,IAAI,sBAAsB,CAAC,kBAAkB,CAAC;YAC3D,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,kBAAkB,CAAC;SAClD,CAAC;KACH,CAAC,EACF,OAAO,CACR,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';\nimport { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';\nimport { InMemoryDecorator } from './decorators/InMemoryDecorator.js';\nimport { ReporterDecorator } from './decorators/ReporterDecorator.js';\nimport { getListOfBlobs } from './getListOfBlobs.js';\nimport type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';\nimport type { RemoteCacheClient } from './types/RemoteCacheClient.js';\nimport { RetryDecorator } from './decorators/RetryDecorator.js';\nimport { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';\nimport { RetryManager } from '@ms-cloudpack/retry';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\n\nexport async function createRemoteCacheClient(options: {\n connectionStringOptions: ConnectionStringOptions;\n context: {\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n };\n}): Promise<RemoteCacheClient> {\n const { connectionStringOptions, context } = options;\n const { container } = connectionStringOptions;\n\n const connectionString = await getAuthenticatedConnectionString(connectionStringOptions);\n\n const cacheClientOptions = {\n container,\n connectionString,\n };\n\n const client = new ReporterDecorator(\n new RetryDecorator({\n retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),\n cacheClient: new InMemoryDecorator({\n cacheClient: new AzureRemoteCacheClient(cacheClientOptions),\n getList: () => getListOfBlobs(cacheClientOptions),\n }),\n }),\n context,\n );\n\n return client;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RemoteCacheClient, RemoteCacheClientDownloadOperationOptions, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult } from '../types/RemoteCacheClient.js';
|
|
2
|
-
import type { RetryManager } from '
|
|
2
|
+
import type { RetryManager } from '@ms-cloudpack/retry';
|
|
3
3
|
/**
|
|
4
4
|
* A decorator that retries the upload/download operation if it fails.
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,qBAAa,cAAe,YAAW,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,OAAO,EAAE;QAAE,WAAW,EAAE,iBAAiB,CAAC;QAAC,YAAY,EAAE,YAAY,CAAA;KAAE;IAKnF,OAAO,CAAC,iBAAiB;IAYnB,YAAY,CAAC,OAAO,EAAE,yCAAyC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAO3G,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAM5G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;SACH;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '
|
|
1
|
+
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;SACH;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAkD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '@ms-cloudpack/retry';\n\n/**\n * A decorator that retries the upload/download operation if it fails.\n */\nexport class RetryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly retryManager: RetryManager;\n\n constructor(options: { cacheClient: RemoteCacheClient; retryManager: RetryManager }) {\n this.cacheClient = options.cacheClient;\n this.retryManager = options.retryManager;\n }\n\n private printRetryContext(\n operationName: string,\n options: RemoteCacheClientOperationOptions,\n retryContext?: { retryAttempt: number; maxRetries: number },\n ) {\n if (retryContext) {\n console.warn(\n `Retrying ${operationName} ${options.friendlyName} ... [${retryContext.retryAttempt}/${retryContext.maxRetries}]`,\n );\n }\n }\n\n async uploadFolder(options: RemoteCacheClientDownloadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('upload', options, retryContext);\n return this.cacheClient.uploadFolder(options);\n });\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('download', options, retryContext);\n return this.cacheClient.downloadFolder(options);\n });\n }\n}\n"]}
|
package/lib/getListOfBlobs.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.
|
|
|
2
2
|
/**
|
|
3
3
|
* Gets all the blobs in the remote cache.
|
|
4
4
|
*/
|
|
5
|
-
export declare function getListOfBlobs({ container,
|
|
5
|
+
export declare function getListOfBlobs({ container, connectionString }: RemoteCacheClientOptions): Promise<Set<string>>;
|
|
6
6
|
//# sourceMappingURL=getListOfBlobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF;;GAEG;AACH,wBAAsB,cAAc,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,wBAAwB,wBAQ7F"}
|
package/lib/getListOfBlobs.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
2
1
|
import { BlobServiceClient } from '@azure/storage-blob';
|
|
3
2
|
/**
|
|
4
3
|
* Gets all the blobs in the remote cache.
|
|
5
4
|
*/
|
|
6
|
-
export async function getListOfBlobs({ container,
|
|
7
|
-
const blobStorageClient =
|
|
5
|
+
export async function getListOfBlobs({ container, connectionString }) {
|
|
6
|
+
const blobStorageClient = BlobServiceClient.fromConnectionString(connectionString);
|
|
8
7
|
const containerClient = blobStorageClient.getContainerClient(container);
|
|
9
8
|
const blobs = new Set();
|
|
10
9
|
for await (const blob of containerClient.listBlobsFlat()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAA4B;IAC5F,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACnF,MAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,eAAe,CAAC,aAAa,EAAE,EAAE;QACxD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACtB;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport { BlobServiceClient } from '@azure/storage-blob';\n\n/**\n * Gets all the blobs in the remote cache.\n */\nexport async function getListOfBlobs({ container, connectionString }: RemoteCacheClientOptions) {\n const blobStorageClient = BlobServiceClient.fromConnectionString(connectionString);\n const containerClient = blobStorageClient.getContainerClient(container);\n const blobs = new Set<string>();\n for await (const blob of containerClient.listBlobsFlat()) {\n blobs.add(blob.name);\n }\n return blobs;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { createRemoteCacheClient
|
|
1
|
+
export { createRemoteCacheClient } from './createRemoteCacheClient.js';
|
|
2
2
|
export type { RemoteCacheClient, RemoteCacheClientDownloadOperationOptions, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult, } from './types/RemoteCacheClient.js';
|
|
3
|
+
export type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
|
|
3
4
|
export type { LoginMethod } from './types/LoginMethod.js';
|
|
4
5
|
export type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,YAAY,EACV,iBAAiB,EACjB,yCAAyC,EACzC,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["export { createRemoteCacheClient } from './createRemoteCacheClient.js';\n\nexport type {\n RemoteCacheClient,\n RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from './types/RemoteCacheClient.js';\nexport type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';\nexport type { LoginMethod } from './types/LoginMethod.js';\nexport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LoginMethod } from './LoginMethod.js';
|
|
2
|
+
export interface ConnectionStringOptions {
|
|
3
|
+
storageAccount: string;
|
|
4
|
+
container: string;
|
|
5
|
+
permissions: {
|
|
6
|
+
read: boolean;
|
|
7
|
+
write: boolean;
|
|
8
|
+
list: boolean;
|
|
9
|
+
};
|
|
10
|
+
tokenExpiresInMs?: number;
|
|
11
|
+
loginMethod: LoginMethod;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ConnectionStringOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionStringOptions.d.ts","sourceRoot":"","sources":["../../src/types/ConnectionStringOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE;QACX,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,OAAO,CAAC;QACf,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionStringOptions.js","sourceRoot":"","sources":["../../src/types/ConnectionStringOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { LoginMethod } from './LoginMethod.js';\n\nexport interface ConnectionStringOptions {\n storageAccount: string;\n container: string;\n permissions: {\n read: boolean;\n write: boolean;\n list: boolean;\n };\n tokenExpiresInMs?: number;\n loginMethod: LoginMethod;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalTokenCacheProvider.d.ts","sourceRoot":"","sources":["../../src/types/LocalTokenCacheProvider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,GAAG,IAAI,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,IAAI,IAAI,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalTokenCacheProvider.js","sourceRoot":"","sources":["../../src/types/LocalTokenCacheProvider.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalTokenCacheProvider {\n get(): string | undefined;\n set(value: string): void;\n delete(): void;\n}\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { TokenCredential } from '@azure/identity';
|
|
2
1
|
export interface RemoteCacheClientOptions {
|
|
3
|
-
|
|
2
|
+
connectionString: string;
|
|
4
3
|
container: string;
|
|
5
|
-
credential: TokenCredential;
|
|
6
4
|
}
|
|
7
5
|
//# sourceMappingURL=RemoteCacheClientOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteCacheClientOptions.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteCacheClientOptions.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface RemoteCacheClientOptions {\n connectionString: string;\n container: string;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/remote-cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,12 +31,13 @@
|
|
|
31
31
|
"lib/**/!(*.test.*)"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@azure/identity": "^3.4.0",
|
|
35
|
-
"@azure/identity-cache-persistence": "^1.0.0",
|
|
36
|
-
"@azure/storage-blob": "^12.17.0",
|
|
37
34
|
"@ms-cloudpack/task-reporter": "^0.10.2",
|
|
38
35
|
"@ms-cloudpack/telemetry": "^0.4.4",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
36
|
+
"@ms-cloudpack/retry": "^0.1.1",
|
|
37
|
+
"@azure/identity": "^3.4.0",
|
|
38
|
+
"@azure/storage-blob": "^12.17.0",
|
|
39
|
+
"@napi-rs/keyring": "^1.1.3",
|
|
40
|
+
"backfill": "^6.2.1",
|
|
41
|
+
"backfill-config": "^6.4.1"
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the authentication record from Cloudpack's global cache folder.
|
|
3
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
4
|
-
* @returns - The authentication record if it exists; otherwise, returns `undefined`.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getAuthenticationRecord(cachePath: string): import("@azure/identity").AuthenticationRecord | undefined;
|
|
7
|
-
//# sourceMappingURL=getAuthenticationRecord.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticationRecord.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecord.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,8DAQxD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { deserializeAuthenticationRecord } from '@azure/identity';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';
|
|
4
|
-
/**
|
|
5
|
-
* Retrieves the authentication record from Cloudpack's global cache folder.
|
|
6
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
7
|
-
* @returns - The authentication record if it exists; otherwise, returns `undefined`.
|
|
8
|
-
*/
|
|
9
|
-
export function getAuthenticationRecord(cachePath) {
|
|
10
|
-
const fullPath = getAuthenticationRecordPath(cachePath);
|
|
11
|
-
if (!existsSync(fullPath)) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const content = readFileSync(fullPath, 'utf-8');
|
|
15
|
-
return deserializeAuthenticationRecord(content);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=getAuthenticationRecord.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticationRecord.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACvD,MAAM,QAAQ,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QACzB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,+BAA+B,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { deserializeAuthenticationRecord } from '@azure/identity';\nimport { existsSync, readFileSync } from 'fs';\nimport { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';\n\n/**\n * Retrieves the authentication record from Cloudpack's global cache folder.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @returns - The authentication record if it exists; otherwise, returns `undefined`.\n */\nexport function getAuthenticationRecord(cachePath: string) {\n const fullPath = getAuthenticationRecordPath(cachePath);\n if (!existsSync(fullPath)) {\n return undefined;\n }\n\n const content = readFileSync(fullPath, 'utf-8');\n return deserializeAuthenticationRecord(content);\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constructs and returns the full path to the authentication record file within the specified cache folder.
|
|
3
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
4
|
-
* @returns - The full path to the authentication record file.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getAuthenticationRecordPath(cachePath: string): string;
|
|
7
|
-
//# sourceMappingURL=getAuthenticationRecordPath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticationRecordPath.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecordPath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,UAE5D"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
/**
|
|
3
|
-
* Constructs and returns the full path to the authentication record file within the specified cache folder.
|
|
4
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
5
|
-
* @returns - The full path to the authentication record file.
|
|
6
|
-
*/
|
|
7
|
-
export function getAuthenticationRecordPath(cachePath) {
|
|
8
|
-
return path.join(cachePath, 'tokencache.bin');
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=getAuthenticationRecordPath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthenticationRecordPath.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticationRecordPath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,SAAiB;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * Constructs and returns the full path to the authentication record file within the specified cache folder.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @returns - The full path to the authentication record file.\n */\nexport function getAuthenticationRecordPath(cachePath: string) {\n return path.join(cachePath, 'tokencache.bin');\n}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type AuthenticationRecord } from '@azure/identity';
|
|
2
|
-
/**
|
|
3
|
-
* Saves the provided authentication record to Cloudpack's global cache folder.
|
|
4
|
-
* Creates the cache folder if it doesn't exist.
|
|
5
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
6
|
-
* @param authRecord - The authentication record to save.
|
|
7
|
-
*/
|
|
8
|
-
export declare function saveAuthenticationRecord(cachePath: string, authRecord: AuthenticationRecord): void;
|
|
9
|
-
//# sourceMappingURL=saveAuthenticationRecord.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saveAuthenticationRecord.d.ts","sourceRoot":"","sources":["../../src/authentication/saveAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAI3F;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,QAQ3F"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { serializeAuthenticationRecord } from '@azure/identity';
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
3
|
-
import { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';
|
|
4
|
-
/**
|
|
5
|
-
* Saves the provided authentication record to Cloudpack's global cache folder.
|
|
6
|
-
* Creates the cache folder if it doesn't exist.
|
|
7
|
-
* @param cachePath - The path to Cloudpack's cache folder.
|
|
8
|
-
* @param authRecord - The authentication record to save.
|
|
9
|
-
*/
|
|
10
|
-
export function saveAuthenticationRecord(cachePath, authRecord) {
|
|
11
|
-
const content = serializeAuthenticationRecord(authRecord);
|
|
12
|
-
if (!existsSync(cachePath)) {
|
|
13
|
-
mkdirSync(cachePath, { recursive: true });
|
|
14
|
-
}
|
|
15
|
-
writeFileSync(getAuthenticationRecordPath(cachePath), content);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=saveAuthenticationRecord.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saveAuthenticationRecord.js","sourceRoot":"","sources":["../../src/authentication/saveAuthenticationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAA6B,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAiB,EAAE,UAAgC;IAC1F,MAAM,OAAO,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAE1D,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC1B,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KAC3C;IAED,aAAa,CAAC,2BAA2B,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { serializeAuthenticationRecord, type AuthenticationRecord } from '@azure/identity';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { getAuthenticationRecordPath } from './getAuthenticationRecordPath.js';\n\n/**\n * Saves the provided authentication record to Cloudpack's global cache folder.\n * Creates the cache folder if it doesn't exist.\n * @param cachePath - The path to Cloudpack's cache folder.\n * @param authRecord - The authentication record to save.\n */\nexport function saveAuthenticationRecord(cachePath: string, authRecord: AuthenticationRecord) {\n const content = serializeAuthenticationRecord(authRecord);\n\n if (!existsSync(cachePath)) {\n mkdirSync(cachePath, { recursive: true });\n }\n\n writeFileSync(getAuthenticationRecordPath(cachePath), content);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBlobStorageUrl.d.ts","sourceRoot":"","sources":["../src/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,UAE1D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBlobStorageUrl.js","sourceRoot":"","sources":["../src/createBlobStorageUrl.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,cAAsB;IACzD,OAAO,WAAW,cAAc,wBAAwB,CAAC;AAC3D,CAAC","sourcesContent":["export function createBlobStorageUrl(storageAccount: string) {\n return `https://${storageAccount}.blob.core.windows.net`;\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { RetryPolicy } from '../types/RetryPolicy.js';
|
|
2
|
-
/**
|
|
3
|
-
* A manager that handles the retry logic.
|
|
4
|
-
*/
|
|
5
|
-
export declare class RetryManager {
|
|
6
|
-
private readonly policies;
|
|
7
|
-
constructor(policies: RetryPolicy[]);
|
|
8
|
-
private findPolicy;
|
|
9
|
-
private sleep;
|
|
10
|
-
/**
|
|
11
|
-
* If the operation call fails and there is an applicable retry policy, it will retry the operation.
|
|
12
|
-
* @param operation The operation to call. The retry context is passed to the operation if it is in retry.
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
retry<T>(operation: (retryContext?: {
|
|
16
|
-
retryAttempt: number;
|
|
17
|
-
maxRetries: number;
|
|
18
|
-
}) => Promise<T>): Promise<T>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=RetryManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RetryManager.d.ts","sourceRoot":"","sources":["../../src/retry/RetryManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,WAAW,EAAE;IAEpD,OAAO,CAAC,UAAU,CAOhB;IAEF,OAAO,CAAC,KAAK;IAIb;;;;OAIG;IACU,KAAK,CAAC,CAAC,EAClB,SAAS,EAAE,CAAC,YAAY,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GACrF,OAAO,CAAC,CAAC,CAAC;CAyBd"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A manager that handles the retry logic.
|
|
3
|
-
*/
|
|
4
|
-
export class RetryManager {
|
|
5
|
-
constructor(policies) {
|
|
6
|
-
this.policies = policies;
|
|
7
|
-
this.findPolicy = (error) => {
|
|
8
|
-
for (const policy of this.policies) {
|
|
9
|
-
if (policy.handle(error)) {
|
|
10
|
-
return policy;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
sleep(ms) {
|
|
17
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* If the operation call fails and there is an applicable retry policy, it will retry the operation.
|
|
21
|
-
* @param operation The operation to call. The retry context is passed to the operation if it is in retry.
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
async retry(operation) {
|
|
25
|
-
let retryAttempt = 0;
|
|
26
|
-
let previousPolicy = undefined;
|
|
27
|
-
do {
|
|
28
|
-
try {
|
|
29
|
-
const retryContext = previousPolicy ? { retryAttempt, maxRetries: previousPolicy.maxRetries } : undefined;
|
|
30
|
-
return await operation(retryContext);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
const policy = this.findPolicy(e);
|
|
34
|
-
if (previousPolicy !== policy) {
|
|
35
|
-
retryAttempt = 0;
|
|
36
|
-
previousPolicy = policy;
|
|
37
|
-
}
|
|
38
|
-
if (!policy || retryAttempt++ >= policy.maxRetries) {
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
await this.sleep(policy.wait(retryAttempt));
|
|
42
|
-
}
|
|
43
|
-
// eslint-disable-next-line no-constant-condition
|
|
44
|
-
} while (true);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=RetryManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RetryManager.js","sourceRoot":"","sources":["../../src/retry/RetryManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;QAE5C,eAAU,GAAG,CAAC,KAAc,EAA2B,EAAE;YAC/D,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;gBAClC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBACxB,OAAO,MAAM,CAAC;iBACf;aACF;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;IATqD,CAAC;IAWhD,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAK,CAChB,SAAsF;QAEtF,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,cAAc,GAA4B,SAAS,CAAC;QAExD,GAAG;YACD,IAAI;gBACF,MAAM,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;gBAE1G,OAAO,MAAM,SAAS,CAAC,YAAY,CAAC,CAAC;aACtC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,cAAc,KAAK,MAAM,EAAE;oBAC7B,YAAY,GAAG,CAAC,CAAC;oBACjB,cAAc,GAAG,MAAM,CAAC;iBACzB;gBAED,IAAI,CAAC,MAAM,IAAI,YAAY,EAAE,IAAI,MAAM,CAAC,UAAU,EAAE;oBAClD,MAAM,CAAC,CAAC;iBACT;gBAED,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;aAC7C;YACD,iDAAiD;SAClD,QAAQ,IAAI,EAAE;IACjB,CAAC;CACF","sourcesContent":["import type { RetryPolicy } from '../types/RetryPolicy.js';\n\n/**\n * A manager that handles the retry logic.\n */\nexport class RetryManager {\n constructor(private readonly policies: RetryPolicy[]) {}\n\n private findPolicy = (error: unknown): RetryPolicy | undefined => {\n for (const policy of this.policies) {\n if (policy.handle(error)) {\n return policy;\n }\n }\n return undefined;\n };\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * If the operation call fails and there is an applicable retry policy, it will retry the operation.\n * @param operation The operation to call. The retry context is passed to the operation if it is in retry.\n * @returns\n */\n public async retry<T>(\n operation: (retryContext?: { retryAttempt: number; maxRetries: number }) => Promise<T>,\n ): Promise<T> {\n let retryAttempt = 0;\n let previousPolicy: RetryPolicy | undefined = undefined;\n\n do {\n try {\n const retryContext = previousPolicy ? { retryAttempt, maxRetries: previousPolicy.maxRetries } : undefined;\n\n return await operation(retryContext);\n } catch (e) {\n const policy = this.findPolicy(e);\n if (previousPolicy !== policy) {\n retryAttempt = 0;\n previousPolicy = policy;\n }\n\n if (!policy || retryAttempt++ >= policy.maxRetries) {\n throw e;\n }\n\n await this.sleep(policy.wait(retryAttempt));\n }\n // eslint-disable-next-line no-constant-condition\n } while (true);\n }\n}\n"]}
|