@journeybee/sdk 0.1.0 → 0.2.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 CHANGED
@@ -11,7 +11,14 @@ npm install @journeybee/sdk
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { client, listPartners, getLead, createLead } from "@journeybee/sdk";
14
+ import {
15
+ client,
16
+ createLogicalOperationId,
17
+ idempotencyHeaders,
18
+ listPartners,
19
+ getLead,
20
+ createLead,
21
+ } from "@journeybee/sdk";
15
22
 
16
23
  // Configure once
17
24
  client.setConfig({
@@ -30,16 +37,32 @@ const { data: lead } = await getLead({
30
37
  });
31
38
 
32
39
  // Create a lead
33
- const { data: newLead } = await createLead({
40
+ // Generate once before the first mutation. Keep it if the response is lost.
41
+ const operationId = createLogicalOperationId();
42
+ const createLeadOptions = {
43
+ headers: idempotencyHeaders(operationId),
34
44
  body: {
35
45
  first_name: "Jane",
36
46
  last_name: "Smith",
37
47
  email: "jane@acme.com",
38
48
  partnership_uuid: "partner-uuid",
39
49
  },
40
- });
50
+ };
51
+ const { data: newLead } = await createLead(createLeadOptions);
52
+
53
+ // Lost-response retry: reuse the same operation id and exact request data
54
+ // within the API's 24-hour Redis replay window.
55
+ const retry = await createLead(createLeadOptions);
41
56
  ```
42
57
 
58
+ The default SDK clients automatically add a fresh `Idempotency-Key` to every
59
+ mutation (`POST`, `PUT`, `PATCH`, `DELETE`) without overwriting an explicit
60
+ header. Use an explicit logical ID only when you need to retry a lost response.
61
+ Journeybee replays terminal 4xx, 429, and 5xx responses too, and Redis/store
62
+ failures fail closed. This is replay protection rather than a transaction with
63
+ the business database: it cannot guarantee no duplicate after the 24-hour
64
+ window or across a database/Redis crash boundary.
65
+
43
66
  ## Authentication
44
67
 
45
68
  Get your API key from **Settings > API Keys** in the Journeybee app.
@@ -56,9 +79,9 @@ client.setConfig({
56
79
  The default singleton is fine for single-tenant servers and CLI tools. For multi-tenant servers (one Node process handling multiple users) use `createClient` to build per-request clients instead of mutating the singleton:
57
80
 
58
81
  ```typescript
59
- import { createClient, createConfig, listPartners } from "@journeybee/sdk";
82
+ import { createIdempotentClient, createConfig, listPartners } from "@journeybee/sdk";
60
83
 
61
- const userClient = createClient(
84
+ const userClient = createIdempotentClient(
62
85
  createConfig({
63
86
  baseUrl: "https://api.journeybee.io/v1",
64
87
  auth: userApiKey,