@omnara/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.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @omnara/sdk
2
+
3
+ TypeScript SDK for the [Omnara](https://omnara.com) API.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @omnara/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createOmnaraClient, bearerToken } from '@omnara/sdk'
15
+
16
+ const client = createOmnaraClient({
17
+ baseUrl: 'https://api.omnara.com',
18
+ auth: bearerToken('your-api-key'),
19
+ })
20
+ ```
21
+
22
+ ### Entry points
23
+
24
+ - `@omnara/sdk` — Node client, auth, and event streaming
25
+ - `@omnara/sdk/browser` — browser-safe client
26
+ - `@omnara/sdk/tanstack` — TanStack Query hooks (requires the optional `@tanstack/react-query` peer dependency)
27
+ - `@omnara/sdk/zod` — Zod schemas for all API types
28
+
29
+ Requires Node.js 22 or later.
30
+
31
+ ## Documentation
32
+
33
+ See the [Omnara docs](https://docs.omnara.com) and the [GitHub repository](https://github.com/omnara-ai/omnara).
34
+
35
+ ## License
36
+
37
+ Apache-2.0
@@ -0,0 +1,6 @@
1
+ interface AuthStrategy {
2
+ authenticate(request: Request): void | Promise<void>;
3
+ }
4
+ declare function bearerToken(token: string | (() => string | Promise<string>)): AuthStrategy;
5
+
6
+ export { type AuthStrategy as A, bearerToken as b };
@@ -0,0 +1,32 @@
1
+ import { A as AuthStrategy } from './auth-CnOxLjlL.js';
2
+
3
+ interface DeviceAuthPending {
4
+ clientName: string;
5
+ tokenName: string;
6
+ createdAt: string;
7
+ expiresAt: string;
8
+ }
9
+ interface AuthConnector {
10
+ slug: string;
11
+ kind: string;
12
+ displayName: string;
13
+ loginURL: string;
14
+ }
15
+ interface WebConfig {
16
+ billingURL?: string;
17
+ }
18
+ declare function getLastUsedAuthMethod(): string | undefined;
19
+ declare function cookieCsrf(): AuthStrategy;
20
+ declare function listAuthConnectors(): Promise<AuthConnector[]>;
21
+ declare function fetchWebConfig(): Promise<WebConfig>;
22
+ declare function pendingDeviceAuth(userCode: string): Promise<DeviceAuthPending>;
23
+ declare function approveDeviceAuth(userCode: string): Promise<void>;
24
+ declare function denyDeviceAuth(userCode: string): Promise<void>;
25
+ declare function sessionLogin(email: string, password: string): Promise<void>;
26
+ declare function sessionLogout(): Promise<void>;
27
+ declare function requestSignup(email: string): Promise<void>;
28
+ declare function completeEmailVerification(token: string, password: string, displayName: string): Promise<void>;
29
+ declare function requestPasswordReset(email: string): Promise<void>;
30
+ declare function completePasswordReset(token: string, password: string): Promise<void>;
31
+
32
+ export { type AuthConnector, type DeviceAuthPending, type WebConfig, approveDeviceAuth, completeEmailVerification, completePasswordReset, cookieCsrf, denyDeviceAuth, fetchWebConfig, getLastUsedAuthMethod, listAuthConnectors, pendingDeviceAuth, requestPasswordReset, requestSignup, sessionLogin, sessionLogout };
@@ -0,0 +1,121 @@
1
+ import {
2
+ ApiError
3
+ } from "./chunk-TMPF6DRL.js";
4
+ import "./chunk-PZ5AY32C.js";
5
+
6
+ // src/browser.ts
7
+ var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
8
+ function cookieValue(name) {
9
+ const prefix = `${name}=`;
10
+ const raw = document.cookie.split(";").map((cookie) => cookie.trim()).find((cookie) => cookie.startsWith(prefix))?.slice(prefix.length);
11
+ if (!raw) return void 0;
12
+ try {
13
+ return decodeURIComponent(raw);
14
+ } catch {
15
+ return void 0;
16
+ }
17
+ }
18
+ function csrfToken() {
19
+ return cookieValue("__Host-omnara_csrf") ?? cookieValue("omnara_csrf");
20
+ }
21
+ function getLastUsedAuthMethod() {
22
+ return cookieValue("omnara_last_login_method");
23
+ }
24
+ function cookieCsrf() {
25
+ return {
26
+ authenticate(request) {
27
+ if (!SAFE_METHODS.has(request.method.toUpperCase())) {
28
+ const token = csrfToken();
29
+ if (token) request.headers.set("X-Omnara-Csrf", token);
30
+ }
31
+ }
32
+ };
33
+ }
34
+ async function authJSON(path, body) {
35
+ const headers = {};
36
+ if (body !== void 0) {
37
+ headers["Content-Type"] = "application/json";
38
+ }
39
+ const token = csrfToken();
40
+ if (token) headers["X-Omnara-Csrf"] = token;
41
+ const response = await fetch(path, {
42
+ method: "POST",
43
+ credentials: "include",
44
+ headers,
45
+ body: body === void 0 ? void 0 : JSON.stringify(body)
46
+ });
47
+ if (!response.ok) throw await ApiError.fromResponse(response);
48
+ }
49
+ async function listAuthConnectors() {
50
+ const response = await fetch("/api/auth/connectors", { credentials: "include" });
51
+ if (!response.ok) throw await ApiError.fromResponse(response);
52
+ const data = await response.json();
53
+ return data.connectors.map((connector) => ({
54
+ slug: connector.slug,
55
+ kind: connector.kind,
56
+ displayName: connector.display_name,
57
+ loginURL: connector.login_url
58
+ }));
59
+ }
60
+ async function fetchWebConfig() {
61
+ const response = await fetch("/api/web-config", { credentials: "include" });
62
+ if (!response.ok) throw await ApiError.fromResponse(response);
63
+ const data = await response.json();
64
+ return { billingURL: data.billing_url };
65
+ }
66
+ async function pendingDeviceAuth(userCode) {
67
+ const params = new URLSearchParams({ user_code: userCode });
68
+ const response = await fetch(`/api/auth/device/pending?${params}`, { credentials: "include" });
69
+ if (!response.ok) throw await ApiError.fromResponse(response);
70
+ const data = await response.json();
71
+ return {
72
+ clientName: data.client_name,
73
+ tokenName: data.token_name,
74
+ createdAt: data.created_at,
75
+ expiresAt: data.expires_at
76
+ };
77
+ }
78
+ async function approveDeviceAuth(userCode) {
79
+ await authJSON("/api/auth/device/approve", { user_code: userCode });
80
+ }
81
+ async function denyDeviceAuth(userCode) {
82
+ await authJSON("/api/auth/device/deny", { user_code: userCode });
83
+ }
84
+ async function sessionLogin(email, password) {
85
+ await authJSON("/api/auth/login", { email, password });
86
+ }
87
+ async function sessionLogout() {
88
+ await authJSON("/api/auth/logout");
89
+ }
90
+ async function requestSignup(email) {
91
+ await authJSON("/api/auth/signup", { email });
92
+ }
93
+ async function completeEmailVerification(token, password, displayName) {
94
+ await authJSON("/api/auth/email/verify", {
95
+ token,
96
+ password,
97
+ display_name: displayName.trim() || void 0
98
+ });
99
+ }
100
+ async function requestPasswordReset(email) {
101
+ await authJSON("/api/auth/password/reset/request", { email });
102
+ }
103
+ async function completePasswordReset(token, password) {
104
+ await authJSON("/api/auth/password/reset", { token, password });
105
+ }
106
+ export {
107
+ approveDeviceAuth,
108
+ completeEmailVerification,
109
+ completePasswordReset,
110
+ cookieCsrf,
111
+ denyDeviceAuth,
112
+ fetchWebConfig,
113
+ getLastUsedAuthMethod,
114
+ listAuthConnectors,
115
+ pendingDeviceAuth,
116
+ requestPasswordReset,
117
+ requestSignup,
118
+ sessionLogin,
119
+ sessionLogout
120
+ };
121
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/browser.ts"],"sourcesContent":["import type { AuthStrategy } from './auth'\nimport { ApiError } from './errors'\n\nconst SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS'])\n\nexport interface DeviceAuthPending {\n clientName: string\n tokenName: string\n createdAt: string\n expiresAt: string\n}\n\nexport interface AuthConnector {\n slug: string\n kind: string\n displayName: string\n loginURL: string\n}\n\nexport interface WebConfig {\n billingURL?: string\n}\n\nfunction cookieValue(name: string): string | undefined {\n const prefix = `${name}=`\n const raw = document.cookie\n .split(';')\n .map((cookie) => cookie.trim())\n .find((cookie) => cookie.startsWith(prefix))\n ?.slice(prefix.length)\n if (!raw) return undefined\n try {\n return decodeURIComponent(raw)\n } catch {\n return undefined\n }\n}\n\nfunction csrfToken(): string | undefined {\n return cookieValue('__Host-omnara_csrf') ?? cookieValue('omnara_csrf')\n}\n\nexport function getLastUsedAuthMethod(): string | undefined {\n return cookieValue('omnara_last_login_method')\n}\n\nexport function cookieCsrf(): AuthStrategy {\n return {\n authenticate(request) {\n if (!SAFE_METHODS.has(request.method.toUpperCase())) {\n const token = csrfToken()\n if (token) request.headers.set('X-Omnara-Csrf', token)\n }\n },\n }\n}\n\nasync function authJSON(path: string, body?: unknown): Promise<void> {\n const headers: Record<string, string> = {}\n if (body !== undefined) {\n headers['Content-Type'] = 'application/json'\n }\n const token = csrfToken()\n if (token) headers['X-Omnara-Csrf'] = token\n const response = await fetch(path, {\n method: 'POST',\n credentials: 'include',\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n })\n if (!response.ok) throw await ApiError.fromResponse(response)\n}\n\nexport async function listAuthConnectors(): Promise<AuthConnector[]> {\n const response = await fetch('/api/auth/connectors', { credentials: 'include' })\n if (!response.ok) throw await ApiError.fromResponse(response)\n const data = (await response.json()) as {\n connectors: {\n slug: string\n kind: string\n display_name: string\n login_url: string\n }[]\n }\n return data.connectors.map((connector) => ({\n slug: connector.slug,\n kind: connector.kind,\n displayName: connector.display_name,\n loginURL: connector.login_url,\n }))\n}\n\nexport async function fetchWebConfig(): Promise<WebConfig> {\n const response = await fetch('/api/web-config', { credentials: 'include' })\n if (!response.ok) throw await ApiError.fromResponse(response)\n const data = (await response.json()) as { billing_url?: string }\n return { billingURL: data.billing_url }\n}\n\nexport async function pendingDeviceAuth(userCode: string): Promise<DeviceAuthPending> {\n const params = new URLSearchParams({ user_code: userCode })\n const response = await fetch(`/api/auth/device/pending?${params}`, { credentials: 'include' })\n if (!response.ok) throw await ApiError.fromResponse(response)\n const data = (await response.json()) as {\n client_name: string\n token_name: string\n created_at: string\n expires_at: string\n }\n return {\n clientName: data.client_name,\n tokenName: data.token_name,\n createdAt: data.created_at,\n expiresAt: data.expires_at,\n }\n}\n\nexport async function approveDeviceAuth(userCode: string): Promise<void> {\n await authJSON('/api/auth/device/approve', { user_code: userCode })\n}\n\nexport async function denyDeviceAuth(userCode: string): Promise<void> {\n await authJSON('/api/auth/device/deny', { user_code: userCode })\n}\n\nexport async function sessionLogin(email: string, password: string): Promise<void> {\n await authJSON('/api/auth/login', { email, password })\n}\n\nexport async function sessionLogout(): Promise<void> {\n await authJSON('/api/auth/logout')\n}\n\nexport async function requestSignup(email: string): Promise<void> {\n await authJSON('/api/auth/signup', { email })\n}\n\nexport async function completeEmailVerification(\n token: string,\n password: string,\n displayName: string,\n): Promise<void> {\n await authJSON('/api/auth/email/verify', {\n token,\n password,\n display_name: displayName.trim() || undefined,\n })\n}\n\nexport async function requestPasswordReset(email: string): Promise<void> {\n await authJSON('/api/auth/password/reset/request', { email })\n}\n\nexport async function completePasswordReset(token: string, password: string): Promise<void> {\n await authJSON('/api/auth/password/reset', { token, password })\n}\n"],"mappings":";;;;;;AAGA,IAAM,eAAe,oBAAI,IAAI,CAAC,OAAO,QAAQ,SAAS,CAAC;AAoBvD,SAAS,YAAY,MAAkC;AACrD,QAAM,SAAS,GAAG,IAAI;AACtB,QAAM,MAAM,SAAS,OAClB,MAAM,GAAG,EACT,IAAI,CAAC,WAAW,OAAO,KAAK,CAAC,EAC7B,KAAK,CAAC,WAAW,OAAO,WAAW,MAAM,CAAC,GACzC,MAAM,OAAO,MAAM;AACvB,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI;AACF,WAAO,mBAAmB,GAAG;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAgC;AACvC,SAAO,YAAY,oBAAoB,KAAK,YAAY,aAAa;AACvE;AAEO,SAAS,wBAA4C;AAC1D,SAAO,YAAY,0BAA0B;AAC/C;AAEO,SAAS,aAA2B;AACzC,SAAO;AAAA,IACL,aAAa,SAAS;AACpB,UAAI,CAAC,aAAa,IAAI,QAAQ,OAAO,YAAY,CAAC,GAAG;AACnD,cAAM,QAAQ,UAAU;AACxB,YAAI,MAAO,SAAQ,QAAQ,IAAI,iBAAiB,KAAK;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAe,SAAS,MAAc,MAA+B;AACnE,QAAM,UAAkC,CAAC;AACzC,MAAI,SAAS,QAAW;AACtB,YAAQ,cAAc,IAAI;AAAA,EAC5B;AACA,QAAM,QAAQ,UAAU;AACxB,MAA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