@bitbybit-dev/create-app 1.3.2 → 1.4.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 (190) hide show
  1. package/README.md +47 -124
  2. package/dist/index.js +253 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/scaffold.d.ts +30 -0
  5. package/dist/scaffold.d.ts.map +1 -0
  6. package/dist/scaffold.js +107 -0
  7. package/dist/scaffold.js.map +1 -0
  8. package/package.json +4 -3
  9. package/src/index.test.ts +309 -8
  10. package/src/index.ts +285 -24
  11. package/src/scaffold.test.ts +177 -0
  12. package/src/scaffold.ts +99 -0
  13. package/templates/_agent/AGENTS.md +39 -0
  14. package/templates/_agent/CLAUDE.md +1 -0
  15. package/templates/_agent/_dot-cursor/mcp.json +5 -0
  16. package/templates/_agent/_dot-gitignore +7 -0
  17. package/templates/_agent/_dot-mcp.json +5 -0
  18. package/templates/_agent/_dot-vscode/mcp.json +5 -0
  19. package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
  20. package/templates/apps/drone-assembly/README.md +35 -0
  21. package/templates/apps/drone-assembly/eslint.config.js +47 -0
  22. package/templates/apps/drone-assembly/index.html +17 -0
  23. package/templates/apps/drone-assembly/package.json +31 -0
  24. package/templates/apps/drone-assembly/public/favicon.ico +0 -0
  25. package/templates/apps/drone-assembly/public/logo.png +0 -0
  26. package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
  27. package/templates/apps/drone-assembly/src/assembly.ts +99 -0
  28. package/templates/apps/drone-assembly/src/exports.ts +10 -0
  29. package/templates/apps/drone-assembly/src/kernel.ts +14 -0
  30. package/templates/apps/drone-assembly/src/main.ts +298 -0
  31. package/templates/apps/drone-assembly/src/materials.ts +58 -0
  32. package/templates/apps/drone-assembly/src/model.ts +280 -0
  33. package/templates/apps/drone-assembly/src/parts.ts +343 -0
  34. package/templates/apps/drone-assembly/src/style.css +219 -0
  35. package/templates/apps/drone-assembly/src/ui.ts +180 -0
  36. package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
  37. package/templates/apps/drone-assembly/tsconfig.json +29 -0
  38. package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
  39. package/templates/apps/laser-cut-box/README.md +34 -0
  40. package/templates/apps/laser-cut-box/eslint.config.js +47 -0
  41. package/templates/apps/laser-cut-box/index.html +17 -0
  42. package/templates/apps/laser-cut-box/package.json +30 -0
  43. package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
  44. package/templates/apps/laser-cut-box/public/logo.png +0 -0
  45. package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
  46. package/templates/apps/laser-cut-box/src/exports.ts +28 -0
  47. package/templates/apps/laser-cut-box/src/main.ts +176 -0
  48. package/templates/apps/laser-cut-box/src/model.ts +92 -0
  49. package/templates/apps/laser-cut-box/src/panels.ts +229 -0
  50. package/templates/apps/laser-cut-box/src/style.css +223 -0
  51. package/templates/apps/laser-cut-box/src/ui.ts +136 -0
  52. package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
  53. package/templates/apps/laser-cut-box/tsconfig.json +29 -0
  54. package/templates/apps/product-configurator/AGENTS.section.md +19 -0
  55. package/templates/apps/product-configurator/README.md +33 -0
  56. package/templates/apps/product-configurator/eslint.config.js +47 -0
  57. package/templates/apps/product-configurator/index.html +17 -0
  58. package/templates/apps/product-configurator/package.json +30 -0
  59. package/templates/apps/product-configurator/public/favicon.ico +0 -0
  60. package/templates/apps/product-configurator/public/logo.png +0 -0
  61. package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
  62. package/templates/apps/product-configurator/src/catalog.ts +56 -0
  63. package/templates/apps/product-configurator/src/exports.ts +19 -0
  64. package/templates/apps/product-configurator/src/main.ts +134 -0
  65. package/templates/apps/product-configurator/src/model.ts +153 -0
  66. package/templates/apps/product-configurator/src/style.css +177 -0
  67. package/templates/apps/product-configurator/src/ui.ts +150 -0
  68. package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
  69. package/templates/apps/product-configurator/tsconfig.json +29 -0
  70. package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
  71. package/templates/apps/sheet-metal-unfold/README.md +41 -0
  72. package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
  73. package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
  74. package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
  75. package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
  76. package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
  77. package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
  78. package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
  79. package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
  80. package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
  81. package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
  82. package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
  83. package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
  84. package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
  85. package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
  86. package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
  87. package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
  88. package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
  89. package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
  90. package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
  91. package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
  92. package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
  93. package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
  94. package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
  95. package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
  96. package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
  97. package/templates/apps/sheet-metal-unfold/package.json +18 -0
  98. package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
  99. package/templates/apps/step-to-gltf-cli/README.md +34 -0
  100. package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
  101. package/templates/apps/step-to-gltf-cli/package.json +26 -0
  102. package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
  103. package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
  104. package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
  105. package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
  106. package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
  107. package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
  108. package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
  109. package/templates/cloud/AGENTS.section.md +22 -0
  110. package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
  111. package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
  112. package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
  113. package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
  114. package/templates/cloud/backends/hono-rest/package.json +11 -4
  115. package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
  116. package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
  117. package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
  118. package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
  119. package/templates/cloud/backends/hono-sdk/package.json +12 -5
  120. package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
  121. package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
  122. package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
  123. package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
  124. package/templates/cloud/backends/nodejs-rest/package.json +12 -5
  125. package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
  126. package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
  127. package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
  128. package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
  129. package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
  130. package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
  131. package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
  132. package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
  133. package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
  134. package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
  135. package/templates/cloud/frontend/eslint.config.js +50 -0
  136. package/templates/cloud/frontend/index.html +3 -1
  137. package/templates/cloud/frontend/package.json +13 -4
  138. package/templates/cloud/frontend/public/favicon.ico +0 -0
  139. package/templates/cloud/frontend/public/logo.png +0 -0
  140. package/templates/cloud/frontend/src/App.tsx +11 -9
  141. package/templates/cloud/frontend/src/api.ts +31 -0
  142. package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
  143. package/templates/cloud/frontend/src/components/Header.tsx +4 -2
  144. package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
  145. package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
  146. package/templates/cloud/frontend/src/main.tsx +6 -1
  147. package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
  148. package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
  149. package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
  150. package/templates/cloud/frontend/tsconfig.json +19 -7
  151. package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
  152. package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
  153. package/templates/vite/babylonjs/typescript/index.html +4 -2
  154. package/templates/vite/babylonjs/typescript/package.json +14 -4
  155. package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
  156. package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
  157. package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
  158. package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
  159. package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
  160. package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
  161. package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
  162. package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
  163. package/templates/vite/playcanvas/typescript/index.html +4 -2
  164. package/templates/vite/playcanvas/typescript/package.json +14 -4
  165. package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
  166. package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
  167. package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
  168. package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
  169. package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
  170. package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
  171. package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
  172. package/templates/vite/threejs/typescript/eslint.config.js +47 -0
  173. package/templates/vite/threejs/typescript/index.html +4 -2
  174. package/templates/vite/threejs/typescript/package.json +16 -6
  175. package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
  176. package/templates/vite/threejs/typescript/public/logo.png +0 -0
  177. package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
  178. package/templates/vite/threejs/typescript/src/main.ts +11 -22
  179. package/templates/vite/threejs/typescript/src/model.ts +24 -0
  180. package/templates/vite/threejs/typescript/tsconfig.json +16 -12
  181. package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
  182. package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
  183. package/templates/vite/threejs/typescript/public/vite.svg +0 -1
  184. /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
  185. /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
  186. /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
  187. /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
  188. /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
  189. /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
  190. /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
@@ -5,7 +5,6 @@ import { createDragonCup, createDragonCupBatch, createInvalidCup, getTaskResult,
5
5
 
6
6
  const app = new Hono<{ Bindings: Env }>();
7
7
 
8
- // Check for missing API key and return a helpful error
9
8
  app.use("/api/*", async (c, next) => {
10
9
  if (!c.env.BITBYBIT_API_KEY) {
11
10
  return c.json({
@@ -13,10 +12,9 @@ app.use("/api/*", async (c, next) => {
13
12
  help: "You need a Bitbybit API key to use this service. Create an account on https://bitbybit.dev and purchase an API key plan at https://bitbybit.dev/auth/pick-plan?api-keys=true to get access to managed CAD cloud servers.",
14
13
  }, 503);
15
14
  }
16
- await next();
15
+ return next();
17
16
  });
18
17
 
19
- // Backend endpoint — calls bitbybit API with server-side API key
20
18
  app.post("/api/generate", async (c) => {
21
19
  try {
22
20
  const result = await createDragonCup(c.env);
@@ -30,7 +28,6 @@ app.post("/api/generate", async (c) => {
30
28
  }
31
29
  });
32
30
 
33
- // Batch generation — creates 3 dragon cup variations in parallel
34
31
  app.post("/api/generate-batch", async (c) => {
35
32
  try {
36
33
  const result = await createDragonCupBatch(c.env);
@@ -41,7 +38,6 @@ app.post("/api/generate-batch", async (c) => {
41
38
  }
42
39
  });
43
40
 
44
- // Validation demo — intentionally sends invalid params to show client-side validation
45
41
  app.post("/api/validate-demo", async (c) => {
46
42
  try {
47
43
  await createInvalidCup(c.env);
@@ -59,7 +55,6 @@ app.post("/api/validate-demo", async (c) => {
59
55
  }
60
56
  });
61
57
 
62
- // Fetch result for an existing task
63
58
  app.get("/api/task/:id", async (c) => {
64
59
  try {
65
60
  const taskId = c.req.param("id");
@@ -71,7 +66,6 @@ app.get("/api/task/:id", async (c) => {
71
66
  }
72
67
  });
73
68
 
74
- // Pipeline: translate → union → fillet
75
69
  app.post("/api/pipeline/translate-union-fillet", async (c) => {
76
70
  try {
77
71
  const result = await runTranslateUnionFilletPipeline(c.env);
@@ -82,7 +76,6 @@ app.post("/api/pipeline/translate-union-fillet", async (c) => {
82
76
  }
83
77
  });
84
78
 
85
- // Pipeline: map cylinders at positions
86
79
  app.post("/api/pipeline/map-cylinders", async (c) => {
87
80
  try {
88
81
  const result = await runMapCylindersPipeline(c.env);
@@ -93,7 +86,6 @@ app.post("/api/pipeline/map-cylinders", async (c) => {
93
86
  }
94
87
  });
95
88
 
96
- // Pipeline: map spheres at different radii
97
89
  app.post("/api/pipeline/map-spheres", async (c) => {
98
90
  try {
99
91
  const result = await runMapSpheresPipeline(c.env);
@@ -104,7 +96,6 @@ app.post("/api/pipeline/map-spheres", async (c) => {
104
96
  }
105
97
  });
106
98
 
107
- // Pipeline: choice conditional
108
99
  app.post("/api/pipeline/choice", async (c) => {
109
100
  try {
110
101
  const result = await runChoicePipeline(c.env);
@@ -115,7 +106,6 @@ app.post("/api/pipeline/choice", async (c) => {
115
106
  }
116
107
  });
117
108
 
118
- // Pipeline: file input (upload STEP → fillet)
119
109
  app.post("/api/pipeline/file-input", async (c) => {
120
110
  try {
121
111
  const formData = await c.req.formData();
@@ -133,7 +123,6 @@ app.post("/api/pipeline/file-input", async (c) => {
133
123
  }
134
124
  });
135
125
 
136
- // Proxy download — fetches a remote file through the backend to avoid CORS issues with GLTFLoader
137
126
  app.get("/api/proxy-download", async (c) => {
138
127
  const url = c.req.query("url");
139
128
  if (!url) return c.json({ error: "Missing url parameter" }, 400);
@@ -1,16 +1,27 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "module": "ES2022",
4
+ "module": "ESNext",
5
5
  "moduleResolution": "bundler",
6
- "strict": true,
7
- "skipLibCheck": true,
8
6
  "lib": ["ES2022"],
9
7
  "types": ["@cloudflare/workers-types"],
10
- "outDir": "dist",
11
- "rootDir": "src",
12
- "resolveJsonModule": true,
13
- "isolatedModules": true
8
+ "noEmit": true,
9
+ "strict": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "exactOptionalPropertyTypes": true,
12
+ "noImplicitReturns": true,
13
+ "noImplicitOverride": true,
14
+ "noPropertyAccessFromIndexSignature": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "noUnusedLocals": true,
17
+ "noUnusedParameters": true,
18
+ "useUnknownInCatchVariables": true,
19
+ "forceConsistentCasingInFileNames": true,
20
+ "isolatedModules": true,
21
+ "verbatimModuleSyntax": true,
22
+ "erasableSyntaxOnly": true,
23
+ "noUncheckedSideEffectImports": true,
24
+ "skipLibCheck": true
14
25
  },
15
- "include": ["src/**/*.ts"]
26
+ "include": ["src"]
16
27
  }
@@ -0,0 +1,47 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import eslint from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+ import noComments from "eslint-plugin-no-comments";
5
+
6
+ const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
7
+
8
+ export default defineConfig([
9
+ globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
10
+ {
11
+ files: ["**/*.ts"],
12
+ extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
13
+ plugins: { "no-comments": noComments },
14
+ languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
15
+ rules: {
16
+ quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
17
+ semi: ["error", "always"],
18
+ eqeqeq: ["error", "always"],
19
+ curly: ["error", "multi-line"],
20
+ "prefer-const": "error",
21
+ "no-var": "error",
22
+ "max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
23
+ "no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
24
+ "no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
25
+ "no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
26
+ "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
27
+ "@typescript-eslint/no-explicit-any": "error",
28
+ "@typescript-eslint/no-non-null-assertion": "error",
29
+ "@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
30
+ "@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
31
+ "@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
32
+ "@typescript-eslint/naming-convention": [
33
+ "error",
34
+ { selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
35
+ { selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
36
+ { selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
37
+ { selector: "typeLike", format: ["PascalCase"] },
38
+ { selector: "property", format: null },
39
+ { selector: "method", format: ["camelCase"] },
40
+ { selector: "import", format: null },
41
+ ],
42
+ "@typescript-eslint/only-throw-error": "error",
43
+ "@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
44
+ "@typescript-eslint/non-nullable-type-assertion-style": "off",
45
+ },
46
+ },
47
+ ]);
@@ -1,22 +1,29 @@
1
1
  {
2
2
  "name": "bitbybit-api-nodejs-rest-threejs",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "tsx watch --env-file=.env src/index.ts",
8
- "build": "tsc",
9
- "start": "node --env-file=.env dist/index.js"
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "start": "node --env-file=.env dist/index.js",
10
+ "smoke": "npm run typecheck && npm run lint",
11
+ "typecheck": "tsc --noEmit",
12
+ "lint": "eslint . --max-warnings 0"
10
13
  },
11
14
  "dependencies": {
12
15
  "express": "^5.1.0",
13
16
  "multer": "^2.3.0"
14
17
  },
15
18
  "devDependencies": {
19
+ "@eslint/js": "10.0.1",
16
20
  "@types/express": "^5.0.2",
17
21
  "@types/multer": "^2.2.0",
18
- "@types/node": "^22.15.0",
22
+ "@types/node": "22.20.1",
23
+ "eslint": "10.10.0",
24
+ "eslint-plugin-no-comments": "1.2.1",
19
25
  "tsx": "^4.19.0",
20
- "typescript": "^5.8.0"
26
+ "typescript": "5.9.3",
27
+ "typescript-eslint": "8.70.0"
21
28
  }
22
29
  }
@@ -1,7 +1,8 @@
1
1
  import type { Env } from "./types.js";
2
2
 
3
3
  const POLL_INTERVAL_MS = 2_000;
4
- const MAX_POLL_ATTEMPTS = 120; // 4 minutes max
4
+ const POLL_TIMEOUT_MS = 4 * 60 * 1000;
5
+ const MAX_POLL_ATTEMPTS = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;
5
6
 
6
7
  interface TaskResponse {
7
8
  ok: boolean;
@@ -44,19 +45,16 @@ async function apiRequest(env: Env, method: string, path: string, body?: unknown
44
45
  const headers: Record<string, string> = {
45
46
  "x-api-key": env.BITBYBIT_API_KEY,
46
47
  };
47
- if (body != null) {
48
+ const init: RequestInit = { method, headers };
49
+ if (body !== undefined) {
48
50
  headers["Content-Type"] = "application/json";
51
+ init.body = JSON.stringify(body);
49
52
  }
50
53
 
51
- return fetch(url, {
52
- method,
53
- headers,
54
- body: body ? JSON.stringify(body) : undefined,
55
- });
54
+ return fetch(url, init);
56
55
  }
57
56
 
58
57
  export async function createDragonCup(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
59
- // 1. Create dragon cup model — returns 202 with taskId
60
58
  const createRes = await apiRequest(env, "POST", "/api/v1/models/dragon-cup", {
61
59
  params: {
62
60
  height: 8,
@@ -147,10 +145,8 @@ export async function createDragonCupBatch(
147
145
 
148
146
  const { taskId, subTasks } = createData.data;
149
147
 
150
- // Poll compound task until all sub-tasks complete
151
148
  await pollUntilDone(env, taskId);
152
149
 
153
- // Fetch each sub-task result
154
150
  const downloadUrls: string[] = [];
155
151
  for (const sub of subTasks) {
156
152
  const resultRes = await apiRequest(env, "GET", `/api/v1/tasks/${sub.taskId}/result/glb`);
@@ -228,10 +224,6 @@ async function pollAndGetResult(env: Env, taskId: string): Promise<{ format: str
228
224
  return resultData.data.downloads;
229
225
  }
230
226
 
231
- // ---------------------------------------------------------------------------
232
- // Pipeline examples
233
- // ---------------------------------------------------------------------------
234
-
235
227
  async function submitPipeline(env: Env, body: unknown): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
236
228
  const createRes = await apiRequest(env, "POST", "/api/v1/cad/pipeline", body);
237
229
  if (!createRes.ok && createRes.status !== 202) {
@@ -249,9 +241,6 @@ async function submitPipeline(env: Env, body: unknown): Promise<{ taskId: string
249
241
  return { taskId, downloads };
250
242
  }
251
243
 
252
- /**
253
- * Translate, Union + Fillet: createBox → translate → union → fillet
254
- */
255
244
  export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
256
245
  return submitPipeline(env, {
257
246
  steps: [
@@ -264,9 +253,6 @@ export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskI
264
253
  });
265
254
  }
266
255
 
267
- /**
268
- * Map: Cylinders at Positions
269
- */
270
256
  export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
271
257
  return submitPipeline(env, {
272
258
  steps: [
@@ -282,9 +268,6 @@ export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: strin
282
268
  });
283
269
  }
284
270
 
285
- /**
286
- * Map: Spheres at Different Radii
287
- */
288
271
  export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
289
272
  return submitPipeline(env, {
290
273
  steps: [
@@ -303,9 +286,6 @@ export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string;
303
286
  });
304
287
  }
305
288
 
306
- /**
307
- * Choice: Conditional Shape Size
308
- */
309
289
  export async function runChoicePipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
310
290
  return submitPipeline(env, {
311
291
  steps: [
@@ -324,9 +304,6 @@ export async function runChoicePipeline(env: Env): Promise<{ taskId: string; dow
324
304
  });
325
305
  }
326
306
 
327
- /**
328
- * File-input pipeline: upload a STEP file, fillet all edges, export.
329
- */
330
307
  export async function runFileInputPipeline(env: Env, fileId: string): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
331
308
  return submitPipeline(env, {
332
309
  steps: [
@@ -338,11 +315,7 @@ export async function runFileInputPipeline(env: Env, fileId: string): Promise<{
338
315
  });
339
316
  }
340
317
 
341
- /**
342
- * Upload a file to the Bitbybit API, returns a fileId for use in pipelines.
343
- */
344
318
  export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: string): Promise<string> {
345
- // 1. Request a pre-signed upload URL
346
319
  const uploadRes = await apiRequest(env, "POST", "/api/v1/files/upload", {
347
320
  filename,
348
321
  contentType: "application/octet-stream",
@@ -361,7 +334,6 @@ export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: st
361
334
 
362
335
  const { fileId, uploadUrl } = uploadData.data;
363
336
 
364
- // 2. PUT raw bytes to the pre-signed URL
365
337
  const putRes = await fetch(uploadUrl, {
366
338
  method: "PUT",
367
339
  headers: { "Content-Type": "application/octet-stream" },
@@ -372,7 +344,6 @@ export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: st
372
344
  throw new Error(`PUT to upload URL failed: ${putRes.status} ${putRes.statusText}`);
373
345
  }
374
346
 
375
- // 3. Confirm the upload
376
347
  const confirmRes = await apiRequest(env, "POST", `/api/v1/files/${encodeURIComponent(fileId)}/confirm`);
377
348
  if (!confirmRes.ok) {
378
349
  const err = await confirmRes.text();
@@ -8,11 +8,10 @@ const app = express();
8
8
  app.use(express.json());
9
9
 
10
10
  const env: Env = {
11
- BITBYBIT_API_KEY: process.env.BITBYBIT_API_KEY ?? "",
12
- BITBYBIT_API_URL: process.env.BITBYBIT_API_URL ?? "https://api.bitbybit.dev",
11
+ BITBYBIT_API_KEY: process.env["BITBYBIT_API_KEY"] ?? "",
12
+ BITBYBIT_API_URL: process.env["BITBYBIT_API_URL"] ?? "https://api.bitbybit.dev",
13
13
  };
14
14
 
15
- // Check for missing API key and return a helpful error
16
15
  app.use("/api", (_req, res, next) => {
17
16
  if (!env.BITBYBIT_API_KEY) {
18
17
  res.status(503).json({
@@ -24,7 +23,6 @@ app.use("/api", (_req, res, next) => {
24
23
  next();
25
24
  });
26
25
 
27
- // Backend endpoint — calls bitbybit API with server-side API key
28
26
  app.post("/api/generate", async (_req, res) => {
29
27
  try {
30
28
  const result = await createDragonCup(env);
@@ -35,7 +33,6 @@ app.post("/api/generate", async (_req, res) => {
35
33
  }
36
34
  });
37
35
 
38
- // Batch generation — creates 3 dragon cup variations in parallel
39
36
  app.post("/api/generate-batch", async (_req, res) => {
40
37
  try {
41
38
  const result = await createDragonCupBatch(env);
@@ -46,7 +43,6 @@ app.post("/api/generate-batch", async (_req, res) => {
46
43
  }
47
44
  });
48
45
 
49
- // Fetch result for an existing task
50
46
  app.get("/api/task/:id", async (req, res) => {
51
47
  try {
52
48
  const taskId = req.params.id;
@@ -58,7 +54,6 @@ app.get("/api/task/:id", async (req, res) => {
58
54
  }
59
55
  });
60
56
 
61
- // Pipeline: translate → union → fillet
62
57
  app.post("/api/pipeline/translate-union-fillet", async (_req, res) => {
63
58
  try {
64
59
  const result = await runTranslateUnionFilletPipeline(env);
@@ -69,7 +64,6 @@ app.post("/api/pipeline/translate-union-fillet", async (_req, res) => {
69
64
  }
70
65
  });
71
66
 
72
- // Pipeline: map cylinders at positions
73
67
  app.post("/api/pipeline/map-cylinders", async (_req, res) => {
74
68
  try {
75
69
  const result = await runMapCylindersPipeline(env);
@@ -80,7 +74,6 @@ app.post("/api/pipeline/map-cylinders", async (_req, res) => {
80
74
  }
81
75
  });
82
76
 
83
- // Pipeline: map spheres at different radii
84
77
  app.post("/api/pipeline/map-spheres", async (_req, res) => {
85
78
  try {
86
79
  const result = await runMapSpheresPipeline(env);
@@ -91,7 +84,6 @@ app.post("/api/pipeline/map-spheres", async (_req, res) => {
91
84
  }
92
85
  });
93
86
 
94
- // Pipeline: choice conditional
95
87
  app.post("/api/pipeline/choice", async (_req, res) => {
96
88
  try {
97
89
  const result = await runChoicePipeline(env);
@@ -102,7 +94,6 @@ app.post("/api/pipeline/choice", async (_req, res) => {
102
94
  }
103
95
  });
104
96
 
105
- // Pipeline: file input (upload STEP → fillet)
106
97
  app.post("/api/pipeline/file-input", upload.single("file"), async (req, res) => {
107
98
  try {
108
99
  const file = req.file;
@@ -117,10 +108,9 @@ app.post("/api/pipeline/file-input", upload.single("file"), async (req, res) =>
117
108
  }
118
109
  });
119
110
 
120
- // Proxy download — streams a remote file through the backend to avoid CORS issues with GLTFLoader
121
111
  app.get("/api/proxy-download", async (req, res) => {
122
- const url = req.query.url as string | undefined;
123
- if (!url) { res.status(400).json({ error: "Missing url parameter" }); return; }
112
+ const url = req.query["url"];
113
+ if (typeof url !== "string" || url.length === 0) { res.status(400).json({ error: "Missing url parameter" }); return; }
124
114
 
125
115
  try {
126
116
  const response = await fetch(url);
@@ -128,7 +118,7 @@ app.get("/api/proxy-download", async (req, res) => {
128
118
  res.status(502).json({ error: `Upstream error: ${response.status}` });
129
119
  return;
130
120
  }
131
- res.setHeader("Content-Type", response.headers.get("Content-Type") || "model/gltf-binary");
121
+ res.setHeader("Content-Type", response.headers.get("Content-Type") ?? "model/gltf-binary");
132
122
  const arrayBuffer = await response.arrayBuffer();
133
123
  res.send(Buffer.from(arrayBuffer));
134
124
  } catch (e: unknown) {
@@ -137,7 +127,7 @@ app.get("/api/proxy-download", async (req, res) => {
137
127
  }
138
128
  });
139
129
 
140
- const PORT = parseInt(process.env.PORT ?? "3000", 10);
130
+ const PORT = parseInt(process.env["PORT"] ?? "3000", 10);
141
131
  app.listen(PORT, () => {
142
132
  console.log(`Server running at http://localhost:${PORT}`);
143
133
  });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "rootDir": "src",
6
+ "outDir": "dist"
7
+ },
8
+ "include": ["src"]
9
+ }
@@ -3,15 +3,25 @@
3
3
  "target": "ES2022",
4
4
  "module": "NodeNext",
5
5
  "moduleResolution": "NodeNext",
6
- "strict": true,
7
- "skipLibCheck": true,
8
6
  "lib": ["ES2022"],
9
7
  "types": ["node"],
10
- "outDir": "dist",
11
- "rootDir": "src",
12
- "resolveJsonModule": true,
8
+ "noEmit": true,
9
+ "strict": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "exactOptionalPropertyTypes": true,
12
+ "noImplicitReturns": true,
13
+ "noImplicitOverride": true,
14
+ "noPropertyAccessFromIndexSignature": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "noUnusedLocals": true,
17
+ "noUnusedParameters": true,
18
+ "useUnknownInCatchVariables": true,
19
+ "forceConsistentCasingInFileNames": true,
13
20
  "isolatedModules": true,
14
- "esModuleInterop": true
21
+ "verbatimModuleSyntax": true,
22
+ "erasableSyntaxOnly": true,
23
+ "noUncheckedSideEffectImports": true,
24
+ "skipLibCheck": true
15
25
  },
16
- "include": ["src/**/*.ts"]
26
+ "include": ["src", "scripts"]
17
27
  }
@@ -0,0 +1,47 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import eslint from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+ import noComments from "eslint-plugin-no-comments";
5
+
6
+ const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
7
+
8
+ export default defineConfig([
9
+ globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
10
+ {
11
+ files: ["**/*.ts"],
12
+ extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
13
+ plugins: { "no-comments": noComments },
14
+ languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
15
+ rules: {
16
+ quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
17
+ semi: ["error", "always"],
18
+ eqeqeq: ["error", "always"],
19
+ curly: ["error", "multi-line"],
20
+ "prefer-const": "error",
21
+ "no-var": "error",
22
+ "max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
23
+ "no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
24
+ "no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
25
+ "no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
26
+ "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
27
+ "@typescript-eslint/no-explicit-any": "error",
28
+ "@typescript-eslint/no-non-null-assertion": "error",
29
+ "@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
30
+ "@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
31
+ "@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
32
+ "@typescript-eslint/naming-convention": [
33
+ "error",
34
+ { selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
35
+ { selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
36
+ { selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
37
+ { selector: "typeLike", format: ["PascalCase"] },
38
+ { selector: "property", format: null },
39
+ { selector: "method", format: ["camelCase"] },
40
+ { selector: "import", format: null },
41
+ ],
42
+ "@typescript-eslint/only-throw-error": "error",
43
+ "@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
44
+ "@typescript-eslint/non-nullable-type-assertion-style": "off",
45
+ },
46
+ },
47
+ ]);
@@ -1,23 +1,30 @@
1
1
  {
2
2
  "name": "bitbybit-api-nodejs-sdk-threejs",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "tsx watch --env-file=.env src/index.ts",
8
- "build": "tsc",
9
- "start": "node --env-file=.env dist/index.js"
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "start": "node --env-file=.env dist/index.js",
10
+ "smoke": "npm run typecheck && npm run lint",
11
+ "typecheck": "tsc --noEmit",
12
+ "lint": "eslint . --max-warnings 0"
10
13
  },
11
14
  "dependencies": {
12
15
  "express": "^5.1.0",
13
16
  "multer": "^2.3.0",
14
- "@bitbybit-dev/cad-cloud-sdk": "1.3.2"
17
+ "@bitbybit-dev/cad-cloud-sdk": "1.4.0"
15
18
  },
16
19
  "devDependencies": {
20
+ "@eslint/js": "10.0.1",
17
21
  "@types/express": "^5.0.2",
18
22
  "@types/multer": "^2.2.0",
19
- "@types/node": "^22.15.0",
23
+ "@types/node": "22.20.1",
24
+ "eslint": "10.10.0",
25
+ "eslint-plugin-no-comments": "1.2.1",
20
26
  "tsx": "^4.19.0",
21
- "typescript": "^5.8.0"
27
+ "typescript": "5.9.3",
28
+ "typescript-eslint": "8.70.0"
22
29
  }
23
- }
30
+ }