spaps 0.5.49 → 0.6.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/package.json +1 -1
- package/src/ai-helper.js +1 -1
- package/src/local-server.js +52 -24
package/package.json
CHANGED
package/src/ai-helper.js
CHANGED
package/src/local-server.js
CHANGED
|
@@ -64,23 +64,47 @@ class LocalServer {
|
|
|
64
64
|
this.app.use('/swagger-ui', express.static(uiPath));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// User IDs must match production for testing against prod data
|
|
68
|
+
const LOCAL_PERSONAS = {
|
|
69
|
+
admin: {
|
|
70
|
+
id: '5bdb0db2-5ab1-4e2c-999b-1153cc329477', // Real prod super admin ID
|
|
71
|
+
email: 'buildooor@gmail.com',
|
|
72
|
+
role: 'admin'
|
|
73
|
+
},
|
|
74
|
+
user: {
|
|
75
|
+
id: '00000000-0000-0000-0000-000000000002',
|
|
76
|
+
email: 'dev@localhost',
|
|
77
|
+
role: 'user'
|
|
78
|
+
},
|
|
79
|
+
premium: {
|
|
80
|
+
id: '00000000-0000-0000-0000-000000000003',
|
|
81
|
+
email: 'premium@localhost',
|
|
82
|
+
role: 'user'
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Store personas on app for use in routes
|
|
87
|
+
this.localPersonas = LOCAL_PERSONAS;
|
|
88
|
+
|
|
67
89
|
// Local mode indicator
|
|
68
90
|
this.app.use((req, res, next) => {
|
|
69
91
|
res.setHeader('X-SPAPS-Mode', 'local-development');
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
|
|
92
|
+
|
|
93
|
+
// Determine persona from query/header (always, regardless of auth header)
|
|
94
|
+
const persona = req.query._user || req.headers['x-test-user'] || 'user';
|
|
95
|
+
req.localPersona = persona;
|
|
96
|
+
|
|
97
|
+
// Auto-auth in local mode - always set user based on persona
|
|
98
|
+
if (!req.headers['x-api-key']) {
|
|
73
99
|
req.headers['x-api-key'] = 'local-dev-key';
|
|
74
|
-
req.user = {
|
|
75
|
-
id: 'local-user-123',
|
|
76
|
-
email: 'dev@localhost',
|
|
77
|
-
role: req.query._user || req.headers['x-test-user'] || 'user'
|
|
78
|
-
};
|
|
79
100
|
}
|
|
80
|
-
|
|
101
|
+
|
|
102
|
+
// Always set req.user based on persona for local mode consistency
|
|
103
|
+
req.user = LOCAL_PERSONAS[persona] || LOCAL_PERSONAS.user;
|
|
104
|
+
|
|
81
105
|
// Log requests (unless in JSON mode)
|
|
82
106
|
if (!this.json) {
|
|
83
|
-
console.log(chalk.dim(`${req.method} ${req.path}`));
|
|
107
|
+
console.log(chalk.dim(`${req.method} ${req.path} [${persona}]`));
|
|
84
108
|
}
|
|
85
109
|
next();
|
|
86
110
|
});
|
|
@@ -123,32 +147,34 @@ class LocalServer {
|
|
|
123
147
|
|
|
124
148
|
// Mock authentication endpoints
|
|
125
149
|
this.app.post('/api/auth/login', (req, res) => {
|
|
126
|
-
const { email
|
|
150
|
+
const { email } = req.body;
|
|
151
|
+
// Use consistent user from middleware (set by persona)
|
|
127
152
|
res.json({
|
|
128
153
|
success: true,
|
|
129
154
|
data: {
|
|
130
155
|
access_token: 'local-jwt-token-' + Date.now(),
|
|
131
156
|
refresh_token: 'local-refresh-token-' + Date.now(),
|
|
132
157
|
user: {
|
|
133
|
-
id:
|
|
134
|
-
email: email ||
|
|
135
|
-
role:
|
|
158
|
+
id: req.user.id,
|
|
159
|
+
email: email || req.user.email,
|
|
160
|
+
role: req.user.role
|
|
136
161
|
}
|
|
137
162
|
}
|
|
138
163
|
});
|
|
139
164
|
});
|
|
140
165
|
|
|
141
166
|
this.app.post('/api/auth/register', (req, res) => {
|
|
142
|
-
const { email
|
|
167
|
+
const { email } = req.body;
|
|
168
|
+
// Use consistent user from middleware (set by persona)
|
|
143
169
|
res.json({
|
|
144
170
|
success: true,
|
|
145
171
|
data: {
|
|
146
172
|
access_token: 'local-jwt-token-' + Date.now(),
|
|
147
173
|
refresh_token: 'local-refresh-token-' + Date.now(),
|
|
148
174
|
user: {
|
|
149
|
-
id:
|
|
150
|
-
email: email ||
|
|
151
|
-
role:
|
|
175
|
+
id: req.user.id,
|
|
176
|
+
email: email || req.user.email,
|
|
177
|
+
role: req.user.role
|
|
152
178
|
}
|
|
153
179
|
}
|
|
154
180
|
});
|
|
@@ -156,16 +182,17 @@ class LocalServer {
|
|
|
156
182
|
|
|
157
183
|
this.app.post('/api/auth/wallet-sign-in', (req, res) => {
|
|
158
184
|
const { wallet_address, chain_type } = req.body;
|
|
185
|
+
// Use consistent user from middleware (set by persona)
|
|
159
186
|
res.json({
|
|
160
187
|
success: true,
|
|
161
188
|
data: {
|
|
162
189
|
access_token: 'local-jwt-token-' + Date.now(),
|
|
163
190
|
refresh_token: 'local-refresh-token-' + Date.now(),
|
|
164
191
|
user: {
|
|
165
|
-
id:
|
|
192
|
+
id: req.user.id,
|
|
166
193
|
wallet_address,
|
|
167
194
|
chain_type,
|
|
168
|
-
role:
|
|
195
|
+
role: req.user.role
|
|
169
196
|
}
|
|
170
197
|
}
|
|
171
198
|
});
|
|
@@ -186,10 +213,11 @@ class LocalServer {
|
|
|
186
213
|
});
|
|
187
214
|
|
|
188
215
|
this.app.get('/api/auth/user', (req, res) => {
|
|
216
|
+
// req.user is always set by the middleware based on persona
|
|
189
217
|
res.json({
|
|
190
|
-
id: req.user
|
|
191
|
-
email: req.user
|
|
192
|
-
role: req.user
|
|
218
|
+
id: req.user.id,
|
|
219
|
+
email: req.user.email,
|
|
220
|
+
role: req.user.role,
|
|
193
221
|
created_at: new Date().toISOString()
|
|
194
222
|
});
|
|
195
223
|
});
|
|
@@ -1339,7 +1367,7 @@ class LocalServer {
|
|
|
1339
1367
|
customer: 'cus_local_' + Date.now(),
|
|
1340
1368
|
payment_status: 'paid',
|
|
1341
1369
|
status: 'complete',
|
|
1342
|
-
metadata: { app_id: '
|
|
1370
|
+
metadata: { app_id: '00000000-0000-0000-0000-000000000100', price_id: priceId }
|
|
1343
1371
|
}
|
|
1344
1372
|
}
|
|
1345
1373
|
};
|