@formio/appserver 1.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 (49) hide show
  1. package/README.md +61 -0
  2. package/lib/actions/index.d.ts +160 -0
  3. package/lib/actions/index.js +10 -0
  4. package/lib/actions/login/LoginAction.d.ts +110 -0
  5. package/lib/actions/login/LoginAction.js +288 -0
  6. package/lib/actions/role/RoleAction.d.ts +62 -0
  7. package/lib/actions/role/RoleAction.js +171 -0
  8. package/lib/actions/save/SaveAction.d.ts +29 -0
  9. package/lib/actions/save/SaveAction.js +307 -0
  10. package/lib/auth.d.ts +5 -0
  11. package/lib/auth.js +70 -0
  12. package/lib/db.d.ts +76 -0
  13. package/lib/db.js +384 -0
  14. package/lib/index.d.ts +167 -0
  15. package/lib/index.js +18 -0
  16. package/lib/prepare/access.d.ts +3 -0
  17. package/lib/prepare/access.js +62 -0
  18. package/lib/prepare/bcrypt.d.ts +3 -0
  19. package/lib/prepare/bcrypt.js +25 -0
  20. package/lib/prepare/index.d.ts +10 -0
  21. package/lib/prepare/index.js +54 -0
  22. package/lib/prepare/password.d.ts +3 -0
  23. package/lib/prepare/password.js +28 -0
  24. package/lib/prepare/persist.d.ts +3 -0
  25. package/lib/prepare/persist.js +24 -0
  26. package/lib/prepare/protect.d.ts +3 -0
  27. package/lib/prepare/protect.js +28 -0
  28. package/lib/process/calculate.d.ts +3 -0
  29. package/lib/process/calculate.js +23 -0
  30. package/lib/process/conditions.d.ts +3 -0
  31. package/lib/process/conditions.js +54 -0
  32. package/lib/process/fetch.d.ts +3 -0
  33. package/lib/process/fetch.js +61 -0
  34. package/lib/process/index.d.ts +9 -0
  35. package/lib/process/index.js +56 -0
  36. package/lib/process/validate.d.ts +3 -0
  37. package/lib/process/validate.js +14 -0
  38. package/lib/types/action.d.ts +7 -0
  39. package/lib/types/action.js +2 -0
  40. package/lib/types/form.d.ts +4 -0
  41. package/lib/types/form.js +2 -0
  42. package/lib/types/project.d.ts +4 -0
  43. package/lib/types/project.js +2 -0
  44. package/lib/types/server.d.ts +75 -0
  45. package/lib/types/server.js +2 -0
  46. package/lib/types/submission.d.ts +38 -0
  47. package/lib/types/submission.js +2 -0
  48. package/package.json +48 -0
  49. package/server.js +3 -0
package/lib/db.js ADDED
@@ -0,0 +1,384 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Database = void 0;
16
+ const mongodb_1 = require("mongodb");
17
+ const pick_1 = __importDefault(require("lodash/pick"));
18
+ const omit_1 = __importDefault(require("lodash/omit"));
19
+ const debug = require('debug')('formio:db');
20
+ const error = require('debug')('formio:error');
21
+ class Database {
22
+ constructor(config) {
23
+ this.config = config;
24
+ this.db = null;
25
+ this.currentCollectionName = 'submissions';
26
+ this.currentCollection = null;
27
+ this.defaultCollection = null;
28
+ }
29
+ ObjectId(id) {
30
+ if (id === null || id === void 0 ? void 0 : id.hasOwnProperty('$in')) {
31
+ return { $in: id['$in'].map((_id) => this.ObjectId(_id)) };
32
+ }
33
+ try {
34
+ return id ? (new mongodb_1.ObjectId(id)) : null;
35
+ }
36
+ catch (e) {
37
+ return id;
38
+ }
39
+ }
40
+ /**
41
+ * Connect to the database.
42
+ * @param {*} scope
43
+ * @returns
44
+ */
45
+ connect() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ try {
48
+ debug('db.connect()');
49
+ const config = this.config.config ? JSON.parse(this.config.config) : {};
50
+ const client = new mongodb_1.MongoClient(this.config.url, config);
51
+ yield client.connect();
52
+ this.db = yield client.db();
53
+ this.addIndex(this.db.collection('project'), 'name');
54
+ this.defaultCollection = this.db.collection('submissions');
55
+ yield this.setupIndexes(this.defaultCollection);
56
+ debug('Connected to database');
57
+ }
58
+ catch (err) {
59
+ error(err.message);
60
+ process.exit();
61
+ }
62
+ });
63
+ }
64
+ // Generic save record method.
65
+ save(collectionName, item) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ if (!this.db) {
68
+ return null;
69
+ }
70
+ const collection = this.db.collection(collectionName);
71
+ let result;
72
+ try {
73
+ debug('db.save()', collectionName);
74
+ result = yield collection.findOneAndUpdate({ _id: this.ObjectId(item._id) }, { $set: (0, omit_1.default)(item, '_id') }, { upsert: true, returnOriginal: false });
75
+ }
76
+ catch (err) {
77
+ error(err.message);
78
+ }
79
+ return result ? result.value : null;
80
+ });
81
+ }
82
+ // Generic load record method.
83
+ load(collectionName) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ if (!this.db) {
86
+ return null;
87
+ }
88
+ debug('db.load()', collectionName);
89
+ const collection = this.db.collection(collectionName);
90
+ let item;
91
+ try {
92
+ item = yield collection.findOne({});
93
+ }
94
+ catch (err) {
95
+ error(err.message);
96
+ }
97
+ return item;
98
+ });
99
+ }
100
+ // Get the collection to use for the call.
101
+ collection(scope) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ if (this.db && scope && scope.form && scope.form.settings && scope.form.settings.collection) {
104
+ if (this.currentCollection && this.currentCollectionName === scope.form.settings.collection) {
105
+ return this.currentCollection;
106
+ }
107
+ let collection = null;
108
+ try {
109
+ debug('db.createCollection()', scope.form.settings.collection);
110
+ yield this.db.createCollection(scope.form.settings.collection);
111
+ collection = this.db.collection(scope.form.settings.collection);
112
+ this.setupIndexes(collection, scope);
113
+ }
114
+ catch (err) {
115
+ error(err.message);
116
+ }
117
+ this.currentCollection = collection || this.db.collection(scope.form.settings.collection);
118
+ this.currentCollectionName = scope.form.settings.collection;
119
+ return this.currentCollection;
120
+ }
121
+ return this.defaultCollection;
122
+ });
123
+ }
124
+ /**
125
+ * Setup indexes.
126
+ */
127
+ setupIndexes(collection, scope) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ if (!collection) {
130
+ return;
131
+ }
132
+ this.addIndex(collection, 'project');
133
+ this.addIndex(collection, 'form');
134
+ this.addIndex(collection, 'deleted');
135
+ this.addIndex(collection, 'modified');
136
+ this.addIndex(collection, 'created');
137
+ if (scope && scope.form && scope.form.components) {
138
+ scope.utils.eachComponent(scope.form.components, (component, components, path) => {
139
+ if (component.dbIndex) {
140
+ this.addIndex(collection, `data.${path}`);
141
+ }
142
+ });
143
+ }
144
+ });
145
+ }
146
+ /**
147
+ * Add a field index
148
+ */
149
+ addIndex(collection, path) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ const index = {};
152
+ index[path] = 1;
153
+ try {
154
+ debug('db.addIndex()', path);
155
+ collection.createIndex(index, { background: true });
156
+ }
157
+ catch (err) {
158
+ error(`Cannot add index ${path}`, err.message);
159
+ }
160
+ });
161
+ }
162
+ /**
163
+ * Remove a field index.
164
+ */
165
+ removeIndex(collection, path) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const index = {};
168
+ index[path] = 1;
169
+ try {
170
+ debug('db.removeIndex()', path);
171
+ collection.dropIndex(index);
172
+ }
173
+ catch (err) {
174
+ error(`Cannot remove index ${path}`, err.message);
175
+ }
176
+ });
177
+ }
178
+ /**
179
+ * Fetch a list of submissions from a table/collection.
180
+ * @param {*} table
181
+ * @param {*} query
182
+ */
183
+ index(scope, query = {}) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ let items;
186
+ try {
187
+ debug('db.index()', query);
188
+ items = yield this.find(scope, query);
189
+ }
190
+ catch (err) {
191
+ error(err.message);
192
+ }
193
+ return items;
194
+ });
195
+ }
196
+ /**
197
+ * Create a new record.
198
+ */
199
+ create(scope, record, allowFields = []) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ record.deleted = null;
202
+ record.created = new Date();
203
+ record.modified = new Date();
204
+ if (scope.form && scope.form._id) {
205
+ record.form = this.ObjectId(scope.form._id);
206
+ }
207
+ if (scope.project && scope.project._id) {
208
+ record.project = this.ObjectId(scope.project._id);
209
+ }
210
+ if (record.owner) {
211
+ record.owner = this.ObjectId(record.owner);
212
+ }
213
+ const collection = yield this.collection(scope);
214
+ try {
215
+ debug('db.create()', record);
216
+ const result = yield collection.insertOne((0, pick_1.default)(record, [
217
+ 'data',
218
+ 'metadata',
219
+ 'modified',
220
+ 'created',
221
+ 'deleted',
222
+ 'form',
223
+ 'project',
224
+ 'owner',
225
+ 'access'
226
+ ].concat(allowFields)));
227
+ if (!result.insertedId) {
228
+ return null;
229
+ }
230
+ return yield this.read(scope, result.insertedId);
231
+ }
232
+ catch (err) {
233
+ error(err.message);
234
+ }
235
+ });
236
+ }
237
+ /**
238
+ * Return a query for a single mongo record.
239
+ * @param {*} form
240
+ * @param {*} id
241
+ * @returns
242
+ */
243
+ query(scope, query = {}) {
244
+ if (query._id) {
245
+ query._id = this.ObjectId(query._id);
246
+ }
247
+ if (query.owner) {
248
+ query.owner = this.ObjectId(query.owner);
249
+ }
250
+ if (query.form) {
251
+ query.form = this.ObjectId(query.form);
252
+ }
253
+ else if (scope.form && scope.form._id) {
254
+ query.form = this.ObjectId(scope.form._id);
255
+ }
256
+ if (scope.project && scope.project._id) {
257
+ query.project = this.ObjectId(scope.project._id);
258
+ }
259
+ query.deleted = { $eq: null };
260
+ // Handle nested queries.
261
+ ['$or', '$and'].forEach((key) => {
262
+ if (query[key]) {
263
+ query[key].forEach((subQuery) => this.query(scope, subQuery));
264
+ }
265
+ });
266
+ return query;
267
+ }
268
+ /**
269
+ * Find many records that match a query.
270
+ */
271
+ find(scope, query = {}) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ try {
274
+ debug('db.find()', query);
275
+ const collection = yield this.collection(scope);
276
+ if (!collection) {
277
+ return [];
278
+ }
279
+ return yield collection.find(this.query(scope, query)).toArray();
280
+ }
281
+ catch (err) {
282
+ error(err.message);
283
+ }
284
+ return [];
285
+ });
286
+ }
287
+ /**
288
+ * Find a record for a provided query.
289
+ */
290
+ findOne(scope, query = {}) {
291
+ return __awaiter(this, void 0, void 0, function* () {
292
+ try {
293
+ debug('db.findOne()', query);
294
+ const collection = yield this.collection(scope);
295
+ if (!collection) {
296
+ return null;
297
+ }
298
+ return yield collection.findOne(this.query(scope, query));
299
+ }
300
+ catch (err) {
301
+ error(err.message);
302
+ }
303
+ return null;
304
+ });
305
+ }
306
+ /**
307
+ * Read a single submission from a form
308
+ *
309
+ * @param {*} table
310
+ * @param {*} query
311
+ */
312
+ read(scope, id) {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ try {
315
+ debug('db.read()', id);
316
+ const collection = yield this.collection(scope);
317
+ if (!collection) {
318
+ return null;
319
+ }
320
+ return yield collection.findOne(this.query(scope, { _id: id }));
321
+ }
322
+ catch (err) {
323
+ error(err.message);
324
+ }
325
+ return null;
326
+ });
327
+ }
328
+ /**
329
+ * Update a single submission of a form.
330
+ *
331
+ * @param {*} table
332
+ * @param {*} query
333
+ */
334
+ update(scope, id, update, allowFields = []) {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ if (!id || !update) {
337
+ return null;
338
+ }
339
+ update.modified = new Date();
340
+ try {
341
+ debug('db.update()', id, update);
342
+ const collection = yield this.collection(scope);
343
+ if (!collection) {
344
+ return null;
345
+ }
346
+ const result = yield collection.updateOne(this.query(scope, { _id: id }), {
347
+ $set: (0, pick_1.default)(update, ['data', 'metadata', 'modified'].concat(allowFields))
348
+ });
349
+ if (result.modifiedCount === 0) {
350
+ return null;
351
+ }
352
+ return yield this.read(scope, id);
353
+ }
354
+ catch (err) {
355
+ error(err.message);
356
+ }
357
+ return null;
358
+ });
359
+ }
360
+ /**
361
+ * Delete a record from the database.
362
+ */
363
+ delete(scope, id) {
364
+ return __awaiter(this, void 0, void 0, function* () {
365
+ if (!id) {
366
+ return false;
367
+ }
368
+ try {
369
+ debug('db.delete()', id);
370
+ const collection = yield this.collection(scope);
371
+ if (!collection) {
372
+ return false;
373
+ }
374
+ const result = yield collection.updateOne(this.query(scope, { _id: id }), { $set: { deleted: Date.now() } });
375
+ return result.modifiedCount > 0;
376
+ }
377
+ catch (err) {
378
+ error(err.message);
379
+ }
380
+ return false;
381
+ });
382
+ }
383
+ }
384
+ exports.Database = Database;
package/lib/index.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ /// <reference types="express" />
2
+ import { Auth } from "./auth";
3
+ import { Database } from "./db";
4
+ export declare const Modules: {
5
+ db: typeof Database;
6
+ auth: typeof Auth;
7
+ process: (scope: import("./types/submission").ProcessScope) => Promise<any>;
8
+ prepare: (scope: import("./types/submission").PrepScope) => Promise<{}>;
9
+ actions: {
10
+ save: {
11
+ readonly info: {
12
+ name: string;
13
+ title: string;
14
+ description: string;
15
+ priority: number;
16
+ defaults: {
17
+ handler: string[];
18
+ method: string[];
19
+ };
20
+ access: {
21
+ handler: boolean;
22
+ method: boolean;
23
+ };
24
+ };
25
+ mappingComponents(scope: import("./types/action").ActionScope): Promise<any>;
26
+ settingsForm(scope: import("./types/action").ActionScope): Promise<any>;
27
+ saveToForm(scope: import("./types/action").ActionScope, resource: string): undefined;
28
+ childSubmission(scope: import("./types/action").ActionScope, req: import("./types/submission").SubmissionRequest, res: import("./types/submission").SubmissionResponse, submission: any): any;
29
+ childResponse(scope: import("./types/action").ActionScope, req: import("./types/submission").SubmissionRequest, res: import("./types/submission").SubmissionResponse): void;
30
+ executor(scope: import("./types/action").ActionScope): Promise<(req: import("./types/submission").SubmissionRequest, res: import("./types/submission").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
31
+ };
32
+ login: {
33
+ readonly info: {
34
+ name: string;
35
+ title: string;
36
+ description: string;
37
+ priority: number;
38
+ defaults: {
39
+ handler: string[];
40
+ method: string[];
41
+ };
42
+ access: {
43
+ handler: boolean;
44
+ method: boolean;
45
+ };
46
+ };
47
+ settingsForm(scope: import("./types/action").ActionScope): Promise<({
48
+ type: string;
49
+ label: string;
50
+ key: string;
51
+ placeholder: string;
52
+ dataSrc: string;
53
+ valueProperty: string;
54
+ data: {
55
+ json: any;
56
+ };
57
+ multiple: boolean;
58
+ validate: {
59
+ required: boolean;
60
+ };
61
+ input?: undefined;
62
+ description?: undefined;
63
+ defaultValue?: undefined;
64
+ suffix?: undefined;
65
+ } | {
66
+ type: string;
67
+ input: boolean;
68
+ label: string;
69
+ key: string;
70
+ placeholder: string;
71
+ dataSrc: string;
72
+ valueProperty: string;
73
+ data: {
74
+ json: any;
75
+ };
76
+ multiple: boolean;
77
+ validate: {
78
+ required: boolean;
79
+ };
80
+ description?: undefined;
81
+ defaultValue?: undefined;
82
+ suffix?: undefined;
83
+ } | {
84
+ type: string;
85
+ key: string;
86
+ input: boolean;
87
+ label: string;
88
+ description: string;
89
+ defaultValue: string;
90
+ placeholder?: undefined;
91
+ dataSrc?: undefined;
92
+ valueProperty?: undefined;
93
+ data?: undefined;
94
+ multiple?: undefined;
95
+ validate?: undefined;
96
+ suffix?: undefined;
97
+ } | {
98
+ type: string;
99
+ key: string;
100
+ input: boolean;
101
+ label: string;
102
+ description: string;
103
+ defaultValue: string;
104
+ suffix: string;
105
+ placeholder?: undefined;
106
+ dataSrc?: undefined;
107
+ valueProperty?: undefined;
108
+ data?: undefined;
109
+ multiple?: undefined;
110
+ validate?: undefined;
111
+ })[]>;
112
+ waitText(time: number): string;
113
+ checkAttempts(scope: import("./types/action").ActionScope, error: any, user: import("./types/server").User): Promise<any>;
114
+ executor(scope: import("./types/action").ActionScope): Promise<(req: import("./types/submission").SubmissionRequest, res: import("./types/submission").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
115
+ };
116
+ role: {
117
+ readonly info: {
118
+ name: string;
119
+ title: string;
120
+ description: string;
121
+ priority: number;
122
+ defaults: {
123
+ handler: string[];
124
+ method: string[];
125
+ };
126
+ access: {
127
+ handler: boolean;
128
+ method: boolean;
129
+ };
130
+ };
131
+ settingsForm(scope: import("./types/action").ActionScope): Promise<({
132
+ type: string;
133
+ input: boolean;
134
+ label: string;
135
+ key: string;
136
+ placeholder: string;
137
+ template: string;
138
+ dataSrc: string;
139
+ data: {
140
+ json: string;
141
+ };
142
+ valueProperty: string;
143
+ multiple: boolean;
144
+ validate: {
145
+ required: boolean;
146
+ };
147
+ } | {
148
+ type: string;
149
+ input: boolean;
150
+ label: string;
151
+ key: string;
152
+ placeholder: string;
153
+ template: string;
154
+ dataSrc: string;
155
+ data: {
156
+ json: unknown[];
157
+ };
158
+ valueProperty: string;
159
+ multiple: boolean;
160
+ validate: {
161
+ required: boolean;
162
+ };
163
+ })[]>;
164
+ executor(scope: import("./types/action").ActionScope): Promise<(req: import("./types/submission").SubmissionRequest, res: import("./types/submission").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("./types/submission").SubmissionResponse>>;
165
+ };
166
+ };
167
+ };
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
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.Modules = void 0;
7
+ const auth_1 = require("./auth");
8
+ const db_1 = require("./db");
9
+ const actions_1 = __importDefault(require("./actions"));
10
+ const process_1 = require("./process");
11
+ const prepare_1 = require("./prepare");
12
+ exports.Modules = {
13
+ db: db_1.Database,
14
+ auth: auth_1.Auth,
15
+ process: process_1.Processor,
16
+ prepare: prepare_1.Prepper,
17
+ actions: actions_1.default
18
+ };
@@ -0,0 +1,3 @@
1
+ import { PrepScope } from '../types/submission';
2
+ declare const _default: (scope: PrepScope) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const find_1 = __importDefault(require("lodash/find"));
16
+ const uniq_1 = __importDefault(require("lodash/uniq"));
17
+ exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const { req, component } = scope;
19
+ let { value } = scope;
20
+ if (!value ||
21
+ !component ||
22
+ !component.key ||
23
+ !(component.submissionAccess || component.defaultPermission)) {
24
+ // Return early if the conditions are not met.
25
+ return;
26
+ }
27
+ // Normalize the submissionAccess property.
28
+ if (!component.submissionAccess) {
29
+ component.submissionAccess = [
30
+ {
31
+ type: component.defaultPermission,
32
+ roles: [],
33
+ },
34
+ ];
35
+ }
36
+ if (!Array.isArray(value)) {
37
+ value = [value];
38
+ }
39
+ if (!value.length) {
40
+ return;
41
+ }
42
+ // Convert the value to an array of ids.
43
+ value = (0, uniq_1.default)(value.map((val) => val._id ? val._id.toString() : val.toString()));
44
+ // Iterate through each submissionAccess object and assign the appropriate access roles.
45
+ component.submissionAccess.map((access) => {
46
+ const perm = (0, find_1.default)(req.body.access, {
47
+ type: access.type,
48
+ });
49
+ if (perm) {
50
+ if (!perm.resources) {
51
+ perm.resources = [];
52
+ }
53
+ perm.resources = (0, uniq_1.default)(perm.resources.concat(value));
54
+ }
55
+ else {
56
+ req.body.access.push({
57
+ type: access.type,
58
+ resources: value,
59
+ });
60
+ }
61
+ });
62
+ });
@@ -0,0 +1,3 @@
1
+ import { PrepScope } from '../types/submission';
2
+ declare const _default: (scope: PrepScope) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const set_1 = __importDefault(require("lodash/set"));
16
+ const bcryptjs_1 = __importDefault(require("bcryptjs"));
17
+ exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const { component, data, value, path } = scope;
19
+ if (!value) {
20
+ return;
21
+ }
22
+ if (component.type === 'password' && !value.hasOwnProperty('hash')) {
23
+ (0, set_1.default)(data, path, { hash: bcryptjs_1.default.hashSync(value, bcryptjs_1.default.genSaltSync(10)) });
24
+ }
25
+ });
@@ -0,0 +1,10 @@
1
+ import { PrepScope } from '../types/submission';
2
+ export declare const Preppers: {
3
+ bcrypt: (scope: PrepScope) => Promise<void>;
4
+ access: (scope: PrepScope) => Promise<void>;
5
+ persist: (scope: PrepScope) => Promise<void>;
6
+ protect: (scope: PrepScope) => Promise<void>;
7
+ password: (scope: PrepScope) => Promise<void>;
8
+ };
9
+ export declare const MethodPreppers: any;
10
+ export declare const Prepper: (scope: PrepScope) => Promise<{}>;