@superblocksteam/sdk 2.0.99 → 2.0.100-next.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.
Files changed (71) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/cli-replacement/dev.d.mts.map +1 -1
  3. package/dist/cli-replacement/dev.mjs +64 -20
  4. package/dist/cli-replacement/dev.mjs.map +1 -1
  5. package/dist/cli-replacement/init.d.ts.map +1 -1
  6. package/dist/cli-replacement/init.js +1 -0
  7. package/dist/cli-replacement/init.js.map +1 -1
  8. package/dist/client.d.ts +8 -21
  9. package/dist/client.d.ts.map +1 -1
  10. package/dist/client.js +36 -5
  11. package/dist/client.js.map +1 -1
  12. package/dist/collect-sdk-apis.d.mts +10 -6
  13. package/dist/collect-sdk-apis.d.mts.map +1 -1
  14. package/dist/collect-sdk-apis.mjs +20 -5
  15. package/dist/collect-sdk-apis.mjs.map +1 -1
  16. package/dist/collect-sdk-apis.test.mjs +53 -4
  17. package/dist/collect-sdk-apis.test.mjs.map +1 -1
  18. package/dist/dbfs/client.d.ts +2 -0
  19. package/dist/dbfs/client.d.ts.map +1 -1
  20. package/dist/dbfs/client.js +43 -17
  21. package/dist/dbfs/client.js.map +1 -1
  22. package/dist/dbfs/client.test.d.ts +2 -0
  23. package/dist/dbfs/client.test.d.ts.map +1 -0
  24. package/dist/dbfs/client.test.js +81 -0
  25. package/dist/dbfs/client.test.js.map +1 -0
  26. package/dist/extract-api-integrations.d.mts +17 -0
  27. package/dist/extract-api-integrations.d.mts.map +1 -0
  28. package/dist/extract-api-integrations.mjs +233 -0
  29. package/dist/extract-api-integrations.mjs.map +1 -0
  30. package/dist/extract-api-integrations.test.d.mts +2 -0
  31. package/dist/extract-api-integrations.test.d.mts.map +1 -0
  32. package/dist/extract-api-integrations.test.mjs +97 -0
  33. package/dist/extract-api-integrations.test.mjs.map +1 -0
  34. package/dist/sdk.d.ts +13 -6
  35. package/dist/sdk.d.ts.map +1 -1
  36. package/dist/sdk.js +13 -6
  37. package/dist/sdk.js.map +1 -1
  38. package/dist/sdk.test.d.ts +2 -0
  39. package/dist/sdk.test.d.ts.map +1 -0
  40. package/dist/sdk.test.js +71 -0
  41. package/dist/sdk.test.js.map +1 -0
  42. package/dist/telemetry/index.d.ts.map +1 -1
  43. package/dist/telemetry/index.js +9 -2
  44. package/dist/telemetry/index.js.map +1 -1
  45. package/dist/telemetry/logging.d.ts.map +1 -1
  46. package/dist/telemetry/logging.js +1 -0
  47. package/dist/telemetry/logging.js.map +1 -1
  48. package/dist/version-control.d.mts +5 -3
  49. package/dist/version-control.d.mts.map +1 -1
  50. package/dist/version-control.mjs +18 -10
  51. package/dist/version-control.mjs.map +1 -1
  52. package/dist/vite-plugin-generate-api-build-manifest.d.mts.map +1 -1
  53. package/dist/vite-plugin-generate-api-build-manifest.mjs.map +1 -1
  54. package/package.json +6 -6
  55. package/src/cli-replacement/dev.mts +73 -24
  56. package/src/cli-replacement/init.ts +1 -0
  57. package/src/client.ts +53 -22
  58. package/src/collect-sdk-apis.mts +30 -6
  59. package/src/collect-sdk-apis.test.mts +58 -4
  60. package/src/dbfs/client.test.ts +116 -0
  61. package/src/dbfs/client.ts +60 -21
  62. package/src/extract-api-integrations.mts +345 -0
  63. package/src/extract-api-integrations.test.mts +114 -0
  64. package/src/sdk.test.ts +106 -0
  65. package/src/sdk.ts +40 -3
  66. package/src/telemetry/index.ts +13 -2
  67. package/src/telemetry/logging.ts +1 -0
  68. package/src/version-control.mts +23 -8
  69. package/src/vite-plugin-generate-api-build-manifest.mts +7 -1
  70. package/test/version-control.test.mts +81 -1
  71. package/tsconfig.tsbuildinfo +1 -1
@@ -8,6 +8,7 @@ import type winston from "winston";
8
8
  const activeTransports: winston.transport[] = [];
9
9
 
10
10
  if (process.env.SUPERBLOCKS_IS_CSB === "true") {
11
+ // TODO(alex): Revisit this for cloud-prem if we want logger to write to stdout
11
12
  activeTransports.push(
12
13
  new transports.File({
13
14
  format: format.json(),
@@ -1,7 +1,7 @@
1
1
  import * as https from "https";
2
2
  import path from "node:path";
3
3
  import { dirname } from "path";
4
- import { ExportViewMode } from "@superblocksteam/shared";
4
+ import { DEFAULT_BRANCH, ExportViewMode } from "@superblocksteam/shared";
5
5
  import {
6
6
  RESOURCE_CONFIG_PATH,
7
7
  SUPERBLOCKS_HOME_FOLDER_NAME,
@@ -46,13 +46,13 @@ import type {
46
46
  } from "@superblocksteam/util";
47
47
  import type { SimpleGit, StatusResult } from "simple-git";
48
48
 
49
+ export { DEFAULT_BRANCH };
50
+
49
51
  const LATEST_EDITS_MODE = "latest-edits";
50
52
  export const DRAFT_MODE = "draft";
51
53
  const MOST_RECENT_COMMIT_MODE = "most-recent-commit";
52
54
  const DEPLOYED_MODE = "deployed";
53
55
 
54
- export const DEFAULT_BRANCH = "main";
55
-
56
56
  export const modeFlagValuesMap: Record<string, string> = {
57
57
  [LATEST_EDITS_MODE]: "Latest edits",
58
58
  [DRAFT_MODE]: "Draft",
@@ -556,6 +556,8 @@ export async function writeApplicationToDisk({
556
556
  resource,
557
557
  projectRootFolder,
558
558
  appRelativePath,
559
+ directoryContentsHash,
560
+ branch,
559
561
  featureFlags,
560
562
  migrateFromSinglePage,
561
563
  preferredApiRepresentation,
@@ -566,6 +568,8 @@ export async function writeApplicationToDisk({
566
568
  | CodeModeApplicationWrapper;
567
569
  projectRootFolder: string;
568
570
  appRelativePath?: string;
571
+ directoryContentsHash?: string;
572
+ branch?: string;
569
573
  featureFlags: FeatureFlags;
570
574
  migrateFromSinglePage?: boolean;
571
575
  preferredApiRepresentation?: ApiRepresentation;
@@ -585,6 +589,8 @@ export async function writeApplicationToDisk({
585
589
  sdk,
586
590
  resource,
587
591
  appDirName,
592
+ directoryContentsHash,
593
+ branch,
588
594
  featureFlags,
589
595
  );
590
596
  return {
@@ -774,6 +780,8 @@ async function writeCodeModeApplicationToDisk(
774
780
  sdk: SuperblocksSdk,
775
781
  resource: CodeModeApplicationWrapper,
776
782
  appDirName: string,
783
+ directoryContentsHash: string | undefined,
784
+ branch: string | undefined,
777
785
  featureFlags: FeatureFlags,
778
786
  ): Promise<void> {
779
787
  // Find the existing application config and existing file paths
@@ -798,11 +806,18 @@ async function writeCodeModeApplicationToDisk(
798
806
 
799
807
  // This writes to DBFS
800
808
  try {
801
- await sdk.dbfsGetApplication({
802
- applicationId: resource.application.id,
803
- branch: DEFAULT_BRANCH,
804
- localDirectoryPath: appDirName,
805
- });
809
+ if (directoryContentsHash) {
810
+ await sdk.dbfsGetDirectoryByHash({
811
+ hash: directoryContentsHash,
812
+ localDirectoryPath: appDirName,
813
+ });
814
+ } else {
815
+ await sdk.dbfsGetApplication({
816
+ applicationId: resource.application.id,
817
+ branch: branch ?? DEFAULT_BRANCH,
818
+ localDirectoryPath: appDirName,
819
+ });
820
+ }
806
821
  } catch (e: any) {
807
822
  // This is most likely to happen if the application is not initialized
808
823
  logger.error(e.message);
@@ -61,7 +61,13 @@ export function generateApiBuildManifestPlugin(root: string) {
61
61
  let buildManifest: {
62
62
  apis: Record<string, { api: DeleteMeLibraryApi; scopeId: string }>;
63
63
  apiDependencies: ApiDependency[];
64
- sdkApis: Record<string, { entryPoint: string }>;
64
+ sdkApis: Record<
65
+ string,
66
+ {
67
+ entryPoint: string;
68
+ integrations?: Array<{ key: string; pluginId: string; id: string }>;
69
+ }
70
+ >;
65
71
  } = { apis: {}, apiDependencies: [], sdkApis: {} };
66
72
 
67
73
  return {
@@ -2,7 +2,7 @@ import os from "node:os";
2
2
  import path from "node:path";
3
3
  import { readAppApiYamlFile, LoopType } from "@superblocksteam/util";
4
4
  import fs from "fs-extra";
5
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
6
  import { stringify as ymlstringify } from "yaml";
7
7
  import { FeatureFlags } from "../src/flag.js";
8
8
  import {
@@ -14,8 +14,10 @@ import {
14
14
  } from "../src/version-control.mjs";
15
15
  import type {
16
16
  ApplicationWrapper,
17
+ CodeModeApplicationWrapper,
17
18
  MultiPageApplicationWrapperWithComponents,
18
19
  } from "../src/client.js";
20
+ import type { SuperblocksSdk } from "../src/sdk.js";
19
21
  import type { ApiWithPb } from "../src/types/common.js";
20
22
  import type { ApiRepresentation } from "../src/version-control.mjs";
21
23
  import type {
@@ -930,6 +932,84 @@ describe("version-control", () => {
930
932
  "superblocks.git.split.large.step.lines": 10,
931
933
  });
932
934
 
935
+ it("should use the requested branch for code mode applications", async () => {
936
+ const dbfsGetApplication = vi.fn().mockResolvedValue(undefined);
937
+ const dbfsGetDirectoryByHash = vi.fn().mockResolvedValue(undefined);
938
+ const codeModeApp: CodeModeApplicationWrapper = {
939
+ type: "code-mode",
940
+ application: {
941
+ id: "d7278b3b-f355-4374-baae-cdcca40fb502",
942
+ name: "Code Mode App",
943
+ },
944
+ };
945
+
946
+ const resourceConfig = await writeApplicationToDisk({
947
+ sdk: {
948
+ dbfsGetDirectoryByHash,
949
+ dbfsGetApplication,
950
+ } as unknown as SuperblocksSdk,
951
+ resource: codeModeApp,
952
+ projectRootFolder: testDir,
953
+ branch: "feature/mcp-checkout",
954
+ featureFlags: mockFeatureFlags,
955
+ });
956
+
957
+ expect(resourceConfig.location).toBe("apps/code_mode_app");
958
+ expect(dbfsGetApplication).toHaveBeenCalledWith({
959
+ applicationId: "d7278b3b-f355-4374-baae-cdcca40fb502",
960
+ branch: "feature/mcp-checkout",
961
+ localDirectoryPath: path.join(testDir, "apps/code_mode_app"),
962
+ });
963
+ expect(dbfsGetDirectoryByHash).not.toHaveBeenCalled();
964
+
965
+ const config = await expectSuperblocksJsonFileExists(
966
+ `${testDir}/apps/code_mode_app/`,
967
+ );
968
+ expect(config).toMatchObject({
969
+ configType: "APPLICATION_V2",
970
+ id: "d7278b3b-f355-4374-baae-cdcca40fb502",
971
+ });
972
+ });
973
+
974
+ it("should use a historical directory hash for code mode applications when provided", async () => {
975
+ const dbfsGetApplication = vi.fn().mockResolvedValue(undefined);
976
+ const dbfsGetDirectoryByHash = vi.fn().mockResolvedValue(undefined);
977
+ const codeModeApp: CodeModeApplicationWrapper = {
978
+ type: "code-mode",
979
+ application: {
980
+ id: "d7278b3b-f355-4374-baae-cdcca40fb502",
981
+ name: "Code Mode App",
982
+ },
983
+ };
984
+
985
+ const resourceConfig = await writeApplicationToDisk({
986
+ sdk: {
987
+ dbfsGetDirectoryByHash,
988
+ dbfsGetApplication,
989
+ } as unknown as SuperblocksSdk,
990
+ resource: codeModeApp,
991
+ projectRootFolder: testDir,
992
+ directoryContentsHash: "dir-hash-123",
993
+ branch: "feature/mcp-checkout",
994
+ featureFlags: mockFeatureFlags,
995
+ });
996
+
997
+ expect(resourceConfig.location).toBe("apps/code_mode_app");
998
+ expect(dbfsGetDirectoryByHash).toHaveBeenCalledWith({
999
+ hash: "dir-hash-123",
1000
+ localDirectoryPath: path.join(testDir, "apps/code_mode_app"),
1001
+ });
1002
+ expect(dbfsGetApplication).not.toHaveBeenCalled();
1003
+
1004
+ const config = await expectSuperblocksJsonFileExists(
1005
+ `${testDir}/apps/code_mode_app/`,
1006
+ );
1007
+ expect(config).toMatchObject({
1008
+ configType: "APPLICATION_V2",
1009
+ id: "d7278b3b-f355-4374-baae-cdcca40fb502",
1010
+ });
1011
+ });
1012
+
933
1013
  it("should write multi-pageapp to disk", async () => {
934
1014
  // Setup
935
1015
  const resourceId = "9736f700-88d6-49fc-a519-245a20af248b";