@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
package/dist/utils.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __generator = (this && this.__generator) || function (thisArg, body) {
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
+ function verb(n) { return function (v) { return step([n, v]); }; }
48
+ function step(op) {
49
+ if (f) throw new TypeError("Generator is already executing.");
50
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
+ 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;
52
+ if (y = 0, t) op = [op[0] & 2, t.value];
53
+ switch (op[0]) {
54
+ case 0: case 1: t = op; break;
55
+ case 4: _.label++; return { value: op[1], done: false };
56
+ case 5: _.label++; y = op[1]; op = [0]; continue;
57
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
+ default:
59
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
+ if (t[2]) _.ops.pop();
64
+ _.trys.pop(); continue;
65
+ }
66
+ op = body.call(thisArg, _);
67
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
+ }
70
+ };
71
+ var __values = (this && this.__values) || function(o) {
72
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
73
+ if (m) return m.call(o);
74
+ if (o && typeof o.length === "number") return {
75
+ next: function () {
76
+ if (o && i >= o.length) o = void 0;
77
+ return { value: o && o[i++], done: !o };
78
+ }
79
+ };
80
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
81
+ };
82
+ Object.defineProperty(exports, "__esModule", { value: true });
83
+ exports.timeout = void 0;
84
+ exports.isValidObjectId = isValidObjectId;
85
+ exports.checkModelsStrict = checkModelsStrict;
86
+ var mongoose_1 = __importStar(require("mongoose"));
87
+ var logger_1 = require("./logger");
88
+ // A better version of mongoose's ObjectId.isValid,
89
+ // which falsely will say any 12 character string is valid.
90
+ function isValidObjectId(id) {
91
+ try {
92
+ return new mongoose_1.Types.ObjectId(id).toString() === id;
93
+ }
94
+ catch (error) {
95
+ logger_1.logger.error("Error validating object id ".concat(id, ": ").concat(error));
96
+ return false;
97
+ }
98
+ }
99
+ var timeout = function (ms) { return __awaiter(void 0, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
102
+ });
103
+ }); };
104
+ exports.timeout = timeout;
105
+ /**
106
+ * Ensure that all mongoose models are set to strict mode.
107
+ * This validates that models will throw errors when attempting to set
108
+ * properties that aren't defined in the schema.
109
+ *
110
+ * @param ignoredModels - Array of model names to skip validation for
111
+ * @throws Error if any model is not set to strict mode or missing virtual settings
112
+ */
113
+ function checkModelsStrict(ignoredModels) {
114
+ var e_1, _a;
115
+ var _b, _c;
116
+ if (ignoredModels === void 0) { ignoredModels = []; }
117
+ var models = mongoose_1.default.modelNames();
118
+ try {
119
+ for (var models_1 = __values(models), models_1_1 = models_1.next(); !models_1_1.done; models_1_1 = models_1.next()) {
120
+ var model = models_1_1.value;
121
+ var schema = mongoose_1.default.model(model).schema;
122
+ if (((_b = schema.get("toObject")) === null || _b === void 0 ? void 0 : _b.virtuals) !== true) {
123
+ throw new Error("Model ".concat(model, " toObject.virtuals not set to true"));
124
+ }
125
+ if (((_c = schema.get("toJSON")) === null || _c === void 0 ? void 0 : _c.virtuals) !== true) {
126
+ throw new Error("Model ".concat(model, " toJSON.virtuals not set to true"));
127
+ }
128
+ if (ignoredModels.includes(model)) {
129
+ continue;
130
+ }
131
+ if (schema.get("strict") !== "throw") {
132
+ throw new Error("Model ".concat(model, " is not set to strict mode."));
133
+ }
134
+ }
135
+ }
136
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
137
+ finally {
138
+ try {
139
+ if (models_1_1 && !models_1_1.done && (_a = models_1.return)) _a.call(models_1);
140
+ }
141
+ finally { if (e_1) throw e_1.error; }
142
+ }
143
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var bun_test_1 = require("bun:test");
4
+ var utils_1 = require("./utils");
5
+ (0, bun_test_1.describe)("utils", function () {
6
+ (0, bun_test_1.it)("checks valid ObjectIds", function () {
7
+ (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("62c44da0003d9f8ee8cc925c")).toBe(true);
8
+ (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("620000000000000000000000")).toBe(true);
9
+ // Mongoose's builtin "ObjectId.isValid" will falsely say this is an ObjectId.
10
+ (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("1234567890ab")).toBe(false);
11
+ (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("microsoft123")).toBe(false);
12
+ (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("62c44da0003d9f8ee8cc925x")).toBe(false);
13
+ });
14
+ });
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ console.log("Hello via Bun!");
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "author": "Josh Gachnang",
3
+ "bugs": {
4
+ "url": "https://github.com/FlourishHealth/terreno/issues"
5
+ },
6
+ "dependencies": {
7
+ "@sentry/node": "^10.25.0",
8
+ "@sentry/profiling-node": "^10.25.0",
9
+ "@types/qs": "^6.14.0",
10
+ "@wesleytodd/openapi": "^1.1.0",
11
+ "axios": "^1.13.2",
12
+ "cors": "^2.8.5",
13
+ "cron": "^4.3.4",
14
+ "expo-server-sdk": "^3.14.0",
15
+ "express": "^4.21.2",
16
+ "generaterr": "^1.5.0",
17
+ "jsonwebtoken": "^9.0.2",
18
+ "lodash": "^4.17.21",
19
+ "luxon": "^3.7.2",
20
+ "mongoose": "^9.1.1",
21
+ "mongoose-to-swagger": "^1.4.0",
22
+ "ms": "^2.1.3",
23
+ "on-finished": "^2.3.0",
24
+ "passport": "^0.7.0",
25
+ "passport-anonymous": "^1.0.1",
26
+ "passport-jwt": "^4.0.0",
27
+ "passport-local": "^1.0.0",
28
+ "passport-local-mongoose": "^9.0.1",
29
+ "qs": "^6.14.1",
30
+ "scmp": "^2.1.0",
31
+ "winston": "^3.18.3"
32
+ },
33
+ "description": "Styled after the Django & Django REST Framework, a batteries-include framework for building REST APIs with Node/Express/Mongoose.",
34
+ "devDependencies": {
35
+ "@biomejs/biome": "^2.3.6",
36
+ "@types/bcrypt": "^5.0.2",
37
+ "@types/bun": "^1.2.4",
38
+ "@types/cors": "^2.8.17",
39
+ "@types/cron": "^2.4.3",
40
+ "@types/express": "^4.17.21",
41
+ "@types/jsonwebtoken": "^9.0.9",
42
+ "@types/lodash": "^4.17.15",
43
+ "@types/node": "^22.13.5",
44
+ "@types/on-finished": "^2.3.4",
45
+ "@types/passport": "^1.0.17",
46
+ "@types/passport-anonymous": "^1.0.5",
47
+ "@types/passport-jwt": "^4.0.1",
48
+ "@types/passport-local": "^1.0.38",
49
+ "@types/sinon": "^17.0.4",
50
+ "@types/supertest": "^6.0.2",
51
+ "sinon": "^19.0.2",
52
+ "supertest": "^7.0.0",
53
+ "typedoc": "~0.27.9",
54
+ "typescript": "5.8.2"
55
+ },
56
+ "homepage": "https://github.com/FlourishHealth/terreno#readme",
57
+ "keywords": [
58
+ "rest",
59
+ "api",
60
+ "mongoose",
61
+ "express"
62
+ ],
63
+ "license": "Apache-2.0",
64
+ "main": "dist/index.js",
65
+ "name": "@terreno/api",
66
+ "peerDependencies": {
67
+ "mongoose": "^9.0.0"
68
+ },
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "git+ssh://git@github.com/FlourishHealth/terreno.git"
72
+ },
73
+ "resolutions": {
74
+ "json5": "2.2.3"
75
+ },
76
+ "scripts": {
77
+ "compile": "bun tsc",
78
+ "dev": "bun tsc -w",
79
+ "docs": "typedoc --out docs src/index.ts",
80
+ "lint": "biome check ./src",
81
+ "lint:fix": "biome check --write ./src",
82
+ "lint:unsafefix": "biome check --fix --unsafe ./src",
83
+ "test": "bun test --preload ./src/tests/bunSetup.ts",
84
+ "updateSnapshot": "bun test --update-snapshots"
85
+ },
86
+ "types": "dist/index.d.ts",
87
+ "version": "0.0.1"
88
+ }