@secondlayer/sdk 0.9.1 → 0.10.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/README.md +33 -0
- package/dist/index.d.ts +98 -5
- package/dist/index.js +103 -4
- package/dist/index.js.map +6 -4
- package/dist/marketplace/index.d.ts +49 -0
- package/dist/marketplace/index.js +139 -0
- package/dist/marketplace/index.js.map +12 -0
- package/dist/subgraphs/index.d.ts +93 -0
- package/dist/subgraphs/index.js +99 -1
- package/dist/subgraphs/index.js.map +6 -4
- package/dist/workflows/index.d.ts +71 -0
- package/dist/workflows/index.js +119 -0
- package/dist/workflows/index.js.map +12 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -62,6 +62,39 @@ const rows = await sl.subgraphs.queryTable("my-subgraph", "transfers", {
|
|
|
62
62
|
const result = await sl.subgraphs.deploy({ name, sources, schema, handlerCode });
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
## Workflows
|
|
66
|
+
|
|
67
|
+
Deploy and manage automated workflows.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// List
|
|
71
|
+
const { workflows } = await sl.workflows.list();
|
|
72
|
+
|
|
73
|
+
// Get
|
|
74
|
+
const detail = await sl.workflows.get("whale-alerts");
|
|
75
|
+
|
|
76
|
+
// Deploy
|
|
77
|
+
const result = await sl.workflows.deploy({
|
|
78
|
+
name: "whale-alerts",
|
|
79
|
+
trigger: { type: "event", filter: { type: "stx_transfer" } },
|
|
80
|
+
handlerCode: "...",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Trigger manually
|
|
84
|
+
const { runId } = await sl.workflows.trigger("whale-alerts", { threshold: 100000 });
|
|
85
|
+
|
|
86
|
+
// Pause / Resume / Delete
|
|
87
|
+
await sl.workflows.pause("whale-alerts");
|
|
88
|
+
await sl.workflows.resume("whale-alerts");
|
|
89
|
+
await sl.workflows.delete("whale-alerts");
|
|
90
|
+
|
|
91
|
+
// List runs
|
|
92
|
+
const { runs } = await sl.workflows.listRuns("whale-alerts", { status: "completed", limit: 10 });
|
|
93
|
+
|
|
94
|
+
// Get run details
|
|
95
|
+
const run = await sl.workflows.getRun("run-id");
|
|
96
|
+
```
|
|
97
|
+
|
|
65
98
|
## Error Handling
|
|
66
99
|
|
|
67
100
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreatorProfile, MarketplaceSubgraphDetail, MarketplaceSubgraphSummary, SubgraphQueryParams } from "@secondlayer/shared/schemas";
|
|
2
2
|
interface SecondLayerOptions {
|
|
3
3
|
/** Base URL of the Secondlayer API (trailing slashes are stripped). */
|
|
4
4
|
baseUrl: string;
|
|
@@ -12,6 +12,40 @@ declare abstract class BaseClient {
|
|
|
12
12
|
static authHeaders(apiKey?: string): Record<string, string>;
|
|
13
13
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
14
14
|
}
|
|
15
|
+
interface MarketplaceBrowseOptions {
|
|
16
|
+
tags?: string[];
|
|
17
|
+
search?: string;
|
|
18
|
+
sort?: "recent" | "popular" | "name";
|
|
19
|
+
limit?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
}
|
|
22
|
+
declare class Marketplace extends BaseClient {
|
|
23
|
+
browse(opts?: MarketplaceBrowseOptions): Promise<{
|
|
24
|
+
data: MarketplaceSubgraphSummary[]
|
|
25
|
+
meta: {
|
|
26
|
+
total: number
|
|
27
|
+
limit: number
|
|
28
|
+
offset: number
|
|
29
|
+
}
|
|
30
|
+
}>;
|
|
31
|
+
get(name: string): Promise<MarketplaceSubgraphDetail>;
|
|
32
|
+
creator(slug: string): Promise<CreatorProfile>;
|
|
33
|
+
fork(name: string, newName?: string): Promise<{
|
|
34
|
+
action: string
|
|
35
|
+
subgraphId: string
|
|
36
|
+
name: string
|
|
37
|
+
forkedFrom: string
|
|
38
|
+
}>;
|
|
39
|
+
queryTable(name: string, table: string, params?: SubgraphQueryParams): Promise<{
|
|
40
|
+
data: unknown[]
|
|
41
|
+
meta: {
|
|
42
|
+
total: number
|
|
43
|
+
limit: number
|
|
44
|
+
offset: number
|
|
45
|
+
}
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
import { BulkPauseResponse, BulkResumeResponse, CreateStream, CreateStreamResponse, ListStreamsResponse, StreamResponse, UpdateStream } from "@secondlayer/shared/schemas";
|
|
15
49
|
interface DeliverySummary {
|
|
16
50
|
id: string;
|
|
17
51
|
blockHeight: number;
|
|
@@ -54,7 +88,7 @@ declare class Streams extends BaseClient {
|
|
|
54
88
|
pauseAll(): Promise<BulkPauseResponse>;
|
|
55
89
|
resumeAll(): Promise<BulkResumeResponse>;
|
|
56
90
|
}
|
|
57
|
-
import { ReindexResponse, SubgraphDetail, SubgraphGapsResponse, SubgraphQueryParams, SubgraphSummary } from "@secondlayer/shared/schemas";
|
|
91
|
+
import { ReindexResponse, SubgraphDetail, SubgraphGapsResponse, SubgraphQueryParams as SubgraphQueryParams2, SubgraphSummary } from "@secondlayer/shared/schemas";
|
|
58
92
|
import { DeploySubgraphRequest, DeploySubgraphResponse } from "@secondlayer/shared/schemas/subgraphs";
|
|
59
93
|
import { InferSubgraphClient } from "@secondlayer/subgraphs";
|
|
60
94
|
declare class Subgraphs extends BaseClient {
|
|
@@ -82,8 +116,8 @@ declare class Subgraphs extends BaseClient {
|
|
|
82
116
|
message: string
|
|
83
117
|
}>;
|
|
84
118
|
deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse>;
|
|
85
|
-
queryTable(name: string, table: string, params?:
|
|
86
|
-
queryTableCount(name: string, table: string, params?:
|
|
119
|
+
queryTable(name: string, table: string, params?: SubgraphQueryParams2): Promise<unknown[]>;
|
|
120
|
+
queryTableCount(name: string, table: string, params?: SubgraphQueryParams2): Promise<{
|
|
87
121
|
count: number
|
|
88
122
|
}>;
|
|
89
123
|
/**
|
|
@@ -106,9 +140,68 @@ declare class Subgraphs extends BaseClient {
|
|
|
106
140
|
}
|
|
107
141
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
108
142
|
import { QueueStats } from "@secondlayer/shared/types";
|
|
143
|
+
import { WorkflowRun, WorkflowRunStatus } from "@secondlayer/workflows";
|
|
144
|
+
interface WorkflowSummary {
|
|
145
|
+
name: string;
|
|
146
|
+
status: "active" | "paused";
|
|
147
|
+
triggerType: "event" | "stream" | "schedule" | "manual";
|
|
148
|
+
createdAt: string;
|
|
149
|
+
updatedAt: string;
|
|
150
|
+
}
|
|
151
|
+
interface WorkflowDetail extends WorkflowSummary {
|
|
152
|
+
trigger: Record<string, unknown>;
|
|
153
|
+
retries?: {
|
|
154
|
+
maxAttempts?: number
|
|
155
|
+
backoffMs?: number
|
|
156
|
+
};
|
|
157
|
+
timeout?: number;
|
|
158
|
+
totalRuns: number;
|
|
159
|
+
lastRunAt: string | null;
|
|
160
|
+
}
|
|
161
|
+
interface WorkflowRunSummary {
|
|
162
|
+
id: string;
|
|
163
|
+
workflowName: string;
|
|
164
|
+
status: WorkflowRunStatus;
|
|
165
|
+
duration: number;
|
|
166
|
+
aiTokensUsed: number;
|
|
167
|
+
triggeredAt: string;
|
|
168
|
+
completedAt: string | null;
|
|
169
|
+
}
|
|
170
|
+
declare class Workflows extends BaseClient {
|
|
171
|
+
deploy(data: {
|
|
172
|
+
name: string
|
|
173
|
+
trigger: Record<string, unknown>
|
|
174
|
+
handlerCode: string
|
|
175
|
+
retries?: Record<string, unknown>
|
|
176
|
+
timeout?: number
|
|
177
|
+
}): Promise<{
|
|
178
|
+
action: string
|
|
179
|
+
workflowId: string
|
|
180
|
+
message: string
|
|
181
|
+
}>;
|
|
182
|
+
list(): Promise<{
|
|
183
|
+
workflows: WorkflowSummary[]
|
|
184
|
+
}>;
|
|
185
|
+
get(name: string): Promise<WorkflowDetail>;
|
|
186
|
+
trigger(name: string, input?: Record<string, unknown>): Promise<{
|
|
187
|
+
runId: string
|
|
188
|
+
}>;
|
|
189
|
+
pause(name: string): Promise<void>;
|
|
190
|
+
resume(name: string): Promise<void>;
|
|
191
|
+
delete(name: string): Promise<void>;
|
|
192
|
+
listRuns(name: string, params?: {
|
|
193
|
+
status?: WorkflowRunStatus
|
|
194
|
+
limit?: number
|
|
195
|
+
}): Promise<{
|
|
196
|
+
runs: WorkflowRunSummary[]
|
|
197
|
+
}>;
|
|
198
|
+
getRun(runId: string): Promise<WorkflowRun>;
|
|
199
|
+
}
|
|
109
200
|
declare class SecondLayer extends BaseClient {
|
|
110
201
|
readonly streams: Streams;
|
|
111
202
|
readonly subgraphs: Subgraphs;
|
|
203
|
+
readonly marketplace: Marketplace;
|
|
204
|
+
readonly workflows: Workflows;
|
|
112
205
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
113
206
|
getQueueStats(): Promise<QueueStats>;
|
|
114
207
|
}
|
|
@@ -150,4 +243,4 @@ declare class ApiError extends Error {
|
|
|
150
243
|
status: number;
|
|
151
244
|
constructor(status: number, message: string);
|
|
152
245
|
}
|
|
153
|
-
export { getSubgraph, Subgraphs, Streams, SecondLayerOptions, SecondLayer, ApiError };
|
|
246
|
+
export { getSubgraph, Workflows, Subgraphs, Streams, SecondLayerOptions, SecondLayer, Marketplace, ApiError };
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,62 @@ class BaseClient {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
// src/marketplace/client.ts
|
|
79
|
+
function buildMarketplaceQuery(opts) {
|
|
80
|
+
const qs = new URLSearchParams;
|
|
81
|
+
if (opts.tags?.length)
|
|
82
|
+
qs.set("tags", opts.tags.join(","));
|
|
83
|
+
if (opts.search)
|
|
84
|
+
qs.set("search", opts.search);
|
|
85
|
+
if (opts.sort)
|
|
86
|
+
qs.set("_sort", opts.sort);
|
|
87
|
+
if (opts.limit !== undefined)
|
|
88
|
+
qs.set("_limit", String(opts.limit));
|
|
89
|
+
if (opts.offset !== undefined)
|
|
90
|
+
qs.set("_offset", String(opts.offset));
|
|
91
|
+
const str = qs.toString();
|
|
92
|
+
return str ? `?${str}` : "";
|
|
93
|
+
}
|
|
94
|
+
function buildSubgraphQueryString(params) {
|
|
95
|
+
const qs = new URLSearchParams;
|
|
96
|
+
if (params.sort)
|
|
97
|
+
qs.set("_sort", params.sort);
|
|
98
|
+
if (params.order)
|
|
99
|
+
qs.set("_order", params.order);
|
|
100
|
+
if (params.limit !== undefined)
|
|
101
|
+
qs.set("_limit", String(params.limit));
|
|
102
|
+
if (params.offset !== undefined)
|
|
103
|
+
qs.set("_offset", String(params.offset));
|
|
104
|
+
if (params.fields)
|
|
105
|
+
qs.set("_fields", params.fields);
|
|
106
|
+
if (params.filters) {
|
|
107
|
+
for (const [key, value] of Object.entries(params.filters)) {
|
|
108
|
+
qs.set(key, String(value));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const str = qs.toString();
|
|
112
|
+
return str ? `?${str}` : "";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class Marketplace extends BaseClient {
|
|
116
|
+
async browse(opts = {}) {
|
|
117
|
+
return this.request("GET", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);
|
|
118
|
+
}
|
|
119
|
+
async get(name) {
|
|
120
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}`);
|
|
121
|
+
}
|
|
122
|
+
async creator(slug) {
|
|
123
|
+
return this.request("GET", `/api/marketplace/creators/${slug}`);
|
|
124
|
+
}
|
|
125
|
+
async fork(name, newName) {
|
|
126
|
+
return this.request("POST", `/api/marketplace/subgraphs/${name}/fork`, {
|
|
127
|
+
newName
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async queryTable(name, table, params = {}) {
|
|
131
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
78
134
|
// src/streams/client.ts
|
|
79
135
|
class Streams extends BaseClient {
|
|
80
136
|
async requestWithStreamId(method, pathTemplate, id, body) {
|
|
@@ -194,7 +250,7 @@ function resolveOrderByColumn(col) {
|
|
|
194
250
|
}
|
|
195
251
|
|
|
196
252
|
// src/subgraphs/client.ts
|
|
197
|
-
function
|
|
253
|
+
function buildSubgraphQueryString2(params) {
|
|
198
254
|
const qs = new URLSearchParams;
|
|
199
255
|
if (params.sort)
|
|
200
256
|
qs.set("_sort", params.sort);
|
|
@@ -249,11 +305,11 @@ class Subgraphs extends BaseClient {
|
|
|
249
305
|
return this.request("POST", "/api/subgraphs", data);
|
|
250
306
|
}
|
|
251
307
|
async queryTable(name, table, params = {}) {
|
|
252
|
-
const result = await this.request("GET", `/api/subgraphs/${name}/${table}${
|
|
308
|
+
const result = await this.request("GET", `/api/subgraphs/${name}/${table}${buildSubgraphQueryString2(params)}`);
|
|
253
309
|
return Array.isArray(result) ? result : result.data;
|
|
254
310
|
}
|
|
255
311
|
async queryTableCount(name, table, params = {}) {
|
|
256
|
-
return this.request("GET", `/api/subgraphs/${name}/${table}/count${
|
|
312
|
+
return this.request("GET", `/api/subgraphs/${name}/${table}/count${buildSubgraphQueryString2(params)}`);
|
|
257
313
|
}
|
|
258
314
|
typed(def) {
|
|
259
315
|
const result = {};
|
|
@@ -301,14 +357,55 @@ class Subgraphs extends BaseClient {
|
|
|
301
357
|
};
|
|
302
358
|
}
|
|
303
359
|
}
|
|
360
|
+
// src/workflows/client.ts
|
|
361
|
+
class Workflows extends BaseClient {
|
|
362
|
+
async deploy(data) {
|
|
363
|
+
return this.request("POST", "/api/workflows", data);
|
|
364
|
+
}
|
|
365
|
+
async list() {
|
|
366
|
+
return this.request("GET", "/api/workflows");
|
|
367
|
+
}
|
|
368
|
+
async get(name) {
|
|
369
|
+
return this.request("GET", `/api/workflows/${name}`);
|
|
370
|
+
}
|
|
371
|
+
async trigger(name, input) {
|
|
372
|
+
return this.request("POST", `/api/workflows/${name}/trigger`, input ? { input } : undefined);
|
|
373
|
+
}
|
|
374
|
+
async pause(name) {
|
|
375
|
+
return this.request("POST", `/api/workflows/${name}/pause`);
|
|
376
|
+
}
|
|
377
|
+
async resume(name) {
|
|
378
|
+
return this.request("POST", `/api/workflows/${name}/resume`);
|
|
379
|
+
}
|
|
380
|
+
async delete(name) {
|
|
381
|
+
return this.request("DELETE", `/api/workflows/${name}`);
|
|
382
|
+
}
|
|
383
|
+
async listRuns(name, params) {
|
|
384
|
+
const qs = new URLSearchParams;
|
|
385
|
+
if (params?.status)
|
|
386
|
+
qs.set("status", params.status);
|
|
387
|
+
if (params?.limit !== undefined)
|
|
388
|
+
qs.set("limit", String(params.limit));
|
|
389
|
+
const query = qs.toString();
|
|
390
|
+
return this.request("GET", `/api/workflows/${name}/runs${query ? `?${query}` : ""}`);
|
|
391
|
+
}
|
|
392
|
+
async getRun(runId) {
|
|
393
|
+
return this.request("GET", `/api/workflows/runs/${runId}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
304
397
|
// src/client.ts
|
|
305
398
|
class SecondLayer extends BaseClient {
|
|
306
399
|
streams;
|
|
307
400
|
subgraphs;
|
|
401
|
+
marketplace;
|
|
402
|
+
workflows;
|
|
308
403
|
constructor(options = {}) {
|
|
309
404
|
super(options);
|
|
310
405
|
this.streams = new Streams(options);
|
|
311
406
|
this.subgraphs = new Subgraphs(options);
|
|
407
|
+
this.marketplace = new Marketplace(options);
|
|
408
|
+
this.workflows = new Workflows(options);
|
|
312
409
|
}
|
|
313
410
|
async getQueueStats() {
|
|
314
411
|
const status = await this.request("GET", "/status");
|
|
@@ -328,11 +425,13 @@ function getSubgraph(def, options = {}) {
|
|
|
328
425
|
}
|
|
329
426
|
export {
|
|
330
427
|
getSubgraph,
|
|
428
|
+
Workflows,
|
|
331
429
|
Subgraphs,
|
|
332
430
|
Streams,
|
|
333
431
|
SecondLayer,
|
|
432
|
+
Marketplace,
|
|
334
433
|
ApiError
|
|
335
434
|
};
|
|
336
435
|
|
|
337
|
-
//# debugId=
|
|
436
|
+
//# debugId=6B8EDB3066EE171A64756E2164756E21
|
|
338
437
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/errors.ts", "../src/base.ts", "../src/streams/client.ts", "../src/subgraphs/serialize.ts", "../src/subgraphs/client.ts", "../src/client.ts", "../src/subgraphs/get-subgraph.ts"],
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/base.ts", "../src/marketplace/client.ts", "../src/streams/client.ts", "../src/subgraphs/serialize.ts", "../src/subgraphs/client.ts", "../src/workflows/client.ts", "../src/client.ts", "../src/subgraphs/get-subgraph.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Error thrown by {@link SecondLayer} when an API request fails.\n * Includes the HTTP status code for programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await client.streams.get(\"abc123\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Stream not found\");\n * }\n * }\n * ```\n */\nexport class ApiError extends Error {\n\tconstructor(\n\t\t/** HTTP status code (0 for network errors). */\n\t\tpublic status: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n",
|
|
6
6
|
"import { ApiError } from \"./errors.ts\";\n\nexport interface SecondLayerOptions {\n\t/** Base URL of the Secondlayer API (trailing slashes are stripped). */\n\tbaseUrl: string;\n\t/** Bearer token for authenticated requests. */\n\tapiKey?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t}\n\n\tstatic authHeaders(apiKey?: string): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t};\n\t\tif (apiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tprotected async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst url = `${this.baseUrl}${path}`;\n\t\tconst headers = BaseClient.authHeaders(this.apiKey);\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: body ? JSON.stringify(body) : undefined,\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t0,\n\t\t\t\t`Cannot reach API at ${this.baseUrl}. Check your connection or try again.`,\n\t\t\t);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 401) {\n\t\t\t\tthrow new ApiError(401, \"API key invalid or expired.\");\n\t\t\t}\n\n\t\t\tif (response.status === 429) {\n\t\t\t\tconst retryAfter = response.headers.get(\"Retry-After\");\n\t\t\t\tconst msg = retryAfter\n\t\t\t\t\t? `Rate limited. Wait ${retryAfter} seconds.`\n\t\t\t\t\t: \"Rate limited. Try again later.\";\n\t\t\t\tthrow new ApiError(429, msg);\n\t\t\t}\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tthrow new ApiError(\n\t\t\t\t\tresponse.status,\n\t\t\t\t\t`Server error. Try again or check status at ${this.baseUrl}/health`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst errorBody = await response.text();\n\t\t\tlet message = `HTTP ${response.status}`;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tconst err = json.error ?? json.message;\n\t\t\t\tif (typeof err === \"string\") {\n\t\t\t\t\tmessage = err;\n\t\t\t\t} else if (err && typeof err === \"object\") {\n\t\t\t\t\tmessage = JSON.stringify(err);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tif (errorBody) message = errorBody;\n\t\t\t}\n\t\t\tthrow new ApiError(response.status, message);\n\t\t}\n\n\t\tif (response.status === 204) {\n\t\t\treturn undefined as T;\n\t\t}\n\n\t\treturn response.json() as Promise<T>;\n\t}\n}\n",
|
|
7
|
+
"import type {\n\tCreatorProfile,\n\tMarketplaceSubgraphDetail,\n\tMarketplaceSubgraphSummary,\n\tSubgraphQueryParams,\n} from \"@secondlayer/shared/schemas\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface MarketplaceBrowseOptions {\n\ttags?: string[];\n\tsearch?: string;\n\tsort?: \"recent\" | \"popular\" | \"name\";\n\tlimit?: number;\n\toffset?: number;\n}\n\nfunction buildMarketplaceQuery(opts: MarketplaceBrowseOptions): string {\n\tconst qs = new URLSearchParams();\n\tif (opts.tags?.length) qs.set(\"tags\", opts.tags.join(\",\"));\n\tif (opts.search) qs.set(\"search\", opts.search);\n\tif (opts.sort) qs.set(\"_sort\", opts.sort);\n\tif (opts.limit !== undefined) qs.set(\"_limit\", String(opts.limit));\n\tif (opts.offset !== undefined) qs.set(\"_offset\", String(opts.offset));\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nfunction buildSubgraphQueryString(params: SubgraphQueryParams): string {\n\tconst qs = new URLSearchParams();\n\tif (params.sort) qs.set(\"_sort\", params.sort);\n\tif (params.order) qs.set(\"_order\", params.order);\n\tif (params.limit !== undefined) qs.set(\"_limit\", String(params.limit));\n\tif (params.offset !== undefined) qs.set(\"_offset\", String(params.offset));\n\tif (params.fields) qs.set(\"_fields\", params.fields);\n\tif (params.filters) {\n\t\tfor (const [key, value] of Object.entries(params.filters)) {\n\t\t\tqs.set(key, String(value));\n\t\t}\n\t}\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nexport class Marketplace extends BaseClient {\n\tasync browse(\n\t\topts: MarketplaceBrowseOptions = {},\n\t): Promise<{\n\t\tdata: MarketplaceSubgraphSummary[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);\n\t}\n\n\tasync get(name: string): Promise<MarketplaceSubgraphDetail> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs/${name}`);\n\t}\n\n\tasync creator(slug: string): Promise<CreatorProfile> {\n\t\treturn this.request(\"GET\", `/api/marketplace/creators/${slug}`);\n\t}\n\n\tasync fork(\n\t\tname: string,\n\t\tnewName?: string,\n\t): Promise<{\n\t\taction: string;\n\t\tsubgraphId: string;\n\t\tname: string;\n\t\tforkedFrom: string;\n\t}> {\n\t\treturn this.request(\"POST\", `/api/marketplace/subgraphs/${name}/fork`, {\n\t\t\tnewName,\n\t\t});\n\t}\n\n\tasync queryTable(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<{\n\t\tdata: unknown[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\n\t\t\t\"GET\",\n\t\t\t`/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`,\n\t\t);\n\t}\n}\n",
|
|
7
8
|
"import type {\n\tBulkPauseResponse,\n\tBulkResumeResponse,\n\tCreateStream,\n\tCreateStreamResponse,\n\tListStreamsResponse,\n\tStreamResponse,\n\tUpdateStream,\n} from \"@secondlayer/shared/schemas\";\nimport { BaseClient } from \"../base.ts\";\nimport { ApiError } from \"../errors.ts\";\n\nexport interface DeliverySummary {\n\tid: string;\n\tblockHeight: number;\n\tstatus: string;\n\tstatusCode: number | null;\n\tresponseTimeMs: number | null;\n\tattempts: number;\n\terror: string | null;\n\tcreatedAt: string;\n}\n\nexport interface DeliveryDetail extends DeliverySummary {\n\tpayload: unknown;\n}\n\nexport interface DeliveriesResponse {\n\tdeliveries: DeliverySummary[];\n}\n\nexport class Streams extends BaseClient {\n\tprivate async requestWithStreamId<T>(\n\t\tmethod: string,\n\t\tpathTemplate: (id: string) => string,\n\t\tid: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst fullId = await this.resolveStreamId(id);\n\t\treturn this.request<T>(method, pathTemplate(fullId), body);\n\t}\n\n\tasync resolveStreamId(partialId: string): Promise<string> {\n\t\tif (partialId.length === 36 && partialId.includes(\"-\")) {\n\t\t\treturn partialId;\n\t\t}\n\n\t\tconst { streams } = await this.list();\n\t\tconst matches = streams.filter((s) => s.id.startsWith(partialId));\n\n\t\tif (matches.length === 0) {\n\t\t\tthrow new ApiError(404, `No stream found matching \"${partialId}\"`);\n\t\t}\n\t\tif (matches.length > 1) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Multiple streams match \"${partialId}\": ${matches.map((s) => s.id.slice(0, 8)).join(\", \")}`,\n\t\t\t);\n\t\t}\n\n\t\treturn matches[0]!.id;\n\t}\n\n\tasync create(data: CreateStream): Promise<CreateStreamResponse> {\n\t\treturn this.request<CreateStreamResponse>(\"POST\", \"/api/streams\", data);\n\t}\n\n\tasync update(id: string, data: UpdateStream): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"PATCH\",\n\t\t\t(id) => `/api/streams/${id}`,\n\t\t\tid,\n\t\t\tdata,\n\t\t);\n\t}\n\n\tasync updateByName(\n\t\tname: string,\n\t\tdata: CreateStream,\n\t): Promise<StreamResponse> {\n\t\tconst { streams } = await this.list();\n\t\tconst existing = streams.find((s) => s.name === name);\n\t\tif (!existing) {\n\t\t\tthrow new ApiError(404, `Stream with name \"${name}\" not found`);\n\t\t}\n\t\treturn this.update(existing.id, data);\n\t}\n\n\tasync list(params?: { status?: string }): Promise<ListStreamsResponse> {\n\t\tconst searchParams = new URLSearchParams();\n\t\tif (params?.status) searchParams.set(\"status\", params.status);\n\t\tconst query = searchParams.toString();\n\t\tconst path = query ? `/api/streams?${query}` : \"/api/streams\";\n\t\treturn this.request<ListStreamsResponse>(\"GET\", path);\n\t}\n\n\tasync get(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\"GET\", (id) => `/api/streams/${id}`, id);\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\treturn this.requestWithStreamId(\"DELETE\", (id) => `/api/streams/${id}`, id);\n\t}\n\n\tasync enable(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/enable`,\n\t\t\tid,\n\t\t);\n\t}\n\n\tasync disable(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/disable`,\n\t\t\tid,\n\t\t);\n\t}\n\n\tasync rotateSecret(id: string): Promise<{ secret: string }> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/rotate-secret`,\n\t\t\tid,\n\t\t);\n\t}\n\n\t// ── Deliveries ─────────────────────────────────────────────────────\n\n\t/** List recent deliveries for a stream. */\n\tasync listDeliveries(\n\t\tid: string,\n\t\tparams?: { limit?: number; status?: string },\n\t): Promise<DeliveriesResponse> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n\t\tif (params?.status) qs.set(\"status\", params.status);\n\t\tconst query = qs.toString();\n\t\treturn this.requestWithStreamId(\n\t\t\t\"GET\",\n\t\t\t(id) => `/api/streams/${id}/deliveries${query ? `?${query}` : \"\"}`,\n\t\t\tid,\n\t\t);\n\t}\n\n\t/** Get a single delivery with full payload. */\n\tasync getDelivery(\n\t\tstreamId: string,\n\t\tdeliveryId: string,\n\t): Promise<DeliveryDetail> {\n\t\tconst fullId = await this.resolveStreamId(streamId);\n\t\treturn this.request<DeliveryDetail>(\n\t\t\t\"GET\",\n\t\t\t`/api/streams/${fullId}/deliveries/${deliveryId}`,\n\t\t);\n\t}\n\n\tasync pauseAll(): Promise<BulkPauseResponse> {\n\t\treturn this.request<BulkPauseResponse>(\"POST\", \"/api/streams/pause\");\n\t}\n\n\tasync resumeAll(): Promise<BulkResumeResponse> {\n\t\treturn this.request<BulkResumeResponse>(\"POST\", \"/api/streams/resume\");\n\t}\n}\n",
|
|
8
9
|
"/**\n * Maps camelCase system column names (with or without `_` prefix) to the\n * actual snake_case DB column names used in query params.\n */\nconst SYSTEM_COLUMN_MAP: Record<string, string> = {\n\t// underscore-prefixed camelCase (canonical row shape)\n\t_blockHeight: \"_block_height\",\n\t_txId: \"_tx_id\",\n\t_createdAt: \"_created_at\",\n\t_id: \"_id\",\n\t// no-prefix aliases\n\tblockHeight: \"_block_height\",\n\ttxId: \"_tx_id\",\n\tcreatedAt: \"_created_at\",\n\tid: \"_id\",\n};\n\nfunction resolveColumn(col: string): string {\n\treturn SYSTEM_COLUMN_MAP[col] ?? col;\n}\n\n/**\n * Serializes a WhereInput object into the flat filter map expected by\n * SubgraphQueryParams.filters (and the REST API query string).\n *\n * Scalar values → `{ column: \"value\" }`\n * Comparison objects → `{ \"column.gte\": \"100\", \"column.lt\": \"200\" }`\n * System column aliases → `blockHeight` / `_blockHeight` both → `_block_height`\n */\nexport function serializeWhere(\n\twhere: Record<string, unknown>,\n): Record<string, string> {\n\tconst filters: Record<string, string> = {};\n\n\tfor (const [column, value] of Object.entries(where)) {\n\t\tif (value === null || value === undefined) continue;\n\n\t\tconst col = resolveColumn(column);\n\n\t\tif (typeof value === \"object\" && !Array.isArray(value)) {\n\t\t\tconst ops = value as Record<string, unknown>;\n\t\t\tfor (const [op, opValue] of Object.entries(ops)) {\n\t\t\t\tif (opValue === null || opValue === undefined) continue;\n\t\t\t\tif (op === \"eq\") {\n\t\t\t\t\tfilters[col] = String(opValue);\n\t\t\t\t} else if ([\"neq\", \"gt\", \"gte\", \"lt\", \"lte\"].includes(op)) {\n\t\t\t\t\tfilters[`${col}.${op}`] = String(opValue);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfilters[col] = String(value);\n\t\t}\n\t}\n\n\treturn filters;\n}\n\n/**\n * Resolves an orderBy column name (either alias or canonical) to the DB column name.\n */\nexport function resolveOrderByColumn(col: string): string {\n\treturn resolveColumn(col);\n}\n",
|
|
9
10
|
"import type {\n\tReindexResponse,\n\tSubgraphDetail,\n\tSubgraphGapsResponse,\n\tSubgraphQueryParams,\n\tSubgraphSummary,\n} from \"@secondlayer/shared/schemas\";\nimport type {\n\tDeploySubgraphRequest,\n\tDeploySubgraphResponse,\n} from \"@secondlayer/shared/schemas/subgraphs\";\nimport type {\n\tFindManyOptions,\n\tInferSubgraphClient,\n\tWhereInput,\n} from \"@secondlayer/subgraphs\";\nimport { BaseClient } from \"../base.ts\";\nimport { resolveOrderByColumn, serializeWhere } from \"./serialize.ts\";\n\nfunction buildSubgraphQueryString(params: SubgraphQueryParams): string {\n\tconst qs = new URLSearchParams();\n\tif (params.sort) qs.set(\"_sort\", params.sort);\n\tif (params.order) qs.set(\"_order\", params.order);\n\tif (params.limit !== undefined) qs.set(\"_limit\", String(params.limit));\n\tif (params.offset !== undefined) qs.set(\"_offset\", String(params.offset));\n\tif (params.fields) qs.set(\"_fields\", params.fields);\n\tif (params.filters) {\n\t\tfor (const [key, value] of Object.entries(params.filters)) {\n\t\t\tqs.set(key, String(value));\n\t\t}\n\t}\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nexport class Subgraphs extends BaseClient {\n\tasync list(): Promise<{ data: SubgraphSummary[] }> {\n\t\treturn this.request<{ data: SubgraphSummary[] }>(\"GET\", \"/api/subgraphs\");\n\t}\n\n\tasync get(name: string): Promise<SubgraphDetail> {\n\t\treturn this.request<SubgraphDetail>(\"GET\", `/api/subgraphs/${name}`);\n\t}\n\n\tasync reindex(\n\t\tname: string,\n\t\toptions?: { fromBlock?: number; toBlock?: number },\n\t): Promise<ReindexResponse> {\n\t\treturn this.request<ReindexResponse>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/reindex`,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tasync stop(name: string): Promise<{ message: string }> {\n\t\treturn this.request<{ message: string }>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/stop`,\n\t\t);\n\t}\n\n\tasync backfill(\n\t\tname: string,\n\t\toptions: { fromBlock: number; toBlock: number },\n\t): Promise<ReindexResponse> {\n\t\treturn this.request<ReindexResponse>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/backfill`,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tasync gaps(\n\t\tname: string,\n\t\topts?: { limit?: number; offset?: number; resolved?: boolean },\n\t): Promise<SubgraphGapsResponse> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) qs.set(\"_limit\", String(opts.limit));\n\t\tif (opts?.offset !== undefined) qs.set(\"_offset\", String(opts.offset));\n\t\tif (opts?.resolved !== undefined) qs.set(\"resolved\", String(opts.resolved));\n\t\tconst query = qs.toString();\n\t\treturn this.request<SubgraphGapsResponse>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/gaps${query ? `?${query}` : \"\"}`,\n\t\t);\n\t}\n\n\tasync delete(name: string): Promise<{ message: string }> {\n\t\treturn this.request<{ message: string }>(\n\t\t\t\"DELETE\",\n\t\t\t`/api/subgraphs/${name}`,\n\t\t);\n\t}\n\n\tasync deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse> {\n\t\treturn this.request<DeploySubgraphResponse>(\"POST\", \"/api/subgraphs\", data);\n\t}\n\n\tasync queryTable(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<unknown[]> {\n\t\tconst result = await this.request<{ data: unknown[] } | unknown[]>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`,\n\t\t);\n\t\treturn Array.isArray(result) ? result : result.data;\n\t}\n\n\tasync queryTableCount(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<{ count: number }> {\n\t\treturn this.request<{ count: number }>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/${table}/count${buildSubgraphQueryString(params)}`,\n\t\t);\n\t}\n\n\t/**\n\t * Returns a typed client for a subgraph defined with `defineSubgraph()`.\n\t * Row types are inferred from the subgraph's schema literal types.\n\t *\n\t * @example\n\t * ```ts\n\t * import mySubgraph from './subgraphs/my-token-subgraph'\n\t * const client = sl.subgraphs.typed(mySubgraph)\n\t * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })\n\t * // rows: InferTableRow<typeof mySubgraph.schema.transfers>[]\n\t * ```\n\t */\n\ttyped<T extends { name: string; schema: Record<string, unknown> }>(\n\t\tdef: T,\n\t): InferSubgraphClient<T> {\n\t\tconst result: Record<string, unknown> = {};\n\n\t\tfor (const tableName of Object.keys(def.schema)) {\n\t\t\tresult[tableName] = this.createTableClient(def.name, tableName);\n\t\t}\n\n\t\treturn result as InferSubgraphClient<T>;\n\t}\n\n\tprivate createTableClient(subgraphName: string, tableName: string) {\n\t\tconst self = this;\n\n\t\treturn {\n\t\t\tasync findMany<TRow>(\n\t\t\t\toptions: FindManyOptions<TRow> = {},\n\t\t\t): Promise<TRow[]> {\n\t\t\t\tconst filters = options.where\n\t\t\t\t\t? serializeWhere(options.where as Record<string, unknown>)\n\t\t\t\t\t: undefined;\n\n\t\t\t\tlet sort: string | undefined;\n\t\t\t\tlet order: string | undefined;\n\t\t\t\tif (options.orderBy) {\n\t\t\t\t\tconst entries = Object.entries(options.orderBy) as [\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\"asc\" | \"desc\",\n\t\t\t\t\t][];\n\t\t\t\t\tif (entries.length > 0) {\n\t\t\t\t\t\tif (entries.length > 1) {\n\t\t\t\t\t\t\tconst extra = entries\n\t\t\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t\t\t.map(([col]) => col)\n\t\t\t\t\t\t\t\t.join(\", \");\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`orderBy supports only one column; remove extra keys: ${extra}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst [col, dir] = entries[0]!;\n\t\t\t\t\t\tsort = resolveOrderByColumn(col);\n\t\t\t\t\t\torder = dir ?? \"asc\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst params: SubgraphQueryParams = {\n\t\t\t\t\tsort,\n\t\t\t\t\torder,\n\t\t\t\t\tlimit: options.limit,\n\t\t\t\t\toffset: options.offset,\n\t\t\t\t\tfields: options.fields?.join(\",\"),\n\t\t\t\t\tfilters,\n\t\t\t\t};\n\n\t\t\t\treturn self.queryTable(subgraphName, tableName, params) as Promise<\n\t\t\t\t\tTRow[]\n\t\t\t\t>;\n\t\t\t},\n\n\t\t\tasync count<TRow>(where?: WhereInput<TRow>): Promise<number> {\n\t\t\t\tconst filters = where\n\t\t\t\t\t? serializeWhere(where as Record<string, unknown>)\n\t\t\t\t\t: undefined;\n\n\t\t\t\tconst result = await self.queryTableCount(subgraphName, tableName, {\n\t\t\t\t\tfilters,\n\t\t\t\t});\n\t\t\t\treturn result.count;\n\t\t\t},\n\t\t};\n\t}\n}\n",
|
|
10
|
-
"import type {
|
|
11
|
+
"import type {\n\tWorkflowRun,\n\tWorkflowRunStatus,\n} from \"@secondlayer/workflows\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface WorkflowSummary {\n\tname: string;\n\tstatus: \"active\" | \"paused\";\n\ttriggerType: \"event\" | \"stream\" | \"schedule\" | \"manual\";\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface WorkflowDetail extends WorkflowSummary {\n\ttrigger: Record<string, unknown>;\n\tretries?: { maxAttempts?: number; backoffMs?: number };\n\ttimeout?: number;\n\ttotalRuns: number;\n\tlastRunAt: string | null;\n}\n\nexport interface WorkflowRunSummary {\n\tid: string;\n\tworkflowName: string;\n\tstatus: WorkflowRunStatus;\n\tduration: number;\n\taiTokensUsed: number;\n\ttriggeredAt: string;\n\tcompletedAt: string | null;\n}\n\nexport class Workflows extends BaseClient {\n\tasync deploy(data: {\n\t\tname: string;\n\t\ttrigger: Record<string, unknown>;\n\t\thandlerCode: string;\n\t\tretries?: Record<string, unknown>;\n\t\ttimeout?: number;\n\t}): Promise<{ action: string; workflowId: string; message: string }> {\n\t\treturn this.request(\"POST\", \"/api/workflows\", data);\n\t}\n\n\tasync list(): Promise<{ workflows: WorkflowSummary[] }> {\n\t\treturn this.request(\"GET\", \"/api/workflows\");\n\t}\n\n\tasync get(name: string): Promise<WorkflowDetail> {\n\t\treturn this.request(\"GET\", `/api/workflows/${name}`);\n\t}\n\n\tasync trigger(\n\t\tname: string,\n\t\tinput?: Record<string, unknown>,\n\t): Promise<{ runId: string }> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/trigger`, input ? { input } : undefined);\n\t}\n\n\tasync pause(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/pause`);\n\t}\n\n\tasync resume(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/resume`);\n\t}\n\n\tasync delete(name: string): Promise<void> {\n\t\treturn this.request(\"DELETE\", `/api/workflows/${name}`);\n\t}\n\n\tasync listRuns(\n\t\tname: string,\n\t\tparams?: { status?: WorkflowRunStatus; limit?: number },\n\t): Promise<{ runs: WorkflowRunSummary[] }> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (params?.status) qs.set(\"status\", params.status);\n\t\tif (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n\t\tconst query = qs.toString();\n\t\treturn this.request(\"GET\", `/api/workflows/${name}/runs${query ? `?${query}` : \"\"}`);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRun> {\n\t\treturn this.request(\"GET\", `/api/workflows/runs/${runId}`);\n\t}\n}\n",
|
|
12
|
+
"import type { QueueStats } from \"@secondlayer/shared/types\";\nimport { BaseClient } from \"./base.ts\";\nimport type { SecondLayerOptions } from \"./base.ts\";\nimport { Marketplace } from \"./marketplace/client.ts\";\nimport { Streams } from \"./streams/client.ts\";\nimport { Subgraphs } from \"./subgraphs/client.ts\";\nimport { Workflows } from \"./workflows/client.ts\";\n\nexport class SecondLayer extends BaseClient {\n\treadonly streams: Streams;\n\treadonly subgraphs: Subgraphs;\n\treadonly marketplace: Marketplace;\n\treadonly workflows: Workflows;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tsuper(options);\n\t\tthis.streams = new Streams(options);\n\t\tthis.subgraphs = new Subgraphs(options);\n\t\tthis.marketplace = new Marketplace(options);\n\t\tthis.workflows = new Workflows(options);\n\t}\n\n\tasync getQueueStats(): Promise<QueueStats> {\n\t\tconst status = await this.request<{ queue: QueueStats }>(\"GET\", \"/status\");\n\t\treturn status.queue;\n\t}\n}\n",
|
|
11
13
|
"import type { InferSubgraphClient } from \"@secondlayer/subgraphs\";\nimport type { SecondLayerOptions } from \"../base.ts\";\nimport { SecondLayer } from \"../client.ts\";\nimport { Subgraphs } from \"./client.ts\";\n\n/**\n * Returns a typed client for a subgraph defined with `defineSubgraph()`.\n *\n * Accepts a plain options object, a `SecondLayer` instance, or a `Subgraphs` instance.\n *\n * @example\n * ```ts\n * import mySubgraph from './subgraphs/my-subgraph'\n * import { getSubgraph } from '@secondlayer/sdk'\n *\n * const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })\n * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })\n * ```\n */\nexport function getSubgraph<\n\tT extends { name: string; schema: Record<string, unknown> },\n>(\n\tdef: T,\n\toptions: Partial<SecondLayerOptions> | SecondLayer | Subgraphs = {},\n): InferSubgraphClient<T> {\n\tif (options instanceof Subgraphs) {\n\t\treturn options.typed(def);\n\t}\n\tif (options instanceof SecondLayer) {\n\t\treturn options.subgraphs.typed(def);\n\t}\n\treturn new Subgraphs(options).typed(def);\n}\n"
|
|
12
14
|
],
|
|
13
|
-
"mappings": ";AAeO,MAAM,iBAAiB,M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AAO;AAAA;AAEhB;;;ACPO,SAAS,WAEf,CACA,KACA,UAAiE,CAAC,GACzC;AAAA,EACzB,IAAI,mBAAmB,WAAW;AAAA,IACjC,OAAO,QAAQ,MAAM,GAAG;AAAA,EACzB;AAAA,EACA,IAAI,mBAAmB,aAAa;AAAA,IACnC,OAAO,QAAQ,UAAU,MAAM,GAAG;AAAA,EACnC;AAAA,EACA,OAAO,IAAI,UAAU,OAAO,EAAE,MAAM,GAAG;AAAA;",
|
|
16
|
+
"debugId": "6B8EDB3066EE171A64756E2164756E21",
|
|
15
17
|
"names": []
|
|
16
18
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CreatorProfile, MarketplaceSubgraphDetail, MarketplaceSubgraphSummary, SubgraphQueryParams } from "@secondlayer/shared/schemas";
|
|
2
|
+
interface SecondLayerOptions {
|
|
3
|
+
/** Base URL of the Secondlayer API (trailing slashes are stripped). */
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
/** Bearer token for authenticated requests. */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare abstract class BaseClient {
|
|
9
|
+
protected baseUrl: string;
|
|
10
|
+
protected apiKey?: string;
|
|
11
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
12
|
+
static authHeaders(apiKey?: string): Record<string, string>;
|
|
13
|
+
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
interface MarketplaceBrowseOptions {
|
|
16
|
+
tags?: string[];
|
|
17
|
+
search?: string;
|
|
18
|
+
sort?: "recent" | "popular" | "name";
|
|
19
|
+
limit?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
}
|
|
22
|
+
declare class Marketplace extends BaseClient {
|
|
23
|
+
browse(opts?: MarketplaceBrowseOptions): Promise<{
|
|
24
|
+
data: MarketplaceSubgraphSummary[]
|
|
25
|
+
meta: {
|
|
26
|
+
total: number
|
|
27
|
+
limit: number
|
|
28
|
+
offset: number
|
|
29
|
+
}
|
|
30
|
+
}>;
|
|
31
|
+
get(name: string): Promise<MarketplaceSubgraphDetail>;
|
|
32
|
+
creator(slug: string): Promise<CreatorProfile>;
|
|
33
|
+
fork(name: string, newName?: string): Promise<{
|
|
34
|
+
action: string
|
|
35
|
+
subgraphId: string
|
|
36
|
+
name: string
|
|
37
|
+
forkedFrom: string
|
|
38
|
+
}>;
|
|
39
|
+
queryTable(name: string, table: string, params?: SubgraphQueryParams): Promise<{
|
|
40
|
+
data: unknown[]
|
|
41
|
+
meta: {
|
|
42
|
+
total: number
|
|
43
|
+
limit: number
|
|
44
|
+
offset: number
|
|
45
|
+
}
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
import { CreatorProfile as CreatorProfile2, MarketplaceSubgraphDetail as MarketplaceSubgraphDetail2, MarketplaceSubgraphSummary as MarketplaceSubgraphSummary2 } from "@secondlayer/shared/schemas";
|
|
49
|
+
export { MarketplaceSubgraphSummary2 as MarketplaceSubgraphSummary, MarketplaceSubgraphDetail2 as MarketplaceSubgraphDetail, MarketplaceBrowseOptions, Marketplace, CreatorProfile2 as CreatorProfile };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
class ApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
constructor(status, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.name = "ApiError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/base.ts
|
|
12
|
+
var DEFAULT_BASE_URL = "https://api.secondlayer.tools";
|
|
13
|
+
|
|
14
|
+
class BaseClient {
|
|
15
|
+
baseUrl;
|
|
16
|
+
apiKey;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
19
|
+
this.apiKey = options.apiKey;
|
|
20
|
+
}
|
|
21
|
+
static authHeaders(apiKey) {
|
|
22
|
+
const headers = {
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
};
|
|
25
|
+
if (apiKey) {
|
|
26
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
async request(method, path, body) {
|
|
31
|
+
const url = `${this.baseUrl}${path}`;
|
|
32
|
+
const headers = BaseClient.authHeaders(this.apiKey);
|
|
33
|
+
let response;
|
|
34
|
+
try {
|
|
35
|
+
response = await fetch(url, {
|
|
36
|
+
method,
|
|
37
|
+
headers,
|
|
38
|
+
body: body ? JSON.stringify(body) : undefined
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
throw new ApiError(0, `Cannot reach API at ${this.baseUrl}. Check your connection or try again.`);
|
|
42
|
+
}
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
if (response.status === 401) {
|
|
45
|
+
throw new ApiError(401, "API key invalid or expired.");
|
|
46
|
+
}
|
|
47
|
+
if (response.status === 429) {
|
|
48
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
49
|
+
const msg = retryAfter ? `Rate limited. Wait ${retryAfter} seconds.` : "Rate limited. Try again later.";
|
|
50
|
+
throw new ApiError(429, msg);
|
|
51
|
+
}
|
|
52
|
+
if (response.status >= 500) {
|
|
53
|
+
throw new ApiError(response.status, `Server error. Try again or check status at ${this.baseUrl}/health`);
|
|
54
|
+
}
|
|
55
|
+
const errorBody = await response.text();
|
|
56
|
+
let message = `HTTP ${response.status}`;
|
|
57
|
+
try {
|
|
58
|
+
const json = JSON.parse(errorBody);
|
|
59
|
+
const err = json.error ?? json.message;
|
|
60
|
+
if (typeof err === "string") {
|
|
61
|
+
message = err;
|
|
62
|
+
} else if (err && typeof err === "object") {
|
|
63
|
+
message = JSON.stringify(err);
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
if (errorBody)
|
|
67
|
+
message = errorBody;
|
|
68
|
+
}
|
|
69
|
+
throw new ApiError(response.status, message);
|
|
70
|
+
}
|
|
71
|
+
if (response.status === 204) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return response.json();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/marketplace/client.ts
|
|
79
|
+
function buildMarketplaceQuery(opts) {
|
|
80
|
+
const qs = new URLSearchParams;
|
|
81
|
+
if (opts.tags?.length)
|
|
82
|
+
qs.set("tags", opts.tags.join(","));
|
|
83
|
+
if (opts.search)
|
|
84
|
+
qs.set("search", opts.search);
|
|
85
|
+
if (opts.sort)
|
|
86
|
+
qs.set("_sort", opts.sort);
|
|
87
|
+
if (opts.limit !== undefined)
|
|
88
|
+
qs.set("_limit", String(opts.limit));
|
|
89
|
+
if (opts.offset !== undefined)
|
|
90
|
+
qs.set("_offset", String(opts.offset));
|
|
91
|
+
const str = qs.toString();
|
|
92
|
+
return str ? `?${str}` : "";
|
|
93
|
+
}
|
|
94
|
+
function buildSubgraphQueryString(params) {
|
|
95
|
+
const qs = new URLSearchParams;
|
|
96
|
+
if (params.sort)
|
|
97
|
+
qs.set("_sort", params.sort);
|
|
98
|
+
if (params.order)
|
|
99
|
+
qs.set("_order", params.order);
|
|
100
|
+
if (params.limit !== undefined)
|
|
101
|
+
qs.set("_limit", String(params.limit));
|
|
102
|
+
if (params.offset !== undefined)
|
|
103
|
+
qs.set("_offset", String(params.offset));
|
|
104
|
+
if (params.fields)
|
|
105
|
+
qs.set("_fields", params.fields);
|
|
106
|
+
if (params.filters) {
|
|
107
|
+
for (const [key, value] of Object.entries(params.filters)) {
|
|
108
|
+
qs.set(key, String(value));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const str = qs.toString();
|
|
112
|
+
return str ? `?${str}` : "";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class Marketplace extends BaseClient {
|
|
116
|
+
async browse(opts = {}) {
|
|
117
|
+
return this.request("GET", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);
|
|
118
|
+
}
|
|
119
|
+
async get(name) {
|
|
120
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}`);
|
|
121
|
+
}
|
|
122
|
+
async creator(slug) {
|
|
123
|
+
return this.request("GET", `/api/marketplace/creators/${slug}`);
|
|
124
|
+
}
|
|
125
|
+
async fork(name, newName) {
|
|
126
|
+
return this.request("POST", `/api/marketplace/subgraphs/${name}/fork`, {
|
|
127
|
+
newName
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async queryTable(name, table, params = {}) {
|
|
131
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
Marketplace
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//# debugId=3BDEB4E6AF6FD61764756E2164756E21
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/base.ts", "../src/marketplace/client.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Error thrown by {@link SecondLayer} when an API request fails.\n * Includes the HTTP status code for programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await client.streams.get(\"abc123\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Stream not found\");\n * }\n * }\n * ```\n */\nexport class ApiError extends Error {\n\tconstructor(\n\t\t/** HTTP status code (0 for network errors). */\n\t\tpublic status: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n",
|
|
6
|
+
"import { ApiError } from \"./errors.ts\";\n\nexport interface SecondLayerOptions {\n\t/** Base URL of the Secondlayer API (trailing slashes are stripped). */\n\tbaseUrl: string;\n\t/** Bearer token for authenticated requests. */\n\tapiKey?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t}\n\n\tstatic authHeaders(apiKey?: string): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t};\n\t\tif (apiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tprotected async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst url = `${this.baseUrl}${path}`;\n\t\tconst headers = BaseClient.authHeaders(this.apiKey);\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: body ? JSON.stringify(body) : undefined,\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t0,\n\t\t\t\t`Cannot reach API at ${this.baseUrl}. Check your connection or try again.`,\n\t\t\t);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 401) {\n\t\t\t\tthrow new ApiError(401, \"API key invalid or expired.\");\n\t\t\t}\n\n\t\t\tif (response.status === 429) {\n\t\t\t\tconst retryAfter = response.headers.get(\"Retry-After\");\n\t\t\t\tconst msg = retryAfter\n\t\t\t\t\t? `Rate limited. Wait ${retryAfter} seconds.`\n\t\t\t\t\t: \"Rate limited. Try again later.\";\n\t\t\t\tthrow new ApiError(429, msg);\n\t\t\t}\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tthrow new ApiError(\n\t\t\t\t\tresponse.status,\n\t\t\t\t\t`Server error. Try again or check status at ${this.baseUrl}/health`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst errorBody = await response.text();\n\t\t\tlet message = `HTTP ${response.status}`;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tconst err = json.error ?? json.message;\n\t\t\t\tif (typeof err === \"string\") {\n\t\t\t\t\tmessage = err;\n\t\t\t\t} else if (err && typeof err === \"object\") {\n\t\t\t\t\tmessage = JSON.stringify(err);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tif (errorBody) message = errorBody;\n\t\t\t}\n\t\t\tthrow new ApiError(response.status, message);\n\t\t}\n\n\t\tif (response.status === 204) {\n\t\t\treturn undefined as T;\n\t\t}\n\n\t\treturn response.json() as Promise<T>;\n\t}\n}\n",
|
|
7
|
+
"import type {\n\tCreatorProfile,\n\tMarketplaceSubgraphDetail,\n\tMarketplaceSubgraphSummary,\n\tSubgraphQueryParams,\n} from \"@secondlayer/shared/schemas\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface MarketplaceBrowseOptions {\n\ttags?: string[];\n\tsearch?: string;\n\tsort?: \"recent\" | \"popular\" | \"name\";\n\tlimit?: number;\n\toffset?: number;\n}\n\nfunction buildMarketplaceQuery(opts: MarketplaceBrowseOptions): string {\n\tconst qs = new URLSearchParams();\n\tif (opts.tags?.length) qs.set(\"tags\", opts.tags.join(\",\"));\n\tif (opts.search) qs.set(\"search\", opts.search);\n\tif (opts.sort) qs.set(\"_sort\", opts.sort);\n\tif (opts.limit !== undefined) qs.set(\"_limit\", String(opts.limit));\n\tif (opts.offset !== undefined) qs.set(\"_offset\", String(opts.offset));\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nfunction buildSubgraphQueryString(params: SubgraphQueryParams): string {\n\tconst qs = new URLSearchParams();\n\tif (params.sort) qs.set(\"_sort\", params.sort);\n\tif (params.order) qs.set(\"_order\", params.order);\n\tif (params.limit !== undefined) qs.set(\"_limit\", String(params.limit));\n\tif (params.offset !== undefined) qs.set(\"_offset\", String(params.offset));\n\tif (params.fields) qs.set(\"_fields\", params.fields);\n\tif (params.filters) {\n\t\tfor (const [key, value] of Object.entries(params.filters)) {\n\t\t\tqs.set(key, String(value));\n\t\t}\n\t}\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nexport class Marketplace extends BaseClient {\n\tasync browse(\n\t\topts: MarketplaceBrowseOptions = {},\n\t): Promise<{\n\t\tdata: MarketplaceSubgraphSummary[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);\n\t}\n\n\tasync get(name: string): Promise<MarketplaceSubgraphDetail> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs/${name}`);\n\t}\n\n\tasync creator(slug: string): Promise<CreatorProfile> {\n\t\treturn this.request(\"GET\", `/api/marketplace/creators/${slug}`);\n\t}\n\n\tasync fork(\n\t\tname: string,\n\t\tnewName?: string,\n\t): Promise<{\n\t\taction: string;\n\t\tsubgraphId: string;\n\t\tname: string;\n\t\tforkedFrom: string;\n\t}> {\n\t\treturn this.request(\"POST\", `/api/marketplace/subgraphs/${name}/fork`, {\n\t\t\tnewName,\n\t\t});\n\t}\n\n\tasync queryTable(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<{\n\t\tdata: unknown[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\n\t\t\t\"GET\",\n\t\t\t`/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`,\n\t\t);\n\t}\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AAeO,MAAM,iBAAiB,MAAM;AAAA,EAG3B;AAAA,EAFR,WAAW,CAEH,QACP,SACC;AAAA,IACD,MAAM,OAAO;AAAA,IAHN;AAAA,IAIP,KAAK,OAAO;AAAA;AAEd;;;ACfA,IAAM,mBAAmB;AAAA;AAElB,MAAe,WAAW;AAAA,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O,UAAU;AAAA,IAAW,GAAG,IAAI,UAAU,OAAO,OAAO,KAAK,CAAC;AAAA,EACrE,IAAI,OAAO,WAAW;AAAA,IAAW,GAAG,IAAI,WAAW,OAAO,OAAO,MAAM,CAAC;AAAA,EACxE,IAAI,OAAO;AAAA,IAAQ,GAAG,IAAI,WAAW,OAAO,MAAM;AAAA,EAClD,IAAI,OAAO,SAAS;AAAA,IACnB,YAAY,KAAK,UAAU,OAAO,QAAQ,OAAO,OAAO,GAAG;AAAA,MAC1D,GAAG,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,IAC1B;AAAA,EACD;AAAA,EACA,MAAM,MAAM,GAAG,SAAS;AAAA,EACxB,OAAO,MAAM,IAAI,QAAQ;AAAA;AAAA;AAGnB,MAAM,oBAAoB,WAAW;AAAA,OACrC,OAAM,CACX,OAAiC,CAAC,GAIhC;AAAA,IACF,OAAO,KAAK,QAAQ,OAAO,6BAA6B,sBAAsB,IAAI,GAAG;AAAA;AAAA,OAGhF,IAAG,CAAC,MAAkD;AAAA,IAC3D,OAAO,KAAK,QAAQ,OAAO,8BAA8B,MAAM;AAAA;AAAA,OAG1D,QAAO,CAAC,MAAuC;AAAA,IACpD,OAAO,KAAK,QAAQ,OAAO,6BAA6B,MAAM;AAAA;AAAA,OAGzD,KAAI,CACT,MACA,SAME;AAAA,IACF,OAAO,KAAK,QAAQ,QAAQ,8BAA8B,aAAa;AAAA,MACtE;AAAA,IACD,CAAC;AAAA;AAAA,OAGI,WAAU,CACf,MACA,OACA,SAA8B,CAAC,GAI7B;AAAA,IACF,OAAO,KAAK,QACX,OACA,8BAA8B,QAAQ,QAAQ,yBAAyB,MAAM,GAC9E;AAAA;AAEF;",
|
|
10
|
+
"debugId": "3BDEB4E6AF6FD61764756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -63,6 +63,40 @@ declare class Subgraphs extends BaseClient {
|
|
|
63
63
|
}
|
|
64
64
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
65
65
|
import { QueueStats } from "@secondlayer/shared/types";
|
|
66
|
+
import { CreatorProfile, MarketplaceSubgraphDetail, MarketplaceSubgraphSummary, SubgraphQueryParams as SubgraphQueryParams2 } from "@secondlayer/shared/schemas";
|
|
67
|
+
interface MarketplaceBrowseOptions {
|
|
68
|
+
tags?: string[];
|
|
69
|
+
search?: string;
|
|
70
|
+
sort?: "recent" | "popular" | "name";
|
|
71
|
+
limit?: number;
|
|
72
|
+
offset?: number;
|
|
73
|
+
}
|
|
74
|
+
declare class Marketplace extends BaseClient {
|
|
75
|
+
browse(opts?: MarketplaceBrowseOptions): Promise<{
|
|
76
|
+
data: MarketplaceSubgraphSummary[]
|
|
77
|
+
meta: {
|
|
78
|
+
total: number
|
|
79
|
+
limit: number
|
|
80
|
+
offset: number
|
|
81
|
+
}
|
|
82
|
+
}>;
|
|
83
|
+
get(name: string): Promise<MarketplaceSubgraphDetail>;
|
|
84
|
+
creator(slug: string): Promise<CreatorProfile>;
|
|
85
|
+
fork(name: string, newName?: string): Promise<{
|
|
86
|
+
action: string
|
|
87
|
+
subgraphId: string
|
|
88
|
+
name: string
|
|
89
|
+
forkedFrom: string
|
|
90
|
+
}>;
|
|
91
|
+
queryTable(name: string, table: string, params?: SubgraphQueryParams2): Promise<{
|
|
92
|
+
data: unknown[]
|
|
93
|
+
meta: {
|
|
94
|
+
total: number
|
|
95
|
+
limit: number
|
|
96
|
+
offset: number
|
|
97
|
+
}
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
66
100
|
import { BulkPauseResponse, BulkResumeResponse, CreateStream, CreateStreamResponse, ListStreamsResponse, StreamResponse, UpdateStream } from "@secondlayer/shared/schemas";
|
|
67
101
|
interface DeliverySummary {
|
|
68
102
|
id: string;
|
|
@@ -106,9 +140,68 @@ declare class Streams extends BaseClient {
|
|
|
106
140
|
pauseAll(): Promise<BulkPauseResponse>;
|
|
107
141
|
resumeAll(): Promise<BulkResumeResponse>;
|
|
108
142
|
}
|
|
143
|
+
import { WorkflowRun, WorkflowRunStatus } from "@secondlayer/workflows";
|
|
144
|
+
interface WorkflowSummary {
|
|
145
|
+
name: string;
|
|
146
|
+
status: "active" | "paused";
|
|
147
|
+
triggerType: "event" | "stream" | "schedule" | "manual";
|
|
148
|
+
createdAt: string;
|
|
149
|
+
updatedAt: string;
|
|
150
|
+
}
|
|
151
|
+
interface WorkflowDetail extends WorkflowSummary {
|
|
152
|
+
trigger: Record<string, unknown>;
|
|
153
|
+
retries?: {
|
|
154
|
+
maxAttempts?: number
|
|
155
|
+
backoffMs?: number
|
|
156
|
+
};
|
|
157
|
+
timeout?: number;
|
|
158
|
+
totalRuns: number;
|
|
159
|
+
lastRunAt: string | null;
|
|
160
|
+
}
|
|
161
|
+
interface WorkflowRunSummary {
|
|
162
|
+
id: string;
|
|
163
|
+
workflowName: string;
|
|
164
|
+
status: WorkflowRunStatus;
|
|
165
|
+
duration: number;
|
|
166
|
+
aiTokensUsed: number;
|
|
167
|
+
triggeredAt: string;
|
|
168
|
+
completedAt: string | null;
|
|
169
|
+
}
|
|
170
|
+
declare class Workflows extends BaseClient {
|
|
171
|
+
deploy(data: {
|
|
172
|
+
name: string
|
|
173
|
+
trigger: Record<string, unknown>
|
|
174
|
+
handlerCode: string
|
|
175
|
+
retries?: Record<string, unknown>
|
|
176
|
+
timeout?: number
|
|
177
|
+
}): Promise<{
|
|
178
|
+
action: string
|
|
179
|
+
workflowId: string
|
|
180
|
+
message: string
|
|
181
|
+
}>;
|
|
182
|
+
list(): Promise<{
|
|
183
|
+
workflows: WorkflowSummary[]
|
|
184
|
+
}>;
|
|
185
|
+
get(name: string): Promise<WorkflowDetail>;
|
|
186
|
+
trigger(name: string, input?: Record<string, unknown>): Promise<{
|
|
187
|
+
runId: string
|
|
188
|
+
}>;
|
|
189
|
+
pause(name: string): Promise<void>;
|
|
190
|
+
resume(name: string): Promise<void>;
|
|
191
|
+
delete(name: string): Promise<void>;
|
|
192
|
+
listRuns(name: string, params?: {
|
|
193
|
+
status?: WorkflowRunStatus
|
|
194
|
+
limit?: number
|
|
195
|
+
}): Promise<{
|
|
196
|
+
runs: WorkflowRunSummary[]
|
|
197
|
+
}>;
|
|
198
|
+
getRun(runId: string): Promise<WorkflowRun>;
|
|
199
|
+
}
|
|
109
200
|
declare class SecondLayer extends BaseClient {
|
|
110
201
|
readonly streams: Streams;
|
|
111
202
|
readonly subgraphs: Subgraphs;
|
|
203
|
+
readonly marketplace: Marketplace;
|
|
204
|
+
readonly workflows: Workflows;
|
|
112
205
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
113
206
|
getQueueStats(): Promise<QueueStats>;
|
|
114
207
|
}
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -224,6 +224,63 @@ class Subgraphs extends BaseClient {
|
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
+
// src/marketplace/client.ts
|
|
228
|
+
function buildMarketplaceQuery(opts) {
|
|
229
|
+
const qs = new URLSearchParams;
|
|
230
|
+
if (opts.tags?.length)
|
|
231
|
+
qs.set("tags", opts.tags.join(","));
|
|
232
|
+
if (opts.search)
|
|
233
|
+
qs.set("search", opts.search);
|
|
234
|
+
if (opts.sort)
|
|
235
|
+
qs.set("_sort", opts.sort);
|
|
236
|
+
if (opts.limit !== undefined)
|
|
237
|
+
qs.set("_limit", String(opts.limit));
|
|
238
|
+
if (opts.offset !== undefined)
|
|
239
|
+
qs.set("_offset", String(opts.offset));
|
|
240
|
+
const str = qs.toString();
|
|
241
|
+
return str ? `?${str}` : "";
|
|
242
|
+
}
|
|
243
|
+
function buildSubgraphQueryString2(params) {
|
|
244
|
+
const qs = new URLSearchParams;
|
|
245
|
+
if (params.sort)
|
|
246
|
+
qs.set("_sort", params.sort);
|
|
247
|
+
if (params.order)
|
|
248
|
+
qs.set("_order", params.order);
|
|
249
|
+
if (params.limit !== undefined)
|
|
250
|
+
qs.set("_limit", String(params.limit));
|
|
251
|
+
if (params.offset !== undefined)
|
|
252
|
+
qs.set("_offset", String(params.offset));
|
|
253
|
+
if (params.fields)
|
|
254
|
+
qs.set("_fields", params.fields);
|
|
255
|
+
if (params.filters) {
|
|
256
|
+
for (const [key, value] of Object.entries(params.filters)) {
|
|
257
|
+
qs.set(key, String(value));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const str = qs.toString();
|
|
261
|
+
return str ? `?${str}` : "";
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
class Marketplace extends BaseClient {
|
|
265
|
+
async browse(opts = {}) {
|
|
266
|
+
return this.request("GET", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);
|
|
267
|
+
}
|
|
268
|
+
async get(name) {
|
|
269
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}`);
|
|
270
|
+
}
|
|
271
|
+
async creator(slug) {
|
|
272
|
+
return this.request("GET", `/api/marketplace/creators/${slug}`);
|
|
273
|
+
}
|
|
274
|
+
async fork(name, newName) {
|
|
275
|
+
return this.request("POST", `/api/marketplace/subgraphs/${name}/fork`, {
|
|
276
|
+
newName
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
async queryTable(name, table, params = {}) {
|
|
280
|
+
return this.request("GET", `/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString2(params)}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
227
284
|
// src/streams/client.ts
|
|
228
285
|
class Streams extends BaseClient {
|
|
229
286
|
async requestWithStreamId(method, pathTemplate, id, body) {
|
|
@@ -302,14 +359,55 @@ class Streams extends BaseClient {
|
|
|
302
359
|
}
|
|
303
360
|
}
|
|
304
361
|
|
|
362
|
+
// src/workflows/client.ts
|
|
363
|
+
class Workflows extends BaseClient {
|
|
364
|
+
async deploy(data) {
|
|
365
|
+
return this.request("POST", "/api/workflows", data);
|
|
366
|
+
}
|
|
367
|
+
async list() {
|
|
368
|
+
return this.request("GET", "/api/workflows");
|
|
369
|
+
}
|
|
370
|
+
async get(name) {
|
|
371
|
+
return this.request("GET", `/api/workflows/${name}`);
|
|
372
|
+
}
|
|
373
|
+
async trigger(name, input) {
|
|
374
|
+
return this.request("POST", `/api/workflows/${name}/trigger`, input ? { input } : undefined);
|
|
375
|
+
}
|
|
376
|
+
async pause(name) {
|
|
377
|
+
return this.request("POST", `/api/workflows/${name}/pause`);
|
|
378
|
+
}
|
|
379
|
+
async resume(name) {
|
|
380
|
+
return this.request("POST", `/api/workflows/${name}/resume`);
|
|
381
|
+
}
|
|
382
|
+
async delete(name) {
|
|
383
|
+
return this.request("DELETE", `/api/workflows/${name}`);
|
|
384
|
+
}
|
|
385
|
+
async listRuns(name, params) {
|
|
386
|
+
const qs = new URLSearchParams;
|
|
387
|
+
if (params?.status)
|
|
388
|
+
qs.set("status", params.status);
|
|
389
|
+
if (params?.limit !== undefined)
|
|
390
|
+
qs.set("limit", String(params.limit));
|
|
391
|
+
const query = qs.toString();
|
|
392
|
+
return this.request("GET", `/api/workflows/${name}/runs${query ? `?${query}` : ""}`);
|
|
393
|
+
}
|
|
394
|
+
async getRun(runId) {
|
|
395
|
+
return this.request("GET", `/api/workflows/runs/${runId}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
305
399
|
// src/client.ts
|
|
306
400
|
class SecondLayer extends BaseClient {
|
|
307
401
|
streams;
|
|
308
402
|
subgraphs;
|
|
403
|
+
marketplace;
|
|
404
|
+
workflows;
|
|
309
405
|
constructor(options = {}) {
|
|
310
406
|
super(options);
|
|
311
407
|
this.streams = new Streams(options);
|
|
312
408
|
this.subgraphs = new Subgraphs(options);
|
|
409
|
+
this.marketplace = new Marketplace(options);
|
|
410
|
+
this.workflows = new Workflows(options);
|
|
313
411
|
}
|
|
314
412
|
async getQueueStats() {
|
|
315
413
|
const status = await this.request("GET", "/status");
|
|
@@ -332,5 +430,5 @@ export {
|
|
|
332
430
|
Subgraphs
|
|
333
431
|
};
|
|
334
432
|
|
|
335
|
-
//# debugId=
|
|
433
|
+
//# debugId=330EFEE1434C2A0964756E2164756E21
|
|
336
434
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/errors.ts", "../src/base.ts", "../src/subgraphs/serialize.ts", "../src/subgraphs/client.ts", "../src/streams/client.ts", "../src/client.ts", "../src/subgraphs/get-subgraph.ts"],
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/base.ts", "../src/subgraphs/serialize.ts", "../src/subgraphs/client.ts", "../src/marketplace/client.ts", "../src/streams/client.ts", "../src/workflows/client.ts", "../src/client.ts", "../src/subgraphs/get-subgraph.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Error thrown by {@link SecondLayer} when an API request fails.\n * Includes the HTTP status code for programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await client.streams.get(\"abc123\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Stream not found\");\n * }\n * }\n * ```\n */\nexport class ApiError extends Error {\n\tconstructor(\n\t\t/** HTTP status code (0 for network errors). */\n\t\tpublic status: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n",
|
|
6
6
|
"import { ApiError } from \"./errors.ts\";\n\nexport interface SecondLayerOptions {\n\t/** Base URL of the Secondlayer API (trailing slashes are stripped). */\n\tbaseUrl: string;\n\t/** Bearer token for authenticated requests. */\n\tapiKey?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t}\n\n\tstatic authHeaders(apiKey?: string): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t};\n\t\tif (apiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tprotected async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst url = `${this.baseUrl}${path}`;\n\t\tconst headers = BaseClient.authHeaders(this.apiKey);\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: body ? JSON.stringify(body) : undefined,\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t0,\n\t\t\t\t`Cannot reach API at ${this.baseUrl}. Check your connection or try again.`,\n\t\t\t);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 401) {\n\t\t\t\tthrow new ApiError(401, \"API key invalid or expired.\");\n\t\t\t}\n\n\t\t\tif (response.status === 429) {\n\t\t\t\tconst retryAfter = response.headers.get(\"Retry-After\");\n\t\t\t\tconst msg = retryAfter\n\t\t\t\t\t? `Rate limited. Wait ${retryAfter} seconds.`\n\t\t\t\t\t: \"Rate limited. Try again later.\";\n\t\t\t\tthrow new ApiError(429, msg);\n\t\t\t}\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tthrow new ApiError(\n\t\t\t\t\tresponse.status,\n\t\t\t\t\t`Server error. Try again or check status at ${this.baseUrl}/health`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst errorBody = await response.text();\n\t\t\tlet message = `HTTP ${response.status}`;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tconst err = json.error ?? json.message;\n\t\t\t\tif (typeof err === \"string\") {\n\t\t\t\t\tmessage = err;\n\t\t\t\t} else if (err && typeof err === \"object\") {\n\t\t\t\t\tmessage = JSON.stringify(err);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tif (errorBody) message = errorBody;\n\t\t\t}\n\t\t\tthrow new ApiError(response.status, message);\n\t\t}\n\n\t\tif (response.status === 204) {\n\t\t\treturn undefined as T;\n\t\t}\n\n\t\treturn response.json() as Promise<T>;\n\t}\n}\n",
|
|
7
7
|
"/**\n * Maps camelCase system column names (with or without `_` prefix) to the\n * actual snake_case DB column names used in query params.\n */\nconst SYSTEM_COLUMN_MAP: Record<string, string> = {\n\t// underscore-prefixed camelCase (canonical row shape)\n\t_blockHeight: \"_block_height\",\n\t_txId: \"_tx_id\",\n\t_createdAt: \"_created_at\",\n\t_id: \"_id\",\n\t// no-prefix aliases\n\tblockHeight: \"_block_height\",\n\ttxId: \"_tx_id\",\n\tcreatedAt: \"_created_at\",\n\tid: \"_id\",\n};\n\nfunction resolveColumn(col: string): string {\n\treturn SYSTEM_COLUMN_MAP[col] ?? col;\n}\n\n/**\n * Serializes a WhereInput object into the flat filter map expected by\n * SubgraphQueryParams.filters (and the REST API query string).\n *\n * Scalar values → `{ column: \"value\" }`\n * Comparison objects → `{ \"column.gte\": \"100\", \"column.lt\": \"200\" }`\n * System column aliases → `blockHeight` / `_blockHeight` both → `_block_height`\n */\nexport function serializeWhere(\n\twhere: Record<string, unknown>,\n): Record<string, string> {\n\tconst filters: Record<string, string> = {};\n\n\tfor (const [column, value] of Object.entries(where)) {\n\t\tif (value === null || value === undefined) continue;\n\n\t\tconst col = resolveColumn(column);\n\n\t\tif (typeof value === \"object\" && !Array.isArray(value)) {\n\t\t\tconst ops = value as Record<string, unknown>;\n\t\t\tfor (const [op, opValue] of Object.entries(ops)) {\n\t\t\t\tif (opValue === null || opValue === undefined) continue;\n\t\t\t\tif (op === \"eq\") {\n\t\t\t\t\tfilters[col] = String(opValue);\n\t\t\t\t} else if ([\"neq\", \"gt\", \"gte\", \"lt\", \"lte\"].includes(op)) {\n\t\t\t\t\tfilters[`${col}.${op}`] = String(opValue);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfilters[col] = String(value);\n\t\t}\n\t}\n\n\treturn filters;\n}\n\n/**\n * Resolves an orderBy column name (either alias or canonical) to the DB column name.\n */\nexport function resolveOrderByColumn(col: string): string {\n\treturn resolveColumn(col);\n}\n",
|
|
8
8
|
"import type {\n\tReindexResponse,\n\tSubgraphDetail,\n\tSubgraphGapsResponse,\n\tSubgraphQueryParams,\n\tSubgraphSummary,\n} from \"@secondlayer/shared/schemas\";\nimport type {\n\tDeploySubgraphRequest,\n\tDeploySubgraphResponse,\n} from \"@secondlayer/shared/schemas/subgraphs\";\nimport type {\n\tFindManyOptions,\n\tInferSubgraphClient,\n\tWhereInput,\n} from \"@secondlayer/subgraphs\";\nimport { BaseClient } from \"../base.ts\";\nimport { resolveOrderByColumn, serializeWhere } from \"./serialize.ts\";\n\nfunction buildSubgraphQueryString(params: SubgraphQueryParams): string {\n\tconst qs = new URLSearchParams();\n\tif (params.sort) qs.set(\"_sort\", params.sort);\n\tif (params.order) qs.set(\"_order\", params.order);\n\tif (params.limit !== undefined) qs.set(\"_limit\", String(params.limit));\n\tif (params.offset !== undefined) qs.set(\"_offset\", String(params.offset));\n\tif (params.fields) qs.set(\"_fields\", params.fields);\n\tif (params.filters) {\n\t\tfor (const [key, value] of Object.entries(params.filters)) {\n\t\t\tqs.set(key, String(value));\n\t\t}\n\t}\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nexport class Subgraphs extends BaseClient {\n\tasync list(): Promise<{ data: SubgraphSummary[] }> {\n\t\treturn this.request<{ data: SubgraphSummary[] }>(\"GET\", \"/api/subgraphs\");\n\t}\n\n\tasync get(name: string): Promise<SubgraphDetail> {\n\t\treturn this.request<SubgraphDetail>(\"GET\", `/api/subgraphs/${name}`);\n\t}\n\n\tasync reindex(\n\t\tname: string,\n\t\toptions?: { fromBlock?: number; toBlock?: number },\n\t): Promise<ReindexResponse> {\n\t\treturn this.request<ReindexResponse>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/reindex`,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tasync stop(name: string): Promise<{ message: string }> {\n\t\treturn this.request<{ message: string }>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/stop`,\n\t\t);\n\t}\n\n\tasync backfill(\n\t\tname: string,\n\t\toptions: { fromBlock: number; toBlock: number },\n\t): Promise<ReindexResponse> {\n\t\treturn this.request<ReindexResponse>(\n\t\t\t\"POST\",\n\t\t\t`/api/subgraphs/${name}/backfill`,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tasync gaps(\n\t\tname: string,\n\t\topts?: { limit?: number; offset?: number; resolved?: boolean },\n\t): Promise<SubgraphGapsResponse> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) qs.set(\"_limit\", String(opts.limit));\n\t\tif (opts?.offset !== undefined) qs.set(\"_offset\", String(opts.offset));\n\t\tif (opts?.resolved !== undefined) qs.set(\"resolved\", String(opts.resolved));\n\t\tconst query = qs.toString();\n\t\treturn this.request<SubgraphGapsResponse>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/gaps${query ? `?${query}` : \"\"}`,\n\t\t);\n\t}\n\n\tasync delete(name: string): Promise<{ message: string }> {\n\t\treturn this.request<{ message: string }>(\n\t\t\t\"DELETE\",\n\t\t\t`/api/subgraphs/${name}`,\n\t\t);\n\t}\n\n\tasync deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse> {\n\t\treturn this.request<DeploySubgraphResponse>(\"POST\", \"/api/subgraphs\", data);\n\t}\n\n\tasync queryTable(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<unknown[]> {\n\t\tconst result = await this.request<{ data: unknown[] } | unknown[]>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`,\n\t\t);\n\t\treturn Array.isArray(result) ? result : result.data;\n\t}\n\n\tasync queryTableCount(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<{ count: number }> {\n\t\treturn this.request<{ count: number }>(\n\t\t\t\"GET\",\n\t\t\t`/api/subgraphs/${name}/${table}/count${buildSubgraphQueryString(params)}`,\n\t\t);\n\t}\n\n\t/**\n\t * Returns a typed client for a subgraph defined with `defineSubgraph()`.\n\t * Row types are inferred from the subgraph's schema literal types.\n\t *\n\t * @example\n\t * ```ts\n\t * import mySubgraph from './subgraphs/my-token-subgraph'\n\t * const client = sl.subgraphs.typed(mySubgraph)\n\t * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })\n\t * // rows: InferTableRow<typeof mySubgraph.schema.transfers>[]\n\t * ```\n\t */\n\ttyped<T extends { name: string; schema: Record<string, unknown> }>(\n\t\tdef: T,\n\t): InferSubgraphClient<T> {\n\t\tconst result: Record<string, unknown> = {};\n\n\t\tfor (const tableName of Object.keys(def.schema)) {\n\t\t\tresult[tableName] = this.createTableClient(def.name, tableName);\n\t\t}\n\n\t\treturn result as InferSubgraphClient<T>;\n\t}\n\n\tprivate createTableClient(subgraphName: string, tableName: string) {\n\t\tconst self = this;\n\n\t\treturn {\n\t\t\tasync findMany<TRow>(\n\t\t\t\toptions: FindManyOptions<TRow> = {},\n\t\t\t): Promise<TRow[]> {\n\t\t\t\tconst filters = options.where\n\t\t\t\t\t? serializeWhere(options.where as Record<string, unknown>)\n\t\t\t\t\t: undefined;\n\n\t\t\t\tlet sort: string | undefined;\n\t\t\t\tlet order: string | undefined;\n\t\t\t\tif (options.orderBy) {\n\t\t\t\t\tconst entries = Object.entries(options.orderBy) as [\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\"asc\" | \"desc\",\n\t\t\t\t\t][];\n\t\t\t\t\tif (entries.length > 0) {\n\t\t\t\t\t\tif (entries.length > 1) {\n\t\t\t\t\t\t\tconst extra = entries\n\t\t\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t\t\t.map(([col]) => col)\n\t\t\t\t\t\t\t\t.join(\", \");\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`orderBy supports only one column; remove extra keys: ${extra}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst [col, dir] = entries[0]!;\n\t\t\t\t\t\tsort = resolveOrderByColumn(col);\n\t\t\t\t\t\torder = dir ?? \"asc\";\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst params: SubgraphQueryParams = {\n\t\t\t\t\tsort,\n\t\t\t\t\torder,\n\t\t\t\t\tlimit: options.limit,\n\t\t\t\t\toffset: options.offset,\n\t\t\t\t\tfields: options.fields?.join(\",\"),\n\t\t\t\t\tfilters,\n\t\t\t\t};\n\n\t\t\t\treturn self.queryTable(subgraphName, tableName, params) as Promise<\n\t\t\t\t\tTRow[]\n\t\t\t\t>;\n\t\t\t},\n\n\t\t\tasync count<TRow>(where?: WhereInput<TRow>): Promise<number> {\n\t\t\t\tconst filters = where\n\t\t\t\t\t? serializeWhere(where as Record<string, unknown>)\n\t\t\t\t\t: undefined;\n\n\t\t\t\tconst result = await self.queryTableCount(subgraphName, tableName, {\n\t\t\t\t\tfilters,\n\t\t\t\t});\n\t\t\t\treturn result.count;\n\t\t\t},\n\t\t};\n\t}\n}\n",
|
|
9
|
+
"import type {\n\tCreatorProfile,\n\tMarketplaceSubgraphDetail,\n\tMarketplaceSubgraphSummary,\n\tSubgraphQueryParams,\n} from \"@secondlayer/shared/schemas\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface MarketplaceBrowseOptions {\n\ttags?: string[];\n\tsearch?: string;\n\tsort?: \"recent\" | \"popular\" | \"name\";\n\tlimit?: number;\n\toffset?: number;\n}\n\nfunction buildMarketplaceQuery(opts: MarketplaceBrowseOptions): string {\n\tconst qs = new URLSearchParams();\n\tif (opts.tags?.length) qs.set(\"tags\", opts.tags.join(\",\"));\n\tif (opts.search) qs.set(\"search\", opts.search);\n\tif (opts.sort) qs.set(\"_sort\", opts.sort);\n\tif (opts.limit !== undefined) qs.set(\"_limit\", String(opts.limit));\n\tif (opts.offset !== undefined) qs.set(\"_offset\", String(opts.offset));\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nfunction buildSubgraphQueryString(params: SubgraphQueryParams): string {\n\tconst qs = new URLSearchParams();\n\tif (params.sort) qs.set(\"_sort\", params.sort);\n\tif (params.order) qs.set(\"_order\", params.order);\n\tif (params.limit !== undefined) qs.set(\"_limit\", String(params.limit));\n\tif (params.offset !== undefined) qs.set(\"_offset\", String(params.offset));\n\tif (params.fields) qs.set(\"_fields\", params.fields);\n\tif (params.filters) {\n\t\tfor (const [key, value] of Object.entries(params.filters)) {\n\t\t\tqs.set(key, String(value));\n\t\t}\n\t}\n\tconst str = qs.toString();\n\treturn str ? `?${str}` : \"\";\n}\n\nexport class Marketplace extends BaseClient {\n\tasync browse(\n\t\topts: MarketplaceBrowseOptions = {},\n\t): Promise<{\n\t\tdata: MarketplaceSubgraphSummary[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs${buildMarketplaceQuery(opts)}`);\n\t}\n\n\tasync get(name: string): Promise<MarketplaceSubgraphDetail> {\n\t\treturn this.request(\"GET\", `/api/marketplace/subgraphs/${name}`);\n\t}\n\n\tasync creator(slug: string): Promise<CreatorProfile> {\n\t\treturn this.request(\"GET\", `/api/marketplace/creators/${slug}`);\n\t}\n\n\tasync fork(\n\t\tname: string,\n\t\tnewName?: string,\n\t): Promise<{\n\t\taction: string;\n\t\tsubgraphId: string;\n\t\tname: string;\n\t\tforkedFrom: string;\n\t}> {\n\t\treturn this.request(\"POST\", `/api/marketplace/subgraphs/${name}/fork`, {\n\t\t\tnewName,\n\t\t});\n\t}\n\n\tasync queryTable(\n\t\tname: string,\n\t\ttable: string,\n\t\tparams: SubgraphQueryParams = {},\n\t): Promise<{\n\t\tdata: unknown[];\n\t\tmeta: { total: number; limit: number; offset: number };\n\t}> {\n\t\treturn this.request(\n\t\t\t\"GET\",\n\t\t\t`/api/marketplace/subgraphs/${name}/${table}${buildSubgraphQueryString(params)}`,\n\t\t);\n\t}\n}\n",
|
|
9
10
|
"import type {\n\tBulkPauseResponse,\n\tBulkResumeResponse,\n\tCreateStream,\n\tCreateStreamResponse,\n\tListStreamsResponse,\n\tStreamResponse,\n\tUpdateStream,\n} from \"@secondlayer/shared/schemas\";\nimport { BaseClient } from \"../base.ts\";\nimport { ApiError } from \"../errors.ts\";\n\nexport interface DeliverySummary {\n\tid: string;\n\tblockHeight: number;\n\tstatus: string;\n\tstatusCode: number | null;\n\tresponseTimeMs: number | null;\n\tattempts: number;\n\terror: string | null;\n\tcreatedAt: string;\n}\n\nexport interface DeliveryDetail extends DeliverySummary {\n\tpayload: unknown;\n}\n\nexport interface DeliveriesResponse {\n\tdeliveries: DeliverySummary[];\n}\n\nexport class Streams extends BaseClient {\n\tprivate async requestWithStreamId<T>(\n\t\tmethod: string,\n\t\tpathTemplate: (id: string) => string,\n\t\tid: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst fullId = await this.resolveStreamId(id);\n\t\treturn this.request<T>(method, pathTemplate(fullId), body);\n\t}\n\n\tasync resolveStreamId(partialId: string): Promise<string> {\n\t\tif (partialId.length === 36 && partialId.includes(\"-\")) {\n\t\t\treturn partialId;\n\t\t}\n\n\t\tconst { streams } = await this.list();\n\t\tconst matches = streams.filter((s) => s.id.startsWith(partialId));\n\n\t\tif (matches.length === 0) {\n\t\t\tthrow new ApiError(404, `No stream found matching \"${partialId}\"`);\n\t\t}\n\t\tif (matches.length > 1) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Multiple streams match \"${partialId}\": ${matches.map((s) => s.id.slice(0, 8)).join(\", \")}`,\n\t\t\t);\n\t\t}\n\n\t\treturn matches[0]!.id;\n\t}\n\n\tasync create(data: CreateStream): Promise<CreateStreamResponse> {\n\t\treturn this.request<CreateStreamResponse>(\"POST\", \"/api/streams\", data);\n\t}\n\n\tasync update(id: string, data: UpdateStream): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"PATCH\",\n\t\t\t(id) => `/api/streams/${id}`,\n\t\t\tid,\n\t\t\tdata,\n\t\t);\n\t}\n\n\tasync updateByName(\n\t\tname: string,\n\t\tdata: CreateStream,\n\t): Promise<StreamResponse> {\n\t\tconst { streams } = await this.list();\n\t\tconst existing = streams.find((s) => s.name === name);\n\t\tif (!existing) {\n\t\t\tthrow new ApiError(404, `Stream with name \"${name}\" not found`);\n\t\t}\n\t\treturn this.update(existing.id, data);\n\t}\n\n\tasync list(params?: { status?: string }): Promise<ListStreamsResponse> {\n\t\tconst searchParams = new URLSearchParams();\n\t\tif (params?.status) searchParams.set(\"status\", params.status);\n\t\tconst query = searchParams.toString();\n\t\tconst path = query ? `/api/streams?${query}` : \"/api/streams\";\n\t\treturn this.request<ListStreamsResponse>(\"GET\", path);\n\t}\n\n\tasync get(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\"GET\", (id) => `/api/streams/${id}`, id);\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\treturn this.requestWithStreamId(\"DELETE\", (id) => `/api/streams/${id}`, id);\n\t}\n\n\tasync enable(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/enable`,\n\t\t\tid,\n\t\t);\n\t}\n\n\tasync disable(id: string): Promise<StreamResponse> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/disable`,\n\t\t\tid,\n\t\t);\n\t}\n\n\tasync rotateSecret(id: string): Promise<{ secret: string }> {\n\t\treturn this.requestWithStreamId(\n\t\t\t\"POST\",\n\t\t\t(id) => `/api/streams/${id}/rotate-secret`,\n\t\t\tid,\n\t\t);\n\t}\n\n\t// ── Deliveries ─────────────────────────────────────────────────────\n\n\t/** List recent deliveries for a stream. */\n\tasync listDeliveries(\n\t\tid: string,\n\t\tparams?: { limit?: number; status?: string },\n\t): Promise<DeliveriesResponse> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n\t\tif (params?.status) qs.set(\"status\", params.status);\n\t\tconst query = qs.toString();\n\t\treturn this.requestWithStreamId(\n\t\t\t\"GET\",\n\t\t\t(id) => `/api/streams/${id}/deliveries${query ? `?${query}` : \"\"}`,\n\t\t\tid,\n\t\t);\n\t}\n\n\t/** Get a single delivery with full payload. */\n\tasync getDelivery(\n\t\tstreamId: string,\n\t\tdeliveryId: string,\n\t): Promise<DeliveryDetail> {\n\t\tconst fullId = await this.resolveStreamId(streamId);\n\t\treturn this.request<DeliveryDetail>(\n\t\t\t\"GET\",\n\t\t\t`/api/streams/${fullId}/deliveries/${deliveryId}`,\n\t\t);\n\t}\n\n\tasync pauseAll(): Promise<BulkPauseResponse> {\n\t\treturn this.request<BulkPauseResponse>(\"POST\", \"/api/streams/pause\");\n\t}\n\n\tasync resumeAll(): Promise<BulkResumeResponse> {\n\t\treturn this.request<BulkResumeResponse>(\"POST\", \"/api/streams/resume\");\n\t}\n}\n",
|
|
10
|
-
"import type {
|
|
11
|
+
"import type {\n\tWorkflowRun,\n\tWorkflowRunStatus,\n} from \"@secondlayer/workflows\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface WorkflowSummary {\n\tname: string;\n\tstatus: \"active\" | \"paused\";\n\ttriggerType: \"event\" | \"stream\" | \"schedule\" | \"manual\";\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface WorkflowDetail extends WorkflowSummary {\n\ttrigger: Record<string, unknown>;\n\tretries?: { maxAttempts?: number; backoffMs?: number };\n\ttimeout?: number;\n\ttotalRuns: number;\n\tlastRunAt: string | null;\n}\n\nexport interface WorkflowRunSummary {\n\tid: string;\n\tworkflowName: string;\n\tstatus: WorkflowRunStatus;\n\tduration: number;\n\taiTokensUsed: number;\n\ttriggeredAt: string;\n\tcompletedAt: string | null;\n}\n\nexport class Workflows extends BaseClient {\n\tasync deploy(data: {\n\t\tname: string;\n\t\ttrigger: Record<string, unknown>;\n\t\thandlerCode: string;\n\t\tretries?: Record<string, unknown>;\n\t\ttimeout?: number;\n\t}): Promise<{ action: string; workflowId: string; message: string }> {\n\t\treturn this.request(\"POST\", \"/api/workflows\", data);\n\t}\n\n\tasync list(): Promise<{ workflows: WorkflowSummary[] }> {\n\t\treturn this.request(\"GET\", \"/api/workflows\");\n\t}\n\n\tasync get(name: string): Promise<WorkflowDetail> {\n\t\treturn this.request(\"GET\", `/api/workflows/${name}`);\n\t}\n\n\tasync trigger(\n\t\tname: string,\n\t\tinput?: Record<string, unknown>,\n\t): Promise<{ runId: string }> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/trigger`, input ? { input } : undefined);\n\t}\n\n\tasync pause(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/pause`);\n\t}\n\n\tasync resume(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/resume`);\n\t}\n\n\tasync delete(name: string): Promise<void> {\n\t\treturn this.request(\"DELETE\", `/api/workflows/${name}`);\n\t}\n\n\tasync listRuns(\n\t\tname: string,\n\t\tparams?: { status?: WorkflowRunStatus; limit?: number },\n\t): Promise<{ runs: WorkflowRunSummary[] }> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (params?.status) qs.set(\"status\", params.status);\n\t\tif (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n\t\tconst query = qs.toString();\n\t\treturn this.request(\"GET\", `/api/workflows/${name}/runs${query ? `?${query}` : \"\"}`);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRun> {\n\t\treturn this.request(\"GET\", `/api/workflows/runs/${runId}`);\n\t}\n}\n",
|
|
12
|
+
"import type { QueueStats } from \"@secondlayer/shared/types\";\nimport { BaseClient } from \"./base.ts\";\nimport type { SecondLayerOptions } from \"./base.ts\";\nimport { Marketplace } from \"./marketplace/client.ts\";\nimport { Streams } from \"./streams/client.ts\";\nimport { Subgraphs } from \"./subgraphs/client.ts\";\nimport { Workflows } from \"./workflows/client.ts\";\n\nexport class SecondLayer extends BaseClient {\n\treadonly streams: Streams;\n\treadonly subgraphs: Subgraphs;\n\treadonly marketplace: Marketplace;\n\treadonly workflows: Workflows;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tsuper(options);\n\t\tthis.streams = new Streams(options);\n\t\tthis.subgraphs = new Subgraphs(options);\n\t\tthis.marketplace = new Marketplace(options);\n\t\tthis.workflows = new Workflows(options);\n\t}\n\n\tasync getQueueStats(): Promise<QueueStats> {\n\t\tconst status = await this.request<{ queue: QueueStats }>(\"GET\", \"/status\");\n\t\treturn status.queue;\n\t}\n}\n",
|
|
11
13
|
"import type { InferSubgraphClient } from \"@secondlayer/subgraphs\";\nimport type { SecondLayerOptions } from \"../base.ts\";\nimport { SecondLayer } from \"../client.ts\";\nimport { Subgraphs } from \"./client.ts\";\n\n/**\n * Returns a typed client for a subgraph defined with `defineSubgraph()`.\n *\n * Accepts a plain options object, a `SecondLayer` instance, or a `Subgraphs` instance.\n *\n * @example\n * ```ts\n * import mySubgraph from './subgraphs/my-subgraph'\n * import { getSubgraph } from '@secondlayer/sdk'\n *\n * const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })\n * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })\n * ```\n */\nexport function getSubgraph<\n\tT extends { name: string; schema: Record<string, unknown> },\n>(\n\tdef: T,\n\toptions: Partial<SecondLayerOptions> | SecondLayer | Subgraphs = {},\n): InferSubgraphClient<T> {\n\tif (options instanceof Subgraphs) {\n\t\treturn options.typed(def);\n\t}\n\tif (options instanceof SecondLayer) {\n\t\treturn options.subgraphs.typed(def);\n\t}\n\treturn new Subgraphs(options).typed(def);\n}\n"
|
|
12
14
|
],
|
|
13
|
-
"mappings": ";AAeO,MAAM,iBAAiB,MAAM;AAAA,EAG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AAEhB;;;ACPO,SAAS,WAEf,CACA,KACA,UAAiE,CAAC,GACzC;AAAA,EACzB,IAAI,mBAAmB,WAAW;AAAA,IACjC,OAAO,QAAQ,MAAM,GAAG;AAAA,EACzB;AAAA,EACA,IAAI,mBAAmB,aAAa;AAAA,IACnC,OAAO,QAAQ,UAAU,MAAM,GAAG;AAAA,EACnC;AAAA,EACA,OAAO,IAAI,UAAU,OAAO,EAAE,MAAM,GAAG;AAAA;",
|
|
16
|
+
"debugId": "330EFEE1434C2A0964756E2164756E21",
|
|
15
17
|
"names": []
|
|
16
18
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { WorkflowRun, WorkflowRunStatus } from "@secondlayer/workflows";
|
|
2
|
+
interface SecondLayerOptions {
|
|
3
|
+
/** Base URL of the Secondlayer API (trailing slashes are stripped). */
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
/** Bearer token for authenticated requests. */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare abstract class BaseClient {
|
|
9
|
+
protected baseUrl: string;
|
|
10
|
+
protected apiKey?: string;
|
|
11
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
12
|
+
static authHeaders(apiKey?: string): Record<string, string>;
|
|
13
|
+
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
interface WorkflowSummary {
|
|
16
|
+
name: string;
|
|
17
|
+
status: "active" | "paused";
|
|
18
|
+
triggerType: "event" | "stream" | "schedule" | "manual";
|
|
19
|
+
createdAt: string;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
}
|
|
22
|
+
interface WorkflowDetail extends WorkflowSummary {
|
|
23
|
+
trigger: Record<string, unknown>;
|
|
24
|
+
retries?: {
|
|
25
|
+
maxAttempts?: number
|
|
26
|
+
backoffMs?: number
|
|
27
|
+
};
|
|
28
|
+
timeout?: number;
|
|
29
|
+
totalRuns: number;
|
|
30
|
+
lastRunAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
interface WorkflowRunSummary {
|
|
33
|
+
id: string;
|
|
34
|
+
workflowName: string;
|
|
35
|
+
status: WorkflowRunStatus;
|
|
36
|
+
duration: number;
|
|
37
|
+
aiTokensUsed: number;
|
|
38
|
+
triggeredAt: string;
|
|
39
|
+
completedAt: string | null;
|
|
40
|
+
}
|
|
41
|
+
declare class Workflows extends BaseClient {
|
|
42
|
+
deploy(data: {
|
|
43
|
+
name: string
|
|
44
|
+
trigger: Record<string, unknown>
|
|
45
|
+
handlerCode: string
|
|
46
|
+
retries?: Record<string, unknown>
|
|
47
|
+
timeout?: number
|
|
48
|
+
}): Promise<{
|
|
49
|
+
action: string
|
|
50
|
+
workflowId: string
|
|
51
|
+
message: string
|
|
52
|
+
}>;
|
|
53
|
+
list(): Promise<{
|
|
54
|
+
workflows: WorkflowSummary[]
|
|
55
|
+
}>;
|
|
56
|
+
get(name: string): Promise<WorkflowDetail>;
|
|
57
|
+
trigger(name: string, input?: Record<string, unknown>): Promise<{
|
|
58
|
+
runId: string
|
|
59
|
+
}>;
|
|
60
|
+
pause(name: string): Promise<void>;
|
|
61
|
+
resume(name: string): Promise<void>;
|
|
62
|
+
delete(name: string): Promise<void>;
|
|
63
|
+
listRuns(name: string, params?: {
|
|
64
|
+
status?: WorkflowRunStatus
|
|
65
|
+
limit?: number
|
|
66
|
+
}): Promise<{
|
|
67
|
+
runs: WorkflowRunSummary[]
|
|
68
|
+
}>;
|
|
69
|
+
getRun(runId: string): Promise<WorkflowRun>;
|
|
70
|
+
}
|
|
71
|
+
export { Workflows, WorkflowSummary, WorkflowRunSummary, WorkflowDetail };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
class ApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
constructor(status, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.name = "ApiError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/base.ts
|
|
12
|
+
var DEFAULT_BASE_URL = "https://api.secondlayer.tools";
|
|
13
|
+
|
|
14
|
+
class BaseClient {
|
|
15
|
+
baseUrl;
|
|
16
|
+
apiKey;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
19
|
+
this.apiKey = options.apiKey;
|
|
20
|
+
}
|
|
21
|
+
static authHeaders(apiKey) {
|
|
22
|
+
const headers = {
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
};
|
|
25
|
+
if (apiKey) {
|
|
26
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
async request(method, path, body) {
|
|
31
|
+
const url = `${this.baseUrl}${path}`;
|
|
32
|
+
const headers = BaseClient.authHeaders(this.apiKey);
|
|
33
|
+
let response;
|
|
34
|
+
try {
|
|
35
|
+
response = await fetch(url, {
|
|
36
|
+
method,
|
|
37
|
+
headers,
|
|
38
|
+
body: body ? JSON.stringify(body) : undefined
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
throw new ApiError(0, `Cannot reach API at ${this.baseUrl}. Check your connection or try again.`);
|
|
42
|
+
}
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
if (response.status === 401) {
|
|
45
|
+
throw new ApiError(401, "API key invalid or expired.");
|
|
46
|
+
}
|
|
47
|
+
if (response.status === 429) {
|
|
48
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
49
|
+
const msg = retryAfter ? `Rate limited. Wait ${retryAfter} seconds.` : "Rate limited. Try again later.";
|
|
50
|
+
throw new ApiError(429, msg);
|
|
51
|
+
}
|
|
52
|
+
if (response.status >= 500) {
|
|
53
|
+
throw new ApiError(response.status, `Server error. Try again or check status at ${this.baseUrl}/health`);
|
|
54
|
+
}
|
|
55
|
+
const errorBody = await response.text();
|
|
56
|
+
let message = `HTTP ${response.status}`;
|
|
57
|
+
try {
|
|
58
|
+
const json = JSON.parse(errorBody);
|
|
59
|
+
const err = json.error ?? json.message;
|
|
60
|
+
if (typeof err === "string") {
|
|
61
|
+
message = err;
|
|
62
|
+
} else if (err && typeof err === "object") {
|
|
63
|
+
message = JSON.stringify(err);
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
if (errorBody)
|
|
67
|
+
message = errorBody;
|
|
68
|
+
}
|
|
69
|
+
throw new ApiError(response.status, message);
|
|
70
|
+
}
|
|
71
|
+
if (response.status === 204) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return response.json();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/workflows/client.ts
|
|
79
|
+
class Workflows extends BaseClient {
|
|
80
|
+
async deploy(data) {
|
|
81
|
+
return this.request("POST", "/api/workflows", data);
|
|
82
|
+
}
|
|
83
|
+
async list() {
|
|
84
|
+
return this.request("GET", "/api/workflows");
|
|
85
|
+
}
|
|
86
|
+
async get(name) {
|
|
87
|
+
return this.request("GET", `/api/workflows/${name}`);
|
|
88
|
+
}
|
|
89
|
+
async trigger(name, input) {
|
|
90
|
+
return this.request("POST", `/api/workflows/${name}/trigger`, input ? { input } : undefined);
|
|
91
|
+
}
|
|
92
|
+
async pause(name) {
|
|
93
|
+
return this.request("POST", `/api/workflows/${name}/pause`);
|
|
94
|
+
}
|
|
95
|
+
async resume(name) {
|
|
96
|
+
return this.request("POST", `/api/workflows/${name}/resume`);
|
|
97
|
+
}
|
|
98
|
+
async delete(name) {
|
|
99
|
+
return this.request("DELETE", `/api/workflows/${name}`);
|
|
100
|
+
}
|
|
101
|
+
async listRuns(name, params) {
|
|
102
|
+
const qs = new URLSearchParams;
|
|
103
|
+
if (params?.status)
|
|
104
|
+
qs.set("status", params.status);
|
|
105
|
+
if (params?.limit !== undefined)
|
|
106
|
+
qs.set("limit", String(params.limit));
|
|
107
|
+
const query = qs.toString();
|
|
108
|
+
return this.request("GET", `/api/workflows/${name}/runs${query ? `?${query}` : ""}`);
|
|
109
|
+
}
|
|
110
|
+
async getRun(runId) {
|
|
111
|
+
return this.request("GET", `/api/workflows/runs/${runId}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
Workflows
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//# debugId=18AC9997BF73F08564756E2164756E21
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/base.ts", "../src/workflows/client.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Error thrown by {@link SecondLayer} when an API request fails.\n * Includes the HTTP status code for programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await client.streams.get(\"abc123\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Stream not found\");\n * }\n * }\n * ```\n */\nexport class ApiError extends Error {\n\tconstructor(\n\t\t/** HTTP status code (0 for network errors). */\n\t\tpublic status: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n",
|
|
6
|
+
"import { ApiError } from \"./errors.ts\";\n\nexport interface SecondLayerOptions {\n\t/** Base URL of the Secondlayer API (trailing slashes are stripped). */\n\tbaseUrl: string;\n\t/** Bearer token for authenticated requests. */\n\tapiKey?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t}\n\n\tstatic authHeaders(apiKey?: string): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t};\n\t\tif (apiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tprotected async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> {\n\t\tconst url = `${this.baseUrl}${path}`;\n\t\tconst headers = BaseClient.authHeaders(this.apiKey);\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: body ? JSON.stringify(body) : undefined,\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t0,\n\t\t\t\t`Cannot reach API at ${this.baseUrl}. Check your connection or try again.`,\n\t\t\t);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 401) {\n\t\t\t\tthrow new ApiError(401, \"API key invalid or expired.\");\n\t\t\t}\n\n\t\t\tif (response.status === 429) {\n\t\t\t\tconst retryAfter = response.headers.get(\"Retry-After\");\n\t\t\t\tconst msg = retryAfter\n\t\t\t\t\t? `Rate limited. Wait ${retryAfter} seconds.`\n\t\t\t\t\t: \"Rate limited. Try again later.\";\n\t\t\t\tthrow new ApiError(429, msg);\n\t\t\t}\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tthrow new ApiError(\n\t\t\t\t\tresponse.status,\n\t\t\t\t\t`Server error. Try again or check status at ${this.baseUrl}/health`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst errorBody = await response.text();\n\t\t\tlet message = `HTTP ${response.status}`;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tconst err = json.error ?? json.message;\n\t\t\t\tif (typeof err === \"string\") {\n\t\t\t\t\tmessage = err;\n\t\t\t\t} else if (err && typeof err === \"object\") {\n\t\t\t\t\tmessage = JSON.stringify(err);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tif (errorBody) message = errorBody;\n\t\t\t}\n\t\t\tthrow new ApiError(response.status, message);\n\t\t}\n\n\t\tif (response.status === 204) {\n\t\t\treturn undefined as T;\n\t\t}\n\n\t\treturn response.json() as Promise<T>;\n\t}\n}\n",
|
|
7
|
+
"import type {\n\tWorkflowRun,\n\tWorkflowRunStatus,\n} from \"@secondlayer/workflows\";\nimport { BaseClient } from \"../base.ts\";\n\nexport interface WorkflowSummary {\n\tname: string;\n\tstatus: \"active\" | \"paused\";\n\ttriggerType: \"event\" | \"stream\" | \"schedule\" | \"manual\";\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface WorkflowDetail extends WorkflowSummary {\n\ttrigger: Record<string, unknown>;\n\tretries?: { maxAttempts?: number; backoffMs?: number };\n\ttimeout?: number;\n\ttotalRuns: number;\n\tlastRunAt: string | null;\n}\n\nexport interface WorkflowRunSummary {\n\tid: string;\n\tworkflowName: string;\n\tstatus: WorkflowRunStatus;\n\tduration: number;\n\taiTokensUsed: number;\n\ttriggeredAt: string;\n\tcompletedAt: string | null;\n}\n\nexport class Workflows extends BaseClient {\n\tasync deploy(data: {\n\t\tname: string;\n\t\ttrigger: Record<string, unknown>;\n\t\thandlerCode: string;\n\t\tretries?: Record<string, unknown>;\n\t\ttimeout?: number;\n\t}): Promise<{ action: string; workflowId: string; message: string }> {\n\t\treturn this.request(\"POST\", \"/api/workflows\", data);\n\t}\n\n\tasync list(): Promise<{ workflows: WorkflowSummary[] }> {\n\t\treturn this.request(\"GET\", \"/api/workflows\");\n\t}\n\n\tasync get(name: string): Promise<WorkflowDetail> {\n\t\treturn this.request(\"GET\", `/api/workflows/${name}`);\n\t}\n\n\tasync trigger(\n\t\tname: string,\n\t\tinput?: Record<string, unknown>,\n\t): Promise<{ runId: string }> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/trigger`, input ? { input } : undefined);\n\t}\n\n\tasync pause(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/pause`);\n\t}\n\n\tasync resume(name: string): Promise<void> {\n\t\treturn this.request(\"POST\", `/api/workflows/${name}/resume`);\n\t}\n\n\tasync delete(name: string): Promise<void> {\n\t\treturn this.request(\"DELETE\", `/api/workflows/${name}`);\n\t}\n\n\tasync listRuns(\n\t\tname: string,\n\t\tparams?: { status?: WorkflowRunStatus; limit?: number },\n\t): Promise<{ runs: WorkflowRunSummary[] }> {\n\t\tconst qs = new URLSearchParams();\n\t\tif (params?.status) qs.set(\"status\", params.status);\n\t\tif (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n\t\tconst query = qs.toString();\n\t\treturn this.request(\"GET\", `/api/workflows/${name}/runs${query ? `?${query}` : \"\"}`);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRun> {\n\t\treturn this.request(\"GET\", `/api/workflows/runs/${runId}`);\n\t}\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AAeO,MAAM,iBAAiB,MAAM;AAAA,EAG3B;AAAA,EAFR,WAAW,CAEH,QACP,SACC;AAAA,IACD,MAAM,OAAO;AAAA,IAHN;AAAA,IAIP,KAAK,OAAO;AAAA;AAEd;;;ACfA,IAAM,mBAAmB;AAAA;AAElB,MAAe,WAAW;AAAA,EACtB;AAAA,EACA;AAAA,EAEV,WAAW,CAAC,UAAuC,CAAC,GAAG;AAAA,IACtD,KAAK,WAAW,QAAQ,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AAAA,IACvE,KAAK,SAAS,QAAQ;AAAA;AAAA,SAGhB,WAAW,CAAC,QAAyC;AAAA,IAC3D,MAAM,UAAkC;AAAA,MACvC,gBAAgB;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AAAA,MACX,QAAQ,mBAAmB,UAAU;AAAA,IACtC;AAAA,IACA,OAAO;AAAA;AAAA,OAGQ,QAAU,CACzB,QACA,MACA,MACa;AAAA,IACb,MAAM,MAAM,GAAG,KAAK,UAAU;AAAA,IAC9B,MAAM,UAAU,WAAW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json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"./subgraphs": {
|
|
17
17
|
"types": "./dist/subgraphs/index.d.ts",
|
|
18
18
|
"import": "./dist/subgraphs/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./marketplace": {
|
|
21
|
+
"types": "./dist/marketplace/index.d.ts",
|
|
22
|
+
"import": "./dist/marketplace/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./workflows": {
|
|
25
|
+
"types": "./dist/workflows/index.d.ts",
|
|
26
|
+
"import": "./dist/workflows/index.js"
|
|
19
27
|
}
|
|
20
28
|
},
|
|
21
29
|
"files": [
|
|
@@ -29,8 +37,9 @@
|
|
|
29
37
|
"prepublishOnly": "bun run build"
|
|
30
38
|
},
|
|
31
39
|
"dependencies": {
|
|
32
|
-
"@secondlayer/shared": "^0.
|
|
33
|
-
"@secondlayer/subgraphs": "^0.
|
|
40
|
+
"@secondlayer/shared": "^0.11.0",
|
|
41
|
+
"@secondlayer/subgraphs": "^0.10.0",
|
|
42
|
+
"@secondlayer/workflows": "^0.0.2"
|
|
34
43
|
},
|
|
35
44
|
"devDependencies": {
|
|
36
45
|
"@types/bun": "latest",
|