@superrouteca/smap 1.1.6 → 1.1.7
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/CHANGELOG.md +9 -0
- package/README.md +10 -0
- package/dist/SOURCE.json +7 -7
- package/dist/smap-client.cjs +2 -2
- package/dist/smap-client.js +2 -2
- package/dist/smap-client.mjs +2 -2
- package/dist/smap.cjs +186 -37
- package/dist/smap.js +185 -36
- package/dist/smap.mjs +186 -37
- package/package.json +1 -1
- package/types/smap.d.cts +24 -1
- package/types/smap.d.mts +24 -1
package/dist/smap.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Generated by js/build.mjs from js/src (see SOURCE.json). Do not edit. */
|
|
2
|
-
/*! sMap Web SDK 1.1.
|
|
2
|
+
/*! sMap Web SDK 1.1.7. Bundles maplibre-gl 6.16.0 (BSD-3-Clause), see vendor-licenses.txt. */
|
|
3
3
|
|
|
4
4
|
var smapCore = null;
|
|
5
5
|
function smapCreateEngine() {
|
|
@@ -28363,6 +28363,24 @@ function smapCreatePlan() {
|
|
|
28363
28363
|
// its Origin; a native app also names itself with X-SMap-App (and X-SMap-App-Cert on Android).
|
|
28364
28364
|
|
|
28365
28365
|
var DEFAULT_BASE = 'https://open.superroute.ca';
|
|
28366
|
+
// The sMap service a map key's configuration is read from (GET <smap>/plan/v1/config), unless the editor is told another.
|
|
28367
|
+
var DEFAULT_SMAP = 'https://tile.srsr.ca';
|
|
28368
|
+
// Fast path (OPEN-ROUTE-EDIT E19, §2f.5): a call there not answered within this long is repeated on the standard path.
|
|
28369
|
+
// Per call, in this one place: every call 2 s, except refine (its search runs up to 2 s inside sRoad, and sMap's own
|
|
28370
|
+
// refine budget is 4 s) 5 s.
|
|
28371
|
+
var FAST_PATH_TIMEOUT_MS = 2000;
|
|
28372
|
+
var FAST_PATH_REFINE_TIMEOUT_MS = 5000;
|
|
28373
|
+
/** The fast-path time limit of a call (`path` after /v1/plan), from the defaults or the options that replace them. */
|
|
28374
|
+
function fastPathTimeoutFor(path, o) {
|
|
28375
|
+
var refine = path === '/refine';
|
|
28376
|
+
var given = refine ? o.fastPathRefineTimeout : o.fastPathTimeout;
|
|
28377
|
+
if (typeof given === 'number' && given > 0) { return given; }
|
|
28378
|
+
return refine ? FAST_PATH_REFINE_TIMEOUT_MS : FAST_PATH_TIMEOUT_MS;
|
|
28379
|
+
}
|
|
28380
|
+
// A map key's configuration is kept this long; one that could not be read is asked for again after RETRY.
|
|
28381
|
+
var KEY_CONFIG_TTL_MS = 600000;
|
|
28382
|
+
var KEY_CONFIG_RETRY_MS = 60000;
|
|
28383
|
+
var PLAN_PREFIX = '/v1/plan';
|
|
28366
28384
|
// A token whose expiry can be read is renewed this many seconds before it ends.
|
|
28367
28385
|
var RENEW_BEFORE = 30;
|
|
28368
28386
|
var TOKEN_PREFIX = 'sr_pet_';
|
|
@@ -28385,19 +28403,27 @@ function smapCreatePlan() {
|
|
|
28385
28403
|
/**
|
|
28386
28404
|
* What a token provider gave: the token string, or the token answer of POST /v1/plan/token
|
|
28387
28405
|
* ({ access_token, token_type, expires_in, expires_at, scopes, origins }, or that answer's `{ data }` envelope).
|
|
28388
|
-
* Returns { token, exp } with exp in Unix seconds (0 when it cannot be told)
|
|
28406
|
+
* Returns { token, exp, fastPath } with exp in Unix seconds (0 when it cannot be told) and fastPath the answer's
|
|
28407
|
+
* `fast_path.url` (null without one: every call goes to the standard path).
|
|
28389
28408
|
*/
|
|
28390
28409
|
function readToken(t) {
|
|
28391
28410
|
if (t && typeof t === 'object' && t.data && typeof t.data === 'object' && !t.access_token) { t = t.data; }
|
|
28392
|
-
if (typeof t === 'string' && t) { return { token: t, exp: tokenExpiry(t) }; }
|
|
28411
|
+
if (typeof t === 'string' && t) { return { token: t, exp: tokenExpiry(t), fastPath: null }; }
|
|
28393
28412
|
if (t && typeof t === 'object' && typeof t.access_token === 'string' && t.access_token) {
|
|
28394
28413
|
var exp = t.expires_at ? Date.parse(t.expires_at) / 1000 : 0;
|
|
28395
28414
|
if (!exp && typeof t.expires_in === 'number') { exp = Date.now() / 1000 + t.expires_in; }
|
|
28396
|
-
return { token: t.access_token, exp: exp || tokenExpiry(t.access_token) };
|
|
28415
|
+
return { token: t.access_token, exp: exp || tokenExpiry(t.access_token), fastPath: fastPathOf(t) };
|
|
28397
28416
|
}
|
|
28398
28417
|
return null;
|
|
28399
28418
|
}
|
|
28400
28419
|
|
|
28420
|
+
/** The fast-path address of a token answer or a map key's configuration (`fast_path.url`), or null. */
|
|
28421
|
+
function fastPathOf(o) {
|
|
28422
|
+
var f = o && typeof o === 'object' ? o.fast_path : null;
|
|
28423
|
+
var url = f && typeof f === 'object' && typeof f.url === 'string' ? f.url.replace(/\/+$/, '') : '';
|
|
28424
|
+
return url ? url : null;
|
|
28425
|
+
}
|
|
28426
|
+
|
|
28401
28427
|
/** The app headers of a native app: options.app is 'android:<package>' / 'apple:<bundle id>' / 'windows:<id>', or { id, cert }. */
|
|
28402
28428
|
function appHeaders(app) {
|
|
28403
28429
|
var h = {};
|
|
@@ -28416,6 +28442,7 @@ function smapCreatePlan() {
|
|
|
28416
28442
|
if (c && typeof c.token === 'function') {
|
|
28417
28443
|
var token = null;
|
|
28418
28444
|
var exp = 0;
|
|
28445
|
+
var fast = null;
|
|
28419
28446
|
var pending = null;
|
|
28420
28447
|
var fetchToken = function () {
|
|
28421
28448
|
if (!pending) {
|
|
@@ -28425,6 +28452,7 @@ function smapCreatePlan() {
|
|
|
28425
28452
|
if (!read) { throw new Error('sMap plan editor: the token provider gave no token'); }
|
|
28426
28453
|
token = read.token;
|
|
28427
28454
|
exp = read.exp;
|
|
28455
|
+
fast = read.fastPath;
|
|
28428
28456
|
return token;
|
|
28429
28457
|
}, function (e) { pending = null; throw e; });
|
|
28430
28458
|
}
|
|
@@ -28438,6 +28466,8 @@ function smapCreatePlan() {
|
|
|
28438
28466
|
},
|
|
28439
28467
|
// After a 401 SESSION_EXPIRED: forget the token so the next call asks the provider again. True when a retry may help.
|
|
28440
28468
|
renew: function () { token = null; exp = 0; return true; },
|
|
28469
|
+
// The fast-path address the latest token answer gave (read after headers()), or null.
|
|
28470
|
+
fastPath: function () { return Promise.resolve(fast); },
|
|
28441
28471
|
};
|
|
28442
28472
|
}
|
|
28443
28473
|
if (c && typeof c.key === 'string' && c.key) {
|
|
@@ -28445,6 +28475,7 @@ function smapCreatePlan() {
|
|
|
28445
28475
|
kind: 'key',
|
|
28446
28476
|
headers: function () { return Promise.resolve({ Authorization: 'Bearer ' + c.key }); },
|
|
28447
28477
|
renew: function () { return false; },
|
|
28478
|
+
fastPath: null, // set by the transport: the key's configuration on sMap
|
|
28448
28479
|
};
|
|
28449
28480
|
}
|
|
28450
28481
|
throw new Error('sMap plan editor: credentials are { token: () => Promise<string | TokenAnswer> } or { key: string }');
|
|
@@ -28467,44 +28498,155 @@ function smapCreatePlan() {
|
|
|
28467
28498
|
function cancelled() { var e = new Error('cancelled'); e.name = 'AbortError'; e.cancelled = true; return e; }
|
|
28468
28499
|
|
|
28469
28500
|
/**
|
|
28470
|
-
* The transport: send(method, path, body, signal) resolves { status, body, data, matrix } (matrix: the
|
|
28471
|
-
* header
|
|
28472
|
-
*
|
|
28501
|
+
* The transport: send(method, path, body, signal) resolves { status, body, data, matrix, path } (matrix: the
|
|
28502
|
+
* X-Plan-Matrix header; path: 'fast' or 'standard', where the answer came from) or rejects with a PlanError. A 401
|
|
28503
|
+
* SESSION_EXPIRED with a token provider asks for a new token and repeats the call once; every other refusal
|
|
28504
|
+
* (SESSION_REVOKED, TOKEN_INVALID, 403 NOT_AUTHORIZED with its reason) is raised.
|
|
28505
|
+
*
|
|
28506
|
+
* Fast path (OPEN-ROUTE-EDIT E19, §2f.5): when the credential names a fast-path address (the token answer's
|
|
28507
|
+
* `fast_path.url`, or a map key's configuration from GET <smapUrl>/plan/v1/config), each call goes to
|
|
28508
|
+
* <url>/<same path> with the same method, credential, headers and body. A 409 USE_STANDARD_PATH (or the header
|
|
28509
|
+
* X-Plan-Path: standard), any 5xx, a network error or no answer within 2 s (refine: 5 s) repeats the same call once on the standard
|
|
28510
|
+
* path (<baseUrl>/v1/plan/<same path>); the next call tries the fast path again. 402, 429 and every other 4xx are final.
|
|
28473
28511
|
*/
|
|
28474
28512
|
function createTransport(o) {
|
|
28475
28513
|
o = o || {};
|
|
28476
28514
|
var base = String(o.baseUrl || DEFAULT_BASE).replace(/\/$/, '');
|
|
28515
|
+
var smap = String(o.smapUrl || DEFAULT_SMAP).replace(/\/$/, '');
|
|
28516
|
+
var fastOn = o.fastPath !== false;
|
|
28517
|
+
var timeoutMs = fastPathTimeoutFor('', o);
|
|
28477
28518
|
var creds = credentialsOf(o.credentials);
|
|
28478
28519
|
var app = appHeaders(o.app);
|
|
28479
28520
|
var fetchFn = o.fetch || (typeof fetch === 'function' ? function (url, init) { return fetch(url, init); } : null);
|
|
28480
28521
|
if (!fetchFn) { throw new Error('sMap plan editor: no fetch; pass options.fetch'); }
|
|
28481
28522
|
|
|
28523
|
+
function headersWith(h, json) {
|
|
28524
|
+
var headers = { Accept: 'application/json' };
|
|
28525
|
+
Object.keys(app).forEach(function (k) { headers[k] = app[k]; });
|
|
28526
|
+
Object.keys(h).forEach(function (k) { headers[k] = h[k]; });
|
|
28527
|
+
if (json) { headers['Content-Type'] = 'application/json'; }
|
|
28528
|
+
return headers;
|
|
28529
|
+
}
|
|
28530
|
+
|
|
28531
|
+
// One request, read to the end. With `limit` it gives up after that many ms ({ timedOut: true }); a network error
|
|
28532
|
+
// resolves { failed: error } unless the caller's own signal ended it (then it rejects, cancelled).
|
|
28533
|
+
function exchange(url, init, signal, limit) {
|
|
28534
|
+
if (!limit) {
|
|
28535
|
+
return fetchFn(url, init).then(read);
|
|
28536
|
+
}
|
|
28537
|
+
var inner = newController();
|
|
28538
|
+
var timedOut = false;
|
|
28539
|
+
var timer = null;
|
|
28540
|
+
var onAbort = function () { if (inner) { inner.abort(); } };
|
|
28541
|
+
if (signal) {
|
|
28542
|
+
if (signal.aborted) { return Promise.reject(cancelled()); }
|
|
28543
|
+
if (signal.addEventListener) { signal.addEventListener('abort', onAbort); }
|
|
28544
|
+
}
|
|
28545
|
+
var own = {};
|
|
28546
|
+
Object.keys(init).forEach(function (k) { own[k] = init[k]; });
|
|
28547
|
+
if (inner) { own.signal = inner.signal; }
|
|
28548
|
+
var done = function () {
|
|
28549
|
+
if (timer) { clearTimeout(timer); }
|
|
28550
|
+
if (signal && signal.removeEventListener) { signal.removeEventListener('abort', onAbort); }
|
|
28551
|
+
};
|
|
28552
|
+
var timeout = new Promise(function (resolve) {
|
|
28553
|
+
timer = setTimeout(function () { timedOut = true; if (inner) { inner.abort(); } resolve({ timedOut: true }); }, limit);
|
|
28554
|
+
});
|
|
28555
|
+
var answer = Promise.resolve().then(function () { return fetchFn(url, own); }).then(read).then(function (r) { return r; }, function (e) {
|
|
28556
|
+
if (signal && signal.aborted) { throw cancelled(); }
|
|
28557
|
+
if (timedOut) { return { timedOut: true }; }
|
|
28558
|
+
return { failed: e };
|
|
28559
|
+
});
|
|
28560
|
+
return Promise.race([answer, timeout]).then(function (r) {
|
|
28561
|
+
done();
|
|
28562
|
+
if (signal && signal.aborted) { throw cancelled(); }
|
|
28563
|
+
return r;
|
|
28564
|
+
}, function (e) { done(); throw e; });
|
|
28565
|
+
}
|
|
28566
|
+
|
|
28567
|
+
function read(res) {
|
|
28568
|
+
return res.text().then(function (text) {
|
|
28569
|
+
var json = null;
|
|
28570
|
+
try { json = text ? JSON.parse(text) : null; } catch (e) { json = null; }
|
|
28571
|
+
var get = function (k) { return res.headers && typeof res.headers.get === 'function' ? res.headers.get(k) : null; };
|
|
28572
|
+
return { status: res.status, ok: res.ok, json: json, matrix: get('X-Plan-Matrix'), planPath: get('X-Plan-Path') };
|
|
28573
|
+
});
|
|
28574
|
+
}
|
|
28575
|
+
|
|
28576
|
+
// A map key's configuration on sMap: GET <smap>/plan/v1/config -> {"fast_path": {"url"}} or {}.
|
|
28577
|
+
var keyConfig = { url: null, until: 0, pending: null };
|
|
28578
|
+
function keyFastPath(h) {
|
|
28579
|
+
if (Date.now() < keyConfig.until) { return Promise.resolve(keyConfig.url); }
|
|
28580
|
+
if (keyConfig.pending) { return keyConfig.pending; }
|
|
28581
|
+
keyConfig.pending = exchange(smap + '/plan/v1/config', { method: 'GET', headers: headersWith(h, false) }, null, timeoutMs).then(function (r) {
|
|
28582
|
+
if (r.status >= 200 && r.status < 300) {
|
|
28583
|
+
keyConfig.url = fastPathOf(r.json);
|
|
28584
|
+
keyConfig.until = Date.now() + KEY_CONFIG_TTL_MS;
|
|
28585
|
+
} else {
|
|
28586
|
+
// A refusal is an answer (no fast path for this key); a failure is asked again after a minute.
|
|
28587
|
+
keyConfig.url = null;
|
|
28588
|
+
keyConfig.until = Date.now() + (r.status >= 400 && r.status < 500 ? KEY_CONFIG_TTL_MS : KEY_CONFIG_RETRY_MS);
|
|
28589
|
+
}
|
|
28590
|
+
return keyConfig.url;
|
|
28591
|
+
}, function () {
|
|
28592
|
+
keyConfig.url = null;
|
|
28593
|
+
keyConfig.until = Date.now() + KEY_CONFIG_RETRY_MS;
|
|
28594
|
+
return null;
|
|
28595
|
+
}).then(function (url) { keyConfig.pending = null; return url; });
|
|
28596
|
+
return keyConfig.pending;
|
|
28597
|
+
}
|
|
28598
|
+
|
|
28599
|
+
function fastPathFor(h) {
|
|
28600
|
+
if (!fastOn) { return Promise.resolve(null); }
|
|
28601
|
+
return creds.fastPath ? creds.fastPath() : keyFastPath(h);
|
|
28602
|
+
}
|
|
28603
|
+
|
|
28604
|
+
// Repeat on the standard path (§2f.5)?
|
|
28605
|
+
function useStandard(r) {
|
|
28606
|
+
if (r.timedOut || r.failed) { return true; }
|
|
28607
|
+
if (r.status >= 500) { return true; }
|
|
28608
|
+
if (r.status !== 409) { return false; }
|
|
28609
|
+
return !!(r.json && r.json.error && r.json.error.code === 'USE_STANDARD_PATH') || String(r.planPath || '').toLowerCase() === 'standard';
|
|
28610
|
+
}
|
|
28611
|
+
|
|
28482
28612
|
function send(method, path, body, signal, retried) {
|
|
28483
|
-
|
|
28484
|
-
|
|
28485
|
-
|
|
28486
|
-
|
|
28487
|
-
|
|
28488
|
-
if (
|
|
28489
|
-
|
|
28490
|
-
|
|
28491
|
-
|
|
28492
|
-
|
|
28493
|
-
|
|
28494
|
-
|
|
28495
|
-
|
|
28496
|
-
|
|
28497
|
-
|
|
28498
|
-
|
|
28499
|
-
|
|
28500
|
-
|
|
28501
|
-
|
|
28502
|
-
|
|
28503
|
-
return
|
|
28613
|
+
var h = null;
|
|
28614
|
+
return creds.headers().then(function (got) {
|
|
28615
|
+
h = got;
|
|
28616
|
+
return fastPathFor(h);
|
|
28617
|
+
}).then(function (fast) {
|
|
28618
|
+
if (signal && signal.aborted) { throw cancelled(); }
|
|
28619
|
+
var init = { method: method, headers: headersWith(h, body !== undefined) };
|
|
28620
|
+
if (body !== undefined) { init.body = JSON.stringify(body); }
|
|
28621
|
+
var standard = function () {
|
|
28622
|
+
var s = {};
|
|
28623
|
+
Object.keys(init).forEach(function (k) { s[k] = init[k]; });
|
|
28624
|
+
s.headers = headersWith(h, body !== undefined);
|
|
28625
|
+
if (signal) { s.signal = signal; }
|
|
28626
|
+
return exchange(base + path, s, signal, 0).then(function (r) { r.via = 'standard'; return r; });
|
|
28627
|
+
};
|
|
28628
|
+
if (!fast || path.indexOf(PLAN_PREFIX + '/') !== 0) { return standard(); }
|
|
28629
|
+
var rest = path.slice(PLAN_PREFIX.length);
|
|
28630
|
+
return exchange(fast + rest, init, signal, fastPathTimeoutFor(rest, o)).then(function (r) {
|
|
28631
|
+
if (useStandard(r)) { return standard(); }
|
|
28632
|
+
r.via = 'fast';
|
|
28633
|
+
return r;
|
|
28504
28634
|
});
|
|
28635
|
+
}).then(function (r) {
|
|
28636
|
+
if (!r.ok) {
|
|
28637
|
+
var json = r.json;
|
|
28638
|
+
var err = (json && json.error) || {};
|
|
28639
|
+
if (r.status === 401 && err.code === 'SESSION_EXPIRED' && !retried && creds.renew()) { return send(method, path, body, signal, true); }
|
|
28640
|
+
var e = PlanError(err.message || ('HTTP ' + r.status), {
|
|
28641
|
+
status: r.status, code: err.code || null, details: err.details || null, reason: err.reason || (json && json.reason) || null, path: path,
|
|
28642
|
+
});
|
|
28643
|
+
e.via = r.via;
|
|
28644
|
+
throw e;
|
|
28645
|
+
}
|
|
28646
|
+
return { status: r.status, body: r.json, data: r.json && r.json.data, matrix: r.matrix, path: r.via };
|
|
28505
28647
|
});
|
|
28506
28648
|
}
|
|
28507
|
-
return { send: send, kind: creds.kind, baseUrl: base };
|
|
28649
|
+
return { send: send, kind: creds.kind, baseUrl: base, smapUrl: smap };
|
|
28508
28650
|
}
|
|
28509
28651
|
|
|
28510
28652
|
// ------------------------------------------------------------------ plans
|
|
@@ -28657,7 +28799,12 @@ function smapCreatePlan() {
|
|
|
28657
28799
|
* @param {Object} options
|
|
28658
28800
|
* @param {Object} options.credentials { token: () => Promise<string | TokenAnswer> } or { key: string }
|
|
28659
28801
|
* @param {string|Object} [options.app] a native app's identity: 'android:<package>' / 'apple:<bundle id>' / 'windows:<id>', or { id, cert }
|
|
28660
|
-
* @param {string} [options.baseUrl] the Open Platform (default https://open.superroute.ca)
|
|
28802
|
+
* @param {string} [options.baseUrl] the Open Platform (default https://open.superroute.ca): the standard path
|
|
28803
|
+
* @param {string} [options.smapUrl] the sMap service a map key's configuration is read from (default
|
|
28804
|
+
* https://tile.srsr.ca; map.planEditor passes the map's own sMap address)
|
|
28805
|
+
* @param {boolean} [options.fastPath=true] use the fast path when the credential names one (false: standard only)
|
|
28806
|
+
* @param {number} [options.fastPathTimeout=2000] ms a fast-path call may take before it is repeated on the standard path
|
|
28807
|
+
* @param {number} [options.fastPathRefineTimeout=5000] the same for refine (its search takes longer)
|
|
28661
28808
|
* @param {Function} [options.fetch] fetch to use (default the page's)
|
|
28662
28809
|
* @param {Object} [options.plan] the starting plan: { vehicles, jobs, routes, region?, profile?, departed_at? }
|
|
28663
28810
|
* @param {string} [options.region] used when the plan names none
|
|
@@ -28693,6 +28840,7 @@ function smapCreatePlan() {
|
|
|
28693
28840
|
this._opening = null;
|
|
28694
28841
|
this._openingKey = null;
|
|
28695
28842
|
this._matrixRetryAt = 0;
|
|
28843
|
+
this._path = null;
|
|
28696
28844
|
this._destroyed = false;
|
|
28697
28845
|
if (options.plan) { this.setPlan(options.plan).catch(function () {}); }
|
|
28698
28846
|
}
|
|
@@ -28761,7 +28909,7 @@ function smapCreatePlan() {
|
|
|
28761
28909
|
return {
|
|
28762
28910
|
plan: this.getPlan(), result: this.getResult(), busy: this._busy, error: this._error, canUndo: this.canUndo(),
|
|
28763
28911
|
canRedo: this.canRedo(), choices: clone(this._choices), locked: this.locked(), last: clone(this._last),
|
|
28764
|
-
preview: this._previewResult ? clone(this._previewResult) : null,
|
|
28912
|
+
preview: this._previewResult ? clone(this._previewResult) : null, path: this._path,
|
|
28765
28913
|
};
|
|
28766
28914
|
};
|
|
28767
28915
|
|
|
@@ -28971,7 +29119,7 @@ function smapCreatePlan() {
|
|
|
28971
29119
|
var e = this._history[this._at] || {};
|
|
28972
29120
|
this._emit('change', {
|
|
28973
29121
|
kind: kind, plan: this.getPlan(), result: this.getResult(), answer: this._last ? clone(this._last.answer) : null,
|
|
28974
|
-
pending: !e.result, canUndo: this.canUndo(), canRedo: this.canRedo(),
|
|
29122
|
+
pending: !e.result, canUndo: this.canUndo(), canRedo: this.canRedo(), path: this._path,
|
|
28975
29123
|
});
|
|
28976
29124
|
};
|
|
28977
29125
|
|
|
@@ -29071,7 +29219,7 @@ function smapCreatePlan() {
|
|
|
29071
29219
|
self._error = null;
|
|
29072
29220
|
self._setBusy(false);
|
|
29073
29221
|
if (self._history[self._at] === target || kind !== 'recost') { self._changed(kind); }
|
|
29074
|
-
return { kind: kind, plan: self.getPlan(), result: self.getResult(), answer: clone(answer) };
|
|
29222
|
+
return { kind: kind, plan: self.getPlan(), result: self.getResult(), answer: clone(answer), path: self._path };
|
|
29075
29223
|
}, function (err) {
|
|
29076
29224
|
var current = self._inflight === ticket;
|
|
29077
29225
|
if (current) { self._inflight = null; self._setBusy(false); }
|
|
@@ -29102,6 +29250,7 @@ function smapCreatePlan() {
|
|
|
29102
29250
|
if (matrix) { body.matrix = matrix; } else { delete body.matrix; }
|
|
29103
29251
|
return self._transport.send('POST', path, body, signal);
|
|
29104
29252
|
}).then(function (res) {
|
|
29253
|
+
if (!self._destroyed) { self._path = res.path || null; }
|
|
29105
29254
|
if (body.matrix) { self._snapshotSeen(res.matrix, body.matrix); }
|
|
29106
29255
|
return res;
|
|
29107
29256
|
}, function (err) {
|
|
@@ -29153,7 +29302,7 @@ function smapCreatePlan() {
|
|
|
29153
29302
|
}
|
|
29154
29303
|
self._matrixRetryAt = 0;
|
|
29155
29304
|
if (self._openingKey === key) { self._matrix = id; self._matrixKey = key; }
|
|
29156
|
-
self._emit('snapshot', { status: 'opened', matrix: id, expires_at: res.data.expires_at || null, node: res.data.node || null });
|
|
29305
|
+
self._emit('snapshot', { status: 'opened', matrix: id, expires_at: res.data.expires_at || null, node: res.data.node || null, path: res.path || null });
|
|
29157
29306
|
return id;
|
|
29158
29307
|
}, function (err) {
|
|
29159
29308
|
self._matrixRetryAt = Date.now() + SNAPSHOT_RETRY_MS;
|
|
@@ -29889,7 +30038,7 @@ function smapCreatePlan() {
|
|
|
29889
30038
|
*/
|
|
29890
30039
|
function attach(map, options) {
|
|
29891
30040
|
options = options || {};
|
|
29892
|
-
var editor = new PlanEditor(Object.assign({}, options, { plan: null }));
|
|
30041
|
+
var editor = new PlanEditor(Object.assign({}, options, { plan: null, smapUrl: options.smapUrl || map._base }));
|
|
29893
30042
|
var layer = attachToMap(map, editor, options);
|
|
29894
30043
|
var toolId = null;
|
|
29895
30044
|
var destroyed = false;
|
|
@@ -29975,7 +30124,7 @@ function smapCreateSdk(engine, interop, plan) {
|
|
|
29975
30124
|
})(typeof self !== 'undefined' ? self : this, function (engine, interop, plan) {
|
|
29976
30125
|
'use strict';
|
|
29977
30126
|
|
|
29978
|
-
var VERSION = '1.1.
|
|
30127
|
+
var VERSION = '1.1.7';
|
|
29979
30128
|
var FLAVORS = ['light', 'white', 'grayscale', 'dark', 'black'];
|
|
29980
30129
|
var BASEMAP_SOURCE = 'basemap';
|
|
29981
30130
|
var BUILDINGS_LAYER = 'smap-buildings-3d';
|
|
@@ -32293,7 +32442,7 @@ function SMapMap(options) {
|
|
|
32293
32442
|
SMapMap.prototype = core.Map.prototype;
|
|
32294
32443
|
return new core.Map(options);
|
|
32295
32444
|
}
|
|
32296
|
-
var smapVersion = "1.1.
|
|
32445
|
+
var smapVersion = "1.1.7";
|
|
32297
32446
|
var smapStyles = ['light', 'white', 'grayscale', 'dark', 'black'];
|
|
32298
32447
|
/** The bundled rendering engine, for anything the SDK does not wrap (loaded on the first call). */
|
|
32299
32448
|
function smapGetEngine() { return smapLoad().engine; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superrouteca/smap",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "sMap for the web: maps from Superroute's sMap service, the Web SDK (map view) and the JS client (tokens, nearest node, styles, tiles).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Goodneo Solutions",
|
package/types/smap.d.cts
CHANGED
|
@@ -640,7 +640,11 @@ export interface PlanTokenAnswer {
|
|
|
640
640
|
expires_at?: string;
|
|
641
641
|
scopes?: string[];
|
|
642
642
|
origins?: string[] | null;
|
|
643
|
+
/** Present when the client's plan calls take the fast path (OPEN-ROUTE-EDIT E19): the editor sends its calls there. */
|
|
644
|
+
fast_path?: { url: string };
|
|
643
645
|
}
|
|
646
|
+
/** Where a plan call was answered: the fast path through sMap, or the Open Platform's standard path. */
|
|
647
|
+
export type PlanPath = 'fast' | 'standard';
|
|
644
648
|
/**
|
|
645
649
|
* How plan calls are authorised, always as `Authorization: Bearer …`: a short-lived plan editor token from your own
|
|
646
650
|
* server (asked again 30 s before its `expires_at` and once after a 401 `SESSION_EXPIRED`), or a map key (`smk_…`)
|
|
@@ -750,6 +754,8 @@ export interface PlanChangeEvent {
|
|
|
750
754
|
pending: boolean;
|
|
751
755
|
canUndo: boolean;
|
|
752
756
|
canRedo: boolean;
|
|
757
|
+
/** Where the last answered call was answered (null before the first answer). */
|
|
758
|
+
path?: PlanPath | null;
|
|
753
759
|
}
|
|
754
760
|
export interface PlanEditorError extends Error {
|
|
755
761
|
status: number;
|
|
@@ -758,6 +764,8 @@ export interface PlanEditorError extends Error {
|
|
|
758
764
|
details: unknown;
|
|
759
765
|
/** Why, where the service says (`expired`, `key_revoked`, `entitlements_changed`, `origin_not_allowed`, `plan_editing_off`, …). */
|
|
760
766
|
reason: string | null;
|
|
767
|
+
/** Where the refusal came from, when it was an answer. */
|
|
768
|
+
via?: PlanPath;
|
|
761
769
|
}
|
|
762
770
|
export interface PlanSnapshotEvent {
|
|
763
771
|
/** `opened`, `failed` (calls go on without one), or the X-Plan-Matrix of an answer: `used`, `expired`, `unavailable`, `mismatch`. */
|
|
@@ -766,10 +774,12 @@ export interface PlanSnapshotEvent {
|
|
|
766
774
|
expires_at?: string | null;
|
|
767
775
|
node?: string | null;
|
|
768
776
|
error?: unknown;
|
|
777
|
+
/** With `opened`: the path that opened it (the id is the same on both paths). */
|
|
778
|
+
path?: PlanPath | null;
|
|
769
779
|
}
|
|
770
780
|
export interface PlanPreview { routes: PlanRoute[]; result: PlanResult }
|
|
771
781
|
/** An edit's outcome; null when a newer edit cancelled it. */
|
|
772
|
-
export interface PlanEditOutcome { kind: string; plan: PlanState; result: PlanResult; answer: unknown }
|
|
782
|
+
export interface PlanEditOutcome { kind: string; plan: PlanState; result: PlanResult; answer: unknown; path?: PlanPath | null }
|
|
773
783
|
export interface PlanEditorState {
|
|
774
784
|
plan: PlanState | null;
|
|
775
785
|
result: PlanResult | null;
|
|
@@ -781,6 +791,8 @@ export interface PlanEditorState {
|
|
|
781
791
|
locked: string[];
|
|
782
792
|
last: { kind: string; answer: unknown } | null;
|
|
783
793
|
preview: PlanPreview | null;
|
|
794
|
+
/** Where the last answered call was answered (null before the first answer). */
|
|
795
|
+
path?: PlanPath | null;
|
|
784
796
|
}
|
|
785
797
|
|
|
786
798
|
export interface PlanEditorOptions {
|
|
@@ -792,6 +804,17 @@ export interface PlanEditorOptions {
|
|
|
792
804
|
app?: string | { id: string; cert?: string };
|
|
793
805
|
/** The Open Platform, `https://open.superroute.ca` by default. */
|
|
794
806
|
baseUrl?: string;
|
|
807
|
+
/**
|
|
808
|
+
* The sMap service a map key's configuration is read from (`GET <smapUrl>/plan/v1/config`), `https://tile.srsr.ca`
|
|
809
|
+
* by default; `map.planEditor` passes the map's own sMap address.
|
|
810
|
+
*/
|
|
811
|
+
smapUrl?: string;
|
|
812
|
+
/** Take the fast path when the credential names one (default true; false: the standard path only). */
|
|
813
|
+
fastPath?: boolean;
|
|
814
|
+
/** Milliseconds a fast-path call (every call but refine) may take before it is repeated on the standard path (default 2000). */
|
|
815
|
+
fastPathTimeout?: number;
|
|
816
|
+
/** The same for refine, whose search takes longer (default 5000). */
|
|
817
|
+
fastPathRefineTimeout?: number;
|
|
795
818
|
/** The fetch to use (the page's by default). */
|
|
796
819
|
fetch?: typeof fetch;
|
|
797
820
|
/** The starting plan. */
|
package/types/smap.d.mts
CHANGED
|
@@ -640,7 +640,11 @@ export interface PlanTokenAnswer {
|
|
|
640
640
|
expires_at?: string;
|
|
641
641
|
scopes?: string[];
|
|
642
642
|
origins?: string[] | null;
|
|
643
|
+
/** Present when the client's plan calls take the fast path (OPEN-ROUTE-EDIT E19): the editor sends its calls there. */
|
|
644
|
+
fast_path?: { url: string };
|
|
643
645
|
}
|
|
646
|
+
/** Where a plan call was answered: the fast path through sMap, or the Open Platform's standard path. */
|
|
647
|
+
export type PlanPath = 'fast' | 'standard';
|
|
644
648
|
/**
|
|
645
649
|
* How plan calls are authorised, always as `Authorization: Bearer …`: a short-lived plan editor token from your own
|
|
646
650
|
* server (asked again 30 s before its `expires_at` and once after a 401 `SESSION_EXPIRED`), or a map key (`smk_…`)
|
|
@@ -750,6 +754,8 @@ export interface PlanChangeEvent {
|
|
|
750
754
|
pending: boolean;
|
|
751
755
|
canUndo: boolean;
|
|
752
756
|
canRedo: boolean;
|
|
757
|
+
/** Where the last answered call was answered (null before the first answer). */
|
|
758
|
+
path?: PlanPath | null;
|
|
753
759
|
}
|
|
754
760
|
export interface PlanEditorError extends Error {
|
|
755
761
|
status: number;
|
|
@@ -758,6 +764,8 @@ export interface PlanEditorError extends Error {
|
|
|
758
764
|
details: unknown;
|
|
759
765
|
/** Why, where the service says (`expired`, `key_revoked`, `entitlements_changed`, `origin_not_allowed`, `plan_editing_off`, …). */
|
|
760
766
|
reason: string | null;
|
|
767
|
+
/** Where the refusal came from, when it was an answer. */
|
|
768
|
+
via?: PlanPath;
|
|
761
769
|
}
|
|
762
770
|
export interface PlanSnapshotEvent {
|
|
763
771
|
/** `opened`, `failed` (calls go on without one), or the X-Plan-Matrix of an answer: `used`, `expired`, `unavailable`, `mismatch`. */
|
|
@@ -766,10 +774,12 @@ export interface PlanSnapshotEvent {
|
|
|
766
774
|
expires_at?: string | null;
|
|
767
775
|
node?: string | null;
|
|
768
776
|
error?: unknown;
|
|
777
|
+
/** With `opened`: the path that opened it (the id is the same on both paths). */
|
|
778
|
+
path?: PlanPath | null;
|
|
769
779
|
}
|
|
770
780
|
export interface PlanPreview { routes: PlanRoute[]; result: PlanResult }
|
|
771
781
|
/** An edit's outcome; null when a newer edit cancelled it. */
|
|
772
|
-
export interface PlanEditOutcome { kind: string; plan: PlanState; result: PlanResult; answer: unknown }
|
|
782
|
+
export interface PlanEditOutcome { kind: string; plan: PlanState; result: PlanResult; answer: unknown; path?: PlanPath | null }
|
|
773
783
|
export interface PlanEditorState {
|
|
774
784
|
plan: PlanState | null;
|
|
775
785
|
result: PlanResult | null;
|
|
@@ -781,6 +791,8 @@ export interface PlanEditorState {
|
|
|
781
791
|
locked: string[];
|
|
782
792
|
last: { kind: string; answer: unknown } | null;
|
|
783
793
|
preview: PlanPreview | null;
|
|
794
|
+
/** Where the last answered call was answered (null before the first answer). */
|
|
795
|
+
path?: PlanPath | null;
|
|
784
796
|
}
|
|
785
797
|
|
|
786
798
|
export interface PlanEditorOptions {
|
|
@@ -792,6 +804,17 @@ export interface PlanEditorOptions {
|
|
|
792
804
|
app?: string | { id: string; cert?: string };
|
|
793
805
|
/** The Open Platform, `https://open.superroute.ca` by default. */
|
|
794
806
|
baseUrl?: string;
|
|
807
|
+
/**
|
|
808
|
+
* The sMap service a map key's configuration is read from (`GET <smapUrl>/plan/v1/config`), `https://tile.srsr.ca`
|
|
809
|
+
* by default; `map.planEditor` passes the map's own sMap address.
|
|
810
|
+
*/
|
|
811
|
+
smapUrl?: string;
|
|
812
|
+
/** Take the fast path when the credential names one (default true; false: the standard path only). */
|
|
813
|
+
fastPath?: boolean;
|
|
814
|
+
/** Milliseconds a fast-path call (every call but refine) may take before it is repeated on the standard path (default 2000). */
|
|
815
|
+
fastPathTimeout?: number;
|
|
816
|
+
/** The same for refine, whose search takes longer (default 5000). */
|
|
817
|
+
fastPathRefineTimeout?: number;
|
|
795
818
|
/** The fetch to use (the page's by default). */
|
|
796
819
|
fetch?: typeof fetch;
|
|
797
820
|
/** The starting plan. */
|