create-erxes 0.1.23 → 0.1.25
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.md +2 -1
- package/dist/templates/base/api/AGENTS.md +13 -5
- package/dist/templates/base/api/package.json +2 -2
- package/dist/templates/base/api/src/server.ts +13 -4
- 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.25";
|
|
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 = [
|
|
@@ -54,7 +54,8 @@ 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`; another plugin reading for an organisation sends a
|
|
58
|
+
call token, checked with `verifyPluginCall`. The same procedures are REST at `/api/v1` for
|
|
58
59
|
scripts, which get the token from core with an API key; `/api/openapi/member.json`
|
|
59
60
|
documents them (`pluginOpenApi`), and core's Settings › Developer › API reference
|
|
60
61
|
shows it. Routes for employees in the plugin's own app, customers or a website get
|
|
@@ -10,9 +10,14 @@ Node 26 runs the TypeScript directly; imports carry `.ts` and `#/` is `src/`.
|
|
|
10
10
|
owner's approval, so ask for one only when a procedure needs it. Owners and
|
|
11
11
|
admins hold every permission; a permission set with `defaultRoles: ['member']`
|
|
12
12
|
is what members get on install, and owners change it from there.
|
|
13
|
-
- `src/server.ts` verifies the session token
|
|
14
|
-
|
|
15
|
-
`canChange()`).
|
|
13
|
+
- `src/server.ts` verifies the session token, or another plugin's call token
|
|
14
|
+
(`verifyPluginCall`), on `/api/rpc/*` and `/api/v1/*` and hands procedures
|
|
15
|
+
`context.member` (`PluginMember`: `orgId`, `userId`, `can()`, `canChange()`).
|
|
16
|
+
A plugin call's `userId` is `plugin:<name>` and its permissions are the reads
|
|
17
|
+
the owner approved, so `reads(...)` serves it unchanged.
|
|
18
|
+
- To read another plugin's API, name it in the manifest's `pluginReads`
|
|
19
|
+
(`{ plugin, permissions, reason }`, the owner approves it) and call
|
|
20
|
+
`core.fetchPlugin(orgId, plugin, '/v1/...')`, outside `context.tx`.
|
|
16
21
|
- `src/orpc.ts`: build every procedure on `reads(action)` or `writes(action)`.
|
|
17
22
|
Both check the permission and run the handler in `withOrg(member.orgId)`, so
|
|
18
23
|
row-level security shows `context.tx` one organisation's rows. Queries carry
|
|
@@ -47,7 +52,8 @@ Node 26 runs the TypeScript directly; imports carry `.ts` and `#/` is `src/`.
|
|
|
47
52
|
- A fact the plugin computes about a customer or company (total spent, last
|
|
48
53
|
order) is a field in the manifest's `fields` (`code`, `contentType`, `label`,
|
|
49
54
|
`type`: number, date, text, select or multiselect). Core shows it read-only
|
|
50
|
-
and members filter and save views by it
|
|
55
|
+
and members filter and save views by it; `filterable: false` keeps it a
|
|
56
|
+
column and sort key only, when a relation filters by the same records. Write values with
|
|
51
57
|
`core.forOrg(orgId).fields.setPluginValues({ contentType, values })` (scope
|
|
52
58
|
`fields:write`, up to 500, `value: null` clears) after the change commits; it
|
|
53
59
|
adds nothing to the timeline and sends no event. Members see the fields only
|
|
@@ -57,7 +63,9 @@ Node 26 runs the TypeScript directly; imports carry `.ts` and `#/` is `src/`.
|
|
|
57
63
|
- Records that belong to customers or companies (deals, orders, tickets) are a
|
|
58
64
|
relation in the manifest's `relations` (`key`, `contentType`, `label`,
|
|
59
65
|
`view`, `permission?`, `fields`: `key`, `label`, `type` text, number, date,
|
|
60
|
-
boolean, select or
|
|
66
|
+
boolean, select, member or product, `options`, `array`, `money`, and
|
|
67
|
+
`measures`: which of `sum`, `avg`, `min`, `max` the filter lists for a
|
|
68
|
+
number or date field, all when absent). Members then filter
|
|
61
69
|
contacts by them, live, with no values to sync: "Deals: count ≥ 3 where
|
|
62
70
|
Stage is Won", "Deals: Amount (total) > 1,000,000", "Deals: Closed (latest)
|
|
63
71
|
more than 60 days ago". Keep a view `<plugin>_*` in a migration, owned by the
|
|
@@ -21,8 +21,8 @@
|
|
|
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.25",
|
|
25
|
+
"@erxes/plugin-sdk": "0.1.0-v2.24",
|
|
26
26
|
"@opentelemetry/instrumentation-express": "^0.73.0",
|
|
27
27
|
"@opentelemetry/instrumentation-http": "^0.301.1",
|
|
28
28
|
"@opentelemetry/instrumentation-pg": "^0.78.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bearerOf, verifyCoreJob, verifyPluginSession } from '@erxes/plugin-sdk';
|
|
1
|
+
import { bearerOf, verifyCoreJob, verifyPluginCall, verifyPluginSession } from '@erxes/plugin-sdk';
|
|
2
2
|
import { pluginOpenApi } from '@erxes/plugin-sdk/openapi';
|
|
3
3
|
import { OpenAPIHandler } from '@orpc/openapi/node';
|
|
4
4
|
import { onError, ORPCError } from '@orpc/server';
|
|
@@ -34,13 +34,21 @@ const memberDoc = pluginOpenApi(router, {
|
|
|
34
34
|
prefix: '/v1',
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Who is calling: the member behind a request from the plugin UI (a session token), or another
|
|
39
|
+
* plugin reading for an organisation (a plugin call token, `userId` `plugin:<name>`, with the
|
|
40
|
+
* permissions the owner approved for it). Null without a valid token of either kind.
|
|
41
|
+
*/
|
|
38
42
|
const memberOf = async (authorization: string | undefined) => {
|
|
39
43
|
const token = bearerOf(authorization);
|
|
40
44
|
|
|
41
45
|
if (!token) return null;
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
const options = { coreUrl: config.coreUrl, plugin: PLUGIN };
|
|
48
|
+
|
|
49
|
+
return verifyPluginSession(token, options)
|
|
50
|
+
.catch(() => verifyPluginCall(token, options))
|
|
51
|
+
.catch(() => null);
|
|
44
52
|
};
|
|
45
53
|
|
|
46
54
|
export const createApp = () => {
|
|
@@ -66,7 +74,8 @@ export const createApp = () => {
|
|
|
66
74
|
});
|
|
67
75
|
|
|
68
76
|
// A 5-minute session token core issued for this member and plugin: erxes-ui's pluginFetch
|
|
69
|
-
// adds it, and a script gets one from core with an API key.
|
|
77
|
+
// adds it, and a script gets one from core with an API key. Another plugin's
|
|
78
|
+
// `core.fetchPlugin` sends a plugin call token, which `reads(...)` checks the same way.
|
|
70
79
|
for (const [prefix, handler] of [
|
|
71
80
|
['/api/rpc', rpc],
|
|
72
81
|
['/api/v1', rest],
|
|
@@ -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.25",
|
|
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.22",
|
|
17
17
|
"jotai": "^3.0.2",
|
|
18
18
|
"nuqs": "^2.10.3",
|
|
19
19
|
"react": "19.3.1",
|