spaps 0.5.48 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spaps",
3
- "version": "0.5.48",
3
+ "version": "0.6.0",
4
4
  "description": "Sweet Potato Authentication & Payment Service CLI - Zero-config local development with built-in admin middleware and permission utilities",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/ai-helper.js CHANGED
@@ -43,7 +43,7 @@ test().then(console.log).catch(console.error);`
43
43
  expected_output: {
44
44
  success: true,
45
45
  user: {
46
- id: "local-user-123",
46
+ id: "00000000-0000-0000-0000-000000000002",
47
47
  email: "test@example.com"
48
48
  }
49
49
  }
@@ -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
- // Auto-auth in local mode
72
- if (!req.headers.authorization && !req.headers['x-api-key']) {
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, password } = req.body;
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: 'local-user-123',
134
- email: email || 'dev@localhost',
135
- role: 'user'
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, password } = req.body;
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: 'local-user-' + Date.now(),
150
- email: email || 'dev@localhost',
151
- role: 'user'
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: 'local-wallet-user-123',
192
+ id: req.user.id,
166
193
  wallet_address,
167
194
  chain_type,
168
- role: 'user'
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?.id || 'local-user-123',
191
- email: req.user?.email || 'dev@localhost',
192
- role: req.user?.role || '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: 'local-app-001', price_id: priceId }
1370
+ metadata: { app_id: '00000000-0000-0000-0000-000000000100', price_id: priceId }
1343
1371
  }
1344
1372
  }
1345
1373
  };