@flusys/nestjs-storage 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/index.d.ts +3 -3
- package/controllers/file-manager.controller.d.ts +4 -4
- package/controllers/folder.controller.d.ts +2 -2
- package/controllers/index.d.ts +4 -4
- package/controllers/storage-config.controller.d.ts +2 -2
- package/controllers/upload.controller.d.ts +3 -3
- package/docs/index.d.ts +1 -1
- package/docs/storage-swagger.config.d.ts +2 -2
- package/dtos/index.d.ts +4 -4
- package/entities/file-manager-with-company.entity.d.ts +2 -2
- package/entities/file-manager.entity.d.ts +1 -1
- package/entities/folder-with-company.entity.d.ts +1 -1
- package/entities/index.d.ts +15 -15
- package/entities/storage-config-with-company.entity.d.ts +1 -1
- package/enums/index.d.ts +1 -1
- package/fesm/493.js +2768 -0
- package/fesm/537.js +1157 -0
- package/fesm/562.js +786 -0
- package/fesm/{providers/azure-provider.optional.js → chunks/190.js} +33 -30
- package/fesm/chunks/252.js +12 -0
- package/fesm/chunks/327.js +12 -0
- package/fesm/chunks/385.js +12 -0
- package/fesm/{providers/s3-provider.optional.js → chunks/591.js} +37 -34
- package/fesm/chunks/746.js +12 -0
- package/fesm/chunks/798.js +12 -0
- package/fesm/{providers/sftp-provider.optional.js → chunks/918.js} +35 -31
- package/fesm/config/index.js +119 -3
- package/fesm/controllers/index.js +16 -4
- package/fesm/docs/index.js +206 -1
- package/fesm/dtos/index.js +879 -4
- package/fesm/entities/index.js +463 -18
- package/fesm/enums/index.js +36 -1
- package/fesm/index.js +398 -12
- package/fesm/interfaces/index.js +19 -5
- package/fesm/modules/index.js +16 -1
- package/fesm/providers/index.js +364 -3
- package/fesm/runtime.js +252 -0
- package/fesm/services/index.js +16 -6
- package/fesm/utils/index.js +149 -1
- package/index.d.ts +11 -11
- package/interfaces/file-manager.interface.d.ts +1 -1
- package/interfaces/folder.interface.d.ts +1 -1
- package/interfaces/index.d.ts +5 -5
- package/interfaces/storage-config.interface.d.ts +1 -1
- package/interfaces/storage-module-options.interface.d.ts +3 -3
- package/interfaces/storage-provider.interface.d.ts +1 -1
- package/middlewares/file-serve.middleware.d.ts +4 -3
- package/middlewares/index.d.ts +1 -1
- package/modules/index.d.ts +1 -1
- package/modules/storage.module.d.ts +2 -2
- package/package.json +30 -41
- package/providers/azure-provider.optional.d.ts +2 -2
- package/providers/index.d.ts +3 -3
- package/providers/local-provider.d.ts +2 -2
- package/providers/s3-provider.optional.d.ts +2 -2
- package/providers/sftp-provider.optional.d.ts +2 -2
- package/providers/storage-factory.service.d.ts +3 -3
- package/providers/storage-provider.registry.d.ts +2 -2
- package/services/file-manager.service.d.ts +9 -8
- package/services/folder.service.d.ts +6 -6
- package/services/index.d.ts +6 -6
- package/services/storage-config.service.d.ts +3 -3
- package/services/storage-datasource.provider.d.ts +3 -3
- package/services/storage-provider-config.service.d.ts +7 -7
- package/services/upload.service.d.ts +6 -6
- package/utils/image-compressor.util.d.ts +1 -1
- package/utils/index.d.ts +1 -1
- package/cjs/config/event-actions.js +0 -34
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -46
- package/cjs/config/storage.constants.js +0 -28
- package/cjs/controllers/file-manager.controller.js +0 -152
- package/cjs/controllers/file-manager.controller.spec.js +0 -135
- package/cjs/controllers/folder.controller.js +0 -102
- package/cjs/controllers/folder.controller.spec.js +0 -86
- package/cjs/controllers/index.js +0 -21
- package/cjs/controllers/storage-config.controller.js +0 -102
- package/cjs/controllers/storage-config.controller.spec.js +0 -85
- package/cjs/controllers/upload.controller.js +0 -234
- package/cjs/controllers/upload.controller.spec.js +0 -132
- package/cjs/docs/index.js +0 -11
- package/cjs/docs/storage-swagger.config.js +0 -188
- package/cjs/docs/storage-swagger.config.spec.js +0 -72
- package/cjs/dtos/file-manager.dto.js +0 -327
- package/cjs/dtos/folder.dto.js +0 -105
- package/cjs/dtos/index.js +0 -21
- package/cjs/dtos/storage-config.dto.js +0 -170
- package/cjs/dtos/upload.dto.js +0 -272
- package/cjs/entities/file-manager-with-company.entity.js +0 -61
- package/cjs/entities/file-manager.entity.js +0 -122
- package/cjs/entities/folder-with-company.entity.js +0 -55
- package/cjs/entities/folder.entity.js +0 -64
- package/cjs/entities/index.js +0 -63
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/entities/storage-config-with-company.entity.js +0 -51
- package/cjs/entities/storage-config.entity.js +0 -96
- package/cjs/enums/file-location.enum.js +0 -17
- package/cjs/enums/index.js +0 -18
- package/cjs/index.js +0 -29
- package/cjs/interfaces/file-manager.interface.js +0 -4
- package/cjs/interfaces/folder.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -22
- package/cjs/interfaces/storage-config.interface.js +0 -4
- package/cjs/interfaces/storage-module-options.interface.js +0 -4
- package/cjs/interfaces/storage-provider.interface.js +0 -4
- package/cjs/middlewares/file-serve.middleware.js +0 -241
- package/cjs/middlewares/file-serve.middleware.spec.js +0 -211
- package/cjs/middlewares/index.js +0 -18
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/storage.module.js +0 -165
- package/cjs/modules/storage.module.spec.js +0 -184
- package/cjs/providers/azure-provider.optional.js +0 -155
- package/cjs/providers/azure-provider.optional.spec.js +0 -228
- package/cjs/providers/index.js +0 -26
- package/cjs/providers/local-provider.js +0 -230
- package/cjs/providers/local-provider.spec.js +0 -239
- package/cjs/providers/s3-provider.optional.js +0 -175
- package/cjs/providers/s3-provider.optional.spec.js +0 -243
- package/cjs/providers/sftp-provider.optional.js +0 -203
- package/cjs/providers/sftp-provider.optional.spec.js +0 -217
- package/cjs/providers/storage-factory.service.js +0 -175
- package/cjs/providers/storage-factory.service.spec.js +0 -253
- package/cjs/providers/storage-provider.registry.js +0 -41
- package/cjs/providers/storage-provider.registry.spec.js +0 -67
- package/cjs/services/file-manager.service.js +0 -387
- package/cjs/services/file-manager.service.spec.js +0 -580
- package/cjs/services/folder.service.js +0 -101
- package/cjs/services/folder.service.spec.js +0 -167
- package/cjs/services/index.js +0 -23
- package/cjs/services/storage-config.service.js +0 -129
- package/cjs/services/storage-config.service.spec.js +0 -257
- package/cjs/services/storage-datasource.provider.js +0 -137
- package/cjs/services/storage-datasource.provider.spec.js +0 -217
- package/cjs/services/storage-provider-config.service.js +0 -171
- package/cjs/services/storage-provider-config.service.spec.js +0 -265
- package/cjs/services/upload.service.js +0 -376
- package/cjs/services/upload.service.spec.js +0 -426
- package/cjs/utils/file-validator.util.js +0 -440
- package/cjs/utils/file-validator.util.spec.js +0 -259
- package/cjs/utils/image-compressor.util.js +0 -162
- package/cjs/utils/image-compressor.util.spec.js +0 -166
- package/cjs/utils/index.js +0 -18
- package/fesm/config/event-actions.js +0 -13
- package/fesm/config/message-keys.js +0 -22
- package/fesm/config/storage.constants.js +0 -7
- package/fesm/controllers/file-manager.controller.js +0 -142
- package/fesm/controllers/file-manager.controller.spec.js +0 -131
- package/fesm/controllers/folder.controller.js +0 -92
- package/fesm/controllers/folder.controller.spec.js +0 -82
- package/fesm/controllers/storage-config.controller.js +0 -92
- package/fesm/controllers/storage-config.controller.spec.js +0 -81
- package/fesm/controllers/upload.controller.js +0 -224
- package/fesm/controllers/upload.controller.spec.js +0 -128
- package/fesm/docs/storage-swagger.config.js +0 -181
- package/fesm/docs/storage-swagger.config.spec.js +0 -68
- package/fesm/dtos/file-manager.dto.js +0 -300
- package/fesm/dtos/folder.dto.js +0 -84
- package/fesm/dtos/storage-config.dto.js +0 -149
- package/fesm/dtos/upload.dto.js +0 -245
- package/fesm/entities/file-manager-with-company.entity.js +0 -51
- package/fesm/entities/file-manager.entity.js +0 -112
- package/fesm/entities/folder-with-company.entity.js +0 -45
- package/fesm/entities/folder.entity.js +0 -54
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/entities/storage-config-with-company.entity.js +0 -41
- package/fesm/entities/storage-config.entity.js +0 -86
- package/fesm/enums/file-location.enum.js +0 -7
- package/fesm/interfaces/file-manager.interface.js +0 -1
- package/fesm/interfaces/folder.interface.js +0 -1
- package/fesm/interfaces/storage-config.interface.js +0 -1
- package/fesm/interfaces/storage-module-options.interface.js +0 -3
- package/fesm/interfaces/storage-provider.interface.js +0 -4
- package/fesm/middlewares/file-serve.middleware.js +0 -190
- package/fesm/middlewares/file-serve.middleware.spec.js +0 -207
- package/fesm/middlewares/index.js +0 -1
- package/fesm/modules/storage.module.js +0 -156
- package/fesm/modules/storage.module.spec.js +0 -180
- package/fesm/providers/azure-provider.optional.spec.js +0 -224
- package/fesm/providers/local-provider.js +0 -182
- package/fesm/providers/local-provider.spec.js +0 -194
- package/fesm/providers/s3-provider.optional.spec.js +0 -239
- package/fesm/providers/sftp-provider.optional.spec.js +0 -213
- package/fesm/providers/storage-factory.service.js +0 -124
- package/fesm/providers/storage-factory.service.spec.js +0 -249
- package/fesm/providers/storage-provider.registry.js +0 -34
- package/fesm/providers/storage-provider.registry.spec.js +0 -63
- package/fesm/services/file-manager.service.js +0 -336
- package/fesm/services/file-manager.service.spec.js +0 -576
- package/fesm/services/folder.service.js +0 -91
- package/fesm/services/folder.service.spec.js +0 -163
- package/fesm/services/storage-config.service.js +0 -119
- package/fesm/services/storage-config.service.spec.js +0 -253
- package/fesm/services/storage-datasource.provider.js +0 -86
- package/fesm/services/storage-datasource.provider.spec.js +0 -172
- package/fesm/services/storage-provider-config.service.js +0 -161
- package/fesm/services/storage-provider-config.service.spec.js +0 -261
- package/fesm/services/upload.service.js +0 -366
- package/fesm/services/upload.service.spec.js +0 -422
- package/fesm/utils/file-validator.util.js +0 -433
- package/fesm/utils/file-validator.util.spec.js +0 -255
- package/fesm/utils/image-compressor.util.js +0 -114
- package/fesm/utils/image-compressor.util.spec.js +0 -162
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _storagemodule = require("./storage.module");
|
|
6
|
-
const _storageconstants = require("../config/storage.constants");
|
|
7
|
-
const _controllers = require("../controllers");
|
|
8
|
-
const _middlewares = require("../middlewares");
|
|
9
|
-
function _define_property(obj, key, value) {
|
|
10
|
-
if (key in obj) {
|
|
11
|
-
Object.defineProperty(obj, key, {
|
|
12
|
-
value: value,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
obj[key] = value;
|
|
19
|
-
}
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
22
|
-
function providerTokens(providers) {
|
|
23
|
-
return providers.map((p)=>typeof p === 'function' ? p : p.provide);
|
|
24
|
-
}
|
|
25
|
-
describe('StorageModule', ()=>{
|
|
26
|
-
describe('forRoot', ()=>{
|
|
27
|
-
it('should default to a non-global module with all controllers registered', ()=>{
|
|
28
|
-
const dynamicModule = _storagemodule.StorageModule.forRoot({});
|
|
29
|
-
expect(dynamicModule.module).toBe(_storagemodule.StorageModule);
|
|
30
|
-
expect(dynamicModule.global).toBe(false);
|
|
31
|
-
expect(dynamicModule.controllers).toEqual([
|
|
32
|
-
_controllers.FileManagerController,
|
|
33
|
-
_controllers.FolderController,
|
|
34
|
-
_controllers.StorageConfigController,
|
|
35
|
-
_controllers.UploadController
|
|
36
|
-
]);
|
|
37
|
-
});
|
|
38
|
-
it('should respect global: true', ()=>{
|
|
39
|
-
expect(_storagemodule.StorageModule.forRoot({
|
|
40
|
-
global: true
|
|
41
|
-
}).global).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
it('should register no controllers when includeController is false', ()=>{
|
|
44
|
-
expect(_storagemodule.StorageModule.forRoot({
|
|
45
|
-
includeController: false
|
|
46
|
-
}).controllers).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
it('should register controllers when includeController is anything other than exactly false', ()=>{
|
|
49
|
-
expect(_storagemodule.StorageModule.forRoot({
|
|
50
|
-
includeController: true
|
|
51
|
-
}).controllers).toHaveLength(4);
|
|
52
|
-
expect(_storagemodule.StorageModule.forRoot({}).controllers).toHaveLength(4);
|
|
53
|
-
});
|
|
54
|
-
it('should register a STORAGE_MODULE_OPTIONS provider carrying the given options', ()=>{
|
|
55
|
-
const options = {
|
|
56
|
-
bootstrapAppConfig: {
|
|
57
|
-
enableCompanyFeature: true
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const dynamicModule = _storagemodule.StorageModule.forRoot(options);
|
|
61
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === _storageconstants.STORAGE_MODULE_OPTIONS);
|
|
62
|
-
expect(provider.useValue).toBe(options);
|
|
63
|
-
});
|
|
64
|
-
it('should always export the same fixed set of services', ()=>{
|
|
65
|
-
const dynamicModule = _storagemodule.StorageModule.forRoot({});
|
|
66
|
-
expect(dynamicModule.exports).toHaveLength(7);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('forRootAsync', ()=>{
|
|
70
|
-
it('should forward external imports alongside CacheModule/UtilsModule', ()=>{
|
|
71
|
-
let FakeImportedModule = class FakeImportedModule {
|
|
72
|
-
};
|
|
73
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
74
|
-
bootstrapAppConfig: {},
|
|
75
|
-
imports: [
|
|
76
|
-
FakeImportedModule
|
|
77
|
-
]
|
|
78
|
-
});
|
|
79
|
-
expect(dynamicModule.imports).toEqual(expect.arrayContaining([
|
|
80
|
-
FakeImportedModule
|
|
81
|
-
]));
|
|
82
|
-
});
|
|
83
|
-
it('should register no controllers when includeController is false', ()=>{
|
|
84
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
85
|
-
bootstrapAppConfig: {},
|
|
86
|
-
includeController: false
|
|
87
|
-
});
|
|
88
|
-
expect(dynamicModule.controllers).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
it('useFactory: builds a STORAGE_MODULE_OPTIONS provider that merges resolved config into the static options', async ()=>{
|
|
91
|
-
const useFactory = jest.fn().mockResolvedValue({
|
|
92
|
-
maxFileSize: 1024
|
|
93
|
-
});
|
|
94
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
95
|
-
bootstrapAppConfig: {},
|
|
96
|
-
useFactory,
|
|
97
|
-
inject: [
|
|
98
|
-
'SOME_TOKEN'
|
|
99
|
-
]
|
|
100
|
-
});
|
|
101
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === _storageconstants.STORAGE_MODULE_OPTIONS);
|
|
102
|
-
expect(provider.inject).toEqual([
|
|
103
|
-
'SOME_TOKEN'
|
|
104
|
-
]);
|
|
105
|
-
const resolved = await provider.useFactory('injected');
|
|
106
|
-
expect(useFactory).toHaveBeenCalledWith('injected');
|
|
107
|
-
expect(resolved.config).toEqual({
|
|
108
|
-
maxFileSize: 1024
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it('useClass: registers both the class provider and an options provider calling createStorageOptions()', async ()=>{
|
|
112
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
113
|
-
constructor(){
|
|
114
|
-
_define_property(this, "createStorageOptions", jest.fn().mockResolvedValue({
|
|
115
|
-
maxFileSize: 2048
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
120
|
-
bootstrapAppConfig: {},
|
|
121
|
-
useClass: MyOptionsFactory
|
|
122
|
-
});
|
|
123
|
-
const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
|
|
124
|
-
expect(classProvider.useClass).toBe(MyOptionsFactory);
|
|
125
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _storageconstants.STORAGE_MODULE_OPTIONS);
|
|
126
|
-
const instance = new MyOptionsFactory();
|
|
127
|
-
const resolved = await optionsProvider.useFactory(instance);
|
|
128
|
-
expect(instance.createStorageOptions).toHaveBeenCalled();
|
|
129
|
-
expect(resolved.config).toEqual({
|
|
130
|
-
maxFileSize: 2048
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
it('useExisting: registers a single options provider without a duplicate class registration', async ()=>{
|
|
134
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
135
|
-
constructor(){
|
|
136
|
-
_define_property(this, "createStorageOptions", jest.fn().mockResolvedValue({
|
|
137
|
-
maxFileSize: 4096
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
142
|
-
bootstrapAppConfig: {},
|
|
143
|
-
useExisting: MyOptionsFactory
|
|
144
|
-
});
|
|
145
|
-
expect(dynamicModule.providers.filter((p)=>p.provide === MyOptionsFactory)).toHaveLength(0);
|
|
146
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _storageconstants.STORAGE_MODULE_OPTIONS);
|
|
147
|
-
expect(optionsProvider.inject).toEqual([
|
|
148
|
-
MyOptionsFactory
|
|
149
|
-
]);
|
|
150
|
-
});
|
|
151
|
-
it('should register no STORAGE_MODULE_OPTIONS provider when neither useFactory, useClass, nor useExisting is given', ()=>{
|
|
152
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
153
|
-
bootstrapAppConfig: {}
|
|
154
|
-
});
|
|
155
|
-
expect(providerTokens(dynamicModule.providers)).not.toContain(_storageconstants.STORAGE_MODULE_OPTIONS);
|
|
156
|
-
});
|
|
157
|
-
it('should still register the fixed exported services as providers alongside async options', ()=>{
|
|
158
|
-
const dynamicModule = _storagemodule.StorageModule.forRootAsync({
|
|
159
|
-
bootstrapAppConfig: {},
|
|
160
|
-
useFactory: jest.fn()
|
|
161
|
-
});
|
|
162
|
-
expect(dynamicModule.providers).toEqual(expect.arrayContaining([
|
|
163
|
-
...dynamicModule.exports
|
|
164
|
-
]));
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe('configure (NestModule)', ()=>{
|
|
168
|
-
it('should wire FileServeMiddleware to the file GET route', ()=>{
|
|
169
|
-
const forRoutes = jest.fn();
|
|
170
|
-
const apply = jest.fn().mockReturnValue({
|
|
171
|
-
forRoutes
|
|
172
|
-
});
|
|
173
|
-
const consumer = {
|
|
174
|
-
apply
|
|
175
|
-
};
|
|
176
|
-
new _storagemodule.StorageModule().configure(consumer);
|
|
177
|
-
expect(apply).toHaveBeenCalledWith(_middlewares.FileServeMiddleware);
|
|
178
|
-
expect(forRoutes).toHaveBeenCalledWith({
|
|
179
|
-
path: 'storage/upload/file/*',
|
|
180
|
-
method: expect.anything()
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optional Azure Blob Storage Provider
|
|
3
|
-
* Requires: npm install @azure/storage-blob
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports, "AzureProvider", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function() {
|
|
11
|
-
return AzureProvider;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
const _common = require("@nestjs/common");
|
|
15
|
-
const _constants = require("@flusys/nestjs-shared/constants");
|
|
16
|
-
const _uuid = require("uuid");
|
|
17
|
-
const _imagecompressorutil = require("../utils/image-compressor.util");
|
|
18
|
-
function _define_property(obj, key, value) {
|
|
19
|
-
if (key in obj) {
|
|
20
|
-
Object.defineProperty(obj, key, {
|
|
21
|
-
value: value,
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
obj[key] = value;
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
32
|
-
if (typeof WeakMap !== "function") return null;
|
|
33
|
-
var cacheBabelInterop = new WeakMap();
|
|
34
|
-
var cacheNodeInterop = new WeakMap();
|
|
35
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
36
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
37
|
-
})(nodeInterop);
|
|
38
|
-
}
|
|
39
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
40
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
44
|
-
return {
|
|
45
|
-
default: obj
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
49
|
-
if (cache && cache.has(obj)) {
|
|
50
|
-
return cache.get(obj);
|
|
51
|
-
}
|
|
52
|
-
var newObj = {
|
|
53
|
-
__proto__: null
|
|
54
|
-
};
|
|
55
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
56
|
-
for(var key in obj){
|
|
57
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
58
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
59
|
-
if (desc && (desc.get || desc.set)) {
|
|
60
|
-
Object.defineProperty(newObj, key, desc);
|
|
61
|
-
} else {
|
|
62
|
-
newObj[key] = obj[key];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
newObj.default = obj;
|
|
67
|
-
if (cache) {
|
|
68
|
-
cache.set(obj, newObj);
|
|
69
|
-
}
|
|
70
|
-
return newObj;
|
|
71
|
-
}
|
|
72
|
-
let AzureProvider = class AzureProvider {
|
|
73
|
-
async initialize(config) {
|
|
74
|
-
try {
|
|
75
|
-
const { BlobServiceClient, StorageSharedKeyCredential } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("@azure/storage-blob")));
|
|
76
|
-
this.accountName = config.accountName;
|
|
77
|
-
this.containerName = config.containerName;
|
|
78
|
-
this.blobServiceClient = config.connectionString ? BlobServiceClient.fromConnectionString(config.connectionString) : new BlobServiceClient(`https://${config.accountName}.blob.core.windows.net`, new StorageSharedKeyCredential(config.accountName, config.accountKey));
|
|
79
|
-
this.containerClient = this.blobServiceClient.getContainerClient(config.containerName);
|
|
80
|
-
await this.containerClient.createIfNotExists();
|
|
81
|
-
} catch {
|
|
82
|
-
throw new _common.InternalServerErrorException({
|
|
83
|
-
message: 'Azure Storage SDK not found',
|
|
84
|
-
messageKey: _constants.SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
|
|
85
|
-
messageVariables: {
|
|
86
|
-
sdk: '@azure/storage-blob'
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async uploadFile(file, options) {
|
|
92
|
-
let processedBuffer = file.buffer;
|
|
93
|
-
let contentType = file.mimetype;
|
|
94
|
-
const fileName = `${(0, _uuid.v4)()}-${file.originalname}`;
|
|
95
|
-
if (options.compress && file.mimetype.startsWith('image/')) {
|
|
96
|
-
const result = await _imagecompressorutil.ImageCompressor.compress(file.buffer, file.mimetype, {
|
|
97
|
-
maxWidth: options.maxWidth,
|
|
98
|
-
maxHeight: options.maxHeight,
|
|
99
|
-
quality: options.quality,
|
|
100
|
-
format: options.format
|
|
101
|
-
});
|
|
102
|
-
processedBuffer = result.buffer;
|
|
103
|
-
contentType = result.format;
|
|
104
|
-
}
|
|
105
|
-
const blobName = options.folderPath ? `${options.folderPath}/${fileName}` : fileName;
|
|
106
|
-
await this.containerClient.getBlockBlobClient(blobName).upload(processedBuffer, processedBuffer.length, {
|
|
107
|
-
blobHTTPHeaders: {
|
|
108
|
-
blobContentType: contentType
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return {
|
|
112
|
-
name: fileName,
|
|
113
|
-
key: blobName,
|
|
114
|
-
size: processedBuffer.length,
|
|
115
|
-
contentType
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
async uploadMultipleFiles(files, options) {
|
|
119
|
-
return Promise.all(files.map((file)=>this.uploadFile(file, options)));
|
|
120
|
-
}
|
|
121
|
-
async deleteFile(key) {
|
|
122
|
-
await this.containerClient.getBlockBlobClient(key).deleteIfExists();
|
|
123
|
-
}
|
|
124
|
-
async deleteMultipleFiles(keys) {
|
|
125
|
-
await Promise.all(keys.map((key)=>this.deleteFile(key)));
|
|
126
|
-
}
|
|
127
|
-
async generatePresignedUrl(key, expiresInSeconds = 3600) {
|
|
128
|
-
const { BlobSASPermissions, generateBlobSASQueryParameters } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("@azure/storage-blob")));
|
|
129
|
-
const blockBlobClient = this.containerClient.getBlockBlobClient(key);
|
|
130
|
-
const startsOn = new Date();
|
|
131
|
-
const expiresOn = new Date(startsOn.getTime() + expiresInSeconds * 1000);
|
|
132
|
-
const sasToken = generateBlobSASQueryParameters({
|
|
133
|
-
containerName: this.containerName,
|
|
134
|
-
blobName: key,
|
|
135
|
-
permissions: BlobSASPermissions.parse('r'),
|
|
136
|
-
startsOn,
|
|
137
|
-
expiresOn
|
|
138
|
-
}, blockBlobClient.credential).toString();
|
|
139
|
-
return `${blockBlobClient.url}?${sasToken}`;
|
|
140
|
-
}
|
|
141
|
-
async healthCheck() {
|
|
142
|
-
try {
|
|
143
|
-
await this.containerClient.exists();
|
|
144
|
-
return true;
|
|
145
|
-
} catch {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
constructor(){
|
|
150
|
-
_define_property(this, "blobServiceClient", void 0);
|
|
151
|
-
_define_property(this, "containerClient", void 0);
|
|
152
|
-
_define_property(this, "containerName", '');
|
|
153
|
-
_define_property(this, "accountName", '');
|
|
154
|
-
}
|
|
155
|
-
};
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _azureprovideroptional = require("./azure-provider.optional");
|
|
6
|
-
const _imagecompressorutil = require("../utils/image-compressor.util");
|
|
7
|
-
function _define_property(obj, key, value) {
|
|
8
|
-
if (key in obj) {
|
|
9
|
-
Object.defineProperty(obj, key, {
|
|
10
|
-
value: value,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true
|
|
14
|
-
});
|
|
15
|
-
} else {
|
|
16
|
-
obj[key] = value;
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
20
|
-
const mockCreateIfNotExists = jest.fn();
|
|
21
|
-
const mockBlockBlobUpload = jest.fn();
|
|
22
|
-
const mockDeleteIfExists = jest.fn();
|
|
23
|
-
const mockContainerExists = jest.fn();
|
|
24
|
-
function buildBlockBlobClient() {
|
|
25
|
-
return {
|
|
26
|
-
upload: mockBlockBlobUpload,
|
|
27
|
-
deleteIfExists: mockDeleteIfExists,
|
|
28
|
-
url: 'https://account.blob.core.windows.net/container/blob-key.jpg',
|
|
29
|
-
credential: 'shared-key-credential'
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const mockGetBlockBlobClient = jest.fn().mockImplementation(()=>buildBlockBlobClient());
|
|
33
|
-
const mockGetContainerClient = jest.fn().mockImplementation(()=>({
|
|
34
|
-
createIfNotExists: mockCreateIfNotExists,
|
|
35
|
-
getBlockBlobClient: mockGetBlockBlobClient,
|
|
36
|
-
exists: mockContainerExists
|
|
37
|
-
}));
|
|
38
|
-
const mockFromConnectionString = jest.fn().mockImplementation(()=>({
|
|
39
|
-
getContainerClient: mockGetContainerClient
|
|
40
|
-
}));
|
|
41
|
-
const mockBlobServiceClientCtor = jest.fn().mockImplementation(()=>({
|
|
42
|
-
getContainerClient: mockGetContainerClient
|
|
43
|
-
}));
|
|
44
|
-
mockBlobServiceClientCtor.fromConnectionString = mockFromConnectionString;
|
|
45
|
-
const mockGenerateBlobSASQueryParameters = jest.fn().mockReturnValue({
|
|
46
|
-
toString: ()=>'sv=2022&sig=abc123'
|
|
47
|
-
});
|
|
48
|
-
let MockStorageSharedKeyCredential = class MockStorageSharedKeyCredential {
|
|
49
|
-
constructor(accountName, accountKey){
|
|
50
|
-
_define_property(this, "accountName", void 0);
|
|
51
|
-
_define_property(this, "accountKey", void 0);
|
|
52
|
-
this.accountName = accountName;
|
|
53
|
-
this.accountKey = accountKey;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
let MockBlobSASPermissions = class MockBlobSASPermissions {
|
|
57
|
-
static parse(input) {
|
|
58
|
-
return {
|
|
59
|
-
permissions: input
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
jest.mock('@azure/storage-blob', ()=>({
|
|
64
|
-
BlobServiceClient: mockBlobServiceClientCtor,
|
|
65
|
-
StorageSharedKeyCredential: MockStorageSharedKeyCredential,
|
|
66
|
-
BlobSASPermissions: MockBlobSASPermissions,
|
|
67
|
-
generateBlobSASQueryParameters: (...args)=>mockGenerateBlobSASQueryParameters(...args)
|
|
68
|
-
}));
|
|
69
|
-
jest.mock('../utils/image-compressor.util', ()=>({
|
|
70
|
-
ImageCompressor: {
|
|
71
|
-
compress: jest.fn()
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
function buildMulterFile(overrides = {}) {
|
|
75
|
-
return {
|
|
76
|
-
fieldname: 'file',
|
|
77
|
-
originalname: 'photo.jpg',
|
|
78
|
-
encoding: '7bit',
|
|
79
|
-
mimetype: 'image/jpeg',
|
|
80
|
-
buffer: Buffer.from('file-bytes'),
|
|
81
|
-
size: 10,
|
|
82
|
-
stream: undefined,
|
|
83
|
-
destination: '',
|
|
84
|
-
filename: '',
|
|
85
|
-
path: '',
|
|
86
|
-
...overrides
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
describe('AzureProvider', ()=>{
|
|
90
|
-
let provider;
|
|
91
|
-
beforeEach(async ()=>{
|
|
92
|
-
jest.clearAllMocks();
|
|
93
|
-
mockCreateIfNotExists.mockResolvedValue(undefined);
|
|
94
|
-
mockBlockBlobUpload.mockResolvedValue(undefined);
|
|
95
|
-
mockDeleteIfExists.mockResolvedValue(undefined);
|
|
96
|
-
mockContainerExists.mockResolvedValue(true);
|
|
97
|
-
mockGetBlockBlobClient.mockImplementation(()=>buildBlockBlobClient());
|
|
98
|
-
mockGetContainerClient.mockImplementation(()=>({
|
|
99
|
-
createIfNotExists: mockCreateIfNotExists,
|
|
100
|
-
getBlockBlobClient: mockGetBlockBlobClient,
|
|
101
|
-
exists: mockContainerExists
|
|
102
|
-
}));
|
|
103
|
-
provider = new _azureprovideroptional.AzureProvider();
|
|
104
|
-
await provider.initialize({
|
|
105
|
-
accountName: 'myaccount',
|
|
106
|
-
accountKey: 'key123',
|
|
107
|
-
containerName: 'my-container'
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('initialize', ()=>{
|
|
111
|
-
it('builds a BlobServiceClient using an account key credential when no connection string is given', ()=>{
|
|
112
|
-
expect(mockBlobServiceClientCtor).toHaveBeenCalledWith('https://myaccount.blob.core.windows.net', expect.any(MockStorageSharedKeyCredential));
|
|
113
|
-
expect(mockCreateIfNotExists).toHaveBeenCalled();
|
|
114
|
-
});
|
|
115
|
-
it('builds a BlobServiceClient from a connection string when provided', async ()=>{
|
|
116
|
-
jest.clearAllMocks();
|
|
117
|
-
mockCreateIfNotExists.mockResolvedValue(undefined);
|
|
118
|
-
const p = new _azureprovideroptional.AzureProvider();
|
|
119
|
-
await p.initialize({
|
|
120
|
-
accountName: 'acct2',
|
|
121
|
-
accountKey: 'key2',
|
|
122
|
-
containerName: 'container2',
|
|
123
|
-
connectionString: 'DefaultEndpointsProtocol=https;AccountName=acct2;AccountKey=key2'
|
|
124
|
-
});
|
|
125
|
-
expect(mockFromConnectionString).toHaveBeenCalledWith('DefaultEndpointsProtocol=https;AccountName=acct2;AccountKey=key2');
|
|
126
|
-
});
|
|
127
|
-
it('throws InternalServerErrorException when the Azure SDK cannot be initialized', async ()=>{
|
|
128
|
-
mockBlobServiceClientCtor.mockImplementationOnce(()=>{
|
|
129
|
-
throw new Error('boom');
|
|
130
|
-
});
|
|
131
|
-
const brokenProvider = new _azureprovideroptional.AzureProvider();
|
|
132
|
-
await expect(brokenProvider.initialize({
|
|
133
|
-
accountName: 'a',
|
|
134
|
-
accountKey: 'b',
|
|
135
|
-
containerName: 'c'
|
|
136
|
-
})).rejects.toThrow('Azure Storage SDK not found');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('uploadFile', ()=>{
|
|
140
|
-
it('uploads the blob and returns file metadata', async ()=>{
|
|
141
|
-
const file = buildMulterFile();
|
|
142
|
-
const result = await provider.uploadFile(file, {});
|
|
143
|
-
expect(mockBlockBlobUpload).toHaveBeenCalledWith(file.buffer, file.buffer.length, expect.objectContaining({
|
|
144
|
-
blobHTTPHeaders: {
|
|
145
|
-
blobContentType: 'image/jpeg'
|
|
146
|
-
}
|
|
147
|
-
}));
|
|
148
|
-
expect(result.name).toMatch(/photo\.jpg$/);
|
|
149
|
-
expect(result.key).toBe(result.name);
|
|
150
|
-
});
|
|
151
|
-
it('prefixes blob name with folderPath when provided', async ()=>{
|
|
152
|
-
const file = buildMulterFile();
|
|
153
|
-
const result = await provider.uploadFile(file, {
|
|
154
|
-
folderPath: 'docs'
|
|
155
|
-
});
|
|
156
|
-
expect(result.key).toMatch(/^docs\//);
|
|
157
|
-
});
|
|
158
|
-
it('compresses image files when options.compress is true', async ()=>{
|
|
159
|
-
_imagecompressorutil.ImageCompressor.compress.mockResolvedValue({
|
|
160
|
-
buffer: Buffer.from('small'),
|
|
161
|
-
format: 'image/webp'
|
|
162
|
-
});
|
|
163
|
-
const file = buildMulterFile();
|
|
164
|
-
const result = await provider.uploadFile(file, {
|
|
165
|
-
compress: true
|
|
166
|
-
});
|
|
167
|
-
expect(_imagecompressorutil.ImageCompressor.compress).toHaveBeenCalled();
|
|
168
|
-
expect(result.contentType).toBe('image/webp');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
describe('uploadMultipleFiles', ()=>{
|
|
172
|
-
it('uploads all files', async ()=>{
|
|
173
|
-
const files = [
|
|
174
|
-
buildMulterFile({
|
|
175
|
-
originalname: 'a.jpg'
|
|
176
|
-
}),
|
|
177
|
-
buildMulterFile({
|
|
178
|
-
originalname: 'b.jpg'
|
|
179
|
-
})
|
|
180
|
-
];
|
|
181
|
-
const results = await provider.uploadMultipleFiles(files, {});
|
|
182
|
-
expect(results).toHaveLength(2);
|
|
183
|
-
expect(mockBlockBlobUpload).toHaveBeenCalledTimes(2);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe('deleteFile', ()=>{
|
|
187
|
-
it('calls deleteIfExists on the block blob client for the given key', async ()=>{
|
|
188
|
-
await provider.deleteFile('blob-key.jpg');
|
|
189
|
-
expect(mockGetBlockBlobClient).toHaveBeenCalledWith('blob-key.jpg');
|
|
190
|
-
expect(mockDeleteIfExists).toHaveBeenCalled();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
describe('deleteMultipleFiles', ()=>{
|
|
194
|
-
it('deletes every provided key', async ()=>{
|
|
195
|
-
await provider.deleteMultipleFiles([
|
|
196
|
-
'a.jpg',
|
|
197
|
-
'b.jpg'
|
|
198
|
-
]);
|
|
199
|
-
expect(mockDeleteIfExists).toHaveBeenCalledTimes(2);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
describe('generatePresignedUrl', ()=>{
|
|
203
|
-
it('generates a SAS URL appended with the query string', async ()=>{
|
|
204
|
-
const url = await provider.generatePresignedUrl('blob-key.jpg', 1800);
|
|
205
|
-
expect(mockGenerateBlobSASQueryParameters).toHaveBeenCalledWith(expect.objectContaining({
|
|
206
|
-
containerName: 'my-container',
|
|
207
|
-
blobName: 'blob-key.jpg'
|
|
208
|
-
}), 'shared-key-credential');
|
|
209
|
-
expect(url).toBe('https://account.blob.core.windows.net/container/blob-key.jpg?sv=2022&sig=abc123');
|
|
210
|
-
});
|
|
211
|
-
it('defaults the expiry window to 3600 seconds', async ()=>{
|
|
212
|
-
await provider.generatePresignedUrl('blob-key.jpg');
|
|
213
|
-
const call = mockGenerateBlobSASQueryParameters.mock.calls[0][0];
|
|
214
|
-
const diffSeconds = (call.expiresOn.getTime() - call.startsOn.getTime()) / 1000;
|
|
215
|
-
expect(diffSeconds).toBeCloseTo(3600, 0);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
describe('healthCheck', ()=>{
|
|
219
|
-
it('returns true when the container exists', async ()=>{
|
|
220
|
-
mockContainerExists.mockResolvedValue(true);
|
|
221
|
-
await expect(provider.healthCheck()).resolves.toBe(true);
|
|
222
|
-
});
|
|
223
|
-
it('returns false when checking existence throws', async ()=>{
|
|
224
|
-
mockContainerExists.mockRejectedValue(new Error('network error'));
|
|
225
|
-
await expect(provider.healthCheck()).resolves.toBe(false);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
package/cjs/providers/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Core exports
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
_export_star(require("./storage-factory.service"), exports);
|
|
7
|
-
_export_star(require("./storage-provider.registry"), exports);
|
|
8
|
-
_export_star(require("./local-provider"), exports);
|
|
9
|
-
function _export_star(from, to) {
|
|
10
|
-
Object.keys(from).forEach(function(k) {
|
|
11
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
-
Object.defineProperty(to, k, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return from[k];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return from;
|
|
21
|
-
}
|
|
22
|
-
// Note: Optional storage providers are loaded dynamically
|
|
23
|
-
// Import them directly from their files when needed:
|
|
24
|
-
// - import { S3Provider } from '@flusys/nestjs-storage/providers/s3-provider.optional';
|
|
25
|
-
// - import { AzureProvider } from '@flusys/nestjs-storage/providers/azure-provider.optional';
|
|
26
|
-
// - import { SftpProvider } from '@flusys/nestjs-storage/providers/sftp-provider.optional';
|