@terreno/api 0.7.2 → 0.8.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.
- package/dist/__tests__/{versionCheck.test.js → versionCheckPlugin.test.js} +2 -2
- package/dist/api.d.ts +4 -2
- package/dist/api.js +7 -2
- package/dist/consentApp.d.ts +33 -0
- package/dist/consentApp.js +484 -0
- package/dist/consentApp.test.d.ts +1 -0
- package/dist/consentApp.test.js +1132 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/models/consentForm.d.ts +2 -0
- package/dist/models/consentForm.js +115 -0
- package/dist/models/consentResponse.d.ts +2 -0
- package/dist/models/consentResponse.js +73 -0
- package/dist/models/versionConfig.d.ts +1 -1
- package/dist/openApiValidator.js +2 -0
- package/dist/populate.d.ts +1 -0
- package/dist/populate.js +53 -13
- package/dist/syncConsents.d.ts +67 -0
- package/dist/syncConsents.js +334 -0
- package/dist/syncConsents.test.d.ts +1 -0
- package/dist/syncConsents.test.js +249 -0
- package/dist/terrenoApp.js +6 -5
- package/dist/terrenoPlugin.d.ts +1 -1
- package/dist/types/consentForm.d.ts +32 -0
- package/dist/types/consentForm.js +2 -0
- package/dist/types/consentResponse.d.ts +23 -0
- package/dist/types/consentResponse.js +2 -0
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +1 -1
- package/dist/versionCheckPlugin.d.ts +2 -0
- package/dist/versionCheckPlugin.js +3 -6
- package/package.json +1 -1
- package/src/__tests__/{versionCheck.test.ts → versionCheckPlugin.test.ts} +2 -2
- package/src/api.ts +11 -4
- package/src/consentApp.test.ts +749 -0
- package/src/consentApp.ts +463 -0
- package/src/index.ts +6 -0
- package/src/models/consentForm.ts +123 -0
- package/src/models/consentResponse.ts +78 -0
- package/src/models/versionConfig.ts +1 -1
- package/src/openApiValidator.ts +2 -0
- package/src/populate.ts +33 -0
- package/src/syncConsents.test.ts +124 -0
- package/src/syncConsents.ts +263 -0
- package/src/terrenoApp.ts +6 -6
- package/src/terrenoPlugin.ts +1 -1
- package/src/types/consentForm.ts +41 -0
- package/src/types/consentResponse.ts +34 -0
- package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +1 -1
- package/src/versionCheckPlugin.ts +5 -6
- /package/dist/__tests__/{versionCheck.test.d.ts → versionCheckPlugin.test.d.ts} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type mongoose from "mongoose";
|
|
2
|
+
import type { FindExactlyOnePlugin, FindOneOrNonePlugin } from "../plugins";
|
|
3
|
+
export type ConsentResponseMethods = {};
|
|
4
|
+
export type ConsentResponseStatics = FindExactlyOnePlugin<ConsentResponseDocument> & FindOneOrNonePlugin<ConsentResponseDocument>;
|
|
5
|
+
export type ConsentResponseModel = mongoose.Model<ConsentResponseDocument, object, ConsentResponseMethods> & ConsentResponseStatics;
|
|
6
|
+
export interface ConsentResponseDocument extends mongoose.Document {
|
|
7
|
+
_id: mongoose.Types.ObjectId;
|
|
8
|
+
userId: mongoose.Types.ObjectId;
|
|
9
|
+
consentFormId: mongoose.Types.ObjectId;
|
|
10
|
+
agreed: boolean;
|
|
11
|
+
agreedAt: Date;
|
|
12
|
+
checkboxValues?: Map<string, boolean>;
|
|
13
|
+
locale: string;
|
|
14
|
+
signature?: string;
|
|
15
|
+
signedAt?: Date;
|
|
16
|
+
ipAddress?: string;
|
|
17
|
+
userAgent?: string;
|
|
18
|
+
contentSnapshot?: string;
|
|
19
|
+
formVersionSnapshot?: number;
|
|
20
|
+
created: Date;
|
|
21
|
+
updated: Date;
|
|
22
|
+
deleted: boolean;
|
|
23
|
+
}
|
|
@@ -108,7 +108,7 @@ function processComplexMatch(thing, keys) {
|
|
|
108
108
|
// (i.e. /:id, /:name, etc...) with the name(s) of those parameter(s)
|
|
109
109
|
// This could have been accomplished with replaceAll for Node version 15 and above
|
|
110
110
|
// no-useless-escape is disabled since we need three backslashes
|
|
111
|
-
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g, function () { return "{".concat(keys[i++].name, "}"); })
|
|
111
|
+
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g, function () { return "{".concat(keys[i++].name, "}"); })
|
|
112
112
|
.replace(/\\(.)/g, '$1')
|
|
113
113
|
// The replace below removes the regex used at the start of the string and
|
|
114
114
|
// the regex used to match the query parameters
|
|
@@ -3,8 +3,10 @@ import type { TerrenoPlugin } from "./terrenoPlugin";
|
|
|
3
3
|
export type VersionCheckStatus = "ok" | "warning" | "required";
|
|
4
4
|
export interface VersionCheckResponse {
|
|
5
5
|
message?: string;
|
|
6
|
+
requiredVersion?: number;
|
|
6
7
|
status: VersionCheckStatus;
|
|
7
8
|
updateUrl?: string;
|
|
9
|
+
warningVersion?: number;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* TerrenoPlugin that adds a public GET /version-check endpoint for upgrade enforcement.
|
|
@@ -80,21 +80,18 @@ var VersionCheckPlugin = /** @class */ (function () {
|
|
|
80
80
|
? ((_c = config.webWarningVersion) !== null && _c !== void 0 ? _c : 0)
|
|
81
81
|
: ((_d = config.mobileWarningVersion) !== null && _d !== void 0 ? _d : 0);
|
|
82
82
|
response = {
|
|
83
|
+
requiredVersion: requiredVersion > 0 ? requiredVersion : undefined,
|
|
83
84
|
status: "ok",
|
|
85
|
+
updateUrl: config.updateUrl || undefined,
|
|
86
|
+
warningVersion: warningVersion > 0 ? warningVersion : undefined,
|
|
84
87
|
};
|
|
85
88
|
if (requiredVersion > 0 && version < requiredVersion) {
|
|
86
89
|
response.status = "required";
|
|
87
90
|
response.message = (_e = config.requiredMessage) !== null && _e !== void 0 ? _e : DEFAULT_REQUIRED_MESSAGE;
|
|
88
|
-
if (config.updateUrl) {
|
|
89
|
-
response.updateUrl = config.updateUrl;
|
|
90
|
-
}
|
|
91
91
|
}
|
|
92
92
|
else if (warningVersion > 0 && version < warningVersion) {
|
|
93
93
|
response.status = "warning";
|
|
94
94
|
response.message = (_f = config.warningMessage) !== null && _f !== void 0 ? _f : DEFAULT_WARNING_MESSAGE;
|
|
95
|
-
if (config.updateUrl) {
|
|
96
|
-
response.updateUrl = config.updateUrl;
|
|
97
|
-
}
|
|
98
95
|
}
|
|
99
96
|
return [2 /*return*/, res.json(response)];
|
|
100
97
|
}
|
package/package.json
CHANGED
|
@@ -52,7 +52,7 @@ describe("VersionCheckPlugin", () => {
|
|
|
52
52
|
|
|
53
53
|
const res = await app.get("/version-check").query({platform: "web", version: 150});
|
|
54
54
|
expect(res.status).toBe(200);
|
|
55
|
-
expect(res.body).toEqual({status: "ok"});
|
|
55
|
+
expect(res.body).toEqual({requiredVersion: 50, status: "ok", warningVersion: 100});
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("returns warning when client version < warning (web)", async () => {
|
|
@@ -116,7 +116,7 @@ describe("VersionCheckPlugin", () => {
|
|
|
116
116
|
|
|
117
117
|
const res = await app.get("/version-check").query({platform: "web", version: 100});
|
|
118
118
|
expect(res.status).toBe(200);
|
|
119
|
-
expect(res.body).toEqual({status: "ok"});
|
|
119
|
+
expect(res.body).toEqual({requiredVersion: 50, status: "ok", warningVersion: 100});
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
it("version equal to required returns warning not required", async () => {
|
package/src/api.ts
CHANGED
|
@@ -160,8 +160,8 @@ export interface ModelRouterOptions<T> {
|
|
|
160
160
|
* query, max limit,
|
|
161
161
|
* or 500. */
|
|
162
162
|
maxLimit?: number; // defaults to 500
|
|
163
|
-
/** */
|
|
164
|
-
endpoints?: (router: any) => void;
|
|
163
|
+
/** Custom route setup function. Receives the router and optionally the full options (including openApi). */
|
|
164
|
+
endpoints?: (router: any, options?: Partial<ModelRouterOptions<T>>) => void;
|
|
165
165
|
/**
|
|
166
166
|
* Hook that runs after `transformer.transform` but before the object is created.
|
|
167
167
|
* Can update the body fields based on the request or the user.
|
|
@@ -416,6 +416,8 @@ export interface ModelRouterRegistration {
|
|
|
416
416
|
path: string;
|
|
417
417
|
/** The Express router containing CRUD endpoints */
|
|
418
418
|
router: express.Router;
|
|
419
|
+
/** @internal Rebuilds the router with the openApi instance injected into options */
|
|
420
|
+
_buildWithOpenApi: (openApi: any) => express.Router;
|
|
419
421
|
}
|
|
420
422
|
|
|
421
423
|
/**
|
|
@@ -459,7 +461,12 @@ export function modelRouter<T>(
|
|
|
459
461
|
const router = _buildModelRouter(model, options);
|
|
460
462
|
|
|
461
463
|
if (path !== undefined) {
|
|
462
|
-
return {
|
|
464
|
+
return {
|
|
465
|
+
__type: "modelRouter",
|
|
466
|
+
_buildWithOpenApi: (openApi: any) => _buildModelRouter(model, {...options, openApi}),
|
|
467
|
+
path,
|
|
468
|
+
router,
|
|
469
|
+
};
|
|
463
470
|
}
|
|
464
471
|
return router;
|
|
465
472
|
}
|
|
@@ -469,7 +476,7 @@ function _buildModelRouter<T>(model: Model<T>, options: ModelRouterOptions<T>):
|
|
|
469
476
|
|
|
470
477
|
// Do before the other router options so endpoints take priority.
|
|
471
478
|
if (options.endpoints) {
|
|
472
|
-
options.endpoints(router);
|
|
479
|
+
options.endpoints(router, options);
|
|
473
480
|
}
|
|
474
481
|
|
|
475
482
|
const responseHandler = options.responseHandler ?? defaultResponseHandler;
|