@esri/hub-common 9.25.5 → 9.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es2017/content/_internal.js +28 -1
- package/dist/es2017/content/_internal.js.map +1 -1
- package/dist/es2017/content/compose.js +27 -23
- package/dist/es2017/content/compose.js.map +1 -1
- package/dist/es2017/content/fetch.js +25 -5
- package/dist/es2017/content/fetch.js.map +1 -1
- package/dist/es2017/resources/_internal/_validate-url-helpers.js +231 -0
- package/dist/es2017/resources/_internal/_validate-url-helpers.js.map +1 -0
- package/dist/es2017/resources/index.js +1 -0
- package/dist/es2017/resources/index.js.map +1 -1
- package/dist/es2017/resources/validate-url.js +86 -0
- package/dist/es2017/resources/validate-url.js.map +1 -0
- package/dist/es2017/types.js +862 -0
- package/dist/es2017/types.js.map +1 -1
- package/dist/esm/content/_internal.js +28 -1
- package/dist/esm/content/_internal.js.map +1 -1
- package/dist/esm/content/compose.js +27 -23
- package/dist/esm/content/compose.js.map +1 -1
- package/dist/esm/content/fetch.js +29 -11
- package/dist/esm/content/fetch.js.map +1 -1
- package/dist/esm/resources/_internal/_validate-url-helpers.js +249 -0
- package/dist/esm/resources/_internal/_validate-url-helpers.js.map +1 -0
- package/dist/esm/resources/index.js +1 -0
- package/dist/esm/resources/index.js.map +1 -1
- package/dist/esm/resources/validate-url.js +103 -0
- package/dist/esm/resources/validate-url.js.map +1 -0
- package/dist/esm/types.js +862 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/node/content/_internal.js +28 -1
- package/dist/node/content/_internal.js.map +1 -1
- package/dist/node/content/compose.js +26 -22
- package/dist/node/content/compose.js.map +1 -1
- package/dist/node/content/fetch.js +23 -3
- package/dist/node/content/fetch.js.map +1 -1
- package/dist/node/resources/_internal/_validate-url-helpers.js +247 -0
- package/dist/node/resources/_internal/_validate-url-helpers.js.map +1 -0
- package/dist/node/resources/index.js +1 -0
- package/dist/node/resources/index.js.map +1 -1
- package/dist/node/resources/validate-url.js +90 -0
- package/dist/node/resources/validate-url.js.map +1 -0
- package/dist/node/types.js +863 -0
- package/dist/node/types.js.map +1 -1
- package/dist/types/content/_internal.d.ts +21 -3
- package/dist/types/resources/_internal/_validate-url-helpers.d.ts +115 -0
- package/dist/types/resources/index.d.ts +1 -0
- package/dist/types/resources/validate-url.d.ts +8 -0
- package/dist/types/types.d.ts +225 -4
- package/dist/umd/common.umd.js +1317 -35
- package/dist/umd/common.umd.js.map +1 -1
- package/dist/umd/common.umd.min.js +1 -1
- package/dist/umd/common.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ItemType } from "../types";
|
|
2
|
+
import { Logger } from "../utils";
|
|
3
|
+
import { isUrl, isFeatureService, isService, pingFeatureService, pingUrl, detectDataTypeFromHeader, getFileName, detectDataTypeFromExtension, shouldHaveDataUrl, } from "./_internal/_validate-url-helpers";
|
|
4
|
+
/**
|
|
5
|
+
* Takes in a URL and validates it based on valid url, type of item, etc
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @param {string} url
|
|
9
|
+
* @return {*} {Promise<any>}
|
|
10
|
+
*/
|
|
11
|
+
export async function validateUrl(url) {
|
|
12
|
+
// If URL doesn't pass then exit out immediately.
|
|
13
|
+
if (!isUrl(url)) {
|
|
14
|
+
return {
|
|
15
|
+
pass: false,
|
|
16
|
+
error: "invalidFormat",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Check if it's a FS, Map service, or image service
|
|
20
|
+
const isFeatureServiceUrl = isFeatureService(url);
|
|
21
|
+
const isServiceUrl = isService(url);
|
|
22
|
+
if (isServiceUrl && !isFeatureServiceUrl) {
|
|
23
|
+
return {
|
|
24
|
+
pass: false,
|
|
25
|
+
error: "invalidFormat",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Content type which can be determined bby the url file extnesion or the request response header
|
|
29
|
+
let type;
|
|
30
|
+
let item;
|
|
31
|
+
let pingResult = {};
|
|
32
|
+
try {
|
|
33
|
+
pingResult = isFeatureServiceUrl
|
|
34
|
+
? await pingFeatureService(url)
|
|
35
|
+
: await pingUrl(url);
|
|
36
|
+
// return an error if the response is not okay
|
|
37
|
+
if (!pingResult.ok) {
|
|
38
|
+
return {
|
|
39
|
+
pass: false,
|
|
40
|
+
error: "invalidUrl",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// TODO: This is tricky. The fetch() API rejects when a network error
|
|
46
|
+
// happens. This error can be a CORS error, or a 404 error, or a timeout
|
|
47
|
+
// error. While an error like 404 does suggest a bad URL, the CORS occurs
|
|
48
|
+
// because this is a front-end request and the file is likely accessible by
|
|
49
|
+
// the server. Unfortunately, the error doesn't have any information about
|
|
50
|
+
// underline failure type. For now, the network failure is ignored, so the
|
|
51
|
+
// user can paste a URL from any domain and avoid the CORS issue.
|
|
52
|
+
Logger.error(`error requesting url`);
|
|
53
|
+
}
|
|
54
|
+
// Use the metadata from the ping response if exists, otherwise guess the file
|
|
55
|
+
// name from the URL
|
|
56
|
+
if (pingResult.item) {
|
|
57
|
+
item = pingResult.item;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
item = { title: getFileName(url), url };
|
|
61
|
+
}
|
|
62
|
+
if (pingResult.headers) {
|
|
63
|
+
type = detectDataTypeFromHeader(pingResult.headers);
|
|
64
|
+
}
|
|
65
|
+
if (isFeatureServiceUrl) {
|
|
66
|
+
type = ItemType["Feature Service"];
|
|
67
|
+
}
|
|
68
|
+
else if (!type) {
|
|
69
|
+
// Guess the data type from the extension
|
|
70
|
+
type = detectDataTypeFromExtension(url);
|
|
71
|
+
}
|
|
72
|
+
if (type) {
|
|
73
|
+
item.type = type;
|
|
74
|
+
}
|
|
75
|
+
if (item.type && shouldHaveDataUrl(item.type)) {
|
|
76
|
+
item.dataUrl = item.url;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
pass: true,
|
|
80
|
+
// The type may or may not be true
|
|
81
|
+
type,
|
|
82
|
+
// fetched / calculated item
|
|
83
|
+
item,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=validate-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-url.js","sourceRoot":"","sources":["../../../src/resources/validate-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,wBAAwB,EACxB,WAAW,EACX,2BAA2B,EAC3B,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAW;IAC3C,iDAAiD;IACjD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACf,OAAO;YACL,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,eAAe;SACvB,CAAC;KACH;IAED,oDAAoD;IACpD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAEpC,IAAI,YAAY,IAAI,CAAC,mBAAmB,EAAE;QACxC,OAAO;YACL,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,eAAe;SACvB,CAAC;KACH;IAED,iGAAiG;IACjG,IAAI,IAAI,CAAC;IAET,IAAI,IAAI,CAAC;IAET,IAAI,UAAU,GAA4D,EAAE,CAAC;IAE7E,IAAI;QACF,UAAU,GAAG,mBAAmB;YAC9B,CAAC,CAAC,MAAM,kBAAkB,CAAC,GAAG,CAAC;YAC/B,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;QAEvB,8CAA8C;QAC9C,IAAI,CAAC,U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