@secondlayer/sdk 10.3.0 → 10.4.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 +23 -21
- package/dist/index.d.ts +53 -23
- package/dist/index.js +38 -39
- package/dist/index.js.map +8 -8
- package/dist/streams/index.js.map +1 -1
- package/dist/subgraphs/index.d.ts +20 -12
- package/dist/subgraphs/index.js +34 -36
- package/dist/subgraphs/index.js.map +7 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ const sl = new SecondLayer({
|
|
|
21
21
|
|
|
22
22
|
Auth, once: `sl.index`, `sl.streams`, `sl.subgraphs.rows`, and the typed
|
|
23
23
|
`subscribe` read `/v1`, which is open on loopback and needs `INSTANCE_TOKEN`
|
|
24
|
-
once the API is bound beyond it. Everything under `sl.subgraphs.*` and `sl.
|
|
24
|
+
once the API is bound beyond it. Everything under `sl.subgraphs.*` and `sl.webhooks.*` calls
|
|
25
25
|
`/api`, which needs `INSTANCE_TOKEN` as soon as one is configured, loopback
|
|
26
26
|
included, and `secondlayer init` always configures one. Every client, including
|
|
27
27
|
`createStreamsClient`, reads `INSTANCE_TOKEN` from the env when `apiKey` is
|
|
@@ -412,7 +412,7 @@ Exported types: `TransactionProof`, `TransactionProofVerifyResult`, `RewardSet`.
|
|
|
412
412
|
|
|
413
413
|
Deploy and query app-specific tables.
|
|
414
414
|
|
|
415
|
-
Subgraphs and
|
|
415
|
+
Subgraphs and webhooks live on the instance API alongside Streams and Index. Everything here except `rows` and the typed `subscribe` calls `/api`, which needs `INSTANCE_TOKEN` once one is configured (init always configures one), loopback included.
|
|
416
416
|
|
|
417
417
|
```typescript
|
|
418
418
|
// List
|
|
@@ -482,9 +482,11 @@ tail only. A dropped connection reconnects from the last delivered row's
|
|
|
482
482
|
`_block_height`, so rows at that height can arrive twice: key durable writes
|
|
483
483
|
by `_id`.
|
|
484
484
|
|
|
485
|
-
##
|
|
485
|
+
## Webhooks
|
|
486
486
|
|
|
487
|
-
|
|
487
|
+
Deprecated aliases (`sl.subscriptions`, `Subscriptions`) keep working for one release cycle.
|
|
488
|
+
|
|
489
|
+
Signed HTTP POSTs. Webhooks are polymorphic — pick one kind:
|
|
488
490
|
|
|
489
491
|
- **subgraph** — fires on rows written to a deployed subgraph table.
|
|
490
492
|
- **chain** — fires on raw chain events with no subgraph. Forward-looking: it
|
|
@@ -493,12 +495,12 @@ Signed HTTP webhooks. Subscriptions are polymorphic — pick one kind:
|
|
|
493
495
|
|
|
494
496
|
```typescript
|
|
495
497
|
// List / get
|
|
496
|
-
const { data } = await sl.
|
|
497
|
-
const
|
|
498
|
+
const { data } = await sl.webhooks.list();
|
|
499
|
+
const hook = await sl.webhooks.get(id);
|
|
498
500
|
|
|
499
|
-
// Create a SUBGRAPH
|
|
501
|
+
// Create a SUBGRAPH webhook — sink a subgraph table to a signed endpoint.
|
|
500
502
|
// `signingSecret` is returned ONCE; store it in the receiver's env.
|
|
501
|
-
const {
|
|
503
|
+
const { webhook, signingSecret } = await sl.webhooks.create({
|
|
502
504
|
name: "whale-alerts",
|
|
503
505
|
subgraphName: "transfers",
|
|
504
506
|
tableName: "events",
|
|
@@ -507,7 +509,7 @@ const { subscription, signingSecret } = await sl.subscriptions.create({
|
|
|
507
509
|
});
|
|
508
510
|
```
|
|
509
511
|
|
|
510
|
-
### Chain
|
|
512
|
+
### Chain webhooks
|
|
511
513
|
|
|
512
514
|
Pass `triggers` instead of `subgraphName`/`tableName`. The `trigger.*` builders
|
|
513
515
|
are optional sugar — you can also pass raw objects (e.g.
|
|
@@ -521,7 +523,7 @@ import { SecondLayer, trigger } from "@secondlayer/sdk";
|
|
|
521
523
|
|
|
522
524
|
const sl = new SecondLayer({ apiKey: process.env.INSTANCE_TOKEN });
|
|
523
525
|
|
|
524
|
-
const {
|
|
526
|
+
const { webhook, signingSecret } = await sl.webhooks.create({
|
|
525
527
|
name: "amm-swaps",
|
|
526
528
|
url: "https://my-app.com/webhook",
|
|
527
529
|
triggers: [
|
|
@@ -542,29 +544,29 @@ body `{ action: "apply", block_hash, block_height, tx_id, canonical, trigger,
|
|
|
542
544
|
event }`. On reorg you get `chain.reorg.rollback` with `{ action: "rollback",
|
|
543
545
|
fork_point_height, orphaned: [{ tx_id, event }] }`. Delivery is at-least-once: a
|
|
544
546
|
tx surviving a reorg re-delivers an apply under its new `block_hash`, so key
|
|
545
|
-
consumer state on `(tx_id, block_hash)`. Per-
|
|
547
|
+
consumer state on `(tx_id, block_hash)`. Per-webhook HMAC signing (Standard
|
|
546
548
|
Webhooks) is unchanged for both kinds.
|
|
547
549
|
|
|
548
550
|
```typescript
|
|
549
551
|
// Lifecycle (both kinds)
|
|
550
|
-
await sl.
|
|
551
|
-
await sl.
|
|
552
|
-
await sl.
|
|
553
|
-
await sl.
|
|
554
|
-
const { data: deliveries } = await sl.
|
|
552
|
+
await sl.webhooks.update(id, { filter: { amount: { gte: "1000000" } } });
|
|
553
|
+
await sl.webhooks.pause(id);
|
|
554
|
+
await sl.webhooks.resume(id);
|
|
555
|
+
await sl.webhooks.rotateSecret(id); // returns new signing secret once
|
|
556
|
+
const { data: deliveries } = await sl.webhooks.deliveries(id);
|
|
555
557
|
|
|
556
558
|
// Replay historical block range
|
|
557
|
-
await sl.
|
|
559
|
+
await sl.webhooks.replay(id, { fromBlock: 180000, toBlock: 181000 });
|
|
558
560
|
|
|
559
561
|
// Dead-letter inspection + requeue
|
|
560
|
-
const { data: dead } = await sl.
|
|
561
|
-
await sl.
|
|
562
|
+
const { data: dead } = await sl.webhooks.dead(id);
|
|
563
|
+
await sl.webhooks.requeue(id, outboxId);
|
|
562
564
|
```
|
|
563
565
|
|
|
564
566
|
### Verifying deliveries
|
|
565
567
|
|
|
566
568
|
Every delivery — any kind, any `format` — also carries a universal authenticity
|
|
567
|
-
signature you can verify with one published key, no per-
|
|
569
|
+
signature you can verify with one published key, no per-webhook secret. The
|
|
568
570
|
headers are `webhook-id`, `x-secondlayer-signature`, and
|
|
569
571
|
`x-secondlayer-signature-keyid`; the signed content is `` `${webhook-id}.${rawBody}` ``
|
|
570
572
|
(ed25519). Fetch the public key from `GET /public/streams/signing-key`.
|
|
@@ -590,7 +592,7 @@ verifySecondlayerSignature(
|
|
|
590
592
|
): boolean;
|
|
591
593
|
```
|
|
592
594
|
|
|
593
|
-
Prefer the per-
|
|
595
|
+
Prefer the per-webhook HMAC (Standard Webhooks) secret instead? Use
|
|
594
596
|
`verifyWebhookSignature(rawBody, headers, secret)` — raw body first.
|
|
595
597
|
|
|
596
598
|
## x402 pay-per-call (accountless)
|
package/dist/index.d.ts
CHANGED
|
@@ -277,6 +277,7 @@ type ArchiveVerifyResult = {
|
|
|
277
277
|
reason?: string;
|
|
278
278
|
};
|
|
279
279
|
import { RangeDigest } from "@secondlayer/shared/archive/range-digest";
|
|
280
|
+
import { ArchiveStatus } from "@secondlayer/shared/archive/status";
|
|
280
281
|
type ArchiveDataset = "blocks" | "transactions" | "events";
|
|
281
282
|
type ArchiveFlow = "bootstrap" | "repair";
|
|
282
283
|
type ArchivePartition = {
|
|
@@ -346,7 +347,7 @@ type ArchiveLoadOptions = {
|
|
|
346
347
|
type ArchiveClient = {
|
|
347
348
|
latest(against?: string, opts?: ArchiveLoadOptions): Promise<LoadedArchive>;
|
|
348
349
|
load(against: string, opts?: ArchiveLoadOptions): Promise<LoadedArchive>;
|
|
349
|
-
status(): Promise<
|
|
350
|
+
status(): Promise<ArchiveStatus>;
|
|
350
351
|
partitions(ref: LoadedArchive, filter?: {
|
|
351
352
|
dataset?: ArchiveDataset;
|
|
352
353
|
fromBlock?: number;
|
|
@@ -2563,25 +2564,43 @@ declare class Index extends BaseClient {
|
|
|
2563
2564
|
private walkPoxCycles;
|
|
2564
2565
|
private getPoxCycle;
|
|
2565
2566
|
}
|
|
2566
|
-
import {
|
|
2567
|
-
import { ChainTrigger, ChainTriggerType,
|
|
2568
|
-
import { trigger } from "@secondlayer/shared/schemas/
|
|
2569
|
-
|
|
2567
|
+
import { CreateWebhookRequest, CreateWebhookResponse, DeadRow, DeliveryRow, ReplayResult, RotateSecretResponse, UpdateWebhookRequest, WebhookDetail, WebhookFormat, WebhookKind, WebhookRuntime, WebhookStatus, WebhookSummary, WebhookTestResult } from "@secondlayer/shared/schemas/webhooks";
|
|
2568
|
+
import { ChainTrigger, ChainTriggerType, CreateWebhookRequest as CreateWebhookRequest2, CreateWebhookResponse as CreateWebhookResponse2, DeadRow as DeadRow2, DeliveryRow as DeliveryRow2, ReplayResult as ReplayResult2, RotateSecretResponse as RotateSecretResponse2, WebhookDetail as WebhookDetail2, WebhookFormat as WebhookFormat2, WebhookKind as WebhookKind2, WebhookRuntime as WebhookRuntime2, WebhookStatus as WebhookStatus2, WebhookSummary as WebhookSummary2, WebhookTestResult as WebhookTestResult2, UpdateWebhookRequest as UpdateWebhookRequest2 } from "@secondlayer/shared/schemas/webhooks";
|
|
2569
|
+
import { trigger } from "@secondlayer/shared/schemas/webhooks";
|
|
2570
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2571
|
+
type CreateSubscriptionRequest = CreateWebhookRequest;
|
|
2572
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2573
|
+
type CreateSubscriptionResponse = CreateWebhookResponse;
|
|
2574
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2575
|
+
type UpdateSubscriptionRequest = UpdateWebhookRequest;
|
|
2576
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2577
|
+
type SubscriptionDetail = WebhookDetail;
|
|
2578
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2579
|
+
type SubscriptionSummary = WebhookSummary;
|
|
2580
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2581
|
+
type SubscriptionFormat = WebhookFormat;
|
|
2582
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2583
|
+
type SubscriptionKind = WebhookKind;
|
|
2584
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2585
|
+
type SubscriptionRuntime = WebhookRuntime;
|
|
2586
|
+
/** @deprecated Use webhook type. Removed next minor. */
|
|
2587
|
+
type SubscriptionStatus = WebhookStatus;
|
|
2588
|
+
declare class Webhooks extends BaseClient {
|
|
2570
2589
|
list(): Promise<{
|
|
2571
|
-
data:
|
|
2590
|
+
data: WebhookSummary[];
|
|
2572
2591
|
}>;
|
|
2573
|
-
get(id: string): Promise<
|
|
2574
|
-
create(input:
|
|
2575
|
-
update(id: string, patch:
|
|
2576
|
-
pause(id: string): Promise<
|
|
2577
|
-
resume(id: string): Promise<
|
|
2592
|
+
get(id: string): Promise<WebhookDetail>;
|
|
2593
|
+
create(input: CreateWebhookRequest): Promise<CreateWebhookResponse>;
|
|
2594
|
+
update(id: string, patch: UpdateWebhookRequest): Promise<WebhookDetail>;
|
|
2595
|
+
pause(id: string): Promise<WebhookDetail>;
|
|
2596
|
+
resume(id: string): Promise<WebhookDetail>;
|
|
2578
2597
|
delete(id: string): Promise<{
|
|
2579
2598
|
ok: true;
|
|
2580
2599
|
}>;
|
|
2581
2600
|
rotateSecret(id: string): Promise<RotateSecretResponse>;
|
|
2582
|
-
/** Send a one-off test webhook to the
|
|
2601
|
+
/** Send a one-off test webhook to the webhook's URL (built for its
|
|
2583
2602
|
* format, SSRF-guarded). Logged as a delivery row, visible via deliveries. */
|
|
2584
|
-
test(id: string): Promise<
|
|
2603
|
+
test(id: string): Promise<WebhookTestResult>;
|
|
2585
2604
|
/** The last 100 delivery attempts, newest first. The server caps the window;
|
|
2586
2605
|
* there is nothing to page. */
|
|
2587
2606
|
deliveries(id: string): Promise<{
|
|
@@ -2601,6 +2620,10 @@ declare class Subscriptions extends BaseClient {
|
|
|
2601
2620
|
ok: true;
|
|
2602
2621
|
}>;
|
|
2603
2622
|
}
|
|
2623
|
+
/** @deprecated Use {@link Webhooks}. Removed in the next minor. */
|
|
2624
|
+
declare const Subscriptions: typeof Webhooks;
|
|
2625
|
+
/** @deprecated Use {@link Webhooks}. Removed in the next minor. */
|
|
2626
|
+
type Subscriptions = Webhooks;
|
|
2604
2627
|
interface ContextAccount {
|
|
2605
2628
|
email: string;
|
|
2606
2629
|
}
|
|
@@ -2642,6 +2665,11 @@ interface ContextSnapshot {
|
|
|
2642
2665
|
streamsTip: ContextField<StreamsTip>;
|
|
2643
2666
|
indexTip: ContextField<IndexTip>;
|
|
2644
2667
|
subgraphs: ContextField<SubgraphSummary2[]>;
|
|
2668
|
+
webhooks: ContextField<{
|
|
2669
|
+
count: number;
|
|
2670
|
+
byStatus: Record<string, number>;
|
|
2671
|
+
}>;
|
|
2672
|
+
/** @deprecated Use {@link ContextSnapshot.webhooks}. Removed next minor. */
|
|
2645
2673
|
subscriptions: ContextField<{
|
|
2646
2674
|
count: number;
|
|
2647
2675
|
byStatus: Record<string, number>;
|
|
@@ -2660,9 +2688,11 @@ declare class SecondLayer extends BaseClient {
|
|
|
2660
2688
|
readonly index: Index;
|
|
2661
2689
|
readonly contracts: Contracts;
|
|
2662
2690
|
readonly subgraphs: Subgraphs;
|
|
2663
|
-
readonly
|
|
2691
|
+
readonly webhooks: Webhooks;
|
|
2664
2692
|
readonly archive: SecondLayerArchive;
|
|
2665
2693
|
readonly instance: InstanceClient;
|
|
2694
|
+
/** @deprecated Use `webhooks`. Removed next minor. */
|
|
2695
|
+
get subscriptions(): Webhooks;
|
|
2666
2696
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
2667
2697
|
/**
|
|
2668
2698
|
* Up to 10 public reads in one round trip (`POST /v1/batch`). Each item
|
|
@@ -2988,7 +3018,7 @@ type WebhookHeaderInput = HeaderLookup | StandardWebhooksHeaders | Record<string
|
|
|
2988
3018
|
/**
|
|
2989
3019
|
* Verify a Secondlayer webhook delivery signature.
|
|
2990
3020
|
*
|
|
2991
|
-
* Every delivery whose
|
|
3021
|
+
* Every delivery whose webhook `format` is `"standard-webhooks"` (the
|
|
2992
3022
|
* default) carries three Standard Webhooks headers:
|
|
2993
3023
|
*
|
|
2994
3024
|
* webhook-id — UUID for the delivery (stable across retries; use as
|
|
@@ -2997,7 +3027,7 @@ type WebhookHeaderInput = HeaderLookup | StandardWebhooksHeaders | Record<string
|
|
|
2997
3027
|
* webhook-signature — space-separated list of `v1,<base64-hmac>` tuples
|
|
2998
3028
|
*
|
|
2999
3029
|
* The signed content is `${id}.${timestamp}.${rawBody}` HMAC-SHA256 with the
|
|
3000
|
-
* signing secret. Secrets returned by `
|
|
3030
|
+
* signing secret. Secrets returned by `secondlayer webhooks create` (or
|
|
3001
3031
|
* `rotate-secret`) are a bare 64-character hex string used directly as the
|
|
3002
3032
|
* HMAC key (its UTF-8 bytes) — this helper handles that. A `whsec_`-prefixed
|
|
3003
3033
|
* base64 secret (the Svix convention) is also accepted and base64-decoded after
|
|
@@ -3018,7 +3048,7 @@ type WebhookHeaderInput = HeaderLookup | StandardWebhooksHeaders | Record<string
|
|
|
3018
3048
|
* a header value by name. Header name matching is
|
|
3019
3049
|
* case-insensitive.
|
|
3020
3050
|
* @param secret The signing secret returned by
|
|
3021
|
-
* `
|
|
3051
|
+
* `secondlayer webhooks create` / `rotateSecret` (a bare
|
|
3022
3052
|
* 64-char hex string). Pass it through verbatim — the
|
|
3023
3053
|
* helper accepts both bare hex and `whsec_`-prefixed
|
|
3024
3054
|
* base64 secrets.
|
|
@@ -3068,7 +3098,7 @@ declare function verifyWebhookSignature(rawBody: string, headers: WebhookHeaderI
|
|
|
3068
3098
|
* Verify the universal Secondlayer authenticity signature that every delivery
|
|
3069
3099
|
* carries, regardless of body format (`raw`, `cloudevents`, `standard-webhooks`,
|
|
3070
3100
|
* …). This is the format-agnostic alternative to {@link verifyWebhookSignature}:
|
|
3071
|
-
* instead of a per-
|
|
3101
|
+
* instead of a per-webhook HMAC secret, it checks an ed25519 signature over
|
|
3072
3102
|
* `${webhook-id}.${rawBody}` against Secondlayer's published public key — so one
|
|
3073
3103
|
* key proves authenticity for any format.
|
|
3074
3104
|
*
|
|
@@ -3095,18 +3125,18 @@ declare function verifyWebhookSignature(rawBody: string, headers: WebhookHeaderI
|
|
|
3095
3125
|
*/
|
|
3096
3126
|
declare function verifySecondlayerSignature(rawBody: string, headers: WebhookHeaderInput, publicKeyPem: string): boolean;
|
|
3097
3127
|
/**
|
|
3098
|
-
* Decode + narrow a chain
|
|
3128
|
+
* Decode + narrow a chain webhook delivery body into a typed
|
|
3099
3129
|
* {@link ChainWebhookDelivery}. Verify the signature first with
|
|
3100
3130
|
* {@link verifyWebhookSignature} (or {@link verifySecondlayerSignature}), then
|
|
3101
3131
|
* decode the same raw body — this does not check authenticity, only shape.
|
|
3102
3132
|
*
|
|
3103
3133
|
* Only understands the `format: "standard-webhooks"` envelope (`{ type,
|
|
3104
|
-
* timestamp, data }`) — the
|
|
3134
|
+
* timestamp, data }`) — the webhook default, and the only format
|
|
3105
3135
|
* `verifyWebhookSignature` covers. Other formats (`raw`, `cloudevents`, …)
|
|
3106
3136
|
* carry the same `data` value under a different envelope; see the "Chain
|
|
3107
|
-
*
|
|
3137
|
+
* webhook payloads" doc for how to unwrap those.
|
|
3108
3138
|
*
|
|
3109
|
-
* A chain
|
|
3139
|
+
* A chain webhook delivery is NOT a Streams/Index event — do not run this
|
|
3110
3140
|
* over a `StreamsEvent` body (`{ event_type, payload }`) or vice versa.
|
|
3111
3141
|
*
|
|
3112
3142
|
* @param rawBody The raw request body string (same bytes passed to
|
|
@@ -3135,4 +3165,4 @@ declare function verifySecondlayerSignature(rawBody: string, headers: WebhookHea
|
|
|
3135
3165
|
declare function decodeChainWebhook(rawBody: string): ChainWebhookDelivery;
|
|
3136
3166
|
import { RewardSet as RewardSet2 } from "@secondlayer/shared/node/consensus";
|
|
3137
3167
|
import { decodeClarityValue, toJsonSafe } from "@secondlayer/shared/streams-rows";
|
|
3138
|
-
export { verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, resolveBaseUrl, resolveApiKey, resolveAccountKey, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, decode, createStreamsClient, createArchiveClient, contextField, consumerHealth, consumeIndexFeed, WithSinkTx, WebhookHeaderInput, WalkOptions, ValidationError,
|
|
3168
|
+
export { verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, resolveBaseUrl, resolveApiKey, resolveAccountKey, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, decode, createStreamsClient, createArchiveClient, contextField, consumerHealth, consumeIndexFeed, WithSinkTx, Webhooks, WebhookTestResult2 as WebhookTestResult, WebhookSummary2 as WebhookSummary, WebhookStatus2 as WebhookStatus, WebhookRuntime2 as WebhookRuntime, WebhookKind2 as WebhookKind, WebhookHeaderInput, WebhookFormat2 as WebhookFormat, WebhookDetail2 as WebhookDetail, WalkOptions, ValidationError, UpdateWebhookRequest2 as UpdateWebhookRequest, UpdateSubscriptionRequest, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsSubscription, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SinkTx, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayerArchive, SecondLayer, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic2 as SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, RequestOptions, ReplayResult2 as ReplayResult, RateLimitError, PublicStatus2 as PublicStatus, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload2 as NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, LoadedArchive, LOCAL_API_URL, InsufficientArchiveCreditsError, InstanceStatus, InstanceState, InstanceIssue, InstanceDiagnosis3 as InstanceDiagnosis, InstanceClient, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEventFields, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, IndexAlwaysFields, Index, INSTANCE_TOKEN_ENV, INDEX_MAX_PAGE_SIZE, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload2 as FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_REQUEST_TIMEOUT_MS, Cursor, CreateWebhookResponse2 as CreateWebhookResponse, CreateWebhookRequest2 as CreateWebhookRequest, CreateSubscriptionResponse, CreateSubscriptionRequest, CreateArchiveClientOptions, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextFieldError, ContextField, ContextAccount, ConsumerSink, ConsumerHealth, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ArchiveVerifyResult, ArchiveVerifyRangeStatus, ArchiveVerifyInput, ArchiveStatus, ArchiveSignatureError, ArchiveQuote, ArchivePartition, ArchiveManifest, ArchiveLoadOptions, ArchiveGateNotConfiguredError, ArchiveFlow, ArchiveFetchResult, ArchiveFetchItem, ArchiveDataset, ArchiveCreditsBalance, ArchiveClient, ArchiveAuthError, ApiError, ActiveSubgraphOperation, ACCOUNT_KEY_ENV };
|
package/dist/index.js
CHANGED
|
@@ -983,7 +983,7 @@ function createArchiveClient(options = {}) {
|
|
|
983
983
|
if (!response.ok) {
|
|
984
984
|
throw new ApiError(response.status, `Could not fetch archive status (${response.status}).`);
|
|
985
985
|
}
|
|
986
|
-
return response.json();
|
|
986
|
+
return await response.json();
|
|
987
987
|
}
|
|
988
988
|
function partitions(ref, filter) {
|
|
989
989
|
let list = ref.manifest.partitions ?? [];
|
|
@@ -2448,50 +2448,51 @@ function createStreamsClient(options) {
|
|
|
2448
2448
|
};
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
|
-
// src/
|
|
2452
|
-
import { trigger } from "@secondlayer/shared/schemas/
|
|
2451
|
+
// src/webhooks/client.ts
|
|
2452
|
+
import { trigger } from "@secondlayer/shared/schemas/webhooks";
|
|
2453
2453
|
|
|
2454
|
-
class
|
|
2454
|
+
class Webhooks extends BaseClient {
|
|
2455
2455
|
async list() {
|
|
2456
|
-
return this.request("GET", "/api/
|
|
2456
|
+
return this.request("GET", "/api/webhooks");
|
|
2457
2457
|
}
|
|
2458
2458
|
async get(id) {
|
|
2459
|
-
return this.request("GET", `/api/
|
|
2459
|
+
return this.request("GET", `/api/webhooks/${seg(id)}`);
|
|
2460
2460
|
}
|
|
2461
2461
|
async create(input) {
|
|
2462
|
-
return this.request("POST", "/api/
|
|
2462
|
+
return this.request("POST", "/api/webhooks", input);
|
|
2463
2463
|
}
|
|
2464
2464
|
async update(id, patch) {
|
|
2465
|
-
return this.request("PATCH", `/api/
|
|
2465
|
+
return this.request("PATCH", `/api/webhooks/${seg(id)}`, patch);
|
|
2466
2466
|
}
|
|
2467
2467
|
async pause(id) {
|
|
2468
|
-
return this.request("POST", `/api/
|
|
2468
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/pause`);
|
|
2469
2469
|
}
|
|
2470
2470
|
async resume(id) {
|
|
2471
|
-
return this.request("POST", `/api/
|
|
2471
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/resume`);
|
|
2472
2472
|
}
|
|
2473
2473
|
async delete(id) {
|
|
2474
|
-
return this.request("DELETE", `/api/
|
|
2474
|
+
return this.request("DELETE", `/api/webhooks/${seg(id)}`);
|
|
2475
2475
|
}
|
|
2476
2476
|
async rotateSecret(id) {
|
|
2477
|
-
return this.request("POST", `/api/
|
|
2477
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/rotate-secret`);
|
|
2478
2478
|
}
|
|
2479
2479
|
async test(id) {
|
|
2480
|
-
return this.request("POST", `/api/
|
|
2480
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/test`);
|
|
2481
2481
|
}
|
|
2482
2482
|
async deliveries(id) {
|
|
2483
|
-
return this.request("GET", `/api/
|
|
2483
|
+
return this.request("GET", `/api/webhooks/${seg(id)}/deliveries`);
|
|
2484
2484
|
}
|
|
2485
2485
|
async replay(id, range) {
|
|
2486
|
-
return this.request("POST", `/api/
|
|
2486
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/replay`, range);
|
|
2487
2487
|
}
|
|
2488
2488
|
async dead(id) {
|
|
2489
|
-
return this.request("GET", `/api/
|
|
2489
|
+
return this.request("GET", `/api/webhooks/${seg(id)}/dead`);
|
|
2490
2490
|
}
|
|
2491
2491
|
async requeue(id, outboxId) {
|
|
2492
|
-
return this.request("POST", `/api/
|
|
2492
|
+
return this.request("POST", `/api/webhooks/${seg(id)}/dead/${seg(outboxId)}/requeue`);
|
|
2493
2493
|
}
|
|
2494
2494
|
}
|
|
2495
|
+
var Subscriptions = Webhooks;
|
|
2495
2496
|
|
|
2496
2497
|
// src/client.ts
|
|
2497
2498
|
async function contextField(read) {
|
|
@@ -2524,9 +2525,12 @@ class SecondLayer extends BaseClient {
|
|
|
2524
2525
|
index;
|
|
2525
2526
|
contracts;
|
|
2526
2527
|
subgraphs;
|
|
2527
|
-
|
|
2528
|
+
webhooks;
|
|
2528
2529
|
archive;
|
|
2529
2530
|
instance;
|
|
2531
|
+
get subscriptions() {
|
|
2532
|
+
return this.webhooks;
|
|
2533
|
+
}
|
|
2530
2534
|
constructor(options = {}) {
|
|
2531
2535
|
super(options);
|
|
2532
2536
|
this.streams = createStreamsClient({
|
|
@@ -2541,7 +2545,7 @@ class SecondLayer extends BaseClient {
|
|
|
2541
2545
|
this.index = new Index(options);
|
|
2542
2546
|
this.contracts = new Contracts(options);
|
|
2543
2547
|
this.subgraphs = new Subgraphs(options);
|
|
2544
|
-
this.
|
|
2548
|
+
this.webhooks = new Webhooks(options);
|
|
2545
2549
|
const request = (method, path, body) => this.request(method, path, body);
|
|
2546
2550
|
this.archive = {
|
|
2547
2551
|
...createArchiveClient({
|
|
@@ -2558,36 +2562,29 @@ class SecondLayer extends BaseClient {
|
|
|
2558
2562
|
return this.request("POST", "/v1/batch", { requests });
|
|
2559
2563
|
}
|
|
2560
2564
|
async context() {
|
|
2561
|
-
const [
|
|
2562
|
-
account,
|
|
2563
|
-
streamsTip,
|
|
2564
|
-
indexEnv,
|
|
2565
|
-
subgraphsRes,
|
|
2566
|
-
subscriptionsRes,
|
|
2567
|
-
instance
|
|
2568
|
-
] = await Promise.all([
|
|
2565
|
+
const [account, streamsTip, indexEnv, subgraphsRes, webhooksRes, instance] = await Promise.all([
|
|
2569
2566
|
contextField(this.request("GET", "/api/accounts/me")),
|
|
2570
2567
|
contextField(this.streams.tip()),
|
|
2571
2568
|
contextField(this.index.canonical.list({ limit: 1 })),
|
|
2572
2569
|
contextField(this.subgraphs.list()),
|
|
2573
|
-
contextField(this.
|
|
2570
|
+
contextField(this.webhooks.list()),
|
|
2574
2571
|
contextField(this.instance.diagnose())
|
|
2575
2572
|
]);
|
|
2576
2573
|
const subgraphs = {
|
|
2577
2574
|
value: subgraphsRes.value?.data ?? null,
|
|
2578
2575
|
...subgraphsRes.error ? { error: subgraphsRes.error } : {}
|
|
2579
2576
|
};
|
|
2580
|
-
const
|
|
2577
|
+
const webhooks = {
|
|
2581
2578
|
value: null,
|
|
2582
|
-
...
|
|
2579
|
+
...webhooksRes.error ? { error: webhooksRes.error } : {}
|
|
2583
2580
|
};
|
|
2584
|
-
if (
|
|
2581
|
+
if (webhooksRes.value) {
|
|
2585
2582
|
const byStatus = {};
|
|
2586
|
-
for (const s of
|
|
2583
|
+
for (const s of webhooksRes.value.data) {
|
|
2587
2584
|
byStatus[s.status] = (byStatus[s.status] ?? 0) + 1;
|
|
2588
2585
|
}
|
|
2589
|
-
|
|
2590
|
-
count:
|
|
2586
|
+
webhooks.value = {
|
|
2587
|
+
count: webhooksRes.value.data.length,
|
|
2591
2588
|
byStatus
|
|
2592
2589
|
};
|
|
2593
2590
|
}
|
|
@@ -2622,7 +2619,8 @@ class SecondLayer extends BaseClient {
|
|
|
2622
2619
|
...indexEnv.error ? { error: indexEnv.error } : {}
|
|
2623
2620
|
},
|
|
2624
2621
|
subgraphs,
|
|
2625
|
-
|
|
2622
|
+
webhooks,
|
|
2623
|
+
subscriptions: webhooks,
|
|
2626
2624
|
activeOperations,
|
|
2627
2625
|
instance
|
|
2628
2626
|
};
|
|
@@ -2710,7 +2708,7 @@ function shutdownSignal(options = {}) {
|
|
|
2710
2708
|
}
|
|
2711
2709
|
return controller.signal;
|
|
2712
2710
|
}
|
|
2713
|
-
// src/webhooks.ts
|
|
2711
|
+
// src/webhooks/verify.ts
|
|
2714
2712
|
import { verifySecondlayerSignatureValues } from "@secondlayer/shared/crypto/secondlayer-webhook";
|
|
2715
2713
|
import {
|
|
2716
2714
|
verify
|
|
@@ -2762,10 +2760,10 @@ function verifySecondlayerSignature(rawBody, headers, publicKeyPem) {
|
|
|
2762
2760
|
function decodeChainWebhook(rawBody) {
|
|
2763
2761
|
const parsed = JSON.parse(rawBody);
|
|
2764
2762
|
if (typeof parsed.type !== "string" || typeof parsed.timestamp !== "string" || typeof parsed.data !== "object" || parsed.data === null) {
|
|
2765
|
-
throw new Error("decodeChainWebhook: not a chain
|
|
2763
|
+
throw new Error("decodeChainWebhook: not a chain webhook delivery — expected { type, timestamp, data }");
|
|
2766
2764
|
}
|
|
2767
2765
|
if (!parsed.type.startsWith("chain.")) {
|
|
2768
|
-
throw new Error(`decodeChainWebhook: not a chain
|
|
2766
|
+
throw new Error(`decodeChainWebhook: not a chain webhook delivery (type "${parsed.type}")`);
|
|
2769
2767
|
}
|
|
2770
2768
|
const data = parsed.data;
|
|
2771
2769
|
if (parsed.type === "chain.test.apply") {
|
|
@@ -2911,6 +2909,7 @@ export {
|
|
|
2911
2909
|
contextField,
|
|
2912
2910
|
consumerHealth,
|
|
2913
2911
|
consumeIndexFeed,
|
|
2912
|
+
Webhooks,
|
|
2914
2913
|
ValidationError,
|
|
2915
2914
|
Subscriptions,
|
|
2916
2915
|
Subgraphs,
|
|
@@ -2935,5 +2934,5 @@ export {
|
|
|
2935
2934
|
ACCOUNT_KEY_ENV
|
|
2936
2935
|
};
|
|
2937
2936
|
|
|
2938
|
-
//# debugId=
|
|
2937
|
+
//# debugId=6F925903665843A164756E2164756E21
|
|
2939
2938
|
//# sourceMappingURL=index.js.map
|