@distilled.cloud/resend 0.0.0 → 1.0.0-rc.9

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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/lib/credentials.d.ts +28 -0
  3. package/lib/credentials.d.ts.map +1 -0
  4. package/lib/credentials.js +34 -0
  5. package/lib/credentials.js.map +1 -0
  6. package/lib/errors.d.ts +36 -0
  7. package/lib/errors.d.ts.map +1 -0
  8. package/lib/errors.js +26 -0
  9. package/lib/errors.js.map +1 -0
  10. package/lib/index.d.ts +23 -0
  11. package/lib/index.d.ts.map +1 -0
  12. package/lib/index.js +27 -0
  13. package/lib/index.js.map +1 -0
  14. package/lib/pagination.d.ts +8 -0
  15. package/lib/pagination.d.ts.map +1 -0
  16. package/lib/pagination.js +50 -0
  17. package/lib/pagination.js.map +1 -0
  18. package/lib/protocol.d.ts +18 -0
  19. package/lib/protocol.d.ts.map +1 -0
  20. package/lib/protocol.js +60 -0
  21. package/lib/protocol.js.map +1 -0
  22. package/lib/retry.d.ts +32 -0
  23. package/lib/retry.d.ts.map +1 -0
  24. package/lib/retry.js +32 -0
  25. package/lib/retry.js.map +1 -0
  26. package/lib/services/index.d.ts +2 -0
  27. package/lib/services/index.d.ts.map +1 -0
  28. package/lib/services/index.js +3 -0
  29. package/lib/services/index.js.map +1 -0
  30. package/lib/services/resend.d.ts +2617 -0
  31. package/lib/services/resend.d.ts.map +1 -0
  32. package/lib/services/resend.js +2428 -0
  33. package/lib/services/resend.js.map +1 -0
  34. package/lib/traits.d.ts +11 -0
  35. package/lib/traits.d.ts.map +1 -0
  36. package/lib/traits.js +11 -0
  37. package/lib/traits.js.map +1 -0
  38. package/package.json +77 -6
  39. package/src/credentials.ts +56 -0
  40. package/src/errors.ts +50 -0
  41. package/src/index.ts +30 -0
  42. package/src/pagination.ts +64 -0
  43. package/src/protocol.ts +82 -0
  44. package/src/retry.ts +54 -0
  45. package/src/services/index.ts +2 -0
  46. package/src/services/resend.ts +6168 -0
  47. package/src/traits.ts +44 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * ResendProtocol — hand-written.
3
+ *
4
+ * Resend speaks plain bearer-authenticated JSON REST (no response envelope),
5
+ * so the whole protocol is one `makeRestProtocol` call from
6
+ * `core/protocol-rest`:
7
+ *
8
+ * request: credentials → `Authorization: Bearer <apiKey>` + base URL
9
+ * (default https://api.resend.com), resolved from the
10
+ * calling fiber on every request
11
+ *
12
+ * response: 2xx JSON is the payload (sensitive members delivered as
13
+ * `Redacted`); non-2xx `{ name?, message, statusCode? }` bodies
14
+ * map to the operation's typed error classes by status, then the
15
+ * shared HTTP-status classes, then {@link UnknownResendError}.
16
+ */
17
+ import * as Effect from "effect/Effect";
18
+ import type * as Layer from "effect/Layer";
19
+ import * as Redacted from "effect/Redacted";
20
+ import type * as HttpClient from "effect/unstable/http/HttpClient";
21
+ import type * as HttpClientError from "effect/unstable/http/HttpClientError";
22
+ import type * as API from "@distilled.cloud/core/api";
23
+ import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
24
+ import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
25
+ import { Credentials, type Config } from "./credentials.ts";
26
+ import { UnknownResendError } from "./errors.ts";
27
+
28
+ /**
29
+ * Error channel shared by every generated Resend operation. Generated service
30
+ * files annotate operations with `API.OperationMethod<I, O, ResendOpError,
31
+ * ResendOpContext>` explicitly so the compiler never infers these back out of
32
+ * the schema generics.
33
+ */
34
+ export type ResendOpError =
35
+ | InstanceType<(typeof API_ERRORS)[number]>
36
+ | UnknownResendError
37
+ | ConfigError
38
+ | HttpClientError.HttpClientError;
39
+
40
+ /** Context (requirements) shared by every generated Resend operation. */
41
+ export type ResendOpContext = Credentials | HttpClient.HttpClient;
42
+
43
+ export const ResendProtocol: Layer.Layer<API.Protocol> =
44
+ makeRestProtocol<Config>({
45
+ // The Credentials service holds an effect — resolving it here (per
46
+ // request, on the calling fiber) picks up context-provided credentials.
47
+ credentials: Effect.gen(function* () {
48
+ const resolve = yield* Credentials;
49
+ return yield* resolve;
50
+ }),
51
+ baseUrl: (creds) => creds.apiBaseUrl,
52
+ headers: (creds) => ({
53
+ Authorization: `Bearer ${Redacted.value(creds.apiKey)}`,
54
+ }),
55
+ // Resend's error body is `{ name?: string, message: string, statusCode?: number }`.
56
+ // The factory's default lenient envelope covers `{ code, message }`; `name`
57
+ // is the machine-readable code Resend actually sends.
58
+ errorEnvelope: (body) => {
59
+ if (body === null || typeof body !== "object") return undefined;
60
+ const rec = body as Record<string, unknown>;
61
+ const code =
62
+ typeof rec.name === "string"
63
+ ? rec.name
64
+ : typeof rec.code === "string"
65
+ ? rec.code
66
+ : undefined;
67
+ const message = typeof rec.message === "string" ? rec.message : undefined;
68
+ if (code === undefined && message === undefined) return undefined;
69
+ return { code, message };
70
+ },
71
+ unknownError: ({ code, message, body }) =>
72
+ new UnknownResendError({
73
+ code:
74
+ typeof code === "string"
75
+ ? code
76
+ : code !== undefined
77
+ ? String(code)
78
+ : undefined,
79
+ message,
80
+ body,
81
+ }),
82
+ });
package/src/retry.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Resend retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that generated operations
5
+ * wire into `API.make`. Callers can install a blanket retry policy at the
6
+ * layer level and have every Resend API call below it pick it up:
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import * as Resend from "@distilled.cloud/resend";
11
+ *
12
+ * myEffect.pipe(Resend.Retry.transient);
13
+ * Effect.provide(myEffect, Layer.succeed(Resend.Retry.Retry, customPolicy));
14
+ * ```
15
+ */
16
+ import * as Context from "effect/Context";
17
+ import * as Effect from "effect/Effect";
18
+ import * as Layer from "effect/Layer";
19
+ import {
20
+ type Policy,
21
+ throttlingFactory,
22
+ transientFactory,
23
+ } from "@distilled.cloud/core/retry";
24
+
25
+ export {
26
+ type Options,
27
+ type Factory,
28
+ type Policy,
29
+ makeDefault,
30
+ jittered,
31
+ capped,
32
+ throttlingOptions,
33
+ transientOptions,
34
+ throttlingFactory,
35
+ transientFactory,
36
+ } from "@distilled.cloud/core/retry";
37
+
38
+ /** Context tag for configuring retry behavior of Resend API calls. */
39
+ export class Retry extends Context.Service<Retry, Policy>()("ResendRetry") {}
40
+
41
+ /** Provides a custom retry policy to every Resend API call below it. */
42
+ export const policy = (optionsOrFactory: Policy) =>
43
+ Effect.provide(Layer.succeed(Retry, optionsOrFactory));
44
+
45
+ /** Disables all automatic retries. */
46
+ export const none = Effect.provide(
47
+ Layer.succeed(Retry, { while: () => false }),
48
+ );
49
+
50
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
51
+ export const throttling = policy(throttlingFactory);
52
+
53
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
54
+ export const transient = policy(transientFactory);
@@ -0,0 +1,2 @@
1
+ // AUTO-GENERATED by scripts/generate.ts. Do not edit.
2
+ export * as resend from "./resend.ts";