@esri/solution-web-experience 4.1.2 → 5.0.1

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 (33) hide show
  1. package/dist/cjs/helpers/convert-web-experience-to-template.d.ts +27 -27
  2. package/dist/cjs/helpers/convert-web-experience-to-template.js +66 -66
  3. package/dist/cjs/helpers/create-web-experience-model-from-template.d.ts +26 -26
  4. package/dist/cjs/helpers/create-web-experience-model-from-template.js +41 -41
  5. package/dist/cjs/helpers/create-web-experience.d.ts +25 -25
  6. package/dist/cjs/helpers/create-web-experience.js +121 -121
  7. package/dist/cjs/helpers/get-experience-subdomain.d.ts +23 -23
  8. package/dist/cjs/helpers/get-experience-subdomain.js +25 -25
  9. package/dist/cjs/helpers/get-web-experience-dependencies.d.ts +23 -23
  10. package/dist/cjs/helpers/get-web-experience-dependencies.js +32 -32
  11. package/dist/cjs/helpers/get-web-experience-url-template.d.ts +23 -23
  12. package/dist/cjs/helpers/get-web-experience-url-template.js +25 -25
  13. package/dist/cjs/index.d.ts +17 -17
  14. package/dist/cjs/index.js +21 -21
  15. package/dist/cjs/web-experience-processor.d.ts +51 -51
  16. package/dist/cjs/web-experience-processor.js +125 -125
  17. package/dist/esm/helpers/convert-web-experience-to-template.d.ts +27 -27
  18. package/dist/esm/helpers/convert-web-experience-to-template.js +62 -62
  19. package/dist/esm/helpers/create-web-experience-model-from-template.d.ts +26 -26
  20. package/dist/esm/helpers/create-web-experience-model-from-template.js +37 -37
  21. package/dist/esm/helpers/create-web-experience.d.ts +25 -25
  22. package/dist/esm/helpers/create-web-experience.js +117 -117
  23. package/dist/esm/helpers/get-experience-subdomain.d.ts +23 -23
  24. package/dist/esm/helpers/get-experience-subdomain.js +21 -21
  25. package/dist/esm/helpers/get-web-experience-dependencies.d.ts +23 -23
  26. package/dist/esm/helpers/get-web-experience-dependencies.js +28 -28
  27. package/dist/esm/helpers/get-web-experience-url-template.d.ts +23 -23
  28. package/dist/esm/helpers/get-web-experience-url-template.js +21 -21
  29. package/dist/esm/index.d.ts +17 -17
  30. package/dist/esm/index.js +17 -17
  31. package/dist/esm/web-experience-processor.d.ts +51 -51
  32. package/dist/esm/web-experience-processor.js +119 -119
  33. package/package.json +5 -5
@@ -1,27 +1,27 @@
1
- /** @license
2
- * Copyright 2020 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { IModel } from "@esri/hub-common";
17
- import { IItemTemplate } from "@esri/solution-common";
18
- /**
19
- * Convert an Experience item into a template
20
- *
21
- * Pretty simpler conversion - remove extra item props, extract out
22
- * items from the data.dataSources hash.
23
- *
24
- * @param model
25
- * @param authentication
26
- */
27
- export declare function convertWebExperienceToTemplate(model: IModel): Promise<IItemTemplate>;
1
+ /** @license
2
+ * Copyright 2020 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { IModel } from "@esri/hub-common";
17
+ import { IItemTemplate } from "@esri/solution-common";
18
+ /**
19
+ * Convert an Experience item into a template
20
+ *
21
+ * Pretty simpler conversion - remove extra item props, extract out
22
+ * items from the data.dataSources hash.
23
+ *
24
+ * @param model
25
+ * @param authentication
26
+ */
27
+ export declare function convertWebExperienceToTemplate(model: IModel): Promise<IItemTemplate>;
@@ -1,67 +1,67 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2020 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.convertWebExperienceToTemplate = void 0;
19
- const hub_common_1 = require("@esri/hub-common");
20
- const solution_common_1 = require("@esri/solution-common");
21
- const get_web_experience_dependencies_1 = require("./get-web-experience-dependencies");
22
- /**
23
- * Convert an Experience item into a template
24
- *
25
- * Pretty simpler conversion - remove extra item props, extract out
26
- * items from the data.dataSources hash.
27
- *
28
- * @param model
29
- * @param authentication
30
- */
31
- function convertWebExperienceToTemplate(model) {
32
- const tmpl = (0, solution_common_1.createPlaceholderTemplate)(model.item.id, model.item.type);
33
- tmpl.key = `${(0, hub_common_1.propifyString)(model.item.title)}_${(0, hub_common_1.createId)("i")}`;
34
- const clone = (0, hub_common_1.cloneObject)(model);
35
- tmpl.data = clone.data;
36
- // We need to save these properties in order to restore them after hub.js deletes them
37
- const created = clone.item.created;
38
- const modified = clone.item.modified;
39
- tmpl.item = (0, hub_common_1.normalizeSolutionTemplateItem)(clone.item);
40
- tmpl.item.created = created;
41
- tmpl.item.modified = modified;
42
- // templatize the url. This is updated during the createModelFromTemplate phase
43
- // of the deployment process
44
- tmpl.item.url = "{{experienceUrlTemplate}}";
45
- // use typeKeyword to mark item as published (we decided to discard unpublished drafts)
46
- const typeKeywords = tmpl.item.typeKeywords;
47
- if (typeKeywords.indexOf(changedTypeKW) !== -1) {
48
- tmpl.item.typeKeywords = [publishedTypeKW].concat(tmpl.item.typeKeywords.filter(word => word !== changedTypeKW));
49
- }
50
- tmpl.dependencies = (0, get_web_experience_dependencies_1.getWebExperienceDependencies)(model);
51
- return Promise.resolve(tmpl);
52
- // TODO: For now, we let the generic process handle item resources
53
- // However, many newer item types have complex type-specific resource handling
54
- // requirements so this code may be useful in the future
55
- // ------------------------------------------------------
56
- // return getItemResources(tmpl.itemId, authentication)
57
- // .then((response) => {
58
- // tmpl.resources = response.resources.map(e => e.resource)
59
- // // Discard draft version
60
- // .filter(filename => filename !== 'config.json');
61
- // return tmpl;
62
- // });
63
- }
64
- exports.convertWebExperienceToTemplate = convertWebExperienceToTemplate;
65
- const publishedTypeKW = "status: Published";
66
- const changedTypeKW = "status: Changed";
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2020 Esri
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertWebExperienceToTemplate = void 0;
19
+ const hub_common_1 = require("@esri/hub-common");
20
+ const solution_common_1 = require("@esri/solution-common");
21
+ const get_web_experience_dependencies_1 = require("./get-web-experience-dependencies");
22
+ /**
23
+ * Convert an Experience item into a template
24
+ *
25
+ * Pretty simpler conversion - remove extra item props, extract out
26
+ * items from the data.dataSources hash.
27
+ *
28
+ * @param model
29
+ * @param authentication
30
+ */
31
+ function convertWebExperienceToTemplate(model) {
32
+ const tmpl = (0, solution_common_1.createPlaceholderTemplate)(model.item.id, model.item.type);
33
+ tmpl.key = `${(0, hub_common_1.propifyString)(model.item.title)}_${(0, hub_common_1.createId)("i")}`;
34
+ const clone = (0, hub_common_1.cloneObject)(model);
35
+ tmpl.data = clone.data;
36
+ // We need to save these properties in order to restore them after hub.js deletes them
37
+ const created = clone.item.created;
38
+ const modified = clone.item.modified;
39
+ tmpl.item = (0, hub_common_1.normalizeSolutionTemplateItem)(clone.item);
40
+ tmpl.item.created = created;
41
+ tmpl.item.modified = modified;
42
+ // templatize the url. This is updated during the createModelFromTemplate phase
43
+ // of the deployment process
44
+ tmpl.item.url = "{{experienceUrlTemplate}}";
45
+ // use typeKeyword to mark item as published (we decided to discard unpublished drafts)
46
+ const typeKeywords = tmpl.item.typeKeywords;
47
+ if (typeKeywords.indexOf(changedTypeKW) !== -1) {
48
+ tmpl.item.typeKeywords = [publishedTypeKW].concat(tmpl.item.typeKeywords.filter(word => word !== changedTypeKW));
49
+ }
50
+ tmpl.dependencies = (0, get_web_experience_dependencies_1.getWebExperienceDependencies)(model);
51
+ return Promise.resolve(tmpl);
52
+ // TODO: For now, we let the generic process handle item resources
53
+ // However, many newer item types have complex type-specific resource handling
54
+ // requirements so this code may be useful in the future
55
+ // ------------------------------------------------------
56
+ // return getItemResources(tmpl.itemId, authentication)
57
+ // .then((response) => {
58
+ // tmpl.resources = response.resources.map(e => e.resource)
59
+ // // Discard draft version
60
+ // .filter(filename => filename !== 'config.json');
61
+ // return tmpl;
62
+ // });
63
+ }
64
+ exports.convertWebExperienceToTemplate = convertWebExperienceToTemplate;
65
+ const publishedTypeKW = "status: Published";
66
+ const changedTypeKW = "status: Changed";
67
67
  //# sourceMappingURL=convert-web-experience-to-template.js.map
@@ -1,26 +1,26 @@
1
- /** @license
2
- * Copyright 2020 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { IModelTemplate } from "@esri/hub-common";
17
- import { UserSession } from "@esri/solution-common";
18
- /**
19
- * Convert a Web Experience template into a Model that can be persisted to the Portal API
20
- *
21
- * @param templateModel Template
22
- * @param settings Hash of values to interpolate into the template
23
- * @param transforms Hash of transform functions to use in the interpolation
24
- * @param authentication UserSession
25
- */
26
- export declare function createWebExperienceModelFromTemplate(templateModel: IModelTemplate, settings: any, transforms: any, authentication: UserSession): Promise<any>;
1
+ /** @license
2
+ * Copyright 2020 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { IModelTemplate } from "@esri/hub-common";
17
+ import { UserSession } from "@esri/solution-common";
18
+ /**
19
+ * Convert a Web Experience template into a Model that can be persisted to the Portal API
20
+ *
21
+ * @param templateModel Template
22
+ * @param settings Hash of values to interpolate into the template
23
+ * @param transforms Hash of transform functions to use in the interpolation
24
+ * @param authentication UserSession
25
+ */
26
+ export declare function createWebExperienceModelFromTemplate(templateModel: IModelTemplate, settings: any, transforms: any, authentication: UserSession): Promise<any>;
@@ -1,42 +1,42 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2020 Esri
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createWebExperienceModelFromTemplate = void 0;
19
- const hub_common_1 = require("@esri/hub-common");
20
- const get_web_experience_url_template_1 = require("./get-web-experience-url-template");
21
- /**
22
- * Convert a Web Experience template into a Model that can be persisted to the Portal API
23
- *
24
- * @param templateModel Template
25
- * @param settings Hash of values to interpolate into the template
26
- * @param transforms Hash of transform functions to use in the interpolation
27
- * @param authentication UserSession
28
- */
29
- function createWebExperienceModelFromTemplate(templateModel, settings, transforms, authentication) {
30
- // get the experience base url
31
- settings.experienceUrlTemplate = (0, get_web_experience_url_template_1.getWebExperiencepUrlTemplate)(authentication);
32
- const model = (0, hub_common_1.interpolate)(templateModel, settings, transforms);
33
- // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}
34
- model.item.url = settings.experienceUrlTemplate;
35
- /* istanbul ignore else */
36
- if (templateModel.item.thumbnail) {
37
- model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary
38
- }
39
- return Promise.resolve(model);
40
- }
41
- exports.createWebExperienceModelFromTemplate = createWebExperienceModelFromTemplate;
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2020 Esri
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createWebExperienceModelFromTemplate = void 0;
19
+ const hub_common_1 = require("@esri/hub-common");
20
+ const get_web_experience_url_template_1 = require("./get-web-experience-url-template");
21
+ /**
22
+ * Convert a Web Experience template into a Model that can be persisted to the Portal API
23
+ *
24
+ * @param templateModel Template
25
+ * @param settings Hash of values to interpolate into the template
26
+ * @param transforms Hash of transform functions to use in the interpolation
27
+ * @param authentication UserSession
28
+ */
29
+ function createWebExperienceModelFromTemplate(templateModel, settings, transforms, authentication) {
30
+ // get the experience base url
31
+ settings.experienceUrlTemplate = (0, get_web_experience_url_template_1.getWebExperiencepUrlTemplate)(authentication);
32
+ const model = (0, hub_common_1.interpolate)(templateModel, settings, transforms);
33
+ // ensure this is set - there may be some templates w/o `{{experienceTemplateUrl}}
34
+ model.item.url = settings.experienceUrlTemplate;
35
+ /* istanbul ignore else */
36
+ if (templateModel.item.thumbnail) {
37
+ model.item.thumbnail = templateModel.item.thumbnail; // interpolation trashes thumbnail binary
38
+ }
39
+ return Promise.resolve(model);
40
+ }
41
+ exports.createWebExperienceModelFromTemplate = createWebExperienceModelFromTemplate;
42
42
  //# sourceMappingURL=create-web-experience-model-from-template.js.map
@@ -1,25 +1,25 @@
1
- /** @license
2
- * Copyright 2020 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { IModel } from "@esri/hub-common";
17
- import { UserSession } from "@esri/solution-common";
18
- /**
19
- * Given a Model for a Web Experience, create the item in the Portal API
20
- *
21
- * @param model
22
- * @param options
23
- * @param authentication
24
- */
25
- export declare function createWebExperience(model: IModel, folderId: string, options: any, authentication: UserSession): Promise<IModel>;
1
+ /** @license
2
+ * Copyright 2020 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { IModel } from "@esri/hub-common";
17
+ import { UserSession } from "@esri/solution-common";
18
+ /**
19
+ * Given a Model for a Web Experience, create the item in the Portal API
20
+ *
21
+ * @param model
22
+ * @param options
23
+ * @param authentication
24
+ */
25
+ export declare function createWebExperience(model: IModel, folderId: string, options: any, authentication: UserSession): Promise<IModel>;
@@ -1,122 +1,122 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWebExperience = void 0;
4
- /** @license
5
- * Copyright 2020 Esri
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const hub_common_1 = require("@esri/hub-common");
20
- const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
21
- /**
22
- * Given a Model for a Web Experience, create the item in the Portal API
23
- *
24
- * @param model
25
- * @param options
26
- * @param authentication
27
- */
28
- function createWebExperience(model, folderId, options, authentication) {
29
- const resources = [];
30
- // For unkown reasons we can not seem to spy on createItemInFolder
31
- // so we will create-then-move for now
32
- const createOptions = {
33
- // need to serialize
34
- item: (0, hub_common_1.serializeModel)(model),
35
- authentication
36
- };
37
- /* istanbul ignore else */
38
- if (model.item.thumbnail) {
39
- createOptions.params = {
40
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
41
- thumbnail: model.item.thumbnail
42
- };
43
- delete createOptions.item.thumbnail;
44
- }
45
- // Create the item
46
- return ((0, arcgis_rest_portal_1.createItem)(createOptions)
47
- .then((createResponse) => {
48
- model.item.id = createResponse.id;
49
- const savedThumbnail = model.item.thumbnail;
50
- model = (0, hub_common_1.interpolateItemId)(model);
51
- model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary
52
- // Experiences store draft data in a resource attached to the item
53
- // We'll just use the published data for the first "draft"
54
- // changed from stringToBlob to objectToJsonBlob for issue #742
55
- const draftResourceModel = (0, hub_common_1.cloneObject)(model.data);
56
- resources.push({
57
- name: "config.json",
58
- prefix: "config",
59
- file: (0, hub_common_1.objectToJsonBlob)(draftResourceModel)
60
- });
61
- // there may also be this image resources list
62
- const imageListModel = (0, hub_common_1.cloneObject)(model.properties.imageResourcesList);
63
- if (imageListModel) {
64
- resources.push({
65
- name: "image-resources-list.json",
66
- prefix: "images",
67
- file: (0, hub_common_1.stringToBlob)(JSON.stringify(imageListModel))
68
- });
69
- }
70
- delete model.properties;
71
- // update the experience with the newly interpolated model
72
- const updateOptions = {
73
- item: (0, hub_common_1.serializeModel)(model),
74
- authentication
75
- };
76
- if (model.item.thumbnail) {
77
- updateOptions.params = {
78
- // Pass thumbnail file in via params because item property is serialized, which discards a blob
79
- thumbnail: model.item.thumbnail
80
- };
81
- delete updateOptions.item.thumbnail;
82
- }
83
- return Promise.all([
84
- (0, arcgis_rest_portal_1.updateItem)(updateOptions),
85
- authentication.getUsername()
86
- ]);
87
- })
88
- .then((responses) => {
89
- const username = responses[1];
90
- const failSafeAddItemResource = (0, hub_common_1.failSafe)(arcgis_rest_portal_1.addItemResource, {
91
- success: true
92
- });
93
- // upload the data and oembed resources
94
- const resourceUploadPromises = resources.map(resource => failSafeAddItemResource({
95
- id: model.item.id,
96
- owner: username,
97
- resource: resource.file,
98
- name: resource.name,
99
- prefix: resource.prefix,
100
- authentication
101
- }));
102
- // fire and forget
103
- return Promise.all(resourceUploadPromises);
104
- })
105
- // .then(() => {
106
- // // TODO: Can we leave this to the main process?
107
- // return uploadResourcesFromUrl(model, options.assets || [], authentication);
108
- // })
109
- .then(() => {
110
- // Move it
111
- return (0, arcgis_rest_portal_1.moveItem)({
112
- itemId: model.item.id,
113
- folderId,
114
- authentication
115
- });
116
- })
117
- .then(() => {
118
- return model;
119
- }));
120
- }
121
- exports.createWebExperience = createWebExperience;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWebExperience = void 0;
4
+ /** @license
5
+ * Copyright 2020 Esri
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const hub_common_1 = require("@esri/hub-common");
20
+ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
21
+ /**
22
+ * Given a Model for a Web Experience, create the item in the Portal API
23
+ *
24
+ * @param model
25
+ * @param options
26
+ * @param authentication
27
+ */
28
+ function createWebExperience(model, folderId, options, authentication) {
29
+ const resources = [];
30
+ // For unkown reasons we can not seem to spy on createItemInFolder
31
+ // so we will create-then-move for now
32
+ const createOptions = {
33
+ // need to serialize
34
+ item: (0, hub_common_1.serializeModel)(model),
35
+ authentication
36
+ };
37
+ /* istanbul ignore else */
38
+ if (model.item.thumbnail) {
39
+ createOptions.params = {
40
+ // Pass thumbnail file in via params because item property is serialized, which discards a blob
41
+ thumbnail: model.item.thumbnail
42
+ };
43
+ delete createOptions.item.thumbnail;
44
+ }
45
+ // Create the item
46
+ return ((0, arcgis_rest_portal_1.createItem)(createOptions)
47
+ .then((createResponse) => {
48
+ model.item.id = createResponse.id;
49
+ const savedThumbnail = model.item.thumbnail;
50
+ model = (0, hub_common_1.interpolateItemId)(model);
51
+ model.item.thumbnail = savedThumbnail; // interpolation trashes thumbnail binary
52
+ // Experiences store draft data in a resource attached to the item
53
+ // We'll just use the published data for the first "draft"
54
+ // changed from stringToBlob to objectToJsonBlob for issue #742
55
+ const draftResourceModel = (0, hub_common_1.cloneObject)(model.data);
56
+ resources.push({
57
+ name: "config.json",
58
+ prefix: "config",
59
+ file: (0, hub_common_1.objectToJsonBlob)(draftResourceModel)
60
+ });
61
+ // there may also be this image resources list
62
+ const imageListModel = (0, hub_common_1.cloneObject)(model.properties.imageResourcesList);
63
+ if (imageListModel) {
64
+ resources.push({
65
+ name: "image-resources-list.json",
66
+ prefix: "images",
67
+ file: (0, hub_common_1.stringToBlob)(JSON.stringify(imageListModel))
68
+ });
69
+ }
70
+ delete model.properties;
71
+ // update the experience with the newly interpolated model
72
+ const updateOptions = {
73
+ item: (0, hub_common_1.serializeModel)(model),
74
+ authentication
75
+ };
76
+ if (model.item.thumbnail) {
77
+ updateOptions.params = {
78
+ // Pass thumbnail file in via params because item property is serialized, which discards a blob
79
+ thumbnail: model.item.thumbnail
80
+ };
81
+ delete updateOptions.item.thumbnail;
82
+ }
83
+ return Promise.all([
84
+ (0, arcgis_rest_portal_1.updateItem)(updateOptions),
85
+ authentication.getUsername()
86
+ ]);
87
+ })
88
+ .then((responses) => {
89
+ const username = responses[1];
90
+ const failSafeAddItemResource = (0, hub_common_1.failSafe)(arcgis_rest_portal_1.addItemResource, {
91
+ success: true
92
+ });
93
+ // upload the data and oembed resources
94
+ const resourceUploadPromises = resources.map(resource => failSafeAddItemResource({
95
+ id: model.item.id,
96
+ owner: username,
97
+ resource: resource.file,
98
+ name: resource.name,
99
+ prefix: resource.prefix,
100
+ authentication
101
+ }));
102
+ // fire and forget
103
+ return Promise.all(resourceUploadPromises);
104
+ })
105
+ // .then(() => {
106
+ // // TODO: Can we leave this to the main process?
107
+ // return uploadResourcesFromUrl(model, options.assets || [], authentication);
108
+ // })
109
+ .then(() => {
110
+ // Move it
111
+ return (0, arcgis_rest_portal_1.moveItem)({
112
+ itemId: model.item.id,
113
+ folderId,
114
+ authentication
115
+ });
116
+ })
117
+ .then(() => {
118
+ return model;
119
+ }));
120
+ }
121
+ exports.createWebExperience = createWebExperience;
122
122
  //# sourceMappingURL=create-web-experience.js.map