@esri/hub-common 28.5.0 → 28.6.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 (85) hide show
  1. package/dist/esm/core/_internal/getBasePropertyMap.js +4 -0
  2. package/dist/esm/core/_internal/getBasePropertyMap.js.map +1 -1
  3. package/dist/esm/core/traits/IWithVersions.js +2 -0
  4. package/dist/esm/core/traits/IWithVersions.js.map +1 -0
  5. package/dist/esm/index.js +3 -0
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/layouts/fetchHubEntityLayouts.js +30 -0
  8. package/dist/esm/layouts/fetchHubEntityLayouts.js.map +1 -0
  9. package/dist/esm/layouts/internal/upsertLayoutAssetResource.js +72 -0
  10. package/dist/esm/layouts/internal/upsertLayoutAssetResource.js.map +1 -0
  11. package/dist/esm/layouts/publishHubEntityLayout.js +82 -0
  12. package/dist/esm/layouts/publishHubEntityLayout.js.map +1 -0
  13. package/dist/esm/layouts/types.js +1 -1
  14. package/dist/esm/layouts/types.js.map +1 -1
  15. package/dist/esm/projects/edit.js +0 -2
  16. package/dist/esm/projects/edit.js.map +1 -1
  17. package/dist/esm/resources/addHubEntityResource.js +36 -0
  18. package/dist/esm/resources/addHubEntityResource.js.map +1 -0
  19. package/dist/esm/resources/addResource.js +37 -0
  20. package/dist/esm/resources/addResource.js.map +1 -0
  21. package/dist/esm/resources/fetchHubEntityResource.js +37 -0
  22. package/dist/esm/resources/fetchHubEntityResource.js.map +1 -0
  23. package/dist/esm/resources/fetchHubEntityResources.js +37 -0
  24. package/dist/esm/resources/fetchHubEntityResources.js.map +1 -0
  25. package/dist/esm/resources/removeHubEntityResource.js +33 -0
  26. package/dist/esm/resources/removeHubEntityResource.js.map +1 -0
  27. package/dist/esm/resources/upsertHubEntityResource.js +34 -0
  28. package/dist/esm/resources/upsertHubEntityResource.js.map +1 -0
  29. package/dist/node/core/_internal/getBasePropertyMap.js +4 -0
  30. package/dist/node/core/_internal/getBasePropertyMap.js.map +1 -1
  31. package/dist/node/core/traits/IWithVersions.js +3 -0
  32. package/dist/node/core/traits/IWithVersions.js.map +1 -0
  33. package/dist/node/index.js +7 -1
  34. package/dist/node/index.js.map +1 -1
  35. package/dist/node/layouts/fetchHubEntityLayouts.js +33 -0
  36. package/dist/node/layouts/fetchHubEntityLayouts.js.map +1 -0
  37. package/dist/node/layouts/internal/upsertLayoutAssetResource.js +75 -0
  38. package/dist/node/layouts/internal/upsertLayoutAssetResource.js.map +1 -0
  39. package/dist/node/layouts/publishHubEntityLayout.js +85 -0
  40. package/dist/node/layouts/publishHubEntityLayout.js.map +1 -0
  41. package/dist/node/layouts/types.js +2 -0
  42. package/dist/node/layouts/types.js.map +1 -1
  43. package/dist/node/projects/edit.js +0 -2
  44. package/dist/node/projects/edit.js.map +1 -1
  45. package/dist/node/resources/addHubEntityResource.js +39 -0
  46. package/dist/node/resources/addHubEntityResource.js.map +1 -0
  47. package/dist/node/resources/addResource.js +40 -0
  48. package/dist/node/resources/addResource.js.map +1 -0
  49. package/dist/node/resources/fetchHubEntityResource.js +40 -0
  50. package/dist/node/resources/fetchHubEntityResource.js.map +1 -0
  51. package/dist/node/resources/fetchHubEntityResources.js +40 -0
  52. package/dist/node/resources/fetchHubEntityResources.js.map +1 -0
  53. package/dist/node/resources/removeHubEntityResource.js +36 -0
  54. package/dist/node/resources/removeHubEntityResource.js.map +1 -0
  55. package/dist/node/resources/upsertHubEntityResource.js +37 -0
  56. package/dist/node/resources/upsertHubEntityResource.js.map +1 -0
  57. package/dist/types/content/_internal/internalContentUtils.d.ts +1 -1
  58. package/dist/types/core/traits/IWithVersions.d.ts +5 -0
  59. package/dist/types/core/types/IHubItemEntity.d.ts +2 -1
  60. package/dist/types/index.d.ts +4 -1
  61. package/dist/types/layouts/fetchHubEntityLayouts.d.ts +16 -0
  62. package/dist/types/layouts/internal/upsertLayoutAssetResource.d.ts +27 -0
  63. package/dist/types/layouts/layout-event-types.d.ts +2 -1
  64. package/dist/types/layouts/migrations/types/ILayoutV2.d.ts +3 -0
  65. package/dist/types/layouts/publishHubEntityLayout.d.ts +29 -0
  66. package/dist/types/layouts/types.d.ts +5 -0
  67. package/dist/types/resources/addHubEntityResource.d.ts +19 -0
  68. package/dist/types/resources/addResource.d.ts +18 -0
  69. package/dist/types/resources/fetchHubEntityResource.d.ts +15 -0
  70. package/dist/types/resources/fetchHubEntityResources.d.ts +17 -0
  71. package/dist/types/resources/removeHubEntityResource.d.ts +18 -0
  72. package/dist/types/resources/upsertHubEntityResource.d.ts +20 -0
  73. package/dist/types/versioning/types/IVersion.d.ts +6 -2
  74. package/dist/types/versioning/types/IVersionMetadata.d.ts +10 -0
  75. package/package.json +3 -3
  76. package/dist/esm/layouts/updateLayout.js +0 -33
  77. package/dist/esm/layouts/updateLayout.js.map +0 -1
  78. package/dist/esm/layouts/upsertLayoutResource.js +0 -78
  79. package/dist/esm/layouts/upsertLayoutResource.js.map +0 -1
  80. package/dist/node/layouts/updateLayout.js +0 -36
  81. package/dist/node/layouts/updateLayout.js.map +0 -1
  82. package/dist/node/layouts/upsertLayoutResource.js +0 -81
  83. package/dist/node/layouts/upsertLayoutResource.js.map +0 -1
  84. package/dist/types/layouts/updateLayout.d.ts +0 -4
  85. package/dist/types/layouts/upsertLayoutResource.d.ts +0 -26
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateLayout = updateLayout;
4
- const util_js_1 = require("../util.js");
5
- const upsertLayoutResource_js_1 = require("./upsertLayoutResource.js");
6
- async function updateLayout(entity, layout, requestOptions) {
7
- if (!layout) {
8
- return layout;
9
- }
10
- const updatedLayout = (0, util_js_1.cloneObject)(layout);
11
- // check the variables and for each one that is of type image and... has a source, a blob?
12
- // we need to upload the image as a resource and update the variable.value to point to the resource and remove all other properties except type
13
- await Promise.all(Object.entries(updatedLayout.variables || {}).map(async ([key, _variable]) => {
14
- const variable = _variable;
15
- if (variable.type === "image") {
16
- if (variable.source === "upload" && !!variable.blob) {
17
- const newVariable = {
18
- type: variable.type,
19
- };
20
- const resourceUrl = await (0, upsertLayoutResource_js_1.upsertLayoutResource)(entity.id, entity.owner, variable.blob, key, // this is something like <nodeId>-image-card
21
- variable.format, requestOptions);
22
- // set the value to the resource name
23
- newVariable.value = { $ref: resourceUrl };
24
- updatedLayout.variables[key] = newVariable;
25
- }
26
- }
27
- }));
28
- /*
29
- TODO: we will also need to clean up any old resources that are no longer referenced
30
- - make sure when we delete it in the ui, we get rid of the variable
31
- - then when we save, we delete any resources for which there is no variable
32
- - when an image card is changed from an upload to a url, we will handle it similarly
33
- */
34
- return updatedLayout;
35
- }
36
- //# sourceMappingURL=updateLayout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateLayout.js","sourceRoot":"","sources":["../../../src/layouts/updateLayout.ts"],"names":[],"mappings":";;AAMA,oCAgDC;AApDD,wCAAyC;AAEzC,uEAAiE;AAE1D,KAAK,UAAU,YAAY,CAChC,MAAsB,EACtB,MAAe,EACf,cAAmC;IAEnC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,aAAa,GAAG,IAAA,qBAAW,EAAC,MAAM,CAAC,CAAC;IAE1C,0FAA0F;IAC1F,+IAA+I;IAC/I,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAC/C,KAAK,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE;QACzB,MAAM,QAAQ,GAAG,SAAoC,CAAC;QACtD,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC9B,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACpD,MAAM,WAAW,GAA4B;oBAC3C,IAAI,EAAE,QAAQ,CAAC,IAAI;iBACpB,CAAC;gBAEF,MAAM,WAAW,GAAG,MAAM,IAAA,8CAAoB,EAC5C,MAAM,CAAC,EAAE,EACT,MAAM,CAAC,KAAK,EACZ,QAAQ,CAAC,IAAI,EACb,GAAG,EAAE,6CAA6C;gBAClD,QAAQ,CAAC,MAAgB,EACzB,cAAc,CACf,CAAC;gBACF,qCAAqC;gBACrC,WAAW,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;gBAC1C,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC,CACF,CACF,CAAC;IAEF;;;;;MAKE;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upsertLayoutResource = upsertLayoutResource;
4
- const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
5
- const HubError_1 = require("../HubError");
6
- const object_to_json_blob_1 = require("../resources/object-to-json-blob");
7
- const string_to_blob_1 = require("../resources/string-to-blob");
8
- const removeResource_1 = require("../resources/removeResource");
9
- /**
10
- * Given an item, and owner, Search for if the resource exists
11
- * and if does, update it, otherwise add it. Returns a url for the item.
12
- *
13
- * Note that layout resources are typically stored with
14
- * - a "layout/" prefix (so we can find them)
15
- * - a name that starts with the cardId
16
- * - and a -{timestamp} suffix (to bust the cache)
17
- * thus 'update' is not really an update, it is:
18
- * - upload the new one
19
- * - then find the old one (which has a different suffix) and delete it.
20
- *
21
- * this is why we cannot simply use upsertResource
22
-
23
- *
24
- * @export
25
- * @param {string} id
26
- * @param {string} owner
27
- * @param {*} resource
28
- * @param {string} name
29
- * @param {string} extension
30
- * @param {IUserRequestOptions} ro
31
- * @return {*} {Promise<string>}
32
- */
33
- async function upsertLayoutResource(id, owner, resource, name, extension, ro) {
34
- try {
35
- const prefix = "layout";
36
- // construct resource name
37
- // the key is of the form <nodeId>-image-card
38
- // we also append a unique timestamp to avoid caching issues
39
- const resourceName = `${name}-${Date.now()}.${extension}`;
40
- // JSON and text resources have....odd things happen
41
- // to them when they are added as resources and NOT
42
- // converted to blobs. Thus we convert them to blobs
43
- let resourceToUpload = resource;
44
- if (extension === "json") {
45
- resourceToUpload = (0, object_to_json_blob_1.objectToJsonBlob)(resource);
46
- }
47
- if (extension === "txt") {
48
- resourceToUpload = (0, string_to_blob_1.stringToBlob)(resource);
49
- }
50
- // Add item resource
51
- // we do not check for existence first, because
52
- // our resource names are unique (timestamped)
53
- const response = await (0, arcgis_rest_portal_1.addItemResource)(Object.assign({ id,
54
- owner, resource: resourceToUpload, name: resourceName, prefix }, ro));
55
- // if err throw
56
- if (!response.success) {
57
- throw new HubError_1.default("Add Item Resource", `Error adding resource ${name} to item ${id}.`);
58
- }
59
- // then delete the old one if it exists
60
- const resources = await (0, arcgis_rest_portal_1.getItemResources)(id, ro);
61
- const foundResource = resources.resources.find((res) => {
62
- return (res.resource.startsWith(`${prefix}/${name}`) &&
63
- res.resource !== `${prefix}/${resourceName}`);
64
- });
65
- if (foundResource) {
66
- await (0, removeResource_1.removeResource)(id, foundResource.resource, owner, ro);
67
- }
68
- // return url
69
- // resourceUrl://:id/:prefix/:filename
70
- return `resourceUrl://${id}/${prefix}/${resourceName}`;
71
- }
72
- catch (err) {
73
- if (err instanceof Error) {
74
- throw new HubError_1.default("Add Item Resource", err.message, err);
75
- }
76
- else {
77
- throw new HubError_1.default("Add Item Resource", `Error adding resource ${name} to item ${id}.`);
78
- }
79
- }
80
- }
81
- //# sourceMappingURL=upsertLayoutResource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"upsertLayoutResource.js","sourceRoot":"","sources":["../../../src/layouts/upsertLayoutResource.ts"],"names":[],"mappings":";;AA+BA,oDAuEC;AArGD,iEAA6E;AAC7E,0CAAmC;AACnC,0EAAoE;AACpE,gEAA2D;AAC3D,gEAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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AC;gBAC5C,GAAG,CAAC,QAAQ,KAAK,GAAG,MAAM,IAAI,YAAY,EAAE,CAC7C,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,IAAA,+BAAc,EAAC,EAAE,EAAE,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC9D,CAAC;QAED,aAAa;QACb,sCAAsC;QACtC,OAAO,iBAAiB,EAAE,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;IACzD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,kBAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,kBAAQ,CAChB,mBAAmB,EACnB,yBAAyB,IAAI,YAAY,EAAE,GAAG,CAC/C,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,4 +0,0 @@
1
- import { IUserRequestOptions } from "@esri/arcgis-rest-request";
2
- import { IHubItemEntity } from "../core/types/IHubItemEntity.js";
3
- import { ILayout } from "./types.js";
4
- export declare function updateLayout(entity: IHubItemEntity, layout: ILayout, requestOptions: IUserRequestOptions): Promise<ILayout>;
@@ -1,26 +0,0 @@
1
- import type { IUserRequestOptions } from "@esri/arcgis-rest-request";
2
- /**
3
- * Given an item, and owner, Search for if the resource exists
4
- * and if does, update it, otherwise add it. Returns a url for the item.
5
- *
6
- * Note that layout resources are typically stored with
7
- * - a "layout/" prefix (so we can find them)
8
- * - a name that starts with the cardId
9
- * - and a -{timestamp} suffix (to bust the cache)
10
- * thus 'update' is not really an update, it is:
11
- * - upload the new one
12
- * - then find the old one (which has a different suffix) and delete it.
13
- *
14
- * this is why we cannot simply use upsertResource
15
-
16
- *
17
- * @export
18
- * @param {string} id
19
- * @param {string} owner
20
- * @param {*} resource
21
- * @param {string} name
22
- * @param {string} extension
23
- * @param {IUserRequestOptions} ro
24
- * @return {*} {Promise<string>}
25
- */
26
- export declare function upsertLayoutResource(id: string, owner: string, resource: unknown, name: string, extension: string, ro: IUserRequestOptions): Promise<string>;