create-erxes 0.0.0-stage → 0.1.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/README.md +23 -2
- package/dist/index.js +481 -0
- package/dist/templates/base/.agents/skills/endpoint/SKILL.md +21 -0
- package/dist/templates/base/.agents/skills/schema-change/SKILL.md +28 -0
- package/dist/templates/base/.agents/skills/verify/SKILL.md +24 -0
- package/dist/templates/base/.github/workflows/ci.yml +44 -0
- package/dist/templates/base/AGENTS.md +60 -0
- package/dist/templates/base/CLAUDE.md +1 -0
- package/dist/templates/base/Dockerfile +13 -0
- package/dist/templates/base/_dockerignore +4 -0
- package/dist/templates/base/_env.example +15 -0
- package/dist/templates/base/_gitignore +11 -0
- package/dist/templates/base/_node-version +1 -0
- package/dist/templates/base/api/AGENTS.md +22 -0
- package/dist/templates/base/api/drizzle/0000_items.sql +13 -0
- package/dist/templates/base/api/drizzle/meta/0000_snapshot.json +126 -0
- package/dist/templates/base/api/drizzle/meta/_journal.json +13 -0
- package/dist/templates/base/api/drizzle.config.ts +16 -0
- package/dist/templates/base/api/openapi.json +450 -0
- package/dist/templates/base/api/package.json +50 -0
- package/dist/templates/base/api/scripts/openapi.ts +27 -0
- package/dist/templates/base/api/src/__tests__/server.test.ts +51 -0
- package/dist/templates/base/api/src/config.ts +43 -0
- package/dist/templates/base/api/src/core.ts +37 -0
- package/dist/templates/base/api/src/db/client.ts +30 -0
- package/dist/templates/base/api/src/db/migrate.ts +86 -0
- package/dist/templates/base/api/src/db/schema.ts +34 -0
- package/dist/templates/base/api/src/db/table.ts +8 -0
- package/dist/templates/base/api/src/logger.ts +5 -0
- package/dist/templates/base/api/src/main.ts +23 -0
- package/dist/templates/base/api/src/modules/items/__tests__/items.test.ts +86 -0
- package/dist/templates/base/api/src/modules/items/items.ts +121 -0
- package/dist/templates/base/api/src/orpc.ts +25 -0
- package/dist/templates/base/api/src/router.ts +10 -0
- package/dist/templates/base/api/src/server.ts +58 -0
- package/dist/templates/base/api/src/telemetry.ts +27 -0
- package/dist/templates/base/api/src/test/core-functions.sql +18 -0
- package/dist/templates/base/api/src/test/setup.ts +68 -0
- package/dist/templates/base/api/tsconfig.json +9 -0
- package/dist/templates/base/knip.ts +22 -0
- package/dist/templates/base/package.json +31 -0
- package/dist/templates/base/pnpm-workspace.yaml +20 -0
- package/dist/templates/base/tools/check-generated.ts +78 -0
- package/dist/templates/base/tools/check-rls.sh +30 -0
- package/dist/templates/base/tools/check-rls.sql +109 -0
- package/dist/templates/base/tools/no-org-id.sql +5 -0
- package/dist/templates/base/tools/test/no-skips.ts +58 -0
- package/dist/templates/base/tsconfig.base.json +16 -0
- package/dist/templates/base/tsconfig.json +9 -0
- package/dist/templates/base/ui/AGENTS.md +18 -0
- package/dist/templates/base/ui/package.json +32 -0
- package/dist/templates/base/ui/rsbuild.config.ts +36 -0
- package/dist/templates/base/ui/src/__Pascal__.tsx +9 -0
- package/dist/templates/base/ui/src/config.tsx +11 -0
- package/dist/templates/base/ui/src/index.ts +3 -0
- package/dist/templates/base/ui/src/items/ItemSheet.tsx +107 -0
- package/dist/templates/base/ui/src/items/ItemsPage.tsx +116 -0
- package/dist/templates/base/ui/src/items/useItems.ts +79 -0
- package/dist/templates/base/ui/src/orpc.ts +32 -0
- package/dist/templates/base/ui/tsconfig.json +11 -0
- package/dist/templates/base/vite.config.ts +63 -0
- package/dist/templates/migrate/.agents/skills/plugin-migrate/SKILL.md +61 -0
- package/dist/templates/migrate/migration/checklist.ts +429 -0
- package/dist/templates/migrate/migration/core-map.ts +149 -0
- package/dist/templates/migrate/migration/import-map.ts +4 -0
- package/dist/templates/migrate/migration/inventory.ts +881 -0
- package/dist/templates/migrate/package.json +15 -0
- package/dist/templates/migrate/scripts/import-mongo.ts +143 -0
- package/package.json +32 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# __title__
|
|
2
|
+
|
|
3
|
+
__description__
|
|
4
|
+
|
|
5
|
+
An erxes plugin for the new core (Postgres). `api/` is the API: Express 5,
|
|
6
|
+
oRPC and Drizzle. `ui/` is the Module Federation remote web loads. Read the
|
|
7
|
+
`AGENTS.md` in the folder you edit. `api/src/modules/items` and `ui/src/items`
|
|
8
|
+
are the reference feature: copy their shape for a new one.
|
|
9
|
+
|
|
10
|
+
<!-- quality:start -->
|
|
11
|
+
|
|
12
|
+
## Quality
|
|
13
|
+
|
|
14
|
+
Every erxes repo on the new stack has this section, unchanged. The brackets name the checks that
|
|
15
|
+
enforce a rule; `review` marks the part no tool can check. The rewrite keeps every feature and improves the
|
|
16
|
+
architecture. Agents write the code and the checks judge it, so a green check lets a change ship
|
|
17
|
+
without line-by-line review.
|
|
18
|
+
|
|
19
|
+
- `vp run check` is the type check: oxfmt, type-aware oxlint on tsrs and knip in about 10 s. Run it after each edit and before each commit; it replaces `tsc`. `vp run fix` formats and autofixes. [vp run check]
|
|
20
|
+
- Port what a feature does, not its code. Fix what the old code got wrong instead of carrying it over. [review]
|
|
21
|
+
- Use a maintained library when one does the job. Keep dependencies near their latest release and off deprecated APIs. [typescript/no-deprecated, review]
|
|
22
|
+
- One way to do each job. Search for the existing helper before writing one, merge the repeats you find, delete what nothing uses. [knip, review]
|
|
23
|
+
- Types flow from the database schema to the contract to the UI. Infer them, so each shape is written once. [pnpm check:generated, review]
|
|
24
|
+
- Parse outside input with zod and narrow it, so the code needs no `any`, cast or `!`. [typescript/no-explicit-any, typescript/no-unsafe-type-assertion, typescript/no-non-null-assertion]
|
|
25
|
+
- Lint and type rules are the spec: when one fires, fix the code. Silencing it is never the fix, whether by a disable comment, `@ts-ignore`, an override, an ignore, a weaker option or a raised limit. A rule that is wrong changes in its own PR. [typescript/ban-ts-comment, review]
|
|
26
|
+
- Split a file or function that outgrows its limit by responsibility (router, service, queries). [max-lines, max-lines-per-function, review]
|
|
27
|
+
- Finish the work in the change, with no TODO or FIXME left in code. [no-warning-comments]
|
|
28
|
+
- Tests call the public interface (HTTP, the typed client, the rendered page) and assert what it does, never source strings or code shapes. [review]
|
|
29
|
+
- Every test runs: a skipped test or an empty suite fails the run. A failing test gets its code or its wrong expectation fixed, never loosened or deleted. [vp run test, review]
|
|
30
|
+
- Log through the structured logger, with the facts as fields. A caught error is rethrown or logged with its context. [no-console, review]
|
|
31
|
+
- Make the long-term change in one go, with no backward-compatibility shim, stopgap or speculative option. [review]
|
|
32
|
+
- Docs, PRs and copy are short: plain words, active voice, what it does or the number. [review]
|
|
33
|
+
|
|
34
|
+
<!-- quality:end -->
|
|
35
|
+
|
|
36
|
+
## This repo
|
|
37
|
+
|
|
38
|
+
- `vp run check` runs the escape guard, format, lint, types, knip, the docs guard
|
|
39
|
+
and `pnpm check:generated`. The drift check compares migrations with the schema
|
|
40
|
+
and `api/openapi.json` with the router's request and response schemas. After a
|
|
41
|
+
deliberate contract change, run `pnpm openapi` and commit the document.
|
|
42
|
+
- Other gates: `vp run test` on real Postgres via `DATA_TEST_URL`,
|
|
43
|
+
`pnpm check:rls`, `pnpm build`. `vp run fix` formats and fixes lint.
|
|
44
|
+
- Core finds the plugin by these names, so they stay fixed: plugin `__id__`,
|
|
45
|
+
remote `__id___ui` exposing `./config` and `./__id__`, pages under `/__id__/*`.
|
|
46
|
+
- Every table, index and constraint starts with `__id___`, and every table has
|
|
47
|
+
`org_id` with forced row-level security, or is listed in `tools/no-org-id.sql`
|
|
48
|
+
with the reason. Core and other plugins share the database. [pnpm check:rls]
|
|
49
|
+
- The lint rules are `@erxes/lint`'s preset (`vite.config.ts`). It,
|
|
50
|
+
`tools/test/no-skips.ts` and `tools/check-rls.sql` come from core unchanged, as
|
|
51
|
+
does the quality section above. Change them in core.
|
|
52
|
+
- The plugin reaches core only through `@erxes/plugin-sdk` (`api/src/core.ts`)
|
|
53
|
+
and the UI's `pluginFetch`. It never reads `core_*` tables or imports core code.
|
|
54
|
+
- Members are signed in by core: the UI sends a session token, the API checks it
|
|
55
|
+
with `verifyPluginSession`. There is no public route yet, because core can't
|
|
56
|
+
tell a public request's organisation.
|
|
57
|
+
- Skills in `.agents/skills/`: `endpoint` for a procedure, `schema-change` for a
|
|
58
|
+
table or column, `verify` before calling a change done.__migrationSkill__
|
|
59
|
+
- What core promises plugins, and what counts as a breaking change, is core's
|
|
60
|
+
`plugin-contract` skill (erxes repo, branch `postgre`).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Packages what `pnpm image:context` built on the host: the bundled API with
|
|
2
|
+
# its production node_modules (.runtime) and the UI remote, served at /ui.
|
|
3
|
+
FROM node:26-bookworm-slim
|
|
4
|
+
ARG VERSION=0.1.0
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
COPY --chown=node:node .runtime/ ./
|
|
7
|
+
COPY --chown=node:node ui/dist/ ./ui/
|
|
8
|
+
ENV NODE_ENV=production PORT=__apiPort__ UI_DIR=/app/ui VERSION=$VERSION
|
|
9
|
+
USER node
|
|
10
|
+
EXPOSE __apiPort__
|
|
11
|
+
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=5 \
|
|
12
|
+
CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
|
|
13
|
+
CMD ["node", "--enable-source-maps", "--import", "./dist/telemetry.mjs", "dist/main.mjs"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The API reads this file in development (`pnpm dev:api`). Copy it to .env.
|
|
2
|
+
PORT=__apiPort__
|
|
3
|
+
# Postgres as the plugin's role: run `pnpm db:plugin-role __id__` in the core repo.
|
|
4
|
+
DATA_URL=postgres://erxes_plugin___id__:change-me@127.0.0.1:5434/erxes
|
|
5
|
+
# Core's address, without /core/v1.
|
|
6
|
+
CORE_URL=http://localhost:3400
|
|
7
|
+
# The secret after `__id__:` in core's CORE_PLUGIN_KEYS (32+ characters).
|
|
8
|
+
PLUGIN_SECRET=change-me-to-the-secret-in-core-plugin-keys
|
|
9
|
+
PUBLIC_URL=http://localhost:__apiPort__
|
|
10
|
+
# `pnpm dev:ui` serves the remote here; in the image the API serves it at /ui.
|
|
11
|
+
UI_ENTRY_URL=http://localhost:__uiPort__/remoteEntry.js
|
|
12
|
+
# web's address, which calls this API from the browser.
|
|
13
|
+
CORE_UI_URL=http://localhost:3500
|
|
14
|
+
# Traces go to an OTLP collector when this is set.
|
|
15
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
26
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# api
|
|
2
|
+
|
|
3
|
+
Node 26 runs the TypeScript directly; imports carry `.ts` and `#/` is `src/`.
|
|
4
|
+
|
|
5
|
+
- `src/main.ts` starts in this order: migrations, `core.registerManifest(manifest)`,
|
|
6
|
+
then the server. Core installs the plugin itself in development
|
|
7
|
+
(`PLUGINS_AUTO_INSTALL`).
|
|
8
|
+
- `src/core.ts` holds the core client and the manifest. Every permission, event
|
|
9
|
+
and kind in the manifest starts with `__id__.`. A new scope waits for the
|
|
10
|
+
owner's approval, so ask for one only when a procedure needs it.
|
|
11
|
+
- `src/server.ts` verifies the session token on `/api/rpc/*` and hands
|
|
12
|
+
procedures `context.member` (`PluginMember`: `orgId`, `userId`, `can()`,
|
|
13
|
+
`canChange()`).
|
|
14
|
+
- `src/orpc.ts`: build every procedure on `reads(action)` or `writes(action)`.
|
|
15
|
+
Both check the permission and run the handler in `withOrg(member.orgId)`, so
|
|
16
|
+
row-level security shows `context.tx` one organisation's rows. Queries carry
|
|
17
|
+
no org filter; only an insert sets `orgId`, from `context.member`.
|
|
18
|
+
- Call core (`core.forOrg(orgId)...`) outside `context.tx`; a failed core call
|
|
19
|
+
must not roll back the plugin's own change.
|
|
20
|
+
- Tests: `vite-plus/test`, run with `call(procedure, input, { context: { member } })`.
|
|
21
|
+
`src/test/setup.ts` gives each file its own database, owned by a role without
|
|
22
|
+
BYPASSRLS, so row-level security is real in tests.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE TABLE "__id___items" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"org_id" text NOT NULL,
|
|
4
|
+
"name" text NOT NULL,
|
|
5
|
+
"description" text DEFAULT '' NOT NULL,
|
|
6
|
+
"created_by" text NOT NULL,
|
|
7
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
8
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
CREATE INDEX "__id___items_org_created_idx" ON "__id___items" USING btree ("org_id","created_at" DESC NULLS LAST,"id" DESC NULLS LAST);--> statement-breakpoint
|
|
12
|
+
CREATE UNIQUE INDEX "__id___items_org_name_key" ON "__id___items" USING btree ("org_id",lower("name"));--> statement-breakpoint
|
|
13
|
+
SELECT core_enable_tenant_rls('__id___items');
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "5ccdfe2d-a57a-4573-bbee-ba11f21e7ddc",
|
|
3
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.__id___items": {
|
|
8
|
+
"name": "__id___items",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "text",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"org_id": {
|
|
18
|
+
"name": "org_id",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": true
|
|
22
|
+
},
|
|
23
|
+
"name": {
|
|
24
|
+
"name": "name",
|
|
25
|
+
"type": "text",
|
|
26
|
+
"primaryKey": false,
|
|
27
|
+
"notNull": true
|
|
28
|
+
},
|
|
29
|
+
"description": {
|
|
30
|
+
"name": "description",
|
|
31
|
+
"type": "text",
|
|
32
|
+
"primaryKey": false,
|
|
33
|
+
"notNull": true,
|
|
34
|
+
"default": "''"
|
|
35
|
+
},
|
|
36
|
+
"created_by": {
|
|
37
|
+
"name": "created_by",
|
|
38
|
+
"type": "text",
|
|
39
|
+
"primaryKey": false,
|
|
40
|
+
"notNull": true
|
|
41
|
+
},
|
|
42
|
+
"created_at": {
|
|
43
|
+
"name": "created_at",
|
|
44
|
+
"type": "timestamp with time zone",
|
|
45
|
+
"primaryKey": false,
|
|
46
|
+
"notNull": true,
|
|
47
|
+
"default": "now()"
|
|
48
|
+
},
|
|
49
|
+
"updated_at": {
|
|
50
|
+
"name": "updated_at",
|
|
51
|
+
"type": "timestamp with time zone",
|
|
52
|
+
"primaryKey": false,
|
|
53
|
+
"notNull": true,
|
|
54
|
+
"default": "now()"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"indexes": {
|
|
58
|
+
"__id___items_org_created_idx": {
|
|
59
|
+
"name": "__id___items_org_created_idx",
|
|
60
|
+
"columns": [
|
|
61
|
+
{
|
|
62
|
+
"expression": "org_id",
|
|
63
|
+
"isExpression": false,
|
|
64
|
+
"asc": true,
|
|
65
|
+
"nulls": "last"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"expression": "created_at",
|
|
69
|
+
"isExpression": false,
|
|
70
|
+
"asc": false,
|
|
71
|
+
"nulls": "last"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"expression": "id",
|
|
75
|
+
"isExpression": false,
|
|
76
|
+
"asc": false,
|
|
77
|
+
"nulls": "last"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"isUnique": false,
|
|
81
|
+
"concurrently": false,
|
|
82
|
+
"method": "btree",
|
|
83
|
+
"with": {}
|
|
84
|
+
},
|
|
85
|
+
"__id___items_org_name_key": {
|
|
86
|
+
"name": "__id___items_org_name_key",
|
|
87
|
+
"columns": [
|
|
88
|
+
{
|
|
89
|
+
"expression": "org_id",
|
|
90
|
+
"isExpression": false,
|
|
91
|
+
"asc": true,
|
|
92
|
+
"nulls": "last"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"expression": "lower(\"name\")",
|
|
96
|
+
"asc": true,
|
|
97
|
+
"isExpression": true,
|
|
98
|
+
"nulls": "last"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"isUnique": true,
|
|
102
|
+
"concurrently": false,
|
|
103
|
+
"method": "btree",
|
|
104
|
+
"with": {}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"foreignKeys": {},
|
|
108
|
+
"compositePrimaryKeys": {},
|
|
109
|
+
"uniqueConstraints": {},
|
|
110
|
+
"policies": {},
|
|
111
|
+
"checkConstraints": {},
|
|
112
|
+
"isRLSEnabled": false
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"enums": {},
|
|
116
|
+
"schemas": {},
|
|
117
|
+
"sequences": {},
|
|
118
|
+
"roles": {},
|
|
119
|
+
"policies": {},
|
|
120
|
+
"views": {},
|
|
121
|
+
"_meta": {
|
|
122
|
+
"columns": {},
|
|
123
|
+
"schemas": {},
|
|
124
|
+
"tables": {}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'drizzle-kit';
|
|
2
|
+
|
|
3
|
+
// `pnpm db:generate` writes a SQL migration from changes in src/db/schema.ts.
|
|
4
|
+
// The API applies pending migrations on startup (src/db/migrate.ts).
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
dialect: 'postgresql',
|
|
7
|
+
schema: './src/db/schema.ts',
|
|
8
|
+
out: './drizzle',
|
|
9
|
+
casing: 'snake_case',
|
|
10
|
+
// Same table as the API's migrator.
|
|
11
|
+
migrations: { schema: 'public', table: '__drizzle_migrations___id__' },
|
|
12
|
+
// Core and other plugins share the database: drizzle-kit must never see their tables.
|
|
13
|
+
tablesFilter: ['__id___*'],
|
|
14
|
+
strict: true,
|
|
15
|
+
verbose: true,
|
|
16
|
+
});
|