@distilled.cloud/zendesk 1.0.0-rc.13 → 1.0.0-rc.14

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/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@distilled.cloud/zendesk",
3
- "version": "1.0.0-rc.13",
3
+ "version": "1.0.0-rc.14",
4
+ "license": "Apache-2.0",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/alchemy-run/distilled",
7
8
  "directory": "packages/zendesk"
8
9
  },
9
- "license": "Apache-2.0",
10
- "type": "module",
11
- "sideEffects": false,
12
10
  "files": [
13
11
  "lib",
14
12
  "src"
15
13
  ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./lib/index.d.ts",
@@ -64,20 +64,22 @@
64
64
  }
65
65
  },
66
66
  "dependencies": {
67
- "@distilled.cloud/core": "1.0.0-rc.13"
67
+ "@distilled.cloud/core": "1.0.0-rc.14"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/bun": "1.3.14",
71
- "@types/node": "26.2.0",
72
- "@effect/platform-bun": "^4.0.0"
70
+ "@types/node": "26.2.0"
73
71
  },
74
72
  "peerDependencies": {
75
73
  "effect": "^4.0.0"
76
74
  },
75
+ "distilled": {
76
+ "generatedAt": "2026-10-06",
77
+ "specUpdatedAt": "2026-10-06"
78
+ },
77
79
  "scripts": {
78
80
  "build": "tsc -b",
79
- "convert": "bun scripts/convert.ts",
80
- "generate": "bun scripts/convert.ts && bun scripts/generate.ts",
81
+ "convert": "node --conditions=bun scripts/convert.ts",
82
+ "generate": "node --conditions=bun scripts/convert.ts && node --conditions=bun scripts/generate.ts",
81
83
  "typecheck": "tsc -p tsconfig.json",
82
84
  "specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-zendesk",
83
85
  "specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-zendesk"
@@ -1,3 +1,4 @@
1
+ import { ConfigError } from "@distilled.cloud/core/errors";
1
2
  /**
2
3
  * Zendesk credentials — hand-written.
3
4
  *
@@ -16,17 +17,15 @@ import * as Context from "effect/Context";
16
17
  import * as Effect from "effect/Effect";
17
18
  import * as Layer from "effect/Layer";
18
19
  import * as Redacted from "effect/Redacted";
19
- import { ConfigError } from "@distilled.cloud/core/errors";
20
20
 
21
21
  export interface Config {
22
22
  readonly authorization: Redacted.Redacted<string>;
23
23
  readonly apiBaseUrl: string;
24
24
  }
25
25
 
26
- export class Credentials extends Context.Service<
27
- Credentials,
28
- Effect.Effect<Config>
29
- >()("ZendeskCredentials") {}
26
+ export class Credentials extends Context.Service<Credentials, Effect.Effect<Config>>()(
27
+ "ZendeskCredentials",
28
+ ) {}
30
29
 
31
30
  const stripTrailingSlash = (url: string): string => url.replace(/\/+$/, "");
32
31
 
@@ -40,8 +39,14 @@ export const originFromSubdomain = (subdomain: string): string => {
40
39
  return `https://${host}.zendesk.com`;
41
40
  };
42
41
 
43
- const basicToken = (email: string, apiToken: string): string =>
44
- `Basic ${btoa(`${email}/token:${apiToken}`)}`;
42
+ const basicToken = (
43
+ email: string,
44
+ apiToken: Redacted.Redacted<string>,
45
+ ): Redacted.Redacted<string> =>
46
+ Redacted.make(`Basic ${btoa(`${email}/token:${Redacted.value(apiToken)}`)}`);
47
+
48
+ const bearerToken = (accessToken: Redacted.Redacted<string>): Redacted.Redacted<string> =>
49
+ Redacted.make(`Bearer ${Redacted.value(accessToken)}`);
45
50
 
46
51
  const resolveBaseUrl = (config: {
47
52
  readonly subdomain?: string;
@@ -55,28 +60,28 @@ const resolveBaseUrl = (config: {
55
60
  /** Layer from an API token (`{email}/token`) + subdomain. */
56
61
  export const fromApiToken = (config: {
57
62
  readonly email: string;
58
- readonly apiToken: string;
63
+ readonly apiToken: Redacted.Redacted<string>;
59
64
  readonly subdomain?: string;
60
65
  readonly apiBaseUrl?: string;
61
66
  }): Layer.Layer<Credentials> =>
62
67
  Layer.succeed(
63
68
  Credentials,
64
69
  Effect.succeed({
65
- authorization: Redacted.make(basicToken(config.email, config.apiToken)),
70
+ authorization: basicToken(config.email, config.apiToken),
66
71
  apiBaseUrl: resolveBaseUrl(config),
67
72
  }),
68
73
  );
69
74
 
70
75
  /** Layer from an OAuth access token + subdomain. */
71
76
  export const fromAccessToken = (config: {
72
- readonly accessToken: string;
77
+ readonly accessToken: Redacted.Redacted<string>;
73
78
  readonly subdomain?: string;
74
79
  readonly apiBaseUrl?: string;
75
80
  }): Layer.Layer<Credentials> =>
76
81
  Layer.succeed(
77
82
  Credentials,
78
83
  Effect.succeed({
79
- authorization: Redacted.make(`Bearer ${config.accessToken}`),
84
+ authorization: bearerToken(config.accessToken),
80
85
  apiBaseUrl: resolveBaseUrl(config),
81
86
  }),
82
87
  );
@@ -91,23 +96,22 @@ export const CredentialsFromEnv: Layer.Layer<Credentials> = Layer.succeed(
91
96
  const subdomain = process.env.ZENDESK_SUBDOMAIN;
92
97
  const apiBaseUrl = process.env.ZENDESK_API_BASE_URL;
93
98
  const email = process.env.ZENDESK_EMAIL;
94
- const apiToken = process.env.ZENDESK_API_TOKEN;
95
- const accessToken = process.env.ZENDESK_ACCESS_TOKEN;
99
+ const apiTokenEnv = process.env.ZENDESK_API_TOKEN;
100
+ const apiToken = apiTokenEnv ? Redacted.make(apiTokenEnv) : undefined;
101
+ const accessTokenEnv = process.env.ZENDESK_ACCESS_TOKEN;
102
+ const accessToken = accessTokenEnv ? Redacted.make(accessTokenEnv) : undefined;
96
103
 
97
104
  if (!subdomain && !apiBaseUrl) {
98
105
  return yield* new ConfigError({
99
- message:
100
- "ZENDESK_SUBDOMAIN (or ZENDESK_API_BASE_URL) environment variable is required",
106
+ message: "ZENDESK_SUBDOMAIN (or ZENDESK_API_BASE_URL) environment variable is required",
101
107
  });
102
108
  }
103
109
 
104
- const origin = apiBaseUrl
105
- ? stripTrailingSlash(apiBaseUrl)
106
- : originFromSubdomain(subdomain!);
110
+ const origin = apiBaseUrl ? stripTrailingSlash(apiBaseUrl) : originFromSubdomain(subdomain!);
107
111
 
108
112
  if (accessToken) {
109
113
  return {
110
- authorization: Redacted.make(`Bearer ${accessToken}`),
114
+ authorization: bearerToken(accessToken),
111
115
  apiBaseUrl: origin,
112
116
  };
113
117
  }
@@ -120,7 +124,7 @@ export const CredentialsFromEnv: Layer.Layer<Credentials> = Layer.succeed(
120
124
  }
121
125
 
122
126
  return {
123
- authorization: Redacted.make(basicToken(email, apiToken)),
127
+ authorization: basicToken(email, apiToken),
124
128
  apiBaseUrl: origin,
125
129
  };
126
130
  }).pipe(Effect.orDie),
package/src/errors.ts CHANGED
@@ -27,8 +27,8 @@ export {
27
27
  } from "@distilled.cloud/core/errors";
28
28
  export type { DefaultErrors } from "@distilled.cloud/core/errors";
29
29
 
30
- import * as Schema from "effect/Schema";
31
30
  import * as Category from "@distilled.cloud/core/category";
31
+ import * as Schema from "effect/Schema";
32
32
 
33
33
  /** Unknown Zendesk error — returned when nothing else matches the failure. */
34
34
  export class UnknownZendeskError extends Schema.TaggedError<UnknownZendeskError>()(
package/src/index.ts CHANGED
@@ -15,11 +15,7 @@
15
15
  export * from "./credentials.ts";
16
16
  export * from "./errors.ts";
17
17
  export * as T from "./traits.ts";
18
- export {
19
- ZendeskProtocol,
20
- type ZendeskOpError,
21
- type ZendeskOpContext,
22
- } from "./protocol.ts";
18
+ export { ZendeskProtocol, type ZendeskOpError, type ZendeskOpContext } from "./protocol.ts";
23
19
  export { paginateCursor, paginatePageNumber } from "./pagination.ts";
24
20
  export * as Retry from "./retry.ts";
25
21
  export * as Services from "./services/index.ts";
package/src/pagination.ts CHANGED
@@ -6,7 +6,4 @@
6
6
  * the converter stamps as paginated pass core's {@link paginateCursor} or
7
7
  * {@link paginatePageNumber} strategy to `API.makePaginated`.
8
8
  */
9
- export {
10
- paginateCursor,
11
- paginatePageNumber,
12
- } from "@distilled.cloud/core/pagination";
9
+ export { paginateCursor, paginatePageNumber } from "@distilled.cloud/core/pagination";
package/src/protocol.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type * as API from "@distilled.cloud/core/api";
2
+ import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
3
+ import { makeRestProtocol, type RestErrorEnvelope } from "@distilled.cloud/core/protocol-rest";
1
4
  /**
2
5
  * ZendeskProtocol — hand-written.
3
6
  *
@@ -15,16 +18,10 @@
15
18
  * HTTP-status classes, then {@link UnknownZendeskError}.
16
19
  */
17
20
  import * as Effect from "effect/Effect";
18
- import type * as Layer from "effect/Layer";
19
- import * as Redacted from "effect/Redacted";
20
21
  import type * as HttpClient from "effect/http/HttpClient";
21
22
  import type * as HttpClientError from "effect/http/HttpClientError";
22
- import type * as API from "@distilled.cloud/core/api";
23
- import {
24
- makeRestProtocol,
25
- type RestErrorEnvelope,
26
- } from "@distilled.cloud/core/protocol-rest";
27
- import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
23
+ import type * as Layer from "effect/Layer";
24
+ import * as Redacted from "effect/Redacted";
28
25
  import { Credentials, type Config } from "./credentials.ts";
29
26
  import { UnknownZendeskError, ZendeskParseError } from "./errors.ts";
30
27
 
@@ -70,30 +67,24 @@ const errorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
70
67
  return { code, message };
71
68
  };
72
69
 
73
- export const ZendeskProtocol: Layer.Layer<API.Protocol> =
74
- makeRestProtocol<Config>({
75
- // The Credentials service holds an effect — resolving it here (per
76
- // request, on the calling fiber) picks up context-provided credentials.
77
- credentials: Effect.gen(function* () {
78
- const resolve = yield* Credentials;
79
- return yield* resolve;
80
- }),
81
- baseUrl: (creds) => creds.apiBaseUrl,
82
- headers: (creds) => ({
83
- Authorization: Redacted.value(creds.authorization),
84
- Accept: "application/json",
70
+ export const ZendeskProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>({
71
+ // The Credentials service holds an effect — resolving it here (per
72
+ // request, on the calling fiber) picks up context-provided credentials.
73
+ credentials: Effect.gen(function* () {
74
+ const resolve = yield* Credentials;
75
+ return yield* resolve;
76
+ }),
77
+ baseUrl: (creds) => creds.apiBaseUrl,
78
+ headers: (creds) => ({
79
+ Authorization: Redacted.value(creds.authorization),
80
+ Accept: "application/json",
81
+ }),
82
+ errorEnvelope,
83
+ unknownError: ({ code, message, body }) =>
84
+ new UnknownZendeskError({
85
+ code: typeof code === "string" ? code : code !== undefined ? String(code) : undefined,
86
+ message,
87
+ body,
85
88
  }),
86
- errorEnvelope,
87
- unknownError: ({ code, message, body }) =>
88
- new UnknownZendeskError({
89
- code:
90
- typeof code === "string"
91
- ? code
92
- : code !== undefined
93
- ? String(code)
94
- : undefined,
95
- message,
96
- body,
97
- }),
98
- parseError: ({ body, cause }) => new ZendeskParseError({ body, cause }),
99
- });
89
+ parseError: ({ body, cause }) => new ZendeskParseError({ body, cause }),
90
+ });
package/src/retry.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
1
2
  /**
2
3
  * Zendesk retry configuration.
3
4
  *
@@ -16,11 +17,6 @@
16
17
  import * as Context from "effect/Context";
17
18
  import * as Effect from "effect/Effect";
18
19
  import * as Layer from "effect/Layer";
19
- import {
20
- type Policy,
21
- throttlingFactory,
22
- transientFactory,
23
- } from "@distilled.cloud/core/retry";
24
20
 
25
21
  export {
26
22
  type Options,
@@ -43,9 +39,7 @@ export const policy = (optionsOrFactory: Policy) =>
43
39
  Effect.provide(Layer.succeed(Retry, optionsOrFactory));
44
40
 
45
41
  /** Disables all automatic retries. */
46
- export const none = Effect.provide(
47
- Layer.succeed(Retry, { while: () => false }),
48
- );
42
+ export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
49
43
 
50
44
  /** Apply the throttling retry policy (retries throttling errors indefinitely). */
51
45
  export const throttling = policy(throttlingFactory);