@superblocksteam/sdk 1.14.2 → 2.0.3-next.101

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 (152) hide show
  1. package/.mocharc.json +7 -0
  2. package/.prettierrc +18 -0
  3. package/dist/cli-replacement/dev.d.mts +19 -0
  4. package/dist/cli-replacement/dev.d.mts.map +1 -0
  5. package/dist/cli-replacement/dev.mjs +129 -0
  6. package/dist/cli-replacement/dev.mjs.map +1 -0
  7. package/dist/cli-replacement/init.d.ts +14 -0
  8. package/dist/cli-replacement/init.d.ts.map +1 -0
  9. package/dist/cli-replacement/init.js +26 -0
  10. package/dist/cli-replacement/init.js.map +1 -0
  11. package/dist/client.d.ts +31 -17
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +137 -155
  14. package/dist/client.js.map +1 -0
  15. package/dist/dbfs/client.d.ts +6 -0
  16. package/dist/dbfs/client.d.ts.map +1 -0
  17. package/dist/dbfs/client.js +117 -0
  18. package/dist/dbfs/client.js.map +1 -0
  19. package/dist/dbfs/local.d.ts +15 -0
  20. package/dist/dbfs/local.d.ts.map +1 -0
  21. package/dist/dbfs/local.js +126 -0
  22. package/dist/dbfs/local.js.map +1 -0
  23. package/dist/dev-utils/custom-build.d.mts +4 -0
  24. package/dist/dev-utils/custom-build.d.mts.map +1 -0
  25. package/dist/dev-utils/custom-build.mjs +99 -0
  26. package/dist/dev-utils/custom-build.mjs.map +1 -0
  27. package/dist/dev-utils/custom-config.d.mts +2 -0
  28. package/dist/dev-utils/custom-config.d.mts.map +1 -0
  29. package/dist/dev-utils/custom-config.mjs +57 -0
  30. package/dist/dev-utils/custom-config.mjs.map +1 -0
  31. package/dist/dev-utils/dev-logger.d.mts +8 -0
  32. package/dist/dev-utils/dev-logger.d.mts.map +1 -0
  33. package/dist/dev-utils/dev-logger.mjs +25 -0
  34. package/dist/dev-utils/dev-logger.mjs.map +1 -0
  35. package/dist/dev-utils/dev-server.d.mts +18 -0
  36. package/dist/dev-utils/dev-server.d.mts.map +1 -0
  37. package/dist/dev-utils/dev-server.mjs +265 -0
  38. package/dist/dev-utils/dev-server.mjs.map +1 -0
  39. package/dist/dev-utils/dev-tracer.d.ts +3 -0
  40. package/dist/dev-utils/dev-tracer.d.ts.map +1 -0
  41. package/dist/dev-utils/dev-tracer.js +28 -0
  42. package/dist/dev-utils/dev-tracer.js.map +1 -0
  43. package/dist/dev-utils/vite-plugin-dd-rum.d.mts +10 -0
  44. package/dist/dev-utils/vite-plugin-dd-rum.d.mts.map +1 -0
  45. package/dist/dev-utils/vite-plugin-dd-rum.mjs +34 -0
  46. package/dist/dev-utils/vite-plugin-dd-rum.mjs.map +1 -0
  47. package/dist/dev-utils/vite-plugin-react-transform.d.mts +7 -0
  48. package/dist/dev-utils/vite-plugin-react-transform.d.mts.map +1 -0
  49. package/dist/dev-utils/vite-plugin-react-transform.mjs +110 -0
  50. package/dist/dev-utils/vite-plugin-react-transform.mjs.map +1 -0
  51. package/dist/dev-utils/vite-plugin-sb-cdn.d.mts +34 -0
  52. package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -0
  53. package/dist/dev-utils/vite-plugin-sb-cdn.mjs +720 -0
  54. package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -0
  55. package/dist/errors.d.ts +1 -0
  56. package/dist/errors.d.ts.map +1 -0
  57. package/dist/errors.js +4 -9
  58. package/dist/errors.js.map +1 -0
  59. package/dist/flag.d.ts +2 -2
  60. package/dist/flag.d.ts.map +1 -0
  61. package/dist/flag.js +5 -9
  62. package/dist/flag.js.map +1 -0
  63. package/dist/index.d.ts +10 -4
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +10 -20
  66. package/dist/index.js.map +1 -0
  67. package/dist/sdk.d.ts +42 -18
  68. package/dist/sdk.d.ts.map +1 -0
  69. package/dist/sdk.js +47 -43
  70. package/dist/sdk.js.map +1 -0
  71. package/dist/socket/handlers.d.ts +3 -128
  72. package/dist/socket/handlers.d.ts.map +1 -0
  73. package/dist/socket/handlers.js +7 -9
  74. package/dist/socket/handlers.js.map +1 -0
  75. package/dist/socket/index.d.ts +4 -3
  76. package/dist/socket/index.d.ts.map +1 -0
  77. package/dist/socket/index.js +12 -21
  78. package/dist/socket/index.js.map +1 -0
  79. package/dist/socket/signing.d.ts +3 -1
  80. package/dist/socket/signing.d.ts.map +1 -0
  81. package/dist/socket/signing.js +8 -17
  82. package/dist/socket/signing.js.map +1 -0
  83. package/dist/socket/socket.d.ts +3 -2
  84. package/dist/socket/socket.d.ts.map +1 -0
  85. package/dist/socket/socket.js +9 -19
  86. package/dist/socket/socket.js.map +1 -0
  87. package/dist/types/common.d.ts +2 -103
  88. package/dist/types/common.d.ts.map +1 -0
  89. package/dist/types/common.js +8 -24
  90. package/dist/types/common.js.map +1 -0
  91. package/dist/types/index.d.ts +5 -4
  92. package/dist/types/index.d.ts.map +1 -0
  93. package/dist/types/index.js +5 -20
  94. package/dist/types/index.js.map +1 -0
  95. package/dist/types/plugin.d.ts +1 -0
  96. package/dist/types/plugin.d.ts.map +1 -0
  97. package/dist/types/plugin.js +3 -5
  98. package/dist/types/plugin.js.map +1 -0
  99. package/dist/types/signing.d.ts +2 -1
  100. package/dist/types/signing.d.ts.map +1 -0
  101. package/dist/types/signing.js +2 -2
  102. package/dist/types/signing.js.map +1 -0
  103. package/dist/types/socket.d.ts +1 -0
  104. package/dist/types/socket.d.ts.map +1 -0
  105. package/dist/types/socket.js +2 -5
  106. package/dist/types/socket.js.map +1 -0
  107. package/dist/utils.d.ts +3 -1
  108. package/dist/utils.d.ts.map +1 -0
  109. package/dist/utils.js +14 -23
  110. package/dist/utils.js.map +1 -0
  111. package/dist/version-control.d.mts +59 -0
  112. package/dist/version-control.d.mts.map +1 -0
  113. package/dist/version-control.mjs +899 -0
  114. package/dist/version-control.mjs.map +1 -0
  115. package/eslint.config.js +85 -0
  116. package/package.json +76 -30
  117. package/src/cli-replacement/dev.mts +194 -0
  118. package/src/cli-replacement/init.ts +47 -0
  119. package/src/client.ts +114 -38
  120. package/src/dbfs/client.ts +162 -0
  121. package/src/dbfs/local.ts +163 -0
  122. package/src/dev-utils/custom-build.mts +113 -0
  123. package/src/dev-utils/custom-config.mts +66 -0
  124. package/src/dev-utils/dev-logger.mts +39 -0
  125. package/src/dev-utils/dev-server.mts +342 -0
  126. package/src/dev-utils/dev-tracer.ts +31 -0
  127. package/src/dev-utils/vite-plugin-dd-rum.mts +47 -0
  128. package/src/dev-utils/vite-plugin-react-transform.mts +130 -0
  129. package/src/dev-utils/vite-plugin-sb-cdn.mts +988 -0
  130. package/src/flag.ts +2 -3
  131. package/src/index.ts +119 -4
  132. package/src/sdk.ts +91 -17
  133. package/src/socket/handlers.ts +9 -147
  134. package/src/socket/index.ts +6 -9
  135. package/src/socket/signing.ts +7 -8
  136. package/src/socket/socket.ts +8 -9
  137. package/src/types/common.ts +2 -119
  138. package/src/types/index.ts +4 -4
  139. package/src/types/signing.ts +1 -1
  140. package/src/types/socket.ts +1 -1
  141. package/src/utils.ts +5 -6
  142. package/src/version-control.mts +1351 -0
  143. package/test/dev-utils/fixture/index.html +12 -0
  144. package/test/dev-utils/fixture/main.jsx +22 -0
  145. package/test/dev-utils/fixture/package-lock.json +25 -0
  146. package/test/dev-utils/fixture/package.json +9 -0
  147. package/test/dev-utils/vite-plugin-sb-cdn.test.mts +74 -0
  148. package/test/tsconfig.json +9 -0
  149. package/test/version-control.test.mts +1412 -0
  150. package/tsconfig.json +15 -4
  151. package/tsconfig.tsbuildinfo +1 -1
  152. package/.eslintrc.json +0 -55
package/dist/client.js CHANGED
@@ -1,68 +1,15 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createSocketConnectionIfNeeded = void 0;
40
- exports.fetchApplication = fetchApplication;
41
- exports.fetchApplicationBranches = fetchApplicationBranches;
42
- exports.fetchApplicationWithComponents = fetchApplicationWithComponents;
43
- exports.fetchApplications = fetchApplications;
44
- exports.fetchApi = fetchApi;
45
- exports.fetchApis = fetchApis;
46
- exports.validateGitSetup = validateGitSetup;
47
- exports.registerComponents = registerComponents;
48
- exports.uploadComponents = uploadComponents;
49
- exports.fetchCurrentUser = fetchCurrentUser;
50
- exports.pushApplication = pushApplication;
51
- exports.pushApi = pushApi;
52
- exports.fetchApplicationCommits = fetchApplicationCommits;
53
- exports.fetchApiCommits = fetchApiCommits;
54
- exports.deployApplication = deployApplication;
55
- exports.deployApi = deployApi;
56
- const fs = __importStar(require("fs"));
57
- const util_1 = require("@superblocksteam/util");
58
- const axios_1 = __importStar(require("axios"));
59
- const form_data_1 = __importDefault(require("form-data"));
60
- const lodash_1 = require("lodash");
61
- const errors_1 = require("./errors");
62
- const flag_1 = require("./flag");
63
- const socket_1 = require("./socket");
64
- const types_1 = require("./types");
65
- const utils_1 = require("./utils");
1
+ import * as fs from "fs";
2
+ import { Bucketeer, FileDescriptor } from "@superblocksteam/bucketeer-sdk";
3
+ import { ExportViewMode } from "@superblocksteam/shared";
4
+ import { COMPONENT_EVENT_HEADER, ComponentEvent, ForbiddenError, getBucketeerUrlFromSuperblocksUrl, getContentType, NotFoundError, BadRequestError, unreachable, } from "@superblocksteam/util";
5
+ import axios, { AxiosError } from "axios";
6
+ import FormData from "form-data";
7
+ import { isEqual, isEmpty } from "lodash-es";
8
+ import { BranchNotCheckedOutError, CommitAlreadyExistsError, ValidateGitSetupError, } from "./errors.js";
9
+ import { signingEnabled } from "./flag.js";
10
+ import { connectToISocketRPCServer } from "./socket/index.js";
11
+ import { AgentType } from "./types/index.js";
12
+ import { getAgentUrl } from "./utils.js";
66
13
  const BASE_BUCKETEER_URL = "api";
67
14
  const BASE_SERVER_PUBLIC_API_URL_V1 = "api/v1/public";
68
15
  const BASE_SERVER_PUBLIC_API_URL_v2 = "api/v2/public";
@@ -76,8 +23,8 @@ var ResourceType;
76
23
  ResourceType["APPLICATION"] = "APPLICATION";
77
24
  ResourceType["BACKEND"] = "BACKEND";
78
25
  })(ResourceType || (ResourceType = {}));
79
- async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
80
- if (commitId && viewMode !== "export-commit") {
26
+ export async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
27
+ if (commitId && viewMode !== ExportViewMode.EXPORT_COMMIT) {
81
28
  throw new Error(`If commitId ${commitId} is provided, viewMode cannot be ${viewMode}`);
82
29
  }
83
30
  try {
@@ -89,7 +36,7 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
89
36
  ...(commitId ? { commitId } : {}),
90
37
  }).toString();
91
38
  const socket = !skipSigningVerification
92
- ? await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl)
39
+ ? await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl)
93
40
  : undefined;
94
41
  if (socket) {
95
42
  try {
@@ -114,18 +61,18 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
114
61
  ...injectedHeaders,
115
62
  },
116
63
  };
117
- const serverResponse = await (0, axios_1.default)(config);
64
+ const serverResponse = await axios(config);
118
65
  const data = serverResponse?.data?.data;
119
66
  return data;
120
67
  }
121
68
  catch (e) {
122
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
123
- throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
69
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
70
+ throw new NotFoundError(`Application ${applicationId} was not found`);
124
71
  }
125
72
  throw new Error(`Could not fetch application: ${typeof e === "object" && e && "message" in e ? e.message : e}`);
126
73
  }
127
74
  }
128
- async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
75
+ export async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
129
76
  const serverURL = new URL(`public/applications/${applicationId}/branches`, superblocksBaseUrl);
130
77
  let serverResponse;
131
78
  try {
@@ -138,17 +85,17 @@ async function fetchApplicationBranches({ cliVersion, applicationId, token, supe
138
85
  ...injectedHeaders,
139
86
  },
140
87
  };
141
- serverResponse = await (0, axios_1.default)(config);
88
+ serverResponse = await axios(config);
142
89
  }
143
90
  catch (e) {
144
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
145
- throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
91
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
92
+ throw new NotFoundError(`Application ${applicationId} was not found`);
146
93
  }
147
94
  throw new Error(`Could not fetch application branches: ${e.message}`);
148
95
  }
149
96
  return serverResponse?.data?.data;
150
97
  }
151
- async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
98
+ export async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
152
99
  const applicationWrapper = await fetchApplication({
153
100
  cliVersion,
154
101
  applicationId,
@@ -160,18 +107,37 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
160
107
  skipSigningVerification,
161
108
  injectedHeaders,
162
109
  });
163
- if ((0, lodash_1.isEmpty)(applicationWrapper)) {
110
+ if (isEmpty(applicationWrapper)) {
164
111
  return;
165
112
  }
113
+ if (applicationWrapper.application.devEnvEnabled) {
114
+ return {
115
+ type: "code-mode",
116
+ ...applicationWrapper,
117
+ };
118
+ }
119
+ return await fetchApplicationWithComponentsFromBucketeer({
120
+ applicationWrapper,
121
+ superblocksBaseUrl,
122
+ applicationId,
123
+ branch,
124
+ commitId,
125
+ viewMode,
126
+ token,
127
+ injectedHeaders,
128
+ });
129
+ }
130
+ async function fetchApplicationWithComponentsFromBucketeer({ applicationWrapper, superblocksBaseUrl, applicationId, branch, commitId, viewMode, token, injectedHeaders, }) {
166
131
  // if there are no custom components, just return here without trying to initialize them using bucketeer
167
- if ((0, lodash_1.isEmpty)(applicationWrapper.application?.settings?.registeredComponents)) {
132
+ if (isEmpty(applicationWrapper.application?.settings?.registeredComponents)) {
168
133
  return {
134
+ type: "multi-page",
169
135
  ...applicationWrapper,
170
136
  componentFiles: null,
171
137
  };
172
138
  }
173
139
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
174
- const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
140
+ const bucketeerBaseUrl = getBucketeerUrlFromSuperblocksUrl(superblocksBaseUrl);
175
141
  // fetch files from bucketeer
176
142
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
177
143
  const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}&multiPage=true`, bucketeerBaseUrl).toString();
@@ -185,21 +151,21 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
185
151
  ...injectedHeaders,
186
152
  },
187
153
  };
188
- const bucketeerApp = (await (0, axios_1.default)(config))
154
+ const bucketeerApp = (await axios(config))
189
155
  .data;
190
- if (!(0, lodash_1.isEqual)(applicationWrapper.application.settings, bucketeerApp.application.settings)) {
156
+ if (!isEqual(applicationWrapper.application.settings, bucketeerApp.application.settings)) {
191
157
  throw new Error("Application settings fetched from bucketeer do not match the settings fetched from the server");
192
158
  }
193
159
  return bucketeerApp;
194
160
  }
195
161
  catch (e) {
196
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
197
- throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
162
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
163
+ throw new NotFoundError(`Application ${applicationId} was not found`);
198
164
  }
199
165
  throw new Error("Could not fetch application");
200
166
  }
201
167
  }
202
- async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
168
+ export async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
203
169
  try {
204
170
  const config = {
205
171
  method: "get",
@@ -210,12 +176,12 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
210
176
  ...injectedHeaders,
211
177
  },
212
178
  };
213
- const response = await (0, axios_1.default)(config);
179
+ const response = await axios(config);
214
180
  return response.data.data.applications;
215
181
  }
216
182
  catch (e) {
217
183
  let message;
218
- if (e instanceof axios_1.AxiosError) {
184
+ if (e instanceof AxiosError) {
219
185
  message =
220
186
  e.response?.data?.responseMeta?.message ??
221
187
  JSON.stringify(e.response?.data) ??
@@ -228,7 +194,7 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
228
194
  throw new Error(`Could not fetch applications: ${message}`);
229
195
  }
230
196
  }
231
- async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch, commitId, skipSigningVerification = false) {
197
+ export async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch, commitId, skipSigningVerification = false) {
232
198
  try {
233
199
  const serverURL = branch
234
200
  ? new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}`, superblocksBaseUrl)
@@ -238,7 +204,7 @@ async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode,
238
204
  ...(commitId ? { commitId } : {}),
239
205
  }).toString();
240
206
  const socket = !skipSigningVerification
241
- ? await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl)
207
+ ? await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl)
242
208
  : undefined;
243
209
  if (socket) {
244
210
  try {
@@ -262,18 +228,18 @@ async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode,
262
228
  [CLI_VERSION_HEADER]: cliVersion,
263
229
  },
264
230
  };
265
- const response = await (0, axios_1.default)(config);
231
+ const response = await axios(config);
266
232
  return response.data.data;
267
233
  }
268
234
  }
269
235
  catch (e) {
270
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
271
- throw new util_1.NotFoundError(`Api ${apiId} was not found`);
236
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
237
+ throw new NotFoundError(`Api ${apiId} was not found`);
272
238
  }
273
239
  throw new Error(`Could not fetch api: ${typeof e === "object" && e && "message" in e ? e.message : e}`);
274
240
  }
275
241
  }
276
- async function fetchApis(cliVersion, token, superblocksBaseUrl) {
242
+ export async function fetchApis(cliVersion, token, superblocksBaseUrl) {
277
243
  try {
278
244
  const config = {
279
245
  method: "get",
@@ -283,14 +249,14 @@ async function fetchApis(cliVersion, token, superblocksBaseUrl) {
283
249
  [CLI_VERSION_HEADER]: cliVersion,
284
250
  },
285
251
  };
286
- const response = await (0, axios_1.default)(config);
252
+ const response = await axios(config);
287
253
  return response.data.data.apis;
288
254
  }
289
255
  catch {
290
256
  throw new Error("Could not fetch apis");
291
257
  }
292
258
  }
293
- async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
259
+ export async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
294
260
  let resourceName;
295
261
  try {
296
262
  const requestBody = {
@@ -308,7 +274,7 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
308
274
  break;
309
275
  }
310
276
  default:
311
- (0, util_1.unreachable)(resourceType);
277
+ unreachable(resourceType);
312
278
  }
313
279
  const config = {
314
280
  method: "post",
@@ -320,7 +286,7 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
320
286
  },
321
287
  data: requestBody,
322
288
  };
323
- const response = await (0, axios_1.default)(config);
289
+ const response = await axios(config);
324
290
  const { validationResult } = response.data.data;
325
291
  if (validationResult.errors.length > 0) {
326
292
  if (validationResult.resourceName) {
@@ -334,7 +300,7 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
334
300
  }
335
301
  catch (e) {
336
302
  let message;
337
- if (e instanceof axios_1.AxiosError) {
303
+ if (e instanceof AxiosError) {
338
304
  message =
339
305
  e.response?.data?.responseMeta?.message ??
340
306
  JSON.stringify(e.response?.data) ??
@@ -348,23 +314,23 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
348
314
  // TODO(@taha-au @gpoulios-sb) Replace this check with a more robust one that uses error codes once
349
315
  // the backend starts returning them as part of the response body
350
316
  if (message.includes("Please initialize git locally")) {
351
- throw new errors_1.ValidateGitSetupError(errorMessage);
317
+ throw new ValidateGitSetupError(errorMessage);
352
318
  }
353
319
  else {
354
320
  throw new Error(errorMessage);
355
321
  }
356
322
  }
357
323
  }
358
- async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
324
+ export async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
359
325
  try {
360
326
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
361
- const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
327
+ const socket = await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl);
362
328
  if (socket) {
363
329
  const resp = await socket.call.v1.public.application.component.register({
364
330
  applicationId,
365
331
  branchName: branch || "",
366
332
  cliVersion: cliVersion,
367
- componentEvent: injectedHeaders[util_1.COMPONENT_EVENT_HEADER],
333
+ componentEvent: injectedHeaders[COMPONENT_EVENT_HEADER],
368
334
  components: componentConfigs,
369
335
  });
370
336
  socket.close();
@@ -381,12 +347,12 @@ async function registerComponents(cliVersion, applicationId, componentConfigs, t
381
347
  },
382
348
  data: { components: componentConfigs },
383
349
  };
384
- const response = await (0, axios_1.default)(config);
350
+ const response = await axios(config);
385
351
  return response.data;
386
352
  }
387
353
  }
388
354
  catch (e) {
389
- if (e instanceof axios_1.AxiosError) {
355
+ if (e instanceof AxiosError) {
390
356
  const message = e.response?.data?.responseMeta?.message ??
391
357
  JSON.stringify(e.response?.data) ??
392
358
  e.response?.statusText;
@@ -395,12 +361,12 @@ async function registerComponents(cliVersion, applicationId, componentConfigs, t
395
361
  throw new Error(`Could not register application components ${e.message ? "\n" + e.message : ""}`);
396
362
  }
397
363
  }
398
- async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
364
+ export async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
399
365
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
400
- const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
366
+ const bucketeerBaseUrl = getBucketeerUrlFromSuperblocksUrl(superblocksBaseUrl);
401
367
  // parse files to source and bundled files based on path
402
368
  const uploadFiles = files.map((file, ind) => {
403
- let contentType = (0, util_1.getContentType)(file);
369
+ let contentType = getContentType(file);
404
370
  if (contentType.length === 0) {
405
371
  contentType = "application/octet-stream"; // default case when we don't know the encoding
406
372
  }
@@ -422,7 +388,7 @@ async function uploadComponents({ cliVersion, applicationId, componentConfigs, f
422
388
  });
423
389
  const postURL = new URL(`${BASE_BUCKETEER_URL}/v2/components/upload`, bucketeerBaseUrl).toString();
424
390
  let totalFileSizeMB = 0;
425
- const formData = new form_data_1.default();
391
+ const formData = new FormData();
426
392
  formData.append("format", formatJSON);
427
393
  uploadFiles.forEach((uploadFile) => {
428
394
  const uploadFileStats = fs.statSync(uploadFile.filename);
@@ -443,15 +409,15 @@ You can reduce your component bundle size by uploading static assets to a separa
443
409
  headers: {
444
410
  Authorization: "Bearer " + token,
445
411
  [CLI_VERSION_HEADER]: cliVersion,
446
- [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.UPLOAD,
412
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.UPLOAD,
447
413
  [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
448
414
  ...formHeaders,
449
415
  },
450
416
  };
451
- const uploadResponse = await axios_1.default.post(postURL, formData, config);
452
- const initialSocket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
417
+ const uploadResponse = await axios.post(postURL, formData, config);
418
+ const initialSocket = await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl);
453
419
  const socket = initialSocket ??
454
- (await (0, socket_1.connectToISocketRPCServer)({
420
+ (await connectToISocketRPCServer({
455
421
  agentUrl: undefined,
456
422
  superblocksBaseUrl,
457
423
  token,
@@ -465,7 +431,7 @@ You can reduce your component bundle size by uploading static assets to a separa
465
431
  registeredComponents: componentConfigs,
466
432
  cliVersion,
467
433
  componentBaseUrl: uploadResponse.data.componentBaseUrl,
468
- signingRequired: !(0, lodash_1.isEmpty)(initialSocket),
434
+ signingRequired: !isEmpty(initialSocket),
469
435
  });
470
436
  }
471
437
  finally {
@@ -473,12 +439,12 @@ You can reduce your component bundle size by uploading static assets to a separa
473
439
  }
474
440
  }
475
441
  catch (e) {
476
- if (e instanceof axios_1.AxiosError && e.response?.status === 413) {
442
+ if (e instanceof AxiosError && e.response?.status === 413) {
477
443
  throw new Error(`Could not upload application components, file size limit exceeded`);
478
444
  }
479
445
  else {
480
446
  let message;
481
- if (e instanceof axios_1.AxiosError) {
447
+ if (e instanceof AxiosError) {
482
448
  message = (e.response?.data?.responseMeta?.message ||
483
449
  e.response?.data ||
484
450
  e.response?.statusText);
@@ -493,7 +459,7 @@ You can reduce your component bundle size by uploading static assets to a separa
493
459
  }
494
460
  }
495
461
  }
496
- async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
462
+ export async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
497
463
  try {
498
464
  const config = {
499
465
  method: "get",
@@ -501,15 +467,15 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
501
467
  headers: {
502
468
  Authorization: "Bearer " + token,
503
469
  [CLI_VERSION_HEADER]: cliVersion,
504
- [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.LOGIN,
470
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.LOGIN,
505
471
  },
506
472
  };
507
- const response = await (0, axios_1.default)(config);
473
+ const response = await axios(config);
508
474
  return response.data.data;
509
475
  }
510
476
  catch (e) {
511
477
  let message;
512
- if (e instanceof axios_1.AxiosError) {
478
+ if (e instanceof AxiosError) {
513
479
  message =
514
480
  e.response?.data?.responseMeta?.message ??
515
481
  JSON.stringify(e.response?.data) ??
@@ -522,32 +488,31 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
522
488
  throw new Error(`Could not fetch current user: ${message}`);
523
489
  }
524
490
  }
525
- const createSocketConnectionIfNeeded = async (cliVersion, token, superblocksBaseUrl) => {
491
+ export const createSocketConnectionIfNeeded = async (cliVersion, token, superblocksBaseUrl) => {
526
492
  const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
527
493
  const organization = userMe.organizations[0];
528
- if (organization.agentType == types_1.AgentType.ONPREMISE &&
529
- (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
494
+ if (organization.agentType == AgentType.ONPREMISE &&
495
+ signingEnabled(userMe.flagBootstrap)) {
530
496
  const profile = process.env.SUPERBLOCKS_PROFILE;
531
- const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
532
- return await (0, socket_1.connectToISocketRPCServer)({
497
+ const agentUrl = await getAgentUrl(userMe.agents, organization.agentType, profile);
498
+ return await connectToISocketRPCServer({
533
499
  agentUrl,
534
500
  superblocksBaseUrl,
535
501
  token,
536
502
  });
537
503
  }
538
504
  };
539
- exports.createSocketConnectionIfNeeded = createSocketConnectionIfNeeded;
540
- async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
505
+ export async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
541
506
  const handleHttpError = (status) => {
542
507
  if (status === 405) {
543
- throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
508
+ throw new BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
544
509
  }
545
510
  else if (status === 409) {
546
- throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
511
+ throw new CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
547
512
  }
548
513
  };
549
514
  try {
550
- const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
515
+ const socket = await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl);
551
516
  if (socket) {
552
517
  const resp = await socket.call.v2.public.application.pushCommit({
553
518
  applicationId,
@@ -582,11 +547,11 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
582
547
  data: applicationConfig,
583
548
  };
584
549
  try {
585
- const serverResponse = await (0, axios_1.default)(config);
550
+ const serverResponse = await axios(config);
586
551
  return serverResponse?.data?.data;
587
552
  }
588
553
  catch (e) {
589
- if (!axios_1.default.isAxiosError(e)) {
554
+ if (!axios.isAxiosError(e)) {
590
555
  throw e;
591
556
  }
592
557
  handleHttpError(e.response?.data?.responseMeta?.status ?? e.response?.status);
@@ -598,26 +563,26 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
598
563
  }
599
564
  }
600
565
  catch (e) {
601
- if (e instanceof errors_1.BranchNotCheckedOutError ||
602
- e instanceof errors_1.CommitAlreadyExistsError) {
566
+ if (e instanceof BranchNotCheckedOutError ||
567
+ e instanceof CommitAlreadyExistsError) {
603
568
  // Rethrow these exceptions because they will be handled higher up the call stack
604
569
  throw e;
605
570
  }
606
571
  throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
607
572
  }
608
573
  }
609
- async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
574
+ export async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
610
575
  const handleHttpError = (status) => {
611
576
  if (status === 405) {
612
- throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
577
+ throw new BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
613
578
  }
614
579
  else if (status === 409) {
615
- throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
580
+ throw new CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
616
581
  }
617
582
  };
618
583
  const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
619
584
  try {
620
- const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
585
+ const socket = await createSocketConnectionIfNeeded(cliVersion, token, superblocksBaseUrl);
621
586
  if (socket) {
622
587
  const resp = await socket.call.v1.public.api.pushCommit({
623
588
  apiId,
@@ -649,11 +614,11 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
649
614
  data: apiConfig,
650
615
  };
651
616
  try {
652
- const serverResponse = await (0, axios_1.default)(config);
617
+ const serverResponse = await axios(config);
653
618
  return serverResponse?.data?.data;
654
619
  }
655
620
  catch (e) {
656
- if (!axios_1.default.isAxiosError(e)) {
621
+ if (!axios.isAxiosError(e)) {
657
622
  throw e;
658
623
  }
659
624
  handleHttpError(e.response?.data?.responseMeta?.status);
@@ -665,15 +630,15 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
665
630
  }
666
631
  }
667
632
  catch (e) {
668
- if (e instanceof errors_1.BranchNotCheckedOutError ||
669
- e instanceof errors_1.CommitAlreadyExistsError) {
633
+ if (e instanceof BranchNotCheckedOutError ||
634
+ e instanceof CommitAlreadyExistsError) {
670
635
  // Rethrow these exceptions because they will be handled higher up the call stack
671
636
  throw e;
672
637
  }
673
638
  throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
674
639
  }
675
640
  }
676
- async function fetchApplicationCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
641
+ export async function fetchApplicationCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
677
642
  try {
678
643
  const serverURL = branch
679
644
  ? new URL(`${BASE_SERVER_API_URL_V2}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/commits`, superblocksBaseUrl)
@@ -692,17 +657,17 @@ async function fetchApplicationCommits({ cliVersion, applicationId, branch, toke
692
657
  ...injectedHeaders,
693
658
  },
694
659
  };
695
- const serverResponse = await (0, axios_1.default)(config);
660
+ const serverResponse = await axios(config);
696
661
  return serverResponse?.data?.data;
697
662
  }
698
663
  catch (e) {
699
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
700
- throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
664
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
665
+ throw new NotFoundError(`Application ${applicationId} was not found`);
701
666
  }
702
667
  throw new Error("Could not fetch application");
703
668
  }
704
669
  }
705
- async function fetchApiCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
670
+ export async function fetchApiCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
706
671
  try {
707
672
  const serverURL = branch
708
673
  ? new URL(`${BASE_SERVER_API_URL_V3}/apis/${applicationId}/branches/${encodeURIComponent(branch)}/commits`, superblocksBaseUrl)
@@ -721,20 +686,20 @@ async function fetchApiCommits({ cliVersion, applicationId, branch, token, super
721
686
  ...injectedHeaders,
722
687
  },
723
688
  };
724
- const serverResponse = await (0, axios_1.default)(config);
689
+ const serverResponse = await axios(config);
725
690
  return serverResponse?.data?.data;
726
691
  }
727
692
  catch (e) {
728
- if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
729
- throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
693
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
694
+ throw new NotFoundError(`Application ${applicationId} was not found`);
730
695
  }
731
696
  throw new Error("Could not fetch application");
732
697
  }
733
698
  }
734
- async function deployApplication(cliVersion, applicationId, token, superblocksBaseUrl, commitId) {
699
+ export async function deployApplication(cliVersion, applicationId, token, superblocksBaseUrl, commitId) {
735
700
  return deployResource(cliVersion, ResourceType.APPLICATION, applicationId, token, superblocksBaseUrl, commitId);
736
701
  }
737
- async function deployApi(cliVersion, apiId, token, superblocksBaseUrl, commitId) {
702
+ export async function deployApi(cliVersion, apiId, token, superblocksBaseUrl, commitId) {
738
703
  return deployResource(cliVersion, ResourceType.BACKEND, apiId, token, superblocksBaseUrl, commitId);
739
704
  }
740
705
  async function deployResource(cliVersion, resourceType, resourceId, token, superblocksBaseUrl, commitId) {
@@ -760,20 +725,20 @@ async function deployResource(cliVersion, resourceType, resourceId, token, super
760
725
  commitId: commitId ?? "HEAD",
761
726
  },
762
727
  };
763
- const serverResponse = await (0, axios_1.default)(config);
728
+ const serverResponse = await axios(config);
764
729
  return serverResponse?.data?.data;
765
730
  }
766
731
  catch (e) {
767
732
  let message;
768
- if (axios_1.default.isAxiosError(e)) {
733
+ if (axios.isAxiosError(e)) {
769
734
  if (e.response?.status === 404) {
770
- throw new util_1.NotFoundError(`${e.response?.data?.responseMeta?.message}`);
735
+ throw new NotFoundError(`${e.response?.data?.responseMeta?.message}`);
771
736
  }
772
737
  else if (e.response?.status === 403) {
773
- throw new util_1.ForbiddenError(`${e.response?.data?.responseMeta?.message}`);
738
+ throw new ForbiddenError(`${e.response?.data?.responseMeta?.message}`);
774
739
  }
775
740
  else if (e.response?.status === 400) {
776
- throw new util_1.BadRequestError(`${e.response?.data?.responseMeta?.message}`);
741
+ throw new BadRequestError(`${e.response?.data?.responseMeta?.message}`);
777
742
  }
778
743
  else {
779
744
  message =
@@ -786,3 +751,20 @@ async function deployResource(cliVersion, resourceType, resourceId, token, super
786
751
  throw new Error(`${e.message}`);
787
752
  }
788
753
  }
754
+ export async function uploadApplication({ files, scopedJwt, url, cliVersion, }) {
755
+ const fds = filesToFileDescriptors(files);
756
+ const bucketeer = new Bucketeer({
757
+ token: scopedJwt,
758
+ baseUrl: url,
759
+ cliVersion,
760
+ maxTotalFileSizeMB: SUPERBLOCKS_MAX_FILE_SIZE_MB,
761
+ });
762
+ await bucketeer.uploadApplication(fds);
763
+ }
764
+ function filesToFileDescriptors(files) {
765
+ const fds = files.map((file) => {
766
+ return new FileDescriptor(file, fs.createReadStream(file));
767
+ });
768
+ return fds;
769
+ }
770
+ //# sourceMappingURL=client.js.map