@formio/appserver 2.11.1 → 2.12.0-rc.1

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.
@@ -107,7 +107,7 @@ exports.RoleAction = {
107
107
  executor(form, action, handler, method) {
108
108
  return __awaiter(this, void 0, void 0, function* () {
109
109
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
110
- var _a, _b;
110
+ var _a, _b, _c;
111
111
  debug('Role Action');
112
112
  // Check the submission for the submissionId.
113
113
  if (action.settings.association !== 'existing' && action.settings.association !== 'new') {
@@ -134,7 +134,7 @@ exports.RoleAction = {
134
134
  return res.status(400).send('Missing submission for RoleAction association of "existing:. Form must have a resource field named "submission".');
135
135
  }
136
136
  // Determine the resources based on the current request.
137
- let resource = res.resource ? (res.resource.item || req.body) : req.body;
137
+ let resource = ((_c = res.resource) === null || _c === void 0 ? void 0 : _c.item) || req.submission || req.body;
138
138
  let role = form.project.roleId(action.settings.role);
139
139
  if (!resource.roles) {
140
140
  resource.roles = [];
@@ -215,7 +215,7 @@ exports.SaveAction = {
215
215
  let childSub = { data: {} };
216
216
  if (action.settings.mapping) {
217
217
  try {
218
- childSub = appserver_core_1.Utils.evaluate(action.settings.mapping, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'body');
218
+ childSub = appserver_core_1.Utils.evaluate(action.settings.mapping, appserver_core_1.Utils.evalContext(form, submission, req.auth, req.headers, req.findQuery), 'body');
219
219
  }
220
220
  catch (err) {
221
221
  console.log(`Error in mapping transform: ${err.message}`);
@@ -234,7 +234,7 @@ exports.SaveAction = {
234
234
  childSub.metadata = submission.metadata;
235
235
  if (action.settings.transform) {
236
236
  try {
237
- childSub.data = appserver_core_1.Utils.evaluate(action.settings.transform, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'data');
237
+ childSub.data = appserver_core_1.Utils.evaluate(action.settings.transform, appserver_core_1.Utils.evalContext(form, req.submission || req.body, req.auth, req.headers, req.findQuery), 'data');
238
238
  }
239
239
  catch (err) {
240
240
  console.log(`Error in submission transform: ${err.message}`);
@@ -246,15 +246,16 @@ exports.SaveAction = {
246
246
  childResponse(action, req, res, form, submission) {
247
247
  var _a, _b;
248
248
  if ((_a = res.resource) === null || _a === void 0 ? void 0 : _a.item) {
249
+ const submission = req.submission || req.body;
249
250
  // Set the action in the property.
250
251
  if ((_b = action.settings) === null || _b === void 0 ? void 0 : _b.property) {
251
- (0, set_1.default)(req.body.data, action.settings.property, res.resource.item);
252
+ (0, set_1.default)(submission.data, action.settings.property, res.resource.item);
252
253
  }
253
254
  // Save the reference in the external ids.
254
255
  if (req.method === 'POST' && res.resource.item._id) {
255
256
  // Save the external resource in the external ids.
256
- req.body.externalIds = req.body.externalIds || [];
257
- req.body.externalIds.push({
257
+ submission.externalIds = submission.externalIds || [];
258
+ submission.externalIds.push({
258
259
  type: 'resource',
259
260
  resource: action.settings.resource,
260
261
  id: res.resource.item._id.toString()
@@ -263,7 +264,7 @@ exports.SaveAction = {
263
264
  // Allow for a response mapping.
264
265
  if (action.settings.response) {
265
266
  try {
266
- res.resource.item = appserver_core_1.Utils.evaluate(action.settings.response, Object.assign(Object.assign({}, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery)), { response: res.resource.item }), 'response');
267
+ res.resource.item = appserver_core_1.Utils.evaluate(action.settings.response, Object.assign(Object.assign({}, appserver_core_1.Utils.evalContext(form, submission, req.auth, req.headers, req.findQuery)), { response: res.resource.item }), 'response');
267
268
  }
268
269
  catch (err) {
269
270
  console.log(`Error in mapping transform: ${err.message}`);
@@ -276,7 +277,7 @@ exports.SaveAction = {
276
277
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
277
278
  var _a;
278
279
  debug('Save Action');
279
- if (req.skipSave || !req.body || (req.method !== 'POST' && req.method !== 'PUT')) {
280
+ if (req.skipSave || !(req.submission || req.body) || (req.method !== 'POST' && req.method !== 'PUT')) {
280
281
  debug('Skipping save action');
281
282
  return next();
282
283
  }
@@ -1,6 +1,6 @@
1
1
  import { Collection, Document, Db, MongoClient, FindOneOptions } from 'mongodb';
2
2
  import { Component, Submission } from '@formio/core';
3
- import { ServerDB, DBConfig, AppServerForm, DatabaseIndexResponse } from '@formio/appserver-core';
3
+ import { ServerDB, DBConfig, AppServerForm, DatabaseIndexResponse, IndexQuery } from '@formio/appserver-core';
4
4
  export declare class Database implements ServerDB {
5
5
  config: DBConfig;
6
6
  db: Db | null;
@@ -9,7 +9,6 @@ export declare class Database implements ServerDB {
9
9
  currentCollection: Collection<Document> | null;
10
10
  defaultCollection: Collection<Document> | null;
11
11
  prefix: string;
12
- authQuery: any;
13
12
  constructor(config: DBConfig);
14
13
  ObjectId(id: any): any;
15
14
  collectionName(name: string): string;
@@ -23,7 +22,6 @@ export declare class Database implements ServerDB {
23
22
  save(collectionName: string, item: any): Promise<any | null>;
24
23
  saveOne(collectionName: string, item: any): Promise<any>;
25
24
  load(collectionName: string, dbQuery?: {}): Promise<any | null>;
26
- indexAuth(query: any): void;
27
25
  getQueryValue(name: string, value: string, selector: string): string | boolean | Date | null;
28
26
  /**
29
27
  * Converts the url query to query parameters.
@@ -61,12 +59,18 @@ export declare class Database implements ServerDB {
61
59
  * @returns
62
60
  */
63
61
  removeIndexes(form: AppServerForm, indexes: string[]): Promise<void>;
62
+ /**
63
+ * Get the index query from the url query.
64
+ * @param urlQuery
65
+ * @returns
66
+ */
67
+ indexQuery(urlQuery: any): IndexQuery;
64
68
  /**
65
69
  * Fetch a list of submissions from a table/collection.
66
70
  * @param {*} table
67
71
  * @param {*} query
68
72
  */
69
- index(form: AppServerForm, urlQuery?: any, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse<Submission>>;
73
+ index(form: AppServerForm, query: IndexQuery, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse<Submission>>;
70
74
  /**
71
75
  * Perform a count of the amount of documents within a collection.
72
76
  * @param form
@@ -30,7 +30,6 @@ class Database {
30
30
  constructor(config) {
31
31
  this.config = config;
32
32
  this.prefix = '';
33
- this.authQuery = null;
34
33
  this.db = null;
35
34
  this.client = null; // Add this line
36
35
  this.currentCollectionName = 'submissions';
@@ -165,10 +164,6 @@ class Database {
165
164
  return item;
166
165
  });
167
166
  }
168
- // Provides a suplemental query for authentication purposes.
169
- indexAuth(query) {
170
- this.authQuery = query || null;
171
- }
172
167
  getQueryValue(name, value, selector) {
173
168
  if (name === 'created' || name === 'modified') {
174
169
  return new Date(value);
@@ -267,10 +262,6 @@ class Database {
267
262
  return;
268
263
  }
269
264
  });
270
- // If an authQuery is provided, merge it in.
271
- if (this.authQuery && (0, lodash_1.isPlainObject)(this.authQuery)) {
272
- return (0, lodash_1.merge)(dbQuery, this.authQuery);
273
- }
274
265
  // Return the dbQuery.
275
266
  return dbQuery;
276
267
  }
@@ -427,40 +418,55 @@ class Database {
427
418
  }
428
419
  });
429
420
  }
421
+ /**
422
+ * Get the index query from the url query.
423
+ * @param urlQuery
424
+ * @returns
425
+ */
426
+ indexQuery(urlQuery) {
427
+ let skip = 0, limit = 10;
428
+ limit = parseInt(urlQuery.limit) || 10;
429
+ skip = parseInt(urlQuery.skip) || 0;
430
+ const sort = urlQuery.sort || { created: -1 };
431
+ const includeDeleted = urlQuery.includeDeleted || false;
432
+ let project = {};
433
+ if (urlQuery.select) {
434
+ if (typeof urlQuery.select === 'string') {
435
+ const fields = urlQuery.select.split(',');
436
+ fields.forEach((field) => {
437
+ project[field] = true;
438
+ });
439
+ }
440
+ else {
441
+ Object.keys(urlQuery.select).forEach((field) => {
442
+ project[field] = true;
443
+ });
444
+ }
445
+ }
446
+ delete urlQuery.limit;
447
+ delete urlQuery.skip;
448
+ delete urlQuery.sort;
449
+ delete urlQuery.select;
450
+ delete urlQuery.includeDeleted;
451
+ return {
452
+ limit,
453
+ skip,
454
+ sort,
455
+ includeDeleted,
456
+ project,
457
+ dbQuery: this.dbQuery(urlQuery)
458
+ };
459
+ }
430
460
  /**
431
461
  * Fetch a list of submissions from a table/collection.
432
462
  * @param {*} table
433
463
  * @param {*} query
434
464
  */
435
- index(form_1) {
436
- return __awaiter(this, arguments, void 0, function* (form, urlQuery = {}, collection = null) {
437
- let items = [], skip = 0, limit = 10, count = 0;
465
+ index(form_1, query_1) {
466
+ return __awaiter(this, arguments, void 0, function* (form, query, collection = null) {
467
+ let items = [], count = 0;
468
+ const { limit, skip, sort, includeDeleted, project, dbQuery } = query;
438
469
  try {
439
- limit = urlQuery.limit || 10;
440
- skip = urlQuery.skip || 0;
441
- const sort = urlQuery.sort || { created: -1 };
442
- const includeDeleted = urlQuery.includeDeleted || false;
443
- let project = {};
444
- if (urlQuery.select) {
445
- if (typeof urlQuery.select === 'string') {
446
- const fields = urlQuery.select.split(',');
447
- fields.forEach((field) => {
448
- project[field] = true;
449
- });
450
- }
451
- else {
452
- Object.keys(urlQuery.select).forEach((field) => {
453
- project[field] = true;
454
- });
455
- }
456
- }
457
- delete urlQuery.limit;
458
- delete urlQuery.skip;
459
- delete urlQuery.sort;
460
- delete urlQuery.select;
461
- delete urlQuery.includeDeleted;
462
- debug('db.index()', urlQuery);
463
- const dbQuery = this.dbQuery(urlQuery);
464
470
  items = (yield this.find(form, dbQuery, limit, skip, sort, project, collection, includeDeleted)) || [];
465
471
  count = yield this.count(form, dbQuery, collection, includeDeleted);
466
472
  }
@@ -580,7 +586,12 @@ class Database {
580
586
  if (!collection) {
581
587
  return [];
582
588
  }
583
- return yield collection.find(this.query(form, dbQuery, includeDeleted)).limit(limit).skip(skip).sort(sort).project(select).toArray();
589
+ return yield collection.find(this.query(form, dbQuery, includeDeleted))
590
+ .limit(parseInt(limit.toString()))
591
+ .skip(parseInt(skip.toString()))
592
+ .sort(sort)
593
+ .project(select)
594
+ .toArray();
584
595
  }
585
596
  catch (err) {
586
597
  error(err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/appserver",
3
- "version": "2.11.1",
3
+ "version": "2.12.0-rc.1",
4
4
  "description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
5
5
  "main": "lib/server.js",
6
6
  "types": "lib/server.d.ts",
@@ -10,7 +10,9 @@
10
10
  "scripts": {
11
11
  "clean": "rm -rf lib",
12
12
  "build": "npm run clean && tsc",
13
+ "build:lib": "npm run clean && tsc; true",
13
14
  "test": "mocha",
15
+ "dev": "tsc --watch --preserveWatchOutput",
14
16
  "prepack": "npm run build"
15
17
  },
16
18
  "repository": {
@@ -31,16 +33,16 @@
31
33
  ],
32
34
  "homepage": "https://github.com/formio/appserver#readme",
33
35
  "dependencies": {
34
- "@formio/appserver-core": "^2.11.1",
36
+ "@formio/appserver-core": "^2.12.0-rc.1",
35
37
  "@formio/core": "2.5.1-dev.291.6557e4e",
36
38
  "async": "^3.2.6",
37
39
  "bcryptjs": "^3.0.3",
38
40
  "debug": "^4.4.3",
39
- "dotenv": "^17.2.3",
41
+ "dotenv": "^17.2.4",
40
42
  "express": "^5.2.1",
41
43
  "jsonwebtoken": "^9.0.3",
42
44
  "lodash": "^4.17.23",
43
- "mongodb": "^7.0.0"
45
+ "mongodb": "^7.1.0"
44
46
  },
45
47
  "devDependencies": {
46
48
  "@types/async": "^3.2.25",
@@ -50,7 +52,7 @@
50
52
  "@types/jsonwebtoken": "^9.0.10",
51
53
  "@types/lodash": "^4.17.23",
52
54
  "@types/mocha": "^10.0.10",
53
- "@types/node": "^25.1.0",
55
+ "@types/node": "^25.2.3",
54
56
  "chai": "^6.2.2",
55
57
  "cross-env": "^10.1.0",
56
58
  "mocha": "^11.7.5",