@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.
- package/dist/esm/core/_internal/getBasePropertyMap.js +4 -0
- package/dist/esm/core/_internal/getBasePropertyMap.js.map +1 -1
- package/dist/esm/core/traits/IWithVersions.js +2 -0
- package/dist/esm/core/traits/IWithVersions.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layouts/fetchHubEntityLayouts.js +30 -0
- package/dist/esm/layouts/fetchHubEntityLayouts.js.map +1 -0
- package/dist/esm/layouts/internal/upsertLayoutAssetResource.js +72 -0
- package/dist/esm/layouts/internal/upsertLayoutAssetResource.js.map +1 -0
- package/dist/esm/layouts/publishHubEntityLayout.js +82 -0
- package/dist/esm/layouts/publishHubEntityLayout.js.map +1 -0
- package/dist/esm/layouts/types.js +1 -1
- package/dist/esm/layouts/types.js.map +1 -1
- package/dist/esm/projects/edit.js +0 -2
- package/dist/esm/projects/edit.js.map +1 -1
- package/dist/esm/resources/addHubEntityResource.js +36 -0
- package/dist/esm/resources/addHubEntityResource.js.map +1 -0
- package/dist/esm/resources/addResource.js +37 -0
- package/dist/esm/resources/addResource.js.map +1 -0
- package/dist/esm/resources/fetchHubEntityResource.js +37 -0
- package/dist/esm/resources/fetchHubEntityResource.js.map +1 -0
- package/dist/esm/resources/fetchHubEntityResources.js +37 -0
- package/dist/esm/resources/fetchHubEntityResources.js.map +1 -0
- package/dist/esm/resources/removeHubEntityResource.js +33 -0
- package/dist/esm/resources/removeHubEntityResource.js.map +1 -0
- package/dist/esm/resources/upsertHubEntityResource.js +34 -0
- package/dist/esm/resources/upsertHubEntityResource.js.map +1 -0
- package/dist/node/core/_internal/getBasePropertyMap.js +4 -0
- package/dist/node/core/_internal/getBasePropertyMap.js.map +1 -1
- package/dist/node/core/traits/IWithVersions.js +3 -0
- package/dist/node/core/traits/IWithVersions.js.map +1 -0
- package/dist/node/index.js +7 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/layouts/fetchHubEntityLayouts.js +33 -0
- package/dist/node/layouts/fetchHubEntityLayouts.js.map +1 -0
- package/dist/node/layouts/internal/upsertLayoutAssetResource.js +75 -0
- package/dist/node/layouts/internal/upsertLayoutAssetResource.js.map +1 -0
- package/dist/node/layouts/publishHubEntityLayout.js +85 -0
- package/dist/node/layouts/publishHubEntityLayout.js.map +1 -0
- package/dist/node/layouts/types.js +2 -0
- package/dist/node/layouts/types.js.map +1 -1
- package/dist/node/projects/edit.js +0 -2
- package/dist/node/projects/edit.js.map +1 -1
- package/dist/node/resources/addHubEntityResource.js +39 -0
- package/dist/node/resources/addHubEntityResource.js.map +1 -0
- package/dist/node/resources/addResource.js +40 -0
- package/dist/node/resources/addResource.js.map +1 -0
- package/dist/node/resources/fetchHubEntityResource.js +40 -0
- package/dist/node/resources/fetchHubEntityResource.js.map +1 -0
- package/dist/node/resources/fetchHubEntityResources.js +40 -0
- package/dist/node/resources/fetchHubEntityResources.js.map +1 -0
- package/dist/node/resources/removeHubEntityResource.js +36 -0
- package/dist/node/resources/removeHubEntityResource.js.map +1 -0
- package/dist/node/resources/upsertHubEntityResource.js +37 -0
- package/dist/node/resources/upsertHubEntityResource.js.map +1 -0
- package/dist/types/content/_internal/internalContentUtils.d.ts +1 -1
- package/dist/types/core/traits/IWithVersions.d.ts +5 -0
- package/dist/types/core/types/IHubItemEntity.d.ts +2 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/layouts/fetchHubEntityLayouts.d.ts +16 -0
- package/dist/types/layouts/internal/upsertLayoutAssetResource.d.ts +27 -0
- package/dist/types/layouts/layout-event-types.d.ts +2 -1
- package/dist/types/layouts/migrations/types/ILayoutV2.d.ts +3 -0
- package/dist/types/layouts/publishHubEntityLayout.d.ts +29 -0
- package/dist/types/layouts/types.d.ts +5 -0
- package/dist/types/resources/addHubEntityResource.d.ts +19 -0
- package/dist/types/resources/addResource.d.ts +18 -0
- package/dist/types/resources/fetchHubEntityResource.d.ts +15 -0
- package/dist/types/resources/fetchHubEntityResources.d.ts +17 -0
- package/dist/types/resources/removeHubEntityResource.d.ts +18 -0
- package/dist/types/resources/upsertHubEntityResource.d.ts +20 -0
- package/dist/types/versioning/types/IVersion.d.ts +6 -2
- package/dist/types/versioning/types/IVersionMetadata.d.ts +10 -0
- package/package.json +3 -3
- package/dist/esm/layouts/updateLayout.js +0 -33
- package/dist/esm/layouts/updateLayout.js.map +0 -1
- package/dist/esm/layouts/upsertLayoutResource.js +0 -78
- package/dist/esm/layouts/upsertLayoutResource.js.map +0 -1
- package/dist/node/layouts/updateLayout.js +0 -36
- package/dist/node/layouts/updateLayout.js.map +0 -1
- package/dist/node/layouts/upsertLayoutResource.js +0 -81
- package/dist/node/layouts/upsertLayoutResource.js.map +0 -1
- package/dist/types/layouts/updateLayout.d.ts +0 -4
- package/dist/types/layouts/upsertLayoutResource.d.ts +0 -26
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchHubEntityResources = fetchHubEntityResources;
|
|
4
|
+
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
|
|
5
|
+
const HubError_1 = require("../HubError");
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a Hub entity's resources. This util handles
|
|
8
|
+
* delegating to the correct resource fetching logic
|
|
9
|
+
* based on the entity type.
|
|
10
|
+
*
|
|
11
|
+
* @param type - type of the entity to fetch the resources for
|
|
12
|
+
* @param identifier - id of the entity to fetch the resources for
|
|
13
|
+
* @param context - contextual portal and auth information
|
|
14
|
+
* @returns the fetched resources
|
|
15
|
+
* @throws {HubError} if there is an error during the fetch process or if fetching is not yet implemented for the entity type
|
|
16
|
+
*/
|
|
17
|
+
async function fetchHubEntityResources(type, identifier, context) {
|
|
18
|
+
let resources = [];
|
|
19
|
+
if (type === "event") {
|
|
20
|
+
// TODO: add logic to fetch event resources
|
|
21
|
+
throw new HubError_1.default("fetchHubEntityResource", "Fetching event resources is not yet implemented");
|
|
22
|
+
}
|
|
23
|
+
else if (type === "group") {
|
|
24
|
+
// TODO: add logic to fetch group resources once
|
|
25
|
+
// supported by portal
|
|
26
|
+
throw new HubError_1.default("fetchHubEntityResource", "Fetching group resources is not yet supported");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// default to item-based resource fetching for item-backed entities
|
|
30
|
+
try {
|
|
31
|
+
const res = await (0, arcgis_rest_portal_1.getItemResources)(identifier, context.requestOptions);
|
|
32
|
+
resources = res.resources.map((resource) => (Object.assign(Object.assign({}, resource), { name: resource.resource })));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new HubError_1.default("Get Item Resources", `Failed to fetch resources for ${type} with identifier ${identifier}`, error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return resources;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=fetchHubEntityResources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchHubEntityResources.js","sourceRoot":"","sources":["../../../src/resources/fetchHubEntityResources.ts"],"names":[],"mappings":";;AAgBA,0DAqCC;AArDD,iEAA4D;AAG5D,0CAAmC;AAEnC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,uBAAuB,CAC3C,IAAmB,EACnB,UAAkB,EAClB,OAAuB;IAEvB,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,2CAA2C;QAC3C,MAAM,IAAI,kBAAQ,CAChB,wBAAwB,EACxB,iDAAiD,CAClD,CAAC;IACJ,CAAC;SAAM,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,gDAAgD;QAChD,sBAAsB;QACtB,MAAM,IAAI,kBAAQ,CAChB,wBAAwB,EACxB,+CAA+C,CAChD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,mEAAmE;QACnE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAA,qCAAgB,EAAC,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;YACvE,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,iCACvC,QAAQ,KACX,IAAI,EAAE,QAAQ,CAAC,QAAQ,IACvB,CAAC,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,kBAAQ,CAChB,oBAAoB,EACpB,iCAAiC,IAAI,oBAAoB,UAAU,EAAE,EACrE,KAAc,CACf,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeHubEntityResource = removeHubEntityResource;
|
|
4
|
+
const HubError_1 = require("../HubError");
|
|
5
|
+
const removeResource_1 = require("./removeResource");
|
|
6
|
+
/**
|
|
7
|
+
* Removes a Hub entity resource. This util handles delegating
|
|
8
|
+
* to the correct resource remove logic based on the entity type.
|
|
9
|
+
*
|
|
10
|
+
* @param type - type of the entity to remove the resource for
|
|
11
|
+
* @param identifier - id of the entity to remove the resource for
|
|
12
|
+
* @param name - name of the new/existing resource file
|
|
13
|
+
* @param context - contextual portal and auth information
|
|
14
|
+
* @param opts.owner - (optional) owner of the resource to add, defaults to the current user if not provided
|
|
15
|
+
* @param opts.prefix - (optional) folder in which to store the new resource
|
|
16
|
+
* @throws {HubError} if there is an error during the remove process or if removeing is not yet implemented for the entity type
|
|
17
|
+
*/
|
|
18
|
+
async function removeHubEntityResource(type, identifier, name, context, opts) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (type === "event") {
|
|
21
|
+
// TODO: add logic to remove event resource
|
|
22
|
+
throw new HubError_1.default("removeHubEntityResource", "removing event resources is not yet implemented");
|
|
23
|
+
}
|
|
24
|
+
else if (type === "group") {
|
|
25
|
+
// TODO: add logic to remove group resource once
|
|
26
|
+
// supported by portal
|
|
27
|
+
throw new HubError_1.default("removeHubEntityResource", "removing group resources is not yet supported");
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// default logic for item-backed entities
|
|
31
|
+
const owner = (opts === null || opts === void 0 ? void 0 : opts.owner) || ((_a = context === null || context === void 0 ? void 0 : context.currentUser) === null || _a === void 0 ? void 0 : _a.username);
|
|
32
|
+
const fileName = (opts === null || opts === void 0 ? void 0 : opts.prefix) ? `${opts.prefix}/${name}` : name;
|
|
33
|
+
await (0, removeResource_1.removeResource)(identifier, fileName, owner, context.userRequestOptions);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=removeHubEntityResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeHubEntityResource.js","sourceRoot":"","sources":["../../../src/resources/removeHubEntityResource.ts"],"names":[],"mappings":";;AAiBA,0DAkCC;AAlDD,0CAAmC;AAEnC,qDAAkD;AAElD;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,uBAAuB,CAC3C,IAAmB,EACnB,UAAkB,EAClB,IAAY,EACZ,OAAuB,EACvB,IAGC;;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,2CAA2C;QAC3C,MAAM,IAAI,kBAAQ,CAChB,yBAAyB,EACzB,iDAAiD,CAClD,CAAC;IACJ,CAAC;SAAM,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,gDAAgD;QAChD,sBAAsB;QACtB,MAAM,IAAI,kBAAQ,CAChB,yBAAyB,EACzB,+CAA+C,CAChD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,yCAAyC;QACzC,MAAM,KAAK,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,QAAQ,CAAA,CAAC;QAC5D,MAAM,QAAQ,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAChE,MAAM,IAAA,+BAAc,EAClB,UAAU,EACV,QAAQ,EACR,KAAK,EACL,OAAO,CAAC,kBAAkB,CAC3B,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upsertHubEntityResource = upsertHubEntityResource;
|
|
4
|
+
const HubError_1 = require("../HubError");
|
|
5
|
+
const upsertResource_1 = require("./upsertResource");
|
|
6
|
+
/**
|
|
7
|
+
* Adds or updates a Hub entity resource depending on whether it
|
|
8
|
+
* already exists. This util handles delegating to the correct
|
|
9
|
+
* resource upsert logic based on the entity type.
|
|
10
|
+
*
|
|
11
|
+
* @param type - type of the entity to upsert the resource for
|
|
12
|
+
* @param identifier - id of the entity to upsert the resource for
|
|
13
|
+
* @param resource - the resource to upsert
|
|
14
|
+
* @param name - name of the new/existing resource file
|
|
15
|
+
* @param context - contextual portal and auth information
|
|
16
|
+
* @param opts.owner - (optional) owner of the resource to add, defaults to the current user if not provided
|
|
17
|
+
* @param opts.prefix - (optional) folder in which to store the new resource
|
|
18
|
+
* @throws {HubError} if there is an error during the upsert process or if upserting is not yet implemented for the entity type
|
|
19
|
+
*/
|
|
20
|
+
async function upsertHubEntityResource(type, identifier, resource, name, context, opts) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (type === "event") {
|
|
23
|
+
// TODO: add logic to upsert event resource
|
|
24
|
+
throw new HubError_1.default("upsertHubEntityResource", "Upserting event resources is not yet implemented");
|
|
25
|
+
}
|
|
26
|
+
else if (type === "group") {
|
|
27
|
+
// TODO: add logic to upsert group resource once
|
|
28
|
+
// supported by portal
|
|
29
|
+
throw new HubError_1.default("upsertHubEntityResource", "Upserting group resources is not yet supported");
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// default logic for item-backed entities
|
|
33
|
+
const owner = (opts === null || opts === void 0 ? void 0 : opts.owner) || ((_a = context === null || context === void 0 ? void 0 : context.currentUser) === null || _a === void 0 ? void 0 : _a.username);
|
|
34
|
+
await (0, upsertResource_1.upsertResource)(identifier, owner, resource, name, context.userRequestOptions, opts === null || opts === void 0 ? void 0 : opts.prefix);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=upsertHubEntityResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertHubEntityResource.js","sourceRoot":"","sources":["../../../src/resources/upsertHubEntityResource.ts"],"names":[],"mappings":";;AAmBA,0DAoCC;AAtDD,0CAAmC;AAEnC,qDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,uBAAuB,CAC3C,IAAmB,EACnB,UAAkB,EAClB,QAAiB,EACjB,IAAY,EACZ,OAAuB,EACvB,IAGC;;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,2CAA2C;QAC3C,MAAM,IAAI,kBAAQ,CAChB,yBAAyB,EACzB,kDAAkD,CACnD,CAAC;IACJ,CAAC;SAAM,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,gDAAgD;QAChD,sBAAsB;QACtB,MAAM,IAAI,kBAAQ,CAChB,yBAAyB,EACzB,gDAAgD,CACjD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,yCAAyC;QACzC,MAAM,KAAK,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,QAAQ,CAAA,CAAC;QAC5D,MAAM,IAAA,+BAAc,EAClB,UAAU,EACV,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,OAAO,CAAC,kBAAkB,EAC1B,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CACb,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -221,7 +221,7 @@ export declare function getValueFromMetadata(metadata: any, identifier: keyof IM
|
|
|
221
221
|
*/
|
|
222
222
|
export declare function parseISODateString(isoString: string): {
|
|
223
223
|
date: Date;
|
|
224
|
-
precision: "
|
|
224
|
+
precision: "time" | "year" | "month" | "day";
|
|
225
225
|
};
|
|
226
226
|
/**
|
|
227
227
|
* Get the spatial reference as an object for an item
|
|
@@ -10,10 +10,11 @@ import { IWithDiscussions } from "../traits/IWithDiscussions";
|
|
|
10
10
|
import { IWithViewSettings } from "../traits/IWithViewSettings";
|
|
11
11
|
import { IWithAssistant } from "../traits/IWithAssistant";
|
|
12
12
|
import { ICatalogSetup } from "../../search/types/types";
|
|
13
|
+
import { IWithVersions } from "../traits/IWithVersions";
|
|
13
14
|
/**
|
|
14
15
|
* Properties exposed by Entities that are backed by Items
|
|
15
16
|
*/
|
|
16
|
-
export interface IHubItemEntity extends IHubEntityBase, IWithPermissions, IWithDiscussions, IWithFollowers, IWithAssociations, IWithAssistant {
|
|
17
|
+
export interface IHubItemEntity extends IHubEntityBase, IWithPermissions, IWithDiscussions, IWithFollowers, IWithAssociations, IWithAssistant, IWithVersions {
|
|
17
18
|
/**
|
|
18
19
|
* Access level of the item ("private" | "org" | "public")
|
|
19
20
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export { IWithLayout, IWithLayoutStore } from "./core/traits/IWithLayout";
|
|
|
106
106
|
export { IWithPermissions } from "./core/traits/IWithPermissions";
|
|
107
107
|
export { IWithSlug } from "./core/traits/IWithSlug";
|
|
108
108
|
export { IWithViewSettings } from "./core/traits/IWithViewSettings";
|
|
109
|
+
export { IWithVersions } from "./core/traits/IWithVersions";
|
|
109
110
|
export { HubActionLink, IHubActionLinkSection, IHubContentActionLink, IHubExternalActionLink, IHubWellKnownActionLink, } from "./core/types/ActionLinks";
|
|
110
111
|
export { CountByValue, DynamicAggregation, DynamicValue, DynamicValueDefinition, DynamicValueResult, DynamicValues, DynamicValueType, IDynamicItemQueryDefinition, IDynamicPortalSelfDefinition, IDynamicServiceQueryDefinition, IStaticValueDefinition, } from "./core/types/DynamicValues";
|
|
111
112
|
export { HubEmbed, IHubEmbed, IHubEmbedApp, IHubEmbedExternal, IHubEmbedMap, IHubEmbedSurvey, } from "./core/types/Embeds";
|
|
@@ -540,6 +541,8 @@ export { HubError, OperationError, OperationStack };
|
|
|
540
541
|
export { IMigratableSchema, MigratableSchemaTransformMap, } from "./migrations/types";
|
|
541
542
|
export { Breakpoint, ColumnWidth, HTMLConfigurableLayoutNodeElement, IColumn, IColumnProps, IConfigurableLayoutNode, ITranslationMap, ILayoutNode, ILayoutNodeConfig, IProcessLayoutOptions, IRow, IRowProps, ISection, ISectionProps, LayoutColumnChild, LayoutNodeTag, layoutNodeTags, LayoutEditorTag, LayoutNode, Ref, SectionOrRef, ResponsiveValue, } from "./layouts/layout-system-types";
|
|
542
543
|
export { ILayoutNodeChangeEventDetail, ILayoutPublishEventDetail, ILayoutResetEventDetail, ILayoutNodeRepositionEventDetail, } from "./layouts/layout-event-types";
|
|
543
|
-
export { ILayout, Layout, LayoutUtils } from "./layouts/types";
|
|
544
|
+
export { ILayout, Layout, LayoutUtils, TLayoutType, TLayouts, LAYOUT_SCHEMA_VERSION, } from "./layouts/types";
|
|
544
545
|
export { ILayoutV1 } from "./layouts/migrations/types/ILayoutV1";
|
|
545
546
|
export { ILayoutV2 } from "./layouts/migrations/types/ILayoutV2";
|
|
547
|
+
export { fetchHubEntityLayouts } from "./layouts/fetchHubEntityLayouts";
|
|
548
|
+
export { publishHubEntityLayout } from "./layouts/publishHubEntityLayout";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
2
|
+
import { Layout, TLayouts } from "./types";
|
|
3
|
+
import { HubEntity } from "../core/types/HubEntity";
|
|
4
|
+
import { IWithVersions } from "../core/traits/IWithVersions";
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the "current version" layouts for a given Hub entity.
|
|
7
|
+
*
|
|
8
|
+
* Note: this function assumes that layout versions are stored
|
|
9
|
+
* as resources on the underlying entity and that pointers to
|
|
10
|
+
* these resources are stored somewhere on the entity (e.g.
|
|
11
|
+
* properties.currentVersions for portal-backed entities).
|
|
12
|
+
*
|
|
13
|
+
* @param entity - the Hub entity for which to fetch layouts
|
|
14
|
+
* @param context - contextual portal and auth information
|
|
15
|
+
*/
|
|
16
|
+
export declare function fetchHubEntityLayouts(entity: HubEntity & IWithVersions, context: IArcGISContext): Promise<TLayouts<Layout>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HubEntityType } from "../../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Adds or updates a layout asset resource (image, video,
|
|
5
|
+
* etc.) and returns the URL reference to the resource.
|
|
6
|
+
*
|
|
7
|
+
* Note that layout resources are typically stored with:
|
|
8
|
+
* - an "assets/" prefix (so we can find them)
|
|
9
|
+
* - a name that starts with the cardId
|
|
10
|
+
* - and a -{timestamp} suffix (to bust the cache)
|
|
11
|
+
* Thus, 'update' is not really an update, it is:
|
|
12
|
+
* 1. upload the new one
|
|
13
|
+
* 2. find the old one (which has a different suffix)
|
|
14
|
+
* and delete it.
|
|
15
|
+
*
|
|
16
|
+
* This is why we cannot simply use upsertHubEntityResource
|
|
17
|
+
*
|
|
18
|
+
* @param type - type of the entity to upsert the resource for
|
|
19
|
+
* @param id - id of the entity to upsert the resource for
|
|
20
|
+
* @param owner - owner of the resource to add/update
|
|
21
|
+
* @param resource - the resource to add/update
|
|
22
|
+
* @param name - name of the new/existing resource file
|
|
23
|
+
* @param extension - file extension of the resource (e.g. 'png', 'json', etc.)
|
|
24
|
+
* @param context - contextual portal and auth information
|
|
25
|
+
* @returns a URL reference to the newly added/updated resource
|
|
26
|
+
*/
|
|
27
|
+
export declare function upsertLayoutAssetResource(type: HubEntityType, identifier: string, owner: string, resource: unknown, name: string, extension: string, context: IArcGISContext): Promise<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IChangeEventDetail } from "../core/schemas/types";
|
|
2
2
|
import { ILayoutNodeConfig, LayoutNode } from "./layout-system-types";
|
|
3
|
-
import { ILayout } from "./types";
|
|
3
|
+
import { ILayout, TLayoutType } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Interface representing the information emitted when
|
|
6
6
|
* a layout node is changed in the layout editor.
|
|
@@ -22,6 +22,7 @@ export interface ILayoutPublishEventDetail {
|
|
|
22
22
|
* a layout is reset to its default
|
|
23
23
|
*/
|
|
24
24
|
export interface ILayoutResetEventDetail {
|
|
25
|
+
type: TLayoutType;
|
|
25
26
|
successCallback?: () => void | Promise<void>;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { IMigratableSchema } from "../../../migrations/types";
|
|
2
2
|
import type { IHistoryEntry, INodeOverrides, ITranslationMap, SectionOrRef } from "../../layout-system-types";
|
|
3
|
+
import { TLayoutType } from "../../types";
|
|
3
4
|
/** Interface representing a V2 layout object. */
|
|
4
5
|
export interface ILayoutV2 extends IMigratableSchema {
|
|
5
6
|
/** Schema version for the layout. */
|
|
6
7
|
schemaVersion: 2;
|
|
8
|
+
/** The type of layout, e.g. "header", "body", etc.*/
|
|
9
|
+
type: TLayoutType;
|
|
7
10
|
/** If true, the entire layout is read-only. */
|
|
8
11
|
readOnly?: boolean;
|
|
9
12
|
/** Array of sections in the layout. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HubEntity } from "../core/types/HubEntity";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
import { ILayout } from "./types";
|
|
4
|
+
import { IWithVersions } from "../core/traits/IWithVersions";
|
|
5
|
+
/**
|
|
6
|
+
* Publishes a Hub entity layout by:
|
|
7
|
+
* 1. Uploading any layout asset resources and updating the
|
|
8
|
+
* layout variables to point to the resource urls
|
|
9
|
+
* 2. Upserting the layout as a resource on the entity
|
|
10
|
+
* 3. Updating the entity's currentVersions to point to the
|
|
11
|
+
* new layout resource
|
|
12
|
+
* 4. Updating the entity
|
|
13
|
+
*
|
|
14
|
+
* TODO: in the future, we'll add layout versioning support, so
|
|
15
|
+
* we'll want this to work with the existing versioning utils.
|
|
16
|
+
* For now, we'll keep it simple and just directly upsert the
|
|
17
|
+
* single published version
|
|
18
|
+
*
|
|
19
|
+
* @param entity - the Hub entity of the layout to publish
|
|
20
|
+
* @param layout - the layout to publish
|
|
21
|
+
* @param versionName - the name of the version to publish
|
|
22
|
+
* @param context - contextual portal and auth information
|
|
23
|
+
* @returns the published layout
|
|
24
|
+
* @throws {HubError} if there is an error during the publish process
|
|
25
|
+
*/
|
|
26
|
+
export declare function publishHubEntityLayout(entity: HubEntity & IWithVersions, layout: ILayout, versionName: string, context: IArcGISContext): Promise<{
|
|
27
|
+
entity: HubEntity;
|
|
28
|
+
layout: ILayout;
|
|
29
|
+
}>;
|
|
@@ -2,6 +2,7 @@ import type { ILayoutV1 } from "./migrations/types/ILayoutV1";
|
|
|
2
2
|
import type { ILayoutV2 } from "./migrations/types/ILayoutV2";
|
|
3
3
|
/** Union type of all layout schema versions. */
|
|
4
4
|
export type Layout = ILayoutV1 | ILayoutV2;
|
|
5
|
+
export declare const LAYOUT_SCHEMA_VERSION = 2;
|
|
5
6
|
/**
|
|
6
7
|
* The latest supported layout schema. This should be
|
|
7
8
|
* updated whenever a new schema version is released.
|
|
@@ -14,3 +15,7 @@ export type ILayout = ILayoutV2;
|
|
|
14
15
|
export type LayoutUtils = {
|
|
15
16
|
processLayout: (layout: ILayout) => Promise<ILayout>;
|
|
16
17
|
};
|
|
18
|
+
/** Type representing the different types of Hub entity layouts */
|
|
19
|
+
export type TLayoutType = "body" | "header" | "footer" | "search" | "404";
|
|
20
|
+
/** Type representing a collection of layouts for different layout types */
|
|
21
|
+
export type TLayouts<T = ILayout> = Partial<Record<TLayoutType, T>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HubEntityType } from "../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Adds a Hub entity resource. This util handles delegating
|
|
5
|
+
* to the correct resource add logic based on the entity type.
|
|
6
|
+
*
|
|
7
|
+
* @param type - type of the entity to add the resource for
|
|
8
|
+
* @param identifier - id of the entity to add the resource for
|
|
9
|
+
* @param resource - the resource to add
|
|
10
|
+
* @param name - name of the new resource file
|
|
11
|
+
* @param context - contextual portal and auth information
|
|
12
|
+
* @param opts.owner - (optional) owner of the resource to add, defaults to the current user if not provided
|
|
13
|
+
* @param opts.prefix - (optional) folder in which to store the new resource
|
|
14
|
+
* @throws {HubError} if there is an error during the add process or if adding is not yet implemented for the entity type
|
|
15
|
+
*/
|
|
16
|
+
export declare function addHubEntityResource(type: HubEntityType, identifier: string, resource: unknown, name: string, context: IArcGISContext, opts?: {
|
|
17
|
+
owner?: string;
|
|
18
|
+
prefix?: string;
|
|
19
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
2
|
+
/**
|
|
3
|
+
* Thin wrapper around addItemResource to add a resource
|
|
4
|
+
* to a portal item and provide Hub-specific error
|
|
5
|
+
* handling.
|
|
6
|
+
*
|
|
7
|
+
* @param id - id of the item to add the resource to
|
|
8
|
+
* @param name - name of the resource file
|
|
9
|
+
* @param owner - owner of the item to add the resource to
|
|
10
|
+
* @param context - contextual portal and auth information
|
|
11
|
+
* @throws {HubError} if there is an error during the add process
|
|
12
|
+
*/
|
|
13
|
+
export declare function addResource(id: string, name: string, resource: unknown, context: IArcGISContext, opts?: {
|
|
14
|
+
owner?: string;
|
|
15
|
+
prefix?: string;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HubEntityType } from "../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Fetches a Hub entity resource. This util handles
|
|
5
|
+
* delegating to the correct resource fetching logic
|
|
6
|
+
* based on the entity type.
|
|
7
|
+
*
|
|
8
|
+
* @param type - type of the entity to fetch the resource for
|
|
9
|
+
* @param identifier - id of the entity to fetch the resource for
|
|
10
|
+
* @param fileName - name of the info file (including the optional folder path) to fetch
|
|
11
|
+
* @param context - contextual portal and auth information
|
|
12
|
+
* @returns the fetched resource
|
|
13
|
+
* @throws {HubError} if there is an error during the fetch process or if fetching is not yet implemented for the entity type
|
|
14
|
+
*/
|
|
15
|
+
export declare function fetchHubEntityResource(type: HubEntityType, identifier: string, fileName: string, context: IArcGISContext): Promise<unknown>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HubEntityType } from "../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Fetches a Hub entity's resources. This util handles
|
|
5
|
+
* delegating to the correct resource fetching logic
|
|
6
|
+
* based on the entity type.
|
|
7
|
+
*
|
|
8
|
+
* @param type - type of the entity to fetch the resources for
|
|
9
|
+
* @param identifier - id of the entity to fetch the resources for
|
|
10
|
+
* @param context - contextual portal and auth information
|
|
11
|
+
* @returns the fetched resources
|
|
12
|
+
* @throws {HubError} if there is an error during the fetch process or if fetching is not yet implemented for the entity type
|
|
13
|
+
*/
|
|
14
|
+
export declare function fetchHubEntityResources(type: HubEntityType, identifier: string, context: IArcGISContext): Promise<{
|
|
15
|
+
name: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HubEntityType } from "../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Removes a Hub entity resource. This util handles delegating
|
|
5
|
+
* to the correct resource remove logic based on the entity type.
|
|
6
|
+
*
|
|
7
|
+
* @param type - type of the entity to remove the resource for
|
|
8
|
+
* @param identifier - id of the entity to remove the resource for
|
|
9
|
+
* @param name - name of the new/existing resource file
|
|
10
|
+
* @param context - contextual portal and auth information
|
|
11
|
+
* @param opts.owner - (optional) owner of the resource to add, defaults to the current user if not provided
|
|
12
|
+
* @param opts.prefix - (optional) folder in which to store the new resource
|
|
13
|
+
* @throws {HubError} if there is an error during the remove process or if removeing is not yet implemented for the entity type
|
|
14
|
+
*/
|
|
15
|
+
export declare function removeHubEntityResource(type: HubEntityType, identifier: string, name: string, context: IArcGISContext, opts?: {
|
|
16
|
+
owner?: string;
|
|
17
|
+
prefix?: string;
|
|
18
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HubEntityType } from "../core/types/HubEntityType";
|
|
2
|
+
import { IArcGISContext } from "../types/IArcGISContext";
|
|
3
|
+
/**
|
|
4
|
+
* Adds or updates a Hub entity resource depending on whether it
|
|
5
|
+
* already exists. This util handles delegating to the correct
|
|
6
|
+
* resource upsert logic based on the entity type.
|
|
7
|
+
*
|
|
8
|
+
* @param type - type of the entity to upsert the resource for
|
|
9
|
+
* @param identifier - id of the entity to upsert the resource for
|
|
10
|
+
* @param resource - the resource to upsert
|
|
11
|
+
* @param name - name of the new/existing resource file
|
|
12
|
+
* @param context - contextual portal and auth information
|
|
13
|
+
* @param opts.owner - (optional) owner of the resource to add, defaults to the current user if not provided
|
|
14
|
+
* @param opts.prefix - (optional) folder in which to store the new resource
|
|
15
|
+
* @throws {HubError} if there is an error during the upsert process or if upserting is not yet implemented for the entity type
|
|
16
|
+
*/
|
|
17
|
+
export declare function upsertHubEntityResource(type: HubEntityType, identifier: string, resource: unknown, name: string, context: IArcGISContext, opts?: {
|
|
18
|
+
owner?: string;
|
|
19
|
+
prefix?: string;
|
|
20
|
+
}): Promise<void>;
|
|
@@ -3,9 +3,13 @@ import { IVersionMetadata } from "./IVersionMetadata";
|
|
|
3
3
|
* The version of the entity.
|
|
4
4
|
* This contains the metadata about the version and the versioned data itself.
|
|
5
5
|
*/
|
|
6
|
-
export interface IVersion extends IVersionMetadata {
|
|
6
|
+
export interface IVersion<T = Record<string, any>> extends IVersionMetadata {
|
|
7
7
|
/**
|
|
8
8
|
* The versioned data
|
|
9
9
|
*/
|
|
10
|
-
data:
|
|
10
|
+
data: T;
|
|
11
|
+
/**
|
|
12
|
+
* Additional optional properties
|
|
13
|
+
*/
|
|
14
|
+
[key: string]: any;
|
|
11
15
|
}
|
|
@@ -43,4 +43,14 @@ export interface IVersionMetadata {
|
|
|
43
43
|
* The updated timestamp
|
|
44
44
|
*/
|
|
45
45
|
updated: number;
|
|
46
|
+
/**
|
|
47
|
+
* The username of the last modifier
|
|
48
|
+
*/
|
|
49
|
+
lastModifiedBy?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The type of the version resource. For item-backed
|
|
52
|
+
* results, this will be item.type. Otherwise, it will
|
|
53
|
+
* be something like "Group", "User", "Event", etc.
|
|
54
|
+
*/
|
|
55
|
+
type?: string;
|
|
46
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esri/hub-common",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.6.0",
|
|
4
4
|
"description": "Common TypeScript types and utility functions for @esri/hub.js.",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"build": "npm run build:node && npm run build:esm",
|
|
55
55
|
"build:esm": "tsc --outDir ./dist/esm --declaration --declarationDir ./dist/types",
|
|
56
56
|
"build:node": "tsc --module commonjs --outDir ./dist/node",
|
|
57
|
-
"ci:lint": "npm run lint
|
|
57
|
+
"ci:lint": "npm run lint -- --quiet",
|
|
58
58
|
"ci:test:coverage": "npm run test:coverage",
|
|
59
59
|
"clean": "rimraf ./dist ./.turbo ./coverage",
|
|
60
60
|
"dev": "npm run dev:esm",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"dev:node": "npm run build:node -- -w",
|
|
63
63
|
"format:fix": "prettier --write './{src,test}/**/*.ts'",
|
|
64
64
|
"format": "prettier --check './{src,test}/**/*.ts'",
|
|
65
|
-
"lint": "eslint
|
|
65
|
+
"lint": "eslint './src/**/*.ts'",
|
|
66
66
|
"lint:warnings": "eslint './src/**/*.ts'",
|
|
67
67
|
"lint:fix": "eslint --quiet --fix './src/**/*.ts'",
|
|
68
68
|
"madge:circular": "madge --circular --ts-config ./tsconfig.json --extensions ts ./src",
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { cloneObject } from "../util.js";
|
|
2
|
-
import { upsertLayoutResource } from "./upsertLayoutResource.js";
|
|
3
|
-
export async function updateLayout(entity, layout, requestOptions) {
|
|
4
|
-
if (!layout) {
|
|
5
|
-
return layout;
|
|
6
|
-
}
|
|
7
|
-
const updatedLayout = cloneObject(layout);
|
|
8
|
-
// check the variables and for each one that is of type image and... has a source, a blob?
|
|
9
|
-
// 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
|
|
10
|
-
await Promise.all(Object.entries(updatedLayout.variables || {}).map(async ([key, _variable]) => {
|
|
11
|
-
const variable = _variable;
|
|
12
|
-
if (variable.type === "image") {
|
|
13
|
-
if (variable.source === "upload" && !!variable.blob) {
|
|
14
|
-
const newVariable = {
|
|
15
|
-
type: variable.type,
|
|
16
|
-
};
|
|
17
|
-
const resourceUrl = await upsertLayoutResource(entity.id, entity.owner, variable.blob, key, // this is something like <nodeId>-image-card
|
|
18
|
-
variable.format, requestOptions);
|
|
19
|
-
// set the value to the resource name
|
|
20
|
-
newVariable.value = { $ref: resourceUrl };
|
|
21
|
-
updatedLayout.variables[key] = newVariable;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}));
|
|
25
|
-
/*
|
|
26
|
-
TODO: we will also need to clean up any old resources that are no longer referenced
|
|
27
|
-
- make sure when we delete it in the ui, we get rid of the variable
|
|
28
|
-
- then when we save, we delete any resources for which there is no variable
|
|
29
|
-
- when an image card is changed from an upload to a url, we will handle it similarly
|
|
30
|
-
*/
|
|
31
|
-
return updatedLayout;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=updateLayout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateLayout.js","sourceRoot":"","sources":["../../../src/layouts/updateLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,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,WAAW,CAAC,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,oBAAoB,CAC5C,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,78 +0,0 @@
|
|
|
1
|
-
import { addItemResource, getItemResources } from "@esri/arcgis-rest-portal";
|
|
2
|
-
import HubError from "../HubError";
|
|
3
|
-
import { objectToJsonBlob } from "../resources/object-to-json-blob";
|
|
4
|
-
import { stringToBlob } from "../resources/string-to-blob";
|
|
5
|
-
import { removeResource } from "../resources/removeResource";
|
|
6
|
-
/**
|
|
7
|
-
* Given an item, and owner, Search for if the resource exists
|
|
8
|
-
* and if does, update it, otherwise add it. Returns a url for the item.
|
|
9
|
-
*
|
|
10
|
-
* Note that layout resources are typically stored with
|
|
11
|
-
* - a "layout/" prefix (so we can find them)
|
|
12
|
-
* - a name that starts with the cardId
|
|
13
|
-
* - and a -{timestamp} suffix (to bust the cache)
|
|
14
|
-
* thus 'update' is not really an update, it is:
|
|
15
|
-
* - upload the new one
|
|
16
|
-
* - then find the old one (which has a different suffix) and delete it.
|
|
17
|
-
*
|
|
18
|
-
* this is why we cannot simply use upsertResource
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @export
|
|
22
|
-
* @param {string} id
|
|
23
|
-
* @param {string} owner
|
|
24
|
-
* @param {*} resource
|
|
25
|
-
* @param {string} name
|
|
26
|
-
* @param {string} extension
|
|
27
|
-
* @param {IUserRequestOptions} ro
|
|
28
|
-
* @return {*} {Promise<string>}
|
|
29
|
-
*/
|
|
30
|
-
export async function upsertLayoutResource(id, owner, resource, name, extension, ro) {
|
|
31
|
-
try {
|
|
32
|
-
const prefix = "layout";
|
|
33
|
-
// construct resource name
|
|
34
|
-
// the key is of the form <nodeId>-image-card
|
|
35
|
-
// we also append a unique timestamp to avoid caching issues
|
|
36
|
-
const resourceName = `${name}-${Date.now()}.${extension}`;
|
|
37
|
-
// JSON and text resources have....odd things happen
|
|
38
|
-
// to them when they are added as resources and NOT
|
|
39
|
-
// converted to blobs. Thus we convert them to blobs
|
|
40
|
-
let resourceToUpload = resource;
|
|
41
|
-
if (extension === "json") {
|
|
42
|
-
resourceToUpload = objectToJsonBlob(resource);
|
|
43
|
-
}
|
|
44
|
-
if (extension === "txt") {
|
|
45
|
-
resourceToUpload = stringToBlob(resource);
|
|
46
|
-
}
|
|
47
|
-
// Add item resource
|
|
48
|
-
// we do not check for existence first, because
|
|
49
|
-
// our resource names are unique (timestamped)
|
|
50
|
-
const response = await addItemResource(Object.assign({ id,
|
|
51
|
-
owner, resource: resourceToUpload, name: resourceName, prefix }, ro));
|
|
52
|
-
// if err throw
|
|
53
|
-
if (!response.success) {
|
|
54
|
-
throw new HubError("Add Item Resource", `Error adding resource ${name} to item ${id}.`);
|
|
55
|
-
}
|
|
56
|
-
// then delete the old one if it exists
|
|
57
|
-
const resources = await getItemResources(id, ro);
|
|
58
|
-
const foundResource = resources.resources.find((res) => {
|
|
59
|
-
return (res.resource.startsWith(`${prefix}/${name}`) &&
|
|
60
|
-
res.resource !== `${prefix}/${resourceName}`);
|
|
61
|
-
});
|
|
62
|
-
if (foundResource) {
|
|
63
|
-
await removeResource(id, foundResource.resource, owner, ro);
|
|
64
|
-
}
|
|
65
|
-
// return url
|
|
66
|
-
// resourceUrl://:id/:prefix/:filename
|
|
67
|
-
return `resourceUrl://${id}/${prefix}/${resourceName}`;
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
if (err instanceof Error) {
|
|
71
|
-
throw new HubError("Add Item Resource", err.message, err);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new HubError("Add Item Resource", `Error adding resource ${name} to item ${id}.`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=upsertLayoutResource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upsertLayoutResource.js","sourceRoot":"","sources":["../../../src/layouts/upsertLayoutResource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,EAAU,EACV,KAAa,EACb,QAAiB,EACjB,IAAY,EACZ,SAAiB,EACjB,EAAuB;IAEvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC;QACxB,0BAA0B;QAC1B,6CAA6C;QAC7C,4DAA4D;QAC5D,MAAM,YAAY,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,SAAS,EAAE,CAAC;QAC1D,oDAAoD;QACpD,mDAAmD;QACnD,oDAAoD;QACpD,IAAI,gBAAgB,GAAG,QAAQ,CAAC;QAChC,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;YACzB,gBAAgB,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,gBAAgB,GAAG,YAAY,CAAC,QAAkB,CAAC,CAAC;QACtD,CAAC;QACD,oBAAoB;QACpB,+CAA+C;QAC/C,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,MAAM,eAAe,iBACpC,EAAE;YACF,KAAK,EACL,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,YAAY,EAClB,MAAM,IACH,EAAE,EACL,CAAC;QACH,eAAe;QACf,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,QAAQ,CAChB,mBAAmB,EACnB,yBAAyB,IAAI,YAAY,EAAE,GAAG,CAC/C,CAAC;QACJ,CAAC;QAED,uCAAuC;QACvC,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,SAAS,CAAC,SAAS,CAAC,IAAI,CAC5C,CAAC,GAAyB,EAAE,EAAE;YAC5B,OAAO,CACL,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;gBAC5C,GAAG,CAAC,QAAQ,KAAK,GAAG,MAAM,IAAI,YAAY,EAAE,CAC7C,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,cAAc,CAAC,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,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,QAAQ,CAChB,mBAAmB,EACnB,yBAAyB,IAAI,YAAY,EAAE,GAAG,CAC/C,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|