two-stroke 6.1.0 → 6.2.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.
Files changed (2) hide show
  1. package/package.json +12 -12
  2. package/src/index.ts +26 -25
package/package.json CHANGED
@@ -10,25 +10,25 @@
10
10
  "type-check": "./bin/type-check.mjs"
11
11
  },
12
12
  "dependencies": {
13
- "@cloudflare/vitest-pool-workers": "^0.9.8",
14
- "@cloudflare/workers-types": "^4.20250927.0",
13
+ "@cloudflare/vitest-pool-workers": "^0.9.11",
14
+ "@cloudflare/workers-types": "^4.20251008.0",
15
15
  "@sentry/cli": "^2.56.0",
16
- "@types/node": "^24.6.0",
17
- "@typescript-eslint/eslint-plugin": "^8.45.0",
18
- "@typescript-eslint/parser": "^8.45.0",
16
+ "@types/node": "^24.7.0",
17
+ "@typescript-eslint/eslint-plugin": "^8.46.0",
18
+ "@typescript-eslint/parser": "^8.46.0",
19
19
  "@vitest/coverage-istanbul": "^3.2.4",
20
20
  "eslint-config-prettier": "^10.1.8",
21
- "eslint-config-two-stroke": "^1.2.11",
21
+ "eslint-config-two-stroke": "^1.2.12",
22
22
  "eslint-config-typescript": "^3.0.0",
23
23
  "jose": "^6.1.0",
24
24
  "jwk-subtle": "^1.0.7",
25
25
  "mime": "^4.1.0",
26
- "miniflare": "^4.20250927.0",
27
- "openapi-fetch": "^0.14.0",
26
+ "miniflare": "^4.20251004.0",
27
+ "openapi-fetch": "^0.14.1",
28
28
  "openapi-typescript": "^7.9.1",
29
29
  "pbkdf-subtle": "^1.0.0",
30
30
  "toucan-js": "^4.1.1",
31
- "zod": "^4.1.11"
31
+ "zod": "^4.1.12"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@sentry/cli": ">=2",
@@ -52,12 +52,12 @@
52
52
  "name": "two-stroke",
53
53
  "packageManager": "yarn@4.6.0",
54
54
  "type": "module",
55
- "version": "6.1.0",
55
+ "version": "6.2.0",
56
56
  "devDependencies": {
57
57
  "@types/eslint": "^9.6.1",
58
- "eslint": "^9.36.0",
58
+ "eslint": "^9.37.0",
59
59
  "prettier": "^3.6.2",
60
- "typescript": "^5.9.2",
60
+ "typescript": "^5.9.3",
61
61
  "vitest": "^3.2.4"
62
62
  }
63
63
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { verify as jwkVerify } from "jwk-subtle";
2
2
  import { verify as pbkdfVerify } from "pbkdf-subtle";
3
3
  import { Toucan } from "toucan-js";
4
- import { type ZodSafeParseResult, ZodObject, z, ZodType } from "zod/v4";
4
+ import { type ZodSafeParseResult, z, ZodObject, ZodType } from "zod/v4";
5
5
  import { openAPI } from "./open-api";
6
6
  import { type Env, type Handler, type Route } from "./types";
7
7
 
@@ -14,7 +14,7 @@ const escapeRegex = (str: string) =>
14
14
  export function twoStroke<T extends Env>(
15
15
  title: string,
16
16
  release: string,
17
- origin?: (o: string | null) => string
17
+ origin?: (o: string | null) => string,
18
18
  ) {
19
19
  let _queue: (c: {
20
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -47,7 +47,7 @@ export function twoStroke<T extends Env>(
47
47
  readonly SENTRY_DSN: string;
48
48
  readonly SENTRY_ENVIRONMENT: string;
49
49
  },
50
- context: ExecutionContext
50
+ context: ExecutionContext,
51
51
  ): Promise<Response> {
52
52
  const defaultHeaders = {
53
53
  "Access-Control-Allow-Origin": origin
@@ -76,6 +76,7 @@ export function twoStroke<T extends Env>(
76
76
  "Access-Control-Max-Age": "86400",
77
77
  "Access-Control-Allow-Methods": "GET,HEAD,PUT,POST,DELETE",
78
78
  "Access-Control-Allow-Headers": "Authorization,Content-Type",
79
+ "Access-Control-Allow-Credentials": "true",
79
80
  },
80
81
  });
81
82
  }
@@ -85,8 +86,8 @@ export function twoStroke<T extends Env>(
85
86
  if (req.method === route.method && route.matcher.test(pathname)) {
86
87
  const params = Object.fromEntries(
87
88
  Object.entries(pathname.match(route.matcher)?.groups ?? {}).map(
88
- ([k, v]) => [k, decodeURIComponent(v)]
89
- )
89
+ ([k, v]) => [k, decodeURIComponent(v)],
90
+ ),
90
91
  );
91
92
  let claims;
92
93
  try {
@@ -125,7 +126,7 @@ export function twoStroke<T extends Env>(
125
126
  {
126
127
  status: 400,
127
128
  headers: defaultHeaders,
128
- }
129
+ },
129
130
  );
130
131
  }
131
132
  const body = route.input
@@ -162,7 +163,7 @@ export function twoStroke<T extends Env>(
162
163
  {
163
164
  status: 400,
164
165
  headers: defaultHeaders,
165
- }
166
+ },
166
167
  );
167
168
  }
168
169
  } else {
@@ -213,7 +214,7 @@ export function twoStroke<T extends Env>(
213
214
  "application/json"
214
215
  ? JSON.stringify(response.body)
215
216
  : response.body,
216
- responseWithHeaders
217
+ responseWithHeaders,
217
218
  );
218
219
  }
219
220
  }
@@ -237,7 +238,7 @@ export function twoStroke<T extends Env>(
237
238
  readonly SENTRY_DSN: string;
238
239
  readonly SENTRY_ENVIRONMENT: string;
239
240
  },
240
- context: ExecutionContext
241
+ context: ExecutionContext,
241
242
  ) {
242
243
  const sentry = new Toucan({
243
244
  dsn: env.SENTRY_DSN,
@@ -258,7 +259,7 @@ export function twoStroke<T extends Env>(
258
259
  readonly SENTRY_DSN: string;
259
260
  readonly SENTRY_ENVIRONMENT: string;
260
261
  },
261
- context: ExecutionContext
262
+ context: ExecutionContext,
262
263
  ) {
263
264
  const sentry = new Toucan({
264
265
  dsn: env.SENTRY_DSN,
@@ -283,7 +284,7 @@ export function twoStroke<T extends Env>(
283
284
  readonly SENTRY_DSN: string;
284
285
  readonly SENTRY_ENVIRONMENT: string;
285
286
  },
286
- context: ExecutionContext
287
+ context: ExecutionContext,
287
288
  ) {
288
289
  const sentry = new Toucan({
289
290
  dsn: env.SENTRY_DSN,
@@ -303,13 +304,13 @@ export function twoStroke<T extends Env>(
303
304
  env: T;
304
305
  message: ForwardableEmailMessage;
305
306
  sentry: Toucan;
306
- }) => Promise<void>
307
+ }) => Promise<void>,
307
308
  ) {
308
309
  _email = handler;
309
310
  },
310
311
  schedule(
311
312
  cron: string,
312
- handler: (c: { env: T; sentry: Toucan }) => Promise<void>
313
+ handler: (c: { env: T; sentry: Toucan }) => Promise<void>,
313
314
  ) {
314
315
  crons[cron] = handler;
315
316
  },
@@ -331,13 +332,13 @@ export function twoStroke<T extends Env>(
331
332
  <J>(k: keyof T, ak: keyof T) =>
332
333
  async ({ req, env }: { req: Request; env: T }) => {
333
334
  const [scheme, token] = (req.headers.get("Authorization") ?? " ").split(
334
- " "
335
+ " ",
335
336
  );
336
337
  if (scheme === "Bearer") {
337
338
  const claims = await jwkVerify<J>(
338
339
  token ?? "",
339
340
  env[k] as string,
340
- env[ak] as string
341
+ env[ak] as string,
341
342
  );
342
343
  if (!claims) {
343
344
  throw Error("Invalid");
@@ -353,7 +354,7 @@ export function twoStroke<T extends Env>(
353
354
  batch: MessageBatch<z.input<I>>;
354
355
  sentry: Toucan;
355
356
  parsedBatch: ZodSafeParseResult<z.output<I>>[];
356
- }) => Promise<void>
357
+ }) => Promise<void>,
357
358
  ) {
358
359
  _queue = async ({
359
360
  batch,
@@ -380,14 +381,14 @@ export function twoStroke<T extends Env>(
380
381
  path: P,
381
382
  input: I,
382
383
  output: O,
383
- handler: Handler<T, I, O, A, P>
384
+ handler: Handler<T, I, O, A, P>,
384
385
  ) {
385
386
  routes.push({
386
387
  auth,
387
388
  method: "PUT",
388
389
  path,
389
390
  matcher: new RegExp(
390
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
391
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
391
392
  ),
392
393
  input,
393
394
  output,
@@ -408,14 +409,14 @@ export function twoStroke<T extends Env>(
408
409
  input: I,
409
410
  output: O,
410
411
  handler: Handler<T, I, O, A, P>,
411
- params?: PP
412
+ params?: PP,
412
413
  ) {
413
414
  routes.push({
414
415
  auth,
415
416
  method: "POST",
416
417
  path,
417
418
  matcher: new RegExp(
418
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
419
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
419
420
  ),
420
421
  input,
421
422
  output,
@@ -435,14 +436,14 @@ export function twoStroke<T extends Env>(
435
436
  path: P,
436
437
  output: O,
437
438
  handler: Handler<T, undefined, O, A, P>,
438
- params?: PP
439
+ params?: PP,
439
440
  ) {
440
441
  routes.push({
441
442
  auth,
442
443
  method: "GET",
443
444
  path,
444
445
  matcher: new RegExp(
445
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
446
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
446
447
  ),
447
448
  output,
448
449
  handler,
@@ -460,14 +461,14 @@ export function twoStroke<T extends Env>(
460
461
  path: P,
461
462
  output: O,
462
463
  handler: Handler<T, undefined, O, A, P>,
463
- params?: PP
464
+ params?: PP,
464
465
  ) {
465
466
  routes.push({
466
467
  auth,
467
468
  method: "DELETE",
468
469
  path,
469
470
  matcher: new RegExp(
470
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
471
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
471
472
  ),
472
473
  output,
473
474
  handler,
@@ -485,7 +486,7 @@ type AddToQueueConfig = QueueSendOptions & {
485
486
  export async function addToQueue<T>(
486
487
  queue: Queue<T>,
487
488
  message: T,
488
- config: AddToQueueConfig = {}
489
+ config: AddToQueueConfig = {},
489
490
  ) {
490
491
  const { retries, backoffFactor, ...options } = config;
491
492