spaps-types 1.0.0

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,112 @@
1
+ # spaps-types
2
+
3
+ Shared TypeScript type definitions for the Sweet Potato Authentication & Payment Service (SPAPS) ecosystem.
4
+
5
+ ## Overview
6
+
7
+ This package provides a single source of truth for all TypeScript types used across the SPAPS server and SDK. It ensures type consistency and prevents drift between different parts of the system.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install spaps-types
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import type {
19
+ User,
20
+ UserProfile,
21
+ ApiResponse,
22
+ TokenPair,
23
+ CheckoutSession,
24
+ Product,
25
+ Price
26
+ } from 'spaps-types';
27
+
28
+ // Use the types in your code
29
+ const user: User = {
30
+ id: '123',
31
+ email: 'user@example.com',
32
+ role: 'user'
33
+ };
34
+
35
+ const response: ApiResponse<User> = {
36
+ success: true,
37
+ data: user
38
+ };
39
+ ```
40
+
41
+ ## Available Types
42
+
43
+ ### Core Domain Models
44
+ - `Application` - Client application configuration
45
+ - `User` - Basic user information
46
+ - `UserProfile` - Extended user profile
47
+ - `UserWallet` - Multi-wallet associations
48
+
49
+ ### Authentication & Session
50
+ - `TokenPayload` - JWT token payload
51
+ - `RefreshTokenPayload` - Refresh token payload
52
+ - `TokenPair` - Access/refresh token pair
53
+ - `AuthResponse` - Authentication response
54
+ - `SessionData` - Session information
55
+
56
+ ### Payments & Subscriptions
57
+ - `Product` - Stripe product
58
+ - `Price` - Stripe price
59
+ - `CheckoutSession` - Stripe checkout session
60
+ - `Subscription` - Active subscription
61
+ - `UsageBalance` - Usage-based balance
62
+
63
+ ### API Types
64
+ - `ApiResponse<T>` - Standard API response wrapper
65
+ - `ApiKeyValidationResult` - API key validation result
66
+ - `TokenValidationResult` - Token validation result
67
+
68
+ ### Admin Types
69
+ - `AdminUser` - Admin user information
70
+ - `AdminAction` - Audit log entry
71
+ - `SecurityAlert` - Security alert
72
+ - `AdminRole` - Admin role types
73
+ - `AdminPermission` - Permission types
74
+
75
+ ### Request/Response DTOs
76
+ - `CreateProductRequest` - Create product payload
77
+ - `UpdateProductRequest` - Update product payload
78
+ - `CreatePriceRequest` - Create price payload
79
+ - `ProductSyncResult` - Product sync result
80
+
81
+ ## Type Guards
82
+
83
+ The package includes runtime type guards for validation:
84
+
85
+ ```typescript
86
+ import { isAdminRole, isValidPermission } from 'spaps-types';
87
+
88
+ if (isAdminRole(user.role)) {
89
+ // User is an admin
90
+ }
91
+
92
+ if (isValidPermission(permission)) {
93
+ // Permission is valid
94
+ }
95
+ ```
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ # Build the types
101
+ npm run build
102
+
103
+ # Run type tests
104
+ npm run test:types
105
+
106
+ # Type check
107
+ npm run typecheck
108
+ ```
109
+
110
+ ## License
111
+
112
+ MIT
@@ -0,0 +1,305 @@
1
+ /**
2
+ * @spaps/types - Shared TypeScript types for SPAPS ecosystem
3
+ * Single source of truth for types across server and SDK
4
+ */
5
+ export interface Application {
6
+ id: string;
7
+ name: string;
8
+ slug: string;
9
+ api_key: string;
10
+ webhook_url?: string;
11
+ settings: {
12
+ supported_chains: string[];
13
+ rate_limit?: {
14
+ window_ms: number;
15
+ max_requests: number;
16
+ };
17
+ };
18
+ created_at: string;
19
+ }
20
+ export interface UserProfile {
21
+ id: string;
22
+ stripe_customer_id?: string;
23
+ default_payment_method?: string;
24
+ username?: string;
25
+ email?: string;
26
+ phone_number?: string;
27
+ tier?: string;
28
+ metadata: Record<string, any>;
29
+ created_at: string;
30
+ }
31
+ export interface User {
32
+ id: string;
33
+ email?: string;
34
+ wallet_address?: string;
35
+ chain_type?: string;
36
+ role: string;
37
+ tier?: string;
38
+ created_at?: string;
39
+ }
40
+ export interface UserWallet {
41
+ id: string;
42
+ user_id: string;
43
+ wallet_address: string;
44
+ chain_type: 'solana' | 'ethereum' | 'bitcoin' | 'base';
45
+ verified: boolean;
46
+ metadata?: Record<string, any>;
47
+ created_at: string;
48
+ updated_at: string;
49
+ }
50
+ export interface ApiResponse<T = any> {
51
+ success: boolean;
52
+ data?: T;
53
+ error?: {
54
+ code: string;
55
+ message: string;
56
+ details?: any;
57
+ };
58
+ metadata?: {
59
+ timestamp: string;
60
+ request_id: string;
61
+ };
62
+ }
63
+ export interface TokenPayload {
64
+ sub: string;
65
+ app_id: string;
66
+ wallets: string[];
67
+ tier: string;
68
+ iat: number;
69
+ exp: number;
70
+ jti: string;
71
+ iss: string;
72
+ aud: string;
73
+ email?: string;
74
+ roles?: string[];
75
+ permissions?: string[];
76
+ isAdmin?: boolean;
77
+ isSuperAdmin?: boolean;
78
+ }
79
+ export interface RefreshTokenPayload {
80
+ sub: string;
81
+ app_id: string;
82
+ token_family: string;
83
+ iat: number;
84
+ exp: number;
85
+ jti: string;
86
+ iss: string;
87
+ aud: string;
88
+ email?: string;
89
+ roles?: string[];
90
+ isAdmin?: boolean;
91
+ }
92
+ export interface TokenPair {
93
+ access_token: string;
94
+ refresh_token: string;
95
+ expires_in: number;
96
+ token_type: 'Bearer';
97
+ }
98
+ export interface AuthResponse {
99
+ access_token: string;
100
+ refresh_token: string;
101
+ user: User;
102
+ expires_in?: number;
103
+ token_type?: 'Bearer';
104
+ }
105
+ export interface CheckoutSession {
106
+ sessionId: string;
107
+ url: string;
108
+ success_url?: string;
109
+ cancel_url?: string;
110
+ customer_email?: string;
111
+ metadata?: Record<string, any>;
112
+ }
113
+ export interface Subscription {
114
+ id: string;
115
+ status: string;
116
+ plan: string;
117
+ current_period_end: string;
118
+ customer_id?: string;
119
+ price_id?: string;
120
+ quantity?: number;
121
+ metadata?: Record<string, any>;
122
+ }
123
+ export interface Product {
124
+ id: string;
125
+ name: string;
126
+ description?: string;
127
+ category: string;
128
+ active: boolean;
129
+ images?: string[];
130
+ metadata?: Record<string, string>;
131
+ statement_descriptor?: string;
132
+ unit_label?: string;
133
+ created?: number;
134
+ updated?: number;
135
+ }
136
+ export interface Price {
137
+ id: string;
138
+ product: string;
139
+ unit_amount: number;
140
+ currency: string;
141
+ recurring?: {
142
+ interval: 'day' | 'week' | 'month' | 'year';
143
+ interval_count: number;
144
+ };
145
+ nickname?: string;
146
+ active: boolean;
147
+ metadata?: Record<string, any>;
148
+ }
149
+ export interface UsageBalance {
150
+ balance: number;
151
+ currency: string;
152
+ updated_at: string;
153
+ user_id?: string;
154
+ }
155
+ export interface CreateProductRequest {
156
+ name: string;
157
+ description?: string;
158
+ category: string;
159
+ images?: string[];
160
+ metadata?: Record<string, string>;
161
+ active?: boolean;
162
+ statement_descriptor?: string;
163
+ unit_label?: string;
164
+ }
165
+ export interface UpdateProductRequest {
166
+ name?: string;
167
+ description?: string;
168
+ category?: string;
169
+ images?: string[];
170
+ metadata?: Record<string, string>;
171
+ active?: boolean;
172
+ statement_descriptor?: string;
173
+ unit_label?: string;
174
+ }
175
+ export interface CreatePriceRequest {
176
+ product_id: string;
177
+ unit_amount: number;
178
+ currency: string;
179
+ interval?: 'day' | 'week' | 'month' | 'year';
180
+ interval_count?: number;
181
+ nickname?: string;
182
+ metadata?: Record<string, any>;
183
+ }
184
+ export interface ProductSyncResult {
185
+ synced_count: number;
186
+ updated_count: number;
187
+ created_count: number;
188
+ errors: any[];
189
+ sync_time: string;
190
+ }
191
+ export interface AdminUser {
192
+ id: string;
193
+ email?: string;
194
+ wallet_address?: string;
195
+ roles?: string[];
196
+ permissions?: string[];
197
+ isAdmin?: boolean;
198
+ isSuperAdmin?: boolean;
199
+ created_at?: string;
200
+ updated_at?: string;
201
+ }
202
+ export interface AdminAction {
203
+ adminUserId: string;
204
+ adminEmail: string;
205
+ action: string;
206
+ resourceType: string;
207
+ resourceId: string;
208
+ resourceData?: Record<string, any>;
209
+ ipAddress?: string;
210
+ userAgent?: string;
211
+ applicationId?: string;
212
+ severity?: AuditSeverity;
213
+ timestamp?: string;
214
+ }
215
+ export interface SecurityAlert {
216
+ id?: string;
217
+ alert_type: string;
218
+ user_id: string;
219
+ elevated_by?: string;
220
+ severity: AlertSeverity;
221
+ details: Record<string, any>;
222
+ timestamp: string;
223
+ resolved?: boolean;
224
+ created_at?: string;
225
+ }
226
+ export interface SessionData {
227
+ user_id: string;
228
+ application_id: string;
229
+ wallets: UserWallet[];
230
+ tier: string;
231
+ created_at: Date;
232
+ last_activity: Date;
233
+ user_agent?: string;
234
+ ip_address?: string;
235
+ email?: string;
236
+ user_profile?: UserProfile;
237
+ }
238
+ export interface BlacklistedToken {
239
+ jti: string;
240
+ user_id: string;
241
+ expires_at: Date;
242
+ blacklisted_at: Date;
243
+ reason: 'logout' | 'refresh' | 'security' | 'admin';
244
+ }
245
+ export interface TokenValidationResult {
246
+ valid: boolean;
247
+ payload?: TokenPayload;
248
+ error?: string;
249
+ expired?: boolean;
250
+ }
251
+ export interface RefreshTokenValidationResult {
252
+ valid: boolean;
253
+ payload?: RefreshTokenPayload;
254
+ error?: string;
255
+ expired?: boolean;
256
+ }
257
+ export interface ApiKeyValidationResult {
258
+ valid: boolean;
259
+ application?: Application;
260
+ error?: string;
261
+ }
262
+ export type AdminRole = 'admin' | 'super_admin' | 'security_admin' | 'billing_admin';
263
+ export type UserRole = 'user' | AdminRole;
264
+ export type AdminPermission = 'view_products' | 'create_orders' | 'access_premium_features' | 'manage_products' | 'access_admin' | 'view_analytics' | 'manage_subscriptions' | 'access_audit_logs' | 'manage_users' | 'system_settings';
265
+ export type AuditSeverity = 'INFO' | 'WARN' | 'HIGH' | 'ERROR' | 'CRITICAL';
266
+ export type AlertSeverity = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
267
+ export type ChainType = 'solana' | 'ethereum' | 'bitcoin' | 'base';
268
+ export type PaymentInterval = 'day' | 'week' | 'month' | 'year';
269
+ export interface RateLimitConfig {
270
+ window_ms: number;
271
+ max_requests: number;
272
+ skip_failed_requests?: boolean;
273
+ skip_successful_requests?: boolean;
274
+ }
275
+ export interface LocalModeConfig {
276
+ environment: string;
277
+ isDocker: boolean;
278
+ defaultUser: 'user' | 'admin' | 'premium';
279
+ features: {
280
+ autoAuth: boolean;
281
+ corsEnabled: boolean;
282
+ verboseLogging: boolean;
283
+ };
284
+ }
285
+ export interface TestUser {
286
+ id: string;
287
+ email: string;
288
+ role: string;
289
+ tier: string;
290
+ created_at: string;
291
+ }
292
+ export declare function isAdminRole(role: string): role is AdminRole;
293
+ export declare function isValidPermission(permission: string): permission is AdminPermission;
294
+ export declare function isValidSeverity(severity: string): severity is AuditSeverity;
295
+ export declare function isValidAlertSeverity(severity: string): severity is AlertSeverity;
296
+ export declare function isValidChainType(chain: string): chain is ChainType;
297
+ export type JWTPayload = TokenPayload;
298
+ export type DecodedToken = {
299
+ payload: TokenPayload;
300
+ header: {
301
+ alg: string;
302
+ typ: string;
303
+ };
304
+ };
305
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE;QACR,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC3B,UAAU,CAAC,EAAE;YACX,SAAS,EAAE,MAAM,CAAC;YAClB,YAAY,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,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WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAE3D;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,IAAI,eAAe,CAMnF;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,aAAa,CAE3E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,aAAa,CAEhF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAElE;AAGD,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC;AACtC,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * @spaps/types - Shared TypeScript types for SPAPS ecosystem
4
+ * Single source of truth for types across server and SDK
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isAdminRole = isAdminRole;
8
+ exports.isValidPermission = isValidPermission;
9
+ exports.isValidSeverity = isValidSeverity;
10
+ exports.isValidAlertSeverity = isValidAlertSeverity;
11
+ exports.isValidChainType = isValidChainType;
12
+ // Type guards for runtime type checking
13
+ function isAdminRole(role) {
14
+ return ['admin', 'super_admin', 'security_admin', 'billing_admin'].includes(role);
15
+ }
16
+ function isValidPermission(permission) {
17
+ return [
18
+ 'view_products', 'create_orders', 'access_premium_features',
19
+ 'manage_products', 'access_admin', 'view_analytics',
20
+ 'manage_subscriptions', 'access_audit_logs', 'manage_users', 'system_settings'
21
+ ].includes(permission);
22
+ }
23
+ function isValidSeverity(severity) {
24
+ return ['INFO', 'WARN', 'HIGH', 'ERROR', 'CRITICAL'].includes(severity);
25
+ }
26
+ function isValidAlertSeverity(severity) {
27
+ return ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL'].includes(severity);
28
+ }
29
+ function isValidChainType(chain) {
30
+ return ['solana', 'ethereum', 'bitcoin', 'base'].includes(chain);
31
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Server-specific types that extend the shared types
3
+ * These are used only by the server and not exposed to SDK
4
+ */
5
+ import type { Request } from 'express';
6
+ import { Application, UserProfile, TokenPayload, AdminUser, AdminPermission, UserRole, LocalModeConfig, TestUser } from './index';
7
+ export interface ApiKeyAuthRequest extends Request {
8
+ application?: Application;
9
+ api_key?: string;
10
+ isLocalMode?: boolean;
11
+ localModeConfig?: LocalModeConfig;
12
+ testUser?: TestUser;
13
+ user?: UserProfile | TestUser;
14
+ }
15
+ export interface AuthenticatedRequest extends ApiKeyAuthRequest {
16
+ user?: UserProfile;
17
+ jwt_payload?: TokenPayload;
18
+ }
19
+ export interface UserSessionRequest extends AuthenticatedRequest {
20
+ userId?: string;
21
+ applicationId?: string;
22
+ }
23
+ export interface EnhancedAuthenticatedRequest extends AuthenticatedRequest {
24
+ adminUser?: AdminUser;
25
+ userPermissions?: AdminPermission[];
26
+ userRoles?: UserRole[];
27
+ isAdminRequest?: boolean;
28
+ }
29
+ export * from './index';
30
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,eAAe,EACf,QAAQ,EACR,eAAe,EACf,QAAQ,EACT,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IAChD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,4BAA6B,SAAQ,oBAAoB;IACxE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,EAAE,CAAC;IACpC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAGD,cAAc,SAAS,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Server-specific types that extend the shared types
4
+ * These are used only by the server and not exposed to SDK
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ // Re-export everything from index for convenience
22
+ __exportStar(require("./index"), exports);
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "spaps-types",
3
+ "version": "1.0.0",
4
+ "description": "Shared TypeScript types for SPAPS ecosystem",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "src"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "clean": "rm -rf dist",
14
+ "prepublishOnly": "npm run clean && npm run build",
15
+ "test:types": "tsd",
16
+ "typecheck": "tsc --noEmit"
17
+ },
18
+ "keywords": [
19
+ "spaps",
20
+ "types",
21
+ "typescript",
22
+ "shared"
23
+ ],
24
+ "author": "",
25
+ "license": "MIT",
26
+ "devDependencies": {
27
+ "@types/node": "^20.0.0",
28
+ "@types/express": "^4.17.21",
29
+ "tsd": "^0.30.0",
30
+ "typescript": "^5.3.0"
31
+ },
32
+ "tsd": {
33
+ "directory": "test"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ }
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,380 @@
1
+ /**
2
+ * @spaps/types - Shared TypeScript types for SPAPS ecosystem
3
+ * Single source of truth for types across server and SDK
4
+ */
5
+
6
+ // Core domain models
7
+ export interface Application {
8
+ id: string;
9
+ name: string;
10
+ slug: string;
11
+ api_key: string;
12
+ webhook_url?: string;
13
+ settings: {
14
+ supported_chains: string[];
15
+ rate_limit?: {
16
+ window_ms: number;
17
+ max_requests: number;
18
+ };
19
+ };
20
+ created_at: string;
21
+ }
22
+
23
+ export interface UserProfile {
24
+ id: string;
25
+ stripe_customer_id?: string;
26
+ default_payment_method?: string;
27
+ username?: string;
28
+ email?: string;
29
+ phone_number?: string;
30
+ tier?: string;
31
+ metadata: Record<string, any>;
32
+ created_at: string;
33
+ }
34
+
35
+ export interface User {
36
+ id: string;
37
+ email?: string;
38
+ wallet_address?: string;
39
+ chain_type?: string;
40
+ role: string;
41
+ tier?: string;
42
+ created_at?: string;
43
+ }
44
+
45
+ export interface UserWallet {
46
+ id: string;
47
+ user_id: string;
48
+ wallet_address: string;
49
+ chain_type: 'solana' | 'ethereum' | 'bitcoin' | 'base';
50
+ verified: boolean;
51
+ metadata?: Record<string, any>;
52
+ created_at: string;
53
+ updated_at: string;
54
+ }
55
+
56
+ // API Response wrapper
57
+ export interface ApiResponse<T = any> {
58
+ success: boolean;
59
+ data?: T;
60
+ error?: {
61
+ code: string;
62
+ message: string;
63
+ details?: any;
64
+ };
65
+ metadata?: {
66
+ timestamp: string;
67
+ request_id: string;
68
+ };
69
+ }
70
+
71
+ // JWT and Session types
72
+ export interface TokenPayload {
73
+ sub: string; // user ID
74
+ app_id: string; // application ID
75
+ wallets: string[]; // array of wallet addresses
76
+ tier: string; // user tier
77
+ iat: number; // issued at
78
+ exp: number; // expires at
79
+ jti: string; // JWT ID for blacklisting
80
+ iss: string; // issuer
81
+ aud: string; // audience
82
+ // Admin claims
83
+ email?: string;
84
+ roles?: string[];
85
+ permissions?: string[];
86
+ isAdmin?: boolean;
87
+ isSuperAdmin?: boolean;
88
+ }
89
+
90
+ export interface RefreshTokenPayload {
91
+ sub: string;
92
+ app_id: string;
93
+ token_family: string;
94
+ iat: number;
95
+ exp: number;
96
+ jti: string;
97
+ iss: string;
98
+ aud: string;
99
+ email?: string;
100
+ roles?: string[];
101
+ isAdmin?: boolean;
102
+ }
103
+
104
+ export interface TokenPair {
105
+ access_token: string;
106
+ refresh_token: string;
107
+ expires_in: number;
108
+ token_type: 'Bearer';
109
+ }
110
+
111
+ export interface AuthResponse {
112
+ access_token: string;
113
+ refresh_token: string;
114
+ user: User;
115
+ expires_in?: number;
116
+ token_type?: 'Bearer';
117
+ }
118
+
119
+ // Stripe/Payment types
120
+ export interface CheckoutSession {
121
+ sessionId: string;
122
+ url: string;
123
+ success_url?: string;
124
+ cancel_url?: string;
125
+ customer_email?: string;
126
+ metadata?: Record<string, any>;
127
+ }
128
+
129
+ export interface Subscription {
130
+ id: string;
131
+ status: string;
132
+ plan: string;
133
+ current_period_end: string;
134
+ customer_id?: string;
135
+ price_id?: string;
136
+ quantity?: number;
137
+ metadata?: Record<string, any>;
138
+ }
139
+
140
+ export interface Product {
141
+ id: string;
142
+ name: string;
143
+ description?: string;
144
+ category: string;
145
+ active: boolean;
146
+ images?: string[];
147
+ metadata?: Record<string, string>;
148
+ statement_descriptor?: string;
149
+ unit_label?: string;
150
+ created?: number;
151
+ updated?: number;
152
+ }
153
+
154
+ export interface Price {
155
+ id: string;
156
+ product: string;
157
+ unit_amount: number;
158
+ currency: string;
159
+ recurring?: {
160
+ interval: 'day' | 'week' | 'month' | 'year';
161
+ interval_count: number;
162
+ };
163
+ nickname?: string;
164
+ active: boolean;
165
+ metadata?: Record<string, any>;
166
+ }
167
+
168
+ export interface UsageBalance {
169
+ balance: number;
170
+ currency: string;
171
+ updated_at: string;
172
+ user_id?: string;
173
+ }
174
+
175
+ // Request/Response DTOs
176
+ export interface CreateProductRequest {
177
+ name: string;
178
+ description?: string;
179
+ category: string;
180
+ images?: string[];
181
+ metadata?: Record<string, string>;
182
+ active?: boolean;
183
+ statement_descriptor?: string;
184
+ unit_label?: string;
185
+ }
186
+
187
+ export interface UpdateProductRequest {
188
+ name?: string;
189
+ description?: string;
190
+ category?: string;
191
+ images?: string[];
192
+ metadata?: Record<string, string>;
193
+ active?: boolean;
194
+ statement_descriptor?: string;
195
+ unit_label?: string;
196
+ }
197
+
198
+ export interface CreatePriceRequest {
199
+ product_id: string;
200
+ unit_amount: number;
201
+ currency: string;
202
+ interval?: 'day' | 'week' | 'month' | 'year';
203
+ interval_count?: number;
204
+ nickname?: string;
205
+ metadata?: Record<string, any>;
206
+ }
207
+
208
+ export interface ProductSyncResult {
209
+ synced_count: number;
210
+ updated_count: number;
211
+ created_count: number;
212
+ errors: any[];
213
+ sync_time: string;
214
+ }
215
+
216
+ // Admin types
217
+ export interface AdminUser {
218
+ id: string;
219
+ email?: string;
220
+ wallet_address?: string;
221
+ roles?: string[];
222
+ permissions?: string[];
223
+ isAdmin?: boolean;
224
+ isSuperAdmin?: boolean;
225
+ created_at?: string;
226
+ updated_at?: string;
227
+ }
228
+
229
+ export interface AdminAction {
230
+ adminUserId: string;
231
+ adminEmail: string;
232
+ action: string;
233
+ resourceType: string;
234
+ resourceId: string;
235
+ resourceData?: Record<string, any>;
236
+ ipAddress?: string;
237
+ userAgent?: string;
238
+ applicationId?: string;
239
+ severity?: AuditSeverity;
240
+ timestamp?: string;
241
+ }
242
+
243
+ export interface SecurityAlert {
244
+ id?: string;
245
+ alert_type: string;
246
+ user_id: string;
247
+ elevated_by?: string;
248
+ severity: AlertSeverity;
249
+ details: Record<string, any>;
250
+ timestamp: string;
251
+ resolved?: boolean;
252
+ created_at?: string;
253
+ }
254
+
255
+ // Session types
256
+ export interface SessionData {
257
+ user_id: string;
258
+ application_id: string;
259
+ wallets: UserWallet[];
260
+ tier: string;
261
+ created_at: Date;
262
+ last_activity: Date;
263
+ user_agent?: string;
264
+ ip_address?: string;
265
+ email?: string;
266
+ user_profile?: UserProfile;
267
+ }
268
+
269
+ export interface BlacklistedToken {
270
+ jti: string;
271
+ user_id: string;
272
+ expires_at: Date;
273
+ blacklisted_at: Date;
274
+ reason: 'logout' | 'refresh' | 'security' | 'admin';
275
+ }
276
+
277
+ // Validation result types
278
+ export interface TokenValidationResult {
279
+ valid: boolean;
280
+ payload?: TokenPayload;
281
+ error?: string;
282
+ expired?: boolean;
283
+ }
284
+
285
+ export interface RefreshTokenValidationResult {
286
+ valid: boolean;
287
+ payload?: RefreshTokenPayload;
288
+ error?: string;
289
+ expired?: boolean;
290
+ }
291
+
292
+ export interface ApiKeyValidationResult {
293
+ valid: boolean;
294
+ application?: Application;
295
+ error?: string;
296
+ }
297
+
298
+ // Utility types and enums
299
+ export type AdminRole = 'admin' | 'super_admin' | 'security_admin' | 'billing_admin';
300
+ export type UserRole = 'user' | AdminRole;
301
+
302
+ export type AdminPermission =
303
+ | 'view_products'
304
+ | 'create_orders'
305
+ | 'access_premium_features'
306
+ | 'manage_products'
307
+ | 'access_admin'
308
+ | 'view_analytics'
309
+ | 'manage_subscriptions'
310
+ | 'access_audit_logs'
311
+ | 'manage_users'
312
+ | 'system_settings';
313
+
314
+ export type AuditSeverity = 'INFO' | 'WARN' | 'HIGH' | 'ERROR' | 'CRITICAL';
315
+ export type AlertSeverity = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
316
+
317
+ export type ChainType = 'solana' | 'ethereum' | 'bitcoin' | 'base';
318
+ export type PaymentInterval = 'day' | 'week' | 'month' | 'year';
319
+
320
+ // Configuration types
321
+ export interface RateLimitConfig {
322
+ window_ms: number;
323
+ max_requests: number;
324
+ skip_failed_requests?: boolean;
325
+ skip_successful_requests?: boolean;
326
+ }
327
+
328
+ export interface LocalModeConfig {
329
+ environment: string;
330
+ isDocker: boolean;
331
+ defaultUser: 'user' | 'admin' | 'premium';
332
+ features: {
333
+ autoAuth: boolean;
334
+ corsEnabled: boolean;
335
+ verboseLogging: boolean;
336
+ };
337
+ }
338
+
339
+ export interface TestUser {
340
+ id: string;
341
+ email: string;
342
+ role: string;
343
+ tier: string;
344
+ created_at: string;
345
+ }
346
+
347
+ // Type guards for runtime type checking
348
+ export function isAdminRole(role: string): role is AdminRole {
349
+ return ['admin', 'super_admin', 'security_admin', 'billing_admin'].includes(role);
350
+ }
351
+
352
+ export function isValidPermission(permission: string): permission is AdminPermission {
353
+ return [
354
+ 'view_products', 'create_orders', 'access_premium_features',
355
+ 'manage_products', 'access_admin', 'view_analytics',
356
+ 'manage_subscriptions', 'access_audit_logs', 'manage_users', 'system_settings'
357
+ ].includes(permission);
358
+ }
359
+
360
+ export function isValidSeverity(severity: string): severity is AuditSeverity {
361
+ return ['INFO', 'WARN', 'HIGH', 'ERROR', 'CRITICAL'].includes(severity);
362
+ }
363
+
364
+ export function isValidAlertSeverity(severity: string): severity is AlertSeverity {
365
+ return ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL'].includes(severity);
366
+ }
367
+
368
+ export function isValidChainType(chain: string): chain is ChainType {
369
+ return ['solana', 'ethereum', 'bitcoin', 'base'].includes(chain);
370
+ }
371
+
372
+ // Re-export compatibility (helps with migration)
373
+ export type JWTPayload = TokenPayload;
374
+ export type DecodedToken = {
375
+ payload: TokenPayload;
376
+ header: {
377
+ alg: string;
378
+ typ: string;
379
+ };
380
+ };
package/src/server.ts ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Server-specific types that extend the shared types
3
+ * These are used only by the server and not exposed to SDK
4
+ */
5
+
6
+ import type { Request } from 'express';
7
+ import {
8
+ Application,
9
+ UserProfile,
10
+ TokenPayload,
11
+ AdminUser,
12
+ AdminPermission,
13
+ UserRole,
14
+ LocalModeConfig,
15
+ TestUser
16
+ } from './index';
17
+
18
+ // Express Request extensions
19
+ export interface ApiKeyAuthRequest extends Request {
20
+ application?: Application;
21
+ api_key?: string;
22
+ isLocalMode?: boolean;
23
+ localModeConfig?: LocalModeConfig;
24
+ testUser?: TestUser;
25
+ user?: UserProfile | TestUser;
26
+ }
27
+
28
+ export interface AuthenticatedRequest extends ApiKeyAuthRequest {
29
+ user?: UserProfile;
30
+ jwt_payload?: TokenPayload;
31
+ }
32
+
33
+ export interface UserSessionRequest extends AuthenticatedRequest {
34
+ userId?: string;
35
+ applicationId?: string;
36
+ }
37
+
38
+ export interface EnhancedAuthenticatedRequest extends AuthenticatedRequest {
39
+ adminUser?: AdminUser;
40
+ userPermissions?: AdminPermission[];
41
+ userRoles?: UserRole[];
42
+ isAdminRequest?: boolean;
43
+ }
44
+
45
+ // Re-export everything from index for convenience
46
+ export * from './index';