@superblocksteam/sdk 1.14.2 → 1.99.99-next.2

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 (155) hide show
  1. package/.mocharc.json +7 -0
  2. package/.prettierrc +18 -0
  3. package/dist/cli-replacement/automatic-upgrades.d.ts +4 -0
  4. package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -0
  5. package/dist/cli-replacement/automatic-upgrades.js +246 -0
  6. package/dist/cli-replacement/automatic-upgrades.js.map +1 -0
  7. package/dist/cli-replacement/dev.d.mts +14 -0
  8. package/dist/cli-replacement/dev.d.mts.map +1 -0
  9. package/dist/cli-replacement/dev.mjs +195 -0
  10. package/dist/cli-replacement/dev.mjs.map +1 -0
  11. package/dist/cli-replacement/init.d.ts +14 -0
  12. package/dist/cli-replacement/init.d.ts.map +1 -0
  13. package/dist/cli-replacement/init.js +26 -0
  14. package/dist/cli-replacement/init.js.map +1 -0
  15. package/dist/client.d.ts +31 -17
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +137 -155
  18. package/dist/client.js.map +1 -0
  19. package/dist/dbfs/client.d.ts +6 -0
  20. package/dist/dbfs/client.d.ts.map +1 -0
  21. package/dist/dbfs/client.js +117 -0
  22. package/dist/dbfs/client.js.map +1 -0
  23. package/dist/dbfs/local.d.ts +15 -0
  24. package/dist/dbfs/local.d.ts.map +1 -0
  25. package/dist/dbfs/local.js +126 -0
  26. package/dist/dbfs/local.js.map +1 -0
  27. package/dist/dev-utils/custom-build.d.mts +4 -0
  28. package/dist/dev-utils/custom-build.d.mts.map +1 -0
  29. package/dist/dev-utils/custom-build.mjs +99 -0
  30. package/dist/dev-utils/custom-build.mjs.map +1 -0
  31. package/dist/dev-utils/custom-config.d.mts +2 -0
  32. package/dist/dev-utils/custom-config.d.mts.map +1 -0
  33. package/dist/dev-utils/custom-config.mjs +57 -0
  34. package/dist/dev-utils/custom-config.mjs.map +1 -0
  35. package/dist/dev-utils/dev-logger.d.mts +8 -0
  36. package/dist/dev-utils/dev-logger.d.mts.map +1 -0
  37. package/dist/dev-utils/dev-logger.mjs +25 -0
  38. package/dist/dev-utils/dev-logger.mjs.map +1 -0
  39. package/dist/dev-utils/dev-server.d.mts +18 -0
  40. package/dist/dev-utils/dev-server.d.mts.map +1 -0
  41. package/dist/dev-utils/dev-server.mjs +283 -0
  42. package/dist/dev-utils/dev-server.mjs.map +1 -0
  43. package/dist/dev-utils/dev-tracer.d.ts +3 -0
  44. package/dist/dev-utils/dev-tracer.d.ts.map +1 -0
  45. package/dist/dev-utils/dev-tracer.js +38 -0
  46. package/dist/dev-utils/dev-tracer.js.map +1 -0
  47. package/dist/dev-utils/vite-plugin-dd-rum.d.mts +10 -0
  48. package/dist/dev-utils/vite-plugin-dd-rum.d.mts.map +1 -0
  49. package/dist/dev-utils/vite-plugin-dd-rum.mjs +34 -0
  50. package/dist/dev-utils/vite-plugin-dd-rum.mjs.map +1 -0
  51. package/dist/dev-utils/vite-plugin-react-transform.d.mts +7 -0
  52. package/dist/dev-utils/vite-plugin-react-transform.d.mts.map +1 -0
  53. package/dist/dev-utils/vite-plugin-react-transform.mjs +110 -0
  54. package/dist/dev-utils/vite-plugin-react-transform.mjs.map +1 -0
  55. package/dist/dev-utils/vite-plugin-sb-cdn.d.mts +34 -0
  56. package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -0
  57. package/dist/dev-utils/vite-plugin-sb-cdn.mjs +720 -0
  58. package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -0
  59. package/dist/errors.d.ts +1 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +4 -9
  62. package/dist/errors.js.map +1 -0
  63. package/dist/flag.d.ts +2 -2
  64. package/dist/flag.d.ts.map +1 -0
  65. package/dist/flag.js +5 -9
  66. package/dist/flag.js.map +1 -0
  67. package/dist/index.d.ts +10 -4
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +10 -20
  70. package/dist/index.js.map +1 -0
  71. package/dist/sdk.d.ts +42 -18
  72. package/dist/sdk.d.ts.map +1 -0
  73. package/dist/sdk.js +47 -43
  74. package/dist/sdk.js.map +1 -0
  75. package/dist/socket/handlers.d.ts +3 -128
  76. package/dist/socket/handlers.d.ts.map +1 -0
  77. package/dist/socket/handlers.js +7 -9
  78. package/dist/socket/handlers.js.map +1 -0
  79. package/dist/socket/index.d.ts +4 -3
  80. package/dist/socket/index.d.ts.map +1 -0
  81. package/dist/socket/index.js +12 -21
  82. package/dist/socket/index.js.map +1 -0
  83. package/dist/socket/signing.d.ts +3 -1
  84. package/dist/socket/signing.d.ts.map +1 -0
  85. package/dist/socket/signing.js +8 -17
  86. package/dist/socket/signing.js.map +1 -0
  87. package/dist/types/common.d.ts +8 -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 +85 -30
  117. package/src/cli-replacement/automatic-upgrades.ts +335 -0
  118. package/src/cli-replacement/dev.mts +276 -0
  119. package/src/cli-replacement/init.ts +47 -0
  120. package/src/client.ts +114 -38
  121. package/src/dbfs/client.ts +162 -0
  122. package/src/dbfs/local.ts +163 -0
  123. package/src/dev-utils/custom-build.mts +113 -0
  124. package/src/dev-utils/custom-config.mts +66 -0
  125. package/src/dev-utils/dev-logger.mts +39 -0
  126. package/src/dev-utils/dev-server.mts +371 -0
  127. package/src/dev-utils/dev-tracer.ts +42 -0
  128. package/src/dev-utils/vite-plugin-dd-rum.mts +47 -0
  129. package/src/dev-utils/vite-plugin-react-transform.mts +130 -0
  130. package/src/dev-utils/vite-plugin-sb-cdn.mts +988 -0
  131. package/src/flag.ts +2 -3
  132. package/src/index.ts +120 -4
  133. package/src/sdk.ts +91 -17
  134. package/src/socket/handlers.ts +9 -147
  135. package/src/socket/index.ts +6 -9
  136. package/src/socket/signing.ts +7 -8
  137. package/src/types/common.ts +9 -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
  153. package/dist/socket/socket.d.ts +0 -60
  154. package/dist/socket/socket.js +0 -261
  155. package/src/socket/socket.ts +0 -400
@@ -0,0 +1,276 @@
1
+ import "../dev-utils/dev-tracer.js";
2
+
3
+ import * as child_process from "node:child_process";
4
+ import * as fsp from "node:fs/promises";
5
+ import { promisify } from "node:util";
6
+ import { maskUnixSignals } from "@superblocksteam/util";
7
+ import { AiService } from "@superblocksteam/vite-plugin-file-sync/ai-service";
8
+ import {
9
+ LockService,
10
+ LockType,
11
+ } from "@superblocksteam/vite-plugin-file-sync/lock-service";
12
+ import { OperationQueue } from "@superblocksteam/vite-plugin-file-sync/operation-queue";
13
+ import { SyncService } from "@superblocksteam/vite-plugin-file-sync/sync-service";
14
+ import { green } from "colorette";
15
+ import { diffJson } from "diff";
16
+ import { resolveCommand } from "package-manager-detector";
17
+ import { detect } from "package-manager-detector/detect";
18
+
19
+ import { getLogger } from "../dev-utils/dev-logger.mjs";
20
+ import { createDevServer } from "../dev-utils/dev-server.mjs";
21
+ import tracer from "../dev-utils/dev-tracer.js";
22
+ import { SuperblocksSdk } from "../sdk.js";
23
+ import { checkVersionsAndUpgrade } from "./automatic-upgrades.js";
24
+ import type { DevLogger } from "../dev-utils/dev-logger.mjs";
25
+ import type { ApplicationConfig } from "../types/common.js";
26
+ import type { DraftInterface } from "@superblocksteam/vite-plugin-file-sync/draft-interface";
27
+
28
+ const exec = promisify(child_process.exec);
29
+
30
+ const passErrorToVSCode = (message: string | undefined, logger: DevLogger) => {
31
+ if (message) {
32
+ // Prefixing with `clierr:` will make the VS code extension capture this message and show it to the user.
33
+ logger.error(`clierr: ${JSON.stringify({ message })}`);
34
+ }
35
+ };
36
+
37
+ async function readPkgJson(cwd: string) {
38
+ try {
39
+ const { readPackage } = await import("read-pkg");
40
+ return await readPackage({ cwd });
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ async function installPackages(cwd: string, logger: DevLogger) {
47
+ try {
48
+ const pm = await detect({
49
+ strategies: [
50
+ "packageManager-field",
51
+ "lockfile",
52
+ "install-metadata",
53
+ "devEngines-field",
54
+ ],
55
+ cwd,
56
+ });
57
+
58
+ if (!pm) {
59
+ logger.warn(
60
+ "Could not detect package manager, skipping package installation",
61
+ );
62
+ return;
63
+ }
64
+
65
+ const installCommand = resolveCommand(pm.agent, "install", []);
66
+
67
+ if (!installCommand) {
68
+ logger.warn(
69
+ `Could not determine install command for ${pm.agent}, skipping package installation`,
70
+ );
71
+ return;
72
+ }
73
+
74
+ const { command, args } = installCommand;
75
+ logger.info(
76
+ `Running ${command} ${args.join(" ")} to install dependencies…`,
77
+ );
78
+
79
+ await exec(`${command} ${args.join(" ")}`, { cwd });
80
+ logger.info("Package installation completed successfully");
81
+ } catch (error) {
82
+ logger.error(`Error during package installation: ${error}`);
83
+ throw error;
84
+ }
85
+ }
86
+
87
+ export async function dev(options: {
88
+ /* cwd is required */
89
+ cwd: string;
90
+ pidfilePath?: string;
91
+ devServerPort?: number;
92
+
93
+ /* user control of sync operations */
94
+ uploadFirst?: boolean;
95
+ downloadFirst?: boolean;
96
+ /* only used for testing purposes */
97
+ skipSync?: boolean;
98
+
99
+ applicationConfig?: ApplicationConfig;
100
+ /* For redirecting output, like when running outside of the CLI */
101
+ logger?: (message: string) => void;
102
+
103
+ /* To cancel the dev server */
104
+ signal?: AbortSignal;
105
+ }) {
106
+ const logger = getLogger(options.logger);
107
+
108
+ const {
109
+ cwd,
110
+ pidfilePath,
111
+ devServerPort,
112
+ downloadFirst,
113
+ uploadFirst,
114
+ skipSync,
115
+ applicationConfig,
116
+ } = options;
117
+
118
+ if (pidfilePath) {
119
+ await fsp.writeFile(pidfilePath, `${process.pid}\n`);
120
+ }
121
+
122
+ const port = devServerPort ?? 5173;
123
+
124
+ const fsOperationQueue = new OperationQueue();
125
+ let syncService: SyncService | undefined;
126
+ let lockService: LockService | undefined;
127
+ let aiService: AiService | undefined;
128
+
129
+ if (applicationConfig && !skipSync) {
130
+ lockService = new LockService({
131
+ authToken: applicationConfig.token,
132
+ superblocksBaseUrl: applicationConfig.superblocksBaseUrl,
133
+ applicationId: applicationConfig.id,
134
+ branchName: applicationConfig.branchName,
135
+ lockType:
136
+ process.env.SUPERBLOCKS_IS_CSB === "true"
137
+ ? LockType.CSB
138
+ : LockType.LOCAL,
139
+ tracer,
140
+ });
141
+ syncService = new SyncService({
142
+ authToken: applicationConfig.token,
143
+ superblocksBaseUrl: applicationConfig.superblocksBaseUrl,
144
+ appRootDirPath: cwd,
145
+ applicationId: applicationConfig.id,
146
+ branchName: applicationConfig.branchName,
147
+ fsOperationQueue,
148
+ lockService,
149
+ tracer,
150
+ });
151
+
152
+ logger.info("Checking if local files are synced with the server");
153
+
154
+ try {
155
+ await maskUnixSignals(async () => {
156
+ const sdk = new SuperblocksSdk(
157
+ applicationConfig.token,
158
+ applicationConfig.superblocksBaseUrl,
159
+ "",
160
+ );
161
+
162
+ if (lockService) {
163
+ try {
164
+ await lockService!.acquireLock();
165
+
166
+ // TODO(code-mode): package naming is preventing upgrade in ephemeral environments
167
+ if (
168
+ !process.env.PACKAGE_SUFFIX ||
169
+ process.env.PACKAGE_SUFFIX === ""
170
+ ) {
171
+ await checkVersionsAndUpgrade(lockService, applicationConfig);
172
+ }
173
+ } catch (error) {
174
+ logger.error("Failed to acquire lock on application", error);
175
+ passErrorToVSCode(
176
+ (error as { context?: { message: string } }).context?.message,
177
+ logger,
178
+ );
179
+ throw new Error(`Failed to acquire lock on application: ${error}`);
180
+ }
181
+ }
182
+
183
+ const [localContents, serverHash, currentUser] = await Promise.all([
184
+ sdk.hashLocalDirectory(cwd),
185
+ sdk.dbfsGetApplicationDirectoryHash({
186
+ applicationId: applicationConfig.id,
187
+ branch: applicationConfig.branchName,
188
+ }),
189
+ sdk.fetchCurrentUser(),
190
+ ]);
191
+
192
+ aiService = new AiService({
193
+ authToken: applicationConfig.token,
194
+ superblocksBaseUrl: applicationConfig.superblocksBaseUrl,
195
+ appRootDirPath: options.cwd,
196
+ applicationId: applicationConfig.id,
197
+ organizationId: currentUser.organizations[0].id,
198
+ anthropicApiKey: process.env.ANTHROPIC_API_KEY || "",
199
+ fsOperationQueue,
200
+ draftInterface: syncService! as DraftInterface,
201
+ });
202
+
203
+ const isSynced = localContents.hash === serverHash;
204
+
205
+ if (isSynced) {
206
+ logger.info("Local files are in sync with the server");
207
+ return;
208
+ }
209
+
210
+ logger.info("Local files are out of sync with the server");
211
+
212
+ if (!(downloadFirst || uploadFirst)) {
213
+ throw new Error(
214
+ "You must choose --download-first or --upload-first to use the dev command",
215
+ );
216
+ }
217
+ if (downloadFirst && uploadFirst) {
218
+ throw new Error("Choose either --download-first or --upload-first");
219
+ }
220
+
221
+ if (downloadFirst) {
222
+ logger.info(
223
+ "Starting directory sync from server before starting the local server",
224
+ );
225
+
226
+ // Read package.json before download
227
+ const packageJsonBefore = await readPkgJson(cwd);
228
+
229
+ await syncService!.downloadDirectory();
230
+
231
+ // Read package.json after download and compare
232
+ const packageJsonAfter = await readPkgJson(cwd);
233
+
234
+ // Check if package.json changed
235
+ if (packageJsonBefore && packageJsonAfter) {
236
+ const diff = diffJson(packageJsonBefore, packageJsonAfter);
237
+ const hasChanges = diff.some((part) => part.added || part.removed);
238
+
239
+ if (hasChanges) {
240
+ logger.info("package.json has changed, installing packages…");
241
+ await installPackages(cwd, logger);
242
+ }
243
+ }
244
+ } else if (uploadFirst) {
245
+ logger.info("Uploading local files to server before starting");
246
+ await syncService!.uploadDirectory();
247
+ }
248
+ });
249
+ } catch (error: any) {
250
+ logger.error(error.message);
251
+ process.exit(1);
252
+ }
253
+ } else {
254
+ logger.info("Skipping directory sync");
255
+ }
256
+
257
+ const httpServer = await createDevServer({
258
+ root: options.cwd,
259
+ mode: "development",
260
+ port: port,
261
+ fsOperationQueue,
262
+ syncService,
263
+ lockService,
264
+ aiService,
265
+ logger: options.logger,
266
+ });
267
+
268
+ options.signal?.addEventListener("abort", () => {
269
+ logger.info("Server closed");
270
+ httpServer.close();
271
+ });
272
+
273
+ logger.debug(green(`Local server started at port ${port}`));
274
+ logger.debug(green(`Visit your application at:`));
275
+ logger.debug(green(`http://localhost:${port}`));
276
+ }
@@ -0,0 +1,47 @@
1
+ import { ComponentEvent } from "@superblocksteam/shared";
2
+ import { COMPONENT_EVENT_HEADER } from "@superblocksteam/util";
3
+ import { writeApplicationToDisk } from "../version-control.mjs";
4
+ import { DEFAULT_BRANCH } from "../version-control.mjs";
5
+ import type { FeatureFlags } from "../flag.js";
6
+ import type { SuperblocksSdk } from "../sdk.js";
7
+ import type { ExportViewMode } from "@superblocksteam/shared";
8
+ import type { VersionedResourceConfig } from "@superblocksteam/util";
9
+
10
+ export async function fetchAndWriteApplication({
11
+ resourceId,
12
+ viewMode,
13
+ featureFlags,
14
+ projectRootFolder,
15
+ appRelativePath,
16
+ sdk,
17
+ skipSigningVerification,
18
+ }: {
19
+ resourceId: string;
20
+ viewMode: ExportViewMode;
21
+ featureFlags: FeatureFlags;
22
+ projectRootFolder: string;
23
+ appRelativePath?: string;
24
+ sdk: SuperblocksSdk;
25
+ skipSigningVerification: boolean;
26
+ }): Promise<VersionedResourceConfig | undefined> {
27
+ const headers: Record<string, string> = {
28
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.INIT,
29
+ };
30
+
31
+ const application = await sdk.fetchApplicationWithComponents({
32
+ applicationId: resourceId,
33
+ branch: DEFAULT_BRANCH,
34
+ viewMode: viewMode,
35
+ headers,
36
+ skipSigningVerification,
37
+ });
38
+ if (application) {
39
+ return await writeApplicationToDisk({
40
+ sdk,
41
+ resource: application,
42
+ projectRootFolder,
43
+ appRelativePath,
44
+ featureFlags,
45
+ });
46
+ }
47
+ }
package/src/client.ts CHANGED
@@ -1,38 +1,42 @@
1
1
  import * as fs from "fs";
2
+ import { Bucketeer, FileDescriptor } from "@superblocksteam/bucketeer-sdk";
3
+ import { ExportViewMode } from "@superblocksteam/shared";
2
4
  import {
3
5
  COMPONENT_EVENT_HEADER,
4
6
  ComponentEvent,
5
7
  ForbiddenError,
6
8
  getBucketeerUrlFromSuperblocksUrl,
7
9
  getContentType,
8
- LocalGitRepoState,
9
10
  NotFoundError,
10
- SuperblocksResourceType,
11
11
  BadRequestError,
12
12
  unreachable,
13
- ValidateGitSetupRequestBody,
14
13
  } from "@superblocksteam/util";
15
- import axios, { AxiosError, AxiosRequestConfig } from "axios";
14
+ import axios, { AxiosError } from "axios";
16
15
  import FormData from "form-data";
17
- import { isEqual, isEmpty } from "lodash";
16
+ import { isEqual, isEmpty } from "lodash-es";
18
17
  import {
19
18
  BranchNotCheckedOutError,
20
19
  CommitAlreadyExistsError,
21
20
  ValidateGitSetupError,
22
- } from "./errors";
23
- import { signingEnabled } from "./flag";
24
- import { connectToISocketRPCServer, StdISocketRPCClient } from "./socket";
25
- import {
26
- AgentType,
27
- Api,
21
+ } from "./errors.js";
22
+ import { signingEnabled } from "./flag.js";
23
+ import { connectToISocketRPCServer } from "./socket/index.js";
24
+ import { AgentType } from "./types/index.js";
25
+ import { getAgentUrl } from "./utils.js";
26
+ import type { StdISocketRPCClient } from "./socket/index.js";
27
+ import type {
28
28
  ApiWithPb,
29
29
  Page,
30
30
  RemoteCommitDto,
31
- UserMeDto,
32
- ViewMode,
33
31
  DeploymentDto,
34
- } from "./types";
35
- import { getAgentUrl } from "./utils";
32
+ UserMeDto,
33
+ } from "./types/index.js";
34
+ import type {
35
+ LocalGitRepoState,
36
+ SuperblocksResourceType,
37
+ ValidateGitSetupRequestBody,
38
+ } from "@superblocksteam/util";
39
+ import type { AxiosRequestConfig } from "axios";
36
40
 
37
41
  const BASE_BUCKETEER_URL = "api";
38
42
  const BASE_SERVER_PUBLIC_API_URL_V1 = "api/v1/public";
@@ -63,23 +67,31 @@ export interface MultiPageApplicationWrapper {
63
67
  apis: Record<string, any>[];
64
68
  }
65
69
 
70
+ export interface MultiPageApplicationWrapperWithComponents {
71
+ type: "multi-page";
72
+ application: Record<string, any>;
73
+ pages: Page[];
74
+ apis: Record<string, any>[];
75
+ componentFiles: any;
76
+ }
77
+
78
+ export interface CodeModeApplicationWrapper {
79
+ type: "code-mode";
80
+ application: Record<string, any>;
81
+ }
82
+
66
83
  export type PushMultiPageApplicationWithCommitConfig =
67
84
  MultiPageApplicationWrapper & {
68
- commitId?: string;
69
- commitMessage?: string;
85
+ commitId: string;
86
+ commitMessage: string;
70
87
  gitState: LocalGitRepoState;
71
88
  skipCommit: boolean;
72
89
  };
73
90
 
74
- export interface ApiWrapper {
75
- apiPb: Api;
76
- name?: string; //@deprecated this attribute is used for getting a name for backends(jobs and workflows) that were never migrated to the new API version.
77
- }
78
-
79
91
  export type PushApiWithCommitConfig = {
80
92
  apiPb: Record<string, any>;
81
- commitId?: string;
82
- commitMessage?: string;
93
+ commitId: string;
94
+ commitMessage: string;
83
95
  gitState: LocalGitRepoState;
84
96
  skipCommit: boolean;
85
97
  };
@@ -136,12 +148,12 @@ export async function fetchApplication({
136
148
  branch?: string;
137
149
  token: string;
138
150
  superblocksBaseUrl: string;
139
- viewMode: ViewMode;
151
+ viewMode: ExportViewMode;
140
152
  commitId?: string;
141
153
  skipSigningVerification?: boolean;
142
154
  injectedHeaders: Record<string, string>;
143
155
  }): Promise<MultiPageApplicationWrapper | undefined> {
144
- if (commitId && viewMode !== "export-commit") {
156
+ if (commitId && viewMode !== ExportViewMode.EXPORT_COMMIT) {
145
157
  throw new Error(
146
158
  `If commitId ${commitId} is provided, viewMode cannot be ${viewMode}`,
147
159
  );
@@ -177,7 +189,7 @@ export async function fetchApplication({
177
189
  branchName: branch,
178
190
  commitId,
179
191
  });
180
- return resp.data;
192
+ return resp.data as unknown as MultiPageApplicationWrapper;
181
193
  } finally {
182
194
  socket.close();
183
195
  }
@@ -263,14 +275,13 @@ export async function fetchApplicationWithComponents({
263
275
  branch: string;
264
276
  token: string;
265
277
  superblocksBaseUrl: string;
266
- viewMode: ViewMode;
278
+ viewMode: ExportViewMode;
267
279
  commitId?: string;
268
280
  skipSigningVerification?: boolean;
269
281
  injectedHeaders: Record<string, string>;
270
282
  }): Promise<
271
- | (MultiPageApplicationWrapper & {
272
- componentFiles: any;
273
- })
283
+ | MultiPageApplicationWrapperWithComponents
284
+ | CodeModeApplicationWrapper
274
285
  | undefined
275
286
  > {
276
287
  const applicationWrapper = await fetchApplication({
@@ -289,9 +300,48 @@ export async function fetchApplicationWithComponents({
289
300
  return;
290
301
  }
291
302
 
303
+ if (applicationWrapper.application.devEnvEnabled) {
304
+ return {
305
+ type: "code-mode",
306
+ ...applicationWrapper,
307
+ } satisfies CodeModeApplicationWrapper;
308
+ }
309
+
310
+ return await fetchApplicationWithComponentsFromBucketeer({
311
+ applicationWrapper,
312
+ superblocksBaseUrl,
313
+ applicationId,
314
+ branch,
315
+ commitId,
316
+ viewMode,
317
+ token,
318
+ injectedHeaders,
319
+ });
320
+ }
321
+
322
+ async function fetchApplicationWithComponentsFromBucketeer({
323
+ applicationWrapper,
324
+ superblocksBaseUrl,
325
+ applicationId,
326
+ branch,
327
+ commitId,
328
+ viewMode,
329
+ token,
330
+ injectedHeaders,
331
+ }: {
332
+ applicationWrapper: MultiPageApplicationWrapper;
333
+ superblocksBaseUrl: string;
334
+ applicationId: string;
335
+ branch: string;
336
+ commitId?: string;
337
+ viewMode: ExportViewMode;
338
+ token: string;
339
+ injectedHeaders: Record<string, string>;
340
+ }): Promise<MultiPageApplicationWrapperWithComponents> {
292
341
  // if there are no custom components, just return here without trying to initialize them using bucketeer
293
342
  if (isEmpty(applicationWrapper.application?.settings?.registeredComponents)) {
294
343
  return {
344
+ type: "multi-page",
295
345
  ...applicationWrapper,
296
346
  componentFiles: null,
297
347
  };
@@ -318,9 +368,7 @@ export async function fetchApplicationWithComponents({
318
368
  },
319
369
  };
320
370
  const bucketeerApp = (await axios(config))
321
- .data as MultiPageApplicationWrapper & {
322
- componentFiles: any;
323
- };
371
+ .data as MultiPageApplicationWrapperWithComponents;
324
372
 
325
373
  if (
326
374
  !isEqual(
@@ -383,7 +431,7 @@ export async function fetchApi(
383
431
  apiId: string,
384
432
  token: string,
385
433
  superblocksBaseUrl: string,
386
- viewMode: ViewMode,
434
+ viewMode: ExportViewMode,
387
435
  branch?: string,
388
436
  commitId?: string,
389
437
  skipSigningVerification = false,
@@ -716,7 +764,7 @@ You can reduce your component bundle size by uploading static assets to a separa
716
764
  branchName: branch ?? undefined,
717
765
  srcFiles: srcFiles.map((file) => file.filename),
718
766
  buildFiles: buildFiles.map((file) => file.filename),
719
- registeredComponents: componentConfigs,
767
+ registeredComponents: componentConfigs as Record<string, never>,
720
768
  cliVersion,
721
769
  componentBaseUrl: uploadResponse.data.componentBaseUrl,
722
770
  signingRequired: !isEmpty(initialSocket),
@@ -858,7 +906,7 @@ export async function pushApplication({
858
906
  if (resp.responseMeta.status !== 200) {
859
907
  // Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
860
908
  const message: string =
861
- (resp?.responseMeta?.message as string) ?? JSON.stringify(resp?.data);
909
+ resp?.responseMeta?.message ?? JSON.stringify(resp?.data);
862
910
  throw new Error(message);
863
911
  }
864
912
  return resp.data;
@@ -968,7 +1016,7 @@ export async function pushApi({
968
1016
  if (resp.responseMeta.status !== 200) {
969
1017
  // Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
970
1018
  const message: string =
971
- (resp?.responseMeta?.message as string) ?? JSON.stringify(resp?.data);
1019
+ resp?.responseMeta?.message ?? JSON.stringify(resp?.data);
972
1020
  throw new Error(message);
973
1021
  }
974
1022
  return resp.data;
@@ -1215,3 +1263,31 @@ async function deployResource(
1215
1263
  throw new Error(`${e.message}`);
1216
1264
  }
1217
1265
  }
1266
+
1267
+ export async function uploadApplication({
1268
+ files,
1269
+ scopedJwt,
1270
+ url,
1271
+ cliVersion,
1272
+ }: {
1273
+ files: string[];
1274
+ scopedJwt: string;
1275
+ url: string;
1276
+ cliVersion: string;
1277
+ }) {
1278
+ const fds = filesToFileDescriptors(files);
1279
+ const bucketeer = new Bucketeer({
1280
+ token: scopedJwt,
1281
+ baseUrl: url,
1282
+ cliVersion,
1283
+ maxTotalFileSizeMB: SUPERBLOCKS_MAX_FILE_SIZE_MB,
1284
+ });
1285
+ await bucketeer.uploadApplication(fds);
1286
+ }
1287
+
1288
+ function filesToFileDescriptors(files: string[]) {
1289
+ const fds = files.map((file) => {
1290
+ return new FileDescriptor(file, fs.createReadStream(file));
1291
+ });
1292
+ return fds;
1293
+ }