@squadbase/vite-server 0.1.19 → 0.1.20-dev.39a001c

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.
@@ -1,100 +1,21 @@
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: "Google Analytics Property ID",
69
- description: "The Google Analytics 4 property ID (e.g., 123456789). Can be found in GA4 Admin > Property Settings.",
70
- envVarBaseKey: "GA_OAUTH_PROPERTY_ID",
71
- type: "text",
72
- secret: false,
73
- required: false
74
- })
75
- };
76
-
77
1
  // ../connectors/src/connectors/google-analytics-oauth/sdk/index.ts
78
2
  var BASE_URL = "https://analyticsdata.googleapis.com/v1beta/";
79
- function createClient(params, fetchFn) {
80
- const propertyId = params[parameters.propertyId.slug];
81
- function resolvePropertyId() {
3
+ function createClient(_params, fetchFn) {
4
+ function resolvePropertyId(propertyId) {
82
5
  if (!propertyId) {
83
6
  throw new Error(
84
- "google-analytics-oauth: propertyId is required. Configure it via connection parameters."
7
+ "google-analytics-oauth: propertyId is required. Pass the numeric GA4 property id explicitly."
85
8
  );
86
9
  }
87
10
  return propertyId;
88
11
  }
89
12
  return {
90
13
  async request(path2, init) {
91
- const pid = propertyId;
92
- const resolvedPath = pid ? path2.replace(/\{propertyId\}/g, pid) : path2;
93
- const url = `${BASE_URL.replace(/\/+$/, "")}/${resolvedPath.replace(/^\/+/, "")}`;
14
+ const url = `${BASE_URL.replace(/\/+$/, "")}/${path2.replace(/^\/+/, "")}`;
94
15
  return fetchFn(url, init);
95
16
  },
96
- async runReport(request) {
97
- const pid = resolvePropertyId();
17
+ async runReport({ propertyId, ...request }) {
18
+ const pid = resolvePropertyId(propertyId);
98
19
  const response = await this.request(
99
20
  `properties/${pid}:runReport`,
100
21
  {
@@ -115,8 +36,8 @@ function createClient(params, fetchFn) {
115
36
  rowCount: data.rowCount ?? 0
116
37
  };
117
38
  },
118
- async getMetadata() {
119
- const pid = resolvePropertyId();
39
+ async getMetadata(propertyId) {
40
+ const pid = resolvePropertyId(propertyId);
120
41
  const response = await this.request(
121
42
  `properties/${pid}/metadata`,
122
43
  { method: "GET" }
@@ -129,8 +50,8 @@ function createClient(params, fetchFn) {
129
50
  }
130
51
  return await response.json();
131
52
  },
132
- async runRealtimeReport(request) {
133
- const pid = resolvePropertyId();
53
+ async runRealtimeReport({ propertyId, ...request }) {
54
+ const pid = resolvePropertyId(propertyId);
134
55
  const response = await this.request(
135
56
  `properties/${pid}:runRealtimeReport`,
136
57
  {
@@ -659,11 +580,11 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
659
580
  - \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
660
581
  - \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
661
582
  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
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
583
+ 4. \u30D7\u30ED\u30D1\u30C6\u30A3\u306E\u9078\u629E:
584
+ - \u30D7\u30ED\u30D1\u30C6\u30A3\u304C **2\u4EF6\u4EE5\u4E0A**: \u300C\u4F7F\u7528\u3059\u308B\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u300D\u3068\u30E6\u30FC\u30B6\u30FC\u306B\u4F1D\u3048\u305F\u4E0A\u3067\u3001\`askUserQuestion\` \u3092\u547C\u3073\u51FA\u3059\uFF08\`options\`: \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\uFF09
585
+ - \u30D7\u30ED\u30D1\u30C6\u30A3\u304C **1\u4EF6\u306E\u307F**: \`askUserQuestion\` \u306F\u30B9\u30AD\u30C3\u30D7\u3057\u3001\u305D\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u9078\u629E\u6E08\u307F\u3068\u3057\u3066\u6B21\u3078\u9032\u3080
586
+ - \u30D7\u30ED\u30D1\u30C6\u30A3\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\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B
587
+ 5. \u9078\u629E\u3055\u308C\u305F\u30D7\u30ED\u30D1\u30C6\u30A3ID\uFF08\u6570\u5024\uFF09\u306F\u4EE5\u964D\u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u3067\u30D1\u30B9\u306B\u76F4\u63A5\u6307\u5B9A\u3059\u308B\uFF08\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u306F\u4FDD\u5B58\u3055\u308C\u306A\u3044\uFF09\u3002\u6B21\u306E\u30B9\u30C6\u30C3\u30D7\u306B\u9032\u3080
667
588
 
668
589
  #### \u5236\u7D04
669
590
  - **\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
@@ -677,11 +598,11 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
677
598
  - **Only 1 account**: Skip \`askUserQuestion\` and proceed using that account as the selection
678
599
  - **0 accounts**: Abort setup and inform the user that no accessible accounts are available
679
600
  3. Call \`${listPropertiesToolName}\` to get the list of properties for the selected account
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
601
+ 4. Select a property:
602
+ - **2 or more properties**: Tell the user "Please select a property.", then call \`askUserQuestion\` (\`options\`: each option's \`label\` should be \`Display Name (id: propertyId)\`, \`value\` should be the property ID)
603
+ - **Only 1 property**: Skip \`askUserQuestion\` and proceed using that property as the selection
604
+ - **0 properties**: Abort setup and inform the user that no accessible properties are available
605
+ 5. Write the selected numeric property id directly into the request path (it is not stored on the connection). Proceed to the next step
685
606
 
686
607
  #### Constraints
687
608
  - **Do NOT fetch report data during setup**. Only the metadata requests specified in the steps above are allowed
@@ -689,13 +610,18 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
689
610
  - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
690
611
  },
691
612
  dataOverviewInstructions: {
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`
613
+ en: `Use the selected numeric property id in the path (write it directly, e.g. properties/123456789).
614
+ 1. Call connector_google-analytics-oauth_request with GET properties/<propertyId>/metadata to list available dimensions and metrics
615
+ 2. Call connector_google-analytics-oauth_request with POST properties/<propertyId>:runReport using a small date range and basic metrics to verify data availability`,
616
+ ja: `\u9078\u629E\u3057\u305F\u6570\u5024\u306E\u30D7\u30ED\u30D1\u30C6\u30A3ID\u3092\u30D1\u30B9\u306B\u76F4\u63A5\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: properties/123456789\uFF09\u3002
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`
696
619
  }
697
620
  });
698
621
 
622
+ // ../connectors/src/connectors/google-analytics-oauth/parameters.ts
623
+ var parameters = {};
624
+
699
625
  // ../connectors/src/connectors/google-analytics-oauth/setup-flow.ts
700
626
  var ADMIN_BASE_URL3 = "https://analyticsadmin.googleapis.com/v1beta";
701
627
  var DATA_BASE_URL = "https://analyticsdata.googleapis.com/v1beta";
@@ -1001,7 +927,7 @@ var inputSchema3 = z3.object({
1001
927
  connectionId: z3.string().describe("ID of the Google Analytics OAuth connection to use"),
1002
928
  method: z3.enum(["GET", "POST"]).describe("HTTP method"),
1003
929
  path: z3.string().describe(
1004
- "API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/{propertyId}:runReport'). {propertyId} is automatically replaced."
930
+ "API path appended to https://analyticsdata.googleapis.com/v1beta/ (e.g., 'properties/123456789:runReport'). Write the numeric property id directly into the path."
1005
931
  ),
1006
932
  body: z3.record(z3.string(), z3.unknown()).optional().describe("POST request body (JSON)")
1007
933
  });
@@ -1020,7 +946,7 @@ var requestTool = new ConnectorTool({
1020
946
  name: "request",
1021
947
  description: `Send authenticated requests to the Google Analytics Data API v1beta.
1022
948
  Authentication is handled automatically via OAuth proxy.
1023
- {propertyId} in the path is automatically replaced with the connection's property ID.`,
949
+ Write the numeric property id directly into the path (e.g. properties/123456789:runReport).`,
1024
950
  inputSchema: inputSchema3,
1025
951
  outputSchema: outputSchema3,
1026
952
  async execute({ connectionId, method, path: path2, body }, connections, config) {
@@ -1035,9 +961,7 @@ Authentication is handled automatically via OAuth proxy.
1035
961
  `[connector-request] google-analytics-oauth/${connection2.name}: ${method} ${path2}`
1036
962
  );
1037
963
  try {
1038
- const propertyId = parameters.propertyId.tryGetValue(connection2);
1039
- const resolvedPath = propertyId ? path2.replace(/\{propertyId\}/g, propertyId) : path2;
1040
- const url = `${BASE_URL2}${resolvedPath}`;
964
+ const url = `${BASE_URL2}${path2}`;
1041
965
  const token = await getProxyToken3(config.oauthProxy);
1042
966
  const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
1043
967
  const controller = new AbortController();
@@ -1107,24 +1031,20 @@ var googleAnalyticsOauthConnector = new ConnectorPlugin({
1107
1031
  systemPrompt: {
1108
1032
  en: `### Tools
1109
1033
 
1110
- - \`connector_google-analytics-oauth_request\`: Send authenticated requests to the GA4 Data API. Use it for running reports, getting metadata, and realtime reports. The {propertyId} placeholder in paths is automatically replaced. Authentication is configured automatically via OAuth.
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}\`. Authentication is configured automatically via OAuth.
1111
1035
  - \`connector_google-analytics-oauth_listAccounts\`: List accessible Google Analytics accounts. Use during setup to discover available accounts.
1112
1036
  - \`connector_google-analytics-oauth_listProperties\`: List GA4 properties for a given account. Use during setup to select the target property.
1113
1037
 
1114
- ### GA4 Data API Reference
1038
+ ### GA4 Data API Reference \u2014 for the \`connector_google-analytics-oauth_request\` **tool** only (setup/discovery)
1115
1039
 
1116
- #### Get Metadata (Check available dimensions and metrics)
1117
- - GET properties/{propertyId}/metadata
1040
+ These raw HTTP shapes describe the discovery **tool** above. **In server-logic (Business Logic below) do NOT hand-build these HTTP requests \u2014 call the SDK method on the same line, which takes the same body fields and returns already-parsed JSON:**
1118
1041
 
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
- }
1042
+ | Raw HTTP (tool, discovery) | Server-logic (SDK method) |
1043
+ |---|---|
1044
+ | \`GET properties/{propertyId}/metadata\` | \`await client.getMetadata(propertyId)\` |
1045
+ | \`POST properties/{propertyId}:runReport\` with body \`{ dateRanges, dimensions, metrics, limit }\` | \`await client.runReport({ propertyId, dateRanges, dimensions, metrics, limit })\` \u2192 \`{ rows, rowCount }\` |
1046
+
1047
+ Report body fields: \`dateRanges: [{ startDate, endDate }]\`, \`dimensions: [{ name }]\`, \`metrics: [{ name }]\`, optional \`limit\`.
1128
1048
 
1129
1049
  ### Common Dimensions
1130
1050
  date, country, city, deviceCategory, browser, pagePath, pageTitle,
@@ -1142,11 +1062,14 @@ averageSessionDuration, conversions, totalRevenue
1142
1062
 
1143
1063
  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.
1144
1064
 
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/\`).
1147
- - \`client.runReport(request)\` \u2014 run a GA4 report.
1148
- - \`client.runRealtimeReport(request)\` \u2014 run a realtime report.
1149
- - \`client.getMetadata()\` \u2014 fetch available dimensions and metrics.
1065
+ SDK surface (client created via \`connection(connectionId)\`). **Every method returns already-parsed JSON \u2014 you never build an HTTP request or parse a response yourself:**
1066
+ - \`client.runReport({ propertyId, dateRanges, dimensions, metrics, limit? })\` \u2014 run a GA4 report. Returns \`{ rows, rowCount }\`. **Use this for all reporting.**
1067
+ - \`client.runRealtimeReport({ propertyId, dimensions, metrics })\` \u2014 realtime report. Returns \`{ rows, rowCount }\`.
1068
+ - \`client.getMetadata(propertyId)\` \u2014 available dimensions and metrics for a property.
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.
1071
+
1072
+ **\`propertyId\` is required on every call** \u2014 pass the numeric id from the data overview. A GA connection can span multiple properties, so there is no stored default.
1150
1073
 
1151
1074
  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.
1152
1075
 
@@ -1155,48 +1078,42 @@ If a handler test fails with \`Connection proxy is not configured\`, retry \u201
1155
1078
  \`\`\`ts
1156
1079
  import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
1157
1080
 
1158
- const ga = connection("<connectionId>");
1081
+ export default async function handler(c) {
1082
+ const client = connection("<connectionId>");
1083
+ const propertyId = "123456789"; // numeric GA4 property id from the data overview
1159
1084
 
1160
- // Authenticated fetch (returns standard Response)
1161
- const res = await ga.request("properties/{propertyId}:runReport", {
1162
- method: "POST",
1163
- body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
1164
- });
1165
- const data = await res.json();
1085
+ const { rows } = await client.runReport({
1086
+ propertyId,
1087
+ dateRanges: [{ startDate: "28daysAgo", endDate: "today" }],
1088
+ dimensions: [{ name: "date" }, { name: "sessionDefaultChannelGroup" }],
1089
+ metrics: [{ name: "sessions" }],
1090
+ });
1166
1091
 
1167
- // Convenience methods
1168
- const { rows, rowCount } = await ga.runReport({
1169
- dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
1170
- dimensions: [{ name: "date" }],
1171
- metrics: [{ name: "activeUsers" }, { name: "sessions" }],
1172
- limit: 100,
1173
- });
1174
- const metadata = await ga.getMetadata();
1175
- const realtime = await ga.runRealtimeReport({
1176
- metrics: [{ name: "activeUsers" }],
1177
- dimensions: [{ name: "country" }],
1178
- });
1092
+ const data = rows.map((row) => ({
1093
+ date: row.dimensionValues[0].value,
1094
+ channel: row.dimensionValues[1].value,
1095
+ sessions: Number(row.metricValues[0].value) || 0,
1096
+ }));
1097
+
1098
+ return c.json(data);
1099
+ }
1179
1100
  \`\`\``,
1180
1101
  ja: `### \u30C4\u30FC\u30EB
1181
1102
 
1182
- - \`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\u5185\u306E{propertyId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
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
1183
1104
  - \`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
1184
1105
  - \`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
1185
1106
 
1186
- ### GA4 Data API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
1107
+ ### GA4 Data API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9 \u2014 \`connector_google-analytics-oauth_request\` **\u30C4\u30FC\u30EB**\u5C02\u7528\uFF08\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7/\u63A2\u7D22\u6642\uFF09
1187
1108
 
1188
- #### \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
1189
- - GET properties/{propertyId}/metadata
1109
+ \u4EE5\u4E0B\u306E\u751F\u306E HTTP \u5F62\u5F0F\u306F\u63A2\u7D22\u7528**\u30C4\u30FC\u30EB**\u306E\u3082\u306E\u3067\u3059\u3002**server-logic\uFF08\u4E0B\u8A18 Business Logic\uFF09\u3067\u306F\u3001\u3053\u308C\u3089\u306E HTTP \u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u624B\u7D44\u307F\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044 \u2014 \u540C\u3058 body \u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u53D6\u308A\u3001\u30D1\u30FC\u30B9\u6E08\u307F JSON \u3092\u8FD4\u3059 SDK \u30E1\u30BD\u30C3\u30C9\u3092\u547C\u3093\u3067\u304F\u3060\u3055\u3044:**
1190
1110
 
1191
- ### \u30EC\u30DD\u30FC\u30C8\u306E\u53D6\u5F97
1192
- - POST properties/{propertyId}:runReport
1193
- - Body\u4F8B:
1194
- {
1195
- "dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
1196
- "dimensions": [{"name": "date"}],
1197
- "metrics": [{"name": "activeUsers"}],
1198
- "limit": 100
1199
- }
1111
+ | \u751F\u306E HTTP\uFF08\u30C4\u30FC\u30EB\u30FB\u63A2\u7D22\u7528\uFF09 | server-logic\uFF08SDK \u30E1\u30BD\u30C3\u30C9\uFF09 |
1112
+ |---|---|
1113
+ | \`GET properties/{propertyId}/metadata\` | \`await client.getMetadata(propertyId)\` |
1114
+ | \`POST properties/{propertyId}:runReport\`\uFF08body: \`{ dateRanges, dimensions, metrics, limit }\`\uFF09 | \`await client.runReport({ propertyId, dateRanges, dimensions, metrics, limit })\` \u2192 \`{ rows, rowCount }\` |
1115
+
1116
+ \u30EC\u30DD\u30FC\u30C8\u306E body \u30D5\u30A3\u30FC\u30EB\u30C9: \`dateRanges: [{ startDate, endDate }]\`, \`dimensions: [{ name }]\`, \`metrics: [{ name }]\`, \u4EFB\u610F\u3067 \`limit\`\u3002
1200
1117
 
1201
1118
  ### \u4E3B\u8981\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3
1202
1119
  date, country, city, deviceCategory, browser, pagePath, pageTitle,
@@ -1214,11 +1131,14 @@ averageSessionDuration, conversions, totalRevenue
1214
1131
 
1215
1132
  \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
1216
1133
 
1217
- SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
1218
- - \`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
1219
- - \`client.runReport(request)\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
1220
- - \`client.runRealtimeReport(request)\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002
1221
- - \`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
1134
+ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09\u3002**\u5404\u30E1\u30BD\u30C3\u30C9\u306F\u30D1\u30FC\u30B9\u6E08\u307F JSON \u3092\u8FD4\u3057\u307E\u3059 \u2014 HTTP \u30EA\u30AF\u30A8\u30B9\u30C8\u306E\u7D44\u307F\u7ACB\u3066\u3084\u30EC\u30B9\u30DD\u30F3\u30B9\u306E\u30D1\u30FC\u30B9\u3092\u81EA\u5206\u3067\u884C\u3046\u5FC5\u8981\u306F\u3042\u308A\u307E\u305B\u3093:**
1135
+ - \`client.runReport({ propertyId, dateRanges, dimensions, metrics, limit? })\` \u2014 GA4 \u30EC\u30DD\u30FC\u30C8\u3092\u5B9F\u884C\u3002\`{ rows, rowCount }\` \u3092\u8FD4\u3057\u307E\u3059\u3002**\u30EC\u30DD\u30FC\u30C8\u53D6\u5F97\u306F\u5FC5\u305A\u3053\u308C\u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002**
1136
+ - \`client.runRealtimeReport({ propertyId, dimensions, metrics })\` \u2014 \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30EC\u30DD\u30FC\u30C8\u3002\`{ rows, rowCount }\` \u3092\u8FD4\u3057\u307E\u3059\u3002
1137
+ - \`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
+
1139
+ **\u30A2\u30F3\u30C1\u30D1\u30BF\u30FC\u30F3 \u2014 \u3053\u308C\u306F\u7D76\u5BFE\u306B\u3084\u3089\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002** \`client.request(...)\` \u306F\u751F\u306E \`Response\` \u3092\u8FD4\u3059\u4F4E\u30EC\u30D9\u30EB\u306E\u9003\u3052\u9053\u3067\u3042\u308A\u3001\u30EC\u30DD\u30FC\u30C8\u5B9F\u884C\u306E\u624B\u6BB5\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7279\u306B **\`client.request({ method, path, body })\` \u306F\u7D76\u5BFE\u306B\u547C\u3070\u306A\u3044\u3067\u304F\u3060\u3055\u3044** \u2014 \u305D\u306E\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u5F62\u306F\u63A2\u7D22\u7528*\u30C4\u30FC\u30EB*\u306E\u5F62\u3067\u3042\u3063\u3066 SDK \u306E\u3082\u306E\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u30EC\u30DD\u30FC\u30C8\u306F\u5B9F\u884C\u3055\u308C\u305A\u3001\`(await client.request({...})).rows\` \u306F\u5E38\u306B \`undefined\` \u306B\u306A\u308A\u307E\u3059\u3002\u4EE3\u308F\u308A\u306B \`client.runReport({ propertyId, ... })\` \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002
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
1222
1142
 
1223
1143
  \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
1224
1144
 
@@ -1227,38 +1147,32 @@ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9
1227
1147
  \`\`\`ts
1228
1148
  import { connection } from "@squadbase/vite-server/connectors/google-analytics-oauth";
1229
1149
 
1230
- const ga = connection("<connectionId>");
1150
+ export default async function handler(c) {
1151
+ const client = connection("<connectionId>");
1152
+ const propertyId = "123456789"; // \u30C7\u30FC\u30BF\u6982\u8981\u306B\u8F09\u3063\u3066\u3044\u308B\u6570\u5024\u306E GA4 \u30D7\u30ED\u30D1\u30C6\u30A3ID
1231
1153
 
1232
- // Authenticated fetch (returns standard Response)
1233
- const res = await ga.request("properties/{propertyId}:runReport", {
1234
- method: "POST",
1235
- body: JSON.stringify({ dateRanges: [{ startDate: "7daysAgo", endDate: "today" }], metrics: [{ name: "activeUsers" }] }),
1236
- });
1237
- const data = await res.json();
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
+ });
1238
1160
 
1239
- // Convenience methods
1240
- const { rows, rowCount } = await ga.runReport({
1241
- dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
1242
- dimensions: [{ name: "date" }],
1243
- metrics: [{ name: "activeUsers" }, { name: "sessions" }],
1244
- limit: 100,
1245
- });
1246
- const metadata = await ga.getMetadata();
1247
- const realtime = await ga.runRealtimeReport({
1248
- metrics: [{ name: "activeUsers" }],
1249
- dimensions: [{ name: "country" }],
1250
- });
1161
+ const data = rows.map((row) => ({
1162
+ date: row.dimensionValues[0].value,
1163
+ channel: row.dimensionValues[1].value,
1164
+ sessions: Number(row.metricValues[0].value) || 0,
1165
+ }));
1166
+
1167
+ return c.json(data);
1168
+ }
1251
1169
  \`\`\``
1252
1170
  },
1253
1171
  tools,
1254
1172
  setup: (params, ctx, config) => runSetupFlow(googleAnalyticsOauthSetupFlow, params, ctx, config),
1255
- async checkConnection(params, config) {
1173
+ async checkConnection(_params, config) {
1256
1174
  const { proxyFetch } = config;
1257
- const propertyId = params[parameters.propertyId.slug];
1258
- if (!propertyId) {
1259
- return { success: true };
1260
- }
1261
- const url = `https://analyticsdata.googleapis.com/v1beta/properties/${propertyId}/metadata`;
1175
+ const url = "https://analyticsadmin.googleapis.com/v1beta/accountSummaries";
1262
1176
  try {
1263
1177
  const res = await proxyFetch(url, { method: "GET" });
1264
1178
  if (!res.ok) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,30 @@
1
1
  import * as hono_types from 'hono/types';
2
2
  import { Hono } from 'hono';
3
3
 
4
+ /**
5
+ * Build-time collected server-logic files, provided by the plugin-generated
6
+ * entry via `import.meta.glob`:
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`).
10
+ */
11
+ interface ServerLogicSource {
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;
27
+
4
28
  interface ConnectionEntry {
5
29
  connector: {
6
30
  slug: string;
@@ -283,4 +307,4 @@ declare const storage: {
283
307
 
284
308
  declare const app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
285
309
 
286
- 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, storage };
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, populateServerLogics, storage };