@crvouga/mockingbird-service-customerio 2.1.0 → 2.2.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 +12 -4
- package/README.md +5 -1
- package/SUPPORT.md +5 -3
- package/dist/{chunk-53O3NJZ5.js → chunk-NL7M7QLP.js} +2 -2
- package/dist/{chunk-LFEHF77A.js → chunk-XGFF36NR.js} +146 -9
- package/dist/chunk-XGFF36NR.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +18 -5
- package/dist/index.js +1 -1
- package/dist/server.d.ts +13 -0
- package/dist/server.js +2 -2
- package/openapi.yaml +80 -0
- package/package.json +1 -1
- package/dist/chunk-LFEHF77A.js.map +0 -7
- /package/dist/{chunk-53O3NJZ5.js.map → chunk-NL7M7QLP.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog — @crvouga/mockingbird-service-customerio
|
|
2
2
|
|
|
3
|
+
## 2.2.0 (2026-10-05)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- add scripted local API mock ([4a76a11](https://github.com/crvouga/mockingbird/commit/4a76a114e2efad45934e0a93cf29576fd418e15c))
|
|
8
|
+
- reconcile sender opt-outs ([43b7c8e](https://github.com/crvouga/mockingbird/commit/43b7c8e55ff8de7d15efe4db55beda80f01bcbd0))
|
|
9
|
+
|
|
10
|
+
### Fixes and improvements
|
|
11
|
+
|
|
12
|
+
- support embedded route parameters ([127cad9](https://github.com/crvouga/mockingbird/commit/127cad997ef106950c1b866070eea191ba54403f))
|
|
13
|
+
- preserve namespace URLs after main sync ([62a15ce](https://github.com/crvouga/mockingbird/commit/62a15ce9bd453069bde69e3a30c91efc01f8871b))
|
|
14
|
+
|
|
3
15
|
## 2.1.0 (2026-10-04)
|
|
4
16
|
|
|
5
17
|
### Features
|
|
@@ -12,10 +24,6 @@
|
|
|
12
24
|
- fill the embedded viewport ([c1a35a4](https://github.com/crvouga/mockingbird/commit/c1a35a4789389ee9cd06c286d09bd47c4d06c71e))
|
|
13
25
|
- make dialog cleanup immediate ([0c1a3c5](https://github.com/crvouga/mockingbird/commit/0c1a3c5b12584d50c19dcae595b951b8e5417b9c))
|
|
14
26
|
|
|
15
|
-
### Dependencies
|
|
16
|
-
|
|
17
|
-
- `@crvouga/mockingbird-service-sqlite`
|
|
18
|
-
|
|
19
27
|
## 2.0.0 (2026-10-04)
|
|
20
28
|
|
|
21
29
|
### ⚠️ Breaking changes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Stateful mock of **Customer.io** for test suites, serving all three hosts our code talks to from
|
|
6
6
|
one process: the Segment-compatible **CDP** (`identify`, `track`, `batch`, exactly as
|
|
7
7
|
`@customerio/cdp-analytics-node` posts them), the **App API** transactional sends (email, SMS,
|
|
8
|
-
inbox message), message catalog, profile attribute reads, and delivery-status reads, and the
|
|
8
|
+
inbox message), message catalog, profile attribute reads, sender opt-out reconciliation, and delivery-status reads, and the
|
|
9
9
|
**link-tracking** click endpoint. Sends land in an outbox a suite asserts on (and reads links out
|
|
10
10
|
of); reporting events (`unsubscribed`, `subscribed`, `spammed`, subscription preferences,
|
|
11
11
|
`clicked`) are posted to our reporting webhook, signed the way Customer.io signs them.
|
|
@@ -81,6 +81,8 @@ await cio.close()
|
|
|
81
81
|
| `GET /v1/transactional` | `{messages: [{id, name, trigger_name, description, send_to_unsubscribed, link_tracking, …}]}`, no pagination (the whole catalog, including hundreds of rows). Seeded with `acme_<key>` for every legacy email key the consumer app has, plus `acme_inbox_message` and `acme_playground_notification` (ids 1–21). `transactionalListKey: "transactional"` renames the array key. |
|
|
82
82
|
| `GET /v1/transactional/{id}` | `{message: {...}}` by id or trigger name (case-insensitive), or 404. |
|
|
83
83
|
| `GET /v1/customers/{customer_id}/attributes?id_type=id\|email\|cio_id` | `{customer: {identifiers: {id, email?, cio_id}, attributes, devices}}`. Unknown `id_type` is 400; an unknown customer is 404. Attributes spread stored traits, then `id`, `cio_id`, `email`, and `unsubscribed` win. |
|
|
84
|
+
| `GET /v1/optouts?limit=&start=&from=` | Workspace sender opt-outs as `{optouts: [{customer_id, cio_id, optouts: [{channel, from}]}], next?}`. `limit` defaults to 100 (1–1000); follow `next` using `start` until it is absent. `from` filters sender/channel entries, omitting people with no matches. Sender values are trimmed and lowercased; E.164 numbers retain their form. |
|
|
85
|
+
| `GET /v1/customers/{customer_id}/optouts?id_type=id\|email\|cio_id` | `{optouts: [{channel, from}]}` for an existing profile, empty if none, 404 for unknown people. Uses the same identity state as CDP identify and profile updates. App API authentication applies to both reads. |
|
|
84
86
|
| `GET /v1/messages/{delivery_id}` | `{message: {id, type, recipient, customer_id, created, state, status, metrics}}`. `type` is `in_app` for inbox. No `message_data`. 404 when the id is missing or still inside `statusVisibleAfterMs`. Failure states add `failure_message`, `rejection_reason`, and `error`. |
|
|
85
87
|
| `POST /click/{linkId}` | Our backend's click report (unauthenticated) → 200, counts the click and posts a `clicked` reporting event. Unknown link: plain-text 404. |
|
|
86
88
|
| `GET /click/{linkId}` | A browser following a tracked link → 302 to the original URL. |
|
|
@@ -103,6 +105,7 @@ is the JSON string of subscription preferences. `timestamp` never runs ahead of
|
|
|
103
105
|
| `POST /__admin/reporting-events` | `{metric, userId? \| email? \| deliveryId?, objectType?, preferences?: {topics?, channels?}}`: apply it to the profile (`unsubscribed`, `subscribed`, `spammed`, `cio_subscription_preferences_changed`) and post the signed event. Any other metric (`delivered`, `opened`, `bounced`, …) is posted as-is. |
|
|
104
106
|
| `GET /__admin/cdp/events?userId=&type=&event=` | CDP calls received (with `duplicate`). |
|
|
105
107
|
| `GET /__admin/profiles`, `GET /__admin/profiles/:id`, `PUT /__admin/profiles/:id` | Profiles (traits, `cioId`, `unsubscribed`, `channelsOff`, `preferences`). PUT merges `{traits?, email?, unsubscribed?, preferences?}`. |
|
|
108
|
+
| `POST /__admin/optouts` | `{customerId, from, optout: boolean, channel?: "sms"\|"whatsapp"}` scripts STOP (`true`) or START (`false`) for an existing person; unknown people are 404. Only that sender/channel changes. Marketing preferences and reporting webhooks stay independent. State participates in namespaces, snapshots, Timeline, clocks and reset. |
|
|
106
109
|
| `POST /__admin/deliveries/:id` | `{"state": "pending"\|"sent"\|"delivered"\|"bounced"\|"dropped"\|"failed"\|"spammed"\|"undeliverable"\|"suppressed"}`. Stamps `metrics[state]` with unix seconds on the namespace clock. `delivered` is success; the failure states are terminal. |
|
|
107
110
|
| `POST /__admin/namespace-clock` | `{"advance": <ms>}` adds to this namespace's clock offset only. |
|
|
108
111
|
| `GET\|PUT /__admin/transactional` | Read or replace the workspace's transactional messages (`[{id?, name?, trigger_name, link_tracking?, send_to_unsubscribed?}]`). |
|
|
@@ -131,6 +134,7 @@ username) or the App API key (Bearer) through `PUT /__admin/credentials {"creden
|
|
|
131
134
|
|
|
132
135
|
### Deliberately not modelled
|
|
133
136
|
|
|
137
|
+
- Opt-out writes through the public PUT API, phone identifier workspace configuration, Twilio sender identity casing recovery, and automatic carrier STOP callbacks. Use the admin control to script reconciler state; it does not model carrier delivery enforcement.
|
|
134
138
|
- Rendering: templates are not rendered; the outbox holds `message_data`, not HTML.
|
|
135
139
|
- Campaigns, segments, journeys, broadcasts and the Track API (`track.customer.io`).
|
|
136
140
|
- CDP `page`, `screen`, `group` and `alias` calls (our consumers send none).
|
package/SUPPORT.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Generated from `openapi.yaml`; do not edit by hand.
|
|
4
4
|
|
|
5
|
-
- operations in spec: **
|
|
6
|
-
- supported by the mock: **
|
|
7
|
-
- parity enabled: **
|
|
5
|
+
- operations in spec: **14**
|
|
6
|
+
- supported by the mock: **14**
|
|
7
|
+
- parity enabled: **14**
|
|
8
8
|
|
|
9
9
|
| operationId | route | mock | parity | notes |
|
|
10
10
|
| --- | --- | --- | --- | --- |
|
|
@@ -17,6 +17,8 @@ Generated from `openapi.yaml`; do not edit by hand.
|
|
|
17
17
|
| `ListTransactionalMessages` | `GET /v1/transactional` | ✅ supported | ✅ | |
|
|
18
18
|
| `GetTransactionalMessage` | `GET /v1/transactional/{transactional_id}` | ✅ supported | ✅ | |
|
|
19
19
|
| `GetCustomerAttributes` | `GET /v1/customers/{customer_id}/attributes` | ✅ supported | ✅ | |
|
|
20
|
+
| `ListOptOuts` | `GET /v1/optouts` | ✅ supported | ✅ | |
|
|
21
|
+
| `GetCustomerOptOuts` | `GET /v1/customers/{customer_id}/optouts` | ✅ supported | ✅ | |
|
|
20
22
|
| `GetMessage` | `GET /v1/messages/{message_id}` | ✅ supported | ✅ | |
|
|
21
23
|
| `FollowClick` | `GET /click/{linkId}` | ✅ supported | ⚠️ unsafe (opt-in) | |
|
|
22
24
|
| `ReportClick` | `POST /click/{linkId}` | ✅ supported | ⚠️ unsafe (opt-in) | |
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createRuntime,
|
|
4
4
|
parseDuration,
|
|
5
5
|
resolveAdminPrefix
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XGFF36NR.js";
|
|
7
7
|
|
|
8
8
|
// ../../adapters/node/dist/cli.js
|
|
9
9
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
@@ -855,4 +855,4 @@ export {
|
|
|
855
855
|
createServer2 as createServer,
|
|
856
856
|
serveTarget
|
|
857
857
|
};
|
|
858
|
-
//# sourceMappingURL=chunk-
|
|
858
|
+
//# sourceMappingURL=chunk-NL7M7QLP.js.map
|
|
@@ -1036,7 +1036,40 @@ var decodeBody = (contentType, bytes) => {
|
|
|
1036
1036
|
return { kind: "bytes", value: bytes };
|
|
1037
1037
|
};
|
|
1038
1038
|
var readBody = async (message) => {
|
|
1039
|
-
|
|
1039
|
+
if (!(message instanceof Request) || !message.body) {
|
|
1040
|
+
if (message instanceof Request)
|
|
1041
|
+
message.signal.throwIfAborted();
|
|
1042
|
+
return decodeBody(message.headers.get("content-type"), new Uint8Array(await message.arrayBuffer()));
|
|
1043
|
+
}
|
|
1044
|
+
message.signal.throwIfAborted();
|
|
1045
|
+
const reader = message.body.getReader();
|
|
1046
|
+
const cancel = () => {
|
|
1047
|
+
void reader.cancel(message.signal.reason).catch(() => {
|
|
1048
|
+
});
|
|
1049
|
+
};
|
|
1050
|
+
message.signal.addEventListener("abort", cancel, { once: true });
|
|
1051
|
+
const chunks = [];
|
|
1052
|
+
let size = 0;
|
|
1053
|
+
try {
|
|
1054
|
+
for (; ; ) {
|
|
1055
|
+
message.signal.throwIfAborted();
|
|
1056
|
+
const { done, value } = await reader.read();
|
|
1057
|
+
message.signal.throwIfAborted();
|
|
1058
|
+
if (done)
|
|
1059
|
+
break;
|
|
1060
|
+
chunks.push(value);
|
|
1061
|
+
size += value.byteLength;
|
|
1062
|
+
}
|
|
1063
|
+
} finally {
|
|
1064
|
+
message.signal.removeEventListener("abort", cancel);
|
|
1065
|
+
reader.releaseLock();
|
|
1066
|
+
}
|
|
1067
|
+
const bytes = new Uint8Array(size);
|
|
1068
|
+
let offset = 0;
|
|
1069
|
+
for (const chunk of chunks) {
|
|
1070
|
+
bytes.set(chunk, offset);
|
|
1071
|
+
offset += chunk.byteLength;
|
|
1072
|
+
}
|
|
1040
1073
|
return decodeBody(message.headers.get("content-type"), bytes);
|
|
1041
1074
|
};
|
|
1042
1075
|
|
|
@@ -1854,7 +1887,42 @@ var verifyOperations = (document2, handlers) => {
|
|
|
1854
1887
|
}
|
|
1855
1888
|
return problems;
|
|
1856
1889
|
};
|
|
1857
|
-
var
|
|
1890
|
+
var escapePattern = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1891
|
+
var serviceRoute = (template) => {
|
|
1892
|
+
const names = [];
|
|
1893
|
+
let pattern = "", end = 0;
|
|
1894
|
+
for (const match of template.matchAll(/\{([^}]+)\}/g)) {
|
|
1895
|
+
pattern += `${escapePattern(template.slice(end, match.index))}([^/]+?)`;
|
|
1896
|
+
const name = match[1];
|
|
1897
|
+
if (!name)
|
|
1898
|
+
throw new Error(`Invalid OpenAPI route template: ${template}`);
|
|
1899
|
+
names.push(name);
|
|
1900
|
+
end = match.index + match[0].length;
|
|
1901
|
+
}
|
|
1902
|
+
pattern += escapePattern(template.slice(end));
|
|
1903
|
+
const matcher = new RegExp(`^${pattern}$`);
|
|
1904
|
+
const path = template.split("/").map((segment, index) => {
|
|
1905
|
+
if (!segment.includes("{"))
|
|
1906
|
+
return segment;
|
|
1907
|
+
const literal = /^\{([^}]+)\}$/.exec(segment);
|
|
1908
|
+
if (literal)
|
|
1909
|
+
return `:${literal[1]}`;
|
|
1910
|
+
let expression = "", offset = 0;
|
|
1911
|
+
for (const match of segment.matchAll(/\{[^}]+\}/g)) {
|
|
1912
|
+
expression += `${escapePattern(segment.slice(offset, match.index))}[^/]+?`;
|
|
1913
|
+
offset = match.index + match[0].length;
|
|
1914
|
+
}
|
|
1915
|
+
expression += escapePattern(segment.slice(offset));
|
|
1916
|
+
return `:mockingbirdSegment${index}{${expression}}`;
|
|
1917
|
+
}).join("/");
|
|
1918
|
+
return {
|
|
1919
|
+
path,
|
|
1920
|
+
params: (pathname) => {
|
|
1921
|
+
const values = matcher.exec(pathname);
|
|
1922
|
+
return Object.fromEntries(names.map((name, index) => [name, decodeURIComponent(values?.[index + 1] ?? "")]));
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
};
|
|
1858
1926
|
var routeOrder = (a, b) => {
|
|
1859
1927
|
const sa = a.path.split("/");
|
|
1860
1928
|
const sb = b.path.split("/");
|
|
@@ -1889,6 +1957,7 @@ var createService = (options) => {
|
|
|
1889
1957
|
for (const operation of operations) {
|
|
1890
1958
|
const metadata = operationMetadata(operation.operation);
|
|
1891
1959
|
const handler = options.handlers[operation.operationId];
|
|
1960
|
+
const registeredRoute = serviceRoute(operation.path);
|
|
1892
1961
|
const route = async (c) => {
|
|
1893
1962
|
const request = c.req.raw;
|
|
1894
1963
|
if (!metadata.supported || !handler) {
|
|
@@ -1898,7 +1967,7 @@ var createService = (options) => {
|
|
|
1898
1967
|
const context = {
|
|
1899
1968
|
request,
|
|
1900
1969
|
url,
|
|
1901
|
-
params:
|
|
1970
|
+
params: registeredRoute.params(url.pathname),
|
|
1902
1971
|
query: queryOf(url),
|
|
1903
1972
|
body: await readBody(request),
|
|
1904
1973
|
sqlite: options.sqlite,
|
|
@@ -1910,7 +1979,7 @@ var createService = (options) => {
|
|
|
1910
1979
|
const short = await options.before?.(context);
|
|
1911
1980
|
return withIssues(request, short ?? await handler(context));
|
|
1912
1981
|
};
|
|
1913
|
-
app.on(operation.method.toUpperCase(),
|
|
1982
|
+
app.on(operation.method.toUpperCase(), registeredRoute.path, route);
|
|
1914
1983
|
}
|
|
1915
1984
|
return {
|
|
1916
1985
|
app,
|
|
@@ -2379,7 +2448,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
2379
2448
|
};
|
|
2380
2449
|
|
|
2381
2450
|
// ../core/dist/version.js
|
|
2382
|
-
var PACKAGE_VERSION = true ? "2.
|
|
2451
|
+
var PACKAGE_VERSION = true ? "2.2.0" : UNRELEASED_VERSION;
|
|
2383
2452
|
|
|
2384
2453
|
// ../core/dist/signing.js
|
|
2385
2454
|
var encoder = new TextEncoder();
|
|
@@ -3565,9 +3634,9 @@ var presetRoutes = (presets, runtime, adminPrefix) => ({
|
|
|
3565
3634
|
});
|
|
3566
3635
|
|
|
3567
3636
|
// src/generated/openapi.ts
|
|
3568
|
-
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Customer.io CDP + App API (Mockingbird subset)","description":"Stateful mock subset of Customer.io: the Segment-compatible CDP ingestion endpoints\\n(\`identify\`, \`track\`, \`batch\`, as \`@customerio/cdp-analytics-node\` posts them), the App API\\ntransactional sends (email, SMS, inbox message), transactional-message catalog, profile\\nattribute reads, delivery-status reads, and the link-tracking click endpoint. One process\\nserves all three hosts (\`cdp.customer.io\`, \`api.customer.io\`, the tracking domain); their\\npaths do not collide.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from Customer.io's CDP (Segment spec) and App API reference, trimmed to what our consumer sends: customer-io.client.service.ts / notification-adapter.ts / transactional-email-adapter.ts (backend), transactional-client.ts (notification-processor), customerio-trigger-name-validator.ts (notification-service) and mobile-links-click-reporter.service.ts."}},"servers":[{"url":"https://api.customer.io"},{"url":"https://cdp.customer.io"}],"paths":{"/v1/identify":{"post":{"operationId":"CdpIdentify","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/IdentifyEvent"}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed event","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/track":{"post":{"operationId":"CdpTrack","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TrackEvent"}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed event","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/batch":{"post":{"operationId":"CdpBatch","description":"What \`@customerio/cdp-analytics-node\` posts: \`{batch: [...]}\`.","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["batch"],"properties":{"batch":{"type":"array","maxItems":5,"items":{"anyOf":[{"$ref":"#/components/schemas/IdentifyEvent"},{"$ref":"#/components/schemas/TrackEvent"}]}},"sentAt":{"type":"string"},"context":{"type":"object"}}}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed batch","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/send/email":{"post":{"operationId":"SendEmail","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendEmailRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/send/sms":{"post":{"operationId":"SendSms","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendSmsRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/send/inbox_message":{"post":{"operationId":"SendInboxMessage","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendInboxRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/transactional":{"get":{"operationId":"ListTransactionalMessages","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Every transactional message in the workspace (no pagination)","content":{"application/json":{"schema":{"type":"object","required":["messages"],"properties":{"messages":{"type":"array","items":{"$ref":"#/components/schemas/TransactionalMessage"}}}}}}},"401":{"$ref":"#/components/responses/AppError"}}}},"/v1/transactional/{transactional_id}":{"parameters":[{"name":"transactional_id","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"transactional_message","missing":"999999"}}}],"get":{"operationId":"GetTransactionalMessage","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One transactional message","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"$ref":"#/components/schemas/TransactionalMessage"}}}}}},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/customers/{customer_id}/attributes":{"parameters":[{"name":"customer_id","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":150}},{"name":"id_type","in":"query","required":false,"schema":{"type":"string","enum":["id","email","cio_id"]}}],"get":{"operationId":"GetCustomerAttributes","description":"App API profile read. \`id_type\` selects which identifier \`customer_id\` is\\n(\`id\` by default, or \`email\`, or \`cio_id\`).\\n","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The customer's identifiers and attributes","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerAttributes"}}}},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/messages/{message_id}":{"parameters":[{"name":"message_id","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":80,"x-mockingbird-resource-ref":{"type":"delivery","missing":"missingdelivery00000000000000"}}}],"get":{"operationId":"GetMessage","description":"Delivery status for one transactional send. Missing ids, and ids still inside the\\nmock's visibility delay, are 404. The body never includes \`message_data\`.\\n","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Delivery status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeliveryMessage"}}}},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/click/{linkId}":{"parameters":[{"name":"linkId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9_~-][A-Za-z0-9._~-]{0,63}$"}}],"post":{"operationId":"ReportClick","description":"Link-tracking click report on the tracking domain (our backend posts it when a smart\\nlink opens the app directly). Unauthenticated.\\n","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"200":{"description":"Click recorded (no body)"},"404":{"description":"Unknown link","content":{"text/plain":{"schema":{"type":"string"}}}}}},"get":{"operationId":"FollowClick","description":"A browser following a tracked link; redirects to the original URL.","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"302":{"description":"Redirect to the original URL"},"404":{"description":"Unknown link","content":{"text/plain":{"schema":{"type":"string"}}}}}}}},"components":{"securitySchemes":{"cdpWriteKey":{"type":"http","scheme":"basic","description":"\`Basic base64(<write key>:)\` (the CDP source write key as the username)."},"appApiKey":{"type":"http","scheme":"bearer","description":"\`Bearer <App API key>\`."}},"responses":{"Queued":{"description":"Queued for delivery","content":{"application/json":{"schema":{"type":"object","required":["delivery_id","queued_at"],"properties":{"delivery_id":{"type":"string","x-mockingbird-resource":{"type":"delivery","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"queued_at":{"type":"integer","x-mockingbird-volatile":{"kind":"timestamp"}}}}}}},"AppError":{"description":"An App API error","content":{"application/json":{"schema":{"type":"object","required":["meta"],"properties":{"meta":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}}}}},"schemas":{"CdpSuccess":{"type":"object","required":["success"],"properties":{"success":{"type":"boolean"}}},"CdpError":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}},"IdentifyEvent":{"type":"object","properties":{"type":{"type":"string","enum":["identify"]},"userId":{"type":"string","minLength":1,"maxLength":64},"anonymousId":{"type":"string","minLength":1,"maxLength":64},"traits":{"type":"object","additionalProperties":true},"context":{"type":"object"},"integrations":{"type":"object"},"timestamp":{"type":"string"},"messageId":{"type":"string","maxLength":128},"_metadata":{"type":"object"}}},"TrackEvent":{"type":"object","required":["event"],"properties":{"type":{"type":"string","enum":["track"]},"userId":{"type":"string","minLength":1,"maxLength":64},"anonymousId":{"type":"string","minLength":1,"maxLength":64},"event":{"type":"string","minLength":1,"maxLength":150},"properties":{"type":"object","additionalProperties":true},"context":{"type":"object"},"integrations":{"type":"object"},"timestamp":{"type":"string"},"messageId":{"type":"string","maxLength":128},"_metadata":{"type":"object"}}},"Identifiers":{"type":"object","properties":{"id":{"type":"string","minLength":1,"maxLength":64},"email":{"type":"string","format":"email","maxLength":120},"cio_id":{"type":"string","maxLength":64}}},"TransactionalMessageId":{"oneOf":[{"type":"string","minLength":1,"maxLength":150},{"type":"integer","minimum":1}]},"SendEmailRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"to":{"type":"string","maxLength":200},"from":{"type":"string","maxLength":200},"subject":{"type":"string","maxLength":300},"body":{"type":"string"},"message_data":{"type":"object","additionalProperties":true},"send_to_unsubscribed":{"type":"boolean"},"tracked":{"type":"boolean"},"disable_message_retention":{"type":"boolean"},"headers":{"type":"object","additionalProperties":{"type":"string"}},"attachments":{"description":"Customer.io documents a \`{filename: base64}\` map; our backend sends an array of \`{filename, content, content_type}\`. Both are accepted.","oneOf":[{"type":"object","additionalProperties":{"type":"string"}},{"type":"array","items":{"type":"object","required":["filename","content"],"properties":{"filename":{"type":"string"},"content":{"type":"string"},"content_type":{"type":"string"}}}}]}}},"SendSmsRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"to":{"type":"string","maxLength":20},"message_data":{"type":"object","additionalProperties":true},"send_to_unsubscribed":{"type":"boolean"},"tracked":{"type":"boolean"},"disable_message_retention":{"type":"boolean"}}},"SendInboxRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"message_data":{"type":"object","additionalProperties":true}}},"TransactionalMessage":{"type":"object","required":["id","name"],"properties":{"id":{"type":"integer"},"name":{"type":"string"},"trigger_name":{"type":"string","x-mockingbird-resource":{"type":"transactional_message","identity":true}},"description":{"type":"string"},"send_to_unsubscribed":{"type":"boolean"},"link_tracking":{"type":"boolean"},"open_tracking":{"type":"boolean"},"hide_message_body":{"type":"boolean"},"queue_drafts":{"type":"boolean"},"created_at":{"type":"integer"},"updated_at":{"type":"integer"}}},"CustomerAttributes":{"type":"object","required":["customer"],"properties":{"customer":{"type":"object","required":["identifiers","attributes"],"properties":{"identifiers":{"type":"object","required":["id"],"additionalProperties":true,"properties":{"id":{"type":"string"},"email":{"type":"string"},"cio_id":{"type":"string"}}},"attributes":{"type":"object","additionalProperties":true},"devices":{"type":"array","items":{"type":"object","additionalProperties":true}}}}}},"DeliveryMessage":{"type":"object","required":["message"],"properties":{"message":{"type":"object","required":["id","state","status","metrics","created"],"additionalProperties":true,"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"delivery","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"type":{"type":"string"},"recipient":{"type":["string","null"]},"customer_id":{"type":["string","null"]},"created":{"type":"integer","x-mockingbird-volatile":{"kind":"timestamp"}},"state":{"type":"string"},"status":{"type":"string"},"metrics":{"type":"object","additionalProperties":{"type":"integer"}},"failure_message":{"type":["string","null"]},"rejection_reason":{"type":["string","null"]},"error":{"type":["string","null"]}}}}}}}}`);
|
|
3569
|
-
var operationIds = ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "GetMessage", "FollowClick", "ReportClick"];
|
|
3570
|
-
var supportedOperationIds = ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "GetMessage", "FollowClick", "ReportClick"];
|
|
3637
|
+
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Customer.io CDP + App API (Mockingbird subset)","description":"Stateful mock subset of Customer.io: the Segment-compatible CDP ingestion endpoints\\n(\`identify\`, \`track\`, \`batch\`, as \`@customerio/cdp-analytics-node\` posts them), the App API\\ntransactional sends (email, SMS, inbox message), transactional-message catalog, profile\\nattribute reads, delivery-status reads, and the link-tracking click endpoint. One process\\nserves all three hosts (\`cdp.customer.io\`, \`api.customer.io\`, the tracking domain); their\\npaths do not collide.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from Customer.io's CDP (Segment spec) and App API reference, trimmed to what our consumer sends: customer-io.client.service.ts / notification-adapter.ts / transactional-email-adapter.ts (backend), transactional-client.ts (notification-processor), customerio-trigger-name-validator.ts (notification-service) and mobile-links-click-reporter.service.ts."}},"servers":[{"url":"https://api.customer.io"},{"url":"https://cdp.customer.io"}],"paths":{"/v1/identify":{"post":{"operationId":"CdpIdentify","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/IdentifyEvent"}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed event","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/track":{"post":{"operationId":"CdpTrack","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TrackEvent"}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed event","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/batch":{"post":{"operationId":"CdpBatch","description":"What \`@customerio/cdp-analytics-node\` posts: \`{batch: [...]}\`.","security":[{"cdpWriteKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["batch"],"properties":{"batch":{"type":"array","maxItems":5,"items":{"anyOf":[{"$ref":"#/components/schemas/IdentifyEvent"},{"$ref":"#/components/schemas/TrackEvent"}]}},"sentAt":{"type":"string"},"context":{"type":"object"}}}}}},"responses":{"200":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpSuccess"}}}},"400":{"description":"Malformed batch","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}},"401":{"description":"Missing or unknown write key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CdpError"}}}}}}},"/v1/send/email":{"post":{"operationId":"SendEmail","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendEmailRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/send/sms":{"post":{"operationId":"SendSms","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendSmsRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/send/inbox_message":{"post":{"operationId":"SendInboxMessage","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendInboxRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/Queued"},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/transactional":{"get":{"operationId":"ListTransactionalMessages","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Every transactional message in the workspace (no pagination)","content":{"application/json":{"schema":{"type":"object","required":["messages"],"properties":{"messages":{"type":"array","items":{"$ref":"#/components/schemas/TransactionalMessage"}}}}}}},"401":{"$ref":"#/components/responses/AppError"}}}},"/v1/transactional/{transactional_id}":{"parameters":[{"name":"transactional_id","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"transactional_message","missing":"999999"}}}],"get":{"operationId":"GetTransactionalMessage","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One transactional message","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"$ref":"#/components/schemas/TransactionalMessage"}}}}}},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/customers/{customer_id}/attributes":{"parameters":[{"name":"customer_id","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":150}},{"name":"id_type","in":"query","required":false,"schema":{"type":"string","enum":["id","email","cio_id"]}}],"get":{"operationId":"GetCustomerAttributes","description":"App API profile read. \`id_type\` selects which identifier \`customer_id\` is\\n(\`id\` by default, or \`email\`, or \`cio_id\`).\\n","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The customer's identifiers and attributes","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerAttributes"}}}},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/optouts":{"get":{"operationId":"ListOptOuts","description":"Sender-specific SMS and WhatsApp opt-outs, paginated by an opaque start cursor.","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":1000,"default":100}},{"name":"start","in":"query","schema":{"type":"string"}},{"name":"from","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"A page of opted-out customers","content":{"application/json":{"schema":{"type":"object","required":["optouts"],"properties":{"next":{"type":"string"},"optouts":{"type":"array","items":{"type":"object","required":["customer_id","cio_id","optouts"],"properties":{"customer_id":{"type":"string"},"cio_id":{"type":"string"},"optouts":{"type":"array","items":{"$ref":"#/components/schemas/SenderOptOut"}}}}}}}}}},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"}}}},"/v1/customers/{customer_id}/optouts":{"get":{"operationId":"GetCustomerOptOuts","description":"Sender opt-outs for an existing person; marketing preferences are separate.","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"customer_id","in":"path","required":true,"schema":{"type":"string","minLength":1}},{"name":"id_type","in":"query","schema":{"type":"string","enum":["id","email","cio_id"],"default":"id"}}],"responses":{"200":{"description":"The customer's sender opt-outs","content":{"application/json":{"schema":{"type":"object","required":["optouts"],"properties":{"optouts":{"type":"array","items":{"$ref":"#/components/schemas/SenderOptOut"}}}}}}},"400":{"$ref":"#/components/responses/AppError"},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/v1/messages/{message_id}":{"parameters":[{"name":"message_id","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":80,"x-mockingbird-resource-ref":{"type":"delivery","missing":"missingdelivery00000000000000"}}}],"get":{"operationId":"GetMessage","description":"Delivery status for one transactional send. Missing ids, and ids still inside the\\nmock's visibility delay, are 404. The body never includes \`message_data\`.\\n","security":[{"appApiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Delivery status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeliveryMessage"}}}},"401":{"$ref":"#/components/responses/AppError"},"404":{"$ref":"#/components/responses/AppError"}}}},"/click/{linkId}":{"parameters":[{"name":"linkId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9_~-][A-Za-z0-9._~-]{0,63}$"}}],"post":{"operationId":"ReportClick","description":"Link-tracking click report on the tracking domain (our backend posts it when a smart\\nlink opens the app directly). Unauthenticated.\\n","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"200":{"description":"Click recorded (no body)"},"404":{"description":"Unknown link","content":{"text/plain":{"schema":{"type":"string"}}}}}},"get":{"operationId":"FollowClick","description":"A browser following a tracked link; redirects to the original URL.","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"302":{"description":"Redirect to the original URL"},"404":{"description":"Unknown link","content":{"text/plain":{"schema":{"type":"string"}}}}}}}},"components":{"securitySchemes":{"cdpWriteKey":{"type":"http","scheme":"basic","description":"\`Basic base64(<write key>:)\` (the CDP source write key as the username)."},"appApiKey":{"type":"http","scheme":"bearer","description":"\`Bearer <App API key>\`."}},"responses":{"Queued":{"description":"Queued for delivery","content":{"application/json":{"schema":{"type":"object","required":["delivery_id","queued_at"],"properties":{"delivery_id":{"type":"string","x-mockingbird-resource":{"type":"delivery","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"queued_at":{"type":"integer","x-mockingbird-volatile":{"kind":"timestamp"}}}}}}},"AppError":{"description":"An App API error","content":{"application/json":{"schema":{"type":"object","required":["meta"],"properties":{"meta":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}}}}},"schemas":{"SenderOptOut":{"type":"object","required":["channel","from"],"properties":{"channel":{"type":"string","enum":["sms","whatsapp"]},"from":{"type":"string"}}},"CdpSuccess":{"type":"object","required":["success"],"properties":{"success":{"type":"boolean"}}},"CdpError":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}},"IdentifyEvent":{"type":"object","properties":{"type":{"type":"string","enum":["identify"]},"userId":{"type":"string","minLength":1,"maxLength":64},"anonymousId":{"type":"string","minLength":1,"maxLength":64},"traits":{"type":"object","additionalProperties":true},"context":{"type":"object"},"integrations":{"type":"object"},"timestamp":{"type":"string"},"messageId":{"type":"string","maxLength":128},"_metadata":{"type":"object"}}},"TrackEvent":{"type":"object","required":["event"],"properties":{"type":{"type":"string","enum":["track"]},"userId":{"type":"string","minLength":1,"maxLength":64},"anonymousId":{"type":"string","minLength":1,"maxLength":64},"event":{"type":"string","minLength":1,"maxLength":150},"properties":{"type":"object","additionalProperties":true},"context":{"type":"object"},"integrations":{"type":"object"},"timestamp":{"type":"string"},"messageId":{"type":"string","maxLength":128},"_metadata":{"type":"object"}}},"Identifiers":{"type":"object","properties":{"id":{"type":"string","minLength":1,"maxLength":64},"email":{"type":"string","format":"email","maxLength":120},"cio_id":{"type":"string","maxLength":64}}},"TransactionalMessageId":{"oneOf":[{"type":"string","minLength":1,"maxLength":150},{"type":"integer","minimum":1}]},"SendEmailRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"to":{"type":"string","maxLength":200},"from":{"type":"string","maxLength":200},"subject":{"type":"string","maxLength":300},"body":{"type":"string"},"message_data":{"type":"object","additionalProperties":true},"send_to_unsubscribed":{"type":"boolean"},"tracked":{"type":"boolean"},"disable_message_retention":{"type":"boolean"},"headers":{"type":"object","additionalProperties":{"type":"string"}},"attachments":{"description":"Customer.io documents a \`{filename: base64}\` map; our backend sends an array of \`{filename, content, content_type}\`. Both are accepted.","oneOf":[{"type":"object","additionalProperties":{"type":"string"}},{"type":"array","items":{"type":"object","required":["filename","content"],"properties":{"filename":{"type":"string"},"content":{"type":"string"},"content_type":{"type":"string"}}}}]}}},"SendSmsRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"to":{"type":"string","maxLength":20},"message_data":{"type":"object","additionalProperties":true},"send_to_unsubscribed":{"type":"boolean"},"tracked":{"type":"boolean"},"disable_message_retention":{"type":"boolean"}}},"SendInboxRequest":{"type":"object","required":["transactional_message_id","identifiers"],"properties":{"transactional_message_id":{"$ref":"#/components/schemas/TransactionalMessageId"},"identifiers":{"$ref":"#/components/schemas/Identifiers"},"message_data":{"type":"object","additionalProperties":true}}},"TransactionalMessage":{"type":"object","required":["id","name"],"properties":{"id":{"type":"integer"},"name":{"type":"string"},"trigger_name":{"type":"string","x-mockingbird-resource":{"type":"transactional_message","identity":true}},"description":{"type":"string"},"send_to_unsubscribed":{"type":"boolean"},"link_tracking":{"type":"boolean"},"open_tracking":{"type":"boolean"},"hide_message_body":{"type":"boolean"},"queue_drafts":{"type":"boolean"},"created_at":{"type":"integer"},"updated_at":{"type":"integer"}}},"CustomerAttributes":{"type":"object","required":["customer"],"properties":{"customer":{"type":"object","required":["identifiers","attributes"],"properties":{"identifiers":{"type":"object","required":["id"],"additionalProperties":true,"properties":{"id":{"type":"string"},"email":{"type":"string"},"cio_id":{"type":"string"}}},"attributes":{"type":"object","additionalProperties":true},"devices":{"type":"array","items":{"type":"object","additionalProperties":true}}}}}},"DeliveryMessage":{"type":"object","required":["message"],"properties":{"message":{"type":"object","required":["id","state","status","metrics","created"],"additionalProperties":true,"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"delivery","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"type":{"type":"string"},"recipient":{"type":["string","null"]},"customer_id":{"type":["string","null"]},"created":{"type":"integer","x-mockingbird-volatile":{"kind":"timestamp"}},"state":{"type":"string"},"status":{"type":"string"},"metrics":{"type":"object","additionalProperties":{"type":"integer"}},"failure_message":{"type":["string","null"]},"rejection_reason":{"type":["string","null"]},"error":{"type":["string","null"]}}}}}}}}`);
|
|
3638
|
+
var operationIds = ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "ListOptOuts", "GetCustomerOptOuts", "GetMessage", "FollowClick", "ReportClick"];
|
|
3639
|
+
var supportedOperationIds = ["CdpIdentify", "CdpTrack", "CdpBatch", "SendEmail", "SendSms", "SendInboxMessage", "ListTransactionalMessages", "GetTransactionalMessage", "GetCustomerAttributes", "ListOptOuts", "GetCustomerOptOuts", "GetMessage", "FollowClick", "ReportClick"];
|
|
3571
3640
|
|
|
3572
3641
|
// src/state.ts
|
|
3573
3642
|
var DELIVERY_STATES = [
|
|
@@ -3643,6 +3712,7 @@ var CustomerIoState = class {
|
|
|
3643
3712
|
this.deliveries = new OutboxStore(sqlite, namespace, "deliveries");
|
|
3644
3713
|
this.cdp = new Collection(sqlite, namespace, "cdp");
|
|
3645
3714
|
this.profiles = new Collection(sqlite, namespace, "profiles");
|
|
3715
|
+
this.optouts = new Collection(sqlite, namespace, "optouts");
|
|
3646
3716
|
this.messages = new Collection(sqlite, namespace, "transactional");
|
|
3647
3717
|
this.links = new Collection(sqlite, namespace, "links");
|
|
3648
3718
|
this.settings = new Collection(sqlite, namespace, "settings");
|
|
@@ -3653,6 +3723,7 @@ var CustomerIoState = class {
|
|
|
3653
3723
|
deliveries;
|
|
3654
3724
|
cdp;
|
|
3655
3725
|
profiles;
|
|
3726
|
+
optouts;
|
|
3656
3727
|
messages;
|
|
3657
3728
|
links;
|
|
3658
3729
|
settings;
|
|
@@ -3683,6 +3754,19 @@ var CustomerIoState = class {
|
|
|
3683
3754
|
const lower = idOrTrigger.toLowerCase();
|
|
3684
3755
|
return this.catalog().find((m) => m.trigger_name.toLowerCase() === lower);
|
|
3685
3756
|
}
|
|
3757
|
+
setOptOut(customerId, from, channel, optout) {
|
|
3758
|
+
if (!this.profile(customerId)) return void 0;
|
|
3759
|
+
const sender = from.trim().toLowerCase();
|
|
3760
|
+
const current = this.optouts.get(customerId);
|
|
3761
|
+
const optouts = (current?.optouts ?? []).filter(
|
|
3762
|
+
(item) => item.channel !== channel || item.from !== sender
|
|
3763
|
+
);
|
|
3764
|
+
if (optout) optouts.push({ channel, from: sender });
|
|
3765
|
+
const next = { customerId, optouts };
|
|
3766
|
+
if (current) this.optouts.update(customerId, next);
|
|
3767
|
+
else this.optouts.insert(customerId, next);
|
|
3768
|
+
return next;
|
|
3769
|
+
}
|
|
3686
3770
|
profile(id) {
|
|
3687
3771
|
return this.profiles.get(id);
|
|
3688
3772
|
}
|
|
@@ -3884,6 +3968,18 @@ var adminRoutes = (runtime) => ({
|
|
|
3884
3968
|
}
|
|
3885
3969
|
return json6(200, runtime.instance(namespace).mergeProfile(params.id, patch));
|
|
3886
3970
|
},
|
|
3971
|
+
"POST /optouts": ({ body, namespace }) => {
|
|
3972
|
+
if (!isRecord5(body) || typeof body.customerId !== "string" || typeof body.from !== "string" || !body.from.trim() || typeof body.optout !== "boolean" || body.channel !== void 0 && body.channel !== "sms" && body.channel !== "whatsapp") {
|
|
3973
|
+
return adminError4(400, "expected {customerId, from, optout: boolean, channel?: sms|whatsapp}");
|
|
3974
|
+
}
|
|
3975
|
+
const result = runtime.instance(namespace).state.setOptOut(
|
|
3976
|
+
body.customerId,
|
|
3977
|
+
body.from,
|
|
3978
|
+
body.channel === "whatsapp" ? "whatsapp" : "sms",
|
|
3979
|
+
body.optout
|
|
3980
|
+
);
|
|
3981
|
+
return result ? json6(200, result) : adminError4(404, "unknown customer");
|
|
3982
|
+
},
|
|
3887
3983
|
"POST /deliveries/:id": ({ params, body, namespace }) => {
|
|
3888
3984
|
if (!isRecord5(body) || typeof body.state !== "string") {
|
|
3889
3985
|
return adminError4(400, `expected {"state": ${DELIVERY_STATES.join("|")}}`);
|
|
@@ -4024,6 +4120,8 @@ var APP_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
4024
4120
|
"ListTransactionalMessages",
|
|
4025
4121
|
"GetTransactionalMessage",
|
|
4026
4122
|
"GetCustomerAttributes",
|
|
4123
|
+
"ListOptOuts",
|
|
4124
|
+
"GetCustomerOptOuts",
|
|
4027
4125
|
"GetMessage"
|
|
4028
4126
|
]);
|
|
4029
4127
|
var E164 = /^\+[1-9]\d{1,14}$/;
|
|
@@ -4116,6 +4214,8 @@ var CustomerIoAPI = class {
|
|
|
4116
4214
|
SendInboxMessage: (context) => this.enqueue(() => this.send(context, "inbox")),
|
|
4117
4215
|
ListTransactionalMessages: (context) => this.enqueue(() => this.listMessages(context)),
|
|
4118
4216
|
GetTransactionalMessage: (context) => this.enqueue(() => this.oneMessage(context)),
|
|
4217
|
+
ListOptOuts: (context) => this.enqueue(() => this.listOptOuts(context)),
|
|
4218
|
+
GetCustomerOptOuts: (context) => this.enqueue(() => this.customerOptOuts(context)),
|
|
4119
4219
|
GetCustomerAttributes: (context) => this.enqueue(() => this.attributes(context)),
|
|
4120
4220
|
GetMessage: (context) => this.enqueue(() => this.deliveryMessage(context)),
|
|
4121
4221
|
ReportClick: (context) => this.enqueue(() => this.click(context, "post")),
|
|
@@ -4347,6 +4447,43 @@ var CustomerIoAPI = class {
|
|
|
4347
4447
|
const message = this.state.message(context.params.transactional_id ?? "");
|
|
4348
4448
|
return message ? jsonRes(200, { message }) : appError(404, "not found");
|
|
4349
4449
|
}
|
|
4450
|
+
listOptOuts(context) {
|
|
4451
|
+
const rawLimit = context.query.limit;
|
|
4452
|
+
const limit = rawLimit === void 0 ? 100 : Number(rawLimit);
|
|
4453
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1e3)
|
|
4454
|
+
return appError(400, "limit must be between 1 and 1000");
|
|
4455
|
+
let after = 0;
|
|
4456
|
+
if (context.query.start !== void 0) {
|
|
4457
|
+
try {
|
|
4458
|
+
const decoded = atob(String(context.query.start));
|
|
4459
|
+
if (!/^optouts:[1-9]\d*$/.test(decoded)) return appError(400, "invalid start cursor");
|
|
4460
|
+
after = Number(decoded.slice(8));
|
|
4461
|
+
if (!Number.isSafeInteger(after)) return appError(400, "invalid start cursor");
|
|
4462
|
+
} catch {
|
|
4463
|
+
return appError(400, "invalid start cursor");
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
const from = typeof context.query.from === "string" ? context.query.from.trim().toLowerCase() : void 0;
|
|
4467
|
+
const rows = this.state.optouts.list({ order: "oldest" }).flatMap((row) => {
|
|
4468
|
+
const profile = this.state.profile(row.value.customerId);
|
|
4469
|
+
const optouts = row.value.optouts.filter((item) => from === void 0 || item.from === from);
|
|
4470
|
+
return row.seq > after && profile && optouts.length ? [{ seq: row.seq, customer_id: profile.id, cio_id: profile.cioId, optouts }] : [];
|
|
4471
|
+
});
|
|
4472
|
+
const page = rows.slice(0, limit);
|
|
4473
|
+
const last = page.at(-1);
|
|
4474
|
+
return jsonRes(200, {
|
|
4475
|
+
...rows.length > limit && last ? { next: btoa(`optouts:${last.seq}`) } : {},
|
|
4476
|
+
optouts: page.map(({ seq: _seq, ...row }) => row)
|
|
4477
|
+
});
|
|
4478
|
+
}
|
|
4479
|
+
customerOptOuts(context) {
|
|
4480
|
+
const customerId = context.params.customer_id ?? "";
|
|
4481
|
+
const idType = context.query.id_type ?? "id";
|
|
4482
|
+
const profile = idType === "id" ? this.state.profile(customerId) : idType === "email" ? this.state.profileByEmail(customerId) : idType === "cio_id" ? this.state.profileByCioId(customerId) : void 0;
|
|
4483
|
+
if (!["id", "email", "cio_id"].includes(String(idType))) return appError(400, "invalid id_type");
|
|
4484
|
+
if (!profile) return appError(404, "not found");
|
|
4485
|
+
return jsonRes(200, { optouts: this.state.optouts.get(profile.id)?.optouts ?? [] });
|
|
4486
|
+
}
|
|
4350
4487
|
attributes(context) {
|
|
4351
4488
|
const rawType = context.query.id_type;
|
|
4352
4489
|
const idType = rawType === void 0 ? "id" : rawType;
|
|
@@ -4574,4 +4711,4 @@ export {
|
|
|
4574
4711
|
customerIoCredential,
|
|
4575
4712
|
CustomerIoAPI
|
|
4576
4713
|
};
|
|
4577
|
-
//# sourceMappingURL=chunk-
|
|
4714
|
+
//# sourceMappingURL=chunk-XGFF36NR.js.map
|