Skip to content

Commit f5d5c60

Browse files
committed
fix(arcgis-rest-basemap-sessions): wrap up work before removing local options
1 parent 67a1de7 commit f5d5c60

File tree

4 files changed

+30
-37
lines changed

4 files changed

+30
-37
lines changed

packages/arcgis-rest-basemap-sessions/src/BaseSession.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ import { StyleFamily } from "./types/StyleFamily.js";
55
import { deserializeAuthentication } from "./utils/deserializeAuthentication.js";
66
import { startNewSession } from "./utils/startNewSession.js";
77
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";
1713

1814
export interface IBasemapSessionParams {
1915
token: string;
@@ -24,7 +20,7 @@ export interface IBasemapSessionParams {
2420
startTime: Date | string;
2521
endTime: Date | string;
2622
safetyMargin?: number;
27-
testSession?: boolean;
23+
duration?: number;
2824
}
2925

3026
export interface IStartSessionParams {
@@ -137,9 +133,9 @@ export abstract class BaseSession implements IAuthenticationManager {
137133
readonly saftyMargin: number;
138134

139135
/**
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.
141137
*/
142-
readonly testSession: boolean;
138+
readonly duration: number;
143139

144140
/**
145141
* The ID of the timer used to check the expiration time of the session.
@@ -165,14 +161,14 @@ export abstract class BaseSession implements IAuthenticationManager {
165161
* @param params.startTime - The start time of the session.
166162
* @param params.endTime - The end time of the session.
167163
* @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.
169165
*/
170166
constructor(params: IBasemapSessionParams) {
171167
this.startSessionUrl = params.startSessionUrl;
172168
this.token = params.token;
173169
this.styleFamily = params.styleFamily || "arcgis";
174170
this.authentication = params.authentication;
175-
this.testSession = params.testSession || false;
171+
this.duration = params.duration || DEFAULT_DURATION;
176172
this.startTime =
177173
typeof params.startTime === "string"
178174
? new Date(params.startTime)
@@ -254,26 +250,24 @@ export abstract class BaseSession implements IAuthenticationManager {
254250
styleFamily = "arcgis",
255251
authentication,
256252
safetyMargin = DEFAULT_SAFETY_MARGIN,
257-
testSession = false
253+
duration = DEFAULT_DURATION
258254
}: {
259255
startSessionUrl?: string;
260256
styleFamily?: StyleFamily;
261257
authentication: IAuthenticationManager | string;
262258
safetyMargin?: number;
263-
testSession?: boolean;
259+
duration?: number;
264260
},
265261
SessionClass: new (params: IBasemapSessionParams) => T
266262
): Promise<T> {
267263
const sessionResponse = await startNewSession({
268264
startSessionUrl,
269265
styleFamily,
270266
authentication,
271-
testSession
267+
duration
272268
});
273269

274-
const timeToSubtract = testSession
275-
? 1
276-
: safetyMargin || DEFAULT_SAFETY_MARGIN;
270+
const timeToSubtract = safetyMargin || DEFAULT_SAFETY_MARGIN;
277271

278272
const session = new SessionClass({
279273
startSessionUrl: startSessionUrl,
@@ -284,7 +278,7 @@ export abstract class BaseSession implements IAuthenticationManager {
284278
expires: new Date(sessionResponse.endTime - timeToSubtract),
285279
startTime: new Date(sessionResponse.startTime),
286280
endTime: new Date(sessionResponse.endTime),
287-
testSession
281+
duration
288282
});
289283

290284
return session as T;
@@ -305,7 +299,7 @@ export abstract class BaseSession implements IAuthenticationManager {
305299
safetyMargin: this.saftyMargin,
306300
startTime: this.startTime,
307301
endTime: this.endTime,
308-
testSession: this.testSession
302+
duration: this.duration
309303
};
310304
}
311305

@@ -332,9 +326,7 @@ export abstract class BaseSession implements IAuthenticationManager {
332326
const params: IBasemapSessionParams = JSON.parse(serializedBasemapSession);
333327
const authentication = deserializeAuthentication(params.authentication);
334328

335-
const timeToSubtract = params.testSession
336-
? 1
337-
: params.safetyMargin || DEFAULT_SAFETY_MARGIN;
329+
const timeToSubtract = params.safetyMargin || DEFAULT_SAFETY_MARGIN;
338330

339331
const session = new SessionClass({
340332
startSessionUrl: params.startSessionUrl,
@@ -345,7 +337,7 @@ export abstract class BaseSession implements IAuthenticationManager {
345337
safetyMargin: timeToSubtract,
346338
startTime: new Date(params.startTime),
347339
endTime: new Date(params.endTime),
348-
testSession: params.testSession || false
340+
duration: params.duration || DEFAULT_DURATION
349341
});
350342

351343
return session;
@@ -402,7 +394,7 @@ export abstract class BaseSession implements IAuthenticationManager {
402394
startSessionUrl: this.startSessionUrl,
403395
styleFamily: this.styleFamily,
404396
authentication: this.authentication,
405-
testSession: this.testSession
397+
duration: this.duration
406398
});
407399

408400
this.setToken(newSession.sessionToken);

packages/arcgis-rest-basemap-sessions/src/BasemapStyleSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
BaseSession,
33
IBasemapSessionParams,
4-
IStartSessionParams,
5-
DEFAULT_START_BASEMAP_SESSION_URL
4+
IStartSessionParams
65
} from "./BaseSession.js";
6+
import { DEFAULT_START_BASEMAP_SESSION_URL } from "./utils/defaults.js";
77

88
/**
99
* `BasemapStyleSession` is a class that extends {@linkcode BaseSession} to manage sessions

packages/arcgis-rest-basemap-sessions/src/StaticBasemapTilesSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
BaseSession,
33
IBasemapSessionParams,
4-
IStartSessionParams,
5-
DEFAULT_START_STATIC_BASEMAP_SESSION_URL
4+
IStartSessionParams
65
} from "./BaseSession.js";
6+
import { DEFAULT_START_STATIC_BASEMAP_SESSION_URL } from "./utils/defaults.js";
77

88
/**
99
* `StaticBasemapTilesSession` is a class that extends {@linkcode BaseSession} to manage sessions
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { IAuthenticationManager, request } from "@esri/arcgis-rest-request";
22
import { StyleFamily } from "../types/StyleFamily.js";
3+
import { DEFAULT_DURATION } from "./defaults.js";
34

45
export interface IRequestNewSessionParams {
5-
startSessionUrl?: string;
6+
startSessionUrl: string;
67
authentication: IAuthenticationManager | string;
78
styleFamily?: StyleFamily;
8-
testSession?: boolean;
9+
duration?: number;
910
}
1011

1112
export interface IStartSessionResponse {
@@ -16,14 +17,14 @@ export interface IStartSessionResponse {
1617
}
1718

1819
export function startNewSession({
19-
startSessionUrl = "https://basemapstylesdev-api.arcgis.com/arcgis/rest/services/styles/v2/sessions/start",
20-
styleFamily = "arcgis",
20+
startSessionUrl,
2121
authentication,
22-
testSession = false
22+
styleFamily = "arcgis",
23+
duration = DEFAULT_DURATION
2324
}: IRequestNewSessionParams): Promise<IStartSessionResponse> {
2425
return request(startSessionUrl, {
2526
httpMethod: "GET",
2627
authentication: authentication,
27-
params: { styleFamily, testSession }
28+
params: { styleFamily, durationSeconds: duration }
2829
});
2930
}

0 commit comments

Comments
 (0)