@terreno/api 0.0.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.
Files changed (119) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +170 -0
  3. package/biome.jsonc +22 -0
  4. package/bunfig.toml +4 -0
  5. package/dist/api.d.ts +227 -0
  6. package/dist/api.js +1024 -0
  7. package/dist/api.test.d.ts +1 -0
  8. package/dist/api.test.js +2143 -0
  9. package/dist/auth.d.ts +50 -0
  10. package/dist/auth.js +512 -0
  11. package/dist/auth.test.d.ts +1 -0
  12. package/dist/auth.test.js +778 -0
  13. package/dist/errors.d.ts +75 -0
  14. package/dist/errors.js +216 -0
  15. package/dist/example.d.ts +1 -0
  16. package/dist/example.js +118 -0
  17. package/dist/expressServer.d.ts +35 -0
  18. package/dist/expressServer.js +436 -0
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +30 -0
  21. package/dist/logger.d.ts +23 -0
  22. package/dist/logger.js +249 -0
  23. package/dist/middleware.d.ts +10 -0
  24. package/dist/middleware.js +52 -0
  25. package/dist/notifiers/googleChatNotifier.d.ts +5 -0
  26. package/dist/notifiers/googleChatNotifier.js +130 -0
  27. package/dist/notifiers/googleChatNotifier.test.d.ts +1 -0
  28. package/dist/notifiers/googleChatNotifier.test.js +260 -0
  29. package/dist/notifiers/index.d.ts +3 -0
  30. package/dist/notifiers/index.js +19 -0
  31. package/dist/notifiers/slackNotifier.d.ts +5 -0
  32. package/dist/notifiers/slackNotifier.js +130 -0
  33. package/dist/notifiers/slackNotifier.test.d.ts +1 -0
  34. package/dist/notifiers/slackNotifier.test.js +259 -0
  35. package/dist/notifiers/zoomNotifier.d.ts +34 -0
  36. package/dist/notifiers/zoomNotifier.js +181 -0
  37. package/dist/notifiers/zoomNotifier.test.d.ts +1 -0
  38. package/dist/notifiers/zoomNotifier.test.js +370 -0
  39. package/dist/openApi.d.ts +60 -0
  40. package/dist/openApi.js +441 -0
  41. package/dist/openApi.test.d.ts +1 -0
  42. package/dist/openApi.test.js +445 -0
  43. package/dist/openApiBuilder.d.ts +419 -0
  44. package/dist/openApiBuilder.js +424 -0
  45. package/dist/openApiBuilder.test.d.ts +1 -0
  46. package/dist/openApiBuilder.test.js +509 -0
  47. package/dist/openApiEtag.d.ts +7 -0
  48. package/dist/openApiEtag.js +38 -0
  49. package/dist/permissions.d.ts +26 -0
  50. package/dist/permissions.js +331 -0
  51. package/dist/permissions.test.d.ts +1 -0
  52. package/dist/permissions.test.js +413 -0
  53. package/dist/plugins.d.ts +67 -0
  54. package/dist/plugins.js +315 -0
  55. package/dist/plugins.test.d.ts +1 -0
  56. package/dist/plugins.test.js +639 -0
  57. package/dist/populate.d.ts +14 -0
  58. package/dist/populate.js +315 -0
  59. package/dist/populate.test.d.ts +1 -0
  60. package/dist/populate.test.js +133 -0
  61. package/dist/response.d.ts +0 -0
  62. package/dist/response.js +1 -0
  63. package/dist/tests/bunSetup.d.ts +1 -0
  64. package/dist/tests/bunSetup.js +297 -0
  65. package/dist/tests/index.d.ts +1 -0
  66. package/dist/tests/index.js +17 -0
  67. package/dist/tests.d.ts +99 -0
  68. package/dist/tests.js +273 -0
  69. package/dist/transformers.d.ts +25 -0
  70. package/dist/transformers.js +217 -0
  71. package/dist/transformers.test.d.ts +1 -0
  72. package/dist/transformers.test.js +370 -0
  73. package/dist/utils.d.ts +11 -0
  74. package/dist/utils.js +143 -0
  75. package/dist/utils.test.d.ts +1 -0
  76. package/dist/utils.test.js +14 -0
  77. package/index.ts +1 -0
  78. package/package.json +88 -0
  79. package/src/__snapshots__/openApi.test.ts.snap +4814 -0
  80. package/src/__snapshots__/openApiBuilder.test.ts.snap +1485 -0
  81. package/src/api.test.ts +1661 -0
  82. package/src/api.ts +1036 -0
  83. package/src/auth.test.ts +550 -0
  84. package/src/auth.ts +408 -0
  85. package/src/errors.ts +225 -0
  86. package/src/example.ts +99 -0
  87. package/src/express.d.ts +5 -0
  88. package/src/expressServer.ts +387 -0
  89. package/src/index.ts +14 -0
  90. package/src/logger.ts +190 -0
  91. package/src/middleware.ts +18 -0
  92. package/src/notifiers/googleChatNotifier.test.ts +114 -0
  93. package/src/notifiers/googleChatNotifier.ts +47 -0
  94. package/src/notifiers/index.ts +3 -0
  95. package/src/notifiers/slackNotifier.test.ts +113 -0
  96. package/src/notifiers/slackNotifier.ts +55 -0
  97. package/src/notifiers/zoomNotifier.test.ts +207 -0
  98. package/src/notifiers/zoomNotifier.ts +111 -0
  99. package/src/openApi.test.ts +331 -0
  100. package/src/openApi.ts +494 -0
  101. package/src/openApiBuilder.test.ts +442 -0
  102. package/src/openApiBuilder.ts +636 -0
  103. package/src/openApiEtag.ts +40 -0
  104. package/src/permissions.test.ts +219 -0
  105. package/src/permissions.ts +228 -0
  106. package/src/plugins.test.ts +390 -0
  107. package/src/plugins.ts +289 -0
  108. package/src/populate.test.ts +65 -0
  109. package/src/populate.ts +258 -0
  110. package/src/response.ts +0 -0
  111. package/src/tests/bunSetup.ts +234 -0
  112. package/src/tests/index.ts +1 -0
  113. package/src/tests.ts +218 -0
  114. package/src/transformers.test.ts +202 -0
  115. package/src/transformers.ts +170 -0
  116. package/src/utils.test.ts +14 -0
  117. package/src/utils.ts +47 -0
  118. package/tsconfig.json +60 -0
  119. package/types.d.ts +17 -0
@@ -0,0 +1,75 @@
1
+ import type { NextFunction, Request, Response } from "express";
2
+ import { Schema } from "mongoose";
3
+ export interface APIErrorConstructor {
4
+ title: string;
5
+ fields?: {
6
+ [id: string]: string;
7
+ };
8
+ id?: string;
9
+ links?: {
10
+ about?: string;
11
+ type?: string;
12
+ } | undefined;
13
+ status?: number;
14
+ code?: string;
15
+ detail?: string;
16
+ source?: {
17
+ pointer?: string;
18
+ parameter?: string;
19
+ header?: string;
20
+ };
21
+ meta?: {
22
+ [id: string]: string;
23
+ };
24
+ error?: Error;
25
+ disableExternalErrorTracking?: boolean;
26
+ }
27
+ /**
28
+ * APIError is a simple way to throw an error in an API route and control what is shown and the
29
+ * HTTP code displayed. It follows the JSONAPI spec to standardize the fields,
30
+ * allowing the UI to show more consistent, better error messages.
31
+ *
32
+ * ```ts
33
+ * throw new APIError({
34
+ * title: "Only an admin can update that!",
35
+ * status: 403,
36
+ * code: "update-admin-error",
37
+ * detail: "You must be an admin to change that field"
38
+ * });
39
+ * ```
40
+ */
41
+ export declare class APIError extends Error {
42
+ title: string;
43
+ id: string | undefined;
44
+ links: {
45
+ about?: string;
46
+ type?: string;
47
+ } | undefined;
48
+ status: number;
49
+ code: string | undefined;
50
+ detail: string | undefined;
51
+ source: {
52
+ pointer?: string;
53
+ parameter?: string;
54
+ header?: string;
55
+ } | undefined;
56
+ meta: {
57
+ [id: string]: any;
58
+ } | undefined;
59
+ error?: Error;
60
+ disableExternalErrorTracking?: boolean;
61
+ constructor(data: APIErrorConstructor);
62
+ }
63
+ export declare function errorsPlugin(schema: Schema): void;
64
+ export declare function isAPIError(error: Error): error is APIError;
65
+ /**
66
+ * Safely extracts the disableExternalErrorTracking property from an error.
67
+ * Works with both APIError instances and regular Error objects that may have
68
+ * this property attached.
69
+ */
70
+ export declare function getDisableExternalErrorTracking(error: unknown): boolean | undefined;
71
+ export declare function getAPIErrorBody(error: APIError): {
72
+ [id: string]: any;
73
+ };
74
+ export declare function apiUnauthorizedMiddleware(err: Error, _req: Request, res: Response, next: NextFunction): void;
75
+ export declare function apiErrorMiddleware(err: Error, _req: Request, res: Response, next: NextFunction): void;
package/dist/errors.js ADDED
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ var __values = (this && this.__values) || function(o) {
51
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
52
+ if (m) return m.call(o);
53
+ if (o && typeof o.length === "number") return {
54
+ next: function () {
55
+ if (o && i >= o.length) o = void 0;
56
+ return { value: o && o[i++], done: !o };
57
+ }
58
+ };
59
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.APIError = void 0;
63
+ exports.errorsPlugin = errorsPlugin;
64
+ exports.isAPIError = isAPIError;
65
+ exports.getDisableExternalErrorTracking = getDisableExternalErrorTracking;
66
+ exports.getAPIErrorBody = getAPIErrorBody;
67
+ exports.apiUnauthorizedMiddleware = apiUnauthorizedMiddleware;
68
+ exports.apiErrorMiddleware = apiErrorMiddleware;
69
+ // https://jsonapi.org/format/#errors
70
+ var Sentry = __importStar(require("@sentry/node"));
71
+ var mongoose_1 = require("mongoose");
72
+ var logger_1 = require("./logger");
73
+ /**
74
+ * APIError is a simple way to throw an error in an API route and control what is shown and the
75
+ * HTTP code displayed. It follows the JSONAPI spec to standardize the fields,
76
+ * allowing the UI to show more consistent, better error messages.
77
+ *
78
+ * ```ts
79
+ * throw new APIError({
80
+ * title: "Only an admin can update that!",
81
+ * status: 403,
82
+ * code: "update-admin-error",
83
+ * detail: "You must be an admin to change that field"
84
+ * });
85
+ * ```
86
+ */
87
+ var APIError = /** @class */ (function (_super) {
88
+ __extends(APIError, _super);
89
+ function APIError(data) {
90
+ var _a, _b;
91
+ // Include details in when the error is printed to the console or sent to Sentry.
92
+ var _this = _super.call(this, "".concat(data.title).concat(data.detail ? ": ".concat(data.detail) : "").concat(data.error ? "\n".concat(data.error.stack) : "")) || this;
93
+ _this.name = "APIError";
94
+ var title = data.title, id = data.id, links = data.links, status = data.status, code = data.code, detail = data.detail, source = data.source, meta = data.meta, fields = data.fields, error = data.error;
95
+ if (!status) {
96
+ status = 500;
97
+ }
98
+ else if (status && (status < 400 || status > 599)) {
99
+ logger_1.logger.error("Invalid ApiError status code: ".concat(status, ", using 500"));
100
+ status = 500;
101
+ }
102
+ _this.status = status;
103
+ _this.title = title;
104
+ _this.id = id;
105
+ _this.links = links;
106
+ _this.code = code;
107
+ _this.detail = detail;
108
+ _this.source = source;
109
+ _this.meta = meta !== null && meta !== void 0 ? meta : {};
110
+ _this.disableExternalErrorTracking = data.disableExternalErrorTracking;
111
+ if (fields) {
112
+ _this.meta.fields = fields;
113
+ }
114
+ _this.error = error;
115
+ logger_1.logger.error("APIError(".concat(status, "): ").concat(title, " ").concat(detail ? detail : "").concat(((_a = data.error) === null || _a === void 0 ? void 0 : _a.stack) ? "\n".concat((_b = data.error) === null || _b === void 0 ? void 0 : _b.stack) : ""));
116
+ return _this;
117
+ }
118
+ return APIError;
119
+ }(Error));
120
+ exports.APIError = APIError;
121
+ // This can be attached to any schema to store errors compatible with the JSONAPI spec.
122
+ // Lazily initialize to avoid module loading order issues with Bun where mongoose
123
+ // may not be fully initialized when this module loads.
124
+ // Create an errors field for storing error information in a JSONAPI compatible form directly on a
125
+ // model.
126
+ function errorsPlugin(schema) {
127
+ var errorSchema = new mongoose_1.Schema({
128
+ code: String,
129
+ detail: String,
130
+ id: String,
131
+ links: {
132
+ about: String,
133
+ type: String,
134
+ },
135
+ meta: mongoose_1.Schema.Types.Mixed,
136
+ source: {
137
+ header: String,
138
+ parameter: String,
139
+ pointer: String,
140
+ },
141
+ status: Number,
142
+ title: { required: true, type: String },
143
+ });
144
+ schema.add({ apiErrors: errorSchema });
145
+ }
146
+ function isAPIError(error) {
147
+ return error.name === "APIError";
148
+ }
149
+ /**
150
+ * Safely extracts the disableExternalErrorTracking property from an error.
151
+ * Works with both APIError instances and regular Error objects that may have
152
+ * this property attached.
153
+ */
154
+ function getDisableExternalErrorTracking(error) {
155
+ if (error instanceof Error) {
156
+ if (isAPIError(error)) {
157
+ return error.disableExternalErrorTracking;
158
+ }
159
+ }
160
+ if (error && typeof error === "object" && "disableExternalErrorTracking" in error) {
161
+ return error.disableExternalErrorTracking;
162
+ }
163
+ return undefined;
164
+ }
165
+ // Creates an APIError body to send to clients as JSON. Errors don't have a toJSON defined,
166
+ // and we want to strip out things like message, name, and stack for the client.
167
+ // There is almost certainly a more elegant solution to this.
168
+ function getAPIErrorBody(error) {
169
+ var e_1, _a;
170
+ var errorData = { status: error.status, title: error.title };
171
+ try {
172
+ for (var _b = __values([
173
+ "id",
174
+ "links",
175
+ "status",
176
+ "code",
177
+ "detail",
178
+ "source",
179
+ "meta",
180
+ "disableExternalErrorTracking",
181
+ ]), _c = _b.next(); !_c.done; _c = _b.next()) {
182
+ var key = _c.value;
183
+ if (error[key]) {
184
+ errorData[key] = error[key];
185
+ }
186
+ }
187
+ }
188
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
189
+ finally {
190
+ try {
191
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
192
+ }
193
+ finally { if (e_1) throw e_1.error; }
194
+ }
195
+ return errorData;
196
+ }
197
+ function apiUnauthorizedMiddleware(err, _req, res, next) {
198
+ if (err.message === "Unauthorized") {
199
+ // not using the actual APIError class here because we don't want to log it as an error.
200
+ res.status(401).json({ status: 401, title: "Unauthorized" }).send();
201
+ }
202
+ else {
203
+ next(err);
204
+ }
205
+ }
206
+ function apiErrorMiddleware(err, _req, res, next) {
207
+ if (isAPIError(err)) {
208
+ if (!err.disableExternalErrorTracking) {
209
+ Sentry.captureException(err);
210
+ }
211
+ res.status(err.status).json(getAPIErrorBody(err)).send();
212
+ }
213
+ else {
214
+ next(err);
215
+ }
216
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ var express_1 = __importDefault(require("express"));
51
+ var mongoose_1 = __importStar(require("mongoose"));
52
+ var passport_local_mongoose_1 = __importDefault(require("passport-local-mongoose"));
53
+ var api_1 = require("./api");
54
+ var auth_1 = require("./auth");
55
+ var expressServer_1 = require("./expressServer");
56
+ var logger_1 = require("./logger");
57
+ var permissions_1 = require("./permissions");
58
+ var plugins_1 = require("./plugins");
59
+ mongoose_1.default
60
+ .connect("mongodb://localhost:27017/example")
61
+ .then(function () {
62
+ logger_1.logger.debug("Connected to mongo");
63
+ })
64
+ .catch(function (err) {
65
+ logger_1.logger.error("Error connecting to mongo ".concat(err));
66
+ });
67
+ var userSchema = new mongoose_1.Schema({
68
+ admin: { default: false, type: Boolean },
69
+ username: String,
70
+ });
71
+ userSchema.plugin(passport_local_mongoose_1.default, { usernameField: "email" });
72
+ userSchema.plugin(plugins_1.createdUpdatedPlugin);
73
+ userSchema.plugin(plugins_1.baseUserPlugin);
74
+ var UserModel = (0, mongoose_1.model)("User", userSchema);
75
+ var schema = new mongoose_1.Schema({
76
+ calories: Number,
77
+ created: Date,
78
+ hidden: { default: false, type: Boolean },
79
+ name: String,
80
+ ownerId: { ref: "User", type: "ObjectId" },
81
+ });
82
+ var FoodModel = (0, mongoose_1.model)("Food", schema);
83
+ function getBaseServer() {
84
+ var app = (0, express_1.default)();
85
+ app.all("/*", function (req, res, next) {
86
+ res.header("Access-Control-Allow-Origin", "*");
87
+ res.header("Access-Control-Allow-Headers", "*");
88
+ // intercepts OPTIONS method
89
+ if (req.method === "OPTIONS") {
90
+ res.send(200);
91
+ }
92
+ else {
93
+ next();
94
+ }
95
+ });
96
+ app.use(express_1.default.json());
97
+ (0, auth_1.setupAuth)(app, UserModel);
98
+ (0, auth_1.addAuthRoutes)(app, UserModel);
99
+ function addRoutes(router, options) {
100
+ router.use("/food", (0, api_1.modelRouter)(FoodModel, __assign(__assign({}, options), { openApiOverwrite: {
101
+ get: { responses: { 200: { description: "Get all the food" } } },
102
+ }, permissions: {
103
+ create: [permissions_1.Permissions.IsAuthenticated],
104
+ delete: [permissions_1.Permissions.IsAdmin],
105
+ list: [permissions_1.Permissions.IsAny],
106
+ read: [permissions_1.Permissions.IsAny],
107
+ update: [permissions_1.Permissions.IsOwner],
108
+ }, queryFields: ["name", "calories", "created", "ownerId", "hidden"] })));
109
+ }
110
+ return (0, expressServer_1.setupServer)({
111
+ addRoutes: addRoutes,
112
+ loggingOptions: {
113
+ level: "debug",
114
+ },
115
+ userModel: UserModel,
116
+ });
117
+ }
118
+ getBaseServer();
@@ -0,0 +1,35 @@
1
+ import * as Sentry from "@sentry/node";
2
+ import express, { type Router } from "express";
3
+ import type jwt from "jsonwebtoken";
4
+ import type { modelRouterOptions } from "./api";
5
+ import { type UserModel as UserMongooseModel } from "./auth";
6
+ import { type LoggingOptions } from "./logger";
7
+ export declare function setupEnvironment(): void;
8
+ export type AddRoutes = (router: Router, options?: Partial<modelRouterOptions<any>>) => void;
9
+ export declare function logRequests(req: any, res: any, next: any): void;
10
+ export declare function createRouter(rootPath: string, addRoutes: AddRoutes, middleware?: any[]): any[];
11
+ export declare function createRouterWithAuth(rootPath: string, addRoutes: (router: Router) => void, middleware?: any[]): any[];
12
+ export interface AuthOptions {
13
+ generateJWTPayload?: (user: any) => Record<string, any>;
14
+ generateTokenExpiration?: (user: any) => number | jwt.SignOptions["expiresIn"];
15
+ generateRefreshTokenExpiration?: (user: any) => number | jwt.SignOptions["expiresIn"];
16
+ }
17
+ export interface SetupServerOptions {
18
+ userModel: UserMongooseModel;
19
+ addRoutes: AddRoutes;
20
+ loggingOptions?: LoggingOptions;
21
+ authOptions?: AuthOptions;
22
+ skipListen?: boolean;
23
+ corsOrigin?: string | boolean | RegExp | Array<boolean | string | RegExp> | ((requestOrigin: string | undefined, callback: (err: Error | null, origin?: boolean | string | RegExp | Array<boolean | string | RegExp>) => void) => void);
24
+ addMiddleware?: AddRoutes;
25
+ ignoreTraces?: string[];
26
+ sentryOptions?: Sentry.NodeOptions;
27
+ }
28
+ export declare function setupServer(options: SetupServerOptions): express.Application;
29
+ export declare function cronjob(name: string, schedule: "hourly" | "minutely" | string, callback: () => void): void;
30
+ export interface WrapScriptOptions {
31
+ onFinish?: (result?: any) => void | Promise<void>;
32
+ terminateTimeout?: number;
33
+ slackChannel?: string;
34
+ }
35
+ export declare function wrapScript(func: () => Promise<any>, options?: WrapScriptOptions): Promise<void>;