@loaders.gl/arcgis 5.0.0-alpha.9 → 5.0.0-beta.1
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 +2 -30
- package/README.md +40 -12
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/dist/arcgis/arcgis-capability-graph.d.ts +1 -1
- package/dist/arcgis/arcgis-capability-graph.d.ts.map +1 -1
- package/dist/arcgis/arcgis-feature-server-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-feature-server-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-feature-server-source-loader.d.ts +3 -3
- package/dist/arcgis/arcgis-feature-server-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-feature-server-source-loader.js +3 -2
- package/dist/arcgis/arcgis-feature-server-source-loader.js.map +1 -1
- package/dist/arcgis/arcgis-image-server-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-image-server-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-image-server-source-loader.d.ts +3 -3
- package/dist/arcgis/arcgis-image-server-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-image-server-source-loader.js +2 -2
- package/dist/arcgis/arcgis-image-server-source-loader.js.map +1 -1
- package/dist/arcgis/arcgis-image-tile-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-image-tile-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-image-tile-source-loader.d.ts +3 -3
- package/dist/arcgis/arcgis-image-tile-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-image-tile-source-loader.js +7 -3
- package/dist/arcgis/arcgis-image-tile-source-loader.js.map +1 -1
- package/dist/arcgis/arcgis-map-tile-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-map-tile-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-map-tile-source-loader.d.ts +2 -2
- package/dist/arcgis/arcgis-map-tile-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-map-tile-source-loader.js +15 -19
- package/dist/arcgis/arcgis-map-tile-source-loader.js.map +1 -1
- package/dist/arcgis/arcgis-scene-server-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-scene-server-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-scene-server-source-loader.d.ts +3 -3
- package/dist/arcgis/arcgis-scene-server-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-scene-server-source-loader.js +2 -2
- package/dist/arcgis/arcgis-scene-server-source-loader.js.map +1 -1
- package/dist/arcgis/arcgis-tile-grid.d.ts +5 -0
- package/dist/arcgis/arcgis-tile-grid.d.ts.map +1 -0
- package/dist/arcgis/arcgis-tile-grid.js +43 -0
- package/dist/arcgis/arcgis-tile-grid.js.map +1 -0
- package/dist/arcgis/arcgis-vector-tile-server-source-loader-types.d.ts +1 -1
- package/dist/arcgis/arcgis-vector-tile-server-source-loader-types.d.ts.map +1 -1
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.d.ts +5 -3
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.d.ts.map +1 -1
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.js +20 -6
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.js.map +1 -1
- package/dist/arcgis-feature-query-types.d.ts +2 -2
- package/dist/arcgis-feature-query-types.d.ts.map +1 -1
- package/dist/arcgis-items.d.ts +64 -0
- package/dist/arcgis-items.d.ts.map +1 -0
- package/dist/arcgis-items.js +137 -0
- package/dist/arcgis-items.js.map +1 -0
- package/dist/arcgis-source-types.d.ts +8 -2
- package/dist/arcgis-source-types.d.ts.map +1 -1
- package/dist/arcgis-source-types.js.map +1 -1
- package/dist/authentication.d.ts +9 -3
- package/dist/authentication.d.ts.map +1 -1
- package/dist/authentication.js +79 -9
- package/dist/authentication.js.map +1 -1
- package/dist/bundled.d.ts +8 -7
- package/dist/bundled.d.ts.map +1 -1
- package/dist/bundled.js +1 -0
- package/dist/bundled.js.map +1 -1
- package/dist/index.cjs +14074 -16905
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +14 -10
- package/src/arcgis/arcgis-capability-graph.ts +1 -1
- package/src/arcgis/arcgis-feature-query.ts +1 -1
- package/src/arcgis/arcgis-feature-server-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-feature-server-source-loader.ts +6 -8
- package/src/arcgis/arcgis-image-server-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-image-server-source-loader.ts +4 -4
- package/src/arcgis/arcgis-image-tile-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-image-tile-source-loader.ts +12 -5
- package/src/arcgis/arcgis-map-tile-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-map-tile-source-loader.ts +24 -21
- package/src/arcgis/arcgis-scene-server-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-scene-server-source-loader.ts +4 -4
- package/src/arcgis/arcgis-tile-grid.ts +55 -0
- package/src/arcgis/arcgis-vector-tile-server-source-loader-types.ts +1 -1
- package/src/arcgis/arcgis-vector-tile-server-source-loader.ts +27 -8
- package/src/arcgis-feature-query-types.ts +2 -2
- package/src/arcgis-items.ts +233 -0
- package/src/arcgis-source-types.ts +11 -3
- package/src/authentication.ts +93 -10
- package/src/bundled.ts +35 -1
- package/src/index.ts +7 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {FetchLike} from '@loaders.gl/core/loader-utils';
|
|
6
|
+
|
|
7
|
+
/** A supported service-backed portal item, retaining the original portal metadata. */
|
|
8
|
+
export type ArcGISItem = {
|
|
9
|
+
/** Portal item identifier. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Display title supplied by the publisher. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Portal item type, distinct from the REST service type. */
|
|
14
|
+
type: string;
|
|
15
|
+
/** REST service endpoint. */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Publisher description, potentially containing HTML; do not render it unsanitized. */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** Publisher attribution, potentially containing HTML. */
|
|
20
|
+
accessInformation?: string;
|
|
21
|
+
/** Geographic item extent in longitude/latitude, when published. */
|
|
22
|
+
extent?: number[][];
|
|
23
|
+
/** Unmodified additional portal metadata. */
|
|
24
|
+
[name: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** An explicit service/layer choice; resolving a choice does not prove renderer support. */
|
|
28
|
+
export type ArcGISItemLayer = {
|
|
29
|
+
/** Numeric layer identifier, or null for a single root service. */
|
|
30
|
+
id: number | null;
|
|
31
|
+
/** Publisher-provided layer name. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Endpoint to pass to an appropriate ArcGIS source loader. */
|
|
34
|
+
url: string;
|
|
35
|
+
/** Whether this is a spatial layer, nonspatial table, or root service. */
|
|
36
|
+
kind: 'layer' | 'table' | 'service';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** A resolved service item with choices and optional selected layer metadata. */
|
|
40
|
+
export type ArcGISItemResolution = {
|
|
41
|
+
/** Canonical portal REST root, including an Enterprise web-adaptor path. */
|
|
42
|
+
portalUrl: string;
|
|
43
|
+
/** Original item metadata, including description, extent and attribution. */
|
|
44
|
+
item: ArcGISItem;
|
|
45
|
+
/** Original service metadata. */
|
|
46
|
+
service: Record<string, any>;
|
|
47
|
+
/** Available choices; no implicit first-layer selection is made. */
|
|
48
|
+
layers: ArcGISItemLayer[];
|
|
49
|
+
/** Explicitly selected layer and its raw fields, domains, extent and attribution. */
|
|
50
|
+
selectedLayer?: ArcGISItemLayer & {
|
|
51
|
+
/** Unmodified selected-layer metadata. */ metadata: Record<string, any>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Controls item resolution without owning authentication or OAuth state. */
|
|
56
|
+
export type ArcGISItemOptions = {
|
|
57
|
+
/** Portal root or sharing/rest endpoint. Defaults to ArcGIS Online for bare IDs. */
|
|
58
|
+
portalUrl?: string;
|
|
59
|
+
/** Shared authenticated transport, also used for service and selected-layer metadata. */
|
|
60
|
+
fetch?: FetchLike;
|
|
61
|
+
/** Cancels all metadata requests. */
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
/** Explicit layer/table identifier to inspect, or null for a root service. */
|
|
64
|
+
layerId?: number | null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Service-backed item types supported by this resolver. */
|
|
68
|
+
const ITEM_SERVICES: Readonly<Record<string, string>> = {
|
|
69
|
+
'Feature Service': 'FeatureServer',
|
|
70
|
+
'Map Service': 'MapServer',
|
|
71
|
+
'Image Service': 'ImageServer',
|
|
72
|
+
'Vector Tile Service': 'VectorTileServer',
|
|
73
|
+
'Scene Service': 'SceneServer'
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resolves a portal item ID, item-details URL, or item REST URL into explicit service choices.
|
|
78
|
+
* Fetches only item, service, and (when selected) layer metadata. Web Maps/Web Scenes are rejected.
|
|
79
|
+
* URLs discovered in metadata never expand the credential's trusted origins.
|
|
80
|
+
*/
|
|
81
|
+
export async function resolveArcGISItem(
|
|
82
|
+
input: string,
|
|
83
|
+
options: ArcGISItemOptions = {}
|
|
84
|
+
): Promise<ArcGISItemResolution> {
|
|
85
|
+
const {itemId, portalUrl} = parseItemReference(input, options.portalUrl);
|
|
86
|
+
const fetchFile = options.fetch || fetch;
|
|
87
|
+
const item = (await fetchMetadata(
|
|
88
|
+
`${portalUrl}/content/items/${itemId}`,
|
|
89
|
+
fetchFile,
|
|
90
|
+
options.signal
|
|
91
|
+
)) as ArcGISItem;
|
|
92
|
+
const serviceType = Object.hasOwn(ITEM_SERVICES, item.type)
|
|
93
|
+
? ITEM_SERVICES[item.type]
|
|
94
|
+
: undefined;
|
|
95
|
+
if (!serviceType)
|
|
96
|
+
throw new Error(
|
|
97
|
+
'Unsupported ArcGIS item type. Resolve a service item, not a Web Map or Web Scene.'
|
|
98
|
+
);
|
|
99
|
+
if (
|
|
100
|
+
typeof item.id !== 'string' ||
|
|
101
|
+
item.id.toLowerCase() !== itemId ||
|
|
102
|
+
typeof item.title !== 'string'
|
|
103
|
+
)
|
|
104
|
+
throw new Error('Invalid ArcGIS item metadata.');
|
|
105
|
+
const serviceUrl = parseEndpoint(item.url);
|
|
106
|
+
const serviceMatch = serviceUrl.pathname.match(
|
|
107
|
+
/\/(FeatureServer|MapServer|ImageServer|VectorTileServer|SceneServer)(?:\/(?:layers\/)?(\d+))?\/?$/i
|
|
108
|
+
);
|
|
109
|
+
if (
|
|
110
|
+
!serviceMatch ||
|
|
111
|
+
serviceMatch[1].toLowerCase() !== serviceType.toLowerCase() ||
|
|
112
|
+
(serviceMatch[2] !== undefined &&
|
|
113
|
+
!new RegExp(
|
|
114
|
+
serviceType === 'SceneServer'
|
|
115
|
+
? '/SceneServer/layers/\\d+/?$'
|
|
116
|
+
: '/(FeatureServer|MapServer)/\\d+/?$',
|
|
117
|
+
'i'
|
|
118
|
+
).test(serviceUrl.pathname))
|
|
119
|
+
) {
|
|
120
|
+
throw new Error('ArcGIS item URL does not match its supported service type.');
|
|
121
|
+
}
|
|
122
|
+
const url = serviceUrl.href.replace(/\/$/, '');
|
|
123
|
+
const service = await fetchMetadata(url, fetchFile, options.signal);
|
|
124
|
+
const isLayer = serviceMatch[2] !== undefined;
|
|
125
|
+
const layers: ArcGISItemLayer[] = isLayer
|
|
126
|
+
? [
|
|
127
|
+
{
|
|
128
|
+
id: Number(serviceMatch[2]),
|
|
129
|
+
name: service.name || item.title,
|
|
130
|
+
url,
|
|
131
|
+
kind: service.type === 'Table' ? 'table' : 'layer'
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
: [
|
|
135
|
+
...createLayerChoices(service.layers, 'layer', url, serviceType),
|
|
136
|
+
...createLayerChoices(service.tables, 'table', url, serviceType)
|
|
137
|
+
];
|
|
138
|
+
// Map roots are also useful as image sources; image/vector tile roots are single services.
|
|
139
|
+
if (!isLayer && serviceType !== 'FeatureServer' && serviceType !== 'SceneServer') {
|
|
140
|
+
layers.unshift({id: null, name: service.name || item.title, url, kind: 'service'});
|
|
141
|
+
}
|
|
142
|
+
const resolution: ArcGISItemResolution = {portalUrl, item, service, layers};
|
|
143
|
+
if (options.layerId !== undefined) {
|
|
144
|
+
const layer = layers.find(candidate => candidate.id === options.layerId);
|
|
145
|
+
if (!layer) throw new Error('The requested ArcGIS layer or table is not present in this item.');
|
|
146
|
+
const metadata =
|
|
147
|
+
layer.url === url ? service : await fetchMetadata(layer.url, fetchFile, options.signal);
|
|
148
|
+
resolution.selectedLayer = {...layer, metadata};
|
|
149
|
+
}
|
|
150
|
+
return resolution;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Builds choices from advertised numeric layer IDs without recursively fetching sublayers. */
|
|
154
|
+
function createLayerChoices(
|
|
155
|
+
entries: any,
|
|
156
|
+
kind: 'layer' | 'table',
|
|
157
|
+
url: string,
|
|
158
|
+
serviceType: string
|
|
159
|
+
): ArcGISItemLayer[] {
|
|
160
|
+
if (!Array.isArray(entries)) return [];
|
|
161
|
+
return entries
|
|
162
|
+
.filter(entry => Number.isSafeInteger(entry?.id) && entry.id >= 0)
|
|
163
|
+
.map(entry => ({
|
|
164
|
+
id: entry.id,
|
|
165
|
+
name: typeof entry.name === 'string' ? entry.name : String(entry.id),
|
|
166
|
+
url: `${url}/${serviceType === 'SceneServer' ? 'layers/' : ''}${entry.id}`,
|
|
167
|
+
kind
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Parses only documented item URL shapes, retaining Enterprise portal prefixes. */
|
|
172
|
+
function parseItemReference(
|
|
173
|
+
input: string,
|
|
174
|
+
configuredPortal?: string
|
|
175
|
+
): {itemId: string; portalUrl: string} {
|
|
176
|
+
let itemId = input;
|
|
177
|
+
let inferredPortal: string | undefined;
|
|
178
|
+
if (!/^[a-f\d]{32}$/i.test(input)) {
|
|
179
|
+
const url = new URL(input);
|
|
180
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.hash)
|
|
181
|
+
throw new Error('Invalid ArcGIS item URL.');
|
|
182
|
+
const details = url.pathname.match(/^(.*)\/home\/item\.html$/);
|
|
183
|
+
const rest = url.pathname.match(/^(.*)\/sharing\/rest\/content\/items\/([a-f\d]{32})\/?$/i);
|
|
184
|
+
if (details) {
|
|
185
|
+
itemId = url.searchParams.get('id') || '';
|
|
186
|
+
inferredPortal = `${url.origin}${details[1]}/sharing/rest`;
|
|
187
|
+
} else if (rest) {
|
|
188
|
+
itemId = rest[2];
|
|
189
|
+
inferredPortal = `${url.origin}${rest[1]}/sharing/rest`;
|
|
190
|
+
} else throw new Error('Expected an ArcGIS item ID or item-details/REST URL.');
|
|
191
|
+
if ([...url.searchParams.keys()].some(key => !['id', 'f'].includes(key)))
|
|
192
|
+
throw new Error('Item URLs must not contain credentials or extra parameters.');
|
|
193
|
+
}
|
|
194
|
+
if (!/^[a-f\d]{32}$/i.test(itemId))
|
|
195
|
+
throw new Error('ArcGIS item IDs must contain 32 hexadecimal characters.');
|
|
196
|
+
const portal = parseEndpoint(configuredPortal || inferredPortal || 'https://www.arcgis.com');
|
|
197
|
+
const portalUrl = `${portal.href.replace(/\/$/, '').replace(/\/sharing\/rest$/i, '')}/sharing/rest`;
|
|
198
|
+
if (inferredPortal && portalUrl !== inferredPortal)
|
|
199
|
+
throw new Error('Item URL does not belong to the configured portal.');
|
|
200
|
+
return {itemId: itemId.toLowerCase(), portalUrl};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Rejects credential-bearing or non-HTTP metadata endpoints. */
|
|
204
|
+
function parseEndpoint(value: string): URL {
|
|
205
|
+
const url = new URL(value);
|
|
206
|
+
if (
|
|
207
|
+
!['http:', 'https:'].includes(url.protocol) ||
|
|
208
|
+
url.username ||
|
|
209
|
+
url.password ||
|
|
210
|
+
url.search ||
|
|
211
|
+
url.hash
|
|
212
|
+
) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
'ArcGIS endpoints must be HTTP(S) URLs without credentials, query parameters or fragments.'
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return url;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Reads JSON metadata and rejects ArcGIS error envelopes even with HTTP 200. */
|
|
221
|
+
async function fetchMetadata(
|
|
222
|
+
url: string,
|
|
223
|
+
fetchFile: FetchLike,
|
|
224
|
+
signal?: AbortSignal
|
|
225
|
+
): Promise<Record<string, any>> {
|
|
226
|
+
const response = await fetchFile(`${url}?f=json`, {signal});
|
|
227
|
+
if (!response.ok) throw new Error(`ArcGIS metadata request failed (HTTP ${response.status}).`);
|
|
228
|
+
const metadata = await response.json();
|
|
229
|
+
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata) || metadata.error) {
|
|
230
|
+
throw new Error('ArcGIS metadata is unavailable or access was denied.');
|
|
231
|
+
}
|
|
232
|
+
return metadata;
|
|
233
|
+
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {DataSourceOptions, SourceLoader} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {DataSourceOptions, SourceLoader} from '@loaders.gl/core/loader-utils';
|
|
6
6
|
import type {ImageLoaderOptions} from '@loaders.gl/images';
|
|
7
|
-
import type {MVTLoaderOptions} from '@loaders.gl/mvt';
|
|
7
|
+
import type {MVTLoaderOptions} from '@loaders.gl/tiles/mvt';
|
|
8
8
|
|
|
9
9
|
/** Static source metadata shared by lazy descriptors and runtime loaders. */
|
|
10
10
|
type ArcGISSourceMetadata = Omit<SourceLoader, 'dataType' | 'batchType' | 'createDataSource'>;
|
|
@@ -155,7 +155,15 @@ export type ArcGISMapServerMetadata = {
|
|
|
155
155
|
fullExtent?: {xmin: number; ymin: number; xmax: number; ymax: number; spatialReference?: unknown};
|
|
156
156
|
spatialReference?: unknown;
|
|
157
157
|
tileInfo?: {
|
|
158
|
-
|
|
158
|
+
/** Advertised level identifiers and coordinate units per pixel. */
|
|
159
|
+
lods?: {
|
|
160
|
+
/** Native cache level identifier. */
|
|
161
|
+
level: number;
|
|
162
|
+
/** Coordinate units per pixel. */
|
|
163
|
+
resolution?: number;
|
|
164
|
+
/** Advertised scale denominator, retained as service metadata. */
|
|
165
|
+
scale?: number;
|
|
166
|
+
}[];
|
|
159
167
|
rows?: number;
|
|
160
168
|
cols?: number;
|
|
161
169
|
format?: string;
|
package/src/authentication.ts
CHANGED
|
@@ -2,10 +2,22 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
AuthenticatedFetchOptions,
|
|
7
|
+
FetchLike,
|
|
8
|
+
RequestCredential,
|
|
9
|
+
TokenValue
|
|
10
|
+
} from '@loaders.gl/core/loader-utils';
|
|
11
|
+
import {
|
|
12
|
+
TokenAuthentication,
|
|
13
|
+
createAuthenticatedFetch,
|
|
14
|
+
createQueryParameterCredential
|
|
15
|
+
} from '@loaders.gl/core/loader-utils';
|
|
7
16
|
|
|
8
|
-
/**
|
|
17
|
+
/** Maximum JSON error bytes retained by the authentication detector. */
|
|
18
|
+
const MAXIMUM_AUTHENTICATION_ERROR_BYTES = 16384;
|
|
19
|
+
|
|
20
|
+
/** ArcGIS token authentication independent of the application's sign-in SDK. */
|
|
9
21
|
export class ArcGISAuthentication extends TokenAuthentication {
|
|
10
22
|
/** Discriminator used in `core.credentials`. */
|
|
11
23
|
static readonly type = 'arcgis';
|
|
@@ -13,6 +25,23 @@ export class ArcGISAuthentication extends TokenAuthentication {
|
|
|
13
25
|
constructor(options: ArcGISCredentialOptions) {
|
|
14
26
|
super(createArcGISCredential(options));
|
|
15
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a fetch transport for discovery and service requests.
|
|
31
|
+
* Refreshes are isolated by trusted origin so server-specific tokens cannot cross hosts.
|
|
32
|
+
* Reuse the returned transport to deduplicate concurrent refreshes within each origin.
|
|
33
|
+
*/
|
|
34
|
+
createFetch(options: Pick<AuthenticatedFetchOptions, 'fetch' | 'fetchOptions'> = {}): FetchLike {
|
|
35
|
+
return createAuthenticatedFetch({
|
|
36
|
+
...options,
|
|
37
|
+
credentials: this.origins.map(origin =>
|
|
38
|
+
createArcGISCredential({
|
|
39
|
+
origins: [origin],
|
|
40
|
+
token: this.token
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
16
45
|
}
|
|
17
46
|
|
|
18
47
|
/** Options for an ArcGIS REST service credential. */
|
|
@@ -25,11 +54,65 @@ export type ArcGISCredentialOptions = {
|
|
|
25
54
|
|
|
26
55
|
/** Creates an exact-origin ArcGIS `token` query credential. */
|
|
27
56
|
export function createArcGISCredential(options: ArcGISCredentialOptions): RequestCredential {
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
return {
|
|
58
|
+
...createQueryParameterCredential({
|
|
59
|
+
id: 'arcgis-token',
|
|
60
|
+
origins: options.origins,
|
|
61
|
+
parameterName: 'token',
|
|
62
|
+
token: options.token,
|
|
63
|
+
refreshStatusCodes: [401, 403, 498, 499]
|
|
64
|
+
}),
|
|
65
|
+
shouldRefresh: isArcGISAuthenticationError,
|
|
66
|
+
canReplayRequest: canReplayArcGISRequest
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Detects small JSON authentication errors without buffering successful feature/tile bodies.
|
|
72
|
+
* Only 498/499 envelopes trigger renewal; permission and query errors remain visible.
|
|
73
|
+
*/
|
|
74
|
+
async function isArcGISAuthenticationError(response: Response): Promise<boolean> {
|
|
75
|
+
if (response.status !== 200 || !response.headers.get('content-type')?.includes('json'))
|
|
76
|
+
return false;
|
|
77
|
+
if (Number(response.headers.get('content-length')) > MAXIMUM_AUTHENTICATION_ERROR_BYTES)
|
|
78
|
+
return false;
|
|
79
|
+
const reader = response.clone().body?.getReader();
|
|
80
|
+
if (!reader) return false;
|
|
81
|
+
const chunks: Uint8Array[] = [];
|
|
82
|
+
let length = 0;
|
|
83
|
+
try {
|
|
84
|
+
while (true) {
|
|
85
|
+
const {value, done} = await reader.read();
|
|
86
|
+
if (done) {
|
|
87
|
+
const bytes = new Uint8Array(length);
|
|
88
|
+
let offset = 0;
|
|
89
|
+
for (const chunk of chunks) {
|
|
90
|
+
bytes.set(chunk, offset);
|
|
91
|
+
offset += chunk.length;
|
|
92
|
+
}
|
|
93
|
+
const json = JSON.parse(new TextDecoder().decode(bytes));
|
|
94
|
+
return json?.error?.code === 498 || json?.error?.code === 499;
|
|
95
|
+
}
|
|
96
|
+
if (value.byteLength > MAXIMUM_AUTHENTICATION_ERROR_BYTES - length) return false;
|
|
97
|
+
length += value.byteLength;
|
|
98
|
+
// Copy only accepted bytes so small views cannot retain oversized backing buffers.
|
|
99
|
+
chunks.push(value.slice());
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
} finally {
|
|
104
|
+
// A tee cancellation can wait for the original consumer; do not await it here.
|
|
105
|
+
void reader.cancel().catch(() => {});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Permits string or URLSearchParams form POST queries on numbered feature or map layers. */
|
|
110
|
+
function canReplayArcGISRequest(url: string, request: RequestInit): boolean {
|
|
111
|
+
return (
|
|
112
|
+
request.method?.toUpperCase() === 'POST' &&
|
|
113
|
+
/\/(FeatureServer|MapServer)\/\d+\/query\/?$/i.test(new URL(url).pathname) &&
|
|
114
|
+
new Headers(request.headers).get('content-type')?.split(';')[0] ===
|
|
115
|
+
'application/x-www-form-urlencoded' &&
|
|
116
|
+
(typeof request.body === 'string' || request.body instanceof URLSearchParams)
|
|
117
|
+
);
|
|
35
118
|
}
|
package/src/bundled.ts
CHANGED
|
@@ -35,7 +35,39 @@ export {
|
|
|
35
35
|
ArcGISVectorTileServerSource
|
|
36
36
|
} from './arcgis/arcgis-vector-tile-server-source-loader';
|
|
37
37
|
|
|
38
|
-
export type
|
|
38
|
+
export type {
|
|
39
|
+
ArcGISService,
|
|
40
|
+
ArcGISCapabilityGraph,
|
|
41
|
+
ArcGISCapabilityGraphOptions,
|
|
42
|
+
ArcGISServiceCapabilities,
|
|
43
|
+
ArcGISServiceSelection,
|
|
44
|
+
ArcGISFeatureServiceQueryOptions,
|
|
45
|
+
ArcGISFeatureServerSourceLoaderOptions,
|
|
46
|
+
ArcGISExportImageParameters,
|
|
47
|
+
ArcGISImageSourceLoaderProps,
|
|
48
|
+
ArcGISImageTileSourceLoaderOptions,
|
|
49
|
+
ArcGISMapTileSourceLoaderOptions,
|
|
50
|
+
ArcGISVectorTileServiceMetadata,
|
|
51
|
+
ArcGISVectorTileServerSourceLoaderOptions,
|
|
52
|
+
ArcGISSceneServerSourceOptions,
|
|
53
|
+
ArcGISSceneQueryOptions,
|
|
54
|
+
ArcGISSceneQueryResult,
|
|
55
|
+
ArcGISSceneAggregationOperation,
|
|
56
|
+
ArcGISSceneAggregationSpec,
|
|
57
|
+
ArcGISSceneAggregationOptions,
|
|
58
|
+
ArcGISSceneAggregationGroup,
|
|
59
|
+
ArcGISCredentialOptions,
|
|
60
|
+
ArcGISFeatureQueryParameters,
|
|
61
|
+
ArcGISFeatureQueryOptions,
|
|
62
|
+
ArcGISFeatureQueryProgress,
|
|
63
|
+
ArcGISFeatureQueryResult,
|
|
64
|
+
ArcGISFeatureObjectIds,
|
|
65
|
+
ArcGISFeatureExtent,
|
|
66
|
+
ArcGISItem,
|
|
67
|
+
ArcGISItemLayer,
|
|
68
|
+
ArcGISItemResolution,
|
|
69
|
+
ArcGISItemOptions
|
|
70
|
+
} from './index';
|
|
39
71
|
export {
|
|
40
72
|
getArcGISServices,
|
|
41
73
|
discoverArcGISCapabilities,
|
|
@@ -64,3 +96,5 @@ export function getArcGISLoader(serviceType: string): ArcGISLoader | undefined {
|
|
|
64
96
|
loader => loader.id === normalizedServiceType || loader.type === normalizedServiceType
|
|
65
97
|
);
|
|
66
98
|
}
|
|
99
|
+
|
|
100
|
+
export {resolveArcGISItem} from './arcgis-items';
|
package/src/index.ts
CHANGED
|
@@ -61,3 +61,10 @@ export type {
|
|
|
61
61
|
ArcGISFeatureExtent
|
|
62
62
|
} from './arcgis-feature-query-types';
|
|
63
63
|
export type {ArcGISFeatureQueryError} from './arcgis/arcgis-feature-query';
|
|
64
|
+
|
|
65
|
+
export type {
|
|
66
|
+
ArcGISItem,
|
|
67
|
+
ArcGISItemLayer,
|
|
68
|
+
ArcGISItemResolution,
|
|
69
|
+
ArcGISItemOptions
|
|
70
|
+
} from './arcgis-items';
|