two-stroke 6.1.0 → 6.1.1

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 +24 -24
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.1.1",
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
@@ -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
@@ -85,8 +85,8 @@ export function twoStroke<T extends Env>(
85
85
  if (req.method === route.method && route.matcher.test(pathname)) {
86
86
  const params = Object.fromEntries(
87
87
  Object.entries(pathname.match(route.matcher)?.groups ?? {}).map(
88
- ([k, v]) => [k, decodeURIComponent(v)]
89
- )
88
+ ([k, v]) => [k, decodeURIComponent(v)],
89
+ ),
90
90
  );
91
91
  let claims;
92
92
  try {
@@ -125,7 +125,7 @@ export function twoStroke<T extends Env>(
125
125
  {
126
126
  status: 400,
127
127
  headers: defaultHeaders,
128
- }
128
+ },
129
129
  );
130
130
  }
131
131
  const body = route.input
@@ -162,7 +162,7 @@ export function twoStroke<T extends Env>(
162
162
  {
163
163
  status: 400,
164
164
  headers: defaultHeaders,
165
- }
165
+ },
166
166
  );
167
167
  }
168
168
  } else {
@@ -213,7 +213,7 @@ export function twoStroke<T extends Env>(
213
213
  "application/json"
214
214
  ? JSON.stringify(response.body)
215
215
  : response.body,
216
- responseWithHeaders
216
+ responseWithHeaders,
217
217
  );
218
218
  }
219
219
  }
@@ -237,7 +237,7 @@ export function twoStroke<T extends Env>(
237
237
  readonly SENTRY_DSN: string;
238
238
  readonly SENTRY_ENVIRONMENT: string;
239
239
  },
240
- context: ExecutionContext
240
+ context: ExecutionContext,
241
241
  ) {
242
242
  const sentry = new Toucan({
243
243
  dsn: env.SENTRY_DSN,
@@ -258,7 +258,7 @@ export function twoStroke<T extends Env>(
258
258
  readonly SENTRY_DSN: string;
259
259
  readonly SENTRY_ENVIRONMENT: string;
260
260
  },
261
- context: ExecutionContext
261
+ context: ExecutionContext,
262
262
  ) {
263
263
  const sentry = new Toucan({
264
264
  dsn: env.SENTRY_DSN,
@@ -283,7 +283,7 @@ export function twoStroke<T extends Env>(
283
283
  readonly SENTRY_DSN: string;
284
284
  readonly SENTRY_ENVIRONMENT: string;
285
285
  },
286
- context: ExecutionContext
286
+ context: ExecutionContext,
287
287
  ) {
288
288
  const sentry = new Toucan({
289
289
  dsn: env.SENTRY_DSN,
@@ -303,13 +303,13 @@ export function twoStroke<T extends Env>(
303
303
  env: T;
304
304
  message: ForwardableEmailMessage;
305
305
  sentry: Toucan;
306
- }) => Promise<void>
306
+ }) => Promise<void>,
307
307
  ) {
308
308
  _email = handler;
309
309
  },
310
310
  schedule(
311
311
  cron: string,
312
- handler: (c: { env: T; sentry: Toucan }) => Promise<void>
312
+ handler: (c: { env: T; sentry: Toucan }) => Promise<void>,
313
313
  ) {
314
314
  crons[cron] = handler;
315
315
  },
@@ -331,13 +331,13 @@ export function twoStroke<T extends Env>(
331
331
  <J>(k: keyof T, ak: keyof T) =>
332
332
  async ({ req, env }: { req: Request; env: T }) => {
333
333
  const [scheme, token] = (req.headers.get("Authorization") ?? " ").split(
334
- " "
334
+ " ",
335
335
  );
336
336
  if (scheme === "Bearer") {
337
337
  const claims = await jwkVerify<J>(
338
338
  token ?? "",
339
339
  env[k] as string,
340
- env[ak] as string
340
+ env[ak] as string,
341
341
  );
342
342
  if (!claims) {
343
343
  throw Error("Invalid");
@@ -353,7 +353,7 @@ export function twoStroke<T extends Env>(
353
353
  batch: MessageBatch<z.input<I>>;
354
354
  sentry: Toucan;
355
355
  parsedBatch: ZodSafeParseResult<z.output<I>>[];
356
- }) => Promise<void>
356
+ }) => Promise<void>,
357
357
  ) {
358
358
  _queue = async ({
359
359
  batch,
@@ -380,14 +380,14 @@ export function twoStroke<T extends Env>(
380
380
  path: P,
381
381
  input: I,
382
382
  output: O,
383
- handler: Handler<T, I, O, A, P>
383
+ handler: Handler<T, I, O, A, P>,
384
384
  ) {
385
385
  routes.push({
386
386
  auth,
387
387
  method: "PUT",
388
388
  path,
389
389
  matcher: new RegExp(
390
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
390
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
391
391
  ),
392
392
  input,
393
393
  output,
@@ -408,14 +408,14 @@ export function twoStroke<T extends Env>(
408
408
  input: I,
409
409
  output: O,
410
410
  handler: Handler<T, I, O, A, P>,
411
- params?: PP
411
+ params?: PP,
412
412
  ) {
413
413
  routes.push({
414
414
  auth,
415
415
  method: "POST",
416
416
  path,
417
417
  matcher: new RegExp(
418
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
418
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
419
419
  ),
420
420
  input,
421
421
  output,
@@ -435,14 +435,14 @@ export function twoStroke<T extends Env>(
435
435
  path: P,
436
436
  output: O,
437
437
  handler: Handler<T, undefined, O, A, P>,
438
- params?: PP
438
+ params?: PP,
439
439
  ) {
440
440
  routes.push({
441
441
  auth,
442
442
  method: "GET",
443
443
  path,
444
444
  matcher: new RegExp(
445
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
445
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
446
446
  ),
447
447
  output,
448
448
  handler,
@@ -460,14 +460,14 @@ export function twoStroke<T extends Env>(
460
460
  path: P,
461
461
  output: O,
462
462
  handler: Handler<T, undefined, O, A, P>,
463
- params?: PP
463
+ params?: PP,
464
464
  ) {
465
465
  routes.push({
466
466
  auth,
467
467
  method: "DELETE",
468
468
  path,
469
469
  matcher: new RegExp(
470
- `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`
470
+ `^${escapeRegex(path).replaceAll(/\/{([^}]*)}/g, "/(?<$1>[^\\/]*)")}$`,
471
471
  ),
472
472
  output,
473
473
  handler,
@@ -485,7 +485,7 @@ type AddToQueueConfig = QueueSendOptions & {
485
485
  export async function addToQueue<T>(
486
486
  queue: Queue<T>,
487
487
  message: T,
488
- config: AddToQueueConfig = {}
488
+ config: AddToQueueConfig = {},
489
489
  ) {
490
490
  const { retries, backoffFactor, ...options } = config;
491
491