@everystack/api 0.2.1 → 0.2.3
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/handler/index.ts +15 -11
package/package.json
CHANGED
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);
|
|
@@ -547,6 +545,12 @@ export function createHandler(db: DrizzleDb, schema: Schema, options?: HandlerOp
|
|
|
547
545
|
const result = await verifyUserToken(request, options.auth);
|
|
548
546
|
if (result.error) return result.error;
|
|
549
547
|
user = result.user;
|
|
548
|
+
} else if (request.headers.get('authorization')) {
|
|
549
|
+
// Public route with token present — verify opportunistically.
|
|
550
|
+
// If valid, the request runs as authenticated (better RLS access).
|
|
551
|
+
// If invalid, ignore and fall through as anonymous.
|
|
552
|
+
const result = await verifyUserToken(request, options.auth);
|
|
553
|
+
if (!result.error) user = result.user;
|
|
550
554
|
}
|
|
551
555
|
|
|
552
556
|
if (user && options.auth.onAuthenticated) {
|
|
@@ -812,7 +816,7 @@ async function handleGet(
|
|
|
812
816
|
};
|
|
813
817
|
if (cacheControl) aggHeaders['Cache-Control'] = cacheControl;
|
|
814
818
|
|
|
815
|
-
return new Response(JSON.stringify(transformResponse(
|
|
819
|
+
return new Response(JSON.stringify(stripHiddenColumns(transformResponse(serialized, options), tableName, options)), {
|
|
816
820
|
status: 200,
|
|
817
821
|
headers: aggHeaders,
|
|
818
822
|
});
|
|
@@ -926,7 +930,7 @@ async function handleGet(
|
|
|
926
930
|
};
|
|
927
931
|
if (cacheControl) getHeaders['Cache-Control'] = cacheControl;
|
|
928
932
|
|
|
929
|
-
return new Response(JSON.stringify(transformResponse(
|
|
933
|
+
return new Response(JSON.stringify(stripHiddenColumns(transformResponse(responseData, options), tableName, options)), {
|
|
930
934
|
status: 200,
|
|
931
935
|
headers: getHeaders,
|
|
932
936
|
});
|
|
@@ -1228,7 +1232,7 @@ async function handlePost(
|
|
|
1228
1232
|
try { await hook.afterCreate(rows[0], user, client); } catch {}
|
|
1229
1233
|
}
|
|
1230
1234
|
|
|
1231
|
-
return json(transformResponse(
|
|
1235
|
+
return json(stripHiddenColumns(transformResponse(rows[0], options), tableName, options), 201);
|
|
1232
1236
|
}
|
|
1233
1237
|
|
|
1234
1238
|
async function handlePatch(
|
|
@@ -1305,7 +1309,7 @@ async function handlePatch(
|
|
|
1305
1309
|
try { await hook.afterUpdate(rows, user, client); } catch {}
|
|
1306
1310
|
}
|
|
1307
1311
|
|
|
1308
|
-
return json(transformResponse(
|
|
1312
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1309
1313
|
}
|
|
1310
1314
|
|
|
1311
1315
|
async function handleDelete(
|
|
@@ -1375,7 +1379,7 @@ async function handleDelete(
|
|
|
1375
1379
|
try { await hook.afterDelete(rows, user, client); } catch {}
|
|
1376
1380
|
}
|
|
1377
1381
|
|
|
1378
|
-
return json(transformResponse(
|
|
1382
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1379
1383
|
}
|
|
1380
1384
|
}
|
|
1381
1385
|
|
|
@@ -1394,7 +1398,7 @@ async function handleDelete(
|
|
|
1394
1398
|
try { await hook.afterDelete(rows, user, client); } catch {}
|
|
1395
1399
|
}
|
|
1396
1400
|
|
|
1397
|
-
return json(transformResponse(
|
|
1401
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1398
1402
|
}
|
|
1399
1403
|
|
|
1400
1404
|
interface JsonPath {
|