@squadbase/vite-server 0.1.19-dev.2880e8d → 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 +13 -18
- package/dist/cli/index.js +460 -417
- package/dist/connectors/google-analytics-oauth.js +192 -96
- package/dist/index.d.ts +5 -22
- package/dist/index.js +617 -499
- package/dist/main.d.ts +1 -1
- package/dist/main.js +620 -502
- package/dist/types/server-logic.d.ts +0 -3
- package/dist/vite-plugin.d.ts +1 -7
- package/dist/vite-plugin.js +47523 -41
- package/package.json +2 -1
|
@@ -1,17 +1,96 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __esm = (fn, res, err) => function __init() {
|
|
3
|
+
if (err) throw err[0];
|
|
4
|
+
try {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
throw err = [e], e;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../connectors/src/parameter-definition.ts
|
|
12
|
+
var ParameterDefinition;
|
|
13
|
+
var init_parameter_definition = __esm({
|
|
14
|
+
"../connectors/src/parameter-definition.ts"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
ParameterDefinition = class {
|
|
17
|
+
slug;
|
|
18
|
+
name;
|
|
19
|
+
description;
|
|
20
|
+
envVarBaseKey;
|
|
21
|
+
type;
|
|
22
|
+
secret;
|
|
23
|
+
required;
|
|
24
|
+
isDeprecated;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.slug = config.slug;
|
|
27
|
+
this.name = config.name;
|
|
28
|
+
this.description = config.description;
|
|
29
|
+
this.envVarBaseKey = config.envVarBaseKey;
|
|
30
|
+
this.type = config.type;
|
|
31
|
+
this.secret = config.secret;
|
|
32
|
+
this.required = config.required;
|
|
33
|
+
this.isDeprecated = config.isDeprecated ?? false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the parameter value from a ConnectorConnectionObject.
|
|
37
|
+
*/
|
|
38
|
+
getValue(connection2) {
|
|
39
|
+
const param = connection2.parameters.find(
|
|
40
|
+
(p) => p.parameterSlug === this.slug
|
|
41
|
+
);
|
|
42
|
+
if (!param || param.value == null) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return param.value;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Try to get the parameter value. Returns undefined if not found (for optional params).
|
|
51
|
+
*/
|
|
52
|
+
tryGetValue(connection2) {
|
|
53
|
+
const param = connection2.parameters.find(
|
|
54
|
+
(p) => p.parameterSlug === this.slug
|
|
55
|
+
);
|
|
56
|
+
if (!param || param.value == null) return void 0;
|
|
57
|
+
return param.value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ../connectors/src/connectors/google-analytics-oauth/parameters.ts
|
|
64
|
+
init_parameter_definition();
|
|
65
|
+
var parameters = {
|
|
66
|
+
propertyId: new ParameterDefinition({
|
|
67
|
+
slug: "property-id",
|
|
68
|
+
name: "Default Property ID",
|
|
69
|
+
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.",
|
|
70
|
+
envVarBaseKey: "GA_OAUTH_PROPERTY_ID",
|
|
71
|
+
type: "text",
|
|
72
|
+
secret: false,
|
|
73
|
+
required: false
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
|
|
1
77
|
// ../connectors/src/connectors/google-analytics-oauth/sdk/index.ts
|
|
2
78
|
var BASE_URL = "https://analyticsdata.googleapis.com/v1beta/";
|
|
3
|
-
function createClient(
|
|
4
|
-
|
|
5
|
-
|
|
79
|
+
function createClient(params, fetchFn) {
|
|
80
|
+
const defaultPropertyId = params[parameters.propertyId.slug];
|
|
81
|
+
function resolvePropertyId(override) {
|
|
82
|
+
const pid = override ?? defaultPropertyId;
|
|
83
|
+
if (!pid) {
|
|
6
84
|
throw new Error(
|
|
7
|
-
"google-analytics-oauth: propertyId is required.
|
|
85
|
+
"google-analytics-oauth: propertyId is required. Configure it via connection parameters or pass it as an argument."
|
|
8
86
|
);
|
|
9
87
|
}
|
|
10
|
-
return
|
|
88
|
+
return pid;
|
|
11
89
|
}
|
|
12
90
|
return {
|
|
13
91
|
async request(path2, init) {
|
|
14
|
-
const
|
|
92
|
+
const resolvedPath = defaultPropertyId ? path2.replace(/\{propertyId\}/g, defaultPropertyId) : path2;
|
|
93
|
+
const url = `${BASE_URL.replace(/\/+$/, "")}/${resolvedPath.replace(/^\/+/, "")}`;
|
|
15
94
|
return fetchFn(url, init);
|
|
16
95
|
},
|
|
17
96
|
async runReport({ propertyId, ...request }) {
|
|
@@ -580,11 +659,11 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
|
|
|
580
659
|
- \u30A2\u30AB\u30A6\u30F3\u30C8\u304C **1\u4EF6\u306E\u307F**: \`askUserQuestion\` \u306F\u30B9\u30AD\u30C3\u30D7\u3057\u3001\u305D\u306E\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u9078\u629E\u6E08\u307F\u3068\u3057\u3066\u6B21\u3078\u9032\u3080
|
|
581
660
|
- \u30A2\u30AB\u30A6\u30F3\u30C8\u304C **0\u4EF6**: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u4E2D\u65AD\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30A2\u30AB\u30A6\u30F3\u30C8\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B
|
|
582
661
|
3. \`${listPropertiesToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u9078\u629E\u3055\u308C\u305F\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
583
|
-
4. \
|
|
584
|
-
-
|
|
585
|
-
- \u30D7\u30ED\u30D1\u30C6\u30A3\
|
|
586
|
-
- \u30D7\u30ED\u30D1\u30C6\u30A3\u304C **0\u4EF6
|
|
587
|
-
5. \u9078\u629E\
|
|
662
|
+
4. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
|
|
663
|
+
- \`parameterSlug\`: \`"property-id"\`
|
|
664
|
+
- \`options\`: \u30D7\u30ED\u30D1\u30C6\u30A3\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u8868\u793A\u540D (id: \u30D7\u30ED\u30D1\u30C6\u30A3ID)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F\u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
665
|
+
- \u30D7\u30ED\u30D1\u30C6\u30A3\u304C **0\u4EF6** \u306E\u5834\u5408\u306F\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u4E2D\u65AD\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B
|
|
666
|
+
5. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30D7\u30ED\u30D1\u30C6\u30A3\u306E \`label\` \u304C\u30E1\u30C3\u30BB\u30FC\u30B8\u3068\u3057\u3066\u5C4A\u304F\u306E\u3067\u3001\u6B21\u306E\u30B9\u30C6\u30C3\u30D7\u306B\u9032\u3080
|
|
588
667
|
|
|
589
668
|
#### \u5236\u7D04
|
|
590
669
|
- **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30EC\u30DD\u30FC\u30C8\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u306E\u307F
|
|
@@ -598,11 +677,11 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
|
|
|
598
677
|
- **Only 1 account**: Skip \`askUserQuestion\` and proceed using that account as the selection
|
|
599
678
|
- **0 accounts**: Abort setup and inform the user that no accessible accounts are available
|
|
600
679
|
3. Call \`${listPropertiesToolName}\` to get the list of properties for the selected account
|
|
601
|
-
4.
|
|
602
|
-
-
|
|
603
|
-
-
|
|
604
|
-
- **0 properties
|
|
605
|
-
5.
|
|
680
|
+
4. Call \`updateConnectionParameters\`:
|
|
681
|
+
- \`parameterSlug\`: \`"property-id"\`
|
|
682
|
+
- \`options\`: The property list. Each option's \`label\` should be \`Display Name (id: propertyId)\`, \`value\` should be the property ID
|
|
683
|
+
- If **0 properties** are returned, abort setup and inform the user that no accessible properties are available
|
|
684
|
+
5. The \`label\` of the user's selected property will arrive as a message. Proceed to the next step
|
|
606
685
|
|
|
607
686
|
#### Constraints
|
|
608
687
|
- **Do NOT fetch report data during setup**. Only the metadata requests specified in the steps above are allowed
|
|
@@ -610,18 +689,13 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
|
|
|
610
689
|
- Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
|
|
611
690
|
},
|
|
612
691
|
dataOverviewInstructions: {
|
|
613
|
-
en: `
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
1. connector_google-analytics-oauth_request \u3067 GET properties/<propertyId>/metadata \u3092\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3\u3068\u30E1\u30C8\u30EA\u30AF\u30B9\u306E\u4E00\u89A7\u3092\u53D6\u5F97
|
|
618
|
-
2. connector_google-analytics-oauth_request \u3067 POST properties/<propertyId>:runReport \u3092\u77ED\u3044\u671F\u9593\u3068\u57FA\u672C\u30E1\u30C8\u30EA\u30AF\u30B9\u3067\u547C\u3073\u51FA\u3057\u3001\u30C7\u30FC\u30BF\u306E\u53EF\u7528\u6027\u3092\u78BA\u8A8D`
|
|
692
|
+
en: `1. Call connector_google-analytics-oauth_request with GET properties/{propertyId}/metadata to list available dimensions and metrics
|
|
693
|
+
2. Call connector_google-analytics-oauth_request with POST properties/{propertyId}:runReport using a small date range and basic metrics to verify data availability`,
|
|
694
|
+
ja: `1. connector_google-analytics-oauth_request \u3067 GET properties/{propertyId}/metadata \u3092\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3\u3068\u30E1\u30C8\u30EA\u30AF\u30B9\u306E\u4E00\u89A7\u3092\u53D6\u5F97
|
|
695
|
+
2. connector_google-analytics-oauth_request \u3067 POST properties/{propertyId}:runReport \u3092\u77ED\u3044\u671F\u9593\u3068\u57FA\u672C\u30E1\u30C8\u30EA\u30AF\u30B9\u3067\u547C\u3073\u51FA\u3057\u3001\u30C7\u30FC\u30BF\u306E\u53EF\u7528\u6027\u3092\u78BA\u8A8D`
|
|
619
696
|
}
|
|
620
697
|
});
|
|
621
698
|
|
|
622
|
-
// ../connectors/src/connectors/google-analytics-oauth/parameters.ts
|
|
623
|
-
var parameters = {};
|
|
624
|
-
|
|
625
699
|
// ../connectors/src/connectors/google-analytics-oauth/setup-flow.ts
|
|
626
700
|
var ADMIN_BASE_URL3 = "https://analyticsadmin.googleapis.com/v1beta";
|
|
627
701
|
var DATA_BASE_URL = "https://analyticsdata.googleapis.com/v1beta";
|
|
@@ -927,7 +1001,7 @@ var inputSchema3 = z3.object({
|
|
|
927
1001
|
connectionId: z3.string().describe("ID of the Google Analytics OAuth connection to use"),
|
|
928
1002
|
method: z3.enum(["GET", "POST"]).describe("HTTP method"),
|
|
929
1003
|
path: z3.string().describe(
|
|
930
|
-
"API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/123456789:runReport'). Write the numeric property id directly
|
|
1004
|
+
"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."
|
|
931
1005
|
),
|
|
932
1006
|
body: z3.record(z3.string(), z3.unknown()).optional().describe("POST request body (JSON)")
|
|
933
1007
|
});
|
|
@@ -946,7 +1020,7 @@ var requestTool = new ConnectorTool({
|
|
|
946
1020
|
name: "request",
|
|
947
1021
|
description: `Send authenticated requests to the Google Analytics Data API v1beta.
|
|
948
1022
|
Authentication is handled automatically via OAuth proxy.
|
|
949
|
-
Write the numeric property id directly into the path (e.g. properties/123456789:runReport).`,
|
|
1023
|
+
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.`,
|
|
950
1024
|
inputSchema: inputSchema3,
|
|
951
1025
|
outputSchema: outputSchema3,
|
|
952
1026
|
async execute({ connectionId, method, path: path2, body }, connections, config) {
|
|
@@ -961,7 +1035,9 @@ Write the numeric property id directly into the path (e.g. properties/123456789:
|
|
|
961
1035
|
`[connector-request] google-analytics-oauth/${connection2.name}: ${method} ${path2}`
|
|
962
1036
|
);
|
|
963
1037
|
try {
|
|
964
|
-
const
|
|
1038
|
+
const propertyId = parameters.propertyId.tryGetValue(connection2);
|
|
1039
|
+
const resolvedPath = propertyId ? path2.replace(/\{propertyId\}/g, propertyId) : path2;
|
|
1040
|
+
const url = `${BASE_URL2}${resolvedPath}`;
|
|
965
1041
|
const token = await getProxyToken3(config.oauthProxy);
|
|
966
1042
|
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
967
1043
|
const controller = new AbortController();
|
|
@@ -1031,20 +1107,24 @@ var googleAnalyticsOauthConnector = new ConnectorPlugin({
|
|
|
1031
1107
|
systemPrompt: {
|
|
1032
1108
|
en: `### Tools
|
|
1033
1109
|
|
|
1034
|
-
- \`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}
|
|
1110
|
+
- \`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.
|
|
1035
1111
|
- \`connector_google-analytics-oauth_listAccounts\`: List accessible Google Analytics accounts. Use during setup to discover available accounts.
|
|
1036
1112
|
- \`connector_google-analytics-oauth_listProperties\`: List GA4 properties for a given account. Use during setup to select the target property.
|
|
1037
1113
|
|
|
1038
|
-
### GA4 Data API Reference
|
|
1114
|
+
### GA4 Data API Reference
|
|
1039
1115
|
|
|
1040
|
-
|
|
1116
|
+
#### Get Metadata (Check available dimensions and metrics)
|
|
1117
|
+
- GET properties/{propertyId}/metadata
|
|
1041
1118
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1119
|
+
### Get Report
|
|
1120
|
+
- POST properties/{propertyId}:runReport
|
|
1121
|
+
- Body example:
|
|
1122
|
+
{
|
|
1123
|
+
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
|
|
1124
|
+
"dimensions": [{"name": "date"}],
|
|
1125
|
+
"metrics": [{"name": "activeUsers"}],
|
|
1126
|
+
"limit": 100
|
|
1127
|
+
}
|
|
1048
1128
|
|
|
1049
1129
|
### Common Dimensions
|
|
1050
1130
|
date, country, city, deviceCategory, browser, pagePath, pageTitle,
|
|
@@ -1062,14 +1142,13 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
1062
1142
|
|
|
1063
1143
|
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.
|
|
1064
1144
|
|
|
1065
|
-
SDK surface (client created via \`connection(connectionId)\`)
|
|
1066
|
-
- \`client.
|
|
1067
|
-
- \`client.
|
|
1068
|
-
- \`client.
|
|
1069
|
-
|
|
1070
|
-
**Anti-pattern \u2014 do NOT do this.** \`client.request(...)\` is a low-level escape hatch that returns a raw \`Response\`; it is NOT how you run a report. In particular, **never call \`client.request({ method, path, body })\`** \u2014 that object shape belongs to the discovery *tool*, not the SDK. It will not run the report, and \`(await client.request({...})).rows\` is always \`undefined\`. Use \`client.runReport({ propertyId, ... })\` instead.
|
|
1145
|
+
SDK surface (client created via \`connection(connectionId)\`):
|
|
1146
|
+
- \`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).
|
|
1147
|
+
- \`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.
|
|
1148
|
+
- \`client.runRealtimeReport(request)\` \u2014 run a realtime report. \`propertyId\` works the same as \`runReport\`.
|
|
1149
|
+
- \`client.getMetadata(propertyId?)\` \u2014 fetch available dimensions and metrics for a property.
|
|
1071
1150
|
|
|
1072
|
-
|
|
1151
|
+
**Always pass \`propertyId\` explicitly** (the numeric id from the data overview) \u2014 the connection does not necessarily store a default property.
|
|
1073
1152
|
|
|
1074
1153
|
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.
|
|
1075
1154
|
|
|
@@ -1078,42 +1157,51 @@ If a handler test fails with \`Connection proxy is not configured\`, retry \u201
|
|
|
1078
1157
|
\`\`\`ts
|
|
1079
1158
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
1080
1159
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
const propertyId = "123456789"; // numeric GA4 property id from the data overview
|
|
1160
|
+
const ga = connection("<connectionId>");
|
|
1161
|
+
const propertyId = "123456789"; // numeric GA4 property id from the data overview
|
|
1084
1162
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1163
|
+
// Convenience methods (pass propertyId explicitly)
|
|
1164
|
+
const { rows, rowCount } = await ga.runReport({
|
|
1165
|
+
propertyId,
|
|
1166
|
+
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
1167
|
+
dimensions: [{ name: "date" }],
|
|
1168
|
+
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
1169
|
+
limit: 100,
|
|
1170
|
+
});
|
|
1171
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
1172
|
+
const realtime = await ga.runRealtimeReport({
|
|
1173
|
+
propertyId,
|
|
1174
|
+
metrics: [{ name: "activeUsers" }],
|
|
1175
|
+
dimensions: [{ name: "country" }],
|
|
1176
|
+
});
|
|
1097
1177
|
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1178
|
+
// Low-level authenticated fetch (write the numeric property id into the path)
|
|
1179
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
1180
|
+
method: "POST",
|
|
1181
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
1182
|
+
});
|
|
1183
|
+
const data = await res.json();
|
|
1100
1184
|
\`\`\``,
|
|
1101
1185
|
ja: `### \u30C4\u30FC\u30EB
|
|
1102
1186
|
|
|
1103
|
-
- \`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\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
1187
|
+
- \`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
|
|
1104
1188
|
- \`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
|
|
1105
1189
|
- \`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
|
|
1106
1190
|
|
|
1107
|
-
### GA4 Data API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
1191
|
+
### GA4 Data API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
1108
1192
|
|
|
1109
|
-
|
|
1193
|
+
#### \u30E1\u30BF\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\uFF08\u5229\u7528\u53EF\u80FD\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3\u3068\u30E1\u30C8\u30EA\u30AF\u30B9\u306E\u78BA\u8A8D\uFF09
|
|
1194
|
+
- GET properties/{propertyId}/metadata
|
|
1110
1195
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1196
|
+
### \u30EC\u30DD\u30FC\u30C8\u306E\u53D6\u5F97
|
|
1197
|
+
- POST properties/{propertyId}:runReport
|
|
1198
|
+
- Body\u4F8B:
|
|
1199
|
+
{
|
|
1200
|
+
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
|
|
1201
|
+
"dimensions": [{"name": "date"}],
|
|
1202
|
+
"metrics": [{"name": "activeUsers"}],
|
|
1203
|
+
"limit": 100
|
|
1204
|
+
}
|
|
1117
1205
|
|
|
1118
1206
|
### \u4E3B\u8981\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3
|
|
1119
1207
|
date, country, city, deviceCategory, browser, pagePath, pageTitle,
|
|
@@ -1131,14 +1219,13 @@ averageSessionDuration, conversions, totalRevenue
|
|
|
1131
1219
|
|
|
1132
1220
|
\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
|
|
1133
1221
|
|
|
1134
|
-
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09
|
|
1135
|
-
- \`client.
|
|
1136
|
-
- \`client.
|
|
1137
|
-
- \`client.
|
|
1222
|
+
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
|
|
1223
|
+
- \`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
|
|
1224
|
+
- \`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
|
|
1225
|
+
- \`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
|
|
1226
|
+
- \`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
|
|
1138
1227
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
**\`propertyId\` \u306F\u3059\u3079\u3066\u306E\u547C\u3073\u51FA\u3057\u3067\u5FC5\u9808\u3067\u3059**\uFF08\u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024ID\uFF09\u3002GA \u306E\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306F\u8907\u6570\u30D7\u30ED\u30D1\u30C6\u30A3\u306B\u307E\u305F\u304C\u308B\u3053\u3068\u304C\u3042\u308B\u305F\u3081\u3001\u30C7\u30D5\u30A9\u30EB\u30C8\u306F\u4FDD\u5B58\u3055\u308C\u307E\u305B\u3093\u3002
|
|
1228
|
+
**\`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
|
|
1142
1229
|
|
|
1143
1230
|
\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
|
|
1144
1231
|
|
|
@@ -1147,32 +1234,41 @@ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9
|
|
|
1147
1234
|
\`\`\`ts
|
|
1148
1235
|
import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
|
|
1149
1236
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
1153
|
-
|
|
1154
|
-
const { rows } = await client.runReport({
|
|
1155
|
-
propertyId,
|
|
1156
|
-
dateRanges: [{ startDate: "28daysAgo", endDate: "today" }],
|
|
1157
|
-
dimensions: [{ name: "date" }, { name: "sessionDefaultChannelGroup" }],
|
|
1158
|
-
metrics: [{ name: "sessions" }],
|
|
1159
|
-
});
|
|
1237
|
+
const ga = connection("<connectionId>");
|
|
1238
|
+
const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
|
|
1160
1239
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1240
|
+
// \u4FBF\u5229\u30E1\u30BD\u30C3\u30C9\uFF08propertyId \u3092\u660E\u793A\u7684\u306B\u6E21\u3059\uFF09
|
|
1241
|
+
const { rows, rowCount } = await ga.runReport({
|
|
1242
|
+
propertyId,
|
|
1243
|
+
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
|
1244
|
+
dimensions: [{ name: "date" }],
|
|
1245
|
+
metrics: [{ name: "activeUsers" }, { name: "sessions" }],
|
|
1246
|
+
limit: 100,
|
|
1247
|
+
});
|
|
1248
|
+
const metadata = await ga.getMetadata(propertyId);
|
|
1249
|
+
const realtime = await ga.runRealtimeReport({
|
|
1250
|
+
propertyId,
|
|
1251
|
+
metrics: [{ name: "activeUsers" }],
|
|
1252
|
+
dimensions: [{ name: "country" }],
|
|
1253
|
+
});
|
|
1166
1254
|
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1255
|
+
// \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
|
|
1256
|
+
const res = await ga.request(\`properties/\${propertyId}:runReport\`, {
|
|
1257
|
+
method: "POST",
|
|
1258
|
+
body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
|
|
1259
|
+
});
|
|
1260
|
+
const data = await res.json();
|
|
1169
1261
|
\`\`\``
|
|
1170
1262
|
},
|
|
1171
1263
|
tools,
|
|
1172
1264
|
setup: (params, ctx, config) => runSetupFlow(googleAnalyticsOauthSetupFlow, params, ctx, config),
|
|
1173
|
-
async checkConnection(
|
|
1265
|
+
async checkConnection(params, config) {
|
|
1174
1266
|
const { proxyFetch } = config;
|
|
1175
|
-
const
|
|
1267
|
+
const propertyId = params[parameters.propertyId.slug];
|
|
1268
|
+
if (!propertyId) {
|
|
1269
|
+
return { success: true };
|
|
1270
|
+
}
|
|
1271
|
+
const url = `https://analyticsdata.googleapis.com/v1beta/properties/${propertyId}/metadata`;
|
|
1176
1272
|
try {
|
|
1177
1273
|
const res = await proxyFetch(url, { method: "GET" });
|
|
1178
1274
|
if (!res.ok) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import * as hono_types from 'hono/types';
|
|
2
|
+
import * as hono from 'hono';
|
|
2
3
|
import { Hono } from 'hono';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - `handlerModules`: each `server-logic/*.ts` → a lazy loader (dynamic import).
|
|
8
|
-
* - `metaModules`: each `server-logic/*.json` → its parsed content.
|
|
9
|
-
* Both are keyed by project-root-relative path (e.g. `/server-logic/foo.ts`).
|
|
6
|
+
* Called once at startup by the build-generated server entry with the map of
|
|
7
|
+
* bundled TypeScript handlers. See `vite-plugin.ts`.
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
|
-
handlerModules: Record<string, () => Promise<Record<string, unknown>>>;
|
|
13
|
-
/**
|
|
14
|
-
* Raw JSON text per file. Parsed here (under try/catch) rather than by Vite's
|
|
15
|
-
* JSON loader, so one malformed file is skipped instead of breaking the whole
|
|
16
|
-
* build / all requests.
|
|
17
|
-
*/
|
|
18
|
-
metaModules: Record<string, string>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Populate the registry from the build-time collected source. Replaces any
|
|
22
|
-
* previous contents. Called once by the plugin-generated entry at startup, and
|
|
23
|
-
* — in development — again when Vite re-evaluates the entry after a server-logic
|
|
24
|
-
* file is added or edited.
|
|
25
|
-
*/
|
|
26
|
-
declare function populateServerLogics(source: ServerLogicSource): void;
|
|
9
|
+
declare function registerBundledHandlers(handlers: Record<string, (c: hono.Context) => Promise<unknown>>): void;
|
|
27
10
|
|
|
28
11
|
interface ConnectionEntry {
|
|
29
12
|
connector: {
|
|
@@ -307,4 +290,4 @@ declare const storage: {
|
|
|
307
290
|
|
|
308
291
|
declare const app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
309
292
|
|
|
310
|
-
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionFetchOptions, type ConnectionsMap, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type PresignedGetResult, PresignedHttpsTransport, type PresignedPutResult, type QueryFn, type GetResult as StorageGetResult, type StorageListItem, type ListOptions as StorageListOptions, type StorageListResult, type StorageMetadata, type PutOptions as StoragePutOptions, type StorageTransport, StorageUploadsClient, type StorageUsageDelta, type WixStoreClient, connection, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getQuery, loadConnections,
|
|
293
|
+
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionFetchOptions, type ConnectionsMap, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type PresignedGetResult, PresignedHttpsTransport, type PresignedPutResult, type QueryFn, type GetResult as StorageGetResult, type StorageListItem, type ListOptions as StorageListOptions, type StorageListResult, type StorageMetadata, type PutOptions as StoragePutOptions, type StorageTransport, StorageUploadsClient, type StorageUsageDelta, type WixStoreClient, connection, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getQuery, loadConnections, registerBundledHandlers, storage };
|