File tree Expand file tree Collapse file tree 4 files changed +24
-4
lines changed Expand file tree Collapse file tree 4 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export type {
1111export { enableConsoleLogger , setLogger } from './internal/logger'
1212export type { Logger } from './internal/logger/logger'
1313export { createClient , createAdvancedClient } from './scw/client'
14+ export { AUTH_HEADER_KEY , SESSION_HEADER_KEY } from './scw/constants'
1415export type { Client } from './scw/client'
1516export type { Profile } from './scw/client-ini-profile'
1617export type { Settings } from './scw/client-settings'
Original file line number Diff line number Diff line change @@ -5,14 +5,30 @@ import {
55import type { RequestInterceptor } from '../internal/interceptors/types'
66import { assertValidAuthenticationSecrets } from './client-ini-profile'
77import 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
1210interface 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 *
Original file line number Diff line number Diff line change 11import pkg from '../../package.json'
22
33export const { version } = pkg
4-
54export 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'
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments