@automate.ax/integration-contracts 0.103.2 → 0.105.0

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.
@@ -138,19 +138,58 @@ const RAW_NOTION_EVENT_SCHEMA = z.discriminatedUnion("type", [
138
138
  })),
139
139
  ]);
140
140
  /** Exact current Notion webhook schema shared by ingress and triggers. */
141
- export const NOTION_EVENT_SCHEMA = RAW_NOTION_EVENT_SCHEMA;
141
+ export const NOTION_EVENT_SCHEMA = RAW_NOTION_EVENT_SCHEMA.transform(camelCaseNotionEvent);
142
+ /** Validates an already-normalized Notion webhook event for trigger delivery. */
143
+ export const NOTION_PUBLIC_EVENT_SCHEMA = z.custom((value) => typeof value === "object" &&
144
+ value !== null &&
145
+ "type" in value &&
146
+ typeof value.type === "string");
142
147
  /**
143
148
  * Runtime schema for one semantic Notion webhook event.
144
149
  *
145
150
  * @param type - Official event discriminant to require.
146
151
  */
147
152
  export function notionSemanticEventSchema(type) {
148
- return z.custom((value) => RAW_NOTION_EVENT_SCHEMA.safeParse(value).success &&
153
+ return z.custom((value) => NOTION_PUBLIC_EVENT_SCHEMA.safeParse(value).success &&
149
154
  typeof value === "object" &&
150
155
  value !== null &&
151
156
  "type" in value &&
152
157
  value.type === type, { message: `Expected a Notion ${type} webhook event.` });
153
158
  }
159
+ /**
160
+ * Converts provider-native webhook fields before public trigger delivery.
161
+ *
162
+ * @param event - Validated provider webhook payload.
163
+ */
164
+ function camelCaseNotionEvent(event) {
165
+ // REVIEW: the recursive transform preserves the raw schema's JSON structure
166
+ // while changing only property names.
167
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Raw schema validation guarantees this result's shape.
168
+ return camelCaseNotionValue(event);
169
+ }
170
+ /**
171
+ * Recursively camel-cases object property names in a JSON-compatible value.
172
+ *
173
+ * @param value - Provider-native JSON value.
174
+ */
175
+ function camelCaseNotionValue(value) {
176
+ if (Array.isArray(value))
177
+ return value.map(camelCaseNotionValue);
178
+ if (!isPlainRecord(value))
179
+ return value;
180
+ return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => [
181
+ key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()),
182
+ camelCaseNotionValue(nestedValue),
183
+ ]));
184
+ }
185
+ /**
186
+ * Checks whether a value can have provider field names.
187
+ *
188
+ * @param value - Value to inspect.
189
+ */
190
+ function isPlainRecord(value) {
191
+ return typeof value === "object" && value !== null;
192
+ }
154
193
  /**
155
194
  * Builds one provider webhook schema over the shared delivery envelope.
156
195
  *