@teamvortexsoftware/vortex-nextjs-15-sdk 0.0.1 → 0.0.3
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/README.md +143 -373
- package/bin/vortex-setup.js +181 -0
- package/dist/config.d.ts +56 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +81 -20
- package/dist/handlers/invitations.js +98 -84
- package/dist/handlers/jwt.d.ts.map +1 -1
- package/dist/handlers/jwt.js +58 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/routes.d.ts +100 -10
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +100 -7
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +37 -3
- package/package.json +14 -12
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const VORTEX_ROUTES = [
|
|
7
|
+
'jwt/route.ts',
|
|
8
|
+
'invitations/route.ts',
|
|
9
|
+
'invitations/[invitationId]/route.ts',
|
|
10
|
+
'invitations/accept/route.ts',
|
|
11
|
+
'invitations/by-group/[groupType]/[groupId]/route.ts',
|
|
12
|
+
'invitations/[invitationId]/reinvite/route.ts'
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const ROUTE_TEMPLATES = {
|
|
16
|
+
'jwt/route.ts': `import 'lib/vortex-config';
|
|
17
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
18
|
+
|
|
19
|
+
export const { POST } = createVortexRoutes().jwt;
|
|
20
|
+
`,
|
|
21
|
+
|
|
22
|
+
'invitations/route.ts': `import 'lib/vortex-config';
|
|
23
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
24
|
+
|
|
25
|
+
export const { GET } = createVortexRoutes().invitations;
|
|
26
|
+
`,
|
|
27
|
+
|
|
28
|
+
'invitations/[invitationId]/route.ts': `import 'lib/vortex-config';
|
|
29
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
30
|
+
|
|
31
|
+
export const { GET, DELETE } = createVortexRoutes().invitation;
|
|
32
|
+
`,
|
|
33
|
+
|
|
34
|
+
'invitations/accept/route.ts': `import 'lib/vortex-config';
|
|
35
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
36
|
+
|
|
37
|
+
export const { POST } = createVortexRoutes().invitationsAccept;
|
|
38
|
+
`,
|
|
39
|
+
|
|
40
|
+
'invitations/by-group/[groupType]/[groupId]/route.ts': `import 'lib/vortex-config';
|
|
41
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
42
|
+
|
|
43
|
+
export const { GET, DELETE } = createVortexRoutes().invitationsByGroup;
|
|
44
|
+
`,
|
|
45
|
+
|
|
46
|
+
'invitations/[invitationId]/reinvite/route.ts': `import 'lib/vortex-config';
|
|
47
|
+
import { createVortexRoutes } from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
48
|
+
|
|
49
|
+
export const { POST } = createVortexRoutes().invitationReinvite;
|
|
50
|
+
`
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const CONFIG_TEMPLATE = `import {
|
|
54
|
+
configureVortexLazy,
|
|
55
|
+
createAllowAllAccessControl,
|
|
56
|
+
type VortexConfig,
|
|
57
|
+
} from '@teamvortexsoftware/vortex-nextjs-15-sdk';
|
|
58
|
+
|
|
59
|
+
// Configure Vortex with lazy initialization - only runs when first API call is made
|
|
60
|
+
configureVortexLazy(async (): Promise<VortexConfig> => {
|
|
61
|
+
return {
|
|
62
|
+
apiKey: process.env.VORTEX_API_KEY!,
|
|
63
|
+
|
|
64
|
+
// Required: How to authenticate users for JWT generation
|
|
65
|
+
authenticateUser: async (request) => {
|
|
66
|
+
// TODO: Replace this with your authentication logic
|
|
67
|
+
//
|
|
68
|
+
// Examples:
|
|
69
|
+
// - NextAuth.js: const session = await getServerSession(request, authOptions);
|
|
70
|
+
// - Supabase: const { data: { user } } = await supabase.auth.getUser();
|
|
71
|
+
// - Custom JWT: const user = await verifyJwtToken(request);
|
|
72
|
+
//
|
|
73
|
+
// Expected return format:
|
|
74
|
+
// return {
|
|
75
|
+
// userId: user.id,
|
|
76
|
+
// identifiers: [{ type: 'email', value: user.email }],
|
|
77
|
+
// groups: [{ type: 'team', id: 'team-123', name: 'My Team' }],
|
|
78
|
+
// };
|
|
79
|
+
|
|
80
|
+
throw new Error('TODO: Implement authenticateUser in lib/vortex-config.ts');
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// Simple access control - allows all operations (customize for production)
|
|
84
|
+
...createAllowAllAccessControl(),
|
|
85
|
+
|
|
86
|
+
// For production, replace createAllowAllAccessControl() with custom logic:
|
|
87
|
+
// canDeleteInvitation: async (request, user, resource) => {
|
|
88
|
+
// return user?.role === 'admin';
|
|
89
|
+
// },
|
|
90
|
+
// canAccessInvitationsByGroup: async (request, user, resource) => {
|
|
91
|
+
// return user?.groups.some(g =>
|
|
92
|
+
// g.type === resource?.groupType && g.id === resource?.groupId
|
|
93
|
+
// );
|
|
94
|
+
// },
|
|
95
|
+
// ... other access control hooks
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
function createDirectory(dirPath) {
|
|
101
|
+
if (!fs.existsSync(dirPath)) {
|
|
102
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
103
|
+
console.log(`✓ Created directory: ${dirPath}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function writeFileIfNotExists(filePath, content) {
|
|
108
|
+
if (fs.existsSync(filePath)) {
|
|
109
|
+
console.log(`⚠ File already exists, skipping: ${filePath}`);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fs.writeFileSync(filePath, content);
|
|
114
|
+
console.log(`✓ Created file: ${filePath}`);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function main() {
|
|
119
|
+
console.log('🚀 Setting up Vortex Next.js 15 SDK...\n');
|
|
120
|
+
|
|
121
|
+
// Check if we're in a Next.js project
|
|
122
|
+
if (!fs.existsSync('next.config.js') && !fs.existsSync('next.config.ts') && !fs.existsSync('next.config.mjs')) {
|
|
123
|
+
console.error('❌ This doesn\'t appear to be a Next.js project. Make sure you\'re in the root directory.');
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Check for app directory
|
|
128
|
+
if (!fs.existsSync('app')) {
|
|
129
|
+
console.error('❌ This setup requires Next.js App Router. Please ensure you have an "app" directory.');
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let filesCreated = 0;
|
|
134
|
+
|
|
135
|
+
// Create API routes
|
|
136
|
+
const apiDir = path.join('app', 'api', 'vortex');
|
|
137
|
+
createDirectory(apiDir);
|
|
138
|
+
|
|
139
|
+
VORTEX_ROUTES.forEach(route => {
|
|
140
|
+
const filePath = path.join(apiDir, route);
|
|
141
|
+
const dirPath = path.dirname(filePath);
|
|
142
|
+
|
|
143
|
+
createDirectory(dirPath);
|
|
144
|
+
|
|
145
|
+
if (writeFileIfNotExists(filePath, ROUTE_TEMPLATES[route])) {
|
|
146
|
+
filesCreated++;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Create lib directory and config file
|
|
151
|
+
createDirectory('lib');
|
|
152
|
+
const configPath = path.join('lib', 'vortex-config.ts');
|
|
153
|
+
|
|
154
|
+
if (writeFileIfNotExists(configPath, CONFIG_TEMPLATE)) {
|
|
155
|
+
filesCreated++;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
console.log(`\n🎉 Setup complete! Created ${filesCreated} new files.`);
|
|
159
|
+
console.log('\n📋 Next steps:');
|
|
160
|
+
console.log('1. Add your VORTEX_API_KEY to .env.local:');
|
|
161
|
+
console.log(' VORTEX_API_KEY=your_api_key_here');
|
|
162
|
+
console.log('2. Import the config in your app/layout.tsx:');
|
|
163
|
+
console.log(' import \'../lib/vortex-config\';');
|
|
164
|
+
console.log('3. Implement the authenticateUser function in lib/vortex-config.ts');
|
|
165
|
+
console.log('4. Wrap your app in VortexProvider:');
|
|
166
|
+
console.log(' <VortexProvider config={{ apiBaseUrl: \'/api/vortex\' }}>');
|
|
167
|
+
|
|
168
|
+
console.log('\n✨ Features:');
|
|
169
|
+
console.log('• Super simple - each route is just 3 lines!');
|
|
170
|
+
console.log('• Lazy initialization - no database calls during build');
|
|
171
|
+
console.log('• createAllowAllAccessControl() for easy development');
|
|
172
|
+
console.log('• Full TypeScript support with IntelliSense');
|
|
173
|
+
|
|
174
|
+
console.log('\n📚 See the README for examples and customization options.');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (require.main === module) {
|
|
178
|
+
main();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = { main };
|
package/dist/config.d.ts
CHANGED
|
@@ -7,27 +7,72 @@ export interface AuthenticatedUser {
|
|
|
7
7
|
}[];
|
|
8
8
|
groups: {
|
|
9
9
|
type: string;
|
|
10
|
-
id
|
|
10
|
+
id?: string;
|
|
11
|
+
groupId?: string;
|
|
11
12
|
name: string;
|
|
12
13
|
}[];
|
|
13
14
|
role?: string;
|
|
15
|
+
attributes?: Record<string, any>;
|
|
14
16
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
+
export interface InvitationResource {
|
|
18
|
+
invitationId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface InvitationTargetResource {
|
|
21
|
+
invitationIds: string[];
|
|
22
|
+
target: {
|
|
23
|
+
type: string;
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface GroupResource {
|
|
28
|
+
groupType: string;
|
|
29
|
+
groupId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface AccessControlHook<T = any> {
|
|
32
|
+
(request: NextRequest, user: AuthenticatedUser | null, resource?: T): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
export interface InvitationAccessHook extends AccessControlHook<InvitationResource> {
|
|
35
|
+
}
|
|
36
|
+
export interface InvitationTargetAccessHook extends AccessControlHook<InvitationTargetResource> {
|
|
37
|
+
}
|
|
38
|
+
export interface GroupAccessHook extends AccessControlHook<GroupResource> {
|
|
39
|
+
}
|
|
40
|
+
export interface BasicAccessHook extends AccessControlHook<void> {
|
|
41
|
+
}
|
|
42
|
+
export interface JwtContext {
|
|
43
|
+
widgetId?: string;
|
|
44
|
+
groupId?: string;
|
|
45
|
+
groupType?: string;
|
|
17
46
|
}
|
|
18
47
|
export interface VortexConfig {
|
|
19
48
|
apiKey: string;
|
|
20
49
|
apiBaseUrl?: string;
|
|
21
50
|
authenticateUser?: (request: NextRequest) => Promise<AuthenticatedUser | null>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
51
|
+
generateJwtAttributes?: (request: NextRequest, context?: JwtContext) => Promise<Record<string, any>>;
|
|
52
|
+
canAccessInvitationsByTarget?: BasicAccessHook;
|
|
53
|
+
canAccessInvitation?: InvitationAccessHook;
|
|
54
|
+
canDeleteInvitation?: InvitationAccessHook;
|
|
55
|
+
canAcceptInvitations?: InvitationTargetAccessHook;
|
|
56
|
+
canAccessInvitationsByGroup?: GroupAccessHook;
|
|
57
|
+
canDeleteInvitationsByGroup?: GroupAccessHook;
|
|
58
|
+
canReinvite?: InvitationAccessHook;
|
|
29
59
|
}
|
|
30
60
|
export declare function configureVortex(config: VortexConfig): void;
|
|
31
|
-
export declare function
|
|
61
|
+
export declare function configureVortexAsync(configPromiseOrConfig: Promise<VortexConfig> | VortexConfig): void | Promise<void>;
|
|
62
|
+
export declare function configureVortexLazy(configFactory: () => Promise<VortexConfig>): void;
|
|
63
|
+
export declare function getVortexConfig(request?: NextRequest): Promise<VortexConfig>;
|
|
32
64
|
export declare function authenticateRequest(request: NextRequest): Promise<AuthenticatedUser | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a set of access control hooks that allow all operations.
|
|
67
|
+
* Useful for demos, development, or when you want to handle authorization elsewhere.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createAllowAllAccessControl(): {
|
|
70
|
+
canAccessInvitationsByTarget: () => Promise<boolean>;
|
|
71
|
+
canAccessInvitation: () => Promise<boolean>;
|
|
72
|
+
canDeleteInvitation: () => Promise<boolean>;
|
|
73
|
+
canAcceptInvitations: () => Promise<boolean>;
|
|
74
|
+
canAccessInvitationsByGroup: () => Promise<boolean>;
|
|
75
|
+
canDeleteInvitationsByGroup: () => Promise<boolean>;
|
|
76
|
+
canReinvite: () => Promise<boolean>;
|
|
77
|
+
};
|
|
33
78
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MA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;;;;;;;;EAY1C"}
|
package/dist/config.js
CHANGED
|
@@ -48,11 +48,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.configureVortex = configureVortex;
|
|
51
|
+
exports.configureVortexAsync = configureVortexAsync;
|
|
52
|
+
exports.configureVortexLazy = configureVortexLazy;
|
|
51
53
|
exports.getVortexConfig = getVortexConfig;
|
|
52
54
|
exports.authenticateRequest = authenticateRequest;
|
|
55
|
+
exports.createAllowAllAccessControl = createAllowAllAccessControl;
|
|
53
56
|
// Store configuration template (immutable after first set)
|
|
54
57
|
var configTemplate = null;
|
|
55
58
|
var isConfigLocked = false;
|
|
59
|
+
var configPromise = null;
|
|
60
|
+
var lazyConfigFactory = null;
|
|
56
61
|
function configureVortex(config) {
|
|
57
62
|
if (isConfigLocked && configTemplate) {
|
|
58
63
|
throw new Error('Vortex configuration is already locked. Configuration can only be set once for security reasons.');
|
|
@@ -64,20 +69,56 @@ function configureVortex(config) {
|
|
|
64
69
|
configTemplate = __assign({}, config);
|
|
65
70
|
isConfigLocked = true;
|
|
66
71
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
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);
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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.');
|
|
79
85
|
}
|
|
80
|
-
|
|
86
|
+
lazyConfigFactory = configFactory;
|
|
87
|
+
}
|
|
88
|
+
function getVortexConfig(request) {
|
|
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, generateJwtAttributes: configTemplate.generateJwtAttributes, 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
|
+
});
|
|
81
122
|
}
|
|
82
123
|
// Helper function to authenticate user for any request
|
|
83
124
|
function authenticateRequest(request) {
|
|
@@ -85,23 +126,43 @@ function authenticateRequest(request) {
|
|
|
85
126
|
var config, error_1;
|
|
86
127
|
return __generator(this, function (_a) {
|
|
87
128
|
switch (_a.label) {
|
|
88
|
-
case 0:
|
|
89
|
-
|
|
129
|
+
case 0: return [4 /*yield*/, getVortexConfig(request)];
|
|
130
|
+
case 1:
|
|
131
|
+
config = _a.sent();
|
|
90
132
|
if (!config.authenticateUser) {
|
|
91
133
|
return [2 /*return*/, null];
|
|
92
134
|
}
|
|
93
|
-
_a.label =
|
|
94
|
-
case
|
|
95
|
-
_a.trys.push([
|
|
135
|
+
_a.label = 2;
|
|
136
|
+
case 2:
|
|
137
|
+
_a.trys.push([2, 4, , 5]);
|
|
96
138
|
return [4 /*yield*/, config.authenticateUser(request)];
|
|
97
|
-
case
|
|
98
|
-
case
|
|
139
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
140
|
+
case 4:
|
|
99
141
|
error_1 = _a.sent();
|
|
100
142
|
// Log error but don't expose details
|
|
101
143
|
console.error('Authentication error:', error_1);
|
|
102
144
|
return [2 /*return*/, null];
|
|
103
|
-
case
|
|
145
|
+
case 5: return [2 /*return*/];
|
|
104
146
|
}
|
|
105
147
|
});
|
|
106
148
|
});
|
|
107
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
|
+
}
|