@profcomff/api-uilib 2024.7.2-5.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.
@@ -0,0 +1,3 @@
1
+ # Каждые 24 часа запускать кодогенерацию
2
+ # Если есть изменения в репозитории – создавать пулл реквест
3
+ # Если уже существует пулл реквест на обновление версии, закрыть его
@@ -0,0 +1,27 @@
1
+ name: Publish package to npm
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+
7
+ jobs:
8
+ publish-npm:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - uses: pnpm/action-setup@v2
14
+ with:
15
+ version: 9.6.0
16
+
17
+ - uses: actions/setup-node@v4
18
+ with:
19
+ node-version: 18
20
+ registry-url: https://registry.npmjs.org/
21
+ cache: pnpm
22
+
23
+ - run: pnpm install
24
+
25
+ - run: pnpm publish
26
+ env:
27
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Профком студентов физфака МГУ
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Схемы и клиент для взаимодействия с API Твой ФФ
2
+
3
+ Представляет интерфейс для совершения запросов к API по адресу <https://api.profcomff.com>.
4
+
5
+
6
+ [<img src="https://cdn.profcomff.com/easycode/easycode.svg" width="200"></img>](https://easycode.profcomff.com/templates/docker-node/workspace?mode=manual&param.Repository+URL=https://github.com/profcomff/api-uilib.git&param.Working+directory=api-uilib)
7
+
8
+ ## Использование
9
+
10
+ ```ts
11
+ import { createClient } from '@profcomff/api-uilib';
12
+
13
+ // Setup client with base API path
14
+ // You can use environment `import.meta.env.VITE_API_URL` for example
15
+ const apiClient = createClient("https://api.test.profcomff.com");
16
+
17
+ // Setup token for requests to API
18
+ // It is optional, only for routes with authention
19
+ setupAuth("myApiTokenHere");
20
+
21
+ // Make request
22
+ const me_with_scopes = await apiClient.GET("/auth/me", {
23
+ params: {
24
+ query: {
25
+ info: ["session_scopes"]
26
+ }
27
+ }
28
+ });
29
+ ```
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@profcomff/api-uilib",
3
+ "version": "2024.07.25.1",
4
+ "description": "API wrappers, autogenerated from openapi.json files",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.d.ts",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "keywords": [],
11
+ "author": "Roman Dyakov <roman@dyakov.space>",
12
+ "license": "BSD 3-Clause",
13
+ "devDependencies": {
14
+ "openapi-typescript": "^7.1.0",
15
+ "typescript": "^5.5.4"
16
+ },
17
+ "dependencies": {
18
+ "openapi-fetch": "^0.10.2"
19
+ },
20
+ "scripts": {
21
+ "generate": "openapi-typescript -c --alphabetize --path-params-as-types"
22
+ }
23
+ }
package/redocly.yaml ADDED
@@ -0,0 +1,44 @@
1
+ resolve:
2
+ http:
3
+ headers:
4
+ - matches: https://api.profcomff.com/**
5
+ name: Authorization
6
+ envVariable: SECRET_KEY
7
+
8
+ apis:
9
+ auth@latest:
10
+ root: https://api.profcomff.com/auth/openapi.json
11
+ x-openapi-ts:
12
+ output: ./src/openapi/auth.ts
13
+ marketing@latest:
14
+ root: https://api.profcomff.com/marketing/openapi.json
15
+ x-openapi-ts:
16
+ output: ./src/openapi/marketing.ts
17
+ timetable@latest:
18
+ root: https://api.profcomff.com/timetable/openapi.json
19
+ x-openapi-ts:
20
+ output: ./src/openapi/timetable.ts
21
+ services@latest:
22
+ root: https://api.profcomff.com/services/openapi.json
23
+ x-openapi-ts:
24
+ output: ./src/openapi/services.ts
25
+ print@latest:
26
+ root: https://api.profcomff.com/print/openapi.json
27
+ x-openapi-ts:
28
+ output: ./src/openapi/print.ts
29
+ social@latest:
30
+ root: https://api.profcomff.com/social/openapi.json
31
+ x-openapi-ts:
32
+ output: ./src/openapi/social.ts
33
+ userdata@latest:
34
+ root: https://api.profcomff.com/userdata/openapi.json
35
+ x-openapi-ts:
36
+ output: ./src/openapi/userdata.ts
37
+ achievement@latest:
38
+ root: https://api.profcomff.com/achievement/openapi.json
39
+ x-openapi-ts:
40
+ output: ./src/openapi/achievement.ts
41
+ pinger@latest:
42
+ root: https://pinger.profcomff.com/openapi.json
43
+ x-openapi-ts:
44
+ output: ./src/openapi/pinger.ts
package/src/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import Client from "openapi-fetch";
2
+ import type { paths as achievementPaths } from "./openapi/achievement.ts";
3
+ import type { paths as authPaths } from "./openapi/auth.ts";
4
+ import type { paths as marketingPaths } from "./openapi/marketing.ts";
5
+ import type { paths as pingerPaths } from "./openapi/pinger.ts";
6
+ import type { paths as printPaths } from "./openapi/print.ts";
7
+ import type { paths as servicesPaths } from "./openapi/services.ts";
8
+ import type { paths as socialPaths } from "./openapi/social.ts";
9
+ import type { paths as timetablePaths } from "./openapi/timetable.ts";
10
+ import type { paths as userdataPaths } from "./openapi/userdata.ts";
11
+
12
+ export type paths = (
13
+ achievementPaths &
14
+ authPaths &
15
+ marketingPaths &
16
+ pingerPaths &
17
+ printPaths &
18
+ servicesPaths &
19
+ socialPaths &
20
+ timetablePaths &
21
+ userdataPaths
22
+ );
23
+ export function createClient(baseUrl: string): ReturnType<typeof Client>;
24
+ export function setupAuth(newToken: string | null): void;
package/src/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ import Client from "openapi-fetch";
2
+ import { Middleware } from "openapi-fetch";
3
+
4
+ import type { paths as achievementPaths } from "./openapi/achievement.ts";
5
+ import type { paths as authPaths } from "./openapi/auth.ts";
6
+ import type { paths as marketingPaths } from "./openapi/marketing.ts";
7
+ import type { paths as pingerPaths } from "./openapi/pinger.ts";
8
+ import type { paths as printPaths } from "./openapi/print.ts";
9
+ import type { paths as servicesPaths } from "./openapi/services.ts";
10
+ import type { paths as socialPaths } from "./openapi/social.ts";
11
+ import type { paths as timetablePaths } from "./openapi/timetable.ts";
12
+ import type { paths as userdataPaths } from "./openapi/userdata.ts";
13
+
14
+
15
+ let currentClient: ReturnType<typeof Client> | undefined = undefined;
16
+ let currentToken: string | undefined = undefined;
17
+
18
+ export type paths = (
19
+ achievementPaths &
20
+ authPaths &
21
+ marketingPaths &
22
+ pingerPaths &
23
+ printPaths &
24
+ servicesPaths &
25
+ socialPaths &
26
+ timetablePaths &
27
+ userdataPaths
28
+ );
29
+
30
+ const authMiddleware: Middleware = {
31
+ async onRequest({ request, options }) {
32
+ request.headers.set("Authorization", currentToken);
33
+ return request;
34
+ },
35
+ };
36
+
37
+ export const createClient = (baseUrl: string) => {
38
+ if (currentClient) {
39
+ throw new Error("Client already initialized");
40
+ }
41
+
42
+ currentClient = Client<paths>({ baseUrl })
43
+ if (currentToken !== null) {
44
+ currentClient.use(authMiddleware);
45
+ }
46
+ return currentClient;
47
+ }
48
+
49
+ export const setupAuth = (newToken: string | null) => {
50
+ currentToken = newToken;
51
+ if (currentClient !== undefined) {
52
+ if (newToken === null) {
53
+ currentClient.eject(authMiddleware)
54
+ } else {
55
+ currentClient.use(authMiddleware);
56
+ }
57
+ }
58
+ }
59
+