create-erxes 0.1.14 → 0.1.16
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/dist/index.js +1 -1
- package/dist/templates/base/.agents/skills/ui-patterns/SKILL.md +4 -0
- package/dist/templates/base/AGENTS.md +4 -1
- package/dist/templates/base/api/package.json +3 -2
- package/dist/templates/base/api/src/core.ts +2 -1
- package/dist/templates/base/api/src/server.ts +42 -17
- package/dist/templates/base/ui/package.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdir, readFile, readdir, symlink, writeFile } from "node:fs/promises";
|
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.1.
|
|
12
|
+
var version = "0.1.16";
|
|
13
13
|
// src/existing-plugins.ts
|
|
14
14
|
/** The old erxes plugins a new-core plugin can be migrated from (`backend/plugins/<name>_api`). */
|
|
15
15
|
const OLD_PLUGINS = [
|
|
@@ -186,6 +186,10 @@ page looks like core's Settings › Profile (`apps/web/src/modules/settings/prof
|
|
|
186
186
|
`@erxes/core-contract/client`: its name, and a click opens it in core's side
|
|
187
187
|
panel beside the page. Never its id, a name copied into the plugin's table,
|
|
188
188
|
or a link to a URL. `useOpenRecord()` opens one from your own control.
|
|
189
|
+
- In the record's panel the field is erxes-ui's `ContactRelationInput` in a
|
|
190
|
+
`PanelField cell={false}`, given `contacts={contactQueries}` and
|
|
191
|
+
`contactSearch={contactSearchQueries}`: the chip, then a small "Add customer"
|
|
192
|
+
button, sized like core's. `multiple={false}` when the record keeps one.
|
|
189
193
|
- A plugin's records of a customer or company are a relation tab on its panel
|
|
190
194
|
(`relationTabs`, above). `recordSections` still draws a section in the
|
|
191
195
|
customer's Detail tab, for a summary that belongs beside its fields.
|
|
@@ -54,7 +54,10 @@ without line-by-line review.
|
|
|
54
54
|
through `@erxes/core-contract/client` with the member's session. Neither reads
|
|
55
55
|
`core_*` tables or imports core's app code.
|
|
56
56
|
- Members are signed in by core: the UI sends a session token, the API checks it
|
|
57
|
-
with `verifyPluginSession`.
|
|
57
|
+
with `verifyPluginSession`. The same procedures are REST at `/api/v1` for
|
|
58
|
+
scripts, which get the token from core with an API key; `/api/openapi.json`
|
|
59
|
+
documents them (`pluginOpenApi`), and core's Settings › Developer › API reference
|
|
60
|
+
shows it. Renaming a procedure breaks those scripts. A caller outside erxes (a webhook) reaches a path
|
|
58
61
|
the manifest's `publicPaths` lists through core, which names the organisation:
|
|
59
62
|
check it with `verifyPublicCall` (`@erxes/plugin-sdk`'s overview has the route).
|
|
60
63
|
- Skills in `.agents/skills/`: `endpoint` for a procedure, `schema-change` for a
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
"db:check": "drizzle-kit check"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
25
|
-
"@erxes/plugin-sdk": "0.1.0-v2.
|
|
24
|
+
"@erxes/core-contract": "0.1.0-v2.15",
|
|
25
|
+
"@erxes/plugin-sdk": "0.1.0-v2.13",
|
|
26
26
|
"@opentelemetry/instrumentation-express": "^0.73.0",
|
|
27
27
|
"@opentelemetry/instrumentation-http": "^0.301.1",
|
|
28
28
|
"@opentelemetry/instrumentation-pg": "^0.78.0",
|
|
29
29
|
"@opentelemetry/instrumentation-pino": "^0.71.0",
|
|
30
30
|
"@opentelemetry/sdk-node": "^0.301.1",
|
|
31
|
+
"@orpc/openapi": "1.16.2",
|
|
31
32
|
"@orpc/server": "1.16.2",
|
|
32
33
|
"cors": "^2.8.6",
|
|
33
34
|
"drizzle-orm": "0.45.4",
|
|
@@ -30,7 +30,8 @@ export const manifest = {
|
|
|
30
30
|
description: '__description__',
|
|
31
31
|
version: config.version,
|
|
32
32
|
ui: { remote: '__id___ui', entry: config.uiEntryUrl },
|
|
33
|
-
|
|
33
|
+
// `server.ts` serves the REST routes at /api/v1 and their document here.
|
|
34
|
+
api: { url: `${config.publicUrl}/api`, openapi: '/openapi.json' },
|
|
34
35
|
scopes: [],
|
|
35
36
|
permissions: [
|
|
36
37
|
{ action: PERMISSIONS.view, label: 'View items', group: '__title__' },
|
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import { bearerOf, verifyCoreJob, verifyPluginSession } from '@erxes/plugin-sdk';
|
|
2
|
+
import { pluginOpenApi } from '@erxes/plugin-sdk/openapi';
|
|
3
|
+
import { OpenAPIHandler } from '@orpc/openapi/node';
|
|
2
4
|
import { onError, ORPCError } from '@orpc/server';
|
|
3
5
|
import { RPCHandler } from '@orpc/server/node';
|
|
4
6
|
import cors from 'cors';
|
|
5
7
|
import express from 'express';
|
|
6
8
|
import { pinoHttp } from 'pino-http';
|
|
7
9
|
import { config, PLUGIN } from '#/config.ts';
|
|
10
|
+
import { manifest } from '#/core.ts';
|
|
8
11
|
import { runJob } from '#/jobs.ts';
|
|
9
12
|
import { logger } from '#/logger.ts';
|
|
10
13
|
import { router } from '#/router.ts';
|
|
11
14
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const logFailure = onError((error) => {
|
|
16
|
+
if (!(error instanceof ORPCError) || error.status >= 500) logger.error(error);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// The same procedures twice: RPC for the plugin UI, REST (documented below) for scripts.
|
|
20
|
+
const rpc = new RPCHandler(router, { interceptors: [logFailure] });
|
|
21
|
+
const rest = new OpenAPIHandler(router, { interceptors: [logFailure] });
|
|
22
|
+
|
|
23
|
+
/** Settings › Developer › API reference shows it (the manifest's `api.openapi`). */
|
|
24
|
+
const openApi = pluginOpenApi(router, {
|
|
25
|
+
plugin: PLUGIN,
|
|
26
|
+
title: manifest.title,
|
|
27
|
+
version: manifest.version,
|
|
28
|
+
description: manifest.description,
|
|
29
|
+
prefix: '/v1',
|
|
18
30
|
});
|
|
19
31
|
|
|
20
32
|
/** The member behind a request from the plugin UI, or null without a valid session token. */
|
|
@@ -35,26 +47,39 @@ export const createApp = () => {
|
|
|
35
47
|
// uses (acme.app.erxes.io, its own domain). Any origin may: access is the
|
|
36
48
|
// Bearer session token core issues, never a cookie, so CORS guards nothing here.
|
|
37
49
|
// Routes for websites (an API key, customer tokens) set their own CORS.
|
|
38
|
-
app.use(
|
|
50
|
+
app.use(
|
|
51
|
+
['/api/rpc', '/api/v1', '/api/openapi.json', '/ui'],
|
|
52
|
+
cors({ origin: true, credentials: false, maxAge: 600 }),
|
|
53
|
+
);
|
|
39
54
|
|
|
40
55
|
app.get('/health', (_req, res) => {
|
|
41
56
|
res.json({ ok: true });
|
|
42
57
|
});
|
|
43
58
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
app.get('/api/openapi.json', async (_req, res) => {
|
|
60
|
+
res.json(await openApi);
|
|
61
|
+
});
|
|
47
62
|
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
// A 5-minute session token core issued for this member and plugin: erxes-ui's pluginFetch
|
|
64
|
+
// adds it, and a script gets one from core with an API key.
|
|
65
|
+
for (const [prefix, handler] of [
|
|
66
|
+
['/api/rpc', rpc],
|
|
67
|
+
['/api/v1', rest],
|
|
68
|
+
] as const) {
|
|
69
|
+
app.use(prefix, async (req, res, next) => {
|
|
70
|
+
const member = await memberOf(req.headers.authorization);
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
if (!member) {
|
|
73
|
+
res.status(401).json({ message: 'Send a session token for this plugin from core' });
|
|
53
74
|
|
|
54
|
-
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
55
77
|
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
const { matched } = await handler.handle(req, res, { prefix, context: { member } });
|
|
79
|
+
|
|
80
|
+
if (!matched) next();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
58
83
|
|
|
59
84
|
// Core's jobs (`api/src/jobs.ts`). The token signs the raw body, so it stays text.
|
|
60
85
|
app.post('/api/jobs/:name', express.text({ type: '*/*' }), async (req, res) => {
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"build": "rsbuild build"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
11
|
+
"@erxes/core-contract": "0.1.0-v2.15",
|
|
12
12
|
"@orpc/client": "1.16.2",
|
|
13
13
|
"@orpc/tanstack-query": "1.16.2",
|
|
14
14
|
"@tabler/icons-react": "3.34.0",
|
|
15
15
|
"@tanstack/react-query": "^5.107.1",
|
|
16
|
-
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.
|
|
16
|
+
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.19",
|
|
17
17
|
"jotai": "^3.0.2",
|
|
18
18
|
"nuqs": "^2.10.3",
|
|
19
19
|
"react": "19.3.1",
|