@profcomff/api-uilib 2024.7.27 → 2024.7.28

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.
@@ -4,8 +4,7 @@
4
4
  name: Autogen API bindings
5
5
 
6
6
  on:
7
- schedule:
8
- - cron: "30 00 * * *"
7
+ workflow_dispatch:
9
8
 
10
9
  jobs:
11
10
  generate:
@@ -30,7 +29,6 @@ jobs:
30
29
  - name: Create Pull Request
31
30
  uses: peter-evans/create-pull-request@v6
32
31
  with:
33
- commit-message:
34
32
  branch: autogen
35
33
  title: Automated API update
36
34
  body: |
@@ -2,7 +2,8 @@ name: Publish package to npm
2
2
 
3
3
  on:
4
4
  push:
5
- branches: ["main"]
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: pnpm publish
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.7.27",
3
+ "version": "2024.07.28",
4
4
  "description": "API wrappers, autogenerated from openapi.json files",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.d.ts",
@@ -14,12 +14,14 @@
14
14
  "@npmcli/package-json": "^5.2.0",
15
15
  "openapi-typescript": "^7.1.0",
16
16
  "simple-git": "^3.25.0",
17
- "typescript": "^5.5.4"
17
+ "typescript": "^5.5.4",
18
+ "yargs-parser": "^21.1.1"
18
19
  },
19
20
  "dependencies": {
20
21
  "openapi-fetch": "^0.10.2"
21
22
  },
22
23
  "scripts": {
23
- "generate": "node ./generate.js"
24
+ "setVersion": "node ./scripts/setversion.js",
25
+ "generate": "node ./scripts/generate.js"
24
26
  }
25
27
  }
@@ -63,7 +63,6 @@ const generate = async () => {
63
63
  */
64
64
  const updateRepo = async () => {
65
65
  const git = simpleGit();
66
- const date = new Date();
67
66
 
68
67
  // Ensure status
69
68
  let status = await git.status();
@@ -72,16 +71,6 @@ const updateRepo = async () => {
72
71
  return;
73
72
  }
74
73
  console.log(`${Object.keys(status.modified).length} files changed`);
75
-
76
- // Change version in package.json file
77
- const pkgJson = await PackageJson.load(".");
78
- pkgJson.update({
79
- version: `${date.getUTCFullYear()}.${date.getUTCMonth()+1}.${date.getUTCDate()}`,
80
- });
81
- pkgJson.save();
82
- console.log(
83
- `package.json version updated to ${date.getUTCFullYear()}.${date.getUTCMonth()+1}.${date.getUTCDate()}`
84
- );
85
74
  };
86
75
 
87
76
  generate().then(() => {
@@ -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.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);
@@ -34,7 +32,7 @@ const authMiddleware: Middleware = {
34
32
  },
35
33
  };
36
34
 
37
- export const createClient = (baseUrl: string) => {
35
+ export const createClient = (baseUrl: string): ReturnType<typeof Client<paths>> => {
38
36
  if (currentClient) {
39
37
  throw new Error("Client already initialized");
40
38
  }
@@ -46,6 +44,10 @@ export const createClient = (baseUrl: string) => {
46
44
  return currentClient;
47
45
  }
48
46
 
47
+ export const createTestClient = (baseUrl: string): ReturnType<typeof Client<paths>> => {
48
+ return Client<paths>({ baseUrl });
49
+ }
50
+
49
51
  export const setupAuth = (newToken: string | null) => {
50
52
  currentToken = newToken;
51
53
  if (currentClient !== undefined) {
@@ -56,4 +58,3 @@ export const setupAuth = (newToken: string | null) => {
56
58
  }
57
59
  }
58
60
  }
59
-
package/src/index.d.ts DELETED
@@ -1,24 +0,0 @@
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<paths>>;
24
- export function setupAuth(newToken: string | null): void;