@@ -5,6 +5,7 @@ export type ClientConfiguration = {
55 tenantId ?: string ;
66 accessTokenId ?: string ;
77 accessTokenSecret ?: string ;
8+ staticAuthToken ?: string ;
89 sessionId ?: string ;
910 origin ?: string ;
1011} ;
@@ -21,6 +22,23 @@ export type ClientInterface = {
2122 config : Pick < ClientConfiguration , 'tenantIdentifier' | 'tenantId' | 'origin' > ;
2223} ;
2324
25+ function authenticationHeaders ( config : ClientConfiguration ) {
26+ if ( config . sessionId ) {
27+ return {
28+ Cookie : 'connect.sid=' + config . sessionId ,
29+ } ;
30+ }
31+ if ( config . staticAuthToken ) {
32+ return {
33+ 'X-Crystallize-Static-Auth-Token' : config . staticAuthToken ,
34+ } ;
35+ }
36+ return {
37+ 'X-Crystallize-Access-Token-Id' : config . accessTokenId || '' ,
38+ 'X-Crystallize-Access-Token-Secret' : config . accessTokenSecret || '' ,
39+ } ;
40+ }
41+
2442async function post < T > (
2543 path : string ,
2644 config : ClientConfiguration ,
@@ -35,12 +53,7 @@ async function post<T>(
3553 } ;
3654 const headers = {
3755 ...commonHeaders ,
38- ...( config . sessionId
39- ? { Cookie : 'connect.sid=' + config . sessionId }
40- : {
41- 'X-Crystallize-Access-Token-Id' : config . accessTokenId || '' ,
42- 'X-Crystallize-Access-Token-Secret' : config . accessTokenSecret || '' ,
43- } ) ,
56+ ...authenticationHeaders ( config ) ,
4457 } ;
4558 const body = JSON . stringify ( { query, variables } ) ;
4659
0 commit comments