@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/index.js
CHANGED
|
@@ -10547,8 +10547,8 @@ init_parameter_definition();
|
|
|
10547
10547
|
var parameters16 = {
|
|
10548
10548
|
propertyId: new ParameterDefinition({
|
|
10549
10549
|
slug: "property-id",
|
|
10550
|
-
name: "
|
|
10551
|
-
description: "
|
|
10550
|
+
name: "Default Property ID",
|
|
10551
|
+
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.",
|
|
10552
10552
|
envVarBaseKey: "GA_OAUTH_PROPERTY_ID",
|
|
10553
10553
|
type: "text",
|
|
10554
10554
|
secret: false,
|
|
@@ -10861,7 +10861,7 @@ var inputSchema25 = z25.object({
|
|
|
10861
10861
|
connectionId: z25.string().describe("ID of the Google Analytics OAuth connection to use"),
|
|
10862
10862
|
method: z25.enum(["GET", "POST"]).describe("HTTP method"),
|
|
10863
10863
|
path: z25.string().describe(
|
|
10864
|
-
"API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/
|
|
10864
|
+
"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."
|
|
10865
10865
|
),
|
|
10866
10866
|
body: z25.record(z25.string(), z25.unknown()).optional().describe("POST request body (JSON)")
|
|
10867
10867
|
});
|
|
@@ -10880,7 +10880,7 @@ var requestTool4 = new ConnectorTool({
|
|
|
10880
10880
|
name: "request",
|
|
10881
10881
|
description: `Send authenticated requests to the Google Analytics Data API v1beta.
|
|
10882
10882
|
Authentication is handled automatically via OAuth proxy.
|
|
10883
|
-
|
|
10883
|
+
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.`,
|
|
10884
10884
|
inputSchema: inputSchema25,
|
|
10885
10885
|
outputSchema: outputSchema25,
|
|
10886
10886
|
async execute({ connectionId, method, path: path5, body }, connections, config) {
|
|
@@ -10967,7 +10967,7 @@ var googleAnalyticsOauthConnector = new ConnectorPlugin({
|
|
|
10967
10967
|
systemPrompt: {
|
|
10968
10968
|
en: `### Tools
|
|
10969
10969
|
|
|
10970
|
-
- \`connector_google-analytics-oauth_request\`: Send authenticated requests to the GA4 Data API. Use it for running reports, getting metadata, and realtime reports.
|
|
10970
|
+
- \`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.
|
|
10971
10971
|
- \`connector_google-analytics-oauth_listAccounts\`: List accessible Google Analytics accounts. Use during setup to discover available accounts.
|
|
10972
10972
|
- \`connector_google-analytics-oauth_listProperties\`: List GA4 properties for a given account. Use during setup to select the target property.
|
|
10973
10973
|
|
|
@@ -11003,10 +11003,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11003
11003
|
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.
|
|
11004
11004
|
|
|
11005
11005
|
SDK surface (client created via \`connection(connectionId)\`):
|
|
11006
|
-
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://analyticsdata.googleapis.com/v1beta
|
|
11007
|
-
- \`client.runReport(request)\` \u2014 run a GA4 report.
|
|
11008
|
-
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report.
|
|
11009
|
-
- \`client.getMetadata()\` \u2014 fetch available dimensions and metrics.
|
|
11006
|
+
- \`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).
|
|
11007
|
+
- \`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.
|
|
11008
|
+
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report. \`propertyId\` works the same as \`runReport\`.
|
|
11009
|
+
- \`client.getMetadata(propertyId?)\` \u2014 fetch available dimensions and metrics for a property.
|
|
11010
|
+
|
|
11011
|
+
**Always pass \`propertyId\` explicitly** (the numeric id from the data overview) \u2014 the connection does not necessarily store a default property.
|
|
11010
11012
|
|
|
11011
11013
|
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.
|
|
11012
11014
|
|
|
@@ -11016,30 +11018,33 @@ If a handler test fails with \`Connection proxy is not configured\`, retry \u201
|
|
|
11016
11018
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11017
11019
|
|
|
11018
11020
|
const ga = connection("<connectionId>");
|
|
11021
|
+
const propertyId = "123456789"; // numeric GA4 property id from the data overview
|
|
11019
11022
|
|
|
11020
|
-
//
|
|
11021
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11022
|
-
method: "POST",
|
|
11023
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11024
|
-
});
|
|
11025
|
-
const data = await res.json();
|
|
11026
|
-
|
|
11027
|
-
// Convenience methods
|
|
11023
|
+
// Convenience methods (pass propertyId explicitly)
|
|
11028
11024
|
const { rows, rowCount } = await ga.runReport({
|
|
11025
|
+
propertyId,
|
|
11029
11026
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11030
11027
|
dimensions: [{ name: "date" }],
|
|
11031
11028
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11032
11029
|
limit: 100,
|
|
11033
11030
|
});
|
|
11034
|
-
const metadata = await ga.getMetadata();
|
|
11031
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11035
11032
|
const realtime = await ga.runRealtimeReport({
|
|
11033
|
+
propertyId,
|
|
11036
11034
|
metrics: [{ name: "activeUsers" }],
|
|
11037
11035
|
dimensions: [{ name: "country" }],
|
|
11038
11036
|
});
|
|
11037
|
+
|
|
11038
|
+
// Low-level authenticated fetch (write the numeric property id into the path)
|
|
11039
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11040
|
+
method: "POST",
|
|
11041
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11042
|
+
});
|
|
11043
|
+
const data = await res.json();
|
|
11039
11044
|
\`\`\``,
|
|
11040
11045
|
ja: `### \u30C4\u30FC\u30EB
|
|
11041
11046
|
|
|
11042
|
-
- \`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\
|
|
11047
|
+
- \`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
|
|
11043
11048
|
- \`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
|
|
11044
11049
|
- \`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
|
|
11045
11050
|
|
|
@@ -11075,10 +11080,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11075
11080
|
\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
|
|
11076
11081
|
|
|
11077
11082
|
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
|
|
11078
|
-
- \`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
|
|
11079
|
-
- \`client.runReport(request)\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11080
|
-
- \`client.runRealtimeReport(request)\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11081
|
-
- \`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
|
|
11083
|
+
- \`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
|
|
11084
|
+
- \`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
|
|
11085
|
+
- \`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
|
|
11086
|
+
- \`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
|
|
11087
|
+
|
|
11088
|
+
**\`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
|
|
11082
11089
|
|
|
11083
11090
|
\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
|
|
11084
11091
|
|
|
@@ -11088,26 +11095,29 @@ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9
|
|
|
11088
11095
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11089
11096
|
|
|
11090
11097
|
const ga = connection("<connectionId>");
|
|
11098
|
+
const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
11091
11099
|
|
|
11092
|
-
//
|
|
11093
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11094
|
-
method: "POST",
|
|
11095
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11096
|
-
});
|
|
11097
|
-
const data = await res.json();
|
|
11098
|
-
|
|
11099
|
-
// Convenience methods
|
|
11100
|
+
// \u4FBF\u5229\u30E1\u30BD\u30C3\u30C9\uFF08propertyId \u3092\u660E\u793A\u7684\u306B\u6E21\u3059\uFF09
|
|
11100
11101
|
const { rows, rowCount } = await ga.runReport({
|
|
11102
|
+
propertyId,
|
|
11101
11103
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11102
11104
|
dimensions: [{ name: "date" }],
|
|
11103
11105
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11104
11106
|
limit: 100,
|
|
11105
11107
|
});
|
|
11106
|
-
const metadata = await ga.getMetadata();
|
|
11108
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11107
11109
|
const realtime = await ga.runRealtimeReport({
|
|
11110
|
+
propertyId,
|
|
11108
11111
|
metrics: [{ name: "activeUsers" }],
|
|
11109
11112
|
dimensions: [{ name: "country" }],
|
|
11110
11113
|
});
|
|
11114
|
+
|
|
11115
|
+
// \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
|
|
11116
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11117
|
+
method: "POST",
|
|
11118
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11119
|
+
});
|
|
11120
|
+
const data = await res.json();
|
|
11111
11121
|
\`\`\``
|
|
11112
11122
|
},
|
|
11113
11123
|
tools: tools16,
|
|
@@ -47691,8 +47701,14 @@ function getSkippedServerLogics() {
|
|
|
47691
47701
|
}
|
|
47692
47702
|
var viteServer = null;
|
|
47693
47703
|
function validateHandlerPath(dirPath, handlerPath) {
|
|
47694
|
-
const absolute = path2.resolve(dirPath, handlerPath);
|
|
47695
47704
|
const normalizedDir = path2.resolve(dirPath);
|
|
47705
|
+
const dirBase = path2.basename(normalizedDir);
|
|
47706
|
+
let normalized = handlerPath.replace(/^\.?[/\\]/, "");
|
|
47707
|
+
const prefix = dirBase + "/";
|
|
47708
|
+
if (normalized.startsWith(prefix)) {
|
|
47709
|
+
normalized = normalized.slice(prefix.length);
|
|
47710
|
+
}
|
|
47711
|
+
const absolute = path2.resolve(dirPath, normalized);
|
|
47696
47712
|
if (!absolute.startsWith(normalizedDir + path2.sep)) {
|
|
47697
47713
|
throw new Error(`Handler path escapes server-logic directory: ${handlerPath}`);
|
|
47698
47714
|
}
|
|
@@ -47701,19 +47717,29 @@ function validateHandlerPath(dirPath, handlerPath) {
|
|
|
47701
47717
|
}
|
|
47702
47718
|
return absolute;
|
|
47703
47719
|
}
|
|
47704
|
-
|
|
47705
|
-
|
|
47720
|
+
var bundledHandlers = {};
|
|
47721
|
+
function registerBundledHandlers(handlers) {
|
|
47722
|
+
bundledHandlers = handlers;
|
|
47723
|
+
}
|
|
47724
|
+
async function loadTypeScriptHandler(slug, absolutePath) {
|
|
47706
47725
|
if (viteServer) {
|
|
47707
47726
|
const module = viteServer.moduleGraph.getModuleById(absolutePath);
|
|
47708
47727
|
if (module) viteServer.moduleGraph.invalidateModule(module);
|
|
47709
|
-
mod = await viteServer.ssrLoadModule(absolutePath);
|
|
47710
|
-
|
|
47711
|
-
|
|
47712
|
-
|
|
47728
|
+
const mod = await viteServer.ssrLoadModule(absolutePath);
|
|
47729
|
+
const handler2 = mod.default;
|
|
47730
|
+
if (typeof handler2 !== "function") {
|
|
47731
|
+
throw new Error(`Handler must export a default function: ${absolutePath}`);
|
|
47732
|
+
}
|
|
47733
|
+
return handler2;
|
|
47734
|
+
}
|
|
47735
|
+
if (!(slug in bundledHandlers)) {
|
|
47736
|
+
throw new Error(
|
|
47737
|
+
`Bundled handler not found for server logic: ${slug} (not compiled into the build)`
|
|
47738
|
+
);
|
|
47713
47739
|
}
|
|
47714
|
-
const handler =
|
|
47740
|
+
const handler = bundledHandlers[slug];
|
|
47715
47741
|
if (typeof handler !== "function") {
|
|
47716
|
-
throw new Error(`
|
|
47742
|
+
throw new Error(`Server logic '${slug}' must export a default function`);
|
|
47717
47743
|
}
|
|
47718
47744
|
return handler;
|
|
47719
47745
|
}
|
|
@@ -48010,7 +48036,7 @@ app.get("/:slug", async (c) => {
|
|
|
48010
48036
|
}
|
|
48011
48037
|
try {
|
|
48012
48038
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
48013
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
48039
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
48014
48040
|
const result = await handler(c);
|
|
48015
48041
|
return result;
|
|
48016
48042
|
} else {
|
|
@@ -48038,7 +48064,7 @@ app.post("/:slug", async (c) => {
|
|
|
48038
48064
|
const ttl = cacheConfig?.ttl ?? 0;
|
|
48039
48065
|
if (ttl <= 0) {
|
|
48040
48066
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
48041
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
48067
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
48042
48068
|
const result = await handler(c);
|
|
48043
48069
|
return result;
|
|
48044
48070
|
} else {
|
|
@@ -48062,7 +48088,7 @@ app.post("/:slug", async (c) => {
|
|
|
48062
48088
|
void (async () => {
|
|
48063
48089
|
try {
|
|
48064
48090
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
48065
|
-
const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
48091
|
+
const tsHandler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
48066
48092
|
const freshResponse = await tsHandler(c);
|
|
48067
48093
|
const outcome = await cacheTypescriptResponse(freshResponse);
|
|
48068
48094
|
if (outcome.cacheable) {
|
|
@@ -48086,7 +48112,7 @@ app.post("/:slug", async (c) => {
|
|
|
48086
48112
|
}
|
|
48087
48113
|
}
|
|
48088
48114
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
48089
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
48115
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
48090
48116
|
const response = await handler(c);
|
|
48091
48117
|
const outcome = await cacheTypescriptResponse(response);
|
|
48092
48118
|
if (outcome.cacheable) {
|
|
@@ -48550,5 +48576,6 @@ export {
|
|
|
48550
48576
|
src_default as default,
|
|
48551
48577
|
getQuery,
|
|
48552
48578
|
loadConnections,
|
|
48579
|
+
registerBundledHandlers,
|
|
48553
48580
|
storage
|
|
48554
48581
|
};
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -10547,8 +10547,8 @@ init_parameter_definition();
|
|
|
10547
10547
|
var parameters16 = {
|
|
10548
10548
|
propertyId: new ParameterDefinition({
|
|
10549
10549
|
slug: "property-id",
|
|
10550
|
-
name: "
|
|
10551
|
-
description: "
|
|
10550
|
+
name: "Default Property ID",
|
|
10551
|
+
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.",
|
|
10552
10552
|
envVarBaseKey: "GA_OAUTH_PROPERTY_ID",
|
|
10553
10553
|
type: "text",
|
|
10554
10554
|
secret: false,
|
|
@@ -10861,7 +10861,7 @@ var inputSchema25 = z25.object({
|
|
|
10861
10861
|
connectionId: z25.string().describe("ID of the Google Analytics OAuth connection to use"),
|
|
10862
10862
|
method: z25.enum(["GET", "POST"]).describe("HTTP method"),
|
|
10863
10863
|
path: z25.string().describe(
|
|
10864
|
-
"API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/
|
|
10864
|
+
"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."
|
|
10865
10865
|
),
|
|
10866
10866
|
body: z25.record(z25.string(), z25.unknown()).optional().describe("POST request body (JSON)")
|
|
10867
10867
|
});
|
|
@@ -10880,7 +10880,7 @@ var requestTool4 = new ConnectorTool({
|
|
|
10880
10880
|
name: "request",
|
|
10881
10881
|
description: `Send authenticated requests to the Google Analytics Data API v1beta.
|
|
10882
10882
|
Authentication is handled automatically via OAuth proxy.
|
|
10883
|
-
|
|
10883
|
+
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.`,
|
|
10884
10884
|
inputSchema: inputSchema25,
|
|
10885
10885
|
outputSchema: outputSchema25,
|
|
10886
10886
|
async execute({ connectionId, method, path: path6, body }, connections, config) {
|
|
@@ -10967,7 +10967,7 @@ var googleAnalyticsOauthConnector = new ConnectorPlugin({
|
|
|
10967
10967
|
systemPrompt: {
|
|
10968
10968
|
en: `### Tools
|
|
10969
10969
|
|
|
10970
|
-
- \`connector_google-analytics-oauth_request\`: Send authenticated requests to the GA4 Data API. Use it for running reports, getting metadata, and realtime reports.
|
|
10970
|
+
- \`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.
|
|
10971
10971
|
- \`connector_google-analytics-oauth_listAccounts\`: List accessible Google Analytics accounts. Use during setup to discover available accounts.
|
|
10972
10972
|
- \`connector_google-analytics-oauth_listProperties\`: List GA4 properties for a given account. Use during setup to select the target property.
|
|
10973
10973
|
|
|
@@ -11003,10 +11003,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11003
11003
|
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.
|
|
11004
11004
|
|
|
11005
11005
|
SDK surface (client created via \`connection(connectionId)\`):
|
|
11006
|
-
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://analyticsdata.googleapis.com/v1beta
|
|
11007
|
-
- \`client.runReport(request)\` \u2014 run a GA4 report.
|
|
11008
|
-
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report.
|
|
11009
|
-
- \`client.getMetadata()\` \u2014 fetch available dimensions and metrics.
|
|
11006
|
+
- \`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).
|
|
11007
|
+
- \`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.
|
|
11008
|
+
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report. \`propertyId\` works the same as \`runReport\`.
|
|
11009
|
+
- \`client.getMetadata(propertyId?)\` \u2014 fetch available dimensions and metrics for a property.
|
|
11010
|
+
|
|
11011
|
+
**Always pass \`propertyId\` explicitly** (the numeric id from the data overview) \u2014 the connection does not necessarily store a default property.
|
|
11010
11012
|
|
|
11011
11013
|
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.
|
|
11012
11014
|
|
|
@@ -11016,30 +11018,33 @@ If a handler test fails with \`Connection proxy is not configured\`, retry \u201
|
|
|
11016
11018
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11017
11019
|
|
|
11018
11020
|
const ga = connection("<connectionId>");
|
|
11021
|
+
const propertyId = "123456789"; // numeric GA4 property id from the data overview
|
|
11019
11022
|
|
|
11020
|
-
//
|
|
11021
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11022
|
-
method: "POST",
|
|
11023
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11024
|
-
});
|
|
11025
|
-
const data = await res.json();
|
|
11026
|
-
|
|
11027
|
-
// Convenience methods
|
|
11023
|
+
// Convenience methods (pass propertyId explicitly)
|
|
11028
11024
|
const { rows, rowCount } = await ga.runReport({
|
|
11025
|
+
propertyId,
|
|
11029
11026
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11030
11027
|
dimensions: [{ name: "date" }],
|
|
11031
11028
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11032
11029
|
limit: 100,
|
|
11033
11030
|
});
|
|
11034
|
-
const metadata = await ga.getMetadata();
|
|
11031
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11035
11032
|
const realtime = await ga.runRealtimeReport({
|
|
11033
|
+
propertyId,
|
|
11036
11034
|
metrics: [{ name: "activeUsers" }],
|
|
11037
11035
|
dimensions: [{ name: "country" }],
|
|
11038
11036
|
});
|
|
11037
|
+
|
|
11038
|
+
// Low-level authenticated fetch (write the numeric property id into the path)
|
|
11039
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11040
|
+
method: "POST",
|
|
11041
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11042
|
+
});
|
|
11043
|
+
const data = await res.json();
|
|
11039
11044
|
\`\`\``,
|
|
11040
11045
|
ja: `### \u30C4\u30FC\u30EB
|
|
11041
11046
|
|
|
11042
|
-
- \`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\
|
|
11047
|
+
- \`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
|
|
11043
11048
|
- \`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
|
|
11044
11049
|
- \`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
|
|
11045
11050
|
|
|
@@ -11075,10 +11080,12 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
11075
11080
|
\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
|
|
11076
11081
|
|
|
11077
11082
|
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
|
|
11078
|
-
- \`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
|
|
11079
|
-
- \`client.runReport(request)\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11080
|
-
- \`client.runRealtimeReport(request)\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
|
|
11081
|
-
- \`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
|
|
11083
|
+
- \`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
|
|
11084
|
+
- \`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
|
|
11085
|
+
- \`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
|
|
11086
|
+
- \`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
|
|
11087
|
+
|
|
11088
|
+
**\`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
|
|
11082
11089
|
|
|
11083
11090
|
\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
|
|
11084
11091
|
|
|
@@ -11088,26 +11095,29 @@ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9
|
|
|
11088
11095
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
11089
11096
|
|
|
11090
11097
|
const ga = connection("<connectionId>");
|
|
11098
|
+
const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
11091
11099
|
|
|
11092
|
-
//
|
|
11093
|
-
const res = await ga.request("properties/{propertyId}:runReport", {
|
|
11094
|
-
method: "POST",
|
|
11095
|
-
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11096
|
-
});
|
|
11097
|
-
const data = await res.json();
|
|
11098
|
-
|
|
11099
|
-
// Convenience methods
|
|
11100
|
+
// \u4FBF\u5229\u30E1\u30BD\u30C3\u30C9\uFF08propertyId \u3092\u660E\u793A\u7684\u306B\u6E21\u3059\uFF09
|
|
11100
11101
|
const { rows, rowCount } = await ga.runReport({
|
|
11102
|
+
propertyId,
|
|
11101
11103
|
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
11102
11104
|
dimensions: [{ name: "date" }],
|
|
11103
11105
|
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
11104
11106
|
limit: 100,
|
|
11105
11107
|
});
|
|
11106
|
-
const metadata = await ga.getMetadata();
|
|
11108
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
11107
11109
|
const realtime = await ga.runRealtimeReport({
|
|
11110
|
+
propertyId,
|
|
11108
11111
|
metrics: [{ name: "activeUsers" }],
|
|
11109
11112
|
dimensions: [{ name: "country" }],
|
|
11110
11113
|
});
|
|
11114
|
+
|
|
11115
|
+
// \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
|
|
11116
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
11117
|
+
method: "POST",
|
|
11118
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
11119
|
+
});
|
|
11120
|
+
const data = await res.json();
|
|
11111
11121
|
\`\`\``
|
|
11112
11122
|
},
|
|
11113
11123
|
tools: tools16,
|
|
@@ -47424,8 +47434,14 @@ function getSkippedServerLogics() {
|
|
|
47424
47434
|
}
|
|
47425
47435
|
var viteServer = null;
|
|
47426
47436
|
function validateHandlerPath(dirPath, handlerPath) {
|
|
47427
|
-
const absolute = path2.resolve(dirPath, handlerPath);
|
|
47428
47437
|
const normalizedDir = path2.resolve(dirPath);
|
|
47438
|
+
const dirBase = path2.basename(normalizedDir);
|
|
47439
|
+
let normalized = handlerPath.replace(/^\.?[/\\]/, "");
|
|
47440
|
+
const prefix = dirBase + "/";
|
|
47441
|
+
if (normalized.startsWith(prefix)) {
|
|
47442
|
+
normalized = normalized.slice(prefix.length);
|
|
47443
|
+
}
|
|
47444
|
+
const absolute = path2.resolve(dirPath, normalized);
|
|
47429
47445
|
if (!absolute.startsWith(normalizedDir + path2.sep)) {
|
|
47430
47446
|
throw new Error(`Handler path escapes server-logic directory: ${handlerPath}`);
|
|
47431
47447
|
}
|
|
@@ -47434,19 +47450,29 @@ function validateHandlerPath(dirPath, handlerPath) {
|
|
|
47434
47450
|
}
|
|
47435
47451
|
return absolute;
|
|
47436
47452
|
}
|
|
47437
|
-
|
|
47438
|
-
|
|
47453
|
+
var bundledHandlers = {};
|
|
47454
|
+
function registerBundledHandlers(handlers) {
|
|
47455
|
+
bundledHandlers = handlers;
|
|
47456
|
+
}
|
|
47457
|
+
async function loadTypeScriptHandler(slug, absolutePath) {
|
|
47439
47458
|
if (viteServer) {
|
|
47440
47459
|
const module = viteServer.moduleGraph.getModuleById(absolutePath);
|
|
47441
47460
|
if (module) viteServer.moduleGraph.invalidateModule(module);
|
|
47442
|
-
mod = await viteServer.ssrLoadModule(absolutePath);
|
|
47443
|
-
|
|
47444
|
-
|
|
47445
|
-
|
|
47461
|
+
const mod = await viteServer.ssrLoadModule(absolutePath);
|
|
47462
|
+
const handler2 = mod.default;
|
|
47463
|
+
if (typeof handler2 !== "function") {
|
|
47464
|
+
throw new Error(`Handler must export a default function: ${absolutePath}`);
|
|
47465
|
+
}
|
|
47466
|
+
return handler2;
|
|
47467
|
+
}
|
|
47468
|
+
if (!(slug in bundledHandlers)) {
|
|
47469
|
+
throw new Error(
|
|
47470
|
+
`Bundled handler not found for server logic: ${slug} (not compiled into the build)`
|
|
47471
|
+
);
|
|
47446
47472
|
}
|
|
47447
|
-
const handler =
|
|
47473
|
+
const handler = bundledHandlers[slug];
|
|
47448
47474
|
if (typeof handler !== "function") {
|
|
47449
|
-
throw new Error(`
|
|
47475
|
+
throw new Error(`Server logic '${slug}' must export a default function`);
|
|
47450
47476
|
}
|
|
47451
47477
|
return handler;
|
|
47452
47478
|
}
|
|
@@ -47743,7 +47769,7 @@ app.get("/:slug", async (c) => {
|
|
|
47743
47769
|
}
|
|
47744
47770
|
try {
|
|
47745
47771
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
47746
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
47772
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
47747
47773
|
const result = await handler(c);
|
|
47748
47774
|
return result;
|
|
47749
47775
|
} else {
|
|
@@ -47771,7 +47797,7 @@ app.post("/:slug", async (c) => {
|
|
|
47771
47797
|
const ttl = cacheConfig?.ttl ?? 0;
|
|
47772
47798
|
if (ttl <= 0) {
|
|
47773
47799
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
47774
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
47800
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
47775
47801
|
const result = await handler(c);
|
|
47776
47802
|
return result;
|
|
47777
47803
|
} else {
|
|
@@ -47795,7 +47821,7 @@ app.post("/:slug", async (c) => {
|
|
|
47795
47821
|
void (async () => {
|
|
47796
47822
|
try {
|
|
47797
47823
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
47798
|
-
const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
47824
|
+
const tsHandler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
47799
47825
|
const freshResponse = await tsHandler(c);
|
|
47800
47826
|
const outcome = await cacheTypescriptResponse(freshResponse);
|
|
47801
47827
|
if (outcome.cacheable) {
|
|
@@ -47819,7 +47845,7 @@ app.post("/:slug", async (c) => {
|
|
|
47819
47845
|
}
|
|
47820
47846
|
}
|
|
47821
47847
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
47822
|
-
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
47848
|
+
const handler = await loadTypeScriptHandler(slug, ds._tsHandlerPath);
|
|
47823
47849
|
const response = await handler(c);
|
|
47824
47850
|
const outcome = await cacheTypescriptResponse(response);
|
|
47825
47851
|
if (outcome.cacheable) {
|
|
@@ -48224,5 +48250,6 @@ src_default.get("*", (c) => {
|
|
|
48224
48250
|
});
|
|
48225
48251
|
var main_default = src_default;
|
|
48226
48252
|
export {
|
|
48227
|
-
main_default as default
|
|
48253
|
+
main_default as default,
|
|
48254
|
+
registerBundledHandlers
|
|
48228
48255
|
};
|