@distilled.cloud/zendesk 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 +4 -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/package.json +4 -4
- package/src/protocol.ts +6 -4
- package/src/response-validation.test.ts +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/zendesk
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [zendesk](https://www.npmjs.com/package/@distilled.cloud/zendesk).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/zendesk effect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Effect, Layer } from "effect";
|
|
15
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
import * as Zendesk from "@distilled.cloud/zendesk";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* Zendesk.listTickets({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
Zendesk.CredentialsFromEnv,
|
|
26
|
+
Zendesk.ZendeskProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `ZENDESK_ACCESS_TOKEN`, `ZENDESK_API_TOKEN`, `ZENDESK_EMAIL`, `ZENDESK_SUBDOMAIN`. Optional: `ZENDESK_API_BASE_URL`. Sent as `Authorization: Bearer`.
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type * as Layer from "effect/Layer";
|
|
2
|
-
import type * as HttpClient from "effect/
|
|
3
|
-
import type * as HttpClientError from "effect/
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
4
4
|
import type * as API from "@distilled.cloud/core/api";
|
|
5
5
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
6
6
|
import { Credentials } from "./credentials.ts";
|
|
7
|
-
import { UnknownZendeskError } from "./errors.ts";
|
|
7
|
+
import { UnknownZendeskError, ZendeskParseError } from "./errors.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Error channel shared by every generated Zendesk operation. Generated
|
|
10
10
|
* service files annotate operations with `API.OperationMethod<I, O,
|
|
11
11
|
* ZendeskOpError, ZendeskOpContext>` explicitly so the compiler never infers
|
|
12
12
|
* these back out of the schema generics.
|
|
13
13
|
*/
|
|
14
|
-
export type ZendeskOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownZendeskError | ConfigError | HttpClientError.HttpClientError;
|
|
14
|
+
export type ZendeskOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownZendeskError | ConfigError | HttpClientError.HttpClientError | ZendeskParseError;
|
|
15
15
|
/** Context (requirements) shared by every generated Zendesk operation. */
|
|
16
16
|
export type ZendeskOpContext = Credentials | HttpClient.HttpClient;
|
|
17
17
|
export declare const ZendeskProtocol: Layer.Layer<API.Protocol>;
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAKtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,mBAAmB,GACnB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,iBAAiB,CAAC;AAEtB,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AA4BnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA0BlD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -18,7 +18,7 @@ import * as Effect from "effect/Effect";
|
|
|
18
18
|
import * as Redacted from "effect/Redacted";
|
|
19
19
|
import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
|
|
20
20
|
import { Credentials } from "./credentials.js";
|
|
21
|
-
import { UnknownZendeskError } from "./errors.js";
|
|
21
|
+
import { UnknownZendeskError, ZendeskParseError } from "./errors.js";
|
|
22
22
|
/**
|
|
23
23
|
* Zendesk error bodies are `{ error, description }` (sometimes `message`,
|
|
24
24
|
* sometimes `details`). A response that arrives without that envelope falls
|
|
@@ -66,5 +66,6 @@ export const ZendeskProtocol = makeRestProtocol({
|
|
|
66
66
|
message,
|
|
67
67
|
body,
|
|
68
68
|
}),
|
|
69
|
+
parseError: ({ body, cause }) => new ZendeskParseError({ body, cause }),
|
|
69
70
|
});
|
|
70
71
|
//# sourceMappingURL=protocol.js.map
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAkBrE;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,IAAa,EAAiC,EAAE;IACrE,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,CAAC,GAAG,IAA+B,CAAC;IAC1C,MAAM,IAAI,GACR,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;QAC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BAAmB,CAAC;QACtB,IAAI,EACF,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,KAAK,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;IACJ,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CACxE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA4CpD,eAAO,MAAM,oBAAoB,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,cAAc,CAAC,GAC3E,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { fromApiToken } from "./credentials.js";
|
|
5
|
+
import { ZendeskParseError } from "./errors.js";
|
|
6
|
+
import * as Retry from "./retry.js";
|
|
7
|
+
import { countTickets } from "./services/zendesk.js";
|
|
8
|
+
// countTickets declares `{ count?: { value?: number; refreshed_at?: string } }`;
|
|
9
|
+
// every member is optional, so the mismatch is a wrong primitive type.
|
|
10
|
+
const run = (body) => runValidationModes(countTickets({}).pipe(Retry.none, Effect.provide(fromApiToken({
|
|
11
|
+
email: "test@example.com",
|
|
12
|
+
apiToken: "test",
|
|
13
|
+
subdomain: "acme",
|
|
14
|
+
}))), { body });
|
|
15
|
+
describe("Zendesk response validation", () => {
|
|
16
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
17
|
+
const body = { count: { value: 5, refreshed_at: "2026-01-01T00:00:00Z" } };
|
|
18
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
19
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
20
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
21
|
+
});
|
|
22
|
+
test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
|
|
23
|
+
const body = { count: { value: "five" } };
|
|
24
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
25
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
26
|
+
expect(strict._tag).toBe("Failure");
|
|
27
|
+
expect(strict.failure).toBeInstanceOf(ZendeskParseError);
|
|
28
|
+
});
|
|
29
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
30
|
+
const { lenient, strict } = await run("not json");
|
|
31
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
32
|
+
expect(strict._tag).toBe("Failure");
|
|
33
|
+
expect(strict.failure).toBeInstanceOf(ZendeskParseError);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
// ZendeskParseError is part of every operation's declared error type.
|
|
37
|
+
export const parseErrorIsDeclared = true;
|
|
38
|
+
//# sourceMappingURL=response-validation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.js","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAA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CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACxE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAErB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/zendesk",
|
|
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
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
import * as Effect from "effect/Effect";
|
|
18
18
|
import type * as Layer from "effect/Layer";
|
|
19
19
|
import * as Redacted from "effect/Redacted";
|
|
20
|
-
import type * as HttpClient from "effect/
|
|
21
|
-
import type * as HttpClientError from "effect/
|
|
20
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
21
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
22
22
|
import type * as API from "@distilled.cloud/core/api";
|
|
23
23
|
import {
|
|
24
24
|
makeRestProtocol,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from "@distilled.cloud/core/protocol-rest";
|
|
27
27
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
28
28
|
import { Credentials, type Config } from "./credentials.ts";
|
|
29
|
-
import { UnknownZendeskError } from "./errors.ts";
|
|
29
|
+
import { UnknownZendeskError, ZendeskParseError } from "./errors.ts";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Error channel shared by every generated Zendesk operation. Generated
|
|
@@ -38,7 +38,8 @@ export type ZendeskOpError =
|
|
|
38
38
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
39
39
|
| UnknownZendeskError
|
|
40
40
|
| ConfigError
|
|
41
|
-
| HttpClientError.HttpClientError
|
|
41
|
+
| HttpClientError.HttpClientError
|
|
42
|
+
| ZendeskParseError;
|
|
42
43
|
|
|
43
44
|
/** Context (requirements) shared by every generated Zendesk operation. */
|
|
44
45
|
export type ZendeskOpContext = Credentials | HttpClient.HttpClient;
|
|
@@ -94,4 +95,5 @@ export const ZendeskProtocol: Layer.Layer<API.Protocol> =
|
|
|
94
95
|
message,
|
|
95
96
|
body,
|
|
96
97
|
}),
|
|
98
|
+
parseError: ({ body, cause }) => new ZendeskParseError({ body, cause }),
|
|
97
99
|
});
|
|
@@ -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 { fromApiToken } from "./credentials.ts";
|
|
5
|
+
import { ZendeskParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { countTickets } from "./services/zendesk.ts";
|
|
8
|
+
import type { ZendeskOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// countTickets declares `{ count?: { value?: number; refreshed_at?: string } }`;
|
|
11
|
+
// every member is optional, so the mismatch is a wrong primitive type.
|
|
12
|
+
const run = (body: string) =>
|
|
13
|
+
runValidationModes(
|
|
14
|
+
countTickets({}).pipe(
|
|
15
|
+
Retry.none,
|
|
16
|
+
Effect.provide(
|
|
17
|
+
fromApiToken({
|
|
18
|
+
email: "test@example.com",
|
|
19
|
+
apiToken: "test",
|
|
20
|
+
subdomain: "acme",
|
|
21
|
+
}),
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
{ body },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
describe("Zendesk response validation", () => {
|
|
28
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
29
|
+
const body = { count: { value: 5, refreshed_at: "2026-01-01T00:00:00Z" } };
|
|
30
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
31
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
32
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
|
|
36
|
+
const body = { count: { value: "five" } };
|
|
37
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
38
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
39
|
+
expect(strict._tag).toBe("Failure");
|
|
40
|
+
expect((strict as any).failure).toBeInstanceOf(ZendeskParseError);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
44
|
+
const { lenient, strict } = await run("not json");
|
|
45
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
46
|
+
expect(strict._tag).toBe("Failure");
|
|
47
|
+
expect((strict as any).failure).toBeInstanceOf(ZendeskParseError);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ZendeskParseError is part of every operation's declared error type.
|
|
52
|
+
export const parseErrorIsDeclared: [ZendeskParseError] extends [ZendeskOpError]
|
|
53
|
+
? true
|
|
54
|
+
: false = true;
|