@superblocksteam/sdk-api 2.0.101-next.5 → 2.0.101
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/README.md +41 -47
- package/dist/api/definition.d.ts +1 -1
- package/dist/api/definition.d.ts.map +1 -1
- package/dist/api/definition.js.map +1 -1
- package/dist/api/definition.test.js.map +1 -1
- package/dist/api/streaming.d.ts +1 -1
- package/dist/api/streaming.d.ts.map +1 -1
- package/dist/api/streaming.js.map +1 -1
- package/dist/api/streaming.test.js +2 -2
- package/dist/api/streaming.test.js.map +1 -1
- package/dist/integrations/athena/client.d.ts +1 -1
- package/dist/integrations/athena/client.d.ts.map +1 -1
- package/dist/integrations/athena/client.js.map +1 -1
- package/dist/integrations/athena/types.d.ts.map +1 -1
- package/dist/integrations/base/graphql-integration-client.d.ts +2 -2
- package/dist/integrations/base/graphql-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/graphql-integration-client.js.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.d.ts +3 -3
- package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
- package/dist/integrations/base/types.d.ts.map +1 -1
- package/dist/integrations/bigquery/client.d.ts +1 -1
- package/dist/integrations/bigquery/client.d.ts.map +1 -1
- package/dist/integrations/bigquery/client.js.map +1 -1
- package/dist/integrations/bigquery/types.d.ts.map +1 -1
- package/dist/integrations/cockroachdb/client.d.ts +1 -1
- package/dist/integrations/cockroachdb/client.d.ts.map +1 -1
- package/dist/integrations/cockroachdb/client.js.map +1 -1
- package/dist/integrations/cockroachdb/types.d.ts.map +1 -1
- package/dist/integrations/cosmosdb/client.d.ts +1 -1
- package/dist/integrations/cosmosdb/client.d.ts.map +1 -1
- package/dist/integrations/cosmosdb/client.js.map +1 -1
- package/dist/integrations/cosmosdb/client.test.js.map +1 -1
- package/dist/integrations/cosmosdb/types.d.ts.map +1 -1
- package/dist/integrations/couchbase/client.d.ts +3 -9
- package/dist/integrations/couchbase/client.d.ts.map +1 -1
- package/dist/integrations/couchbase/client.js +33 -27
- package/dist/integrations/couchbase/client.js.map +1 -1
- package/dist/integrations/couchbase/types.d.ts.map +1 -1
- package/dist/integrations/databricks/client.d.ts +1 -1
- package/dist/integrations/databricks/client.d.ts.map +1 -1
- package/dist/integrations/databricks/client.js.map +1 -1
- package/dist/integrations/databricks/types.d.ts.map +1 -1
- package/dist/integrations/declarations.d.ts +36 -36
- package/dist/integrations/declarations.d.ts.map +1 -1
- package/dist/integrations/declarations.test.js.map +1 -1
- package/dist/integrations/dynamodb/client.d.ts +1 -1
- package/dist/integrations/dynamodb/client.d.ts.map +1 -1
- package/dist/integrations/dynamodb/client.js.map +1 -1
- package/dist/integrations/dynamodb/types.d.ts.map +1 -1
- package/dist/integrations/gcs/client.d.ts +1 -1
- package/dist/integrations/gcs/client.d.ts.map +1 -1
- package/dist/integrations/gcs/client.js.map +1 -1
- package/dist/integrations/gcs/types.d.ts.map +1 -1
- package/dist/integrations/graphql/types.d.ts +1 -1
- package/dist/integrations/graphql/types.d.ts.map +1 -1
- package/dist/integrations/gsheets/client.d.ts +1 -1
- package/dist/integrations/gsheets/client.d.ts.map +1 -1
- package/dist/integrations/gsheets/client.js.map +1 -1
- package/dist/integrations/gsheets/types.d.ts.map +1 -1
- package/dist/integrations/kafka/client.d.ts +1 -1
- package/dist/integrations/kafka/client.d.ts.map +1 -1
- package/dist/integrations/kafka/client.js.map +1 -1
- package/dist/integrations/kafka/types.d.ts.map +1 -1
- package/dist/integrations/kinesis/client.d.ts +1 -1
- package/dist/integrations/kinesis/client.d.ts.map +1 -1
- package/dist/integrations/kinesis/client.js.map +1 -1
- package/dist/integrations/lakebase/client.d.ts +1 -1
- package/dist/integrations/lakebase/client.d.ts.map +1 -1
- package/dist/integrations/lakebase/client.js.map +1 -1
- package/dist/integrations/lakebase/types.d.ts.map +1 -1
- package/dist/integrations/mariadb/client.d.ts +1 -1
- package/dist/integrations/mariadb/client.d.ts.map +1 -1
- package/dist/integrations/mariadb/client.js.map +1 -1
- package/dist/integrations/mariadb/types.d.ts.map +1 -1
- package/dist/integrations/mongodb/client.d.ts +1 -1
- package/dist/integrations/mongodb/client.d.ts.map +1 -1
- package/dist/integrations/mongodb/client.js.map +1 -1
- package/dist/integrations/mongodb/types.d.ts.map +1 -1
- package/dist/integrations/mssql/client.d.ts +1 -1
- package/dist/integrations/mssql/client.d.ts.map +1 -1
- package/dist/integrations/mssql/client.js.map +1 -1
- package/dist/integrations/mssql/types.d.ts.map +1 -1
- package/dist/integrations/mysql/client.d.ts +1 -1
- package/dist/integrations/mysql/client.d.ts.map +1 -1
- package/dist/integrations/mysql/client.js.map +1 -1
- package/dist/integrations/mysql/types.d.ts.map +1 -1
- package/dist/integrations/oracledb/client.d.ts +1 -1
- package/dist/integrations/oracledb/client.d.ts.map +1 -1
- package/dist/integrations/oracledb/client.js.map +1 -1
- package/dist/integrations/oracledb/types.d.ts.map +1 -1
- package/dist/integrations/postgres/client.d.ts +2 -2
- package/dist/integrations/postgres/client.d.ts.map +1 -1
- package/dist/integrations/postgres/client.js.map +1 -1
- package/dist/integrations/postgres/types.d.ts.map +1 -1
- package/dist/integrations/python/client.d.ts +2 -2
- package/dist/integrations/python/client.d.ts.map +1 -1
- package/dist/integrations/python/client.js.map +1 -1
- package/dist/integrations/python/client.test.js.map +1 -1
- package/dist/integrations/python/types.d.ts.map +1 -1
- package/dist/integrations/redis/client.d.ts +1 -1
- package/dist/integrations/redis/client.d.ts.map +1 -1
- package/dist/integrations/redis/client.js.map +1 -1
- package/dist/integrations/redis/types.d.ts.map +1 -1
- package/dist/integrations/redshift/client.d.ts +1 -1
- package/dist/integrations/redshift/client.d.ts.map +1 -1
- package/dist/integrations/redshift/client.js.map +1 -1
- package/dist/integrations/redshift/types.d.ts.map +1 -1
- package/dist/integrations/registry.d.ts.map +1 -1
- package/dist/integrations/registry.js +22 -22
- package/dist/integrations/registry.js.map +1 -1
- package/dist/integrations/registry.test.js.map +1 -1
- package/dist/integrations/s3/client.d.ts +1 -1
- package/dist/integrations/s3/client.d.ts.map +1 -1
- package/dist/integrations/s3/client.js.map +1 -1
- package/dist/integrations/s3/types.d.ts +1 -3
- package/dist/integrations/s3/types.d.ts.map +1 -1
- package/dist/integrations/salesforce/client.d.ts +1 -1
- package/dist/integrations/salesforce/client.d.ts.map +1 -1
- package/dist/integrations/salesforce/client.js.map +1 -1
- package/dist/integrations/salesforce/types.d.ts.map +1 -1
- package/dist/integrations/smtp/client.d.ts +1 -1
- package/dist/integrations/smtp/client.d.ts.map +1 -1
- package/dist/integrations/smtp/client.js.map +1 -1
- package/dist/integrations/snowflake/client.d.ts +1 -1
- package/dist/integrations/snowflake/client.d.ts.map +1 -1
- package/dist/integrations/snowflake/client.js.map +1 -1
- package/dist/integrations/snowflake/types.d.ts.map +1 -1
- package/dist/integrations/snowflakepostgres/client.d.ts +1 -1
- package/dist/integrations/snowflakepostgres/client.d.ts.map +1 -1
- package/dist/integrations/snowflakepostgres/client.js.map +1 -1
- package/dist/integrations/snowflakepostgres/types.d.ts.map +1 -1
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/streaming-context.d.ts +2 -2
- package/dist/runtime/streaming-context.d.ts.map +1 -1
- package/dist/runtime/streaming-context.js.map +1 -1
- package/dist/runtime/streaming-executor.d.ts.map +1 -1
- package/dist/runtime/streaming-executor.js +1 -1
- package/dist/runtime/streaming-executor.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/definition.test.ts +0 -1
- package/src/api/definition.ts +1 -1
- package/src/api/streaming.test.ts +2 -3
- package/src/api/streaming.ts +1 -2
- package/src/integrations/athena/client.ts +3 -5
- package/src/integrations/athena/types.ts +0 -1
- package/src/integrations/base/graphql-integration-client.ts +2 -3
- package/src/integrations/base/rest-api-integration-client.ts +7 -9
- package/src/integrations/base/types.ts +0 -1
- package/src/integrations/bigquery/client.ts +3 -5
- package/src/integrations/bigquery/types.ts +0 -1
- package/src/integrations/cockroachdb/client.ts +3 -5
- package/src/integrations/cockroachdb/types.ts +0 -1
- package/src/integrations/cosmosdb/client.test.ts +1 -2
- package/src/integrations/cosmosdb/client.ts +3 -5
- package/src/integrations/cosmosdb/types.ts +0 -1
- package/src/integrations/couchbase/client.ts +46 -34
- package/src/integrations/couchbase/types.ts +0 -1
- package/src/integrations/databricks/client.ts +3 -5
- package/src/integrations/databricks/types.ts +0 -1
- package/src/integrations/declarations.test.ts +0 -1
- package/src/integrations/declarations.ts +36 -36
- package/src/integrations/dynamodb/client.ts +2 -3
- package/src/integrations/dynamodb/types.ts +0 -1
- package/src/integrations/gcs/client.ts +3 -5
- package/src/integrations/gcs/types.ts +0 -1
- package/src/integrations/graphql/types.ts +1 -2
- package/src/integrations/gsheets/client.ts +3 -5
- package/src/integrations/gsheets/types.ts +0 -1
- package/src/integrations/kafka/client.ts +2 -3
- package/src/integrations/kafka/types.ts +0 -1
- package/src/integrations/kinesis/client.ts +2 -2
- package/src/integrations/lakebase/client.ts +4 -6
- package/src/integrations/lakebase/types.ts +0 -1
- package/src/integrations/mariadb/client.ts +3 -5
- package/src/integrations/mariadb/types.ts +0 -1
- package/src/integrations/mongodb/client.ts +3 -5
- package/src/integrations/mongodb/types.ts +0 -1
- package/src/integrations/mssql/client.ts +3 -5
- package/src/integrations/mssql/types.ts +0 -1
- package/src/integrations/mysql/client.ts +3 -5
- package/src/integrations/mysql/types.ts +0 -1
- package/src/integrations/oracledb/client.ts +3 -5
- package/src/integrations/oracledb/types.ts +0 -1
- package/src/integrations/postgres/client.ts +4 -6
- package/src/integrations/postgres/types.ts +0 -1
- package/src/integrations/python/client.test.ts +2 -3
- package/src/integrations/python/client.ts +3 -5
- package/src/integrations/python/types.ts +0 -1
- package/src/integrations/redis/client.ts +2 -3
- package/src/integrations/redis/types.ts +0 -1
- package/src/integrations/redshift/client.ts +3 -5
- package/src/integrations/redshift/types.ts +0 -1
- package/src/integrations/registry.test.ts +0 -1
- package/src/integrations/registry.ts +23 -23
- package/src/integrations/s3/client.ts +3 -5
- package/src/integrations/s3/types.ts +1 -4
- package/src/integrations/salesforce/client.ts +2 -3
- package/src/integrations/salesforce/types.ts +0 -1
- package/src/integrations/smtp/client.ts +2 -4
- package/src/integrations/snowflake/client.ts +3 -5
- package/src/integrations/snowflake/types.ts +0 -1
- package/src/integrations/snowflakepostgres/client.ts +1 -1
- package/src/integrations/snowflakepostgres/types.ts +0 -1
- package/src/runtime/context.ts +10 -10
- package/src/runtime/streaming-context.ts +10 -10
- package/src/runtime/streaming-executor.ts +4 -4
- package/src/types.ts +0 -1
- package/src/integrations/lakebase/README.md +0 -242
- package/src/integrations/restapiintegration/README.md +0 -359
- package/src/integrations/smtp/README.md +0 -220
- package/src/integrations/snowflakecortex/README.md +0 -216
- package/src/integrations/snowflakepostgres/README.md +0 -233
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# SMTP Client
|
|
2
|
-
|
|
3
|
-
Send emails via SMTP with support for HTML content, CC/BCC, reply-to, and attachments.
|
|
4
|
-
|
|
5
|
-
## Methods
|
|
6
|
-
|
|
7
|
-
| Method | Description |
|
|
8
|
-
| -------------------------- | ---------------------- |
|
|
9
|
-
| `send(options, metadata?)` | Send an email via SMTP |
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### Send a Simple Email
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { api, z, smtp } from "@superblocksteam/sdk-api";
|
|
17
|
-
|
|
18
|
-
// Integration ID from the integrations panel
|
|
19
|
-
const MAILER = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
20
|
-
|
|
21
|
-
export default api({
|
|
22
|
-
name: "SendEmail",
|
|
23
|
-
integrations: {
|
|
24
|
-
mailer: smtp(MAILER),
|
|
25
|
-
},
|
|
26
|
-
input: z.object({
|
|
27
|
-
to: z.string(),
|
|
28
|
-
subject: z.string(),
|
|
29
|
-
body: z.string(),
|
|
30
|
-
}),
|
|
31
|
-
output: z.object({ success: z.boolean() }),
|
|
32
|
-
|
|
33
|
-
async run(ctx, { to, subject, body }) {
|
|
34
|
-
await ctx.integrations.mailer.send({
|
|
35
|
-
from: "noreply@example.com",
|
|
36
|
-
to,
|
|
37
|
-
subject,
|
|
38
|
-
body,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return { success: true };
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Send HTML Email
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
await ctx.integrations.mailer.send({
|
|
50
|
-
from: "noreply@example.com",
|
|
51
|
-
to: "user@example.com",
|
|
52
|
-
subject: "Welcome!",
|
|
53
|
-
body: "<h1>Welcome!</h1><p>Thank you for signing up.</p>",
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Send with CC and BCC
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
await ctx.integrations.mailer.send({
|
|
61
|
-
from: "noreply@example.com",
|
|
62
|
-
to: "user@example.com",
|
|
63
|
-
subject: "Team Update",
|
|
64
|
-
body: "Hello team!",
|
|
65
|
-
cc: "manager@example.com,lead@example.com",
|
|
66
|
-
bcc: "archive@example.com",
|
|
67
|
-
replyTo: "support@example.com",
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Send to Multiple Recipients
|
|
72
|
-
|
|
73
|
-
Use comma-separated email addresses:
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
await ctx.integrations.mailer.send({
|
|
77
|
-
from: "noreply@example.com",
|
|
78
|
-
to: "user1@example.com,user2@example.com,user3@example.com",
|
|
79
|
-
subject: "Announcement",
|
|
80
|
-
body: "<p>Important update for the team.</p>",
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Send with Attachments
|
|
85
|
-
|
|
86
|
-
Attachments are passed as a JSON string containing an array of objects with `content` (base64-encoded), `name` (filename), and `type` (MIME type):
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
const attachments = JSON.stringify([
|
|
90
|
-
{
|
|
91
|
-
content: base64EncodedPdf, // Base64-encoded file content
|
|
92
|
-
name: "report.pdf",
|
|
93
|
-
type: "application/pdf",
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
content: base64EncodedCsv,
|
|
97
|
-
name: "data.csv",
|
|
98
|
-
type: "text/csv",
|
|
99
|
-
},
|
|
100
|
-
]);
|
|
101
|
-
|
|
102
|
-
await ctx.integrations.mailer.send({
|
|
103
|
-
from: "reports@example.com",
|
|
104
|
-
to: "user@example.com",
|
|
105
|
-
subject: "Your Report",
|
|
106
|
-
body: "<p>Please find the attached report.</p>",
|
|
107
|
-
attachments,
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Trace Metadata
|
|
112
|
-
|
|
113
|
-
The `send` method accepts an optional `metadata` parameter as the last argument for diagnostics labeling:
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
await ctx.integrations.mailer.send(
|
|
117
|
-
{
|
|
118
|
-
from: "noreply@example.com",
|
|
119
|
-
to: "user@example.com",
|
|
120
|
-
subject: "Welcome",
|
|
121
|
-
body: "Hello!",
|
|
122
|
-
},
|
|
123
|
-
{ label: "Send welcome email" },
|
|
124
|
-
);
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
When `includeDiagnostics` is enabled, `label` and `description` appear in the trace view. See the [root SDK README](../../../README.md#trace-metadata) for details.
|
|
128
|
-
|
|
129
|
-
## Send Options Reference
|
|
130
|
-
|
|
131
|
-
| Option | Type | Required | Description |
|
|
132
|
-
| ------------- | -------- | -------- | --------------------------------------------- |
|
|
133
|
-
| `from` | `string` | Yes | Sender email address |
|
|
134
|
-
| `to` | `string` | Yes | Recipient(s), comma-separated for multiple |
|
|
135
|
-
| `subject` | `string` | Yes | Email subject line |
|
|
136
|
-
| `body` | `string` | Yes | Email body (HTML or plain text) |
|
|
137
|
-
| `cc` | `string` | No | CC recipient(s), comma-separated |
|
|
138
|
-
| `bcc` | `string` | No | BCC recipient(s), comma-separated |
|
|
139
|
-
| `replyTo` | `string` | No | Reply-to email address |
|
|
140
|
-
| `attachments` | `string` | No | JSON array of `{content, name, type}` objects |
|
|
141
|
-
|
|
142
|
-
## Common Pitfalls
|
|
143
|
-
|
|
144
|
-
### Use the `send` Method, Not `apiRequest`
|
|
145
|
-
|
|
146
|
-
Unlike most integrations, SMTP has a dedicated `send()` method:
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
// WRONG - apiRequest does not exist on SmtpClient
|
|
150
|
-
await ctx.integrations.mailer.apiRequest({ ... });
|
|
151
|
-
|
|
152
|
-
// CORRECT - Use send()
|
|
153
|
-
await ctx.integrations.mailer.send({
|
|
154
|
-
from: "noreply@example.com",
|
|
155
|
-
to: "user@example.com",
|
|
156
|
-
subject: "Hello",
|
|
157
|
-
body: "World",
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Attachments Must Be a JSON String
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
// WRONG - Passing an array directly
|
|
165
|
-
await ctx.integrations.mailer.send({
|
|
166
|
-
from: "noreply@example.com",
|
|
167
|
-
to: "user@example.com",
|
|
168
|
-
subject: "Report",
|
|
169
|
-
body: "See attached",
|
|
170
|
-
attachments: [{ content: "...", name: "file.pdf", type: "application/pdf" }],
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// CORRECT - JSON.stringify the array
|
|
174
|
-
await ctx.integrations.mailer.send({
|
|
175
|
-
from: "noreply@example.com",
|
|
176
|
-
to: "user@example.com",
|
|
177
|
-
subject: "Report",
|
|
178
|
-
body: "See attached",
|
|
179
|
-
attachments: JSON.stringify([
|
|
180
|
-
{ content: "...", name: "file.pdf", type: "application/pdf" },
|
|
181
|
-
]),
|
|
182
|
-
});
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Multiple Recipients Use Comma Separation
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
// WRONG - Array of recipients
|
|
189
|
-
await ctx.integrations.mailer.send({
|
|
190
|
-
to: ["user1@example.com", "user2@example.com"],
|
|
191
|
-
// ...
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// CORRECT - Comma-separated string
|
|
195
|
-
await ctx.integrations.mailer.send({
|
|
196
|
-
to: "user1@example.com,user2@example.com",
|
|
197
|
-
// ...
|
|
198
|
-
});
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## Error Handling
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
import { IntegrationError } from "@superblocksteam/sdk-api";
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
await ctx.integrations.mailer.send({
|
|
208
|
-
from: "noreply@example.com",
|
|
209
|
-
to: "user@example.com",
|
|
210
|
-
subject: "Test",
|
|
211
|
-
body: "Hello",
|
|
212
|
-
});
|
|
213
|
-
} catch (error) {
|
|
214
|
-
if (error instanceof IntegrationError) {
|
|
215
|
-
console.error(
|
|
216
|
-
`SMTP error in ${error.integrationName}.${error.method}: ${error.message}`,
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
# Snowflake Cortex Client
|
|
2
|
-
|
|
3
|
-
Interact with Snowflake Cortex AI/ML inference endpoints for text generation, embeddings, and other AI capabilities.
|
|
4
|
-
|
|
5
|
-
## Methods
|
|
6
|
-
|
|
7
|
-
| Method | Description |
|
|
8
|
-
| ---------------------------------------------- | ------------------------------------------------------------ |
|
|
9
|
-
| `apiRequest(options, schema, metadata?)` | Make any Snowflake Cortex API request with schema validation |
|
|
10
|
-
| `streamApiRequest(options, schema, metadata?)` | Stream responses with real-time chunk validation |
|
|
11
|
-
|
|
12
|
-
## Usage
|
|
13
|
-
|
|
14
|
-
### Text Completion
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
import { api, z, snowflakeCortex } from "@superblocksteam/sdk-api";
|
|
18
|
-
|
|
19
|
-
// Integration ID from the integrations panel
|
|
20
|
-
const CORTEX = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
21
|
-
|
|
22
|
-
const CompletionResponseSchema = z
|
|
23
|
-
.object({
|
|
24
|
-
choices: z
|
|
25
|
-
.array(
|
|
26
|
-
z
|
|
27
|
-
.object({
|
|
28
|
-
message: z
|
|
29
|
-
.object({
|
|
30
|
-
content: z.string().optional(),
|
|
31
|
-
})
|
|
32
|
-
.passthrough()
|
|
33
|
-
.optional(),
|
|
34
|
-
})
|
|
35
|
-
.passthrough(),
|
|
36
|
-
)
|
|
37
|
-
.optional(),
|
|
38
|
-
})
|
|
39
|
-
.passthrough();
|
|
40
|
-
|
|
41
|
-
export default api({
|
|
42
|
-
name: "CortexCompletion",
|
|
43
|
-
integrations: {
|
|
44
|
-
cortex: snowflakeCortex(CORTEX),
|
|
45
|
-
},
|
|
46
|
-
input: z.object({
|
|
47
|
-
prompt: z.string(),
|
|
48
|
-
}),
|
|
49
|
-
output: z.object({
|
|
50
|
-
response: z.string(),
|
|
51
|
-
}),
|
|
52
|
-
async run(ctx, { prompt }) {
|
|
53
|
-
const result = await ctx.integrations.cortex.apiRequest(
|
|
54
|
-
{
|
|
55
|
-
method: "POST",
|
|
56
|
-
path: "/api/v2/cortex/inference:complete",
|
|
57
|
-
body: {
|
|
58
|
-
model: "llama3.1-8b",
|
|
59
|
-
messages: [{ role: "user", content: prompt }],
|
|
60
|
-
stream: false,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
body: z.object({
|
|
65
|
-
model: z.string(),
|
|
66
|
-
messages: z.array(
|
|
67
|
-
z.object({ role: z.string(), content: z.string() }),
|
|
68
|
-
),
|
|
69
|
-
stream: z.boolean(),
|
|
70
|
-
}),
|
|
71
|
-
response: CompletionResponseSchema,
|
|
72
|
-
},
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
response: result.choices?.[0]?.message?.content ?? "",
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Streaming Completion
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
import { streamingApi, z, snowflakeCortex } from "@superblocksteam/sdk-api";
|
|
86
|
-
|
|
87
|
-
const CORTEX = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
88
|
-
|
|
89
|
-
const StreamChunkSchema = z.object({
|
|
90
|
-
choices: z.array(
|
|
91
|
-
z.object({
|
|
92
|
-
delta: z.object({
|
|
93
|
-
content: z.string().optional(),
|
|
94
|
-
}),
|
|
95
|
-
}),
|
|
96
|
-
),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export default streamingApi({
|
|
100
|
-
integrations: {
|
|
101
|
-
cortex: snowflakeCortex(CORTEX),
|
|
102
|
-
},
|
|
103
|
-
input: z.object({ prompt: z.string() }),
|
|
104
|
-
chunk: z.object({ type: z.literal("text"), text: z.string() }),
|
|
105
|
-
|
|
106
|
-
async *run(ctx, { prompt }) {
|
|
107
|
-
const stream = ctx.integrations.cortex.streamApiRequest(
|
|
108
|
-
{
|
|
109
|
-
method: "POST",
|
|
110
|
-
path: "/api/v2/cortex/inference:complete",
|
|
111
|
-
body: {
|
|
112
|
-
model: "mistral-large2",
|
|
113
|
-
stream: true,
|
|
114
|
-
messages: [{ role: "user", content: prompt }],
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
{ chunk: StreamChunkSchema },
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
for await (const chunk of stream) {
|
|
121
|
-
const content = chunk.choices[0]?.delta?.content;
|
|
122
|
-
if (content) {
|
|
123
|
-
yield { type: "text" as const, text: content };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Text Embedding
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
const EmbeddingResponseSchema = z.object({
|
|
134
|
-
data: z.array(
|
|
135
|
-
z.object({
|
|
136
|
-
embedding: z.array(z.number()),
|
|
137
|
-
}),
|
|
138
|
-
),
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const embeddings = await ctx.integrations.cortex.apiRequest(
|
|
142
|
-
{
|
|
143
|
-
method: "POST",
|
|
144
|
-
path: "/api/v2/cortex/inference:embed",
|
|
145
|
-
body: {
|
|
146
|
-
model: "e5-base-v2",
|
|
147
|
-
input: ["Hello world", "How are you?"],
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
{ response: EmbeddingResponseSchema },
|
|
151
|
-
);
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Trace Metadata
|
|
155
|
-
|
|
156
|
-
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.
|
|
157
|
-
|
|
158
|
-
## Common Pitfalls
|
|
159
|
-
|
|
160
|
-
### No Specialized Methods
|
|
161
|
-
|
|
162
|
-
The Snowflake Cortex client only provides `apiRequest()` and `streamApiRequest()`. There are no SDK-specific methods:
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
// WRONG - These methods do not exist
|
|
166
|
-
await cortex.complete({ ... });
|
|
167
|
-
await cortex.embed({ ... });
|
|
168
|
-
|
|
169
|
-
// CORRECT - Use apiRequest for all operations
|
|
170
|
-
await ctx.integrations.cortex.apiRequest(
|
|
171
|
-
{ method: "POST", path: "/api/v2/cortex/inference:complete", body: { ... } },
|
|
172
|
-
{ response: ResponseSchema }
|
|
173
|
-
);
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Response Schema is Required
|
|
177
|
-
|
|
178
|
-
You must always provide a schema object with at least a `response` schema. The `body` schema is optional but recommended for request validation:
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
// WRONG - Missing schema object entirely
|
|
182
|
-
const result = await ctx.integrations.cortex.apiRequest({
|
|
183
|
-
method: "POST",
|
|
184
|
-
path: "/api/v2/cortex/inference:complete",
|
|
185
|
-
body: { ... },
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// CORRECT - Include at least a response schema
|
|
189
|
-
const result = await ctx.integrations.cortex.apiRequest(
|
|
190
|
-
{ method: "POST", path: "/api/v2/cortex/inference:complete", body: { ... } },
|
|
191
|
-
{ response: CompletionResponseSchema }
|
|
192
|
-
);
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
## Error Handling
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { RestApiValidationError } from "@superblocksteam/sdk-api";
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
const result = await ctx.integrations.cortex.apiRequest(
|
|
202
|
-
{ method: "POST", path: "/api/v2/cortex/inference:complete", body: { ... } },
|
|
203
|
-
{ response: CompletionResponseSchema }
|
|
204
|
-
);
|
|
205
|
-
} catch (error) {
|
|
206
|
-
if (error instanceof RestApiValidationError) {
|
|
207
|
-
console.error("Validation failed:", error.details.zodError);
|
|
208
|
-
console.error("Actual response:", error.details.data);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## API Reference
|
|
214
|
-
|
|
215
|
-
- [Snowflake Cortex Documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/overview)
|
|
216
|
-
- [Cortex LLM Functions](https://docs.snowflake.com/en/user-guide/snowflake-cortex/llm-functions)
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# Snowflake Postgres Client
|
|
2
|
-
|
|
3
|
-
Execute SQL queries and statements against Snowflake databases using the PostgreSQL wire protocol, with full type safety and runtime validation.
|
|
4
|
-
|
|
5
|
-
Snowflake Postgres uses the same API contract as the PostgreSQL integration. If you are familiar with the Postgres client, this works identically.
|
|
6
|
-
|
|
7
|
-
## Methods
|
|
8
|
-
|
|
9
|
-
| Method | Description |
|
|
10
|
-
| ------------------------------------------- | -------------------------------------------------------------------------- |
|
|
11
|
-
| `query<T>(sql, schema, params?, metadata?)` | Execute a SELECT query and return validated, typed results |
|
|
12
|
-
| `execute(sql, params?, metadata?)` | Execute a statement (INSERT, UPDATE, DELETE) and return affected row count |
|
|
13
|
-
|
|
14
|
-
## Usage
|
|
15
|
-
|
|
16
|
-
### Basic Query with Schema Validation
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
import { api, z, snowflakePostgres } from "@superblocksteam/sdk-api";
|
|
20
|
-
|
|
21
|
-
// Integration ID from the integrations panel
|
|
22
|
-
const SNOWFLAKE_PG = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
23
|
-
|
|
24
|
-
const SalesSchema = z.object({
|
|
25
|
-
region: z.string(),
|
|
26
|
-
total_revenue: z.string(), // NUMERIC returned as string
|
|
27
|
-
order_count: z.coerce.number(),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export default api({
|
|
31
|
-
name: "GetSalesByRegion",
|
|
32
|
-
integrations: {
|
|
33
|
-
db: snowflakePostgres(SNOWFLAKE_PG),
|
|
34
|
-
},
|
|
35
|
-
input: z.object({
|
|
36
|
-
region: z.string(),
|
|
37
|
-
}),
|
|
38
|
-
output: z.object({
|
|
39
|
-
sales: z.array(SalesSchema),
|
|
40
|
-
}),
|
|
41
|
-
async run(ctx, { region }) {
|
|
42
|
-
const sales = await ctx.integrations.db.query(
|
|
43
|
-
"SELECT region, total_revenue, order_count FROM sales_summary WHERE region = $1",
|
|
44
|
-
SalesSchema,
|
|
45
|
-
[region],
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
return { sales };
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Executing INSERT, UPDATE, DELETE Statements
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import { api, z, snowflakePostgres } from "@superblocksteam/sdk-api";
|
|
57
|
-
|
|
58
|
-
const SNOWFLAKE_PG = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
59
|
-
|
|
60
|
-
export default api({
|
|
61
|
-
name: "ManageRecords",
|
|
62
|
-
integrations: {
|
|
63
|
-
db: snowflakePostgres(SNOWFLAKE_PG),
|
|
64
|
-
},
|
|
65
|
-
input: z.object({
|
|
66
|
-
name: z.string(),
|
|
67
|
-
email: z.string(),
|
|
68
|
-
}),
|
|
69
|
-
output: z.object({ success: z.boolean() }),
|
|
70
|
-
|
|
71
|
-
async run(ctx, { name, email }) {
|
|
72
|
-
// INSERT
|
|
73
|
-
await ctx.integrations.db.execute(
|
|
74
|
-
"INSERT INTO users (name, email) VALUES ($1, $2)",
|
|
75
|
-
[name, email],
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// UPDATE
|
|
79
|
-
const updateResult = await ctx.integrations.db.execute(
|
|
80
|
-
"UPDATE users SET last_login = CURRENT_TIMESTAMP() WHERE email = $1",
|
|
81
|
-
[email],
|
|
82
|
-
);
|
|
83
|
-
console.log(`Updated ${updateResult.rowCount} rows`);
|
|
84
|
-
|
|
85
|
-
return { success: true };
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Query with JOIN
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
const OrderSchema = z.object({
|
|
94
|
-
order_id: z.string(),
|
|
95
|
-
customer_name: z.string(),
|
|
96
|
-
total: z.string(), // NUMERIC as string
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const orders = await ctx.integrations.db.query(
|
|
100
|
-
`SELECT o.id as order_id, c.name as customer_name, o.total
|
|
101
|
-
FROM orders o
|
|
102
|
-
JOIN customers c ON o.customer_id = c.id
|
|
103
|
-
WHERE o.status = $1`,
|
|
104
|
-
OrderSchema,
|
|
105
|
-
["pending"],
|
|
106
|
-
);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## Trace Metadata
|
|
110
|
-
|
|
111
|
-
All methods accept an optional `metadata` parameter as the last argument for diagnostics labeling:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
const users = await ctx.integrations.db.query(
|
|
115
|
-
"SELECT * FROM users WHERE status = $1",
|
|
116
|
-
UserSchema,
|
|
117
|
-
["active"],
|
|
118
|
-
{ label: "Fetch active users" },
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
await ctx.integrations.db.execute(
|
|
122
|
-
"DELETE FROM sessions WHERE expires_at < CURRENT_TIMESTAMP()",
|
|
123
|
-
undefined, // no params
|
|
124
|
-
{ label: "Clean expired sessions" },
|
|
125
|
-
);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
When `includeDiagnostics` is enabled, `label` and `description` appear in the trace view. See the [root SDK README](../../../README.md#trace-metadata) for details.
|
|
129
|
-
|
|
130
|
-
## Common Pitfalls
|
|
131
|
-
|
|
132
|
-
### Schema Parameter is Required
|
|
133
|
-
|
|
134
|
-
The `query()` method requires a Zod schema for runtime validation:
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
// WRONG - Missing schema parameter
|
|
138
|
-
const users = await ctx.integrations.db.query(
|
|
139
|
-
"SELECT * FROM users",
|
|
140
|
-
[
|
|
141
|
-
/* params */
|
|
142
|
-
], // This is wrong - params are 3rd argument
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
// CORRECT - Schema is the second parameter
|
|
146
|
-
const users = await ctx.integrations.db.query(
|
|
147
|
-
"SELECT * FROM users WHERE id = $1",
|
|
148
|
-
UserSchema, // Schema is required
|
|
149
|
-
[userId], // Params are optional, third argument
|
|
150
|
-
);
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Use Parameterized Queries to Prevent SQL Injection
|
|
154
|
-
|
|
155
|
-
Always use `$1, $2, ...` placeholders instead of string interpolation:
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
// WRONG - SQL injection vulnerability
|
|
159
|
-
const users = await ctx.integrations.db.query(
|
|
160
|
-
`SELECT * FROM users WHERE name = '${userName}'`, // DANGEROUS!
|
|
161
|
-
UserSchema,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// CORRECT - Use parameterized queries
|
|
165
|
-
const users = await ctx.integrations.db.query(
|
|
166
|
-
"SELECT * FROM users WHERE name = $1",
|
|
167
|
-
UserSchema,
|
|
168
|
-
[userName], // Safe - value is escaped
|
|
169
|
-
);
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### NUMERIC/DECIMAL Values Returned as Strings
|
|
173
|
-
|
|
174
|
-
Large `NUMERIC` and `DECIMAL` columns are returned as strings to preserve precision:
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
// WRONG - May lose precision
|
|
178
|
-
const schema = z.object({ price: z.number() });
|
|
179
|
-
|
|
180
|
-
// CORRECT - Keep as string or transform
|
|
181
|
-
const schema = z.object({
|
|
182
|
-
price: z.string().transform((val) => parseFloat(val)),
|
|
183
|
-
});
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Aggregate Functions (COUNT, SUM) Return Strings
|
|
187
|
-
|
|
188
|
-
Use `z.coerce.number()` to convert:
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
const StatsSchema = z.object({
|
|
192
|
-
total_orders: z.coerce.number(),
|
|
193
|
-
total_revenue: z.coerce.number(),
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Handling NULL Values
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
// WRONG - Will fail if column contains NULL
|
|
201
|
-
const schema = z.object({ bio: z.string() });
|
|
202
|
-
|
|
203
|
-
// CORRECT - Mark nullable columns
|
|
204
|
-
const schema = z.object({ bio: z.string().nullable() });
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## Error Handling
|
|
208
|
-
|
|
209
|
-
### QueryValidationError
|
|
210
|
-
|
|
211
|
-
Thrown when query results fail schema validation:
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
import { QueryValidationError } from "@superblocksteam/sdk-api";
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
const users = await ctx.integrations.db.query(
|
|
218
|
-
"SELECT * FROM users",
|
|
219
|
-
UserSchema,
|
|
220
|
-
);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
if (error instanceof QueryValidationError) {
|
|
223
|
-
console.error("Row index:", error.details.rowIndex);
|
|
224
|
-
console.error("Validation errors:", error.details.errors);
|
|
225
|
-
console.error("Actual row data:", error.details.row);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## API Reference
|
|
231
|
-
|
|
232
|
-
- [Snowflake SQL Reference](https://docs.snowflake.com/en/sql-reference)
|
|
233
|
-
- [Snowflake Data Types](https://docs.snowflake.com/en/sql-reference/data-types)
|