@secondlayer/sdk 0.10.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -22
- package/dist/index.d.ts +195 -55
- package/dist/index.js +143 -89
- package/dist/index.js.map +10 -10
- package/dist/marketplace/index.d.ts +3 -0
- package/dist/marketplace/index.js +22 -4
- package/dist/marketplace/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +148 -47
- package/dist/subgraphs/index.js +128 -81
- package/dist/subgraphs/index.js.map +8 -9
- package/dist/workflows/index.d.ts +125 -5
- package/dist/workflows/index.js +130 -5
- package/dist/workflows/index.js.map +5 -5
- package/package.json +4 -8
- package/dist/streams/index.d.ts +0 -57
- package/dist/streams/index.js +0 -160
- package/dist/streams/index.js.map +0 -12
package/dist/index.js.map
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/errors.ts", "../src/base.ts", "../src/marketplace/client.ts", "../src/
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/base.ts", "../src/marketplace/client.ts", "../src/subgraphs/serialize.ts", "../src/subgraphs/client.ts", "../src/workflows/client.ts", "../src/client.ts", "../src/subgraphs/get-subgraph.ts", "../src/webhooks.ts"],
|
|
4
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.
|
|
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
|
|
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.subgraphs.get(\"my-subgraph\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Subgraph 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\t/** Raw response body (parsed JSON if possible) — preserved for callers that need error details. */\n\t\tpublic body?: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n\n/**\n * Thrown by {@link Workflows.deploy} when the server rejects a deploy because the\n * provided `expectedVersion` does not match the current stored version.\n */\nexport class VersionConflictError extends ApiError {\n\tconstructor(\n\t\tpublic currentVersion: string,\n\t\tpublic expectedVersion: string,\n\t\tmessage = `Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t) {\n\t\tsuper(409, message, { currentVersion, expectedVersion });\n\t\tthis.name = \"VersionConflictError\";\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\t/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */\n\torigin?: \"cli\" | \"mcp\" | \"session\";\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\tprotected origin: \"cli\" | \"mcp\" | \"session\";\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t\tthis.origin = options.origin ?? \"cli\";\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\t\theaders[\"x-sl-origin\"] = this.origin;\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\tlet parsedBody: unknown = errorBody;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tparsedBody = json;\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, parsedBody);\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
|
"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
|
-
"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",
|
|
9
8
|
"/**\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",
|
|
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",
|
|
11
|
-
"import type {
|
|
12
|
-
"import
|
|
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"
|
|
9
|
+
"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\nexport interface SubgraphSource {\n\tname: string;\n\tversion: string;\n\tsourceCode: string | null;\n\treadOnly: boolean;\n\treason?: string;\n\tupdatedAt: string;\n}\n\nexport interface BundleSubgraphResponse {\n\tok: true;\n\tname: string;\n\tversion: string | null;\n\tdescription: string | null;\n\tsources: Record<string, Record<string, unknown>>;\n\tschema: Record<string, unknown>;\n\thandlerCode: string;\n\tsourceCode: string;\n\tbundleSize: number;\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 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 getSource(name: string): Promise<SubgraphSource> {\n\t\treturn this.request<SubgraphSource>(\"GET\", `/api/subgraphs/${name}/source`);\n\t}\n\n\t/**\n\t * Bundle a TypeScript subgraph source on the server. Used by the web chat\n\t * authoring loop so Vercel's serverless runtime doesn't have to run esbuild.\n\t */\n\tasync bundle(data: { code: string }): Promise<BundleSubgraphResponse> {\n\t\treturn this.request<BundleSubgraphResponse>(\n\t\t\t\"POST\",\n\t\t\t\"/api/subgraphs/bundle\",\n\t\t\tdata,\n\t\t);\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 { WorkflowRun, WorkflowRunStatus } from \"@secondlayer/workflows\";\nimport { BaseClient } from \"../base.ts\";\nimport { ApiError, VersionConflictError } from \"../errors.ts\";\n\nfunction parseSseChunk(raw: string): WorkflowTailEvent | null {\n\tlet event = \"message\";\n\tconst dataLines: string[] = [];\n\tfor (const line of raw.split(\"\\n\")) {\n\t\tif (line.startsWith(\"event:\")) {\n\t\t\tevent = line.slice(6).trim();\n\t\t} else if (line.startsWith(\"data:\")) {\n\t\t\tdataLines.push(line.slice(5).trimStart());\n\t\t}\n\t}\n\tif (dataLines.length === 0) return null;\n\tconst data = dataLines.join(\"\\n\");\n\ttry {\n\t\tconst parsed = JSON.parse(data);\n\t\tswitch (event) {\n\t\t\tcase \"step\":\n\t\t\t\treturn { type: \"step\", step: parsed as WorkflowStepEvent };\n\t\t\tcase \"done\":\n\t\t\t\treturn { type: \"done\", done: parsed as WorkflowRunDoneEvent };\n\t\t\tcase \"heartbeat\":\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"heartbeat\",\n\t\t\t\t\tts: typeof parsed === \"string\" ? parsed : String(parsed),\n\t\t\t\t};\n\t\t\tcase \"timeout\":\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"timeout\",\n\t\t\t\t\tmessage: (parsed as { message?: string }).message ?? \"timeout\",\n\t\t\t\t};\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport interface WorkflowSource {\n\tname: string;\n\tversion: string;\n\tsourceCode: string | null;\n\treadOnly: boolean;\n\treason?: string;\n\tupdatedAt: string;\n}\n\nexport interface WorkflowStepEvent {\n\tid: string;\n\tstepIndex: number;\n\tstepId: string;\n\tstepType: string;\n\tstatus: string;\n\toutput?: unknown;\n\terror: string | null;\n\tretryCount: number;\n\taiTokensUsed: number;\n\tstartedAt: string | null;\n\tcompletedAt: string | null;\n\tdurationMs: number | null;\n\tts: string;\n}\n\nexport interface WorkflowRunDoneEvent {\n\trunId: string;\n\tstatus: string;\n\terror?: string | null;\n\tcompletedAt?: string | null;\n}\n\nexport type WorkflowTailEvent =\n\t| { type: \"step\"; step: WorkflowStepEvent }\n\t| { type: \"done\"; done: WorkflowRunDoneEvent }\n\t| { type: \"heartbeat\"; ts: string }\n\t| { type: \"timeout\"; message: string };\n\nexport interface DeployDryRunResponse {\n\tvalid: boolean;\n\tvalidation?: { name: string; triggerType: string };\n\tbundleSize: number;\n\terror?: string;\n}\n\nexport interface DeployResponse {\n\taction: \"created\" | \"updated\";\n\tworkflowId: string;\n\tversion: string;\n\tmessage: string;\n}\n\nexport interface BundleWorkflowResponse {\n\tok: true;\n\tname: string;\n\ttrigger: Record<string, unknown>;\n\thandlerCode: string;\n\tsourceCode: string;\n\tretries: Record<string, unknown> | null;\n\ttimeout: number | null;\n\tbundleSize: number;\n}\n\nexport interface WorkflowSummary {\n\tname: string;\n\tstatus: \"active\" | \"paused\";\n\ttriggerType: \"event\" | \"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(\n\t\tdata: {\n\t\t\tname: string;\n\t\t\ttrigger: Record<string, unknown>;\n\t\t\thandlerCode: string;\n\t\t\tsourceCode?: string;\n\t\t\texpectedVersion?: string;\n\t\t\tretries?: Record<string, unknown>;\n\t\t\ttimeout?: number;\n\t\t\tclientRequestId?: string;\n\t\t} & { dryRun?: false },\n\t): Promise<DeployResponse>;\n\tasync deploy(data: {\n\t\tname: string;\n\t\ttrigger: Record<string, unknown>;\n\t\thandlerCode: string;\n\t\tsourceCode?: string;\n\t\texpectedVersion?: string;\n\t\tretries?: Record<string, unknown>;\n\t\ttimeout?: number;\n\t\tdryRun: true;\n\t}): Promise<DeployDryRunResponse>;\n\tasync deploy(data: {\n\t\tname: string;\n\t\ttrigger: Record<string, unknown>;\n\t\thandlerCode: string;\n\t\tsourceCode?: string;\n\t\texpectedVersion?: string;\n\t\tdryRun?: boolean;\n\t\tclientRequestId?: string;\n\t\tretries?: Record<string, unknown>;\n\t\ttimeout?: number;\n\t}): Promise<DeployResponse | DeployDryRunResponse> {\n\t\ttry {\n\t\t\treturn await this.request(\"POST\", \"/api/workflows\", data);\n\t\t} catch (err) {\n\t\t\tif (err instanceof ApiError && err.status === 409) {\n\t\t\t\tconst body = err.body as\n\t\t\t\t\t| { currentVersion?: string; expectedVersion?: string }\n\t\t\t\t\t| undefined;\n\t\t\t\tif (body?.currentVersion && body.expectedVersion) {\n\t\t\t\t\tthrow new VersionConflictError(\n\t\t\t\t\t\tbody.currentVersion,\n\t\t\t\t\t\tbody.expectedVersion,\n\t\t\t\t\t\terr.message,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync getSource(name: string): Promise<WorkflowSource> {\n\t\treturn this.request(\"GET\", `/api/workflows/${name}/source`);\n\t}\n\n\t/**\n\t * Bundle a TypeScript workflow source on the server. Used by the web chat\n\t * authoring loop so Vercel's serverless runtime doesn't have to run esbuild.\n\t * CLI and MCP still bundle locally — this method is for clients that can't\n\t * install `@secondlayer/bundler` directly (e.g. browser tooling, edge\n\t * functions).\n\t */\n\tasync bundle(data: { code: string }): Promise<BundleWorkflowResponse> {\n\t\treturn this.request(\"POST\", \"/api/workflows/bundle\", data);\n\t}\n\n\tasync pauseAll(): Promise<{\n\t\tpaused: number;\n\t\tworkflows: Array<{ name: string; version: string; status: string }>;\n\t}> {\n\t\treturn this.request(\"POST\", \"/api/workflows/pause-all\");\n\t}\n\n\tasync cancelRun(runId: string): Promise<{\n\t\trunId: string;\n\t\tstatus: string;\n\t\tcancelled: boolean;\n\t\tcompletedAt?: string;\n\t\tmessage?: string;\n\t}> {\n\t\treturn this.request(\"POST\", `/api/workflows/runs/${runId}/cancel`);\n\t}\n\n\tasync rollback(\n\t\tname: string,\n\t\ttoVersion?: string,\n\t): Promise<{\n\t\taction: \"rolled-back\";\n\t\tname: string;\n\t\tfromVersion: string;\n\t\trestoredFromVersion: string;\n\t\tversion: string;\n\t}> {\n\t\treturn this.request(\n\t\t\t\"POST\",\n\t\t\t`/api/workflows/${name}/rollback`,\n\t\t\ttoVersion ? { toVersion } : {},\n\t\t);\n\t}\n\n\t/**\n\t * Subscribe to a workflow run's server-sent event stream. Resolves when the\n\t * run completes, times out, or the signal is aborted. Throws on HTTP errors\n\t * opening the stream.\n\t */\n\tasync streamRun(\n\t\tname: string,\n\t\trunId: string,\n\t\tonEvent: (event: WorkflowTailEvent) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<void> {\n\t\tconst url = `${this.baseUrl}/api/workflows/${name}/runs/${runId}/stream`;\n\t\tconst headers: Record<string, string> = {\n\t\t\tAccept: \"text/event-stream\",\n\t\t\t\"x-sl-origin\": this.origin,\n\t\t};\n\t\tif (this.apiKey) {\n\t\t\theaders.Authorization = `Bearer ${this.apiKey}`;\n\t\t}\n\n\t\tconst res = await fetch(url, { headers, signal });\n\t\tif (!res.ok || !res.body) {\n\t\t\tthrow new ApiError(\n\t\t\t\tres.status,\n\t\t\t\t`Failed to open workflow run stream (HTTP ${res.status})`,\n\t\t\t);\n\t\t}\n\n\t\tconst reader = res.body.pipeThrough(new TextDecoderStream()).getReader();\n\t\tlet buffer = \"\";\n\n\t\twhile (true) {\n\t\t\tconst { value, done } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffer += value;\n\n\t\t\tlet sep = buffer.indexOf(\"\\n\\n\");\n\t\t\twhile (sep !== -1) {\n\t\t\t\tconst chunk = buffer.slice(0, sep);\n\t\t\t\tbuffer = buffer.slice(sep + 2);\n\t\t\t\tconst parsed = parseSseChunk(chunk);\n\t\t\t\tif (parsed) {\n\t\t\t\t\tonEvent(parsed);\n\t\t\t\t\tif (parsed.type === \"done\" || parsed.type === \"timeout\") {\n\t\t\t\t\t\tawait reader.cancel().catch(() => undefined);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsep = buffer.indexOf(\"\\n\\n\");\n\t\t\t}\n\t\t}\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(\n\t\t\t\"POST\",\n\t\t\t`/api/workflows/${name}/trigger`,\n\t\t\tinput ? { input } : undefined,\n\t\t);\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(\n\t\t\t\"GET\",\n\t\t\t`/api/workflows/${name}/runs${query ? `?${query}` : \"\"}`,\n\t\t);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRun> {\n\t\treturn this.request(\"GET\", `/api/workflows/runs/${runId}`);\n\t}\n}\n",
|
|
11
|
+
"import { BaseClient } from \"./base.ts\";\nimport type { SecondLayerOptions } from \"./base.ts\";\nimport { Marketplace } from \"./marketplace/client.ts\";\nimport { Subgraphs } from \"./subgraphs/client.ts\";\nimport { Workflows } from \"./workflows/client.ts\";\n\nexport class SecondLayer extends BaseClient {\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.subgraphs = new Subgraphs(options);\n\t\tthis.marketplace = new Marketplace(options);\n\t\tthis.workflows = new Workflows(options);\n\t}\n}\n",
|
|
12
|
+
"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",
|
|
13
|
+
"import { verifySignatureHeader } from \"@secondlayer/shared/crypto/hmac\";\n\nexport { verifySignatureHeader };\n\n/**\n * Verify a webhook delivery signature from Secondlayer.\n *\n * Every delivery includes an `x-secondlayer-signature` header in the format\n * `t=<timestamp>,v1=<hmac>`. This function verifies the HMAC and checks\n * the timestamp is within the tolerance window (default 5 minutes).\n *\n * @param rawBody - The raw request body as a string (not parsed JSON)\n * @param signatureHeader - The value of the `x-secondlayer-signature` header\n * @param secret - Your signing secret\n * @param toleranceSeconds - Max age of signature in seconds (default 300)\n * @returns true if the signature is valid\n *\n * @example\n * ```ts\n * import { verifyWebhookSignature } from \"@secondlayer/sdk\";\n *\n * app.post(\"/webhook\", (req, res) => {\n * const sig = req.headers[\"x-secondlayer-signature\"];\n * const raw = JSON.stringify(req.body);\n * if (!verifyWebhookSignature(raw, sig, process.env.SIGNING_SECRET!)) {\n * return res.status(401).send(\"Invalid signature\");\n * }\n * // Process the event...\n * });\n * ```\n */\nexport function verifyWebhookSignature(\n\trawBody: string,\n\tsignatureHeader: string,\n\tsecret: string,\n\ttoleranceSeconds = 300,\n): boolean {\n\treturn verifySignatureHeader(\n\t\trawBody,\n\t\tsignatureHeader,\n\t\tsecret,\n\t\ttoleranceSeconds,\n\t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AiE,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;;AC/BxC;AA+BO,SAAS,sBAAsB,CACrC,SACA,iBACA,QACA,mBAAmB,KACT;AAAA,EACV,OAAO,sBACN,SACA,iBACA,QACA,gBACD;AAAA;",
|
|
16
|
+
"debugId": "4C3F7801DDE9B0B964756E2164756E21",
|
|
17
17
|
"names": []
|
|
18
18
|
}
|
|
@@ -4,10 +4,13 @@ interface SecondLayerOptions {
|
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
/** Bearer token for authenticated requests. */
|
|
6
6
|
apiKey?: string;
|
|
7
|
+
/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */
|
|
8
|
+
origin?: "cli" | "mcp" | "session";
|
|
7
9
|
}
|
|
8
10
|
declare abstract class BaseClient {
|
|
9
11
|
protected baseUrl: string;
|
|
10
12
|
protected apiKey?: string;
|
|
13
|
+
protected origin: "cli" | "mcp" | "session";
|
|
11
14
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
12
15
|
static authHeaders(apiKey?: string): Record<string, string>;
|
|
13
16
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
@@ -1,35 +1,51 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
2
|
class ApiError extends Error {
|
|
3
3
|
status;
|
|
4
|
-
|
|
4
|
+
body;
|
|
5
|
+
constructor(status, message, body) {
|
|
5
6
|
super(message);
|
|
6
7
|
this.status = status;
|
|
8
|
+
this.body = body;
|
|
7
9
|
this.name = "ApiError";
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
class VersionConflictError extends ApiError {
|
|
14
|
+
currentVersion;
|
|
15
|
+
expectedVersion;
|
|
16
|
+
constructor(currentVersion, expectedVersion, message = `Version conflict: expected ${expectedVersion}, current ${currentVersion}`) {
|
|
17
|
+
super(409, message, { currentVersion, expectedVersion });
|
|
18
|
+
this.currentVersion = currentVersion;
|
|
19
|
+
this.expectedVersion = expectedVersion;
|
|
20
|
+
this.name = "VersionConflictError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
// src/base.ts
|
|
12
25
|
var DEFAULT_BASE_URL = "https://api.secondlayer.tools";
|
|
13
26
|
|
|
14
27
|
class BaseClient {
|
|
15
28
|
baseUrl;
|
|
16
29
|
apiKey;
|
|
30
|
+
origin;
|
|
17
31
|
constructor(options = {}) {
|
|
18
32
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
19
33
|
this.apiKey = options.apiKey;
|
|
34
|
+
this.origin = options.origin ?? "cli";
|
|
20
35
|
}
|
|
21
36
|
static authHeaders(apiKey) {
|
|
22
37
|
const headers = {
|
|
23
38
|
"Content-Type": "application/json"
|
|
24
39
|
};
|
|
25
40
|
if (apiKey) {
|
|
26
|
-
headers
|
|
41
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
27
42
|
}
|
|
28
43
|
return headers;
|
|
29
44
|
}
|
|
30
45
|
async request(method, path, body) {
|
|
31
46
|
const url = `${this.baseUrl}${path}`;
|
|
32
47
|
const headers = BaseClient.authHeaders(this.apiKey);
|
|
48
|
+
headers["x-sl-origin"] = this.origin;
|
|
33
49
|
let response;
|
|
34
50
|
try {
|
|
35
51
|
response = await fetch(url, {
|
|
@@ -54,8 +70,10 @@ class BaseClient {
|
|
|
54
70
|
}
|
|
55
71
|
const errorBody = await response.text();
|
|
56
72
|
let message = `HTTP ${response.status}`;
|
|
73
|
+
let parsedBody = errorBody;
|
|
57
74
|
try {
|
|
58
75
|
const json = JSON.parse(errorBody);
|
|
76
|
+
parsedBody = json;
|
|
59
77
|
const err = json.error ?? json.message;
|
|
60
78
|
if (typeof err === "string") {
|
|
61
79
|
message = err;
|
|
@@ -66,7 +84,7 @@ class BaseClient {
|
|
|
66
84
|
if (errorBody)
|
|
67
85
|
message = errorBody;
|
|
68
86
|
}
|
|
69
|
-
throw new ApiError(response.status, message);
|
|
87
|
+
throw new ApiError(response.status, message, parsedBody);
|
|
70
88
|
}
|
|
71
89
|
if (response.status === 204) {
|
|
72
90
|
return;
|
|
@@ -135,5 +153,5 @@ export {
|
|
|
135
153
|
Marketplace
|
|
136
154
|
};
|
|
137
155
|
|
|
138
|
-
//# debugId=
|
|
156
|
+
//# debugId=89434BF75099946264756E2164756E21
|
|
139
157
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors.ts", "../src/base.ts", "../src/marketplace/client.ts"],
|
|
4
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.
|
|
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
|
|
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.subgraphs.get(\"my-subgraph\");\n * } catch (err) {\n * if (err instanceof ApiError && err.status === 404) {\n * console.log(\"Subgraph 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\t/** Raw response body (parsed JSON if possible) — preserved for callers that need error details. */\n\t\tpublic body?: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n\n/**\n * Thrown by {@link Workflows.deploy} when the server rejects a deploy because the\n * provided `expectedVersion` does not match the current stored version.\n */\nexport class VersionConflictError extends ApiError {\n\tconstructor(\n\t\tpublic currentVersion: string,\n\t\tpublic expectedVersion: string,\n\t\tmessage = `Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t) {\n\t\tsuper(409, message, { currentVersion, expectedVersion });\n\t\tthis.name = \"VersionConflictError\";\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\t/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */\n\torigin?: \"cli\" | \"mcp\" | \"session\";\n}\n\nconst DEFAULT_BASE_URL = \"https://api.secondlayer.tools\";\n\nexport abstract class BaseClient {\n\tprotected baseUrl: string;\n\tprotected apiKey?: string;\n\tprotected origin: \"cli\" | \"mcp\" | \"session\";\n\n\tconstructor(options: Partial<SecondLayerOptions> = {}) {\n\t\tthis.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\t\tthis.apiKey = options.apiKey;\n\t\tthis.origin = options.origin ?? \"cli\";\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\t\theaders[\"x-sl-origin\"] = this.origin;\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\tlet parsedBody: unknown = errorBody;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(errorBody);\n\t\t\t\tparsedBody = json;\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, parsedBody);\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
|
"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
8
|
],
|
|
9
|
-
"mappings": ";AAeO,MAAM,iBAAiB,MAAM;AAAA,EAG3B;AAAA,
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";AAeO,MAAM,iBAAiB,MAAM;AAAA,EAG3B;AAAA,EAGA;AAAA,EALR,WAAW,CAEH,QACP,SAEO,MACN;AAAA,IACD,MAAM,OAAO;AAAA,IALN;AAAA,IAGA;AAAA,IAGP,KAAK,OAAO;AAAA;AAEd;AAAA;AAMO,MAAM,6BAA6B,SAAS;AAAA,EAE1C;AAAA,EACA;AAAA,EAFR,WAAW,CACH,gBACA,iBACP,UAAU,8BAA8B,4BAA4B,kBAC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CACf,MACA,OACA,SAA8B,CAAC,GAI7B;AAAA,IACF,OAAO,KAAK,QACX,OACA,8BAA8B,QAAQ,QAAQ,yBAAyB,MAAM,GAC9E;AAAA;AAEF;",
|
|
10
|
+
"debugId": "89434BF75099946264756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -6,14 +6,36 @@ interface SecondLayerOptions {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
/** Bearer token for authenticated requests. */
|
|
8
8
|
apiKey?: string;
|
|
9
|
+
/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */
|
|
10
|
+
origin?: "cli" | "mcp" | "session";
|
|
9
11
|
}
|
|
10
12
|
declare abstract class BaseClient {
|
|
11
13
|
protected baseUrl: string;
|
|
12
14
|
protected apiKey?: string;
|
|
15
|
+
protected origin: "cli" | "mcp" | "session";
|
|
13
16
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
14
17
|
static authHeaders(apiKey?: string): Record<string, string>;
|
|
15
18
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
16
19
|
}
|
|
20
|
+
interface SubgraphSource {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
sourceCode: string | null;
|
|
24
|
+
readOnly: boolean;
|
|
25
|
+
reason?: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
}
|
|
28
|
+
interface BundleSubgraphResponse {
|
|
29
|
+
ok: true;
|
|
30
|
+
name: string;
|
|
31
|
+
version: string | null;
|
|
32
|
+
description: string | null;
|
|
33
|
+
sources: Record<string, Record<string, unknown>>;
|
|
34
|
+
schema: Record<string, unknown>;
|
|
35
|
+
handlerCode: string;
|
|
36
|
+
sourceCode: string;
|
|
37
|
+
bundleSize: number;
|
|
38
|
+
}
|
|
17
39
|
declare class Subgraphs extends BaseClient {
|
|
18
40
|
list(): Promise<{
|
|
19
41
|
data: SubgraphSummary[]
|
|
@@ -39,6 +61,14 @@ declare class Subgraphs extends BaseClient {
|
|
|
39
61
|
message: string
|
|
40
62
|
}>;
|
|
41
63
|
deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse>;
|
|
64
|
+
getSource(name: string): Promise<SubgraphSource>;
|
|
65
|
+
/**
|
|
66
|
+
* Bundle a TypeScript subgraph source on the server. Used by the web chat
|
|
67
|
+
* authoring loop so Vercel's serverless runtime doesn't have to run esbuild.
|
|
68
|
+
*/
|
|
69
|
+
bundle(data: {
|
|
70
|
+
code: string
|
|
71
|
+
}): Promise<BundleSubgraphResponse>;
|
|
42
72
|
queryTable(name: string, table: string, params?: SubgraphQueryParams): Promise<unknown[]>;
|
|
43
73
|
queryTableCount(name: string, table: string, params?: SubgraphQueryParams): Promise<{
|
|
44
74
|
count: number
|
|
@@ -62,7 +92,6 @@ declare class Subgraphs extends BaseClient {
|
|
|
62
92
|
private createTableClient;
|
|
63
93
|
}
|
|
64
94
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
65
|
-
import { QueueStats } from "@secondlayer/shared/types";
|
|
66
95
|
import { CreatorProfile, MarketplaceSubgraphDetail, MarketplaceSubgraphSummary, SubgraphQueryParams as SubgraphQueryParams2 } from "@secondlayer/shared/schemas";
|
|
67
96
|
interface MarketplaceBrowseOptions {
|
|
68
97
|
tags?: string[];
|
|
@@ -97,54 +126,78 @@ declare class Marketplace extends BaseClient {
|
|
|
97
126
|
}
|
|
98
127
|
}>;
|
|
99
128
|
}
|
|
100
|
-
import {
|
|
101
|
-
interface
|
|
129
|
+
import { WorkflowRun, WorkflowRunStatus } from "@secondlayer/workflows";
|
|
130
|
+
interface WorkflowSource {
|
|
131
|
+
name: string;
|
|
132
|
+
version: string;
|
|
133
|
+
sourceCode: string | null;
|
|
134
|
+
readOnly: boolean;
|
|
135
|
+
reason?: string;
|
|
136
|
+
updatedAt: string;
|
|
137
|
+
}
|
|
138
|
+
interface WorkflowStepEvent {
|
|
102
139
|
id: string;
|
|
103
|
-
|
|
140
|
+
stepIndex: number;
|
|
141
|
+
stepId: string;
|
|
142
|
+
stepType: string;
|
|
104
143
|
status: string;
|
|
105
|
-
|
|
106
|
-
responseTimeMs: number | null;
|
|
107
|
-
attempts: number;
|
|
144
|
+
output?: unknown;
|
|
108
145
|
error: string | null;
|
|
109
|
-
|
|
146
|
+
retryCount: number;
|
|
147
|
+
aiTokensUsed: number;
|
|
148
|
+
startedAt: string | null;
|
|
149
|
+
completedAt: string | null;
|
|
150
|
+
durationMs: number | null;
|
|
151
|
+
ts: string;
|
|
110
152
|
}
|
|
111
|
-
interface
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
interface WorkflowRunDoneEvent {
|
|
154
|
+
runId: string;
|
|
155
|
+
status: string;
|
|
156
|
+
error?: string | null;
|
|
157
|
+
completedAt?: string | null;
|
|
158
|
+
}
|
|
159
|
+
type WorkflowTailEvent = {
|
|
160
|
+
type: "step"
|
|
161
|
+
step: WorkflowStepEvent
|
|
162
|
+
} | {
|
|
163
|
+
type: "done"
|
|
164
|
+
done: WorkflowRunDoneEvent
|
|
165
|
+
} | {
|
|
166
|
+
type: "heartbeat"
|
|
167
|
+
ts: string
|
|
168
|
+
} | {
|
|
169
|
+
type: "timeout"
|
|
170
|
+
message: string
|
|
171
|
+
};
|
|
172
|
+
interface DeployDryRunResponse {
|
|
173
|
+
valid: boolean;
|
|
174
|
+
validation?: {
|
|
175
|
+
name: string
|
|
176
|
+
triggerType: string
|
|
177
|
+
};
|
|
178
|
+
bundleSize: number;
|
|
179
|
+
error?: string;
|
|
180
|
+
}
|
|
181
|
+
interface DeployResponse {
|
|
182
|
+
action: "created" | "updated";
|
|
183
|
+
workflowId: string;
|
|
184
|
+
version: string;
|
|
185
|
+
message: string;
|
|
186
|
+
}
|
|
187
|
+
interface BundleWorkflowResponse {
|
|
188
|
+
ok: true;
|
|
189
|
+
name: string;
|
|
190
|
+
trigger: Record<string, unknown>;
|
|
191
|
+
handlerCode: string;
|
|
192
|
+
sourceCode: string;
|
|
193
|
+
retries: Record<string, unknown> | null;
|
|
194
|
+
timeout: number | null;
|
|
195
|
+
bundleSize: number;
|
|
142
196
|
}
|
|
143
|
-
import { WorkflowRun, WorkflowRunStatus } from "@secondlayer/workflows";
|
|
144
197
|
interface WorkflowSummary {
|
|
145
198
|
name: string;
|
|
146
199
|
status: "active" | "paused";
|
|
147
|
-
triggerType: "event" | "
|
|
200
|
+
triggerType: "event" | "schedule" | "manual";
|
|
148
201
|
createdAt: string;
|
|
149
202
|
updatedAt: string;
|
|
150
203
|
}
|
|
@@ -172,13 +225,63 @@ declare class Workflows extends BaseClient {
|
|
|
172
225
|
name: string
|
|
173
226
|
trigger: Record<string, unknown>
|
|
174
227
|
handlerCode: string
|
|
228
|
+
sourceCode?: string
|
|
229
|
+
expectedVersion?: string
|
|
175
230
|
retries?: Record<string, unknown>
|
|
176
231
|
timeout?: number
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
232
|
+
clientRequestId?: string
|
|
233
|
+
} & {
|
|
234
|
+
dryRun?: false
|
|
235
|
+
}): Promise<DeployResponse>;
|
|
236
|
+
deploy(data: {
|
|
237
|
+
name: string
|
|
238
|
+
trigger: Record<string, unknown>
|
|
239
|
+
handlerCode: string
|
|
240
|
+
sourceCode?: string
|
|
241
|
+
expectedVersion?: string
|
|
242
|
+
retries?: Record<string, unknown>
|
|
243
|
+
timeout?: number
|
|
244
|
+
dryRun: true
|
|
245
|
+
}): Promise<DeployDryRunResponse>;
|
|
246
|
+
getSource(name: string): Promise<WorkflowSource>;
|
|
247
|
+
/**
|
|
248
|
+
* Bundle a TypeScript workflow source on the server. Used by the web chat
|
|
249
|
+
* authoring loop so Vercel's serverless runtime doesn't have to run esbuild.
|
|
250
|
+
* CLI and MCP still bundle locally — this method is for clients that can't
|
|
251
|
+
* install `@secondlayer/bundler` directly (e.g. browser tooling, edge
|
|
252
|
+
* functions).
|
|
253
|
+
*/
|
|
254
|
+
bundle(data: {
|
|
255
|
+
code: string
|
|
256
|
+
}): Promise<BundleWorkflowResponse>;
|
|
257
|
+
pauseAll(): Promise<{
|
|
258
|
+
paused: number
|
|
259
|
+
workflows: Array<{
|
|
260
|
+
name: string
|
|
261
|
+
version: string
|
|
262
|
+
status: string
|
|
263
|
+
}>
|
|
264
|
+
}>;
|
|
265
|
+
cancelRun(runId: string): Promise<{
|
|
266
|
+
runId: string
|
|
267
|
+
status: string
|
|
268
|
+
cancelled: boolean
|
|
269
|
+
completedAt?: string
|
|
270
|
+
message?: string
|
|
271
|
+
}>;
|
|
272
|
+
rollback(name: string, toVersion?: string): Promise<{
|
|
273
|
+
action: "rolled-back"
|
|
274
|
+
name: string
|
|
275
|
+
fromVersion: string
|
|
276
|
+
restoredFromVersion: string
|
|
277
|
+
version: string
|
|
181
278
|
}>;
|
|
279
|
+
/**
|
|
280
|
+
* Subscribe to a workflow run's server-sent event stream. Resolves when the
|
|
281
|
+
* run completes, times out, or the signal is aborted. Throws on HTTP errors
|
|
282
|
+
* opening the stream.
|
|
283
|
+
*/
|
|
284
|
+
streamRun(name: string, runId: string, onEvent: (event: WorkflowTailEvent) => void, signal?: AbortSignal): Promise<void>;
|
|
182
285
|
list(): Promise<{
|
|
183
286
|
workflows: WorkflowSummary[]
|
|
184
287
|
}>;
|
|
@@ -198,12 +301,10 @@ declare class Workflows extends BaseClient {
|
|
|
198
301
|
getRun(runId: string): Promise<WorkflowRun>;
|
|
199
302
|
}
|
|
200
303
|
declare class SecondLayer extends BaseClient {
|
|
201
|
-
readonly streams: Streams;
|
|
202
304
|
readonly subgraphs: Subgraphs;
|
|
203
305
|
readonly marketplace: Marketplace;
|
|
204
306
|
readonly workflows: Workflows;
|
|
205
307
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
206
|
-
getQueueStats(): Promise<QueueStats>;
|
|
207
308
|
}
|
|
208
309
|
/**
|
|
209
310
|
* Returns a typed client for a subgraph defined with `defineSubgraph()`.
|