@superblocksteam/sdk 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json CHANGED
@@ -27,6 +27,9 @@
27
27
  "@typescript-eslint/no-unsafe-return": "off",
28
28
  "@typescript-eslint/no-unsafe-member-access": "off",
29
29
  "@typescript-eslint/restrict-template-expressions": "off",
30
+ "@typescript-eslint/no-unsafe-assignment": "off",
31
+ "@typescript-eslint/no-unsafe-argument": "off",
32
+ "@typescript-eslint/no-unsafe-call": "off",
30
33
  "import/order": [
31
34
  "error",
32
35
  {
package/dist/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
2
+ import { RemoteCommitDto, UserMeDto } from "./types";
2
3
  export type ViewMode = "export-deployed" | "export-latest" | "export-live";
3
4
  export interface UploadFile {
4
5
  name: string;
@@ -30,7 +31,8 @@ export type Branch = {
30
31
  name: string;
31
32
  isDefault: boolean;
32
33
  };
33
- export declare function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
34
+ export declare function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
35
+ cliVersion: string;
34
36
  applicationId: string;
35
37
  branch?: string;
36
38
  token: string;
@@ -38,13 +40,15 @@ export declare function fetchApplication({ applicationId, branch, token, superbl
38
40
  viewMode: ViewMode;
39
41
  injectedHeaders: Record<string, string>;
40
42
  }): Promise<ApplicationWrapper | undefined>;
41
- export declare function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
43
+ export declare function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
44
+ cliVersion: string;
42
45
  applicationId: string;
43
46
  token: string;
44
47
  superblocksBaseUrl: string;
45
48
  injectedHeaders: Record<string, string>;
46
49
  }): Promise<Branches | undefined>;
47
- export declare function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
50
+ export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
51
+ cliVersion: string;
48
52
  applicationId: string;
49
53
  branch: string;
50
54
  token: string;
@@ -54,31 +58,34 @@ export declare function fetchApplicationWithComponents({ applicationId, branch,
54
58
  }): Promise<(ApplicationWrapper & {
55
59
  componentFiles: any;
56
60
  }) | undefined>;
57
- export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
58
- export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
59
- export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
60
- export declare function validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
61
+ export declare function fetchApplications(cliVersion: string, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
62
+ export declare function fetchApi(cliVersion: string, apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode, branch?: string): Promise<any>;
63
+ export declare function fetchApis(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<any>;
64
+ export declare function validateGitSetup(cliVersion: string, resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
61
65
  branchName: string | null;
62
66
  }>;
63
- export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
64
- export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
67
+ export declare function registerComponents(cliVersion: string, applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
68
+ export declare function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
69
+ cliVersion: string;
65
70
  applicationId: string;
66
71
  componentConfigs: Record<string, any>;
67
72
  files: string[];
68
73
  token: string;
69
74
  superblocksBaseUrl: string;
70
75
  branch: string | null;
71
- }): Promise<any>;
72
- export declare function fetchCurrentUser(token: string, superblocksBaseUrl: string): Promise<any>;
73
- export declare function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
76
+ }): Promise<void>;
77
+ export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<UserMeDto>;
78
+ export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
79
+ cliVersion: string;
74
80
  applicationId: string;
75
81
  token: string;
76
82
  superblocksBaseUrl: string;
77
83
  branch: string;
78
84
  injectedHeaders: Record<string, string>;
79
85
  applicationConfig: PushApplicationWithCommitConfig;
80
- }): Promise<ApplicationWrapper | undefined>;
81
- export declare function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
86
+ }): Promise<RemoteCommitDto | undefined>;
87
+ export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
88
+ cliVersion: string;
82
89
  apiId: string;
83
90
  token: string;
84
91
  superblocksBaseUrl: string;
package/dist/client.js CHANGED
@@ -1,22 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pushApi = exports.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.validateGitSetup = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
4
- const fs = require("fs");
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
5
6
  const util_1 = require("@superblocksteam/util");
6
- const axios_1 = require("axios");
7
- const FormData = require("form-data");
7
+ const axios_1 = tslib_1.__importStar(require("axios"));
8
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
8
9
  const lodash_1 = require("lodash");
9
10
  const errors_1 = require("./errors");
10
- const BASE_SERVER_URL = "api/v1";
11
- const BASE_BUCKETEER_URL = "api/v1";
11
+ const flag_1 = require("./flag");
12
+ const socket_1 = require("./socket");
13
+ const types_1 = require("./types");
14
+ const utils_1 = require("./utils");
15
+ const BASE_BUCKETEER_URL = "api";
16
+ const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
12
17
  const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
13
18
  const CLI_VERSION_HEADER = "x-superblocks-cli-version";
14
19
  const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
15
- async function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
20
+ async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
16
21
  var _a, _b;
17
22
  const serverURL = branch
18
- ? new URL(`api/v2/applications/${applicationId}/branches/${branch}?viewMode=${viewMode}`, superblocksBaseUrl)
19
- : new URL(`api/v2/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
23
+ ? new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
24
+ : new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
20
25
  let serverResponse;
21
26
  try {
22
27
  const config = {
@@ -24,6 +29,7 @@ async function fetchApplication({ applicationId, branch, token, superblocksBaseU
24
29
  url: serverURL.toString(),
25
30
  headers: {
26
31
  Authorization: "Bearer " + token,
32
+ [CLI_VERSION_HEADER]: cliVersion,
27
33
  ...injectedHeaders,
28
34
  },
29
35
  };
@@ -38,9 +44,9 @@ async function fetchApplication({ applicationId, branch, token, superblocksBaseU
38
44
  return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
39
45
  }
40
46
  exports.fetchApplication = fetchApplication;
41
- async function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
47
+ async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
42
48
  var _a, _b;
43
- const serverURL = new URL(`api/v2/applications/${applicationId}/branches`, superblocksBaseUrl);
49
+ const serverURL = new URL(`public/applications/${applicationId}/branches`, superblocksBaseUrl);
44
50
  let serverResponse;
45
51
  try {
46
52
  const config = {
@@ -48,6 +54,7 @@ async function fetchApplicationBranches({ applicationId, token, superblocksBaseU
48
54
  url: serverURL.toString(),
49
55
  headers: {
50
56
  Authorization: "Bearer " + token,
57
+ [CLI_VERSION_HEADER]: cliVersion,
51
58
  ...injectedHeaders,
52
59
  },
53
60
  };
@@ -62,9 +69,10 @@ async function fetchApplicationBranches({ applicationId, token, superblocksBaseU
62
69
  return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
63
70
  }
64
71
  exports.fetchApplicationBranches = fetchApplicationBranches;
65
- async function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
72
+ async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
66
73
  var _a, _b, _c;
67
74
  const applicationWrapper = await fetchApplication({
75
+ cliVersion,
68
76
  applicationId,
69
77
  branch,
70
78
  token,
@@ -88,7 +96,7 @@ async function fetchApplicationWithComponents({ applicationId, branch, token, su
88
96
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
89
97
  // fetch files from bucketeer
90
98
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
91
- const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
99
+ const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
92
100
  try {
93
101
  const config = {
94
102
  method: "get",
@@ -110,13 +118,15 @@ async function fetchApplicationWithComponents({ applicationId, branch, token, su
110
118
  }
111
119
  }
112
120
  exports.fetchApplicationWithComponents = fetchApplicationWithComponents;
113
- async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}) {
121
+ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
122
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
114
123
  try {
115
124
  const config = {
116
125
  method: "get",
117
- url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
126
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications`, superblocksBaseUrl).toString(),
118
127
  headers: {
119
128
  Authorization: "Bearer " + token,
129
+ [CLI_VERSION_HEADER]: cliVersion,
120
130
  ...injectedHeaders,
121
131
  },
122
132
  };
@@ -124,18 +134,30 @@ async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}
124
134
  return response.data.data.applications;
125
135
  }
126
136
  catch (e) {
127
- throw new Error("Could not fetch applications");
137
+ let message;
138
+ if (e instanceof axios_1.AxiosError) {
139
+ message =
140
+ (_j = (_h = (_f = (_d = (_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.responseMeta) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : JSON.stringify((_e = e.response) === null || _e === void 0 ? void 0 : _e.data)) !== null && _f !== void 0 ? _f : (_g = e.response) === null || _g === void 0 ? void 0 : _g.statusText) !== null && _h !== void 0 ? _h : e === null || e === void 0 ? void 0 : e.message) !== null && _j !== void 0 ? _j : `${e}`;
141
+ }
142
+ else {
143
+ message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
144
+ }
145
+ throw new Error(`Could not fetch applications: ${message}`);
128
146
  }
129
147
  }
130
148
  exports.fetchApplications = fetchApplications;
131
- async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
149
+ async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
132
150
  var _a;
133
151
  try {
152
+ const serverURL = branch
153
+ ? new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
154
+ : new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl);
134
155
  const config = {
135
156
  method: "get",
136
- url: new URL(`/api/v3/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl).toString(),
157
+ url: new URL(serverURL, superblocksBaseUrl).toString(),
137
158
  headers: {
138
159
  Authorization: "Bearer " + token,
160
+ [CLI_VERSION_HEADER]: cliVersion,
139
161
  },
140
162
  };
141
163
  const response = await (0, axios_1.default)(config);
@@ -149,28 +171,28 @@ async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
149
171
  }
150
172
  }
151
173
  exports.fetchApi = fetchApi;
152
- async function fetchApis(token, superblocksBaseUrl) {
174
+ async function fetchApis(cliVersion, token, superblocksBaseUrl) {
153
175
  try {
154
176
  const config = {
155
177
  method: "get",
156
- url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
178
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis`, superblocksBaseUrl).toString(),
157
179
  headers: {
158
180
  Authorization: "Bearer " + token,
181
+ [CLI_VERSION_HEADER]: cliVersion,
159
182
  },
160
183
  };
161
184
  const response = await (0, axios_1.default)(config);
162
- return response.data.data;
185
+ return response.data.data.apis;
163
186
  }
164
187
  catch (e) {
165
188
  throw new Error("Could not fetch apis");
166
189
  }
167
190
  }
168
191
  exports.fetchApis = fetchApis;
169
- async function validateGitSetup(resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
192
+ async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
170
193
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
171
194
  let resourceName;
172
195
  try {
173
- const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
174
196
  const requestBody = {
175
197
  event,
176
198
  gitState: localGitRepoState,
@@ -178,11 +200,11 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
178
200
  let path;
179
201
  switch (resourceType) {
180
202
  case "APPLICATION": {
181
- path = `/public/application/${resourceId}/validate-git-setup`;
203
+ path = `/application/${resourceId}/validate-git-setup`;
182
204
  break;
183
205
  }
184
206
  case "BACKEND": {
185
- path = `/public/api/${resourceId}/validate-git-setup`;
207
+ path = `/api/${resourceId}/validate-git-setup`;
186
208
  break;
187
209
  }
188
210
  default:
@@ -190,10 +212,10 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
190
212
  }
191
213
  const config = {
192
214
  method: "post",
193
- url: new URL(`${BASE_SERVER_URL}/${path}`, superblocksBaseUrl).toString(),
215
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/${path}`, superblocksBaseUrl).toString(),
194
216
  headers: {
195
217
  Authorization: "Bearer " + token,
196
- [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
218
+ [CLI_VERSION_HEADER]: cliVersion,
197
219
  ...injectedHeaders,
198
220
  },
199
221
  data: requestBody,
@@ -223,23 +245,43 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
223
245
  }
224
246
  }
225
247
  exports.validateGitSetup = validateGitSetup;
226
- async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
248
+ async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
227
249
  var _a, _b, _c, _d, _e, _f, _g;
228
250
  try {
229
- const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
230
251
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
231
- const config = {
232
- method: "put",
233
- url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
234
- headers: {
235
- Authorization: "Bearer " + token,
236
- [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
237
- ...injectedHeaders,
238
- },
239
- data: { components: componentConfigs },
240
- };
241
- const response = await (0, axios_1.default)(config);
242
- return response.data;
252
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
253
+ const organization = userMe.organizations[0];
254
+ if (organization.agentType == types_1.AgentType.ONPREMISE && (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
255
+ const agentUrls = (0, utils_1.getAgentUrls)(userMe.agents, organization.agentType);
256
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
257
+ agentUrls,
258
+ superblocksBaseUrl,
259
+ token,
260
+ });
261
+ const resp = await socket.call.v1.public.application.component.register({
262
+ applicationId,
263
+ branchName: branch || "",
264
+ cliVersion: cliVersion,
265
+ componentEvent: injectedHeaders[util_1.COMPONENT_EVENT_HEADER],
266
+ components: componentConfigs,
267
+ });
268
+ socket.close();
269
+ return resp.data;
270
+ }
271
+ else {
272
+ const config = {
273
+ method: "put",
274
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
275
+ headers: {
276
+ Authorization: "Bearer " + token,
277
+ [CLI_VERSION_HEADER]: cliVersion,
278
+ ...injectedHeaders,
279
+ },
280
+ data: { components: componentConfigs },
281
+ };
282
+ const response = await (0, axios_1.default)(config);
283
+ return response.data;
284
+ }
243
285
  }
244
286
  catch (e) {
245
287
  if (e instanceof axios_1.AxiosError) {
@@ -250,7 +292,7 @@ async function registerComponents(applicationId, componentConfigs, token, superb
250
292
  }
251
293
  }
252
294
  exports.registerComponents = registerComponents;
253
- async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
295
+ async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
254
296
  var _a, _b, _c, _d, _e, _f;
255
297
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
256
298
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
@@ -276,9 +318,9 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
276
318
  srcFiles,
277
319
  buildFiles,
278
320
  });
279
- const postURL = new URL(`${BASE_BUCKETEER_URL}/components/upload`, bucketeerBaseUrl).toString();
321
+ const postURL = new URL(`${BASE_BUCKETEER_URL}/v2/components/upload`, bucketeerBaseUrl).toString();
280
322
  let totalFileSizeMB = 0;
281
- const formData = new FormData();
323
+ const formData = new form_data_1.default();
282
324
  formData.append("format", formatJSON);
283
325
  uploadFiles.forEach((uploadFile) => {
284
326
  const uploadFileStats = fs.statSync(uploadFile.filename);
@@ -295,18 +337,43 @@ You can reduce your component bundle size by uploading static assets to a separa
295
337
  }
296
338
  const formHeaders = formData.getHeaders();
297
339
  try {
298
- const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
299
340
  const config = {
300
341
  headers: {
301
342
  Authorization: "Bearer " + token,
302
- [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
343
+ [CLI_VERSION_HEADER]: cliVersion,
303
344
  [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.UPLOAD,
304
345
  [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
305
346
  ...formHeaders,
306
347
  },
307
348
  };
308
- const response = await axios_1.default.post(postURL, formData, config);
309
- return response.data;
349
+ const uploadResponse = await axios_1.default.post(postURL, formData, config);
350
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
351
+ const organization = userMe.organizations[0];
352
+ const signingRequired = organization.agentType == types_1.AgentType.ONPREMISE && (0, flag_1.signingEnabled)(userMe.flagBootstrap);
353
+ let agentUrls = [];
354
+ if (signingRequired) {
355
+ agentUrls = (0, utils_1.getAgentUrls)(userMe.agents, organization.agentType);
356
+ }
357
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
358
+ agentUrls,
359
+ superblocksBaseUrl,
360
+ token,
361
+ });
362
+ try {
363
+ await socket.call.v1.public.application.component.update({
364
+ applicationId,
365
+ branchName: branch !== null && branch !== void 0 ? branch : undefined,
366
+ srcFiles: srcFiles.map((file) => file.filename),
367
+ buildFiles: buildFiles.map((file) => file.filename),
368
+ registeredComponents: componentConfigs,
369
+ cliVersion,
370
+ componentBaseUrl: uploadResponse.data.componentBaseUrl,
371
+ signingRequired,
372
+ });
373
+ }
374
+ finally {
375
+ socket.close();
376
+ }
310
377
  }
311
378
  catch (e) {
312
379
  if (e instanceof axios_1.AxiosError && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 413) {
@@ -330,41 +397,73 @@ You can reduce your component bundle size by uploading static assets to a separa
330
397
  }
331
398
  }
332
399
  exports.uploadComponents = uploadComponents;
333
- async function fetchCurrentUser(token, superblocksBaseUrl) {
400
+ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
401
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
334
402
  try {
335
403
  const config = {
336
404
  method: "get",
337
- url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
405
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/users/me`, superblocksBaseUrl).toString(),
338
406
  headers: {
339
407
  Authorization: "Bearer " + token,
408
+ [CLI_VERSION_HEADER]: cliVersion,
340
409
  [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.LOGIN,
341
410
  },
342
411
  };
343
412
  const response = await (0, axios_1.default)(config);
344
- return response.data.data.user;
413
+ return response.data.data;
345
414
  }
346
415
  catch (e) {
347
- throw new Error("Could not fetch current user");
416
+ let message;
417
+ if (e instanceof axios_1.AxiosError) {
418
+ message =
419
+ (_j = (_h = (_f = (_d = (_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.responseMeta) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : JSON.stringify((_e = e.response) === null || _e === void 0 ? void 0 : _e.data)) !== null && _f !== void 0 ? _f : (_g = e.response) === null || _g === void 0 ? void 0 : _g.statusText) !== null && _h !== void 0 ? _h : e === null || e === void 0 ? void 0 : e.message) !== null && _j !== void 0 ? _j : `${e}`;
420
+ }
421
+ else {
422
+ message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
423
+ }
424
+ throw new Error(`Could not fetch current user: ${message}`);
348
425
  }
349
426
  }
350
427
  exports.fetchCurrentUser = fetchCurrentUser;
351
- async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
428
+ async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
352
429
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
353
- const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
354
- const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
430
+ const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
355
431
  let serverResponse;
356
432
  try {
357
- const config = {
358
- method: "post",
359
- url: serverURL.toString(),
360
- headers: {
361
- Authorization: "Bearer " + token,
362
- [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
363
- ...injectedHeaders,
364
- },
365
- data: applicationConfig,
366
- };
367
- serverResponse = await (0, axios_1.default)(config);
433
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
434
+ const organization = userMe.organizations[0];
435
+ if (organization.agentType == types_1.AgentType.ONPREMISE && (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
436
+ const agentUrls = (0, utils_1.getAgentUrls)(userMe.agents, organization.agentType);
437
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
438
+ agentUrls,
439
+ superblocksBaseUrl,
440
+ token,
441
+ });
442
+ const resp = await socket.call.v1.public.application.pushCommit({
443
+ applicationId,
444
+ apis: applicationConfig.apis,
445
+ application: applicationConfig.application,
446
+ branchName: branch,
447
+ commitId: applicationConfig.commitId,
448
+ commitMessage: applicationConfig.commitMessage,
449
+ page: applicationConfig.page,
450
+ });
451
+ socket.close();
452
+ return resp.data;
453
+ }
454
+ else {
455
+ const config = {
456
+ method: "post",
457
+ url: serverURL.toString(),
458
+ headers: {
459
+ Authorization: "Bearer " + token,
460
+ [CLI_VERSION_HEADER]: cliVersion,
461
+ ...injectedHeaders,
462
+ },
463
+ data: applicationConfig,
464
+ };
465
+ serverResponse = await (0, axios_1.default)(config);
466
+ }
368
467
  }
369
468
  catch (e) {
370
469
  if (axios_1.default.isAxiosError(e)) {
@@ -383,23 +482,43 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
383
482
  return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
384
483
  }
385
484
  exports.pushApplication = pushApplication;
386
- async function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
485
+ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
387
486
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
388
- const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
389
- const serverURL = new URL(`${BASE_SERVER_URL}/public/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
487
+ const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
390
488
  let serverResponse;
391
489
  try {
392
- const config = {
393
- method: "post",
394
- url: serverURL.toString(),
395
- headers: {
396
- Authorization: "Bearer " + token,
397
- [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
398
- ...injectedHeaders,
399
- },
400
- data: apiConfig,
401
- };
402
- serverResponse = await (0, axios_1.default)(config);
490
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
491
+ const organization = userMe.organizations[0];
492
+ if (organization.agentType == types_1.AgentType.ONPREMISE && (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
493
+ const agentUrls = (0, utils_1.getAgentUrls)(userMe.agents, organization.agentType);
494
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
495
+ agentUrls,
496
+ superblocksBaseUrl,
497
+ token,
498
+ });
499
+ const resp = await socket.call.v1.public.api.pushCommit({
500
+ apiId,
501
+ apiPb: apiConfig.apiPb,
502
+ branchName: branch,
503
+ commitId: apiConfig.commitId,
504
+ commitMessage: apiConfig.commitMessage,
505
+ });
506
+ socket.close();
507
+ return resp.data;
508
+ }
509
+ else {
510
+ const config = {
511
+ method: "post",
512
+ url: serverURL.toString(),
513
+ headers: {
514
+ Authorization: "Bearer " + token,
515
+ [CLI_VERSION_HEADER]: cliVersion,
516
+ ...injectedHeaders,
517
+ },
518
+ data: apiConfig,
519
+ };
520
+ serverResponse = await (0, axios_1.default)(config);
521
+ }
403
522
  }
404
523
  catch (e) {
405
524
  if (axios_1.default.isAxiosError(e)) {
package/dist/flag.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { FlagBootstrap } from "./types";
2
+ export declare const signingEnabled: (flags: FlagBootstrap) => boolean;
package/dist/flag.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signingEnabled = void 0;
4
+ const signingEnabled = (flags) => {
5
+ var _a;
6
+ return (_a = flags["ui.enable-resource-signing"]) !== null && _a !== void 0 ? _a : false;
7
+ };
8
+ exports.signingEnabled = signingEnabled;
package/dist/sdk.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
2
- import { ViewMode, PushApplicationWithCommitConfig, PushApiWithCommitConfig } from "./client";
2
+ import { PushApiWithCommitConfig, PushApplicationWithCommitConfig, ViewMode } from "./client";
3
3
  export * from "./errors";
4
4
  export declare class SuperblocksSdk {
5
5
  token: string;
6
6
  superblocksBaseUrl: string;
7
- constructor(accessToken: string, superblocksBaseUrl: string);
7
+ cliVersion: string;
8
+ constructor(accessToken: string, superblocksBaseUrl: string, cliVersion: string);
8
9
  fetchApplication({ applicationId, branch, headers, viewMode, }: {
9
10
  applicationId: string;
10
11
  branch?: string;
@@ -21,20 +22,20 @@ export declare class SuperblocksSdk {
21
22
  componentFiles: any;
22
23
  }) | undefined>;
23
24
  fetchApplications(headers?: Record<string, string>): Promise<any>;
24
- fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
25
+ fetchApi(apiId: string, viewMode?: ViewMode, branch?: string): Promise<any>;
25
26
  fetchApis(): Promise<any>;
26
27
  validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
27
28
  branchName: string | null;
28
29
  }>;
29
- registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
30
- uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<any>;
31
- fetchCurrentUser(): Promise<any>;
30
+ registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
31
+ uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<void>;
32
+ fetchCurrentUser(): Promise<import("./types").UserMeDto>;
32
33
  pushApplication({ applicationId, applicationConfig, branch, headers, }: {
33
34
  applicationId: string;
34
35
  applicationConfig: PushApplicationWithCommitConfig;
35
36
  branch: string;
36
37
  headers?: Record<string, string>;
37
- }): Promise<import("./client").ApplicationWrapper | undefined>;
38
+ }): Promise<import("./types").RemoteCommitDto | undefined>;
38
39
  pushApi({ apiId, apiConfig, branch, headers, }: {
39
40
  apiId: string;
40
41
  apiConfig: PushApiWithCommitConfig;