@hnnp/sdk 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.
Files changed (2) hide show
  1. package/README.md +226 -0
  2. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # HNNP Node.js SDK
2
+
3
+ This directory contains the official Node.js SDK for interacting with the HNNP Cloud backend.
4
+ It implements REST API wrappers and webhook verification logic exactly as defined in the protocol specification.
5
+
6
+ All SDK behavior MUST follow: protocol/spec.md
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ - Typed API client (TypeScript)
13
+ - REST methods for orgs, sessions lifecycle, receivers, presence, billing, incidents
14
+ - Webhook signature verification
15
+ - Pagination helpers
16
+ - Error handling & retry wrappers
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ npm install @hnnp/sdk
23
+
24
+ ---
25
+
26
+ ## Usage Example
27
+
28
+ import { HnnpClient } from "@hnnp/sdk";
29
+
30
+ const client = new HnnpClient({
31
+ apiKey: "YOUR_API_KEY",
32
+ baseUrl: "https://api.hnnp.example"
33
+ });
34
+
35
+ const events = await client.listPresenceEvents({ orgId: "org_123" });
36
+
37
+ await client.createLink({
38
+ orgId: "org_123",
39
+ userRef: "emp_45"
40
+ });
41
+
42
+ await client.linkPresenceSession({
43
+ presenceSessionId: "psess_001",
44
+ userRef: "emp_45",
45
+ orgId: "org_123"
46
+ });
47
+
48
+ ---
49
+
50
+ ## Webhook Verification
51
+
52
+ import { verifyHnnpWebhook } from "@hnnp/sdk";
53
+
54
+ const isValid = verifyHnnpWebhook({
55
+ rawBody,
56
+ signature: headers["x-hnnp-signature"],
57
+ timestamp: headers["x-hnnp-timestamp"],
58
+ webhookSecret: process.env.WEBHOOK_SECRET
59
+ });
60
+
61
+ ---
62
+
63
+ ## Webhook Consumer Example (Express)
64
+
65
+ You can use the SDK helper inside a minimal Express server. An example is provided in:
66
+
67
+ - `examples/webhook-consumer.ts`
68
+
69
+ Outline:
70
+
71
+ ```ts
72
+ import express from "express";
73
+ import { verifyHnnpWebhook } from "@hnnp/sdk";
74
+
75
+ const app = express();
76
+ app.use(express.json({ verify: (req, _res, buf) => { req.rawBody = Buffer.from(buf); } }));
77
+
78
+ app.post("/hnnp/webhook", (req, res) => {
79
+ const isValid = verifyHnnpWebhook({
80
+ rawBody: req.rawBody,
81
+ signature: req.header("X-HNNP-Signature"),
82
+ timestamp: req.header("X-HNNP-Timestamp"),
83
+ webhookSecret: process.env.WEBHOOK_SECRET
84
+ });
85
+
86
+ if (!isValid) return res.status(400).json({ error: "invalid_webhook_signature" });
87
+
88
+ console.log("Received HNNP webhook", req.body);
89
+ return res.status(200).json({ status: "ok" });
90
+ });
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Available Methods
96
+
97
+ Receivers
98
+ - listReceivers({ orgId })
99
+ - createReceiver({ orgId, receiverId, authMode, ... })
100
+ - updateReceiver({ orgId, receiverId, ... })
101
+
102
+ Presence (public)
103
+ - listPresenceEvents({ orgId, ... })
104
+ - listPresenceSessions({ orgId, ... })
105
+
106
+ Links (public)
107
+ - createLink({ orgId, userRef, deviceId? })
108
+ - activateLink(id)
109
+ - revokeLink(id)
110
+ - listLinks({ orgId, userRef? })
111
+ - linkPresenceSession({ orgId, presenceSessionId, userRef })
112
+ - unlink(id)
113
+
114
+ Org console
115
+ - listOrgs()
116
+ - getOrg({ orgId })
117
+ - getOrgSettings({ orgId })
118
+ - updateOrgSettings({ orgId, settings })
119
+ - getOrgConfig({ orgId })
120
+ - updateOrgConfig({ orgId, config })
121
+ - getOrgMetricsRealtime({ orgId, ... })
122
+ - listOrgUsers({ orgId })
123
+
124
+ Receivers health (org console)
125
+ - listReceiversAdmin()
126
+ - getReceiver({ receiverId })
127
+ - updateReceiverAdmin({ receiverId, payload })
128
+ - getReceiverStatus({ receiverId })
129
+ - getReceiverHealth({ receiverId })
130
+
131
+ Sessions lifecycle (org console)
132
+ - listOrgSessions()
133
+ - getOrgSessionsSummary()
134
+ - createOrgSession(payload)
135
+ - updateOrgSession({ sessionId, payload })
136
+ - deleteOrgSession({ sessionId })
137
+ - finalizeOrgSession({ sessionId })
138
+
139
+ Attendance + presence (org console)
140
+ - getPresenceLive()
141
+ - getPresenceLogs()
142
+ - getPresenceEvents()
143
+ - listLocations()
144
+ - listGroups()
145
+ - createGroup(payload)
146
+ - updateGroup({ groupId, payload })
147
+ - deleteGroup({ groupId })
148
+ - getAttendance()
149
+ - exportAttendanceCsv()
150
+
151
+ Billing
152
+ - getBillingSummary()
153
+ - listInvoices()
154
+ - getInvoicePdf({ invoiceId })
155
+
156
+ Incidents + safety
157
+ - listIncidents()
158
+ - getIncident({ incidentId })
159
+ - getIncidentRollcall({ incidentId })
160
+ - getSafetyStatus()
161
+ - getSafetySummary()
162
+
163
+ ---
164
+
165
+ ## File Structure
166
+
167
+ src/
168
+ index.ts
169
+ client.ts
170
+ http.ts
171
+ webhook.ts
172
+ types.ts
173
+
174
+ ---
175
+
176
+ ## Environment Variables
177
+
178
+ WEBHOOK_SECRET=your_org_webhook_secret
179
+
180
+ ---
181
+
182
+ ## Notes
183
+
184
+ - Webhook signing follows the HMAC rules in Section 10.3 of the v2 spec.
185
+ - All network calls use HTTPS.
186
+ - SDK MUST NOT alter any packet formats or cryptographic logic.
187
+ - Some endpoints require an org admin JWT (org console auth) instead of an API key.
188
+
189
+ Typed models are exported from `@hnnp/sdk` (see `types.ts`).
190
+
191
+ ---
192
+
193
+ ## Pagination helpers
194
+
195
+ ```ts
196
+ for await (const evt of client.iteratePresenceEvents({ orgId: "org_123" })) {
197
+ console.log(evt.id);
198
+ }
199
+
200
+ for await (const sess of client.iteratePresenceSessions({ orgId: "org_123" })) {
201
+ console.log(sess.session_id);
202
+ }
203
+
204
+ for await (const rcv of client.iterateReceivers({ orgId: "org_123" })) {
205
+ console.log(rcv.receiver_id);
206
+ }
207
+ ```
208
+
209
+ ---
210
+
211
+ ## Rate limiting
212
+
213
+ The client retries on `5xx` and `429` responses with exponential backoff.
214
+ If `Retry-After` is provided, it is respected (up to 30s).
215
+
216
+ ---
217
+
218
+ ## Testing
219
+
220
+ npm test
221
+
222
+ ---
223
+
224
+ ## Reference
225
+
226
+ Full protocol spec: ../../protocol/spec.md
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@hnnp/sdk",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "HNNP Node.js SDK",
6
+ "license": "UNLICENSED",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/hawkeye17-warex/hnnp"
10
+ },
11
+ "keywords": [
12
+ "nearid",
13
+ "hnnp",
14
+ "presence",
15
+ "ble",
16
+ "security",
17
+ "sdk"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "test": "vitest run"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.5.0",
31
+ "vitest": "^2.1.0"
32
+ },
33
+ "dependencies": {
34
+ "hnnp-monorepo": "file:../.."
35
+ }
36
+ }