@wordkey/sdk 1.0.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,6 @@
1
+ Copyright (c) 2026 Agostino Industries. All rights reserved.
2
+
3
+ This SDK may be used solely to integrate with the WordKey platform
4
+ (https://wordkey.app) under the terms of your WordKey partner or
5
+ merchant agreement. Redistribution or modification outside those
6
+ terms is not permitted.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @wordkey/sdk
2
+
3
+ Add the **Word?** button to your site in one afternoon. One word. Every door.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @wordkey/sdk
9
+ ```
10
+
11
+ ## 1. Add the button
12
+
13
+ ```jsx
14
+ import { WordKeyButton } from "@wordkey/sdk";
15
+
16
+ export function LoginPage() {
17
+ return (
18
+ <WordKeyButton
19
+ publishableKey="wk_pub_xxxxxxxxxxxx"
20
+ onSuccess={(user) => console.log("Authenticated:", user)}
21
+ onError={(err) => console.error(err)}
22
+ />
23
+ );
24
+ }
25
+ ```
26
+
27
+ ### Request profile fields (optional)
28
+
29
+ Ask for autofill data the user keeps on their device. After the word is
30
+ verified, WordKey opens a small first-party consent window on
31
+ `app.wordkey.app` (a full-page redirect if the popup is blocked) where the
32
+ user sees exactly what your site will receive, fills in anything missing, and
33
+ approves. The granted values are then handed to your page — directly, never
34
+ through WordKey's servers. Approval is remembered per site, so repeat visits
35
+ skip straight through.
36
+
37
+ ```jsx
38
+ <WordKeyButton
39
+ publishableKey="wk_pub_xxxx"
40
+ requestedFields={[
41
+ "name",
42
+ "email",
43
+ "shipping_address",
44
+ { key: "height", label: "Height", type: "text", required: true },
45
+ ]}
46
+ onSuccess={(user) => {
47
+ // user.profile?.name, user.profile?.email,
48
+ // user.profile?.shippingAddress, user.profile?.custom?.height
49
+ // user.profile is undefined if the user declined to share.
50
+ }}
51
+ />
52
+ ```
53
+
54
+ Standard fields: `name`, `email`, `phone`, `shipping_address`. Custom fields are
55
+ `{ key, label, type: "text" | "date" | "number" | "select", required?, options? }`.
56
+ Fields the user hasn't stored are offered as inline inputs in the consent
57
+ window, with a "save for next time" option.
58
+
59
+ Because the consent window is a top-level first-party page (not a third-party
60
+ iframe), the flow works in Safari and Chrome even with third-party storage
61
+ partitioning and cookie blocking fully enabled. If the popup is blocked, the
62
+ SDK automatically falls back to a full-page redirect and resumes your
63
+ `onSuccess` when the user returns — no extra integration work.
64
+
65
+ ## 2. Verify server-side
66
+
67
+ ```ts
68
+ import { WordKey } from "@wordkey/sdk/server";
69
+
70
+ const wk = new WordKey({ secretKey: process.env.WORDKEY_SECRET_KEY! });
71
+
72
+ export async function POST(req: Request) {
73
+ const { token } = await req.json();
74
+ const user = await wk.verify(token);
75
+ // user.id — permanent unique id for this WordKey user
76
+ // user.isNewUser — true if this is their first authentication
77
+ }
78
+ ```
79
+
80
+ ## Webhooks
81
+
82
+ WordKey signs webhook deliveries with your secret key (HMAC-SHA256) in the
83
+ `X-WordKey-Signature` header.
84
+
85
+ ```ts
86
+ const ok = await wk.verifyWebhook(rawBody, req.headers.get("x-wordkey-signature")!);
87
+ ```
88
+
89
+ Event types: `auth.success`, `auth.failed`, `user.word_changed`, `user.disconnected`.
90
+
91
+ ## Server API
92
+
93
+ ```ts
94
+ wk.verify(token) // → WordKeyUser
95
+ wk.userExists(userId) // → boolean
96
+ wk.getUserEvents(userId) // → AuthEvent[]
97
+ wk.verifyWebhook(body, sig) // → boolean
98
+ ```
99
+
100
+ ## Testing against a local protocol host
101
+
102
+ Both `WordKeyButton` and `WordKey` accept an `apiUrl` to point at a non-production
103
+ host (e.g. `http://localhost:3001`).
@@ -0,0 +1,13 @@
1
+ // src/types.ts
2
+ var FIELD_LABELS = {
3
+ name: "Full name",
4
+ email: "Email address",
5
+ phone: "Phone number",
6
+ shipping_address: "Shipping address"
7
+ };
8
+ var DEFAULT_API_URL = "https://app.wordkey.app";
9
+
10
+ export {
11
+ FIELD_LABELS,
12
+ DEFAULT_API_URL
13
+ };
@@ -0,0 +1,19 @@
1
+ import * as react from 'react';
2
+ import { W as WordKeyUser, a as WordKeyError, R as RequestedField } from './types-Be6QFOjD.mjs';
3
+ export { A as Address, b as AuthEvent, C as CustomField, P as ProfileField, c as WordKeyProfile } from './types-Be6QFOjD.mjs';
4
+
5
+ interface WordKeyButtonProps {
6
+ publishableKey: string;
7
+ onSuccess: (user: WordKeyUser) => void;
8
+ onError?: (error: WordKeyError) => void;
9
+ theme?: "dark" | "light" | "auto";
10
+ size?: "sm" | "md" | "lg";
11
+ label?: string;
12
+ /** Profile fields to request. Standard names or custom field descriptors. */
13
+ requestedFields?: RequestedField[];
14
+ /** Override the protocol host (defaults to app.wordkey.app). */
15
+ apiUrl?: string;
16
+ }
17
+ declare function WordKeyButton({ publishableKey, onSuccess, onError, size, label, requestedFields, apiUrl, }: WordKeyButtonProps): react.JSX.Element;
18
+
19
+ export { RequestedField, WordKeyButton, type WordKeyButtonProps, WordKeyError, WordKeyUser };
@@ -0,0 +1,19 @@
1
+ import * as react from 'react';
2
+ import { W as WordKeyUser, a as WordKeyError, R as RequestedField } from './types-Be6QFOjD.js';
3
+ export { A as Address, b as AuthEvent, C as CustomField, P as ProfileField, c as WordKeyProfile } from './types-Be6QFOjD.js';
4
+
5
+ interface WordKeyButtonProps {
6
+ publishableKey: string;
7
+ onSuccess: (user: WordKeyUser) => void;
8
+ onError?: (error: WordKeyError) => void;
9
+ theme?: "dark" | "light" | "auto";
10
+ size?: "sm" | "md" | "lg";
11
+ label?: string;
12
+ /** Profile fields to request. Standard names or custom field descriptors. */
13
+ requestedFields?: RequestedField[];
14
+ /** Override the protocol host (defaults to app.wordkey.app). */
15
+ apiUrl?: string;
16
+ }
17
+ declare function WordKeyButton({ publishableKey, onSuccess, onError, size, label, requestedFields, apiUrl, }: WordKeyButtonProps): react.JSX.Element;
18
+
19
+ export { RequestedField, WordKeyButton, type WordKeyButtonProps, WordKeyError, WordKeyUser };