two-stroke 8.0.18 → 8.0.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +36 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "two-stroke",
3
- "version": "8.0.18",
3
+ "version": "8.0.19",
4
4
  "description": "Simple Cloudflare Worker framework.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -102,9 +102,9 @@ export function twoStroke<T>(
102
102
  rawBody = route.input
103
103
  ? req.headers.get("Content-Type") === "application/x-www-form-urlencoded"
104
104
  ? // oxlint-disable-next-line no-await-in-loop
105
- Object.fromEntries(new URLSearchParams(await req.text()))
105
+ Object.fromEntries(new URLSearchParams(await req.text()))
106
106
  : // oxlint-disable-next-line no-await-in-loop
107
- await req.json()
107
+ await req.json()
108
108
  : undefined;
109
109
  } catch (error) {
110
110
  console.error({
@@ -125,10 +125,10 @@ export function twoStroke<T>(
125
125
  const body = route.input
126
126
  ? route.input.safeParse(rawBody)
127
127
  : {
128
- success: true,
129
- data: undefined,
130
- error: undefined,
131
- };
128
+ success: true,
129
+ data: undefined,
130
+ error: undefined,
131
+ };
132
132
  if (body.success)
133
133
  // oxlint-disable-next-line no-await-in-loop
134
134
  response = await route.handler({
@@ -298,41 +298,41 @@ export function twoStroke<T>(
298
298
  noAuth,
299
299
  pbkdf:
300
300
  (k: keyof T, customHeaderName = "Authorization") =>
301
- async ({ req, env }: { req: Request; env: T }) => {
302
- const [scheme, token] = (req.headers.get(customHeaderName) ?? " ").split(" ");
303
- if (
304
- (scheme === "token" || scheme === "Bearer") &&
305
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion
306
- (await pbkdfVerify(env[k] as string, token ?? ""))
307
- )
308
- return;
309
- throw new Error("Invalid");
310
- },
301
+ async ({ req, env }: { req: Request; env: T }) => {
302
+ const [scheme, token] = (req.headers.get(customHeaderName) ?? " ").split(" ");
303
+ if (
304
+ (scheme === "token" || scheme === "Bearer") &&
305
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
306
+ (await pbkdfVerify(env[k] as string, token ?? ""))
307
+ )
308
+ return;
309
+ throw new Error("Invalid");
310
+ },
311
311
  jwt:
312
312
  <J>(k: keyof T, ak: keyof T) =>
313
- async ({ req, env }: { req: Request; env: T }) => {
314
- const [scheme, token] = (req.headers.get("Authorization") ?? " ").split(" ");
315
- if (scheme === "Bearer") {
316
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion
317
- const rawIssuer = env[k] as string;
318
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion
319
- const rawAudience = env[ak] as string;
320
- const issuer = rawIssuer.startsWith("{")
321
- ? // oxlint-disable-next-line typescript/no-unsafe-type-assertion
313
+ async ({ req, env }: { req: Request; env: T }) => {
314
+ const [scheme, token] = (req.headers.get("Authorization") ?? " ").split(" ");
315
+ if (scheme === "Bearer") {
316
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
317
+ const rawIssuer = env[k] as string;
318
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
319
+ const rawAudience = env[ak] as string;
320
+ const issuer = rawIssuer.startsWith("{")
321
+ ? // oxlint-disable-next-line typescript/no-unsafe-type-assertion
322
322
  (JSON.parse(rawIssuer) as Record<string, JSONWebKeySet | true>)
323
- : { [rawIssuer]: true as const };
324
- const audience = rawAudience.startsWith("[")
325
- ? // oxlint-disable-next-line typescript/no-unsafe-type-assertion
323
+ : { [rawIssuer]: true as const };
324
+ const audience = rawAudience.startsWith("[")
325
+ ? // oxlint-disable-next-line typescript/no-unsafe-type-assertion
326
326
  (JSON.parse(rawAudience) as string[])
327
- : [rawAudience];
328
- const claims = await jwkVerifyMulti<J>(token ?? "", issuer, audience);
329
- if (!claims) {
330
- throw new Error("Invalid");
331
- }
332
- return claims;
327
+ : [rawAudience];
328
+ const claims = await jwkVerifyMulti<J>(token ?? "", issuer, audience);
329
+ if (!claims) {
330
+ throw new Error("Invalid");
333
331
  }
334
- throw new Error("Invalid");
335
- },
332
+ return claims;
333
+ }
334
+ throw new Error("Invalid");
335
+ },
336
336
  queueHandler<I extends ZodType>(
337
337
  input: I,
338
338
  handler: (c: {