@scaletrail/connector 0.0.0-stage → 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 +16 -0
- package/LICENSE +21 -0
- package/README.md +151 -2
- package/examples/customer-redact.json +9 -0
- package/examples/event-add-to-cart.json +17 -0
- package/examples/event-login-identity.json +13 -0
- package/examples/order-marketplace.json +21 -0
- package/examples/order-migrated-update.json +22 -0
- package/examples/order-subscription-renewal.json +44 -0
- package/examples/order-web-paid.json +73 -0
- package/examples/order-web-refund-partial.json +154 -0
- package/package.json +43 -4
- package/src/client.js +143 -0
- package/src/cookies.js +251 -0
- package/src/index.d.ts +109 -0
- package/src/index.js +18 -0
- package/src/schema.js +1110 -0
- package/src/signature.js +123 -0
- package/src/types.d.ts +256 -0
- package/src/types.js +2 -0
- package/src/uuid.js +38 -0
- package/src/validate.js +154 -0
- package/src/version.js +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unveröffentlicht)
|
|
4
|
+
|
|
5
|
+
Erste Version.
|
|
6
|
+
|
|
7
|
+
- `createClient()` mit `sendOrder`, `sendEvent`, `sendRedact`, Testmodus `dryRun`, Einteilung jeder Antwort in
|
|
8
|
+
`accepted`, `valid`, `rejected`, `retry`; `retryDelaySeconds()` für die Pausen.
|
|
9
|
+
- `signRequest()`, `computeSignature()`, `verifySignature()`.
|
|
10
|
+
- `edgeCookies()`, `applyEdgeCookies()`, `readAttribution()`: Spiegel der Besucher-ID, Klick-ID- und UTM-Cookies,
|
|
11
|
+
Domain-Ableitung mit Einstellung für Test-Umgebungen, Modus `after_consent`.
|
|
12
|
+
- `validateMessage()` und je Botschaft eine Funktion, Schema-Version `1.0.0-draft.6` (09.11.2026: `updated_at` mit
|
|
13
|
+
3 bis 6 Nachkommastellen Pflicht).
|
|
14
|
+
- `uuidV7()`, `isVisitorId()`.
|
|
15
|
+
- Typen für alle Botschaften der Schnittstelle.
|
|
16
|
+
- Beispieldaten unter `examples/` (acht Botschaften) für die Tests der eigenen Anbindung.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Upfold KLG
|
|
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
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @scaletrail/connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bindet einen selbst gebauten Shop an ScaleTrail an. Das Paket übernimmt den Transport: signierte Schnappschüsse
|
|
4
|
+
von Bestellungen, die Cookies am Server des Shops und die Prüfung gegen das Schema der Schnittstelle.
|
|
5
|
+
|
|
6
|
+
- ohne Abhängigkeiten, nur Web-Standards (`fetch`, Web Crypto)
|
|
7
|
+
- läuft in Cloudflare Workers, Node.js ab 20, Deno und Bun
|
|
8
|
+
- Typen für TypeScript inklusive
|
|
9
|
+
|
|
10
|
+
> **Version 0.x:** Die Schnittstelle ist noch ein Entwurf. Bis 1.0 kann sich zwischen Minor-Versionen etwas ändern;
|
|
11
|
+
> jede Änderung steht im [CHANGELOG](CHANGELOG.md).
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @scaletrail/connector
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Zugang
|
|
18
|
+
|
|
19
|
+
ScaleTrail gibt je Shop eine **Schlüssel-ID** (`ck_…`) und ein **Signing-Secret** aus. Beides gehört auf den Server
|
|
20
|
+
des Shops, als Secret der Umgebung, nie in den Quelltext und nie in den Browser. Die Signatur verweigert den Dienst,
|
|
21
|
+
wenn sie in einem Browser läuft.
|
|
22
|
+
|
|
23
|
+
## Bestellungen senden
|
|
24
|
+
|
|
25
|
+
Bei **jeder** Änderung einer Bestellung den **vollständigen** Stand senden: angelegt, bezahlt, Status gewechselt,
|
|
26
|
+
bearbeitet, erstattet, Sendung angelegt.
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { createClient } from '@scaletrail/connector';
|
|
30
|
+
|
|
31
|
+
const scaletrail = createClient({
|
|
32
|
+
keyId: env.SCALETRAIL_KEY_ID,
|
|
33
|
+
secret: env.SCALETRAIL_SECRET,
|
|
34
|
+
connector: 'mein-shop/2.3.0', // Name und Version deiner Anbindung
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const result = await scaletrail.sendOrder(order);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`result.outcome` sagt, was zu tun ist:
|
|
41
|
+
|
|
42
|
+
| `outcome` | Bedeutung | Was der Shop tut |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `accepted` | angenommen (`requestId`) | Übergabe als erledigt markieren |
|
|
45
|
+
| `valid` | nur bei `{ dryRun: true }`: Form gültig, nichts gespeichert | nichts |
|
|
46
|
+
| `rejected` | ungültig (`paths` nennt die Felder), Zugang falsch oder Body zu gross | **nicht** wiederholen, Alarm |
|
|
47
|
+
| `retry` | vorübergehend: Netz, Timeout, Überlast, Wartung | später wiederholen |
|
|
48
|
+
|
|
49
|
+
Wiederholen ist immer sicher. Derselbe Stand zweimal ändert nichts. Die Pausen dafür:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { retryDelaySeconds } from '@scaletrail/connector';
|
|
53
|
+
|
|
54
|
+
// attempt = Anzahl Versuche bisher; null heisst: aufgeben und Alarm (nach 72 Stunden)
|
|
55
|
+
const wait = retryDelaySeconds(attempt, { retryAfterSeconds: result.retryAfterSeconds, firstAttemptAt });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Empfohlen: jede Übergabe als Zeile mit Status in der eigenen Datenbank, ein Cron holt nach. Nie in der Kasse auf
|
|
59
|
+
ScaleTrail warten.
|
|
60
|
+
|
|
61
|
+
Ebenso: `sendEvent(event)` für `add_to_cart` und `login_identity`, `sendRedact(redact)`, wenn eine Kundin im Shop
|
|
62
|
+
anonymisiert wird.
|
|
63
|
+
|
|
64
|
+
## Cookies am Server des Shops
|
|
65
|
+
|
|
66
|
+
Der Server des Shops setzt bei **jeder** Antwort den Spiegel der Besucher-ID `_sa_uid_shop` und bei einer Landung mit
|
|
67
|
+
Klick-ID oder UTM je Parameter ein Cookie `__sa_<parameter>`. Weil die Antwort vom Shop selbst kommt, behält der
|
|
68
|
+
Browser diese Cookies bis zu 400 Tage. Jeder Wert wird geprüft; ein ungültiger ergibt kein Cookie.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { edgeCookies, applyEdgeCookies } from '@scaletrail/connector';
|
|
72
|
+
|
|
73
|
+
export default {
|
|
74
|
+
async fetch(request, env, ctx) {
|
|
75
|
+
const cookies = edgeCookies(request); // bei jeder Anfrage, vor dem Cache
|
|
76
|
+
const page = await renderOrFromCache(request); // die gecachte Seite bleibt ohne Set-Cookie
|
|
77
|
+
return applyEdgeCookies(page, cookies); // Cookies an die Antwort, Cache-Control: private
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Wichtig bei Seiten aus dem Cache:
|
|
83
|
+
- `edgeCookies()` läuft in der Stufe, die **jede** Anfrage sieht, nicht in der gecachten.
|
|
84
|
+
- Die Cookies kommen an die Antwort an den Browser, **nie** an den gespeicherten Eintrag.
|
|
85
|
+
- Der Cache-Schlüssel bleibt ohne Klick-IDs und UTM-Parameter.
|
|
86
|
+
|
|
87
|
+
Optionen:
|
|
88
|
+
|
|
89
|
+
| Option | Standard | Bedeutung |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `cookieDomain` | registrierbare Domain des Shops | für Test-Umgebungen, z.B. `'staging.mein-shop.ch'`: die Cookies gelten dann nur dort. Gilt nur, wenn es der Host selbst oder eine seiner Elterndomains ist |
|
|
92
|
+
| `mode` | `'always'` | `'after_consent'`: Klick-ID- und UTM-Cookies nur mit `marketingConsent: true` |
|
|
93
|
+
| `marketingConsent` | `null` | Stand der Einwilligung, nur für `after_consent` |
|
|
94
|
+
|
|
95
|
+
Den Namen `_sa_uid` schreibt der Shop nie selbst; den setzt ScaleTrail.
|
|
96
|
+
|
|
97
|
+
## Herkunft an Warenkorb und Bestellung
|
|
98
|
+
|
|
99
|
+
Beim Anlegen des Warenkorbs die Werte aus den Cookies lesen und speichern, bei der Bestellung in `attribution`
|
|
100
|
+
übernehmen, **vor** der Zahlung:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { readAttribution } from '@scaletrail/connector';
|
|
104
|
+
|
|
105
|
+
const attribution = {
|
|
106
|
+
...readAttribution(request.headers.get('Cookie')), // sa_uid, click_ids, utm, browser_ids
|
|
107
|
+
landing_url, referrer, captured_at, // aus der eigenen Sitzung
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Prüfen gegen das Schema
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import { validateOrderMessage } from '@scaletrail/connector';
|
|
115
|
+
|
|
116
|
+
const paths = validateOrderMessage({ order }); // [] = gültig, sonst z.B. ['order.items[0].quantity']
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Standard ist streng: ein unbekanntes Feld ist ein Fehler, damit nichts gesendet wird, was nicht verarbeitet wird.
|
|
120
|
+
`{ strict: false }` ignoriert unbekannte Felder. Für Tests der eigenen Anbindung: `sendOrder(order, { dryRun: true })`
|
|
121
|
+
prüft Zugang und Form bei ScaleTrail, ohne etwas zu speichern.
|
|
122
|
+
|
|
123
|
+
**Beispieldaten** für die eigenen Tests liegen im Paket unter `examples/`: bezahlte Bestellung, Teilerstattung,
|
|
124
|
+
Abo-Verlängerung, Marktplatz, übernommene Altbestellung, `add_to_cart`, `login_identity`, Anonymisierung. Es sind
|
|
125
|
+
dieselben, gegen die ScaleTrail prüft. Ein guter Test baut aus den eigenen Testdaten einen Schnappschuss und vergleicht
|
|
126
|
+
ihn feldweise mit dem passenden Beispiel.
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import { readFile } from 'node:fs/promises';
|
|
130
|
+
import { createRequire } from 'node:module';
|
|
131
|
+
|
|
132
|
+
const file = createRequire(import.meta.url).resolve('@scaletrail/connector/examples/order-web-paid.json');
|
|
133
|
+
const example = JSON.parse(await readFile(file, 'utf8'));
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Signatur ohne Client
|
|
137
|
+
|
|
138
|
+
Wer einen eigenen HTTP-Client nutzt:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import { signRequest } from '@scaletrail/connector';
|
|
142
|
+
|
|
143
|
+
const body = JSON.stringify({ order });
|
|
144
|
+
const headers = await signRequest({ keyId, secret, body, connector: 'mein-shop/2.3.0' });
|
|
145
|
+
await fetch('https://api.scaletrail.io/connect/v1/orders', { method: 'POST', headers, body, redirect: 'manual' });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Signiert wird der Body Byte für Byte so, wie er gesendet wird: nach dem Signieren nicht neu serialisieren.
|
|
149
|
+
|
|
150
|
+
## Lizenz
|
|
151
|
+
|
|
152
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"event": {
|
|
3
|
+
"type": "add_to_cart",
|
|
4
|
+
"event_id": "0192f3b0-1a2b-7c3d-8e4f-5a6b7c8d9e0f",
|
|
5
|
+
"occurred_at": "2026-12-03T09:38:47.211+01:00",
|
|
6
|
+
"sa_uid": "0192f3a4-5b6c-7d8e-9f01-23456789abcd",
|
|
7
|
+
"product_id": "4711",
|
|
8
|
+
"variant_id": null,
|
|
9
|
+
"sku": "1020",
|
|
10
|
+
"name": "Beispiel Serum 50 ml",
|
|
11
|
+
"quantity": 1,
|
|
12
|
+
"unit_price_cents": 4990,
|
|
13
|
+
"currency": "CHF",
|
|
14
|
+
"page_url": "https://www.example.ch/produkt/beispiel-serum/",
|
|
15
|
+
"client": { "ip": "203.0.113.24", "user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 26_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Mobile/15E148 Safari/604.1" }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"event": {
|
|
3
|
+
"type": "login_identity",
|
|
4
|
+
"event_id": "login_c-58210_2026-12-03",
|
|
5
|
+
"occurred_at": "2026-12-03T09:36:02.000+01:00",
|
|
6
|
+
"sa_uid": "0192f3a4-5b6c-7d8e-9f01-23456789abcd",
|
|
7
|
+
"customer_id": "c-58210",
|
|
8
|
+
"email": "beispiel.kundin@example.ch",
|
|
9
|
+
"phone": "+41791234567",
|
|
10
|
+
"first_name": "Anna",
|
|
11
|
+
"last_name": "Muster"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"order": {
|
|
3
|
+
"schema_version": "1",
|
|
4
|
+
"order_id": "1000401",
|
|
5
|
+
"order_number": "GX-55120931",
|
|
6
|
+
"created_at": "2027-01-06T11:12:00.000+01:00",
|
|
7
|
+
"updated_at": "2027-01-06T11:12:01.010+01:00",
|
|
8
|
+
"paid_at": "2027-01-06T11:12:00.000+01:00",
|
|
9
|
+
"status": "processing",
|
|
10
|
+
"sales_channel": "galaxus",
|
|
11
|
+
"is_test": false,
|
|
12
|
+
"currency": "CHF",
|
|
13
|
+
"totals": { "total_cents": 4290, "tax_cents": 321, "taxes_included": true },
|
|
14
|
+
"items": [
|
|
15
|
+
{ "line_id": "l1", "product_id": "4712", "sku": "1031", "name": "Beispiel Shampoo 200 ml", "quantity": 1, "unit_price_cents": 4290, "line_total_cents": 4290, "unit_cost_cents": 380 }
|
|
16
|
+
],
|
|
17
|
+
"payments": [{ "gateway_id": "galaxus", "amount_cents": 4290 }],
|
|
18
|
+
"customer": { "customer_id": "c-90311", "is_guest": true, "email": "marktplatz.kundin@example.ch" },
|
|
19
|
+
"attribution": null
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"order": {
|
|
3
|
+
"schema_version": "1",
|
|
4
|
+
"order_id": "111842",
|
|
5
|
+
"origin": "migrated",
|
|
6
|
+
"created_at": "2026-10-28T19:05:44.000+01:00",
|
|
7
|
+
"updated_at": "2027-01-08T10:30:02.120+01:00",
|
|
8
|
+
"paid_at": "2026-10-28T19:06:10.000+01:00",
|
|
9
|
+
"status": "refunded",
|
|
10
|
+
"sales_channel": "web",
|
|
11
|
+
"is_test": false,
|
|
12
|
+
"currency": "CHF",
|
|
13
|
+
"totals": { "total_cents": 6480, "taxes_included": true },
|
|
14
|
+
"items": [
|
|
15
|
+
{ "line_id": "w-90021", "product_id": "4713", "sku": "Y1003", "name": "Beispiel Wimpernserum", "quantity": 1, "unit_price_cents": 6480, "line_total_cents": 6480 }
|
|
16
|
+
],
|
|
17
|
+
"refunds": [
|
|
18
|
+
{ "refund_id": "w-r-1201", "created_at": "2027-01-08T10:30:00.000+01:00", "amount_cents": 6480, "reason": "Rücksendung" }
|
|
19
|
+
],
|
|
20
|
+
"customer": { "customer_id": "c-33018", "email": "alt.kundin@example.ch" }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"order": {
|
|
3
|
+
"schema_version": "1",
|
|
4
|
+
"order_id": "1000377",
|
|
5
|
+
"created_at": "2027-01-05T03:00:12.000+01:00",
|
|
6
|
+
"updated_at": "2027-01-05T03:00:14.551+01:00",
|
|
7
|
+
"paid_at": "2027-01-05T03:00:13.000+01:00",
|
|
8
|
+
"status": "processing",
|
|
9
|
+
"sales_channel": "web",
|
|
10
|
+
"is_test": false,
|
|
11
|
+
"currency": "CHF",
|
|
12
|
+
"language": "fr",
|
|
13
|
+
"totals": { "total_cents": 5490, "shipping_cents": 0, "tax_cents": 411, "taxes_included": true },
|
|
14
|
+
"items": [
|
|
15
|
+
{
|
|
16
|
+
"line_id": "l1",
|
|
17
|
+
"product_id": "4711",
|
|
18
|
+
"sku": "1020",
|
|
19
|
+
"name": "Sérum exemple 50 ml",
|
|
20
|
+
"quantity": 1,
|
|
21
|
+
"unit_price_cents": 5490,
|
|
22
|
+
"line_total_cents": 5490,
|
|
23
|
+
"tax_rate": 8.1,
|
|
24
|
+
"unit_cost_cents": 610,
|
|
25
|
+
"is_subscription": true
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"payments": [
|
|
29
|
+
{ "gateway_id": "stripe_card", "method": "Carte de crédit", "amount_cents": 5490, "fee_cents": 112, "fee_source": "provider", "status": "captured" }
|
|
30
|
+
],
|
|
31
|
+
"subscription": {
|
|
32
|
+
"subscription_id": "sub-2291",
|
|
33
|
+
"is_renewal": true,
|
|
34
|
+
"renewal_number": 4,
|
|
35
|
+
"status": "active",
|
|
36
|
+
"interval": "P2M",
|
|
37
|
+
"started_at": "2026-05-05T11:20:00.000+02:00"
|
|
38
|
+
},
|
|
39
|
+
"customer": { "customer_id": "c-41007", "email": "client.exemple@example.ch", "order_count": 5 },
|
|
40
|
+
"attribution": null,
|
|
41
|
+
"client": null,
|
|
42
|
+
"consent": null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"order": {
|
|
3
|
+
"schema_version": "1",
|
|
4
|
+
"order_id": "1000123",
|
|
5
|
+
"origin": "native",
|
|
6
|
+
"created_at": "2026-12-03T09:41:12.000+01:00",
|
|
7
|
+
"updated_at": "2026-12-03T09:42:05.318+01:00",
|
|
8
|
+
"paid_at": "2026-12-03T09:42:03.000+01:00",
|
|
9
|
+
"status": "processing",
|
|
10
|
+
"sales_channel": "web",
|
|
11
|
+
"is_test": false,
|
|
12
|
+
"currency": "CHF",
|
|
13
|
+
"language": "de",
|
|
14
|
+
"totals": {
|
|
15
|
+
"total_cents": 9770,
|
|
16
|
+
"subtotal_cents": 8980,
|
|
17
|
+
"shipping_cents": 790,
|
|
18
|
+
"discount_cents": 1000,
|
|
19
|
+
"tax_cents": 732,
|
|
20
|
+
"taxes_included": true,
|
|
21
|
+
"tax_lines": [{ "rate": 8.1, "base_cents": 9038, "tax_cents": 732 }]
|
|
22
|
+
},
|
|
23
|
+
"items": [
|
|
24
|
+
{
|
|
25
|
+
"line_id": "l1",
|
|
26
|
+
"product_id": "4711",
|
|
27
|
+
"variant_id": null,
|
|
28
|
+
"sku": "1020",
|
|
29
|
+
"name": "Beispiel Serum 50 ml",
|
|
30
|
+
"quantity": 2,
|
|
31
|
+
"unit_price_cents": 4490,
|
|
32
|
+
"line_total_cents": 8980,
|
|
33
|
+
"line_discount_cents": 1000,
|
|
34
|
+
"tax_rate": 8.1,
|
|
35
|
+
"unit_cost_cents": 610,
|
|
36
|
+
"category": "Haar",
|
|
37
|
+
"is_subscription": false
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"discounts": [
|
|
41
|
+
{ "source": "rule", "amount_cents": 1000, "rule_id": "mengenpreis-2", "label": "Mengenpreis ab 2", "line_ids": ["l1"] }
|
|
42
|
+
],
|
|
43
|
+
"payments": [
|
|
44
|
+
{ "gateway_id": "saferpay_twint", "method": "TWINT", "amount_cents": 9770, "fee_cents": null, "fee_source": null, "status": "captured", "captured_at": "2026-12-03T09:42:03.000+01:00" }
|
|
45
|
+
],
|
|
46
|
+
"shipments": [],
|
|
47
|
+
"refunds": [],
|
|
48
|
+
"subscription": null,
|
|
49
|
+
"customer": {
|
|
50
|
+
"customer_id": "c-58210",
|
|
51
|
+
"is_guest": false,
|
|
52
|
+
"email": "beispiel.kundin@example.ch",
|
|
53
|
+
"phone": "+41791234567",
|
|
54
|
+
"first_name": "Anna",
|
|
55
|
+
"last_name": "Muster",
|
|
56
|
+
"order_count": 3,
|
|
57
|
+
"first_order_at": "2025-04-17T18:03:00.000+02:00"
|
|
58
|
+
},
|
|
59
|
+
"billing_address": { "street": "Musterweg 1", "postcode": "6343", "city": "Rotkreuz", "region": "ZG", "country": "CH" },
|
|
60
|
+
"shipping_address": { "street": "Musterweg 1", "postcode": "6343", "city": "Rotkreuz", "region": "ZG", "country": "CH" },
|
|
61
|
+
"attribution": {
|
|
62
|
+
"sa_uid": "0192f3a4-5b6c-7d8e-9f01-23456789abcd",
|
|
63
|
+
"click_ids": { "gclid": "Cj0KCQiA_beispiel_gclid_0123456789", "fbclid": null },
|
|
64
|
+
"utm": { "source": "google", "medium": "cpc", "campaign": "pmax-haar", "content": null, "term": null, "id": "21987654321" },
|
|
65
|
+
"landing_url": "https://www.example.ch/produkt/beispiel-serum/?gclid=Cj0KCQiA_beispiel_gclid_0123456789",
|
|
66
|
+
"referrer": "https://www.google.com/",
|
|
67
|
+
"browser_ids": { "ga": "GA1.1.123456789.1764750000", "fbp": "fb.1.1764750000000.1234567890", "fbc": null, "ttp": null },
|
|
68
|
+
"captured_at": "2026-11-28T20:15:44.000+01:00"
|
|
69
|
+
},
|
|
70
|
+
"client": { "ip": "203.0.113.24", "user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 26_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Mobile/15E148 Safari/604.1" },
|
|
71
|
+
"consent": { "source": "cookiebot", "statistics": true, "marketing": true, "captured_at": "2026-12-03T09:40:58.000+01:00" }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
{
|
|
2
|
+
"order": {
|
|
3
|
+
"schema_version": "1",
|
|
4
|
+
"order_id": "1000123",
|
|
5
|
+
"origin": "native",
|
|
6
|
+
"created_at": "2026-12-03T09:41:12.000+01:00",
|
|
7
|
+
"updated_at": "2026-12-09T14:02:51.904+01:00",
|
|
8
|
+
"paid_at": "2026-12-03T09:42:03.000+01:00",
|
|
9
|
+
"status": "completed",
|
|
10
|
+
"sales_channel": "web",
|
|
11
|
+
"is_test": false,
|
|
12
|
+
"currency": "CHF",
|
|
13
|
+
"language": "de",
|
|
14
|
+
"totals": {
|
|
15
|
+
"total_cents": 9770,
|
|
16
|
+
"subtotal_cents": 8980,
|
|
17
|
+
"shipping_cents": 790,
|
|
18
|
+
"discount_cents": 1000,
|
|
19
|
+
"tax_cents": 732,
|
|
20
|
+
"taxes_included": true,
|
|
21
|
+
"tax_lines": [
|
|
22
|
+
{
|
|
23
|
+
"rate": 8.1,
|
|
24
|
+
"base_cents": 9038,
|
|
25
|
+
"tax_cents": 732
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"items": [
|
|
30
|
+
{
|
|
31
|
+
"line_id": "l1",
|
|
32
|
+
"product_id": "4711",
|
|
33
|
+
"variant_id": null,
|
|
34
|
+
"sku": "1020",
|
|
35
|
+
"name": "Beispiel Serum 50 ml",
|
|
36
|
+
"quantity": 2,
|
|
37
|
+
"unit_price_cents": 4490,
|
|
38
|
+
"line_total_cents": 8980,
|
|
39
|
+
"line_discount_cents": 1000,
|
|
40
|
+
"tax_rate": 8.1,
|
|
41
|
+
"unit_cost_cents": 610,
|
|
42
|
+
"category": "Haar",
|
|
43
|
+
"is_subscription": false
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"discounts": [
|
|
47
|
+
{
|
|
48
|
+
"source": "rule",
|
|
49
|
+
"amount_cents": 1000,
|
|
50
|
+
"rule_id": "mengenpreis-2",
|
|
51
|
+
"label": "Mengenpreis ab 2",
|
|
52
|
+
"line_ids": [
|
|
53
|
+
"l1"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"payments": [
|
|
58
|
+
{
|
|
59
|
+
"gateway_id": "saferpay_twint",
|
|
60
|
+
"method": "TWINT",
|
|
61
|
+
"amount_cents": 9770,
|
|
62
|
+
"fee_cents": null,
|
|
63
|
+
"fee_source": null,
|
|
64
|
+
"status": "captured",
|
|
65
|
+
"captured_at": "2026-12-03T09:42:03.000+01:00"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"shipments": [
|
|
69
|
+
{
|
|
70
|
+
"shipment_id": "s-1000123-1",
|
|
71
|
+
"method": "post_a_post",
|
|
72
|
+
"postage_cents": 700,
|
|
73
|
+
"weight_grams": 180,
|
|
74
|
+
"created_at": "2026-12-03T15:10:00.000+01:00"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"refunds": [
|
|
78
|
+
{
|
|
79
|
+
"refund_id": "r-88",
|
|
80
|
+
"created_at": "2026-12-09T14:02:50.000+01:00",
|
|
81
|
+
"amount_cents": 4490,
|
|
82
|
+
"tax_cents": 336,
|
|
83
|
+
"shipping_cents": 0,
|
|
84
|
+
"reason": "Rückgabe eine Flasche",
|
|
85
|
+
"items": [
|
|
86
|
+
{
|
|
87
|
+
"line_id": "l1",
|
|
88
|
+
"quantity": 1,
|
|
89
|
+
"amount_cents": 4490
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"subscription": null,
|
|
95
|
+
"customer": {
|
|
96
|
+
"customer_id": "c-58210",
|
|
97
|
+
"is_guest": false,
|
|
98
|
+
"email": "beispiel.kundin@example.ch",
|
|
99
|
+
"phone": "+41791234567",
|
|
100
|
+
"first_name": "Anna",
|
|
101
|
+
"last_name": "Muster",
|
|
102
|
+
"order_count": 3,
|
|
103
|
+
"first_order_at": "2025-04-17T18:03:00.000+02:00"
|
|
104
|
+
},
|
|
105
|
+
"billing_address": {
|
|
106
|
+
"street": "Musterweg 1",
|
|
107
|
+
"postcode": "6343",
|
|
108
|
+
"city": "Rotkreuz",
|
|
109
|
+
"region": "ZG",
|
|
110
|
+
"country": "CH"
|
|
111
|
+
},
|
|
112
|
+
"shipping_address": {
|
|
113
|
+
"street": "Musterweg 1",
|
|
114
|
+
"postcode": "6343",
|
|
115
|
+
"city": "Rotkreuz",
|
|
116
|
+
"region": "ZG",
|
|
117
|
+
"country": "CH"
|
|
118
|
+
},
|
|
119
|
+
"attribution": {
|
|
120
|
+
"sa_uid": "0192f3a4-5b6c-7d8e-9f01-23456789abcd",
|
|
121
|
+
"click_ids": {
|
|
122
|
+
"gclid": "Cj0KCQiA_beispiel_gclid_0123456789",
|
|
123
|
+
"fbclid": null
|
|
124
|
+
},
|
|
125
|
+
"utm": {
|
|
126
|
+
"source": "google",
|
|
127
|
+
"medium": "cpc",
|
|
128
|
+
"campaign": "pmax-haar",
|
|
129
|
+
"content": null,
|
|
130
|
+
"term": null,
|
|
131
|
+
"id": "21987654321"
|
|
132
|
+
},
|
|
133
|
+
"landing_url": "https://www.example.ch/produkt/beispiel-serum/?gclid=Cj0KCQiA_beispiel_gclid_0123456789",
|
|
134
|
+
"referrer": "https://www.google.com/",
|
|
135
|
+
"browser_ids": {
|
|
136
|
+
"ga": "GA1.1.123456789.1764750000",
|
|
137
|
+
"fbp": "fb.1.1764750000000.1234567890",
|
|
138
|
+
"fbc": null,
|
|
139
|
+
"ttp": null
|
|
140
|
+
},
|
|
141
|
+
"captured_at": "2026-11-28T20:15:44.000+01:00"
|
|
142
|
+
},
|
|
143
|
+
"client": {
|
|
144
|
+
"ip": "203.0.113.24",
|
|
145
|
+
"user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 26_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Mobile/15E148 Safari/604.1"
|
|
146
|
+
},
|
|
147
|
+
"consent": {
|
|
148
|
+
"source": "cookiebot",
|
|
149
|
+
"statistics": true,
|
|
150
|
+
"marketing": true,
|
|
151
|
+
"captured_at": "2026-12-03T09:40:58.000+01:00"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaletrail/connector",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect a custom-built shop to ScaleTrail: signed order snapshots, edge cookies, schema validation.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://scaletrail.io",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/upfold-ch/upfold-scaletrail.git",
|
|
10
|
+
"directory": "packages/connector"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./src/index.d.ts",
|
|
16
|
+
"default": "./src/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./examples/*": "./examples/*",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"types": "./src/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"src/",
|
|
24
|
+
"examples/",
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"scaletrail",
|
|
35
|
+
"attribution",
|
|
36
|
+
"ecommerce",
|
|
37
|
+
"cloudflare-workers"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "node --test \"test/*.test.js\""
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|