@memberjunction/storage 0.9.4

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.
@@ -0,0 +1,11 @@
1
+ import { CreatePreAuthUploadUrlPayload, FileStorageBase } from '../generic/FileStorageBase';
2
+ export declare class AzureFileStorage extends FileStorageBase {
3
+ private _sharedKeyCredential;
4
+ private _container;
5
+ private _accountName;
6
+ constructor();
7
+ CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
8
+ CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
9
+ DeleteObject(objectName: string): Promise<boolean>;
10
+ }
11
+ //# sourceMappingURL=AzureFileStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureFileStorage.d.ts","sourceRoot":"","sources":["../../src/drivers/AzureFileStorage.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE5F,qBACa,gBAAiB,SAAQ,eAAe;IACnD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;;IAYtB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBlF,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBvD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAMhE"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.AzureFileStorage = void 0;
36
+ const storage_blob_1 = require("@azure/storage-blob");
37
+ const global_1 = require("@memberjunction/global");
38
+ const env = __importStar(require("env-var"));
39
+ const FileStorageBase_1 = require("../generic/FileStorageBase");
40
+ let AzureFileStorage = class AzureFileStorage extends FileStorageBase_1.FileStorageBase {
41
+ constructor() {
42
+ super();
43
+ this._container = env.get('STORAGE_AZURE_CONTAINER').required().asString();
44
+ this._accountName = env.get('STORAGE_AZURE_ACCOUNT_NAME').required().asString();
45
+ const accountKey = env.get('STORAGE_AZURE_ACCOUNT_KEY').required().asString();
46
+ this._sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(this._accountName, accountKey);
47
+ }
48
+ CreatePreAuthUploadUrl(objectName) {
49
+ const sasOptions = {
50
+ services: storage_blob_1.AccountSASServices.parse('b').toString(), // blobs
51
+ resourceTypes: storage_blob_1.AccountSASResourceTypes.parse('o').toString(), // object
52
+ permissions: storage_blob_1.AccountSASPermissions.parse('w'), // write-only permissions
53
+ protocol: storage_blob_1.SASProtocol.Https,
54
+ startsOn: new Date(),
55
+ expiresOn: new Date(new Date().valueOf() + 10 * 60 * 1000), // 10 minutes
56
+ };
57
+ // Using the SAS url to upload e.g.
58
+ // curl -H "x-ms-blob-type: BlockBlob" --upload-file 1236.txt --url "https://bccdpfiles.blob.core.windows.net/ca-temp/1236.txt?sv=2023-11-03&ss=btqf&srt=sco&spr=https&st=2024-03-18T15%3A59%3A19Z&se=2024-03-18T16%3A09%3A19Z&sp=rwdlacupi&sig=Vu68WUzRmVDsTLXpFvRUKiZVQgjWtds1FFiRDXiwtug%3D"
59
+ const sasToken = (0, storage_blob_1.generateAccountSASQueryParameters)(sasOptions, this._sharedKeyCredential).toString();
60
+ const queryString = sasToken[0] === '?' ? sasToken : `?${sasToken}`;
61
+ const UploadUrl = `https://${this._accountName}.blob.core.windows.net/${this._container}/${objectName}${queryString}`;
62
+ return Promise.resolve({ UploadUrl });
63
+ }
64
+ CreatePreAuthDownloadUrl(objectName) {
65
+ const sasOptions = {
66
+ services: storage_blob_1.AccountSASServices.parse('b').toString(), // blobs
67
+ resourceTypes: storage_blob_1.AccountSASResourceTypes.parse('o').toString(), // object
68
+ permissions: storage_blob_1.AccountSASPermissions.parse('r'), // read-only permissions
69
+ protocol: storage_blob_1.SASProtocol.Https,
70
+ startsOn: new Date(),
71
+ expiresOn: new Date(new Date().valueOf() + 10 * 60 * 1000), // 10 minutes
72
+ };
73
+ const sasToken = (0, storage_blob_1.generateAccountSASQueryParameters)(sasOptions, this._sharedKeyCredential).toString();
74
+ const queryString = sasToken[0] === '?' ? sasToken : `?${sasToken}`;
75
+ const url = `https://${this._accountName}.blob.core.windows.net/${this._container}/${objectName}${queryString}`;
76
+ return Promise.resolve(url);
77
+ }
78
+ async DeleteObject(objectName) {
79
+ const url = `https://${this._accountName}.blob.core.windows.net/${this._container}/${objectName}`;
80
+ const blobClient = new storage_blob_1.BlobClient(url, this._sharedKeyCredential);
81
+ const { succeeded } = await blobClient.deleteIfExists();
82
+ return succeeded;
83
+ }
84
+ };
85
+ exports.AzureFileStorage = AzureFileStorage;
86
+ exports.AzureFileStorage = AzureFileStorage = __decorate([
87
+ (0, global_1.RegisterClass)(FileStorageBase_1.FileStorageBase, 'Azure Blob Storage'),
88
+ __metadata("design:paramtypes", [])
89
+ ], AzureFileStorage);
90
+ //# sourceMappingURL=AzureFileStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureFileStorage.js","sourceRoot":"","sources":["../../src/drivers/AzureFileStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAS6B;AAC7B,mDAAuD;AACvD,6CAA+B;AAC/B,gEAA4F;AAGrF,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,iCAAe;IAKnD;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC3E,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QAChF,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QAE9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,yCAA0B,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC5F,CAAC;IAEM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4
+ };
5
+ /**
6
+ * Represents an abstract base class for file storage. Provides methods for creating pre-authorized upload and download URLs, as well as deleting objects. This
7
+ * interface is implemented in specific driver classes for each storage provider.
8
+ */
9
+ export declare abstract class FileStorageBase {
10
+ /**
11
+ * This method is designed to generate a pre-authenticated URL for uploading files to a storage provider. It abstracts over different storage providers,
12
+ * allowing for a unified interface to obtain upload URLs, regardless of the underlying provider's specifics. The method takes the name of the file (or
13
+ * object) you wish to upload as input and returns a Promise. This Promise, when resolved, provides a payload containing two key pieces of information:
14
+ *
15
+ * 1. `UploadUrl`: The URL to which the file should be uploaded. This URL is pre-authenticated, meaning it includes any necessary authentication tokens or
16
+ * signatures. The URL's format and the authentication method depend on the storage provider being used.
17
+ *
18
+ * 2. `ProviderKey` (optional): Some storage providers assign their own unique key or name to the uploaded object instead of using the name provided by the
19
+ * user. If the provider you are using does this, the `ProviderKey` will be included in the payload. This key can be useful for future reference to the
20
+ * object within the storage provider's system.
21
+ *
22
+ * @usage
23
+ *
24
+ * Suppose you have a file named "photo.jpg" that you want to upload to your storage provider. You would call this method with the object name "photo.jpg".
25
+ * After the Promise resolves, you will receive the upload URL and, if applicable, the provider's object key. You can then use this URL to upload your file
26
+ * directly to the storage provider.
27
+ *
28
+ * ```typescript
29
+ * const uploadPayload = await CreatePreAuthUploadUrl("photo.jpg");
30
+ * console.log(uploadPayload.UploadUrl); // Use this URL to upload your file
31
+ * if (uploadPayload.ProviderKey) {
32
+ * // If this is returned, use it as the `objectName` for `CreatePreAuthDownloadUrl` or `DeleteObject`
33
+ * console.log(uploadPayload.ProviderKey);
34
+ * }
35
+ * ```
36
+ *
37
+ * Note: This method is abstract and must be implemented by a subclass that specifies the logic for interacting with a specific storage provider.
38
+ *
39
+ * @param objectName - The name of the object or file to be uploaded. This name is used by the storage provider and may also be included in the
40
+ * pre-authenticated URL.
41
+ * @returns A Promise that resolves to a payload containing the upload URL and, optionally, the provider's object key. This payload allows you to proceed with
42
+ * uploading your file to the storage provider.
43
+ */
44
+ abstract CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
45
+ /**
46
+ * This abstract method is designed to generate a pre-authenticated URL that allows for the downloading of files or objects from a storage provider. Being
47
+ * abstract, it requires implementation in a subclass tailored to the specifics of the storage provider you're using. This method abstracts the process of
48
+ * generating download URLs across different storage providers, offering a unified interface for obtaining these URLs.
49
+ *
50
+ * When you call this method with the name of the file or object you wish to download, it initiates a process to create a URL. This URL is not just any link;
51
+ * it is pre-authenticated. This means it includes any necessary authentication tokens or signatures directly in the URL, allowing for secure access without
52
+ * requiring additional authentication steps at the time of download. The format of the URL and the authentication method depend on the storage provider.
53
+ *
54
+ * @usage
55
+ *
56
+ * Suppose you have a file named "report.pdf" stored in your cloud storage, and you want to generate a URL to download this file. You would call this method
57
+ * with the object name "report.pdf". After the Promise resolves, you will receive a URL that is ready to use for downloading the file.
58
+ *
59
+ * ```typescript
60
+ * const downloadUrl = await CreatePreAuthDownloadUrl("report.pdf");
61
+ * console.log(downloadUrl); // Use this URL to download your file directly
62
+ * ```
63
+ *
64
+ * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the `objectName` instead of the object's natural name.
65
+ *
66
+ * ```typescript
67
+ * const downloadUrl = await CreatePreAuthDownloadUrl(file.ProviderKey);
68
+ * console.log(downloadUrl); // Use this URL to download your file directly
69
+ * ```
70
+ *
71
+ * This method simplifies the process of securely sharing or accessing files stored in cloud storage by providing a direct, pre-authenticated link to the
72
+ * file. It's particularly useful in applications where files need to be accessed or shared without navigating through the storage provider's standard
73
+ * authentication flow each time.
74
+ *
75
+ * Note: Since this method is abstract, you must implement it in a subclass that defines the specific interactions with your chosen storage provider.
76
+ *
77
+ * @param objectName - The name of the object or file for which you want to generate a download URL. This is the name as it is known to the storage provider,
78
+ * and it will be used to locate the file and generate the URL.
79
+ * @returns A Promise that resolves to a string, which is the pre-authenticated download URL for the specified object or file. This URL can be used
80
+ * immediately for downloading the file without further authentication.
81
+ */
82
+ abstract CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
83
+ /**
84
+ * This abstract method is designed for deleting an object or file from a storage provider's system. Being abstract, it requires concrete implementation in
85
+ * subclasses that are tailored to interact with specific storage providers. The method aims to provide a unified interface for object deletion across
86
+ * different storage providers, simplifying the deletion process regardless of the underlying provider's specifics.
87
+ *
88
+ * When invoking this method, you need to specify the name of the object you wish to delete. This name should match exactly as it is known to the storage
89
+ * provider, ensuring the correct object is targeted for deletion.
90
+ *
91
+ * The method returns a Promise that, when resolved, indicates the success or failure of the deletion operation. A resolved value of `true` means the object
92
+ * was successfully deleted, while `false` indicates a failure to delete the object. It's important to handle both outcomes to ensure your application can
93
+ * respond appropriately to the deletion operation's result.
94
+ *
95
+ * @usage
96
+ *
97
+ * Suppose you have a file named "old_report.pdf" that is no longer needed and you want to delete it from your cloud storage. You would call this method with
98
+ * the object name "old_report.pdf". After the Promise resolves, you can check the result to confirm the deletion.
99
+ *
100
+ * ```typescript
101
+ * DeleteObject("old_report.pdf").then((isDeleted) => {
102
+ * if (isDeleted) {
103
+ * console.log("The file was successfully deleted.");
104
+ * } else {
105
+ * console.log("Failed to delete the file. It may not exist or there was an error in the deletion process.");
106
+ * }
107
+ * });
108
+ * ```
109
+ *
110
+ * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the `objectName` instead of the object's natural name.
111
+ *
112
+ * ```typescript
113
+ * DeleteObject(file.ProviderKey).then((isDeleted) => {
114
+ * if (isDeleted) {
115
+ * console.log("The file was successfully deleted.");
116
+ * } else {
117
+ * console.log("Failed to delete the file. It may not exist or there was an error in the deletion process.");
118
+ * }
119
+ * });
120
+ * ```
121
+ *
122
+ * Note: Since this method is abstract, it must be implemented in a subclass that defines the specific logic for interacting with your chosen storage
123
+ * provider. This implementation should handle the intricacies of the deletion process, including any authentication and authorization required by the storage
124
+ * provider.
125
+ *
126
+ * @param objectName - The name of the object or file to be deleted. This is the identifier used by the storage provider to locate the object for deletion.
127
+ * @returns A Promise that resolves to a boolean value. `true` indicates that the object was successfully deleted, while `false` indicates a failure in the
128
+ * deletion process.
129
+ */
130
+ abstract DeleteObject(objectName: string): Promise<boolean>;
131
+ }
132
+ //# sourceMappingURL=FileStorageBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileStorageBase.d.ts","sourceRoot":"","sources":["../../src/generic/FileStorageBase.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF;;;GAGG;AACH,8BAAsB,eAAe;IACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;aACa,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAElG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;aACa,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;aACa,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CACnE"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileStorageBase = void 0;
4
+ /**
5
+ * Represents an abstract base class for file storage. Provides methods for creating pre-authorized upload and download URLs, as well as deleting objects. This
6
+ * interface is implemented in specific driver classes for each storage provider.
7
+ */
8
+ class FileStorageBase {
9
+ }
10
+ exports.FileStorageBase = FileStorageBase;
11
+ //# sourceMappingURL=FileStorageBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileStorageBase.js","sourceRoot":"","sources":["../../src/generic/FileStorageBase.ts"],"names":[],"mappings":";;;AAKA;;;GAGG;AACH,MAAsB,eAAe;CA4HpC;AA5HD,0CA4HC"}
@@ -0,0 +1,4 @@
1
+ export * from './drivers/AzureFileStorage';
2
+ export * from './generic/FileStorageBase';
3
+ export * from './util';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,QAAQ,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./drivers/AzureFileStorage"), exports);
18
+ __exportStar(require("./generic/FileStorageBase"), exports);
19
+ __exportStar(require("./util"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,4DAA0C;AAC1C,yCAAuB"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { FileStorageProviderEntity } from '@memberjunction/core-entities';
2
+ /**
3
+ * Creates an upload URL for a file in the specified file storage provider. Infers ContentType based on the file name, enforces a specific `Status` and may set
4
+ * the `ProviderKey` value, dependening on the underlying file storage provider.
5
+ *
6
+ * @param providerEntity - The file storage provider entity.
7
+ * @param input - The input object containing the file details.
8
+ * @returns A promise that resolves to an object with the updated input and the upload URL.
9
+ */
10
+ export declare const createUploadUrl: <TInput extends {
11
+ ID: number;
12
+ Name: string;
13
+ ProviderID: number;
14
+ ContentType?: string;
15
+ ProviderKey?: string;
16
+ }>(providerEntity: FileStorageProviderEntity, input: TInput) => Promise<{
17
+ updatedInput: TInput & {
18
+ Status: string;
19
+ ContentType: string;
20
+ };
21
+ UploadUrl: string;
22
+ }>;
23
+ /**
24
+ * Creates a pre-authorized download URL for a file from the specified file storage provider.
25
+ *
26
+ * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
27
+ * @param {string | number} providerKeyOrID - The provider key or ID for the file to download.
28
+ * @returns {Promise<string>} - The pre-authorized download URL.
29
+ */
30
+ export declare const createDownloadUrl: (providerEntity: FileStorageProviderEntity, providerKeyOrID: string | number) => Promise<string>;
31
+ /**
32
+ * Delete a previously uploaded file from the specified file storage provider.
33
+ *
34
+ * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
35
+ * @param {string | number} providerKeyOrID - The provider key or ID for the file to delete.
36
+ * @returns {Promise<boolean>} - The success of he delete operation.
37
+ */
38
+ export declare const deleteObject: (providerEntity: FileStorageProviderEntity, providerKeyOrID: string | number) => Promise<boolean>;
39
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAK1E;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;QACL,MAAM;UAAQ,MAAM;gBAAc,MAAM;kBAAgB,MAAM;kBAAgB,MAAM;mBAEzF,yBAAyB;;gBAGR,MAAM;qBAAe,MAAM;;eACjD,MAAM;EAclB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,mBAA0B,yBAAyB,mBAAmB,MAAM,GAAG,MAAM,KAAG,QAAQ,MAAM,CAGnI,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,mBAAoB,yBAAyB,mBAAmB,MAAM,GAAG,MAAM,qBAGvG,CAAC"}
package/dist/util.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deleteObject = exports.createDownloadUrl = exports.createUploadUrl = void 0;
7
+ const global_1 = require("@memberjunction/global");
8
+ const mime_types_1 = __importDefault(require("mime-types"));
9
+ const FileStorageBase_1 = require("./generic/FileStorageBase");
10
+ /**
11
+ * Creates an upload URL for a file in the specified file storage provider. Infers ContentType based on the file name, enforces a specific `Status` and may set
12
+ * the `ProviderKey` value, dependening on the underlying file storage provider.
13
+ *
14
+ * @param providerEntity - The file storage provider entity.
15
+ * @param input - The input object containing the file details.
16
+ * @returns A promise that resolves to an object with the updated input and the upload URL.
17
+ */
18
+ const createUploadUrl = async (providerEntity, input) => {
19
+ const { ID, ProviderID } = input;
20
+ const ContentType = input.ContentType ?? mime_types_1.default.lookup(input.Name) ?? 'application/octet-stream';
21
+ const Status = 'Uploading';
22
+ await providerEntity.Load(ProviderID);
23
+ const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
24
+ const { UploadUrl, ...maybeProviderKey } = await driver.CreatePreAuthUploadUrl(String(ID));
25
+ const updatedInput = { ...input, ...maybeProviderKey, ContentType, Status };
26
+ return { updatedInput, UploadUrl };
27
+ };
28
+ exports.createUploadUrl = createUploadUrl;
29
+ /**
30
+ * Creates a pre-authorized download URL for a file from the specified file storage provider.
31
+ *
32
+ * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
33
+ * @param {string | number} providerKeyOrID - The provider key or ID for the file to download.
34
+ * @returns {Promise<string>} - The pre-authorized download URL.
35
+ */
36
+ const createDownloadUrl = async (providerEntity, providerKeyOrID) => {
37
+ const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
38
+ return driver.CreatePreAuthDownloadUrl(String(providerKeyOrID));
39
+ };
40
+ exports.createDownloadUrl = createDownloadUrl;
41
+ /**
42
+ * Delete a previously uploaded file from the specified file storage provider.
43
+ *
44
+ * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
45
+ * @param {string | number} providerKeyOrID - The provider key or ID for the file to delete.
46
+ * @returns {Promise<boolean>} - The success of he delete operation.
47
+ */
48
+ const deleteObject = (providerEntity, providerKeyOrID) => {
49
+ const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
50
+ return driver.DeleteObject(String(providerKeyOrID));
51
+ };
52
+ exports.deleteObject = deleteObject;
53
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AACA,mDAAkD;AAClD,4DAA8B;AAC9B,+DAA4D;AAE5D;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,KAAK,EAGlC,cAAyC,EACzC,KAAa,EAIZ,EAAE;IACH,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAEjC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,oBAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC;IAC/F,MAAM,MAAM,GAAG,WAAW,CAAC;IAE3B,MAAM,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAE/H,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3F,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IAE5E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,eAAe,mBAqB1B;AAEF;;;;;;GAMG;AACI,MAAM,iBAAiB,GAAG,KAAK,EAAE,cAAyC,EAAE,eAAgC,EAAmB,EAAE;IACtI,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAC/H,OAAO,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC;AAHW,QAAA,iBAAiB,qBAG5B;AAEF;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAC,cAAyC,EAAE,eAAgC,EAAE,EAAE;IAC1G,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAC/H,OAAO,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAHW,QAAA,YAAY,gBAGvB"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@memberjunction/storage",
3
+ "version": "0.9.4",
4
+ "description": "This library provides a set of objects that handle the interface between the server-side API and various cloud storage providers.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "start": "ts-node-dev src/index.ts",
12
+ "build": "tsc",
13
+ "watch": "tsc -w",
14
+ "test": "echo \"Error: no test specified\" && exit 1"
15
+ },
16
+ "author": "MemberJunction.com",
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "ts-node-dev": "^2.0.0",
20
+ "typescript": "^5.3.3"
21
+ },
22
+ "dependencies": {
23
+ "@azure/identity": "^4.0.1",
24
+ "@azure/storage-blob": "^12.17.0",
25
+ "@memberjunction/core": "^0.9.174",
26
+ "@memberjunction/core-entities": "^0.9.159",
27
+ "@memberjunction/global": "^0.9.155",
28
+ "env-var": "^7.3.0",
29
+ "mime-types": "^2.1.35"
30
+ }
31
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # @memberjunction/storage
2
+
3
+ The `@memberjunction/storage` library provides a set of objects that handle the interface between the server-side API and various cloud storage providers.