@@ -5,15 +5,11 @@ import { StyleFamily } from "./types/StyleFamily.js";
5
5
import { deserializeAuthentication } from "./utils/deserializeAuthentication.js" ;
6
6
import { startNewSession } from "./utils/startNewSession.js" ;
7
7
import { Writable } from "./utils/writable.js" ;
8
-
9
- export const DEFAULT_START_BASEMAP_SESSION_URL =
10
- "https://basemapstylesdev-api.arcgis.com/arcgis/rest/services/styles/v2/sessions/start" ;
11
-
12
- export const DEFAULT_START_STATIC_BASEMAP_SESSION_URL =
13
- "https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1/sessions/start" ;
14
-
15
- const DEFAULT_SAFETY_MARGIN = 1000 * 60 * 5 ; // Default to 5 minutes
16
- const DEFAULT_CHECK_EXPIRATION_INTERVAL = 1000 * 10 ; // Default to 1 minute
8
+ import {
9
+ DEFAULT_DURATION ,
10
+ DEFAULT_SAFETY_MARGIN ,
11
+ DEFAULT_CHECK_EXPIRATION_INTERVAL
12
+ } from "./utils/defaults.js" ;
17
13
18
14
export interface IBasemapSessionParams {
19
15
token : string ;
@@ -24,7 +20,7 @@ export interface IBasemapSessionParams {
24
20
startTime : Date | string ;
25
21
endTime : Date | string ;
26
22
safetyMargin ?: number ;
27
- testSession ?: boolean ;
23
+ duration ?: number ;
28
24
}
29
25
30
26
export interface IStartSessionParams {
@@ -137,9 +133,9 @@ export abstract class BaseSession implements IAuthenticationManager {
137
133
readonly saftyMargin : number ;
138
134
139
135
/**
140
- * Indicates if the session is a test session.
136
+ * The duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed .
141
137
*/
142
- readonly testSession : boolean ;
138
+ readonly duration : number ;
143
139
144
140
/**
145
141
* The ID of the timer used to check the expiration time of the session.
@@ -165,14 +161,14 @@ export abstract class BaseSession implements IAuthenticationManager {
165
161
* @param params.startTime - The start time of the session.
166
162
* @param params.endTime - The end time of the session.
167
163
* @param params.safetyMargin - The safety margin in milliseconds.
168
- * @param params.testSession - Indicates if this is a test session.
164
+ * @param params.duration - Indicates if this is a test session.
169
165
*/
170
166
constructor ( params : IBasemapSessionParams ) {
171
167
this . startSessionUrl = params . startSessionUrl ;
172
168
this . token = params . token ;
173
169
this . styleFamily = params . styleFamily || "arcgis" ;
174
170
this . authentication = params . authentication ;
175
- this . testSession = params . testSession || false ;
171
+ this . duration = params . duration || DEFAULT_DURATION ;
176
172
this . startTime =
177
173
typeof params . startTime === "string"
178
174
? new Date ( params . startTime )
@@ -254,26 +250,24 @@ export abstract class BaseSession implements IAuthenticationManager {
254
250
styleFamily = "arcgis" ,
255
251
authentication,
256
252
safetyMargin = DEFAULT_SAFETY_MARGIN ,
257
- testSession = false
253
+ duration = DEFAULT_DURATION
258
254
} : {
259
255
startSessionUrl ?: string ;
260
256
styleFamily ?: StyleFamily ;
261
257
authentication : IAuthenticationManager | string ;
262
258
safetyMargin ?: number ;
263
- testSession ?: boolean ;
259
+ duration ?: number ;
264
260
} ,
265
261
SessionClass : new ( params : IBasemapSessionParams ) => T
266
262
) : Promise < T > {
267
263
const sessionResponse = await startNewSession ( {
268
264
startSessionUrl,
269
265
styleFamily,
270
266
authentication,
271
- testSession
267
+ duration
272
268
} ) ;
273
269
274
- const timeToSubtract = testSession
275
- ? 1
276
- : safetyMargin || DEFAULT_SAFETY_MARGIN ;
270
+ const timeToSubtract = safetyMargin || DEFAULT_SAFETY_MARGIN ;
277
271
278
272
const session = new SessionClass ( {
279
273
startSessionUrl : startSessionUrl ,
@@ -284,7 +278,7 @@ export abstract class BaseSession implements IAuthenticationManager {
284
278
expires : new Date ( sessionResponse . endTime - timeToSubtract ) ,
285
279
startTime : new Date ( sessionResponse . startTime ) ,
286
280
endTime : new Date ( sessionResponse . endTime ) ,
287
- testSession
281
+ duration
288
282
} ) ;
289
283
290
284
return session as T ;
@@ -305,7 +299,7 @@ export abstract class BaseSession implements IAuthenticationManager {
305
299
safetyMargin : this . saftyMargin ,
306
300
startTime : this . startTime ,
307
301
endTime : this . endTime ,
308
- testSession : this . testSession
302
+ duration : this . duration
309
303
} ;
310
304
}
311
305
@@ -332,9 +326,7 @@ export abstract class BaseSession implements IAuthenticationManager {
332
326
const params : IBasemapSessionParams = JSON . parse ( serializedBasemapSession ) ;
333
327
const authentication = deserializeAuthentication ( params . authentication ) ;
334
328
335
- const timeToSubtract = params . testSession
336
- ? 1
337
- : params . safetyMargin || DEFAULT_SAFETY_MARGIN ;
329
+ const timeToSubtract = params . safetyMargin || DEFAULT_SAFETY_MARGIN ;
338
330
339
331
const session = new SessionClass ( {
340
332
startSessionUrl : params . startSessionUrl ,
@@ -345,7 +337,7 @@ export abstract class BaseSession implements IAuthenticationManager {
345
337
safetyMargin : timeToSubtract ,
346
338
startTime : new Date ( params . startTime ) ,
347
339
endTime : new Date ( params . endTime ) ,
348
- testSession : params . testSession || false
340
+ duration : params . duration || DEFAULT_DURATION
349
341
} ) ;
350
342
351
343
return session ;
@@ -402,7 +394,7 @@ export abstract class BaseSession implements IAuthenticationManager {
402
394
startSessionUrl : this . startSessionUrl ,
403
395
styleFamily : this . styleFamily ,
404
396
authentication : this . authentication ,
405
- testSession : this . testSession
397
+ duration : this . duration
406
398
} ) ;
407
399
408
400
this . setToken ( newSession . sessionToken ) ;
0 commit comments