@profcomff/api-uilib 2024.7.2-5.2 → 2024.7.27-1
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/.github/workflows/autogen.yaml +35 -0
- package/.github/workflows/publish.yaml +8 -3
- package/package.json +7 -3
- package/scripts/generate.js +80 -0
- package/scripts/setversion.js +22 -0
- package/src/index.d.ts +1 -3
- package/src/index.ts +3 -6
- package/src/openapi/achievement.ts +6 -6
- package/src/openapi/auth.ts +63 -63
- package/src/openapi/marketing.ts +3 -3
- package/src/openapi/print.ts +6 -6
- package/src/openapi/services.ts +5 -5
- package/src/openapi/social.ts +8 -8
- package/src/openapi/timetable.ts +21 -21
- package/src/openapi/userdata.ts +7 -7
- package/tsconfig.json +3 -1
- package/src/openapi/pinger.ts +0 -895
|
@@ -1,3 +1,38 @@
|
|
|
1
1
|
# Каждые 24 часа запускать кодогенерацию
|
|
2
2
|
# Если есть изменения в репозитории – создавать пулл реквест
|
|
3
3
|
# Если уже существует пулл реквест на обновление версии, закрыть его
|
|
4
|
+
name: Autogen API bindings
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
generate:
|
|
11
|
+
runs-on: 'ubuntu-latest'
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- uses: pnpm/action-setup@v2
|
|
16
|
+
with:
|
|
17
|
+
version: 9.6.0
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 18
|
|
22
|
+
registry-url: https://registry.npmjs.org/
|
|
23
|
+
cache: pnpm
|
|
24
|
+
|
|
25
|
+
- run: pnpm install
|
|
26
|
+
|
|
27
|
+
- run: pnpm generate
|
|
28
|
+
|
|
29
|
+
- name: Create Pull Request
|
|
30
|
+
uses: peter-evans/create-pull-request@v6
|
|
31
|
+
with:
|
|
32
|
+
branch: autogen
|
|
33
|
+
title: Automated API update
|
|
34
|
+
body: |
|
|
35
|
+
Автоматика заметила изменения в API, которые нужно прокинуть на фронтенд
|
|
36
|
+
|
|
37
|
+
Проверь кодогенерацию, если все ок – вмержи изменения
|
|
38
|
+
commit-message: API codegen update
|
|
@@ -2,7 +2,8 @@ name: Publish package to npm
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
6
7
|
|
|
7
8
|
jobs:
|
|
8
9
|
publish-npm:
|
|
@@ -22,6 +23,10 @@ jobs:
|
|
|
22
23
|
|
|
23
24
|
- run: pnpm install
|
|
24
25
|
|
|
25
|
-
- run:
|
|
26
|
+
- run: |
|
|
27
|
+
VERSION=${{ github.ref_name }}
|
|
28
|
+
pnpm setVersion -v ${VERSION:1}
|
|
29
|
+
|
|
30
|
+
- run: pnpm publish --no-git-checks
|
|
26
31
|
env:
|
|
27
|
-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
32
|
+
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profcomff/api-uilib",
|
|
3
|
-
"version": "2024.07.
|
|
3
|
+
"version": "2024.07.27-1",
|
|
4
4
|
"description": "API wrappers, autogenerated from openapi.json files",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
"author": "Roman Dyakov <roman@dyakov.space>",
|
|
12
12
|
"license": "BSD 3-Clause",
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@npmcli/package-json": "^5.2.0",
|
|
14
15
|
"openapi-typescript": "^7.1.0",
|
|
15
|
-
"
|
|
16
|
+
"simple-git": "^3.25.0",
|
|
17
|
+
"typescript": "^5.5.4",
|
|
18
|
+
"yargs-parser": "^21.1.1"
|
|
16
19
|
},
|
|
17
20
|
"dependencies": {
|
|
18
21
|
"openapi-fetch": "^0.10.2"
|
|
19
22
|
},
|
|
20
23
|
"scripts": {
|
|
21
|
-
"
|
|
24
|
+
"setVersion": "node ./scripts/setversion.js",
|
|
25
|
+
"generate": "node ./scripts/generate.js"
|
|
22
26
|
}
|
|
23
27
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const openapiTS = require("openapi-typescript").default;
|
|
3
|
+
const astToString = require("openapi-typescript").astToString;
|
|
4
|
+
const simpleGit = require("simple-git");
|
|
5
|
+
const PackageJson = require("@npmcli/package-json");
|
|
6
|
+
|
|
7
|
+
const apis = {
|
|
8
|
+
auth: "https://api.profcomff.com/auth/openapi.json",
|
|
9
|
+
marketing: "https://api.profcomff.com/marketing/openapi.json",
|
|
10
|
+
timetable: "https://api.profcomff.com/timetable/openapi.json",
|
|
11
|
+
services: "https://api.profcomff.com/services/openapi.json",
|
|
12
|
+
print: "https://api.profcomff.com/print/openapi.json",
|
|
13
|
+
social: "https://api.profcomff.com/social/openapi.json",
|
|
14
|
+
userdata: "https://api.profcomff.com/userdata/openapi.json",
|
|
15
|
+
achievement: "https://api.profcomff.com/achievement/openapi.json",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const header = `/**
|
|
19
|
+
* This file was auto-generated by openapi-typescript.
|
|
20
|
+
* Do not make direct changes to the file.
|
|
21
|
+
*/`.trim();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Добавляет к путям префикс, соответствующий пути к корню API
|
|
25
|
+
*/
|
|
26
|
+
const updatePathsWithPrefix = (prefix, ast) => {
|
|
27
|
+
for (const i in ast) {
|
|
28
|
+
for (const j in ast[i]["members"]) {
|
|
29
|
+
if (ast[i]["members"][j]["name"]) {
|
|
30
|
+
if (ast[i]["members"][j]["name"]["text"].startsWith("/")) {
|
|
31
|
+
ast[i]["members"][j]["name"]["text"] =
|
|
32
|
+
prefix + ast[i]["members"][j]["name"]["text"];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Генерирует список путей и интерфейсов
|
|
41
|
+
*/
|
|
42
|
+
const generate = async () => {
|
|
43
|
+
for (const file in apis) {
|
|
44
|
+
const spec = apis[file];
|
|
45
|
+
const prefix = "/" + file;
|
|
46
|
+
console.log(`Generating ${file} from ${spec}`);
|
|
47
|
+
|
|
48
|
+
const ast = await openapiTS(spec, {
|
|
49
|
+
alphabetize: true,
|
|
50
|
+
excludeDeprecated: true,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
updatePathsWithPrefix(prefix, ast);
|
|
54
|
+
|
|
55
|
+
const contents = astToString(ast);
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(`./src/openapi/${file}.ts`, header + "\n\n" + contents);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Проверяет есть ли изменения в репозитории, меняет версию в package-json если да
|
|
63
|
+
*/
|
|
64
|
+
const updateRepo = async () => {
|
|
65
|
+
const git = simpleGit();
|
|
66
|
+
|
|
67
|
+
// Ensure status
|
|
68
|
+
let status = await git.status();
|
|
69
|
+
if (Object.keys(status.modified).length === 0) {
|
|
70
|
+
console.log("Nothing changed");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
console.log(`${Object.keys(status.modified).length} files changed`);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
generate().then(() => {
|
|
77
|
+
updateRepo().then(() => {
|
|
78
|
+
console.log("Completed");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const parser = require("yargs-parser");
|
|
2
|
+
const PackageJson = require("@npmcli/package-json");
|
|
3
|
+
|
|
4
|
+
const updateRepo = async (version) => {
|
|
5
|
+
// Change version in package.json file
|
|
6
|
+
const pkgJson = await PackageJson.load(".");
|
|
7
|
+
pkgJson.update({
|
|
8
|
+
version: version,
|
|
9
|
+
});
|
|
10
|
+
pkgJson.save();
|
|
11
|
+
console.log(`package.json version updated to ${version}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const [, , ...args] = process.argv;
|
|
15
|
+
const flags = parser(args, {
|
|
16
|
+
string: ["version"],
|
|
17
|
+
alias: {
|
|
18
|
+
version: ["v"],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
updateRepo(flags.version);
|
package/src/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Client from "openapi-fetch";
|
|
|
2
2
|
import type { paths as achievementPaths } from "./openapi/achievement.ts";
|
|
3
3
|
import type { paths as authPaths } from "./openapi/auth.ts";
|
|
4
4
|
import type { paths as marketingPaths } from "./openapi/marketing.ts";
|
|
5
|
-
import type { paths as pingerPaths } from "./openapi/pinger.ts";
|
|
6
5
|
import type { paths as printPaths } from "./openapi/print.ts";
|
|
7
6
|
import type { paths as servicesPaths } from "./openapi/services.ts";
|
|
8
7
|
import type { paths as socialPaths } from "./openapi/social.ts";
|
|
@@ -13,12 +12,11 @@ export type paths = (
|
|
|
13
12
|
achievementPaths &
|
|
14
13
|
authPaths &
|
|
15
14
|
marketingPaths &
|
|
16
|
-
pingerPaths &
|
|
17
15
|
printPaths &
|
|
18
16
|
servicesPaths &
|
|
19
17
|
socialPaths &
|
|
20
18
|
timetablePaths &
|
|
21
19
|
userdataPaths
|
|
22
20
|
);
|
|
23
|
-
export function createClient(baseUrl: string): ReturnType<typeof Client
|
|
21
|
+
export function createClient(baseUrl: string): ReturnType<typeof Client<paths>>;
|
|
24
22
|
export function setupAuth(newToken: string | null): void;
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { Middleware } from "openapi-fetch";
|
|
|
4
4
|
import type { paths as achievementPaths } from "./openapi/achievement.ts";
|
|
5
5
|
import type { paths as authPaths } from "./openapi/auth.ts";
|
|
6
6
|
import type { paths as marketingPaths } from "./openapi/marketing.ts";
|
|
7
|
-
import type { paths as pingerPaths } from "./openapi/pinger.ts";
|
|
8
7
|
import type { paths as printPaths } from "./openapi/print.ts";
|
|
9
8
|
import type { paths as servicesPaths } from "./openapi/services.ts";
|
|
10
9
|
import type { paths as socialPaths } from "./openapi/social.ts";
|
|
@@ -12,14 +11,10 @@ import type { paths as timetablePaths } from "./openapi/timetable.ts";
|
|
|
12
11
|
import type { paths as userdataPaths } from "./openapi/userdata.ts";
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
let currentClient: ReturnType<typeof Client> | undefined = undefined;
|
|
16
|
-
let currentToken: string | undefined = undefined;
|
|
17
|
-
|
|
18
14
|
export type paths = (
|
|
19
15
|
achievementPaths &
|
|
20
16
|
authPaths &
|
|
21
17
|
marketingPaths &
|
|
22
|
-
pingerPaths &
|
|
23
18
|
printPaths &
|
|
24
19
|
servicesPaths &
|
|
25
20
|
socialPaths &
|
|
@@ -27,6 +22,9 @@ export type paths = (
|
|
|
27
22
|
userdataPaths
|
|
28
23
|
);
|
|
29
24
|
|
|
25
|
+
let currentClient: ReturnType<typeof Client<paths>> | undefined = undefined;
|
|
26
|
+
let currentToken: string | undefined = undefined;
|
|
27
|
+
|
|
30
28
|
const authMiddleware: Middleware = {
|
|
31
29
|
async onRequest({ request, options }) {
|
|
32
30
|
request.headers.set("Authorization", currentToken);
|
|
@@ -56,4 +54,3 @@ export const setupAuth = (newToken: string | null) => {
|
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export interface paths {
|
|
7
|
-
"/achievement": {
|
|
7
|
+
"/achievement/achievement": {
|
|
8
8
|
parameters: {
|
|
9
9
|
query?: never;
|
|
10
10
|
header?: never;
|
|
@@ -25,7 +25,7 @@ export interface paths {
|
|
|
25
25
|
patch?: never;
|
|
26
26
|
trace?: never;
|
|
27
27
|
};
|
|
28
|
-
"/achievement/{achievement_id}/reciever": {
|
|
28
|
+
"/achievement/achievement/{achievement_id}/reciever": {
|
|
29
29
|
parameters: {
|
|
30
30
|
query?: never;
|
|
31
31
|
header?: never;
|
|
@@ -42,7 +42,7 @@ export interface paths {
|
|
|
42
42
|
patch?: never;
|
|
43
43
|
trace?: never;
|
|
44
44
|
};
|
|
45
|
-
"/achievement/{achievement_id}/reciever/{user_id}": {
|
|
45
|
+
"/achievement/achievement/{achievement_id}/reciever/{user_id}": {
|
|
46
46
|
parameters: {
|
|
47
47
|
query?: never;
|
|
48
48
|
header?: never;
|
|
@@ -66,7 +66,7 @@ export interface paths {
|
|
|
66
66
|
patch?: never;
|
|
67
67
|
trace?: never;
|
|
68
68
|
};
|
|
69
|
-
"/achievement/{id}": {
|
|
69
|
+
"/achievement/achievement/{id}": {
|
|
70
70
|
parameters: {
|
|
71
71
|
query?: never;
|
|
72
72
|
header?: never;
|
|
@@ -91,7 +91,7 @@ export interface paths {
|
|
|
91
91
|
patch: operations["edit_achievement_achievement__id__patch"];
|
|
92
92
|
trace?: never;
|
|
93
93
|
};
|
|
94
|
-
"/achievement/{id}/picture": {
|
|
94
|
+
"/achievement/achievement/{id}/picture": {
|
|
95
95
|
parameters: {
|
|
96
96
|
query?: never;
|
|
97
97
|
header?: never;
|
|
@@ -108,7 +108,7 @@ export interface paths {
|
|
|
108
108
|
patch: operations["upload_picture_achievement__id__picture_patch"];
|
|
109
109
|
trace?: never;
|
|
110
110
|
};
|
|
111
|
-
"/user/{user_id}": {
|
|
111
|
+
"/achievement/user/{user_id}": {
|
|
112
112
|
parameters: {
|
|
113
113
|
query?: never;
|
|
114
114
|
header?: never;
|