Skip to content

Commit 9a34e2c

Browse files
committed
chore: added typings for sec ya headers
1 parent 079b9eb commit 9a34e2c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

packages/shared/src/data/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export default {
1515
defaultDuration: 343,
1616
minChunkSize: 5295308,
1717
loggerLevel: 1,
18-
version: "2.2.2",
18+
version: "2.2.3",
1919
} as ConfigSchema;

packages/shared/src/secure.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config from "./data/config";
22
import Logger from "./utils/logger";
3-
import { SecType, ClientSession, HashName } from "./types/secure";
3+
import { SecType, ClientSession, HashName, SecYaHeaders } from "./types/secure";
44

55
const { componentVersion } = config;
66

@@ -38,12 +38,12 @@ export async function getSignature(body: Uint8Array) {
3838
);
3939
}
4040

41-
export async function getSecYaHeaders(
42-
secType: SecType,
41+
export async function getSecYaHeaders<T extends SecType>(
42+
secType: T,
4343
session: ClientSession,
4444
body: Uint8Array,
4545
path: string,
46-
) {
46+
): Promise<SecYaHeaders<T>> {
4747
const { secretKey, uuid } = session;
4848
const sign = await getSignature(body);
4949

@@ -56,7 +56,7 @@ export async function getSecYaHeaders(
5656
[`${secType}-Signature`]: sign,
5757
[`Sec-${secType}-Sk`]: secretKey,
5858
[`Sec-${secType}-Token`]: `${tokenSign}:${token}`,
59-
};
59+
} as SecYaHeaders<T>;
6060
}
6161

6262
// yandex uuid
@@ -87,4 +87,4 @@ export const browserSecHeaders = {
8787
"sec-ch-ua": `"Chromium";v="130", "YaBrowser";v="${componentVersion.slice(0, 5)}", "Not?A_Brand";v="99", "Yowser";v="2.5"`,
8888
"sec-ch-ua-full-version-list": `"Chromium";v="130.0.6723.152", "YaBrowser";v="${componentVersion}", "Not?A_Brand";v="99.0.0.0", "Yowser";v="2.5"`,
8989
"Sec-Fetch-Mode": "no-cors",
90-
};
90+
} as const;

packages/shared/src/types/secure.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ export type ClientSession = {
1313
uuid: string;
1414
secretKey: string;
1515
};
16+
17+
export type SecYaHeader<T extends SecType> =
18+
| `${T}-Signature`
19+
| `Sec-${T}-Sk`
20+
| `Sec-${T}-Token`;
21+
export type SecYaHeaders<T extends SecType> = Record<SecYaHeader<T>, string>;

0 commit comments

Comments
 (0)