@superblocksteam/sdk-api 2.0.105 → 2.0.106-next.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.
Files changed (182) hide show
  1. package/README.md +439 -89
  2. package/dist/api/definition.d.ts +11 -6
  3. package/dist/api/definition.d.ts.map +1 -1
  4. package/dist/api/definition.js +19 -12
  5. package/dist/api/definition.js.map +1 -1
  6. package/dist/api/definition.test.js +39 -15
  7. package/dist/api/definition.test.js.map +1 -1
  8. package/dist/errors.d.ts +1 -1
  9. package/dist/errors.js +1 -1
  10. package/dist/index.d.ts +10 -11
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +9 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/integrations/base/index.d.ts +2 -1
  15. package/dist/integrations/base/index.d.ts.map +1 -1
  16. package/dist/integrations/base/index.js +1 -0
  17. package/dist/integrations/base/index.js.map +1 -1
  18. package/dist/integrations/base/rest-api-client-base.d.ts +48 -0
  19. package/dist/integrations/base/rest-api-client-base.d.ts.map +1 -0
  20. package/dist/integrations/base/rest-api-client-base.js +98 -0
  21. package/dist/integrations/base/rest-api-client-base.js.map +1 -0
  22. package/dist/integrations/base/rest-api-integration-client.d.ts +10 -20
  23. package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
  24. package/dist/integrations/base/rest-api-integration-client.js +10 -65
  25. package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
  26. package/dist/integrations/box/types.d.ts +1 -1
  27. package/dist/integrations/declarations.d.ts +5 -73
  28. package/dist/integrations/declarations.d.ts.map +1 -1
  29. package/dist/integrations/declarations.js +5 -68
  30. package/dist/integrations/declarations.js.map +1 -1
  31. package/dist/integrations/documentation.test.js +0 -2
  32. package/dist/integrations/documentation.test.js.map +1 -1
  33. package/dist/integrations/googledrive/types.d.ts +1 -1
  34. package/dist/integrations/index.d.ts +1 -11
  35. package/dist/integrations/index.d.ts.map +1 -1
  36. package/dist/integrations/index.js +1 -7
  37. package/dist/integrations/index.js.map +1 -1
  38. package/dist/integrations/registry.d.ts +1 -11
  39. package/dist/integrations/registry.d.ts.map +1 -1
  40. package/dist/integrations/registry.js +0 -29
  41. package/dist/integrations/registry.js.map +1 -1
  42. package/dist/integrations/slack/client.d.ts +13 -9
  43. package/dist/integrations/slack/client.d.ts.map +1 -1
  44. package/dist/integrations/slack/client.js +60 -8
  45. package/dist/integrations/slack/client.js.map +1 -1
  46. package/dist/integrations/slack/client.test.d.ts +11 -0
  47. package/dist/integrations/slack/client.test.d.ts.map +1 -0
  48. package/dist/integrations/slack/client.test.js +368 -0
  49. package/dist/integrations/slack/client.test.js.map +1 -0
  50. package/dist/integrations/slack/index.d.ts +2 -1
  51. package/dist/integrations/slack/index.d.ts.map +1 -1
  52. package/dist/integrations/slack/index.js +1 -0
  53. package/dist/integrations/slack/index.js.map +1 -1
  54. package/dist/integrations/slack/types.d.ts +127 -28
  55. package/dist/integrations/slack/types.d.ts.map +1 -1
  56. package/dist/integrations/slack/types.js +27 -1
  57. package/dist/integrations/slack/types.js.map +1 -1
  58. package/dist/integrations/snowflake/client.d.ts +2 -2
  59. package/dist/integrations/snowflake/client.js +2 -2
  60. package/dist/runtime/context.d.ts +1 -1
  61. package/dist/runtime/executor.d.ts +2 -2
  62. package/dist/types.d.ts +15 -6
  63. package/dist/types.d.ts.map +1 -1
  64. package/package.json +2 -2
  65. package/src/api/definition.test.ts +40 -15
  66. package/src/api/definition.ts +19 -12
  67. package/src/errors.ts +1 -1
  68. package/src/index.ts +13 -33
  69. package/src/integrations/asana/README.md +12 -12
  70. package/src/integrations/base/index.ts +2 -1
  71. package/src/integrations/base/rest-api-client-base.ts +134 -0
  72. package/src/integrations/base/rest-api-integration-client.ts +12 -89
  73. package/src/integrations/bitbucket/README.md +19 -19
  74. package/src/integrations/box/README.md +24 -24
  75. package/src/integrations/box/types.ts +1 -1
  76. package/src/integrations/circleci/README.md +18 -18
  77. package/src/integrations/declarations.ts +5 -105
  78. package/src/integrations/documentation.test.ts +0 -2
  79. package/src/integrations/googledrive/README.md +25 -22
  80. package/src/integrations/googledrive/types.ts +1 -1
  81. package/src/integrations/graphql/README.md +2 -2
  82. package/src/integrations/groq/README.md +8 -8
  83. package/src/integrations/index.ts +0 -51
  84. package/src/integrations/mongodb/README.md +65 -12
  85. package/src/integrations/perplexity/README.md +39 -48
  86. package/src/integrations/registry.ts +1 -39
  87. package/src/integrations/salesforce/README.md +11 -9
  88. package/src/integrations/slack/README.md +62 -19
  89. package/src/integrations/slack/client.test.ts +553 -0
  90. package/src/integrations/slack/client.ts +92 -12
  91. package/src/integrations/slack/index.ts +6 -1
  92. package/src/integrations/slack/types.ts +142 -29
  93. package/src/integrations/snowflake/client.ts +2 -2
  94. package/src/integrations/zoom/README.md +15 -15
  95. package/src/runtime/context.ts +1 -1
  96. package/src/runtime/executor.ts +2 -2
  97. package/src/types.ts +15 -6
  98. package/dist/integrations/couchbase/client.d.ts +0 -36
  99. package/dist/integrations/couchbase/client.d.ts.map +0 -1
  100. package/dist/integrations/couchbase/client.js +0 -148
  101. package/dist/integrations/couchbase/client.js.map +0 -1
  102. package/dist/integrations/couchbase/index.d.ts +0 -8
  103. package/dist/integrations/couchbase/index.d.ts.map +0 -1
  104. package/dist/integrations/couchbase/index.js +0 -7
  105. package/dist/integrations/couchbase/index.js.map +0 -1
  106. package/dist/integrations/couchbase/types.d.ts +0 -100
  107. package/dist/integrations/couchbase/types.d.ts.map +0 -1
  108. package/dist/integrations/couchbase/types.js +0 -5
  109. package/dist/integrations/couchbase/types.js.map +0 -1
  110. package/dist/integrations/kafka/client.d.ts +0 -25
  111. package/dist/integrations/kafka/client.d.ts.map +0 -1
  112. package/dist/integrations/kafka/client.js +0 -124
  113. package/dist/integrations/kafka/client.js.map +0 -1
  114. package/dist/integrations/kafka/index.d.ts +0 -8
  115. package/dist/integrations/kafka/index.d.ts.map +0 -1
  116. package/dist/integrations/kafka/index.js +0 -7
  117. package/dist/integrations/kafka/index.js.map +0 -1
  118. package/dist/integrations/kafka/types.d.ts +0 -113
  119. package/dist/integrations/kafka/types.d.ts.map +0 -1
  120. package/dist/integrations/kafka/types.js +0 -5
  121. package/dist/integrations/kafka/types.js.map +0 -1
  122. package/dist/integrations/kinesis/client.d.ts +0 -31
  123. package/dist/integrations/kinesis/client.d.ts.map +0 -1
  124. package/dist/integrations/kinesis/client.js +0 -101
  125. package/dist/integrations/kinesis/client.js.map +0 -1
  126. package/dist/integrations/kinesis/index.d.ts +0 -8
  127. package/dist/integrations/kinesis/index.d.ts.map +0 -1
  128. package/dist/integrations/kinesis/index.js +0 -7
  129. package/dist/integrations/kinesis/index.js.map +0 -1
  130. package/dist/integrations/kinesis/types.d.ts +0 -97
  131. package/dist/integrations/kinesis/types.d.ts.map +0 -1
  132. package/dist/integrations/kinesis/types.js +0 -7
  133. package/dist/integrations/kinesis/types.js.map +0 -1
  134. package/dist/integrations/python/client.d.ts +0 -42
  135. package/dist/integrations/python/client.d.ts.map +0 -1
  136. package/dist/integrations/python/client.js +0 -89
  137. package/dist/integrations/python/client.js.map +0 -1
  138. package/dist/integrations/python/client.test.d.ts +0 -5
  139. package/dist/integrations/python/client.test.d.ts.map +0 -1
  140. package/dist/integrations/python/client.test.js +0 -214
  141. package/dist/integrations/python/client.test.js.map +0 -1
  142. package/dist/integrations/python/index.d.ts +0 -6
  143. package/dist/integrations/python/index.d.ts.map +0 -1
  144. package/dist/integrations/python/index.js +0 -5
  145. package/dist/integrations/python/index.js.map +0 -1
  146. package/dist/integrations/python/types.d.ts +0 -85
  147. package/dist/integrations/python/types.d.ts.map +0 -1
  148. package/dist/integrations/python/types.js +0 -5
  149. package/dist/integrations/python/types.js.map +0 -1
  150. package/dist/integrations/redis/client.d.ts +0 -43
  151. package/dist/integrations/redis/client.d.ts.map +0 -1
  152. package/dist/integrations/redis/client.js +0 -142
  153. package/dist/integrations/redis/client.js.map +0 -1
  154. package/dist/integrations/redis/index.d.ts +0 -8
  155. package/dist/integrations/redis/index.d.ts.map +0 -1
  156. package/dist/integrations/redis/index.js +0 -7
  157. package/dist/integrations/redis/index.js.map +0 -1
  158. package/dist/integrations/redis/types.d.ts +0 -137
  159. package/dist/integrations/redis/types.d.ts.map +0 -1
  160. package/dist/integrations/redis/types.js +0 -5
  161. package/dist/integrations/redis/types.js.map +0 -1
  162. package/src/integrations/couchbase/README.md +0 -138
  163. package/src/integrations/couchbase/client.ts +0 -225
  164. package/src/integrations/couchbase/index.ts +0 -8
  165. package/src/integrations/couchbase/types.ts +0 -126
  166. package/src/integrations/kafka/README.md +0 -144
  167. package/src/integrations/kafka/client.ts +0 -216
  168. package/src/integrations/kafka/index.ts +0 -14
  169. package/src/integrations/kafka/types.ts +0 -128
  170. package/src/integrations/kinesis/README.md +0 -153
  171. package/src/integrations/kinesis/client.ts +0 -146
  172. package/src/integrations/kinesis/index.ts +0 -14
  173. package/src/integrations/kinesis/types.ts +0 -114
  174. package/src/integrations/python/README.md +0 -566
  175. package/src/integrations/python/client.test.ts +0 -341
  176. package/src/integrations/python/client.ts +0 -136
  177. package/src/integrations/python/index.ts +0 -6
  178. package/src/integrations/python/types.ts +0 -92
  179. package/src/integrations/redis/README.md +0 -200
  180. package/src/integrations/redis/client.ts +0 -208
  181. package/src/integrations/redis/index.ts +0 -8
  182. package/src/integrations/redis/types.ts +0 -167
@@ -1,225 +0,0 @@
1
- /**
2
- * Couchbase client implementation.
3
- *
4
- * Builds proto JSON-style request objects for SQL++ queries, document insert,
5
- * get, and remove operations against Couchbase buckets.
6
- *
7
- * IMPORTANT: Request objects use plain objects with flat proto JSON keys
8
- * (e.g. `{runSql: {sqlBody}}`) rather than the protobuf-es `CouchbaseRequest`
9
- * type. The protobuf-es type uses oneof wrappers (`{case: "runSql", value: {...}}`)
10
- * which get lost during the JSON → Go proto → JSON roundtrip in the orchestrator,
11
- * resulting in "invalid operation: undefined". The Go orchestrator expects the
12
- * standard proto JSON format with flat field names, not the TS-specific wrapper.
13
- */
14
-
15
- import type { z } from "zod";
16
-
17
- import { QueryValidationError, RestApiValidationError } from "../../errors.js";
18
- import { IntegrationError } from "../../runtime/errors.js";
19
- import type { QueryExecutor, TraceMetadata } from "../registry.js";
20
- import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
21
- import { describeType } from "../utils.js";
22
- import type { CouchbaseClient, CouchbaseIdentifier } from "./types.js";
23
-
24
- /**
25
- * Internal implementation of CouchbaseClient.
26
- *
27
- * Communicates with the orchestrator using the native Couchbase plugin
28
- * proto format, supporting SQL++ queries and key-value document operations.
29
- * All operations require a bucket name.
30
- */
31
- export class CouchbaseClientImpl
32
- implements CouchbaseClient, IntegrationClientImpl
33
- {
34
- readonly config: IntegrationConfig;
35
- private readonly executeQuery: QueryExecutor;
36
-
37
- constructor(config: IntegrationConfig, executeQuery: QueryExecutor) {
38
- this.config = config;
39
- this.executeQuery = executeQuery;
40
- }
41
-
42
- get name(): string {
43
- return this.config.name;
44
- }
45
-
46
- get pluginId(): string {
47
- return this.config.pluginId;
48
- }
49
-
50
- async query<T>(
51
- bucket: string,
52
- sql: string,
53
- schema: z.ZodSchema<T>,
54
- params?: unknown[],
55
- metadata?: TraceMetadata,
56
- ): Promise<T[]> {
57
- const hasParams = params && params.length > 0;
58
- const request = {
59
- bucketName: bucket,
60
- runSql: {
61
- sqlBody: sql,
62
- parameters: hasParams ? JSON.stringify(params) : undefined,
63
- },
64
- };
65
-
66
- try {
67
- const result = await this.executeQuery(
68
- request as Record<string, unknown>,
69
- undefined,
70
- metadata,
71
- );
72
-
73
- if (!Array.isArray(result)) {
74
- throw new IntegrationError(
75
- this.config.name,
76
- "query",
77
- `Expected array result from Couchbase query, got: ${describeType(result)}`,
78
- );
79
- }
80
-
81
- const validated: T[] = [];
82
- for (let i = 0; i < result.length; i++) {
83
- const row = result[i];
84
- const parseResult = schema.safeParse(row);
85
-
86
- if (!parseResult.success) {
87
- throw new QueryValidationError(
88
- `Row ${i} failed validation: ${parseResult.error.message}`,
89
- {
90
- rowIndex: i,
91
- errors: parseResult.error.errors,
92
- row,
93
- },
94
- );
95
- }
96
-
97
- validated.push(parseResult.data);
98
- }
99
-
100
- return validated;
101
- } catch (error) {
102
- if (
103
- error instanceof QueryValidationError ||
104
- error instanceof IntegrationError
105
- ) {
106
- throw error;
107
- }
108
-
109
- throw new IntegrationError(this.config.name, "query", error);
110
- }
111
- }
112
-
113
- async insert(
114
- key: string,
115
- value: unknown,
116
- identifier: CouchbaseIdentifier,
117
- metadata?: TraceMetadata,
118
- ): Promise<void> {
119
- const request = {
120
- bucketName: identifier.bucket,
121
- insert: {
122
- key,
123
- value: typeof value === "string" ? value : JSON.stringify(value),
124
- identifier: {
125
- scope: identifier.scope,
126
- collection: identifier.collection,
127
- },
128
- },
129
- };
130
-
131
- try {
132
- await this.executeQuery(
133
- request as Record<string, unknown>,
134
- undefined,
135
- metadata,
136
- );
137
- } catch (error) {
138
- if (error instanceof IntegrationError) {
139
- throw error;
140
- }
141
-
142
- throw new IntegrationError(this.config.name, "insert", error);
143
- }
144
- }
145
-
146
- async get<T>(
147
- key: string,
148
- schema: z.ZodSchema<T>,
149
- identifier: CouchbaseIdentifier,
150
- metadata?: TraceMetadata,
151
- ): Promise<T> {
152
- const request = {
153
- bucketName: identifier.bucket,
154
- get: {
155
- key,
156
- identifier: {
157
- scope: identifier.scope,
158
- collection: identifier.collection,
159
- },
160
- },
161
- };
162
-
163
- try {
164
- const result = await this.executeQuery(
165
- request as Record<string, unknown>,
166
- undefined,
167
- metadata,
168
- );
169
-
170
- const parseResult = schema.safeParse(result);
171
-
172
- if (!parseResult.success) {
173
- throw new RestApiValidationError(
174
- `Result validation failed: ${parseResult.error.message}`,
175
- {
176
- zodError: parseResult.error,
177
- data: result,
178
- },
179
- );
180
- }
181
-
182
- return parseResult.data;
183
- } catch (error) {
184
- if (
185
- error instanceof RestApiValidationError ||
186
- error instanceof IntegrationError
187
- ) {
188
- throw error;
189
- }
190
-
191
- throw new IntegrationError(this.config.name, "get", error);
192
- }
193
- }
194
-
195
- async remove(
196
- key: string,
197
- identifier: CouchbaseIdentifier,
198
- metadata?: TraceMetadata,
199
- ): Promise<void> {
200
- const request = {
201
- bucketName: identifier.bucket,
202
- remove: {
203
- key,
204
- identifier: {
205
- scope: identifier.scope,
206
- collection: identifier.collection,
207
- },
208
- },
209
- };
210
-
211
- try {
212
- await this.executeQuery(
213
- request as Record<string, unknown>,
214
- undefined,
215
- metadata,
216
- );
217
- } catch (error) {
218
- if (error instanceof IntegrationError) {
219
- throw error;
220
- }
221
-
222
- throw new IntegrationError(this.config.name, "remove", error);
223
- }
224
- }
225
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Couchbase integration client.
3
- *
4
- * @module
5
- */
6
-
7
- export type { CouchbaseClient, CouchbaseIdentifier } from "./types.js";
8
- export { CouchbaseClientImpl } from "./client.js";
@@ -1,126 +0,0 @@
1
- /**
2
- * Couchbase client types.
3
- */
4
-
5
- import type { z } from "zod";
6
-
7
- import type { BaseIntegrationClient } from "../../types.js";
8
- import type { TraceMetadata } from "../registry.js";
9
-
10
- /**
11
- * Parameters for identifying a Couchbase document location.
12
- *
13
- * All Couchbase operations require a bucket name. Key-value operations
14
- * (insert, get, remove) additionally require a scope and collection.
15
- */
16
- export interface CouchbaseIdentifier {
17
- /** The bucket name (required for all operations) */
18
- bucket: string;
19
- /** The scope name */
20
- scope: string;
21
- /** The collection name */
22
- collection: string;
23
- }
24
-
25
- /**
26
- * Couchbase client for document and query operations.
27
- *
28
- * Provides methods for SQL++ queries, document insertion, retrieval,
29
- * and removal in Couchbase buckets.
30
- *
31
- * @example
32
- * ```typescript
33
- * // Declare in api(): integrations: { cb: couchbase(INTEGRATION_ID) }
34
- * // In run(), access via ctx.integrations.cb
35
- *
36
- * // Run a SQL++ query
37
- * const users = await ctx.integrations.cb.query(
38
- * 'my-bucket',
39
- * 'SELECT * FROM bucket WHERE status = "active"',
40
- * UserSchema,
41
- * );
42
- *
43
- * // Insert a document
44
- * await ctx.integrations.cb.insert('user::123', { name: 'Alice' }, {
45
- * bucket: 'my-bucket',
46
- * scope: '_default',
47
- * collection: '_default',
48
- * });
49
- *
50
- * // Get a document
51
- * const doc = await ctx.integrations.cb.get('user::123', DocSchema, {
52
- * bucket: 'my-bucket',
53
- * scope: '_default',
54
- * collection: '_default',
55
- * });
56
- *
57
- * // Remove a document
58
- * await ctx.integrations.cb.remove('user::123', {
59
- * bucket: 'my-bucket',
60
- * scope: '_default',
61
- * collection: '_default',
62
- * });
63
- * ```
64
- */
65
- export interface CouchbaseClient extends BaseIntegrationClient {
66
- /**
67
- * Execute a SQL++ query against Couchbase.
68
- *
69
- * @param bucket - The bucket name to query against
70
- * @param sql - The SQL++ query string (with optional $1, $2 placeholders when parameterized)
71
- * @param schema - Zod schema for validating result rows
72
- * @param params - Optional array of parameter values for server-side binding
73
- * @returns Array of validated result rows
74
- */
75
- query<T>(
76
- bucket: string,
77
- sql: string,
78
- schema: z.ZodSchema<T>,
79
- params?: unknown[],
80
- metadata?: TraceMetadata,
81
- ): Promise<T[]>;
82
-
83
- /**
84
- * Insert a document into a collection.
85
- *
86
- * @param key - The document key
87
- * @param value - The document value (will be JSON-serialized)
88
- * @param identifier - The bucket, scope, and collection to insert into
89
- * @param metadata - Optional trace metadata for diagnostics
90
- */
91
- insert(
92
- key: string,
93
- value: unknown,
94
- identifier: CouchbaseIdentifier,
95
- metadata?: TraceMetadata,
96
- ): Promise<void>;
97
-
98
- /**
99
- * Get a document by key from a collection.
100
- *
101
- * @param key - The document key
102
- * @param schema - Zod schema for validating the result
103
- * @param identifier - The bucket, scope, and collection to get from
104
- * @param metadata - Optional trace metadata for diagnostics
105
- * @returns The validated document
106
- */
107
- get<T>(
108
- key: string,
109
- schema: z.ZodSchema<T>,
110
- identifier: CouchbaseIdentifier,
111
- metadata?: TraceMetadata,
112
- ): Promise<T>;
113
-
114
- /**
115
- * Remove a document by key from a collection.
116
- *
117
- * @param key - The document key
118
- * @param identifier - The bucket, scope, and collection to remove from
119
- * @param metadata - Optional trace metadata for diagnostics
120
- */
121
- remove(
122
- key: string,
123
- identifier: CouchbaseIdentifier,
124
- metadata?: TraceMetadata,
125
- ): Promise<void>;
126
- }
@@ -1,144 +0,0 @@
1
- # Kafka Client
2
-
3
- Interact with Apache Kafka with full type safety and runtime validation.
4
-
5
- ## Methods
6
-
7
- | Method | Description |
8
- | ------------------------------------ | ----------------------------------- |
9
- | `consume(schema, params, metadata?)` | Consume messages from a Kafka topic |
10
- | `produce(schema, params, metadata?)` | Produce messages to Kafka topics |
11
-
12
- ## Usage
13
-
14
- ### Consume Messages
15
-
16
- ```typescript
17
- import { api, z, kafka } from "@superblocksteam/sdk-api";
18
-
19
- // Integration ID from the integrations panel
20
- const PROD_KAFKA = "a1b2c3d4-5678-90ab-cdef-kafka0000001";
21
-
22
- const MessageSchema = z.array(
23
- z.object({
24
- topic: z.string(),
25
- partition: z.number(),
26
- offset: z.number(),
27
- value: z.unknown(),
28
- }),
29
- );
30
-
31
- export default api({
32
- integrations: {
33
- kafka: kafka(PROD_KAFKA),
34
- },
35
- name: "KafkaExample",
36
- input: z.object({
37
- topic: z.string(),
38
- }),
39
- output: z.object({
40
- messages: MessageSchema,
41
- }),
42
- async run(ctx, { topic }) {
43
- const messages = await kafka.consume(MessageSchema, {
44
- topic: topic,
45
- from: "LATEST",
46
- groupId: "my-consumer-group",
47
- });
48
-
49
- return { messages };
50
- },
51
- });
52
- ```
53
-
54
- ### Consume from Beginning
55
-
56
- ```typescript
57
- const messages = await kafka.consume(MessageSchema, {
58
- topic: "my-topic",
59
- from: "BEGINNING",
60
- groupId: "my-consumer-group",
61
- });
62
- ```
63
-
64
- ### Produce Messages
65
-
66
- ```typescript
67
- const ProduceResultSchema = z.any();
68
-
69
- const result = await ctx.integrations.kafka.produce(ProduceResultSchema, {
70
- messages: JSON.stringify([
71
- { topic: "my-topic", value: { event: "purchase", amount: 99.99 } },
72
- { topic: "my-topic", value: { event: "signup", userId: "123" } },
73
- ]),
74
- });
75
- ```
76
-
77
- ### Produce with Options
78
-
79
- ```typescript
80
- const result = await ctx.integrations.kafka.produce(ProduceResultSchema, {
81
- messages: JSON.stringify([
82
- { topic: "my-topic", key: "user-123", value: { data: "payload" } },
83
- ]),
84
- acks: "ALL",
85
- compression: "GZIP",
86
- autoCreateTopic: true,
87
- transaction: true,
88
- });
89
- ```
90
-
91
- ## Consume Parameters
92
-
93
- | Parameter | Type | Description |
94
- | ----------------- | ----------------------------------- | ------------------------------------ |
95
- | `topic` | `string` | Topic to consume from |
96
- | `from` | `'BEGINNING' \| 'LATEST' \| 'SEEK'` | Where to start consuming from |
97
- | `groupId` | `string` | Consumer group ID |
98
- | `clientId` | `string` | Client ID |
99
- | `readUncommitted` | `boolean` | Whether to read uncommitted messages |
100
- | `seek` | `object` | Seek position for SEEK mode |
101
-
102
- ## Produce Parameters
103
-
104
- | Parameter | Type | Description |
105
- | ----------------- | --------------------------------------- | ----------------------------- |
106
- | `messages` | `string` | JSON string array of messages |
107
- | `acks` | `'NONE' \| 'LEADER' \| 'ALL'` | Acknowledgment level |
108
- | `compression` | `'GZIP' \| 'SNAPPY' \| 'LZ4' \| 'ZSTD'` | Compression type |
109
- | `autoCreateTopic` | `boolean` | Auto-create topic if missing |
110
- | `transaction` | `boolean` | Use transactions |
111
- | `idempotent` | `boolean` | Enable idempotent delivery |
112
- | `clientId` | `string` | Client ID |
113
- | `timeout` | `number` | Timeout in milliseconds |
114
-
115
- ## Trace Metadata
116
-
117
- All methods accept an optional `metadata` parameter as the last argument for diagnostics labeling. See the [root SDK README](../../../README.md#trace-metadata) for details.
118
-
119
- ## Error Handling
120
-
121
- ```typescript
122
- import {
123
- RestApiValidationError,
124
- IntegrationError,
125
- } from "@superblocksteam/sdk-api";
126
-
127
- try {
128
- const messages = await kafka.consume(MessageSchema, {
129
- topic: "my-topic",
130
- from: "LATEST",
131
- });
132
- } catch (error) {
133
- if (error instanceof RestApiValidationError) {
134
- console.error("Validation failed:", error.details.zodError);
135
- } else if (error instanceof IntegrationError) {
136
- console.error("Kafka error:", error.message);
137
- }
138
- }
139
- ```
140
-
141
- ## API Reference
142
-
143
- - [Apache Kafka Documentation](https://kafka.apache.org/documentation/)
144
- - [Confluent Documentation](https://docs.confluent.io/)
@@ -1,216 +0,0 @@
1
- /**
2
- * Kafka client implementation.
3
- *
4
- * Constructs request objects matching the expected backend format.
5
- */
6
-
7
- import type { z } from "zod";
8
-
9
- import { RestApiValidationError } from "../../errors.js";
10
- import { IntegrationError } from "../../runtime/errors.js";
11
- import type { QueryExecutor, TraceMetadata } from "../registry.js";
12
- import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
13
- import type {
14
- KafkaClient,
15
- KafkaConsumeParams,
16
- KafkaProduceParams,
17
- } from "./types.js";
18
-
19
- /**
20
- * Consume request structure.
21
- */
22
- interface KafkaConsumeRequest {
23
- operation: "OPERATION_CONSUME";
24
- consume: {
25
- topic: string;
26
- from: string;
27
- groupId?: string;
28
- clientId?: string;
29
- readUncommitted?: boolean;
30
- seek?: {
31
- topic?: string;
32
- offset?: string;
33
- partition?: number;
34
- };
35
- };
36
- }
37
-
38
- /**
39
- * Produce request structure.
40
- */
41
- interface KafkaProduceRequest {
42
- operation: "OPERATION_PRODUCE";
43
- produce: {
44
- messages: string;
45
- acks?: string;
46
- clientId?: string;
47
- timeout?: number;
48
- compression?: string;
49
- transactionId?: string;
50
- autoCreateTopic?: boolean;
51
- idempotent?: boolean;
52
- transaction?: boolean;
53
- };
54
- }
55
-
56
- /**
57
- * Kafka plugin request - discriminated union on operation.
58
- */
59
- type KafkaRequest = KafkaConsumeRequest | KafkaProduceRequest;
60
-
61
- /**
62
- * Operation string values expected by the Kafka plugin.
63
- */
64
- const OPERATION = {
65
- CONSUME: "OPERATION_CONSUME",
66
- PRODUCE: "OPERATION_PRODUCE",
67
- } as const;
68
-
69
- /**
70
- * Consume from string values.
71
- */
72
- const CONSUME_FROM = {
73
- BEGINNING: "FROM_BEGINNING",
74
- LATEST: "FROM_LATEST",
75
- SEEK: "FROM_SEEK",
76
- } as const;
77
-
78
- /**
79
- * Acks string values.
80
- */
81
- const ACKS = {
82
- NONE: "ACKS_NONE",
83
- LEADER: "ACKS_LEADER",
84
- ALL: "ACKS_ALL",
85
- } as const;
86
-
87
- /**
88
- * Compression string values.
89
- */
90
- const COMPRESSION = {
91
- GZIP: "COMPRESSION_GZIP",
92
- SNAPPY: "COMPRESSION_SNAPPY",
93
- LZ4: "COMPRESSION_LZ4",
94
- ZSTD: "COMPRESSION_ZSTD",
95
- } as const;
96
-
97
- /**
98
- * Internal implementation of KafkaClient.
99
- */
100
- export class KafkaClientImpl implements KafkaClient, IntegrationClientImpl {
101
- readonly config: IntegrationConfig;
102
- private readonly executeQuery: QueryExecutor;
103
-
104
- constructor(config: IntegrationConfig, executeQuery: QueryExecutor) {
105
- this.config = config;
106
- this.executeQuery = executeQuery;
107
- }
108
-
109
- get name(): string {
110
- return this.config.name;
111
- }
112
-
113
- get pluginId(): string {
114
- return this.config.pluginId;
115
- }
116
-
117
- private buildConsumeRequest(params: KafkaConsumeParams): KafkaConsumeRequest {
118
- const request: KafkaConsumeRequest = {
119
- operation: OPERATION.CONSUME,
120
- consume: {
121
- topic: params.topic,
122
- from: params.from ? CONSUME_FROM[params.from] : CONSUME_FROM.LATEST,
123
- groupId: params.groupId,
124
- clientId: params.clientId,
125
- readUncommitted: params.readUncommitted ?? false,
126
- },
127
- };
128
-
129
- if (params.seek && request.consume) {
130
- request.consume.seek = {
131
- topic: params.seek.topic,
132
- offset: String(params.seek.offset),
133
- partition: params.seek.partition,
134
- };
135
- }
136
-
137
- return request;
138
- }
139
-
140
- private buildProduceRequest(params: KafkaProduceParams): KafkaProduceRequest {
141
- const request: KafkaProduceRequest = {
142
- operation: OPERATION.PRODUCE,
143
- produce: {
144
- messages: params.messages,
145
- acks: params.acks ? ACKS[params.acks] : ACKS.ALL,
146
- clientId: params.clientId,
147
- timeout: params.timeout,
148
- compression: params.compression
149
- ? COMPRESSION[params.compression]
150
- : undefined,
151
- transactionId: params.transactionId,
152
- autoCreateTopic: params.autoCreateTopic ?? false,
153
- idempotent: params.idempotent ?? false,
154
- transaction: params.transaction ?? false,
155
- },
156
- };
157
-
158
- return request;
159
- }
160
-
161
- private async executeAndValidate<T>(
162
- request: KafkaRequest,
163
- schema: z.ZodSchema<T>,
164
- operation: string,
165
- metadata?: TraceMetadata,
166
- ): Promise<T> {
167
- try {
168
- const result = await this.executeQuery(
169
- request as unknown as Record<string, unknown>,
170
- undefined,
171
- metadata,
172
- );
173
-
174
- const parseResult = schema.safeParse(result);
175
-
176
- if (!parseResult.success) {
177
- throw new RestApiValidationError(
178
- `Result validation failed: ${parseResult.error.message}`,
179
- {
180
- zodError: parseResult.error,
181
- data: result,
182
- },
183
- );
184
- }
185
-
186
- return parseResult.data;
187
- } catch (error) {
188
- if (
189
- error instanceof RestApiValidationError ||
190
- error instanceof IntegrationError
191
- ) {
192
- throw error;
193
- }
194
-
195
- throw new IntegrationError(this.config.name, operation, error);
196
- }
197
- }
198
-
199
- async consume<T>(
200
- schema: z.ZodSchema<T>,
201
- params: KafkaConsumeParams,
202
- metadata?: TraceMetadata,
203
- ): Promise<T> {
204
- const request = this.buildConsumeRequest(params);
205
- return this.executeAndValidate(request, schema, "consume", metadata);
206
- }
207
-
208
- async produce<T>(
209
- schema: z.ZodSchema<T>,
210
- params: KafkaProduceParams,
211
- metadata?: TraceMetadata,
212
- ): Promise<T> {
213
- const request = this.buildProduceRequest(params);
214
- return this.executeAndValidate(request, schema, "produce", metadata);
215
- }
216
- }