@distilled.cloud/customerio 1.0.0-rc.11 → 1.0.0-rc.13
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/README.md +34 -0
- package/lib/protocol.d.ts +4 -4
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/response-validation.test.d.ts +6 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +38 -0
- package/lib/response-validation.test.js.map +1 -0
- package/lib/services/customerio.d.ts +1 -4
- package/lib/services/customerio.d.ts.map +1 -1
- package/lib/services/customerio.js +1 -2
- package/lib/services/customerio.js.map +1 -1
- package/lib/traits.d.ts +1 -1
- package/lib/traits.d.ts.map +1 -1
- package/lib/traits.js +1 -1
- package/lib/traits.js.map +1 -1
- package/package.json +4 -4
- package/src/protocol.ts +6 -4
- package/src/response-validation.test.ts +54 -0
- package/src/services/customerio.ts +2 -10
- package/src/traits.ts +2 -0
package/lib/traits.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* the REST-protocol traits (SensitiveValue / RawResponse) come from
|
|
7
7
|
* `core/protocol-rest`.
|
|
8
8
|
*/
|
|
9
|
-
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, type HttpTrait, type ErrorMatcher, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
9
|
+
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, StringEncoded, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, type HttpTrait, type ErrorMatcher, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, stringEncodedSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
10
10
|
export { SensitiveValue, RawResponse, RawResponseRoot, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
|
|
11
11
|
//# sourceMappingURL=traits.d.ts.map
|
package/lib/traits.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traits.d.ts","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"traits.d.ts","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
|
package/lib/traits.js
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* the REST-protocol traits (SensitiveValue / RawResponse) come from
|
|
7
7
|
* `core/protocol-rest`.
|
|
8
8
|
*/
|
|
9
|
-
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
9
|
+
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, StringEncoded, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, stringEncodedSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
10
10
|
export { SensitiveValue, RawResponse, RawResponseRoot, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
|
|
11
11
|
//# sourceMappingURL=traits.js.map
|
package/lib/traits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traits.js","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAGhB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"traits.js","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAGhB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/customerio",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
67
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/bun": "1.3.14",
|
|
71
71
|
"@types/node": "26.2.0",
|
|
72
|
-
"@effect/platform-bun": "
|
|
72
|
+
"@effect/platform-bun": "^4.0.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"effect": "
|
|
75
|
+
"effect": "^4.0.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
import * as Effect from "effect/Effect";
|
|
20
20
|
import type * as Layer from "effect/Layer";
|
|
21
21
|
import * as Redacted from "effect/Redacted";
|
|
22
|
-
import type * as HttpClient from "effect/
|
|
23
|
-
import type * as HttpClientError from "effect/
|
|
22
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
23
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
24
24
|
import type * as API from "@distilled.cloud/core/api";
|
|
25
25
|
import {
|
|
26
26
|
makeRestProtocol,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from "@distilled.cloud/core/protocol-rest";
|
|
29
29
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
30
30
|
import { Credentials, type Config } from "./credentials.ts";
|
|
31
|
-
import { UnknownCustomerioError } from "./errors.ts";
|
|
31
|
+
import { UnknownCustomerioError, CustomerioParseError } from "./errors.ts";
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Error channel shared by every generated Customer.io operation. Generated
|
|
@@ -40,7 +40,8 @@ export type CustomerioOpError =
|
|
|
40
40
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
41
41
|
| UnknownCustomerioError
|
|
42
42
|
| ConfigError
|
|
43
|
-
| HttpClientError.HttpClientError
|
|
43
|
+
| HttpClientError.HttpClientError
|
|
44
|
+
| CustomerioParseError;
|
|
44
45
|
|
|
45
46
|
/** Context (requirements) shared by every generated Customer.io operation. */
|
|
46
47
|
export type CustomerioOpContext = Credentials | HttpClient.HttpClient;
|
|
@@ -111,4 +112,5 @@ export const CustomerioProtocol: Layer.Layer<API.Protocol> =
|
|
|
111
112
|
message,
|
|
112
113
|
body,
|
|
113
114
|
}),
|
|
115
|
+
parseError: ({ body, cause }) => new CustomerioParseError({ body, cause }),
|
|
114
116
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { fromApiKey } from "./credentials.ts";
|
|
5
|
+
import { CustomerioParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { getWebhook } from "./services/customerio.ts";
|
|
8
|
+
import type { CustomerioOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// getWebhook declares `{ name: string; endpoint: string; events: [...]; … }`.
|
|
11
|
+
const run = (body: string) =>
|
|
12
|
+
runValidationModes(
|
|
13
|
+
getWebhook({ webhook_id: 1 }).pipe(
|
|
14
|
+
Retry.none,
|
|
15
|
+
Effect.provide(fromApiKey({ apiKey: "test" })),
|
|
16
|
+
),
|
|
17
|
+
{ body },
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
describe("Customer.io response validation", () => {
|
|
21
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
22
|
+
const body = {
|
|
23
|
+
id: 1,
|
|
24
|
+
name: "hook",
|
|
25
|
+
endpoint: "https://example.com/hook",
|
|
26
|
+
events: [],
|
|
27
|
+
};
|
|
28
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
29
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
30
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
34
|
+
const body = {};
|
|
35
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
36
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
37
|
+
expect(strict._tag).toBe("Failure");
|
|
38
|
+
expect((strict as any).failure).toBeInstanceOf(CustomerioParseError);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
42
|
+
const { lenient, strict } = await run("not json");
|
|
43
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
44
|
+
expect(strict._tag).toBe("Failure");
|
|
45
|
+
expect((strict as any).failure).toBeInstanceOf(CustomerioParseError);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// CustomerioParseError is part of every operation's declared error type.
|
|
50
|
+
export const parseErrorIsDeclared: [CustomerioParseError] extends [
|
|
51
|
+
CustomerioOpError,
|
|
52
|
+
]
|
|
53
|
+
? true
|
|
54
|
+
: false = true;
|
|
@@ -26674,10 +26674,6 @@ export const SendPushRequestSound = S.String;
|
|
|
26674
26674
|
export type SendPushRequestCustomDevicePlatform = "ios" | "android";
|
|
26675
26675
|
export const SendPushRequestCustomDevicePlatform = S.String;
|
|
26676
26676
|
|
|
26677
|
-
/** If `"true"`, the device is opted-in and can receive push notifications. */
|
|
26678
|
-
export type SendPushRequestCustomDeviceAttributesPushEnabled = "true" | "false";
|
|
26679
|
-
export const SendPushRequestCustomDeviceAttributesPushEnabled = S.String;
|
|
26680
|
-
|
|
26681
26677
|
/** Attributes that you can reference to segment your audience—like a person's attributes, but specific to a device. These can be either the attributes defined below or custom key-value attributes. */
|
|
26682
26678
|
export interface SendPushRequestCustomDeviceAttributes {
|
|
26683
26679
|
/** The operating system, including the version, on the device. */
|
|
@@ -26691,9 +26687,7 @@ export interface SendPushRequestCustomDeviceAttributes {
|
|
|
26691
26687
|
/** The device's [IETF language code](/journeys/channels/localization/getting-started/#supported-languages), such as `en-MX` or `es-ES`. */
|
|
26692
26688
|
device_locale?: string;
|
|
26693
26689
|
/** If `"true"`, the device is opted-in and can receive push notifications. */
|
|
26694
|
-
push_enabled?:
|
|
26695
|
-
| SendPushRequestCustomDeviceAttributesPushEnabled
|
|
26696
|
-
| (string & {});
|
|
26690
|
+
push_enabled?: boolean;
|
|
26697
26691
|
}
|
|
26698
26692
|
export const SendPushRequestCustomDeviceAttributes = /*@__PURE__*/ S.suspend(
|
|
26699
26693
|
() =>
|
|
@@ -26703,9 +26697,7 @@ export const SendPushRequestCustomDeviceAttributes = /*@__PURE__*/ S.suspend(
|
|
|
26703
26697
|
app_version: S.optional(S.String),
|
|
26704
26698
|
cio_sdk_version: S.optional(S.String),
|
|
26705
26699
|
device_locale: S.optional(S.String),
|
|
26706
|
-
push_enabled: S.optional(
|
|
26707
|
-
SendPushRequestCustomDeviceAttributesPushEnabled,
|
|
26708
|
-
),
|
|
26700
|
+
push_enabled: S.optional(S.Boolean.pipe(T.StringEncoded())),
|
|
26709
26701
|
}),
|
|
26710
26702
|
).annotate({
|
|
26711
26703
|
identifier: "SendPushRequestCustomDeviceAttributes",
|
package/src/traits.ts
CHANGED
|
@@ -15,6 +15,7 @@ export {
|
|
|
15
15
|
ResponseCode,
|
|
16
16
|
HttpBody,
|
|
17
17
|
FormDataFile,
|
|
18
|
+
StringEncoded,
|
|
18
19
|
KeyDictionary,
|
|
19
20
|
UnionCases,
|
|
20
21
|
applyErrorMatchers,
|
|
@@ -29,6 +30,7 @@ export {
|
|
|
29
30
|
responseCodeSymbol,
|
|
30
31
|
httpBodySymbol,
|
|
31
32
|
formDataFileSymbol,
|
|
33
|
+
stringEncodedSymbol,
|
|
32
34
|
keyDictionarySymbol,
|
|
33
35
|
unionCasesSymbol,
|
|
34
36
|
errorMatchersSymbol,
|