From 7c6e5fcc418490690a52de4dc698dd29a76de74b Mon Sep 17 00:00:00 2001 From: Ola Adebayo Date: Sat, 28 Mar 2026 22:30:17 +0000 Subject: [PATCH] fix: export REPError and document all getSecure() throw conditions REPError was not exported, making instanceof checks impossible for consumers. Documents all four throw cases including key-not-found, with a complete try/catch example in the SDK reference. --- docs/src/content/docs/reference/sdk.mdx | 19 +++++++++++++++++-- sdk/src/index.ts | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/src/content/docs/reference/sdk.mdx b/docs/src/content/docs/reference/sdk.mdx index fe99058..4c64ad8 100644 --- a/docs/src/content/docs/reference/sdk.mdx +++ b/docs/src/content/docs/reference/sdk.mdx @@ -48,10 +48,25 @@ function getSecure(key: string): Promise; **Returns:** `Promise` — the decrypted value. -**Throws:** `REPError` if the session key endpoint is unreachable, the key has expired, or decryption fails. +**Throws:** `REPError` in the following cases: +- The requested key does not exist in the sensitive payload +- The session key endpoint is unreachable or returns a non-2xx status +- The session key has expired (30s TTL) +- Decryption fails (corrupted payload or mismatched key) + +Always wrap `getSecure()` in a try/catch: ```typescript -const key = await rep.getSecure('ANALYTICS_KEY'); +import { rep, REPError } from '@rep-protocol/sdk'; + +try { + const analyticsKey = await rep.getSecure('ANALYTICS_KEY'); +} catch (err) { + if (err instanceof REPError) { + // Key not found, endpoint unreachable, or decryption failed. + console.error(err.message); + } +} ```