Skip to content

Commit 332b58f

Browse files
authored
feat(client): add pl-waw-3 zone, add headers, add sessionheader (#2016)
1 parent 939bed6 commit 332b58f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

packages/client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type {
1111
export { enableConsoleLogger, setLogger } from './internal/logger'
1212
export type { Logger } from './internal/logger/logger'
1313
export { createClient, createAdvancedClient } from './scw/client'
14+
export { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from './scw/constants'
1415
export type { Client } from './scw/client'
1516
export type { Profile } from './scw/client-ini-profile'
1617
export type { Settings } from './scw/client-settings'

packages/client/src/scw/auth.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@ import {
55
import type { RequestInterceptor } from '../internal/interceptors/types'
66
import { assertValidAuthenticationSecrets } from './client-ini-profile'
77
import type { AuthenticationSecrets } from './client-ini-profile'
8-
9-
const SESSION_HEADER_KEY = 'x-session-token'
10-
const AUTH_HEADER_KEY = 'x-auth-token'
8+
import { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from './constants'
119

1210
interface TokenAccessor {
1311
(): Promise<string | undefined>
1412
}
1513

14+
interface AddSessionHeader {
15+
request: Request
16+
getAsyncToken: () => Promise<string | undefined>
17+
}
18+
/**
19+
* Add an JWT Session Header to a request through an interceptor.
20+
*
21+
* @param request - The request to modify
22+
* @param getJwt - The session value
23+
* @returns The Request interceptor
24+
*
25+
*/
26+
export const addSessionHeader = async ({
27+
request,
28+
getAsyncToken,
29+
}: AddSessionHeader) =>
30+
addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getAsyncToken)({ request })
31+
1632
/**
1733
* Authenticates with a session token.
1834
*
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pkg from '../../package.json'
22

33
export const { version } = pkg
4-
54
export const userAgent = `scaleway-sdk-js/${version}`
5+
6+
export const SESSION_HEADER_KEY = 'x-session-token'
7+
export const AUTH_HEADER_KEY = 'x-auth-token'

packages/client/src/scw/locality.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export type Zone =
1010
| 'nl-ams-3'
1111
| 'pl-waw-1'
1212
| 'pl-waw-2'
13+
| 'pl-waw-3'
1314
| (string & {})
1415
/* eslint-enable @typescript-eslint/ban-types */

0 commit comments

Comments
 (0)