@multitenantkit/sdk 0.1.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/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # @multitenantkit/sdk
2
+
3
+ Complete SDK for building multi-tenant SaaS backends - includes all adapters and options.
4
+
5
+ ## 📦 What's Included
6
+
7
+ This SDK bundles all available packages from the MultiTenantKit:
8
+
9
+ ### Core
10
+
11
+ - `@multitenantkit/domain-contracts` - Domain schemas and types
12
+ - `@multitenantkit/api-contracts` - API HTTP schemas
13
+ - `@multitenantkit/domain` - Business logic and use cases
14
+ - `@multitenantkit/composition` - Dependency injection and orchestration
15
+
16
+ ### Persistence Adapters
17
+
18
+ - `@multitenantkit/adapter-persistence-json` - JSON file persistence (development)
19
+ - `@multitenantkit/adapter-persistence-postgres` - PostgreSQL persistence (production)
20
+
21
+ ### Authentication
22
+
23
+ - `@multitenantkit/adapter-auth-supabase` - Supabase authentication
24
+
25
+ ### API Layer
26
+
27
+ - `@multitenantkit/api-handlers` - Transport-agnostic HTTP handlers
28
+ - `@multitenantkit/adapter-transport-express` - Express.js adapter
29
+
30
+ ### System Adapters
31
+
32
+ - `@multitenantkit/adapter-system-crypto-uuid` - UUID generator
33
+ - `@multitenantkit/adapter-system-system-clock` - System clock
34
+ - `@multitenantkit/adapter-metrics-http` - HTTP metrics and observability
35
+
36
+ ## 🚀 Installation
37
+
38
+ ### From Local Tarballs
39
+
40
+ When installing from local development, you need to install ALL the tarballs at once:
41
+
42
+ ```bash
43
+ # Generate all tarballs
44
+ npm run pack
45
+
46
+ # Install all packages together
47
+ cd /path/to/your/project
48
+ npm install /path/to/multitenantkit/dist-packages/*.tgz
49
+ ```
50
+
51
+ **Important:** The SDK requires all its peer dependencies to be installed. Installing only the SDK tarball will not work.
52
+
53
+ ### From npm Registry
54
+
55
+ ```bash
56
+ npm install @multitenantkit/sdk
57
+ ```
58
+
59
+ ## 📖 Usage
60
+
61
+ ### Quick Start (Recommended)
62
+
63
+ The fastest way to get started with the most common stack (PostgreSQL + Supabase + Express):
64
+
65
+ ```typescript
66
+ import { createExpressApp } from '@multitenantkit/sdk';
67
+
68
+ // One line to create a fully configured API
69
+ const app = createExpressApp();
70
+
71
+ app.listen(3000);
72
+ ```
73
+
74
+ With custom fields:
75
+
76
+ ```typescript
77
+ import { createExpressApp } from '@multitenantkit/sdk';
78
+ import { z } from 'zod';
79
+
80
+ const app = createExpressApp({
81
+ namingStrategy: 'snake_case',
82
+ users: {
83
+ customFields: {
84
+ customSchema: z.object({
85
+ firstName: z.string(),
86
+ lastName: z.string(),
87
+ email: z.string().email()
88
+ })
89
+ }
90
+ }
91
+ });
92
+
93
+ app.listen(3000);
94
+ ```
95
+
96
+ Integrate into existing Express app:
97
+
98
+ ```typescript
99
+ import express from 'express';
100
+ import { createExpressRouter } from '@multitenantkit/sdk';
101
+
102
+ const app = express();
103
+ app.get('/api/billing', billingHandler);
104
+
105
+ const router = createExpressRouter();
106
+ app.use('/api/teams', router);
107
+
108
+ app.listen(3000);
109
+ ```
110
+
111
+ ### Advanced Usage
112
+
113
+ For more control, use the individual functions:
114
+
115
+ ```typescript
116
+ import {
117
+ compose,
118
+ buildHandlers,
119
+ AdapterAuthSupabase,
120
+ AdapterTransportExpress
121
+ } from '@multitenantkit/sdk';
122
+
123
+ // 1. Compose use cases
124
+ const { useCases } = compose(envOverrides, toolkitOptions);
125
+
126
+ // 2. Build handlers
127
+ const handlers = buildHandlers(useCases, toolkitOptions);
128
+
129
+ // 3. Create auth service
130
+ const authService = AdapterAuthSupabase.createSupabaseAuthService();
131
+
132
+ // 4. Create Express app
133
+ const app = AdapterTransportExpress.buildExpressApp(handlers, authService);
134
+
135
+ app.listen(3000);
136
+ ```
137
+
138
+ ### Direct Access to Components
139
+
140
+ This SDK gives you access to all adapters and options through convenient exports:
141
+
142
+ ```typescript
143
+ // Import domain entities and use cases directly
144
+ import { User, CreateUser, Organization } from '@multitenantkit/sdk';
145
+
146
+ // Import contracts and types directly
147
+ import { ToolkitOptions, UserSchema, OrganizationSchema } from '@multitenantkit/sdk';
148
+
149
+ // Import API schemas
150
+ import { CreateUserRequestSchema, OrganizationResponseSchema } from '@multitenantkit/sdk';
151
+
152
+ // Import handlers
153
+ import { createUserHandler, getOrganizationHandler } from '@multitenantkit/sdk';
154
+
155
+ // Import adapters using namespaces (to avoid conflicts)
156
+ import {
157
+ AdapterPersistenceJson,
158
+ AdapterPersistencePostgres,
159
+ AdapterTransportExpress,
160
+ AdapterAuthSupabase
161
+ } from '@multitenantkit/sdk';
162
+
163
+ // Use JSON adapter for development
164
+ const userRepo = new AdapterPersistenceJson.JsonUserRepository(/* ... */);
165
+
166
+ // Or PostgreSQL for production
167
+ const repos = AdapterPersistencePostgres.createPostgresRepositories(/* ... */);
168
+
169
+ // Express server setup
170
+ const app = AdapterTransportExpress.buildExpressApp(/* ... */);
171
+ ```
172
+
173
+ ### Import Patterns
174
+
175
+ **Direct imports** (domain, contracts, handlers):
176
+
177
+ ```typescript
178
+ import {
179
+ User, // Domain entity
180
+ CreateUser, // Use case
181
+ ToolkitOptions, // Contract type
182
+ UserSchema // Schema
183
+ } from '@multitenantkit/sdk';
184
+ ```
185
+
186
+ **Namespace imports** (adapters):
187
+
188
+ ```typescript
189
+ import { JsonAdapter, PostgresAdapter } from '@multitenantkit/sdk';
190
+
191
+ // Then use:
192
+ const repo = new JsonAdapter.JsonUserRepository(/* ... */);
193
+ ```
194
+
195
+ ## 🎯 When to Use
196
+
197
+ ### ✅ Good for:
198
+
199
+ - **Development**: Experiment with different adapters
200
+ - **Testing**: Have all options available
201
+ - **Evaluation**: Try the SDK before committing
202
+ - **Monorepo apps**: When bundle size isn't critical
203
+ - **Prototyping**: Quick setup with all features
204
+
205
+ ### ⚠️ Consider alternatives for:
206
+
207
+ - **Production deployments**: Use specific bundles or individual packages
208
+ - **Bundle size optimization**: Install only what you need
209
+ - **Microservices**: Use specific packages per service
210
+
211
+ ## 📚 Alternative Packages
212
+
213
+ - **`@multitenantkit/express-starter`**: Production-ready Express setup with PostgreSQL (coming soon)
214
+ - **Individual packages**: Maximum control, smallest bundle size
215
+
216
+ ## 🏗️ Architecture
217
+
218
+ Built with Clean Architecture and Hexagonal Architecture principles:
219
+
220
+ - **Domain-centric**: Business logic is independent
221
+ - **Pluggable adapters**: Swap implementations easily
222
+ - **Schema-first**: Single source of truth for contracts
223
+ - **Type-safe**: Full TypeScript support
224
+
225
+ ## 📖 Documentation
226
+
227
+ - [Main Documentation](https://github.com/multitenantkit/multitenantkit)
228
+ - [Getting Started Guide](https://github.com/multitenantkit/multitenantkit/docs/getting-started.md)
229
+ - [API Reference](https://github.com/multitenantkit/multitenantkit/docs/api-reference.md)
230
+ - [Architecture Guide](https://github.com/multitenantkit/multitenantkit/docs/architecture.md)
231
+
232
+ ## 📄 License
233
+
234
+ MIT
235
+
236
+ ## 🤝 Contributing
237
+
238
+ Contributions welcome! See [CONTRIBUTING.md](https://github.com/multitenantkit/multitenantkit/CONTRIBUTING.md)
@@ -0,0 +1,137 @@
1
+ import type { ToolkitOptions } from '@multitenantkit/domain-contracts';
2
+ import type { Express, Router } from 'express';
3
+ /**
4
+ * Infrastructure adapter options
5
+ * Allows specifying which adapters to use via string presets or custom implementations
6
+ */
7
+ export interface InfrastructureOptions {
8
+ /**
9
+ * Persistence adapter to use
10
+ * - 'postgres': PostgreSQL (default)
11
+ * - 'json': JSON file storage (development only)
12
+ * - Custom: Provide your own adapter factory
13
+ */
14
+ persistence?: 'postgres' | 'json';
15
+ /**
16
+ * Authentication adapter to use
17
+ * - 'supabase': Supabase Auth (default)
18
+ * - Custom: Provide your own auth service factory
19
+ */
20
+ auth?: 'supabase';
21
+ }
22
+ /**
23
+ * Create a complete Express application with MultiTenantKit
24
+ *
25
+ * This convenience function sets up a fully configured Express app with:
26
+ * - PostgreSQL persistence (default) or JSON for development
27
+ * - Supabase authentication (default)
28
+ * - All MultiTenantKit routes and middleware
29
+ *
30
+ * Parameters can be provided in any order for convenience.
31
+ *
32
+ * @template TUserCustomFields - Custom fields schema for Users
33
+ * @template TOrganizationCustomFields - Custom fields schema for Organizations
34
+ * @template TOrganizationMembershipCustomFields - Custom fields schema for Organization Memberships
35
+ *
36
+ * @param param1 - Either ToolkitOptions or InfrastructureOptions
37
+ * @param param2 - Either ToolkitOptions or InfrastructureOptions (whichever wasn't param1)
38
+ * @returns Express application ready to listen on a port
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Minimal setup with defaults (Postgres + Supabase)
43
+ * import { createExpressApp } from '@multitenantkit/sdk';
44
+ *
45
+ * const app = createExpressApp();
46
+ * app.listen(3000);
47
+ * ```
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // With custom fields
52
+ * import { createExpressApp } from '@multitenantkit/sdk';
53
+ * import { z } from 'zod';
54
+ *
55
+ * const app = createExpressApp({
56
+ * namingStrategy: 'snake_case',
57
+ * users: {
58
+ * customFields: {
59
+ * customSchema: z.object({
60
+ * firstName: z.string(),
61
+ * lastName: z.string(),
62
+ * email: z.string().email()
63
+ * })
64
+ * }
65
+ * }
66
+ * });
67
+ *
68
+ * app.listen(3000);
69
+ * ```
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // With custom infrastructure (parameters in any order)
74
+ * const app = createExpressApp(
75
+ * { persistence: 'json', auth: 'supabase' },
76
+ * { namingStrategy: 'snake_case' }
77
+ * );
78
+ *
79
+ * // Or reversed order - same result
80
+ * const app = createExpressApp(
81
+ * { namingStrategy: 'snake_case' },
82
+ * { persistence: 'json' }
83
+ * );
84
+ * ```
85
+ */
86
+ export declare function createExpressApp<TUserCustomFields = {}, TOrganizationCustomFields = {}, TOrganizationMembershipCustomFields = {}>(param1?: ToolkitOptions<TUserCustomFields, TOrganizationCustomFields, TOrganizationMembershipCustomFields> | InfrastructureOptions, param2?: ToolkitOptions<TUserCustomFields, TOrganizationCustomFields, TOrganizationMembershipCustomFields> | InfrastructureOptions): Express;
87
+ /**
88
+ * Create an Express Router with MultiTenantKit routes
89
+ *
90
+ * Use this when you want to integrate MultiTenantKit into an existing Express application.
91
+ * The router can be mounted at any path in your app.
92
+ *
93
+ * Parameters can be provided in any order for convenience.
94
+ *
95
+ * @template TUserCustomFields - Custom fields schema for Users
96
+ * @template TOrganizationCustomFields - Custom fields schema for Organizations
97
+ * @template TOrganizationMembershipCustomFields - Custom fields schema for Organization Memberships
98
+ *
99
+ * @param param1 - Either ToolkitOptions or InfrastructureOptions
100
+ * @param param2 - Either ToolkitOptions or InfrastructureOptions (whichever wasn't param1)
101
+ * @returns Express Router with all MultiTenantKit routes
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Add to existing Express app
106
+ * import express from 'express';
107
+ * import { createExpressRouter } from '@multitenantkit/sdk';
108
+ *
109
+ * const app = express();
110
+ *
111
+ * // Your existing routes
112
+ * app.get('/api/billing', billingHandler);
113
+ *
114
+ * // Add MultiTenantKit routes under /api/teams
115
+ * const teamsRouter = createExpressRouter();
116
+ * app.use('/api/teams', teamsRouter);
117
+ *
118
+ * app.listen(3000);
119
+ * ```
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // With custom configuration (parameters in any order)
124
+ * const router = createExpressRouter(
125
+ * { persistence: 'postgres', auth: 'supabase' },
126
+ * { namingStrategy: 'snake_case' }
127
+ * );
128
+ *
129
+ * // Or reversed
130
+ * const router = createExpressRouter(
131
+ * { namingStrategy: 'snake_case' },
132
+ * { persistence: 'postgres' }
133
+ * );
134
+ * ```
135
+ */
136
+ export declare function createExpressRouter<TUserCustomFields = {}, TOrganizationCustomFields = {}, TOrganizationMembershipCustomFields = {}>(param1?: ToolkitOptions<TUserCustomFields, TOrganizationCustomFields, TOrganizationMembershipCustomFields> | InfrastructureOptions, param2?: ToolkitOptions<TUserCustomFields, TOrganizationCustomFields, TOrganizationMembershipCustomFields> | InfrastructureOptions): Router;
137
+ //# sourceMappingURL=convenience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convenience.d.ts","sourceRoot":"","sources":["../src/convenience.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAElC;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACrB;AA+ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,gBAAgB,CAE5B,iBAAiB,GAAG,EAAE,EAEtB,yBAAyB,GAAG,EAAE,EAE9B,mCAAmC,GAAG,EAAE,EAExC,MAAM,CAAC,EACD,cAAc,CACV,iBAAiB,EACjB,yBAAyB,EACzB,mCAAmC,CACtC,GACD,qBAAqB,EAC3B,MAAM,CAAC,EACD,cAAc,CACV,iBAAiB,EACjB,yBAAyB,EACzB,mCAAmC,CACtC,GACD,qBAAqB,GAC5B,OAAO,CAsDT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,mBAAmB,CAE/B,iBAAiB,GAAG,EAAE,EAEtB,yBAAyB,GAAG,EAAE,EAE9B,mCAAmC,GAAG,EAAE,EAExC,MAAM,CAAC,EACD,cAAc,CACV,iBAAiB,EACjB,yBAAyB,EACzB,mCAAmC,CACtC,GACD,qBAAqB,EAC3B,MAAM,CAAC,EACD,cAAc,CACV,iBAAiB,EACjB,yBAAyB,EACzB,mCAAmC,CACtC,GACD,qBAAqB,GAC5B,MAAM,CAsDR"}
@@ -0,0 +1,209 @@
1
+ // =============================================================================
2
+ // Convenience functions for quick setup
3
+ // =============================================================================
4
+ import { createSupabaseAuthService } from '@multitenantkit/adapter-auth-supabase';
5
+ import { buildExpressApp, buildExpressRouter } from '@multitenantkit/adapter-transport-express';
6
+ import { buildHandlers } from '@multitenantkit/api-handlers';
7
+ import { createJsonAdapters, createMetricsAdapter, createPostgresAdapters, createSystemAdapters, createUseCases } from '@multitenantkit/composition';
8
+ /**
9
+ * Detects which parameter is which based on their properties
10
+ * This allows calling the function with parameters in any order
11
+ */
12
+ function resolveParameters(param1, param2) {
13
+ if (!param1 && !param2) {
14
+ return { toolkitOptions: undefined, infraOptions: undefined };
15
+ }
16
+ // Helper to detect if an object is InfrastructureOptions
17
+ const isInfraOptions = (obj) => {
18
+ return obj && (obj.persistence !== undefined || obj.auth !== undefined);
19
+ };
20
+ // Only one parameter provided
21
+ if (!param2) {
22
+ if (isInfraOptions(param1)) {
23
+ return { infraOptions: param1, toolkitOptions: undefined };
24
+ }
25
+ return {
26
+ toolkitOptions: param1,
27
+ infraOptions: undefined
28
+ };
29
+ }
30
+ // Two parameters provided - detect order
31
+ if (isInfraOptions(param1)) {
32
+ return {
33
+ infraOptions: param1,
34
+ toolkitOptions: param2
35
+ };
36
+ }
37
+ else {
38
+ return {
39
+ toolkitOptions: param1,
40
+ infraOptions: isInfraOptions(param2) ? param2 : undefined
41
+ };
42
+ }
43
+ }
44
+ /**
45
+ * Create a complete Express application with MultiTenantKit
46
+ *
47
+ * This convenience function sets up a fully configured Express app with:
48
+ * - PostgreSQL persistence (default) or JSON for development
49
+ * - Supabase authentication (default)
50
+ * - All MultiTenantKit routes and middleware
51
+ *
52
+ * Parameters can be provided in any order for convenience.
53
+ *
54
+ * @template TUserCustomFields - Custom fields schema for Users
55
+ * @template TOrganizationCustomFields - Custom fields schema for Organizations
56
+ * @template TOrganizationMembershipCustomFields - Custom fields schema for Organization Memberships
57
+ *
58
+ * @param param1 - Either ToolkitOptions or InfrastructureOptions
59
+ * @param param2 - Either ToolkitOptions or InfrastructureOptions (whichever wasn't param1)
60
+ * @returns Express application ready to listen on a port
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // Minimal setup with defaults (Postgres + Supabase)
65
+ * import { createExpressApp } from '@multitenantkit/sdk';
66
+ *
67
+ * const app = createExpressApp();
68
+ * app.listen(3000);
69
+ * ```
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // With custom fields
74
+ * import { createExpressApp } from '@multitenantkit/sdk';
75
+ * import { z } from 'zod';
76
+ *
77
+ * const app = createExpressApp({
78
+ * namingStrategy: 'snake_case',
79
+ * users: {
80
+ * customFields: {
81
+ * customSchema: z.object({
82
+ * firstName: z.string(),
83
+ * lastName: z.string(),
84
+ * email: z.string().email()
85
+ * })
86
+ * }
87
+ * }
88
+ * });
89
+ *
90
+ * app.listen(3000);
91
+ * ```
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // With custom infrastructure (parameters in any order)
96
+ * const app = createExpressApp(
97
+ * { persistence: 'json', auth: 'supabase' },
98
+ * { namingStrategy: 'snake_case' }
99
+ * );
100
+ *
101
+ * // Or reversed order - same result
102
+ * const app = createExpressApp(
103
+ * { namingStrategy: 'snake_case' },
104
+ * { persistence: 'json' }
105
+ * );
106
+ * ```
107
+ */
108
+ export function createExpressApp(param1, param2) {
109
+ const { toolkitOptions, infraOptions } = resolveParameters(param1, param2);
110
+ // Apply defaults for infrastructure
111
+ const persistenceType = infraOptions?.persistence ?? 'postgres';
112
+ const authType = infraOptions?.auth ?? 'supabase';
113
+ // 1. Create persistence adapters based on selected type
114
+ const persistenceAdapters = persistenceType === 'json'
115
+ ? createJsonAdapters(process.env.JSON_DATA_DIR ?? './data')
116
+ : createPostgresAdapters(undefined, toolkitOptions);
117
+ // 2. Create system and metrics adapters
118
+ const systemAdapters = createSystemAdapters();
119
+ const metricsAdapter = createMetricsAdapter();
120
+ // 3. Create use cases with all adapters
121
+ const useCases = createUseCases({
122
+ persistence: persistenceAdapters,
123
+ system: systemAdapters,
124
+ observability: metricsAdapter
125
+ }, toolkitOptions);
126
+ // 4. Build HTTP handlers
127
+ const handlers = buildHandlers(useCases, toolkitOptions);
128
+ // 5. Create auth service based on selection
129
+ const authService = authType === 'supabase' ? createSupabaseAuthService() : createSupabaseAuthService();
130
+ // 6. Build Express app with all middleware and routes
131
+ const app = buildExpressApp(handlers, authService);
132
+ return app;
133
+ }
134
+ /**
135
+ * Create an Express Router with MultiTenantKit routes
136
+ *
137
+ * Use this when you want to integrate MultiTenantKit into an existing Express application.
138
+ * The router can be mounted at any path in your app.
139
+ *
140
+ * Parameters can be provided in any order for convenience.
141
+ *
142
+ * @template TUserCustomFields - Custom fields schema for Users
143
+ * @template TOrganizationCustomFields - Custom fields schema for Organizations
144
+ * @template TOrganizationMembershipCustomFields - Custom fields schema for Organization Memberships
145
+ *
146
+ * @param param1 - Either ToolkitOptions or InfrastructureOptions
147
+ * @param param2 - Either ToolkitOptions or InfrastructureOptions (whichever wasn't param1)
148
+ * @returns Express Router with all MultiTenantKit routes
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Add to existing Express app
153
+ * import express from 'express';
154
+ * import { createExpressRouter } from '@multitenantkit/sdk';
155
+ *
156
+ * const app = express();
157
+ *
158
+ * // Your existing routes
159
+ * app.get('/api/billing', billingHandler);
160
+ *
161
+ * // Add MultiTenantKit routes under /api/teams
162
+ * const teamsRouter = createExpressRouter();
163
+ * app.use('/api/teams', teamsRouter);
164
+ *
165
+ * app.listen(3000);
166
+ * ```
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // With custom configuration (parameters in any order)
171
+ * const router = createExpressRouter(
172
+ * { persistence: 'postgres', auth: 'supabase' },
173
+ * { namingStrategy: 'snake_case' }
174
+ * );
175
+ *
176
+ * // Or reversed
177
+ * const router = createExpressRouter(
178
+ * { namingStrategy: 'snake_case' },
179
+ * { persistence: 'postgres' }
180
+ * );
181
+ * ```
182
+ */
183
+ export function createExpressRouter(param1, param2) {
184
+ const { toolkitOptions, infraOptions } = resolveParameters(param1, param2);
185
+ // Apply defaults for infrastructure
186
+ const persistenceType = infraOptions?.persistence ?? 'postgres';
187
+ const authType = infraOptions?.auth ?? 'supabase';
188
+ // 1. Create persistence adapters based on selected type
189
+ const persistenceAdapters = persistenceType === 'json'
190
+ ? createJsonAdapters(process.env.JSON_DATA_DIR ?? './data')
191
+ : createPostgresAdapters(undefined, toolkitOptions);
192
+ // 2. Create system and metrics adapters
193
+ const systemAdapters = createSystemAdapters();
194
+ const metricsAdapter = createMetricsAdapter();
195
+ // 3. Create use cases with all adapters
196
+ const useCases = createUseCases({
197
+ persistence: persistenceAdapters,
198
+ system: systemAdapters,
199
+ observability: metricsAdapter
200
+ }, toolkitOptions);
201
+ // 4. Build HTTP handlers
202
+ const handlers = buildHandlers(useCases, toolkitOptions);
203
+ // 5. Create auth service based on selection
204
+ const authService = authType === 'supabase' ? createSupabaseAuthService() : createSupabaseAuthService();
205
+ // 6. Build Express router with routes only (no global middleware)
206
+ const router = buildExpressRouter(handlers, authService);
207
+ return router;
208
+ }
209
+ //# sourceMappingURL=convenience.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convenience.js","sourceRoot":"","sources":["../src/convenience.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wCAAwC;AACxC,gFAAgF;AAEhF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACjB,MAAM,6BAA6B,CAAC;AAyBrC;;;GAGG;AACH,SAAS,iBAAiB,CAKtB,MAM2B,EAC3B,MAM2B;IAS3B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IAClE,CAAC;IAED,yDAAyD;IACzD,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAgC,EAA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xC,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAC9C,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAE9C,wCAAwC;IACxC,MAAM,QAAQ,GAAG,cAAc,CAK3B;QACI,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,cAAc;QACtB,aAAa,EAAE,cAAc;KAChC,EACD,cAAc,CACjB,CAAC;IAEF,yBAAyB;IACzB,MAAM,QAAQ,GAAG,aAAa,CAI5B,QAAQ,EAAE,cAAc,CAAC,CAAC;IAE5B,4CAA4C;IAC5C,MAAM,WAAW,GACb,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC,yBAAyB,EAAE,CAAC;IAExF,kEAAkE;IAClE,MAAM,MAAM,GAAG,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * as AdapterAuthSupabase from '@multitenantkit/adapter-auth-supabase';
2
+ export * as AdapterPersistenceJson from '@multitenantkit/adapter-persistence-json';
3
+ export * as AdapterPersistencePostgres from '@multitenantkit/adapter-persistence-postgres';
4
+ export * as AdapterSystemCryptoUuid from '@multitenantkit/adapter-system-crypto-uuid';
5
+ export * as AdapterSystemSystemClock from '@multitenantkit/adapter-system-system-clock';
6
+ export * as AdapterTransportExpress from '@multitenantkit/adapter-transport-express';
7
+ export * from '@multitenantkit/api-contracts';
8
+ export * from '@multitenantkit/api-handlers';
9
+ export * from '@multitenantkit/composition';
10
+ export * from '@multitenantkit/domain';
11
+ export * from '@multitenantkit/domain-contracts';
12
+ export * from './convenience';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,mBAAmB,MAAM,uCAAuC,CAAC;AAE7E,OAAO,KAAK,sBAAsB,MAAM,0CAA0C,CAAC;AACnF,OAAO,KAAK,0BAA0B,MAAM,8CAA8C,CAAC;AAE3F,OAAO,KAAK,uBAAuB,MAAM,4CAA4C,CAAC;AACtF,OAAO,KAAK,wBAAwB,MAAM,6CAA6C,CAAC;AAExF,OAAO,KAAK,uBAAuB,MAAM,2CAA2C,CAAC;AACrF,cAAc,+BAA+B,CAAC;AAE9C,cAAc,8BAA8B,CAAC;AAE7C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,wBAAwB,CAAC;AAEvC,cAAc,kCAAkC,CAAC;AAEjD,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ // =============================================================================
2
+ // multitenantkit/sdk
3
+ // Complete SDK bundle - re-exports all packages for easy consumption
4
+ // =============================================================================
5
+ // Authentication Adapters - Export as namespace
6
+ export * as AdapterAuthSupabase from '@multitenantkit/adapter-auth-supabase';
7
+ // Persistence Adapters - Export as namespace to avoid mapper name conflicts
8
+ export * as AdapterPersistenceJson from '@multitenantkit/adapter-persistence-json';
9
+ export * as AdapterPersistencePostgres from '@multitenantkit/adapter-persistence-postgres';
10
+ // System Adapters - Export as namespace
11
+ export * as AdapterSystemCryptoUuid from '@multitenantkit/adapter-system-crypto-uuid';
12
+ export * as AdapterSystemSystemClock from '@multitenantkit/adapter-system-system-clock';
13
+ // Transport Adapters - Export as namespace
14
+ export * as AdapterTransportExpress from '@multitenantkit/adapter-transport-express';
15
+ export * from '@multitenantkit/api-contracts';
16
+ // API Handlers - Direct exports
17
+ export * from '@multitenantkit/api-handlers';
18
+ // Composition - Direct exports
19
+ export * from '@multitenantkit/composition';
20
+ // Core Domain - Direct exports (entities, use cases, implementations)
21
+ export * from '@multitenantkit/domain';
22
+ // Contracts - Direct exports (schemas and types)
23
+ export * from '@multitenantkit/domain-contracts';
24
+ // Convenience functions for quick setup
25
+ export * from './convenience';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,qBAAqB;AACrB,qEAAqE;AACrE,gFAAgF;AAEhF,gDAAgD;AAChD,OAAO,KAAK,mBAAmB,MAAM,uCAAuC,CAAC;AAC7E,4EAA4E;AAC5E,OAAO,KAAK,sBAAsB,MAAM,0CAA0C,CAAC;AACnF,OAAO,KAAK,0BAA0B,MAAM,8CAA8C,CAAC;AAC3F,wCAAwC;AACxC,OAAO,KAAK,uBAAuB,MAAM,4CAA4C,CAAC;AACtF,OAAO,KAAK,wBAAwB,MAAM,6CAA6C,CAAC;AACxF,2CAA2C;AAC3C,OAAO,KAAK,uBAAuB,MAAM,2CAA2C,CAAC;AACrF,cAAc,+BAA+B,CAAC;AAC9C,gCAAgC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,+BAA+B;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,sEAAsE;AACtE,cAAc,wBAAwB,CAAC;AACvC,iDAAiD;AACjD,cAAc,kCAAkC,CAAC;AACjD,wCAAwC;AACxC,cAAc,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@multitenantkit/sdk",
3
+ "version": "0.1.1",
4
+ "description": "Complete SDK for building multi-tenant SaaS applications - includes all adapters and options",
5
+ "keywords": [
6
+ "multitenantkit",
7
+ "sdk",
8
+ "saas",
9
+ "saas-toolkit",
10
+ "multi-tenant",
11
+ "multitenancy",
12
+ "b2b",
13
+ "organization-management",
14
+ "team-management",
15
+ "user-management",
16
+ "organizations",
17
+ "teams",
18
+ "users",
19
+ "rbac",
20
+ "backend",
21
+ "typescript",
22
+ "complete",
23
+ "all-inclusive"
24
+ ],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/multitenantkit/multitenantkit.git",
30
+ "directory": "packages/bundles/sdk"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/multitenantkit/multitenantkit/issues"
34
+ },
35
+ "homepage": "https://github.com/multitenantkit/multitenantkit#readme",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "main": "./dist/index.js",
40
+ "types": "./dist/index.d.ts",
41
+ "type": "module",
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "scripts": {
47
+ "build": "tsc --build",
48
+ "clean": "rm -rf dist",
49
+ "type-check": "tsc --noEmit"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "types": "./dist/index.d.ts",
54
+ "import": "./dist/index.js"
55
+ }
56
+ },
57
+ "peerDependencies": {
58
+ "@multitenantkit/adapter-auth-supabase": "^0.1.1",
59
+ "@multitenantkit/adapter-persistence-json": "^0.1.1",
60
+ "@multitenantkit/adapter-persistence-postgres": "^0.1.1",
61
+ "@multitenantkit/adapter-system-crypto-uuid": "^0.1.1",
62
+ "@multitenantkit/adapter-system-system-clock": "^0.1.1",
63
+ "@multitenantkit/adapter-transport-express": "^0.1.1",
64
+ "@multitenantkit/api-handlers": "^0.1.1",
65
+ "@multitenantkit/api-contracts": "^0.1.1",
66
+ "@multitenantkit/domain-contracts": "^0.1.1",
67
+ "@multitenantkit/domain": "^0.1.1",
68
+ "@multitenantkit/composition": "^0.1.1"
69
+ },
70
+ "devDependencies": {
71
+ "typescript": "^5.0.0"
72
+ }
73
+ }