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.
Files changed (69) hide show
  1. package/README.md +23 -2
  2. package/dist/index.js +481 -0
  3. package/dist/templates/base/.agents/skills/endpoint/SKILL.md +21 -0
  4. package/dist/templates/base/.agents/skills/schema-change/SKILL.md +28 -0
  5. package/dist/templates/base/.agents/skills/verify/SKILL.md +24 -0
  6. package/dist/templates/base/.github/workflows/ci.yml +44 -0
  7. package/dist/templates/base/AGENTS.md +60 -0
  8. package/dist/templates/base/CLAUDE.md +1 -0
  9. package/dist/templates/base/Dockerfile +13 -0
  10. package/dist/templates/base/_dockerignore +4 -0
  11. package/dist/templates/base/_env.example +15 -0
  12. package/dist/templates/base/_gitignore +11 -0
  13. package/dist/templates/base/_node-version +1 -0
  14. package/dist/templates/base/api/AGENTS.md +22 -0
  15. package/dist/templates/base/api/drizzle/0000_items.sql +13 -0
  16. package/dist/templates/base/api/drizzle/meta/0000_snapshot.json +126 -0
  17. package/dist/templates/base/api/drizzle/meta/_journal.json +13 -0
  18. package/dist/templates/base/api/drizzle.config.ts +16 -0
  19. package/dist/templates/base/api/openapi.json +450 -0
  20. package/dist/templates/base/api/package.json +50 -0
  21. package/dist/templates/base/api/scripts/openapi.ts +27 -0
  22. package/dist/templates/base/api/src/__tests__/server.test.ts +51 -0
  23. package/dist/templates/base/api/src/config.ts +43 -0
  24. package/dist/templates/base/api/src/core.ts +37 -0
  25. package/dist/templates/base/api/src/db/client.ts +30 -0
  26. package/dist/templates/base/api/src/db/migrate.ts +86 -0
  27. package/dist/templates/base/api/src/db/schema.ts +34 -0
  28. package/dist/templates/base/api/src/db/table.ts +8 -0
  29. package/dist/templates/base/api/src/logger.ts +5 -0
  30. package/dist/templates/base/api/src/main.ts +23 -0
  31. package/dist/templates/base/api/src/modules/items/__tests__/items.test.ts +86 -0
  32. package/dist/templates/base/api/src/modules/items/items.ts +121 -0
  33. package/dist/templates/base/api/src/orpc.ts +25 -0
  34. package/dist/templates/base/api/src/router.ts +10 -0
  35. package/dist/templates/base/api/src/server.ts +58 -0
  36. package/dist/templates/base/api/src/telemetry.ts +27 -0
  37. package/dist/templates/base/api/src/test/core-functions.sql +18 -0
  38. package/dist/templates/base/api/src/test/setup.ts +68 -0
  39. package/dist/templates/base/api/tsconfig.json +9 -0
  40. package/dist/templates/base/knip.ts +22 -0
  41. package/dist/templates/base/package.json +31 -0
  42. package/dist/templates/base/pnpm-workspace.yaml +20 -0
  43. package/dist/templates/base/tools/check-generated.ts +78 -0
  44. package/dist/templates/base/tools/check-rls.sh +30 -0
  45. package/dist/templates/base/tools/check-rls.sql +109 -0
  46. package/dist/templates/base/tools/no-org-id.sql +5 -0
  47. package/dist/templates/base/tools/test/no-skips.ts +58 -0
  48. package/dist/templates/base/tsconfig.base.json +16 -0
  49. package/dist/templates/base/tsconfig.json +9 -0
  50. package/dist/templates/base/ui/AGENTS.md +18 -0
  51. package/dist/templates/base/ui/package.json +32 -0
  52. package/dist/templates/base/ui/rsbuild.config.ts +36 -0
  53. package/dist/templates/base/ui/src/__Pascal__.tsx +9 -0
  54. package/dist/templates/base/ui/src/config.tsx +11 -0
  55. package/dist/templates/base/ui/src/index.ts +3 -0
  56. package/dist/templates/base/ui/src/items/ItemSheet.tsx +107 -0
  57. package/dist/templates/base/ui/src/items/ItemsPage.tsx +116 -0
  58. package/dist/templates/base/ui/src/items/useItems.ts +79 -0
  59. package/dist/templates/base/ui/src/orpc.ts +32 -0
  60. package/dist/templates/base/ui/tsconfig.json +11 -0
  61. package/dist/templates/base/vite.config.ts +63 -0
  62. package/dist/templates/migrate/.agents/skills/plugin-migrate/SKILL.md +61 -0
  63. package/dist/templates/migrate/migration/checklist.ts +429 -0
  64. package/dist/templates/migrate/migration/core-map.ts +149 -0
  65. package/dist/templates/migrate/migration/import-map.ts +4 -0
  66. package/dist/templates/migrate/migration/inventory.ts +881 -0
  67. package/dist/templates/migrate/package.json +15 -0
  68. package/dist/templates/migrate/scripts/import-mongo.ts +143 -0
  69. package/package.json +32 -3
@@ -0,0 +1,149 @@
1
+ // What an old erxes call into core becomes on the new core. Built from what
2
+ // erxes `postgre` opens to plugins: packages/contract and the access map in
3
+ // apps/api/src/http/access.ts. Old calls run on the server, so:
4
+ //
5
+ // sdk core.forOrg(orgId).<procedure> from the API, with the scope named
6
+ // contract no plugin scope; the UI calls core with the member's own session
7
+ // plugin-owned the plugin keeps it in its own tables or code
8
+ // gap core offers no equivalent yet: file it, don't work around it
9
+
10
+ export type Equivalent = {
11
+ kind: 'sdk' | 'contract' | 'plugin-owned' | 'gap';
12
+ /** The procedure, function or place it moves to. */
13
+ to: string;
14
+ note?: string;
15
+ };
16
+
17
+ const sdk = (to: string, note?: string): Equivalent => ({ kind: 'sdk', to, note });
18
+ const contract = (to: string, note?: string): Equivalent => ({ kind: 'contract', to, note });
19
+ const owned = (to: string, note?: string): Equivalent => ({ kind: 'plugin-owned', to, note });
20
+ const gap = (note: string): Equivalent => ({ kind: 'gap', to: '', note });
21
+
22
+ /** `sendTRPCMessage({ pluginName: 'core', module, action })`, keyed `module.action`. */
23
+ export const CORE_CALLS: Record<string, Equivalent> = {
24
+ 'customers.findOne': sdk('customers.get', 'scope customers:read; by id only'),
25
+ 'customers.find': contract(
26
+ 'customers.list',
27
+ 'member needs contacts.view; no plugin scope lists customers',
28
+ ),
29
+ 'customers.createCustomer': sdk(
30
+ 'customers.findOrCreate',
31
+ 'scope customers:write; by email or phone',
32
+ ),
33
+ 'customers.createMessengerCustomer': sdk('customers.findOrCreate', 'scope customers:write'),
34
+ 'customers.getWidgetCustomer': sdk(
35
+ 'customers.findOrCreate',
36
+ 'scope customers:write; by email or phone',
37
+ ),
38
+ 'customers.updateCustomer': gap('plugins cannot change a customer'),
39
+ 'customers.updateOne': gap('plugins cannot change a customer'),
40
+ 'customers.updateMessengerCustomer': gap('plugins cannot change a customer'),
41
+ 'customers.updateLocation': gap('plugins cannot change a customer'),
42
+ 'customers.updateSession': gap('plugins cannot change a customer'),
43
+ 'customers.markCustomerAsActive': gap('plugins cannot change a customer'),
44
+ 'customers.findActiveCustomers': gap('plugins cannot list or search customers'),
45
+ 'companies.findOne': sdk('companies.get', 'scope customers:read; by id only'),
46
+ 'companies.find': contract('companies.list', 'member needs contacts.view'),
47
+ 'companies.createCompany': gap('plugins cannot create companies'),
48
+ 'companies.updateCompany': gap('plugins cannot change a company'),
49
+ 'users.findOne': contract('users.get', 'member needs team.view; keep user ids on the server'),
50
+ 'users.find': contract('users.list', 'member needs team.view; keep user ids on the server'),
51
+ 'users.getIds': contract('users.list', 'member needs team.view'),
52
+ 'tags.find': owned('<plugin>_tags', "core's tags are for customers and companies (decision 9)"),
53
+ 'tags.findOne': owned(
54
+ '<plugin>_tags',
55
+ "core's tags are for customers and companies (decision 9)",
56
+ ),
57
+ 'fields.find': owned(
58
+ '<plugin>_fields',
59
+ 'core custom fields cover customers, companies and products',
60
+ ),
61
+ 'fields.validateFieldValues': owned('zod in the procedure input'),
62
+ 'fields.getFieldList': owned('<plugin>_fields'),
63
+ 'fields.generateTypedListFromMap': owned('<plugin>_fields'),
64
+ 'fields.generatePropertiesData': owned('<plugin>_fields'),
65
+ 'fields.fieldsCombinedByContentType': owned('<plugin>_fields'),
66
+ 'fieldsGroups.find': owned('<plugin>_fields'),
67
+ 'configs.getConfig': owned(
68
+ '<plugin>_settings',
69
+ 'country and currency: organizations.current (sdk)',
70
+ ),
71
+ 'configs.getConfigs': owned(
72
+ '<plugin>_settings',
73
+ 'country and currency: organizations.current (sdk)',
74
+ ),
75
+ 'config.getConfig': owned(
76
+ '<plugin>_settings',
77
+ 'country and currency: organizations.current (sdk)',
78
+ ),
79
+ 'activityLog.createActivityLog': sdk(
80
+ 'activities.create',
81
+ 'scope activities:write; customer or company targets, else manifest timelines',
82
+ ),
83
+ 'notifications.send': sdk('notifications.create', 'scope notifications:write; team members only'),
84
+ 'core.sendEmail': gap('no email API for plugins; team members: notifications.create'),
85
+ 'emailDeliveries.create': gap('no email API for plugins'),
86
+ 'emailDeliveries.recordHandoff': gap('no email API for plugins'),
87
+ 'emailSuppression.blocked': gap('no email API for plugins'),
88
+ 'cpUsers.get': gap('customer sign-in (decision 42) has no plugin procedure yet'),
89
+ 'cpNotifications.create': gap('customer sign-in (decision 42) has no plugin procedure yet'),
90
+ 'clientPortals.get': gap('core has no client portals'),
91
+ 'segment.fetchSegment': gap('core has saved views, not segments, and none for plugins'),
92
+ 'automation.find': gap(
93
+ 'plugins declare manifest events and actions; they cannot read automations',
94
+ ),
95
+ 'brands.create': gap('core has no brands'),
96
+ 'brands.updateOne': gap('core has no brands'),
97
+ 'branches.findOne': gap('core has no branches'),
98
+ 'departments.findWithChild': gap('core has no departments'),
99
+ 'organization.identity': owned('nothing', 'the organisation id is in every token (orgId)'),
100
+ };
101
+
102
+ /** Event, audit and automation helpers from erxes-api-shared. */
103
+ export const HELPERS: Record<string, Equivalent> = {
104
+ sendDbEventLog: sdk(
105
+ 'core_record_audit() in the same transaction',
106
+ 'or audit.record (audit:write)',
107
+ ),
108
+ sendEvent: sdk(
109
+ 'core_publish_event() in the same transaction',
110
+ 'declare the type in manifest.events',
111
+ ),
112
+ sendNotification: sdk(
113
+ 'notifications.create',
114
+ 'scope notifications:write; kind in manifest.notificationKinds',
115
+ ),
116
+ sendNotifications: sdk('notifications.create', 'scope notifications:write'),
117
+ sendAutomationTrigger: sdk(
118
+ 'core_publish_event() in the same transaction',
119
+ 'declare the type in manifest.events; automations start from events',
120
+ ),
121
+ sendAutomationDeferredCompletion: gap(
122
+ 'an automation action answers in its HTTP response; core has no deferred completion',
123
+ ),
124
+ };
125
+
126
+ /** Meta registrations in `startPlugin({ meta })` and `meta/`. */
127
+ export const REGISTRATIONS: Record<string, Equivalent> = {
128
+ permission: sdk(
129
+ 'manifest.permissions',
130
+ '<plugin>.<record>.<verb>; own/team/all reach stays in the plugin',
131
+ ),
132
+ notification: sdk('manifest.notificationKinds'),
133
+ 'automation trigger': sdk('manifest.events', 'published with core_publish_event()'),
134
+ 'automation action': sdk(
135
+ 'manifest.actions',
136
+ 'POST <api>/automations/actions/<type>, verifyCoreCall()',
137
+ ),
138
+ 'default role': gap('core roles are its own; a plugin cannot ship a role with grants'),
139
+ segment: gap('core has no segments for plugins'),
140
+ 'import-export': gap("core's import and export cover contacts only"),
141
+ };
142
+
143
+ /** A call to another plugin, or to this one through tRPC. */
144
+ export const pluginCall = (target: string, self: string): Equivalent =>
145
+ target === self
146
+ ? owned('a direct function call')
147
+ : gap(`plugins cannot call ${target}; listen to its events instead`);
148
+
149
+ export const UNMAPPED = gap('not in migration/core-map.ts yet');
@@ -0,0 +1,4 @@
1
+ // Which Mongo field goes to which column, per collection, for scripts/import-mongo.ts.
2
+ // Written by migration/checklist.ts; edit it as the tables in api/src/db/schema.ts change.
3
+ export const IMPORT_MAP: { collection: string; table: string; columns: Record<string, string> }[] =
4
+ [];