@offerkit/sdk 0.2.3 → 0.2.5

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 ADDED
@@ -0,0 +1,84 @@
1
+ # @offerkit/sdk
2
+
3
+ Typed TypeScript client for the OfferKit API.
4
+
5
+ OfferKit is open-source promotion infrastructure for coupons, gift cards, loyalty, referrals, customer segments, and validation rules. The SDK is generated from the same oRPC contract used by the REST API, so request and response types stay in sync with your OfferKit deployment.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @offerkit/sdk
11
+ ```
12
+
13
+ ```bash
14
+ pnpm add @offerkit/sdk
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { createClient } from "@offerkit/sdk";
21
+
22
+ const offerkit = createClient({
23
+ baseUrl: "https://your-offerkit-deployment",
24
+ apiKey: process.env.OFFERKIT_API_KEY,
25
+ });
26
+
27
+ const vouchers = await offerkit.vouchers.list({
28
+ limit: 20,
29
+ search: "SUMMER",
30
+ });
31
+
32
+ const validation = await offerkit.vouchers.validate({
33
+ params: { code: "SUMMER10" },
34
+ body: {
35
+ order: {
36
+ amount: 9999,
37
+ currency: "USD",
38
+ items: [],
39
+ },
40
+ },
41
+ });
42
+
43
+ const redemption = await offerkit.vouchers.redeem({
44
+ params: { code: "SUMMER10" },
45
+ body: {
46
+ order: {
47
+ amount: 9999,
48
+ currency: "USD",
49
+ items: [],
50
+ },
51
+ idempotencyKey: "order-42",
52
+ },
53
+ });
54
+ ```
55
+
56
+ Path-bearing procedures use oRPC's detailed input shape:
57
+
58
+ - `params` for path values, such as `{ code }` or `{ id }`
59
+ - `body` for request payloads
60
+ - direct input fields for simple list filters, such as `vouchers.list({ limit: 20 })`
61
+
62
+ ## Webhook signatures
63
+
64
+ ```ts
65
+ import { verifyWebhook } from "@offerkit/sdk";
66
+
67
+ const valid = verifyWebhook(rawBody, request.headers.get("x-offerkit-signature")!, secret);
68
+
69
+ if (!valid) {
70
+ throw new Error("Invalid OfferKit webhook signature");
71
+ }
72
+ ```
73
+
74
+ `verifyWebhook` checks the `X-Offerkit-Signature` header using HMAC-SHA256 and rejects stale signatures by default after 300 seconds.
75
+
76
+ ## API keys
77
+
78
+ Mint an API key in the OfferKit dashboard at `/settings/api-keys`, then pass it as `apiKey` or set `OFFERKIT_API_KEY` in your runtime environment.
79
+
80
+ ## Links
81
+
82
+ - Repository: https://github.com/offerkit/offerkit
83
+ - Docs: https://github.com/offerkit/offerkit/tree/main/apps/web/content/docs
84
+ - License: MIT