@terreno/api 0.3.0 → 0.4.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/api.js +9 -8
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +7 -1
- package/dist/betterAuthSetup.js +15 -9
- package/dist/configuration.test.d.ts +1 -0
- package/dist/configuration.test.js +699 -0
- package/dist/configurationApp.d.ts +91 -0
- package/dist/configurationApp.js +407 -0
- package/dist/configurationPlugin.d.ts +102 -0
- package/dist/configurationPlugin.js +285 -0
- package/dist/configurationPlugin.test.d.ts +1 -0
- package/dist/configurationPlugin.test.js +509 -0
- package/dist/example.js +1 -1
- package/dist/expressServer.js +5 -1
- package/dist/githubAuth.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/openApiCompat.d.ts +23 -0
- package/dist/openApiCompat.js +198 -0
- package/dist/scriptRunner.d.ts +52 -0
- package/dist/scriptRunner.js +231 -0
- package/dist/secretProviders.d.ts +47 -0
- package/dist/secretProviders.js +214 -0
- package/dist/terrenoApp.d.ts +25 -0
- package/dist/terrenoApp.js +50 -3
- package/dist/tests.d.ts +27 -9
- package/dist/tests.js +10 -1
- package/package.json +13 -13
- package/src/api.ts +9 -8
- package/src/auth.ts +7 -1
- package/src/betterAuthSetup.ts +5 -3
- package/src/configuration.test.ts +398 -0
- package/src/configurationApp.ts +359 -0
- package/src/configurationPlugin.test.ts +299 -0
- package/src/configurationPlugin.ts +288 -0
- package/src/example.ts +1 -1
- package/src/expressServer.ts +6 -1
- package/src/githubAuth.ts +4 -4
- package/src/index.ts +5 -0
- package/src/openApiCompat.ts +147 -0
- package/src/permissions.ts +1 -1
- package/src/scriptRunner.ts +219 -0
- package/src/secretProviders.ts +109 -0
- package/src/terrenoApp.ts +45 -3
- package/src/tests.ts +12 -1
package/dist/api.js
CHANGED
|
@@ -879,7 +879,7 @@ function _buildModelRouter(model, options) {
|
|
|
879
879
|
}); }));
|
|
880
880
|
function arrayOperation(req, res, operation) {
|
|
881
881
|
return __awaiter(this, void 0, void 0, function () {
|
|
882
|
-
var doc, prevDoc, field, array, index, body, error_17, error_18, error_19;
|
|
882
|
+
var doc, prevDoc, field, itemId, array, index, body, error_17, error_18, error_19;
|
|
883
883
|
var _a;
|
|
884
884
|
var _b, _c;
|
|
885
885
|
return __generator(this, function (_d) {
|
|
@@ -911,36 +911,37 @@ function _buildModelRouter(model, options) {
|
|
|
911
911
|
title: "Patch not allowed for user ".concat((_c = req.user) === null || _c === void 0 ? void 0 : _c.id, " on doc ").concat(doc._id),
|
|
912
912
|
});
|
|
913
913
|
}
|
|
914
|
+
field = req.params.field;
|
|
915
|
+
itemId = req.params.itemId;
|
|
914
916
|
// We apply the operation *before* the hooks. As far as the callers are concerned, this should
|
|
915
917
|
// be like PATCHing the field and replacing the whole thing.
|
|
916
|
-
if (operation !== "DELETE" && req.body[
|
|
918
|
+
if (operation !== "DELETE" && req.body[field] === undefined) {
|
|
917
919
|
throw new errors_1.APIError({
|
|
918
920
|
status: 400,
|
|
919
921
|
title: "Malformed body, array operations should have a single, top level key, got: ".concat(Object.keys(req.body).join(",")),
|
|
920
922
|
});
|
|
921
923
|
}
|
|
922
|
-
field = req.params.field;
|
|
923
924
|
array = __spreadArray([], __read(doc[field]), false);
|
|
924
925
|
if (operation === "POST") {
|
|
925
926
|
array.push(req.body[field]);
|
|
926
927
|
}
|
|
927
928
|
else if (operation === "PATCH" || operation === "DELETE") {
|
|
928
929
|
index = void 0;
|
|
929
|
-
if ((0, utils_1.isValidObjectId)(
|
|
930
|
-
index = array.findIndex(function (x) { return x.id ===
|
|
930
|
+
if ((0, utils_1.isValidObjectId)(itemId)) {
|
|
931
|
+
index = array.findIndex(function (x) { return x.id === itemId; });
|
|
931
932
|
}
|
|
932
933
|
else {
|
|
933
|
-
index = array.findIndex(function (x) { return x ===
|
|
934
|
+
index = array.findIndex(function (x) { return x === itemId; });
|
|
934
935
|
}
|
|
935
936
|
if (index === -1) {
|
|
936
937
|
throw new errors_1.APIError({
|
|
937
938
|
status: 404,
|
|
938
|
-
title: "Could not find ".concat(field, "/").concat(
|
|
939
|
+
title: "Could not find ".concat(field, "/").concat(itemId),
|
|
939
940
|
});
|
|
940
941
|
}
|
|
941
942
|
// For PATCHing an item by ID, we need to merge the objects so we don't override the _id or
|
|
942
943
|
// other parts of the subdocument.
|
|
943
|
-
if (operation === "PATCH" && (0, utils_1.isValidObjectId)(
|
|
944
|
+
if (operation === "PATCH" && (0, utils_1.isValidObjectId)(itemId)) {
|
|
944
945
|
Object.assign(array[index], req.body[field]);
|
|
945
946
|
}
|
|
946
947
|
else if (operation === "PATCH") {
|
package/dist/auth.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface UserModel extends Model<User> {
|
|
|
19
19
|
deserializeUser(): any;
|
|
20
20
|
findByUsername(username: string, findOpts: any): any;
|
|
21
21
|
}
|
|
22
|
-
export declare function authenticateMiddleware(anonymous?: boolean): any;
|
|
22
|
+
export declare function authenticateMiddleware(anonymous?: boolean): (req: any, res: any, next: any) => any;
|
|
23
23
|
export declare function signupUser(userModel: UserModel, email: string, password: string, body?: any): Promise<any>;
|
|
24
24
|
/**
|
|
25
25
|
* Generates both an access token (JWT) and a refresh token for a given user.
|
package/dist/auth.js
CHANGED
|
@@ -82,11 +82,17 @@ function authenticateMiddleware(anonymous) {
|
|
|
82
82
|
if (anonymous) {
|
|
83
83
|
strategies.push("anonymous");
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
var passportAuth = passport_1.default.authenticate(strategies, {
|
|
86
86
|
failureMessage: false, // this is just avoiding storing the message in the session
|
|
87
87
|
failWithError: true,
|
|
88
88
|
session: false,
|
|
89
89
|
});
|
|
90
|
+
return function (req, res, next) {
|
|
91
|
+
if (req.user) {
|
|
92
|
+
return next();
|
|
93
|
+
}
|
|
94
|
+
return passportAuth(req, res, next);
|
|
95
|
+
};
|
|
90
96
|
}
|
|
91
97
|
function signupUser(userModel, email, password, body) {
|
|
92
98
|
return __awaiter(this, void 0, void 0, function () {
|
package/dist/betterAuthSetup.js
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* This module provides functions to initialize Better Auth with MongoDB,
|
|
6
6
|
* create session middleware, and sync users with the application User model.
|
|
7
7
|
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
8
19
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
20
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
21
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -169,7 +180,7 @@ exports.createBetterAuthSessionMiddleware = createBetterAuthSessionMiddleware;
|
|
|
169
180
|
* Creates or updates the user as needed.
|
|
170
181
|
*/
|
|
171
182
|
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
-
var existingUser, userByEmail, newUser, error_2;
|
|
183
|
+
var existingUser, userByEmail, useAsId, newUser, error_2;
|
|
173
184
|
return __generator(this, function (_a) {
|
|
174
185
|
switch (_a.label) {
|
|
175
186
|
case 0:
|
|
@@ -201,13 +212,8 @@ var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { r
|
|
|
201
212
|
_a.sent();
|
|
202
213
|
return [2 /*return*/, userByEmail];
|
|
203
214
|
case 6:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
betterAuthId: betterAuthUser.id,
|
|
207
|
-
email: betterAuthUser.email,
|
|
208
|
-
name: betterAuthUser.name || betterAuthUser.email.split("@")[0],
|
|
209
|
-
oauthProvider: oauthProvider || null,
|
|
210
|
-
});
|
|
215
|
+
useAsId = mongoose_1.default.isValidObjectId(betterAuthUser.id) ? { _id: betterAuthUser.id } : {};
|
|
216
|
+
newUser = new userModel(__assign(__assign({}, useAsId), { admin: false, betterAuthId: betterAuthUser.id, email: betterAuthUser.email, name: betterAuthUser.name || betterAuthUser.email.split("@")[0], oauthProvider: oauthProvider || null }));
|
|
211
217
|
return [4 /*yield*/, newUser.save()];
|
|
212
218
|
case 7:
|
|
213
219
|
_a.sent();
|
|
@@ -229,7 +235,7 @@ var mountBetterAuthRoutes = function (app, auth, basePath) {
|
|
|
229
235
|
if (basePath === void 0) { basePath = "/api/auth"; }
|
|
230
236
|
var handler = (0, node_1.toNodeHandler)(auth);
|
|
231
237
|
// Mount at the base path with wildcard
|
|
232
|
-
app.all("".concat(basePath, "/*"), function (req, res) {
|
|
238
|
+
app.all("".concat(basePath, "/*path"), function (req, res) {
|
|
233
239
|
return handler(req, res);
|
|
234
240
|
});
|
|
235
241
|
logger_1.logger.info("Better Auth routes mounted at ".concat(basePath, "/*"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|