@vc-shell/api-client-generator 1.0.131 → 1.0.132
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/CHANGELOG.md +9 -0
- package/README.md +68 -17
- package/dist/api-client-generator.js +15 -14
- package/dist/assets/authApiBase.ts +1 -1
- package/dist/assets/config.nswag +1 -1
- package/dist/assets/templates/File.Header.liquid +4 -0
- package/package.json +2 -2
- package/public/assets/authApiBase.ts +1 -1
- package/public/assets/config.nswag +1 -1
- package/public/assets/templates/File.Header.liquid +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [1.0.132](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.131...v1.0.132) (2023-12-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **api-client-generator:** add [@ts-nocheck](https://github.com/ts-nocheck) to every generated api-client ([ec63e8d](https://github.com/VirtoCommerce/vc-shell/commit/ec63e8dadb252ae29294632357bced6725d5c8c9))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [1.0.131](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.130...v1.0.131) (2023-12-28)
|
|
2
11
|
|
|
3
12
|
|
package/README.md
CHANGED
|
@@ -1,28 +1,79 @@
|
|
|
1
1
|
# Platform Manager REST Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Generate API client
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This guide describes the process of generating an API client to access the VC Platform API from your custom application.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Add `"generate-api-client:project-name": "lerna run generate-api-client --scope=@vc-shell/project-name --stream --no-prefix"`
|
|
7
|
+
!!! note
|
|
8
|
+
Platform Manager REST Client offers generated REST API methods that make it easy to interact with the existing VirtoCommerce Platform API.
|
|
10
9
|
|
|
11
|
-
##
|
|
10
|
+
## Prerequisites
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
* .NET Core 6.0, particularly if you are using MacOS or Linux.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
1. Run `yarn` or `yarn bootstrap` to install dependency
|
|
17
|
-
2. Run `yarn build` or `yarn build-cli:api-client` to build API client generator
|
|
14
|
+
## Generate TypeScript API clients
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
To enable TypeScript API client generation in your project:
|
|
20
17
|
|
|
18
|
+
1. Add dependencies to your project:
|
|
19
|
+
|
|
20
|
+
Using command
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @vc-shell/api-client-generator cross-env
|
|
21
24
|
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
<br>
|
|
26
|
+
|
|
27
|
+
`cross-env` runs scripts that set and use environment variables across platforms.
|
|
28
|
+
|
|
29
|
+
Manually
|
|
30
|
+
|
|
31
|
+
Add the dependencies to your project's **package.json**:
|
|
32
|
+
|
|
33
|
+
```json title="vc-app/package.json" linenums="1"
|
|
34
|
+
{
|
|
35
|
+
...
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
...
|
|
38
|
+
"@vc-shell/api-client-generator": "latest",
|
|
39
|
+
"cross-env": "latest",
|
|
40
|
+
...
|
|
41
|
+
}
|
|
42
|
+
}
|
|
27
43
|
```
|
|
28
|
-
|
|
44
|
+
|
|
45
|
+
2. Configure client generation in your project. Inside your project's **package.json** file, add a `"generate-api-client"` command to the list of scripts:
|
|
46
|
+
|
|
47
|
+
```title="vc-app-extend/package.json" linenums="1"
|
|
48
|
+
{
|
|
49
|
+
"scripts": {
|
|
50
|
+
...
|
|
51
|
+
"generate-api-client": cross-env api-client-generator --APP_PLATFORM_MODULES='[MarketplaceVendor,Catalog,Orders]' --APP_API_CLIENT_DIRECTORY=./src/api_client/
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The options are listed in the table below:
|
|
57
|
+
|
|
58
|
+
| Options | Description | Example |
|
|
59
|
+
|----------------------------- |---------------------------------------------------------------- |------------------------------------------------------------ |
|
|
60
|
+
| `--APP_PLATFORM_MODULES` | Platform modules to generate API client.<br>{==string[]==} <br> Customize the `--APP_PLATFORM_MODULES` list<br>to match your project's requirements. | `--APP_PLATFORM_MODULES='[MarketplaceVendor,Orders,Catalog]'` |
|
|
61
|
+
| `--APP_API_CLIENT_DIRECTORY` | Output directory for generated API clients. <br>{==string==} | `--APP_API_CLIENT_DIRECTORY=./src/api_client/` |
|
|
62
|
+
| `--APP_PLATFORM_URL` | Platform URL to obtain client API configs. <br>{==string==} | `--APP_PLATFORM_URL=https://vcmp-dev.paas.govirto.com/` |
|
|
63
|
+
|
|
64
|
+
3. Configure Platform URL to ensure your project can access the platform's API configurations. Add the platform URL to your project's **.env** file:
|
|
65
|
+
|
|
66
|
+
```title="vc-app-extend/.env"
|
|
67
|
+
APP_PLATFORM_URL=https://vcmp-dev.paas.govirto.com/
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
!!! note
|
|
71
|
+
Alternatively, you can specify the Platform URL as a command option in the previous step when running the `"generate-api-client"` command.
|
|
72
|
+
|
|
73
|
+
4. Generate the API clients using the following command:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
yarn generate-api-client
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This command generates the required API clients for your custom application. Now you can effortlessly access the VC Platform API from your custom application using the generated API client.
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import f from "chalk";
|
|
2
2
|
import { spawnSync as y } from "node:child_process";
|
|
3
|
-
import { resolveConfig as
|
|
4
|
-
import { dirname as
|
|
3
|
+
import { resolveConfig as L } from "vite";
|
|
4
|
+
import { dirname as b, resolve as D, join as h, relative as P } from "node:path";
|
|
5
5
|
import { fileURLToPath as C } from "node:url";
|
|
6
|
-
import { cwd as
|
|
7
|
-
const
|
|
8
|
-
class
|
|
6
|
+
import { cwd as T } from "node:process";
|
|
7
|
+
const O = C(import.meta.url), R = b(O);
|
|
8
|
+
class p {
|
|
9
9
|
workingDirectory;
|
|
10
10
|
generatorDirectory;
|
|
11
11
|
assetsDirectory;
|
|
12
12
|
apiClientDirectory;
|
|
13
13
|
nswagPaths;
|
|
14
14
|
constructor(e) {
|
|
15
|
-
this.workingDirectory =
|
|
15
|
+
this.workingDirectory = T(), this.generatorDirectory = D(R, ".."), this.assetsDirectory = h(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = D(this.workingDirectory, e), this.nswagPaths = {
|
|
16
16
|
configuration: h(P(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
17
|
-
authApiBase: "authApiBase.ts"
|
|
17
|
+
authApiBase: "authApiBase.ts",
|
|
18
|
+
templates: "templates"
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
resolveApiClientPaths(e) {
|
|
@@ -33,7 +34,7 @@ function M(n, e, r, i) {
|
|
|
33
34
|
var t, o = n[e], g = ~i.string.indexOf(e) ? r == null || r === !0 ? "" : String(r) : typeof r == "boolean" ? r : ~i.boolean.indexOf(e) ? r === "false" ? !1 : r === "true" || (n._.push((t = +r, t * 0 === 0 ? t : r)), !!r) : (t = +r, t * 0 === 0 ? t : r);
|
|
34
35
|
n[e] = o == null ? g : Array.isArray(o) ? o.concat(g) : [o, g];
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
+
function k(n, e) {
|
|
37
38
|
n = n || [], e = e || {};
|
|
38
39
|
var r, i, t, o, g, l = { _: [] }, a = 0, s = 0, c = 0, d = n.length;
|
|
39
40
|
const _ = e.alias !== void 0, u = e.unknown !== void 0, m = e.default !== void 0;
|
|
@@ -86,9 +87,9 @@ function p(n, e) {
|
|
|
86
87
|
l[i.shift()] = l[r];
|
|
87
88
|
return l;
|
|
88
89
|
}
|
|
89
|
-
async function
|
|
90
|
-
await
|
|
91
|
-
const n =
|
|
90
|
+
async function E() {
|
|
91
|
+
await L({}, "build");
|
|
92
|
+
const n = k(process.argv.slice(2)), e = process.env.APP_PLATFORM_URL ?? n.APP_PLATFORM_URL;
|
|
92
93
|
if (!e)
|
|
93
94
|
return console.log(
|
|
94
95
|
f.red("error"),
|
|
@@ -98,7 +99,7 @@ async function I() {
|
|
|
98
99
|
return console.log(f.red("error"), "api-client-generator modules command is required");
|
|
99
100
|
if (!n.APP_API_CLIENT_DIRECTORY)
|
|
100
101
|
return console.log(f.red("error"), "api-client-generator outDir command is required");
|
|
101
|
-
const r = new
|
|
102
|
+
const r = new p(n.APP_API_CLIENT_DIRECTORY), i = n?.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(",");
|
|
102
103
|
for (const t of i) {
|
|
103
104
|
const o = r.resolveApiClientPaths(t);
|
|
104
105
|
console.log(
|
|
@@ -111,7 +112,7 @@ async function I() {
|
|
|
111
112
|
[
|
|
112
113
|
"run",
|
|
113
114
|
r.nswagPaths.configuration,
|
|
114
|
-
`/variables:APP_PLATFORM_URL=${e},APP_PLATFORM_MODULE=${t},APP_AUTH_API_BASE_PATH=${r.nswagPaths.authApiBase},APP_API_CLIENT_PATH=${o.nswag}`,
|
|
115
|
+
`/variables:APP_PLATFORM_URL=${e},APP_PLATFORM_MODULE=${t},APP_AUTH_API_BASE_PATH=${r.nswagPaths.authApiBase},APP_TEMPLATE_DIRECTORY=${r.nswagPaths.templates},APP_API_CLIENT_PATH=${o.nswag}`,
|
|
115
116
|
"/runtime:Net60"
|
|
116
117
|
],
|
|
117
118
|
{
|
|
@@ -129,4 +130,4 @@ async function I() {
|
|
|
129
130
|
);
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
|
-
|
|
133
|
+
E();
|
|
@@ -14,7 +14,7 @@ export class AuthApiBase {
|
|
|
14
14
|
|
|
15
15
|
protected transformOptions(options: any): Promise<any> {
|
|
16
16
|
if (this.authToken) {
|
|
17
|
-
options.headers[
|
|
17
|
+
options.headers["authorization"] = `Bearer ${this.authToken}`;
|
|
18
18
|
}
|
|
19
19
|
return Promise.resolve(options);
|
|
20
20
|
}
|
package/dist/assets/config.nswag
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"inlineNamedDictionaries": false,
|
|
64
64
|
"inlineNamedAny": false,
|
|
65
65
|
"includeHttpContext": false,
|
|
66
|
-
"templateDirectory":
|
|
66
|
+
"templateDirectory": "$(APP_TEMPLATE_DIRECTORY)",
|
|
67
67
|
"typeNameGeneratorType": null,
|
|
68
68
|
"propertyNameGeneratorType": null,
|
|
69
69
|
"enumNameGeneratorType": null,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vc-shell/api-client-generator",
|
|
3
3
|
"description": "Tool for API clients generation",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.132",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/api-client-generator.js",
|
|
7
7
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build": "vite build"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@vc-shell/ts-config": "^1.0.
|
|
15
|
+
"@vc-shell/ts-config": "^1.0.132",
|
|
16
16
|
"typescript": "^5.3.3"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
@@ -14,7 +14,7 @@ export class AuthApiBase {
|
|
|
14
14
|
|
|
15
15
|
protected transformOptions(options: any): Promise<any> {
|
|
16
16
|
if (this.authToken) {
|
|
17
|
-
options.headers[
|
|
17
|
+
options.headers["authorization"] = `Bearer ${this.authToken}`;
|
|
18
18
|
}
|
|
19
19
|
return Promise.resolve(options);
|
|
20
20
|
}
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"inlineNamedDictionaries": false,
|
|
64
64
|
"inlineNamedAny": false,
|
|
65
65
|
"includeHttpContext": false,
|
|
66
|
-
"templateDirectory":
|
|
66
|
+
"templateDirectory": "$(APP_TEMPLATE_DIRECTORY)",
|
|
67
67
|
"typeNameGeneratorType": null,
|
|
68
68
|
"propertyNameGeneratorType": null,
|
|
69
69
|
"enumNameGeneratorType": null,
|