@intellibiz/create-intellibiz 1.0.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/LICENSE +125 -0
- package/dist/index.cjs +258 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +261 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity.
|
|
18
|
+
|
|
19
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
20
|
+
exercising permissions granted by this License.
|
|
21
|
+
|
|
22
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
23
|
+
including but not limited to software source code, documentation
|
|
24
|
+
source, and configuration files.
|
|
25
|
+
|
|
26
|
+
"Object" form shall mean any form resulting from mechanical
|
|
27
|
+
transformation or translation of a Source form, including but
|
|
28
|
+
not limited to compiled object code, generated documentation,
|
|
29
|
+
and conversions to other media types.
|
|
30
|
+
|
|
31
|
+
"Work" shall mean the work of authorship made available under
|
|
32
|
+
the License, as indicated by a copyright notice that is included
|
|
33
|
+
in or attached to the work.
|
|
34
|
+
|
|
35
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
36
|
+
form, that is based on (or derived from) the Work and for which the
|
|
37
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
38
|
+
represent, as a whole, an original work of authorship.
|
|
39
|
+
|
|
40
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
41
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
42
|
+
authorized to submit on behalf of the copyright owner.
|
|
43
|
+
|
|
44
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
45
|
+
whom a Contribution has been received by the Licensor and included
|
|
46
|
+
within the Work.
|
|
47
|
+
|
|
48
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
49
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
50
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
51
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
52
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
53
|
+
Work and such Derivative Works in Source or Object form.
|
|
54
|
+
|
|
55
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
56
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
57
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
58
|
+
patent license to make, use, sell, offer for sale, import, and
|
|
59
|
+
otherwise transfer the Work.
|
|
60
|
+
|
|
61
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
62
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
63
|
+
modifications, and in Source or Object form, provided that You
|
|
64
|
+
meet the following conditions:
|
|
65
|
+
|
|
66
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
67
|
+
Works a copy of this License; and
|
|
68
|
+
|
|
69
|
+
(b) You must cause any modified files to carry prominent notices
|
|
70
|
+
stating that You changed the files; and
|
|
71
|
+
|
|
72
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
73
|
+
that You distribute, all copyright, patent, trademark, and
|
|
74
|
+
attribution notices from the Source form of the Work; and
|
|
75
|
+
|
|
76
|
+
(d) If the Work includes a "NOTICE" text file, you must include a
|
|
77
|
+
readable copy of the attribution notices contained within such
|
|
78
|
+
NOTICE file.
|
|
79
|
+
|
|
80
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
81
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
82
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
83
|
+
this License, without any additional terms or conditions.
|
|
84
|
+
|
|
85
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
86
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
87
|
+
|
|
88
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
89
|
+
agreed to in writing, Licensor provides the Work on an "AS IS"
|
|
90
|
+
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
91
|
+
or implied, including, without limitation, any warranties or
|
|
92
|
+
conditions of TITLE, MERCHANTIBILITY, or FITNESS FOR A PARTICULAR
|
|
93
|
+
PURPOSE. You are solely responsible for determining the
|
|
94
|
+
appropriateness of using or reproducing the Work.
|
|
95
|
+
|
|
96
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
97
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
98
|
+
unless required by applicable law, shall any Contributor be liable
|
|
99
|
+
to You for damages, including any direct, indirect, special,
|
|
100
|
+
incidental, or exemplary damages of any character arising as a
|
|
101
|
+
result of this License or out of the use or inability to use the
|
|
102
|
+
Work.
|
|
103
|
+
|
|
104
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
105
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
106
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
107
|
+
or other liability obligations and rights consistent with this
|
|
108
|
+
License. However, in accepting such obligations, You may offer such
|
|
109
|
+
conditions only on Your own behalf and on Your sole responsibility.
|
|
110
|
+
|
|
111
|
+
END OF TERMS AND CONDITIONS
|
|
112
|
+
|
|
113
|
+
Copyright 2025 Intellibiz
|
|
114
|
+
|
|
115
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
116
|
+
you may not use this file except in compliance with the License.
|
|
117
|
+
You may obtain a copy of the License at
|
|
118
|
+
|
|
119
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
120
|
+
|
|
121
|
+
Unless required by applicable law or agreed to in writing, software
|
|
122
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
123
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
124
|
+
See the License for the specific language governing permissions and
|
|
125
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
let citty = require("citty");
|
|
3
|
+
let consola = require("consola");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* create-intellibiz
|
|
9
|
+
*
|
|
10
|
+
* Usage: npx create-intellibiz my-app
|
|
11
|
+
*
|
|
12
|
+
* Scaffolds a new Intellibiz project with:
|
|
13
|
+
* - intellibiz.config.ts (full config reference)
|
|
14
|
+
* - src/index.ts (server entry with routes)
|
|
15
|
+
* - src/actions/ (sample defineAction handlers)
|
|
16
|
+
* - package.json (correct dependencies)
|
|
17
|
+
* - tsconfig.json
|
|
18
|
+
* - .env.example
|
|
19
|
+
* - .gitignore
|
|
20
|
+
* - README.md
|
|
21
|
+
*/
|
|
22
|
+
function template(name, vars) {
|
|
23
|
+
let content = TEMPLATES[name];
|
|
24
|
+
if (!content) throw new Error(`Template not found: ${name}`);
|
|
25
|
+
for (const [key, value] of Object.entries(vars)) content = content.replaceAll(`{{${key}}}`, value);
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
const TEMPLATES = {
|
|
29
|
+
"intellibiz.config.ts": `import { defineConfig } from 'intellibiz'
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
app: {
|
|
33
|
+
name: '{{APP_NAME}}',
|
|
34
|
+
env: 'development',
|
|
35
|
+
},
|
|
36
|
+
tenancy: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
strategy: 'header',
|
|
39
|
+
column: 'org_id',
|
|
40
|
+
strict: false,
|
|
41
|
+
},
|
|
42
|
+
database: {
|
|
43
|
+
provider: 'postgres',
|
|
44
|
+
poolSize: 10,
|
|
45
|
+
},
|
|
46
|
+
taxation: {
|
|
47
|
+
defaultCountry: 'ZA',
|
|
48
|
+
vatEnabled: true,
|
|
49
|
+
},
|
|
50
|
+
modules: {
|
|
51
|
+
commerce: { enabled: true },
|
|
52
|
+
identity: { enabled: true },
|
|
53
|
+
},
|
|
54
|
+
governance: {
|
|
55
|
+
ledgerEnabled: true,
|
|
56
|
+
allowSudo: false,
|
|
57
|
+
auditRetentionDays: 90,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
`,
|
|
61
|
+
"src/actions/health.ts": `import { defineAction } from 'intellibiz'
|
|
62
|
+
|
|
63
|
+
export const health = defineAction({
|
|
64
|
+
input: undefined,
|
|
65
|
+
handler: async () => {
|
|
66
|
+
return { status: 'ok', timestamp: new Date().toISOString() }
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
`,
|
|
70
|
+
"src/actions/create-order.ts": `import { defineAction } from 'intellibiz'
|
|
71
|
+
import { z } from 'zod'
|
|
72
|
+
|
|
73
|
+
const CreateOrderInput = z.object({
|
|
74
|
+
customerId: z.string(),
|
|
75
|
+
items: z.array(
|
|
76
|
+
z.object({
|
|
77
|
+
productId: z.string(),
|
|
78
|
+
quantity: z.number().int().positive(),
|
|
79
|
+
unitPrice: z.string(),
|
|
80
|
+
currency: z.string().default('USD'),
|
|
81
|
+
})
|
|
82
|
+
),
|
|
83
|
+
currency: z.string().default('USD'),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
export const createOrder = defineAction({
|
|
87
|
+
input: CreateOrderInput,
|
|
88
|
+
handler: async (action) => {
|
|
89
|
+
const { customerId, items, currency } = action.input
|
|
90
|
+
|
|
91
|
+
let totalMinor = 0
|
|
92
|
+
for (const item of items) {
|
|
93
|
+
const unitMinor = Math.round(parseFloat(item.unitPrice) * 100)
|
|
94
|
+
totalMinor += unitMinor * item.quantity
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
orderId: \`ord_\${Date.now()}\`,
|
|
99
|
+
customerId,
|
|
100
|
+
total: \`\${(totalMinor / 100).toFixed(2)}\`,
|
|
101
|
+
currency,
|
|
102
|
+
itemCount: items.length,
|
|
103
|
+
createdAt: new Date().toISOString(),
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
`,
|
|
108
|
+
"src/index.ts": `import { http } from 'intellibiz'
|
|
109
|
+
import { health } from './actions/health'
|
|
110
|
+
import { createOrder } from './actions/create-order'
|
|
111
|
+
|
|
112
|
+
http.get('/health', async () => {
|
|
113
|
+
return await health({})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
http.post('/orders', async (req) => {
|
|
117
|
+
return await createOrder(req.body as any)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
http.listen(3000, () => {
|
|
121
|
+
console.log(\`🚀 {{APP_NAME}} running on http://localhost:3000\`)
|
|
122
|
+
})
|
|
123
|
+
`,
|
|
124
|
+
"package.json": `{
|
|
125
|
+
"name": "{{APP_NAME}}",
|
|
126
|
+
"version": "0.1.0",
|
|
127
|
+
"private": true,
|
|
128
|
+
"type": "module",
|
|
129
|
+
"scripts": {
|
|
130
|
+
"dev": "tsx src/index.ts",
|
|
131
|
+
"build": "tsc",
|
|
132
|
+
"start": "node dist/index.js",
|
|
133
|
+
"lint": "tsc --noEmit"
|
|
134
|
+
},
|
|
135
|
+
"dependencies": {
|
|
136
|
+
"intellibiz": "^1.0.0",
|
|
137
|
+
"zod": "^3.23.0"
|
|
138
|
+
},
|
|
139
|
+
"devDependencies": {
|
|
140
|
+
"tsx": "^4.0.0",
|
|
141
|
+
"typescript": "^5.6.0",
|
|
142
|
+
"@types/node": "^22.0.0"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
`,
|
|
146
|
+
"tsconfig.json": `{
|
|
147
|
+
"compilerOptions": {
|
|
148
|
+
"target": "ES2022",
|
|
149
|
+
"module": "ESNext",
|
|
150
|
+
"moduleResolution": "bundler",
|
|
151
|
+
"strict": true,
|
|
152
|
+
"esModuleInterop": true,
|
|
153
|
+
"outDir": "dist",
|
|
154
|
+
"rootDir": "src",
|
|
155
|
+
"declaration": true,
|
|
156
|
+
"skipLibCheck": true,
|
|
157
|
+
"forceConsistentCasingInFileNames": true
|
|
158
|
+
},
|
|
159
|
+
"include": ["src"],
|
|
160
|
+
"exclude": ["node_modules", "dist"]
|
|
161
|
+
}
|
|
162
|
+
`,
|
|
163
|
+
".gitignore": `node_modules/
|
|
164
|
+
dist/
|
|
165
|
+
*.tsbuildinfo
|
|
166
|
+
.env
|
|
167
|
+
.env.local
|
|
168
|
+
`,
|
|
169
|
+
".env.example": `# Intellibiz Environment Variables
|
|
170
|
+
PORT=3000
|
|
171
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
|
|
172
|
+
JWT_SECRET=your-jwt-secret-change-me
|
|
173
|
+
STRIPE_SECRET_KEY=sk_test_...
|
|
174
|
+
STRIPE_WEBHOOK_SECRET=whsec_...
|
|
175
|
+
DEFAULT_TENANT=system
|
|
176
|
+
`,
|
|
177
|
+
"README.md": `# {{APP_NAME}}
|
|
178
|
+
|
|
179
|
+
Built with [Intellibiz](https://intellibiz.dev) — the Business Application Engine.
|
|
180
|
+
|
|
181
|
+
## Getting Started
|
|
182
|
+
|
|
183
|
+
\`\`\`bash
|
|
184
|
+
pnpm install
|
|
185
|
+
pnpm dev
|
|
186
|
+
\`\`\`
|
|
187
|
+
|
|
188
|
+
Server runs at http://localhost:3000
|
|
189
|
+
|
|
190
|
+
## Project Structure
|
|
191
|
+
|
|
192
|
+
\`\`\`
|
|
193
|
+
src/
|
|
194
|
+
├── actions/
|
|
195
|
+
│ ├── health.ts
|
|
196
|
+
│ └── create-order.ts
|
|
197
|
+
└── index.ts
|
|
198
|
+
intellibiz.config.ts
|
|
199
|
+
\`\`\`
|
|
200
|
+
|
|
201
|
+
## Docs
|
|
202
|
+
|
|
203
|
+
- [Intellibiz Guide](https://intellibiz.dev/docs)
|
|
204
|
+
- [Quick Start](https://intellibiz.dev/docs/quick-start)
|
|
205
|
+
- [API Reference](https://intellibiz.dev/docs/api)
|
|
206
|
+
`
|
|
207
|
+
};
|
|
208
|
+
const main = (0, citty.defineCommand)({
|
|
209
|
+
meta: {
|
|
210
|
+
name: "create-intellibiz",
|
|
211
|
+
description: "Create a new Intellibiz project",
|
|
212
|
+
version: "1.0.0"
|
|
213
|
+
},
|
|
214
|
+
args: {
|
|
215
|
+
name: {
|
|
216
|
+
type: "positional",
|
|
217
|
+
description: "Project name",
|
|
218
|
+
required: false
|
|
219
|
+
},
|
|
220
|
+
dir: {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Target directory (defaults to project name)"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
async run({ args }) {
|
|
226
|
+
const appName = args.name || "my-intellibiz-app";
|
|
227
|
+
const targetDir = (0, node_path.resolve)(args.dir || `./${appName}`);
|
|
228
|
+
console.log("");
|
|
229
|
+
consola.consola.start(`Creating Intellibiz project: ${appName}`);
|
|
230
|
+
console.log("");
|
|
231
|
+
if ((0, node_fs.existsSync)(targetDir) && (0, node_fs.readdirSync)(targetDir).length > 0) {
|
|
232
|
+
consola.consola.error(`Directory already exists and is not empty: ${targetDir}`);
|
|
233
|
+
consola.consola.info("Please use an empty directory or remove it first.");
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
(0, node_fs.mkdirSync)(targetDir, { recursive: true });
|
|
237
|
+
const vars = { APP_NAME: appName };
|
|
238
|
+
for (const [filePath] of Object.entries(TEMPLATES)) {
|
|
239
|
+
const fullPath = (0, node_path.join)(targetDir, filePath);
|
|
240
|
+
const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
|
|
241
|
+
(0, node_fs.mkdirSync)(dir, { recursive: true });
|
|
242
|
+
(0, node_fs.writeFileSync)(fullPath, template(filePath, vars), "utf-8");
|
|
243
|
+
consola.consola.success(` ${filePath}`);
|
|
244
|
+
}
|
|
245
|
+
console.log("");
|
|
246
|
+
consola.consola.success(`Project "${appName}" created at ${targetDir}`);
|
|
247
|
+
console.log("");
|
|
248
|
+
consola.consola.box([
|
|
249
|
+
` cd ${appName}`,
|
|
250
|
+
" pnpm install",
|
|
251
|
+
" pnpm dev",
|
|
252
|
+
"",
|
|
253
|
+
" Then open http://localhost:3000/health"
|
|
254
|
+
].join("\n"));
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
(0, citty.runMain)(main);
|
|
258
|
+
//#endregion
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import { consola } from "consola";
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* create-intellibiz
|
|
9
|
+
*
|
|
10
|
+
* Usage: npx create-intellibiz my-app
|
|
11
|
+
*
|
|
12
|
+
* Scaffolds a new Intellibiz project with:
|
|
13
|
+
* - intellibiz.config.ts (full config reference)
|
|
14
|
+
* - src/index.ts (server entry with routes)
|
|
15
|
+
* - src/actions/ (sample defineAction handlers)
|
|
16
|
+
* - package.json (correct dependencies)
|
|
17
|
+
* - tsconfig.json
|
|
18
|
+
* - .env.example
|
|
19
|
+
* - .gitignore
|
|
20
|
+
* - README.md
|
|
21
|
+
*/
|
|
22
|
+
function template(name, vars) {
|
|
23
|
+
let content = TEMPLATES[name];
|
|
24
|
+
if (!content) throw new Error(`Template not found: ${name}`);
|
|
25
|
+
for (const [key, value] of Object.entries(vars)) content = content.replaceAll(`{{${key}}}`, value);
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
const TEMPLATES = {
|
|
29
|
+
"intellibiz.config.ts": `import { defineConfig } from 'intellibiz'
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
app: {
|
|
33
|
+
name: '{{APP_NAME}}',
|
|
34
|
+
env: 'development',
|
|
35
|
+
},
|
|
36
|
+
tenancy: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
strategy: 'header',
|
|
39
|
+
column: 'org_id',
|
|
40
|
+
strict: false,
|
|
41
|
+
},
|
|
42
|
+
database: {
|
|
43
|
+
provider: 'postgres',
|
|
44
|
+
poolSize: 10,
|
|
45
|
+
},
|
|
46
|
+
taxation: {
|
|
47
|
+
defaultCountry: 'ZA',
|
|
48
|
+
vatEnabled: true,
|
|
49
|
+
},
|
|
50
|
+
modules: {
|
|
51
|
+
commerce: { enabled: true },
|
|
52
|
+
identity: { enabled: true },
|
|
53
|
+
},
|
|
54
|
+
governance: {
|
|
55
|
+
ledgerEnabled: true,
|
|
56
|
+
allowSudo: false,
|
|
57
|
+
auditRetentionDays: 90,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
`,
|
|
61
|
+
"src/actions/health.ts": `import { defineAction } from 'intellibiz'
|
|
62
|
+
|
|
63
|
+
export const health = defineAction({
|
|
64
|
+
input: undefined,
|
|
65
|
+
handler: async () => {
|
|
66
|
+
return { status: 'ok', timestamp: new Date().toISOString() }
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
`,
|
|
70
|
+
"src/actions/create-order.ts": `import { defineAction } from 'intellibiz'
|
|
71
|
+
import { z } from 'zod'
|
|
72
|
+
|
|
73
|
+
const CreateOrderInput = z.object({
|
|
74
|
+
customerId: z.string(),
|
|
75
|
+
items: z.array(
|
|
76
|
+
z.object({
|
|
77
|
+
productId: z.string(),
|
|
78
|
+
quantity: z.number().int().positive(),
|
|
79
|
+
unitPrice: z.string(),
|
|
80
|
+
currency: z.string().default('USD'),
|
|
81
|
+
})
|
|
82
|
+
),
|
|
83
|
+
currency: z.string().default('USD'),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
export const createOrder = defineAction({
|
|
87
|
+
input: CreateOrderInput,
|
|
88
|
+
handler: async (action) => {
|
|
89
|
+
const { customerId, items, currency } = action.input
|
|
90
|
+
|
|
91
|
+
let totalMinor = 0
|
|
92
|
+
for (const item of items) {
|
|
93
|
+
const unitMinor = Math.round(parseFloat(item.unitPrice) * 100)
|
|
94
|
+
totalMinor += unitMinor * item.quantity
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
orderId: \`ord_\${Date.now()}\`,
|
|
99
|
+
customerId,
|
|
100
|
+
total: \`\${(totalMinor / 100).toFixed(2)}\`,
|
|
101
|
+
currency,
|
|
102
|
+
itemCount: items.length,
|
|
103
|
+
createdAt: new Date().toISOString(),
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
`,
|
|
108
|
+
"src/index.ts": `import { http } from 'intellibiz'
|
|
109
|
+
import { health } from './actions/health'
|
|
110
|
+
import { createOrder } from './actions/create-order'
|
|
111
|
+
|
|
112
|
+
http.get('/health', async () => {
|
|
113
|
+
return await health({})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
http.post('/orders', async (req) => {
|
|
117
|
+
return await createOrder(req.body as any)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
http.listen(3000, () => {
|
|
121
|
+
console.log(\`🚀 {{APP_NAME}} running on http://localhost:3000\`)
|
|
122
|
+
})
|
|
123
|
+
`,
|
|
124
|
+
"package.json": `{
|
|
125
|
+
"name": "{{APP_NAME}}",
|
|
126
|
+
"version": "0.1.0",
|
|
127
|
+
"private": true,
|
|
128
|
+
"type": "module",
|
|
129
|
+
"scripts": {
|
|
130
|
+
"dev": "tsx src/index.ts",
|
|
131
|
+
"build": "tsc",
|
|
132
|
+
"start": "node dist/index.js",
|
|
133
|
+
"lint": "tsc --noEmit"
|
|
134
|
+
},
|
|
135
|
+
"dependencies": {
|
|
136
|
+
"intellibiz": "^1.0.0",
|
|
137
|
+
"zod": "^3.23.0"
|
|
138
|
+
},
|
|
139
|
+
"devDependencies": {
|
|
140
|
+
"tsx": "^4.0.0",
|
|
141
|
+
"typescript": "^5.6.0",
|
|
142
|
+
"@types/node": "^22.0.0"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
`,
|
|
146
|
+
"tsconfig.json": `{
|
|
147
|
+
"compilerOptions": {
|
|
148
|
+
"target": "ES2022",
|
|
149
|
+
"module": "ESNext",
|
|
150
|
+
"moduleResolution": "bundler",
|
|
151
|
+
"strict": true,
|
|
152
|
+
"esModuleInterop": true,
|
|
153
|
+
"outDir": "dist",
|
|
154
|
+
"rootDir": "src",
|
|
155
|
+
"declaration": true,
|
|
156
|
+
"skipLibCheck": true,
|
|
157
|
+
"forceConsistentCasingInFileNames": true
|
|
158
|
+
},
|
|
159
|
+
"include": ["src"],
|
|
160
|
+
"exclude": ["node_modules", "dist"]
|
|
161
|
+
}
|
|
162
|
+
`,
|
|
163
|
+
".gitignore": `node_modules/
|
|
164
|
+
dist/
|
|
165
|
+
*.tsbuildinfo
|
|
166
|
+
.env
|
|
167
|
+
.env.local
|
|
168
|
+
`,
|
|
169
|
+
".env.example": `# Intellibiz Environment Variables
|
|
170
|
+
PORT=3000
|
|
171
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
|
|
172
|
+
JWT_SECRET=your-jwt-secret-change-me
|
|
173
|
+
STRIPE_SECRET_KEY=sk_test_...
|
|
174
|
+
STRIPE_WEBHOOK_SECRET=whsec_...
|
|
175
|
+
DEFAULT_TENANT=system
|
|
176
|
+
`,
|
|
177
|
+
"README.md": `# {{APP_NAME}}
|
|
178
|
+
|
|
179
|
+
Built with [Intellibiz](https://intellibiz.dev) — the Business Application Engine.
|
|
180
|
+
|
|
181
|
+
## Getting Started
|
|
182
|
+
|
|
183
|
+
\`\`\`bash
|
|
184
|
+
pnpm install
|
|
185
|
+
pnpm dev
|
|
186
|
+
\`\`\`
|
|
187
|
+
|
|
188
|
+
Server runs at http://localhost:3000
|
|
189
|
+
|
|
190
|
+
## Project Structure
|
|
191
|
+
|
|
192
|
+
\`\`\`
|
|
193
|
+
src/
|
|
194
|
+
├── actions/
|
|
195
|
+
│ ├── health.ts
|
|
196
|
+
│ └── create-order.ts
|
|
197
|
+
└── index.ts
|
|
198
|
+
intellibiz.config.ts
|
|
199
|
+
\`\`\`
|
|
200
|
+
|
|
201
|
+
## Docs
|
|
202
|
+
|
|
203
|
+
- [Intellibiz Guide](https://intellibiz.dev/docs)
|
|
204
|
+
- [Quick Start](https://intellibiz.dev/docs/quick-start)
|
|
205
|
+
- [API Reference](https://intellibiz.dev/docs/api)
|
|
206
|
+
`
|
|
207
|
+
};
|
|
208
|
+
const main = defineCommand({
|
|
209
|
+
meta: {
|
|
210
|
+
name: "create-intellibiz",
|
|
211
|
+
description: "Create a new Intellibiz project",
|
|
212
|
+
version: "1.0.0"
|
|
213
|
+
},
|
|
214
|
+
args: {
|
|
215
|
+
name: {
|
|
216
|
+
type: "positional",
|
|
217
|
+
description: "Project name",
|
|
218
|
+
required: false
|
|
219
|
+
},
|
|
220
|
+
dir: {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Target directory (defaults to project name)"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
async run({ args }) {
|
|
226
|
+
const appName = args.name || "my-intellibiz-app";
|
|
227
|
+
const targetDir = resolve(args.dir || `./${appName}`);
|
|
228
|
+
console.log("");
|
|
229
|
+
consola.start(`Creating Intellibiz project: ${appName}`);
|
|
230
|
+
console.log("");
|
|
231
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
232
|
+
consola.error(`Directory already exists and is not empty: ${targetDir}`);
|
|
233
|
+
consola.info("Please use an empty directory or remove it first.");
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
mkdirSync(targetDir, { recursive: true });
|
|
237
|
+
const vars = { APP_NAME: appName };
|
|
238
|
+
for (const [filePath] of Object.entries(TEMPLATES)) {
|
|
239
|
+
const fullPath = join(targetDir, filePath);
|
|
240
|
+
const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
|
|
241
|
+
mkdirSync(dir, { recursive: true });
|
|
242
|
+
writeFileSync(fullPath, template(filePath, vars), "utf-8");
|
|
243
|
+
consola.success(` ${filePath}`);
|
|
244
|
+
}
|
|
245
|
+
console.log("");
|
|
246
|
+
consola.success(`Project "${appName}" created at ${targetDir}`);
|
|
247
|
+
console.log("");
|
|
248
|
+
consola.box([
|
|
249
|
+
` cd ${appName}`,
|
|
250
|
+
" pnpm install",
|
|
251
|
+
" pnpm dev",
|
|
252
|
+
"",
|
|
253
|
+
" Then open http://localhost:3000/health"
|
|
254
|
+
].join("\n"));
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
runMain(main);
|
|
258
|
+
//#endregion
|
|
259
|
+
export {};
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * create-intellibiz\n *\n * Usage: npx create-intellibiz my-app\n *\n * Scaffolds a new Intellibiz project with:\n * - intellibiz.config.ts (full config reference)\n * - src/index.ts (server entry with routes)\n * - src/actions/ (sample defineAction handlers)\n * - package.json (correct dependencies)\n * - tsconfig.json\n * - .env.example\n * - .gitignore\n * - README.md\n */\nimport { defineCommand, runMain } from 'citty';\nimport { consola } from 'consola';\nimport { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\n// ─── Inline Templates ────────────────────────────────────────────────────────\n// Kept inline so create-intellibiz has zero runtime deps beyond citty+consola.\n\nfunction template(name: string, vars: Record<string, string>): string {\n let content = TEMPLATES[name];\n if (!content) throw new Error(`Template not found: ${name}`);\n for (const [key, value] of Object.entries(vars)) {\n content = content.replaceAll(`{{${key}}}`, value);\n }\n return content;\n}\n\nconst TEMPLATES: Record<string, string> = {\n 'intellibiz.config.ts': `import { defineConfig } from 'intellibiz'\n\nexport default defineConfig({\n app: {\n name: '{{APP_NAME}}',\n env: 'development',\n },\n tenancy: {\n enabled: true,\n strategy: 'header',\n column: 'org_id',\n strict: false,\n },\n database: {\n provider: 'postgres',\n poolSize: 10,\n },\n taxation: {\n defaultCountry: 'ZA',\n vatEnabled: true,\n },\n modules: {\n commerce: { enabled: true },\n identity: { enabled: true },\n },\n governance: {\n ledgerEnabled: true,\n allowSudo: false,\n auditRetentionDays: 90,\n },\n})\n`,\n\n 'src/actions/health.ts': `import { defineAction } from 'intellibiz'\n\nexport const health = defineAction({\n input: undefined,\n handler: async () => {\n return { status: 'ok', timestamp: new Date().toISOString() }\n },\n})\n`,\n\n 'src/actions/create-order.ts': `import { defineAction } from 'intellibiz'\nimport { z } from 'zod'\n\nconst CreateOrderInput = z.object({\n customerId: z.string(),\n items: z.array(\n z.object({\n productId: z.string(),\n quantity: z.number().int().positive(),\n unitPrice: z.string(),\n currency: z.string().default('USD'),\n })\n ),\n currency: z.string().default('USD'),\n})\n\nexport const createOrder = defineAction({\n input: CreateOrderInput,\n handler: async (action) => {\n const { customerId, items, currency } = action.input\n\n let totalMinor = 0\n for (const item of items) {\n const unitMinor = Math.round(parseFloat(item.unitPrice) * 100)\n totalMinor += unitMinor * item.quantity\n }\n\n return {\n orderId: \\`ord_\\${Date.now()}\\`,\n customerId,\n total: \\`\\${(totalMinor / 100).toFixed(2)}\\`,\n currency,\n itemCount: items.length,\n createdAt: new Date().toISOString(),\n }\n },\n})\n`,\n\n 'src/index.ts': `import { http } from 'intellibiz'\nimport { health } from './actions/health'\nimport { createOrder } from './actions/create-order'\n\nhttp.get('/health', async () => {\n return await health({})\n})\n\nhttp.post('/orders', async (req) => {\n return await createOrder(req.body as any)\n})\n\nhttp.listen(3000, () => {\n console.log(\\`🚀 {{APP_NAME}} running on http://localhost:3000\\`)\n})\n`,\n\n 'package.json': `{\n \"name\": \"{{APP_NAME}}\",\n \"version\": \"0.1.0\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"tsx src/index.ts\",\n \"build\": \"tsc\",\n \"start\": \"node dist/index.js\",\n \"lint\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"intellibiz\": \"^1.0.0\",\n \"zod\": \"^3.23.0\"\n },\n \"devDependencies\": {\n \"tsx\": \"^4.0.0\",\n \"typescript\": \"^5.6.0\",\n \"@types/node\": \"^22.0.0\"\n }\n}\n`,\n\n 'tsconfig.json': `{\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"module\": \"ESNext\",\n \"moduleResolution\": \"bundler\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"outDir\": \"dist\",\n \"rootDir\": \"src\",\n \"declaration\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true\n },\n \"include\": [\"src\"],\n \"exclude\": [\"node_modules\", \"dist\"]\n}\n`,\n\n '.gitignore': `node_modules/\ndist/\n*.tsbuildinfo\n.env\n.env.local\n`,\n\n '.env.example': `# Intellibiz Environment Variables\nPORT=3000\nDATABASE_URL=postgresql://user:password@localhost:5432/mydb\nJWT_SECRET=your-jwt-secret-change-me\nSTRIPE_SECRET_KEY=sk_test_...\nSTRIPE_WEBHOOK_SECRET=whsec_...\nDEFAULT_TENANT=system\n`,\n\n 'README.md': `# {{APP_NAME}}\n\nBuilt with [Intellibiz](https://intellibiz.dev) — the Business Application Engine.\n\n## Getting Started\n\n\\`\\`\\`bash\npnpm install\npnpm dev\n\\`\\`\\`\n\nServer runs at http://localhost:3000\n\n## Project Structure\n\n\\`\\`\\`\nsrc/\n├── actions/\n│ ├── health.ts\n│ └── create-order.ts\n└── index.ts\nintellibiz.config.ts\n\\`\\`\\`\n\n## Docs\n\n- [Intellibiz Guide](https://intellibiz.dev/docs)\n- [Quick Start](https://intellibiz.dev/docs/quick-start)\n- [API Reference](https://intellibiz.dev/docs/api)\n`,\n};\n\n// ─── CLI ─────────────────────────────────────────────────────────────────────\n\nconst main = defineCommand({\n meta: {\n name: 'create-intellibiz',\n description: 'Create a new Intellibiz project',\n version: '1.0.0',\n },\n args: {\n name: {\n type: 'positional',\n description: 'Project name',\n required: false,\n },\n dir: {\n type: 'string',\n description: 'Target directory (defaults to project name)',\n },\n },\n async run({ args }) {\n const appName = (args.name as string) || 'my-intellibiz-app';\n const targetDir = resolve((args.dir as string) || `./${appName}`);\n\n console.log('');\n consola.start(`Creating Intellibiz project: ${appName}`);\n console.log('');\n\n // Check target\n if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {\n consola.error(`Directory already exists and is not empty: ${targetDir}`);\n consola.info('Please use an empty directory or remove it first.');\n process.exit(1);\n }\n\n mkdirSync(targetDir, { recursive: true });\n\n const vars = { APP_NAME: appName };\n\n for (const [filePath] of Object.entries(TEMPLATES)) {\n const fullPath = join(targetDir, filePath);\n const dir = fullPath.substring(0, fullPath.lastIndexOf('/'));\n mkdirSync(dir, { recursive: true });\n writeFileSync(fullPath, template(filePath, vars), 'utf-8');\n consola.success(` ${filePath}`);\n }\n\n console.log('');\n consola.success(`Project \"${appName}\" created at ${targetDir}`);\n console.log('');\n consola.box([\n ` cd ${appName}`,\n ' pnpm install',\n ' pnpm dev',\n '',\n ' Then open http://localhost:3000/health',\n ].join('\\n'));\n },\n});\n\nrunMain(main);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,SAAS,MAAc,MAAsC;CACpE,IAAI,UAAU,UAAU;CACxB,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,uBAAuB,MAAM;CAC3D,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAC5C,UAAU,QAAQ,WAAW,KAAK,IAAI,KAAK,KAAK;CAElD,OAAO;AACT;AAEA,MAAM,YAAoC;CACxC,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCxB,yBAAyB;;;;;;;;;CAUzB,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC/B,gBAAgB;;;;;;;;;;;;;;;;CAiBhB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;CAuBhB,iBAAiB;;;;;;;;;;;;;;;;;CAkBjB,cAAc;;;;;;CAOd,gBAAgB;;;;;;;;CAShB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Bf;AAIA,MAAM,OAAO,cAAc;CACzB,MAAM;EACJ,MAAM;EACN,aAAa;EACb,SAAS;CACX;CACA,MAAM;EACJ,MAAM;GACJ,MAAM;GACN,aAAa;GACb,UAAU;EACZ;EACA,KAAK;GACH,MAAM;GACN,aAAa;EACf;CACF;CACA,MAAM,IAAI,EAAE,QAAQ;EAClB,MAAM,UAAW,KAAK,QAAmB;EACzC,MAAM,YAAY,QAAS,KAAK,OAAkB,KAAK,SAAS;EAEhE,QAAQ,IAAI,EAAE;EACd,QAAQ,MAAM,gCAAgC,SAAS;EACvD,QAAQ,IAAI,EAAE;EAGd,IAAI,WAAW,SAAS,KAAK,YAAY,SAAS,CAAC,CAAC,SAAS,GAAG;GAC9D,QAAQ,MAAM,8CAA8C,WAAW;GACvE,QAAQ,KAAK,mDAAmD;GAChE,QAAQ,KAAK,CAAC;EAChB;EAEA,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;EAExC,MAAM,OAAO,EAAE,UAAU,QAAQ;EAEjC,KAAK,MAAM,CAAC,aAAa,OAAO,QAAQ,SAAS,GAAG;GAClD,MAAM,WAAW,KAAK,WAAW,QAAQ;GACzC,MAAM,MAAM,SAAS,UAAU,GAAG,SAAS,YAAY,GAAG,CAAC;GAC3D,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;GAClC,cAAc,UAAU,SAAS,UAAU,IAAI,GAAG,OAAO;GACzD,QAAQ,QAAQ,KAAK,UAAU;EACjC;EAEA,QAAQ,IAAI,EAAE;EACd,QAAQ,QAAQ,YAAY,QAAQ,eAAe,WAAW;EAC9D,QAAQ,IAAI,EAAE;EACd,QAAQ,IAAI;GACV,QAAQ;GACR;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI,CAAC;CACd;AACF,CAAC;AAED,QAAQ,IAAI"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intellibiz/create-intellibiz",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Create a new Intellibiz project with npx create-intellibiz",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"bin": {
|
|
9
|
+
"create-intellibiz": "./dist/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"citty": "^0.1.6",
|
|
17
|
+
"consola": "^3.4.2"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.0.0",
|
|
21
|
+
"tsdown": "^0.22.14",
|
|
22
|
+
"typescript": "^5.8.3"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsdown src/index.ts --format esm,cjs --dts --clean",
|
|
29
|
+
"dev": "tsdown src/index.ts --format esm,cjs --dts --watch"
|
|
30
|
+
}
|
|
31
|
+
}
|