@teamvortexsoftware/vortex-nextjs-15-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 +454 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +107 -0
- package/dist/examples.d.ts +41 -0
- package/dist/examples.d.ts.map +1 -0
- package/dist/examples.js +50 -0
- package/dist/handlers/invitations.d.ts +9 -0
- package/dist/handlers/invitations.d.ts.map +1 -0
- package/dist/handlers/invitations.js +400 -0
- package/dist/handlers/jwt.d.ts +3 -0
- package/dist/handlers/jwt.d.ts.map +1 -0
- package/dist/handlers/jwt.js +79 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/routes.d.ts +42 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +129 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +88 -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,454 @@
|
|
|
1
|
+
# Vortex Next.js 15 SDK
|
|
2
|
+
|
|
3
|
+
A Next.js SDK that provides API route handlers for Vortex functionality. This SDK wraps the `@teamvortexsoftware/vortex-node-22-sdk` to help integrate Vortex into your Next.js applications.
|
|
4
|
+
|
|
5
|
+
## ⚠️ SECURITY NOTICE
|
|
6
|
+
|
|
7
|
+
**This SDK requires proper security configuration before production use:**
|
|
8
|
+
- ✋ **All invitation endpoints require access control hooks to be configured**
|
|
9
|
+
- ✋ **JWT endpoints require authentication hooks to be configured**
|
|
10
|
+
- ✋ **No endpoints are secured by default - you must implement authorization**
|
|
11
|
+
- ✋ **Input sanitization and rate limiting should be implemented**
|
|
12
|
+
- ✋ **Error messages are sanitized but you should implement proper logging**
|
|
13
|
+
|
|
14
|
+
**This is NOT a drop-in solution - it requires security implementation by you.**
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @teamvortexsoftware/vortex-nextjs-15-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
Configure Vortex in your application:
|
|
25
|
+
|
|
26
|
+
### Environment Variables
|
|
27
|
+
Set the following environment variables:
|
|
28
|
+
```bash
|
|
29
|
+
VORTEX_API_KEY=your_api_key
|
|
30
|
+
VORTEX_API_BASE_URL=https://api.vortexsoftware.com # optional
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Security Configuration (REQUIRED)
|
|
34
|
+
|
|
35
|
+
**CRITICAL**: You MUST configure authentication and access control hooks for ALL endpoints to work securely.
|
|
36
|
+
|
|
37
|
+
#### Complete Security Configuration
|
|
38
|
+
|
|
39
|
+
1. Create a configuration file: `lib/vortex-config.ts`
|
|
40
|
+
```typescript
|
|
41
|
+
import { configureVortex, type AuthenticatedUser, type AccessControlHook } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
42
|
+
import { NextRequest } from 'next/server';
|
|
43
|
+
|
|
44
|
+
configureVortex({
|
|
45
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
46
|
+
|
|
47
|
+
// Required for JWT generation
|
|
48
|
+
authenticateUser: async (request: NextRequest): Promise<AuthenticatedUser | null> => {
|
|
49
|
+
// Your authentication logic - get user from session, JWT, etc.
|
|
50
|
+
const user = await getCurrentUser(request);
|
|
51
|
+
|
|
52
|
+
return user ? {
|
|
53
|
+
userId: user.id,
|
|
54
|
+
identifiers: [{ type: 'email', value: user.email }],
|
|
55
|
+
groups: user.groups || [],
|
|
56
|
+
role: user.role
|
|
57
|
+
} : null;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// Required for invitation endpoints - implement all that you plan to use
|
|
61
|
+
canAccessInvitationsByTarget: async (request, user, resource) => {
|
|
62
|
+
// Check if user can access invitations for the target
|
|
63
|
+
return user && await canUserAccessTarget(user, resource);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
canAccessInvitation: async (request, user, resource) => {
|
|
67
|
+
// Check if user can access this specific invitation
|
|
68
|
+
return user && await canUserAccessInvitation(user, resource.invitationId);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
canDeleteInvitation: async (request, user, resource) => {
|
|
72
|
+
// Check if user can delete this invitation (e.g., admin only)
|
|
73
|
+
return user && user.role === 'admin' && await canUserAccessInvitation(user, resource.invitationId);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
canAcceptInvitations: async (request, user, resource) => {
|
|
77
|
+
// Check if user can accept these invitations
|
|
78
|
+
return user && await canUserAcceptInvitations(user, resource.invitationIds);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
canAccessInvitationsByGroup: async (request, user, resource) => {
|
|
82
|
+
// Check if user can access invitations for this group
|
|
83
|
+
return user && await canUserAccessGroup(user, resource.groupType, resource.groupId);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
canDeleteInvitationsByGroup: async (request, user, resource) => {
|
|
87
|
+
// Check if user can delete invitations for this group
|
|
88
|
+
return user && user.role === 'admin' && await canUserAccessGroup(user, resource.groupType, resource.groupId);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
canReinvite: async (request, user, resource) => {
|
|
92
|
+
// Check if user can resend this invitation
|
|
93
|
+
return user && await canUserReinvite(user, resource.invitationId);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**⚠️ WARNING**: If any access control hook is missing, that endpoint will fail with 403 unless the user is authenticated. This is by design for security.
|
|
99
|
+
|
|
100
|
+
2. Import it in your root layout: `app/layout.tsx`
|
|
101
|
+
```typescript
|
|
102
|
+
import '../lib/vortex-config'; // Initialize Vortex configuration
|
|
103
|
+
|
|
104
|
+
export default function RootLayout({ children }) {
|
|
105
|
+
return <html><body>{children}</body></html>;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### For Invitations Only (No Authentication Hook Needed)
|
|
110
|
+
```bash
|
|
111
|
+
# Just set environment variables
|
|
112
|
+
VORTEX_API_KEY=your_api_key
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
📖 **For detailed configuration options and authentication examples (NextAuth.js, Supabase, custom JWT), see [CONFIGURATION_GUIDE.md](./CONFIGURATION_GUIDE.md)**
|
|
116
|
+
|
|
117
|
+
## Setting Up API Routes
|
|
118
|
+
|
|
119
|
+
This SDK provides convenience functions to create Next.js API route handlers. Create the following files in your Next.js app directory:
|
|
120
|
+
|
|
121
|
+
⚠️ **IMPORTANT - Access Control Required**: The invitation management endpoints do not implement authorization checks. You must add your own access controls to ensure users can only access invitations they are authorized to see. The SDK only handles the Vortex API communication - authorization is your responsibility.
|
|
122
|
+
|
|
123
|
+
### 1. JWT Generation Route
|
|
124
|
+
**File:** `app/api/vortex/jwt/route.ts`
|
|
125
|
+
```typescript
|
|
126
|
+
import { createVortexJwtRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
127
|
+
|
|
128
|
+
export const POST = createVortexJwtRoute();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 2. Get Invitations by Target
|
|
132
|
+
**File:** `app/api/vortex/invitations/route.ts`
|
|
133
|
+
```typescript
|
|
134
|
+
import { createVortexInvitationsRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
135
|
+
|
|
136
|
+
export const { GET } = createVortexInvitationsRoute();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**With Access Control Example:**
|
|
140
|
+
```typescript
|
|
141
|
+
import { NextRequest } from 'next/server';
|
|
142
|
+
import { handleGetInvitationsByTarget, createErrorResponse } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
143
|
+
|
|
144
|
+
export async function GET(request: NextRequest) {
|
|
145
|
+
// Add your authorization logic here
|
|
146
|
+
const user = await getCurrentUser(request);
|
|
147
|
+
|
|
148
|
+
if (!user) {
|
|
149
|
+
return createErrorResponse('Unauthorized', 401);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Additional checks - ensure user can access the requested target
|
|
153
|
+
const targetValue = request.nextUrl.searchParams.get('targetValue');
|
|
154
|
+
if (!canUserAccessTarget(user, targetValue)) {
|
|
155
|
+
return createErrorResponse('Forbidden', 403);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return handleGetInvitationsByTarget(request);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 3. Individual Invitation Management
|
|
163
|
+
**File:** `app/api/vortex/invitations/[invitationId]/route.ts`
|
|
164
|
+
```typescript
|
|
165
|
+
import { createVortexInvitationRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
166
|
+
|
|
167
|
+
export const { GET, DELETE } = createVortexInvitationRoute();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**With Access Control Example:**
|
|
171
|
+
```typescript
|
|
172
|
+
import { NextRequest } from 'next/server';
|
|
173
|
+
import { handleGetInvitation, handleRevokeInvitation, createErrorResponse } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
174
|
+
|
|
175
|
+
export async function GET(request: NextRequest, { params }: { params: { invitationId: string } }) {
|
|
176
|
+
const user = await getCurrentUser(request);
|
|
177
|
+
|
|
178
|
+
if (!user || !await canUserAccessInvitation(user, params.invitationId)) {
|
|
179
|
+
return createErrorResponse('Unauthorized', 401);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return handleGetInvitation(request, params.invitationId);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function DELETE(request: NextRequest, { params }: { params: { invitationId: string } }) {
|
|
186
|
+
const user = await getCurrentUser(request);
|
|
187
|
+
|
|
188
|
+
if (!user || !await canUserDeleteInvitation(user, params.invitationId)) {
|
|
189
|
+
return createErrorResponse('Unauthorized', 401);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return handleRevokeInvitation(request, params.invitationId);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 4. Accept Invitations
|
|
197
|
+
**File:** `app/api/vortex/invitations/accept/route.ts`
|
|
198
|
+
```typescript
|
|
199
|
+
import { createVortexInvitationsAcceptRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
200
|
+
|
|
201
|
+
export const { POST } = createVortexInvitationsAcceptRoute();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### 5. Group-based Invitation Management
|
|
205
|
+
**File:** `app/api/vortex/invitations/by-group/[groupType]/[groupId]/route.ts`
|
|
206
|
+
```typescript
|
|
207
|
+
import { createVortexInvitationsByGroupRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
208
|
+
|
|
209
|
+
export const { GET, DELETE } = createVortexInvitationsByGroupRoute();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**With Access Control Example:**
|
|
213
|
+
```typescript
|
|
214
|
+
import { NextRequest } from 'next/server';
|
|
215
|
+
import { handleGetInvitationsByGroup, handleDeleteInvitationsByGroup, createErrorResponse } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
216
|
+
|
|
217
|
+
export async function GET(request: NextRequest, { params }: { params: { groupType: string; groupId: string } }) {
|
|
218
|
+
const user = await getCurrentUser(request);
|
|
219
|
+
|
|
220
|
+
if (!user || !await canUserAccessGroup(user, params.groupType, params.groupId)) {
|
|
221
|
+
return createErrorResponse('Unauthorized', 401);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return handleGetInvitationsByGroup(request, params.groupType, params.groupId);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function DELETE(request: NextRequest, { params }: { params: { groupType: string; groupId: string } }) {
|
|
228
|
+
const user = await getCurrentUser(request);
|
|
229
|
+
|
|
230
|
+
if (!user || !await canUserManageGroup(user, params.groupType, params.groupId)) {
|
|
231
|
+
return createErrorResponse('Unauthorized', 401);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return handleDeleteInvitationsByGroup(request, params.groupType, params.groupId);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 6. Reinvite
|
|
239
|
+
**File:** `app/api/vortex/invitations/[invitationId]/reinvite/route.ts`
|
|
240
|
+
```typescript
|
|
241
|
+
import { createVortexReinviteRoute } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
242
|
+
|
|
243
|
+
export const { POST } = createVortexReinviteRoute();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**With Access Control Example:**
|
|
247
|
+
```typescript
|
|
248
|
+
import { NextRequest } from 'next/server';
|
|
249
|
+
import { handleReinvite, createErrorResponse } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
250
|
+
|
|
251
|
+
export async function POST(request: NextRequest, { params }: { params: { invitationId: string } }) {
|
|
252
|
+
const user = await getCurrentUser(request);
|
|
253
|
+
|
|
254
|
+
if (!user || !await canUserReinvite(user, params.invitationId)) {
|
|
255
|
+
return createErrorResponse('Unauthorized', 401);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return handleReinvite(request, params.invitationId);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## API Endpoints
|
|
263
|
+
|
|
264
|
+
Once set up, your Next.js app will expose the following API endpoints:
|
|
265
|
+
|
|
266
|
+
### JWT Generation
|
|
267
|
+
- **POST** `/api/vortex/jwt`
|
|
268
|
+
- Generates JWT token for the authenticated user making the request
|
|
269
|
+
|
|
270
|
+
**Authentication Required**: This endpoint requires the `authenticateUser` hook to be configured. The JWT will be generated using data from your authenticated user, not from request body data.
|
|
271
|
+
|
|
272
|
+
**Request**: No request body required. User information is obtained through your authentication hook.
|
|
273
|
+
|
|
274
|
+
**Response:**
|
|
275
|
+
```json
|
|
276
|
+
{
|
|
277
|
+
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Error Responses:**
|
|
282
|
+
- `401 Unauthorized`: User is not authenticated
|
|
283
|
+
- `500 Internal Server Error`: Missing authenticateUser configuration
|
|
284
|
+
|
|
285
|
+
### Invitations Management
|
|
286
|
+
|
|
287
|
+
#### Get Invitations by Target
|
|
288
|
+
- **GET** `/api/vortex/invitations?targetType=email&targetValue=user@example.com`
|
|
289
|
+
- Supported `targetType`: `email`, `username`, `phoneNumber`
|
|
290
|
+
|
|
291
|
+
#### Get Specific Invitation
|
|
292
|
+
- **GET** `/api/vortex/invitations/{invitationId}`
|
|
293
|
+
|
|
294
|
+
#### Revoke Invitation
|
|
295
|
+
- **DELETE** `/api/vortex/invitations/{invitationId}`
|
|
296
|
+
|
|
297
|
+
#### Accept Invitations
|
|
298
|
+
- **POST** `/api/vortex/invitations/accept`
|
|
299
|
+
|
|
300
|
+
**Request Body:**
|
|
301
|
+
```json
|
|
302
|
+
{
|
|
303
|
+
"invitationIds": ["inv-123", "inv-456"],
|
|
304
|
+
"target": {
|
|
305
|
+
"type": "email",
|
|
306
|
+
"value": "user@example.com"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### Get Invitations by Group
|
|
312
|
+
- **GET** `/api/vortex/invitations/by-group/{groupType}/{groupId}`
|
|
313
|
+
|
|
314
|
+
#### Delete Invitations by Group
|
|
315
|
+
- **DELETE** `/api/vortex/invitations/by-group/{groupType}/{groupId}`
|
|
316
|
+
|
|
317
|
+
#### Resend Invitation
|
|
318
|
+
- **POST** `/api/vortex/invitations/{invitationId}/reinvite`
|
|
319
|
+
|
|
320
|
+
## Advanced Usage
|
|
321
|
+
|
|
322
|
+
### Custom Route Handlers
|
|
323
|
+
If you need more control, you can use the individual handler functions:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import { NextRequest } from 'next/server';
|
|
327
|
+
import { handleJwtGeneration } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
328
|
+
|
|
329
|
+
export async function POST(request: NextRequest) {
|
|
330
|
+
// Add custom logic here (e.g., authentication, logging)
|
|
331
|
+
|
|
332
|
+
return handleJwtGeneration(request);
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Direct SDK Access
|
|
337
|
+
You can also use the underlying Vortex SDK directly:
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
import { Vortex } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
341
|
+
|
|
342
|
+
const vortex = new Vortex(process.env.VORTEX_API_KEY!);
|
|
343
|
+
const jwt = vortex.generateJwt({
|
|
344
|
+
userId: 'user-123',
|
|
345
|
+
identifiers: [{ type: 'email', value: 'user@example.com' }],
|
|
346
|
+
groups: [{ type: 'org', id: 'org-123', name: 'My Org' }]
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Implementing Access Controls
|
|
351
|
+
|
|
352
|
+
**CRITICAL**: You must implement your own authorization logic for all invitation endpoints. The SDK does not make authorization decisions - it only handles Vortex API communication.
|
|
353
|
+
|
|
354
|
+
### Common Access Control Patterns
|
|
355
|
+
|
|
356
|
+
#### Resource Ownership
|
|
357
|
+
```typescript
|
|
358
|
+
async function canUserAccessInvitation(user: any, invitationId: string): Promise<boolean> {
|
|
359
|
+
// Check if the invitation belongs to the user's organization
|
|
360
|
+
const invitation = await getInvitationFromDatabase(invitationId);
|
|
361
|
+
return invitation && user.organizationIds.includes(invitation.organizationId);
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
#### Role-Based Access
|
|
366
|
+
```typescript
|
|
367
|
+
async function canUserDeleteInvitation(user: any, invitationId: string): Promise<boolean> {
|
|
368
|
+
// Only admins can delete invitations
|
|
369
|
+
return user.role === 'admin' && await canUserAccessInvitation(user, invitationId);
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### Group Membership
|
|
374
|
+
```typescript
|
|
375
|
+
async function canUserAccessGroup(user: any, groupType: string, groupId: string): Promise<boolean> {
|
|
376
|
+
// Check if user is a member of the group
|
|
377
|
+
return user.groups.some(group =>
|
|
378
|
+
group.type === groupType && group.id === groupId
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Access Control Checklist
|
|
384
|
+
|
|
385
|
+
For each endpoint, consider:
|
|
386
|
+
- ✅ **Authentication**: Is the user logged in?
|
|
387
|
+
- ✅ **Resource Ownership**: Does the user own or have access to this resource?
|
|
388
|
+
- ✅ **Permission Level**: Does the user have the right permissions for this action?
|
|
389
|
+
- ✅ **Rate Limiting**: Should this endpoint be rate limited?
|
|
390
|
+
- ✅ **Audit Logging**: Should this action be logged?
|
|
391
|
+
|
|
392
|
+
## Error Handling
|
|
393
|
+
|
|
394
|
+
All API routes return standardized error responses:
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"error": "Error message here"
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Common HTTP status codes:
|
|
403
|
+
- `400`: Bad Request (missing required fields, invalid parameters)
|
|
404
|
+
- `401`: Unauthorized (authentication required)
|
|
405
|
+
- `403`: Forbidden (insufficient permissions)
|
|
406
|
+
- `405`: Method Not Allowed
|
|
407
|
+
- `429`: Too Many Requests (if you implement rate limiting)
|
|
408
|
+
- `500`: Internal Server Error
|
|
409
|
+
|
|
410
|
+
## Rate Limiting & Security Best Practices
|
|
411
|
+
|
|
412
|
+
**CRITICAL**: Implement rate limiting to prevent abuse. Here are examples:
|
|
413
|
+
|
|
414
|
+
### With `@upstash/ratelimit`
|
|
415
|
+
```typescript
|
|
416
|
+
import { Ratelimit } from '@upstash/ratelimit';
|
|
417
|
+
import { Redis } from '@upstash/redis';
|
|
418
|
+
|
|
419
|
+
const ratelimit = new Ratelimit({
|
|
420
|
+
redis: Redis.fromEnv(),
|
|
421
|
+
limiter: Ratelimit.slidingWindow(10, '1 m'), // 10 requests per minute
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// In your API route
|
|
425
|
+
export async function GET(request: NextRequest) {
|
|
426
|
+
// Rate limiting
|
|
427
|
+
const identifier = await getUserIdentifier(request); // IP or user ID
|
|
428
|
+
const { success } = await ratelimit.limit(identifier);
|
|
429
|
+
|
|
430
|
+
if (!success) {
|
|
431
|
+
return createErrorResponse('Too many requests', 429);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Your Vortex handler
|
|
435
|
+
return handleGetInvitationsByTarget(request);
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Security Checklist
|
|
440
|
+
- ✅ **Rate limiting**: Prevent DoS attacks
|
|
441
|
+
- ✅ **Input validation**: All user input is sanitized by the SDK
|
|
442
|
+
- ✅ **Error logging**: Log security events without exposing internals
|
|
443
|
+
- ✅ **HTTPS only**: Never use these endpoints over HTTP
|
|
444
|
+
- ✅ **Secret management**: Use proper secret storage (not `.env` files in production)
|
|
445
|
+
- ✅ **Monitoring**: Monitor for unusual access patterns
|
|
446
|
+
|
|
447
|
+
## TypeScript Support
|
|
448
|
+
|
|
449
|
+
This package includes full TypeScript definitions. All types from the underlying Node.js SDK are re-exported for convenience.
|
|
450
|
+
|
|
451
|
+
## Requirements
|
|
452
|
+
|
|
453
|
+
- Next.js 13.0.0 or higher
|
|
454
|
+
- Node.js 18 or higher
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
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 AccessControlHook {
|
|
16
|
+
(request: NextRequest, user: AuthenticatedUser | null, resource?: any): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
export interface VortexConfig {
|
|
19
|
+
apiKey: string;
|
|
20
|
+
apiBaseUrl?: string;
|
|
21
|
+
authenticateUser?: (request: NextRequest) => Promise<AuthenticatedUser | null>;
|
|
22
|
+
canAccessInvitationsByTarget?: AccessControlHook;
|
|
23
|
+
canAccessInvitation?: AccessControlHook;
|
|
24
|
+
canDeleteInvitation?: AccessControlHook;
|
|
25
|
+
canAcceptInvitations?: AccessControlHook;
|
|
26
|
+
canAccessInvitationsByGroup?: AccessControlHook;
|
|
27
|
+
canDeleteInvitationsByGroup?: AccessControlHook;
|
|
28
|
+
canReinvite?: AccessControlHook;
|
|
29
|
+
}
|
|
30
|
+
export declare function configureVortex(config: VortexConfig): void;
|
|
31
|
+
export declare function getVortexConfig(request?: NextRequest): VortexConfig;
|
|
32
|
+
export declare function authenticateRequest(request: NextRequest): Promise<AuthenticatedUser | null>;
|
|
33
|
+
//# 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,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,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;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1F;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAE/E,4BAA4B,CAAC,EAAE,iBAAiB,CAAC;IACjD,mBAAmB,CAAC,EAAE,iBAAiB,CAAC;IACxC,mBAAmB,CAAC,EAAE,iBAAiB,CAAC;IACxC,oBAAoB,CAAC,EAAE,iBAAiB,CAAC;IACzC,2BAA2B,CAAC,EAAE,iBAAiB,CAAC;IAChD,2BAA2B,CAAC,EAAE,iBAAiB,CAAC;IAChD,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC;AAMD,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAY1D;AAED,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,YAAY,CA2BnE;AAGD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAcjG"}
|