@secondlayer/sdk 14.5.1 → 15.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -36
- package/dist/index.d.ts +558 -143
- package/dist/index.js +3 -23
- package/dist/index.js.map +12 -12
- package/dist/streams/index.d.ts +109 -59
- package/dist/streams/index.js.map +3 -3
- package/dist/subgraphs/index.d.ts +554 -128
- package/dist/subgraphs/index.js.map +9 -9
- package/dist/webhooks/doctor.d.ts +2 -13
- package/dist/webhooks/doctor.js +3 -23
- package/dist/webhooks/doctor.js.map +3 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -517,46 +517,25 @@ by `_id`.
|
|
|
517
517
|
|
|
518
518
|
Deprecated aliases (`sl.subscriptions`, `Subscriptions`) keep working for one release cycle.
|
|
519
519
|
|
|
520
|
-
Signed HTTP POSTs.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
starts at the chain tip and never backfills. The turnkey "webhook on a
|
|
525
|
-
contract / event / function / trait".
|
|
526
|
-
|
|
527
|
-
```typescript
|
|
528
|
-
// List / get
|
|
529
|
-
const { data } = await sl.webhooks.list();
|
|
530
|
-
const hook = await sl.webhooks.get(id);
|
|
531
|
-
|
|
532
|
-
// Create a SUBGRAPH webhook — sink a subgraph table to a signed endpoint.
|
|
533
|
-
// `signingSecret` is returned ONCE; store it in the receiver's env.
|
|
534
|
-
const { webhook, signingSecret } = await sl.webhooks.create({
|
|
535
|
-
name: "whale-alerts",
|
|
536
|
-
subgraphName: "transfers",
|
|
537
|
-
tableName: "events",
|
|
538
|
-
url: "https://example.com/hooks/transfers",
|
|
539
|
-
format: "standard-webhooks", // or inngest | trigger | cloudflare | cloudevents | raw
|
|
540
|
-
});
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
### Chain webhooks
|
|
544
|
-
|
|
545
|
-
Pass `triggers` instead of `subgraphName`/`tableName`. The `trigger.*` builders
|
|
546
|
-
are optional sugar — you can also pass raw objects (e.g.
|
|
547
|
-
`{ type: "contract_call", contractId: "SP....amm", functionName: "swap-*" }`).
|
|
548
|
-
All string fields accept `*` wildcards; `trait` scopes to contracts conforming
|
|
549
|
-
to a SIP/trait (e.g. `"sip-010"`); amounts are non-negative integer strings
|
|
550
|
-
(uint128-safe) or numbers.
|
|
520
|
+
Signed HTTP POSTs on raw chain events. A webhook starts at the chain tip and
|
|
521
|
+
never backfills; it is the turnkey "webhook on a contract / event / function /
|
|
522
|
+
trait". To react to your subgraph rows, watch the table from your own Postgres
|
|
523
|
+
or poll the subgraph API: see [React to your rows](https://www.secondlayer.tools/docs/subgraphs/reading#react-to-your-rows).
|
|
551
524
|
|
|
552
525
|
```typescript
|
|
553
526
|
import { SecondLayer, trigger } from "@secondlayer/sdk";
|
|
554
527
|
|
|
555
528
|
const sl = new SecondLayer({ apiKey: process.env.INSTANCE_TOKEN });
|
|
556
529
|
|
|
530
|
+
// List / get
|
|
531
|
+
const { data } = await sl.webhooks.list();
|
|
532
|
+
const hook = await sl.webhooks.get(id);
|
|
533
|
+
|
|
534
|
+
// Create. `signingSecret` is returned ONCE; store it in the receiver's env.
|
|
557
535
|
const { webhook, signingSecret } = await sl.webhooks.create({
|
|
558
536
|
name: "amm-swaps",
|
|
559
537
|
url: "https://my-app.com/webhook",
|
|
538
|
+
format: "standard-webhooks", // or inngest | trigger | cloudflare | cloudevents | raw
|
|
560
539
|
triggers: [
|
|
561
540
|
trigger.contractCall({ contractId: "SP....amm", functionName: "swap-*" }),
|
|
562
541
|
trigger.ftTransfer({ trait: "sip-010", minAmount: "1000000" }),
|
|
@@ -564,23 +543,29 @@ const { webhook, signingSecret } = await sl.webhooks.create({
|
|
|
564
543
|
});
|
|
565
544
|
```
|
|
566
545
|
|
|
546
|
+
The `trigger.*` builders are optional sugar: you can also pass raw objects
|
|
547
|
+
(e.g. `{ type: "contract_call", contractId: "SP....amm", functionName: "swap-*" }`).
|
|
548
|
+
All string fields accept `*` wildcards; `trait` scopes to contracts conforming
|
|
549
|
+
to a SIP/trait (e.g. `"sip-010"`); amounts are non-negative integer strings
|
|
550
|
+
(uint128-safe) or numbers.
|
|
551
|
+
|
|
567
552
|
One builder per event type:
|
|
568
553
|
`trigger.stxTransfer` / `stxMint` / `stxBurn` / `stxLock`,
|
|
569
554
|
`trigger.ftTransfer` / `ftMint` / `ftBurn`,
|
|
570
555
|
`trigger.nftTransfer` / `nftMint` / `nftBurn`,
|
|
571
556
|
`trigger.contractCall`, `trigger.contractDeploy`, `trigger.printEvent`.
|
|
572
557
|
|
|
573
|
-
Delivery envelope
|
|
558
|
+
Delivery envelope: each apply is `chain.{type}.apply` with
|
|
574
559
|
body `{ action: "apply", block_hash, block_height, tx_id, canonical, trigger,
|
|
575
560
|
event }`. On reorg you get `chain.reorg.rollback` with `{ action: "rollback",
|
|
576
561
|
fork_point_height, orphaned: [{ tx_id, event }] }`. Delivery is at-least-once: a
|
|
577
562
|
tx surviving a reorg re-delivers an apply under its new `block_hash`, so key
|
|
578
563
|
consumer state on `(tx_id, block_hash)`. Per-webhook HMAC signing (Standard
|
|
579
|
-
Webhooks) is unchanged
|
|
564
|
+
Webhooks) is unchanged.
|
|
580
565
|
|
|
581
566
|
```typescript
|
|
582
|
-
// Lifecycle
|
|
583
|
-
await sl.webhooks.update(id, {
|
|
567
|
+
// Lifecycle
|
|
568
|
+
await sl.webhooks.update(id, { maxRetries: 10 });
|
|
584
569
|
await sl.webhooks.pause(id);
|
|
585
570
|
await sl.webhooks.resume(id);
|
|
586
571
|
await sl.webhooks.rotateSecret(id); // returns new signing secret once
|
|
@@ -596,7 +581,7 @@ await sl.webhooks.requeue(id, outboxId);
|
|
|
596
581
|
|
|
597
582
|
### Verifying deliveries
|
|
598
583
|
|
|
599
|
-
Every delivery
|
|
584
|
+
Every delivery, any `format`, also carries a universal authenticity
|
|
600
585
|
signature you can verify with one published key, no per-webhook secret. The
|
|
601
586
|
headers are `webhook-id`, `x-secondlayer-signature`, and
|
|
602
587
|
`x-secondlayer-signature-keyid`; the signed content is `` `${webhook-id}.${rawBody}` ``
|