@loaders.gl/services 5.0.0-alpha.10

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/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ loaders.gl is licensed under the MIT license
2
+
3
+ Copyright (c) vis.gl contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ ---
24
+
25
+ Copyright (c) 2015 Uber Technologies, Inc.
26
+
27
+ Portions of modules/images/src/lib/category-api/binary-image-api.ts are based on
28
+ binary-gltf-utils (https://github.com/Qantas94Heavy/binary-gltf-utils) under the
29
+ MIT License reproduced above.
30
+
31
+ Copyright (c) 2016-17 Karl Cheng
32
+
33
+ Portions of modules/schema-utils/src/lib/utils/async-queue.ts are adapted from
34
+ async-iter-demo (https://github.com/rauschma/async-iter-demo) under the MIT
35
+ License reproduced above.
36
+
37
+ Copyright (c) 2016 Axel Rauschmayer
38
+
39
+ loaders.gl includes certain files from Cesium (https://github.com/CesiumGS/cesium)
40
+ under the Apache 2.0 License, including files in modules/3d-tiles.
41
+
42
+ Copyright 2011-2018 CesiumJS Contributors
43
+
44
+ Licensed under the Apache License, Version 2.0 (the "License");
45
+ you may not use this file except in compliance with the License.
46
+ You may obtain a copy of the License at
47
+ http://www.apache.org/licenses/LICENSE-2.0
48
+
49
+ Unless required by applicable law or agreed to in writing, software
50
+ distributed under the License is distributed on an "AS IS" BASIS,
51
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
+ See the License for the specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @loaders.gl/services
2
+
3
+ Authentication presets for Mapbox, Google Maps and Cesium ion.
4
+
5
+ Use `MapboxAuthentication`, `GoogleMapsAuthentication`, `CesiumIonAuthentication`, or their
6
+ `create*Credential` helpers with the shared loaders.gl credential pipeline. Sign-in and token
7
+ issuance remain application responsibilities.
8
+
9
+ ArcGIS sources and credentials live in [@loaders.gl/arcgis](https://loaders.gl/docs/modules/arcgis).
10
+ OGC protocol sources live in [@loaders.gl/wms](https://loaders.gl/docs/modules/wms).
11
+
12
+ See the [authentication guide](https://loaders.gl/docs/developer-guide/authentication).
@@ -0,0 +1,62 @@
1
+ import type { FetchLike, RequestCredential, TokenValue } from '@loaders.gl/loader-utils';
2
+ import { TokenAuthentication } from '@loaders.gl/loader-utils';
3
+ /** Declarative Mapbox access-token authentication. */
4
+ export declare class MapboxAuthentication extends TokenAuthentication {
5
+ /** Discriminator used in `core.credentials`. */
6
+ static readonly type = "mapbox";
7
+ /** Creates a Mapbox credential with the existing provider defaults. */
8
+ constructor(options: MapboxCredentialOptions);
9
+ }
10
+ /** Declarative Google Maps API-key authentication. */
11
+ export declare class GoogleMapsAuthentication extends TokenAuthentication {
12
+ /** Discriminator used in `core.credentials`. */
13
+ static readonly type = "google-maps";
14
+ /** Creates a Google Maps credential with the existing provider defaults. */
15
+ constructor(options: GoogleMapsCredentialOptions);
16
+ }
17
+ /** Declarative Cesium ion authentication, including lazy asset-token exchange. */
18
+ export declare class CesiumIonAuthentication extends TokenAuthentication {
19
+ /** Discriminator used in `core.credentials`. */
20
+ static readonly type = "cesium-ion";
21
+ /** Creates an ion credential with the existing provider lifecycle. */
22
+ constructor(options: CesiumIonCredentialOptions);
23
+ }
24
+ /** Shared options for provider credential presets with known public API origins. */
25
+ export type ServiceCredentialOptions = {
26
+ /** Replaces the provider's default exact-origin allowlist. */
27
+ origins?: readonly string[];
28
+ };
29
+ /** Options for a Mapbox API credential. */
30
+ export type MapboxCredentialOptions = ServiceCredentialOptions & {
31
+ /** Mapbox public access token or application-managed token callback. */
32
+ accessToken: TokenValue;
33
+ };
34
+ /** Options for a Google Maps Platform credential. */
35
+ export type GoogleMapsCredentialOptions = ServiceCredentialOptions & {
36
+ /** Google Maps Platform API key or application-managed key callback. */
37
+ apiKey: TokenValue;
38
+ };
39
+ /** Options for a Cesium ion API credential. */
40
+ export type CesiumIonCredentialOptions = ServiceCredentialOptions & {
41
+ /** Cesium ion access token or application-managed token callback. */
42
+ accessToken: TokenValue;
43
+ /** Optional asset whose endpoint-scoped token should be resolved. */
44
+ assetId?: number | string;
45
+ /** Overrides the transport used for the ion endpoint-token exchange. */
46
+ fetch?: FetchLike;
47
+ /** Whether the supplied token is account-scoped or already asset-scoped. */
48
+ tokenType?: 'account' | 'asset' | 'auto';
49
+ };
50
+ /** Creates a Mapbox `access_token` query credential. */
51
+ export declare function createMapboxCredential(options: MapboxCredentialOptions): RequestCredential;
52
+ /** Creates a Google Maps Platform `key` query credential. */
53
+ export declare function createGoogleMapsCredential(options: GoogleMapsCredentialOptions): RequestCredential;
54
+ /**
55
+ * Creates a bearer credential for the Cesium ion REST API or one Cesium ion asset.
56
+ *
57
+ * Supplying `assetId` creates an asset-origin credential. Account tokens are exchanged lazily
58
+ * through Cesium ion's endpoint API; legacy asset-scoped tokens are used directly. Without an
59
+ * `assetId`, the credential is scoped only to the ion REST API for backwards compatibility.
60
+ */
61
+ export declare function createCesiumIonCredential(options: CesiumIonCredentialOptions): RequestCredential;
62
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EAEjB,UAAU,EACX,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,mBAAmB,EAGpB,MAAM,0BAA0B,CAAC;AAIlC,sDAAsD;AACtD,qBAAa,oBAAqB,SAAQ,mBAAmB;IAC3D,gDAAgD;IAChD,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAY;IAChC,uEAAuE;gBAC3D,OAAO,EAAE,uBAAuB;CAG7C;AAED,sDAAsD;AACtD,qBAAa,wBAAyB,SAAQ,mBAAmB;IAC/D,gDAAgD;IAChD,MAAM,CAAC,QAAQ,CAAC,IAAI,iBAAiB;IACrC,4EAA4E;gBAChE,OAAO,EAAE,2BAA2B;CAGjD;AAED,kFAAkF;AAClF,qBAAa,uBAAwB,SAAQ,mBAAmB;IAC9D,gDAAgD;IAChD,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB;IACpC,sEAAsE;gBAC1D,OAAO,EAAE,0BAA0B;CAGhD;AAMD,oFAAoF;AACpF,MAAM,MAAM,wBAAwB,GAAG;IACrC,8DAA8D;IAC9D,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF,2CAA2C;AAC3C,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG;IAC/D,wEAAwE;IACxE,WAAW,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,GAAG;IACnE,wEAAwE;IACxE,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,0BAA0B,GAAG,wBAAwB,GAAG;IAClE,qEAAqE;IACrE,WAAW,EAAE,UAAU,CAAC;IACxB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,wEAAwE;IACxE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;CAC1C,CAAC;AAEF,wDAAwD;AACxD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,iBAAiB,CAO1F;AAED,6DAA6D;AAC7D,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,iBAAiB,CAOnB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,iBAAiB,CAwBhG"}
@@ -0,0 +1,136 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { createAuthenticatedFetch, TokenAuthentication, createBearerTokenCredential, createQueryParameterCredential } from '@loaders.gl/loader-utils';
5
+ const CESIUM_ION_API_ORIGIN = 'https://api.cesium.com';
6
+ /** Declarative Mapbox access-token authentication. */
7
+ export class MapboxAuthentication extends TokenAuthentication {
8
+ /** Discriminator used in `core.credentials`. */
9
+ static type = 'mapbox';
10
+ /** Creates a Mapbox credential with the existing provider defaults. */
11
+ constructor(options) {
12
+ super(createMapboxCredential(options));
13
+ }
14
+ }
15
+ /** Declarative Google Maps API-key authentication. */
16
+ export class GoogleMapsAuthentication extends TokenAuthentication {
17
+ /** Discriminator used in `core.credentials`. */
18
+ static type = 'google-maps';
19
+ /** Creates a Google Maps credential with the existing provider defaults. */
20
+ constructor(options) {
21
+ super(createGoogleMapsCredential(options));
22
+ }
23
+ }
24
+ /** Declarative Cesium ion authentication, including lazy asset-token exchange. */
25
+ export class CesiumIonAuthentication extends TokenAuthentication {
26
+ /** Discriminator used in `core.credentials`. */
27
+ static type = 'cesium-ion';
28
+ /** Creates an ion credential with the existing provider lifecycle. */
29
+ constructor(options) {
30
+ super(createCesiumIonCredential(options));
31
+ }
32
+ }
33
+ const CESIUM_ION_ASSET_ORIGINS = [
34
+ 'https://assets.ion.cesium.com',
35
+ 'https://assets.cesium.com'
36
+ ];
37
+ /** Creates a Mapbox `access_token` query credential. */
38
+ export function createMapboxCredential(options) {
39
+ return createQueryParameterCredential({
40
+ id: 'mapbox-access-token',
41
+ origins: options.origins || ['https://api.mapbox.com'],
42
+ parameterName: 'access_token',
43
+ token: options.accessToken
44
+ });
45
+ }
46
+ /** Creates a Google Maps Platform `key` query credential. */
47
+ export function createGoogleMapsCredential(options) {
48
+ return createQueryParameterCredential({
49
+ id: 'google-maps-api-key',
50
+ origins: options.origins || ['https://tile.googleapis.com'],
51
+ parameterName: 'key',
52
+ token: options.apiKey
53
+ });
54
+ }
55
+ /**
56
+ * Creates a bearer credential for the Cesium ion REST API or one Cesium ion asset.
57
+ *
58
+ * Supplying `assetId` creates an asset-origin credential. Account tokens are exchanged lazily
59
+ * through Cesium ion's endpoint API; legacy asset-scoped tokens are used directly. Without an
60
+ * `assetId`, the credential is scoped only to the ion REST API for backwards compatibility.
61
+ */
62
+ export function createCesiumIonCredential(options) {
63
+ if (options.assetId === undefined || options.assetId === null) {
64
+ return createBearerTokenCredential({
65
+ id: 'cesium-ion-access-token',
66
+ origins: options.origins || [CESIUM_ION_API_ORIGIN],
67
+ token: options.accessToken
68
+ });
69
+ }
70
+ const assetId = options.assetId;
71
+ const origins = options.origins || CESIUM_ION_ASSET_ORIGINS;
72
+ let endpointTokenPromise = null;
73
+ return createBearerTokenCredential({
74
+ id: `cesium-ion-asset-${assetId}`,
75
+ origins,
76
+ token: context => {
77
+ if (context.reason === 'refresh') {
78
+ endpointTokenPromise = null;
79
+ }
80
+ endpointTokenPromise ||= resolveCesiumIonAssetToken(options, assetId, origins, context);
81
+ return endpointTokenPromise;
82
+ }
83
+ });
84
+ }
85
+ /** Resolves an account token and exchanges it for an asset endpoint token when required. */
86
+ async function resolveCesiumIonAssetToken(options, assetId, origins, context) {
87
+ const endpointURL = `${CESIUM_ION_API_ORIGIN}/v1/assets/${assetId}/endpoint`;
88
+ const accessToken = typeof options.accessToken === 'function'
89
+ ? await options.accessToken({ ...context, url: endpointURL })
90
+ : options.accessToken;
91
+ if (!accessToken)
92
+ return null;
93
+ const tokenType = options.tokenType || 'auto';
94
+ if (tokenType === 'asset' ||
95
+ (tokenType === 'auto' && isCesiumIonAssetToken(accessToken, assetId))) {
96
+ return accessToken;
97
+ }
98
+ const apiCredential = createBearerTokenCredential({
99
+ id: `cesium-ion-api-${assetId}`,
100
+ origins: [CESIUM_ION_API_ORIGIN],
101
+ token: accessToken
102
+ });
103
+ const ionFetch = createAuthenticatedFetch({
104
+ fetch: options.fetch,
105
+ credentials: [apiCredential]
106
+ });
107
+ const response = await ionFetch(endpointURL);
108
+ if (!response.ok) {
109
+ throw new Error(`Cesium ion asset ${assetId} endpoint request failed: ${response.status}`);
110
+ }
111
+ const endpoint = (await response.json());
112
+ if (typeof endpoint.url !== 'string' || !origins.includes(new URL(endpoint.url).origin)) {
113
+ throw new Error(`Cesium ion asset ${assetId} resolved to an unconfigured origin.`);
114
+ }
115
+ if (typeof endpoint.accessToken !== 'string' || !endpoint.accessToken) {
116
+ throw new Error(`Cesium ion did not return an endpoint token for asset ${assetId}.`);
117
+ }
118
+ return endpoint.accessToken;
119
+ }
120
+ /** Detects legacy JWTs whose claims scope them directly to the requested asset. */
121
+ function isCesiumIonAssetToken(token, assetId) {
122
+ try {
123
+ const encodedClaims = token.split('.')[1];
124
+ if (!encodedClaims)
125
+ return false;
126
+ const base64 = encodedClaims.replace(/-/g, '+').replace(/_/g, '/');
127
+ const paddedBase64 = base64.padEnd(Math.ceil(base64.length / 4) * 4, '=');
128
+ const claims = JSON.parse(atob(paddedBase64));
129
+ return (Array.isArray(claims.assets) &&
130
+ claims.assets.some(claimAssetId => String(claimAssetId) === String(assetId)));
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ }
136
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAQpC,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,2BAA2B,EAC3B,8BAA8B,EAC/B,MAAM,0BAA0B,CAAC;AAElC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAEvD,sDAAsD;AACtD,MAAM,OAAO,oBAAqB,SAAQ,mBAAmB;IAC3D,gDAAgD;IAChD,MAAM,CAAU,IAAI,GAAG,QAAQ,CAAC;IAChC,uEAAuE;IACvE,YAAY,OAAgC;QAC1C,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,CAAC;;AAGH,sDAAsD;AACtD,MAAM,OAAO,wBAAyB,SAAQ,mBAAmB;IAC/D,gDAAgD;IAChD,MAAM,CAAU,IAAI,GAAG,aAAa,CAAC;IACrC,4EAA4E;IAC5E,YAAY,OAAoC;QAC9C,KAAK,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC;;AAGH,kFAAkF;AAClF,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAC9D,gDAAgD;IAChD,MAAM,CAAU,IAAI,GAAG,YAAY,CAAC;IACpC,sEAAsE;IACtE,YAAY,OAAmC;QAC7C,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,CAAC;;AAEH,MAAM,wBAAwB,GAAG;IAC/B,+BAA+B;IAC/B,2BAA2B;CACnB,CAAC;AAgCX,wDAAwD;AACxD,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,OAAO,8BAA8B,CAAC;QACpC,EAAE,EAAE,qBAAqB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,wBAAwB,CAAC;QACtD,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CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./index.js";
2
+ //# sourceMappingURL=bundled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled.d.ts","sourceRoot":"","sources":["../src/bundled.ts"],"names":[],"mappings":"AAKA,2BAAwB"}
@@ -0,0 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // ArcGIS sources have no parser-only implementation to defer.
5
+ export * from "./index.js";
6
+ //# sourceMappingURL=bundled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled.js","sourceRoot":"","sources":["../src/bundled.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,8DAA8D;AAC9D,2BAAwB"}
package/dist/index.cjs ADDED
@@ -0,0 +1,454 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // dist/index.js
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CesiumIonAuthentication: () => CesiumIonAuthentication,
24
+ GoogleMapsAuthentication: () => GoogleMapsAuthentication,
25
+ MapboxAuthentication: () => MapboxAuthentication,
26
+ createCesiumIonCredential: () => createCesiumIonCredential,
27
+ createGoogleMapsCredential: () => createGoogleMapsCredential,
28
+ createMapboxCredential: () => createMapboxCredential
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+
32
+ // ../loader-utils/src/lib/request-utils/authentication.ts
33
+ function resolveCredentials(credentials, authentications = []) {
34
+ if (credentials.every(isAuthentication)) return credentials;
35
+ return credentials.map((credential, index) => {
36
+ if (isAuthentication(credential)) return credential;
37
+ const AuthenticationClass = authentications.find(
38
+ (authentication2) => authentication2.type === (credential == null ? void 0 : credential.type)
39
+ );
40
+ if (!AuthenticationClass) {
41
+ throw new Error(`No authentication class registered for credential at index ${index}.`);
42
+ }
43
+ let authentication;
44
+ try {
45
+ authentication = new AuthenticationClass(credential);
46
+ } catch {
47
+ throw new Error(`Invalid authentication configuration at index ${index}.`);
48
+ }
49
+ if (!isAuthentication(authentication)) {
50
+ throw new Error(`Authentication class returned an invalid credential at index ${index}.`);
51
+ }
52
+ return authentication;
53
+ });
54
+ }
55
+ function isAuthentication(credential) {
56
+ if (!credential || typeof credential !== "object") return false;
57
+ if (typeof credential.id !== "string" || !Array.isArray(credential.origins)) return false;
58
+ if (credential.type === "request") return typeof credential.authenticate === "function";
59
+ return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
60
+ }
61
+
62
+ // ../loader-utils/src/lib/request-utils/request-credentials.ts
63
+ var DEFAULT_REFRESH_STATUS_CODES = [401, 403];
64
+ var AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
65
+ var refreshPromises = /* @__PURE__ */ new WeakMap();
66
+ function createQueryParameterCredential(options) {
67
+ return {
68
+ id: options.id,
69
+ origins: normalizeOrigins(options.origins),
70
+ type: "query-parameter",
71
+ name: options.parameterName,
72
+ token: options.token,
73
+ refreshStatusCodes: options.refreshStatusCodes || DEFAULT_REFRESH_STATUS_CODES
74
+ };
75
+ }
76
+ function createBearerTokenCredential(options) {
77
+ return {
78
+ id: options.id,
79
+ origins: normalizeOrigins(options.origins),
80
+ type: "header",
81
+ name: options.headerName || "Authorization",
82
+ prefix: options.prefix ?? "Bearer ",
83
+ token: options.token,
84
+ refreshStatusCodes: options.refreshStatusCodes || DEFAULT_REFRESH_STATUS_CODES
85
+ };
86
+ }
87
+ var TokenAuthentication = class {
88
+ /** Stable identifier used in diagnostics. */
89
+ id;
90
+ /** Exact origins authorized to receive the token. */
91
+ origins;
92
+ /** Transport placement of the token. */
93
+ type;
94
+ /** Header or query parameter name. */
95
+ name;
96
+ /** Optional prefix for header values. */
97
+ prefix;
98
+ /** Static token or application-managed token provider. */
99
+ token;
100
+ /** Statuses that permit one refresh and replay. */
101
+ refreshStatusCodes;
102
+ /** Provider-specific response failure detection. */
103
+ shouldRefresh;
104
+ /** Provider-specific read-only request replay predicate. */
105
+ canReplayRequest;
106
+ /** Initializes the instance from an existing transport credential. */
107
+ constructor(credential) {
108
+ this.id = credential.id;
109
+ this.origins = credential.origins;
110
+ this.type = credential.type;
111
+ this.name = credential.name;
112
+ this.prefix = credential.prefix;
113
+ this.token = credential.token;
114
+ this.refreshStatusCodes = credential.refreshStatusCodes;
115
+ this.shouldRefresh = credential.shouldRefresh;
116
+ this.canReplayRequest = credential.canReplayRequest;
117
+ }
118
+ };
119
+ function createAuthenticatedFetch(options) {
120
+ const suppliedFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
121
+ const existingMetadata = suppliedFetch[AUTHENTICATED_FETCH];
122
+ const credentialResolutions = new Map(existingMetadata == null ? void 0 : existingMetadata.credentialResolutions);
123
+ const resolvedCredentials = resolveCredentials(
124
+ options.credentials.map((credential) => credentialResolutions.get(credential) || credential),
125
+ options.authentications
126
+ );
127
+ options.credentials.forEach((credential, index) => {
128
+ credentialResolutions.set(credential, resolvedCredentials[index]);
129
+ });
130
+ if (!options.fetchOptions && (!resolvedCredentials.length || (existingMetadata == null ? void 0 : existingMetadata.credentials.length) === resolvedCredentials.length && resolvedCredentials.every(
131
+ (credential, index) => credential === existingMetadata.credentials[index]
132
+ )))
133
+ return suppliedFetch;
134
+ const baseFetch = (existingMetadata == null ? void 0 : existingMetadata.fetch) || suppliedFetch;
135
+ const credentials = existingMetadata ? [.../* @__PURE__ */ new Set([...resolvedCredentials, ...existingMetadata.credentials])] : resolvedCredentials;
136
+ const fetchOptions = mergeFetchOptions(
137
+ (existingMetadata == null ? void 0 : existingMetadata.fetchOptions) || {},
138
+ options.fetchOptions
139
+ );
140
+ const tokenCredentials = credentials.filter(
141
+ (credential) => credential.type !== "request"
142
+ );
143
+ const requestCredentials = credentials.filter(
144
+ (credential) => credential.type === "request"
145
+ );
146
+ for (const credential of requestCredentials) normalizeRequestOrigins(credential.origins);
147
+ const authenticatedFetch = async (url, requestOptions = {}) => {
148
+ var _a, _b, _c, _d, _e, _f, _g;
149
+ requestOptions = mergeFetchOptions(fetchOptions, requestOptions);
150
+ if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError();
151
+ if (!credentials.length) return baseFetch(url, requestOptions);
152
+ const resolvedURL = parseHTTPURL(url);
153
+ const authorization = resolvedURL ? await authorizeRequest(resolvedURL, requestOptions, tokenCredentials) : { url, options: requestOptions, credentials: [] };
154
+ const signedRequest = await authenticateRequest(authorization, requestCredentials, "request");
155
+ const response = await baseFetch(signedRequest.url, signedRequest.options);
156
+ const refreshableCredentials = [];
157
+ for (const resolvedCredential of authorization.credentials) {
158
+ const { credential } = resolvedCredential;
159
+ if (typeof credential.token === "function" && (isReplayableRequest(requestOptions) || ((_b = credential.canReplayRequest) == null ? void 0 : _b.call(credential, url, requestOptions))) && (isReplayableRequest(signedRequest.options) || ((_c = credential.canReplayRequest) == null ? void 0 : _c.call(credential, signedRequest.url, signedRequest.options))) && (credential.refreshStatusCodes.includes(response.status) || await ((_d = credential.shouldRefresh) == null ? void 0 : _d.call(credential, response))))
160
+ refreshableCredentials.push(resolvedCredential);
161
+ }
162
+ const shouldRetrySignature = isReplayableRequest(requestOptions) && isReplayableRequest(signedRequest.options) && signedRequest.credentials.some(
163
+ (credential) => {
164
+ var _a2;
165
+ return (_a2 = credential.refreshStatusCodes) == null ? void 0 : _a2.includes(response.status);
166
+ }
167
+ );
168
+ if (!refreshableCredentials.length && !shouldRetrySignature) return response;
169
+ if ((_e = requestOptions.signal) == null ? void 0 : _e.aborted) throw createAbortError();
170
+ const refreshedTokens = /* @__PURE__ */ new Map();
171
+ await Promise.all(
172
+ refreshableCredentials.map(async ({ credential }) => {
173
+ const token = await refreshCredential(credential, url, response);
174
+ if (token) refreshedTokens.set(credential, token);
175
+ })
176
+ );
177
+ if (!refreshedTokens.size && !shouldRetrySignature) return response;
178
+ await ((_f = response.body) == null ? void 0 : _f.cancel().catch(() => {
179
+ }));
180
+ if ((_g = requestOptions.signal) == null ? void 0 : _g.aborted) throw createAbortError();
181
+ const replayAuthorization = resolvedURL ? await authorizeRequest(
182
+ resolvedURL,
183
+ requestOptions,
184
+ tokenCredentials,
185
+ refreshedTokens,
186
+ authorization.credentials
187
+ ) : { url, options: requestOptions };
188
+ const replayRequest = await authenticateRequest(
189
+ replayAuthorization,
190
+ requestCredentials,
191
+ "retry",
192
+ response
193
+ );
194
+ return baseFetch(replayRequest.url, replayRequest.options);
195
+ };
196
+ Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
197
+ value: {
198
+ fetch: baseFetch,
199
+ credentials,
200
+ credentialResolutions,
201
+ fetchOptions
202
+ }
203
+ });
204
+ return authenticatedFetch;
205
+ }
206
+ function mergeFetchOptions(defaultOptions, requestOptions) {
207
+ const mergedOptions = { ...defaultOptions, ...requestOptions };
208
+ if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
209
+ const headers = new Headers(defaultOptions.headers);
210
+ new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
211
+ mergedOptions.headers = headers;
212
+ }
213
+ return mergedOptions;
214
+ }
215
+ async function authenticateRequest(request, credentials, reason, response) {
216
+ const appliedCredentials = [];
217
+ const signal = request.options.signal;
218
+ for (const credential of credentials) {
219
+ const origin = getRequestOrigin(request.url);
220
+ if (!origin || !normalizeRequestOrigins(credential.origins).includes(origin)) continue;
221
+ if (signal == null ? void 0 : signal.aborted) throw createAbortError();
222
+ const authenticatedRequest = await credential.authenticate({
223
+ url: request.url,
224
+ options: { ...request.options, headers: new Headers(request.options.headers) },
225
+ reason,
226
+ response: response ? { status: response.status, headers: new Headers(response.headers) } : void 0
227
+ });
228
+ if (!authenticatedRequest || typeof authenticatedRequest.url !== "string" || !authenticatedRequest.options || typeof authenticatedRequest.options !== "object") {
229
+ throw new Error("Authentication callback returned an invalid request.");
230
+ }
231
+ request = {
232
+ url: authenticatedRequest.url,
233
+ options: { ...authenticatedRequest.options, ...signal ? { signal } : {} }
234
+ };
235
+ appliedCredentials.push(credential);
236
+ }
237
+ if (signal == null ? void 0 : signal.aborted) throw createAbortError();
238
+ return { ...request, credentials: appliedCredentials };
239
+ }
240
+ function getRequestOrigin(url) {
241
+ try {
242
+ const parsedURL = new URL(url);
243
+ if (!parsedURL.host || parsedURL.username || parsedURL.password) return null;
244
+ return parsedURL.origin !== "null" ? parsedURL.origin : `${parsedURL.protocol}//${parsedURL.host}`;
245
+ } catch {
246
+ return null;
247
+ }
248
+ }
249
+ function normalizeRequestOrigins(origins) {
250
+ if (!origins.length)
251
+ throw new Error("Request authentication requires at least one exact origin.");
252
+ return origins.map((origin) => {
253
+ const resolvedOrigin = getRequestOrigin(origin);
254
+ let url;
255
+ try {
256
+ url = new URL(origin);
257
+ } catch {
258
+ throw new Error("Invalid request authentication origin.");
259
+ }
260
+ if (!resolvedOrigin || url.pathname && url.pathname !== "/" || url.search || url.hash) {
261
+ throw new Error("Invalid request authentication origin.");
262
+ }
263
+ return resolvedOrigin;
264
+ });
265
+ }
266
+ async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
267
+ const url = new URL(sourceURL);
268
+ const headers = new Headers(requestOptions.headers);
269
+ const resolvedCredentials = [];
270
+ const previousTokens = new Map(
271
+ previousCredentials.map(({ credential, token }) => [credential, token])
272
+ );
273
+ for (const credential of credentials) {
274
+ if (!credential.origins.includes(url.origin)) continue;
275
+ const overrideToken = tokenOverrides.get(credential);
276
+ const previousToken = previousTokens.get(credential);
277
+ const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
278
+ const ownsHeader = credential.type === "header" && previousToken !== void 0;
279
+ if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
280
+ continue;
281
+ }
282
+ const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
283
+ if (!token) continue;
284
+ if (credential.type === "query-parameter") {
285
+ url.searchParams.set(credential.name, token);
286
+ } else {
287
+ headers.set(credential.name, `${credential.prefix || ""}${token}`);
288
+ }
289
+ resolvedCredentials.push({ credential, token });
290
+ }
291
+ return {
292
+ url: url.toString(),
293
+ options: { ...requestOptions, headers },
294
+ credentials: resolvedCredentials
295
+ };
296
+ }
297
+ async function refreshCredential(credential, url, response) {
298
+ const existingPromise = refreshPromises.get(credential);
299
+ if (existingPromise) return existingPromise;
300
+ const tokenProvider = credential.token;
301
+ const promise = Promise.resolve(
302
+ tokenProvider({
303
+ url,
304
+ reason: "refresh",
305
+ response: { status: response.status, headers: response.headers }
306
+ })
307
+ ).finally(() => refreshPromises.delete(credential));
308
+ refreshPromises.set(credential, promise);
309
+ return promise;
310
+ }
311
+ async function resolveToken(token, context) {
312
+ return typeof token === "function" ? token(context) : token;
313
+ }
314
+ function normalizeOrigins(origins) {
315
+ if (!origins.length) throw new Error("Request credentials require at least one exact origin.");
316
+ return origins.map((origin) => {
317
+ const url = new URL(origin);
318
+ if (!["http:", "https:"].includes(url.protocol) || url.pathname !== "/" || url.search || url.hash) {
319
+ throw new Error(`Credential origin must contain only scheme, host, and port: ${origin}`);
320
+ }
321
+ return url.origin;
322
+ });
323
+ }
324
+ function parseHTTPURL(url) {
325
+ try {
326
+ const parsedURL = new URL(url);
327
+ return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
328
+ } catch {
329
+ return null;
330
+ }
331
+ }
332
+ function isReplayableRequest(options) {
333
+ const method = (options.method || "GET").toUpperCase();
334
+ if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
335
+ return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
336
+ }
337
+ function createAbortError() {
338
+ return new DOMException("The operation was aborted.", "AbortError");
339
+ }
340
+
341
+ // dist/authentication.js
342
+ var CESIUM_ION_API_ORIGIN = "https://api.cesium.com";
343
+ var MapboxAuthentication = class extends TokenAuthentication {
344
+ /** Discriminator used in `core.credentials`. */
345
+ static type = "mapbox";
346
+ /** Creates a Mapbox credential with the existing provider defaults. */
347
+ constructor(options) {
348
+ super(createMapboxCredential(options));
349
+ }
350
+ };
351
+ var GoogleMapsAuthentication = class extends TokenAuthentication {
352
+ /** Discriminator used in `core.credentials`. */
353
+ static type = "google-maps";
354
+ /** Creates a Google Maps credential with the existing provider defaults. */
355
+ constructor(options) {
356
+ super(createGoogleMapsCredential(options));
357
+ }
358
+ };
359
+ var CesiumIonAuthentication = class extends TokenAuthentication {
360
+ /** Discriminator used in `core.credentials`. */
361
+ static type = "cesium-ion";
362
+ /** Creates an ion credential with the existing provider lifecycle. */
363
+ constructor(options) {
364
+ super(createCesiumIonCredential(options));
365
+ }
366
+ };
367
+ var CESIUM_ION_ASSET_ORIGINS = [
368
+ "https://assets.ion.cesium.com",
369
+ "https://assets.cesium.com"
370
+ ];
371
+ function createMapboxCredential(options) {
372
+ return createQueryParameterCredential({
373
+ id: "mapbox-access-token",
374
+ origins: options.origins || ["https://api.mapbox.com"],
375
+ parameterName: "access_token",
376
+ token: options.accessToken
377
+ });
378
+ }
379
+ function createGoogleMapsCredential(options) {
380
+ return createQueryParameterCredential({
381
+ id: "google-maps-api-key",
382
+ origins: options.origins || ["https://tile.googleapis.com"],
383
+ parameterName: "key",
384
+ token: options.apiKey
385
+ });
386
+ }
387
+ function createCesiumIonCredential(options) {
388
+ if (options.assetId === void 0 || options.assetId === null) {
389
+ return createBearerTokenCredential({
390
+ id: "cesium-ion-access-token",
391
+ origins: options.origins || [CESIUM_ION_API_ORIGIN],
392
+ token: options.accessToken
393
+ });
394
+ }
395
+ const assetId = options.assetId;
396
+ const origins = options.origins || CESIUM_ION_ASSET_ORIGINS;
397
+ let endpointTokenPromise = null;
398
+ return createBearerTokenCredential({
399
+ id: `cesium-ion-asset-${assetId}`,
400
+ origins,
401
+ token: (context) => {
402
+ if (context.reason === "refresh") {
403
+ endpointTokenPromise = null;
404
+ }
405
+ endpointTokenPromise ||= resolveCesiumIonAssetToken(options, assetId, origins, context);
406
+ return endpointTokenPromise;
407
+ }
408
+ });
409
+ }
410
+ async function resolveCesiumIonAssetToken(options, assetId, origins, context) {
411
+ const endpointURL = `${CESIUM_ION_API_ORIGIN}/v1/assets/${assetId}/endpoint`;
412
+ const accessToken = typeof options.accessToken === "function" ? await options.accessToken({ ...context, url: endpointURL }) : options.accessToken;
413
+ if (!accessToken)
414
+ return null;
415
+ const tokenType = options.tokenType || "auto";
416
+ if (tokenType === "asset" || tokenType === "auto" && isCesiumIonAssetToken(accessToken, assetId)) {
417
+ return accessToken;
418
+ }
419
+ const apiCredential = createBearerTokenCredential({
420
+ id: `cesium-ion-api-${assetId}`,
421
+ origins: [CESIUM_ION_API_ORIGIN],
422
+ token: accessToken
423
+ });
424
+ const ionFetch = createAuthenticatedFetch({
425
+ fetch: options.fetch,
426
+ credentials: [apiCredential]
427
+ });
428
+ const response = await ionFetch(endpointURL);
429
+ if (!response.ok) {
430
+ throw new Error(`Cesium ion asset ${assetId} endpoint request failed: ${response.status}`);
431
+ }
432
+ const endpoint = await response.json();
433
+ if (typeof endpoint.url !== "string" || !origins.includes(new URL(endpoint.url).origin)) {
434
+ throw new Error(`Cesium ion asset ${assetId} resolved to an unconfigured origin.`);
435
+ }
436
+ if (typeof endpoint.accessToken !== "string" || !endpoint.accessToken) {
437
+ throw new Error(`Cesium ion did not return an endpoint token for asset ${assetId}.`);
438
+ }
439
+ return endpoint.accessToken;
440
+ }
441
+ function isCesiumIonAssetToken(token, assetId) {
442
+ try {
443
+ const encodedClaims = token.split(".")[1];
444
+ if (!encodedClaims)
445
+ return false;
446
+ const base64 = encodedClaims.replace(/-/g, "+").replace(/_/g, "/");
447
+ const paddedBase64 = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
448
+ const claims = JSON.parse(atob(paddedBase64));
449
+ return Array.isArray(claims.assets) && claims.assets.some((claimAssetId) => String(claimAssetId) === String(assetId));
450
+ } catch {
451
+ return false;
452
+ }
453
+ }
454
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../../loader-utils/src/lib/request-utils/authentication.ts", "../../loader-utils/src/lib/request-utils/request-credentials.ts", "../src/authentication.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACiEO,SAAS,mBACd,aACA,kBAAwD,CAAC,GAC9B;AAC3B,MAAI,YAAY,MAAM,gBAAgB,EAAG,QAAO;AAChD,SAAO,YAAY,IAAI,CAAC,YAAY,UAAU;AAC5C,QAAI,iBAAiB,UAAU,EAAG,QAAO;AACzC,UAAM,sBAAsB,gBAAgB;AAAA,MAC1C,CAAAA,oBAAkBA,gBAAe,UAAS,yCAAY;AAAA,IACxD;AACA,QAAI,CAAC,qBAAqB;AACxB,YAAM,IAAI,MAAM,8DAA8D,KAAK,GAAG;AAAA,IACxF;AACA,QAAI;AACJ,QAAI;AACF,uBAAiB,IAAI,oBAAoB,UAAU;AAAA,IACrD,QAAQ;AAEN,YAAM,IAAI,MAAM,iDAAiD,KAAK,GAAG;AAAA,IAC3E;AACA,QAAI,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yD,OAAO,GAAG;EACrF;AACA,SAAO,SAAS;AAClB;AAGA,SAAS,sBAAsB,OAAe,SAAwB;AACpE,MAAI;AACF,UAAM,gBAAgB,MAAM,MAAM,GAAG,EAAE,CAAC;AACxC,QAAI,CAAC;AAAe,aAAO;AAC3B,UAAM,SAAS,cAAc,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AACjE,UAAM,eAAe,OAAO,OAAO,KAAK,KAAK,OAAO,SAAS,CAAC,IAAI,GAAG,GAAG;AACxE,UAAM,SAAS,KAAK,MAAM,KAAK,YAAY,CAAC;AAC5C,WACE,MAAM,QAAQ,OAAO,MAAM,KAC3B,OAAO,OAAO,KAAK,kBAAgB,OAAO,YAAY,MAAM,OAAO,OAAO,CAAC;EAE/E,QAAQ;AACN,WAAO;EACT;AACF;",
5
+ "names": ["authentication", "_a"]
6
+ }
@@ -0,0 +1,3 @@
1
+ export { MapboxAuthentication, GoogleMapsAuthentication, CesiumIonAuthentication, createCesiumIonCredential, createGoogleMapsCredential, createMapboxCredential } from "./authentication.js";
2
+ export type { CesiumIonCredentialOptions, GoogleMapsCredentialOptions, MapboxCredentialOptions, ServiceCredentialOptions } from "./authentication.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACvB,4BAAyB;AAC1B,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACvB,wBAAwB,EACzB,4BAAyB"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { MapboxAuthentication, GoogleMapsAuthentication, CesiumIonAuthentication, createCesiumIonCredential, createGoogleMapsCredential, createMapboxCredential } from "./authentication.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACvB,4BAAyB"}
@@ -0,0 +1,2 @@
1
+ export * from "./index.js";
2
+ //# sourceMappingURL=unbundled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbundled.d.ts","sourceRoot":"","sources":["../src/unbundled.ts"],"names":[],"mappings":"AAKA,2BAAwB"}
@@ -0,0 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // ArcGIS sources are already metadata-only entrypoints and have no parser bundle to defer.
5
+ export * from "./index.js";
6
+ //# sourceMappingURL=unbundled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbundled.js","sourceRoot":"","sources":["../src/unbundled.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,2FAA2F;AAC3F,2BAAwB"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@loaders.gl/services",
3
+ "version": "5.0.0-alpha.10",
4
+ "description": "Authentication presets for geospatial service providers",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/visgl/loaders.gl"
13
+ },
14
+ "keywords": [
15
+ "authentication",
16
+ "services",
17
+ "geospatial"
18
+ ],
19
+ "types": "dist/index.d.ts",
20
+ "main": "dist/index.cjs",
21
+ "module": "dist/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "./unbundled": {
29
+ "types": "./dist/unbundled.d.ts",
30
+ "import": "./dist/unbundled.js"
31
+ },
32
+ "./bundled": {
33
+ "types": "./dist/bundled.d.ts",
34
+ "import": "./dist/bundled.js"
35
+ },
36
+ "./authentication": {
37
+ "types": "./dist/authentication.d.ts",
38
+ "import": "./dist/authentication.js"
39
+ }
40
+ },
41
+ "sideEffects": false,
42
+ "files": [
43
+ "src",
44
+ "dist",
45
+ "README.md"
46
+ ],
47
+ "dependencies": {
48
+ "@loaders.gl/loader-utils": "5.0.0-alpha.10"
49
+ },
50
+ "peerDependencies": {
51
+ "@loaders.gl/core": "~5.0.0-alpha.0"
52
+ },
53
+ "gitHead": "7cbfaef633e86356c946541dab4977b522745b6c"
54
+ }
@@ -0,0 +1,200 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ FetchLike,
7
+ RequestCredential,
8
+ TokenProviderContext,
9
+ TokenValue
10
+ } from '@loaders.gl/loader-utils';
11
+ import {
12
+ createAuthenticatedFetch,
13
+ TokenAuthentication,
14
+ createBearerTokenCredential,
15
+ createQueryParameterCredential
16
+ } from '@loaders.gl/loader-utils';
17
+
18
+ const CESIUM_ION_API_ORIGIN = 'https://api.cesium.com';
19
+
20
+ /** Declarative Mapbox access-token authentication. */
21
+ export class MapboxAuthentication extends TokenAuthentication {
22
+ /** Discriminator used in `core.credentials`. */
23
+ static readonly type = 'mapbox';
24
+ /** Creates a Mapbox credential with the existing provider defaults. */
25
+ constructor(options: MapboxCredentialOptions) {
26
+ super(createMapboxCredential(options));
27
+ }
28
+ }
29
+
30
+ /** Declarative Google Maps API-key authentication. */
31
+ export class GoogleMapsAuthentication extends TokenAuthentication {
32
+ /** Discriminator used in `core.credentials`. */
33
+ static readonly type = 'google-maps';
34
+ /** Creates a Google Maps credential with the existing provider defaults. */
35
+ constructor(options: GoogleMapsCredentialOptions) {
36
+ super(createGoogleMapsCredential(options));
37
+ }
38
+ }
39
+
40
+ /** Declarative Cesium ion authentication, including lazy asset-token exchange. */
41
+ export class CesiumIonAuthentication extends TokenAuthentication {
42
+ /** Discriminator used in `core.credentials`. */
43
+ static readonly type = 'cesium-ion';
44
+ /** Creates an ion credential with the existing provider lifecycle. */
45
+ constructor(options: CesiumIonCredentialOptions) {
46
+ super(createCesiumIonCredential(options));
47
+ }
48
+ }
49
+ const CESIUM_ION_ASSET_ORIGINS = [
50
+ 'https://assets.ion.cesium.com',
51
+ 'https://assets.cesium.com'
52
+ ] as const;
53
+
54
+ /** Shared options for provider credential presets with known public API origins. */
55
+ export type ServiceCredentialOptions = {
56
+ /** Replaces the provider's default exact-origin allowlist. */
57
+ origins?: readonly string[];
58
+ };
59
+
60
+ /** Options for a Mapbox API credential. */
61
+ export type MapboxCredentialOptions = ServiceCredentialOptions & {
62
+ /** Mapbox public access token or application-managed token callback. */
63
+ accessToken: TokenValue;
64
+ };
65
+
66
+ /** Options for a Google Maps Platform credential. */
67
+ export type GoogleMapsCredentialOptions = ServiceCredentialOptions & {
68
+ /** Google Maps Platform API key or application-managed key callback. */
69
+ apiKey: TokenValue;
70
+ };
71
+
72
+ /** Options for a Cesium ion API credential. */
73
+ export type CesiumIonCredentialOptions = ServiceCredentialOptions & {
74
+ /** Cesium ion access token or application-managed token callback. */
75
+ accessToken: TokenValue;
76
+ /** Optional asset whose endpoint-scoped token should be resolved. */
77
+ assetId?: number | string;
78
+ /** Overrides the transport used for the ion endpoint-token exchange. */
79
+ fetch?: FetchLike;
80
+ /** Whether the supplied token is account-scoped or already asset-scoped. */
81
+ tokenType?: 'account' | 'asset' | 'auto';
82
+ };
83
+
84
+ /** Creates a Mapbox `access_token` query credential. */
85
+ export function createMapboxCredential(options: MapboxCredentialOptions): RequestCredential {
86
+ return createQueryParameterCredential({
87
+ id: 'mapbox-access-token',
88
+ origins: options.origins || ['https://api.mapbox.com'],
89
+ parameterName: 'access_token',
90
+ token: options.accessToken
91
+ });
92
+ }
93
+
94
+ /** Creates a Google Maps Platform `key` query credential. */
95
+ export function createGoogleMapsCredential(
96
+ options: GoogleMapsCredentialOptions
97
+ ): RequestCredential {
98
+ return createQueryParameterCredential({
99
+ id: 'google-maps-api-key',
100
+ origins: options.origins || ['https://tile.googleapis.com'],
101
+ parameterName: 'key',
102
+ token: options.apiKey
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Creates a bearer credential for the Cesium ion REST API or one Cesium ion asset.
108
+ *
109
+ * Supplying `assetId` creates an asset-origin credential. Account tokens are exchanged lazily
110
+ * through Cesium ion's endpoint API; legacy asset-scoped tokens are used directly. Without an
111
+ * `assetId`, the credential is scoped only to the ion REST API for backwards compatibility.
112
+ */
113
+ export function createCesiumIonCredential(options: CesiumIonCredentialOptions): RequestCredential {
114
+ if (options.assetId === undefined || options.assetId === null) {
115
+ return createBearerTokenCredential({
116
+ id: 'cesium-ion-access-token',
117
+ origins: options.origins || [CESIUM_ION_API_ORIGIN],
118
+ token: options.accessToken
119
+ });
120
+ }
121
+
122
+ const assetId = options.assetId;
123
+ const origins = options.origins || CESIUM_ION_ASSET_ORIGINS;
124
+ let endpointTokenPromise: Promise<string | null> | null = null;
125
+
126
+ return createBearerTokenCredential({
127
+ id: `cesium-ion-asset-${assetId}`,
128
+ origins,
129
+ token: context => {
130
+ if (context.reason === 'refresh') {
131
+ endpointTokenPromise = null;
132
+ }
133
+ endpointTokenPromise ||= resolveCesiumIonAssetToken(options, assetId, origins, context);
134
+ return endpointTokenPromise;
135
+ }
136
+ });
137
+ }
138
+
139
+ /** Resolves an account token and exchanges it for an asset endpoint token when required. */
140
+ async function resolveCesiumIonAssetToken(
141
+ options: CesiumIonCredentialOptions,
142
+ assetId: number | string,
143
+ origins: readonly string[],
144
+ context: TokenProviderContext
145
+ ): Promise<string | null> {
146
+ const endpointURL = `${CESIUM_ION_API_ORIGIN}/v1/assets/${assetId}/endpoint`;
147
+ const accessToken =
148
+ typeof options.accessToken === 'function'
149
+ ? await options.accessToken({...context, url: endpointURL})
150
+ : options.accessToken;
151
+ if (!accessToken) return null;
152
+
153
+ const tokenType = options.tokenType || 'auto';
154
+ if (
155
+ tokenType === 'asset' ||
156
+ (tokenType === 'auto' && isCesiumIonAssetToken(accessToken, assetId))
157
+ ) {
158
+ return accessToken;
159
+ }
160
+
161
+ const apiCredential = createBearerTokenCredential({
162
+ id: `cesium-ion-api-${assetId}`,
163
+ origins: [CESIUM_ION_API_ORIGIN],
164
+ token: accessToken
165
+ });
166
+ const ionFetch = createAuthenticatedFetch({
167
+ fetch: options.fetch,
168
+ credentials: [apiCredential]
169
+ });
170
+ const response = await ionFetch(endpointURL);
171
+ if (!response.ok) {
172
+ throw new Error(`Cesium ion asset ${assetId} endpoint request failed: ${response.status}`);
173
+ }
174
+
175
+ const endpoint = (await response.json()) as {accessToken?: unknown; url?: unknown};
176
+ if (typeof endpoint.url !== 'string' || !origins.includes(new URL(endpoint.url).origin)) {
177
+ throw new Error(`Cesium ion asset ${assetId} resolved to an unconfigured origin.`);
178
+ }
179
+ if (typeof endpoint.accessToken !== 'string' || !endpoint.accessToken) {
180
+ throw new Error(`Cesium ion did not return an endpoint token for asset ${assetId}.`);
181
+ }
182
+ return endpoint.accessToken;
183
+ }
184
+
185
+ /** Detects legacy JWTs whose claims scope them directly to the requested asset. */
186
+ function isCesiumIonAssetToken(token: string, assetId: number | string): boolean {
187
+ try {
188
+ const encodedClaims = token.split('.')[1];
189
+ if (!encodedClaims) return false;
190
+ const base64 = encodedClaims.replace(/-/g, '+').replace(/_/g, '/');
191
+ const paddedBase64 = base64.padEnd(Math.ceil(base64.length / 4) * 4, '=');
192
+ const claims = JSON.parse(atob(paddedBase64)) as {assets?: unknown};
193
+ return (
194
+ Array.isArray(claims.assets) &&
195
+ claims.assets.some(claimAssetId => String(claimAssetId) === String(assetId))
196
+ );
197
+ } catch {
198
+ return false;
199
+ }
200
+ }
package/src/bundled.ts ADDED
@@ -0,0 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // ArcGIS sources have no parser-only implementation to defer.
6
+ export * from './index';
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export {
6
+ MapboxAuthentication,
7
+ GoogleMapsAuthentication,
8
+ CesiumIonAuthentication,
9
+ createCesiumIonCredential,
10
+ createGoogleMapsCredential,
11
+ createMapboxCredential
12
+ } from './authentication';
13
+ export type {
14
+ CesiumIonCredentialOptions,
15
+ GoogleMapsCredentialOptions,
16
+ MapboxCredentialOptions,
17
+ ServiceCredentialOptions
18
+ } from './authentication';
@@ -0,0 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // ArcGIS sources are already metadata-only entrypoints and have no parser bundle to defer.
6
+ export * from './index';