@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.
Files changed (52) hide show
  1. package/dist/es2017/content/_internal.js +28 -1
  2. package/dist/es2017/content/_internal.js.map +1 -1
  3. package/dist/es2017/content/compose.js +27 -23
  4. package/dist/es2017/content/compose.js.map +1 -1
  5. package/dist/es2017/content/fetch.js +25 -5
  6. package/dist/es2017/content/fetch.js.map +1 -1
  7. package/dist/es2017/resources/_internal/_validate-url-helpers.js +231 -0
  8. package/dist/es2017/resources/_internal/_validate-url-helpers.js.map +1 -0
  9. package/dist/es2017/resources/index.js +1 -0
  10. package/dist/es2017/resources/index.js.map +1 -1
  11. package/dist/es2017/resources/validate-url.js +86 -0
  12. package/dist/es2017/resources/validate-url.js.map +1 -0
  13. package/dist/es2017/types.js +862 -0
  14. package/dist/es2017/types.js.map +1 -1
  15. package/dist/esm/content/_internal.js +28 -1
  16. package/dist/esm/content/_internal.js.map +1 -1
  17. package/dist/esm/content/compose.js +27 -23
  18. package/dist/esm/content/compose.js.map +1 -1
  19. package/dist/esm/content/fetch.js +29 -11
  20. package/dist/esm/content/fetch.js.map +1 -1
  21. package/dist/esm/resources/_internal/_validate-url-helpers.js +249 -0
  22. package/dist/esm/resources/_internal/_validate-url-helpers.js.map +1 -0
  23. package/dist/esm/resources/index.js +1 -0
  24. package/dist/esm/resources/index.js.map +1 -1
  25. package/dist/esm/resources/validate-url.js +103 -0
  26. package/dist/esm/resources/validate-url.js.map +1 -0
  27. package/dist/esm/types.js +862 -0
  28. package/dist/esm/types.js.map +1 -1
  29. package/dist/node/content/_internal.js +28 -1
  30. package/dist/node/content/_internal.js.map +1 -1
  31. package/dist/node/content/compose.js +26 -22
  32. package/dist/node/content/compose.js.map +1 -1
  33. package/dist/node/content/fetch.js +23 -3
  34. package/dist/node/content/fetch.js.map +1 -1
  35. package/dist/node/resources/_internal/_validate-url-helpers.js +247 -0
  36. package/dist/node/resources/_internal/_validate-url-helpers.js.map +1 -0
  37. package/dist/node/resources/index.js +1 -0
  38. package/dist/node/resources/index.js.map +1 -1
  39. package/dist/node/resources/validate-url.js +90 -0
  40. package/dist/node/resources/validate-url.js.map +1 -0
  41. package/dist/node/types.js +863 -0
  42. package/dist/node/types.js.map +1 -1
  43. package/dist/types/content/_internal.d.ts +21 -3
  44. package/dist/types/resources/_internal/_validate-url-helpers.d.ts +115 -0
  45. package/dist/types/resources/index.d.ts +1 -0
  46. package/dist/types/resources/validate-url.d.ts +8 -0
  47. package/dist/types/types.d.ts +225 -4
  48. package/dist/umd/common.umd.js +1317 -35
  49. package/dist/umd/common.umd.js.map +1 -1
  50. package/dist/umd/common.umd.min.js +1 -1
  51. package/dist/umd/common.umd.min.js.map +1 -1
  52. package/package.json +1 -1
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateUrl = void 0;
4
+ const types_1 = require("../types");
5
+ const utils_1 = require("../utils");
6
+ const _validate_url_helpers_1 = require("./_internal/_validate-url-helpers");
7
+ /**
8
+ * Takes in a URL and validates it based on valid url, type of item, etc
9
+ *
10
+ * @export
11
+ * @param {string} url
12
+ * @return {*} {Promise<any>}
13
+ */
14
+ async function validateUrl(url) {
15
+ // If URL doesn't pass then exit out immediately.
16
+ if (!_validate_url_helpers_1.isUrl(url)) {
17
+ return {
18
+ pass: false,
19
+ error: "invalidFormat",
20
+ };
21
+ }
22
+ // Check if it's a FS, Map service, or image service
23
+ const isFeatureServiceUrl = _validate_url_helpers_1.isFeatureService(url);
24
+ const isServiceUrl = _validate_url_helpers_1.isService(url);
25
+ if (isServiceUrl && !isFeatureServiceUrl) {
26
+ return {
27
+ pass: false,
28
+ error: "invalidFormat",
29
+ };
30
+ }
31
+ // Content type which can be determined bby the url file extnesion or the request response header
32
+ let type;
33
+ let item;
34
+ let pingResult = {};
35
+ try {
36
+ pingResult = isFeatureServiceUrl
37
+ ? await _validate_url_helpers_1.pingFeatureService(url)
38
+ : await _validate_url_helpers_1.pingUrl(url);
39
+ // return an error if the response is not okay
40
+ if (!pingResult.ok) {
41
+ return {
42
+ pass: false,
43
+ error: "invalidUrl",
44
+ };
45
+ }
46
+ }
47
+ catch (e) {
48
+ // TODO: This is tricky. The fetch() API rejects when a network error
49
+ // happens. This error can be a CORS error, or a 404 error, or a timeout
50
+ // error. While an error like 404 does suggest a bad URL, the CORS occurs
51
+ // because this is a front-end request and the file is likely accessible by
52
+ // the server. Unfortunately, the error doesn't have any information about
53
+ // underline failure type. For now, the network failure is ignored, so the
54
+ // user can paste a URL from any domain and avoid the CORS issue.
55
+ utils_1.Logger.error(`error requesting url`);
56
+ }
57
+ // Use the metadata from the ping response if exists, otherwise guess the file
58
+ // name from the URL
59
+ if (pingResult.item) {
60
+ item = pingResult.item;
61
+ }
62
+ else {
63
+ item = { title: _validate_url_helpers_1.getFileName(url), url };
64
+ }
65
+ if (pingResult.headers) {
66
+ type = _validate_url_helpers_1.detectDataTypeFromHeader(pingResult.headers);
67
+ }
68
+ if (isFeatureServiceUrl) {
69
+ type = types_1.ItemType["Feature Service"];
70
+ }
71
+ else if (!type) {
72
+ // Guess the data type from the extension
73
+ type = _validate_url_helpers_1.detectDataTypeFromExtension(url);
74
+ }
75
+ if (type) {
76
+ item.type = type;
77
+ }
78
+ if (item.type && _validate_url_helpers_1.shouldHaveDataUrl(item.type)) {
79
+ item.dataUrl = item.url;
80
+ }
81
+ return {
82
+ pass: true,
83
+ // The type may or may not be true
84
+ type,
85
+ // fetched / calculated item
86
+ item,
87
+ };
88
+ }
89
+ exports.validateUrl = validateUrl;
90
+ //# 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,oCAAoC;AACpC,oCAAkC;AAClC,6EAU2C;AAE3C;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAA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