@symbo.ls/sdk 3.2.3 → 3.2.7

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.
Files changed (183) hide show
  1. package/README.md +141 -0
  2. package/dist/cjs/config/environment.js +94 -10
  3. package/dist/cjs/index.js +152 -12
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +439 -116
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +60 -4
  23. package/dist/cjs/state/RootStateManager.js +2 -23
  24. package/dist/cjs/state/rootEventBus.js +9 -0
  25. package/dist/cjs/utils/CollabClient.js +78 -12
  26. package/dist/cjs/utils/TokenManager.js +16 -3
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +46 -4
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +285 -128
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +94 -10
  33. package/dist/esm/index.js +47862 -18248
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +24956 -16089
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +47373 -18027
  53. package/dist/esm/state/RootStateManager.js +11 -23
  54. package/dist/esm/state/rootEventBus.js +9 -0
  55. package/dist/esm/utils/CollabClient.js +17526 -16120
  56. package/dist/esm/utils/TokenManager.js +16 -3
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +958 -43
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +285 -128
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +94 -10
  63. package/dist/node/index.js +183 -16
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +439 -116
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +60 -4
  83. package/dist/node/state/RootStateManager.js +2 -23
  84. package/dist/node/state/rootEventBus.js +9 -0
  85. package/dist/node/utils/CollabClient.js +77 -11
  86. package/dist/node/utils/TokenManager.js +16 -3
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +46 -4
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +285 -128
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +30 -18
  93. package/src/config/environment.js +95 -10
  94. package/src/index.js +190 -23
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +557 -148
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +79 -5
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +37 -32
  148. package/src/state/rootEventBus.js +19 -0
  149. package/src/utils/CollabClient.js +99 -12
  150. package/src/utils/TokenManager.js +20 -3
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +40 -5
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +306 -139
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -2295
  159. package/dist/cjs/services/SocketService.js +0 -309
  160. package/dist/cjs/services/SymstoryService.js +0 -571
  161. package/dist/cjs/utils/basedQuerys.js +0 -181
  162. package/dist/cjs/utils/symstoryClient.js +0 -259
  163. package/dist/esm/services/AIService.js +0 -185
  164. package/dist/esm/services/BasedService.js +0 -5262
  165. package/dist/esm/services/CoreService.js +0 -2827
  166. package/dist/esm/services/SocketService.js +0 -456
  167. package/dist/esm/services/SymstoryService.js +0 -7025
  168. package/dist/esm/utils/basedQuerys.js +0 -163
  169. package/dist/esm/utils/symstoryClient.js +0 -354
  170. package/dist/node/services/AIService.js +0 -136
  171. package/dist/node/services/BasedService.js +0 -1156
  172. package/dist/node/services/CoreService.js +0 -2266
  173. package/dist/node/services/SocketService.js +0 -280
  174. package/dist/node/services/SymstoryService.js +0 -542
  175. package/dist/node/utils/basedQuerys.js +0 -162
  176. package/dist/node/utils/symstoryClient.js +0 -230
  177. package/src/services/AIService.js +0 -150
  178. package/src/services/BasedService.js +0 -1302
  179. package/src/services/CoreService.js +0 -2548
  180. package/src/services/SocketService.js +0 -336
  181. package/src/services/SymstoryService.js +0 -649
  182. package/src/utils/basedQuerys.js +0 -164
  183. package/src/utils/symstoryClient.js +0 -252
@@ -1,163 +0,0 @@
1
- // src/utils/basedQuerys.js
2
- var buildProjectQuery = (projectId) => ({
3
- $id: projectId,
4
- $all: true,
5
- createdAt: true,
6
- updatedAt: true,
7
- package: true,
8
- schema: true,
9
- bucket: true,
10
- settings: true,
11
- tier: true,
12
- members: {
13
- $list: { $inherit: true },
14
- id: true,
15
- name: true,
16
- username: true,
17
- email: true,
18
- state: true,
19
- roles: {
20
- $list: { $inherit: true },
21
- $all: true
22
- }
23
- },
24
- users: {
25
- $list: { $inherit: true },
26
- $all: true
27
- }
28
- });
29
- var buildUserQuery = (userId) => ({
30
- $id: userId,
31
- name: true,
32
- username: true,
33
- email: true,
34
- state: true,
35
- roles: {
36
- $list: { $inherit: true },
37
- $all: true
38
- }
39
- });
40
- var buildGetUserDataQuery = (userId) => ({
41
- $id: userId,
42
- id: true,
43
- name: true,
44
- email: true,
45
- username: true,
46
- globalRole: true,
47
- updatedAt: true,
48
- createdAt: true,
49
- memberProjects: {
50
- $list: true,
51
- id: true,
52
- role: true,
53
- createdAt: true,
54
- updatedAt: true,
55
- project: {
56
- id: true,
57
- key: true,
58
- name: true,
59
- thumbnail: true,
60
- icon: true,
61
- tier: true,
62
- visibility: true,
63
- access: true,
64
- members: {
65
- $list: true,
66
- user: {
67
- id: true,
68
- name: true,
69
- email: true,
70
- globalRole: true
71
- },
72
- role: true,
73
- updatedAt: true,
74
- createdAt: true
75
- }
76
- }
77
- }
78
- });
79
- var buildGetProjectsByKeysQuery = (keys) => ({
80
- projects: {
81
- id: true,
82
- key: true,
83
- name: true,
84
- thumbnail: true,
85
- icon: true,
86
- tier: true,
87
- visibility: true,
88
- access: true,
89
- members: {
90
- $list: true,
91
- user: {
92
- id: true,
93
- name: true,
94
- email: true,
95
- globalRole: true
96
- },
97
- role: true,
98
- updatedAt: true,
99
- createdAt: true
100
- },
101
- $list: {
102
- $find: {
103
- $traverse: "children",
104
- $filter: [
105
- { $field: "type", $operator: "=", $value: "project" },
106
- { $field: "key", $operator: "=", $value: keys }
107
- ]
108
- }
109
- }
110
- }
111
- });
112
- var GetProjectFields = {
113
- id: true,
114
- name: true,
115
- key: true,
116
- tier: true,
117
- projectType: true,
118
- icon: true,
119
- package: true,
120
- seats: true,
121
- projectPassword: true,
122
- stripe: true,
123
- payments: {
124
- $list: true,
125
- id: true,
126
- name: true
127
- },
128
- access: true,
129
- isSharedLibrary: true,
130
- framework: true,
131
- designTool: true,
132
- language: true,
133
- visibility: true,
134
- domains: true,
135
- subscription: { id: true },
136
- members: {
137
- $list: true,
138
- user: { id: true, name: true, email: true },
139
- role: true
140
- }
141
- };
142
- var buildGetProjectDataQuery = (projectId) => ({
143
- $id: projectId,
144
- ...GetProjectFields
145
- });
146
- var buildGetProjectByKeyDataQuery = (key) => ({
147
- ...GetProjectFields,
148
- $find: {
149
- $traverse: "children",
150
- $filter: [
151
- { $field: "type", $operator: "=", $value: "project" },
152
- { $field: "key", $operator: "=", $value: key }
153
- ]
154
- }
155
- });
156
- export {
157
- buildGetProjectByKeyDataQuery,
158
- buildGetProjectDataQuery,
159
- buildGetProjectsByKeysQuery,
160
- buildGetUserDataQuery,
161
- buildProjectQuery,
162
- buildUserQuery
163
- };
@@ -1,354 +0,0 @@
1
- // src/config/environment.js
2
- import { isDevelopment } from "@domql/utils";
3
- var CONFIG = {
4
- // Common defaults for all environments
5
- common: {
6
- // NOTE: Google client id for google auth, need to configure URLs for each environment in Google console
7
- googleClientId: "686286207466-bvd2fqs31rlm64fgich7rtpnc8ns2tqg.apps.googleusercontent.com",
8
- // Feature toggles that apply across all environments by default
9
- features: {
10
- newUserOnboarding: true,
11
- betaFeatures: false
12
- }
13
- },
14
- // Environment-specific configurations
15
- local: {
16
- // local
17
- socketUrl: "http://localhost:8080",
18
- // For socket api
19
- apiUrl: "http://localhost:8080",
20
- // For server api
21
- basedEnv: "development",
22
- // For based api
23
- basedProject: "platform-v2-sm",
24
- // For based api
25
- basedOrg: "symbols",
26
- // For based api
27
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
28
- // For github api
29
- // Environment-specific feature toggles (override common)
30
- features: {
31
- betaFeatures: true
32
- // Enable beta features in local dev
33
- }
34
- },
35
- development: {
36
- socketUrl: "https://dev.api.symbols.app",
37
- apiUrl: "https://dev.api.symbols.app",
38
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
39
- },
40
- testing: {
41
- socketUrl: "https://test.api.symbols.app",
42
- apiUrl: "https://test.api.symbols.app",
43
- basedEnv: "testing",
44
- basedProject: "platform-v2-sm",
45
- basedOrg: "symbols",
46
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
47
- },
48
- upcoming: {
49
- socketUrl: "https://upcoming.api.symbols.app",
50
- apiUrl: "https://upcoming.api.symbols.app",
51
- githubClientId: "Ov23liWF7NvdZ056RV5J"
52
- },
53
- staging: {
54
- socketUrl: "https://staging.api.symbols.app",
55
- apiUrl: "https://staging.api.symbols.app",
56
- basedEnv: "staging",
57
- basedProject: "platform-v2-sm",
58
- basedOrg: "symbols",
59
- githubClientId: "Ov23ligwZDQVD0VfuWNa"
60
- },
61
- production: {
62
- socketUrl: "https://api.symbols.app",
63
- apiUrl: "https://api.symbols.app",
64
- basedEnv: "production",
65
- basedProject: "platform-v2-sm",
66
- basedOrg: "symbols",
67
- githubClientId: "Ov23liFAlOEIXtX3dBtR"
68
- }
69
- };
70
- var getEnvironment = () => {
71
- const env = process.env.SYMBOLS_APP_ENV || process.env.NODE_ENV;
72
- if (!CONFIG[env]) {
73
- throw new Error(`Unknown environment "${env}"`);
74
- }
75
- return env;
76
- };
77
- var getConfig = () => {
78
- try {
79
- const env = getEnvironment();
80
- const envConfig = { ...CONFIG.common, ...CONFIG[env] };
81
- const finalConfig = {
82
- ...envConfig,
83
- socketUrl: process.env.SYMBOLS_APP_SOCKET_URL || envConfig.socketUrl,
84
- apiUrl: process.env.SYMBOLS_APP_API_URL || envConfig.apiUrl,
85
- basedEnv: process.env.SYMBOLS_APP_BASED_ENV || envConfig.basedEnv,
86
- basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
87
- basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
88
- githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
89
- isDevelopment: isDevelopment(env),
90
- isTesting: env === "testing",
91
- isStaging: env === "staging",
92
- isProduction: env === "production"
93
- // Store all environment variables for potential future use
94
- };
95
- const requiredFields = [
96
- "socketUrl",
97
- "apiUrl",
98
- "githubClientId",
99
- "googleClientId"
100
- ];
101
- const missingFields = requiredFields.filter((field) => !finalConfig[field]);
102
- if (missingFields.length > 0) {
103
- console.error(
104
- `Missing required configuration: ${missingFields.join(", ")}`
105
- );
106
- }
107
- if (finalConfig.isDevelopment) {
108
- console.log(
109
- "environment in SDK:",
110
- env || process.env.NODE_ENV || process.env.NODE_ENV
111
- );
112
- console.log(finalConfig);
113
- }
114
- return finalConfig;
115
- } catch (error) {
116
- console.error("Failed to load environment configuration:", error);
117
- return {
118
- ...CONFIG.development
119
- };
120
- }
121
- };
122
- var environment_default = getConfig();
123
-
124
- // src/utils/symstoryClient.js
125
- var DEFAULT_OPTIONS = {
126
- apiUrl: environment_default.apiUrl
127
- };
128
- var SymstoryClient = class {
129
- /**
130
- * Creates an instance of SymstoryClient.
131
- * @param {string} appKey - The application key.
132
- * @param {object} [options={}] - The options for the client.
133
- */
134
- constructor(appKey, options = {}) {
135
- if (!appKey) {
136
- throw new Error("AppKey is required");
137
- }
138
- this.appKey = appKey;
139
- this.options = { ...DEFAULT_OPTIONS, ...options };
140
- this.headers = {
141
- "Content-Type": "application/json",
142
- ...this.options.headers,
143
- "X-AppKey": appKey
144
- };
145
- }
146
- /**
147
- * Makes a request to the Symstory service.
148
- * @param {string} [path=''] - The request path.
149
- * @param {object} [options={}] - The request options.
150
- * @returns {Promise<any>} - The response data.
151
- */
152
- async request(path = "", options = {}) {
153
- const url = `${this.options.apiUrl}/symstory/${this.appKey}${path}`;
154
- const response = await fetch(url, {
155
- ...options,
156
- headers: { ...this.headers, ...options.headers }
157
- });
158
- if (!response.ok) {
159
- const error = await response.json();
160
- throw new Error(error.message || error.error || "Request failed");
161
- }
162
- return response.status === 204 ? null : response.json();
163
- }
164
- /**
165
- * Fetches project data.
166
- * @param {object} query - The query object to filter data.
167
- * @param {string|null} [branch=null] - The branch name.
168
- * @param {string|null} [version=null] - The version number.
169
- * @returns {Promise<any>} - The project data.
170
- */
171
- get(query, branch = null, version = null) {
172
- const params = new URLSearchParams({
173
- ...branch && { branch },
174
- ...version ? { version } : { cacheId: Math.random() },
175
- ...query && { query: JSON.stringify(query) }
176
- });
177
- return this.request(`?${params}`);
178
- }
179
- /**
180
- * Sets a value at the specified path.
181
- * @param {string} path - The path where the value should be set.
182
- * @param {any} value - The value to set.
183
- * @returns {Promise<any>} - The response data.
184
- */
185
- set(path, value) {
186
- return this.request("", {
187
- method: "POST",
188
- body: JSON.stringify({ changes: [["update", path, value]] })
189
- });
190
- }
191
- /**
192
- * Updates project data.
193
- * @param {Array} changes - The changes to apply.
194
- * @param {object} [options={}] - The update options.
195
- * @param {string} [options.type='patch'] - The type of update.
196
- * @param {string} [options.message=''] - A message describing the update.
197
- * @param {string} [options.branch='main'] - The branch name.
198
- * @returns {Promise<any>} - The response data.
199
- */
200
- async update(changes, { type = "patch", message = "", branch = "main" } = {}) {
201
- return await this.request("", {
202
- method: "POST",
203
- body: JSON.stringify({ changes, type, message, branch })
204
- });
205
- }
206
- /**
207
- * Retrieves all branches of the project.
208
- * @returns {Promise<any>} - The branches data.
209
- */
210
- getBranches() {
211
- return this.request("/branches");
212
- }
213
- /**
214
- * Creates a new branch.
215
- * @param {string} branch - The name of the new branch.
216
- * @param {object} [options={}] - The branch creation options.
217
- * @param {string} [options.message] - A message describing the branch creation.
218
- * @param {string} [options.source='main'] - The source branch.
219
- * @param {string} [options.version] - The version number.
220
- * @returns {Promise<any>} - The response data.
221
- */
222
- createBranch(branch, { message, source = "main", version } = {}) {
223
- return this.request("/branch", {
224
- method: "POST",
225
- body: JSON.stringify({ branch, message, source, version })
226
- });
227
- }
228
- /**
229
- * Edit an existing branch. (For now only supports branch renaming)
230
- * @param {string} branch - The current name of the branch to edit.
231
- * @param {object} [options={}] - The branch edit options.
232
- * @param {string} [options.name] - New name for the branch
233
- * @returns {Promise<any>} - The response data.
234
- */
235
- editBranch(branch, { name } = {}) {
236
- return this.request("/branch", {
237
- method: "PATCH",
238
- body: JSON.stringify({ branch, name })
239
- });
240
- }
241
- /**
242
- * Delete an existing branch.
243
- * @param {string} branch - The name of the branch to delete.
244
- * @returns {Promise<any>} - The response data.
245
- */
246
- deleteBranch(branch) {
247
- return this.request("/branch", {
248
- method: "DELETE",
249
- body: JSON.stringify({ branch })
250
- });
251
- }
252
- /**
253
- * Merges a branch into the target branch.
254
- * @param {string} target - The target branch.
255
- * @param {object} [options={}] - The merge options.
256
- * @param {string} [options.message] - A message describing the merge.
257
- * @param {string} [options.source='main'] - The source branch.
258
- * @param {string} [options.type='patch'] - The type of merge.
259
- * @param {string} [options.version] - The version number.
260
- * @param {boolean} [options.commit='false'] - Whether to commit the merge.
261
- * @param {Array} [options.changes] - The changes to apply during the merge.
262
- * @returns {Promise<any>} - The response data.
263
- */
264
- mergeBranch(target, {
265
- message,
266
- source = "main",
267
- type = "patch",
268
- version,
269
- commit = "false",
270
- changes
271
- } = {}) {
272
- return this.request("/merge", {
273
- method: "POST",
274
- body: JSON.stringify({
275
- target,
276
- source,
277
- message,
278
- type,
279
- version,
280
- commit,
281
- changes
282
- })
283
- });
284
- }
285
- /**
286
- * Restores an older version of the project.
287
- * @param {string} version - The version number to restore.
288
- * @param {object} [options={}] - The restore options.
289
- * @param {string} [options.branch='main'] - The branch name.
290
- * @param {string} [options.type='patch'] - The type of restore.
291
- * @param {string} [options.message] - A message describing the restore.
292
- * @returns {Promise<any>} - The response data.
293
- */
294
- restoreVersion(version, { branch = "main", type = "patch", message } = {}) {
295
- return this.request("/restore", {
296
- method: "POST",
297
- body: JSON.stringify({ branch, version, type, message })
298
- });
299
- }
300
- /**
301
- * Publishes an existing version of the project.
302
- * @param {string} version - The version ID/number to publish.
303
- * @param {object} [options={}] - The publishing options.
304
- * @param {string} [options.branch='main'] - The branch name. (Only if version number is provided)
305
- * @returns {Promise<any>} - The response data.
306
- */
307
- publishVersion(version) {
308
- return this.request("/publish", {
309
- method: "POST",
310
- body: JSON.stringify({ version })
311
- });
312
- }
313
- /**
314
- * Retrieves all changes after a specific version.
315
- * @param {object} [options={}] - The changes options.
316
- * @param {string} [options.versionId] - The version ID to publish.
317
- * @param {string} [options.versionValue] - The version ID to publish. (alternative to versionId)
318
- * @param {string} [options.branch] - The branch to publish (Only in combination to versionValue)
319
- * @returns {Promise<any>} - The changes data.
320
- */
321
- getChanges({ versionId, versionValue, branch } = {}) {
322
- return this.request(
323
- `/changes?${new URLSearchParams({
324
- ...versionId ? { versionId } : {},
325
- ...versionValue ? { versionValue } : {},
326
- ...branch ? { branch } : {}
327
- }).toString()}`,
328
- {}
329
- );
330
- }
331
- };
332
- var symstoryClient_default = {
333
- /**
334
- * Creates a new SymstoryClient instance.
335
- * @param {string} appKey - The application key.
336
- * @param {object} options - The options for the client.
337
- * @returns {SymstoryClient} - The SymstoryClient instance.
338
- */
339
- create: (appKey, options) => new SymstoryClient(appKey, options),
340
- /**
341
- * Initializes the Symstory client.
342
- * @param {string} appKey - The application key.
343
- * @param {object} options - The options for the client.
344
- * @returns {SymstoryClient} - The initialized SymstoryClient instance.
345
- */
346
- init(appKey, options) {
347
- this.client = this.create(appKey, options);
348
- return this;
349
- }
350
- };
351
- export {
352
- symstoryClient_default as default
353
- };
354
- // @preserve-env
@@ -1,136 +0,0 @@
1
- import { BaseService } from "./BaseService.js";
2
- class AIService extends BaseService {
3
- constructor(config) {
4
- super(config);
5
- this._client = null;
6
- this._initialized = false;
7
- this._defaultConfig = {
8
- apiUrl: "https://api.openai.com/v1/engines/text-curie/completions",
9
- temperature: 0,
10
- maxTokens: 2e3,
11
- headers: {
12
- "Content-Type": "application/json"
13
- }
14
- };
15
- }
16
- init() {
17
- try {
18
- const { appKey, authToken } = this._context;
19
- this._info = {
20
- config: {
21
- appKey: appKey ? `${appKey.substr(0, 4)}...${appKey.substr(-4)}` : "",
22
- hasToken: Boolean(authToken)
23
- }
24
- };
25
- this._initialized = true;
26
- this._setReady();
27
- } catch (error) {
28
- this._setError(error);
29
- throw error;
30
- }
31
- }
32
- // Helper to check if method requires initialization
33
- _requiresInit(methodName) {
34
- const noInitMethods = /* @__PURE__ */ new Set(["getConfig", "validateConfig"]);
35
- return !noInitMethods.has(methodName);
36
- }
37
- // Override _requireReady to be more flexible
38
- _requireReady(methodName) {
39
- if (this._requiresInit(methodName) && !this._initialized) {
40
- throw new Error("AI service not initialized");
41
- }
42
- }
43
- // Configuration methods
44
- getConfig() {
45
- var _a;
46
- return {
47
- ...this._defaultConfig,
48
- ...(_a = this._context.ai) == null ? void 0 : _a.config
49
- };
50
- }
51
- validateConfig(config = {}) {
52
- const requiredFields = ["apiUrl", "temperature", "maxTokens"];
53
- const missingFields = requiredFields.filter((field) => !config[field]);
54
- if (missingFields.length > 0) {
55
- throw new Error(
56
- `Missing required configuration fields: ${missingFields.join(", ")}`
57
- );
58
- }
59
- return true;
60
- }
61
- // AI Methods
62
- async prompt(query, opts = {}) {
63
- var _a;
64
- this._requireReady("prompt");
65
- try {
66
- const config = this.getConfig();
67
- const options = {
68
- method: "POST",
69
- headers: {
70
- ...config.headers,
71
- Authorization: `Bearer ${(_a = this._context.ai) == null ? void 0 : _a.authToken}`
72
- },
73
- body: JSON.stringify({
74
- prompt: query,
75
- temperature: opts.temperature || config.temperature,
76
- max_tokens: opts.maxTokens || config.maxTokens,
77
- ...opts
78
- })
79
- };
80
- const response = await this._request(config.apiUrl, options);
81
- return response;
82
- } catch (error) {
83
- throw new Error(`AI prompt failed: ${error.message}`);
84
- }
85
- }
86
- // Helper methods
87
- async _request(url, options = {}) {
88
- try {
89
- const response = await fetch(url, {
90
- ...options,
91
- headers: {
92
- ...this._defaultConfig.headers,
93
- ...options.headers
94
- }
95
- });
96
- if (!response.ok) {
97
- const error = await response.json();
98
- throw new Error(error.message || "Request failed");
99
- }
100
- return response.status === 204 ? null : response.json();
101
- } catch (error) {
102
- throw new Error(`Request failed: ${error.message}`);
103
- }
104
- }
105
- // Context update methods
106
- updateAuth(authToken) {
107
- this.updateContext({
108
- ai: {
109
- ...this._context.ai,
110
- authToken
111
- }
112
- });
113
- }
114
- updateConfig(config) {
115
- var _a;
116
- this.validateConfig(config);
117
- this.updateContext({
118
- ai: {
119
- ...this._context.ai,
120
- config: {
121
- ...(_a = this._context.ai) == null ? void 0 : _a.config,
122
- ...config
123
- }
124
- }
125
- });
126
- }
127
- // Cleanup
128
- destroy() {
129
- this._client = null;
130
- this._initialized = false;
131
- this._setReady(false);
132
- }
133
- }
134
- export {
135
- AIService
136
- };