@superblocksteam/sdk 2.0.117 → 2.0.118-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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/cli-replacement/dev.d.mts +6 -0
- package/dist/cli-replacement/dev.d.mts.map +1 -1
- package/dist/cli-replacement/dev.mjs +1 -0
- package/dist/cli-replacement/dev.mjs.map +1 -1
- package/dist/client.d.ts +67 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +94 -0
- package/dist/client.js.map +1 -1
- package/dist/dev-utils/dedupe-async.d.ts +16 -0
- package/dist/dev-utils/dedupe-async.d.ts.map +1 -0
- package/dist/dev-utils/dedupe-async.js +27 -0
- package/dist/dev-utils/dedupe-async.js.map +1 -0
- package/dist/dev-utils/dedupe-async.test.d.ts +2 -0
- package/dist/dev-utils/dedupe-async.test.d.ts.map +1 -0
- package/dist/dev-utils/dedupe-async.test.js +120 -0
- package/dist/dev-utils/dedupe-async.test.js.map +1 -0
- package/dist/dev-utils/dev-server-metrics.d.mts +95 -0
- package/dist/dev-utils/dev-server-metrics.d.mts.map +1 -0
- package/dist/dev-utils/dev-server-metrics.mjs +193 -0
- package/dist/dev-utils/dev-server-metrics.mjs.map +1 -0
- package/dist/dev-utils/dev-server-persist.test.mjs +117 -17
- package/dist/dev-utils/dev-server-persist.test.mjs.map +1 -1
- package/dist/dev-utils/dev-server.d.mts +19 -1
- package/dist/dev-utils/dev-server.d.mts.map +1 -1
- package/dist/dev-utils/dev-server.mjs +296 -28
- package/dist/dev-utils/dev-server.mjs.map +1 -1
- package/dist/flag.d.ts +1 -1
- package/dist/flag.d.ts.map +1 -1
- package/dist/flag.js +3 -3
- package/dist/flag.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +8 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +24 -1
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.test.js +102 -1
- package/dist/sdk.test.js.map +1 -1
- package/dist/telemetry/index.d.ts +2 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +8 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/logging.d.ts +1 -2
- package/dist/telemetry/logging.d.ts.map +1 -1
- package/dist/telemetry/logging.js +1 -1
- package/dist/telemetry/logging.js.map +1 -1
- package/dist/telemetry/memory-metrics.d.ts +3 -0
- package/dist/telemetry/memory-metrics.d.ts.map +1 -0
- package/dist/telemetry/memory-metrics.js +59 -0
- package/dist/telemetry/memory-metrics.js.map +1 -0
- package/dist/types/common.d.ts +1 -1
- package/dist/types/common.d.ts.map +1 -1
- package/dist/version-control.d.mts.map +1 -1
- package/dist/version-control.mjs +14 -19
- package/dist/version-control.mjs.map +1 -1
- package/eslint.config.js +6 -0
- package/package.json +8 -8
- package/src/cli-replacement/dev.mts +8 -0
- package/src/client.ts +189 -6
- package/src/dev-utils/dedupe-async.test.ts +151 -0
- package/src/dev-utils/dedupe-async.ts +45 -0
- package/src/dev-utils/dev-server-metrics.mts +252 -0
- package/src/dev-utils/dev-server-persist.test.mts +170 -19
- package/src/dev-utils/dev-server.mts +366 -32
- package/src/flag.ts +4 -4
- package/src/index.ts +19 -1
- package/src/sdk.test.ts +145 -6
- package/src/sdk.ts +36 -0
- package/src/telemetry/index.ts +9 -1
- package/src/telemetry/logging.ts +2 -2
- package/src/telemetry/memory-metrics.ts +90 -0
- package/src/types/common.ts +1 -1
- package/src/version-control.mts +11 -30
- package/test/version-control.test.mts +0 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/turbo.json +1 -0
package/src/index.ts
CHANGED
|
@@ -7,13 +7,18 @@ export {
|
|
|
7
7
|
type CodeModeApplicationWrapper,
|
|
8
8
|
type CreateApplicationResult,
|
|
9
9
|
type CurrentBranch,
|
|
10
|
+
type BillingUsageLimitsResponse,
|
|
10
11
|
type DailyUsageRow,
|
|
11
12
|
type GetCommitsResponseBody,
|
|
12
13
|
type IntegrationFilters,
|
|
13
14
|
type IntegrationSummary,
|
|
14
15
|
type MultiPageApplicationWrapper,
|
|
15
16
|
type MultiPageApplicationWrapperWithComponents,
|
|
17
|
+
type OrgCreditLimit,
|
|
16
18
|
type PlanSummary,
|
|
19
|
+
type UpdateOrgBillingUsageLimitRequest,
|
|
20
|
+
type UpdateUserBillingUsageLimitRequest,
|
|
21
|
+
type UserCreditLimit,
|
|
17
22
|
type UsageRecordRow,
|
|
18
23
|
} from "./client.js";
|
|
19
24
|
|
|
@@ -65,6 +70,12 @@ export { AUTO_UPGRADE_EXIT_CODE } from "./cli-replacement/automatic-upgrades.js"
|
|
|
65
70
|
export { RESTART_EXIT_CODE } from "./dev-utils/dev-server.mjs";
|
|
66
71
|
|
|
67
72
|
export { createDevServer, preWarmViteCache } from "./dev-utils/dev-server.mjs";
|
|
73
|
+
export {
|
|
74
|
+
devServerMetrics,
|
|
75
|
+
type DevServerEndpoint,
|
|
76
|
+
type DevServerFailureType,
|
|
77
|
+
type WarmActivationOutcome,
|
|
78
|
+
} from "./dev-utils/dev-server-metrics.mjs";
|
|
68
79
|
|
|
69
80
|
export { TokenManager } from "./dev-utils/token-manager.js";
|
|
70
81
|
|
|
@@ -101,7 +112,12 @@ export {
|
|
|
101
112
|
type PackageJsonSnapshotReadResult,
|
|
102
113
|
} from "./cli-replacement/package-json-snapshot.mjs";
|
|
103
114
|
|
|
104
|
-
export {
|
|
115
|
+
export {
|
|
116
|
+
getErrorMeta,
|
|
117
|
+
getLogger,
|
|
118
|
+
type ErrorMeta,
|
|
119
|
+
type Logger,
|
|
120
|
+
} from "./telemetry/logging.js";
|
|
105
121
|
|
|
106
122
|
export {
|
|
107
123
|
AuthHotReloadServer,
|
|
@@ -111,5 +127,7 @@ export {
|
|
|
111
127
|
export {
|
|
112
128
|
configureTelemetry,
|
|
113
129
|
deploymentType,
|
|
130
|
+
getMeter,
|
|
131
|
+
getTracer,
|
|
114
132
|
isCloudPrem,
|
|
115
133
|
} from "./telemetry/index.js";
|
package/src/sdk.test.ts
CHANGED
|
@@ -7,12 +7,23 @@ import {
|
|
|
7
7
|
type GetPublicOrganizationSummaryResponseBody,
|
|
8
8
|
} from "@superblocksteam/shared";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
import type { PlanSummary } from "./index.js";
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
fetchApplicationCommits,
|
|
14
|
+
fetchAuditEvents,
|
|
15
|
+
fetchBillingUsageLimits,
|
|
16
|
+
fetchOrganizationSummary,
|
|
17
|
+
updateOrgBillingUsageLimit,
|
|
18
|
+
updateUserBillingUsageLimit,
|
|
19
|
+
} = vi.hoisted(() => ({
|
|
20
|
+
fetchApplicationCommits: vi.fn(),
|
|
21
|
+
fetchAuditEvents: vi.fn(),
|
|
22
|
+
fetchBillingUsageLimits: vi.fn(),
|
|
23
|
+
fetchOrganizationSummary: vi.fn(),
|
|
24
|
+
updateOrgBillingUsageLimit: vi.fn(),
|
|
25
|
+
updateUserBillingUsageLimit: vi.fn(),
|
|
26
|
+
}));
|
|
16
27
|
|
|
17
28
|
vi.mock("./client.js", async () => {
|
|
18
29
|
const actual = await vi.importActual("./client.js");
|
|
@@ -21,12 +32,55 @@ vi.mock("./client.js", async () => {
|
|
|
21
32
|
...actual,
|
|
22
33
|
fetchApplicationCommits,
|
|
23
34
|
fetchAuditEvents,
|
|
35
|
+
fetchBillingUsageLimits,
|
|
24
36
|
fetchOrganizationSummary,
|
|
37
|
+
updateOrgBillingUsageLimit,
|
|
38
|
+
updateUserBillingUsageLimit,
|
|
25
39
|
};
|
|
26
40
|
});
|
|
27
41
|
|
|
28
42
|
import { SuperblocksSdk } from "./sdk.js";
|
|
29
43
|
|
|
44
|
+
describe("PlanSummary", () => {
|
|
45
|
+
it("types enterprise contract limits and usage fields", () => {
|
|
46
|
+
const plan: PlanSummary = {
|
|
47
|
+
billingInterval: "annual",
|
|
48
|
+
builderSeatsAssigned: 12,
|
|
49
|
+
builderSeatsTotal: 20,
|
|
50
|
+
contractEnd: "2027-05-01",
|
|
51
|
+
contractStart: "2026-05-01",
|
|
52
|
+
contractType: "dollar_commit",
|
|
53
|
+
creditsPerSeat: null,
|
|
54
|
+
currentPlanCredits: 0,
|
|
55
|
+
currentUsageCredits: 0,
|
|
56
|
+
cycleEnd: "2026-05-31",
|
|
57
|
+
cycleStart: "2026-05-01",
|
|
58
|
+
deployedAppCostCents: 2500,
|
|
59
|
+
deployedAppPriceAnnual: null,
|
|
60
|
+
deployedAppPriceMonthly: null,
|
|
61
|
+
deployedAppsAdditional: 0,
|
|
62
|
+
deployedAppsIncluded: 0,
|
|
63
|
+
deployedAppsLimit: 0,
|
|
64
|
+
deployedAppsUsed: 4,
|
|
65
|
+
dollarCommitAmountCents: 1000000,
|
|
66
|
+
dollarCommitUsedCents: 250000,
|
|
67
|
+
overageAppsEnabled: true,
|
|
68
|
+
overageCreditsEnabled: true,
|
|
69
|
+
overageSeatsEnabled: false,
|
|
70
|
+
pricePerSeatAnnual: null,
|
|
71
|
+
pricePerSeatMonthly: null,
|
|
72
|
+
seatsUnlimited: false,
|
|
73
|
+
subscriptionStatus: "active",
|
|
74
|
+
topupCreditsPurchased: 0,
|
|
75
|
+
topupCreditsUsed: 0,
|
|
76
|
+
usageResetPeriodLimit: 0,
|
|
77
|
+
usageResetPeriodType: "monthly",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
expect(plan.dollarCommitUsedCents).toBe(250000);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
30
84
|
describe("SuperblocksSdk.fetchOrganizationSummary", () => {
|
|
31
85
|
beforeEach(() => {
|
|
32
86
|
fetchApplicationCommits.mockReset();
|
|
@@ -66,6 +120,91 @@ describe("SuperblocksSdk.fetchOrganizationSummary", () => {
|
|
|
66
120
|
});
|
|
67
121
|
});
|
|
68
122
|
|
|
123
|
+
describe("SuperblocksSdk billing usage limit methods", () => {
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
fetchBillingUsageLimits.mockReset();
|
|
126
|
+
updateOrgBillingUsageLimit.mockReset();
|
|
127
|
+
updateUserBillingUsageLimit.mockReset();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("delegates listing usage limits with the SDK context", async () => {
|
|
131
|
+
const expectedResponse = {
|
|
132
|
+
limits: [
|
|
133
|
+
{
|
|
134
|
+
id: "limit-1",
|
|
135
|
+
orgId: "org-1",
|
|
136
|
+
userId: null,
|
|
137
|
+
amountLimitCents: null,
|
|
138
|
+
creditLimit: 5000,
|
|
139
|
+
updatedAt: "2026-05-01T00:00:00.000Z",
|
|
140
|
+
updatedBy: "admin-1",
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
orgLimit: null,
|
|
144
|
+
};
|
|
145
|
+
fetchBillingUsageLimits.mockResolvedValue(expectedResponse);
|
|
146
|
+
|
|
147
|
+
const sdk = new SuperblocksSdk(
|
|
148
|
+
"test-token",
|
|
149
|
+
"https://staging.superblocks.com",
|
|
150
|
+
"1.2.3",
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
await expect(sdk.fetchBillingUsageLimits()).resolves.toEqual(
|
|
154
|
+
expectedResponse,
|
|
155
|
+
);
|
|
156
|
+
expect(fetchBillingUsageLimits).toHaveBeenCalledWith({
|
|
157
|
+
cliVersion: "1.2.3",
|
|
158
|
+
token: "test-token",
|
|
159
|
+
superblocksBaseUrl: "https://staging.superblocks.com",
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("delegates user usage limit updates with the SDK context", async () => {
|
|
164
|
+
updateUserBillingUsageLimit.mockResolvedValue({ success: true });
|
|
165
|
+
|
|
166
|
+
const sdk = new SuperblocksSdk(
|
|
167
|
+
"test-token",
|
|
168
|
+
"https://staging.superblocks.com",
|
|
169
|
+
"1.2.3",
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
await expect(
|
|
173
|
+
sdk.updateUserBillingUsageLimit({
|
|
174
|
+
amountLimitCents: 2500,
|
|
175
|
+
userId: "user-1",
|
|
176
|
+
}),
|
|
177
|
+
).resolves.toEqual({ success: true });
|
|
178
|
+
expect(updateUserBillingUsageLimit).toHaveBeenCalledWith({
|
|
179
|
+
cliVersion: "1.2.3",
|
|
180
|
+
token: "test-token",
|
|
181
|
+
superblocksBaseUrl: "https://staging.superblocks.com",
|
|
182
|
+
amountLimitCents: 2500,
|
|
183
|
+
userId: "user-1",
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("delegates organization usage limit updates with the SDK context", async () => {
|
|
188
|
+
updateOrgBillingUsageLimit.mockResolvedValue({ success: true });
|
|
189
|
+
|
|
190
|
+
const sdk = new SuperblocksSdk(
|
|
191
|
+
"test-token",
|
|
192
|
+
"https://staging.superblocks.com",
|
|
193
|
+
"1.2.3",
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
await expect(
|
|
197
|
+
sdk.updateOrgBillingUsageLimit({ creditLimit: 5000 }),
|
|
198
|
+
).resolves.toEqual({ success: true });
|
|
199
|
+
expect(updateOrgBillingUsageLimit).toHaveBeenCalledWith({
|
|
200
|
+
cliVersion: "1.2.3",
|
|
201
|
+
token: "test-token",
|
|
202
|
+
superblocksBaseUrl: "https://staging.superblocks.com",
|
|
203
|
+
creditLimit: 5000,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
69
208
|
describe("SuperblocksSdk.fetchApplicationCommits", () => {
|
|
70
209
|
beforeEach(() => {
|
|
71
210
|
fetchApplicationCommits.mockReset();
|
package/src/sdk.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
fetchChatHistory,
|
|
40
40
|
fetchBillingPlanSummary,
|
|
41
41
|
fetchBillingUsageDaily,
|
|
42
|
+
fetchBillingUsageLimits,
|
|
42
43
|
fetchBillingUsageRecords,
|
|
43
44
|
fetchCurrentUser,
|
|
44
45
|
fetchFact,
|
|
@@ -64,6 +65,8 @@ import {
|
|
|
64
65
|
deployApi,
|
|
65
66
|
fetchApplicationDeployments,
|
|
66
67
|
undeployApplication,
|
|
68
|
+
updateOrgBillingUsageLimit,
|
|
69
|
+
updateUserBillingUsageLimit,
|
|
67
70
|
} from "./client.js";
|
|
68
71
|
import type {
|
|
69
72
|
ApplicationGitConfig,
|
|
@@ -72,6 +75,7 @@ import type {
|
|
|
72
75
|
AuditEventsAggregateResponse,
|
|
73
76
|
CreateApplicationResult,
|
|
74
77
|
CreateRbacAssignmentsRequest,
|
|
78
|
+
BillingUsageLimitsResponse,
|
|
75
79
|
DailyUsageRow,
|
|
76
80
|
FolderMutationPayload,
|
|
77
81
|
FolderSummary,
|
|
@@ -84,7 +88,9 @@ import type {
|
|
|
84
88
|
PushMultiPageApplicationWithCommitConfig,
|
|
85
89
|
SyncRequest,
|
|
86
90
|
SyncResponse,
|
|
91
|
+
UpdateOrgBillingUsageLimitRequest,
|
|
87
92
|
UpdateRbacAssignmentRequest,
|
|
93
|
+
UpdateUserBillingUsageLimitRequest,
|
|
88
94
|
UsageRecordRow,
|
|
89
95
|
} from "./client.js";
|
|
90
96
|
import {
|
|
@@ -893,6 +899,36 @@ export class SuperblocksSdk {
|
|
|
893
899
|
});
|
|
894
900
|
}
|
|
895
901
|
|
|
902
|
+
async fetchBillingUsageLimits(): Promise<BillingUsageLimitsResponse> {
|
|
903
|
+
return fetchBillingUsageLimits({
|
|
904
|
+
cliVersion: this.cliVersion,
|
|
905
|
+
token: this.token,
|
|
906
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
async updateUserBillingUsageLimit(
|
|
911
|
+
input: UpdateUserBillingUsageLimitRequest,
|
|
912
|
+
): Promise<{ success: boolean }> {
|
|
913
|
+
return updateUserBillingUsageLimit({
|
|
914
|
+
cliVersion: this.cliVersion,
|
|
915
|
+
token: this.token,
|
|
916
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
917
|
+
...input,
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
async updateOrgBillingUsageLimit(
|
|
922
|
+
input: UpdateOrgBillingUsageLimitRequest,
|
|
923
|
+
): Promise<{ success: boolean }> {
|
|
924
|
+
return updateOrgBillingUsageLimit({
|
|
925
|
+
cliVersion: this.cliVersion,
|
|
926
|
+
token: this.token,
|
|
927
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
928
|
+
...input,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
|
|
896
932
|
async sync({
|
|
897
933
|
applicationId,
|
|
898
934
|
payload,
|
package/src/telemetry/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
2
|
|
|
3
|
-
import { trace, type Tracer } from "@opentelemetry/api";
|
|
3
|
+
import { metrics, type Meter, trace, type Tracer } from "@opentelemetry/api";
|
|
4
4
|
import { logs, type Logger } from "@opentelemetry/api-logs";
|
|
5
5
|
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
|
|
6
6
|
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
|
|
@@ -230,3 +230,11 @@ export function getTracer(): Tracer {
|
|
|
230
230
|
// Fallback to global API if telemetry not initialized
|
|
231
231
|
return trace.getTracer(SERVICE_NAME, packageJson.version);
|
|
232
232
|
}
|
|
233
|
+
|
|
234
|
+
export function getMeter(): Meter {
|
|
235
|
+
if (isTelemetryInitialized()) {
|
|
236
|
+
return getTelemetryInstance().getMeter(SERVICE_NAME);
|
|
237
|
+
}
|
|
238
|
+
// Fallback to global API if telemetry not initialized
|
|
239
|
+
return metrics.getMeter(SERVICE_NAME, packageJson.version);
|
|
240
|
+
}
|
package/src/telemetry/logging.ts
CHANGED
|
@@ -59,7 +59,7 @@ const winstonLogger = createLogger({
|
|
|
59
59
|
transports: activeTransports,
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
interface ErrorMeta {
|
|
62
|
+
export interface ErrorMeta {
|
|
63
63
|
error: {
|
|
64
64
|
kind: string;
|
|
65
65
|
message: string;
|
|
@@ -156,7 +156,7 @@ export function getErrorMeta(error: unknown): ErrorMeta {
|
|
|
156
156
|
return {
|
|
157
157
|
error: {
|
|
158
158
|
kind: "Unknown Error",
|
|
159
|
-
message:
|
|
159
|
+
message: safeStringify(error) ?? String(error),
|
|
160
160
|
},
|
|
161
161
|
};
|
|
162
162
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PerformanceObserver,
|
|
3
|
+
type PerformanceObserverEntryList,
|
|
4
|
+
} from "node:perf_hooks";
|
|
5
|
+
|
|
6
|
+
import type { BatchObservableResult } from "@opentelemetry/api";
|
|
7
|
+
|
|
8
|
+
import { getMeter } from "./index.js";
|
|
9
|
+
|
|
10
|
+
let cleanupFn: (() => void) | undefined;
|
|
11
|
+
|
|
12
|
+
export function startMemoryMetrics(): void {
|
|
13
|
+
if (cleanupFn) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const meter = getMeter();
|
|
18
|
+
|
|
19
|
+
const heapUsedGauge = meter.createObservableGauge(
|
|
20
|
+
"nodejs.memory.heap_used_bytes",
|
|
21
|
+
{ description: "V8 heap memory used (bytes)", unit: "By" },
|
|
22
|
+
);
|
|
23
|
+
const heapTotalGauge = meter.createObservableGauge(
|
|
24
|
+
"nodejs.memory.heap_total_bytes",
|
|
25
|
+
{ description: "V8 heap memory allocated (bytes)", unit: "By" },
|
|
26
|
+
);
|
|
27
|
+
const rssGauge = meter.createObservableGauge("nodejs.memory.rss_bytes", {
|
|
28
|
+
description: "Resident Set Size - total memory allocated for the process",
|
|
29
|
+
unit: "By",
|
|
30
|
+
});
|
|
31
|
+
const externalGauge = meter.createObservableGauge(
|
|
32
|
+
"nodejs.memory.external_bytes",
|
|
33
|
+
{
|
|
34
|
+
description: "Memory used by C++ objects bound to JavaScript objects",
|
|
35
|
+
unit: "By",
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
const arrayBuffersGauge = meter.createObservableGauge(
|
|
39
|
+
"nodejs.memory.array_buffers_bytes",
|
|
40
|
+
{
|
|
41
|
+
description:
|
|
42
|
+
"Memory allocated for ArrayBuffers and SharedArrayBuffers (also included in external)",
|
|
43
|
+
unit: "By",
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const gcCountCounter = meter.createCounter("nodejs.gc.count", {
|
|
48
|
+
description: "Number of garbage collection events",
|
|
49
|
+
unit: "{event}",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const gauges = [
|
|
53
|
+
heapUsedGauge,
|
|
54
|
+
heapTotalGauge,
|
|
55
|
+
rssGauge,
|
|
56
|
+
externalGauge,
|
|
57
|
+
arrayBuffersGauge,
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// Single memoryUsage() call per export interval for all 5 gauges (idiomatic OTEL batch pattern).
|
|
61
|
+
const batchCb = (result: BatchObservableResult) => {
|
|
62
|
+
const mem = process.memoryUsage();
|
|
63
|
+
result.observe(heapUsedGauge, mem.heapUsed);
|
|
64
|
+
result.observe(heapTotalGauge, mem.heapTotal);
|
|
65
|
+
result.observe(rssGauge, mem.rss);
|
|
66
|
+
result.observe(externalGauge, mem.external);
|
|
67
|
+
result.observe(arrayBuffersGauge, mem.arrayBuffers);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
meter.addBatchObservableCallback(batchCb, gauges);
|
|
71
|
+
|
|
72
|
+
const gcObserver = new PerformanceObserver(
|
|
73
|
+
(list: PerformanceObserverEntryList) => {
|
|
74
|
+
gcCountCounter.add(list.getEntries().length);
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
gcObserver.observe({ entryTypes: ["gc"], buffered: false });
|
|
78
|
+
|
|
79
|
+
cleanupFn = () => {
|
|
80
|
+
gcObserver.disconnect();
|
|
81
|
+
meter.removeBatchObservableCallback(batchCb, gauges);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function stopMemoryMetrics(): void {
|
|
86
|
+
if (cleanupFn) {
|
|
87
|
+
cleanupFn();
|
|
88
|
+
cleanupFn = undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/types/common.ts
CHANGED
|
@@ -12,12 +12,12 @@ export interface UserMeDto {
|
|
|
12
12
|
export interface FlagBootstrap {
|
|
13
13
|
"ui.enable-resource-signing"?: boolean;
|
|
14
14
|
"superblocks.git.split.large.steps.enabled"?: boolean;
|
|
15
|
-
"superblocks.git.split.large.steps.new.enabled"?: boolean;
|
|
16
15
|
"superblocks.git.split.large.step.lines"?: number;
|
|
17
16
|
"ui.code-mode.enable-session-recording"?: boolean;
|
|
18
17
|
"superblocks.dev-server.inactivity-timeout.cloud"?: number;
|
|
19
18
|
"superblocks.dev-server.inactivity-timeout.local"?: number;
|
|
20
19
|
"superblocks.dev-server.llmobs.enabled"?: boolean;
|
|
20
|
+
"superblocks.dev-server.memory-metrics.enabled"?: boolean;
|
|
21
21
|
"superblocks.deploy.include-dot-superblocks"?: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
package/src/version-control.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as https from "https";
|
|
1
|
+
import * as https from "node:https";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { dirname } from "path";
|
|
4
4
|
|
|
5
5
|
import { bold } from "colorette";
|
|
6
6
|
import fs from "fs-extra";
|
|
7
7
|
import { isEmpty, isArray, isObject, get } from "lodash-es";
|
|
8
|
-
import
|
|
8
|
+
import semver from "semver";
|
|
9
9
|
import { simpleGit } from "simple-git";
|
|
10
10
|
import type { SimpleGit, StatusResult } from "simple-git";
|
|
11
11
|
import slugify from "slugify";
|
|
@@ -419,10 +419,7 @@ export async function writeResourceToDisk(
|
|
|
419
419
|
configType: "APPLICATION",
|
|
420
420
|
defaultPageId: resource.page?.id,
|
|
421
421
|
id: resource.application.id,
|
|
422
|
-
metadata: getResourceConfigMetadata(
|
|
423
|
-
featureFlags,
|
|
424
|
-
existingApplicationConfig,
|
|
425
|
-
),
|
|
422
|
+
metadata: getResourceConfigMetadata(existingApplicationConfig),
|
|
426
423
|
};
|
|
427
424
|
|
|
428
425
|
const apiRepresentation =
|
|
@@ -506,10 +503,7 @@ export async function writeResourceToDisk(
|
|
|
506
503
|
const backendConfig: SuperblocksBackendConfig = {
|
|
507
504
|
id: resourceId,
|
|
508
505
|
configType: "BACKEND",
|
|
509
|
-
metadata: getResourceConfigMetadata(
|
|
510
|
-
featureFlags,
|
|
511
|
-
existingBackendConfig,
|
|
512
|
-
),
|
|
506
|
+
metadata: getResourceConfigMetadata(existingBackendConfig),
|
|
513
507
|
};
|
|
514
508
|
|
|
515
509
|
const apiRepresentation =
|
|
@@ -594,7 +588,6 @@ export async function writeApplicationToDisk({
|
|
|
594
588
|
appDirName,
|
|
595
589
|
directoryContentsHash,
|
|
596
590
|
branch,
|
|
597
|
-
featureFlags,
|
|
598
591
|
);
|
|
599
592
|
return {
|
|
600
593
|
location: relativeLocation,
|
|
@@ -636,10 +629,7 @@ async function writeV1ApplicationToDisk(
|
|
|
636
629
|
const newApplicationConfig: SuperblocksApplicationConfig = {
|
|
637
630
|
configType: "APPLICATION",
|
|
638
631
|
id: resource.application.id,
|
|
639
|
-
metadata: getResourceConfigMetadata(
|
|
640
|
-
featureFlags,
|
|
641
|
-
existingApplicationConfig,
|
|
642
|
-
),
|
|
632
|
+
metadata: getResourceConfigMetadata(existingApplicationConfig),
|
|
643
633
|
};
|
|
644
634
|
|
|
645
635
|
const apiRepresentation =
|
|
@@ -785,7 +775,6 @@ async function writeCodeModeApplicationToDisk(
|
|
|
785
775
|
appDirName: string,
|
|
786
776
|
directoryContentsHash: string | undefined,
|
|
787
777
|
branch: string | undefined,
|
|
788
|
-
featureFlags: FeatureFlags,
|
|
789
778
|
): Promise<void> {
|
|
790
779
|
// Find the existing application config and existing file paths
|
|
791
780
|
const existingApplicationConfig =
|
|
@@ -794,10 +783,7 @@ async function writeCodeModeApplicationToDisk(
|
|
|
794
783
|
const newApplicationConfig: SuperblocksApplicationV2Config = {
|
|
795
784
|
configType: "APPLICATION_V2",
|
|
796
785
|
id: resource.application.id,
|
|
797
|
-
metadata: getResourceConfigMetadata(
|
|
798
|
-
featureFlags,
|
|
799
|
-
existingApplicationConfig,
|
|
800
|
-
),
|
|
786
|
+
metadata: getResourceConfigMetadata(existingApplicationConfig),
|
|
801
787
|
};
|
|
802
788
|
|
|
803
789
|
await fs.ensureDir(`${appDirName}/${SUPERBLOCKS_HOME_FOLDER_NAME}`);
|
|
@@ -930,20 +916,15 @@ export function addExistingFilePathsForApi(
|
|
|
930
916
|
}
|
|
931
917
|
|
|
932
918
|
function getResourceConfigMetadata(
|
|
933
|
-
featureFlags: FeatureFlags,
|
|
934
919
|
existingResourceConfig: SuperblocksResourceConfig | undefined,
|
|
935
920
|
): SuperblocksResourceConfigMetadata | undefined {
|
|
936
921
|
if (!existingResourceConfig) {
|
|
937
|
-
// This is a new application
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
} else if (existingResourceConfig.metadata) {
|
|
944
|
-
return existingResourceConfig.metadata;
|
|
922
|
+
// This is a new application; tag the application config with the latest file version.
|
|
923
|
+
return {
|
|
924
|
+
fileVersion: LATEST_FILE_VERSION,
|
|
925
|
+
};
|
|
945
926
|
}
|
|
946
|
-
return
|
|
927
|
+
return existingResourceConfig.metadata;
|
|
947
928
|
}
|
|
948
929
|
|
|
949
930
|
export async function removeResourceFromDisk(
|
|
@@ -662,7 +662,6 @@ describe("version-control", () => {
|
|
|
662
662
|
describe("writeResourcesToDisk", () => {
|
|
663
663
|
const mockFeatureFlags = new FeatureFlags({
|
|
664
664
|
"superblocks.git.split.large.steps.enabled": true,
|
|
665
|
-
"superblocks.git.split.large.steps.new.enabled": true,
|
|
666
665
|
"superblocks.git.split.large.step.lines": 10,
|
|
667
666
|
});
|
|
668
667
|
|
|
@@ -931,7 +930,6 @@ describe("version-control", () => {
|
|
|
931
930
|
describe("writeApplicationToDIsk", () => {
|
|
932
931
|
const mockFeatureFlags = new FeatureFlags({
|
|
933
932
|
"superblocks.git.split.large.steps.enabled": true,
|
|
934
|
-
"superblocks.git.split.large.steps.new.enabled": false,
|
|
935
933
|
"superblocks.git.split.large.step.lines": 10,
|
|
936
934
|
});
|
|
937
935
|
|