@erxes/plugin-sdk 0.1.0-v2.17 → 0.1.0-v2.19
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.d.ts +2 -2
- package/dist/openapi.d.ts +12 -4
- package/dist/openapi.js +13 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -122,11 +122,11 @@
|
|
|
122
122
|
*
|
|
123
123
|
* API reference: `@erxes/plugin-sdk/openapi` documents the plugin's routes, served as REST beside
|
|
124
124
|
* the RPC handler. The manifest's `api.docs` lists one document per audience (`member`, and
|
|
125
|
-
* `customer` or `website` for routes those call), and Settings › Developer shows them:
|
|
125
|
+
* `employee`, `customer` or `website` for routes those call), and Settings › Developer shows them:
|
|
126
126
|
*
|
|
127
127
|
* api: { url: `${publicUrl}/api`, docs: [{ audience: 'member', path: '/openapi/member.json' }] },
|
|
128
128
|
* app.use('/api/v1', member check, (req, res, next) => rest.handle(req, res, { prefix: '/api/v1', context }));
|
|
129
|
-
* app.get('/api/openapi/member.json', async (_req, res) => res.json(await pluginOpenApi(router, { plugin, audience: 'member', title, version, prefix: '/v1' })));
|
|
129
|
+
* app.get('/api/openapi/member.json', async (_req, res) => res.json(await pluginOpenApi(router, { plugin, audience: 'member', title, version, server: `${publicUrl}/api`, prefix: '/v1' })));
|
|
130
130
|
*
|
|
131
131
|
* The client secret is only ever sent to `POST /plugins/token`; API calls use
|
|
132
132
|
* 15-minute tokens, fetched and renewed here. Plugins on core's database can
|
package/dist/openapi.d.ts
CHANGED
|
@@ -11,8 +11,14 @@ export interface PluginOpenApiOptions {
|
|
|
11
11
|
version: string;
|
|
12
12
|
description?: string;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* `
|
|
14
|
+
* The address the document's paths start from, which "try it" calls: the manifest's
|
|
15
|
+
* `api.url` (`${publicUrl}/api`) for routes under it, or the plugin's public URL for routes
|
|
16
|
+
* outside it (a website's `/public/v1`, customers' `/customer`).
|
|
17
|
+
*/
|
|
18
|
+
server: string;
|
|
19
|
+
/**
|
|
20
|
+
* Where the REST routes are mounted under `server` (`/v1`, for an `OpenAPIHandler` with
|
|
21
|
+
* prefix `<api path>/v1`): every path in the document starts with it.
|
|
16
22
|
*/
|
|
17
23
|
prefix: `/${string}`;
|
|
18
24
|
}
|
|
@@ -22,8 +28,10 @@ export interface PluginOpenApiOptions {
|
|
|
22
28
|
* Each audience signs in its own way (`securityOf`), and the document says how.
|
|
23
29
|
*
|
|
24
30
|
* const rest = new OpenAPIHandler(router); // mounted at `<api path>/v1`, like the RPC handler
|
|
25
|
-
* const doc = pluginOpenApi(router, {
|
|
31
|
+
* const doc = pluginOpenApi(router, {
|
|
32
|
+
* plugin: 'sales', audience: 'member', title, version, server: `${publicUrl}/api`, prefix: '/v1',
|
|
33
|
+
* });
|
|
26
34
|
* app.get('/api/openapi/member.json', async (_req, res) => res.json(await doc));
|
|
27
35
|
*/
|
|
28
|
-
export declare const pluginOpenApi: (router: Documented, { plugin, audience, title, version, description, prefix }: PluginOpenApiOptions) => Promise<OpenAPI.Document>;
|
|
36
|
+
export declare const pluginOpenApi: (router: Documented, { plugin, audience, title, version, description, server, prefix }: PluginOpenApiOptions) => Promise<OpenAPI.Document>;
|
|
29
37
|
export {};
|
package/dist/openapi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CORE_API_PREFIX, CUSTOMER_TOKEN_SCHEME, PLUGIN_SESSION_SCHEME, WEBSITE_KEY_SCHEME } from "@erxes/core-contract";
|
|
1
|
+
import { CORE_API_PREFIX, CUSTOMER_TOKEN_SCHEME, EMPLOYEE_TOKEN_SCHEME, PLUGIN_SESSION_SCHEME, WEBSITE_KEY_SCHEME } from "@erxes/core-contract";
|
|
2
2
|
import { OpenAPIGenerator } from "@orpc/openapi";
|
|
3
3
|
import { ZodToJsonSchemaConverter } from "@orpc/zod/zod4";
|
|
4
4
|
// src/openapi.ts
|
|
@@ -20,6 +20,13 @@ const securityOf = (plugin, audience) => {
|
|
|
20
20
|
} } },
|
|
21
21
|
security: [{ [PLUGIN_SESSION_SCHEME]: [] }]
|
|
22
22
|
};
|
|
23
|
+
if (audience === "employee") return {
|
|
24
|
+
components: { securitySchemes: { [EMPLOYEE_TOKEN_SCHEME]: {
|
|
25
|
+
...BEARER,
|
|
26
|
+
description: "An employee's access token, from this plugin's own sign-in in this document (employees sign in to the plugin's app, not to erxes)."
|
|
27
|
+
} } },
|
|
28
|
+
security: [{ [EMPLOYEE_TOKEN_SCHEME]: [] }]
|
|
29
|
+
};
|
|
23
30
|
if (audience === "customer") return {
|
|
24
31
|
components: { securitySchemes: { [CUSTOMER_TOKEN_SCHEME]: customerToken } },
|
|
25
32
|
security: [{ [CUSTOMER_TOKEN_SCHEME]: [] }]
|
|
@@ -46,16 +53,19 @@ const securityOf = (plugin, audience) => {
|
|
|
46
53
|
* Each audience signs in its own way (`securityOf`), and the document says how.
|
|
47
54
|
*
|
|
48
55
|
* const rest = new OpenAPIHandler(router); // mounted at `<api path>/v1`, like the RPC handler
|
|
49
|
-
* const doc = pluginOpenApi(router, {
|
|
56
|
+
* const doc = pluginOpenApi(router, {
|
|
57
|
+
* plugin: 'sales', audience: 'member', title, version, server: `${publicUrl}/api`, prefix: '/v1',
|
|
58
|
+
* });
|
|
50
59
|
* app.get('/api/openapi/member.json', async (_req, res) => res.json(await doc));
|
|
51
60
|
*/
|
|
52
|
-
const pluginOpenApi = async (router, { plugin, audience, title, version, description, prefix }) => {
|
|
61
|
+
const pluginOpenApi = async (router, { plugin, audience, title, version, description, server, prefix }) => {
|
|
53
62
|
const doc = await new OpenAPIGenerator({ schemaConverters: [new ZodToJsonSchemaConverter()] }).generate(router, {
|
|
54
63
|
info: {
|
|
55
64
|
title,
|
|
56
65
|
version,
|
|
57
66
|
description
|
|
58
67
|
},
|
|
68
|
+
servers: [{ url: server }],
|
|
59
69
|
...securityOf(plugin, audience)
|
|
60
70
|
});
|
|
61
71
|
doc.paths = Object.fromEntries(Object.entries(doc.paths ?? {}).map(([path, item]) => [`${prefix}${path}`, item]));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erxes/plugin-sdk",
|
|
3
|
-
"version": "0.1.0-v2.
|
|
3
|
+
"version": "0.1.0-v2.19",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "For erxes plugin servers: a typed core client with automatic plugin tokens, verification of members' plugin session tokens and of core's deliveries, and plugin jobs",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@orpc/zod": "1.16.2",
|
|
37
37
|
"jose": "^6.2.17",
|
|
38
38
|
"zod": "^4.6.7",
|
|
39
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
39
|
+
"@erxes/core-contract": "0.1.0-v2.20"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"drizzle-orm": "0.45.4"
|