@company-semantics/contracts 27.13.0 → 27.13.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "27.13.0",
3
+ "version": "27.13.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,10 +28,12 @@ function add<K extends ImplementedEmailKind>(
28
28
  payload: EmailPayloads[K],
29
29
  options?: RenderEmailOptions,
30
30
  ): void {
31
+ // `payload as never`: the add() call sites are type-checked (payload:
32
+ // EmailPayloads[K]); this only bridges the generic conditional in renderEmail.
31
33
  fixtures.push({
32
34
  kind,
33
35
  name,
34
- render: () => renderEmail(kind, payload, options),
36
+ render: () => renderEmail(kind, payload as never, options),
35
37
  });
36
38
  }
37
39
 
@@ -57,6 +57,7 @@ export {
57
57
  export {
58
58
  renderAuthOtpBody,
59
59
  renderAuthOtpHtml,
60
+ type AuthOtpPayload,
60
61
  type RenderOptions,
61
62
  } from "./auth-otp";
62
63
  export { renderOrgInviteBody, renderOrgInviteHtml } from "./org-invite";
@@ -68,15 +68,22 @@ export const IMPLEMENTED_EMAIL_KINDS = [
68
68
 
69
69
  export type ImplementedEmailKind = (typeof IMPLEMENTED_EMAIL_KINDS)[number];
70
70
 
71
+ /** Payload type for a kind (or `never` for kinds without a payload). */
72
+ type PayloadFor<K extends EmailKind> = K extends keyof EmailPayloads
73
+ ? EmailPayloads[K]
74
+ : never;
75
+
71
76
  /**
72
77
  * Render an email by kind. Subject comes from `EMAIL_KINDS`; `html` is present
73
- * only when the template emits an HTML variant.
78
+ * only when the template emits an HTML variant. Accepts the full `EmailKind`
79
+ * union so callers with a generic kind (e.g. the backend `EmailService`) type
80
+ * cleanly; unimplemented kinds throw at runtime.
74
81
  *
75
82
  * @throws if the kind has no implementation.
76
83
  */
77
- export function renderEmail<K extends ImplementedEmailKind>(
84
+ export function renderEmail<K extends EmailKind>(
78
85
  kind: K,
79
- payload: EmailPayloads[K],
86
+ payload: PayloadFor<K>,
80
87
  options?: RenderEmailOptions,
81
88
  ): RenderedEmail {
82
89
  const subject = EMAIL_KINDS[kind].subject;
@@ -159,8 +166,9 @@ export function renderEmail<K extends ImplementedEmailKind>(
159
166
  };
160
167
  }
161
168
  default: {
162
- const unimplemented: never = kind;
163
- throw new Error(`Email kind not implemented: ${String(unimplemented)}`);
169
+ // Reachable for registered-but-unimplemented kinds (e.g. auth.magic_link).
170
+ const unimplemented: string = kind;
171
+ throw new Error(`Email kind not implemented: ${unimplemented}`);
164
172
  }
165
173
  }
166
174
  }