@superblocksteam/sdk 1.4.2 → 1.5.1

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;
@@ -63,7 +64,7 @@ export declare function fetchApis(cliVersion: string, token: string, superblocks
63
64
  export declare function validateGitSetup(cliVersion: string, resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
64
65
  branchName: string | null;
65
66
  }>;
66
- 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>;
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>;
67
68
  export declare function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
68
69
  cliVersion: string;
69
70
  applicationId: string;
@@ -72,8 +73,8 @@ export declare function uploadComponents({ cliVersion, applicationId, componentC
72
73
  token: string;
73
74
  superblocksBaseUrl: string;
74
75
  branch: string | null;
75
- }): Promise<any>;
76
- export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<any>;
76
+ }): Promise<void>;
77
+ export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<UserMeDto>;
77
78
  export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
78
79
  cliVersion: string;
79
80
  applicationId: string;
@@ -82,7 +83,7 @@ export declare function pushApplication({ cliVersion, applicationId, token, supe
82
83
  branch: string;
83
84
  injectedHeaders: Record<string, string>;
84
85
  applicationConfig: PushApplicationWithCommitConfig;
85
- }): Promise<ApplicationWrapper | undefined>;
86
+ }): Promise<RemoteCommitDto | undefined>;
86
87
  export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
87
88
  cliVersion: string;
88
89
  apiId: string;
package/dist/client.js CHANGED
@@ -1,19 +1,23 @@
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_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";
11
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
20
  async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
16
- var _a, _b;
17
21
  const serverURL = branch
18
22
  ? new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
19
23
  : new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
@@ -31,16 +35,15 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
31
35
  serverResponse = await (0, axios_1.default)(config);
32
36
  }
33
37
  catch (e) {
34
- if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
38
+ if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
35
39
  throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
36
40
  }
37
41
  throw new Error("Could not fetch application");
38
42
  }
39
- return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
43
+ return serverResponse?.data?.data;
40
44
  }
41
45
  exports.fetchApplication = fetchApplication;
42
46
  async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
43
- var _a, _b;
44
47
  const serverURL = new URL(`public/applications/${applicationId}/branches`, superblocksBaseUrl);
45
48
  let serverResponse;
46
49
  try {
@@ -56,16 +59,15 @@ async function fetchApplicationBranches({ cliVersion, applicationId, token, supe
56
59
  serverResponse = await (0, axios_1.default)(config);
57
60
  }
58
61
  catch (e) {
59
- if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
62
+ if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
60
63
  throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
61
64
  }
62
65
  throw new Error(`Could not fetch application branches: ${e.message}`);
63
66
  }
64
- return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
67
+ return serverResponse?.data?.data;
65
68
  }
66
69
  exports.fetchApplicationBranches = fetchApplicationBranches;
67
70
  async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
68
- var _a, _b, _c;
69
71
  const applicationWrapper = await fetchApplication({
70
72
  cliVersion,
71
73
  applicationId,
@@ -79,7 +81,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
79
81
  return;
80
82
  }
81
83
  // if there are no custom components, just return here without trying to initialize them using bucketeer
82
- if ((0, lodash_1.isEmpty)((_b = (_a = applicationWrapper.application) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.registeredComponents)) {
84
+ if ((0, lodash_1.isEmpty)(applicationWrapper.application?.settings?.registeredComponents)) {
83
85
  return {
84
86
  ...applicationWrapper,
85
87
  componentFiles: null,
@@ -91,7 +93,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
91
93
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
92
94
  // fetch files from bucketeer
93
95
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
94
- const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
96
+ const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
95
97
  try {
96
98
  const config = {
97
99
  method: "get",
@@ -106,7 +108,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
106
108
  return response.data;
107
109
  }
108
110
  catch (e) {
109
- if (axios_1.default.isAxiosError(e) && ((_c = e.response) === null || _c === void 0 ? void 0 : _c.status) === 404) {
111
+ if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
110
112
  throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
111
113
  }
112
114
  throw new Error("Could not fetch application");
@@ -114,7 +116,6 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
114
116
  }
115
117
  exports.fetchApplicationWithComponents = fetchApplicationWithComponents;
116
118
  async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
117
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
118
119
  try {
119
120
  const config = {
120
121
  method: "get",
@@ -132,17 +133,20 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
132
133
  let message;
133
134
  if (e instanceof axios_1.AxiosError) {
134
135
  message =
135
- (_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}`;
136
+ e.response?.data?.responseMeta?.message ??
137
+ JSON.stringify(e.response?.data) ??
138
+ e.response?.statusText ??
139
+ e?.message ??
140
+ `${e}`;
136
141
  }
137
142
  else {
138
- message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
143
+ message = `${e?.message ? e?.message : e}`;
139
144
  }
140
145
  throw new Error(`Could not fetch applications: ${message}`);
141
146
  }
142
147
  }
143
148
  exports.fetchApplications = fetchApplications;
144
149
  async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
145
- var _a;
146
150
  try {
147
151
  const serverURL = branch
148
152
  ? new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
@@ -159,7 +163,7 @@ async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode,
159
163
  return response.data.data;
160
164
  }
161
165
  catch (e) {
162
- if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
166
+ if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
163
167
  throw new util_1.NotFoundError(`Api ${apiId} was not found`);
164
168
  }
165
169
  throw new Error("Could not fetch api");
@@ -185,7 +189,6 @@ async function fetchApis(cliVersion, token, superblocksBaseUrl) {
185
189
  }
186
190
  exports.fetchApis = fetchApis;
187
191
  async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
188
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
189
192
  let resourceName;
190
193
  try {
191
194
  const requestBody = {
@@ -224,42 +227,70 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
224
227
  throw new Error(validationResult.errors.join("\n"));
225
228
  }
226
229
  return {
227
- branchName: ((_a = validationResult.branchName) !== null && _a !== void 0 ? _a : null),
230
+ branchName: (validationResult.branchName ?? null),
228
231
  };
229
232
  }
230
233
  catch (e) {
231
234
  let message;
232
235
  if (e instanceof axios_1.AxiosError) {
233
236
  message =
234
- (_k = (_j = (_g = (_e = (_d = (_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.responseMeta) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : JSON.stringify((_f = e.response) === null || _f === void 0 ? void 0 : _f.data)) !== null && _g !== void 0 ? _g : (_h = e.response) === null || _h === void 0 ? void 0 : _h.statusText) !== null && _j !== void 0 ? _j : e === null || e === void 0 ? void 0 : e.message) !== null && _k !== void 0 ? _k : `${e}`;
237
+ e.response?.data?.responseMeta?.message ??
238
+ JSON.stringify(e.response?.data) ??
239
+ e.response?.statusText ??
240
+ e?.message ??
241
+ `${e}`;
235
242
  }
236
243
  else {
237
- message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
244
+ message = `${e?.message ? e?.message : e}`;
238
245
  }
239
- throw new Error(`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName !== null && resourceName !== void 0 ? resourceName : resourceId}${message ? "\n" + message : ""}`);
246
+ throw new Error(`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName ?? resourceId}${message ? "\n" + message : ""}`);
240
247
  }
241
248
  }
242
249
  exports.validateGitSetup = validateGitSetup;
243
250
  async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
244
- var _a, _b, _c, _d, _e, _f, _g;
245
251
  try {
246
252
  const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
247
- const config = {
248
- method: "put",
249
- url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
250
- headers: {
251
- Authorization: "Bearer " + token,
252
- [CLI_VERSION_HEADER]: cliVersion,
253
- ...injectedHeaders,
254
- },
255
- data: { components: componentConfigs },
256
- };
257
- const response = await (0, axios_1.default)(config);
258
- return response.data;
253
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
254
+ const organization = userMe.organizations[0];
255
+ if (organization.agentType == types_1.AgentType.ONPREMISE &&
256
+ (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
257
+ const profile = process.env.SUPERBLOCKS_PROFILE;
258
+ const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
259
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
260
+ agentUrl,
261
+ superblocksBaseUrl,
262
+ token,
263
+ });
264
+ const resp = await socket.call.v1.public.application.component.register({
265
+ applicationId,
266
+ branchName: branch || "",
267
+ cliVersion: cliVersion,
268
+ componentEvent: injectedHeaders[util_1.COMPONENT_EVENT_HEADER],
269
+ components: componentConfigs,
270
+ });
271
+ socket.close();
272
+ return resp.data;
273
+ }
274
+ else {
275
+ const config = {
276
+ method: "put",
277
+ url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
278
+ headers: {
279
+ Authorization: "Bearer " + token,
280
+ [CLI_VERSION_HEADER]: cliVersion,
281
+ ...injectedHeaders,
282
+ },
283
+ data: { components: componentConfigs },
284
+ };
285
+ const response = await (0, axios_1.default)(config);
286
+ return response.data;
287
+ }
259
288
  }
260
289
  catch (e) {
261
290
  if (e instanceof axios_1.AxiosError) {
262
- const message = (_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;
291
+ const message = e.response?.data?.responseMeta?.message ??
292
+ JSON.stringify(e.response?.data) ??
293
+ e.response?.statusText;
263
294
  throw new Error(`Could not register application components ${message ? "\n" + message : ""}`);
264
295
  }
265
296
  throw new Error(`Could not register application components ${e.message ? "\n" + e.message : ""}`);
@@ -267,7 +298,6 @@ async function registerComponents(cliVersion, applicationId, componentConfigs, t
267
298
  }
268
299
  exports.registerComponents = registerComponents;
269
300
  async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
270
- var _a, _b, _c, _d, _e, _f;
271
301
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
272
302
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
273
303
  // parse files to source and bundled files based on path
@@ -292,9 +322,9 @@ async function uploadComponents({ cliVersion, applicationId, componentConfigs, f
292
322
  srcFiles,
293
323
  buildFiles,
294
324
  });
295
- const postURL = new URL(`${BASE_BUCKETEER_URL}/components/upload`, bucketeerBaseUrl).toString();
325
+ const postURL = new URL(`${BASE_BUCKETEER_URL}/v2/components/upload`, bucketeerBaseUrl).toString();
296
326
  let totalFileSizeMB = 0;
297
- const formData = new FormData();
327
+ const formData = new form_data_1.default();
298
328
  formData.append("format", formatJSON);
299
329
  uploadFiles.forEach((uploadFile) => {
300
330
  const uploadFileStats = fs.statSync(uploadFile.filename);
@@ -320,19 +350,46 @@ You can reduce your component bundle size by uploading static assets to a separa
320
350
  ...formHeaders,
321
351
  },
322
352
  };
323
- const response = await axios_1.default.post(postURL, formData, config);
324
- return response.data;
353
+ const uploadResponse = await axios_1.default.post(postURL, formData, config);
354
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
355
+ const organization = userMe.organizations[0];
356
+ let agentUrl;
357
+ const signingRequired = organization.agentType == types_1.AgentType.ONPREMISE &&
358
+ (0, flag_1.signingEnabled)(userMe.flagBootstrap);
359
+ if (signingRequired) {
360
+ agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType);
361
+ }
362
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
363
+ agentUrl,
364
+ superblocksBaseUrl,
365
+ token,
366
+ });
367
+ try {
368
+ await socket.call.v1.public.application.component.update({
369
+ applicationId,
370
+ branchName: branch ?? undefined,
371
+ srcFiles: srcFiles.map((file) => file.filename),
372
+ buildFiles: buildFiles.map((file) => file.filename),
373
+ registeredComponents: componentConfigs,
374
+ cliVersion,
375
+ componentBaseUrl: uploadResponse.data.componentBaseUrl,
376
+ signingRequired,
377
+ });
378
+ }
379
+ finally {
380
+ socket.close();
381
+ }
325
382
  }
326
383
  catch (e) {
327
- if (e instanceof axios_1.AxiosError && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 413) {
384
+ if (e instanceof axios_1.AxiosError && e.response?.status === 413) {
328
385
  throw new Error(`Could not upload application components, file size limit exceeded`);
329
386
  }
330
387
  else {
331
388
  let message;
332
389
  if (e instanceof axios_1.AxiosError) {
333
- message = (((_d = (_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.responseMeta) === null || _d === void 0 ? void 0 : _d.message) ||
334
- ((_e = e.response) === null || _e === void 0 ? void 0 : _e.data) ||
335
- ((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText));
390
+ message = (e.response?.data?.responseMeta?.message ||
391
+ e.response?.data ||
392
+ e.response?.statusText);
336
393
  }
337
394
  else {
338
395
  message = e.message;
@@ -346,7 +403,6 @@ You can reduce your component bundle size by uploading static assets to a separa
346
403
  }
347
404
  exports.uploadComponents = uploadComponents;
348
405
  async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
349
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
350
406
  try {
351
407
  const config = {
352
408
  method: "get",
@@ -358,85 +414,138 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
358
414
  },
359
415
  };
360
416
  const response = await (0, axios_1.default)(config);
361
- return response.data.data.user;
417
+ return response.data.data;
362
418
  }
363
419
  catch (e) {
364
420
  let message;
365
421
  if (e instanceof axios_1.AxiosError) {
366
422
  message =
367
- (_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}`;
423
+ e.response?.data?.responseMeta?.message ??
424
+ JSON.stringify(e.response?.data) ??
425
+ e.response?.statusText ??
426
+ e?.message ??
427
+ `${e}`;
368
428
  }
369
429
  else {
370
- message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
430
+ message = `${e?.message ? e?.message : e}`;
371
431
  }
372
432
  throw new Error(`Could not fetch current user: ${message}`);
373
433
  }
374
434
  }
375
435
  exports.fetchCurrentUser = fetchCurrentUser;
376
436
  async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
377
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
378
437
  const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
379
438
  let serverResponse;
380
439
  try {
381
- const config = {
382
- method: "post",
383
- url: serverURL.toString(),
384
- headers: {
385
- Authorization: "Bearer " + token,
386
- [CLI_VERSION_HEADER]: cliVersion,
387
- ...injectedHeaders,
388
- },
389
- data: applicationConfig,
390
- };
391
- serverResponse = await (0, axios_1.default)(config);
440
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
441
+ const organization = userMe.organizations[0];
442
+ if (organization.agentType == types_1.AgentType.ONPREMISE &&
443
+ (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
444
+ const profile = process.env.SUPERBLOCKS_PROFILE;
445
+ const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
446
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
447
+ agentUrl,
448
+ superblocksBaseUrl,
449
+ token,
450
+ });
451
+ const resp = await socket.call.v1.public.application.pushCommit({
452
+ applicationId,
453
+ apis: applicationConfig.apis,
454
+ application: applicationConfig.application,
455
+ branchName: branch,
456
+ commitId: applicationConfig.commitId,
457
+ commitMessage: applicationConfig.commitMessage,
458
+ page: applicationConfig.page,
459
+ });
460
+ socket.close();
461
+ return resp.data;
462
+ }
463
+ else {
464
+ const config = {
465
+ method: "post",
466
+ url: serverURL.toString(),
467
+ headers: {
468
+ Authorization: "Bearer " + token,
469
+ [CLI_VERSION_HEADER]: cliVersion,
470
+ ...injectedHeaders,
471
+ },
472
+ data: applicationConfig,
473
+ };
474
+ serverResponse = await (0, axios_1.default)(config);
475
+ }
392
476
  }
393
477
  catch (e) {
394
478
  if (axios_1.default.isAxiosError(e)) {
395
- const respCode = (_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.status) !== null && _d !== void 0 ? _d : (_e = e.response) === null || _e === void 0 ? void 0 : _e.status;
479
+ const respCode = e.response?.data?.responseMeta?.status ?? e.response?.status;
396
480
  if (respCode === 405) {
397
481
  throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
398
482
  }
399
483
  else if (respCode === 409) {
400
484
  throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
401
485
  }
402
- const message = (_l = (_j = (_h = (_g = (_f = e.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.responseMeta) === null || _h === void 0 ? void 0 : _h.message) !== null && _j !== void 0 ? _j : JSON.stringify((_k = e.response) === null || _k === void 0 ? void 0 : _k.data)) !== null && _l !== void 0 ? _l : (_m = e.response) === null || _m === void 0 ? void 0 : _m.statusText;
486
+ const message = e.response?.data?.responseMeta?.message ??
487
+ JSON.stringify(e.response?.data) ??
488
+ e.response?.statusText;
403
489
  throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
404
490
  }
405
491
  throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
406
492
  }
407
- return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
493
+ return serverResponse?.data?.data;
408
494
  }
409
495
  exports.pushApplication = pushApplication;
410
496
  async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
411
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
412
497
  const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
413
498
  let serverResponse;
414
499
  try {
415
- const config = {
416
- method: "post",
417
- url: serverURL.toString(),
418
- headers: {
419
- Authorization: "Bearer " + token,
420
- [CLI_VERSION_HEADER]: cliVersion,
421
- ...injectedHeaders,
422
- },
423
- data: apiConfig,
424
- };
425
- serverResponse = await (0, axios_1.default)(config);
500
+ const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
501
+ const organization = userMe.organizations[0];
502
+ if (organization.agentType == types_1.AgentType.ONPREMISE &&
503
+ (0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
504
+ const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType);
505
+ const socket = await (0, socket_1.connectToISocketRPCServer)({
506
+ agentUrl,
507
+ superblocksBaseUrl,
508
+ token,
509
+ });
510
+ const resp = await socket.call.v1.public.api.pushCommit({
511
+ apiId,
512
+ apiPb: apiConfig.apiPb,
513
+ branchName: branch,
514
+ commitId: apiConfig.commitId,
515
+ commitMessage: apiConfig.commitMessage,
516
+ });
517
+ socket.close();
518
+ return resp.data;
519
+ }
520
+ else {
521
+ const config = {
522
+ method: "post",
523
+ url: serverURL.toString(),
524
+ headers: {
525
+ Authorization: "Bearer " + token,
526
+ [CLI_VERSION_HEADER]: cliVersion,
527
+ ...injectedHeaders,
528
+ },
529
+ data: apiConfig,
530
+ };
531
+ serverResponse = await (0, axios_1.default)(config);
532
+ }
426
533
  }
427
534
  catch (e) {
428
535
  if (axios_1.default.isAxiosError(e)) {
429
- if (((_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.status) === 405) {
536
+ if (e.response?.data?.responseMeta?.status === 405) {
430
537
  throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
431
538
  }
432
- else if (((_f = (_e = (_d = e.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.responseMeta) === null || _f === void 0 ? void 0 : _f.status) === 409) {
539
+ else if (e.response?.data?.responseMeta?.status === 409) {
433
540
  throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
434
541
  }
435
- const message = (_m = (_k = (_j = (_h = (_g = e.response) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.responseMeta) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : JSON.stringify((_l = e.response) === null || _l === void 0 ? void 0 : _l.data)) !== null && _m !== void 0 ? _m : (_o = e.response) === null || _o === void 0 ? void 0 : _o.statusText;
542
+ const message = e.response?.data?.responseMeta?.message ??
543
+ JSON.stringify(e.response?.data) ??
544
+ e.response?.statusText;
436
545
  throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
437
546
  }
438
547
  throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
439
548
  }
440
- return (_p = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _p === void 0 ? void 0 : _p.data;
549
+ return serverResponse?.data?.data;
441
550
  }
442
551
  exports.pushApi = pushApi;
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,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signingEnabled = void 0;
4
+ const signingEnabled = (flags) => {
5
+ return flags["ui.enable-resource-signing"] ?? false;
6
+ };
7
+ exports.signingEnabled = signingEnabled;
package/dist/sdk.d.ts CHANGED
@@ -1,5 +1,5 @@
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;
@@ -27,15 +27,15 @@ export declare class SuperblocksSdk {
27
27
  validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
28
28
  branchName: string | null;
29
29
  }>;
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<any>;
32
- 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>;
33
33
  pushApplication({ applicationId, applicationConfig, branch, headers, }: {
34
34
  applicationId: string;
35
35
  applicationConfig: PushApplicationWithCommitConfig;
36
36
  branch: string;
37
37
  headers?: Record<string, string>;
38
- }): Promise<import("./client").ApplicationWrapper | undefined>;
38
+ }): Promise<import("./types").RemoteCommitDto | undefined>;
39
39
  pushApi({ apiId, apiConfig, branch, headers, }: {
40
40
  apiId: string;
41
41
  apiConfig: PushApiWithCommitConfig;