@checkbox-site/node 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Checkbox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ # Checkbox Node.js SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Automatic-renewal-law compliance (ROSCA, California Bus. & Prof. Code § 17600, New York GBL § 527-a and ~26 other state
4
+ laws) for subscription businesses, as an API. Zero runtime dependencies (global `fetch`; Node 20+, Bun, Deno, edge).
5
+ Free to use.
6
+
7
+ > **Install.** `npm install @checkbox-site/node` (Node 20+). Never install the unscoped npm package `checkbox`: it is an
8
+ > unrelated project.
9
+
10
+ ## Quickstart
11
+
12
+ ```ts
13
+ import Checkbox from '@checkbox-site/node';
14
+ const checkbox = new Checkbox(); // reads CHECKBOX_API_KEY, then CHECKBOX_SECRET_KEY (ck_test_… written by `checkbox init`)
15
+ const check = await checkbox.checks.stripeCheckoutSession({ params: sessionParams, merchant: { merchant_name: 'Acme', price: 19.99, interval: 'month' } });
16
+ console.log(check.verdict, check.next_action.message);
17
+ const params = check.verdict === 'fail' ? check.correction.corrected_params : sessionParams; // engine-verified fix
18
+ ```
19
+
20
+ No key yet? Connect the MCP server (`setup_checkbox`) or call `POST /v1/device/authorize`: one browser approval creates the account, writes
21
+ `CHECKBOX_SECRET_KEY=ck_test_…` to `.env.local` (the SDK reads it when `CHECKBOX_API_KEY` is not set) and installs the snippet. Test keys (`ck_test_…`) act on an isolated
22
+ sandbox and never need activation.
23
+
24
+ ## What you get
25
+
26
+ | | |
27
+ |---|---|
28
+ | Resources | `checkbox.<namespace>.<method>()` for every `/v1` operation: `sites`, `checks`, `plans`, `tasks`, `verifications`, `findings`, `fixes`, `scans`, `evaluations`, `evidence`, `certificates`, `noticeSettings`, `lawUpdates`, `testRuns`, `testCredentials`, `stripeCheckoutConfigs`, `disclosures`, `consents`, `elements`, `domainVerifications`, `setupSessions`, `device`, `webhookEndpoints`, `events`, `account` |
29
+ | Types | Every request, response and webhook event is typed, generated from `openapi/checkbox.v1.json` (`import type { Site, Finding, WebhookEvent } from '@checkbox-site/node'`). JSDoc on every method and field |
30
+ | Pagination | `for await (const f of checkbox.findings.list({ site }))` walks every page; `.autoPagingToArray({ limit })`, `.autoPagingEach(fn)` |
31
+ | Retries | Network errors, 409 `idempotency_key_in_use`, 429 (honours `Retry-After`) and 5xx are retried with exponential backoff and jitter (`maxNetworkRetries`, default 2) |
32
+ | Idempotency | Every POST that changes something gets an `Idempotency-Key` automatically, reused across retries; pass your own with `{ idempotencyKey }` |
33
+ | Versioning | Sends `Checkbox-Version: 2026-10-30` (the version the SDK was generated for); override with `new Checkbox(key, { apiVersion })` or per request |
34
+ | Mode | `checkbox.mode` is `'test'` or `'live'` from the key prefix (`ck_test_` / `ck_live_` / `rk_…` / legacy `sk_live_`) |
35
+ | Errors | `CheckboxInvalidRequestError`, `CheckboxAuthenticationError`, `CheckboxPermissionError`, `CheckboxRateLimitError`, `CheckboxIdempotencyError`, `CheckboxAPIError`, `CheckboxConnectionError` (all `CheckboxError`), each with a stable `code`, `param`, `statusCode`, `requestId`, `docUrl` and `nextAction` |
36
+ | Webhooks | `checkbox.webhooks.constructEvent(rawBody, signatureHeader, secret)` verifies `Checkbox-Signature` and returns a typed `WebhookEvent`; `constructEventAsync` for edge runtimes |
37
+ | Agents / MCP | `checkbox.call('verifyTask', { task, wait: 30 })`: any operation by its operationId with flat arguments (the operation_id of every next_action) |
38
+
39
+ ## Usage
40
+
41
+ ```ts
42
+ import Checkbox, { CheckboxError } from '@checkbox-site/node';
43
+
44
+ const checkbox = new Checkbox(process.env.CHECKBOX_API_KEY, {
45
+ maxNetworkRetries: 2, // default
46
+ timeout: 80_000, // ms per attempt
47
+ appInfo: { name: 'my-app', version: '1.0.0' },
48
+ });
49
+
50
+ // Register a site (idempotent per key) and read its compliance plan: ordered tasks with the law, the exact change and
51
+ // how to verify it. Every plan, task and error carries next_action for an AI agent.
52
+ const site = await checkbox.sites.create({ url: 'https://acme.example' }, { idempotencyKey: 'site:acme.example' });
53
+ const plan = await checkbox.plans.retrieve(site.id);
54
+ for (const task of plan.tasks) console.log(task.id, task.title, task.requirement.citations[0]?.citation);
55
+
56
+ // Apply a task's change, then verify it (long-poll up to 30 s).
57
+ const first = plan.tasks[0];
58
+ if (first) {
59
+ const verification = await checkbox.tasks.verify(first.id, { wait: 30 });
60
+ console.log(verification.status, verification.next_action);
61
+ }
62
+
63
+ // Every failing finding across pages.
64
+ for await (const finding of checkbox.findings.list({ site: site.id, status: 'fail' })) {
65
+ console.log(finding.check_id, finding.requirements[0]?.citation);
66
+ }
67
+
68
+ // Errors: branch on the stable code; nextAction says what to do.
69
+ try {
70
+ await checkbox.certificates.create(site.id);
71
+ } catch (err) {
72
+ if (!(err instanceof CheckboxError)) throw err;
73
+ // resource_conflict: not eligible yet (verify the domain, stay compliant for 7 days);
74
+ // account_not_activated: a live key before any domain is verified.
75
+ console.log(err.code, err.message, err.nextAction);
76
+ }
77
+ ```
78
+
79
+ Per-request options (last argument of every method): `{ idempotencyKey, apiVersion, apiKey, timeout, maxNetworkRetries,
80
+ headers, signal }`. Response metadata: `getLastResponse(obj)` → `{ statusCode, requestId, idempotentReplayed, headers }`.
81
+ Endpoints newer than your SDK version: `checkbox.request('POST', '/v1/…', { query, body })` or Stripe-style
82
+ `checkbox.rawRequest(method, path, params)`.
83
+
84
+ ## Webhooks
85
+
86
+ ```ts
87
+ // Next.js App Router: app/api/webhooks/checkbox/route.ts
88
+ export async function POST(request: Request) {
89
+ const event = checkbox.webhooks.constructEvent(await request.text(), request.headers.get('checkbox-signature'), process.env.CHECKBOX_WEBHOOK_SECRET!);
90
+ if (event.type === 'plan.updated') console.log(event.data?.object.status);
91
+ return Response.json({ received: true });
92
+ }
93
+ ```
94
+
95
+ Pass the **raw** body (Express: `express.raw({ type: 'application/json' })`). Signatures older than 5 minutes are
96
+ rejected (`tolerance` argument). Several `v1=` entries are accepted, so rolling a secret never drops events.
97
+
98
+ ## Examples
99
+
100
+ [`examples/`](examples/): preflight a Stripe Checkout Session in a
101
+ [Next.js route](examples/nextjs/app/api/checkout/route.ts) or an [Express server](examples/express-checkout.mjs) (shared
102
+ logic in [compliant-checkout.ts](examples/compliant-checkout.ts)), [register a site](examples/register-site.ts), and
103
+ [verify a webhook](examples/nextjs/app/api/webhooks/checkbox/route.ts). The TypeScript examples are typechecked and run
104
+ against the real API in Checkbox's test suite; the quickstart and
105
+ usage snippets above are [quickstart.ts](examples/quickstart.ts) and [usage.ts](examples/usage.ts).
106
+
107
+ ## Development
108
+
109
+ - `npm install` at the repository root, then `npm run build --workspace node` (plain ESM + `.d.ts` in `dist/`) and
110
+ `npm run typecheck:examples`.
111
+ - Types and resource methods in `src/generated/` are generated from [`openapi/checkbox.v1.json`](../openapi/checkbox.v1.json)
112
+ in Checkbox's main codebase and mirrored here with each release; see [CONTRIBUTING.md](../CONTRIBUTING.md).
113
+ - Releases: [RELEASING.md](../RELEASING.md).