@everystack/api 0.2.2 → 0.2.4
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/package.json +1 -1
- package/src/client/index.ts +23 -0
- package/src/handler/index.ts +3 -5
package/package.json
CHANGED
package/src/client/index.ts
CHANGED
|
@@ -76,6 +76,8 @@ export interface QueryBuilder {
|
|
|
76
76
|
|
|
77
77
|
export interface Client {
|
|
78
78
|
from(table: string): QueryBuilder;
|
|
79
|
+
/** Call a named RPC on the handler: POST {baseUrl}/rpc/{fn}. */
|
|
80
|
+
rpc<T = unknown>(fn: string, body?: unknown): Promise<ClientResponse<T>>;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
/**
|
|
@@ -89,6 +91,27 @@ export function createClient(options: ClientOptions): Client {
|
|
|
89
91
|
from(table: string): QueryBuilder {
|
|
90
92
|
return createQueryBuilder(options, table);
|
|
91
93
|
},
|
|
94
|
+
|
|
95
|
+
async rpc<T = unknown>(fn: string, body?: unknown): Promise<ClientResponse<T>> {
|
|
96
|
+
const url = `${options.baseUrl}/rpc/${encodeURIComponent(fn)}`;
|
|
97
|
+
const headers = await buildHeaders(options);
|
|
98
|
+
headers['Content-Type'] = 'application/json';
|
|
99
|
+
|
|
100
|
+
const { response, retried } = await fetchWithRetry(
|
|
101
|
+
url,
|
|
102
|
+
{ method: 'POST', headers, body: JSON.stringify(body ?? {}) },
|
|
103
|
+
options,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (retried) return retried as ClientResponse<T>;
|
|
107
|
+
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
return { data: null, error: await parseError(response) };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const data = (await response.json()) as T;
|
|
113
|
+
return { data, error: null };
|
|
114
|
+
},
|
|
92
115
|
};
|
|
93
116
|
}
|
|
94
117
|
|
package/src/handler/index.ts
CHANGED
|
@@ -431,14 +431,12 @@ export function createHandler(db: DrizzleDb, schema: Schema, options?: HandlerOp
|
|
|
431
431
|
// 1. Header-based (native/server): X-Client-Id + X-Client-Secret
|
|
432
432
|
// 2. Referer-based (web): Referer or Origin header (no secrets in browser source)
|
|
433
433
|
// The verifyClient callback receives all three and decides which path to validate.
|
|
434
|
-
// Skipped for publicRoutes methods (e.g. GET)
|
|
434
|
+
// Skipped for publicRoutes methods (e.g. GET) — no credentials needed.
|
|
435
|
+
// publicRpc skips JWT verification only, NOT client auth.
|
|
435
436
|
let user: Record<string, unknown> | null = null;
|
|
436
437
|
let client: Record<string, unknown> | null = null;
|
|
437
438
|
const isPublicRoute = options?.auth?.publicRoutes?.includes(method) ?? false;
|
|
438
|
-
|
|
439
|
-
&& !!pathSegments[1]
|
|
440
|
-
&& (options?.auth?.publicRpc?.includes(pathSegments[1]) ?? false);
|
|
441
|
-
if (options?.auth?.verifyClient && !isPublicRoute && !isPublicRpc) {
|
|
439
|
+
if (options?.auth?.verifyClient && !isPublicRoute) {
|
|
442
440
|
const idHeader = options.auth.clientHeaders?.id ?? 'X-Client-Id';
|
|
443
441
|
const secretHeader = options.auth.clientHeaders?.secret ?? 'X-Client-Secret';
|
|
444
442
|
const clientId = request.headers.get(idHeader);
|