@@ -6,6 +6,8 @@ import React, { FC, useEffect, useMemo, useState } from 'react';
66
77import { default as ACSDeclarativesContext } from '../contexts/ACSClientsContext' ;
88import createDebug from '../utils/debug' ;
9+ import ResolvableToken from '../types/ResolvableToken' ;
10+ import resolveFunction from '../utils/resolveFunction' ;
911import styleConsole from '../utils/styleConsole' ;
1012
1113// TODO: This is from acs-ui-sdk, we need it.
@@ -28,7 +30,7 @@ let debug;
2830
2931// TODO: Type "children".
3032// eslint-disable-next-line @typescript-eslint/no-explicit-any
31- const ACSDeclarativesComposer : FC < { children : any ; endpointURL : string ; threadId : string ; token : string } > = ( {
33+ const ACSClientsComposer : FC < { children : any ; endpointURL : string ; threadId : string ; token : ResolvableToken } > = ( {
3234 children,
3335 endpointURL,
3436 threadId,
@@ -40,12 +42,12 @@ const ACSDeclarativesComposer: FC<{ children: any; endpointURL: string; threadId
4042 const credentials = useMemo < { dispose ( ) : void ; getToken ( ) : Promise < { expiresOnTimestamp : number ; token : string } > } > (
4143 ( ) => ( {
4244 dispose : ( ) => undefined ,
43- getToken : ( ) =>
44- Promise . resolve ( {
45- // TODO: Should we extract the expiry from the token?
46- expiresOnTimestamp : Infinity ,
47- token
48- } )
45+ getToken : async ( ) => {
46+ const actualToken = await resolveFunction ( token ) ;
47+
48+ // TODO: Should we extract the expiry from the token?
49+ return { expiresOnTimestamp : Infinity , token : actualToken } ;
50+ }
4951 } ) ,
5052 [ token ]
5153 ) ;
@@ -119,15 +121,15 @@ const ACSDeclarativesComposer: FC<{ children: any; endpointURL: string; threadId
119121 return < ACSDeclarativesContext . Provider value = { context } > { children } </ ACSDeclarativesContext . Provider > ;
120122} ;
121123
122- ACSDeclarativesComposer . defaultProps = {
124+ ACSClientsComposer . defaultProps = {
123125 children : undefined
124126} ;
125127
126- ACSDeclarativesComposer . propTypes = {
128+ ACSClientsComposer . propTypes = {
127129 children : PropTypes . any ,
128130 endpointURL : PropTypes . string . isRequired ,
129131 threadId : PropTypes . string . isRequired ,
130- token : PropTypes . string . isRequired
132+ token : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] ) . isRequired
131133} ;
132134
133- export default ACSDeclarativesComposer ;
135+ export default ACSClientsComposer ;
0 commit comments