@esri/solution-deployer 4.1.2 → 5.0.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 (41) hide show
  1. package/dist/cjs/deploySolutionFromTemplate.d.ts +48 -48
  2. package/dist/cjs/deploySolutionFromTemplate.js +331 -331
  3. package/dist/cjs/deploySolutionFromTemplate.js.map +1 -1
  4. package/dist/cjs/deploySolutionItems.d.ts +224 -224
  5. package/dist/cjs/deploySolutionItems.js +853 -849
  6. package/dist/cjs/deploySolutionItems.js.map +1 -1
  7. package/dist/cjs/deployer.d.ts +34 -34
  8. package/dist/cjs/deployer.js +101 -101
  9. package/dist/cjs/deployerUtils.d.ts +47 -47
  10. package/dist/cjs/deployerUtils.js +123 -123
  11. package/dist/cjs/helpers/post-process.d.ts +29 -29
  12. package/dist/cjs/helpers/post-process.js +61 -61
  13. package/dist/cjs/helpers/share-templates-to-groups.d.ts +24 -24
  14. package/dist/cjs/helpers/share-templates-to-groups.js +64 -64
  15. package/dist/cjs/helpers/sortTemplates.d.ts +23 -23
  16. package/dist/cjs/helpers/sortTemplates.js +14 -14
  17. package/dist/cjs/index.d.ts +24 -24
  18. package/dist/cjs/index.js +27 -27
  19. package/dist/cjs/module-map.d.ts +23 -23
  20. package/dist/cjs/module-map.js +195 -195
  21. package/dist/esm/deploySolutionFromTemplate.d.ts +48 -48
  22. package/dist/esm/deploySolutionFromTemplate.js +317 -317
  23. package/dist/esm/deploySolutionFromTemplate.js.map +1 -1
  24. package/dist/esm/deploySolutionItems.d.ts +224 -224
  25. package/dist/esm/deploySolutionItems.js +830 -826
  26. package/dist/esm/deploySolutionItems.js.map +1 -1
  27. package/dist/esm/deployer.d.ts +34 -34
  28. package/dist/esm/deployer.js +96 -96
  29. package/dist/esm/deployerUtils.d.ts +47 -47
  30. package/dist/esm/deployerUtils.js +115 -115
  31. package/dist/esm/helpers/post-process.d.ts +29 -29
  32. package/dist/esm/helpers/post-process.js +57 -57
  33. package/dist/esm/helpers/share-templates-to-groups.d.ts +24 -24
  34. package/dist/esm/helpers/share-templates-to-groups.js +60 -60
  35. package/dist/esm/helpers/sortTemplates.d.ts +23 -23
  36. package/dist/esm/helpers/sortTemplates.js +10 -10
  37. package/dist/esm/index.d.ts +24 -24
  38. package/dist/esm/index.js +24 -24
  39. package/dist/esm/module-map.d.ts +23 -23
  40. package/dist/esm/module-map.js +191 -191
  41. package/package.json +12 -12
@@ -1,116 +1,116 @@
1
- /** @license
2
- * Copyright 2018 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 * as common from "@esri/solution-common";
17
- /**
18
- * Given an itemId or an object, either fetch the item or
19
- * resolve using the object, if it is structured as expected
20
- *
21
- * @param idOrObject string || object like `{item:{...}, data: {...}}`
22
- * @param authentication UserSession
23
- */
24
- export function getSolutionTemplateItem(idOrObject, authentication) {
25
- if (typeof idOrObject === "string") {
26
- // get the item + data
27
- return Promise.all([
28
- common.getItemBase(idOrObject, authentication),
29
- common.getItemDataAsJson(idOrObject, authentication)
30
- ]).then(([item, data]) => {
31
- // format into a model and migrate the schema
32
- return common.migrateSchema({
33
- item,
34
- data
35
- });
36
- });
37
- }
38
- else {
39
- // check if it is a "Model"
40
- if (_isModel(idOrObject)) {
41
- // run migrations
42
- return common.migrateSchema(idOrObject);
43
- }
44
- else {
45
- return Promise.reject(common.fail(`getSolutionTemplateItem must be passed an item id or a model object`));
46
- }
47
- }
48
- }
49
- /**
50
- * Update the Deploy Options with information from the
51
- * Solution Template item
52
- *
53
- * @param deployOptions
54
- * @param item
55
- * @param authentication
56
- */
57
- export function updateDeployOptions(deployOptions, item, authentication) {
58
- deployOptions.jobId = deployOptions.jobId ?? item.id;
59
- deployOptions.title = deployOptions.title ?? item.title;
60
- deployOptions.snippet = deployOptions.snippet ?? item.snippet;
61
- deployOptions.description = deployOptions.description ?? item.description;
62
- deployOptions.tags = deployOptions.tags ?? item.tags;
63
- // add the thumbnail url
64
- deployOptions.thumbnailurl = item.thumbnail
65
- ? common.getItemThumbnailUrl(item.id, item.thumbnail, false, authentication)
66
- : null;
67
- return deployOptions;
68
- }
69
- /**
70
- * Check if an object is an Model
71
- *
72
- * @param obj any object
73
- * @private
74
- */
75
- export function _isModel(obj) {
76
- let result = false;
77
- // TODO Hoist into common?
78
- const isNotStringOrArray = (v) => v != null &&
79
- typeof v !== "string" &&
80
- !Array.isArray(v) &&
81
- typeof v === "object";
82
- if (isNotStringOrArray(obj)) {
83
- result = ["item", "data"].reduce((acc, prop) => {
84
- if (acc) {
85
- acc = isNotStringOrArray(obj[prop]);
86
- }
87
- return acc;
88
- }, true);
89
- }
90
- return result;
91
- }
92
- /**
93
- * Does the item have the correct type and keywords
94
- * to be a Solution Template item?
95
- *
96
- * @param item IItem
97
- */
98
- export function isSolutionTemplateItem(item) {
99
- const kwds = item.typeKeywords;
100
- // Solution items
101
- let result = false;
102
- if (item.type === "Solution") {
103
- if (kwds.indexOf("Solution") > -1 &&
104
- (kwds.indexOf("Template") > -1 || kwds.indexOf("solutionTemplate") > -1)) {
105
- result = true;
106
- }
107
- }
108
- // Older Hub Solutions used Web Mapping Application items
109
- if (item.type === "Web Mapping Application") {
110
- if (kwds.indexOf("hubSolutionTemplate") > -1) {
111
- result = true;
112
- }
113
- }
114
- return result;
115
- }
1
+ /** @license
2
+ * Copyright 2018 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 * as common from "@esri/solution-common";
17
+ /**
18
+ * Given an itemId or an object, either fetch the item or
19
+ * resolve using the object, if it is structured as expected
20
+ *
21
+ * @param idOrObject string || object like `{item:{...}, data: {...}}`
22
+ * @param authentication UserSession
23
+ */
24
+ export function getSolutionTemplateItem(idOrObject, authentication) {
25
+ if (typeof idOrObject === "string") {
26
+ // get the item + data
27
+ return Promise.all([
28
+ common.getItemBase(idOrObject, authentication),
29
+ common.getItemDataAsJson(idOrObject, authentication)
30
+ ]).then(([item, data]) => {
31
+ // format into a model and migrate the schema
32
+ return common.migrateSchema({
33
+ item,
34
+ data
35
+ });
36
+ });
37
+ }
38
+ else {
39
+ // check if it is a "Model"
40
+ if (_isModel(idOrObject)) {
41
+ // run migrations
42
+ return common.migrateSchema(idOrObject);
43
+ }
44
+ else {
45
+ return Promise.reject(common.fail(`getSolutionTemplateItem must be passed an item id or a model object`));
46
+ }
47
+ }
48
+ }
49
+ /**
50
+ * Update the Deploy Options with information from the
51
+ * Solution Template item
52
+ *
53
+ * @param deployOptions
54
+ * @param item
55
+ * @param authentication
56
+ */
57
+ export function updateDeployOptions(deployOptions, item, authentication) {
58
+ deployOptions.jobId = deployOptions.jobId ?? item.id;
59
+ deployOptions.title = deployOptions.title ?? item.title;
60
+ deployOptions.snippet = deployOptions.snippet ?? item.snippet;
61
+ deployOptions.description = deployOptions.description ?? item.description;
62
+ deployOptions.tags = deployOptions.tags ?? item.tags;
63
+ // add the thumbnail url
64
+ deployOptions.thumbnailurl = item.thumbnail
65
+ ? common.getItemThumbnailUrl(item.id, item.thumbnail, false, authentication)
66
+ : null;
67
+ return deployOptions;
68
+ }
69
+ /**
70
+ * Check if an object is an Model
71
+ *
72
+ * @param obj any object
73
+ * @private
74
+ */
75
+ export function _isModel(obj) {
76
+ let result = false;
77
+ // TODO Hoist into common?
78
+ const isNotStringOrArray = (v) => v != null &&
79
+ typeof v !== "string" &&
80
+ !Array.isArray(v) &&
81
+ typeof v === "object";
82
+ if (isNotStringOrArray(obj)) {
83
+ result = ["item", "data"].reduce((acc, prop) => {
84
+ if (acc) {
85
+ acc = isNotStringOrArray(obj[prop]);
86
+ }
87
+ return acc;
88
+ }, true);
89
+ }
90
+ return result;
91
+ }
92
+ /**
93
+ * Does the item have the correct type and keywords
94
+ * to be a Solution Template item?
95
+ *
96
+ * @param item IItem
97
+ */
98
+ export function isSolutionTemplateItem(item) {
99
+ const kwds = item.typeKeywords;
100
+ // Solution items
101
+ let result = false;
102
+ if (item.type === "Solution") {
103
+ if (kwds.indexOf("Solution") > -1 &&
104
+ (kwds.indexOf("Template") > -1 || kwds.indexOf("solutionTemplate") > -1)) {
105
+ result = true;
106
+ }
107
+ }
108
+ // Older Hub Solutions used Web Mapping Application items
109
+ if (item.type === "Web Mapping Application") {
110
+ if (kwds.indexOf("hubSolutionTemplate") > -1) {
111
+ result = true;
112
+ }
113
+ }
114
+ return result;
115
+ }
116
116
  //# sourceMappingURL=deployerUtils.js.map
@@ -1,29 +1,29 @@
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 { UserSession, IItemTemplate, ICreateItemFromTemplateResponse } from "@esri/solution-common";
17
- /**
18
- * Delegate post-processing to the type specific
19
- * processors. This allows each type to have fine-grained
20
- * control over what they do. Common post-processing is
21
- * exposed as functions that can be imported
22
- *
23
- * @param deployedSolutionId
24
- * @param templates
25
- * @param clonedSolutions
26
- * @param authentication
27
- * @param templateDictionary
28
- */
29
- export declare function postProcess(deployedSolutionId: string, templates: IItemTemplate[], clonedSolutions: ICreateItemFromTemplateResponse[], authentication: UserSession, templateDictionary: any): 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 { UserSession, IItemTemplate, ICreateItemFromTemplateResponse } from "@esri/solution-common";
17
+ /**
18
+ * Delegate post-processing to the type specific
19
+ * processors. This allows each type to have fine-grained
20
+ * control over what they do. Common post-processing is
21
+ * exposed as functions that can be imported
22
+ *
23
+ * @param deployedSolutionId
24
+ * @param templates
25
+ * @param clonedSolutions
26
+ * @param authentication
27
+ * @param templateDictionary
28
+ */
29
+ export declare function postProcess(deployedSolutionId: string, templates: IItemTemplate[], clonedSolutions: ICreateItemFromTemplateResponse[], authentication: UserSession, templateDictionary: any): Promise<any>;
@@ -1,58 +1,58 @@
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 { getTemplateById } from "@esri/solution-common";
17
- import { addItemRelationship } from "@esri/arcgis-rest-portal";
18
- import { moduleMap } from "../module-map";
19
- import { shareTemplatesToGroups } from "./share-templates-to-groups";
20
- /**
21
- * Delegate post-processing to the type specific
22
- * processors. This allows each type to have fine-grained
23
- * control over what they do. Common post-processing is
24
- * exposed as functions that can be imported
25
- *
26
- * @param deployedSolutionId
27
- * @param templates
28
- * @param clonedSolutions
29
- * @param authentication
30
- * @param templateDictionary
31
- */
32
- export function postProcess(deployedSolutionId, templates, clonedSolutions, authentication, templateDictionary) {
33
- // connect the solution with its items; groups cannot be connected
34
- const relationshipPromises = clonedSolutions
35
- .filter(entry => entry.type !== "Group")
36
- .map(entry => addItemRelationship({
37
- originItemId: deployedSolutionId,
38
- destinationItemId: entry.id,
39
- relationshipType: "Solution2Item",
40
- authentication: authentication
41
- }) // TODO: remove `as any`, which is here until arcgis-rest-js' ItemRelationshipType defn catches up
42
- );
43
- // delegate sharing to groups
44
- const sharePromises = shareTemplatesToGroups(templates, templateDictionary, authentication);
45
- // what needs post processing?
46
- const itemsToProcess = clonedSolutions.filter(entry => entry.postProcess);
47
- // map over these items
48
- const postProcessPromises = itemsToProcess.reduce((acc, entry) => {
49
- const itemHandler = moduleMap[entry.type];
50
- // only delegate if the handler has a postProcess method
51
- if (itemHandler && itemHandler.postProcess) {
52
- acc.push(itemHandler.postProcess(entry.id, entry.type, clonedSolutions, getTemplateById(templates, entry.id), templates, templateDictionary, authentication));
53
- }
54
- return acc;
55
- }, []);
56
- return Promise.all([sharePromises].concat(postProcessPromises, relationshipPromises));
57
- }
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 { getTemplateById } from "@esri/solution-common";
17
+ import { addItemRelationship } from "@esri/arcgis-rest-portal";
18
+ import { moduleMap } from "../module-map";
19
+ import { shareTemplatesToGroups } from "./share-templates-to-groups";
20
+ /**
21
+ * Delegate post-processing to the type specific
22
+ * processors. This allows each type to have fine-grained
23
+ * control over what they do. Common post-processing is
24
+ * exposed as functions that can be imported
25
+ *
26
+ * @param deployedSolutionId
27
+ * @param templates
28
+ * @param clonedSolutions
29
+ * @param authentication
30
+ * @param templateDictionary
31
+ */
32
+ export function postProcess(deployedSolutionId, templates, clonedSolutions, authentication, templateDictionary) {
33
+ // connect the solution with its items; groups cannot be connected
34
+ const relationshipPromises = clonedSolutions
35
+ .filter(entry => entry.type !== "Group")
36
+ .map(entry => addItemRelationship({
37
+ originItemId: deployedSolutionId,
38
+ destinationItemId: entry.id,
39
+ relationshipType: "Solution2Item",
40
+ authentication: authentication
41
+ }) // TODO: remove `as any`, which is here until arcgis-rest-js' ItemRelationshipType defn catches up
42
+ );
43
+ // delegate sharing to groups
44
+ const sharePromises = shareTemplatesToGroups(templates, templateDictionary, authentication);
45
+ // what needs post processing?
46
+ const itemsToProcess = clonedSolutions.filter(entry => entry.postProcess);
47
+ // map over these items
48
+ const postProcessPromises = itemsToProcess.reduce((acc, entry) => {
49
+ const itemHandler = moduleMap[entry.type];
50
+ // only delegate if the handler has a postProcess method
51
+ if (itemHandler && itemHandler.postProcess) {
52
+ acc.push(itemHandler.postProcess(entry.id, entry.type, clonedSolutions, getTemplateById(templates, entry.id), templates, templateDictionary, authentication));
53
+ }
54
+ return acc;
55
+ }, []);
56
+ return Promise.all([sharePromises].concat(postProcessPromises, relationshipPromises));
57
+ }
58
58
  //# sourceMappingURL=post-process.js.map
@@ -1,24 +1,24 @@
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 { IItemTemplate, UserSession } from "@esri/solution-common";
17
- /**
18
- * Given the created templates
19
- *
20
- * @param templates
21
- * @param templateDictionary
22
- * @param authentication
23
- */
24
- export declare function shareTemplatesToGroups(templates: IItemTemplate[], templateDictionary: 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 { IItemTemplate, UserSession } from "@esri/solution-common";
17
+ /**
18
+ * Given the created templates
19
+ *
20
+ * @param templates
21
+ * @param templateDictionary
22
+ * @param authentication
23
+ */
24
+ export declare function shareTemplatesToGroups(templates: IItemTemplate[], templateDictionary: any, authentication: UserSession): Promise<any>;
@@ -1,61 +1,61 @@
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 { getProp, shareItemToGroups, isTrackingViewTemplate, replaceInTemplate } from "@esri/solution-common";
17
- import { maybePush } from "@esri/hub-common";
18
- /**
19
- * Given the created templates
20
- *
21
- * @param templates
22
- * @param templateDictionary
23
- * @param authentication
24
- */
25
- export function shareTemplatesToGroups(templates, templateDictionary, authentication) {
26
- // Filter to entries with groups to share to
27
- const templatesWithGroups = templates.filter(e => {
28
- return e.groups && e.groups.length > 0;
29
- });
30
- // fire off all the promises
31
- return Promise.all(templatesWithGroups.map(tmpl => {
32
- const groupIds = tmpl.groups.reduce((acc, sourceGroupId) => {
33
- return maybePush(getProp(templateDictionary, `${sourceGroupId}.itemId`), acc);
34
- }, []);
35
- // need to pass the tracking owner when sharing to tracking group
36
- if (isTrackingViewTemplate(tmpl) && !getProp(templateDictionary, "locationTracking.userIsOwner")) {
37
- const trackingGroupId = getProp(tmpl, "item.properties.trackViewGroup");
38
- const owner = getProp(templateDictionary, "locationTracking.owner");
39
- /* istanbul ignore else */
40
- if (trackingGroupId && owner) {
41
- const trackerGroupIds = groupIds.filter(id => {
42
- return id === replaceInTemplate(trackingGroupId, templateDictionary);
43
- });
44
- if (trackerGroupIds.length !== groupIds.length) {
45
- const nonTrackerGroupIds = groupIds.filter(id => id !== trackingGroupId);
46
- return Promise.all([
47
- shareItemToGroups(trackerGroupIds, tmpl.itemId, authentication, owner),
48
- shareItemToGroups(nonTrackerGroupIds, tmpl.itemId, authentication)
49
- ]);
50
- }
51
- else {
52
- return shareItemToGroups(groupIds, tmpl.itemId, authentication, owner);
53
- }
54
- }
55
- }
56
- else {
57
- return shareItemToGroups(groupIds, tmpl.itemId, authentication);
58
- }
59
- }));
60
- }
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 { getProp, shareItemToGroups, isTrackingViewTemplate, replaceInTemplate } from "@esri/solution-common";
17
+ import { maybePush } from "@esri/hub-common";
18
+ /**
19
+ * Given the created templates
20
+ *
21
+ * @param templates
22
+ * @param templateDictionary
23
+ * @param authentication
24
+ */
25
+ export function shareTemplatesToGroups(templates, templateDictionary, authentication) {
26
+ // Filter to entries with groups to share to
27
+ const templatesWithGroups = templates.filter(e => {
28
+ return e.groups && e.groups.length > 0;
29
+ });
30
+ // fire off all the promises
31
+ return Promise.all(templatesWithGroups.map(tmpl => {
32
+ const groupIds = tmpl.groups.reduce((acc, sourceGroupId) => {
33
+ return maybePush(getProp(templateDictionary, `${sourceGroupId}.itemId`), acc);
34
+ }, []);
35
+ // need to pass the tracking owner when sharing to tracking group
36
+ if (isTrackingViewTemplate(tmpl) && !getProp(templateDictionary, "locationTracking.userIsOwner")) {
37
+ const trackingGroupId = getProp(tmpl, "item.properties.trackViewGroup");
38
+ const owner = getProp(templateDictionary, "locationTracking.owner");
39
+ /* istanbul ignore else */
40
+ if (trackingGroupId && owner) {
41
+ const trackerGroupIds = groupIds.filter(id => {
42
+ return id === replaceInTemplate(trackingGroupId, templateDictionary);
43
+ });
44
+ if (trackerGroupIds.length !== groupIds.length) {
45
+ const nonTrackerGroupIds = groupIds.filter(id => id !== trackingGroupId);
46
+ return Promise.all([
47
+ shareItemToGroups(trackerGroupIds, tmpl.itemId, authentication, owner),
48
+ shareItemToGroups(nonTrackerGroupIds, tmpl.itemId, authentication)
49
+ ]);
50
+ }
51
+ else {
52
+ return shareItemToGroups(groupIds, tmpl.itemId, authentication, owner);
53
+ }
54
+ }
55
+ }
56
+ else {
57
+ return shareItemToGroups(groupIds, tmpl.itemId, authentication);
58
+ }
59
+ }));
60
+ }
61
61
  //# sourceMappingURL=share-templates-to-groups.js.map
@@ -1,23 +1,23 @@
1
- /** @license
2
- * Copyright 2021 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 { IItemTemplate } from "@esri/solution-common";
17
- /**
18
- * Sorts a list of templates in place to match a provided sort-order list.
19
- *
20
- * @param templates List of templates in a Solution
21
- * @param sortOrderIds List of template ids in the desired sort order
22
- */
23
- export declare function sortTemplates(templates: IItemTemplate[], sortOrderIds: string[]): void;
1
+ /** @license
2
+ * Copyright 2021 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 { IItemTemplate } from "@esri/solution-common";
17
+ /**
18
+ * Sorts a list of templates in place to match a provided sort-order list.
19
+ *
20
+ * @param templates List of templates in a Solution
21
+ * @param sortOrderIds List of template ids in the desired sort order
22
+ */
23
+ export declare function sortTemplates(templates: IItemTemplate[], sortOrderIds: string[]): void;
@@ -1,11 +1,11 @@
1
- /**
2
- * Sorts a list of templates in place to match a provided sort-order list.
3
- *
4
- * @param templates List of templates in a Solution
5
- * @param sortOrderIds List of template ids in the desired sort order
6
- */
7
- export function sortTemplates(templates, sortOrderIds) {
8
- templates.sort((template1, template2) => sortOrderIds.indexOf(template1.itemId) -
9
- sortOrderIds.indexOf(template2.itemId));
10
- }
1
+ /**
2
+ * Sorts a list of templates in place to match a provided sort-order list.
3
+ *
4
+ * @param templates List of templates in a Solution
5
+ * @param sortOrderIds List of template ids in the desired sort order
6
+ */
7
+ export function sortTemplates(templates, sortOrderIds) {
8
+ templates.sort((template1, template2) => sortOrderIds.indexOf(template1.itemId) -
9
+ sortOrderIds.indexOf(template2.itemId));
10
+ }
11
11
  //# sourceMappingURL=sortTemplates.js.map