@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.
package/dist/config.js ADDED
@@ -0,0 +1,168 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ 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);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.configureVortex = configureVortex;
51
+ exports.configureVortexAsync = configureVortexAsync;
52
+ exports.configureVortexLazy = configureVortexLazy;
53
+ exports.getVortexConfig = getVortexConfig;
54
+ exports.authenticateRequest = authenticateRequest;
55
+ exports.createAllowAllAccessControl = createAllowAllAccessControl;
56
+ // Store configuration template (immutable after first set)
57
+ var configTemplate = null;
58
+ var isConfigLocked = false;
59
+ var configPromise = null;
60
+ var lazyConfigFactory = null;
61
+ function configureVortex(config) {
62
+ if (isConfigLocked && configTemplate) {
63
+ throw new Error('Vortex configuration is already locked. Configuration can only be set once for security reasons.');
64
+ }
65
+ // Validate required config
66
+ if (!config.apiKey && !process.env.VORTEX_API_KEY) {
67
+ throw new Error('API key is required in config or VORTEX_API_KEY environment variable');
68
+ }
69
+ configTemplate = __assign({}, config);
70
+ isConfigLocked = true;
71
+ }
72
+ function configureVortexAsync(configPromiseOrConfig) {
73
+ if (configPromiseOrConfig instanceof Promise) {
74
+ configPromise = configPromiseOrConfig.then(function (config) {
75
+ configureVortex(config);
76
+ });
77
+ }
78
+ else {
79
+ configureVortex(configPromiseOrConfig);
80
+ }
81
+ }
82
+ function configureVortexLazy(configFactory) {
83
+ if (isConfigLocked && configTemplate) {
84
+ throw new Error('Vortex configuration is already locked. Configuration can only be set once for security reasons.');
85
+ }
86
+ lazyConfigFactory = configFactory;
87
+ }
88
+ function getVortexConfig() {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var baseConfig;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ // Initialize lazily if lazy factory is set and config hasn't been initialized
95
+ if (lazyConfigFactory && !configTemplate && !configPromise) {
96
+ // Lazy initializing Vortex configuration
97
+ configPromise = lazyConfigFactory().then(function (config) {
98
+ configureVortex(config);
99
+ });
100
+ }
101
+ if (!(configPromise && !configTemplate)) return [3 /*break*/, 2];
102
+ return [4 /*yield*/, configPromise];
103
+ case 1:
104
+ _a.sent();
105
+ _a.label = 2;
106
+ case 2:
107
+ baseConfig = {
108
+ apiKey: (configTemplate === null || configTemplate === void 0 ? void 0 : configTemplate.apiKey) || process.env.VORTEX_API_KEY,
109
+ apiBaseUrl: (configTemplate === null || configTemplate === void 0 ? void 0 : configTemplate.apiBaseUrl) || process.env.VORTEX_API_BASE_URL,
110
+ };
111
+ if (!baseConfig.apiKey) {
112
+ throw new Error('Vortex not configured. Call configureVortex() or set VORTEX_API_KEY environment variable');
113
+ }
114
+ // Copy hooks from template if they exist
115
+ if (configTemplate) {
116
+ return [2 /*return*/, __assign(__assign({}, baseConfig), { authenticateUser: configTemplate.authenticateUser, canAccessInvitationsByTarget: configTemplate.canAccessInvitationsByTarget, canAccessInvitation: configTemplate.canAccessInvitation, canDeleteInvitation: configTemplate.canDeleteInvitation, canAcceptInvitations: configTemplate.canAcceptInvitations, canAccessInvitationsByGroup: configTemplate.canAccessInvitationsByGroup, canDeleteInvitationsByGroup: configTemplate.canDeleteInvitationsByGroup, canReinvite: configTemplate.canReinvite })];
117
+ }
118
+ return [2 /*return*/, baseConfig];
119
+ }
120
+ });
121
+ });
122
+ }
123
+ // Helper function to authenticate user for any request
124
+ function authenticateRequest(request, reply) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var config, error_1;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0: return [4 /*yield*/, getVortexConfig()];
130
+ case 1:
131
+ config = _a.sent();
132
+ if (!config.authenticateUser) {
133
+ return [2 /*return*/, null];
134
+ }
135
+ _a.label = 2;
136
+ case 2:
137
+ _a.trys.push([2, 4, , 5]);
138
+ return [4 /*yield*/, config.authenticateUser(request, reply)];
139
+ case 3: return [2 /*return*/, _a.sent()];
140
+ case 4:
141
+ error_1 = _a.sent();
142
+ // Log error but don't expose details
143
+ console.error('Authentication error:', error_1);
144
+ return [2 /*return*/, null];
145
+ case 5: return [2 /*return*/];
146
+ }
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * Creates a set of access control hooks that allow all operations.
152
+ * Useful for demos, development, or when you want to handle authorization elsewhere.
153
+ */
154
+ function createAllowAllAccessControl() {
155
+ var _this = this;
156
+ var allowAll = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
157
+ return [2 /*return*/, true];
158
+ }); }); };
159
+ return {
160
+ canAccessInvitationsByTarget: allowAll,
161
+ canAccessInvitation: allowAll,
162
+ canDeleteInvitation: allowAll,
163
+ canAcceptInvitations: allowAll,
164
+ canAccessInvitationsByGroup: allowAll,
165
+ canDeleteInvitationsByGroup: allowAll,
166
+ canReinvite: allowAll,
167
+ };
168
+ }
@@ -0,0 +1,9 @@
1
+ import { FastifyRequest, FastifyReply } from 'fastify';
2
+ export declare function handleGetInvitationsByTarget(request: FastifyRequest, reply: FastifyReply): Promise<never>;
3
+ export declare function handleGetInvitation(request: FastifyRequest, reply: FastifyReply): Promise<never>;
4
+ export declare function handleRevokeInvitation(request: FastifyRequest, reply: FastifyReply): Promise<never>;
5
+ export declare function handleAcceptInvitations(request: FastifyRequest, reply: FastifyReply): Promise<never>;
6
+ export declare function handleGetInvitationsByGroup(request: FastifyRequest, reply: FastifyReply): Promise<never>;
7
+ export declare function handleDeleteInvitationsByGroup(request: FastifyRequest, reply: FastifyReply): Promise<never>;
8
+ export declare function handleReinvite(request: FastifyRequest, reply: FastifyReply): Promise<never>;
9
+ //# sourceMappingURL=invitations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitations.d.ts","sourceRoot":"","sources":["../../src/handlers/invitations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvD,wBAAsB,4BAA4B,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAuC9F;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAiCrF;AAED,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBA+BxF;AAED,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAyDzF;AAED,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAqC7F;AAED,wBAAsB,8BAA8B,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAqChG;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBA+BhF"}
@@ -0,0 +1,423 @@
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.handleGetInvitationsByTarget = handleGetInvitationsByTarget;
40
+ exports.handleGetInvitation = handleGetInvitation;
41
+ exports.handleRevokeInvitation = handleRevokeInvitation;
42
+ exports.handleAcceptInvitations = handleAcceptInvitations;
43
+ exports.handleGetInvitationsByGroup = handleGetInvitationsByGroup;
44
+ exports.handleDeleteInvitationsByGroup = handleDeleteInvitationsByGroup;
45
+ exports.handleReinvite = handleReinvite;
46
+ var vortex_node_22_sdk_1 = require("@teamvortexsoftware/vortex-node-22-sdk");
47
+ var config_1 = require("../config");
48
+ var utils_1 = require("../utils");
49
+ function handleGetInvitationsByTarget(request, reply) {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var config, user, hasAccess, targetType, targetValue, vortex, invitations, error_1;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ _a.trys.push([0, 7, , 8]);
56
+ if (request.method !== 'GET') {
57
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
58
+ }
59
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
60
+ case 1:
61
+ config = _a.sent();
62
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
63
+ case 2:
64
+ user = _a.sent();
65
+ if (!config.canAccessInvitationsByTarget) return [3 /*break*/, 4];
66
+ return [4 /*yield*/, config.canAccessInvitationsByTarget(request, reply, user)];
67
+ case 3:
68
+ hasAccess = _a.sent();
69
+ if (!hasAccess) {
70
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
71
+ }
72
+ return [3 /*break*/, 5];
73
+ case 4:
74
+ if (!user) {
75
+ // If no access control hook is configured, require authentication
76
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
77
+ }
78
+ _a.label = 5;
79
+ case 5:
80
+ targetType = (0, utils_1.sanitizeInput)((0, utils_1.getQueryParam)(request, 'targetType'));
81
+ targetValue = (0, utils_1.sanitizeInput)((0, utils_1.getQueryParam)(request, 'targetValue'));
82
+ if (!targetType || !targetValue) {
83
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'targetType and targetValue query parameters are required', 400)];
84
+ }
85
+ if (!['email', 'username', 'phoneNumber'].includes(targetType)) {
86
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'targetType must be email, username, or phoneNumber', 400)];
87
+ }
88
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
89
+ return [4 /*yield*/, vortex.getInvitationsByTarget(targetType, targetValue)];
90
+ case 6:
91
+ invitations = _a.sent();
92
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, { invitations: invitations })];
93
+ case 7:
94
+ error_1 = _a.sent();
95
+ console.error('Error in handleGetInvitationsByTarget:', error_1);
96
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
97
+ case 8: return [2 /*return*/];
98
+ }
99
+ });
100
+ });
101
+ }
102
+ function handleGetInvitation(request, reply) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var invitationId, sanitizedId, config, user, hasAccess, vortex, invitation, error_2;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0:
108
+ _a.trys.push([0, 7, , 8]);
109
+ if (request.method !== 'GET') {
110
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
111
+ }
112
+ invitationId = (0, utils_1.getRouteParam)(request, 'invitationId');
113
+ sanitizedId = (0, utils_1.sanitizeInput)(invitationId);
114
+ if (!sanitizedId) {
115
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid invitation ID', 400)];
116
+ }
117
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
118
+ case 1:
119
+ config = _a.sent();
120
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
121
+ case 2:
122
+ user = _a.sent();
123
+ if (!config.canAccessInvitation) return [3 /*break*/, 4];
124
+ return [4 /*yield*/, config.canAccessInvitation(request, reply, user, { invitationId: sanitizedId })];
125
+ case 3:
126
+ hasAccess = _a.sent();
127
+ if (!hasAccess) {
128
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
129
+ }
130
+ return [3 /*break*/, 5];
131
+ case 4:
132
+ if (!user) {
133
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
134
+ }
135
+ _a.label = 5;
136
+ case 5:
137
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
138
+ return [4 /*yield*/, vortex.getInvitation(sanitizedId)];
139
+ case 6:
140
+ invitation = _a.sent();
141
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, invitation)];
142
+ case 7:
143
+ error_2 = _a.sent();
144
+ console.error('Error in handleGetInvitation:', error_2);
145
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
146
+ case 8: return [2 /*return*/];
147
+ }
148
+ });
149
+ });
150
+ }
151
+ function handleRevokeInvitation(request, reply) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ var invitationId, sanitizedId, config, user, hasAccess, vortex, error_3;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ _a.trys.push([0, 7, , 8]);
158
+ if (request.method !== 'DELETE') {
159
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
160
+ }
161
+ invitationId = (0, utils_1.getRouteParam)(request, 'invitationId');
162
+ sanitizedId = (0, utils_1.sanitizeInput)(invitationId);
163
+ if (!sanitizedId) {
164
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid invitation ID', 400)];
165
+ }
166
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
167
+ case 1:
168
+ config = _a.sent();
169
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
170
+ case 2:
171
+ user = _a.sent();
172
+ if (!config.canDeleteInvitation) return [3 /*break*/, 4];
173
+ return [4 /*yield*/, config.canDeleteInvitation(request, reply, user, { invitationId: sanitizedId })];
174
+ case 3:
175
+ hasAccess = _a.sent();
176
+ if (!hasAccess) {
177
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
178
+ }
179
+ return [3 /*break*/, 5];
180
+ case 4:
181
+ if (!user) {
182
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
183
+ }
184
+ _a.label = 5;
185
+ case 5:
186
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
187
+ return [4 /*yield*/, vortex.revokeInvitation(sanitizedId)];
188
+ case 6:
189
+ _a.sent();
190
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, { success: true })];
191
+ case 7:
192
+ error_3 = _a.sent();
193
+ console.error('Error in handleRevokeInvitation:', error_3);
194
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
195
+ case 8: return [2 /*return*/];
196
+ }
197
+ });
198
+ });
199
+ }
200
+ function handleAcceptInvitations(request, reply) {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ var body, invitationIds, target, sanitizedIds, targetObj, validatedTarget, config, user, hasAccess, vortex, result, error_4;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0:
206
+ _a.trys.push([0, 8, , 9]);
207
+ if (request.method !== 'POST') {
208
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
209
+ }
210
+ return [4 /*yield*/, (0, utils_1.parseRequestBody)(request)];
211
+ case 1:
212
+ body = _a.sent();
213
+ (0, utils_1.validateRequiredFields)(body, ['invitationIds', 'target']);
214
+ invitationIds = body.invitationIds, target = body.target;
215
+ if (!Array.isArray(invitationIds) || invitationIds.length === 0) {
216
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'invitationIds must be a non-empty array', 400)];
217
+ }
218
+ sanitizedIds = invitationIds.map(function (id) { return (0, utils_1.sanitizeInput)(id); }).filter(function (id) { return Boolean(id); });
219
+ if (sanitizedIds.length !== invitationIds.length) {
220
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid invitation IDs provided', 400)];
221
+ }
222
+ targetObj = target;
223
+ if (!targetObj.type || !targetObj.value) {
224
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'target must have type and value properties', 400)];
225
+ }
226
+ if (!['email', 'username', 'phoneNumber'].includes(targetObj.type)) {
227
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'target.type must be email, username, or phoneNumber', 400)];
228
+ }
229
+ validatedTarget = { type: targetObj.type, value: targetObj.value };
230
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
231
+ case 2:
232
+ config = _a.sent();
233
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
234
+ case 3:
235
+ user = _a.sent();
236
+ if (!config.canAcceptInvitations) return [3 /*break*/, 5];
237
+ return [4 /*yield*/, config.canAcceptInvitations(request, reply, user, { invitationIds: sanitizedIds, target: validatedTarget })];
238
+ case 4:
239
+ hasAccess = _a.sent();
240
+ if (!hasAccess) {
241
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
242
+ }
243
+ return [3 /*break*/, 6];
244
+ case 5:
245
+ if (!user) {
246
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
247
+ }
248
+ _a.label = 6;
249
+ case 6:
250
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
251
+ return [4 /*yield*/, vortex.acceptInvitations(sanitizedIds, {
252
+ type: validatedTarget.type,
253
+ value: (0, utils_1.sanitizeInput)(validatedTarget.value) || validatedTarget.value
254
+ })];
255
+ case 7:
256
+ result = _a.sent();
257
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, result)];
258
+ case 8:
259
+ error_4 = _a.sent();
260
+ console.error('Error in handleAcceptInvitations:', error_4);
261
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
262
+ case 9: return [2 /*return*/];
263
+ }
264
+ });
265
+ });
266
+ }
267
+ function handleGetInvitationsByGroup(request, reply) {
268
+ return __awaiter(this, void 0, void 0, function () {
269
+ var groupType, groupId, sanitizedGroupType, sanitizedGroupId, config, user, hasAccess, vortex, invitations, error_5;
270
+ return __generator(this, function (_a) {
271
+ switch (_a.label) {
272
+ case 0:
273
+ _a.trys.push([0, 7, , 8]);
274
+ if (request.method !== 'GET') {
275
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
276
+ }
277
+ groupType = (0, utils_1.getRouteParam)(request, 'groupType');
278
+ groupId = (0, utils_1.getRouteParam)(request, 'groupId');
279
+ sanitizedGroupType = (0, utils_1.sanitizeInput)(groupType);
280
+ sanitizedGroupId = (0, utils_1.sanitizeInput)(groupId);
281
+ if (!sanitizedGroupType || !sanitizedGroupId) {
282
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid group parameters', 400)];
283
+ }
284
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
285
+ case 1:
286
+ config = _a.sent();
287
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
288
+ case 2:
289
+ user = _a.sent();
290
+ if (!config.canAccessInvitationsByGroup) return [3 /*break*/, 4];
291
+ return [4 /*yield*/, config.canAccessInvitationsByGroup(request, reply, user, {
292
+ groupType: sanitizedGroupType,
293
+ groupId: sanitizedGroupId
294
+ })];
295
+ case 3:
296
+ hasAccess = _a.sent();
297
+ if (!hasAccess) {
298
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
299
+ }
300
+ return [3 /*break*/, 5];
301
+ case 4:
302
+ if (!user) {
303
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
304
+ }
305
+ _a.label = 5;
306
+ case 5:
307
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
308
+ return [4 /*yield*/, vortex.getInvitationsByGroup(sanitizedGroupType, sanitizedGroupId)];
309
+ case 6:
310
+ invitations = _a.sent();
311
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, { invitations: invitations })];
312
+ case 7:
313
+ error_5 = _a.sent();
314
+ console.error('Error in handleGetInvitationsByGroup:', error_5);
315
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
316
+ case 8: return [2 /*return*/];
317
+ }
318
+ });
319
+ });
320
+ }
321
+ function handleDeleteInvitationsByGroup(request, reply) {
322
+ return __awaiter(this, void 0, void 0, function () {
323
+ var groupType, groupId, sanitizedGroupType, sanitizedGroupId, config, user, hasAccess, vortex, error_6;
324
+ return __generator(this, function (_a) {
325
+ switch (_a.label) {
326
+ case 0:
327
+ _a.trys.push([0, 7, , 8]);
328
+ if (request.method !== 'DELETE') {
329
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
330
+ }
331
+ groupType = (0, utils_1.getRouteParam)(request, 'groupType');
332
+ groupId = (0, utils_1.getRouteParam)(request, 'groupId');
333
+ sanitizedGroupType = (0, utils_1.sanitizeInput)(groupType);
334
+ sanitizedGroupId = (0, utils_1.sanitizeInput)(groupId);
335
+ if (!sanitizedGroupType || !sanitizedGroupId) {
336
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid group parameters', 400)];
337
+ }
338
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
339
+ case 1:
340
+ config = _a.sent();
341
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
342
+ case 2:
343
+ user = _a.sent();
344
+ if (!config.canDeleteInvitationsByGroup) return [3 /*break*/, 4];
345
+ return [4 /*yield*/, config.canDeleteInvitationsByGroup(request, reply, user, {
346
+ groupType: sanitizedGroupType,
347
+ groupId: sanitizedGroupId
348
+ })];
349
+ case 3:
350
+ hasAccess = _a.sent();
351
+ if (!hasAccess) {
352
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
353
+ }
354
+ return [3 /*break*/, 5];
355
+ case 4:
356
+ if (!user) {
357
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
358
+ }
359
+ _a.label = 5;
360
+ case 5:
361
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
362
+ return [4 /*yield*/, vortex.deleteInvitationsByGroup(sanitizedGroupType, sanitizedGroupId)];
363
+ case 6:
364
+ _a.sent();
365
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, { success: true })];
366
+ case 7:
367
+ error_6 = _a.sent();
368
+ console.error('Error in handleDeleteInvitationsByGroup:', error_6);
369
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
370
+ case 8: return [2 /*return*/];
371
+ }
372
+ });
373
+ });
374
+ }
375
+ function handleReinvite(request, reply) {
376
+ return __awaiter(this, void 0, void 0, function () {
377
+ var invitationId, sanitizedId, config, user, hasAccess, vortex, invitation, error_7;
378
+ return __generator(this, function (_a) {
379
+ switch (_a.label) {
380
+ case 0:
381
+ _a.trys.push([0, 7, , 8]);
382
+ if (request.method !== 'POST') {
383
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Method not allowed', 405)];
384
+ }
385
+ invitationId = (0, utils_1.getRouteParam)(request, 'invitationId');
386
+ sanitizedId = (0, utils_1.sanitizeInput)(invitationId);
387
+ if (!sanitizedId) {
388
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Invalid invitation ID', 400)];
389
+ }
390
+ return [4 /*yield*/, (0, config_1.getVortexConfig)()];
391
+ case 1:
392
+ config = _a.sent();
393
+ return [4 /*yield*/, (0, config_1.authenticateRequest)(request, reply)];
394
+ case 2:
395
+ user = _a.sent();
396
+ if (!config.canReinvite) return [3 /*break*/, 4];
397
+ return [4 /*yield*/, config.canReinvite(request, reply, user, { invitationId: sanitizedId })];
398
+ case 3:
399
+ hasAccess = _a.sent();
400
+ if (!hasAccess) {
401
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied', 403)];
402
+ }
403
+ return [3 /*break*/, 5];
404
+ case 4:
405
+ if (!user) {
406
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'Access denied. Configure access control hooks for invitation endpoints.', 403)];
407
+ }
408
+ _a.label = 5;
409
+ case 5:
410
+ vortex = new vortex_node_22_sdk_1.Vortex(config.apiKey);
411
+ return [4 /*yield*/, vortex.reinvite(sanitizedId)];
412
+ case 6:
413
+ invitation = _a.sent();
414
+ return [2 /*return*/, (0, utils_1.createApiResponse)(reply, invitation)];
415
+ case 7:
416
+ error_7 = _a.sent();
417
+ console.error('Error in handleReinvite:', error_7);
418
+ return [2 /*return*/, (0, utils_1.createErrorResponse)(reply, 'An error occurred while processing your request', 500)];
419
+ case 8: return [2 /*return*/];
420
+ }
421
+ });
422
+ });
423
+ }
@@ -0,0 +1,3 @@
1
+ import { FastifyRequest, FastifyReply } from 'fastify';
2
+ export declare function handleJwtGeneration(request: FastifyRequest, reply: FastifyReply): Promise<never>;
3
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/handlers/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAgCrF"}