@aeriajs/builtins 0.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.
Files changed (63) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +6 -0
  3. package/dist/collections/file/description.d.ts +50 -0
  4. package/dist/collections/file/description.js +70 -0
  5. package/dist/collections/file/description.mjs +258 -0
  6. package/dist/collections/file/download.d.ts +13 -0
  7. package/dist/collections/file/download.js +78 -0
  8. package/dist/collections/file/download.mjs +232 -0
  9. package/dist/collections/file/index.d.ts +1183 -0
  10. package/dist/collections/file/index.js +49 -0
  11. package/dist/collections/file/index.mjs +46 -0
  12. package/dist/collections/file/insert.d.ts +7 -0
  13. package/dist/collections/file/insert.js +44 -0
  14. package/dist/collections/file/insert.mjs +246 -0
  15. package/dist/collections/file/remove.d.ts +3 -0
  16. package/dist/collections/file/remove.js +28 -0
  17. package/dist/collections/file/remove.mjs +184 -0
  18. package/dist/collections/file/removeAll.d.ts +3 -0
  19. package/dist/collections/file/removeAll.js +30 -0
  20. package/dist/collections/file/removeAll.mjs +194 -0
  21. package/dist/collections/index.d.ts +4 -0
  22. package/dist/collections/index.js +20 -0
  23. package/dist/collections/index.mjs +4 -0
  24. package/dist/collections/log/index.d.ts +458 -0
  25. package/dist/collections/log/index.js +46 -0
  26. package/dist/collections/log/index.mjs +45 -0
  27. package/dist/collections/resourceUsage/index.d.ts +57 -0
  28. package/dist/collections/resourceUsage/index.js +19 -0
  29. package/dist/collections/resourceUsage/index.mjs +16 -0
  30. package/dist/collections/user/activate.d.ts +10 -0
  31. package/dist/collections/user/activate.js +65 -0
  32. package/dist/collections/user/activate.mjs +247 -0
  33. package/dist/collections/user/authenticate.d.ts +24 -0
  34. package/dist/collections/user/authenticate.js +103 -0
  35. package/dist/collections/user/authenticate.mjs +398 -0
  36. package/dist/collections/user/createAccount.d.ts +101 -0
  37. package/dist/collections/user/createAccount.js +66 -0
  38. package/dist/collections/user/createAccount.mjs +219 -0
  39. package/dist/collections/user/description.d.ts +103 -0
  40. package/dist/collections/user/description.js +146 -0
  41. package/dist/collections/user/description.mjs +151 -0
  42. package/dist/collections/user/getActivationLink.d.ts +2 -0
  43. package/dist/collections/user/getActivationLink.js +15 -0
  44. package/dist/collections/user/getActivationLink.mjs +156 -0
  45. package/dist/collections/user/getInfo.d.ts +14 -0
  46. package/dist/collections/user/getInfo.js +39 -0
  47. package/dist/collections/user/getInfo.mjs +192 -0
  48. package/dist/collections/user/index.d.ts +3992 -0
  49. package/dist/collections/user/index.js +37 -0
  50. package/dist/collections/user/index.mjs +36 -0
  51. package/dist/collections/user/insert.d.ts +5 -0
  52. package/dist/collections/user/insert.js +35 -0
  53. package/dist/collections/user/insert.mjs +156 -0
  54. package/dist/functions/describe.d.ts +2 -0
  55. package/dist/functions/describe.js +54 -0
  56. package/dist/functions/describe.mjs +302 -0
  57. package/dist/functions/index.d.ts +1 -0
  58. package/dist/functions/index.js +17 -0
  59. package/dist/functions/index.mjs +1 -0
  60. package/dist/index.d.ts +5701 -0
  61. package/dist/index.js +39 -0
  62. package/dist/index.mjs +11 -0
  63. package/package.json +60 -0
@@ -0,0 +1,219 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ }
125
+ import { isLeft, unwrapEither, left, right } from "@aeriajs/common";
126
+ import { validate } from "@aeriajs/validation";
127
+ import bcrypt from "bcrypt";
128
+ export var createAccount = function() {
129
+ var _ref = _async_to_generator(function(payload, context) {
130
+ var user, validationEither, insertedId, newUser;
131
+ return _ts_generator(this, function(_state) {
132
+ switch(_state.label){
133
+ case 0:
134
+ user = Object.assign({}, payload);
135
+ if (!context.config.allowSignup) {
136
+ throw new Error("signup disallowed");
137
+ }
138
+ validationEither = validate(user, {
139
+ type: "object",
140
+ required: [
141
+ "name",
142
+ "email",
143
+ "phone_number"
144
+ ],
145
+ properties: {
146
+ name: {
147
+ type: "string"
148
+ },
149
+ email: {
150
+ type: "string"
151
+ },
152
+ phone_number: {
153
+ type: "string"
154
+ },
155
+ password: {
156
+ type: "string"
157
+ }
158
+ }
159
+ }, {
160
+ extraneous: [
161
+ "_id",
162
+ "roles",
163
+ "active"
164
+ ]
165
+ });
166
+ if (isLeft(validationEither)) {
167
+ return [
168
+ 2,
169
+ left(unwrapEither(validationEither))
170
+ ];
171
+ }
172
+ if (context.config.signupDefaults) {
173
+ Object.assign(user, context.config.signupDefaults);
174
+ }
175
+ if (!user.password) return [
176
+ 3,
177
+ 2
178
+ ];
179
+ return [
180
+ 4,
181
+ bcrypt.hash(user.password, 10)
182
+ ];
183
+ case 1:
184
+ user.password = _state.sent();
185
+ _state.label = 2;
186
+ case 2:
187
+ if (!context.token.authenticated) {
188
+ Object.assign(user, {
189
+ self_registered: true
190
+ });
191
+ }
192
+ return [
193
+ 4,
194
+ context.collection.model.insertOne(user)
195
+ ];
196
+ case 3:
197
+ insertedId = _state.sent().insertedId;
198
+ return [
199
+ 4,
200
+ context.collection.model.findOne({
201
+ _id: insertedId
202
+ })
203
+ ];
204
+ case 4:
205
+ newUser = _state.sent();
206
+ if (!newUser) {
207
+ throw new Error();
208
+ }
209
+ return [
210
+ 2,
211
+ right(newUser)
212
+ ];
213
+ }
214
+ });
215
+ });
216
+ return function createAccount(payload, context) {
217
+ return _ref.apply(this, arguments);
218
+ };
219
+ }();
@@ -0,0 +1,103 @@
1
+ /**
2
+ * This description complies with JWT claims specified in RFC-7519.
3
+ * Reference: https://www.iana.org/assignments/jwt/jwt.xhtml#claims
4
+ */
5
+ export declare const description: {
6
+ readonly $id: "user";
7
+ readonly required: readonly ["name", "roles", "email"];
8
+ readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
9
+ readonly indexes: readonly ["name"];
10
+ readonly freshItem: {
11
+ readonly active: true;
12
+ };
13
+ readonly properties: {
14
+ readonly name: {
15
+ readonly type: "string";
16
+ };
17
+ readonly given_name: {
18
+ readonly getter: (document: any) => string;
19
+ };
20
+ readonly family_name: {
21
+ readonly getter: (document: any) => string;
22
+ };
23
+ readonly active: {
24
+ readonly type: "boolean";
25
+ };
26
+ readonly roles: {
27
+ readonly type: "array";
28
+ readonly items: {
29
+ readonly type: "string";
30
+ };
31
+ readonly uniqueItems: true;
32
+ };
33
+ readonly email: {
34
+ readonly type: "string";
35
+ readonly inputType: "email";
36
+ readonly unique: true;
37
+ };
38
+ readonly password: {
39
+ readonly type: "string";
40
+ readonly inputType: "password";
41
+ readonly hidden: true;
42
+ };
43
+ readonly phone_number: {
44
+ readonly type: "string";
45
+ readonly mask: "(##) #####-####";
46
+ };
47
+ readonly picture_file: {
48
+ readonly $ref: "file";
49
+ readonly accept: readonly ["image/*"];
50
+ };
51
+ readonly picture: {
52
+ readonly getter: (value: any) => any;
53
+ };
54
+ readonly group: {
55
+ readonly type: "string";
56
+ };
57
+ readonly self_registered: {
58
+ readonly type: "boolean";
59
+ readonly readOnly: true;
60
+ };
61
+ readonly updated_at: {
62
+ readonly type: "string";
63
+ readonly format: "date-time";
64
+ };
65
+ };
66
+ readonly presets: readonly ["crud", "view", "duplicate"];
67
+ readonly layout: {
68
+ readonly name: "grid";
69
+ readonly options: {
70
+ readonly title: "name";
71
+ readonly badge: "roles";
72
+ readonly picture: "picture_file";
73
+ readonly information: "email";
74
+ readonly active: "active";
75
+ readonly translateBadge: true;
76
+ };
77
+ };
78
+ readonly individualActions: {
79
+ readonly 'ui:spawnEdit': {
80
+ readonly name: "Editar";
81
+ readonly icon: "pencil";
82
+ };
83
+ readonly 'route:/dashboard/user/changepass': {
84
+ readonly name: "Mudar senha";
85
+ readonly icon: "key";
86
+ readonly fetchItem: true;
87
+ };
88
+ };
89
+ readonly icon: "users";
90
+ readonly filters: readonly ["name", "roles", "email", "phone_number"];
91
+ readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
92
+ readonly tableMeta: readonly ["email"];
93
+ readonly formLayout: {
94
+ readonly fields: {
95
+ readonly given_name: {
96
+ readonly span: 3;
97
+ };
98
+ readonly family_name: {
99
+ readonly span: 3;
100
+ };
101
+ };
102
+ };
103
+ };
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.description = void 0;
4
+ const api_1 = require("@aeriajs/api");
5
+ /**
6
+ * This description complies with JWT claims specified in RFC-7519.
7
+ * Reference: https://www.iana.org/assignments/jwt/jwt.xhtml#claims
8
+ */
9
+ exports.description = (0, api_1.defineDescription)({
10
+ $id: 'user',
11
+ required: [
12
+ 'name',
13
+ 'roles',
14
+ 'email',
15
+ ],
16
+ form: [
17
+ 'name',
18
+ 'active',
19
+ 'roles',
20
+ 'email',
21
+ 'phone_number',
22
+ 'picture_file',
23
+ ],
24
+ indexes: ['name'],
25
+ freshItem: {
26
+ active: true,
27
+ },
28
+ properties: {
29
+ name: {
30
+ type: 'string',
31
+ },
32
+ given_name: {
33
+ getter: (document) => {
34
+ return `${document.name?.split(' ')[0] || 'N/A'}`;
35
+ },
36
+ },
37
+ family_name: {
38
+ getter: (document) => {
39
+ return `${document.name?.split(' ')[1]}`;
40
+ },
41
+ },
42
+ active: {
43
+ type: 'boolean',
44
+ },
45
+ roles: {
46
+ type: 'array',
47
+ items: {
48
+ type: 'string',
49
+ },
50
+ uniqueItems: true,
51
+ },
52
+ email: {
53
+ type: 'string',
54
+ inputType: 'email',
55
+ unique: true,
56
+ },
57
+ password: {
58
+ type: 'string',
59
+ inputType: 'password',
60
+ hidden: true,
61
+ },
62
+ phone_number: {
63
+ type: 'string',
64
+ mask: '(##) #####-####',
65
+ },
66
+ picture_file: {
67
+ $ref: 'file',
68
+ accept: ['image/*'],
69
+ },
70
+ picture: {
71
+ getter: (value) => {
72
+ return value.picture_file?.link;
73
+ },
74
+ },
75
+ group: {
76
+ type: 'string',
77
+ },
78
+ self_registered: {
79
+ type: 'boolean',
80
+ readOnly: true,
81
+ },
82
+ // resources_usage: {
83
+ // type: 'object',
84
+ // additionalProperties: {
85
+ // $ref: 'resourceUsage',
86
+ // inline: true,
87
+ // },
88
+ // },
89
+ updated_at: {
90
+ type: 'string',
91
+ format: 'date-time',
92
+ },
93
+ },
94
+ presets: [
95
+ 'crud',
96
+ 'view',
97
+ 'duplicate',
98
+ ],
99
+ layout: {
100
+ name: 'grid',
101
+ options: {
102
+ title: 'name',
103
+ badge: 'roles',
104
+ picture: 'picture_file',
105
+ information: 'email',
106
+ active: 'active',
107
+ translateBadge: true,
108
+ },
109
+ },
110
+ individualActions: {
111
+ 'ui:spawnEdit': {
112
+ name: 'Editar',
113
+ icon: 'pencil',
114
+ },
115
+ 'route:/dashboard/user/changepass': {
116
+ name: 'Mudar senha',
117
+ icon: 'key',
118
+ fetchItem: true,
119
+ },
120
+ },
121
+ icon: 'users',
122
+ filters: [
123
+ 'name',
124
+ 'roles',
125
+ 'email',
126
+ 'phone_number',
127
+ ],
128
+ table: [
129
+ 'name',
130
+ 'roles',
131
+ 'picture_file',
132
+ 'active',
133
+ 'updated_at',
134
+ ],
135
+ tableMeta: ['email'],
136
+ formLayout: {
137
+ fields: {
138
+ given_name: {
139
+ span: 3,
140
+ },
141
+ family_name: {
142
+ span: 3,
143
+ },
144
+ },
145
+ },
146
+ });
@@ -0,0 +1,151 @@
1
+ import { defineDescription } from "@aeriajs/api";
2
+ /**
3
+ * This description complies with JWT claims specified in RFC-7519.
4
+ * Reference: https://www.iana.org/assignments/jwt/jwt.xhtml#claims
5
+ */ export var description = defineDescription({
6
+ $id: "user",
7
+ required: [
8
+ "name",
9
+ "roles",
10
+ "email"
11
+ ],
12
+ form: [
13
+ "name",
14
+ "active",
15
+ "roles",
16
+ "email",
17
+ "phone_number",
18
+ "picture_file"
19
+ ],
20
+ indexes: [
21
+ "name"
22
+ ],
23
+ freshItem: {
24
+ active: true
25
+ },
26
+ properties: {
27
+ name: {
28
+ type: "string"
29
+ },
30
+ given_name: {
31
+ getter: function(document) {
32
+ var _document_name;
33
+ return "".concat(((_document_name = document.name) === null || _document_name === void 0 ? void 0 : _document_name.split(" ")[0]) || "N/A");
34
+ }
35
+ },
36
+ family_name: {
37
+ getter: function(document) {
38
+ var _document_name;
39
+ return "".concat((_document_name = document.name) === null || _document_name === void 0 ? void 0 : _document_name.split(" ")[1]);
40
+ }
41
+ },
42
+ active: {
43
+ type: "boolean"
44
+ },
45
+ roles: {
46
+ type: "array",
47
+ items: {
48
+ type: "string"
49
+ },
50
+ uniqueItems: true
51
+ },
52
+ email: {
53
+ type: "string",
54
+ inputType: "email",
55
+ unique: true
56
+ },
57
+ password: {
58
+ type: "string",
59
+ inputType: "password",
60
+ hidden: true
61
+ },
62
+ phone_number: {
63
+ type: "string",
64
+ mask: "(##) #####-####"
65
+ },
66
+ picture_file: {
67
+ $ref: "file",
68
+ accept: [
69
+ "image/*"
70
+ ]
71
+ },
72
+ picture: {
73
+ getter: function(value) {
74
+ var _value_picture_file;
75
+ return (_value_picture_file = value.picture_file) === null || _value_picture_file === void 0 ? void 0 : _value_picture_file.link;
76
+ }
77
+ },
78
+ group: {
79
+ type: "string"
80
+ },
81
+ self_registered: {
82
+ type: "boolean",
83
+ readOnly: true
84
+ },
85
+ // resources_usage: {
86
+ // type: 'object',
87
+ // additionalProperties: {
88
+ // $ref: 'resourceUsage',
89
+ // inline: true,
90
+ // },
91
+ // },
92
+ updated_at: {
93
+ type: "string",
94
+ format: "date-time"
95
+ }
96
+ },
97
+ presets: [
98
+ "crud",
99
+ "view",
100
+ "duplicate"
101
+ ],
102
+ layout: {
103
+ name: "grid",
104
+ options: {
105
+ title: "name",
106
+ badge: "roles",
107
+ picture: "picture_file",
108
+ information: "email",
109
+ active: "active",
110
+ translateBadge: true
111
+ }
112
+ },
113
+ individualActions: {
114
+ "ui:spawnEdit": {
115
+ name: "Editar",
116
+ icon: "pencil"
117
+ },
118
+ "route:/dashboard/user/changepass": {
119
+ name: "Mudar senha",
120
+ icon: "key",
121
+ fetchItem: true
122
+ }
123
+ },
124
+ icon: "users",
125
+ filters: [
126
+ "name",
127
+ "roles",
128
+ "email",
129
+ "phone_number"
130
+ ],
131
+ table: [
132
+ "name",
133
+ "roles",
134
+ "picture_file",
135
+ "active",
136
+ "updated_at"
137
+ ],
138
+ tableMeta: [
139
+ "email"
140
+ ],
141
+ formLayout: {
142
+ fields: {
143
+ given_name: {
144
+ span: 3
145
+ },
146
+ family_name: {
147
+ span: 3
148
+ }
149
+ }
150
+ }
151
+ });
@@ -0,0 +1,2 @@
1
+ import type { ObjectId } from '@aeriajs/types';
2
+ export declare const getActivationLink: (userId: ObjectId) => Promise<string>;
@@ -0,0 +1,15 @@
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.getActivationLink = void 0;
7
+ const entrypoint_1 = require("@aeriajs/entrypoint");
8
+ const bcrypt_1 = __importDefault(require("bcrypt"));
9
+ const getActivationLink = async (userId) => {
10
+ const config = await (0, entrypoint_1.getConfig)();
11
+ const activationToken = await bcrypt_1.default.hash(userId.toString(), 10);
12
+ const link = `${config.apiUrl}/user/activate?u=${userId.toString()}&t=${activationToken}`;
13
+ return link;
14
+ };
15
+ exports.getActivationLink = getActivationLink;