@esri/arcgis-rest-basemap-sessions 1.0.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/basemap-sessions.esm.js +88 -42
- package/dist/bundled/basemap-sessions.esm.js.map +1 -1
- package/dist/bundled/basemap-sessions.esm.min.js +7 -7
- package/dist/bundled/basemap-sessions.esm.min.js.map +1 -1
- package/dist/bundled/basemap-sessions.umd.js +406 -362
- package/dist/bundled/basemap-sessions.umd.js.map +1 -1
- package/dist/bundled/basemap-sessions.umd.min.js +7 -7
- package/dist/bundled/basemap-sessions.umd.min.js.map +1 -1
- package/dist/cjs/BaseSession.js +85 -39
- package/dist/cjs/BaseSession.js.map +1 -1
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/detemineSafetyMargin.js +1 -2
- package/dist/cjs/utils/detemineSafetyMargin.js.map +1 -1
- package/dist/cjs/utils/startNewSession.js +1 -2
- package/dist/cjs/utils/startNewSession.js.map +1 -1
- package/dist/cjs/utils/writable.js.map +1 -1
- package/dist/esm/BaseSession.d.ts +45 -30
- package/dist/esm/BaseSession.js +85 -39
- package/dist/esm/BaseSession.js.map +1 -1
- package/dist/esm/types/StyleFamily.d.ts +1 -1
- package/dist/esm/utils/detemineSafetyMargin.js.map +1 -1
- package/dist/esm/utils/writable.d.ts +2 -2
- package/dist/esm/utils/writable.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/StaticBasemapTilesSession.js +0 -30
- package/dist/cjs/StaticBasemapTilesSession.js.map +0 -1
- package/dist/esm/StaticBasemapTilesSession.d.ts +0 -20
- package/dist/esm/StaticBasemapTilesSession.js +0 -26
- package/dist/esm/StaticBasemapTilesSession.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/arcgis-rest-basemap-sessions -
|
|
3
|
-
* Copyright (c) 2017-
|
|
4
|
-
*
|
|
2
|
+
* @esri/arcgis-rest-basemap-sessions - v4.8.0 - Apache-2.0
|
|
3
|
+
* Copyright (c) 2017-2026 Esri, Inc.
|
|
4
|
+
* Fri Jan 16 2026 01:29:33 GMT+0000 (Coordinated Universal Time)
|
|
5
5
|
*/
|
|
6
6
|
import { request } from '@esri/arcgis-rest-request';
|
|
7
7
|
|
|
@@ -31,11 +31,10 @@ function determineSafetyMargin(duration, safetyMargin) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* The base class for all basemap sessions. This class implements the {@linkcode IAuthenticationManager} interface and provides methods to start, refresh, and check the expiration of a session.
|
|
35
|
-
* This is not
|
|
34
|
+
* The base class for all basemap sessions. This class implements the {@linkcode @esri/arcgis-rest-request!IAuthenticationManager} interface and provides methods to start, refresh, and check the expiration of a session.
|
|
35
|
+
* This is not intended to be used directly, but instead is extended by other classes such as {@linkcode BasemapStyleSession} .
|
|
36
36
|
*
|
|
37
37
|
* @abstract
|
|
38
|
-
* @implements {IAuthenticationManager}
|
|
39
38
|
*/
|
|
40
39
|
class BaseSession {
|
|
41
40
|
/**
|
|
@@ -59,6 +58,10 @@ class BaseSession {
|
|
|
59
58
|
* The ID of the timer used to check the expiration time of the session.
|
|
60
59
|
*/
|
|
61
60
|
this.expirationTimerId = null;
|
|
61
|
+
/**
|
|
62
|
+
* A pending session that is being refreshed. This is used to prevent multiple refreshes from happening at the same time.
|
|
63
|
+
*/
|
|
64
|
+
this.pendingSession = null;
|
|
62
65
|
/**
|
|
63
66
|
* A handler that is used to automatically refresh the session when it expires.
|
|
64
67
|
*/
|
|
@@ -77,12 +80,13 @@ class BaseSession {
|
|
|
77
80
|
this.emitter = mitt();
|
|
78
81
|
}
|
|
79
82
|
/**
|
|
80
|
-
* Checks if the session is expired. If it is expired, it emits an "expired" event. The event will fire **before** the method returns true.
|
|
83
|
+
* Checks if the session is expired. If it is expired, it emits an "expired" event and disables expiration time checking. The event will fire **before** the method returns true.
|
|
81
84
|
*
|
|
82
85
|
* @returns {boolean} - Returns true if the session is expired, otherwise false.
|
|
83
86
|
*/
|
|
84
87
|
isSessionExpired() {
|
|
85
88
|
if (this.isExpired) {
|
|
89
|
+
this.disableCheckingExpirationTime();
|
|
86
90
|
this.emitter.emit("expired", {
|
|
87
91
|
token: this.token,
|
|
88
92
|
startTime: this.startTime,
|
|
@@ -96,14 +100,14 @@ class BaseSession {
|
|
|
96
100
|
* Starts checking the expiration time of the session. This will check the expiration time immediately and then on an interval.
|
|
97
101
|
* If the session is expired, it will emit an "expired" event.
|
|
98
102
|
*/
|
|
99
|
-
|
|
103
|
+
enableCheckingExpirationTime() {
|
|
100
104
|
const check = () => {
|
|
101
105
|
this.isSessionExpired();
|
|
102
106
|
};
|
|
103
107
|
if (!this.expirationTimerId) {
|
|
104
108
|
this.expirationTimerId = setInterval(check,
|
|
105
109
|
// check every 10 seconds or 1/100th of the duration, whichever is smaller
|
|
106
|
-
this.expirationCheckInterval); // check
|
|
110
|
+
this.expirationCheckInterval); // check immediately then on an interval
|
|
107
111
|
}
|
|
108
112
|
setTimeout(() => {
|
|
109
113
|
check(); // check immediately after starting the interval
|
|
@@ -111,22 +115,14 @@ class BaseSession {
|
|
|
111
115
|
return this.expirationTimerId; // return the timer ID so it can be stopped later
|
|
112
116
|
}
|
|
113
117
|
/**
|
|
114
|
-
* Stops checking the expiration time of the session. This will clear the
|
|
118
|
+
* Stops checking the expiration time of the session. This will clear the `setInterval()` that was started by {@linkcode BaseSession.enableCheckingExpirationTime}.
|
|
115
119
|
*/
|
|
116
|
-
|
|
120
|
+
disableCheckingExpirationTime() {
|
|
117
121
|
if (this.expirationTimerId) {
|
|
118
122
|
clearInterval(this.expirationTimerId);
|
|
119
123
|
this.expirationTimerId = null;
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Indicates if the session is currently checking for expiration time.
|
|
124
|
-
*
|
|
125
|
-
* @returns {boolean} - Returns true if the session is checking for expiration time, otherwise false.
|
|
126
|
-
*/
|
|
127
|
-
get checkingExpirationTime() {
|
|
128
|
-
return !!this.expirationTimerId;
|
|
129
|
-
}
|
|
130
126
|
/**
|
|
131
127
|
* Starts a new session using the provided parameters and returns an instance of the session class.
|
|
132
128
|
*
|
|
@@ -134,7 +130,13 @@ class BaseSession {
|
|
|
134
130
|
* @param SessionClass - The class to use for the session.
|
|
135
131
|
* @returns A promise that resolves to an instance of the session class.
|
|
136
132
|
*/
|
|
137
|
-
static async startSession({ startSessionUrl, styleFamily = "arcgis", authentication, safetyMargin, duration = DEFAULT_DURATION, autoRefresh =
|
|
133
|
+
static async startSession({ startSessionUrl, styleFamily = "arcgis", authentication, safetyMargin, duration = DEFAULT_DURATION, autoRefresh = false }, SessionClass) {
|
|
134
|
+
if (duration < 10) {
|
|
135
|
+
throw new Error("Session duration must be at least 10 seconds.");
|
|
136
|
+
}
|
|
137
|
+
if (duration > 43200) {
|
|
138
|
+
throw new Error("Session duration cannot exceed 12 hours (43200 seconds).");
|
|
139
|
+
}
|
|
138
140
|
const sessionResponse = await startNewSession({
|
|
139
141
|
startSessionUrl,
|
|
140
142
|
styleFamily,
|
|
@@ -153,12 +155,37 @@ class BaseSession {
|
|
|
153
155
|
endTime: new Date(sessionResponse.endTime),
|
|
154
156
|
duration
|
|
155
157
|
});
|
|
156
|
-
session.
|
|
158
|
+
session.enableCheckingExpirationTime();
|
|
157
159
|
if (autoRefresh) {
|
|
158
|
-
session.
|
|
160
|
+
session.enableAutoRefresh();
|
|
159
161
|
}
|
|
160
162
|
return session;
|
|
161
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Indicates if the session is currently checking for expiration time.
|
|
166
|
+
*
|
|
167
|
+
* @returns {boolean} - Returns true if the session is checking for expiration time, otherwise false.
|
|
168
|
+
*/
|
|
169
|
+
get checkingExpirationTime() {
|
|
170
|
+
return !!this.expirationTimerId;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns the number of seconds until the session is no longer valid rounded down. If the session is expired, it will return 0.
|
|
174
|
+
*/
|
|
175
|
+
get secondsUntilExpiration() {
|
|
176
|
+
return Math.floor(this.millisecondsUntilExpiration / 1000);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns the number of milliseconds until the session token is no longer valid. If the session is expired, it will return 0.
|
|
180
|
+
*/
|
|
181
|
+
get millisecondsUntilExpiration() {
|
|
182
|
+
if (this.isExpired) {
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
const now = new Date();
|
|
186
|
+
const millisecondsLeft = this.endTime.getTime() - now.getTime();
|
|
187
|
+
return millisecondsLeft;
|
|
188
|
+
}
|
|
162
189
|
/**
|
|
163
190
|
* Checks if the session is expired.
|
|
164
191
|
*
|
|
@@ -178,7 +205,7 @@ class BaseSession {
|
|
|
178
205
|
return Promise.resolve(this.token);
|
|
179
206
|
}
|
|
180
207
|
/**
|
|
181
|
-
* Indicates if the session can be refreshed. This is always true for this
|
|
208
|
+
* Indicates if the session can be refreshed. This is always true for this basemap sessions.
|
|
182
209
|
*
|
|
183
210
|
* @returns {boolean} - Always returns true.
|
|
184
211
|
*/
|
|
@@ -200,6 +227,11 @@ class BaseSession {
|
|
|
200
227
|
* @returns A promise that resolves to the current instance of the session.
|
|
201
228
|
*/
|
|
202
229
|
async refreshCredentials() {
|
|
230
|
+
if (this.pendingSession) {
|
|
231
|
+
// if there is a pending session, wait for it to resolve
|
|
232
|
+
await this.pendingSession;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
203
235
|
// @TODO switch this to structured clone when we upgrade to Node 20+ types so we don't have to parse the dates later
|
|
204
236
|
const previous = JSON.parse(JSON.stringify({
|
|
205
237
|
token: this.token,
|
|
@@ -208,16 +240,19 @@ class BaseSession {
|
|
|
208
240
|
expires: this.expires
|
|
209
241
|
}));
|
|
210
242
|
try {
|
|
211
|
-
|
|
243
|
+
this.pendingSession = startNewSession({
|
|
212
244
|
startSessionUrl: this.startSessionUrl,
|
|
213
245
|
styleFamily: this.styleFamily,
|
|
214
246
|
authentication: this.authentication,
|
|
215
247
|
duration: this.duration
|
|
216
248
|
});
|
|
249
|
+
const newSession = await this.pendingSession;
|
|
250
|
+
this.pendingSession = null; // reset the pending session
|
|
217
251
|
this.setToken(newSession.sessionToken);
|
|
218
252
|
this.setStartTime(new Date(newSession.startTime));
|
|
219
253
|
this.setEndTime(new Date(newSession.endTime));
|
|
220
254
|
this.setExpires(new Date(newSession.endTime - this.safetyMargin * 1000));
|
|
255
|
+
this.enableCheckingExpirationTime(); // restart checking expiration time after refreshing credentials
|
|
221
256
|
this.emitter.emit("refreshed", {
|
|
222
257
|
previous: {
|
|
223
258
|
token: previous.token,
|
|
@@ -241,11 +276,11 @@ class BaseSession {
|
|
|
241
276
|
}
|
|
242
277
|
/**
|
|
243
278
|
* Enables auto-refresh for the session. This will automatically refresh the session when it expires.
|
|
244
|
-
* It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.
|
|
279
|
+
* It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.enableCheckingExpirationTime}.
|
|
245
280
|
*/
|
|
246
|
-
|
|
281
|
+
enableAutoRefresh() {
|
|
247
282
|
if (!this.expirationTimerId) {
|
|
248
|
-
this.
|
|
283
|
+
this.enableCheckingExpirationTime();
|
|
249
284
|
}
|
|
250
285
|
this.autoRefreshHandler = () => {
|
|
251
286
|
this.refreshCredentials().catch((error) => {
|
|
@@ -257,27 +292,38 @@ class BaseSession {
|
|
|
257
292
|
/**
|
|
258
293
|
* Disables auto-refresh for the session. This will stop automatically refreshing the session when it expires.
|
|
259
294
|
* This will **not** stop checking the expiration time of the session. If you want to stop automated expiration
|
|
260
|
-
* checking, call {@linkcode BaseSession.
|
|
295
|
+
* checking, call {@linkcode BaseSession.disableCheckingExpirationTime} after calling this method.
|
|
261
296
|
*/
|
|
262
|
-
|
|
297
|
+
disableAutoRefresh() {
|
|
263
298
|
if (this.autoRefreshHandler) {
|
|
264
299
|
this.off("expired", this.autoRefreshHandler);
|
|
265
300
|
this.autoRefreshHandler = null;
|
|
266
301
|
}
|
|
267
302
|
}
|
|
268
|
-
|
|
269
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Removes all event listeners and disables auto-refresh and expiration time checking. This is useful for cleaning up the session when it is no longer needed or replaced with a new session.
|
|
305
|
+
*/
|
|
306
|
+
destroy() {
|
|
307
|
+
this.disableAutoRefresh();
|
|
308
|
+
this.disableCheckingExpirationTime();
|
|
309
|
+
this.emitter.off("expired");
|
|
310
|
+
this.emitter.off("refreshed");
|
|
311
|
+
this.emitter.off("error");
|
|
312
|
+
this.emitter.off("*");
|
|
313
|
+
}
|
|
314
|
+
on(event, handler) {
|
|
315
|
+
this.emitter.on(event, handler);
|
|
270
316
|
this.isSessionExpired(); // check if the session is expired immediately after adding the handler
|
|
271
317
|
}
|
|
272
|
-
once(
|
|
318
|
+
once(event, handler) {
|
|
273
319
|
const fn = (e) => {
|
|
274
|
-
this.emitter.off(
|
|
320
|
+
this.emitter.off(event, fn);
|
|
275
321
|
handler(e);
|
|
276
322
|
};
|
|
277
|
-
this.emitter.on(
|
|
323
|
+
this.emitter.on(event, fn);
|
|
278
324
|
}
|
|
279
|
-
off(
|
|
280
|
-
this.emitter.off(
|
|
325
|
+
off(event, handler) {
|
|
326
|
+
this.emitter.off(event, handler);
|
|
281
327
|
}
|
|
282
328
|
/**
|
|
283
329
|
* These private methods are used to set the internal state of the session.
|
|
@@ -300,27 +346,27 @@ class BaseSession {
|
|
|
300
346
|
/**
|
|
301
347
|
* Event handler for when an error occurs during session management.
|
|
302
348
|
*/
|
|
303
|
-
BaseSession.error = function error(e) { };
|
|
349
|
+
BaseSession.error = function error(e) { };
|
|
304
350
|
// the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.
|
|
305
351
|
/* istanbul ignore next -- @preserve */
|
|
306
352
|
/**
|
|
307
|
-
* Event handler for when
|
|
353
|
+
* Event handler for when the current session expires and the session token it no longer valid. This event will only fire if {@linkcode BaseSession.checkingExpirationTime}
|
|
354
|
+
* is `true` which is the default. Once this event fires, {@linkcode BaseSession.checkingExpirationTime} will be set to `false` until the session is refreshed with
|
|
355
|
+
* {@linkcode BaseSession.refreshCredentials}.
|
|
308
356
|
*
|
|
309
357
|
* @event expired
|
|
310
|
-
* @param e - The parameters for the expired event.
|
|
311
358
|
* @param e.token - The session token that expired.
|
|
312
359
|
* @param e.startTime - The start time of the session.
|
|
313
360
|
* @param e.endTime - The end time of the session.
|
|
314
361
|
* @param e.expires - The expiration time of the session.
|
|
315
362
|
*/
|
|
316
|
-
BaseSession.expired = function expired(e) { };
|
|
363
|
+
BaseSession.expired = function expired(e) { };
|
|
317
364
|
// the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.
|
|
318
365
|
/* istanbul ignore next -- @preserve */
|
|
319
366
|
/**
|
|
320
367
|
* Event handler for when a session refreshes and a new `token` is available.
|
|
321
368
|
*
|
|
322
369
|
* @event refreshed
|
|
323
|
-
* @param e. - The parameters for the refreshed event.
|
|
324
370
|
* @param e.previous - The previous session details.
|
|
325
371
|
* @param e.previous.token - The previous session token.
|
|
326
372
|
* @param e.previous.startTime - The start time of the previous session.
|
|
@@ -332,7 +378,7 @@ BaseSession.expired = function expired(e) { }; // eslint-disable-line @typescrip
|
|
|
332
378
|
* @param e.current.endTime - The end time of the current session.
|
|
333
379
|
* @param e.current.expires - The expiration time of the current token.
|
|
334
380
|
*/
|
|
335
|
-
BaseSession.refreshed = function refreshed(e) { };
|
|
381
|
+
BaseSession.refreshed = function refreshed(e) { };
|
|
336
382
|
|
|
337
383
|
/**
|
|
338
384
|
* `BasemapStyleSession` is a class that extends {@linkcode BaseSession} to manage sessions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basemap-sessions.esm.js","sources":["../../node_modules/mitt/dist/mitt.mjs","../../src/utils/defaults.ts","../../src/utils/startNewSession.ts","../../src/utils/detemineSafetyMargin.ts","../../src/BaseSession.ts","../../src/BasemapStyleSession.ts"],"sourcesContent":["export default function(n){return{all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]))},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e)}),(i=n.get(\"*\"))&&i.slice().map(function(n){n(t,e)})}}}\n//# sourceMappingURL=mitt.mjs.map\n","export const DEFAULT_START_BASEMAP_STYLE_SESSION_URL =\n \"https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/sessions/start\";\n\nexport const DEFAULT_SAFETY_MARGIN = 5 * 60; // Default to 5 minutes in seconds\n\nexport const DEFAULT_CHECK_EXPIRATION_INTERVAL = 10; // Default to 10 seconds\n\nexport const DEFAULT_DURATION = 12 * 60 * 60; // Default to 12 hours in seconds\n","import { IAuthenticationManager, request } from \"@esri/arcgis-rest-request\";\nimport { StyleFamily } from \"../types/StyleFamily.js\";\nimport { DEFAULT_DURATION } from \"./defaults.js\";\n\nexport interface IRequestNewSessionParams {\n startSessionUrl: string;\n authentication: IAuthenticationManager | string;\n styleFamily?: StyleFamily;\n duration?: number;\n}\n\nexport interface IStartSessionResponse {\n sessionToken: string;\n endTime: number;\n startTime: number;\n styleFamily: StyleFamily;\n}\n\nexport function startNewSession({\n startSessionUrl,\n authentication,\n styleFamily = \"arcgis\",\n duration = DEFAULT_DURATION\n}: IRequestNewSessionParams): Promise<IStartSessionResponse> {\n return request(startSessionUrl, {\n httpMethod: \"GET\",\n authentication: authentication,\n params: { styleFamily, durationSeconds: duration }\n });\n}\n","import { DEFAULT_SAFETY_MARGIN } from \"./defaults.js\";\n\nexport function determineSafetyMargin(\n duration: number | undefined,\n safetyMargin: number | undefined\n): number {\n if (safetyMargin) {\n return safetyMargin;\n }\n // common cases are\n // duration is 60 seconds, this will return a 1 second safety margin\n // duration is 43200 seconds, this will return a 300 second (5 minutes) safety margin\n return Math.min(Math.max(duration / 100, 1), DEFAULT_SAFETY_MARGIN);\n}\n","import mitt from \"mitt\";\n\nimport { IAuthenticationManager } from \"@esri/arcgis-rest-request\";\nimport { StyleFamily } from \"./types/StyleFamily.js\";\nimport { startNewSession } from \"./utils/startNewSession.js\";\nimport { Writable } from \"./utils/writable.js\";\nimport { determineSafetyMargin } from \"./utils/detemineSafetyMargin.js\";\nimport {\n DEFAULT_DURATION,\n DEFAULT_SAFETY_MARGIN,\n DEFAULT_CHECK_EXPIRATION_INTERVAL\n} from \"./utils/defaults.js\";\n\nexport interface IBasemapSessionParams {\n token: string;\n startSessionUrl: string;\n styleFamily: StyleFamily;\n authentication: IAuthenticationManager | string;\n expires: Date;\n startTime: Date;\n endTime: Date;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n}\n\nexport interface IStartSessionParams {\n styleFamily?: StyleFamily;\n authentication: IAuthenticationManager | string;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n\n /**\n * The URL to start the session. If not provided, it will use the default URL.\n * @private\n */\n startSessionUrl?: string;\n}\n\n/**\n * The base class for all basemap sessions. This class implements the {@linkcode IAuthenticationManager} interface and provides methods to start, refresh, and check the expiration of a session.\n * This is not intendet to be used directly, but instead is extended by other classes such as {@linkcode BasemapStyleSession} and {@linkcode StaticBasemapTilesSession}.\n *\n * @abstract\n * @implements {IAuthenticationManager}\n */\nexport abstract class BaseSession implements IAuthenticationManager {\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when an error occurs during session management.\n */\n static readonly error = function error(e: Error): void {}; // eslint-disable-line @typescript-eslint/no-empty-function\n\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when a session expires and the `token` it no longer valid.\n *\n * @event expired\n * @param e - The parameters for the expired event.\n * @param e.token - The session token that expired.\n * @param e.startTime - The start time of the session.\n * @param e.endTime - The end time of the session.\n * @param e.expires - The expiration time of the session.\n */\n static readonly expired = function expired(e: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n }): void {}; // eslint-disable-line @typescript-eslint/no-empty-function\n\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when a session refreshes and a new `token` is available.\n *\n * @event refreshed\n * @param e. - The parameters for the refreshed event.\n * @param e.previous - The previous session details.\n * @param e.previous.token - The previous session token.\n * @param e.previous.startTime - The start time of the previous session.\n * @param e.previous.endTime - The end time of the previous session.\n * @param e.previous.expires - The expiration time of the previous session.\n * @param e.current - The current session details.\n * @param e.current.token - The current session token.\n * @param e.current.startTime - The start time of the current token.\n * @param e.current.endTime - The end time of the current session.\n * @param e.current.expires - The expiration time of the current token.\n */\n static readonly refreshed = function refreshed(e: {\n previous: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n };\n current: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n };\n }): void {}; // eslint-disable-line @typescript-eslint/no-empty-function\n\n /**\n * The portal URL that the session is associated with. This generally is not used but exists to implement the `IAuthenticationManager` interface.\n */\n readonly portal: string;\n\n /**\n * The style family of the session. This is used to determine the type of basemap styles that are available.\n */\n readonly styleFamily: StyleFamily;\n\n /**\n * The authentication manager or token used for the session.\n * This can be an instance of {@linkcode ApiKeyManager}, {@linkcode ArcGISIdentityManager}, {@linkcode ApplicationCredentialsManager} or a string token.\n */\n readonly authentication: IAuthenticationManager | string;\n\n /**\n * The expiration date of the session. This is the {@linkcode BaseSession.endTime} minus the {@linkcode BaseSession.safetyMargin}. This is used internally to determine if the session is expired.\n */\n readonly expires: Date;\n\n /**\n * The start time of the session. This is the time returned from the API when the session war started.\n */\n readonly startTime: Date;\n\n /**\n * The end time of the session. This is the time returned from the API when the session will end.\n */\n readonly endTime: Date;\n\n /**\n * The token for the session.\n */\n readonly token: string;\n\n /**\n * The URL used to start the session.\n */\n readonly startSessionUrl: string;\n\n /**\n * The safety margin in milliseconds. This subtracted from the {@linkcode BaseSession.endTime} to get the {@linkcode BaseSession.expiration}.\n */\n readonly safetyMargin: number;\n\n /**\n * The duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed.\n */\n readonly duration: number;\n\n /**\n * The interval at which to check the expiration time of the session. This is always 10 seconds or 1/100th of the duration, whichever is smaller.\n */\n readonly expirationCheckInterval: number;\n\n /**\n * The ID of the timer used to check the expiration time of the session.\n */\n private expirationTimerId: any = null;\n\n /**\n * Internal instance of [`mitt`](https://github.com/developit/mitt) used for event handlers. It is recommended to use {@linkcode BasemapSession.on}, {@linkcode BasemapSession.off} or {@linkcode BasemapSession.once} instead of `emitter.`\n */\n private emitter: any;\n\n /**\n * A handler that is used to automatically refresh the session when it expires.\n */\n private autoRefreshHandler: (() => void) | null = null;\n\n /**\n * Creates a new instance of the BaseSession class. Generally you should not create an instance of this class directly, but instead use the static methods to start a session or deserialize a session.\n *\n * You may need to create an instance of this class directly if you are not using the built in deserialize method.\n *\n * @param params - The parameters for the session.\n * @param params.startSessionUrl - The URL to start the session.\n * @param params.token - The token for the session.\n * @param params.styleFamily - The style family of the session.\n * @param params.authentication - The authentication manager or token used for the session.\n * @param params.expires - The expiration date of the session.\n * @param params.startTime - The start time of the session.\n * @param params.endTime - The end time of the session.\n * @param params.safetyMargin - The safety margin in milliseconds.\n * @param params.duration - Indicates if this is a test session.\n */\n constructor(params: IBasemapSessionParams) {\n this.startSessionUrl = params.startSessionUrl;\n this.token = params.token;\n this.styleFamily = params.styleFamily || \"arcgis\";\n this.authentication = params.authentication;\n this.duration = params.duration || DEFAULT_DURATION;\n this.startTime = params.startTime;\n this.endTime = params.endTime;\n this.expires = params.expires;\n this.safetyMargin = params.safetyMargin;\n this.expirationCheckInterval =\n Math.min(this.duration / 100, DEFAULT_CHECK_EXPIRATION_INTERVAL) * 1000;\n this.emitter = mitt();\n }\n\n /**\n * Checks if the session is expired. If it is expired, it emits an \"expired\" event. The event will fire **before** the method returns true.\n *\n * @returns {boolean} - Returns true if the session is expired, otherwise false.\n */\n isSessionExpired() {\n if (this.isExpired) {\n this.emitter.emit(\"expired\", {\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n });\n }\n return this.isExpired;\n }\n\n /**\n * Starts checking the expiration time of the session. This will check the expiration time immediately and then on an interval.\n * If the session is expired, it will emit an \"expired\" event.\n */\n startCheckingExpirationTime() {\n const check = () => {\n this.isSessionExpired();\n };\n\n if (!this.expirationTimerId) {\n this.expirationTimerId = setInterval(\n check,\n // check every 10 seconds or 1/100th of the duration, whichever is smaller\n this.expirationCheckInterval\n ); // check immediatly then on an interval\n }\n\n setTimeout(() => {\n check(); // check immediately after starting the interval\n }, 10);\n\n return this.expirationTimerId; // return the timer ID so it can be stopped later\n }\n\n /**\n * Stops checking the expiration time of the session. This will clear the interval that was set by {@linkcode BaseSession.startCheckingExpirationTime}.\n */\n stopCheckingExpirationTime() {\n if (this.expirationTimerId) {\n clearInterval(this.expirationTimerId);\n this.expirationTimerId = null;\n }\n }\n\n /**\n * Indicates if the session is currently checking for expiration time.\n *\n * @returns {boolean} - Returns true if the session is checking for expiration time, otherwise false.\n */\n get checkingExpirationTime(): boolean {\n return !!this.expirationTimerId;\n }\n\n /**\n * Starts a new session using the provided parameters and returns an instance of the session class.\n *\n * @param params - The parameters for starting the session.\n * @param SessionClass - The class to use for the session.\n * @returns A promise that resolves to an instance of the session class.\n */\n protected static async startSession<T extends BaseSession>(\n {\n startSessionUrl,\n styleFamily = \"arcgis\",\n authentication,\n safetyMargin,\n duration = DEFAULT_DURATION,\n autoRefresh = true\n }: {\n startSessionUrl?: string;\n styleFamily?: StyleFamily;\n authentication: IAuthenticationManager | string;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n },\n SessionClass: new (params: IBasemapSessionParams) => T\n ): Promise<T> {\n const sessionResponse = await startNewSession({\n startSessionUrl,\n styleFamily,\n authentication,\n duration\n });\n const actualSafetyMargin = determineSafetyMargin(duration, safetyMargin);\n\n const session = new SessionClass({\n startSessionUrl: startSessionUrl,\n token: sessionResponse.sessionToken,\n styleFamily,\n authentication,\n safetyMargin: actualSafetyMargin,\n expires: new Date(sessionResponse.endTime - actualSafetyMargin * 1000),\n startTime: new Date(sessionResponse.startTime),\n endTime: new Date(sessionResponse.endTime),\n duration\n });\n\n session.startCheckingExpirationTime();\n\n if (autoRefresh) {\n session.startAutoRefresh();\n }\n\n return session as T;\n }\n\n /**\n * Checks if the session is expired.\n *\n */\n get isExpired(): boolean {\n return this.expires < new Date();\n }\n\n /**\n * Gets the session token. If the session is expired, it will refresh the credentials and return the new token.\n *\n * @returns A promise that resolves to the session token.\n */\n getToken(): Promise<string> {\n if (this.isExpired) {\n return this.refreshCredentials().then(() => this.token);\n }\n\n return Promise.resolve(this.token);\n }\n\n /**\n * Indicates if the session can be refreshed. This is always true for this class.\n *\n * @returns {boolean} - Always returns true.\n */\n get canRefresh(): boolean {\n return true;\n }\n\n /**\n * Indicates if the session is set to automatically refresh when it expires.\n *\n * @returns {boolean} - Returns true if auto-refresh is enabled, otherwise false.\n */\n get autoRefresh(): boolean {\n return !!this.autoRefreshHandler && !!this.expirationTimerId;\n }\n\n /**\n * Refreshes the session credentials by starting a new session.\n * This will emit a \"refreshed\" event with the previous and current session details.\n *\n * @returns A promise that resolves to the current instance of the session.\n */\n async refreshCredentials(): Promise<this> {\n // @TODO switch this to structured clone when we upgrade to Node 20+ types so we don't have to parse the dates later\n const previous = JSON.parse(\n JSON.stringify({\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n })\n );\n\n try {\n const newSession = await startNewSession({\n startSessionUrl: this.startSessionUrl,\n styleFamily: this.styleFamily,\n authentication: this.authentication,\n duration: this.duration\n });\n\n this.setToken(newSession.sessionToken);\n this.setStartTime(new Date(newSession.startTime));\n this.setEndTime(new Date(newSession.endTime));\n this.setExpires(new Date(newSession.endTime - this.safetyMargin * 1000));\n\n this.emitter.emit(\"refreshed\", {\n previous: {\n token: previous.token,\n startTime: new Date(previous.startTime),\n endTime: new Date(previous.endTime),\n expires: new Date(previous.expires)\n },\n current: {\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n }\n });\n } catch (error) {\n this.emitter.emit(\"error\", error);\n throw error;\n }\n\n return this;\n }\n /**\n * Enables auto-refresh for the session. This will automatically refresh the session when it expires.\n * It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.startCheckingExpirationTime}.\n */\n startAutoRefresh() {\n if (!this.expirationTimerId) {\n this.startCheckingExpirationTime();\n }\n\n this.autoRefreshHandler = () => {\n this.refreshCredentials().catch((error: Error) => {\n this.emitter.emit(\"error\", error);\n });\n };\n\n this.on(\"expired\", this.autoRefreshHandler);\n }\n\n /**\n * Disables auto-refresh for the session. This will stop automatically refreshing the session when it expires.\n * This will **not** stop checking the expiration time of the session. If you want to stop automated expiration\n * checking, call {@linkcode BaseSession.stopCheckingExpirationTime} after calling this method.\n */\n stopAutoRefresh() {\n if (this.autoRefreshHandler) {\n this.off(\"expired\", this.autoRefreshHandler);\n this.autoRefreshHandler = null;\n }\n }\n\n /**\n * A handler that listens for an eventName and returns custom handler.\n *\n * @param eventName A string of what event to listen for.\n * @param handler A function of what to do when eventName was called.\n */\n on(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n on(event: \"expired\", handler: typeof BaseSession.expired): void;\n on(event: \"error\", handler: typeof BaseSession.error): void;\n on(\n eventName: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n this.emitter.on(eventName, handler);\n this.isSessionExpired(); // check if the session is expired immediately after adding the handler\n }\n\n /**\n * A handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with {@linkcode BasemapSession.off}.\n *\n * @param eventName A string of what event to listen for.\n * @param handler A function of what to do when eventName was called.\n */\n once(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n once(event: \"expired\", handler: typeof BaseSession.expired): void;\n once(event: \"error\", handler: typeof BaseSession.error): void;\n once(\n eventName: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n const fn = (e: any) => {\n this.emitter.off(eventName, fn);\n handler(e);\n };\n\n this.emitter.on(eventName, fn);\n }\n\n /**\n * A handler that will remove a listener from a given event.\n *\n * @param eventName A string of what event to listen for.\n * @param handler A function of what to do when eventName was called.\n */\n off(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n off(event: \"expired\", handler: typeof BaseSession.expired): void;\n off(event: \"error\", handler: typeof BaseSession.error): void;\n off(\n eventName: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n this.emitter.off(eventName, handler);\n }\n\n /**\n * These private methods are used to set the internal state of the session.\n */\n private setToken(token: string) {\n (this as Writable<typeof this>).token = token;\n }\n private setStartTime(startTime: Date) {\n (this as Writable<typeof this>).startTime = startTime;\n }\n private setEndTime(endTime: Date) {\n (this as Writable<typeof this>).endTime = endTime;\n }\n private setExpires(expires: Date) {\n (this as Writable<typeof this>).expires = expires;\n }\n}\n","import {\n BaseSession,\n IBasemapSessionParams,\n IStartSessionParams\n} from \"./BaseSession.js\";\nimport { DEFAULT_START_BASEMAP_STYLE_SESSION_URL } from \"./utils/defaults.js\";\n\n/**\n * `BasemapStyleSession` is a class that extends {@linkcode BaseSession} to manage sessions\n * for basemap styles. It provides methods to {@linkcode BasemapStyleSession.start} a new session\n * which should be used instead of constructing a new instance directly.\n *\n * @class BasemapStyleSession\n * @extends BaseSession\n */\nexport class BasemapStyleSession extends BaseSession {\n /**\n * Creates an instance of `BasemapStyleSession`. Constructing `BasemapStyleSession` directly is discouraged.\n * Instead, use the static method {@linkcode BasemapStyleSession.start} to start a new session.\n */\n constructor(params: IBasemapSessionParams) {\n super(params);\n }\n\n /**\n * Starts a new basemap style session.\n */\n static async start(params: IStartSessionParams) {\n return BaseSession.startSession<BasemapStyleSession>(\n {\n ...params,\n startSessionUrl:\n params?.startSession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;QAEF,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;KAChC;IAWD,GAAG,CACD,SAAiB,EACjB,OAG4B;QAE5B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;KACtC;;;;IAKO,QAAQ,CAAC,KAAa;QAC3B,IAA8B,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/C;IACO,YAAY,CAAC,SAAe;QACjC,IAA8B,CAAC,SAAS,GAAG,SAAS,CAAC;KACvD;IACO,UAAU,CAAC,OAAa;QAC7B,IAA8B,CAAC,OAAO,GAAG,OAAO,CAAC;KACnD;IACO,UAAU,CAAC,OAAa;QAC7B,IAA8B,CAAC,OAAO,GAAG,OAAO,CAAC;KACnD;;AAxdD;AACA;AACA;;;AAGgB,iBAAK,GAAG,SAAS,KAAK,CAAC,CAAQ,KAAU,CAAC;AAE1D;AACA;AACA;;;;;;;;;;AAUgB,mBAAO,GAAG,SAAS,OAAO,CAAC,CAK1C,KAAU,CAAC;AAEZ;AACA;AACA;;;;;;;;;;;;;;;;AAgBgB,qBAAS,GAAG,SAAS,SAAS,CAAC,CAa9C,KAAU,CAAC;;AClGd;;;;;;;;MAQa,mBAAoB,SAAQ,WAAW;;;;;IAKlD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;KACf;;;;IAKD,aAAa,KAAK,CAAC,MAA2B;QAC5C,OAAO,WAAW,CAAC,YAAY,iCAExB,MAAM,KACT,eAAe,EACb,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,eAAe,KAAI,uCAAuC,KAEtE,mBAEwB,CACzB,CAAC;KACH;;;;;"}
|
|
1
|
+
{"version":3,"file":"basemap-sessions.esm.js","sources":["../../node_modules/mitt/dist/mitt.mjs","../../src/utils/defaults.ts","../../src/utils/startNewSession.ts","../../src/utils/detemineSafetyMargin.ts","../../src/BaseSession.ts","../../src/BasemapStyleSession.ts"],"sourcesContent":["export default function(n){return{all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]))},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e)}),(i=n.get(\"*\"))&&i.slice().map(function(n){n(t,e)})}}}\n//# sourceMappingURL=mitt.mjs.map\n","export const DEFAULT_START_BASEMAP_STYLE_SESSION_URL =\n \"https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/sessions/start\";\n\nexport const DEFAULT_SAFETY_MARGIN = 5 * 60; // Default to 5 minutes in seconds\n\nexport const DEFAULT_CHECK_EXPIRATION_INTERVAL = 10; // Default to 10 seconds\n\nexport const DEFAULT_DURATION = 12 * 60 * 60; // Default to 12 hours in seconds\n","import { IAuthenticationManager, request } from \"@esri/arcgis-rest-request\";\nimport { StyleFamily } from \"../types/StyleFamily.js\";\nimport { DEFAULT_DURATION } from \"./defaults.js\";\n\nexport interface IRequestNewSessionParams {\n startSessionUrl: string;\n authentication: IAuthenticationManager | string;\n styleFamily?: StyleFamily;\n duration?: number;\n}\n\nexport interface IStartSessionResponse {\n sessionToken: string;\n endTime: number;\n startTime: number;\n styleFamily: StyleFamily;\n}\n\nexport function startNewSession({\n startSessionUrl,\n authentication,\n styleFamily = \"arcgis\",\n duration = DEFAULT_DURATION\n}: IRequestNewSessionParams): Promise<IStartSessionResponse> {\n return request(startSessionUrl, {\n httpMethod: \"GET\",\n authentication: authentication,\n params: { styleFamily, durationSeconds: duration }\n });\n}\n","import { DEFAULT_SAFETY_MARGIN } from \"./defaults.js\";\n\nexport function determineSafetyMargin(\n duration: number | undefined,\n safetyMargin: number | undefined\n): number {\n if (safetyMargin) {\n return safetyMargin;\n }\n\n // common cases are\n // duration is 60 seconds, this will return a 1 second safety margin\n // duration is 43200 seconds, this will return a 300 second (5 minutes) safety margin\n return Math.min(Math.max(duration / 100, 1), DEFAULT_SAFETY_MARGIN);\n}\n","import mitt from \"mitt\";\n\nimport { IAuthenticationManager } from \"@esri/arcgis-rest-request\";\nimport { StyleFamily } from \"./types/StyleFamily.js\";\nimport {\n IStartSessionResponse,\n startNewSession\n} from \"./utils/startNewSession.js\";\nimport { Writable } from \"./utils/writable.js\";\nimport { determineSafetyMargin } from \"./utils/detemineSafetyMargin.js\";\nimport {\n DEFAULT_DURATION,\n DEFAULT_CHECK_EXPIRATION_INTERVAL\n} from \"./utils/defaults.js\";\n\nexport interface IBasemapSessionParams {\n token: string;\n startSessionUrl: string;\n styleFamily: StyleFamily;\n authentication: IAuthenticationManager | string;\n expires: Date;\n startTime: Date;\n endTime: Date;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n}\n\nexport interface IStartSessionParams {\n styleFamily?: StyleFamily;\n authentication: IAuthenticationManager | string;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n\n /**\n * The URL to start the session. If not provided, it will use the default URL.\n * @private\n */\n startSessionUrl?: string;\n}\n\n/**\n * The base class for all basemap sessions. This class implements the {@linkcode @esri/arcgis-rest-request!IAuthenticationManager} interface and provides methods to start, refresh, and check the expiration of a session.\n * This is not intended to be used directly, but instead is extended by other classes such as {@linkcode BasemapStyleSession} .\n *\n * @abstract\n */\nexport abstract class BaseSession implements IAuthenticationManager {\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when an error occurs during session management.\n */\n static readonly error = function error(e: Error): void {};\n\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when the current session expires and the session token it no longer valid. This event will only fire if {@linkcode BaseSession.checkingExpirationTime}\n * is `true` which is the default. Once this event fires, {@linkcode BaseSession.checkingExpirationTime} will be set to `false` until the session is refreshed with\n * {@linkcode BaseSession.refreshCredentials}.\n *\n * @event expired\n * @param e.token - The session token that expired.\n * @param e.startTime - The start time of the session.\n * @param e.endTime - The end time of the session.\n * @param e.expires - The expiration time of the session.\n */\n static readonly expired = function expired(e: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n }): void {};\n\n // the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.\n /* istanbul ignore next -- @preserve */\n /**\n * Event handler for when a session refreshes and a new `token` is available.\n *\n * @event refreshed\n * @param e.previous - The previous session details.\n * @param e.previous.token - The previous session token.\n * @param e.previous.startTime - The start time of the previous session.\n * @param e.previous.endTime - The end time of the previous session.\n * @param e.previous.expires - The expiration time of the previous session.\n * @param e.current - The current session details.\n * @param e.current.token - The current session token.\n * @param e.current.startTime - The start time of the current token.\n * @param e.current.endTime - The end time of the current session.\n * @param e.current.expires - The expiration time of the current token.\n */\n static readonly refreshed = function refreshed(e: {\n previous: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n };\n current: {\n token: string;\n startTime: Date;\n endTime: Date;\n expires: Date;\n };\n }): void {};\n\n /**\n * The portal URL that the session is associated with. This generally is not used but exists to implement the `IAuthenticationManager` interface.\n */\n readonly portal: string;\n\n /**\n * The style family of the session. This is used to determine the type of basemap styles that are available.\n */\n readonly styleFamily: StyleFamily;\n\n /**\n * The authentication manager or token used for the session.\n * This can be an instance of {@linkcode @esri/arcgis-rest-request!ApiKeyManager}, {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager}, {@linkcode @esri/arcgis-rest-request!ApplicationCredentialsManager} or a string token.\n */\n readonly authentication: IAuthenticationManager | string;\n\n /**\n * The expiration date of the session. This is the {@linkcode BaseSession.endTime} minus the {@linkcode BaseSession.safetyMargin}. This is used internally to determine if the session is expired.\n */\n readonly expires: Date;\n\n /**\n * The start time of the session. This is the time returned from the API when the session war started.\n */\n readonly startTime: Date;\n\n /**\n * The end time of the session. This is the time returned from the API when the session will end.\n */\n readonly endTime: Date;\n\n /**\n * The token for the session.\n */\n readonly token: string;\n\n /**\n * The URL used to start the session.\n */\n readonly startSessionUrl: string;\n\n /**\n * The safety margin in milliseconds. This subtracted from the {@linkcode BaseSession.endTime} to get the expiration time of the session.\n */\n readonly safetyMargin: number;\n\n /**\n * The duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed.\n */\n readonly duration: number;\n\n /**\n * The interval at which to check the expiration time of the session. This is always 10 seconds or 1/100th of the duration, whichever is smaller.\n */\n private readonly expirationCheckInterval: number;\n\n /**\n * The ID of the timer used to check the expiration time of the session.\n */\n private expirationTimerId: any = null;\n\n /**\n * A pending session that is being refreshed. This is used to prevent multiple refreshes from happening at the same time.\n */\n private pendingSession: Promise<IStartSessionResponse> | null = null;\n\n /**\n * Internal instance of [`mitt`](https://github.com/developit/mitt) used for event handlers. It is recommended to use {@linkcode BasemapSession.on}, {@linkcode BasemapSession.off} or {@linkcode BasemapSession.once} instead of `emitter.`\n */\n private emitter: any;\n\n /**\n * A handler that is used to automatically refresh the session when it expires.\n */\n private autoRefreshHandler: (() => void) | null = null;\n\n /**\n * Creates a new instance of the BaseSession class. Generally you should not create an instance of this class directly, but instead use the static methods to start a session or deserialize a session.\n *\n * You may need to create an instance of this class directly if you are not using the built in deserialize method.\n *\n * @param params - The parameters for the session.\n * @param params.startSessionUrl - The URL to start the session.\n * @param params.token - The token for the session.\n * @param params.styleFamily - The style family of the session.\n * @param params.authentication - The authentication manager or token used for the session.\n * @param params.expires - The expiration date of the session.\n * @param params.startTime - The start time of the session.\n * @param params.endTime - The end time of the session.\n * @param params.safetyMargin - The safety margin in milliseconds.\n * @param params.duration - Indicates if this is a test session.\n */\n constructor(params: IBasemapSessionParams) {\n this.startSessionUrl = params.startSessionUrl;\n this.token = params.token;\n this.styleFamily = params.styleFamily || \"arcgis\";\n this.authentication = params.authentication;\n this.duration = params.duration || DEFAULT_DURATION;\n this.startTime = params.startTime;\n this.endTime = params.endTime;\n this.expires = params.expires;\n this.safetyMargin = params.safetyMargin;\n this.expirationCheckInterval =\n Math.min(this.duration / 100, DEFAULT_CHECK_EXPIRATION_INTERVAL) * 1000;\n this.emitter = mitt();\n }\n\n /**\n * Checks if the session is expired. If it is expired, it emits an \"expired\" event and disables expiration time checking. The event will fire **before** the method returns true.\n *\n * @returns {boolean} - Returns true if the session is expired, otherwise false.\n */\n isSessionExpired() {\n if (this.isExpired) {\n this.disableCheckingExpirationTime();\n\n this.emitter.emit(\"expired\", {\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n });\n }\n\n return this.isExpired;\n }\n\n /**\n * Starts checking the expiration time of the session. This will check the expiration time immediately and then on an interval.\n * If the session is expired, it will emit an \"expired\" event.\n */\n enableCheckingExpirationTime() {\n const check = () => {\n this.isSessionExpired();\n };\n\n if (!this.expirationTimerId) {\n this.expirationTimerId = setInterval(\n check,\n // check every 10 seconds or 1/100th of the duration, whichever is smaller\n this.expirationCheckInterval\n ); // check immediately then on an interval\n }\n\n setTimeout(() => {\n check(); // check immediately after starting the interval\n }, 10);\n\n return this.expirationTimerId; // return the timer ID so it can be stopped later\n }\n\n /**\n * Stops checking the expiration time of the session. This will clear the `setInterval()` that was started by {@linkcode BaseSession.enableCheckingExpirationTime}.\n */\n disableCheckingExpirationTime() {\n if (this.expirationTimerId) {\n clearInterval(this.expirationTimerId);\n this.expirationTimerId = null;\n }\n }\n\n /**\n * Starts a new session using the provided parameters and returns an instance of the session class.\n *\n * @param params - The parameters for starting the session.\n * @param SessionClass - The class to use for the session.\n * @returns A promise that resolves to an instance of the session class.\n */\n protected static async startSession<T extends BaseSession>(\n {\n startSessionUrl,\n styleFamily = \"arcgis\",\n authentication,\n safetyMargin,\n duration = DEFAULT_DURATION,\n autoRefresh = false\n }: {\n startSessionUrl?: string;\n styleFamily?: StyleFamily;\n authentication: IAuthenticationManager | string;\n safetyMargin?: number;\n duration?: number;\n autoRefresh?: boolean;\n },\n SessionClass: new (params: IBasemapSessionParams) => T\n ): Promise<T> {\n if (duration < 10) {\n throw new Error(\"Session duration must be at least 10 seconds.\");\n }\n\n if (duration > 43200) {\n throw new Error(\n \"Session duration cannot exceed 12 hours (43200 seconds).\"\n );\n }\n\n const sessionResponse = await startNewSession({\n startSessionUrl,\n styleFamily,\n authentication,\n duration\n });\n const actualSafetyMargin = determineSafetyMargin(duration, safetyMargin);\n\n const session = new SessionClass({\n startSessionUrl: startSessionUrl,\n token: sessionResponse.sessionToken,\n styleFamily,\n authentication,\n safetyMargin: actualSafetyMargin,\n expires: new Date(sessionResponse.endTime - actualSafetyMargin * 1000),\n startTime: new Date(sessionResponse.startTime),\n endTime: new Date(sessionResponse.endTime),\n duration\n });\n\n session.enableCheckingExpirationTime();\n\n if (autoRefresh) {\n session.enableAutoRefresh();\n }\n\n return session as T;\n }\n\n /**\n * Indicates if the session is currently checking for expiration time.\n *\n * @returns {boolean} - Returns true if the session is checking for expiration time, otherwise false.\n */\n get checkingExpirationTime(): boolean {\n return !!this.expirationTimerId;\n }\n\n /**\n * Returns the number of seconds until the session is no longer valid rounded down. If the session is expired, it will return 0.\n */\n get secondsUntilExpiration(): number {\n return Math.floor(this.millisecondsUntilExpiration / 1000);\n }\n\n /**\n * Returns the number of milliseconds until the session token is no longer valid. If the session is expired, it will return 0.\n */\n get millisecondsUntilExpiration(): number {\n if (this.isExpired) {\n return 0;\n }\n\n const now = new Date();\n const millisecondsLeft = this.endTime.getTime() - now.getTime();\n\n return millisecondsLeft;\n }\n\n /**\n * Checks if the session is expired.\n *\n */\n get isExpired(): boolean {\n return this.expires < new Date();\n }\n\n /**\n * Gets the session token. If the session is expired, it will refresh the credentials and return the new token.\n *\n * @returns A promise that resolves to the session token.\n */\n getToken(): Promise<string> {\n if (this.isExpired) {\n return this.refreshCredentials().then(() => this.token);\n }\n\n return Promise.resolve(this.token);\n }\n\n /**\n * Indicates if the session can be refreshed. This is always true for this basemap sessions.\n *\n * @returns {boolean} - Always returns true.\n */\n get canRefresh(): boolean {\n return true;\n }\n\n /**\n * Indicates if the session is set to automatically refresh when it expires.\n *\n * @returns {boolean} - Returns true if auto-refresh is enabled, otherwise false.\n */\n get autoRefresh(): boolean {\n return !!this.autoRefreshHandler && !!this.expirationTimerId;\n }\n\n /**\n * Refreshes the session credentials by starting a new session.\n * This will emit a \"refreshed\" event with the previous and current session details.\n *\n * @returns A promise that resolves to the current instance of the session.\n */\n async refreshCredentials(): Promise<this> {\n if (this.pendingSession) {\n // if there is a pending session, wait for it to resolve\n await this.pendingSession;\n return this;\n }\n\n // @TODO switch this to structured clone when we upgrade to Node 20+ types so we don't have to parse the dates later\n const previous = JSON.parse(\n JSON.stringify({\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n })\n );\n\n try {\n this.pendingSession = startNewSession({\n startSessionUrl: this.startSessionUrl,\n styleFamily: this.styleFamily,\n authentication: this.authentication,\n duration: this.duration\n });\n\n const newSession = await this.pendingSession;\n\n this.pendingSession = null; // reset the pending session\n\n this.setToken(newSession.sessionToken);\n this.setStartTime(new Date(newSession.startTime));\n this.setEndTime(new Date(newSession.endTime));\n this.setExpires(new Date(newSession.endTime - this.safetyMargin * 1000));\n\n this.enableCheckingExpirationTime(); // restart checking expiration time after refreshing credentials\n\n this.emitter.emit(\"refreshed\", {\n previous: {\n token: previous.token,\n startTime: new Date(previous.startTime),\n endTime: new Date(previous.endTime),\n expires: new Date(previous.expires)\n },\n current: {\n token: this.token,\n startTime: this.startTime,\n endTime: this.endTime,\n expires: this.expires\n }\n });\n } catch (error) {\n this.emitter.emit(\"error\", error);\n throw error;\n }\n\n return this;\n }\n /**\n * Enables auto-refresh for the session. This will automatically refresh the session when it expires.\n * It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.enableCheckingExpirationTime}.\n */\n enableAutoRefresh() {\n if (!this.expirationTimerId) {\n this.enableCheckingExpirationTime();\n }\n\n this.autoRefreshHandler = () => {\n this.refreshCredentials().catch((error: Error) => {\n this.emitter.emit(\"error\", error);\n });\n };\n\n this.on(\"expired\", this.autoRefreshHandler);\n }\n\n /**\n * Disables auto-refresh for the session. This will stop automatically refreshing the session when it expires.\n * This will **not** stop checking the expiration time of the session. If you want to stop automated expiration\n * checking, call {@linkcode BaseSession.disableCheckingExpirationTime} after calling this method.\n */\n disableAutoRefresh() {\n if (this.autoRefreshHandler) {\n this.off(\"expired\", this.autoRefreshHandler);\n this.autoRefreshHandler = null;\n }\n }\n\n /**\n * Removes all event listeners and disables auto-refresh and expiration time checking. This is useful for cleaning up the session when it is no longer needed or replaced with a new session.\n */\n destroy() {\n this.disableAutoRefresh();\n this.disableCheckingExpirationTime();\n this.emitter.off(\"expired\");\n this.emitter.off(\"refreshed\");\n this.emitter.off(\"error\");\n this.emitter.off(\"*\");\n }\n\n /**\n * A handler that listens for an eventName and returns custom handler.\n *\n * @param event A string of what event to listen for.\n * @param handler A function of what to do when eventName was called.\n */\n on(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n on(event: \"expired\", handler: typeof BaseSession.expired): void;\n on(event: \"error\", handler: typeof BaseSession.error): void;\n on(\n event: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n this.emitter.on(event, handler);\n this.isSessionExpired(); // check if the session is expired immediately after adding the handler\n }\n\n /**\n * A handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with {@linkcode BaseSession.off}.\n *\n * @param event A string of what event to listen for.\n * @param handler A function of what to do when event was called.\n */\n once(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n once(event: \"expired\", handler: typeof BaseSession.expired): void;\n once(event: \"error\", handler: typeof BaseSession.error): void;\n once(\n event: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n const fn = (e: any) => {\n this.emitter.off(event, fn);\n handler(e);\n };\n\n this.emitter.on(event, fn);\n }\n\n /**\n * A handler that will remove a listener from a given event.\n *\n * @param event A string of what event to listen for.\n * @param handler A function of what to do when event was called.\n */\n off(event: \"refreshed\", handler: typeof BaseSession.refreshed): void;\n off(event: \"expired\", handler: typeof BaseSession.expired): void;\n off(event: \"error\", handler: typeof BaseSession.error): void;\n off(\n event: string,\n handler:\n | typeof BaseSession.refreshed\n | typeof BaseSession.expired\n | typeof BaseSession.error\n ) {\n this.emitter.off(event, handler);\n }\n\n /**\n * These private methods are used to set the internal state of the session.\n */\n private setToken(token: string) {\n (this as Writable<typeof this>).token = token;\n }\n private setStartTime(startTime: Date) {\n (this as Writable<typeof this>).startTime = startTime;\n }\n private setEndTime(endTime: Date) {\n (this as Writable<typeof this>).endTime = endTime;\n }\n private setExpires(expires: Date) {\n (this as Writable<typeof this>).expires = expires;\n }\n}\n","import {\n BaseSession,\n IBasemapSessionParams,\n IStartSessionParams\n} from \"./BaseSession.js\";\nimport { DEFAULT_START_BASEMAP_STYLE_SESSION_URL } from \"./utils/defaults.js\";\n\n/**\n * `BasemapStyleSession` is a class that extends {@linkcode BaseSession} to manage sessions\n * for basemap styles. It provides methods to {@linkcode BasemapStyleSession.start} a new session\n * which should be used instead of constructing a new instance directly.\n *\n * @class BasemapStyleSession\n * @extends BaseSession\n */\nexport class BasemapStyleSession extends BaseSession {\n /**\n * Creates an instance of `BasemapStyleSession`. Constructing `BasemapStyleSession` directly is discouraged.\n * Instead, use the static method {@linkcode BasemapStyleSession.start} to start a new session.\n */\n constructor(params: IBasemapSessionParams) {\n super(params);\n }\n\n /**\n * Starts a new basemap style session.\n */\n static async start(params: IStartSessionParams) {\n return BaseSession.startSession<BasemapStyleSession>(\n {\n ...params,\n startSessionUrl:\n params?.startSessionUrl || DEFAULT_START_BASEMAP_STYLE_SESSION_URL\n },\n BasemapStyleSession as new (\n params: IBasemapSessionParams\n ) => BasemapStyleSession\n );\n }\n}\n"],"names":[],"mappings":";;;;;;;AAAe,aAAQ,CAAC,CAAC,CAAC,CAAC,OAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,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AA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAExB,MAAM,CAAA,EAAA,EACT,eAAe,EACb,CAAA,MAAM,aAAN,MAAM,KAAA,MAAA,GAAA,MAAA,GAAN,MAAM,CAAE,eAAe,KAAI,uCAAuC,EAAA,CAAA,EAEtE,mBAEwB,CACzB;IACH;AACD;;;;","x_google_ignoreList":[0]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/arcgis-rest-basemap-sessions -
|
|
3
|
-
* Copyright (c) 2017-
|
|
4
|
-
*
|
|
2
|
+
* @esri/arcgis-rest-basemap-sessions - v4.8.0 - Apache-2.0
|
|
3
|
+
* Copyright (c) 2017-2026 Esri, Inc.
|
|
4
|
+
* Fri Jan 16 2026 01:29:33 GMT+0000 (Coordinated Universal Time)
|
|
5
5
|
*/
|
|
6
|
-
import{request as
|
|
7
|
-
/* istanbul ignore next -- @preserve */a.error=function(
|
|
6
|
+
import{request as e}from"@esri/arcgis-rest-request";const t="https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/sessions/start",i=300,s=10,r=43200;function n({startSessionUrl:t,authentication:i,styleFamily:s="arcgis",duration:r=43200}){return e(t,{httpMethod:"GET",authentication:i,params:{styleFamily:s,durationSeconds:r}})}class a{constructor(e){var t;this.expirationTimerId=null,this.pendingSession=null,this.autoRefreshHandler=null,this.startSessionUrl=e.startSessionUrl,this.token=e.token,this.styleFamily=e.styleFamily||"arcgis",this.authentication=e.authentication,this.duration=e.duration||r,this.startTime=e.startTime,this.endTime=e.endTime,this.expires=e.expires,this.safetyMargin=e.safetyMargin,this.expirationCheckInterval=1e3*Math.min(this.duration/100,10),this.emitter={all:t=t||new Map,on:function(e,i){var s=t.get(e);s?s.push(i):t.set(e,[i])},off:function(e,i){var s=t.get(e);s&&(i?s.splice(s.indexOf(i)>>>0,1):t.set(e,[]))},emit:function(e,i){var s=t.get(e);s&&s.slice().map(function(e){e(i)}),(s=t.get("*"))&&s.slice().map(function(t){t(e,i)})}}}isSessionExpired(){return this.isExpired&&(this.disableCheckingExpirationTime(),this.emitter.emit("expired",{token:this.token,startTime:this.startTime,endTime:this.endTime,expires:this.expires})),this.isExpired}enableCheckingExpirationTime(){const e=()=>{this.isSessionExpired()};return this.expirationTimerId||(this.expirationTimerId=setInterval(e,this.expirationCheckInterval)),setTimeout(()=>{e()},10),this.expirationTimerId}disableCheckingExpirationTime(){this.expirationTimerId&&(clearInterval(this.expirationTimerId),this.expirationTimerId=null)}static async startSession({startSessionUrl:e,styleFamily:t="arcgis",authentication:i,safetyMargin:s,duration:r=43200,autoRefresh:a=!1},o){if(r<10)throw new Error("Session duration must be at least 10 seconds.");if(r>43200)throw new Error("Session duration cannot exceed 12 hours (43200 seconds).");const h=await n({startSessionUrl:e,styleFamily:t,authentication:i,duration:r}),m=function(e,t){return t||Math.min(Math.max(e/100,1),300)}(r,s),d=new o({startSessionUrl:e,token:h.sessionToken,styleFamily:t,authentication:i,safetyMargin:m,expires:new Date(h.endTime-1e3*m),startTime:new Date(h.startTime),endTime:new Date(h.endTime),duration:r});return d.enableCheckingExpirationTime(),a&&d.enableAutoRefresh(),d}get checkingExpirationTime(){return!!this.expirationTimerId}get secondsUntilExpiration(){return Math.floor(this.millisecondsUntilExpiration/1e3)}get millisecondsUntilExpiration(){if(this.isExpired)return 0;const e=new Date;return this.endTime.getTime()-e.getTime()}get isExpired(){return this.expires<new Date}getToken(){return this.isExpired?this.refreshCredentials().then(()=>this.token):Promise.resolve(this.token)}get canRefresh(){return!0}get autoRefresh(){return!!this.autoRefreshHandler&&!!this.expirationTimerId}async refreshCredentials(){if(this.pendingSession)return await this.pendingSession,this;const e=JSON.parse(JSON.stringify({token:this.token,startTime:this.startTime,endTime:this.endTime,expires:this.expires}));try{this.pendingSession=n({startSessionUrl:this.startSessionUrl,styleFamily:this.styleFamily,authentication:this.authentication,duration:this.duration});const t=await this.pendingSession;this.pendingSession=null,this.setToken(t.sessionToken),this.setStartTime(new Date(t.startTime)),this.setEndTime(new Date(t.endTime)),this.setExpires(new Date(t.endTime-1e3*this.safetyMargin)),this.enableCheckingExpirationTime(),this.emitter.emit("refreshed",{previous:{token:e.token,startTime:new Date(e.startTime),endTime:new Date(e.endTime),expires:new Date(e.expires)},current:{token:this.token,startTime:this.startTime,endTime:this.endTime,expires:this.expires}})}catch(e){throw this.emitter.emit("error",e),e}return this}enableAutoRefresh(){this.expirationTimerId||this.enableCheckingExpirationTime(),this.autoRefreshHandler=()=>{this.refreshCredentials().catch(e=>{this.emitter.emit("error",e)})},this.on("expired",this.autoRefreshHandler)}disableAutoRefresh(){this.autoRefreshHandler&&(this.off("expired",this.autoRefreshHandler),this.autoRefreshHandler=null)}destroy(){this.disableAutoRefresh(),this.disableCheckingExpirationTime(),this.emitter.off("expired"),this.emitter.off("refreshed"),this.emitter.off("error"),this.emitter.off("*")}on(e,t){this.emitter.on(e,t),this.isSessionExpired()}once(e,t){const i=s=>{this.emitter.off(e,i),t(s)};this.emitter.on(e,i)}off(e,t){this.emitter.off(e,t)}setToken(e){this.token=e}setStartTime(e){this.startTime=e}setEndTime(e){this.endTime=e}setExpires(e){this.expires=e}}
|
|
7
|
+
/* istanbul ignore next -- @preserve */a.error=function(e){},
|
|
8
8
|
/* istanbul ignore next -- @preserve */
|
|
9
|
-
a.expired=function(
|
|
9
|
+
a.expired=function(e){},
|
|
10
10
|
/* istanbul ignore next -- @preserve */
|
|
11
|
-
a.refreshed=function(
|
|
11
|
+
a.refreshed=function(e){};class o extends a{constructor(e){super(e)}static async start(e){return a.startSession(Object.assign(Object.assign({},e),{startSessionUrl:(null==e?void 0:e.startSessionUrl)||t}),o)}}export{a as BaseSession,o as BasemapStyleSession,s as DEFAULT_CHECK_EXPIRATION_INTERVAL,r as DEFAULT_DURATION,i as DEFAULT_SAFETY_MARGIN,t as DEFAULT_START_BASEMAP_STYLE_SESSION_URL,n as startNewSession};
|
|
12
12
|
//# sourceMappingURL=basemap-sessions.esm.min.js.map
|