Skip to content

Commit b283d83

Browse files
fix(project): 👽 Kideapp changes now better handled
1 parent 59dacc5 commit b283d83

File tree

15 files changed

+8335
-6480
lines changed

15 files changed

+8335
-6480
lines changed

apps/web/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web",
3-
"version": "4.7.0",
3+
"version": "4.8.0",
44
"private": true,
55
"scripts": {
66
"dev": "concurrently pnpm:dev:*",
@@ -17,6 +17,8 @@
1717
"build-storybook": "storybook build"
1818
},
1919
"devDependencies": {
20+
"@babel/parser": "^7.26.3",
21+
"@babel/types": "^7.26.3",
2022
"@common/types": "workspace:*",
2123
"@floating-ui/dom": "^1.2.8",
2224
"@formkit/auto-animate": "1.0.0-beta.6",

apps/web/src/routes/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
logs = [];
1919
const bot = new KideAppBot({
2020
token: $normalizedToken,
21-
extraIdApiUrl: `/api/extraid`
21+
extraIdApiUrl: `/api/extra-properties`
2222
});
2323
bot.setOnIsActiveChanged(isActive => (isRunning = isActive));
2424
bot.setOnLog(log => (logs = [...logs, log]));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getLatestExtraProperties } from 'kideappbot';
2+
import type { RequestHandler } from '../$types';
3+
4+
export const GET: RequestHandler = async () => {
5+
const extraProperties = await getLatestExtraProperties();
6+
return new Response(JSON.stringify(extraProperties));
7+
};

apps/web/src/routes/api/extraid/+server.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/aleksivirkkala/kideappbot.git"
99
},
10-
"version": "4.7.0",
10+
"version": "4.8.0",
1111
"scripts": {
1212
"build": "turbo run build",
1313
"dev": "dotenv -- turbo run dev --concurrency 16",

packages/bot-logic/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kideappbot",
3-
"version": "2.7.2",
3+
"version": "2.8.0",
44
"private": true,
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -18,7 +18,8 @@
1818
"author": "Aleksi Virkkala",
1919
"license": "UNLICENSED",
2020
"dependencies": {
21-
"@aleksivirkkala/kideappbot-private": "1.0.0",
21+
"@babel/parser": "^7.26.3",
22+
"@babel/types": "^7.26.3",
2223
"@common/constants": "workspace:*",
2324
"@common/types": "workspace:*",
2425
"@common/utils": "workspace:*",
@@ -29,16 +30,16 @@
2930
},
3031
"devDependencies": {
3132
"@types/node": "^18.15.0",
32-
"@vitest/coverage-c8": "^0.29.2",
33+
"@vitest/coverage-c8": "^0.33.0",
3334
"eslint-config-base": "workspace:*",
3435
"module-alias": "^2.2.2",
35-
"msw": "^1.2.0",
36+
"msw": "^2.6.8",
3637
"nodemon": "^2.0.21",
3738
"tsconfig": "workspace:*",
3839
"tsup": "^6.7.0",
3940
"tsup-config-base": "workspace:*",
4041
"typescript": "^5.0.4",
41-
"vitest": "^0.29.8"
42+
"vitest": "^2.1.8"
4243
},
4344
"type": "module"
4445
}

packages/bot-logic/src/bot.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LogMessage, LogType } from '@common/types';
66
import jwtDecode, { InvalidTokenError } from 'jwt-decode';
77
import { getTimeLeft, timeout } from '@common/utils';
88
import { BotError, FatalBotError, NotImplementedError } from '@/utils/errorUtils';
9-
import { getLatestExtraID } from '@/utils/reverser';
9+
import { ExtraProperties, getLatestExtraProperties } from '@/utils/reverser';
1010
import {
1111
Variant,
1212
ReservationsPostResponse,
@@ -40,7 +40,10 @@ interface BotOptions {
4040
}
4141

4242
export class KideAppBot {
43-
protected extraId = LATEST_EXTRA_ID;
43+
protected extraProperties: ExtraProperties = {
44+
extraId: LATEST_EXTRA_ID,
45+
xRequestedTokenKey: 'X-Requested-Token-a02'
46+
};
4447
protected _botIsActive = false;
4548
protected silentLog = false;
4649
protected startTime: number | null = null;
@@ -88,12 +91,16 @@ export class KideAppBot {
8891
icon: '🆔',
8992
title: 'Fetching extra ID...'
9093
});
91-
const latestExtraId = await getLatestExtraID(this.options.extraIdApiUrl);
92-
this.extraId = latestExtraId;
94+
this.extraProperties = await getLatestExtraProperties(this.options.extraIdApiUrl);
95+
this.fullLog({
96+
icon: '✅',
97+
title: 'Received extra header key',
98+
content: this.extraProperties.xRequestedTokenKey
99+
});
93100
this.fullLog({
94101
icon: '✅',
95102
title: 'Received extra ID',
96-
content: latestExtraId
103+
content: this.extraProperties.extraId
97104
});
98105
} catch (e) {
99106
console.error(e);
@@ -104,8 +111,6 @@ export class KideAppBot {
104111
content: e.message,
105112
force: true
106113
});
107-
// As a backup return latest known extraID
108-
this.extraId = LATEST_EXTRA_ID;
109114
}
110115
}
111116
}
@@ -126,7 +131,10 @@ export class KideAppBot {
126131
'Content-Type': 'application/json;charset=UTF-8',
127132
accept: 'application/json, text/plain, */*',
128133
authorization: 'Bearer ' + token,
129-
'X-Requested-Token-c69': calculateXRequestedId(inventoryId, this.extraId)
134+
[this.extraProperties.xRequestedTokenKey]: calculateXRequestedId(
135+
inventoryId,
136+
this.extraProperties.extraId
137+
)
130138
};
131139

132140
return await axios.post<ReservationsPostResponse>(API_RESERVATION_ENDPOINT, body, { headers });

packages/bot-logic/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Bot to be used in the app
22
export { KideAppBot as default } from './bot';
33

4-
export { getLatestExtraID } from './utils/reverser';
4+
export { getLatestExtraProperties, type ExtraProperties } from './utils/reverser';

0 commit comments

Comments
 (0)