@particle-academy/google-analytics-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/chunk-NY2RRZPH.js +153 -0
- package/dist/chunk-NY2RRZPH.js.map +1 -0
- package/dist/flow.cjs +177 -0
- package/dist/flow.cjs.map +1 -0
- package/dist/flow.d.cts +26 -0
- package/dist/flow.d.ts +26 -0
- package/dist/flow.js +25 -0
- package/dist/flow.js.map +1 -0
- package/dist/index.cjs +162 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +85 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@particle-academy/google-analytics-ui`,
|
|
4
|
+
`@particle-academy/google-analytics-js`,
|
|
5
|
+
`particle-academy/google-analytics-php` and `fancy-google-analytics`.
|
|
6
|
+
|
|
7
|
+
The four packages share one version, because they are generated from one
|
|
8
|
+
`provider/` definition and a version that meant something different in each
|
|
9
|
+
would be a version nobody could reason about.
|
|
10
|
+
|
|
11
|
+
## [0.1.0] — 2026-08-23
|
|
12
|
+
|
|
13
|
+
First release.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `report_run` — run a report against a GA4 property.
|
|
18
|
+
`POST /v1beta/{+property}:runReport`.
|
|
19
|
+
- A faker for it, so a flow can be built with no Google account.
|
|
20
|
+
|
|
21
|
+
### `{+property}` — the plus is the whole point
|
|
22
|
+
|
|
23
|
+
RFC 6570 **reserved expansion**. The value is `properties/1234567890` and the
|
|
24
|
+
**slash must survive**: percent-encoded it becomes `properties%2F1234567890` and
|
|
25
|
+
Google answers 404.
|
|
26
|
+
|
|
27
|
+
That is the exact opposite of Google Sheets, where a sheet named `Q1/Q2` *must*
|
|
28
|
+
have its slash escaped or the request reaches a different document. The two
|
|
29
|
+
templates are **one character apart** and both fail silently when confused — so
|
|
30
|
+
each runtime now picks its encoder from the `+`: `encodeURI` rather than
|
|
31
|
+
`encodeURIComponent`, `quote(safe="/")` rather than `quote(safe="")`, and in PHP
|
|
32
|
+
the slash is put back after `rawurlencode`, since PHP has no reserved-expansion
|
|
33
|
+
encoder at all.
|
|
34
|
+
|
|
35
|
+
### `metrics` is a list of NAMED OBJECTS
|
|
36
|
+
|
|
37
|
+
Google asks for `[{"name": "activeUsers"}]`, not `["activeUsers"]`; a bare list
|
|
38
|
+
of strings is refused as the wrong type. That is `encoding: "objects"` with an
|
|
39
|
+
`itemKey`, declared rather than guessed — a guess that fits one provider is
|
|
40
|
+
still a guess.
|
|
41
|
+
|
|
42
|
+
### The only read-only action in the estate
|
|
43
|
+
|
|
44
|
+
`sideEffects: "none"`. Running the same report twice returns the same numbers
|
|
45
|
+
and changes nothing, so a durable run may replay it freely and there is no
|
|
46
|
+
idempotency question at all.
|
|
47
|
+
|
|
48
|
+
The scope is `analytics.readonly`, not `analytics`. The discovery document lists
|
|
49
|
+
both for this method, and granting write access to run a report would let an
|
|
50
|
+
automation modify property configuration it never needs to touch.
|
|
51
|
+
|
|
52
|
+
### Metric values are STRINGS
|
|
53
|
+
|
|
54
|
+
Google sends `"412"`, not `412` — including for integer metrics. The faker says
|
|
55
|
+
so, because a fixture that emitted numbers would let an author write arithmetic
|
|
56
|
+
that works against the fake and concatenates against the real thing.
|
|
57
|
+
|
|
58
|
+
[0.1.0]: https://github.com/Fancy-Friends/google-analytics/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Particle Academy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Google Analytics
|
|
2
|
+
|
|
3
|
+
Google Analytics for [fancy-flow][flow] — as **four imported, versioned packages**, one
|
|
4
|
+
per runtime. Not vendored source: a copy cannot be upgraded, and third-party APIs
|
|
5
|
+
change.
|
|
6
|
+
|
|
7
|
+
[flow]: https://github.com/Particle-Academy/fancy-flow
|
|
8
|
+
|
|
9
|
+
| Runtime | Package | Install |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Authoring surface (every host) | `@particle-academy/google-analytics-ui` | `npm install @particle-academy/google-analytics-ui` |
|
|
12
|
+
| Node | `@particle-academy/google-analytics-js` | `npm install @particle-academy/google-analytics-js` |
|
|
13
|
+
| PHP 8.4+ | `particle-academy/google-analytics-php` | `composer require particle-academy/google-analytics-php` |
|
|
14
|
+
| Python 3.11+ | `fancy-google-analytics` | `pip install fancy-google-analytics` |
|
|
15
|
+
|
|
16
|
+
The `ui` package is the editor surface and is React on every host — a PHP or
|
|
17
|
+
Python project installs it *and* its own runtime package, and never the `js` one.
|
|
18
|
+
|
|
19
|
+
## What it costs you
|
|
20
|
+
|
|
21
|
+
One dependency: `@particle-academy/fancy-connector-core` (or
|
|
22
|
+
`particle-academy/fancy-connector-core` on Composer), which the `js` and `php`
|
|
23
|
+
packages pull in themselves. The Python package has **zero** runtime
|
|
24
|
+
dependencies.
|
|
25
|
+
|
|
26
|
+
**No Google Analytics SDK.** Plain HTTP, deliberately: a vendor SDK is third-party code
|
|
27
|
+
subject to the kit's full approval bar, and one per provider is hundreds of
|
|
28
|
+
dependencies nobody is tracking.
|
|
29
|
+
|
|
30
|
+
## Run it before you have credentials
|
|
31
|
+
|
|
32
|
+
Every operation ships a **faker**, whether or not Google Analytics has a sandbox. Set a
|
|
33
|
+
node's mode to `fake` and it returns the shape Google Analytics actually publishes — the
|
|
34
|
+
same field names, deterministically — so you can wire the downstream nodes before
|
|
35
|
+
touching an account, a key, or a network.
|
|
36
|
+
|
|
37
|
+
## This repository is generated
|
|
38
|
+
|
|
39
|
+
`provider/` is the source. Everything under `packages/` is emitted from it and
|
|
40
|
+
**must not be hand-edited** — CI regenerates and diffs on every push, and the
|
|
41
|
+
next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
|
|
42
|
+
|
|
43
|
+
## Two namespaces, which do not match on purpose
|
|
44
|
+
|
|
45
|
+
The repo is `github.com/Fancy-Friends/google-analytics`; the packages publish under
|
|
46
|
+
`particle-academy`. Nothing derives one from the other — the names come from
|
|
47
|
+
weaver's `friends.json` and nowhere else.
|
|
48
|
+
|
|
49
|
+
## Licence
|
|
50
|
+
|
|
51
|
+
MIT.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { callConnector } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
// src/faker.ts
|
|
4
|
+
function fakeReportRun({ config, fake }) {
|
|
5
|
+
return {
|
|
6
|
+
"dimensionHeaders": [
|
|
7
|
+
{
|
|
8
|
+
"name": "date"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"metricHeaders": [
|
|
12
|
+
{
|
|
13
|
+
"name": "activeUsers",
|
|
14
|
+
"type": "TYPE_INTEGER"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "sessions",
|
|
18
|
+
"type": "TYPE_INTEGER"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"rows": [
|
|
22
|
+
{
|
|
23
|
+
"dimensionValues": [
|
|
24
|
+
{
|
|
25
|
+
"value": "20260821"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"metricValues": [
|
|
29
|
+
{
|
|
30
|
+
"value": "412"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"value": "530"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"dimensionValues": [
|
|
39
|
+
{
|
|
40
|
+
"value": "20260822"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"metricValues": [
|
|
44
|
+
{
|
|
45
|
+
"value": "389"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"value": "501"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"rowCount": 2,
|
|
54
|
+
"kind": "analyticsData#runReport"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var googleAnalyticsFaker = (operation, request) => {
|
|
58
|
+
switch (operation) {
|
|
59
|
+
case "report_run":
|
|
60
|
+
return fakeReportRun(request);
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(
|
|
63
|
+
`google_analytics: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/service.ts
|
|
69
|
+
var CONNECTOR_API_VERSION = 1;
|
|
70
|
+
var GOOGLE_ANALYTICS_BASE_URLS = {
|
|
71
|
+
"live": "https://analyticsdata.googleapis.com"
|
|
72
|
+
};
|
|
73
|
+
var GOOGLE_ANALYTICS_REQUIRES = [
|
|
74
|
+
"accessToken",
|
|
75
|
+
"refreshToken",
|
|
76
|
+
"clientId",
|
|
77
|
+
"clientSecret"
|
|
78
|
+
];
|
|
79
|
+
function googleAnalyticsAuthorize(credentials, request, _mode) {
|
|
80
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
81
|
+
}
|
|
82
|
+
var GOOGLE_ANALYTICS = {
|
|
83
|
+
service: "google_analytics",
|
|
84
|
+
title: "Google Analytics",
|
|
85
|
+
sandbox: "none",
|
|
86
|
+
baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },
|
|
87
|
+
requires: [...GOOGLE_ANALYTICS_REQUIRES],
|
|
88
|
+
authorize: googleAnalyticsAuthorize,
|
|
89
|
+
faker: googleAnalyticsFaker
|
|
90
|
+
};
|
|
91
|
+
var REPORT_RUN_OPERATION = "report_run";
|
|
92
|
+
async function googleAnalyticsReportRun(options) {
|
|
93
|
+
const config = options.config ?? {};
|
|
94
|
+
if (config.property === void 0 || config.property === null || config.property === "") {
|
|
95
|
+
throw new Error(`report_run: "property" is required (Property).`);
|
|
96
|
+
}
|
|
97
|
+
if (config.startDate === void 0 || config.startDate === null || config.startDate === "") {
|
|
98
|
+
throw new Error(`report_run: "startDate" is required (Start date).`);
|
|
99
|
+
}
|
|
100
|
+
if (config.endDate === void 0 || config.endDate === null || config.endDate === "") {
|
|
101
|
+
throw new Error(`report_run: "endDate" is required (End date).`);
|
|
102
|
+
}
|
|
103
|
+
if (config.metrics === void 0 || config.metrics === null || config.metrics === "") {
|
|
104
|
+
throw new Error(`report_run: "metrics" is required (Metrics).`);
|
|
105
|
+
}
|
|
106
|
+
return callConnector(GOOGLE_ANALYTICS, {
|
|
107
|
+
operation: REPORT_RUN_OPERATION,
|
|
108
|
+
config,
|
|
109
|
+
input: options.input,
|
|
110
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
111
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
112
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
113
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
114
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
115
|
+
request: {
|
|
116
|
+
method: "POST",
|
|
117
|
+
path: `/v1beta/${encodeURI(String(config.property))}:runReport`,
|
|
118
|
+
json: nestFields({
|
|
119
|
+
"dateRanges.0.startDate": String(config.startDate),
|
|
120
|
+
"dateRanges.0.endDate": String(config.endDate),
|
|
121
|
+
"metrics": metricsList(config.metrics).map((item) => ({ "name": item })),
|
|
122
|
+
...config.dimensions !== void 0 && config.dimensions !== null && config.dimensions !== "" ? { "dimensions": dimensionsList(config.dimensions).map((item) => ({ "name": item })) } : {}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function nestFields(flat) {
|
|
128
|
+
const out = {};
|
|
129
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
130
|
+
const parts = path.split(".");
|
|
131
|
+
let node = out;
|
|
132
|
+
while (parts.length > 1) {
|
|
133
|
+
const key = parts.shift();
|
|
134
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
135
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
136
|
+
node = node[key];
|
|
137
|
+
}
|
|
138
|
+
node[parts[0]] = value;
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function metricsList(value) {
|
|
143
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
144
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
145
|
+
}
|
|
146
|
+
function dimensionsList(value) {
|
|
147
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
148
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { CONNECTOR_API_VERSION, GOOGLE_ANALYTICS, GOOGLE_ANALYTICS_BASE_URLS, GOOGLE_ANALYTICS_REQUIRES, REPORT_RUN_OPERATION, googleAnalyticsAuthorize, googleAnalyticsFaker, googleAnalyticsReportRun };
|
|
152
|
+
//# sourceMappingURL=chunk-NY2RRZPH.js.map
|
|
153
|
+
//# sourceMappingURL=chunk-NY2RRZPH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/report-run.ts"],"names":[],"mappings":";;;AA0BA,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AAC7D,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB;AAAA,MAClB;AAAA,QACE,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf;AAAA,QACE,MAAA,EAAQ,aAAA;AAAA,QACR,MAAA,EAAQ;AAAA,OACV;AAAA,MACA;AAAA,QACE,MAAA,EAAQ,UAAA;AAAA,QACR,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,MAAA,EAAQ;AAAA,MACN;AAAA,QACE,iBAAA,EAAmB;AAAA,UACjB;AAAA,YACE,OAAA,EAAS;AAAA;AACX,SACF;AAAA,QACA,cAAA,EAAgB;AAAA,UACd;AAAA,YACE,OAAA,EAAS;AAAA,WACX;AAAA,UACA;AAAA,YACE,OAAA,EAAS;AAAA;AACX;AACF,OACF;AAAA,MACA;AAAA,QACE,iBAAA,EAAmB;AAAA,UACjB;AAAA,YACE,OAAA,EAAS;AAAA;AACX,SACF;AAAA,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AA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAE9C,MAAA,IAAI,OAAO,IAAA,CAAK,GAAG,CAAA,KAAM,YAAY,IAAA,CAAK,GAAG,CAAA,KAAM,IAAA,OAAW,GAAG,CAAA,GAAI,UAAA,GAAa,KAAK,EAAC;AACxF,MAAA,IAAA,GAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,IAAA,CAAK,KAAA,CAAM,CAAC,CAAW,CAAA,GAAI,KAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,GAAA;AACT;AAGA,SAAS,YAAY,KAAA,EAA0B;AAC7C,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAC7B,MAAM,GAAA,CAAI,MAAM,CAAA,GAChB,OAAO,UAAU,QAAA,GACf,KAAA,CAAM,KAAA,CAAM,GAAG,IACf,EAAC;AAEP,EAAA,OAAO,KAAA,CAAM,IAAI,CAAC,IAAA,KAAS,KAAK,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AACxD;AAGA,SAAS,eAAe,KAAA,EAA0B;AAChD,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAC7B,MAAM,GAAA,CAAI,MAAM,CAAA,GAChB,OAAO,UAAU,QAAA,GACf,KAAA,CAAM,KAAA,CAAM,GAAG,IACf,EAAC;AAEP,EAAA,OAAO,KAAA,CAAM,IAAI,CAAC,IAAA,KAAS,KAAK,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AACxD","file":"chunk-NY2RRZPH.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * The Google Analytics faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES Google Analytics actually publishes, so an author can wire {{\n * $json.data.id }} against a fake and have it keep working against the real\n * thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakeReportRun({ config, fake }: FakeRequest): unknown {\n return {\n \"dimensionHeaders\": [\n {\n \"name\": \"date\",\n },\n ],\n \"metricHeaders\": [\n {\n \"name\": \"activeUsers\",\n \"type\": \"TYPE_INTEGER\",\n },\n {\n \"name\": \"sessions\",\n \"type\": \"TYPE_INTEGER\",\n },\n ],\n \"rows\": [\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260821\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"412\",\n },\n {\n \"value\": \"530\",\n },\n ],\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260822\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"389\",\n },\n {\n \"value\": \"501\",\n },\n ],\n },\n ],\n \"rowCount\": 2,\n \"kind\": \"analyticsData#runReport\",\n };\n}\n\nexport const googleAnalyticsFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"report_run\":\n return fakeReportRun(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `google_analytics: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Google Analytics, as one service descriptor shared by every Google Analytics\n * operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of Google Analytics: its base URL, its\n * auth scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * Google Analytics has no sandbox. A report reads a real property's real data\n * and spends real quota. The faker returns a plausibly-shaped report so a flow\n * can be built without a Google account.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { googleAnalyticsFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const GOOGLE_ANALYTICS_BASE_URLS = {\n \"live\": \"https://analyticsdata.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const GOOGLE_ANALYTICS_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply Google Analytics's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function googleAnalyticsAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The Google Analytics service, for the TypeScript runtime. */\nexport const GOOGLE_ANALYTICS: ServiceDescriptor = {\n service: \"google_analytics\",\n title: \"Google Analytics\",\n sandbox: \"none\",\n baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },\n requires: [...GOOGLE_ANALYTICS_REQUIRES],\n authorize: googleAnalyticsAuthorize,\n faker: googleAnalyticsFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/report-run.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/report-run.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Run a report against a Google Analytics 4 property.\n *\n * POST /v1beta/{+property}:runReport —\n * https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls Google Analytics or calls the\n * faker.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { GOOGLE_ANALYTICS } from \"../service.js\";\n\nexport const REPORT_RUN_OPERATION = \"report_run\";\n\nexport type ReportRunOptions = {\n /** The node's resolved config. Keys: property, startDate, endDate, metrics, dimensions. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function googleAnalyticsReportRun(options: ReportRunOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.property === undefined || config.property === null || config.property === \"\") {\n throw new Error(`report_run: \"property\" is required (Property).`);\n }\n\n if (config.startDate === undefined || config.startDate === null || config.startDate === \"\") {\n throw new Error(`report_run: \"startDate\" is required (Start date).`);\n }\n\n if (config.endDate === undefined || config.endDate === null || config.endDate === \"\") {\n throw new Error(`report_run: \"endDate\" is required (End date).`);\n }\n\n if (config.metrics === undefined || config.metrics === null || config.metrics === \"\") {\n throw new Error(`report_run: \"metrics\" is required (Metrics).`);\n }\n\n return callConnector(GOOGLE_ANALYTICS, {\n operation: REPORT_RUN_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: `/v1beta/${encodeURI(String(config.property))}:runReport`,\n json: nestFields({\n \"dateRanges.0.startDate\": String(config.startDate),\n \"dateRanges.0.endDate\": String(config.endDate),\n \"metrics\": metricsList(config.metrics).map((item) => ({ \"name\": item })),\n ...(config.dimensions !== undefined && config.dimensions !== null && config.dimensions !== \"\" ? { \"dimensions\": dimensionsList(config.dimensions).map((item) => ({ \"name\": item })) } : {}),\n }),\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction metricsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction dimensionsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n"]}
|
package/dist/flow.cjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyConnectorCore = require('@particle-academy/fancy-connector-core');
|
|
4
|
+
var googleAnalyticsUi = require('@particle-academy/google-analytics-ui');
|
|
5
|
+
|
|
6
|
+
// src/flow.ts
|
|
7
|
+
|
|
8
|
+
// src/faker.ts
|
|
9
|
+
function fakeReportRun({ config, fake }) {
|
|
10
|
+
return {
|
|
11
|
+
"dimensionHeaders": [
|
|
12
|
+
{
|
|
13
|
+
"name": "date"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"metricHeaders": [
|
|
17
|
+
{
|
|
18
|
+
"name": "activeUsers",
|
|
19
|
+
"type": "TYPE_INTEGER"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "sessions",
|
|
23
|
+
"type": "TYPE_INTEGER"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"rows": [
|
|
27
|
+
{
|
|
28
|
+
"dimensionValues": [
|
|
29
|
+
{
|
|
30
|
+
"value": "20260821"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"metricValues": [
|
|
34
|
+
{
|
|
35
|
+
"value": "412"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"value": "530"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"dimensionValues": [
|
|
44
|
+
{
|
|
45
|
+
"value": "20260822"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"metricValues": [
|
|
49
|
+
{
|
|
50
|
+
"value": "389"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"value": "501"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"rowCount": 2,
|
|
59
|
+
"kind": "analyticsData#runReport"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var googleAnalyticsFaker = (operation, request) => {
|
|
63
|
+
switch (operation) {
|
|
64
|
+
case "report_run":
|
|
65
|
+
return fakeReportRun(request);
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(
|
|
68
|
+
`google_analytics: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/service.ts
|
|
74
|
+
var GOOGLE_ANALYTICS_BASE_URLS = {
|
|
75
|
+
"live": "https://analyticsdata.googleapis.com"
|
|
76
|
+
};
|
|
77
|
+
var GOOGLE_ANALYTICS_REQUIRES = [
|
|
78
|
+
"accessToken",
|
|
79
|
+
"refreshToken",
|
|
80
|
+
"clientId",
|
|
81
|
+
"clientSecret"
|
|
82
|
+
];
|
|
83
|
+
function googleAnalyticsAuthorize(credentials, request, _mode) {
|
|
84
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
85
|
+
}
|
|
86
|
+
var GOOGLE_ANALYTICS = {
|
|
87
|
+
service: "google_analytics",
|
|
88
|
+
title: "Google Analytics",
|
|
89
|
+
sandbox: "none",
|
|
90
|
+
baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },
|
|
91
|
+
requires: [...GOOGLE_ANALYTICS_REQUIRES],
|
|
92
|
+
authorize: googleAnalyticsAuthorize,
|
|
93
|
+
faker: googleAnalyticsFaker
|
|
94
|
+
};
|
|
95
|
+
var REPORT_RUN_OPERATION = "report_run";
|
|
96
|
+
async function googleAnalyticsReportRun(options) {
|
|
97
|
+
const config = options.config ?? {};
|
|
98
|
+
if (config.property === void 0 || config.property === null || config.property === "") {
|
|
99
|
+
throw new Error(`report_run: "property" is required (Property).`);
|
|
100
|
+
}
|
|
101
|
+
if (config.startDate === void 0 || config.startDate === null || config.startDate === "") {
|
|
102
|
+
throw new Error(`report_run: "startDate" is required (Start date).`);
|
|
103
|
+
}
|
|
104
|
+
if (config.endDate === void 0 || config.endDate === null || config.endDate === "") {
|
|
105
|
+
throw new Error(`report_run: "endDate" is required (End date).`);
|
|
106
|
+
}
|
|
107
|
+
if (config.metrics === void 0 || config.metrics === null || config.metrics === "") {
|
|
108
|
+
throw new Error(`report_run: "metrics" is required (Metrics).`);
|
|
109
|
+
}
|
|
110
|
+
return fancyConnectorCore.callConnector(GOOGLE_ANALYTICS, {
|
|
111
|
+
operation: REPORT_RUN_OPERATION,
|
|
112
|
+
config,
|
|
113
|
+
input: options.input,
|
|
114
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
115
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
116
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
117
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
118
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
119
|
+
request: {
|
|
120
|
+
method: "POST",
|
|
121
|
+
path: `/v1beta/${encodeURI(String(config.property))}:runReport`,
|
|
122
|
+
json: nestFields({
|
|
123
|
+
"dateRanges.0.startDate": String(config.startDate),
|
|
124
|
+
"dateRanges.0.endDate": String(config.endDate),
|
|
125
|
+
"metrics": metricsList(config.metrics).map((item) => ({ "name": item })),
|
|
126
|
+
...config.dimensions !== void 0 && config.dimensions !== null && config.dimensions !== "" ? { "dimensions": dimensionsList(config.dimensions).map((item) => ({ "name": item })) } : {}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function nestFields(flat) {
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
134
|
+
const parts = path.split(".");
|
|
135
|
+
let node = out;
|
|
136
|
+
while (parts.length > 1) {
|
|
137
|
+
const key = parts.shift();
|
|
138
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
139
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
140
|
+
node = node[key];
|
|
141
|
+
}
|
|
142
|
+
node[parts[0]] = value;
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
function metricsList(value) {
|
|
147
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
148
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
149
|
+
}
|
|
150
|
+
function dimensionsList(value) {
|
|
151
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
152
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/flow.ts
|
|
156
|
+
var googleAnalyticsReportExecutor = async (ctx) => {
|
|
157
|
+
const config = ctx.node.data?.config ?? {};
|
|
158
|
+
const result = await googleAnalyticsReportRun({
|
|
159
|
+
config,
|
|
160
|
+
input: ctx.inputs?.in
|
|
161
|
+
});
|
|
162
|
+
ctx.emit({
|
|
163
|
+
type: "log",
|
|
164
|
+
level: "info",
|
|
165
|
+
nodeId: ctx.node.id,
|
|
166
|
+
message: `google_analytics report_run ${result.data?.id} (${result.mode})`
|
|
167
|
+
});
|
|
168
|
+
return { __port: "out", value: result };
|
|
169
|
+
};
|
|
170
|
+
var GOOGLE_ANALYTICS_RUNNABLE_KINDS = [
|
|
171
|
+
{ ...googleAnalyticsUi.googleAnalyticsReportKind, executor: googleAnalyticsReportExecutor }
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
exports.GOOGLE_ANALYTICS_RUNNABLE_KINDS = GOOGLE_ANALYTICS_RUNNABLE_KINDS;
|
|
175
|
+
exports.googleAnalyticsReportExecutor = googleAnalyticsReportExecutor;
|
|
176
|
+
//# sourceMappingURL=flow.cjs.map
|
|
177
|
+
//# sourceMappingURL=flow.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/report-run.ts","../src/flow.ts"],"names":["callConnector","googleAnalyticsReportKind"],"mappings":";;;;;;;;AA0BA,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AAC7D,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB;AAAA,MAClB;AAAA,QACE,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf;AAAA,QACE,MAAA,EAAQ,aAAA;AAAA,QACR,MAAA,EAAQ;AAAA,OACV;AAAA,MACA;AAAA,QACE,MAAA,EAAQ,UAAA;AAAA,QACR,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,MAAA,EAAQ;AAAA,MACN;AAAA,QACE,iBAAA,EAAmB;AAAA,UACjB;AAAA,YACE,OAAA,EAAS;AAAA;AACX,SACF;AAAA,QACA,cAAA,EAAgB;AAAA,UACd;AAAA,YACE,OAAA,EAAS;AAAA,WACX;AAAA,UACA;AAAA,YACE,OAAA,EAAS;AAAA;AACX;AACF,OACF;AAAA,MACA;AAAA,QACE,iBAAA,EAAmB;AAAA,UACjB;AAAA,YACE,OAAA,EAAS;AAAA;AACX,SACF;AAAA,QACA,cAAA,EAAgB;AAAA,UACd;AAAA,YACE,OAAA,EAAS;AAAA,WACX;AAAA,UACA;AAAA,YACE,OAAA,EAAS;AAAA;AACX;AACF;AACF,KACF;AAAA,IACA,UAAA,EAAY,CAAA;AAAA,IACZ,MAAA,EAAQ;AAAA,GACV;AACF;AAEO,IAAM,oBAAA,GAAuC,CAAC,SAAA,EAAW,OAAA,KAAY;AAC1E,EAAA,QAAQ,SAAA;AAAW,IACjB,KAAK,YAAA;AACH,MAAA,OAAO,cAAc,OAAO,CAAA;AAAA,IAE9B;AAIE,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,sDAAsD,SAAS,CAAA,iJAAA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EAAE,GAAGC,2CAAA,EAA2B,QAAA,EAAU,6BAAA;AAC5C","file":"flow.cjs","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * The Google Analytics faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES Google Analytics actually publishes, so an author can wire {{\n * $json.data.id }} against a fake and have it keep working against the real\n * thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakeReportRun({ config, fake }: FakeRequest): unknown {\n return {\n \"dimensionHeaders\": [\n {\n \"name\": \"date\",\n },\n ],\n \"metricHeaders\": [\n {\n \"name\": \"activeUsers\",\n \"type\": \"TYPE_INTEGER\",\n },\n {\n \"name\": \"sessions\",\n \"type\": \"TYPE_INTEGER\",\n },\n ],\n \"rows\": [\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260821\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"412\",\n },\n {\n \"value\": \"530\",\n },\n ],\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260822\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"389\",\n },\n {\n \"value\": \"501\",\n },\n ],\n },\n ],\n \"rowCount\": 2,\n \"kind\": \"analyticsData#runReport\",\n };\n}\n\nexport const googleAnalyticsFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"report_run\":\n return fakeReportRun(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `google_analytics: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Google Analytics, as one service descriptor shared by every Google Analytics\n * operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of Google Analytics: its base URL, its\n * auth scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * Google Analytics has no sandbox. A report reads a real property's real data\n * and spends real quota. The faker returns a plausibly-shaped report so a flow\n * can be built without a Google account.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { googleAnalyticsFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const GOOGLE_ANALYTICS_BASE_URLS = {\n \"live\": \"https://analyticsdata.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const GOOGLE_ANALYTICS_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply Google Analytics's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function googleAnalyticsAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The Google Analytics service, for the TypeScript runtime. */\nexport const GOOGLE_ANALYTICS: ServiceDescriptor = {\n service: \"google_analytics\",\n title: \"Google Analytics\",\n sandbox: \"none\",\n baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },\n requires: [...GOOGLE_ANALYTICS_REQUIRES],\n authorize: googleAnalyticsAuthorize,\n faker: googleAnalyticsFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/report-run.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/report-run.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Run a report against a Google Analytics 4 property.\n *\n * POST /v1beta/{+property}:runReport —\n * https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls Google Analytics or calls the\n * faker.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { GOOGLE_ANALYTICS } from \"../service.js\";\n\nexport const REPORT_RUN_OPERATION = \"report_run\";\n\nexport type ReportRunOptions = {\n /** The node's resolved config. Keys: property, startDate, endDate, metrics, dimensions. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function googleAnalyticsReportRun(options: ReportRunOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.property === undefined || config.property === null || config.property === \"\") {\n throw new Error(`report_run: \"property\" is required (Property).`);\n }\n\n if (config.startDate === undefined || config.startDate === null || config.startDate === \"\") {\n throw new Error(`report_run: \"startDate\" is required (Start date).`);\n }\n\n if (config.endDate === undefined || config.endDate === null || config.endDate === \"\") {\n throw new Error(`report_run: \"endDate\" is required (End date).`);\n }\n\n if (config.metrics === undefined || config.metrics === null || config.metrics === \"\") {\n throw new Error(`report_run: \"metrics\" is required (Metrics).`);\n }\n\n return callConnector(GOOGLE_ANALYTICS, {\n operation: REPORT_RUN_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: `/v1beta/${encodeURI(String(config.property))}:runReport`,\n json: nestFields({\n \"dateRanges.0.startDate\": String(config.startDate),\n \"dateRanges.0.endDate\": String(config.endDate),\n \"metrics\": metricsList(config.metrics).map((item) => ({ \"name\": item })),\n ...(config.dimensions !== undefined && config.dimensions !== null && config.dimensions !== \"\" ? { \"dimensions\": dimensionsList(config.dimensions).map((item) => ({ \"name\": item })) } : {}),\n }),\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction metricsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction dimensionsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/ + triggers/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/ + triggers/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Google Analytics's node kinds with their TypeScript executors attached — for\n * hosts that EXECUTE on TS.\n *\n * The authoring surface in @particle-academy/google-analytics-ui carries no\n * executor: the editor is React on every host, so a PHP or Python project\n * installs the ui package and never this one.\n */\n\nimport type { NodeExecutor, NodeKindDefinition } from \"@particle-academy/fancy-flow/engine\";\nimport {\n idempotencyKeyFor,\n NO_IDEMPOTENCY_KEY_WARNING,\n resolveConnection,\n triggerEvent,\n type RequestedMode,\n} from \"@particle-academy/fancy-connector-core\";\nimport { GOOGLE_ANALYTICS } from \"./service.js\";\n\nimport {\n googleAnalyticsReportKind,\n} from \"@particle-academy/google-analytics-ui\";\n\nimport { googleAnalyticsReportRun } from \"./actions/report-run.js\";\n\nexport const googleAnalyticsReportExecutor: NodeExecutor = async (ctx) => {\n const config = ((ctx.node.data as { config?: Record<string, unknown> })?.config ?? {});\n\n const result = await googleAnalyticsReportRun({\n config,\n input: ctx.inputs?.in,\n });\n\n ctx.emit({\n type: \"log\",\n level: \"info\",\n nodeId: ctx.node.id,\n message: `google_analytics report_run ${(result.data as { id?: string })?.id} (${result.mode})`,\n });\n\n return { __port: \"out\", value: result };\n};\n\n/** The kinds a TypeScript host registers. */\nexport const GOOGLE_ANALYTICS_RUNNABLE_KINDS: NodeKindDefinition[] = [\n { ...googleAnalyticsReportKind, executor: googleAnalyticsReportExecutor },\n];\n"]}
|
package/dist/flow.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NodeKindDefinition, NodeExecutor } from '@particle-academy/fancy-flow/engine';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/actions/ + triggers/ by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/actions/ + triggers/ (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- google_analytics
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics's node kinds with their TypeScript executors attached — for
|
|
15
|
+
* hosts that EXECUTE on TS.
|
|
16
|
+
*
|
|
17
|
+
* The authoring surface in @particle-academy/google-analytics-ui carries no
|
|
18
|
+
* executor: the editor is React on every host, so a PHP or Python project
|
|
19
|
+
* installs the ui package and never this one.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const googleAnalyticsReportExecutor: NodeExecutor;
|
|
23
|
+
/** The kinds a TypeScript host registers. */
|
|
24
|
+
declare const GOOGLE_ANALYTICS_RUNNABLE_KINDS: NodeKindDefinition[];
|
|
25
|
+
|
|
26
|
+
export { GOOGLE_ANALYTICS_RUNNABLE_KINDS, googleAnalyticsReportExecutor };
|
package/dist/flow.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NodeKindDefinition, NodeExecutor } from '@particle-academy/fancy-flow/engine';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/actions/ + triggers/ by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/actions/ + triggers/ (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- google_analytics
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics's node kinds with their TypeScript executors attached — for
|
|
15
|
+
* hosts that EXECUTE on TS.
|
|
16
|
+
*
|
|
17
|
+
* The authoring surface in @particle-academy/google-analytics-ui carries no
|
|
18
|
+
* executor: the editor is React on every host, so a PHP or Python project
|
|
19
|
+
* installs the ui package and never this one.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const googleAnalyticsReportExecutor: NodeExecutor;
|
|
23
|
+
/** The kinds a TypeScript host registers. */
|
|
24
|
+
declare const GOOGLE_ANALYTICS_RUNNABLE_KINDS: NodeKindDefinition[];
|
|
25
|
+
|
|
26
|
+
export { GOOGLE_ANALYTICS_RUNNABLE_KINDS, googleAnalyticsReportExecutor };
|
package/dist/flow.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { googleAnalyticsReportRun } from './chunk-NY2RRZPH.js';
|
|
2
|
+
import '@particle-academy/fancy-connector-core';
|
|
3
|
+
import { googleAnalyticsReportKind } from '@particle-academy/google-analytics-ui';
|
|
4
|
+
|
|
5
|
+
var googleAnalyticsReportExecutor = async (ctx) => {
|
|
6
|
+
const config = ctx.node.data?.config ?? {};
|
|
7
|
+
const result = await googleAnalyticsReportRun({
|
|
8
|
+
config,
|
|
9
|
+
input: ctx.inputs?.in
|
|
10
|
+
});
|
|
11
|
+
ctx.emit({
|
|
12
|
+
type: "log",
|
|
13
|
+
level: "info",
|
|
14
|
+
nodeId: ctx.node.id,
|
|
15
|
+
message: `google_analytics report_run ${result.data?.id} (${result.mode})`
|
|
16
|
+
});
|
|
17
|
+
return { __port: "out", value: result };
|
|
18
|
+
};
|
|
19
|
+
var GOOGLE_ANALYTICS_RUNNABLE_KINDS = [
|
|
20
|
+
{ ...googleAnalyticsReportKind, executor: googleAnalyticsReportExecutor }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export { GOOGLE_ANALYTICS_RUNNABLE_KINDS, googleAnalyticsReportExecutor };
|
|
24
|
+
//# sourceMappingURL=flow.js.map
|
|
25
|
+
//# sourceMappingURL=flow.js.map
|
package/dist/flow.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flow.ts"],"names":[],"mappings":";;;;AAoCO,IAAM,6BAAA,GAA8C,OAAO,GAAA,KAAQ;AACxE,EAAA,MAAM,MAAA,GAAW,GAAA,CAAI,IAAA,CAAK,IAAA,EAA+C,UAAU,EAAC;AAEpF,EAAA,MAAM,MAAA,GAAS,MAAM,wBAAA,CAAyB;AAAA,IAC5C,MAAA;AAAA,IACA,KAAA,EAAO,IAAI,MAAA,EAAQ;AAAA,GACpB,CAAA;AAED,EAAA,GAAA,CAAI,IAAA,CAAK;AAAA,IACP,IAAA,EAAM,KAAA;AAAA,IACN,KAAA,EAAO,MAAA;AAAA,IACP,MAAA,EAAQ,IAAI,IAAA,CAAK,EAAA;AAAA,IACjB,SAAS,CAAA,4BAAA,EAAgC,MAAA,CAAO,MAA0B,EAAE,CAAA,EAAA,EAAK,OAAO,IAAI,CAAA,CAAA;AAAA,GAC7F,CAAA;AAED,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,MAAA,EAAO;AACxC;AAGO,IAAM,+BAAA,GAAwD;AAAA,EACnE,EAAE,GAAG,yBAAA,EAA2B,QAAA,EAAU,6BAAA;AAC5C","file":"flow.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/ + triggers/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/ + triggers/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Google Analytics's node kinds with their TypeScript executors attached — for\n * hosts that EXECUTE on TS.\n *\n * The authoring surface in @particle-academy/google-analytics-ui carries no\n * executor: the editor is React on every host, so a PHP or Python project\n * installs the ui package and never this one.\n */\n\nimport type { NodeExecutor, NodeKindDefinition } from \"@particle-academy/fancy-flow/engine\";\nimport {\n idempotencyKeyFor,\n NO_IDEMPOTENCY_KEY_WARNING,\n resolveConnection,\n triggerEvent,\n type RequestedMode,\n} from \"@particle-academy/fancy-connector-core\";\nimport { GOOGLE_ANALYTICS } from \"./service.js\";\n\nimport {\n googleAnalyticsReportKind,\n} from \"@particle-academy/google-analytics-ui\";\n\nimport { googleAnalyticsReportRun } from \"./actions/report-run.js\";\n\nexport const googleAnalyticsReportExecutor: NodeExecutor = async (ctx) => {\n const config = ((ctx.node.data as { config?: Record<string, unknown> })?.config ?? {});\n\n const result = await googleAnalyticsReportRun({\n config,\n input: ctx.inputs?.in,\n });\n\n ctx.emit({\n type: \"log\",\n level: \"info\",\n nodeId: ctx.node.id,\n message: `google_analytics report_run ${(result.data as { id?: string })?.id} (${result.mode})`,\n });\n\n return { __port: \"out\", value: result };\n};\n\n/** The kinds a TypeScript host registers. */\nexport const GOOGLE_ANALYTICS_RUNNABLE_KINDS: NodeKindDefinition[] = [\n { ...googleAnalyticsReportKind, executor: googleAnalyticsReportExecutor },\n];\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyConnectorCore = require('@particle-academy/fancy-connector-core');
|
|
4
|
+
|
|
5
|
+
// src/faker.ts
|
|
6
|
+
function fakeReportRun({ config, fake }) {
|
|
7
|
+
return {
|
|
8
|
+
"dimensionHeaders": [
|
|
9
|
+
{
|
|
10
|
+
"name": "date"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"metricHeaders": [
|
|
14
|
+
{
|
|
15
|
+
"name": "activeUsers",
|
|
16
|
+
"type": "TYPE_INTEGER"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "sessions",
|
|
20
|
+
"type": "TYPE_INTEGER"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"rows": [
|
|
24
|
+
{
|
|
25
|
+
"dimensionValues": [
|
|
26
|
+
{
|
|
27
|
+
"value": "20260821"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"metricValues": [
|
|
31
|
+
{
|
|
32
|
+
"value": "412"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"value": "530"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"dimensionValues": [
|
|
41
|
+
{
|
|
42
|
+
"value": "20260822"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"metricValues": [
|
|
46
|
+
{
|
|
47
|
+
"value": "389"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "501"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"rowCount": 2,
|
|
56
|
+
"kind": "analyticsData#runReport"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var googleAnalyticsFaker = (operation, request) => {
|
|
60
|
+
switch (operation) {
|
|
61
|
+
case "report_run":
|
|
62
|
+
return fakeReportRun(request);
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(
|
|
65
|
+
`google_analytics: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/service.ts
|
|
71
|
+
var CONNECTOR_API_VERSION = 1;
|
|
72
|
+
var GOOGLE_ANALYTICS_BASE_URLS = {
|
|
73
|
+
"live": "https://analyticsdata.googleapis.com"
|
|
74
|
+
};
|
|
75
|
+
var GOOGLE_ANALYTICS_REQUIRES = [
|
|
76
|
+
"accessToken",
|
|
77
|
+
"refreshToken",
|
|
78
|
+
"clientId",
|
|
79
|
+
"clientSecret"
|
|
80
|
+
];
|
|
81
|
+
function googleAnalyticsAuthorize(credentials, request, _mode) {
|
|
82
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
83
|
+
}
|
|
84
|
+
var GOOGLE_ANALYTICS = {
|
|
85
|
+
service: "google_analytics",
|
|
86
|
+
title: "Google Analytics",
|
|
87
|
+
sandbox: "none",
|
|
88
|
+
baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },
|
|
89
|
+
requires: [...GOOGLE_ANALYTICS_REQUIRES],
|
|
90
|
+
authorize: googleAnalyticsAuthorize,
|
|
91
|
+
faker: googleAnalyticsFaker
|
|
92
|
+
};
|
|
93
|
+
var REPORT_RUN_OPERATION = "report_run";
|
|
94
|
+
async function googleAnalyticsReportRun(options) {
|
|
95
|
+
const config = options.config ?? {};
|
|
96
|
+
if (config.property === void 0 || config.property === null || config.property === "") {
|
|
97
|
+
throw new Error(`report_run: "property" is required (Property).`);
|
|
98
|
+
}
|
|
99
|
+
if (config.startDate === void 0 || config.startDate === null || config.startDate === "") {
|
|
100
|
+
throw new Error(`report_run: "startDate" is required (Start date).`);
|
|
101
|
+
}
|
|
102
|
+
if (config.endDate === void 0 || config.endDate === null || config.endDate === "") {
|
|
103
|
+
throw new Error(`report_run: "endDate" is required (End date).`);
|
|
104
|
+
}
|
|
105
|
+
if (config.metrics === void 0 || config.metrics === null || config.metrics === "") {
|
|
106
|
+
throw new Error(`report_run: "metrics" is required (Metrics).`);
|
|
107
|
+
}
|
|
108
|
+
return fancyConnectorCore.callConnector(GOOGLE_ANALYTICS, {
|
|
109
|
+
operation: REPORT_RUN_OPERATION,
|
|
110
|
+
config,
|
|
111
|
+
input: options.input,
|
|
112
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
113
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
114
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
115
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
116
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
117
|
+
request: {
|
|
118
|
+
method: "POST",
|
|
119
|
+
path: `/v1beta/${encodeURI(String(config.property))}:runReport`,
|
|
120
|
+
json: nestFields({
|
|
121
|
+
"dateRanges.0.startDate": String(config.startDate),
|
|
122
|
+
"dateRanges.0.endDate": String(config.endDate),
|
|
123
|
+
"metrics": metricsList(config.metrics).map((item) => ({ "name": item })),
|
|
124
|
+
...config.dimensions !== void 0 && config.dimensions !== null && config.dimensions !== "" ? { "dimensions": dimensionsList(config.dimensions).map((item) => ({ "name": item })) } : {}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function nestFields(flat) {
|
|
130
|
+
const out = {};
|
|
131
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
132
|
+
const parts = path.split(".");
|
|
133
|
+
let node = out;
|
|
134
|
+
while (parts.length > 1) {
|
|
135
|
+
const key = parts.shift();
|
|
136
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
137
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
138
|
+
node = node[key];
|
|
139
|
+
}
|
|
140
|
+
node[parts[0]] = value;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
function metricsList(value) {
|
|
145
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
146
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
147
|
+
}
|
|
148
|
+
function dimensionsList(value) {
|
|
149
|
+
const items = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(",") : [];
|
|
150
|
+
return items.map((item) => item.trim()).filter(Boolean);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.CONNECTOR_API_VERSION = CONNECTOR_API_VERSION;
|
|
154
|
+
exports.GOOGLE_ANALYTICS = GOOGLE_ANALYTICS;
|
|
155
|
+
exports.GOOGLE_ANALYTICS_BASE_URLS = GOOGLE_ANALYTICS_BASE_URLS;
|
|
156
|
+
exports.GOOGLE_ANALYTICS_REQUIRES = GOOGLE_ANALYTICS_REQUIRES;
|
|
157
|
+
exports.REPORT_RUN_OPERATION = REPORT_RUN_OPERATION;
|
|
158
|
+
exports.googleAnalyticsAuthorize = googleAnalyticsAuthorize;
|
|
159
|
+
exports.googleAnalyticsFaker = googleAnalyticsFaker;
|
|
160
|
+
exports.googleAnalyticsReportRun = googleAnalyticsReportRun;
|
|
161
|
+
//# sourceMappingURL=index.cjs.map
|
|
162
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/report-run.ts"],"names":["callConnector"],"mappings":";;;;;AA0BA,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AAC7D,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB;AAAA,MAClB;AAAA,QACE,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf;AAAA,QACE,MAAA,EAAQ,aAAA;AAAA,QACR,MAAA,EAAQ;AAAA,OACV;AAAA,MACA;AAAA,QACE,MAAA,EAAQ,UAAA;AAAA,QACR,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,MAAA,EAAQ;AAAA,MACN;AAAA,QACE,iBAAA,EAAmB;AAAA,UACjB;AAAA,YACE,OAAA,EAAS;AAAA;AACX,SACF;AAAA,QACA,cAAA,EAAgB;AAAA,UACd;AAAA,YACE,OAAA,EAAS;AAAA,WACX;AAAA,UACA;AAAA,YACE,OAAA,EAAS;AAAA;AACX;AAC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A,CAAM,SAAS,CAAA,EAAG;AACvB,MAAA,MAAM,GAAA,GAAM,MAAM,KAAA,EAAM;AAMxB,MAAA,MAAM,aAAa,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAE9C,MAAA,IAAI,OAAO,IAAA,CAAK,GAAG,CAAA,KAAM,YAAY,IAAA,CAAK,GAAG,CAAA,KAAM,IAAA,OAAW,GAAG,CAAA,GAAI,UAAA,GAAa,KAAK,EAAC;AACxF,MAAA,IAAA,GAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,IAAA,CAAK,KAAA,CAAM,CAAC,CAAW,CAAA,GAAI,KAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,GAAA;AACT;AAGA,SAAS,YAAY,KAAA,EAA0B;AAC7C,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAC7B,MAAM,GAAA,CAAI,MAAM,CAAA,GAChB,OAAO,UAAU,QAAA,GACf,KAAA,CAAM,KAAA,CAAM,GAAG,IACf,EAAC;AAEP,EAAA,OAAO,KAAA,CAAM,IAAI,CAAC,IAAA,KAAS,KAAK,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AACxD;AAGA,SAAS,eAAe,KAAA,EAA0B;AAChD,EAAA,MAAM,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAC7B,MAAM,GAAA,CAAI,MAAM,CAAA,GAChB,OAAO,UAAU,QAAA,GACf,KAAA,CAAM,KAAA,CAAM,GAAG,IACf,EAAC;AAEP,EAAA,OAAO,KAAA,CAAM,IAAI,CAAC,IAAA,KAAS,KAAK,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AACxD","file":"index.cjs","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * The Google Analytics faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES Google Analytics actually publishes, so an author can wire {{\n * $json.data.id }} against a fake and have it keep working against the real\n * thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakeReportRun({ config, fake }: FakeRequest): unknown {\n return {\n \"dimensionHeaders\": [\n {\n \"name\": \"date\",\n },\n ],\n \"metricHeaders\": [\n {\n \"name\": \"activeUsers\",\n \"type\": \"TYPE_INTEGER\",\n },\n {\n \"name\": \"sessions\",\n \"type\": \"TYPE_INTEGER\",\n },\n ],\n \"rows\": [\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260821\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"412\",\n },\n {\n \"value\": \"530\",\n },\n ],\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"20260822\",\n },\n ],\n \"metricValues\": [\n {\n \"value\": \"389\",\n },\n {\n \"value\": \"501\",\n },\n ],\n },\n ],\n \"rowCount\": 2,\n \"kind\": \"analyticsData#runReport\",\n };\n}\n\nexport const googleAnalyticsFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"report_run\":\n return fakeReportRun(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `google_analytics: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Google Analytics, as one service descriptor shared by every Google Analytics\n * operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of Google Analytics: its base URL, its\n * auth scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * Google Analytics has no sandbox. A report reads a real property's real data\n * and spends real quota. The faker returns a plausibly-shaped report so a flow\n * can be built without a Google account.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { googleAnalyticsFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const GOOGLE_ANALYTICS_BASE_URLS = {\n \"live\": \"https://analyticsdata.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const GOOGLE_ANALYTICS_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply Google Analytics's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function googleAnalyticsAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The Google Analytics service, for the TypeScript runtime. */\nexport const GOOGLE_ANALYTICS: ServiceDescriptor = {\n service: \"google_analytics\",\n title: \"Google Analytics\",\n sandbox: \"none\",\n baseUrls: { ...GOOGLE_ANALYTICS_BASE_URLS },\n requires: [...GOOGLE_ANALYTICS_REQUIRES],\n authorize: googleAnalyticsAuthorize,\n faker: googleAnalyticsFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/report-run.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/report-run.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- google_analytics\n */\n\n/**\n * Run a report against a Google Analytics 4 property.\n *\n * POST /v1beta/{+property}:runReport —\n * https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls Google Analytics or calls the\n * faker.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { GOOGLE_ANALYTICS } from \"../service.js\";\n\nexport const REPORT_RUN_OPERATION = \"report_run\";\n\nexport type ReportRunOptions = {\n /** The node's resolved config. Keys: property, startDate, endDate, metrics, dimensions. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function googleAnalyticsReportRun(options: ReportRunOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.property === undefined || config.property === null || config.property === \"\") {\n throw new Error(`report_run: \"property\" is required (Property).`);\n }\n\n if (config.startDate === undefined || config.startDate === null || config.startDate === \"\") {\n throw new Error(`report_run: \"startDate\" is required (Start date).`);\n }\n\n if (config.endDate === undefined || config.endDate === null || config.endDate === \"\") {\n throw new Error(`report_run: \"endDate\" is required (End date).`);\n }\n\n if (config.metrics === undefined || config.metrics === null || config.metrics === \"\") {\n throw new Error(`report_run: \"metrics\" is required (Metrics).`);\n }\n\n return callConnector(GOOGLE_ANALYTICS, {\n operation: REPORT_RUN_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: `/v1beta/${encodeURI(String(config.property))}:runReport`,\n json: nestFields({\n \"dateRanges.0.startDate\": String(config.startDate),\n \"dateRanges.0.endDate\": String(config.endDate),\n \"metrics\": metricsList(config.metrics).map((item) => ({ \"name\": item })),\n ...(config.dimensions !== undefined && config.dimensions !== null && config.dimensions !== \"\" ? { \"dimensions\": dimensionsList(config.dimensions).map((item) => ({ \"name\": item })) } : {}),\n }),\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction metricsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n\n/** One value, a \",\"-separated string, or an array — all end up a list. */\nfunction dimensionsList(value: unknown): string[] {\n const items = Array.isArray(value)\n ? value.map(String)\n : typeof value === \"string\"\n ? value.split(\",\")\n : [];\n\n return items.map((item) => item.trim()).filter(Boolean);\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ServiceDescriptor, PreparedRequest, ConnectorMode, ConnectorFaker, RequestedMode, Transport, ConnectorResult } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/manifest.json by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/manifest.json (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- google_analytics
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics, as one service descriptor shared by every Google Analytics
|
|
15
|
+
* operation.
|
|
16
|
+
*
|
|
17
|
+
* @particle-academy/fancy-connector-core carries what is true of ALL
|
|
18
|
+
* connectors. This carries what is true of Google Analytics: its base URL, its
|
|
19
|
+
* auth scheme, its idempotency header, and its faker.
|
|
20
|
+
*
|
|
21
|
+
* ## The sandbox trap, written down where it is used
|
|
22
|
+
*
|
|
23
|
+
* Google Analytics has no sandbox. A report reads a real property's real data
|
|
24
|
+
* and spends real quota. The faker returns a plausibly-shaped report so a flow
|
|
25
|
+
* can be built without a Google account.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The connector API version this package was GENERATED against.
|
|
30
|
+
*
|
|
31
|
+
* A literal, never imported. An imported constant lets an upgrade rewrite the
|
|
32
|
+
* very claim it exists to detect, after which the copy agrees with itself
|
|
33
|
+
* forever.
|
|
34
|
+
*/
|
|
35
|
+
declare const CONNECTOR_API_VERSION = 1;
|
|
36
|
+
declare const GOOGLE_ANALYTICS_BASE_URLS: {
|
|
37
|
+
readonly live: "https://analyticsdata.googleapis.com";
|
|
38
|
+
};
|
|
39
|
+
/** Credential keys a remote call cannot proceed without. */
|
|
40
|
+
declare const GOOGLE_ANALYTICS_REQUIRES: readonly ["accessToken", "refreshToken", "clientId", "clientSecret"];
|
|
41
|
+
/**
|
|
42
|
+
* Apply Google Analytics's auth scheme to an outgoing request.
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
* The mode is passed in because for some providers auth and estate are the
|
|
47
|
+
* same decision expressed in the URL; here it is unused, and saying so is
|
|
48
|
+
* cheaper than wondering later whether it was forgotten.
|
|
49
|
+
*/
|
|
50
|
+
declare function googleAnalyticsAuthorize(credentials: Record<string, string | undefined>, request: PreparedRequest, _mode: ConnectorMode): void;
|
|
51
|
+
/** The Google Analytics service, for the TypeScript runtime. */
|
|
52
|
+
declare const GOOGLE_ANALYTICS: ServiceDescriptor;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* GENERATED FILE — do not edit.
|
|
56
|
+
*
|
|
57
|
+
* Emitted from provider/fixtures/ by weaver's generator.
|
|
58
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
59
|
+
* being rejected, because it works until it silently does not. Fix
|
|
60
|
+
* provider/fixtures/ (or weaver's template/) and regenerate:
|
|
61
|
+
*
|
|
62
|
+
* npm run provider -- google_analytics
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* The Google Analytics faker.
|
|
66
|
+
*
|
|
67
|
+
* Shapes, not behaviour: the goal is that a downstream node sees the field
|
|
68
|
+
* NAMES Google Analytics actually publishes, so an author can wire {{
|
|
69
|
+
* $json.data.id }} against a fake and have it keep working against the real
|
|
70
|
+
* thing.
|
|
71
|
+
*
|
|
72
|
+
* Deterministic — same inputs, same output. A faker returning a fresh uuid
|
|
73
|
+
* every call cannot be asserted on, so its fixtures degrade to "it did not
|
|
74
|
+
* throw", which is the assertion that catches nothing.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
declare const googleAnalyticsFaker: ConnectorFaker;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* GENERATED FILE — do not edit.
|
|
81
|
+
*
|
|
82
|
+
* Emitted from provider/actions/report-run.json by weaver's generator.
|
|
83
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
84
|
+
* being rejected, because it works until it silently does not. Fix
|
|
85
|
+
* provider/actions/report-run.json (or weaver's template/) and regenerate:
|
|
86
|
+
*
|
|
87
|
+
* npm run provider -- google_analytics
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Run a report against a Google Analytics 4 property.
|
|
91
|
+
*
|
|
92
|
+
* POST /v1beta/{+property}:runReport —
|
|
93
|
+
* https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
|
|
94
|
+
*
|
|
95
|
+
* Notice what is NOT here: no key, no base URL, no mode check, no retry loop,
|
|
96
|
+
* no fake/real branch. This describes the request; callConnector resolves the
|
|
97
|
+
* connection, picks the estate, and either calls Google Analytics or calls the
|
|
98
|
+
* faker.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
declare const REPORT_RUN_OPERATION = "report_run";
|
|
102
|
+
type ReportRunOptions = {
|
|
103
|
+
/** The node's resolved config. Keys: property, startDate, endDate, metrics, dimensions. */
|
|
104
|
+
config: Record<string, unknown>;
|
|
105
|
+
credentials?: Record<string, string | undefined>;
|
|
106
|
+
mode?: RequestedMode;
|
|
107
|
+
connectionId?: string | null;
|
|
108
|
+
input?: unknown;
|
|
109
|
+
attempts?: number;
|
|
110
|
+
/** Override the transport. The only way to exercise this without a network. */
|
|
111
|
+
transport?: Transport;
|
|
112
|
+
};
|
|
113
|
+
declare function googleAnalyticsReportRun(options: ReportRunOptions): Promise<ConnectorResult>;
|
|
114
|
+
|
|
115
|
+
export { CONNECTOR_API_VERSION, GOOGLE_ANALYTICS, GOOGLE_ANALYTICS_BASE_URLS, GOOGLE_ANALYTICS_REQUIRES, REPORT_RUN_OPERATION, type ReportRunOptions, googleAnalyticsAuthorize, googleAnalyticsFaker, googleAnalyticsReportRun };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ServiceDescriptor, PreparedRequest, ConnectorMode, ConnectorFaker, RequestedMode, Transport, ConnectorResult } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/manifest.json by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/manifest.json (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- google_analytics
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics, as one service descriptor shared by every Google Analytics
|
|
15
|
+
* operation.
|
|
16
|
+
*
|
|
17
|
+
* @particle-academy/fancy-connector-core carries what is true of ALL
|
|
18
|
+
* connectors. This carries what is true of Google Analytics: its base URL, its
|
|
19
|
+
* auth scheme, its idempotency header, and its faker.
|
|
20
|
+
*
|
|
21
|
+
* ## The sandbox trap, written down where it is used
|
|
22
|
+
*
|
|
23
|
+
* Google Analytics has no sandbox. A report reads a real property's real data
|
|
24
|
+
* and spends real quota. The faker returns a plausibly-shaped report so a flow
|
|
25
|
+
* can be built without a Google account.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The connector API version this package was GENERATED against.
|
|
30
|
+
*
|
|
31
|
+
* A literal, never imported. An imported constant lets an upgrade rewrite the
|
|
32
|
+
* very claim it exists to detect, after which the copy agrees with itself
|
|
33
|
+
* forever.
|
|
34
|
+
*/
|
|
35
|
+
declare const CONNECTOR_API_VERSION = 1;
|
|
36
|
+
declare const GOOGLE_ANALYTICS_BASE_URLS: {
|
|
37
|
+
readonly live: "https://analyticsdata.googleapis.com";
|
|
38
|
+
};
|
|
39
|
+
/** Credential keys a remote call cannot proceed without. */
|
|
40
|
+
declare const GOOGLE_ANALYTICS_REQUIRES: readonly ["accessToken", "refreshToken", "clientId", "clientSecret"];
|
|
41
|
+
/**
|
|
42
|
+
* Apply Google Analytics's auth scheme to an outgoing request.
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
* The mode is passed in because for some providers auth and estate are the
|
|
47
|
+
* same decision expressed in the URL; here it is unused, and saying so is
|
|
48
|
+
* cheaper than wondering later whether it was forgotten.
|
|
49
|
+
*/
|
|
50
|
+
declare function googleAnalyticsAuthorize(credentials: Record<string, string | undefined>, request: PreparedRequest, _mode: ConnectorMode): void;
|
|
51
|
+
/** The Google Analytics service, for the TypeScript runtime. */
|
|
52
|
+
declare const GOOGLE_ANALYTICS: ServiceDescriptor;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* GENERATED FILE — do not edit.
|
|
56
|
+
*
|
|
57
|
+
* Emitted from provider/fixtures/ by weaver's generator.
|
|
58
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
59
|
+
* being rejected, because it works until it silently does not. Fix
|
|
60
|
+
* provider/fixtures/ (or weaver's template/) and regenerate:
|
|
61
|
+
*
|
|
62
|
+
* npm run provider -- google_analytics
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* The Google Analytics faker.
|
|
66
|
+
*
|
|
67
|
+
* Shapes, not behaviour: the goal is that a downstream node sees the field
|
|
68
|
+
* NAMES Google Analytics actually publishes, so an author can wire {{
|
|
69
|
+
* $json.data.id }} against a fake and have it keep working against the real
|
|
70
|
+
* thing.
|
|
71
|
+
*
|
|
72
|
+
* Deterministic — same inputs, same output. A faker returning a fresh uuid
|
|
73
|
+
* every call cannot be asserted on, so its fixtures degrade to "it did not
|
|
74
|
+
* throw", which is the assertion that catches nothing.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
declare const googleAnalyticsFaker: ConnectorFaker;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* GENERATED FILE — do not edit.
|
|
81
|
+
*
|
|
82
|
+
* Emitted from provider/actions/report-run.json by weaver's generator.
|
|
83
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
84
|
+
* being rejected, because it works until it silently does not. Fix
|
|
85
|
+
* provider/actions/report-run.json (or weaver's template/) and regenerate:
|
|
86
|
+
*
|
|
87
|
+
* npm run provider -- google_analytics
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Run a report against a Google Analytics 4 property.
|
|
91
|
+
*
|
|
92
|
+
* POST /v1beta/{+property}:runReport —
|
|
93
|
+
* https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
|
|
94
|
+
*
|
|
95
|
+
* Notice what is NOT here: no key, no base URL, no mode check, no retry loop,
|
|
96
|
+
* no fake/real branch. This describes the request; callConnector resolves the
|
|
97
|
+
* connection, picks the estate, and either calls Google Analytics or calls the
|
|
98
|
+
* faker.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
declare const REPORT_RUN_OPERATION = "report_run";
|
|
102
|
+
type ReportRunOptions = {
|
|
103
|
+
/** The node's resolved config. Keys: property, startDate, endDate, metrics, dimensions. */
|
|
104
|
+
config: Record<string, unknown>;
|
|
105
|
+
credentials?: Record<string, string | undefined>;
|
|
106
|
+
mode?: RequestedMode;
|
|
107
|
+
connectionId?: string | null;
|
|
108
|
+
input?: unknown;
|
|
109
|
+
attempts?: number;
|
|
110
|
+
/** Override the transport. The only way to exercise this without a network. */
|
|
111
|
+
transport?: Transport;
|
|
112
|
+
};
|
|
113
|
+
declare function googleAnalyticsReportRun(options: ReportRunOptions): Promise<ConnectorResult>;
|
|
114
|
+
|
|
115
|
+
export { CONNECTOR_API_VERSION, GOOGLE_ANALYTICS, GOOGLE_ANALYTICS_BASE_URLS, GOOGLE_ANALYTICS_REQUIRES, REPORT_RUN_OPERATION, type ReportRunOptions, googleAnalyticsAuthorize, googleAnalyticsFaker, googleAnalyticsReportRun };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { CONNECTOR_API_VERSION, GOOGLE_ANALYTICS, GOOGLE_ANALYTICS_BASE_URLS, GOOGLE_ANALYTICS_REQUIRES, REPORT_RUN_OPERATION, googleAnalyticsAuthorize, googleAnalyticsFaker, googleAnalyticsReportRun } from './chunk-NY2RRZPH.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@particle-academy/google-analytics-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Google Analytics for Node — the service descriptor, its faker, its webhook verification, and one function per operation. Plain HTTP on @particle-academy/fancy-connector-core; no vendor SDK.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Fancy-Friends/google-analytics.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/Fancy-Friends/google-analytics#readme",
|
|
10
|
+
"bugs": "https://github.com/Fancy-Friends/google-analytics/issues",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./flow": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/flow.d.ts",
|
|
29
|
+
"default": "./dist/flow.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/flow.d.cts",
|
|
33
|
+
"default": "./dist/flow.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"lint": "tsc --noEmit",
|
|
47
|
+
"test": "node --import tsx --test tests/*.test.ts",
|
|
48
|
+
"prepublishOnly": "tsup"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@particle-academy/fancy-connector-core": ">=0.3.1 <2.0",
|
|
52
|
+
"@particle-academy/google-analytics-ui": "0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@particle-academy/fancy-flow": ">=0.47.1 <2.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"@particle-academy/fancy-flow": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@particle-academy/fancy-flow": ">=0.47.1 <2.0",
|
|
64
|
+
"@types/node": "^26.2.0",
|
|
65
|
+
"tsup": "^8.5.0",
|
|
66
|
+
"tsx": "^4.19.0",
|
|
67
|
+
"typescript": "^5.8.0"
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"keywords": [
|
|
73
|
+
"google_analytics",
|
|
74
|
+
"analytics",
|
|
75
|
+
"connector",
|
|
76
|
+
"api",
|
|
77
|
+
"fancy-ui",
|
|
78
|
+
"particle-academy"
|
|
79
|
+
],
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"sideEffects": false,
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=22"
|
|
84
|
+
}
|
|
85
|
+
}
|