@orion-js/file-manager 3.0.17 → 3.0.25
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/File/index.d.ts +2 -0
- package/lib/File/index.js +20 -36
- package/lib/File/resolvers/genericType.d.ts +2 -0
- package/lib/File/resolvers/genericType.js +14 -23
- package/lib/File/resolvers/index.d.ts +5 -0
- package/lib/File/resolvers/index.js +9 -16
- package/lib/File/resolvers/url.d.ts +2 -0
- package/lib/File/resolvers/url.js +9 -18
- package/lib/File/schema.d.ts +3 -0
- package/lib/File/schema.js +47 -51
- package/lib/Files/index.d.ts +2 -0
- package/lib/Files/index.js +22 -27
- package/lib/credentials.d.ts +10 -0
- package/lib/credentials.js +3 -10
- package/lib/index.d.ts +5 -0
- package/lib/index.js +14 -44
- package/lib/resolvers/completeUpload.d.ts +2 -0
- package/lib/resolvers/completeUpload.js +19 -39
- package/lib/resolvers/fileManagerFile.d.ts +2 -0
- package/lib/resolvers/fileManagerFile.js +16 -29
- package/lib/resolvers/fileManagerFiles.d.ts +11 -0
- package/lib/resolvers/fileManagerFiles.js +23 -43
- package/lib/resolvers/generateUploadCredentials.d.ts +5 -0
- package/lib/resolvers/generateUploadCredentials.js +85 -100
- package/lib/resolvers/index.d.ts +19 -0
- package/lib/resolvers/index.js +13 -22
- package/package.json +23 -18
- package/tsconfig.json +20 -0
- package/yarn-error.log +5080 -0
- package/LICENSE +0 -21
|
@@ -1,104 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
size: {
|
|
24
|
-
type: Number
|
|
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
|
+
const resolvers_1 = require("@orion-js/resolvers");
|
|
7
|
+
const helpers_1 = require("@orion-js/helpers");
|
|
8
|
+
const models_1 = require("@orion-js/models");
|
|
9
|
+
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
10
|
+
const credentials_1 = require("../credentials");
|
|
11
|
+
const Files_1 = __importDefault(require("../Files"));
|
|
12
|
+
exports.default = (0, resolvers_1.resolver)({
|
|
13
|
+
params: {
|
|
14
|
+
name: {
|
|
15
|
+
type: String
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
type: Number
|
|
19
|
+
},
|
|
20
|
+
type: {
|
|
21
|
+
type: String
|
|
22
|
+
}
|
|
25
23
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
key: {
|
|
43
|
-
type: String
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}),
|
|
47
|
-
mutation: true,
|
|
48
|
-
|
|
49
|
-
async resolve(params, viewer) {
|
|
50
|
-
const {
|
|
51
|
-
accessKeyId,
|
|
52
|
-
secretAccessKey,
|
|
53
|
-
region,
|
|
54
|
-
bucket,
|
|
55
|
-
canUpload,
|
|
56
|
-
basePath
|
|
57
|
-
} = (0, _credentials.getAWSCredentials)();
|
|
58
|
-
const s3 = new _awsSdk.default.S3({
|
|
59
|
-
accessKeyId,
|
|
60
|
-
secretAccessKey,
|
|
61
|
-
region
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (canUpload) {
|
|
65
|
-
if (!(await canUpload(params, viewer))) return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const key = `${basePath}/${(0, _app.generateId)()}-${params.name}`;
|
|
69
|
-
const fileId = await _Files.default.insert({
|
|
70
|
-
key,
|
|
71
|
-
bucket,
|
|
72
|
-
name: params.name,
|
|
73
|
-
type: params.type,
|
|
74
|
-
size: params.size,
|
|
75
|
-
status: 'uploading',
|
|
76
|
-
createdBy: viewer.userId,
|
|
77
|
-
createdAt: new Date()
|
|
78
|
-
});
|
|
79
|
-
const result = await new Promise((resolve, reject) => {
|
|
80
|
-
s3.createPresignedPost({
|
|
81
|
-
Bucket: bucket,
|
|
82
|
-
Conditions: [['content-length-range', params.size, params.size], {
|
|
83
|
-
'Content-Type': params.type
|
|
84
|
-
}, {
|
|
85
|
-
Key: key
|
|
86
|
-
}],
|
|
87
|
-
Fields: {
|
|
88
|
-
key: key,
|
|
89
|
-
'Content-Type': params.type
|
|
24
|
+
returns: (0, models_1.createModel)({
|
|
25
|
+
name: 'UploadCredentials',
|
|
26
|
+
schema: {
|
|
27
|
+
fileId: {
|
|
28
|
+
type: 'ID'
|
|
29
|
+
},
|
|
30
|
+
url: {
|
|
31
|
+
type: String
|
|
32
|
+
},
|
|
33
|
+
fields: {
|
|
34
|
+
type: 'blackbox'
|
|
35
|
+
},
|
|
36
|
+
key: {
|
|
37
|
+
type: String
|
|
38
|
+
}
|
|
90
39
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
40
|
+
}),
|
|
41
|
+
mutation: true,
|
|
42
|
+
async resolve(params, viewer) {
|
|
43
|
+
const { accessKeyId, secretAccessKey, region, bucket, canUpload, basePath } = (0, credentials_1.getAWSCredentials)();
|
|
44
|
+
const s3 = new aws_sdk_1.default.S3({
|
|
45
|
+
accessKeyId,
|
|
46
|
+
secretAccessKey,
|
|
47
|
+
region
|
|
48
|
+
});
|
|
49
|
+
if (canUpload) {
|
|
50
|
+
if (!(await canUpload(params, viewer)))
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const key = `${basePath}/${(0, helpers_1.generateId)()}-${params.name}`;
|
|
54
|
+
const fileId = await Files_1.default.insertOne({
|
|
55
|
+
key,
|
|
56
|
+
bucket,
|
|
57
|
+
name: params.name,
|
|
58
|
+
type: params.type,
|
|
59
|
+
size: params.size,
|
|
60
|
+
status: 'uploading',
|
|
61
|
+
createdBy: viewer.userId,
|
|
62
|
+
createdAt: new Date()
|
|
63
|
+
});
|
|
64
|
+
const result = await new Promise((resolve, reject) => {
|
|
65
|
+
s3.createPresignedPost({
|
|
66
|
+
Bucket: bucket,
|
|
67
|
+
Conditions: [
|
|
68
|
+
['content-length-range', params.size, params.size],
|
|
69
|
+
{ 'Content-Type': params.type },
|
|
70
|
+
{ Key: key }
|
|
71
|
+
],
|
|
72
|
+
Fields: {
|
|
73
|
+
key: key,
|
|
74
|
+
'Content-Type': params.type
|
|
75
|
+
}
|
|
76
|
+
}, function (error, data) {
|
|
77
|
+
if (error)
|
|
78
|
+
reject(error);
|
|
79
|
+
else
|
|
80
|
+
resolve(data);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
fileId,
|
|
85
|
+
...result,
|
|
86
|
+
key
|
|
87
|
+
};
|
|
88
|
+
}
|
|
102
89
|
});
|
|
103
|
-
|
|
104
|
-
exports.default = _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
fileManagerFile: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<any>, undefined>;
|
|
3
|
+
fileManagerFiles: import("@orion-js/resolvers").Resolver<(params: any, viewer: any) => Promise<{
|
|
4
|
+
cursor: import("@orion-js/mongodb").FindCursor<any>;
|
|
5
|
+
params: any;
|
|
6
|
+
viewer: any;
|
|
7
|
+
options: {
|
|
8
|
+
skip: number;
|
|
9
|
+
limit: any;
|
|
10
|
+
};
|
|
11
|
+
count: number;
|
|
12
|
+
}>, undefined>;
|
|
13
|
+
completeUpload: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<any>, undefined>;
|
|
14
|
+
generateUploadCredentials: import("@orion-js/resolvers").Resolver<(params: any, viewer: any) => Promise<{
|
|
15
|
+
key: string;
|
|
16
|
+
fileId: string;
|
|
17
|
+
}>, undefined>;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
package/lib/resolvers/index.js
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _generateUploadCredentials = _interopRequireDefault(require("./generateUploadCredentials"));
|
|
17
|
-
|
|
18
|
-
var _default = {
|
|
19
|
-
fileManagerFile: _fileManagerFile.default,
|
|
20
|
-
fileManagerFiles: _fileManagerFiles.default,
|
|
21
|
-
completeUpload: _completeUpload.default,
|
|
22
|
-
generateUploadCredentials: _generateUploadCredentials.default
|
|
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
|
+
const fileManagerFile_1 = __importDefault(require("./fileManagerFile"));
|
|
7
|
+
const fileManagerFiles_1 = __importDefault(require("./fileManagerFiles"));
|
|
8
|
+
const completeUpload_1 = __importDefault(require("./completeUpload"));
|
|
9
|
+
const generateUploadCredentials_1 = __importDefault(require("./generateUploadCredentials"));
|
|
10
|
+
exports.default = {
|
|
11
|
+
fileManagerFile: fileManagerFile_1.default,
|
|
12
|
+
fileManagerFiles: fileManagerFiles_1.default,
|
|
13
|
+
completeUpload: completeUpload_1.default,
|
|
14
|
+
generateUploadCredentials: generateUploadCredentials_1.default
|
|
23
15
|
};
|
|
24
|
-
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/file-manager",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.25",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"test": "exit 0",
|
|
9
9
|
"prepare": "yarn run build",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"clean": "rm -rf ./lib",
|
|
11
|
+
"build": "yarn run clean && tsc",
|
|
12
|
+
"watch": "yarn run clean && tsc -w"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@orion-js/
|
|
15
|
-
"@orion-js/
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"@orion-js/helpers": "^3.0.17",
|
|
16
|
+
"@orion-js/models": "^3.0.24",
|
|
17
|
+
"@orion-js/mongodb": "^3.0.24",
|
|
18
|
+
"@orion-js/paginated-mongodb": "^3.0.24",
|
|
19
|
+
"@orion-js/resolvers": "^3.0.24",
|
|
20
|
+
"@orion-js/schema": "^3.0.7",
|
|
21
|
+
"aws-sdk": "^2.1028.0",
|
|
22
|
+
"lodash": "^4.17.21",
|
|
23
|
+
"luxon": "^2.1.1"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
|
-
"@babel/cli": "^7.5.5",
|
|
22
|
-
"@babel/core": "^7.5.5",
|
|
23
|
-
"@babel/plugin-transform-runtime": "^7.5.5",
|
|
24
|
-
"@babel/preset-env": "^7.5.5",
|
|
25
|
-
"@babel/runtime": "^7.5.5",
|
|
26
|
-
"@orion-js/app": "^3.0.0-alpha.10",
|
|
27
26
|
"@shelf/jest-mongodb": "^2.1.0",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
27
|
+
"@types/jest": "^27.0.2",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "5.4.0",
|
|
29
|
+
"@typescript-eslint/parser": "5.4.0",
|
|
30
|
+
"eslint": "8.2.0",
|
|
31
|
+
"eslint-plugin-import": "2.25.3",
|
|
32
|
+
"jest": "27.3.1",
|
|
33
|
+
"ts-jest": "27.0.7",
|
|
34
|
+
"typescript": "^4.4.4"
|
|
30
35
|
},
|
|
31
36
|
"peerDependencies": {
|
|
32
37
|
"@orion-js/app": "*"
|
|
@@ -34,5 +39,5 @@
|
|
|
34
39
|
"publishConfig": {
|
|
35
40
|
"access": "public"
|
|
36
41
|
},
|
|
37
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "80d7ff4f8452fdc0d046ed7a37dde041916a2906"
|
|
38
43
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": false,
|
|
4
|
+
"outDir": "./lib",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"target": "es2020",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"lib": ["es2020"],
|
|
10
|
+
"declaration": true,
|
|
11
|
+
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
|
|
16
|
+
// required for typed models
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"emitDecoratorMetadata": true
|
|
19
|
+
}
|
|
20
|
+
}
|