@symbo.ls/sdk 3.1.1 → 3.1.2
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 +172 -11
- package/dist/cjs/config/environment.js +39 -33
- package/dist/cjs/index.js +35 -8
- package/dist/cjs/services/AuthService.js +44 -3
- package/dist/cjs/services/BasedService.js +530 -24
- package/dist/cjs/services/CoreService.js +1751 -0
- package/dist/cjs/services/SocketIOService.js +34 -36
- package/dist/cjs/services/SymstoryService.js +135 -49
- package/dist/cjs/services/index.js +4 -4
- package/dist/cjs/utils/TokenManager.js +374 -0
- package/dist/cjs/utils/basedQuerys.js +120 -0
- package/dist/cjs/utils/permission.js +4 -4
- package/dist/cjs/utils/services.js +32 -9
- package/dist/cjs/utils/symstoryClient.js +32 -1
- package/dist/esm/config/environment.js +39 -33
- package/dist/esm/index.js +8964 -11076
- package/dist/esm/services/AuthService.js +48 -7
- package/dist/esm/services/BasedService.js +683 -56
- package/dist/esm/services/CoreService.js +2264 -0
- package/dist/esm/services/SocketIOService.js +71 -68
- package/dist/esm/services/SymstoryService.js +293 -101
- package/dist/esm/services/index.js +8905 -11066
- package/dist/esm/utils/TokenManager.js +360 -0
- package/dist/esm/utils/basedQuerys.js +120 -0
- package/dist/esm/utils/permission.js +4 -4
- package/dist/esm/utils/services.js +32 -9
- package/dist/esm/utils/symstoryClient.js +69 -33
- package/dist/esm/utils/validation.js +89 -19
- package/dist/node/config/environment.js +39 -33
- package/dist/node/index.js +43 -10
- package/dist/node/services/AuthService.js +44 -3
- package/dist/node/services/BasedService.js +531 -25
- package/dist/node/services/CoreService.js +1722 -0
- package/dist/node/services/SocketIOService.js +34 -36
- package/dist/node/services/SymstoryService.js +135 -49
- package/dist/node/services/index.js +4 -4
- package/dist/node/utils/TokenManager.js +355 -0
- package/dist/node/utils/basedQuerys.js +120 -0
- package/dist/node/utils/permission.js +4 -4
- package/dist/node/utils/services.js +32 -9
- package/dist/node/utils/symstoryClient.js +32 -1
- package/package.json +16 -13
- package/src/config/environment.js +40 -35
- package/src/index.js +49 -10
- package/src/services/AuthService.js +52 -3
- package/src/services/BasedService.js +602 -23
- package/src/services/CoreService.js +1943 -0
- package/src/services/SocketIOService.js +49 -71
- package/src/services/SymstoryService.js +150 -64
- package/src/services/index.js +4 -4
- package/src/utils/TokenManager.js +424 -0
- package/src/utils/basedQuerys.js +123 -0
- package/src/utils/permission.js +4 -4
- package/src/utils/services.js +32 -9
- package/src/utils/symstoryClient.js +35 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ import { SDK } from '@symbo.ls/sdk'
|
|
|
13
13
|
const sdk = new SDK({
|
|
14
14
|
useNewServices: true, // Use new service implementations
|
|
15
15
|
baseUrl: 'https://api.symbols.app',
|
|
16
|
-
socketUrl: 'https://
|
|
16
|
+
socketUrl: 'https://api.symbols.app',
|
|
17
17
|
timeout: 30000,
|
|
18
18
|
retryAttempts: 3,
|
|
19
19
|
debug: false
|
|
@@ -397,7 +397,7 @@ sdk.destroy()
|
|
|
397
397
|
const options = {
|
|
398
398
|
useNewServices: true,
|
|
399
399
|
baseUrl: 'https://api.symbols.app',
|
|
400
|
-
socketUrl: 'https://
|
|
400
|
+
socketUrl: 'https://api.symbols.app',
|
|
401
401
|
timeout: 30000,
|
|
402
402
|
retryAttempts: 3,
|
|
403
403
|
debug: false
|
|
@@ -418,7 +418,7 @@ const canEdit = sdk.hasPermission(projectId, 'edit')
|
|
|
418
418
|
const hasCopilot = sdk.checkProjectFeature(projectTier, 'aiCopilot')
|
|
419
419
|
|
|
420
420
|
// Check if user has global admin access
|
|
421
|
-
const isAdmin = sdk.hasGlobalPermission('admin', '
|
|
421
|
+
const isAdmin = sdk.hasGlobalPermission('admin', 'governance')
|
|
422
422
|
```
|
|
423
423
|
|
|
424
424
|
## Permission Types
|
|
@@ -494,11 +494,11 @@ if (isProjectAdmin) {
|
|
|
494
494
|
const canMerge = projectId => {
|
|
495
495
|
const hasPermission = sdk.hasPermission(projectId, 'merge')
|
|
496
496
|
const isProtectedBranch = sdk.getBranchProtection(projectId)
|
|
497
|
-
|
|
497
|
+
|
|
498
498
|
if (isProtectedBranch) {
|
|
499
499
|
return hasPermission && sdk.hasPermission(projectId, 'manage')
|
|
500
500
|
}
|
|
501
|
-
|
|
501
|
+
|
|
502
502
|
return hasPermission
|
|
503
503
|
}
|
|
504
504
|
```
|
|
@@ -510,8 +510,8 @@ const canMerge = projectId => {
|
|
|
510
510
|
const ROLE_PERMISSIONS = {
|
|
511
511
|
guest: ['viewPublicProjects'],
|
|
512
512
|
user: ['viewPublicProjects', 'createProject'],
|
|
513
|
-
admin: ['viewPublicProjects', 'createProject', '
|
|
514
|
-
superAdmin: ['viewPublicProjects', 'createProject', '
|
|
513
|
+
admin: ['viewPublicProjects', 'createProject', 'governance'],
|
|
514
|
+
superAdmin: ['viewPublicProjects', 'createProject', 'governance', 'managePlatform']
|
|
515
515
|
}
|
|
516
516
|
```
|
|
517
517
|
|
|
@@ -551,7 +551,7 @@ if (canInvite) {
|
|
|
551
551
|
const tier = sdk.getProjectTier(projectId)
|
|
552
552
|
const maxMembers = TIER_LIMITS[tier].teamMembers
|
|
553
553
|
const currentSize = await sdk.getCurrentTeamSize()
|
|
554
|
-
|
|
554
|
+
|
|
555
555
|
if (currentSize < maxMembers) {
|
|
556
556
|
await sdk.inviteTeamMember(email, 'editor')
|
|
557
557
|
}
|
|
@@ -563,7 +563,7 @@ if (canInvite) {
|
|
|
563
563
|
const handleAIFeature = async (projectId) => {
|
|
564
564
|
const tier = await sdk.getProjectTier(projectId)
|
|
565
565
|
const copilotAccess = sdk.checkProjectFeature(tier, 'aiCopilot')
|
|
566
|
-
|
|
566
|
+
|
|
567
567
|
if (copilotAccess) {
|
|
568
568
|
const tokensLeft = await sdk.getAITokensRemaining(projectId)
|
|
569
569
|
return {
|
|
@@ -572,7 +572,7 @@ const handleAIFeature = async (projectId) => {
|
|
|
572
572
|
maxTokens: copilotAccess
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
-
|
|
575
|
+
|
|
576
576
|
return { hasAccess: false }
|
|
577
577
|
}
|
|
578
578
|
```
|
|
@@ -582,7 +582,7 @@ const handleAIFeature = async (projectId) => {
|
|
|
582
582
|
const protectBranch = async (projectId, branchName) => {
|
|
583
583
|
const canManage = sdk.hasPermission(projectId, 'manage')
|
|
584
584
|
if (!canManage) return false
|
|
585
|
-
|
|
585
|
+
|
|
586
586
|
return sdk.setBranchProtection(projectId, branchName, {
|
|
587
587
|
requireReview: true,
|
|
588
588
|
requiredApprovals: 2,
|
|
@@ -614,5 +614,166 @@ try {
|
|
|
614
614
|
}
|
|
615
615
|
```
|
|
616
616
|
|
|
617
|
+
## Token Management
|
|
618
|
+
|
|
619
|
+
The SDK now includes automatic token management with persistence and refresh capabilities:
|
|
620
|
+
|
|
621
|
+
### Features
|
|
622
|
+
- **Automatic Token Refresh**: Tokens are refreshed automatically before expiration
|
|
623
|
+
- **Persistent Storage**: Tokens persist across page refreshes using localStorage
|
|
624
|
+
- **Secure Handling**: Automatic cleanup on logout and error handling
|
|
625
|
+
- **Flexible Storage**: Supports localStorage, sessionStorage, or memory storage
|
|
626
|
+
|
|
627
|
+
### Configuration
|
|
628
|
+
```javascript
|
|
629
|
+
import { getTokenManager } from '@symbols/sdk'
|
|
630
|
+
|
|
631
|
+
// Configure token management (optional - handled automatically by CoreService)
|
|
632
|
+
const tokenManager = getTokenManager({
|
|
633
|
+
storageType: 'localStorage', // 'localStorage' | 'sessionStorage' | 'memory'
|
|
634
|
+
refreshBuffer: 60 * 1000, // Refresh 1 minute before expiry
|
|
635
|
+
apiUrl: '/api',
|
|
636
|
+
onTokenRefresh: (tokens) => console.log('Token refreshed'),
|
|
637
|
+
onTokenExpired: () => console.log('Session expired'),
|
|
638
|
+
onTokenError: (error) => console.error('Token error:', error)
|
|
639
|
+
})
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Usage with CoreService
|
|
643
|
+
```javascript
|
|
644
|
+
// Initialize SDK - token management is automatic
|
|
645
|
+
const symbols = new Symbols({
|
|
646
|
+
appKey: 'your-app-key',
|
|
647
|
+
authToken: 'your-initial-token' // Optional
|
|
648
|
+
})
|
|
649
|
+
|
|
650
|
+
// Login - tokens are automatically managed
|
|
651
|
+
const loginResult = await symbols.login('user@example.com', 'password')
|
|
652
|
+
|
|
653
|
+
// All subsequent API calls automatically use fresh tokens
|
|
654
|
+
const projects = await symbols.getProjects()
|
|
655
|
+
const projectData = await symbols.getProjectData('projectId123')
|
|
656
|
+
|
|
657
|
+
// Logout - tokens are automatically cleared
|
|
658
|
+
await symbols.logout()
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
## New Core Service Methods
|
|
662
|
+
|
|
663
|
+
### Project Data Management (Symstory Replacement)
|
|
664
|
+
```javascript
|
|
665
|
+
// Apply changes to project
|
|
666
|
+
await symbols.applyProjectChanges('projectId', [
|
|
667
|
+
['update', ['components', 'Button'], { color: 'blue' }],
|
|
668
|
+
['delete', ['pages', 'oldPage']]
|
|
669
|
+
], { message: 'Update button color', type: 'patch' })
|
|
670
|
+
|
|
671
|
+
// Get current project data
|
|
672
|
+
const projectData = await symbols.getProjectData('projectId', {
|
|
673
|
+
branch: 'main',
|
|
674
|
+
includeHistory: true
|
|
675
|
+
})
|
|
676
|
+
|
|
677
|
+
// Restore to previous version
|
|
678
|
+
await symbols.restoreProjectVersion('projectId', '1.2.0', {
|
|
679
|
+
message: 'Rollback to stable version'
|
|
680
|
+
})
|
|
681
|
+
|
|
682
|
+
// Helper methods for single operations
|
|
683
|
+
await symbols.updateProjectItem('projectId', ['components', 'Button'], { color: 'red' })
|
|
684
|
+
await symbols.deleteProjectItem('projectId', ['pages', 'unused'])
|
|
685
|
+
await symbols.setProjectValue('projectId', ['settings', 'theme'], 'dark')
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
### Pull Request Management
|
|
689
|
+
```javascript
|
|
690
|
+
// Create pull request
|
|
691
|
+
const pr = await symbols.createPullRequest('projectId', {
|
|
692
|
+
source: 'feature/new-ui',
|
|
693
|
+
target: 'main',
|
|
694
|
+
title: 'Add new UI components',
|
|
695
|
+
description: 'Modern UI overhaul'
|
|
696
|
+
})
|
|
697
|
+
|
|
698
|
+
// List pull requests
|
|
699
|
+
const { pullRequests, pagination } = await symbols.listPullRequests('projectId', {
|
|
700
|
+
status: 'open',
|
|
701
|
+
page: 1,
|
|
702
|
+
limit: 10
|
|
703
|
+
})
|
|
704
|
+
|
|
705
|
+
// Review pull request
|
|
706
|
+
await symbols.approvePullRequest('projectId', 'pr_123', 'Great work!')
|
|
707
|
+
|
|
708
|
+
// Request changes
|
|
709
|
+
await symbols.requestPullRequestChanges('projectId', 'pr_123', [
|
|
710
|
+
{
|
|
711
|
+
file: 'src/Button.js',
|
|
712
|
+
line: 25,
|
|
713
|
+
comment: 'Add error handling',
|
|
714
|
+
type: 'issue'
|
|
715
|
+
}
|
|
716
|
+
])
|
|
717
|
+
|
|
718
|
+
// Merge pull request
|
|
719
|
+
await symbols.mergePullRequest('projectId', 'pr_123')
|
|
720
|
+
|
|
721
|
+
// Get diff
|
|
722
|
+
const diff = await symbols.getPullRequestDiff('projectId', 'pr_123')
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
### Branch Management
|
|
726
|
+
```javascript
|
|
727
|
+
// List branches
|
|
728
|
+
const branches = await symbols.listBranches('projectId')
|
|
729
|
+
|
|
730
|
+
// Create branch
|
|
731
|
+
await symbols.createFeatureBranch('projectId', 'user authentication')
|
|
732
|
+
// Creates: 'feature/user-authentication'
|
|
733
|
+
|
|
734
|
+
// Check branch status
|
|
735
|
+
const status = await symbols.getBranchStatus('projectId', 'feature/new-ui')
|
|
736
|
+
|
|
737
|
+
// Preview merge
|
|
738
|
+
const preview = await symbols.previewMerge('projectId', 'feature/new-ui', 'main')
|
|
739
|
+
if (preview.data.conflicts.length === 0) {
|
|
740
|
+
// Commit merge if no conflicts
|
|
741
|
+
await symbols.commitMerge('projectId', 'feature/new-ui', {
|
|
742
|
+
message: 'Add new UI features',
|
|
743
|
+
type: 'minor'
|
|
744
|
+
})
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Delete branch safely
|
|
748
|
+
await symbols.deleteBranchSafely('projectId', 'feature/old-feature')
|
|
749
|
+
|
|
750
|
+
// Publish version
|
|
751
|
+
await symbols.publishVersion('projectId', {
|
|
752
|
+
version: '1.2.0',
|
|
753
|
+
branch: 'main'
|
|
754
|
+
})
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
## Error Handling
|
|
758
|
+
|
|
759
|
+
The SDK provides comprehensive error handling for all scenarios:
|
|
760
|
+
|
|
761
|
+
```javascript
|
|
762
|
+
try {
|
|
763
|
+
await symbols.mergePullRequest('projectId', 'pr_123')
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (error.message.includes('conflicts')) {
|
|
766
|
+
// Handle merge conflicts
|
|
767
|
+
console.log('Manual conflict resolution required')
|
|
768
|
+
} else if (error.message.includes('403')) {
|
|
769
|
+
// Handle permission errors
|
|
770
|
+
console.log('Insufficient permissions')
|
|
771
|
+
} else {
|
|
772
|
+
// Handle other errors
|
|
773
|
+
console.error('Operation failed:', error.message)
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
```
|
|
777
|
+
|
|
617
778
|
|
|
618
779
|
|
|
@@ -17,9 +17,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var environment_exports = {};
|
|
19
19
|
__export(environment_exports, {
|
|
20
|
-
default: () => environment_default
|
|
20
|
+
default: () => environment_default,
|
|
21
|
+
getConfig: () => getConfig
|
|
21
22
|
});
|
|
22
23
|
module.exports = __toCommonJS(environment_exports);
|
|
24
|
+
var import_utils = require("@domql/utils");
|
|
23
25
|
const CONFIG = {
|
|
24
26
|
// Common defaults for all environments
|
|
25
27
|
common: {
|
|
@@ -33,17 +35,18 @@ const CONFIG = {
|
|
|
33
35
|
},
|
|
34
36
|
// Environment-specific configurations
|
|
35
37
|
local: {
|
|
36
|
-
|
|
38
|
+
// local
|
|
39
|
+
baseUrl: "http://localhost:8080",
|
|
37
40
|
// For symstory api
|
|
38
41
|
socketUrl: "http://localhost:8080",
|
|
39
42
|
// For socket api
|
|
40
|
-
routerUrl: "http://localhost:
|
|
43
|
+
routerUrl: "http://localhost:8080",
|
|
41
44
|
// For router api
|
|
42
|
-
apiUrl: "http://localhost:
|
|
45
|
+
apiUrl: "http://localhost:8080",
|
|
43
46
|
// For server api
|
|
44
47
|
basedEnv: "development",
|
|
45
48
|
// For based api
|
|
46
|
-
basedProject: "platform-v2",
|
|
49
|
+
basedProject: "platform-v2-sm",
|
|
47
50
|
// For based api
|
|
48
51
|
basedOrg: "symbols",
|
|
49
52
|
// For based api
|
|
@@ -56,41 +59,51 @@ const CONFIG = {
|
|
|
56
59
|
}
|
|
57
60
|
},
|
|
58
61
|
development: {
|
|
59
|
-
baseUrl: "https://
|
|
60
|
-
socketUrl: "https://
|
|
61
|
-
routerUrl: "https://
|
|
62
|
-
apiUrl: "https://api.symbols.app",
|
|
62
|
+
baseUrl: "https://dev.api.symbols.app",
|
|
63
|
+
socketUrl: "https://dev.api.symbols.app",
|
|
64
|
+
routerUrl: "https://dev.api.symbols.app",
|
|
65
|
+
apiUrl: "https://dev.api.symbols.app",
|
|
63
66
|
basedEnv: "development",
|
|
64
|
-
basedProject: "platform-v2",
|
|
67
|
+
basedProject: "platform-v2-sm",
|
|
68
|
+
basedOrg: "symbols",
|
|
69
|
+
githubClientId: "Ov23liHxyWFBxS8f1gnF"
|
|
70
|
+
},
|
|
71
|
+
testing: {
|
|
72
|
+
baseUrl: "https://test.api.symbols.app",
|
|
73
|
+
socketUrl: "https://test.api.symbols.app",
|
|
74
|
+
routerUrl: "https://test.api.symbols.app",
|
|
75
|
+
apiUrl: "https://test.api.symbols.app",
|
|
76
|
+
basedEnv: "testing",
|
|
77
|
+
basedProject: "platform-v2-sm",
|
|
65
78
|
basedOrg: "symbols",
|
|
66
79
|
githubClientId: "Ov23liHxyWFBxS8f1gnF"
|
|
67
80
|
},
|
|
68
81
|
staging: {
|
|
69
|
-
baseUrl: "https://staging.
|
|
70
|
-
socketUrl: "https://staging.
|
|
71
|
-
routerUrl: "https://staging.
|
|
82
|
+
baseUrl: "https://staging.api.symbols.app",
|
|
83
|
+
socketUrl: "https://staging.api.symbols.app",
|
|
84
|
+
routerUrl: "https://staging.api.symbols.app",
|
|
72
85
|
apiUrl: "https://staging.api.symbols.app",
|
|
73
86
|
basedEnv: "staging",
|
|
74
|
-
basedProject: "platform-v2",
|
|
87
|
+
basedProject: "platform-v2-sm",
|
|
75
88
|
basedOrg: "symbols",
|
|
76
89
|
githubClientId: "Ov23ligwZDQVD0VfuWNa"
|
|
77
90
|
},
|
|
78
91
|
production: {
|
|
79
|
-
baseUrl: "https://
|
|
80
|
-
socketUrl: "https://
|
|
81
|
-
routerUrl: "https://
|
|
92
|
+
baseUrl: "https://api.symbols.app",
|
|
93
|
+
socketUrl: "https://api.symbols.app",
|
|
94
|
+
routerUrl: "https://api.symbols.app",
|
|
82
95
|
apiUrl: "https://api.symbols.app",
|
|
83
96
|
basedEnv: "production",
|
|
84
|
-
basedProject: "platform-v2",
|
|
97
|
+
basedProject: "platform-v2-sm",
|
|
85
98
|
basedOrg: "symbols",
|
|
86
99
|
githubClientId: "Ov23liFAlOEIXtX3dBtR"
|
|
87
100
|
}
|
|
88
101
|
};
|
|
89
102
|
const getEnvironment = () => {
|
|
90
|
-
|
|
103
|
+
// @preserve-env
|
|
104
|
+
const env = process.env.SYMBOLS_APP_ENV || process.env.NODE_ENV;
|
|
91
105
|
if (!CONFIG[env]) {
|
|
92
|
-
|
|
93
|
-
return "development";
|
|
106
|
+
throw new Error(`Unknown environment "${env}"`);
|
|
94
107
|
}
|
|
95
108
|
return env;
|
|
96
109
|
};
|
|
@@ -108,9 +121,11 @@ const getConfig = () => {
|
|
|
108
121
|
basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
|
|
109
122
|
basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
|
|
110
123
|
githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
|
|
111
|
-
isDevelopment:
|
|
124
|
+
isDevelopment: (0, import_utils.isDevelopment)(env),
|
|
125
|
+
isTesting: env === "testing",
|
|
112
126
|
isStaging: env === "staging",
|
|
113
127
|
isProduction: env === "production"
|
|
128
|
+
// Store all environment variables for potential future use
|
|
114
129
|
};
|
|
115
130
|
const requiredFields = [
|
|
116
131
|
"baseUrl",
|
|
@@ -131,9 +146,7 @@ const getConfig = () => {
|
|
|
131
146
|
if (finalConfig.isDevelopment) {
|
|
132
147
|
console.log(
|
|
133
148
|
"environment in SDK:",
|
|
134
|
-
env
|
|
135
|
-
"",
|
|
136
|
-
process.env.SYMBOLS_APP_ENV
|
|
149
|
+
env || process.env.NODE_ENV || process.env.NODE_ENV
|
|
137
150
|
);
|
|
138
151
|
console.log(finalConfig);
|
|
139
152
|
}
|
|
@@ -141,14 +154,7 @@ const getConfig = () => {
|
|
|
141
154
|
} catch (error) {
|
|
142
155
|
console.error("Failed to load environment configuration:", error);
|
|
143
156
|
return {
|
|
144
|
-
|
|
145
|
-
socketUrl: "https://socket.symbols.app",
|
|
146
|
-
routerUrl: "https://router.symbols.app",
|
|
147
|
-
apiUrl: "https://api.symbols.app",
|
|
148
|
-
basedEnv: "development",
|
|
149
|
-
basedProject: "platform-v2",
|
|
150
|
-
basedOrg: "symbols",
|
|
151
|
-
githubClientId: "Ov23liHxyWFBxS8f1gnF"
|
|
157
|
+
...CONFIG.development
|
|
152
158
|
};
|
|
153
159
|
}
|
|
154
160
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,6 +28,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
28
28
|
var index_exports = {};
|
|
29
29
|
__export(index_exports, {
|
|
30
30
|
SDK: () => SDK,
|
|
31
|
+
createAIService: () => import_services3.createAIService,
|
|
32
|
+
createAuthService: () => import_services3.createAuthService,
|
|
33
|
+
createCoreService: () => import_services3.createCoreService,
|
|
34
|
+
createSocketService: () => import_services3.createSocketService,
|
|
35
|
+
createSymstoryService: () => import_services3.createSymstoryService,
|
|
31
36
|
default: () => index_default,
|
|
32
37
|
environment: () => import_environment2.default
|
|
33
38
|
});
|
|
@@ -36,6 +41,7 @@ var import_services = require("./services/index.js");
|
|
|
36
41
|
var import_services2 = require("./utils/services.js");
|
|
37
42
|
var import_SymstoryService = require("./services/SymstoryService.js");
|
|
38
43
|
var import_environment = __toESM(require("./config/environment.js"), 1);
|
|
44
|
+
var import_services3 = require("./services/index.js");
|
|
39
45
|
var import_environment2 = __toESM(require("./config/environment.js"), 1);
|
|
40
46
|
class SDK {
|
|
41
47
|
constructor(options = {}) {
|
|
@@ -44,19 +50,13 @@ class SDK {
|
|
|
44
50
|
this._options = this._validateOptions(options);
|
|
45
51
|
this._createServiceProxies();
|
|
46
52
|
}
|
|
53
|
+
// Initialize SDK with context
|
|
47
54
|
async initialize(context = {}) {
|
|
48
55
|
this._context = {
|
|
49
56
|
...this._context,
|
|
50
57
|
...context
|
|
51
58
|
};
|
|
52
59
|
await Promise.all([
|
|
53
|
-
this._initService(
|
|
54
|
-
"based",
|
|
55
|
-
(0, import_services.createBasedService)({
|
|
56
|
-
context: this._context,
|
|
57
|
-
options: this._options
|
|
58
|
-
})
|
|
59
|
-
),
|
|
60
60
|
this._initService(
|
|
61
61
|
"auth",
|
|
62
62
|
(0, import_services.createAuthService)({
|
|
@@ -84,6 +84,13 @@ class SDK {
|
|
|
84
84
|
context: this._context,
|
|
85
85
|
options: this._options
|
|
86
86
|
})
|
|
87
|
+
),
|
|
88
|
+
this._initService(
|
|
89
|
+
"core",
|
|
90
|
+
(0, import_services.createCoreService)({
|
|
91
|
+
context: this._context,
|
|
92
|
+
options: this._options
|
|
93
|
+
})
|
|
87
94
|
)
|
|
88
95
|
]);
|
|
89
96
|
return this;
|
|
@@ -134,7 +141,8 @@ class SDK {
|
|
|
134
141
|
}
|
|
135
142
|
// Check if SDK is ready
|
|
136
143
|
isReady() {
|
|
137
|
-
|
|
144
|
+
const sdkServices = Array.from(this._services.values());
|
|
145
|
+
return sdkServices.length > 0 && sdkServices.every(
|
|
138
146
|
(service) => service.isReady()
|
|
139
147
|
);
|
|
140
148
|
}
|
|
@@ -165,5 +173,24 @@ class SDK {
|
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Destroys all services and cleans up resources
|
|
178
|
+
* @returns {Promise<boolean>} Returns true when cleanup is complete
|
|
179
|
+
*/
|
|
180
|
+
async destroy() {
|
|
181
|
+
try {
|
|
182
|
+
const destroyPromises = Array.from(this._services.entries()).filter(([, service]) => typeof service.destroy === "function").map(async ([name, service]) => {
|
|
183
|
+
await service.destroy();
|
|
184
|
+
console.log(`Service ${name} destroyed successfully`);
|
|
185
|
+
});
|
|
186
|
+
await Promise.all(destroyPromises);
|
|
187
|
+
this._services.clear();
|
|
188
|
+
this._context = {};
|
|
189
|
+
return true;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error("Error during SDK destruction:", error);
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
168
195
|
}
|
|
169
196
|
var index_default = SDK;
|
|
@@ -109,15 +109,53 @@ class AuthService extends import_BaseService.BaseService {
|
|
|
109
109
|
async googleAuth(idToken) {
|
|
110
110
|
try {
|
|
111
111
|
const based = this._getBasedService("googleAuth");
|
|
112
|
-
|
|
112
|
+
const response = await based.call("users:google-auth", { idToken });
|
|
113
|
+
if (this._initialized) {
|
|
114
|
+
this.updateContext({ authToken: response.token });
|
|
115
|
+
}
|
|
116
|
+
based.setAuthState({
|
|
117
|
+
token: response.token,
|
|
118
|
+
userId: response.userId,
|
|
119
|
+
persistent: true
|
|
120
|
+
});
|
|
121
|
+
return response;
|
|
113
122
|
} catch (error) {
|
|
114
123
|
throw new Error(`Google auth failed: ${error.message}`);
|
|
115
124
|
}
|
|
116
125
|
}
|
|
126
|
+
async googleAuthCallback(code, redirectUri) {
|
|
127
|
+
try {
|
|
128
|
+
const based = this._getBasedService("googleAuthCallback");
|
|
129
|
+
const response = await based.call("users:google-auth-callback", {
|
|
130
|
+
code,
|
|
131
|
+
redirectUri
|
|
132
|
+
});
|
|
133
|
+
if (this._initialized) {
|
|
134
|
+
this.updateContext({ authToken: response.token });
|
|
135
|
+
}
|
|
136
|
+
based.setAuthState({
|
|
137
|
+
token: response.token,
|
|
138
|
+
userId: response.userId,
|
|
139
|
+
persistent: true
|
|
140
|
+
});
|
|
141
|
+
return response;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw new Error(`Google auth callback failed: ${error.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
117
146
|
async githubAuth(code) {
|
|
118
147
|
try {
|
|
119
148
|
const based = this._getBasedService("githubAuth");
|
|
120
|
-
|
|
149
|
+
const response = await based.call("users:github-auth", { code });
|
|
150
|
+
if (this._initialized) {
|
|
151
|
+
this.updateContext({ authToken: response.token });
|
|
152
|
+
}
|
|
153
|
+
based.setAuthState({
|
|
154
|
+
token: response.token,
|
|
155
|
+
userId: response.userId,
|
|
156
|
+
persistent: true
|
|
157
|
+
});
|
|
158
|
+
return response;
|
|
121
159
|
} catch (error) {
|
|
122
160
|
throw new Error(`GitHub auth failed: ${error.message}`);
|
|
123
161
|
}
|
|
@@ -126,7 +164,7 @@ class AuthService extends import_BaseService.BaseService {
|
|
|
126
164
|
this._requireReady("logout");
|
|
127
165
|
try {
|
|
128
166
|
const based = this._getBasedService("logout");
|
|
129
|
-
await based.call("logout");
|
|
167
|
+
await based.call("users:logout");
|
|
130
168
|
this.updateContext({ authToken: null });
|
|
131
169
|
} catch (error) {
|
|
132
170
|
throw new Error(`Logout failed: ${error.message}`);
|
|
@@ -308,6 +346,7 @@ class AuthService extends import_BaseService.BaseService {
|
|
|
308
346
|
}, 0);
|
|
309
347
|
}
|
|
310
348
|
async getProjectMembers(projectId) {
|
|
349
|
+
var _a;
|
|
311
350
|
this._requireReady("getProjectMembers");
|
|
312
351
|
if (!projectId) {
|
|
313
352
|
throw new Error("Project ID is required");
|
|
@@ -316,6 +355,8 @@ class AuthService extends import_BaseService.BaseService {
|
|
|
316
355
|
const based = this._getBasedService("getProjectMembers");
|
|
317
356
|
return await based.call("projects:get-members", { projectId });
|
|
318
357
|
} catch (error) {
|
|
358
|
+
if ((_a = error.message) == null ? void 0 : _a.includes("Authentication failed. Please try again"))
|
|
359
|
+
window.location.reload();
|
|
319
360
|
throw new Error(`Failed to get project members: ${error.message}`);
|
|
320
361
|
}
|
|
321
362
|
}
|