spaps 0.4.3 → 0.5.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.
@@ -16,21 +16,21 @@ ${chalk.green('Installation:')}
16
16
  yarn add spaps-sdk
17
17
 
18
18
  ${chalk.green('Basic Usage:')}
19
- ${chalk.gray('// ES6 Import')}
20
- import { SPAPSClient } from 'spaps-sdk'
19
+ ${chalk.gray('// ES Module')}
20
+ import { SweetPotatoSDK } from 'spaps-sdk'
21
21
 
22
22
  ${chalk.gray('// CommonJS')}
23
- const { SPAPSClient } = require('spaps-sdk')
23
+ const { SweetPotatoSDK } = require('spaps-sdk')
24
24
 
25
25
  ${chalk.gray('// Create client (auto-detects local mode)')}
26
- const spaps = new SPAPSClient()
27
-
28
- ${chalk.gray('// With custom config')}
29
- const spaps = new SPAPSClient({
30
- apiUrl: 'http://localhost:3300',
31
- apiKey: 'your-api-key', ${chalk.gray('// Not needed for localhost')}
32
- timeout: 10000
26
+ const sdk = new SweetPotatoSDK({
27
+ apiUrl: process.env.SPAPS_API_URL || 'http://localhost:3300',
28
+ apiKey: process.env.SPAPS_API_KEY, ${chalk.gray('// Not required in local mode')}
33
29
  })
30
+
31
+ ${chalk.gray('// Sign in with email/password (local mode accepts any credentials)')}
32
+ const auth = await sdk.auth.signInWithPassword({ email: 'user@example.com', password: 'password' })
33
+ console.log('User:', auth.user)
34
34
  `
35
35
  },
36
36
 
@@ -39,48 +39,30 @@ ${chalk.green('Basic Usage:')}
39
39
  content: `
40
40
  ${chalk.green('Email/Password Authentication:')}
41
41
  ${chalk.gray('// Register new user')}
42
- const { data } = await spaps.register(email, password)
43
- console.log('User:', data.user)
44
- console.log('Token:', data.access_token)
42
+ const registered = await sdk.auth.register({ email, password })
43
+ console.log('User:', registered.user)
44
+ console.log('Token:', registered.access_token)
45
45
 
46
46
  ${chalk.gray('// Login existing user')}
47
- const { data } = await spaps.login(email, password)
47
+ const auth = await sdk.auth.signInWithPassword({ email, password })
48
48
 
49
49
  ${chalk.gray('// Check authentication status')}
50
- if (spaps.isAuthenticated()) {
51
- const user = await spaps.getUser()
52
- console.log('Current user:', user.data)
50
+ if (sdk.auth.isAuthenticated()) {
51
+ const user = await sdk.auth.getCurrentUser()
52
+ console.log('Current user:', user)
53
53
  }
54
54
 
55
55
  ${chalk.gray('// Logout')}
56
- await spaps.logout()
56
+ await sdk.auth.logout()
57
57
 
58
58
  ${chalk.green('Wallet Authentication:')}
59
- ${chalk.gray('// Solana wallet')}
60
- await spaps.walletSignIn(
61
- walletAddress,
62
- signature,
63
- message,
64
- 'solana'
65
- )
66
-
67
- ${chalk.gray('// Ethereum wallet')}
68
- await spaps.walletSignIn(
69
- walletAddress,
70
- signature,
71
- message,
72
- 'ethereum'
73
- )
59
+ ${chalk.gray('// One-call helper: authenticateWallet')}
60
+ const resp = await sdk.auth.authenticateWallet(walletAddress, signMessage, 'ethereum')
61
+ console.log('User:', resp.user)
74
62
 
75
63
  ${chalk.green('Token Management:')}
76
- ${chalk.gray('// Get current token')}
77
- const token = spaps.getAccessToken()
78
-
79
- ${chalk.gray('// Set token manually')}
80
- spaps.setAccessToken(token)
81
-
82
- ${chalk.gray('// Refresh token')}
83
- await spaps.refresh()
64
+ ${chalk.gray('// Access token is managed internally; you can also set it manually')}
65
+ sdk.setAccessToken('jwt-token')
84
66
  `
85
67
  },
86
68
 
@@ -89,33 +71,25 @@ ${chalk.green('Token Management:')}
89
71
  content: `
90
72
  ${chalk.green('Stripe Checkout:')}
91
73
  ${chalk.gray('// Create checkout session')}
92
- const session = await spaps.createCheckoutSession(
93
- 'price_123abc', ${chalk.gray('// Stripe price ID')}
94
- 'http://localhost:3000/success', ${chalk.gray('// Success URL')}
95
- 'http://localhost:3000/cancel' ${chalk.gray('// Cancel URL (optional)')}
96
- )
74
+ const session = await sdk.payments.createCheckoutSession({
75
+ price_id: 'price_123abc',
76
+ success_url: 'http://localhost:3000/success',
77
+ cancel_url: 'http://localhost:3000/cancel'
78
+ })
97
79
 
98
80
  ${chalk.gray('// Redirect to Stripe')}
99
- window.location.href = session.data.url
81
+ window.location.href = session.url
100
82
 
101
83
  ${chalk.green('Subscription Management:')}
102
84
  ${chalk.gray('// Get current subscription')}
103
- const subscription = await spaps.getSubscription()
104
- console.log('Status:', subscription.data.status)
105
- console.log('Plan:', subscription.data.plan)
106
- console.log('Renews:', subscription.data.current_period_end)
85
+ // Example subscription helpers would go here if enabled
107
86
 
108
87
  ${chalk.gray('// Cancel subscription')}
109
88
  await spaps.cancelSubscription()
110
89
 
111
90
  ${chalk.green('Usage Tracking:')}
112
91
  ${chalk.gray('// Check balance')}
113
- const balance = await spaps.getUsageBalance()
114
- console.log('Credits:', balance.data.balance)
115
-
116
- ${chalk.gray('// Record usage')}
117
- await spaps.recordUsage('api-call', 1)
118
- await spaps.recordUsage('image-generation', 10)
92
+ // Usage APIs depend on your server config
119
93
  `
120
94
  },
121
95
 
@@ -132,18 +106,9 @@ ${chalk.green('Environment Variables:')}
132
106
  NEXT_PUBLIC_SPAPS_API_KEY=spaps_live_abc123...
133
107
 
134
108
  ${chalk.green('Configuration Options:')}
135
- const spaps = new SPAPSClient({
136
- ${chalk.gray('// API endpoint (auto-detected from env)')}
137
- apiUrl: 'http://localhost:3300',
138
-
139
- ${chalk.gray('// API key (not needed for localhost)')}
140
- apiKey: 'spaps_live_abc123...',
141
-
142
- ${chalk.gray('// Request timeout in milliseconds')}
143
- timeout: 10000,
144
-
145
- ${chalk.gray('// Auto-detect local mode (default: true)')}
146
- autoDetect: true
109
+ const sdk = new SweetPotatoSDK({
110
+ apiUrl: process.env.SPAPS_API_URL || 'http://localhost:3300',
111
+ apiKey: process.env.SPAPS_API_KEY, ${chalk.gray('// Omit in local dev')}
147
112
  })
148
113
 
149
114
  ${chalk.green('Local Mode Detection:')}
@@ -153,7 +118,7 @@ ${chalk.green('Local Mode Detection:')}
153
118
  - No API URL is provided
154
119
 
155
120
  ${chalk.gray('// Check if in local mode')}
156
- if (spaps.isLocalMode()) {
121
+ if (sdk.isLocalMode) {
157
122
  console.log('Running in local mode - no API key needed!')
158
123
  }
159
124
  `
@@ -165,14 +130,14 @@ ${chalk.green('Local Mode Detection:')}
165
130
  ${chalk.green('React Context Setup:')}
166
131
  ${chalk.gray('// contexts/SpapsContext.tsx')}
167
132
  import { createContext, useContext } from 'react'
168
- import { SPAPSClient } from 'spaps-sdk'
133
+ import { SweetPotatoSDK } from 'spaps-sdk'
169
134
 
170
- const spaps = new SPAPSClient()
171
- const SpapsContext = createContext(spaps)
135
+ const sdk = new SweetPotatoSDK({ apiUrl: process.env.NEXT_PUBLIC_SPAPS_API_URL || 'http://localhost:3300' })
136
+ const SpapsContext = createContext(sdk)
172
137
 
173
138
  export function SpapsProvider({ children }) {
174
139
  return (
175
- <SpapsContext.Provider value={spaps}>
140
+ <SpapsContext.Provider value={sdk}>
176
141
  {children}
177
142
  </SpapsContext.Provider>
178
143
  )
@@ -273,26 +238,23 @@ ${chalk.green('Server Actions:')}
273
238
  ${chalk.gray('// app/actions/auth.ts')}
274
239
  'use server'
275
240
 
276
- import { SPAPSClient } from 'spaps-sdk'
241
+ import { SweetPotatoSDK } from 'spaps-sdk'
277
242
  import { cookies } from 'next/headers'
278
243
 
279
- const spaps = new SPAPSClient({
280
- apiUrl: process.env.SPAPS_API_URL,
281
- apiKey: process.env.SPAPS_API_KEY
282
- })
244
+ const sdk = new SweetPotatoSDK({ apiUrl: process.env.SPAPS_API_URL, apiKey: process.env.SPAPS_API_KEY })
283
245
 
284
246
  export async function loginAction(email: string, password: string) {
285
- const { data } = await spaps.login(email, password)
247
+ const auth = await sdk.auth.signInWithPassword({ email, password })
286
248
 
287
249
  // Store token in cookie
288
- cookies().set('spaps_token', data.access_token, {
250
+ cookies().set('spaps_token', auth.access_token, {
289
251
  httpOnly: true,
290
252
  secure: process.env.NODE_ENV === 'production',
291
253
  sameSite: 'lax',
292
254
  maxAge: 60 * 60 * 24 * 7 // 1 week
293
255
  })
294
256
 
295
- return { success: true, user: data.user }
257
+ return { success: true, user: auth.user }
296
258
  }
297
259
 
298
260
  ${chalk.green('Middleware Protection:')}
@@ -322,17 +284,14 @@ ${chalk.green('Middleware Protection:')}
322
284
  ${chalk.green('Express Middleware:')}
323
285
  ${chalk.gray('// server.js')}
324
286
  const express = require('express')
325
- const { SPAPSClient } = require('spaps-sdk')
287
+ const { SweetPotatoSDK } = require('spaps-sdk')
326
288
 
327
289
  const app = express()
328
- const spaps = new SPAPSClient({
329
- apiUrl: process.env.SPAPS_API_URL,
330
- apiKey: process.env.SPAPS_API_KEY
331
- })
290
+ const sdk = new SweetPotatoSDK({ apiUrl: process.env.SPAPS_API_URL, apiKey: process.env.SPAPS_API_KEY })
332
291
 
333
292
  ${chalk.gray('// Add SPAPS to request')}
334
293
  app.use((req, res, next) => {
335
- req.spaps = spaps
294
+ req.spaps = sdk
336
295
  next()
337
296
  })
338
297
 
@@ -346,8 +305,8 @@ ${chalk.green('Express Middleware:')}
346
305
 
347
306
  try {
348
307
  req.spaps.setAccessToken(token)
349
- const { data } = await req.spaps.getUser()
350
- req.user = data
308
+ const user = await req.spaps.auth.getCurrentUser()
309
+ req.user = user
351
310
  next()
352
311
  } catch (error) {
353
312
  res.status(401).json({ error: 'Invalid token' })
@@ -360,8 +319,8 @@ ${chalk.green('Route Examples:')}
360
319
  const { email, password } = req.body
361
320
 
362
321
  try {
363
- const { data } = await req.spaps.login(email, password)
364
- res.json(data)
322
+ const auth = await req.spaps.auth.signInWithPassword({ email, password })
323
+ res.json(auth)
365
324
  } catch (error) {
366
325
  res.status(401).json({ error: 'Invalid credentials' })
367
326
  }
@@ -567,17 +526,17 @@ ${chalk.green('E2E Testing with Cypress:')}
567
526
  ${chalk.green('Mocking for Tests:')}
568
527
  ${chalk.gray('// Mock SPAPS client')}
569
528
  jest.mock('spaps-sdk', () => ({
570
- SPAPSClient: jest.fn().mockImplementation(() => ({
571
- login: jest.fn().mockResolvedValue({
572
- data: {
529
+ SweetPotatoSDK: jest.fn().mockImplementation(() => ({
530
+ auth: {
531
+ signInWithPassword: jest.fn().mockResolvedValue({
573
532
  user: { id: '123', email: 'test@example.com' },
574
- access_token: 'mock-token'
575
- }
576
- }),
577
- isAuthenticated: jest.fn().mockReturnValue(true),
578
- getUser: jest.fn().mockResolvedValue({
579
- data: { id: '123', email: 'test@example.com' }
580
- })
533
+ access_token: 'mock-token',
534
+ refresh_token: 'mock-refresh'
535
+ }),
536
+ isAuthenticated: jest.fn().mockReturnValue(true),
537
+ getCurrentUser: jest.fn().mockResolvedValue({ id: '123', email: 'test@example.com' })
538
+ },
539
+ setAccessToken: jest.fn()
581
540
  }))
582
541
  }))
583
542
  `
@@ -587,39 +546,29 @@ ${chalk.green('Mocking for Tests:')}
587
546
  title: 'API Reference',
588
547
  content: `
589
548
  ${chalk.green('Authentication Methods:')}
590
- login(email: string, password: string): Promise<{data: AuthResponse}>
591
- register(email: string, password: string): Promise<{data: AuthResponse}>
592
- walletSignIn(address: string, signature: string, message: string, chain: string): Promise<{data: AuthResponse}>
593
- refresh(refreshToken?: string): Promise<{data: AuthResponse}>
594
- logout(): Promise<void>
595
- getUser(): Promise<{data: User}>
549
+ sdk.auth.signInWithPassword({ email, password }): Promise<AuthResponse>
550
+ sdk.auth.register({ email, password, username? }): Promise<AuthResponse>
551
+ sdk.auth.authenticateWallet(address, signFn, chain?): Promise<AuthResponse>
552
+ sdk.auth.refreshToken(refreshToken): Promise<AuthResponse>
553
+ sdk.auth.logout(): Promise<void>
554
+ sdk.auth.getCurrentUser(): Promise<User>
596
555
 
597
556
  ${chalk.green('Payment Methods:')}
598
- createCheckoutSession(priceId: string, successUrl: string, cancelUrl?: string): Promise<{data: CheckoutSession}>
599
- getSubscription(): Promise<{data: Subscription}>
600
- cancelSubscription(): Promise<void>
557
+ sdk.payments.createCheckoutSession({ price_id, success_url, cancel_url }): Promise<CheckoutSession>
558
+ sdk.payments.getCheckoutSession(id): Promise<CheckoutSession>
559
+ sdk.payments.listProducts({ category?, active?, limit? }): Promise<ProductsListResponse>
601
560
 
602
561
  ${chalk.green('Usage Methods:')}
603
- getUsageBalance(): Promise<{data: UsageBalance}>
604
- recordUsage(feature: string, amount: number): Promise<void>
562
+ See server docs if enabled
605
563
 
606
564
  ${chalk.green('Utility Methods:')}
607
- isAuthenticated(): boolean
608
- getAccessToken(): string | undefined
609
- setAccessToken(token: string): void
610
- isLocalMode(): boolean
611
- health(): Promise<{data: any}>
612
-
613
- ${chalk.green('Properties:')}
614
- client: AxiosInstance ${chalk.gray('// Direct access to Axios client')}
565
+ sdk.setAccessToken(token: string): void
566
+ sdk.clearAccessToken(): void
615
567
 
616
568
  ${chalk.green('Response Types:')}
617
- ${chalk.gray('// All methods return data wrapped in { data: T }')}
618
- ${chalk.gray('// This matches Axios response structure')}
619
- ${chalk.gray('// Example:')}
620
- const response = await spaps.login(email, password)
621
- // response.data contains AuthResponse
622
- // response.status, response.headers also available
569
+ ${chalk.gray('// Methods generally return typed objects directly')}
570
+ const auth = await sdk.auth.signInWithPassword({ email, password })
571
+ console.log(auth.access_token)
623
572
  `
624
573
  }
625
574
  };
@@ -636,7 +585,7 @@ ${chalk.green('Authentication Endpoints:')}
636
585
  GET /api/auth/user ${chalk.gray('Get current user')}
637
586
 
638
587
  ${chalk.green('Stripe Endpoints:')}
639
- POST /api/stripe/create-checkout-session ${chalk.gray('Create Stripe checkout')}
588
+ POST /api/stripe/checkout-sessions ${chalk.gray('Create Stripe checkout')}
640
589
  GET /api/stripe/subscription ${chalk.gray('Get subscription status')}
641
590
  DELETE /api/stripe/subscription ${chalk.gray('Cancel subscription')}
642
591
  POST /api/stripe/webhook ${chalk.gray('Stripe webhook handler')}
@@ -803,4 +752,4 @@ module.exports = {
803
752
  searchDocs,
804
753
  SDK_DOCS,
805
754
  API_ENDPOINTS
806
- };
755
+ };
@@ -0,0 +1,155 @@
1
+ const chalk = require('chalk');
2
+ const fs = require('fs');
3
+ const { DEFAULT_PORT } = require('./config');
4
+ const { handleError } = require('./error-handler');
5
+ const { showInteractiveHelp, showQuickHelp } = require('./help-system');
6
+ const { showInteractiveDocs, showQuickReference, searchDocs } = require('./docs-system');
7
+ const { getQuickStartInstructions, getServerStatus, runQuickTest } = require('./ai-helper');
8
+
9
+ function createHandlers(version, logo) {
10
+ return {
11
+ local: async ({ options }) => {
12
+ const isJson = options.json;
13
+ if (!isJson) console.log(logo);
14
+ try {
15
+ const LocalServer = require('./local-server.js');
16
+ const server = new LocalServer({ port: options.port, json: isJson });
17
+ if (isJson) {
18
+ await server.start();
19
+ console.log(JSON.stringify({
20
+ success: true,
21
+ command: 'local',
22
+ server: {
23
+ url: `http://localhost:${options.port}`,
24
+ docs: `http://localhost:${options.port}/docs`,
25
+ mode: 'local-development',
26
+ port: Number(options.port),
27
+ features: { autoAuth: true, corsEnabled: true, testUsers: ['user', 'admin', 'premium'], apiKeyRequired: false }
28
+ }
29
+ }));
30
+ } else {
31
+ await server.start();
32
+ if (options.open) {
33
+ const { exec } = require('child_process');
34
+ const url = `http://localhost:${options.port}/docs`;
35
+ const start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
36
+ exec(`${start} ${url}`);
37
+ }
38
+ }
39
+ process.on('SIGINT', () => {
40
+ if (!isJson) console.log(chalk.yellow('\n👋 Shutting down SPAPS local server...'));
41
+ process.exit(0);
42
+ });
43
+ } catch (error) {
44
+ handleError(error, { port: options.port, command: 'local' }, { json: isJson });
45
+ }
46
+ },
47
+ quickstart: async ({ options }) => {
48
+ const instructions = getQuickStartInstructions(options.port);
49
+ if (options.json) {
50
+ console.log(JSON.stringify(instructions, null, 2));
51
+ } else {
52
+ console.log(chalk.yellow('\n🍠 SPAPS Quick Start Instructions\n'));
53
+ console.log('1. Install SDK: npm install spaps-sdk');
54
+ console.log('2. Create test file with the code above');
55
+ console.log('3. Run: node test-spaps.js');
56
+ console.log('\nFor JSON output: npx spaps quickstart --json');
57
+ }
58
+ },
59
+ status: async ({ options }) => {
60
+ const status = await getServerStatus(options.port);
61
+ if (options.json) {
62
+ console.log(JSON.stringify(status));
63
+ } else {
64
+ if (!status.running) {
65
+ console.log(chalk.red('\n❌ SPAPS server is not running'));
66
+ console.log('Start it with:');
67
+ console.log(chalk.cyan(` npx spaps local --port ${options.port}`));
68
+ console.log();
69
+ } else {
70
+ console.log(chalk.green('\n✅ SPAPS server is running!\n'));
71
+ console.log(' URL:', chalk.cyan(status.url));
72
+ console.log(' Docs:', chalk.cyan(status.docs));
73
+ console.log();
74
+ }
75
+ }
76
+ },
77
+ test: async ({ options }) => {
78
+ const result = await runQuickTest(options.port);
79
+ console.log(JSON.stringify(result, null, 2));
80
+ },
81
+ init: async ({ options }) => {
82
+ const isJson = options.json;
83
+ const envContent = `# SPAPS Local Development\nSPAPS_API_URL=http://localhost:${DEFAULT_PORT}\n# SPAPS_API_KEY=your-api-key-here\n`;
84
+ const result = { success: true, command: 'init', files_created: [], files_skipped: [], next_steps: ['npx spaps local', 'npm install @spaps/sdk', 'Start coding!'] };
85
+ if (!fs.existsSync('.env.local')) {
86
+ fs.writeFileSync('.env.local', envContent);
87
+ result.files_created.push('.env.local');
88
+ if (!isJson) console.log(chalk.green('✅ Created .env.local'));
89
+ } else {
90
+ result.files_skipped.push('.env.local');
91
+ result.message = '.env.local already exists';
92
+ if (!isJson) console.log(chalk.yellow('⚠️ .env.local already exists'));
93
+ }
94
+ if (isJson) {
95
+ console.log(JSON.stringify(result));
96
+ } else {
97
+ console.log();
98
+ console.log(chalk.green('✨ SPAPS initialized!'));
99
+ console.log();
100
+ console.log('Next steps:');
101
+ console.log(chalk.cyan(' 1. Run: npx spaps local'));
102
+ console.log(chalk.cyan(' 2. Install SDK: npm install @spaps/sdk'));
103
+ console.log(chalk.cyan(' 3. Start coding!'));
104
+ }
105
+ },
106
+ create: () => {
107
+ console.log(chalk.yellow('🍠 SPAPS'));
108
+ console.log(chalk.yellow(`🚧 'spaps create' coming in v0.3.0!`));
109
+ console.log();
110
+ console.log('For now, check out our examples:');
111
+ console.log(chalk.cyan(' https://github.com/yourusername/sweet-potato/tree/main/examples'));
112
+ },
113
+ types: () => {
114
+ console.log(chalk.yellow('🍠 SPAPS'));
115
+ console.log(chalk.yellow(`🚧 'spaps types' coming in v0.4.0!`));
116
+ },
117
+ help: async ({ options }) => {
118
+ if (options.interactive) {
119
+ await showInteractiveHelp();
120
+ } else if (options.quick) {
121
+ showQuickHelp();
122
+ } else {
123
+ showQuickHelp();
124
+ }
125
+ },
126
+ docs: async ({ options }) => {
127
+ if (options.search) {
128
+ const results = searchDocs(options.search);
129
+ if (options.json) {
130
+ console.log(JSON.stringify({ results }, null, 2));
131
+ } else {
132
+ console.log(chalk.yellow(`\n🔍 Search results for "${options.search}":\n`));
133
+ if (results.length === 0) {
134
+ console.log(chalk.gray(' No results found'));
135
+ } else {
136
+ results.forEach((result, i) => {
137
+ console.log(chalk.green(` ${i + 1}. ${result.title}`));
138
+ console.log(chalk.gray(` ${result.preview}`));
139
+ console.log();
140
+ });
141
+ }
142
+ console.log(chalk.blue(' Run: npx spaps docs --interactive'));
143
+ console.log(chalk.blue(' to browse full documentation\n'));
144
+ }
145
+ } else if (options.interactive) {
146
+ await showInteractiveDocs();
147
+ } else {
148
+ showQuickReference();
149
+ }
150
+ }
151
+ };
152
+ }
153
+
154
+ module.exports = { createHandlers };
155
+
@@ -6,6 +6,8 @@
6
6
  const chalk = require('chalk');
7
7
  const prompts = require('prompts');
8
8
 
9
+ const { DEFAULT_PORT } = require('./config');
10
+
9
11
  const HELP_TREE = {
10
12
  root: {
11
13
  question: 'What would you like to do?',
@@ -45,12 +47,12 @@ const HELP_TREE = {
45
47
  title: 'Quick start (default settings)',
46
48
  value: 'quick-start',
47
49
  command: 'npx spaps local',
48
- description: 'Start on port 3300'
50
+ description: `Start on port ${DEFAULT_PORT}`
49
51
  },
50
52
  {
51
53
  title: 'Custom port',
52
54
  value: 'custom-port',
53
- command: 'npx spaps local --port 3001',
55
+ command: `npx spaps local --port ${DEFAULT_PORT + 1}`,
54
56
  description: 'Choose your own port'
55
57
  },
56
58
  {
@@ -484,4 +486,4 @@ module.exports = {
484
486
  showInteractiveHelp,
485
487
  showQuickHelp,
486
488
  HELP_TREE
487
- };
489
+ };
package/src/index.js ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * SPAPS Package Main Export
3
+ * Provides middleware, utilities, and client functionality
4
+ */
5
+
6
+ const adminMiddleware = require('./middleware/admin');
7
+
8
+ // Export admin middleware and utilities
9
+ module.exports = {
10
+ // Admin middleware functions
11
+ requireAdmin: adminMiddleware.requireAdmin,
12
+ requirePermission: adminMiddleware.requirePermission,
13
+
14
+ // Permission checking utilities
15
+ isAdminAccount: adminMiddleware.isAdminAccount,
16
+ getUserRole: adminMiddleware.getUserRole,
17
+ hasPermission: adminMiddleware.hasPermission,
18
+ getRoleAwareErrorMessage: adminMiddleware.getRoleAwareErrorMessage,
19
+
20
+ // Constants
21
+ DEFAULT_ADMIN_ACCOUNTS: adminMiddleware.DEFAULT_ADMIN_ACCOUNTS,
22
+
23
+ // Factory function for custom admin configurations
24
+ createPermissionChecker: adminMiddleware.createPermissionChecker,
25
+
26
+ // Express middleware aliases for convenience
27
+ admin: adminMiddleware.requireAdmin,
28
+ permission: adminMiddleware.requirePermission,
29
+
30
+ // Version and metadata
31
+ version: require('../package.json').version,
32
+ name: 'spaps'
33
+ };
34
+
35
+ // Named exports for ES6 compatibility
36
+ module.exports.requireAdmin = adminMiddleware.requireAdmin;
37
+ module.exports.requirePermission = adminMiddleware.requirePermission;
38
+ module.exports.isAdminAccount = adminMiddleware.isAdminAccount;
39
+ module.exports.getUserRole = adminMiddleware.getUserRole;
40
+ module.exports.hasPermission = adminMiddleware.hasPermission;
41
+ module.exports.getRoleAwareErrorMessage = adminMiddleware.getRoleAwareErrorMessage;
42
+ module.exports.createPermissionChecker = adminMiddleware.createPermissionChecker;