@teamvortexsoftware/vortex-fastify-5-sdk 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.
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.handleJwtGeneration = handleJwtGeneration;
40
+ var vortex_node_22_sdk_1 = require("@teamvortexsoftware/vortex-node-22-sdk");
41
+ var config_1 = require("../config");
42
+ var utils_1 = require("../utils");
43
+ function handleJwtGeneration(request, reply) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var config, authenticatedUser, vortex, jwt, error_1, message;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ _a.trys.push([0, 3, , 4]);
50
+ if (request.method !== 'POST') {
51
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
52
+ }
53
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
54
+ case 1:
55
+ config = _a.sent();
56
+ if (!config.authenticateUser) {
57
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'JWT generation requires authentication configuration. Please configure authenticateUser hook.', 500)];
58
+ }
59
+ return [4 /*yield*/, config.authenticateUser(request, reply)];
60
+ case 2:
61
+ authenticatedUser = _a.sent();
62
+ if (!authenticatedUser) {
63
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Unauthorized', 401)];
64
+ }
65
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
66
+ jwt = vortex.generateJwt({
67
+ userId: authenticatedUser.userId,
68
+ identifiers: authenticatedUser.identifiers,
69
+ groups: authenticatedUser.groups,
70
+ role: authenticatedUser.role,
71
+ });
72
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, { jwt: jwt })];
73
+ case 3:
74
+ error_1 = _a.sent();
75
+ message = error_1 instanceof Error ? error_1.message : 'An error occurred';
76
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, message, 500)];
77
+ case 4: return [2 /*return*/];
78
+ }
79
+ });
80
+ });
81
+ }
@@ -0,0 +1,9 @@
1
+ export { configureVortex, configureVortexAsync, configureVortexLazy, getVortexConfig, authenticateRequest, createAllowAllAccessControl } from './config';
2
+ export type { VortexConfig, AuthenticatedUser, AccessControlHook, InvitationResource, InvitationTargetResource, GroupResource, InvitationAccessHook, InvitationTargetAccessHook, GroupAccessHook, BasicAccessHook } from './config';
3
+ export { createVortexJwtRoute, createVortexInvitationsRoute, createVortexInvitationRoute, createVortexInvitationsAcceptRoute, createVortexInvitationsByGroupRoute, createVortexReinviteRoute, createVortexRoutes, vortexPlugin, registerVortexRoutes, VORTEX_ROUTES, createVortexApiPath, } from './routes';
4
+ export type { VortexPluginOptions } from './routes';
5
+ export { handleJwtGeneration, } from './handlers/jwt';
6
+ export { handleGetInvitationsByTarget, handleGetInvitation, handleRevokeInvitation, handleAcceptInvitations, handleGetInvitationsByGroup, handleDeleteInvitationsByGroup, handleReinvite, } from './handlers/invitations';
7
+ export { createApiResponse, createErrorResponse, parseRequestBody, getQueryParam, getRouteParam, validateRequiredFields, sanitizeInput, } from './utils';
8
+ export * from '@teamvortexsoftware/vortex-node-22-sdk';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACzJ,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,2BAA2B,EAC3B,kCAAkC,EAClC,mCAAmC,EACnC,yBAAyB,EACzB,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EACL,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,8BAA8B,EAC9B,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,aAAa,GACd,MAAM,SAAS,CAAC;AAEjB,cAAc,wCAAwC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.sanitizeInput = exports.validateRequiredFields = exports.getRouteParam = exports.getQueryParam = exports.parseRequestBody = exports.createErrorResponse = exports.createApiResponse = exports.handleReinvite = exports.handleDeleteInvitationsByGroup = exports.handleGetInvitationsByGroup = exports.handleAcceptInvitations = exports.handleRevokeInvitation = exports.handleGetInvitation = exports.handleGetInvitationsByTarget = exports.handleJwtGeneration = exports.createVortexApiPath = exports.VORTEX_ROUTES = exports.registerVortexRoutes = exports.vortexPlugin = exports.createVortexRoutes = exports.createVortexReinviteRoute = exports.createVortexInvitationsByGroupRoute = exports.createVortexInvitationsAcceptRoute = exports.createVortexInvitationRoute = exports.createVortexInvitationsRoute = exports.createVortexJwtRoute = exports.createAllowAllAccessControl = exports.authenticateRequest = exports.getVortexConfig = exports.configureVortexLazy = exports.configureVortexAsync = exports.configureVortex = void 0;
18
+ var config_1 = require("./config");
19
+ Object.defineProperty(exports, "configureVortex", { enumerable: true, get: function () { return config_1.configureVortex; } });
20
+ Object.defineProperty(exports, "configureVortexAsync", { enumerable: true, get: function () { return config_1.configureVortexAsync; } });
21
+ Object.defineProperty(exports, "configureVortexLazy", { enumerable: true, get: function () { return config_1.configureVortexLazy; } });
22
+ Object.defineProperty(exports, "getVortexConfig", { enumerable: true, get: function () { return config_1.getVortexConfig; } });
23
+ Object.defineProperty(exports, "authenticateRequest", { enumerable: true, get: function () { return config_1.authenticateRequest; } });
24
+ Object.defineProperty(exports, "createAllowAllAccessControl", { enumerable: true, get: function () { return config_1.createAllowAllAccessControl; } });
25
+ var routes_1 = require("./routes");
26
+ Object.defineProperty(exports, "createVortexJwtRoute", { enumerable: true, get: function () { return routes_1.createVortexJwtRoute; } });
27
+ Object.defineProperty(exports, "createVortexInvitationsRoute", { enumerable: true, get: function () { return routes_1.createVortexInvitationsRoute; } });
28
+ Object.defineProperty(exports, "createVortexInvitationRoute", { enumerable: true, get: function () { return routes_1.createVortexInvitationRoute; } });
29
+ Object.defineProperty(exports, "createVortexInvitationsAcceptRoute", { enumerable: true, get: function () { return routes_1.createVortexInvitationsAcceptRoute; } });
30
+ Object.defineProperty(exports, "createVortexInvitationsByGroupRoute", { enumerable: true, get: function () { return routes_1.createVortexInvitationsByGroupRoute; } });
31
+ Object.defineProperty(exports, "createVortexReinviteRoute", { enumerable: true, get: function () { return routes_1.createVortexReinviteRoute; } });
32
+ Object.defineProperty(exports, "createVortexRoutes", { enumerable: true, get: function () { return routes_1.createVortexRoutes; } });
33
+ Object.defineProperty(exports, "vortexPlugin", { enumerable: true, get: function () { return routes_1.vortexPlugin; } });
34
+ Object.defineProperty(exports, "registerVortexRoutes", { enumerable: true, get: function () { return routes_1.registerVortexRoutes; } });
35
+ Object.defineProperty(exports, "VORTEX_ROUTES", { enumerable: true, get: function () { return routes_1.VORTEX_ROUTES; } });
36
+ Object.defineProperty(exports, "createVortexApiPath", { enumerable: true, get: function () { return routes_1.createVortexApiPath; } });
37
+ var jwt_1 = require("./handlers/jwt");
38
+ Object.defineProperty(exports, "handleJwtGeneration", { enumerable: true, get: function () { return jwt_1.handleJwtGeneration; } });
39
+ var invitations_1 = require("./handlers/invitations");
40
+ Object.defineProperty(exports, "handleGetInvitationsByTarget", { enumerable: true, get: function () { return invitations_1.handleGetInvitationsByTarget; } });
41
+ Object.defineProperty(exports, "handleGetInvitation", { enumerable: true, get: function () { return invitations_1.handleGetInvitation; } });
42
+ Object.defineProperty(exports, "handleRevokeInvitation", { enumerable: true, get: function () { return invitations_1.handleRevokeInvitation; } });
43
+ Object.defineProperty(exports, "handleAcceptInvitations", { enumerable: true, get: function () { return invitations_1.handleAcceptInvitations; } });
44
+ Object.defineProperty(exports, "handleGetInvitationsByGroup", { enumerable: true, get: function () { return invitations_1.handleGetInvitationsByGroup; } });
45
+ Object.defineProperty(exports, "handleDeleteInvitationsByGroup", { enumerable: true, get: function () { return invitations_1.handleDeleteInvitationsByGroup; } });
46
+ Object.defineProperty(exports, "handleReinvite", { enumerable: true, get: function () { return invitations_1.handleReinvite; } });
47
+ var utils_1 = require("./utils");
48
+ Object.defineProperty(exports, "createApiResponse", { enumerable: true, get: function () { return utils_1.createApiResponse; } });
49
+ Object.defineProperty(exports, "createErrorResponse", { enumerable: true, get: function () { return utils_1.createErrorResponse; } });
50
+ Object.defineProperty(exports, "parseRequestBody", { enumerable: true, get: function () { return utils_1.parseRequestBody; } });
51
+ Object.defineProperty(exports, "getQueryParam", { enumerable: true, get: function () { return utils_1.getQueryParam; } });
52
+ Object.defineProperty(exports, "getRouteParam", { enumerable: true, get: function () { return utils_1.getRouteParam; } });
53
+ Object.defineProperty(exports, "validateRequiredFields", { enumerable: true, get: function () { return utils_1.validateRequiredFields; } });
54
+ Object.defineProperty(exports, "sanitizeInput", { enumerable: true, get: function () { return utils_1.sanitizeInput; } });
55
+ __exportStar(require("@teamvortexsoftware/vortex-node-22-sdk"), exports);
@@ -0,0 +1,102 @@
1
+ import { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginAsync } from 'fastify';
2
+ /**
3
+ * Expected route paths that match the React provider's API calls
4
+ * This ensures the Fastify routes and React provider stay in sync
5
+ */
6
+ export declare const VORTEX_ROUTES: {
7
+ readonly JWT: "/jwt";
8
+ readonly INVITATIONS: "/invitations";
9
+ readonly INVITATION: "/invitations/:invitationId";
10
+ readonly INVITATIONS_ACCEPT: "/invitations/accept";
11
+ readonly INVITATIONS_BY_GROUP: "/invitations/by-group/:groupType/:groupId";
12
+ readonly INVITATION_REINVITE: "/invitations/:invitationId/reinvite";
13
+ };
14
+ /**
15
+ * Utility to create the full API path based on base URL
16
+ */
17
+ export declare function createVortexApiPath(baseUrl: string, route: keyof typeof VORTEX_ROUTES): string;
18
+ /**
19
+ * Creates individual route handlers for JWT endpoint
20
+ */
21
+ export declare function createVortexJwtRoute(): (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
22
+ /**
23
+ * Creates individual route handlers for invitations endpoint
24
+ */
25
+ export declare function createVortexInvitationsRoute(): (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
26
+ /**
27
+ * Creates individual route handlers for single invitation endpoint
28
+ */
29
+ export declare function createVortexInvitationRoute(): {
30
+ get: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
31
+ delete: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
32
+ };
33
+ /**
34
+ * Creates individual route handlers for invitations accept endpoint
35
+ */
36
+ export declare function createVortexInvitationsAcceptRoute(): (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
37
+ /**
38
+ * Creates individual route handlers for invitations by group endpoint
39
+ */
40
+ export declare function createVortexInvitationsByGroupRoute(): {
41
+ get: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
42
+ delete: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
43
+ };
44
+ /**
45
+ * Creates individual route handlers for reinvite endpoint
46
+ */
47
+ export declare function createVortexReinviteRoute(): (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
48
+ /**
49
+ * Creates all Vortex routes for manual registration
50
+ * This provides individual handlers that can be attached to specific routes
51
+ */
52
+ export declare function createVortexRoutes(): {
53
+ jwt: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
54
+ invitations: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
55
+ invitation: {
56
+ get: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
57
+ delete: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
58
+ };
59
+ invitationsAccept: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
60
+ invitationsByGroup: {
61
+ get: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
62
+ delete: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
63
+ };
64
+ invitationReinvite: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
65
+ };
66
+ /**
67
+ * Creates a Fastify plugin with all Vortex routes configured
68
+ * This is the easiest way to integrate Vortex into a Fastify app
69
+ *
70
+ * Usage:
71
+ * ```typescript
72
+ * import Fastify from 'fastify';
73
+ * import { vortexPlugin } from '@teamvortexsoftware/vortex-fastify-5-sdk';
74
+ *
75
+ * const fastify = Fastify();
76
+ * await fastify.register(vortexPlugin, { prefix: '/api/vortex' });
77
+ * ```
78
+ */
79
+ export declare const vortexPlugin: FastifyPluginAsync;
80
+ /**
81
+ * Manual route registration helper for more control
82
+ * Use this if you want to register routes individually or with custom logic
83
+ *
84
+ * Usage:
85
+ * ```typescript
86
+ * import Fastify from 'fastify';
87
+ * import { registerVortexRoutes } from '@teamvortexsoftware/vortex-fastify-5-sdk';
88
+ *
89
+ * const fastify = Fastify();
90
+ *
91
+ * // Register with custom prefix
92
+ * await registerVortexRoutes(fastify, '/api/v1/vortex');
93
+ * ```
94
+ */
95
+ export declare function registerVortexRoutes(fastify: FastifyInstance, basePath?: string): Promise<void>;
96
+ /**
97
+ * Type definitions for Fastify plugin options
98
+ */
99
+ export interface VortexPluginOptions {
100
+ prefix?: string;
101
+ }
102
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAY5F;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;CAOhB,CAAC;AAEX;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,aAAa,GAAG,MAAM,CAE9F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,KACZ,SAAS,cAAc,EAAE,OAAO,YAAY,oBAGnE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,KACpB,SAAS,cAAc,EAAE,OAAO,YAAY,oBAGnE;AAED;;GAEG;AACH,wBAAgB,2BAA2B;mBAEV,cAAc,SAAS,YAAY;sBAGhC,cAAc,SAAS,YAAY;EAItE;AAED;;GAEG;AACH,wBAAgB,kCAAkC,KAC1B,SAAS,cAAc,EAAE,OAAO,YAAY,oBAGnE;AAED;;GAEG;AACH,wBAAgB,mCAAmC;mBAElB,cAAc,SAAS,YAAY;sBAGhC,cAAc,SAAS,YAAY;EAItE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,KACjB,SAAS,cAAc,EAAE,OAAO,YAAY,oBAGnE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB;mBAhED,cAAc,SAAS,YAAY;2BASnC,cAAc,SAAS,YAAY;;uBAUnC,cAAc,SAAS,YAAY;0BAGhC,cAAc,SAAS,YAAY;;iCAUtC,cAAc,SAAS,YAAY;;uBAUnC,cAAc,SAAS,YAAY;0BAGhC,cAAc,SAAS,YAAY;;kCAUtC,cAAc,SAAS,YAAY;EAkBnE;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,EAAE,kBAc1B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAapH;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/dist/routes.js ADDED
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.vortexPlugin = exports.VORTEX_ROUTES = void 0;
40
+ exports.createVortexApiPath = createVortexApiPath;
41
+ exports.createVortexJwtRoute = createVortexJwtRoute;
42
+ exports.createVortexInvitationsRoute = createVortexInvitationsRoute;
43
+ exports.createVortexInvitationRoute = createVortexInvitationRoute;
44
+ exports.createVortexInvitationsAcceptRoute = createVortexInvitationsAcceptRoute;
45
+ exports.createVortexInvitationsByGroupRoute = createVortexInvitationsByGroupRoute;
46
+ exports.createVortexReinviteRoute = createVortexReinviteRoute;
47
+ exports.createVortexRoutes = createVortexRoutes;
48
+ exports.registerVortexRoutes = registerVortexRoutes;
49
+ var jwt_1 = require("./handlers/jwt");
50
+ var invitations_1 = require("./handlers/invitations");
51
+ /**
52
+ * Expected route paths that match the React provider's API calls
53
+ * This ensures the Fastify routes and React provider stay in sync
54
+ */
55
+ exports.VORTEX_ROUTES = {
56
+ JWT: '/jwt',
57
+ INVITATIONS: '/invitations',
58
+ INVITATION: '/invitations/:invitationId',
59
+ INVITATIONS_ACCEPT: '/invitations/accept',
60
+ INVITATIONS_BY_GROUP: '/invitations/by-group/:groupType/:groupId',
61
+ INVITATION_REINVITE: '/invitations/:invitationId/reinvite',
62
+ };
63
+ /**
64
+ * Utility to create the full API path based on base URL
65
+ */
66
+ function createVortexApiPath(baseUrl, route) {
67
+ return "".concat(baseUrl.replace(/\/$/, '')).concat(exports.VORTEX_ROUTES[route]);
68
+ }
69
+ /**
70
+ * Creates individual route handlers for JWT endpoint
71
+ */
72
+ function createVortexJwtRoute() {
73
+ return function (request, reply) {
74
+ return __awaiter(this, void 0, void 0, function () {
75
+ return __generator(this, function (_a) {
76
+ return [2 /*return*/, (0, jwt_1.handleJwtGeneration)(request, reply)];
77
+ });
78
+ });
79
+ };
80
+ }
81
+ /**
82
+ * Creates individual route handlers for invitations endpoint
83
+ */
84
+ function createVortexInvitationsRoute() {
85
+ return function (request, reply) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ return [2 /*return*/, (0, invitations_1.handleGetInvitationsByTarget)(request, reply)];
89
+ });
90
+ });
91
+ };
92
+ }
93
+ /**
94
+ * Creates individual route handlers for single invitation endpoint
95
+ */
96
+ function createVortexInvitationRoute() {
97
+ return {
98
+ get: function (request, reply) {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ return [2 /*return*/, (0, invitations_1.handleGetInvitation)(request, reply)];
102
+ });
103
+ });
104
+ },
105
+ delete: function (request, reply) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ return __generator(this, function (_a) {
108
+ return [2 /*return*/, (0, invitations_1.handleRevokeInvitation)(request, reply)];
109
+ });
110
+ });
111
+ },
112
+ };
113
+ }
114
+ /**
115
+ * Creates individual route handlers for invitations accept endpoint
116
+ */
117
+ function createVortexInvitationsAcceptRoute() {
118
+ return function (request, reply) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ return __generator(this, function (_a) {
121
+ return [2 /*return*/, (0, invitations_1.handleAcceptInvitations)(request, reply)];
122
+ });
123
+ });
124
+ };
125
+ }
126
+ /**
127
+ * Creates individual route handlers for invitations by group endpoint
128
+ */
129
+ function createVortexInvitationsByGroupRoute() {
130
+ return {
131
+ get: function (request, reply) {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ return __generator(this, function (_a) {
134
+ return [2 /*return*/, (0, invitations_1.handleGetInvitationsByGroup)(request, reply)];
135
+ });
136
+ });
137
+ },
138
+ delete: function (request, reply) {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ return __generator(this, function (_a) {
141
+ return [2 /*return*/, (0, invitations_1.handleDeleteInvitationsByGroup)(request, reply)];
142
+ });
143
+ });
144
+ },
145
+ };
146
+ }
147
+ /**
148
+ * Creates individual route handlers for reinvite endpoint
149
+ */
150
+ function createVortexReinviteRoute() {
151
+ return function (request, reply) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ return __generator(this, function (_a) {
154
+ return [2 /*return*/, (0, invitations_1.handleReinvite)(request, reply)];
155
+ });
156
+ });
157
+ };
158
+ }
159
+ /**
160
+ * Creates all Vortex routes for manual registration
161
+ * This provides individual handlers that can be attached to specific routes
162
+ */
163
+ function createVortexRoutes() {
164
+ return {
165
+ jwt: createVortexJwtRoute(),
166
+ invitations: createVortexInvitationsRoute(),
167
+ invitation: createVortexInvitationRoute(),
168
+ invitationsAccept: createVortexInvitationsAcceptRoute(),
169
+ invitationsByGroup: createVortexInvitationsByGroupRoute(),
170
+ invitationReinvite: createVortexReinviteRoute(),
171
+ };
172
+ }
173
+ /**
174
+ * Creates a Fastify plugin with all Vortex routes configured
175
+ * This is the easiest way to integrate Vortex into a Fastify app
176
+ *
177
+ * Usage:
178
+ * ```typescript
179
+ * import Fastify from 'fastify';
180
+ * import { vortexPlugin } from '@teamvortexsoftware/vortex-fastify-5-sdk';
181
+ *
182
+ * const fastify = Fastify();
183
+ * await fastify.register(vortexPlugin, { prefix: '/api/vortex' });
184
+ * ```
185
+ */
186
+ var vortexPlugin = function vortexPlugin(fastify) {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var routes;
189
+ return __generator(this, function (_a) {
190
+ routes = createVortexRoutes();
191
+ // Register all routes
192
+ fastify.post(exports.VORTEX_ROUTES.JWT, routes.jwt);
193
+ fastify.get(exports.VORTEX_ROUTES.INVITATIONS, routes.invitations);
194
+ fastify.get(exports.VORTEX_ROUTES.INVITATION, routes.invitation.get);
195
+ fastify.delete(exports.VORTEX_ROUTES.INVITATION, routes.invitation.delete);
196
+ fastify.post(exports.VORTEX_ROUTES.INVITATIONS_ACCEPT, routes.invitationsAccept);
197
+ fastify.get(exports.VORTEX_ROUTES.INVITATIONS_BY_GROUP, routes.invitationsByGroup.get);
198
+ fastify.delete(exports.VORTEX_ROUTES.INVITATIONS_BY_GROUP, routes.invitationsByGroup.delete);
199
+ fastify.post(exports.VORTEX_ROUTES.INVITATION_REINVITE, routes.invitationReinvite);
200
+ return [2 /*return*/];
201
+ });
202
+ });
203
+ };
204
+ exports.vortexPlugin = vortexPlugin;
205
+ /**
206
+ * Manual route registration helper for more control
207
+ * Use this if you want to register routes individually or with custom logic
208
+ *
209
+ * Usage:
210
+ * ```typescript
211
+ * import Fastify from 'fastify';
212
+ * import { registerVortexRoutes } from '@teamvortexsoftware/vortex-fastify-5-sdk';
213
+ *
214
+ * const fastify = Fastify();
215
+ *
216
+ * // Register with custom prefix
217
+ * await registerVortexRoutes(fastify, '/api/v1/vortex');
218
+ * ```
219
+ */
220
+ function registerVortexRoutes(fastify_1) {
221
+ return __awaiter(this, arguments, void 0, function (fastify, basePath) {
222
+ var routes, cleanBasePath;
223
+ if (basePath === void 0) { basePath = '/api/vortex'; }
224
+ return __generator(this, function (_a) {
225
+ routes = createVortexRoutes();
226
+ cleanBasePath = basePath.replace(/\/$/, '');
227
+ // Register all routes with the base path
228
+ fastify.post("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.JWT), routes.jwt);
229
+ fastify.get("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATIONS), routes.invitations);
230
+ fastify.get("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATION), routes.invitation.get);
231
+ fastify.delete("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATION), routes.invitation.delete);
232
+ fastify.post("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATIONS_ACCEPT), routes.invitationsAccept);
233
+ fastify.get("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATIONS_BY_GROUP), routes.invitationsByGroup.get);
234
+ fastify.delete("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATIONS_BY_GROUP), routes.invitationsByGroup.delete);
235
+ fastify.post("".concat(cleanBasePath).concat(exports.VORTEX_ROUTES.INVITATION_REINVITE), routes.invitationReinvite);
236
+ return [2 /*return*/];
237
+ });
238
+ });
239
+ }
@@ -0,0 +1,9 @@
1
+ import { FastifyRequest, FastifyReply } from 'fastify';
2
+ export declare function createApiResponse(reply: FastifyReply, data: unknown, status?: number): FastifyReply;
3
+ export declare function createErrorResponse(reply: FastifyReply, message: string, status?: number): FastifyReply;
4
+ export declare function parseRequestBody(request: FastifyRequest): Promise<unknown>;
5
+ export declare function getQueryParam(request: FastifyRequest, param: string): string | null;
6
+ export declare function getRouteParam(request: FastifyRequest, param: string): string | null;
7
+ export declare function validateRequiredFields(data: Record<string, unknown>, fields: string[]): void;
8
+ export declare function sanitizeInput(input: string | null): string | null;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAE,MAAY,GAAG,YAAY,CAExG;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAY,GAAG,YAAY,CAE5G;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAMhF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUnF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAInF;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAK5F;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAQjE"}
package/dist/utils.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createApiResponse = createApiResponse;
40
+ exports.createErrorResponse = createErrorResponse;
41
+ exports.parseRequestBody = parseRequestBody;
42
+ exports.getQueryParam = getQueryParam;
43
+ exports.getRouteParam = getRouteParam;
44
+ exports.validateRequiredFields = validateRequiredFields;
45
+ exports.sanitizeInput = sanitizeInput;
46
+ function createApiResponse(reply, data, status) {
47
+ if (status === void 0) { status = 200; }
48
+ return reply.status(status).send(data);
49
+ }
50
+ function createErrorResponse(reply, message, status) {
51
+ if (status === void 0) { status = 400; }
52
+ return reply.status(status).send({ error: message });
53
+ }
54
+ function parseRequestBody(request) {
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ return __generator(this, function (_a) {
57
+ // In Fastify, the body is already parsed and available on the request
58
+ if (request.body) {
59
+ return [2 /*return*/, request.body];
60
+ }
61
+ throw new Error('Request body is empty or not parsed');
62
+ });
63
+ });
64
+ }
65
+ function getQueryParam(request, param) {
66
+ var query = request.query;
67
+ var value = query[param];
68
+ if (typeof value === 'string') {
69
+ return value;
70
+ }
71
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'string') {
72
+ return value[0];
73
+ }
74
+ return null;
75
+ }
76
+ function getRouteParam(request, param) {
77
+ var params = request.params;
78
+ var value = params[param];
79
+ return typeof value === 'string' ? value : null;
80
+ }
81
+ function validateRequiredFields(data, fields) {
82
+ var missing = fields.filter(function (field) { return data[field] === undefined || data[field] === null; });
83
+ if (missing.length > 0) {
84
+ throw new Error("Missing required fields: ".concat(missing.join(', ')));
85
+ }
86
+ }
87
+ function sanitizeInput(input) {
88
+ if (!input)
89
+ return null;
90
+ // Basic input sanitization - remove potential XSS/injection characters
91
+ return input
92
+ .trim()
93
+ .replace(/[<>'"]/g, '') // Remove basic XSS characters
94
+ .substring(0, 1000); // Limit length to prevent DoS
95
+ }