two-stroke 5.5.0 → 5.6.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.
package/bin/api-types.mjs CHANGED
@@ -14,7 +14,7 @@ const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull());
14
14
 
15
15
  await Promise.all(
16
16
  services.map(async (service) => {
17
- const output = await openapiTS(`https://${service}.changeengine.com/doc`, {
17
+ const output = await openapiTS(`${service}/doc`, {
18
18
  transform(schemaObject) {
19
19
  if ("format" in schemaObject && schemaObject.format === "uuid") {
20
20
  return schemaObject.nullable
@@ -25,7 +25,7 @@ await Promise.all(
25
25
  });
26
26
  const printer = ts.createPrinter({});
27
27
  const resultFile = ts.createSourceFile(
28
- `src/__definitions__/${service}-definitions.ts`,
28
+ `src/__definitions__/${service.replace("https://", "")}-definitions.ts`,
29
29
  "",
30
30
  ts.ScriptTarget.Latest,
31
31
  );
@@ -35,7 +35,7 @@ await Promise.all(
35
35
  resultFile,
36
36
  );
37
37
  fs.writeFileSync(
38
- `src/__definitions__/${service}-definitions.ts`,
38
+ `src/__definitions__/${service.replace("https://", "")}-definitions.ts`,
39
39
  await prettier.format(
40
40
  `// Autogenerated by two-stroke
41
41
 
package/package.json CHANGED
@@ -52,7 +52,7 @@
52
52
  "name": "two-stroke",
53
53
  "packageManager": "yarn@4.6.0",
54
54
  "type": "module",
55
- "version": "5.5.0",
55
+ "version": "5.6.0",
56
56
  "devDependencies": {
57
57
  "@types/eslint": "^9.6.1",
58
58
  "eslint": "^9.32.0",
package/src/index.ts CHANGED
@@ -92,12 +92,32 @@ export function twoStroke<T extends Env>(title: string, release: string) {
92
92
  });
93
93
  }
94
94
  if (route.method === "POST" || route.method === "PUT") {
95
- const rawBody = route.input
96
- ? req.headers.get("Content-Type") ===
97
- "application/x-www-form-urlencoded"
98
- ? Object.fromEntries(new URLSearchParams(await req.text()))
99
- : await req.json()
100
- : undefined;
95
+ let rawBody;
96
+ try {
97
+ rawBody = route.input
98
+ ? req.headers.get("Content-Type") ===
99
+ "application/x-www-form-urlencoded"
100
+ ? Object.fromEntries(new URLSearchParams(await req.text()))
101
+ : await req.json()
102
+ : undefined;
103
+ } catch (e) {
104
+ console.error({
105
+ message: "Request body is required'",
106
+ error: e instanceof Error ? e.message : "Error",
107
+ });
108
+ return new Response(
109
+ JSON.stringify({
110
+ error: "Request body is required",
111
+ issues: [],
112
+ }),
113
+ {
114
+ status: 400,
115
+ headers: {
116
+ "Access-Control-Allow-Origin": "*",
117
+ },
118
+ },
119
+ );
120
+ }
101
121
  const body = route.input
102
122
  ? route.input.safeParse(rawBody)
103
123
  : {