@automate.ax/integration-contracts 0.147.1 → 0.148.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.
@@ -0,0 +1,93 @@
1
+ /* oxlint-disable typescript/no-unsafe-type-assertion -- Generated operation keys index a frozen external contract. */
2
+ import { Validator } from "@cfworker/json-schema"
3
+ import * as z from "zod"
4
+ import { KIT_OPENAPI_DATA } from "./openapi-operations.generated"
5
+ import type { KitOperationKey } from "./operation-manifest"
6
+ import type { KitOperationInput, KitOperationOutput } from "./types"
7
+
8
+ export interface KitRuntimeParameter {
9
+ explode: boolean
10
+ name: string
11
+ providerName: string
12
+ style: string
13
+ }
14
+
15
+ /** Frozen runtime description of one public Kit operation. */
16
+ export interface KitRuntimeOperation {
17
+ bodyParameters: string[]
18
+ bodyWireSchema?: Record<string, unknown>
19
+ inputSchema: Record<string, unknown>
20
+ method: "DELETE" | "GET" | "PATCH" | "POST" | "PUT"
21
+ outputSchema: Record<string, unknown>
22
+ outputWireSchema: Record<string, unknown>
23
+ path: string
24
+ pathParameters: KitRuntimeParameter[]
25
+ queryParameters: KitRuntimeParameter[]
26
+ responseMode: "json" | "void"
27
+ }
28
+
29
+ /** Runtime Kit contract narrowed once from the opaque generated payload. */
30
+ const operationData = KIT_OPENAPI_DATA as {
31
+ definitions: Record<string, Record<string, unknown>>
32
+ operations: Record<string, unknown>
33
+ wireDefinitions: Record<string, Record<string, unknown>>
34
+ }
35
+ const OPERATIONS = operationData.operations as unknown as Record<
36
+ KitOperationKey,
37
+ KitRuntimeOperation
38
+ >
39
+ const VALIDATOR = new Validator(
40
+ {
41
+ $defs: operationData.definitions,
42
+ $schema: "https://json-schema.org/draft/2020-12/schema",
43
+ additionalProperties: false,
44
+ properties: Object.fromEntries(
45
+ Object.entries(OPERATIONS).flatMap(([key, operation]) => [
46
+ [`${key}:input`, operation.inputSchema],
47
+ [`${key}:output`, operation.outputSchema],
48
+ ]),
49
+ ),
50
+ type: "object",
51
+ },
52
+ "2020-12",
53
+ )
54
+
55
+ /**
56
+ * Returns the immutable runtime descriptor for one Kit operation.
57
+ *
58
+ * @param key Public operation name.
59
+ */
60
+ export function kitOperation<TKey extends KitOperationKey>(key: TKey) {
61
+ return OPERATIONS[key]
62
+ }
63
+
64
+ /**
65
+ * Validates flattened public input for one Kit operation.
66
+ *
67
+ * @param key Public operation name.
68
+ */
69
+ export function kitOperationInputSchema<TKey extends KitOperationKey>(
70
+ key: TKey,
71
+ ): z.ZodType<KitOperationInput<TKey>> {
72
+ return z.custom<KitOperationInput<TKey>>(
73
+ (value) => VALIDATOR.validate({ [`${key}:input`]: value }).valid,
74
+ { message: `Input does not match Kit operation ${key}.` },
75
+ )
76
+ }
77
+
78
+ /**
79
+ * Validates a public successful response for one Kit operation.
80
+ *
81
+ * @param key Public operation name.
82
+ */
83
+ export function kitOperationOutputSchema<TKey extends KitOperationKey>(
84
+ key: TKey,
85
+ ): z.ZodType<KitOperationOutput<TKey>> {
86
+ return z.custom<KitOperationOutput<TKey>>(
87
+ (value) => VALIDATOR.validate({ [`${key}:output`]: value }).valid,
88
+ { message: `Output does not match Kit operation ${key}.` },
89
+ )
90
+ }
91
+
92
+ /** Provider-native component schemas used for schema-guided key mapping. */
93
+ export const KIT_WIRE_DEFINITIONS = operationData.wireDefinitions
@@ -0,0 +1,87 @@
1
+ import type { Encodable } from "@automate.ax/codec"
2
+ import type { KitOperationMap } from "./openapi-types.generated"
3
+ import type { KitOperationKey } from "./operation-manifest"
4
+
5
+ type Operation<TKey extends KitOperationKey> =
6
+ TKey extends keyof KitOperationMap ? KitOperationMap[TKey] : never
7
+
8
+ /** Converts absent generated operation sections into intersection identities. */
9
+ type InputPart<TValue> = [NonNullable<TValue>] extends [never]
10
+ ? unknown
11
+ : NonNullable<TValue>
12
+
13
+ type Parameters<TOperation, TLocation extends string> = TOperation extends {
14
+ parameters?: infer TParameters
15
+ }
16
+ ? TLocation extends keyof NonNullable<TParameters>
17
+ ? InputPart<NonNullable<TParameters>[TLocation]>
18
+ : unknown
19
+ : unknown
20
+
21
+ /** Extracts the JSON request body from one generated operation. */
22
+ type JsonBody<TOperation> = TOperation extends { requestBody?: infer TBody }
23
+ ? [NonNullable<TBody>] extends [never]
24
+ ? unknown
25
+ : NonNullable<TBody> extends { content: infer TContent }
26
+ ? "application/json" extends keyof TContent
27
+ ? TContent["application/json"]
28
+ : unknown
29
+ : unknown
30
+ : unknown
31
+
32
+ /** Extracts the JSON response body from one generated response. */
33
+ type JsonResponse<TResponse> = TResponse extends { content: infer TContent }
34
+ ? "application/json" extends keyof TContent
35
+ ? TContent["application/json"]
36
+ : object
37
+ : object
38
+
39
+ /** Extracts the union of successful generated operation responses. */
40
+ type SuccessResponse<TOperation> = TOperation extends {
41
+ responses: infer TResponses
42
+ }
43
+ ? JsonResponse<
44
+ TResponses[Extract<keyof TResponses, 200 | 201 | 202 | 203 | 204>]
45
+ >
46
+ : never
47
+
48
+ /** Materializes an intersection as one readable object type. */
49
+ type Simplify<TValue> = { [TKey in keyof TValue]: TValue[TKey] } & {}
50
+
51
+ type EncodableValue<TValue> = unknown extends TValue
52
+ ? Encodable
53
+ : TValue extends undefined | null | boolean | number | string
54
+ ? TValue
55
+ : TValue extends readonly (infer TItem)[]
56
+ ? EncodableValue<TItem>[]
57
+ : TValue extends object
58
+ ? keyof TValue extends never
59
+ ? Record<string, Encodable>
60
+ : { [TKey in keyof TValue]: EncodableValue<TValue[TKey]> }
61
+ : never
62
+
63
+ /** Flattens one generated operation's path, query, and body fields. */
64
+ type RawKitOperationInput<TKey extends KitOperationKey> = Simplify<
65
+ Parameters<Operation<TKey>, "path"> &
66
+ Parameters<Operation<TKey>, "query"> &
67
+ JsonBody<Operation<TKey>>
68
+ >
69
+
70
+ /** Preserves operation unions and rejects fields on truly empty inputs. */
71
+ type PublicInput<TValue> = TValue extends unknown
72
+ ? keyof TValue extends never
73
+ ? Record<string, never>
74
+ : {
75
+ [TField in keyof TValue]: EncodableValue<TValue[TField]>
76
+ }
77
+ : never
78
+
79
+ /** Flattened camelCase input for one frozen Kit V4 operation. */
80
+ export type KitOperationInput<TKey extends KitOperationKey> = PublicInput<
81
+ RawKitOperationInput<TKey>
82
+ >
83
+
84
+ /** CamelCase successful response for one frozen Kit V4 operation. */
85
+ export type KitOperationOutput<TKey extends KitOperationKey> = EncodableValue<
86
+ SuccessResponse<Operation<TKey>>
87
+ >
package/src/triggers.ts CHANGED
@@ -22,6 +22,7 @@ import type { googleAdsTriggerContracts } from "./google-ads"
22
22
  import type { googleSheetsTriggerContracts } from "./google-sheets"
23
23
  import type { hubspotTriggerContracts } from "./hubspot"
24
24
  import type { highLevelTriggerContracts } from "./highlevel"
25
+ import type { kitTriggerContracts } from "./kit"
25
26
  import type { linearTriggerContracts } from "./linear"
26
27
  import type { millionVerifierTriggerContracts } from "./millionverifier"
27
28
  import type { metaAdsTriggerContracts } from "./meta-ads"
@@ -63,6 +64,7 @@ export type TriggerContractMap = typeof airtableTriggerContracts &
63
64
  typeof googleSheetsTriggerContracts &
64
65
  typeof hubspotTriggerContracts &
65
66
  typeof highLevelTriggerContracts &
67
+ typeof kitTriggerContracts &
66
68
  typeof linearTriggerContracts &
67
69
  typeof millionVerifierTriggerContracts &
68
70
  typeof metaAdsTriggerContracts &