@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 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. Webhooks are polymorphic — pick one kind:
521
-
522
- - **subgraph** — fires on rows written to a deployed subgraph table.
523
- - **chain** — fires on raw chain events with no subgraph. Forward-looking: it
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 (chain subs only): each apply is `chain.{type}.apply` with
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 for both kinds.
564
+ Webhooks) is unchanged.
580
565
 
581
566
  ```typescript
582
- // Lifecycle (both kinds)
583
- await sl.webhooks.update(id, { filter: { amount: { gte: "1000000" } } });
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 — any kind, any `format` — also carries a universal authenticity
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}` ``