File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,9 @@ const sirv = new SirvClient({
132132// Connect and obtain token (called automatically when needed)
133133await sirv .connect ();
134134
135+ // Optional: Request a token with custom expiry time (5-604800 seconds)
136+ await sirv .connect (3600 ); // Token valid for 1 hour
137+
135138// Check if connected
136139if (sirv .isConnected ()) {
137140 console .log (' Connected!' );
@@ -141,6 +144,10 @@ if (sirv.isConnected()) {
141144const token = sirv .getAccessToken ();
142145```
143146
147+ The ` connect() ` method accepts an optional ` expiresIn ` parameter to customize token lifetime:
148+ - ** Range** : 5 to 604800 seconds (7 days)
149+ - ** Default** : 1200 seconds (20 minutes)
150+
144151### Account API
145152
146153``` javascript
Original file line number Diff line number Diff line change 66 < title > Sirv REST API SDK Documentation</ title >
77 < style >
88 : root {
9- --primary-color : # 0066cc ;
9+ --primary-color : # 327bba ;
1010 --primary-dark : # 004d99 ;
1111 --secondary-color : # 28a745 ;
1212 --text-color : # 333 ;
103103 }
104104
105105 h2 {
106- color : var (--primary -color );
106+ color : var (--text -color );
107107 font-size : 1.8rem ;
108108 margin-bottom : 20px ;
109109 padding-bottom : 10px ;
@@ -530,9 +530,17 @@ <h2>API Reference</h2>
530530 <!-- Authentication -->
531531 < h3 > Authentication</ h3 >
532532 < div class ="api-method ">
533- < h4 > connect()</ h4 >
533+ < h4 > connect(expiresIn? )</ h4 >
534534 < p > Connects to Sirv API and obtains access token. Called automatically when needed.</ p >
535- < pre > < code > await sirv.connect();</ code > </ pre >
535+ < p > < strong > Parameters:</ strong > </ p >
536+ < ul >
537+ < li > < code > expiresIn</ code > (optional): Token expiry time in seconds (5-604800). Default is 1200 (20 minutes).</ li >
538+ </ ul >
539+ < pre > < code > // Default token (20 minutes)
540+ await sirv.connect();
541+
542+ // Custom expiry time (1 hour)
543+ await sirv.connect(3600);</ code > </ pre >
536544 </ div >
537545
538546 < div class ="api-method ">
Original file line number Diff line number Diff line change @@ -289,14 +289,22 @@ export class SirvClient {
289289
290290 /**
291291 * Authenticate and obtain a bearer token
292+ * @param expiresIn - Optional token expiry time in seconds (5-604800). Default is 1200 (20 minutes).
292293 * @returns Token response with token, expiration, and scopes
293294 */
294- async connect ( ) : Promise < TokenResponse > {
295- const body = {
295+ async connect ( expiresIn ?: number ) : Promise < TokenResponse > {
296+ const body : Record < string , unknown > = {
296297 clientId : this . config . clientId ,
297298 clientSecret : this . config . clientSecret ,
298299 } ;
299300
301+ if ( expiresIn !== undefined ) {
302+ if ( expiresIn < 5 || expiresIn > 604800 ) {
303+ throw new SirvApiError ( 'expiresIn must be between 5 and 604800 seconds' , 400 ) ;
304+ }
305+ body . expiresIn = expiresIn ;
306+ }
307+
300308 let data : TokenResponse ;
301309
302310 if ( isNode && this . axios ) {
You can’t perform that action at this time.
0 commit comments