@superblocksteam/sdk 2.0.102-next.0 → 2.0.102

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 (150) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/application-build.d.mts.map +1 -1
  3. package/dist/application-build.mjs +1 -1
  4. package/dist/application-build.mjs.map +1 -1
  5. package/dist/cli-replacement/auth-hot-reload.d.mts.map +1 -1
  6. package/dist/cli-replacement/auth-hot-reload.mjs.map +1 -1
  7. package/dist/cli-replacement/automatic-upgrades.d.ts +1 -1
  8. package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -1
  9. package/dist/cli-replacement/automatic-upgrades.js +1 -1
  10. package/dist/cli-replacement/automatic-upgrades.js.map +1 -1
  11. package/dist/cli-replacement/dev.d.mts.map +1 -1
  12. package/dist/cli-replacement/dev.mjs +7 -5
  13. package/dist/cli-replacement/dev.mjs.map +1 -1
  14. package/dist/cli-replacement/git-repo-setup.d.mts.map +1 -1
  15. package/dist/cli-replacement/git-repo-setup.mjs +0 -30
  16. package/dist/cli-replacement/git-repo-setup.mjs.map +1 -1
  17. package/dist/cli-replacement/git-repo-setup.test.mjs.map +1 -1
  18. package/dist/cli-replacement/init.d.ts +2 -2
  19. package/dist/cli-replacement/init.d.ts.map +1 -1
  20. package/dist/cli-replacement/init.js.map +1 -1
  21. package/dist/cli-replacement/version-detection.d.ts.map +1 -1
  22. package/dist/cli-replacement/version-detection.js.map +1 -1
  23. package/dist/cli-replacement/version-detection.test.js.map +1 -1
  24. package/dist/client-sync.test.mjs.map +1 -1
  25. package/dist/client.d.ts +3 -252
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +5 -762
  28. package/dist/client.js.map +1 -1
  29. package/dist/collect-sdk-apis.d.mts.map +1 -1
  30. package/dist/collect-sdk-apis.mjs.map +1 -1
  31. package/dist/collect-sdk-apis.test.mjs.map +1 -1
  32. package/dist/dbfs/client.d.ts.map +1 -1
  33. package/dist/dbfs/client.js.map +1 -1
  34. package/dist/dbfs/client.test.js +1 -1
  35. package/dist/dbfs/client.test.js.map +1 -1
  36. package/dist/dbfs/local.d.ts.map +1 -1
  37. package/dist/dbfs/local.js.map +1 -1
  38. package/dist/dev-utils/custom-build.d.mts.map +1 -1
  39. package/dist/dev-utils/custom-build.mjs.map +1 -1
  40. package/dist/dev-utils/custom-config.d.mts.map +1 -1
  41. package/dist/dev-utils/custom-config.mjs.map +1 -1
  42. package/dist/dev-utils/dev-server.d.mts +2 -2
  43. package/dist/dev-utils/dev-server.d.mts.map +1 -1
  44. package/dist/dev-utils/dev-server.mjs +11 -5
  45. package/dist/dev-utils/dev-server.mjs.map +1 -1
  46. package/dist/dev-utils/token-manager.d.ts.map +1 -1
  47. package/dist/dev-utils/token-manager.js.map +1 -1
  48. package/dist/extract-api-integrations.d.mts +16 -1
  49. package/dist/extract-api-integrations.d.mts.map +1 -1
  50. package/dist/extract-api-integrations.mjs +232 -1
  51. package/dist/extract-api-integrations.mjs.map +1 -1
  52. package/dist/extract-api-integrations.test.mjs.map +1 -1
  53. package/dist/flag.d.ts.map +1 -1
  54. package/dist/flag.js.map +1 -1
  55. package/dist/index.d.ts +1 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js.map +1 -1
  58. package/dist/parse-sdk-registry.d.mts.map +1 -1
  59. package/dist/parse-sdk-registry.mjs.map +1 -1
  60. package/dist/parse-sdk-registry.test.mjs.map +1 -1
  61. package/dist/sdk.d.ts +4 -59
  62. package/dist/sdk.d.ts.map +1 -1
  63. package/dist/sdk.js +1 -184
  64. package/dist/sdk.js.map +1 -1
  65. package/dist/sdk.test.js +2 -72
  66. package/dist/sdk.test.js.map +1 -1
  67. package/dist/socket/handlers.d.ts +1 -1
  68. package/dist/socket/handlers.d.ts.map +1 -1
  69. package/dist/socket/handlers.js.map +1 -1
  70. package/dist/socket/index.d.ts +1 -1
  71. package/dist/socket/index.d.ts.map +1 -1
  72. package/dist/socket/index.js.map +1 -1
  73. package/dist/socket/signing.d.ts +1 -1
  74. package/dist/socket/signing.d.ts.map +1 -1
  75. package/dist/socket/signing.js.map +1 -1
  76. package/dist/telemetry/index.d.ts.map +1 -1
  77. package/dist/telemetry/index.js.map +1 -1
  78. package/dist/telemetry/logging.d.ts.map +1 -1
  79. package/dist/telemetry/logging.js +1 -1
  80. package/dist/telemetry/logging.js.map +1 -1
  81. package/dist/types/common.d.ts +1 -1
  82. package/dist/types/common.d.ts.map +1 -1
  83. package/dist/types/common.js.map +1 -1
  84. package/dist/utils.d.ts +1 -1
  85. package/dist/utils.d.ts.map +1 -1
  86. package/dist/utils.js.map +1 -1
  87. package/dist/version-control.d.mts +1 -1
  88. package/dist/version-control.d.mts.map +1 -1
  89. package/dist/version-control.mjs +2 -2
  90. package/dist/version-control.mjs.map +1 -1
  91. package/dist/vite-plugin-generate-api-build-manifest.d.mts.map +1 -1
  92. package/dist/vite-plugin-generate-api-build-manifest.mjs +3 -3
  93. package/dist/vite-plugin-generate-api-build-manifest.mjs.map +1 -1
  94. package/dist/vite-plugin-inject-sb-ids-transform.d.mts.map +1 -1
  95. package/dist/vite-plugin-inject-sb-ids-transform.mjs +1 -1
  96. package/dist/vite-plugin-inject-sb-ids-transform.mjs.map +1 -1
  97. package/dist/vite-plugin-sdk-api-entry-point.d.mts.map +1 -1
  98. package/dist/vite-plugin-sdk-api-entry-point.mjs.map +1 -1
  99. package/dist/vite-plugin-sdk-api-entry-point.test.mjs.map +1 -1
  100. package/eslint.config.js +17 -2
  101. package/package.json +6 -6
  102. package/src/application-build.mts +1 -4
  103. package/src/cli-replacement/auth-hot-reload.mts +2 -2
  104. package/src/cli-replacement/automatic-upgrades.ts +7 -10
  105. package/src/cli-replacement/dev.mts +17 -17
  106. package/src/cli-replacement/git-repo-setup.mts +1 -34
  107. package/src/cli-replacement/git-repo-setup.test.mts +1 -4
  108. package/src/cli-replacement/init.ts +4 -5
  109. package/src/cli-replacement/version-detection.test.ts +0 -2
  110. package/src/cli-replacement/version-detection.ts +0 -1
  111. package/src/client-sync.test.mts +0 -1
  112. package/src/client.ts +21 -1204
  113. package/src/collect-sdk-apis.mts +0 -1
  114. package/src/collect-sdk-apis.test.mts +0 -2
  115. package/src/dbfs/client.test.ts +1 -2
  116. package/src/dbfs/client.ts +0 -1
  117. package/src/dbfs/local.ts +0 -2
  118. package/src/dev-utils/custom-build.mts +1 -3
  119. package/src/dev-utils/custom-config.mts +0 -1
  120. package/src/dev-utils/dev-server.mts +26 -22
  121. package/src/dev-utils/token-manager.ts +0 -1
  122. package/src/extract-api-integrations.mts +345 -5
  123. package/src/extract-api-integrations.test.mts +0 -1
  124. package/src/flag.ts +0 -1
  125. package/src/index.ts +0 -7
  126. package/src/parse-sdk-registry.mts +0 -1
  127. package/src/parse-sdk-registry.test.mts +0 -2
  128. package/src/sdk.test.ts +5 -85
  129. package/src/sdk.ts +14 -324
  130. package/src/socket/handlers.ts +2 -3
  131. package/src/socket/index.ts +3 -4
  132. package/src/socket/signing.ts +3 -5
  133. package/src/telemetry/index.ts +2 -5
  134. package/src/telemetry/logging.ts +3 -4
  135. package/src/types/common.ts +1 -2
  136. package/src/utils.ts +2 -4
  137. package/src/version-control.mts +18 -21
  138. package/src/vite-plugin-generate-api-build-manifest.mts +7 -10
  139. package/src/vite-plugin-inject-sb-ids-transform.mts +2 -5
  140. package/src/vite-plugin-sdk-api-entry-point.mts +0 -1
  141. package/src/vite-plugin-sdk-api-entry-point.test.mts +0 -2
  142. package/test/clients.test.mts +1 -4
  143. package/test/safe-stringify.test.mts +0 -1
  144. package/test/version-control.test.mts +14 -17
  145. package/tsconfig.tsbuildinfo +1 -1
  146. package/dist/client.fetch-audit-events.test.d.ts +0 -2
  147. package/dist/client.fetch-audit-events.test.d.ts.map +0 -1
  148. package/dist/client.fetch-audit-events.test.js +0 -69
  149. package/dist/client.fetch-audit-events.test.js.map +0 -1
  150. package/src/client.fetch-audit-events.test.ts +0 -82
@@ -1,5 +1,4 @@
1
1
  import path from "node:path";
2
-
3
2
  import {
4
3
  extractIntegrationsFromSource,
5
4
  type IntegrationInfo,
@@ -1,7 +1,5 @@
1
1
  import path from "node:path";
2
-
3
2
  import { describe, it, expect, vi } from "vitest";
4
-
5
3
  import { collectSdkApisFromRegistry } from "./collect-sdk-apis.mjs";
6
4
 
7
5
  describe("collectSdkApisFromRegistry", () => {
@@ -1,6 +1,5 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
1
  import { ExportViewMode, NotFoundError } from "@superblocksteam/shared";
2
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
3
 
5
4
  const { connectToISocketRPCServer, unwrapResponseDto, warn } = vi.hoisted(
6
5
  () => ({
@@ -4,7 +4,6 @@ import {
4
4
  NotFoundError,
5
5
  } from "@superblocksteam/shared";
6
6
  import { unreachable } from "@superblocksteam/util";
7
-
8
7
  import { connectToISocketRPCServer } from "../socket/index.js";
9
8
  import { getLogger } from "../telemetry/logging.js";
10
9
  import { doDownloadDirectoryToLocal, doUploadLocalDirectory } from "./local.js";
package/src/dbfs/local.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as fsp from "node:fs/promises";
2
-
3
2
  import {
4
3
  hashDirectoryContents,
5
4
  hashFileContents,
@@ -7,7 +6,6 @@ import {
7
6
  } from "@superblocksteam/shared";
8
7
  import { unreachable } from "@superblocksteam/util";
9
8
  import { listLocalDirectory } from "@superblocksteam/vite-plugin-file-sync/list-dir";
10
-
11
9
  import type { StdISocketRPCClient } from "../socket/index.js";
12
10
 
13
11
  export async function doDownloadDirectoryToLocal(
@@ -1,13 +1,11 @@
1
1
  import path from "node:path";
2
-
3
2
  import watcher, { type FSWatcher } from "chokidar";
4
3
  import { red } from "colorette";
5
4
  import fs from "fs-extra";
6
5
  import semver from "semver";
7
6
  import { build } from "vite";
8
- import type { Plugin, UserConfig, ViteDevServer } from "vite";
9
-
10
7
  import { getLegacyComponentsConfig } from "./custom-config.mjs";
8
+ import type { Plugin, UserConfig, ViteDevServer } from "vite";
11
9
 
12
10
  // we only need to build if not on React 18
13
11
  export async function isCustomComponentsEnabled() {
@@ -1,5 +1,4 @@
1
1
  import path from "node:path";
2
-
3
2
  import react from "@vitejs/plugin-react";
4
3
  import glob from "fast-glob";
5
4
  import { defineConfig } from "vite";
@@ -1,17 +1,6 @@
1
- import type http from "node:http";
2
1
  import net from "node:net";
3
2
  import os from "node:os";
4
3
  import path from "node:path";
5
-
6
- import react from "@vitejs/plugin-react";
7
- import cors from "cors";
8
- import express from "express";
9
- import type { IRouter, RequestHandler } from "express";
10
- import { createLogger, createServer, loadEnv } from "vite";
11
- import type { HmrOptions } from "vite";
12
- import type { ViteDevServer } from "vite";
13
- import tsconfigPaths from "vite-tsconfig-paths";
14
-
15
4
  import {
16
5
  JwtVerifier,
17
6
  SUPERBLOCKS_LIVE_GIT_BRANCH,
@@ -22,17 +11,12 @@ import {
22
11
  type FileSyncPluginParams,
23
12
  fileSyncVitePlugin,
24
13
  } from "@superblocksteam/vite-plugin-file-sync";
25
- import type {
26
- AiService,
27
- SnapshotManager,
28
- } from "@superblocksteam/vite-plugin-file-sync/ai-service";
29
- import type { GitService } from "@superblocksteam/vite-plugin-file-sync/git-service";
30
- import type { LockService } from "@superblocksteam/vite-plugin-file-sync/lock-service";
31
- import type { OperationQueue } from "@superblocksteam/vite-plugin-file-sync/operation-queue";
32
- import type { SyncService } from "@superblocksteam/vite-plugin-file-sync/sync-service";
33
-
14
+ import react from "@vitejs/plugin-react";
15
+ import cors from "cors";
16
+ import express from "express";
17
+ import { createLogger, createServer, loadEnv } from "vite";
18
+ import tsconfigPaths from "vite-tsconfig-paths";
34
19
  import pkg from "../../package.json" with { type: "json" };
35
- import type { SuperblocksSdk } from "../sdk.js";
36
20
  import { getTracer } from "../telemetry/index.js";
37
21
  import { getErrorMeta, getLogger } from "../telemetry/logging.js";
38
22
  import {
@@ -40,6 +24,7 @@ import {
40
24
  type SuperblocksScopedJwtPayload,
41
25
  } from "../types/scoped-jwt-token-payload.js";
42
26
  import { getCurrentGitBranchIfGit } from "../version-control.mjs";
27
+
43
28
  import createLucideReactImportOptimizer from "../vite-plugin-optimize-lucide-imports.js";
44
29
  import { sdkApiEntryPointPlugin } from "../vite-plugin-sdk-api-entry-point.mjs";
45
30
  import {
@@ -48,6 +33,19 @@ import {
48
33
  } from "./custom-build.mjs";
49
34
  import { buildManifestStubPlugin } from "./vite-plugin-build-manifest-stub.mjs";
50
35
  import { ddRumPlugin } from "./vite-plugin-dd-rum.mjs";
36
+ import type { SuperblocksSdk } from "../sdk.js";
37
+ import type {
38
+ AiService,
39
+ SnapshotManager,
40
+ } from "@superblocksteam/vite-plugin-file-sync/ai-service";
41
+ import type { GitService } from "@superblocksteam/vite-plugin-file-sync/git-service";
42
+ import type { LockService } from "@superblocksteam/vite-plugin-file-sync/lock-service";
43
+ import type { OperationQueue } from "@superblocksteam/vite-plugin-file-sync/operation-queue";
44
+ import type { SyncService } from "@superblocksteam/vite-plugin-file-sync/sync-service";
45
+ import type { IRouter, RequestHandler } from "express";
46
+ import type http from "node:http";
47
+ import type { HmrOptions } from "vite";
48
+ import type { ViteDevServer } from "vite";
51
49
 
52
50
  const tracer = getTracer();
53
51
 
@@ -637,7 +635,6 @@ async function startVite({
637
635
  tracer,
638
636
  logger,
639
637
  superblocksBaseUrl,
640
- appRootDir: root,
641
638
  features,
642
639
  },
643
640
  { isCustomBuildEnabled },
@@ -653,6 +650,13 @@ async function startVite({
653
650
  mode,
654
651
  clearScreen: process.env.SUPERBLOCKS_CLI_ENV !== "local",
655
652
  customLogger: viteLogger,
653
+ optimizeDeps: {
654
+ esbuildOptions: {
655
+ supported: {
656
+ destructuring: true,
657
+ },
658
+ },
659
+ },
656
660
  server: {
657
661
  middlewareMode: true,
658
662
  watch: {
@@ -1,5 +1,4 @@
1
1
  import { EventEmitter } from "node:events";
2
-
3
2
  import type { ITokenManager, TokenUpdateEvent } from "@superblocksteam/util";
4
3
 
5
4
  export class TokenManager extends EventEmitter implements ITokenManager {
@@ -1,5 +1,345 @@
1
- export {
2
- extractIntegrationIdsFromSource,
3
- extractIntegrationsFromSource,
4
- type IntegrationInfo,
5
- } from "@superblocksteam/vite-plugin-file-sync/extract-api-integrations";
1
+ import { parse } from "@babel/parser";
2
+
3
+ export type IntegrationInfo = {
4
+ key: string;
5
+ pluginId: string;
6
+ id: string;
7
+ };
8
+
9
+ type AstNode = {
10
+ type?: string;
11
+ [key: string]: unknown;
12
+ };
13
+
14
+ function isNode(value: unknown): value is AstNode {
15
+ return !!value && typeof value === "object";
16
+ }
17
+
18
+ function getPropertyName(node: unknown): string | undefined {
19
+ if (!isNode(node)) {
20
+ return undefined;
21
+ }
22
+
23
+ if (node.type === "Identifier" && typeof node.name === "string") {
24
+ return node.name;
25
+ }
26
+
27
+ if (node.type === "StringLiteral" && typeof node.value === "string") {
28
+ return node.value;
29
+ }
30
+
31
+ return undefined;
32
+ }
33
+
34
+ function getLiteralString(node: unknown): string | undefined {
35
+ if (!isNode(node)) {
36
+ return undefined;
37
+ }
38
+
39
+ if (node.type === "StringLiteral" && typeof node.value === "string") {
40
+ return node.value;
41
+ }
42
+
43
+ if (
44
+ node.type === "TemplateLiteral" &&
45
+ Array.isArray(node.expressions) &&
46
+ node.expressions.length === 0 &&
47
+ Array.isArray(node.quasis) &&
48
+ node.quasis.length === 1
49
+ ) {
50
+ const quasi = node.quasis[0];
51
+ if (
52
+ isNode(quasi) &&
53
+ isNode(quasi.value) &&
54
+ typeof quasi.value.cooked === "string"
55
+ ) {
56
+ return quasi.value.cooked;
57
+ }
58
+ }
59
+
60
+ return undefined;
61
+ }
62
+
63
+ function getCalleeName(node: unknown): string | undefined {
64
+ if (!isNode(node)) {
65
+ return undefined;
66
+ }
67
+
68
+ if (node.type === "Identifier" && typeof node.name === "string") {
69
+ return node.name;
70
+ }
71
+
72
+ if (node.type === "MemberExpression") {
73
+ return getPropertyName(node.property);
74
+ }
75
+
76
+ return undefined;
77
+ }
78
+
79
+ function unwrapExpression(node: unknown): AstNode | undefined {
80
+ if (!isNode(node)) {
81
+ return undefined;
82
+ }
83
+
84
+ if (
85
+ node.type === "TSAsExpression" ||
86
+ node.type === "TSTypeAssertion" ||
87
+ node.type === "ParenthesizedExpression"
88
+ ) {
89
+ return unwrapExpression(node.expression);
90
+ }
91
+
92
+ return node;
93
+ }
94
+
95
+ function buildVariableInitializerMap(
96
+ programBody: unknown[],
97
+ ): Map<string, unknown> {
98
+ const initializers = new Map<string, unknown>();
99
+
100
+ for (const statement of programBody) {
101
+ if (
102
+ !isNode(statement) ||
103
+ statement.type !== "VariableDeclaration" ||
104
+ !Array.isArray(statement.declarations)
105
+ ) {
106
+ continue;
107
+ }
108
+
109
+ for (const declaration of statement.declarations) {
110
+ if (!isNode(declaration)) {
111
+ continue;
112
+ }
113
+
114
+ const identifier = declaration.id;
115
+ if (
116
+ !isNode(identifier) ||
117
+ identifier.type !== "Identifier" ||
118
+ typeof identifier.name !== "string"
119
+ ) {
120
+ continue;
121
+ }
122
+
123
+ initializers.set(identifier.name, declaration.init);
124
+ }
125
+ }
126
+
127
+ return initializers;
128
+ }
129
+
130
+ function resolveApiConfigObject(
131
+ expression: unknown,
132
+ variableInitializers: Map<string, unknown>,
133
+ ): AstNode | undefined {
134
+ const resolvedExpression = unwrapExpression(expression);
135
+ if (!resolvedExpression) {
136
+ return undefined;
137
+ }
138
+
139
+ if (
140
+ resolvedExpression.type === "Identifier" &&
141
+ typeof resolvedExpression.name === "string"
142
+ ) {
143
+ return resolveApiConfigObject(
144
+ variableInitializers.get(resolvedExpression.name),
145
+ variableInitializers,
146
+ );
147
+ }
148
+
149
+ if (
150
+ resolvedExpression.type !== "CallExpression" ||
151
+ getCalleeName(resolvedExpression.callee) !== "api" ||
152
+ !Array.isArray(resolvedExpression.arguments)
153
+ ) {
154
+ return undefined;
155
+ }
156
+
157
+ const config = unwrapExpression(resolvedExpression.arguments[0]);
158
+ if (!config || config.type !== "ObjectExpression") {
159
+ return undefined;
160
+ }
161
+
162
+ return config;
163
+ }
164
+
165
+ function findExportedApiConfigObject(
166
+ programBody: unknown[],
167
+ ): AstNode | undefined {
168
+ const variableInitializers = buildVariableInitializerMap(programBody);
169
+
170
+ for (const statement of programBody) {
171
+ if (!isNode(statement)) {
172
+ continue;
173
+ }
174
+
175
+ if (statement.type === "ExportDefaultDeclaration") {
176
+ return resolveApiConfigObject(
177
+ statement.declaration,
178
+ variableInitializers,
179
+ );
180
+ }
181
+
182
+ if (
183
+ statement.type === "ExportNamedDeclaration" &&
184
+ Array.isArray(statement.specifiers)
185
+ ) {
186
+ for (const specifier of statement.specifiers) {
187
+ if (
188
+ !isNode(specifier) ||
189
+ specifier.type !== "ExportSpecifier" ||
190
+ getPropertyName(specifier.exported) !== "default"
191
+ ) {
192
+ continue;
193
+ }
194
+
195
+ return resolveApiConfigObject(specifier.local, variableInitializers);
196
+ }
197
+ }
198
+ }
199
+
200
+ return undefined;
201
+ }
202
+
203
+ function buildVariableReferenceMap(
204
+ programBody: unknown[],
205
+ ): Map<string, Omit<IntegrationInfo, "key">> {
206
+ const refs = new Map<string, Omit<IntegrationInfo, "key">>();
207
+
208
+ for (const statement of programBody) {
209
+ if (
210
+ !isNode(statement) ||
211
+ statement.type !== "VariableDeclaration" ||
212
+ !Array.isArray(statement.declarations)
213
+ ) {
214
+ continue;
215
+ }
216
+
217
+ for (const declaration of statement.declarations) {
218
+ if (!isNode(declaration)) {
219
+ continue;
220
+ }
221
+
222
+ const identifier = declaration.id;
223
+ const init = declaration.init;
224
+ if (
225
+ !isNode(identifier) ||
226
+ identifier.type !== "Identifier" ||
227
+ typeof identifier.name !== "string"
228
+ ) {
229
+ continue;
230
+ }
231
+
232
+ if (
233
+ !isNode(init) ||
234
+ init.type !== "CallExpression" ||
235
+ !Array.isArray(init.arguments)
236
+ ) {
237
+ continue;
238
+ }
239
+
240
+ const pluginId = getCalleeName(init.callee);
241
+ const id = getLiteralString(init.arguments[0]);
242
+ if (!pluginId || !id) {
243
+ continue;
244
+ }
245
+
246
+ refs.set(identifier.name, { pluginId, id });
247
+ }
248
+ }
249
+
250
+ return refs;
251
+ }
252
+
253
+ /**
254
+ * Extract integration declarations from an SDK API source file.
255
+ *
256
+ * Supports both inline declarations:
257
+ * `integrations: { db: postgres("uuid") }`
258
+ *
259
+ * and top-level variable references:
260
+ * `const DB = postgres("uuid"); integrations: { db: DB }`
261
+ */
262
+ export function extractIntegrationsFromSource(
263
+ source: string,
264
+ ): IntegrationInfo[] {
265
+ let ast: ReturnType<typeof parse>;
266
+ try {
267
+ ast = parse(source, {
268
+ sourceType: "module",
269
+ plugins: ["typescript"],
270
+ });
271
+ } catch {
272
+ return [];
273
+ }
274
+
275
+ const variableRefs = buildVariableReferenceMap(ast.program.body);
276
+ const apiConfig = findExportedApiConfigObject(ast.program.body);
277
+ if (!apiConfig) {
278
+ return [];
279
+ }
280
+ const results: IntegrationInfo[] = [];
281
+
282
+ const apiConfigProperties = Array.isArray(apiConfig.properties)
283
+ ? apiConfig.properties
284
+ : [];
285
+ const integrationsProperty = apiConfigProperties.find(
286
+ (property: AstNode) =>
287
+ isNode(property) &&
288
+ property.type === "ObjectProperty" &&
289
+ getPropertyName(property.key) === "integrations",
290
+ );
291
+
292
+ if (
293
+ !isNode(integrationsProperty) ||
294
+ !isNode(integrationsProperty.value) ||
295
+ integrationsProperty.value.type !== "ObjectExpression"
296
+ ) {
297
+ return [];
298
+ }
299
+
300
+ const properties = Array.isArray(integrationsProperty.value.properties)
301
+ ? integrationsProperty.value.properties
302
+ : [];
303
+ for (const property of properties) {
304
+ if (!isNode(property) || property.type !== "ObjectProperty") {
305
+ continue;
306
+ }
307
+
308
+ const key = getPropertyName(property.key);
309
+ if (!key) {
310
+ continue;
311
+ }
312
+
313
+ if (
314
+ isNode(property.value) &&
315
+ property.value.type === "CallExpression" &&
316
+ Array.isArray(property.value.arguments)
317
+ ) {
318
+ const pluginId = getCalleeName(property.value.callee);
319
+ const id = getLiteralString(property.value.arguments[0]);
320
+ if (pluginId && id) {
321
+ results.push({ key, pluginId, id });
322
+ }
323
+ continue;
324
+ }
325
+
326
+ if (
327
+ isNode(property.value) &&
328
+ property.value.type === "Identifier" &&
329
+ typeof property.value.name === "string"
330
+ ) {
331
+ const resolved = variableRefs.get(property.value.name);
332
+ if (resolved) {
333
+ results.push({ key, ...resolved });
334
+ }
335
+ }
336
+ }
337
+
338
+ return results;
339
+ }
340
+
341
+ export function extractIntegrationIdsFromSource(source: string): string[] {
342
+ return extractIntegrationsFromSource(source).map(
343
+ (integration) => integration.id,
344
+ );
345
+ }
@@ -1,5 +1,4 @@
1
1
  import { describe, expect, it } from "vitest";
2
-
3
2
  import {
4
3
  extractIntegrationIdsFromSource,
5
4
  extractIntegrationsFromSource,
package/src/flag.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { DEFAULT_LINES_FOR_LARGE_STEPS } from "@superblocksteam/util";
2
-
3
2
  import type { FlagBootstrap } from "./types/index.js";
4
3
 
5
4
  export const signingEnabled = (flags: FlagBootstrap): boolean => {
package/src/index.ts CHANGED
@@ -3,18 +3,11 @@ export { buildApplication } from "./application-build.mjs";
3
3
  export {
4
4
  getCurrentBranchInfo,
5
5
  uploadApplication,
6
- type AuditLogFilters,
7
6
  type CodeModeApplicationWrapper,
8
- type CreateApplicationResult,
9
7
  type CurrentBranch,
10
- type DailyUsageRow,
11
8
  type GetCommitsResponseBody,
12
- type IntegrationFilters,
13
- type IntegrationSummary,
14
9
  type MultiPageApplicationWrapper,
15
10
  type MultiPageApplicationWrapperWithComponents,
16
- type PlanSummary,
17
- type UsageRecordRow,
18
11
  } from "./client.js";
19
12
 
20
13
  export { FeatureFlags } from "./flag.js";
@@ -1,5 +1,4 @@
1
1
  import path from "node:path";
2
-
3
2
  import { parseSdkRegistryFromContent } from "@superblocksteam/vite-plugin-file-sync/parsing";
4
3
 
5
4
  export type RegistryKeyToPath = Map<string, string>;
@@ -1,7 +1,5 @@
1
1
  import path from "node:path";
2
-
3
2
  import { describe, it, expect } from "vitest";
4
-
5
3
  import { parseSdkRegistry } from "./parse-sdk-registry.mjs";
6
4
 
7
5
  describe("parseSdkRegistry", () => {
package/src/sdk.test.ts CHANGED
@@ -1,18 +1,17 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
1
  import {
4
2
  CommitType,
5
3
  BillingPlan,
6
4
  type GetApplicationCommitsResponseBody,
7
5
  type GetPublicOrganizationSummaryResponseBody,
8
6
  } from "@superblocksteam/shared";
7
+ import { beforeEach, describe, expect, it, vi } from "vitest";
9
8
 
10
- const { fetchApplicationCommits, fetchAuditEvents, fetchOrganizationSummary } =
11
- vi.hoisted(() => ({
9
+ const { fetchApplicationCommits, fetchOrganizationSummary } = vi.hoisted(
10
+ () => ({
12
11
  fetchApplicationCommits: vi.fn(),
13
- fetchAuditEvents: vi.fn(),
14
12
  fetchOrganizationSummary: vi.fn(),
15
- }));
13
+ }),
14
+ );
16
15
 
17
16
  vi.mock("./client.js", async () => {
18
17
  const actual = await vi.importActual("./client.js");
@@ -20,7 +19,6 @@ vi.mock("./client.js", async () => {
20
19
  return {
21
20
  ...actual,
22
21
  fetchApplicationCommits,
23
- fetchAuditEvents,
24
22
  fetchOrganizationSummary,
25
23
  };
26
24
  });
@@ -106,81 +104,3 @@ describe("SuperblocksSdk.fetchApplicationCommits", () => {
106
104
  });
107
105
  });
108
106
  });
109
-
110
- describe("SuperblocksSdk.fetchAuditEvents", () => {
111
- beforeEach(() => {
112
- fetchAuditEvents.mockReset();
113
- });
114
-
115
- it("delegates audit event requests with OCSF filters", async () => {
116
- const expectedResponse = {
117
- events: [
118
- {
119
- activity_id: 5,
120
- category_uid: 6,
121
- class_uid: 6003,
122
- status_id: 1,
123
- severity_id: 1,
124
- type_uid: 600305,
125
- time: 1742428800000,
126
- actor: {
127
- user: {
128
- uid: "user-1",
129
- },
130
- },
131
- resource: {
132
- uid: "api-1",
133
- type: "API",
134
- },
135
- metadata: {
136
- log_name: "audit_event",
137
- version: "1.3.0",
138
- product: { name: "Superblocks", vendor_name: "Superblocks" },
139
- },
140
- },
141
- ],
142
- next_cursor: "cursor-2",
143
- };
144
- fetchAuditEvents.mockResolvedValue(expectedResponse);
145
-
146
- const sdk = new SuperblocksSdk(
147
- "test-token",
148
- "https://staging.superblocks.com",
149
- "1.2.3",
150
- );
151
-
152
- await expect(
153
- sdk.fetchAuditEvents({
154
- timeStart: "2025-03-20T00:00:00Z",
155
- timeEnd: "2025-03-21T00:00:00Z",
156
- classUid: 6003,
157
- status: 2,
158
- severity: 4,
159
- actor: "user-1",
160
- resourceType: "API",
161
- resourceId: "api-1",
162
- search: "deploy",
163
- cursor: "cursor-1",
164
- limit: 50,
165
- }),
166
- ).resolves.toEqual(expectedResponse);
167
- expect(fetchAuditEvents).toHaveBeenCalledWith({
168
- cliVersion: "1.2.3",
169
- token: "test-token",
170
- superblocksBaseUrl: "https://staging.superblocks.com",
171
- filters: {
172
- timeStart: "2025-03-20T00:00:00Z",
173
- timeEnd: "2025-03-21T00:00:00Z",
174
- classUid: 6003,
175
- status: 2,
176
- severity: 4,
177
- actor: "user-1",
178
- resourceType: "API",
179
- resourceId: "api-1",
180
- search: "deploy",
181
- cursor: "cursor-1",
182
- limit: 50,
183
- },
184
- });
185
- });
186
- });