@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/LICENSE +201 -0
- package/README.md +351 -0
- package/dist/config.d.ts +66 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +168 -0
- package/dist/handlers/invitations.d.ts +9 -0
- package/dist/handlers/invitations.d.ts.map +1 -0
- package/dist/handlers/invitations.js +423 -0
- package/dist/handlers/jwt.d.ts +3 -0
- package/dist/handlers/jwt.d.ts.map +1 -0
- package/dist/handlers/jwt.js +81 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/routes.d.ts +102 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +239 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +95 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Vortex Software, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Vortex Fastify 5 SDK
|
|
2
|
+
|
|
3
|
+
Drop-in Fastify integration for Vortex invitations and JWT functionality. Get up and running in under 2 minutes!
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @teamvortexsoftware/vortex-fastify-5-sdk @teamvortexsoftware/vortex-react-provider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Easy Integration (Recommended)
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import Fastify from 'fastify';
|
|
15
|
+
import { vortexPlugin, configureVortex, createAllowAllAccessControl } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
16
|
+
|
|
17
|
+
const fastify = Fastify();
|
|
18
|
+
|
|
19
|
+
// Configure Vortex
|
|
20
|
+
configureVortex({
|
|
21
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
22
|
+
|
|
23
|
+
// Required: How to authenticate users
|
|
24
|
+
authenticateUser: async (request, reply) => {
|
|
25
|
+
const user = await getCurrentUser(request); // Your auth logic
|
|
26
|
+
return user ? {
|
|
27
|
+
userId: user.id,
|
|
28
|
+
identifiers: [{ type: 'email', value: user.email }],
|
|
29
|
+
groups: user.groups, // [{ type: 'team', id: '123', name: 'My Team' }]
|
|
30
|
+
} : null;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// Simple: Allow all operations (customize for production)
|
|
34
|
+
...createAllowAllAccessControl(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Add Vortex routes as a plugin
|
|
38
|
+
await fastify.register(vortexPlugin, { prefix: '/api/vortex' });
|
|
39
|
+
|
|
40
|
+
await fastify.listen({ port: 3000 });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That's it! Your Fastify app now has all Vortex API endpoints.
|
|
44
|
+
|
|
45
|
+
## ⚡ What You Get
|
|
46
|
+
|
|
47
|
+
- **JWT Authentication**: Secure user authentication with Vortex
|
|
48
|
+
- **Invitation Management**: Create, accept, and manage invitations
|
|
49
|
+
- **Full Node.js SDK Access**: All `@teamvortexsoftware/vortex-node-22-sdk` functionality
|
|
50
|
+
- **TypeScript Support**: Fully typed with IntelliSense
|
|
51
|
+
- **React Integration**: Works seamlessly with `@teamvortexsoftware/vortex-react-provider`
|
|
52
|
+
- **Fastify Plugin Architecture**: Native Fastify plugin for optimal performance
|
|
53
|
+
|
|
54
|
+
## 📚 API Endpoints
|
|
55
|
+
|
|
56
|
+
Your app automatically gets these API routes:
|
|
57
|
+
|
|
58
|
+
| Endpoint | Method | Description |
|
|
59
|
+
|----------|--------|-------------|
|
|
60
|
+
| `/api/vortex/jwt` | POST | Generate JWT for authenticated user |
|
|
61
|
+
| `/api/vortex/invitations` | GET | Get invitations by target (email/phone) |
|
|
62
|
+
| `/api/vortex/invitations/accept` | POST | Accept multiple invitations |
|
|
63
|
+
| `/api/vortex/invitations/:id` | GET/DELETE | Get or delete specific invitation |
|
|
64
|
+
| `/api/vortex/invitations/:id/reinvite` | POST | Resend invitation |
|
|
65
|
+
| `/api/vortex/invitations/by-group/:type/:id` | GET/DELETE | Group-based operations |
|
|
66
|
+
|
|
67
|
+
## 🛠️ Setup Options
|
|
68
|
+
|
|
69
|
+
### Option 1: Plugin Registration (Easiest)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import Fastify from 'fastify';
|
|
73
|
+
import { vortexPlugin } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
74
|
+
|
|
75
|
+
const fastify = Fastify();
|
|
76
|
+
|
|
77
|
+
// Register as plugin with custom prefix
|
|
78
|
+
await fastify.register(vortexPlugin, { prefix: '/api/vortex' });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Option 2: Manual Route Registration
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import Fastify from 'fastify';
|
|
85
|
+
import { registerVortexRoutes } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
86
|
+
|
|
87
|
+
const fastify = Fastify();
|
|
88
|
+
|
|
89
|
+
// Register with custom base path
|
|
90
|
+
await registerVortexRoutes(fastify, '/api/v1/vortex');
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Option 3: Individual Route Handlers
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import Fastify from 'fastify';
|
|
97
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
98
|
+
|
|
99
|
+
const fastify = Fastify();
|
|
100
|
+
const routes = createVortexRoutes();
|
|
101
|
+
|
|
102
|
+
// Register individual routes with full control
|
|
103
|
+
fastify.post('/api/vortex/jwt', routes.jwt);
|
|
104
|
+
fastify.get('/api/vortex/invitations', routes.invitations);
|
|
105
|
+
fastify.get('/api/vortex/invitations/:invitationId', routes.invitation.get);
|
|
106
|
+
fastify.delete('/api/vortex/invitations/:invitationId', routes.invitation.delete);
|
|
107
|
+
// ... etc
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## ⚙️ Configuration
|
|
111
|
+
|
|
112
|
+
### 1. Environment Variables
|
|
113
|
+
|
|
114
|
+
Add to your `.env`:
|
|
115
|
+
```bash
|
|
116
|
+
VORTEX_API_KEY=your_api_key_here
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 2. Basic Configuration
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { configureVortex, createAllowAllAccessControl } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
123
|
+
|
|
124
|
+
configureVortex({
|
|
125
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
126
|
+
|
|
127
|
+
// Required: How to authenticate users
|
|
128
|
+
authenticateUser: async (request, reply) => {
|
|
129
|
+
const user = await getCurrentUser(request); // Your auth logic
|
|
130
|
+
return user ? {
|
|
131
|
+
userId: user.id,
|
|
132
|
+
identifiers: [{ type: 'email', value: user.email }],
|
|
133
|
+
groups: user.groups, // [{ type: 'team', id: '123', name: 'My Team' }]
|
|
134
|
+
} : null;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// Simple: Allow all operations (customize for production)
|
|
138
|
+
...createAllowAllAccessControl(),
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 3. Lazy Configuration (Advanced)
|
|
143
|
+
|
|
144
|
+
Use this if your configuration depends on database connections or other async setup:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { configureVortexLazy } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
148
|
+
|
|
149
|
+
configureVortexLazy(async () => ({
|
|
150
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
151
|
+
|
|
152
|
+
authenticateUser: async (request, reply) => {
|
|
153
|
+
// This can make database calls, etc.
|
|
154
|
+
const user = await getUserFromDatabase(request);
|
|
155
|
+
return user ? {
|
|
156
|
+
userId: user.id,
|
|
157
|
+
identifiers: [{ type: 'email', value: user.email }],
|
|
158
|
+
groups: await getUserGroups(user.id),
|
|
159
|
+
} : null;
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
...createAllowAllAccessControl(),
|
|
163
|
+
}));
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 🔧 Production Security
|
|
167
|
+
|
|
168
|
+
For production apps, replace `createAllowAllAccessControl()` with proper authorization:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
configureVortex({
|
|
172
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
173
|
+
authenticateUser: async (request, reply) => { /* your auth */ },
|
|
174
|
+
|
|
175
|
+
// Custom access control
|
|
176
|
+
canDeleteInvitation: async (request, reply, user, resource) => {
|
|
177
|
+
return user?.role === 'admin'; // Only admins can delete
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
canAccessInvitationsByGroup: async (request, reply, user, resource) => {
|
|
181
|
+
return user?.groups.some(g =>
|
|
182
|
+
g.type === resource?.groupType && g.id === resource?.groupId
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
// ... other access control hooks
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 🎯 Frontend Integration
|
|
191
|
+
|
|
192
|
+
### React: Get User's JWT
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { useVortexJWT } from '@teamvortexsoftware/vortex-react-provider';
|
|
196
|
+
|
|
197
|
+
function MyComponent() {
|
|
198
|
+
const { jwt, isLoading } = useVortexJWT();
|
|
199
|
+
|
|
200
|
+
if (isLoading) return <div>Loading...</div>;
|
|
201
|
+
if (!jwt) return <div>Not authenticated</div>;
|
|
202
|
+
|
|
203
|
+
return <div>Authenticated! JWT: {jwt.substring(0, 20)}...</div>;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### React: Setup Provider
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
// In your app root
|
|
211
|
+
import { VortexProvider } from '@teamvortexsoftware/vortex-react-provider';
|
|
212
|
+
|
|
213
|
+
function App() {
|
|
214
|
+
return (
|
|
215
|
+
<VortexProvider config={{ apiBaseUrl: '/api/vortex' }}>
|
|
216
|
+
{/* Your app */}
|
|
217
|
+
</VortexProvider>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Manage Invitations
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
// Get invitations
|
|
226
|
+
const response = await fetch('/api/vortex/invitations/by-group/team/my-team-id');
|
|
227
|
+
const { invitations } = await response.json();
|
|
228
|
+
|
|
229
|
+
// Delete invitation
|
|
230
|
+
await fetch(`/api/vortex/invitations/${invitationId}`, { method: 'DELETE' });
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## 🚀 Fastify-Specific Features
|
|
234
|
+
|
|
235
|
+
### Plugin Architecture
|
|
236
|
+
The Fastify SDK leverages Fastify's native plugin system for optimal performance and encapsulation:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Clean plugin registration
|
|
240
|
+
await fastify.register(vortexPlugin, {
|
|
241
|
+
prefix: '/api/vortex'
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Or with encapsulation
|
|
245
|
+
await fastify.register(async function (fastify) {
|
|
246
|
+
await fastify.register(vortexPlugin);
|
|
247
|
+
|
|
248
|
+
// Add custom routes in the same context
|
|
249
|
+
fastify.get('/custom', async () => ({ custom: 'route' }));
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Performance Benefits
|
|
254
|
+
- **Native Fastify Integration**: Uses FastifyRequest and FastifyReply directly
|
|
255
|
+
- **Automatic JSON Parsing**: Body parsing handled by Fastify automatically
|
|
256
|
+
- **Optimized Routing**: Leverages Fastify's high-performance router
|
|
257
|
+
- **Plugin Encapsulation**: Clean separation of concerns
|
|
258
|
+
|
|
259
|
+
## 🔄 Comparison with Other SDKs
|
|
260
|
+
|
|
261
|
+
| Feature | Fastify SDK | Express SDK | Next.js SDK |
|
|
262
|
+
|---------|-------------|-------------|-------------|
|
|
263
|
+
| **Setup** | `fastify.register(vortexPlugin)` | `app.use(createVortexRouter())` | Multiple route files |
|
|
264
|
+
| **Architecture** | Plugin-based | Middleware-based | File-based routing |
|
|
265
|
+
| **Performance** | High (Fastify native) | Good | Good |
|
|
266
|
+
| **Config** | Same API | Same API | Same API |
|
|
267
|
+
| **Access Control** | Same API | Same API | Same API |
|
|
268
|
+
| **Frontend Integration** | Same React Provider | Same React Provider | Same React Provider |
|
|
269
|
+
|
|
270
|
+
## 📦 Direct SDK Usage
|
|
271
|
+
|
|
272
|
+
All Node.js SDK functionality is available:
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import { Vortex } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
276
|
+
|
|
277
|
+
// All Node.js SDK functionality is available
|
|
278
|
+
const vortex = new Vortex(process.env.VORTEX_API_KEY!);
|
|
279
|
+
const invitations = await vortex.getInvitationsByGroup('team', 'team-123');
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 🛠️ Advanced: Custom Handlers
|
|
283
|
+
|
|
284
|
+
Need custom logic? Use individual handlers:
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import Fastify from 'fastify';
|
|
288
|
+
import { handleGetInvitation, createErrorResponse } from '@teamvortexsoftware/vortex-fastify-5-sdk';
|
|
289
|
+
|
|
290
|
+
const fastify = Fastify();
|
|
291
|
+
|
|
292
|
+
fastify.get('/api/custom-invitation/:invitationId', async (request, reply) => {
|
|
293
|
+
// Add custom validation
|
|
294
|
+
const user = await validateUser(request);
|
|
295
|
+
if (!user.isAdmin) {
|
|
296
|
+
return createErrorResponse(reply, 'Admin required', 403);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Use SDK handler
|
|
300
|
+
return handleGetInvitation(request, reply);
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## 📋 Requirements
|
|
305
|
+
|
|
306
|
+
- **Fastify**: 5.0.0 or higher
|
|
307
|
+
- **Node.js**: 18.0.0 or higher
|
|
308
|
+
- **TypeScript**: 5.0.0 or higher (for TypeScript projects)
|
|
309
|
+
|
|
310
|
+
## 🆘 Troubleshooting
|
|
311
|
+
|
|
312
|
+
### Common Issues
|
|
313
|
+
|
|
314
|
+
**Configuration errors**
|
|
315
|
+
- Ensure you're calling `configureVortex()` or `configureVortexLazy()` before registering the plugin
|
|
316
|
+
- Check that your `.env` has `VORTEX_API_KEY`
|
|
317
|
+
|
|
318
|
+
**Plugin registration issues**
|
|
319
|
+
- Make sure you're using `await fastify.register(vortexPlugin)`
|
|
320
|
+
- Verify the prefix doesn't conflict with other routes
|
|
321
|
+
|
|
322
|
+
**Authentication Issues**
|
|
323
|
+
- Verify your `authenticateUser` function returns the correct format
|
|
324
|
+
- Check that your authentication middleware is working
|
|
325
|
+
- Make sure JWT requests include authentication cookies/headers
|
|
326
|
+
|
|
327
|
+
**TypeScript Errors**
|
|
328
|
+
- All types are exported from the main package
|
|
329
|
+
- Resource parameters are fully typed for access control hooks
|
|
330
|
+
|
|
331
|
+
## 📦 What's Included
|
|
332
|
+
|
|
333
|
+
This SDK re-exports everything from `@teamvortexsoftware/vortex-node-22-sdk`, so you get:
|
|
334
|
+
|
|
335
|
+
- ✅ `Vortex` class for direct API access
|
|
336
|
+
- ✅ All invitation management methods
|
|
337
|
+
- ✅ JWT generation utilities
|
|
338
|
+
- ✅ TypeScript definitions
|
|
339
|
+
- ✅ Fastify optimized route handlers
|
|
340
|
+
- ✅ Native plugin architecture
|
|
341
|
+
|
|
342
|
+
## 🔗 Links
|
|
343
|
+
|
|
344
|
+
- [Node.js SDK Documentation](../vortex-node-22-sdk/README.md)
|
|
345
|
+
- [Express SDK Documentation](../vortex-express-5-sdk/README.md)
|
|
346
|
+
- [Next.js SDK Documentation](../vortex-nextjs-15-sdk/README.md)
|
|
347
|
+
- [React Provider Documentation](../vortex-react-provider/README.md)
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
**Need help?** Open an issue or check the Express/Next.js SDK examples for reference patterns.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
export interface AuthenticatedUser {
|
|
3
|
+
userId: string;
|
|
4
|
+
identifiers: {
|
|
5
|
+
type: 'email' | 'sms';
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
groups: {
|
|
9
|
+
type: string;
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}[];
|
|
13
|
+
role?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface InvitationResource {
|
|
16
|
+
invitationId: string;
|
|
17
|
+
}
|
|
18
|
+
export interface InvitationTargetResource {
|
|
19
|
+
invitationIds: string[];
|
|
20
|
+
target: {
|
|
21
|
+
type: string;
|
|
22
|
+
value: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface GroupResource {
|
|
26
|
+
groupType: string;
|
|
27
|
+
groupId: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AccessControlHook<T = unknown> {
|
|
30
|
+
(request: FastifyRequest, reply: FastifyReply, user: AuthenticatedUser | null, resource?: T): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export type InvitationAccessHook = AccessControlHook<InvitationResource>;
|
|
33
|
+
export type InvitationTargetAccessHook = AccessControlHook<InvitationTargetResource>;
|
|
34
|
+
export type GroupAccessHook = AccessControlHook<GroupResource>;
|
|
35
|
+
export type BasicAccessHook = AccessControlHook<void>;
|
|
36
|
+
export interface VortexConfig {
|
|
37
|
+
apiKey: string;
|
|
38
|
+
apiBaseUrl?: string;
|
|
39
|
+
authenticateUser?: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>;
|
|
40
|
+
canAccessInvitationsByTarget?: BasicAccessHook;
|
|
41
|
+
canAccessInvitation?: InvitationAccessHook;
|
|
42
|
+
canDeleteInvitation?: InvitationAccessHook;
|
|
43
|
+
canAcceptInvitations?: InvitationTargetAccessHook;
|
|
44
|
+
canAccessInvitationsByGroup?: GroupAccessHook;
|
|
45
|
+
canDeleteInvitationsByGroup?: GroupAccessHook;
|
|
46
|
+
canReinvite?: InvitationAccessHook;
|
|
47
|
+
}
|
|
48
|
+
export declare function configureVortex(config: VortexConfig): void;
|
|
49
|
+
export declare function configureVortexAsync(configPromiseOrConfig: Promise<VortexConfig> | VortexConfig): void | Promise<void>;
|
|
50
|
+
export declare function configureVortexLazy(configFactory: () => Promise<VortexConfig>): void;
|
|
51
|
+
export declare function getVortexConfig(): Promise<VortexConfig>;
|
|
52
|
+
export declare function authenticateRequest(request: FastifyRequest, reply: FastifyReply): Promise<AuthenticatedUser | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a set of access control hooks that allow all operations.
|
|
55
|
+
* Useful for demos, development, or when you want to handle authorization elsewhere.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createAllowAllAccessControl(): {
|
|
58
|
+
canAccessInvitationsByTarget: () => Promise<boolean>;
|
|
59
|
+
canAccessInvitation: () => Promise<boolean>;
|
|
60
|
+
canDeleteInvitation: () => Promise<boolean>;
|
|
61
|
+
canAcceptInvitations: () => Promise<boolean>;
|
|
62
|
+
canAccessInvitationsByGroup: () => Promise<boolean>;
|
|
63
|
+
canDeleteInvitationsByGroup: () => Promise<boolean>;
|
|
64
|
+
canReinvite: () => Promise<boolean>;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE;QAAE,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxD,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC5C,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChH;AAGD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AACzE,MAAM,MAAM,0BAA0B,GAAG,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;AACrF,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAC/D,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAEvG,4BAA4B,CAAC,EAAE,eAAe,CAAC;IAC/C,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;IAClD,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAC9C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAC9C,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC;AAQD,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAY1D;AAED,wBAAgB,oBAAoB,CAAC,qBAAqB,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtH;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAKpF;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,CAwC7D;AAGD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAczH;AAED;;;GAGG;AACH,wBAAgB,2BAA2B;;;;;;;;EAY1C"}
|