@aeriajs/core 0.0.277 → 0.0.279
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/dist/__scripts__/postinstall.js +2 -37
- package/dist/accessControl.js +14 -18
- package/dist/assets.js +25 -31
- package/dist/collection/cascadingRemove.js +14 -19
- package/dist/collection/define.js +5 -10
- package/dist/collection/description.js +2 -7
- package/dist/collection/index.js +8 -24
- package/dist/collection/makePagination.js +5 -9
- package/dist/collection/normalizeProjection.js +1 -5
- package/dist/collection/preload.js +13 -18
- package/dist/collection/reference.js +19 -26
- package/dist/collection/traverseDocument.js +90 -127
- package/dist/context.js +16 -53
- package/dist/database.js +12 -52
- package/dist/endpoints.js +11 -48
- package/dist/functions/count.js +11 -15
- package/dist/functions/get.js +20 -24
- package/dist/functions/getAll.js +8 -12
- package/dist/functions/index.js +9 -27
- package/dist/functions/insert.js +19 -23
- package/dist/functions/remove.js +15 -19
- package/dist/functions/removeAll.js +11 -15
- package/dist/functions/removeFile.js +7 -11
- package/dist/functions/unpaginatedGetAll.js +15 -19
- package/dist/functions/upload.js +19 -57
- package/dist/index.js +11 -51
- package/dist/presets/add.js +1 -4
- package/dist/presets/crud.js +1 -4
- package/dist/presets/duplicate.js +1 -4
- package/dist/presets/index.js +17 -20
- package/dist/presets/owned.js +1 -4
- package/dist/presets/remove.js +1 -4
- package/dist/presets/removeAll.js +1 -4
- package/dist/presets/timestamped.js +1 -4
- package/dist/presets/view.js +1 -4
- package/dist/token.js +7 -15
- package/package.json +12 -17
- package/dist/__scripts__/postinstall.mjs +0 -50
- package/dist/accessControl.mjs +0 -31
- package/dist/assets.mjs +0 -67
- package/dist/collection/cascadingRemove.mjs +0 -71
- package/dist/collection/define.mjs +0 -13
- package/dist/collection/description.mjs +0 -8
- package/dist/collection/index.mjs +0 -9
- package/dist/collection/makePagination.mjs +0 -20
- package/dist/collection/normalizeProjection.mjs +0 -17
- package/dist/collection/preload.mjs +0 -88
- package/dist/collection/reference.mjs +0 -374
- package/dist/collection/traverseDocument.mjs +0 -454
- package/dist/context.mjs +0 -120
- package/dist/database.mjs +0 -49
- package/dist/endpoints.mjs +0 -52
- package/dist/functions/count.mjs +0 -50
- package/dist/functions/get.mjs +0 -89
- package/dist/functions/getAll.mjs +0 -14
- package/dist/functions/index.mjs +0 -12
- package/dist/functions/insert.mjs +0 -102
- package/dist/functions/remove.mjs +0 -41
- package/dist/functions/removeAll.mjs +0 -40
- package/dist/functions/removeFile.mjs +0 -29
- package/dist/functions/unpaginatedGetAll.mjs +0 -123
- package/dist/functions/upload.mjs +0 -91
- package/dist/index.mjs +0 -14
- package/dist/presets/add.mjs +0 -12
- package/dist/presets/crud.mjs +0 -35
- package/dist/presets/duplicate.mjs +0 -11
- package/dist/presets/index.mjs +0 -19
- package/dist/presets/owned.mjs +0 -9
- package/dist/presets/remove.mjs +0 -11
- package/dist/presets/removeAll.mjs +0 -11
- package/dist/presets/timestamped.mjs +0 -19
- package/dist/presets/view.mjs +0 -14
- package/dist/token.mjs +0 -31
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const types_1 = require("@aeriajs/types");
|
|
6
|
-
const common_1 = require("@aeriajs/common");
|
|
7
|
-
const index_js_1 = require("../collection/index.js");
|
|
1
|
+
import { useSecurity, applyReadMiddlewares } from '@aeriajs/security';
|
|
2
|
+
import { Result, HTTPStatus, ACError } from '@aeriajs/types';
|
|
3
|
+
import { throwIfError } from '@aeriajs/common';
|
|
4
|
+
import { traverseDocument, normalizeProjection, getReferences, buildLookupPipeline, } from '../collection/index.js';
|
|
8
5
|
const internalGetAll = async (payload, context, options) => {
|
|
9
6
|
const { limit, sort, project, offset = 0, } = payload;
|
|
10
7
|
const filters = payload.filters
|
|
@@ -17,7 +14,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
17
14
|
delete filters.$text;
|
|
18
15
|
}
|
|
19
16
|
const pipeline = [];
|
|
20
|
-
const refMap = await
|
|
17
|
+
const refMap = await getReferences(context.description.properties, {
|
|
21
18
|
memoize: context.description.$id,
|
|
22
19
|
});
|
|
23
20
|
if ($text) {
|
|
@@ -39,7 +36,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
39
36
|
$sort: preferredSort,
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
|
-
const { error: filtersError, result: traversedFilters } = await
|
|
39
|
+
const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
|
|
43
40
|
autoCast: true,
|
|
44
41
|
allowOperators: true,
|
|
45
42
|
noRegExpEscaping: options.noRegExpEscaping,
|
|
@@ -47,7 +44,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
47
44
|
});
|
|
48
45
|
if (filtersError) {
|
|
49
46
|
switch (filtersError) {
|
|
50
|
-
case
|
|
47
|
+
case ACError.InsecureOperator: return context.error(HTTPStatus.Forbidden, {
|
|
51
48
|
code: filtersError,
|
|
52
49
|
});
|
|
53
50
|
default: throw new Error;
|
|
@@ -69,14 +66,14 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
69
66
|
});
|
|
70
67
|
}
|
|
71
68
|
if (project) {
|
|
72
|
-
const projection =
|
|
69
|
+
const projection = normalizeProjection(project, context.description);
|
|
73
70
|
if (projection) {
|
|
74
71
|
pipeline.push({
|
|
75
72
|
$project: projection,
|
|
76
73
|
});
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
|
-
pipeline.push(...
|
|
76
|
+
pipeline.push(...buildLookupPipeline(refMap, {
|
|
80
77
|
memoize: context.description.$id,
|
|
81
78
|
project: payload.populate
|
|
82
79
|
? payload.populate
|
|
@@ -90,7 +87,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
90
87
|
const result = await context.collection.model.aggregate(pipeline).toArray();
|
|
91
88
|
const documents = [];
|
|
92
89
|
for (const doc of result) {
|
|
93
|
-
documents.push(
|
|
90
|
+
documents.push(throwIfError(await traverseDocument(doc, context.description, {
|
|
94
91
|
context,
|
|
95
92
|
getters: true,
|
|
96
93
|
fromProperties: true,
|
|
@@ -98,27 +95,26 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
98
95
|
recurseDeep: true,
|
|
99
96
|
})));
|
|
100
97
|
}
|
|
101
|
-
return
|
|
98
|
+
return Result.result(documents);
|
|
102
99
|
};
|
|
103
|
-
const unpaginatedGetAll = async (payload, context, options = {}) => {
|
|
100
|
+
export const unpaginatedGetAll = async (payload, context, options = {}) => {
|
|
104
101
|
if (!payload) {
|
|
105
102
|
return internalGetAll({}, context, options);
|
|
106
103
|
}
|
|
107
104
|
if (options.bypassSecurity) {
|
|
108
105
|
return internalGetAll(payload, context, options);
|
|
109
106
|
}
|
|
110
|
-
const security =
|
|
107
|
+
const security = useSecurity(context);
|
|
111
108
|
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
112
109
|
if (error) {
|
|
113
|
-
return context.error(
|
|
110
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
114
111
|
code: error,
|
|
115
112
|
});
|
|
116
113
|
}
|
|
117
114
|
if (!options.noDefaultLimit) {
|
|
118
115
|
securedPayload.limit ||= context.config.defaultPaginationLimit;
|
|
119
116
|
}
|
|
120
|
-
return
|
|
117
|
+
return applyReadMiddlewares(securedPayload, context, (payload, context) => {
|
|
121
118
|
return internalGetAll(payload, context, options);
|
|
122
119
|
});
|
|
123
120
|
};
|
|
124
|
-
exports.unpaginatedGetAll = unpaginatedGetAll;
|
package/dist/functions/upload.js
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var _a, _b;
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.upload = exports.validateUploadHeaders = exports.UploadHeaders = exports.validateFileMetadata = exports.FileMetadata = void 0;
|
|
38
|
-
const types_1 = require("@aeriajs/types");
|
|
39
|
-
const validation_1 = require("@aeriajs/validation");
|
|
40
|
-
const path = __importStar(require("node:path"));
|
|
41
|
-
const node_fs_1 = require("node:fs");
|
|
42
|
-
const node_crypto_1 = require("node:crypto");
|
|
43
|
-
_a = (0, validation_1.validator)({
|
|
1
|
+
import { Result, ACError, HTTPStatus } from '@aeriajs/types';
|
|
2
|
+
import { validator } from '@aeriajs/validation';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { createWriteStream } from 'node:fs';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
export const [FileMetadata, validateFileMetadata] = validator({
|
|
44
7
|
type: 'object',
|
|
45
8
|
required: ['name'],
|
|
46
9
|
properties: {
|
|
@@ -54,8 +17,8 @@ _a = (0, validation_1.validator)({
|
|
|
54
17
|
],
|
|
55
18
|
},
|
|
56
19
|
},
|
|
57
|
-
})
|
|
58
|
-
|
|
20
|
+
});
|
|
21
|
+
export const [UploadHeaders, validateUploadHeaders] = validator({
|
|
59
22
|
type: 'object',
|
|
60
23
|
additionalProperties: true,
|
|
61
24
|
required: [
|
|
@@ -70,9 +33,9 @@ _b = (0, validation_1.validator)({
|
|
|
70
33
|
type: 'string',
|
|
71
34
|
},
|
|
72
35
|
},
|
|
73
|
-
})
|
|
36
|
+
});
|
|
74
37
|
const streamToFs = (metadata, context) => {
|
|
75
|
-
const nameHash =
|
|
38
|
+
const nameHash = createHash('sha1')
|
|
76
39
|
.update(metadata.name + Date.now())
|
|
77
40
|
.digest('hex');
|
|
78
41
|
const extension = metadata.name.includes('.')
|
|
@@ -86,7 +49,7 @@ const streamToFs = (metadata, context) => {
|
|
|
86
49
|
}
|
|
87
50
|
const absolutePath = path.join(tmpPath, `${nameHash}.${extension}`);
|
|
88
51
|
return new Promise(async (resolve, reject) => {
|
|
89
|
-
const stream =
|
|
52
|
+
const stream = createWriteStream(absolutePath);
|
|
90
53
|
stream.on('close', () => resolve(absolutePath));
|
|
91
54
|
stream.on('error', (error) => reject(error));
|
|
92
55
|
switch (metadata.format) {
|
|
@@ -103,18 +66,18 @@ const streamToFs = (metadata, context) => {
|
|
|
103
66
|
}
|
|
104
67
|
});
|
|
105
68
|
};
|
|
106
|
-
const upload = async (_props, context) => {
|
|
107
|
-
const { error: headersError } =
|
|
69
|
+
export const upload = async (_props, context) => {
|
|
70
|
+
const { error: headersError } = validateUploadHeaders(context.request.headers);
|
|
108
71
|
if (headersError) {
|
|
109
|
-
return context.error(
|
|
110
|
-
code:
|
|
72
|
+
return context.error(HTTPStatus.BadRequest, {
|
|
73
|
+
code: ACError.MalformedInput,
|
|
111
74
|
details: headersError,
|
|
112
75
|
});
|
|
113
76
|
}
|
|
114
|
-
const { error, result: metadata } =
|
|
77
|
+
const { error, result: metadata } = validateFileMetadata(context.request.query);
|
|
115
78
|
if (error) {
|
|
116
|
-
return context.error(
|
|
117
|
-
code:
|
|
79
|
+
return context.error(HTTPStatus.BadRequest, {
|
|
80
|
+
code: ACError.MalformedInput,
|
|
118
81
|
details: error,
|
|
119
82
|
});
|
|
120
83
|
}
|
|
@@ -127,8 +90,7 @@ const upload = async (_props, context) => {
|
|
|
127
90
|
collection: context.description.$id,
|
|
128
91
|
name: metadata.name,
|
|
129
92
|
});
|
|
130
|
-
return
|
|
93
|
+
return Result.result({
|
|
131
94
|
tempId: file.insertedId,
|
|
132
95
|
});
|
|
133
96
|
};
|
|
134
|
-
exports.upload = upload;
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ObjectId = exports.functions = void 0;
|
|
40
|
-
__exportStar(require("./accessControl.js"), exports);
|
|
41
|
-
__exportStar(require("./assets.js"), exports);
|
|
42
|
-
__exportStar(require("./collection/index.js"), exports);
|
|
43
|
-
__exportStar(require("./context.js"), exports);
|
|
44
|
-
__exportStar(require("./database.js"), exports);
|
|
45
|
-
__exportStar(require("./functions/index.js"), exports);
|
|
46
|
-
__exportStar(require("./endpoints.js"), exports);
|
|
47
|
-
__exportStar(require("./token.js"), exports);
|
|
48
|
-
__exportStar(require("./functions/index.js"), exports);
|
|
49
|
-
exports.functions = __importStar(require("./functions/index.js"));
|
|
50
|
-
var mongodb_1 = require("mongodb");
|
|
51
|
-
Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
|
|
1
|
+
export * from './accessControl.js';
|
|
2
|
+
export * from './assets.js';
|
|
3
|
+
export * from './collection/index.js';
|
|
4
|
+
export * from './context.js';
|
|
5
|
+
export * from './database.js';
|
|
6
|
+
export * from './functions/index.js';
|
|
7
|
+
export * from './endpoints.js';
|
|
8
|
+
export * from './token.js';
|
|
9
|
+
export * from './functions/index.js';
|
|
10
|
+
export * as functions from './functions/index.js';
|
|
11
|
+
export { ObjectId, } from 'mongodb';
|
package/dist/presets/add.js
CHANGED
package/dist/presets/crud.js
CHANGED
package/dist/presets/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
remove: remove_js_1.remove,
|
|
19
|
-
timestamped: timestamped_js_1.timestamped,
|
|
20
|
-
view: view_js_1.view,
|
|
1
|
+
import { add } from './add.js';
|
|
2
|
+
import { crud } from './crud.js';
|
|
3
|
+
import { removeAll } from './removeAll.js';
|
|
4
|
+
import { duplicate } from './duplicate.js';
|
|
5
|
+
import { owned } from './owned.js';
|
|
6
|
+
import { remove } from './remove.js';
|
|
7
|
+
import { timestamped } from './timestamped.js';
|
|
8
|
+
import { view } from './view.js';
|
|
9
|
+
export const presets = {
|
|
10
|
+
add,
|
|
11
|
+
crud,
|
|
12
|
+
removeAll,
|
|
13
|
+
duplicate,
|
|
14
|
+
owned,
|
|
15
|
+
remove,
|
|
16
|
+
timestamped,
|
|
17
|
+
view,
|
|
21
18
|
};
|
package/dist/presets/owned.js
CHANGED
package/dist/presets/remove.js
CHANGED
package/dist/presets/view.js
CHANGED
package/dist/token.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.decodeToken = exports.signToken = void 0;
|
|
7
|
-
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
8
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
1
|
+
import { getConfig } from '@aeriajs/entrypoint';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
9
3
|
const getTokenConfig = async () => {
|
|
10
|
-
const config = await
|
|
4
|
+
const config = await getConfig();
|
|
11
5
|
if (!config.secret) {
|
|
12
6
|
throw new Error('application secret is not set');
|
|
13
7
|
}
|
|
@@ -17,7 +11,7 @@ const getTokenConfig = async () => {
|
|
|
17
11
|
tokenExpiration: config.security.tokenExpiration,
|
|
18
12
|
};
|
|
19
13
|
};
|
|
20
|
-
const signToken = async ({ iat, exp, ...payload }, secret, options) => {
|
|
14
|
+
export const signToken = async ({ iat, exp, ...payload }, secret, options) => {
|
|
21
15
|
const tokenConfig = await getTokenConfig();
|
|
22
16
|
if (tokenConfig.name) {
|
|
23
17
|
payload.aud = tokenConfig.name;
|
|
@@ -28,11 +22,9 @@ const signToken = async ({ iat, exp, ...payload }, secret, options) => {
|
|
|
28
22
|
tokenOptions.expiresIn = tokenConfig.tokenExpiration;
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
|
-
return
|
|
25
|
+
return jwt.sign(payload, secret || tokenConfig.secret, tokenOptions);
|
|
32
26
|
};
|
|
33
|
-
|
|
34
|
-
const decodeToken = async (token, secret) => {
|
|
27
|
+
export const decodeToken = async (token, secret) => {
|
|
35
28
|
const tokenConfig = await getTokenConfig();
|
|
36
|
-
return
|
|
29
|
+
return jwt.verify(token, secret || tokenConfig.secret);
|
|
37
30
|
};
|
|
38
|
-
exports.decodeToken = decodeToken;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.279",
|
|
4
5
|
"description": "",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"aeriaMain": "tests/fixtures/aeriaMain.js",
|
|
7
|
-
"module": "dist/index.mjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"require": "./dist/index.js"
|
|
15
|
+
"default": "./dist/index.js"
|
|
17
16
|
},
|
|
18
17
|
"./presets": {
|
|
19
18
|
"types": "./dist/presets/index.d.ts",
|
|
20
|
-
"
|
|
21
|
-
"require": "./dist/presets/index.js"
|
|
19
|
+
"default": "./dist/presets/index.js"
|
|
22
20
|
},
|
|
23
21
|
"./presets/*": "./dist/presets/*"
|
|
24
22
|
},
|
|
@@ -42,13 +40,13 @@
|
|
|
42
40
|
"mongodb-memory-server": "^10.1.4"
|
|
43
41
|
},
|
|
44
42
|
"peerDependencies": {
|
|
45
|
-
"@aeriajs/builtins": "^0.0.
|
|
46
|
-
"@aeriajs/common": "^0.0.
|
|
47
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
48
|
-
"@aeriajs/http": "^0.0.
|
|
49
|
-
"@aeriajs/security": "^0.0.
|
|
50
|
-
"@aeriajs/types": "^0.0.
|
|
51
|
-
"@aeriajs/validation": "^0.0.
|
|
43
|
+
"@aeriajs/builtins": "^0.0.279",
|
|
44
|
+
"@aeriajs/common": "^0.0.158",
|
|
45
|
+
"@aeriajs/entrypoint": "^0.0.165",
|
|
46
|
+
"@aeriajs/http": "^0.0.195",
|
|
47
|
+
"@aeriajs/security": "^0.0.279",
|
|
48
|
+
"@aeriajs/types": "^0.0.136",
|
|
49
|
+
"@aeriajs/validation": "^0.0.180"
|
|
52
50
|
},
|
|
53
51
|
"dependencies": {
|
|
54
52
|
"mongodb": "^6.17.0",
|
|
@@ -62,10 +60,7 @@
|
|
|
62
60
|
"test:typecheck": "tsc -p tsconfig.test.json",
|
|
63
61
|
"lint": "eslint .",
|
|
64
62
|
"lint:fix": "eslint . --fix",
|
|
65
|
-
"build": "
|
|
66
|
-
"build:cjs": "tsc",
|
|
67
|
-
"build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
|
|
68
|
-
"build:esm-transform": "pnpm -w esm-transform $PWD/dist",
|
|
63
|
+
"build": "tsc",
|
|
69
64
|
"postinstall": "node dist/__scripts__/postinstall.js || true"
|
|
70
65
|
}
|
|
71
66
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as fs from "node:fs";
|
|
4
|
-
const DTS_FILENAME = "aeria.d.ts";
|
|
5
|
-
const makeDts = (typesPath) => `// this file will be overwritten
|
|
6
|
-
import type {} from '@aeriajs/types'
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
type UnpackCollections<TCollections> = {
|
|
10
|
-
[P in keyof TCollections]: TCollections[P] extends infer Candidate
|
|
11
|
-
? Candidate extends (...args: unknown[]) => infer Coll
|
|
12
|
-
? Coll
|
|
13
|
-
: Candidate
|
|
14
|
-
: never
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type Collections = typeof import('${typesPath}') extends infer EntrypointModule
|
|
18
|
-
? 'collections' extends keyof EntrypointModule
|
|
19
|
-
? UnpackCollections<EntrypointModule['collections']>
|
|
20
|
-
: 'default' extends keyof EntrypointModule
|
|
21
|
-
? EntrypointModule['default'] extends infer Entrypoint
|
|
22
|
-
? 'options' extends keyof Entrypoint
|
|
23
|
-
? 'collections' extends keyof Entrypoint['options']
|
|
24
|
-
? UnpackCollections<Entrypoint['options']['collections']>
|
|
25
|
-
: never
|
|
26
|
-
: never
|
|
27
|
-
: never
|
|
28
|
-
: never
|
|
29
|
-
: never
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare module 'aeria' {
|
|
33
|
-
import type { Context } from 'aeria'
|
|
34
|
-
export const createAeria: () => Promise<Context>
|
|
35
|
-
export const aeria: Context
|
|
36
|
-
}
|
|
37
|
-
//`;
|
|
38
|
-
const install = async () => {
|
|
39
|
-
const base = process.env.INIT_CWD || process.cwd();
|
|
40
|
-
const aeriaDir = path.join(base, ".aeria");
|
|
41
|
-
if (!fs.existsSync(aeriaDir)) {
|
|
42
|
-
await fs.promises.mkdir(aeriaDir);
|
|
43
|
-
}
|
|
44
|
-
const { types = "src/index.ts" } = JSON.parse(await fs.promises.readFile(path.join(base, "package.json"), {
|
|
45
|
-
encoding: "utf8"
|
|
46
|
-
}));
|
|
47
|
-
const dts = makeDts(path.join("..", types).split(path.sep).join("/"));
|
|
48
|
-
await fs.promises.writeFile(path.join(aeriaDir, DTS_FILENAME), dts);
|
|
49
|
-
};
|
|
50
|
-
install();
|
package/dist/accessControl.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { getConfig } from "@aeriajs/entrypoint";
|
|
3
|
-
import { isGranted } from "@aeriajs/common";
|
|
4
|
-
export const FunctionExposedStatus = {
|
|
5
|
-
FunctionNotExposed: "FUNCTION_NOT_EXPOSED",
|
|
6
|
-
FunctionNotGranted: "FUNCTION_NOT_GRANTED",
|
|
7
|
-
FunctionAccessible: "FUNCTION_ACCESSIBLE"
|
|
8
|
-
};
|
|
9
|
-
export const isFunctionExposed = async (collection, fnName, token) => {
|
|
10
|
-
const config = await getConfig();
|
|
11
|
-
if (!collection.functions) {
|
|
12
|
-
return FunctionExposedStatus.FunctionNotExposed;
|
|
13
|
-
}
|
|
14
|
-
if (collection.exposedFunctions && fnName in collection.exposedFunctions) {
|
|
15
|
-
const exposed = collection.exposedFunctions[fnName];
|
|
16
|
-
if (exposed === false) {
|
|
17
|
-
return FunctionExposedStatus.FunctionNotExposed;
|
|
18
|
-
}
|
|
19
|
-
if (!token) {
|
|
20
|
-
return FunctionExposedStatus.FunctionAccessible;
|
|
21
|
-
}
|
|
22
|
-
return isGranted(exposed, token) ? FunctionExposedStatus.FunctionAccessible : FunctionExposedStatus.FunctionNotGranted;
|
|
23
|
-
}
|
|
24
|
-
if (config.security.exposeFunctionsByDefault) {
|
|
25
|
-
if (config.security.exposeFunctionsByDefault !== "unauthenticated" && (!token || !token.authenticated)) {
|
|
26
|
-
return FunctionExposedStatus.FunctionNotGranted;
|
|
27
|
-
}
|
|
28
|
-
return FunctionExposedStatus.FunctionAccessible;
|
|
29
|
-
}
|
|
30
|
-
return FunctionExposedStatus.FunctionNotExposed;
|
|
31
|
-
};
|
package/dist/assets.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, ACError } from "@aeriajs/types";
|
|
3
|
-
import { limitRate } from "@aeriajs/security";
|
|
4
|
-
import { getCollection } from "@aeriajs/entrypoint";
|
|
5
|
-
import { isFunctionExposed, FunctionExposedStatus } from "./accessControl.mjs";
|
|
6
|
-
const assetsMemo = {
|
|
7
|
-
assets: {}
|
|
8
|
-
};
|
|
9
|
-
export const internalGetCollectionAsset = async (collectionName, assetName) => {
|
|
10
|
-
const collection = await getCollection(collectionName);
|
|
11
|
-
const asset = collection?.[assetName];
|
|
12
|
-
if (!asset) {
|
|
13
|
-
return Result.error(ACError.ResourceNotFound);
|
|
14
|
-
}
|
|
15
|
-
return Result.result(asset);
|
|
16
|
-
};
|
|
17
|
-
export const getCollectionAsset = async (collectionName, assetName) => {
|
|
18
|
-
const cached = assetsMemo.assets[collectionName];
|
|
19
|
-
if (cached?.[assetName]) {
|
|
20
|
-
return Result.result(cached[assetName]);
|
|
21
|
-
}
|
|
22
|
-
const { error, result: asset } = await internalGetCollectionAsset(collectionName, assetName);
|
|
23
|
-
if (error) {
|
|
24
|
-
return Result.error(error);
|
|
25
|
-
}
|
|
26
|
-
assetsMemo.assets[collectionName] ??= {};
|
|
27
|
-
assetsMemo.assets[collectionName][assetName] = asset;
|
|
28
|
-
return Result.result(asset);
|
|
29
|
-
};
|
|
30
|
-
export const getFunction = async (collectionName, functionName, token, options = {
|
|
31
|
-
exposedOnly: false
|
|
32
|
-
}) => {
|
|
33
|
-
const { error, result: functions } = await getCollectionAsset(collectionName, "functions");
|
|
34
|
-
if (error) {
|
|
35
|
-
return Result.error(error);
|
|
36
|
-
}
|
|
37
|
-
if (!(functionName in functions)) {
|
|
38
|
-
return Result.error(ACError.FunctionNotFound);
|
|
39
|
-
}
|
|
40
|
-
const collection = await getCollection(collectionName);
|
|
41
|
-
const fn = functions[functionName];
|
|
42
|
-
if (!collection) {
|
|
43
|
-
return Result.error(ACError.ResourceNotFound);
|
|
44
|
-
}
|
|
45
|
-
if (options.exposedOnly) {
|
|
46
|
-
const exposedStatus = await isFunctionExposed(collection, functionName, token);
|
|
47
|
-
switch (exposedStatus) {
|
|
48
|
-
case FunctionExposedStatus.FunctionNotExposed:
|
|
49
|
-
return Result.error(ACError.FunctionNotExposed);
|
|
50
|
-
case FunctionExposedStatus.FunctionNotGranted:
|
|
51
|
-
return Result.error(ACError.AuthorizationError);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const wrapper = async (payload, context) => {
|
|
55
|
-
const securityPolicy = collection.security?.functions?.[functionName];
|
|
56
|
-
if (securityPolicy) {
|
|
57
|
-
if (securityPolicy.rateLimiting) {
|
|
58
|
-
const { error: error2 } = await limitRate(securityPolicy.rateLimiting, context);
|
|
59
|
-
if (error2) {
|
|
60
|
-
return Result.error(error2);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return fn(payload, context);
|
|
65
|
-
};
|
|
66
|
-
return Result.result(wrapper);
|
|
67
|
-
};
|