@squadbase/vite-server 0.1.18 → 0.1.19-dev.40d2ebd
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/build-entry/server-entry.mjs +18 -0
- package/dist/cli/index.js +42 -32
- package/dist/connectors/google-analytics-oauth.js +55 -45
- package/dist/index.d.ts +8 -1
- package/dist/index.js +72 -45
- package/dist/main.d.ts +1 -0
- package/dist/main.js +73 -46
- package/dist/vite-plugin.d.ts +0 -1
- package/dist/vite-plugin.js +125 -45
- package/package.json +3 -6
package/dist/vite-plugin.js
CHANGED
|
@@ -622,6 +622,7 @@ import devServer from "@hono/vite-dev-server";
|
|
|
622
622
|
import nodeAdapter from "@hono/vite-dev-server/node";
|
|
623
623
|
import { fileURLToPath } from "url";
|
|
624
624
|
import path3 from "path";
|
|
625
|
+
import fs from "fs";
|
|
625
626
|
|
|
626
627
|
// src/registry.ts
|
|
627
628
|
import { readdir, readFile as readFile2, mkdir } from "fs/promises";
|
|
@@ -10548,8 +10549,8 @@ init_parameter_definition();
|
|
|
10548
10549
|
var parameters16 = {
|
|
10549
10550
|
propertyId: new ParameterDefinition({
|
|
10550
10551
|
slug: "property-id",
|
|
10551
|
-
name: "
|
|
10552
|
-
description: "
|
|
10552
|
+
name: "Default Property ID",
|
|
10553
|
+
description: "Optional default Google Analytics 4 property ID (e.g., 123456789) used when a request does not specify one. Can be found in GA4 Admin > Property Settings. Leave empty to always pass the property ID per request.",
|
|
10553
10554
|
envVarBaseKey: "GA_OAUTH_PROPERTY_ID",
|
|
10554
10555
|
type: "text",
|
|
10555
10556
|
secret: false,
|
|
@@ -10862,7 +10863,7 @@ var inputSchema25 = z25.object({
|
|
|
10862
10863
|
connectionId: z25.string().describe("ID of the Google Analytics OAuth connection to use"),
|
|
10863
10864
|
method: z25.enum(["GET", "POST"]).describe("HTTP method"),
|
|
10864
10865
|
path: z25.string().describe(
|
|
10865
|
-
"API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/
|
|
10866
|
+
"API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/123456789:runReport'). Write the numeric property id directly; the {propertyId} placeholder is only substituted when a default property is configured on the connection."
|
|
10866
10867
|
),
|
|
10867
10868
|
body: z25.record(z25.string(), z25.unknown()).optional().describe("POST request body (JSON)")
|
|
10868
10869
|
});
|
|
@@ -10881,7 +10882,7 @@ var requestTool4 = new ConnectorTool({
|
|
|
10881
10882
|
name: "request",
|
|
10882
10883
|
description: `Send authenticated requests to the Google Analytics Data API v1beta.
|
|
10883
10884
|
Authentication is handled automatically via OAuth proxy.
|
|
10884
|
-
|
|
10885
|
+
Write the numeric property id directly into the path (e.g. properties/123456789:runReport). The {propertyId} placeholder is only substituted when a default property is configured on the connection.`,
|
|
10885
10886
|
inputSchema: inputSchema25,
|
|
10886
10887
|
outputSchema: outputSchema25,
|
|
10887
10888
|
async execute({ connectionId, method, path: path4, body }, connections, config) {
|
|
@@ -10968,7 +10969,7 @@ var googleAnalyticsOauthConnector = new ConnectorPlugin({
|
|
|
10968
10969
|
systemPrompt: {
|
|
10969
10970
|
en: `### Tools
|
|
10970
10971
|
|
|
10971
|
-
- \`connector_google-analytics-oauth_request\`: Send authenticated requests to the GA4 Data API. Use it for running reports, getting metadata, and realtime reports.
|
|
10972
|
+
- \`connector_google-analytics-oauth_request\`: Send authenticated requests to the GA4 Data API. Use it for running reports, getting metadata, and realtime reports. Write the target property into the path as \`properties/{numericPropertyId}\` (the \`{propertyId}\` placeholder is only substituted when a default property is configured on the connection). Authentication is configured automatically via OAuth.
|
|
10972
10973
|
- \`connector_google-analytics-oauth_listAccounts\`: List accessible Google Analytics accounts. Use during setup to discover available accounts.
|
|
10973
10974
|
- \`connector_google-analytics-oauth_listProperties\`: List GA4 properties for a given account. Use during setup to select the target property.
|
|
10974
10975
|
|
|
@@ -11004,10 +11005,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11004
11005
|
The business logic type for this connector is "typescript". Write handler code using the connector SDK shown below. Do NOT access credentials directly from environment variables and do NOT read \`INTERNAL_SQUADBASE_*\` env vars \u2014 the SDK takes care of OAuth.
|
|
11005
11006
|
|
|
11006
11007
|
SDK surface (client created via \`connection(connectionId)\`):
|
|
11007
|
-
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://analyticsdata.googleapis.com/v1beta
|
|
11008
|
-
- \`client.runReport(request)\` \u2014 run a GA4 report.
|
|
11009
|
-
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report.
|
|
11010
|
-
- \`client.getMetadata()\` \u2014 fetch available dimensions and metrics.
|
|
11008
|
+
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://analyticsdata.googleapis.com/v1beta/\`; \`{propertyId}\` placeholders are auto-replaced only when a default property is configured on the connection).
|
|
11009
|
+
- \`client.runReport(request)\` \u2014 run a GA4 report. Set \`propertyId\` (bare numeric id) on the request object to target a property; required when no default is configured.
|
|
11010
|
+
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report. \`propertyId\` works the same as \`runReport\`.
|
|
11011
|
+
- \`client.getMetadata(propertyId?)\` \u2014 fetch available dimensions and metrics for a property.
|
|
11012
|
+
|
|
11013
|
+
**Always pass \`propertyId\` explicitly** (the numeric id from the data overview) \u2014 the connection does not necessarily store a default property.
|
|
11011
11014
|
|
|
11012
11015
|
If a handler test fails with \`Connection proxy is not configured\`, retry \u2014 the sandbox is still initializing. Do NOT abandon the SDK and construct OAuth proxy URLs manually.
|
|
11013
11016
|
|
|
@@ -11017,30 +11020,33 @@ If a handler test fails with \`Connection proxy is not configured\`, retry \u201
|
|
|
11017
11020
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11018
11021
|
|
|
11019
11022
|
const ga = connection("<connectionId>");
|
|
11023
|
+
const propertyId = "123456789"; // numeric GA4 property id from the data overview
|
|
11020
11024
|
|
|
11021
|
-
//
|
|
11022
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11023
|
-
method: "POST",
|
|
11024
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11025
|
-
});
|
|
11026
|
-
const data = await res.json();
|
|
11027
|
-
|
|
11028
|
-
// Convenience methods
|
|
11025
|
+
// Convenience methods (pass propertyId explicitly)
|
|
11029
11026
|
const { rows, rowCount } = await ga.runReport({
|
|
11027
|
+
propertyId,
|
|
11030
11028
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11031
11029
|
dimensions: [{ name: "date" }],
|
|
11032
11030
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11033
11031
|
limit: 100,
|
|
11034
11032
|
});
|
|
11035
|
-
const metadata = await ga.getMetadata();
|
|
11033
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11036
11034
|
const realtime = await ga.runRealtimeReport({
|
|
11035
|
+
propertyId,
|
|
11037
11036
|
metrics: [{ name: "activeUsers" }],
|
|
11038
11037
|
dimensions: [{ name: "country" }],
|
|
11039
11038
|
});
|
|
11039
|
+
|
|
11040
|
+
// Low-level authenticated fetch (write the numeric property id into the path)
|
|
11041
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11042
|
+
method: "POST",
|
|
11043
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11044
|
+
});
|
|
11045
|
+
const data = await res.json();
|
|
11040
11046
|
\`\`\``,
|
|
11041
11047
|
ja: `### \u30C4\u30FC\u30EB
|
|
11042
11048
|
|
|
11043
|
-
- \`connector_google-analytics-oauth_request\`: GA4 Data API\u3078\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306E\u5B9F\u884C\u3001\u30E1\u30BF\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u3001\u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30D1\u30B9\
|
|
11049
|
+
- \`connector_google-analytics-oauth_request\`: GA4 Data API\u3078\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306E\u5B9F\u884C\u3001\u30E1\u30BF\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u3001\u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u5BFE\u8C61\u30D7\u30ED\u30D1\u30C6\u30A3\u306F\u30D1\u30B9\u306B \`properties/{\u6570\u5024\u306E\u30D7\u30ED\u30D1\u30C6\u30A3ID}\` \u306E\u5F62\u3067\u76F4\u63A5\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\`{propertyId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u30C7\u30D5\u30A9\u30EB\u30C8\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u5834\u5408\u306E\u307F\u7F6E\u63DB\u3055\u308C\u307E\u3059\uFF09\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
11044
11050
|
- \`connector_google-analytics-oauth_listAccounts\`: \u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGoogle Analytics\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u6642\u306B\u5229\u7528\u53EF\u80FD\u306A\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u78BA\u8A8D\u3059\u308B\u305F\u3081\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
11045
11051
|
- \`connector_google-analytics-oauth_listProperties\`: \u6307\u5B9A\u30A2\u30AB\u30A6\u30F3\u30C8\u306EGA4\u30D7\u30ED\u30D1\u30C6\u30A3\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u6642\u306B\u30BF\u30FC\u30B2\u30C3\u30C8\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u9078\u629E\u3059\u308B\u305F\u3081\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
11046
11052
|
|
|
@@ -11076,10 +11082,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11076
11082
|
\u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u4EE5\u4E0B\u306B\u793A\u3059\u30B3\u30CD\u30AF\u30BF SDK \u3092\u4F7F\u7528\u3057\u3066\u30CF\u30F3\u30C9\u30E9\u30B3\u30FC\u30C9\u3092\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u76F4\u63A5\u8A8D\u8A3C\u60C5\u5831\u306B\u30A2\u30AF\u30BB\u30B9\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002\`INTERNAL_SQUADBASE_*\` \u306E\u74B0\u5883\u5909\u6570\u3092\u4F7F\u3063\u3066\u624B\u52D5\u3067 OAuth \u30D7\u30ED\u30AD\u30B7\u3092\u53E9\u304F\u3053\u3068\u3082\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044 \u2014 SDK \u304C OAuth \u3092\u51E6\u7406\u3057\u307E\u3059\u3002
|
|
11077
11083
|
|
|
11078
11084
|
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
|
|
11079
|
-
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304D fetch\uFF08\`path\` \u306F \`https://analyticsdata.googleapis.com/v1beta/\` \u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\uFF09\u3002
|
|
11080
|
-
- \`client.runReport(request)\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11081
|
-
- \`client.runRealtimeReport(request)\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11082
|
-
- \`client.getMetadata()\` \u2014 \u5229\u7528\u53EF\u80FD\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3\u3068\u30E1\u30C8\u30EA\u30AF\u30B9\u3092\u53D6\u5F97\u3002
|
|
11085
|
+
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304D fetch\uFF08\`path\` \u306F \`https://analyticsdata.googleapis.com/v1beta/\` \u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\`{propertyId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u306F\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u30C7\u30D5\u30A9\u30EB\u30C8\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u5834\u5408\u306E\u307F\u81EA\u52D5\u7F6E\u63DB\u3055\u308C\u307E\u3059\uFF09\u3002
|
|
11086
|
+
- \`client.runReport(request)\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002\u30EA\u30AF\u30A8\u30B9\u30C8\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B \`propertyId\`\uFF08\u6570\u5024\u306E\u30D7\u30ED\u30D1\u30C6\u30A3ID\uFF09\u3092\u6307\u5B9A\u3057\u3066\u5BFE\u8C61\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u6C7A\u3081\u307E\u3059\u3002\u30C7\u30D5\u30A9\u30EB\u30C8\u672A\u8A2D\u5B9A\u306E\u5834\u5408\u306F\u5FC5\u9808\u3067\u3059\u3002
|
|
11087
|
+
- \`client.runRealtimeReport(request)\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002\`propertyId\` \u306E\u6271\u3044\u306F \`runReport\` \u3068\u540C\u3058\u3067\u3059\u3002
|
|
11088
|
+
- \`client.getMetadata(propertyId?)\` \u2014 \u6307\u5B9A\u30D7\u30ED\u30D1\u30C6\u30A3\u306E\u5229\u7528\u53EF\u80FD\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3\u3068\u30E1\u30C8\u30EA\u30AF\u30B9\u3092\u53D6\u5F97\u3002
|
|
11089
|
+
|
|
11090
|
+
**\`propertyId\` \u306F\u5FC5\u305A\u660E\u793A\u7684\u306B\u6E21\u3057\u3066\u304F\u3060\u3055\u3044**\uFF08\u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024ID\uFF09\u3002\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u30C7\u30D5\u30A9\u30EB\u30C8\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u3068\u306F\u9650\u308A\u307E\u305B\u3093\u3002
|
|
11083
11091
|
|
|
11084
11092
|
\u30CF\u30F3\u30C9\u30E9\u306E\u30C6\u30B9\u30C8\u304C \`Connection proxy is not configured\` \u3067\u5931\u6557\u3059\u308B\u5834\u5408\u306F\u518D\u8A66\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u901A\u5E38\u306F\u30B5\u30F3\u30C9\u30DC\u30C3\u30AF\u30B9\u306E\u521D\u671F\u5316\u4E2D\u306B\u8D77\u304D\u307E\u3059\u3002SDK \u3092\u8AE6\u3081\u3066 OAuth \u30D7\u30ED\u30AD\u30B7\u306E URL \u3092\u81EA\u5206\u3067\u7D44\u307F\u7ACB\u3066\u308B\u3053\u3068\u306F **\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044**\u3002
|
|
11085
11093
|
|
|
@@ -11089,26 +11097,29 @@ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9
|
|
|
11089
11097
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11090
11098
|
|
|
11091
11099
|
const ga = connection("<connectionId>");
|
|
11100
|
+
const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
11092
11101
|
|
|
11093
|
-
//
|
|
11094
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11095
|
-
method: "POST",
|
|
11096
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11097
|
-
});
|
|
11098
|
-
const data = await res.json();
|
|
11099
|
-
|
|
11100
|
-
// Convenience methods
|
|
11102
|
+
// \u4FBF\u5229\u30E1\u30BD\u30C3\u30C9\uFF08propertyId \u3092\u660E\u793A\u7684\u306B\u6E21\u3059\uFF09
|
|
11101
11103
|
const { rows, rowCount } = await ga.runReport({
|
|
11104
|
+
propertyId,
|
|
11102
11105
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11103
11106
|
dimensions: [{ name: "date" }],
|
|
11104
11107
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11105
11108
|
limit: 100,
|
|
11106
11109
|
});
|
|
11107
|
-
const metadata = await ga.getMetadata();
|
|
11110
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11108
11111
|
const realtime = await ga.runRealtimeReport({
|
|
11112
|
+
propertyId,
|
|
11109
11113
|
metrics: [{ name: "activeUsers" }],
|
|
11110
11114
|
dimensions: [{ name: "country" }],
|
|
11111
11115
|
});
|
|
11116
|
+
|
|
11117
|
+
// \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304D fetch\uFF08\u6570\u5024\u306E\u30D7\u30ED\u30D1\u30C6\u30A3ID\u3092\u30D1\u30B9\u306B\u76F4\u63A5\u66F8\u304F\uFF09
|
|
11118
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11119
|
+
method: "POST",
|
|
11120
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11121
|
+
});
|
|
11122
|
+
const data = await res.json();
|
|
11112
11123
|
\`\`\``
|
|
11113
11124
|
},
|
|
11114
11125
|
tools: tools16,
|
|
@@ -47421,6 +47432,23 @@ var viteServer = null;
|
|
|
47421
47432
|
function setViteServer(server) {
|
|
47422
47433
|
viteServer = server;
|
|
47423
47434
|
}
|
|
47435
|
+
function validateHandlerPath(dirPath, handlerPath) {
|
|
47436
|
+
const normalizedDir = path2.resolve(dirPath);
|
|
47437
|
+
const dirBase = path2.basename(normalizedDir);
|
|
47438
|
+
let normalized = handlerPath.replace(/^\.?[/\\]/, "");
|
|
47439
|
+
const prefix = dirBase + "/";
|
|
47440
|
+
if (normalized.startsWith(prefix)) {
|
|
47441
|
+
normalized = normalized.slice(prefix.length);
|
|
47442
|
+
}
|
|
47443
|
+
const absolute = path2.resolve(dirPath, normalized);
|
|
47444
|
+
if (!absolute.startsWith(normalizedDir + path2.sep)) {
|
|
47445
|
+
throw new Error(`Handler path escapes server-logic directory: ${handlerPath}`);
|
|
47446
|
+
}
|
|
47447
|
+
if (!absolute.endsWith(".ts")) {
|
|
47448
|
+
throw new Error(`Handler must be a .ts file: ${handlerPath}`);
|
|
47449
|
+
}
|
|
47450
|
+
return absolute;
|
|
47451
|
+
}
|
|
47424
47452
|
var defaultServerLogicDir = path2.join(process.cwd(), "server-logic");
|
|
47425
47453
|
|
|
47426
47454
|
// src/vite-plugin.ts
|
|
@@ -47435,20 +47463,17 @@ var DEFAULT_EXCLUDE = [
|
|
|
47435
47463
|
/^\/node_modules\/.*/,
|
|
47436
47464
|
/^(?!\/api)/
|
|
47437
47465
|
];
|
|
47438
|
-
|
|
47439
|
-
|
|
47440
|
-
|
|
47441
|
-
|
|
47442
|
-
|
|
47443
|
-
|
|
47444
|
-
|
|
47445
|
-
|
|
47446
|
-
return entry;
|
|
47447
|
-
}
|
|
47466
|
+
var SERVER_LOGICS_VIRTUAL = "virtual:squadbase-server-logics";
|
|
47467
|
+
var SERVER_LOGICS_RESOLVED = "\0" + SERVER_LOGICS_VIRTUAL;
|
|
47468
|
+
function resolveServerBuildEntry() {
|
|
47469
|
+
const absolute = fileURLToPath(new URL("../build-entry/server-entry.mjs", import.meta.url));
|
|
47470
|
+
return "./" + path3.relative(process.cwd(), absolute).replace(/\\/g, "/");
|
|
47471
|
+
}
|
|
47472
|
+
function resolveServerLogicDir() {
|
|
47473
|
+
return process.env.SERVER_LOGIC_DIR || process.env.DATA_SOURCE_DIR || path3.resolve(process.cwd(), "server-logic");
|
|
47448
47474
|
}
|
|
47449
47475
|
function squadbasePlugin(options = {}) {
|
|
47450
47476
|
const {
|
|
47451
|
-
buildEntry = "@squadbase/vite-server/main",
|
|
47452
47477
|
devEntry = "@squadbase/vite-server",
|
|
47453
47478
|
external = [
|
|
47454
47479
|
"pg",
|
|
@@ -47465,8 +47490,63 @@ function squadbasePlugin(options = {}) {
|
|
|
47465
47490
|
exclude = DEFAULT_EXCLUDE
|
|
47466
47491
|
} = options;
|
|
47467
47492
|
const isServerBuild = (_, { command, mode }) => command === "build" && mode !== "client";
|
|
47493
|
+
const serverLogicBarrelPlugin = {
|
|
47494
|
+
name: "squadbase-server-logic-barrel",
|
|
47495
|
+
apply: isServerBuild,
|
|
47496
|
+
resolveId(id) {
|
|
47497
|
+
if (id === SERVER_LOGICS_VIRTUAL) return SERVER_LOGICS_RESOLVED;
|
|
47498
|
+
return null;
|
|
47499
|
+
},
|
|
47500
|
+
load(id) {
|
|
47501
|
+
if (id !== SERVER_LOGICS_RESOLVED) return null;
|
|
47502
|
+
const dir = resolveServerLogicDir();
|
|
47503
|
+
let jsonFiles = [];
|
|
47504
|
+
try {
|
|
47505
|
+
jsonFiles = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
47506
|
+
} catch {
|
|
47507
|
+
}
|
|
47508
|
+
let imports = "";
|
|
47509
|
+
let entries = "";
|
|
47510
|
+
jsonFiles.forEach((file, i) => {
|
|
47511
|
+
const slug = file.replace(/\.json$/, "");
|
|
47512
|
+
let raw;
|
|
47513
|
+
try {
|
|
47514
|
+
raw = JSON.parse(fs.readFileSync(path3.join(dir, file), "utf-8"));
|
|
47515
|
+
} catch {
|
|
47516
|
+
console.warn(`[squadbase] skipping ${file}: invalid JSON`);
|
|
47517
|
+
return;
|
|
47518
|
+
}
|
|
47519
|
+
const parsed = anyJsonServerLogicSchema.safeParse(raw);
|
|
47520
|
+
if (!parsed.success) return;
|
|
47521
|
+
const def = parsed.data;
|
|
47522
|
+
if (def.type !== "typescript") return;
|
|
47523
|
+
let handlerAbs;
|
|
47524
|
+
try {
|
|
47525
|
+
handlerAbs = validateHandlerPath(dir, def.handlerPath);
|
|
47526
|
+
} catch (e) {
|
|
47527
|
+
console.warn(
|
|
47528
|
+
`[squadbase] skipping server logic '${slug}': ${e.message}`
|
|
47529
|
+
);
|
|
47530
|
+
return;
|
|
47531
|
+
}
|
|
47532
|
+
if (!fs.existsSync(handlerAbs)) {
|
|
47533
|
+
console.warn(
|
|
47534
|
+
`[squadbase] skipping server logic '${slug}': handler file not found (${def.handlerPath})`
|
|
47535
|
+
);
|
|
47536
|
+
return;
|
|
47537
|
+
}
|
|
47538
|
+
imports += `import h${i} from ${JSON.stringify(handlerAbs)};
|
|
47539
|
+
`;
|
|
47540
|
+
entries += ` ${JSON.stringify(slug)}: h${i},
|
|
47541
|
+
`;
|
|
47542
|
+
});
|
|
47543
|
+
return `${imports}export const HANDLERS = {
|
|
47544
|
+
${entries}};
|
|
47545
|
+
`;
|
|
47546
|
+
}
|
|
47547
|
+
};
|
|
47468
47548
|
const rawBuildPlugin = buildPlugin({
|
|
47469
|
-
entry:
|
|
47549
|
+
entry: resolveServerBuildEntry(),
|
|
47470
47550
|
outputDir: "./dist/server",
|
|
47471
47551
|
output: "index.js",
|
|
47472
47552
|
external
|
|
@@ -47489,7 +47569,7 @@ function squadbasePlugin(options = {}) {
|
|
|
47489
47569
|
setViteServer(server);
|
|
47490
47570
|
}
|
|
47491
47571
|
};
|
|
47492
|
-
return [...buildPlugins, ...devPlugins, viteServerInjectionPlugin];
|
|
47572
|
+
return [serverLogicBarrelPlugin, ...buildPlugins, ...devPlugins, viteServerInjectionPlugin];
|
|
47493
47573
|
}
|
|
47494
47574
|
export {
|
|
47495
47575
|
squadbasePlugin
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squadbase/vite-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19-dev.40d2ebd",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -322,14 +322,11 @@
|
|
|
322
322
|
"./connectors/hackernews": {
|
|
323
323
|
"import": "./dist/connectors/hackernews.js",
|
|
324
324
|
"types": "./dist/connectors/hackernews.d.ts"
|
|
325
|
-
},
|
|
326
|
-
"./connectors/slack": {
|
|
327
|
-
"import": "./dist/connectors/slack.js",
|
|
328
|
-
"types": "./dist/connectors/slack.d.ts"
|
|
329
325
|
}
|
|
330
326
|
},
|
|
331
327
|
"files": [
|
|
332
|
-
"dist"
|
|
328
|
+
"dist",
|
|
329
|
+
"build-entry"
|
|
333
330
|
],
|
|
334
331
|
"publishConfig": {
|
|
335
332
|
"access": "public",
|