@vertigis/arcgis-rest-client 16.6.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -4
- package/portal/request.d.ts +1 -0
- package/portal/request.js +1 -1
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://dev.azure.com/vertigis/Studio/_git/arcgis-rest-client"
|
|
15
15
|
},
|
|
16
|
-
"version": "
|
|
16
|
+
"version": "18.0.0",
|
|
17
17
|
"files": [
|
|
18
18
|
"**/*.js",
|
|
19
19
|
"**/*.d.ts",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"!jest/*",
|
|
22
22
|
"!**/*config.js"
|
|
23
23
|
],
|
|
24
|
-
"type": "module",
|
|
25
24
|
"sideEffects": false,
|
|
26
25
|
"scripts": {
|
|
27
26
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -39,7 +38,6 @@
|
|
|
39
38
|
"@eslint/js": "^9.8.0",
|
|
40
39
|
"@types/jest": "^29.5.12",
|
|
41
40
|
"@typescript-eslint/eslint-plugin": "^8.0.1",
|
|
42
|
-
"@vertigis-internal/environment": "^1.0.3",
|
|
43
41
|
"@vertigis/licensing": "5.1.1",
|
|
44
42
|
"copyfiles": "^2.4.1",
|
|
45
43
|
"eslint": "~9.8.0",
|
|
@@ -57,7 +55,13 @@
|
|
|
57
55
|
"typescript-eslint": "8.1.0"
|
|
58
56
|
},
|
|
59
57
|
"peerDependencies": {
|
|
60
|
-
"@vertigis/licensing": "*"
|
|
58
|
+
"@vertigis/licensing": "*",
|
|
59
|
+
"@vertigis-internal/environment": "^1.0.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@vertigis-internal/environment": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
61
65
|
},
|
|
62
66
|
"simple-git-hooks": {
|
|
63
67
|
"pre-commit": "npx lint-staged"
|
package/portal/request.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type PortalPagingParams from "./models/PortalPagingParams";
|
|
|
3
3
|
import type PortalPagingResult from "./models/PortalPagingResult";
|
|
4
4
|
import type Principal from "../auth/models/Principal";
|
|
5
5
|
export declare function setAllowHttpRequests(allowHttp: boolean): void;
|
|
6
|
+
export declare function setRefreshFunction(refreshToUse: (principal: Principal) => Promise<Principal | undefined>): void;
|
|
6
7
|
export interface RequestOptions {
|
|
7
8
|
url: string;
|
|
8
9
|
principal: Principal;
|
package/portal/request.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isArcGISOnlineUrl}from"./utils";import{getToken}from"../auth";import{warn}from"../utils/log";let refresh,allowHttpRequests=!1;function defaultFetch(){return fetch}export function setAllowHttpRequests(allowHttp){allowHttpRequests=allowHttp}export function setRefreshFunction(refreshToUse){refresh=refreshToUse}export async function requestWithPaging(options,limit=1e3){const results=[];let total=0,start=options.pagingParams?.start??1,num=options.pagingParams?.num??100;for(;total<limit;){limit-total<num&&(num=limit-total);const response=await request({...options,pagingParams:{start:start,num:num}});if(results.push(response),"number"!=typeof response.nextStart)throw new Error(`Endpoint does not support paging: ${options.url}`);if(-1===response.nextStart)break;start=response.nextStart,total+=response.num}return results}async function request(options){const{fetch:fetch=defaultFetch(),params:params={},pagingParams:pagingParams={},principal:principal,usePost:usePost=!1,responseType:responseType="json"}=options;let url=options.url;if(url.startsWith("http:")){if(!allowHttpRequests)throw new Error(`Requests to insecure portal are not supported. Url: ${url}`);"https:"===window.location.protocol&&(url=url.replace(/^http:/i,"https:"))}const principalUrl=principal.credentials?.url,isAGOUrl=isArcGISOnlineUrl(url),isAGOPrincipalUrl=principalUrl&&isArcGISOnlineUrl(principalUrl),finalParams={...params,...pagingParams,f:"json"};if(isAGOUrl&&isAGOPrincipalUrl||principalUrl&&url.toLowerCase().startsWith(principalUrl.toLowerCase())){let updatedPrincipal;if(refresh){if(updatedPrincipal=await refresh(principal),!updatedPrincipal)throw new Error(`Could not update principal credentials during request to ${url}`)}else warn("Principal Refresh function not set, see `setRefreshFunction` for details.");const token=getToken(updatedPrincipal??principal);token&&(finalParams.token=token)}const useFormData=Object.keys(finalParams).some((key=>finalParams[key]instanceof Blob||"function"==typeof Buffer&&finalParams[key]instanceof Buffer));let paramsAsQuery="";const formData=new FormData;for(const[key,value]of Object.entries(finalParams))null!=value&&(useFormData?value instanceof Blob&&value.name?formData.append(key,value,value.name):formData.append(key,value):paramsAsQuery=`${paramsAsQuery}${key}=${encodeURIComponent(value)}&`);paramsAsQuery.endsWith("&")&&(paramsAsQuery=paramsAsQuery.slice(0,-1));let finalUrl=url;const init={credentials:isArcGISOnlineUrl(finalUrl)?void 0:"include"};usePost?(init.method="POST",useFormData?init.body=formData:(init.body=paramsAsQuery,init.headers={"Content-Type":"application/x-www-form-urlencoded"})):finalUrl=`${finalUrl}?${paramsAsQuery}`;const response=await fetch(finalUrl,init);let error,result,responseCopy=response;"json"!==responseType&&(responseCopy=response.clone());try{result=await responseCopy.json(),error=result.error}catch{}if(error){const err=new Error(error.message);throw err.response=result,err}switch(responseType){case"json":return result;case"blob":return await response.blob();case"text":return await response.text();default:throw assertNever(responseType),new Error(`Unknown response type: ${responseType}`)}}function assertNever(x){}export default request;
|