@heedeo/sdk 0.1.0-pilot.4 → 0.1.0-pilot.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 +6 -4
- package/dist/browser.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -2
- package/dist/shared.d.ts +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,12 @@ Use HTTPS for deployed testing, including Safari's secure-cookie behavior. Revie
|
|
|
108
108
|
|
|
109
109
|
Server options: `secretKey`, required `clientIp(request)`, optional `path` (default `/hd`), `timeoutMs` (default 3000 total across event retries), `baseUrl` (default `https://app.heedeo.com`), and `fetch` for testing. Custom origins require HTTPS, except localhost. Browser options: `publishableKey`, matching `path`, and `timeoutMs` (default 3000 total for script loading and identification).
|
|
110
110
|
|
|
111
|
-
Configuration mistakes throw when you construct the client, so missing keys are caught at setup. Operational failures return `{ data: null, error: { code, message, status? } }
|
|
111
|
+
Configuration mistakes throw when you construct the client, so missing keys are caught at setup. Operational failures return `{ data: null, error: { code, message, status? } }`; checking `error` narrows `data` to the success value. `code` is a `HeedeoErrorCode`, so a `switch` over it is checked by TypeScript:
|
|
112
|
+
|
|
113
|
+
- Server: `missing_token`, `missing_client_ip`, `invalid_key`, `api_error`, `invalid_response`, `network_error`, `timeout_or_aborted`, `configuration_error`.
|
|
114
|
+
- Browser: `browser_required`, `timeout`, `invalid_response`, `identification_unavailable`.
|
|
115
|
+
|
|
116
|
+
Neither entry point logs credentials, request bodies or upstream error bodies.
|
|
112
117
|
|
|
113
118
|
Browser timeouts stop waiting, but cannot cancel an already-running collector call in this pilot version. Always pass the returned token explicitly; never fall back to an older cookie token after a timeout. Browser results are not security decisions. Secret keys and event signals stay on your server.
|
|
114
119
|
|
|
@@ -116,11 +121,8 @@ Browser timeouts stop waiting, but cannot cancel an already-running collector ca
|
|
|
116
121
|
|
|
117
122
|
This package is an ESM package (use `import`) for Node.js servers. The browser entry is separate and imports no server code. The server entry supports Node.js and Cloudflare Workers with `nodejs_compat`. Other edge runtimes have not been verified. No change to your hosting, database or sign-in provider is required. React hooks, server-action adapters, Express-specific wrappers and an automatic installer are not included in this release.
|
|
118
123
|
|
|
119
|
-
|
|
120
124
|
## Cloudflare Workers
|
|
121
125
|
|
|
122
|
-
Cloudflare Workers is supported by the npm release.
|
|
123
|
-
|
|
124
126
|
Enable `nodejs_compat` in Wrangler. Create the client inside the request handler so keys come from Worker secrets:
|
|
125
127
|
|
|
126
128
|
```ts
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Identification, type Result } from "./shared.js";
|
|
2
|
-
export type { HeedeoError, Identification, Result } from "./shared.js";
|
|
2
|
+
export type { HeedeoError, HeedeoErrorCode, Identification, Result } from "./shared.js";
|
|
3
3
|
/** Create once per app. Calling this function alone makes no identification request. */
|
|
4
4
|
export declare function createHeedeo(options: {
|
|
5
5
|
publishableKey: string | undefined;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type EventData } from "./response.js";
|
|
2
2
|
export type { EventData } from "./response.js";
|
|
3
3
|
import { type Result } from "./shared.js";
|
|
4
|
-
export type { HeedeoError, Result } from "./shared.js";
|
|
4
|
+
export type { HeedeoError, HeedeoErrorCode, Result } from "./shared.js";
|
|
5
5
|
export type HeedeoOptions = {
|
|
6
6
|
secretKey: string | undefined;
|
|
7
7
|
/** Resolve only an IP supplied by your trusted hosting layer. Used for BOTH requests. */
|
package/dist/server.js
CHANGED
|
@@ -27,6 +27,8 @@ const EVENT_HEADERS = [
|
|
|
27
27
|
"sec-ch-ua-platform",
|
|
28
28
|
"sec-ch-ua-mobile",
|
|
29
29
|
];
|
|
30
|
+
class PayloadTooLarge extends Error {
|
|
31
|
+
}
|
|
30
32
|
async function limitedBody(request, signal) {
|
|
31
33
|
const reader = request.body?.getReader();
|
|
32
34
|
if (!reader)
|
|
@@ -46,7 +48,7 @@ async function limitedBody(request, signal) {
|
|
|
46
48
|
break;
|
|
47
49
|
size += value.byteLength;
|
|
48
50
|
if (size > 65536)
|
|
49
|
-
throw new
|
|
51
|
+
throw new PayloadTooLarge();
|
|
50
52
|
chunks.push(value);
|
|
51
53
|
}
|
|
52
54
|
const body = new Uint8Array(size);
|
|
@@ -205,7 +207,7 @@ export class Heedeo {
|
|
|
205
207
|
return new Response(response.body, { status: response.status, headers: outgoing });
|
|
206
208
|
}
|
|
207
209
|
catch (error) {
|
|
208
|
-
if (error instanceof
|
|
210
|
+
if (error instanceof PayloadTooLarge)
|
|
209
211
|
return new Response("Payload too large", { status: 413 });
|
|
210
212
|
return new Response("Heedeo is unavailable", {
|
|
211
213
|
status: 502,
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export type HeedeoErrorCode = "missing_token" | "missing_client_ip" | "invalid_key" | "api_error" | "invalid_response" | "network_error" | "timeout_or_aborted" | "configuration_error" | "browser_required" | "timeout" | "identification_unavailable";
|
|
1
2
|
export type HeedeoError = {
|
|
2
|
-
code:
|
|
3
|
+
code: HeedeoErrorCode;
|
|
3
4
|
message: string;
|
|
4
5
|
status?: number;
|
|
5
6
|
};
|
|
@@ -10,7 +11,7 @@ export type Result<T> = {
|
|
|
10
11
|
data: null;
|
|
11
12
|
error: HeedeoError;
|
|
12
13
|
};
|
|
13
|
-
export declare function failure(code:
|
|
14
|
+
export declare function failure(code: HeedeoErrorCode, message: string, status?: number): Result<never>;
|
|
14
15
|
export declare function timeout(value: number): number;
|
|
15
16
|
export declare function pathPrefix(value: string): string;
|
|
16
17
|
export type Identification = {
|