@symbo.ls/sdk 3.1.2 → 3.2.6

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 (187) hide show
  1. package/README.md +143 -2
  2. package/dist/cjs/config/environment.js +98 -30
  3. package/dist/cjs/index.js +144 -24
  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 +743 -0
  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 +64 -16
  23. package/dist/cjs/state/RootStateManager.js +65 -0
  24. package/dist/cjs/state/rootEventBus.js +74 -0
  25. package/dist/cjs/utils/CollabClient.js +223 -0
  26. package/dist/cjs/utils/TokenManager.js +78 -30
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +145 -0
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +301 -103
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +98 -30
  33. package/dist/esm/index.js +49505 -8718
  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 +26895 -0
  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 +49062 -8569
  53. package/dist/esm/state/RootStateManager.js +90 -0
  54. package/dist/esm/state/rootEventBus.js +56 -0
  55. package/dist/esm/utils/CollabClient.js +18889 -0
  56. package/dist/esm/utils/TokenManager.js +78 -30
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +7011 -0
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +301 -103
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +98 -30
  63. package/dist/node/index.js +175 -32
  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 +724 -0
  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 +64 -16
  83. package/dist/node/state/RootStateManager.js +36 -0
  84. package/dist/node/state/rootEventBus.js +55 -0
  85. package/dist/node/utils/CollabClient.js +194 -0
  86. package/dist/node/utils/TokenManager.js +78 -30
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +116 -0
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +301 -103
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +39 -21
  93. package/src/config/environment.js +99 -28
  94. package/src/index.js +181 -36
  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 +900 -0
  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 +80 -13
  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 +76 -0
  148. package/src/state/rootEventBus.js +67 -0
  149. package/src/utils/CollabClient.js +248 -0
  150. package/src/utils/TokenManager.js +88 -33
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +144 -0
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +326 -107
  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 -1751
  159. package/dist/cjs/services/SocketIOService.js +0 -307
  160. package/dist/cjs/services/SocketService.js +0 -161
  161. package/dist/cjs/services/SymstoryService.js +0 -571
  162. package/dist/cjs/utils/basedQuerys.js +0 -181
  163. package/dist/cjs/utils/symstoryClient.js +0 -259
  164. package/dist/esm/services/AIService.js +0 -185
  165. package/dist/esm/services/BasedService.js +0 -5278
  166. package/dist/esm/services/CoreService.js +0 -2264
  167. package/dist/esm/services/SocketIOService.js +0 -470
  168. package/dist/esm/services/SocketService.js +0 -191
  169. package/dist/esm/services/SymstoryService.js +0 -7041
  170. package/dist/esm/utils/basedQuerys.js +0 -163
  171. package/dist/esm/utils/symstoryClient.js +0 -370
  172. package/dist/node/services/AIService.js +0 -136
  173. package/dist/node/services/BasedService.js +0 -1156
  174. package/dist/node/services/CoreService.js +0 -1722
  175. package/dist/node/services/SocketIOService.js +0 -278
  176. package/dist/node/services/SocketService.js +0 -142
  177. package/dist/node/services/SymstoryService.js +0 -542
  178. package/dist/node/utils/basedQuerys.js +0 -162
  179. package/dist/node/utils/symstoryClient.js +0 -230
  180. package/src/services/AIService.js +0 -150
  181. package/src/services/BasedService.js +0 -1301
  182. package/src/services/CoreService.js +0 -1943
  183. package/src/services/SocketIOService.js +0 -334
  184. package/src/services/SocketService.js +0 -168
  185. package/src/services/SymstoryService.js +0 -649
  186. package/src/utils/basedQuerys.js +0 -164
  187. package/src/utils/symstoryClient.js +0 -252
@@ -1,181 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var basedQuerys_exports = {};
19
- __export(basedQuerys_exports, {
20
- buildGetProjectByKeyDataQuery: () => buildGetProjectByKeyDataQuery,
21
- buildGetProjectDataQuery: () => buildGetProjectDataQuery,
22
- buildGetProjectsByKeysQuery: () => buildGetProjectsByKeysQuery,
23
- buildGetUserDataQuery: () => buildGetUserDataQuery,
24
- buildProjectQuery: () => buildProjectQuery,
25
- buildUserQuery: () => buildUserQuery
26
- });
27
- module.exports = __toCommonJS(basedQuerys_exports);
28
- const buildProjectQuery = (projectId) => ({
29
- $id: projectId,
30
- $all: true,
31
- createdAt: true,
32
- updatedAt: true,
33
- package: true,
34
- schema: true,
35
- bucket: true,
36
- settings: true,
37
- tier: true,
38
- members: {
39
- $list: { $inherit: true },
40
- id: true,
41
- name: true,
42
- username: true,
43
- email: true,
44
- state: true,
45
- roles: {
46
- $list: { $inherit: true },
47
- $all: true
48
- }
49
- },
50
- users: {
51
- $list: { $inherit: true },
52
- $all: true
53
- }
54
- });
55
- const buildUserQuery = (userId) => ({
56
- $id: userId,
57
- name: true,
58
- username: true,
59
- email: true,
60
- state: true,
61
- roles: {
62
- $list: { $inherit: true },
63
- $all: true
64
- }
65
- });
66
- const buildGetUserDataQuery = (userId) => ({
67
- $id: userId,
68
- id: true,
69
- name: true,
70
- email: true,
71
- username: true,
72
- globalRole: true,
73
- updatedAt: true,
74
- createdAt: true,
75
- memberProjects: {
76
- $list: true,
77
- id: true,
78
- role: true,
79
- createdAt: true,
80
- updatedAt: true,
81
- project: {
82
- id: true,
83
- key: true,
84
- name: true,
85
- thumbnail: true,
86
- icon: true,
87
- tier: true,
88
- visibility: true,
89
- access: true,
90
- members: {
91
- $list: true,
92
- user: {
93
- id: true,
94
- name: true,
95
- email: true,
96
- globalRole: true
97
- },
98
- role: true,
99
- updatedAt: true,
100
- createdAt: true
101
- }
102
- }
103
- }
104
- });
105
- const buildGetProjectsByKeysQuery = (keys) => ({
106
- projects: {
107
- id: true,
108
- key: true,
109
- name: true,
110
- thumbnail: true,
111
- icon: true,
112
- tier: true,
113
- visibility: true,
114
- access: true,
115
- members: {
116
- $list: true,
117
- user: {
118
- id: true,
119
- name: true,
120
- email: true,
121
- globalRole: true
122
- },
123
- role: true,
124
- updatedAt: true,
125
- createdAt: true
126
- },
127
- $list: {
128
- $find: {
129
- $traverse: "children",
130
- $filter: [
131
- { $field: "type", $operator: "=", $value: "project" },
132
- { $field: "key", $operator: "=", $value: keys }
133
- ]
134
- }
135
- }
136
- }
137
- });
138
- const GetProjectFields = {
139
- id: true,
140
- name: true,
141
- key: true,
142
- tier: true,
143
- projectType: true,
144
- icon: true,
145
- package: true,
146
- seats: true,
147
- projectPassword: true,
148
- stripe: true,
149
- payments: {
150
- $list: true,
151
- id: true,
152
- name: true
153
- },
154
- access: true,
155
- isSharedLibrary: true,
156
- framework: true,
157
- designTool: true,
158
- language: true,
159
- visibility: true,
160
- domains: true,
161
- subscription: { id: true },
162
- members: {
163
- $list: true,
164
- user: { id: true, name: true, email: true },
165
- role: true
166
- }
167
- };
168
- const buildGetProjectDataQuery = (projectId) => ({
169
- $id: projectId,
170
- ...GetProjectFields
171
- });
172
- const buildGetProjectByKeyDataQuery = (key) => ({
173
- ...GetProjectFields,
174
- $find: {
175
- $traverse: "children",
176
- $filter: [
177
- { $field: "type", $operator: "=", $value: "project" },
178
- { $field: "key", $operator: "=", $value: key }
179
- ]
180
- }
181
- });
@@ -1,259 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var symstoryClient_exports = {};
29
- __export(symstoryClient_exports, {
30
- default: () => symstoryClient_default
31
- });
32
- module.exports = __toCommonJS(symstoryClient_exports);
33
- var import_environment = __toESM(require("../config/environment.js"), 1);
34
- const DEFAULT_OPTIONS = {
35
- baseUrl: import_environment.default.baseUrl
36
- };
37
- class SymstoryClient {
38
- /**
39
- * Creates an instance of SymstoryClient.
40
- * @param {string} appKey - The application key.
41
- * @param {object} [options={}] - The options for the client.
42
- */
43
- constructor(appKey, options = {}) {
44
- if (!appKey) {
45
- throw new Error("AppKey is required");
46
- }
47
- this.appKey = appKey;
48
- this.options = { ...DEFAULT_OPTIONS, ...options };
49
- this.headers = {
50
- "Content-Type": "application/json",
51
- ...this.options.headers,
52
- "X-AppKey": appKey
53
- };
54
- }
55
- /**
56
- * Makes a request to the Symstory service.
57
- * @param {string} [path=''] - The request path.
58
- * @param {object} [options={}] - The request options.
59
- * @returns {Promise<any>} - The response data.
60
- */
61
- async request(path = "", options = {}) {
62
- const url = `${this.options.baseUrl}/symstory/${this.appKey}${path}`;
63
- const response = await fetch(url, {
64
- ...options,
65
- headers: { ...this.headers, ...options.headers }
66
- });
67
- if (!response.ok) {
68
- const error = await response.json();
69
- throw new Error(error.message || error.error || "Request failed");
70
- }
71
- return response.status === 204 ? null : response.json();
72
- }
73
- /**
74
- * Fetches project data.
75
- * @param {object} query - The query object to filter data.
76
- * @param {string|null} [branch=null] - The branch name.
77
- * @param {string|null} [version=null] - The version number.
78
- * @returns {Promise<any>} - The project data.
79
- */
80
- get(query, branch = null, version = null) {
81
- const params = new URLSearchParams({
82
- ...branch && { branch },
83
- ...version ? { version } : { cacheId: Math.random() },
84
- ...query && { query: JSON.stringify(query) }
85
- });
86
- return this.request(`?${params}`);
87
- }
88
- /**
89
- * Sets a value at the specified path.
90
- * @param {string} path - The path where the value should be set.
91
- * @param {any} value - The value to set.
92
- * @returns {Promise<any>} - The response data.
93
- */
94
- set(path, value) {
95
- return this.request("", {
96
- method: "POST",
97
- body: JSON.stringify({ changes: [["update", path, value]] })
98
- });
99
- }
100
- /**
101
- * Updates project data.
102
- * @param {Array} changes - The changes to apply.
103
- * @param {object} [options={}] - The update options.
104
- * @param {string} [options.type='patch'] - The type of update.
105
- * @param {string} [options.message=''] - A message describing the update.
106
- * @param {string} [options.branch='main'] - The branch name.
107
- * @returns {Promise<any>} - The response data.
108
- */
109
- async update(changes, { type = "patch", message = "", branch = "main" } = {}) {
110
- return await this.request("", {
111
- method: "POST",
112
- body: JSON.stringify({ changes, type, message, branch })
113
- });
114
- }
115
- /**
116
- * Retrieves all branches of the project.
117
- * @returns {Promise<any>} - The branches data.
118
- */
119
- getBranches() {
120
- return this.request("/branches");
121
- }
122
- /**
123
- * Creates a new branch.
124
- * @param {string} branch - The name of the new branch.
125
- * @param {object} [options={}] - The branch creation options.
126
- * @param {string} [options.message] - A message describing the branch creation.
127
- * @param {string} [options.source='main'] - The source branch.
128
- * @param {string} [options.version] - The version number.
129
- * @returns {Promise<any>} - The response data.
130
- */
131
- createBranch(branch, { message, source = "main", version } = {}) {
132
- return this.request("/branch", {
133
- method: "POST",
134
- body: JSON.stringify({ branch, message, source, version })
135
- });
136
- }
137
- /**
138
- * Edit an existing branch. (For now only supports branch renaming)
139
- * @param {string} branch - The current name of the branch to edit.
140
- * @param {object} [options={}] - The branch edit options.
141
- * @param {string} [options.name] - New name for the branch
142
- * @returns {Promise<any>} - The response data.
143
- */
144
- editBranch(branch, { name } = {}) {
145
- return this.request("/branch", {
146
- method: "PATCH",
147
- body: JSON.stringify({ branch, name })
148
- });
149
- }
150
- /**
151
- * Delete an existing branch.
152
- * @param {string} branch - The name of the branch to delete.
153
- * @returns {Promise<any>} - The response data.
154
- */
155
- deleteBranch(branch) {
156
- return this.request("/branch", {
157
- method: "DELETE",
158
- body: JSON.stringify({ branch })
159
- });
160
- }
161
- /**
162
- * Merges a branch into the target branch.
163
- * @param {string} target - The target branch.
164
- * @param {object} [options={}] - The merge options.
165
- * @param {string} [options.message] - A message describing the merge.
166
- * @param {string} [options.source='main'] - The source branch.
167
- * @param {string} [options.type='patch'] - The type of merge.
168
- * @param {string} [options.version] - The version number.
169
- * @param {boolean} [options.commit='false'] - Whether to commit the merge.
170
- * @param {Array} [options.changes] - The changes to apply during the merge.
171
- * @returns {Promise<any>} - The response data.
172
- */
173
- mergeBranch(target, {
174
- message,
175
- source = "main",
176
- type = "patch",
177
- version,
178
- commit = "false",
179
- changes
180
- } = {}) {
181
- return this.request("/merge", {
182
- method: "POST",
183
- body: JSON.stringify({
184
- target,
185
- source,
186
- message,
187
- type,
188
- version,
189
- commit,
190
- changes
191
- })
192
- });
193
- }
194
- /**
195
- * Restores an older version of the project.
196
- * @param {string} version - The version number to restore.
197
- * @param {object} [options={}] - The restore options.
198
- * @param {string} [options.branch='main'] - The branch name.
199
- * @param {string} [options.type='patch'] - The type of restore.
200
- * @param {string} [options.message] - A message describing the restore.
201
- * @returns {Promise<any>} - The response data.
202
- */
203
- restoreVersion(version, { branch = "main", type = "patch", message } = {}) {
204
- return this.request("/restore", {
205
- method: "POST",
206
- body: JSON.stringify({ branch, version, type, message })
207
- });
208
- }
209
- /**
210
- * Publishes an existing version of the project.
211
- * @param {string} version - The version ID/number to publish.
212
- * @param {object} [options={}] - The publishing options.
213
- * @param {string} [options.branch='main'] - The branch name. (Only if version number is provided)
214
- * @returns {Promise<any>} - The response data.
215
- */
216
- publishVersion(version, { branch = "main" } = {}) {
217
- return this.request("/publish", {
218
- method: "POST",
219
- body: JSON.stringify({ version })
220
- });
221
- }
222
- /**
223
- * Retrieves all changes after a specific version.
224
- * @param {object} [options={}] - The changes options.
225
- * @param {string} [options.versionId] - The version ID to publish.
226
- * @param {string} [options.versionValue] - The version ID to publish. (alternative to versionId)
227
- * @param {string} [options.branch] - The branch to publish (Only in combination to versionValue)
228
- * @returns {Promise<any>} - The changes data.
229
- */
230
- getChanges({ versionId, versionValue, branch } = {}) {
231
- return this.request(
232
- "/changes?" + new URLSearchParams({
233
- ...versionId ? { versionId } : {},
234
- ...versionValue ? { versionValue } : {},
235
- ...branch ? { branch } : {}
236
- }).toString(),
237
- {}
238
- );
239
- }
240
- }
241
- var symstoryClient_default = {
242
- /**
243
- * Creates a new SymstoryClient instance.
244
- * @param {string} appKey - The application key.
245
- * @param {object} options - The options for the client.
246
- * @returns {SymstoryClient} - The SymstoryClient instance.
247
- */
248
- create: (appKey, options) => new SymstoryClient(appKey, options),
249
- /**
250
- * Initializes the Symstory client.
251
- * @param {string} appKey - The application key.
252
- * @param {object} options - The options for the client.
253
- * @returns {SymstoryClient} - The initialized SymstoryClient instance.
254
- */
255
- init(appKey, options) {
256
- this.client = this.create(appKey, options);
257
- return this;
258
- }
259
- };
@@ -1,185 +0,0 @@
1
- // src/services/BaseService.js
2
- var BaseService = class {
3
- constructor({ context, options } = {}) {
4
- this._context = context || {};
5
- this._options = options || {};
6
- this._ready = false;
7
- this._error = null;
8
- }
9
- // Initialize service
10
- init() {
11
- throw new Error("init() must be implemented by service");
12
- }
13
- // Update context
14
- updateContext(context) {
15
- this._context = { ...this._context, ...context };
16
- }
17
- // Get service status
18
- getStatus() {
19
- return {
20
- ready: this._ready,
21
- error: this._error,
22
- context: { ...this._context }
23
- };
24
- }
25
- // Check if service is ready
26
- isReady() {
27
- return this._ready;
28
- }
29
- // Protected helper methods
30
- _setReady(ready = true) {
31
- this._ready = ready;
32
- this._error = null;
33
- }
34
- _setError(error) {
35
- this._ready = false;
36
- this._error = error;
37
- }
38
- _requireAuth() {
39
- if (!this._context.authToken) {
40
- throw new Error("Authentication required");
41
- }
42
- }
43
- _requireReady() {
44
- if (!this.isReady()) {
45
- throw new Error("Service not initialized");
46
- }
47
- }
48
- };
49
-
50
- // src/services/AIService.js
51
- var AIService = class extends BaseService {
52
- constructor(config) {
53
- super(config);
54
- this._client = null;
55
- this._initialized = false;
56
- this._defaultConfig = {
57
- baseUrl: "https://api.openai.com/v1/engines/text-curie/completions",
58
- temperature: 0,
59
- maxTokens: 2e3,
60
- headers: {
61
- "Content-Type": "application/json"
62
- }
63
- };
64
- }
65
- init() {
66
- try {
67
- const { appKey, authToken } = this._context;
68
- this._info = {
69
- config: {
70
- appKey: appKey ? `${appKey.substr(0, 4)}...${appKey.substr(-4)}` : "",
71
- hasToken: Boolean(authToken)
72
- }
73
- };
74
- this._initialized = true;
75
- this._setReady();
76
- } catch (error) {
77
- this._setError(error);
78
- throw error;
79
- }
80
- }
81
- // Helper to check if method requires initialization
82
- _requiresInit(methodName) {
83
- const noInitMethods = /* @__PURE__ */ new Set(["getConfig", "validateConfig"]);
84
- return !noInitMethods.has(methodName);
85
- }
86
- // Override _requireReady to be more flexible
87
- _requireReady(methodName) {
88
- if (this._requiresInit(methodName) && !this._initialized) {
89
- throw new Error("AI service not initialized");
90
- }
91
- }
92
- // Configuration methods
93
- getConfig() {
94
- var _a;
95
- return {
96
- ...this._defaultConfig,
97
- ...(_a = this._context.ai) == null ? void 0 : _a.config
98
- };
99
- }
100
- validateConfig(config = {}) {
101
- const requiredFields = ["baseUrl", "temperature", "maxTokens"];
102
- const missingFields = requiredFields.filter((field) => !config[field]);
103
- if (missingFields.length > 0) {
104
- throw new Error(
105
- `Missing required configuration fields: ${missingFields.join(", ")}`
106
- );
107
- }
108
- return true;
109
- }
110
- // AI Methods
111
- async prompt(query, opts = {}) {
112
- var _a;
113
- this._requireReady("prompt");
114
- try {
115
- const config = this.getConfig();
116
- const options = {
117
- method: "POST",
118
- headers: {
119
- ...config.headers,
120
- Authorization: `Bearer ${(_a = this._context.ai) == null ? void 0 : _a.authToken}`
121
- },
122
- body: JSON.stringify({
123
- prompt: query,
124
- temperature: opts.temperature || config.temperature,
125
- max_tokens: opts.maxTokens || config.maxTokens,
126
- ...opts
127
- })
128
- };
129
- const response = await this._request(config.baseUrl, options);
130
- return response;
131
- } catch (error) {
132
- throw new Error(`AI prompt failed: ${error.message}`);
133
- }
134
- }
135
- // Helper methods
136
- async _request(url, options = {}) {
137
- try {
138
- const response = await fetch(url, {
139
- ...options,
140
- headers: {
141
- ...this._defaultConfig.headers,
142
- ...options.headers
143
- }
144
- });
145
- if (!response.ok) {
146
- const error = await response.json();
147
- throw new Error(error.message || "Request failed");
148
- }
149
- return response.status === 204 ? null : response.json();
150
- } catch (error) {
151
- throw new Error(`Request failed: ${error.message}`);
152
- }
153
- }
154
- // Context update methods
155
- updateAuth(authToken) {
156
- this.updateContext({
157
- ai: {
158
- ...this._context.ai,
159
- authToken
160
- }
161
- });
162
- }
163
- updateConfig(config) {
164
- var _a;
165
- this.validateConfig(config);
166
- this.updateContext({
167
- ai: {
168
- ...this._context.ai,
169
- config: {
170
- ...(_a = this._context.ai) == null ? void 0 : _a.config,
171
- ...config
172
- }
173
- }
174
- });
175
- }
176
- // Cleanup
177
- destroy() {
178
- this._client = null;
179
- this._initialized = false;
180
- this._setReady(false);
181
- }
182
- };
183
- export {
184
- AIService
185
- };