@esri/solution-file 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.
@@ -1,32 +1,32 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- import * as common from "@esri/solution-common";
22
- /**
23
- * Converts a file item into a template.
24
- *
25
- * @param solutionItemId The solution to contain the template
26
- * @param itemInfo Info about the item
27
- * @param destAuthentication Credentials for requests to the destination organization
28
- * @param srcAuthentication Credentials for requests to source items
29
- * @returns A promise that will resolve when the template has been created
30
- */
31
- export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: common.UserSession, srcAuthentication: common.UserSession): Promise<common.IItemTemplate>;
32
- export declare function createItemFromTemplate(template: common.IItemTemplate, templateDictionary: any, destinationAuthentication: common.UserSession, itemProgressCallback: common.IItemProgressCallback): Promise<common.ICreateItemFromTemplateResponse>;
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ import * as common from "@esri/solution-common";
22
+ /**
23
+ * Converts a file item into a template.
24
+ *
25
+ * @param solutionItemId The solution to contain the template
26
+ * @param itemInfo Info about the item
27
+ * @param destAuthentication Credentials for requests to the destination organization
28
+ * @param srcAuthentication Credentials for requests to source items
29
+ * @returns A promise that will resolve when the template has been created
30
+ */
31
+ export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: common.UserSession, srcAuthentication: common.UserSession): Promise<common.IItemTemplate>;
32
+ export declare function createItemFromTemplate(template: common.IItemTemplate, templateDictionary: any, destinationAuthentication: common.UserSession, itemProgressCallback: common.IItemProgressCallback): Promise<common.ICreateItemFromTemplateResponse>;
package/dist/cjs/file.js CHANGED
@@ -1,134 +1,134 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2018 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.createItemFromTemplate = exports.convertItemToTemplate = void 0;
19
- const tslib_1 = require("tslib");
20
- /**
21
- * Manages the creation and deployment of item types that contain files.
22
- *
23
- * @module file
24
- */
25
- const common = tslib_1.__importStar(require("@esri/solution-common"));
26
- // ------------------------------------------------------------------------------------------------------------------ //
27
- /**
28
- * Converts a file item into a template.
29
- *
30
- * @param solutionItemId The solution to contain the template
31
- * @param itemInfo Info about the item
32
- * @param destAuthentication Credentials for requests to the destination organization
33
- * @param srcAuthentication Credentials for requests to source items
34
- * @returns A promise that will resolve when the template has been created
35
- */
36
- function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
37
- return new Promise(resolve => {
38
- // Init template
39
- const itemTemplate = common.createInitializedItemTemplate(itemInfo);
40
- // Templatize item info property values
41
- itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
42
- // Request file
43
- const dataPromise = new Promise(dataResolve => {
44
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
45
- common
46
- .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
47
- .then(response => {
48
- if (!response || response.size === 0) {
49
- dataResolve(null);
50
- }
51
- else {
52
- dataResolve(response);
53
- }
54
- });
55
- });
56
- // Request related items
57
- const relatedPromise = Promise.resolve({});
58
- // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
59
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
60
- Promise.all([dataPromise, relatedPromise]).then(responses => {
61
- const [itemDataResponse] = responses;
62
- if (itemDataResponse) {
63
- const resource = common.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
64
- itemTemplate.properties[resource.filename] = resource.mimeType;
65
- const storageName = common.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
66
- ? common.SolutionResourceType.data
67
- : common.SolutionResourceType.fakezip));
68
- // Add the data file to the template so that it can be uploaded with the other resources in the solution
69
- const dataFile = {
70
- itemId: itemTemplate.itemId,
71
- file: resource.blob,
72
- folder: storageName.folder,
73
- filename: storageName.filename
74
- };
75
- itemTemplate.dataFile = dataFile;
76
- // Update the template's resources
77
- itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
78
- resolve(itemTemplate);
79
- }
80
- else {
81
- resolve(itemTemplate);
82
- }
83
- });
84
- });
85
- }
86
- exports.convertItemToTemplate = convertItemToTemplate;
87
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
88
- return new Promise(resolve => {
89
- // Interrupt process if progress callback returns `false`
90
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
91
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
92
- resolve(common.generateEmptyCreationResponse(template.type));
93
- return;
94
- }
95
- // Replace the templatized symbols in a copy of the template
96
- let newItemTemplate = common.cloneObject(template);
97
- newItemTemplate = common.replaceInTemplate(newItemTemplate, templateDictionary);
98
- /* istanbul ignore else */
99
- if (template.item.thumbnail) {
100
- newItemTemplate.item.thumbnail = template.item.thumbnail;
101
- }
102
- // Create the item, then update its URL with its new id
103
- common
104
- .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
105
- .then(createResponse => {
106
- // Interrupt process if progress callback returns `false`
107
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
108
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
109
- common
110
- .removeItem(createResponse.id, destinationAuthentication)
111
- .then(() => resolve(common.generateEmptyCreationResponse(template.type)), () => resolve(common.generateEmptyCreationResponse(template.type)));
112
- }
113
- else {
114
- // Add the new item to the settings
115
- newItemTemplate.itemId = createResponse.id;
116
- templateDictionary[template.itemId] = {
117
- itemId: createResponse.id
118
- };
119
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
120
- resolve({
121
- item: newItemTemplate,
122
- id: createResponse.id,
123
- type: newItemTemplate.type,
124
- postProcess: false
125
- });
126
- }
127
- }, () => {
128
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
129
- resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
130
- });
131
- });
132
- }
133
- exports.createItemFromTemplate = createItemFromTemplate;
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2018 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.createItemFromTemplate = exports.convertItemToTemplate = void 0;
19
+ const tslib_1 = require("tslib");
20
+ /**
21
+ * Manages the creation and deployment of item types that contain files.
22
+ *
23
+ * @module file
24
+ */
25
+ const common = tslib_1.__importStar(require("@esri/solution-common"));
26
+ // ------------------------------------------------------------------------------------------------------------------ //
27
+ /**
28
+ * Converts a file item into a template.
29
+ *
30
+ * @param solutionItemId The solution to contain the template
31
+ * @param itemInfo Info about the item
32
+ * @param destAuthentication Credentials for requests to the destination organization
33
+ * @param srcAuthentication Credentials for requests to source items
34
+ * @returns A promise that will resolve when the template has been created
35
+ */
36
+ function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
37
+ return new Promise(resolve => {
38
+ // Init template
39
+ const itemTemplate = common.createInitializedItemTemplate(itemInfo);
40
+ // Templatize item info property values
41
+ itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
42
+ // Request file
43
+ const dataPromise = new Promise(dataResolve => {
44
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
45
+ common
46
+ .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
47
+ .then(response => {
48
+ if (!response || response.size === 0) {
49
+ dataResolve(null);
50
+ }
51
+ else {
52
+ dataResolve(response);
53
+ }
54
+ });
55
+ });
56
+ // Request related items
57
+ const relatedPromise = Promise.resolve({});
58
+ // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
59
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
60
+ Promise.all([dataPromise, relatedPromise]).then(responses => {
61
+ const [itemDataResponse] = responses;
62
+ if (itemDataResponse) {
63
+ const resource = common.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
64
+ itemTemplate.properties[resource.filename] = resource.mimeType;
65
+ const storageName = common.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
66
+ ? common.SolutionResourceType.data
67
+ : common.SolutionResourceType.fakezip));
68
+ // Add the data file to the template so that it can be uploaded with the other resources in the solution
69
+ const dataFile = {
70
+ itemId: itemTemplate.itemId,
71
+ file: resource.blob,
72
+ folder: storageName.folder,
73
+ filename: storageName.filename
74
+ };
75
+ itemTemplate.dataFile = dataFile;
76
+ // Update the template's resources
77
+ itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
78
+ resolve(itemTemplate);
79
+ }
80
+ else {
81
+ resolve(itemTemplate);
82
+ }
83
+ });
84
+ });
85
+ }
86
+ exports.convertItemToTemplate = convertItemToTemplate;
87
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
88
+ return new Promise(resolve => {
89
+ // Interrupt process if progress callback returns `false`
90
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
91
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
92
+ resolve(common.generateEmptyCreationResponse(template.type));
93
+ return;
94
+ }
95
+ // Replace the templatized symbols in a copy of the template
96
+ let newItemTemplate = common.cloneObject(template);
97
+ newItemTemplate = common.replaceInTemplate(newItemTemplate, templateDictionary);
98
+ /* istanbul ignore else */
99
+ if (template.item.thumbnail) {
100
+ newItemTemplate.item.thumbnail = template.item.thumbnail;
101
+ }
102
+ // Create the item, then update its URL with its new id
103
+ common
104
+ .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
105
+ .then(createResponse => {
106
+ // Interrupt process if progress callback returns `false`
107
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
108
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
109
+ common
110
+ .removeItem(createResponse.id, destinationAuthentication)
111
+ .then(() => resolve(common.generateEmptyCreationResponse(template.type)), () => resolve(common.generateEmptyCreationResponse(template.type)));
112
+ }
113
+ else {
114
+ // Add the new item to the settings
115
+ newItemTemplate.itemId = createResponse.id;
116
+ templateDictionary[template.itemId] = {
117
+ itemId: createResponse.id
118
+ };
119
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
120
+ resolve({
121
+ item: newItemTemplate,
122
+ id: createResponse.id,
123
+ type: newItemTemplate.type,
124
+ postProcess: false
125
+ });
126
+ }
127
+ }, () => {
128
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
129
+ resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
130
+ });
131
+ });
132
+ }
133
+ exports.createItemFromTemplate = createItemFromTemplate;
134
134
  //# sourceMappingURL=file.js.map
@@ -1,21 +1,21 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- export * from "./file";
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ export * from "./file";
package/dist/cjs/index.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2018 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
- const tslib_1 = require("tslib");
19
- /**
20
- * Manages the creation and deployment of item types that contain files.
21
- *
22
- * @module file
23
- */
24
- tslib_1.__exportStar(require("./file"), exports);
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2018 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
+ const tslib_1 = require("tslib");
19
+ /**
20
+ * Manages the creation and deployment of item types that contain files.
21
+ *
22
+ * @module file
23
+ */
24
+ tslib_1.__exportStar(require("./file"), exports);
25
25
  //# sourceMappingURL=index.js.map
@@ -1,32 +1,32 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- import * as common from "@esri/solution-common";
22
- /**
23
- * Converts a file item into a template.
24
- *
25
- * @param solutionItemId The solution to contain the template
26
- * @param itemInfo Info about the item
27
- * @param destAuthentication Credentials for requests to the destination organization
28
- * @param srcAuthentication Credentials for requests to source items
29
- * @returns A promise that will resolve when the template has been created
30
- */
31
- export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: common.UserSession, srcAuthentication: common.UserSession): Promise<common.IItemTemplate>;
32
- export declare function createItemFromTemplate(template: common.IItemTemplate, templateDictionary: any, destinationAuthentication: common.UserSession, itemProgressCallback: common.IItemProgressCallback): Promise<common.ICreateItemFromTemplateResponse>;
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ import * as common from "@esri/solution-common";
22
+ /**
23
+ * Converts a file item into a template.
24
+ *
25
+ * @param solutionItemId The solution to contain the template
26
+ * @param itemInfo Info about the item
27
+ * @param destAuthentication Credentials for requests to the destination organization
28
+ * @param srcAuthentication Credentials for requests to source items
29
+ * @returns A promise that will resolve when the template has been created
30
+ */
31
+ export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: common.UserSession, srcAuthentication: common.UserSession): Promise<common.IItemTemplate>;
32
+ export declare function createItemFromTemplate(template: common.IItemTemplate, templateDictionary: any, destinationAuthentication: common.UserSession, itemProgressCallback: common.IItemProgressCallback): Promise<common.ICreateItemFromTemplateResponse>;
package/dist/esm/file.js CHANGED
@@ -1,128 +1,128 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- import * as common from "@esri/solution-common";
22
- // ------------------------------------------------------------------------------------------------------------------ //
23
- /**
24
- * Converts a file item into a template.
25
- *
26
- * @param solutionItemId The solution to contain the template
27
- * @param itemInfo Info about the item
28
- * @param destAuthentication Credentials for requests to the destination organization
29
- * @param srcAuthentication Credentials for requests to source items
30
- * @returns A promise that will resolve when the template has been created
31
- */
32
- export function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
33
- return new Promise(resolve => {
34
- // Init template
35
- const itemTemplate = common.createInitializedItemTemplate(itemInfo);
36
- // Templatize item info property values
37
- itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
38
- // Request file
39
- const dataPromise = new Promise(dataResolve => {
40
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
41
- common
42
- .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
43
- .then(response => {
44
- if (!response || response.size === 0) {
45
- dataResolve(null);
46
- }
47
- else {
48
- dataResolve(response);
49
- }
50
- });
51
- });
52
- // Request related items
53
- const relatedPromise = Promise.resolve({});
54
- // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
55
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
56
- Promise.all([dataPromise, relatedPromise]).then(responses => {
57
- const [itemDataResponse] = responses;
58
- if (itemDataResponse) {
59
- const resource = common.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
60
- itemTemplate.properties[resource.filename] = resource.mimeType;
61
- const storageName = common.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
62
- ? common.SolutionResourceType.data
63
- : common.SolutionResourceType.fakezip));
64
- // Add the data file to the template so that it can be uploaded with the other resources in the solution
65
- const dataFile = {
66
- itemId: itemTemplate.itemId,
67
- file: resource.blob,
68
- folder: storageName.folder,
69
- filename: storageName.filename
70
- };
71
- itemTemplate.dataFile = dataFile;
72
- // Update the template's resources
73
- itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
74
- resolve(itemTemplate);
75
- }
76
- else {
77
- resolve(itemTemplate);
78
- }
79
- });
80
- });
81
- }
82
- export function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
83
- return new Promise(resolve => {
84
- // Interrupt process if progress callback returns `false`
85
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
86
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
87
- resolve(common.generateEmptyCreationResponse(template.type));
88
- return;
89
- }
90
- // Replace the templatized symbols in a copy of the template
91
- let newItemTemplate = common.cloneObject(template);
92
- newItemTemplate = common.replaceInTemplate(newItemTemplate, templateDictionary);
93
- /* istanbul ignore else */
94
- if (template.item.thumbnail) {
95
- newItemTemplate.item.thumbnail = template.item.thumbnail;
96
- }
97
- // Create the item, then update its URL with its new id
98
- common
99
- .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
100
- .then(createResponse => {
101
- // Interrupt process if progress callback returns `false`
102
- if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
103
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
104
- common
105
- .removeItem(createResponse.id, destinationAuthentication)
106
- .then(() => resolve(common.generateEmptyCreationResponse(template.type)), () => resolve(common.generateEmptyCreationResponse(template.type)));
107
- }
108
- else {
109
- // Add the new item to the settings
110
- newItemTemplate.itemId = createResponse.id;
111
- templateDictionary[template.itemId] = {
112
- itemId: createResponse.id
113
- };
114
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
115
- resolve({
116
- item: newItemTemplate,
117
- id: createResponse.id,
118
- type: newItemTemplate.type,
119
- postProcess: false
120
- });
121
- }
122
- }, () => {
123
- itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
124
- resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
125
- });
126
- });
127
- }
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ import * as common from "@esri/solution-common";
22
+ // ------------------------------------------------------------------------------------------------------------------ //
23
+ /**
24
+ * Converts a file item into a template.
25
+ *
26
+ * @param solutionItemId The solution to contain the template
27
+ * @param itemInfo Info about the item
28
+ * @param destAuthentication Credentials for requests to the destination organization
29
+ * @param srcAuthentication Credentials for requests to source items
30
+ * @returns A promise that will resolve when the template has been created
31
+ */
32
+ export function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
33
+ return new Promise(resolve => {
34
+ // Init template
35
+ const itemTemplate = common.createInitializedItemTemplate(itemInfo);
36
+ // Templatize item info property values
37
+ itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
38
+ // Request file
39
+ const dataPromise = new Promise(dataResolve => {
40
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
41
+ common
42
+ .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
43
+ .then(response => {
44
+ if (!response || response.size === 0) {
45
+ dataResolve(null);
46
+ }
47
+ else {
48
+ dataResolve(response);
49
+ }
50
+ });
51
+ });
52
+ // Request related items
53
+ const relatedPromise = Promise.resolve({});
54
+ // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
55
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
56
+ Promise.all([dataPromise, relatedPromise]).then(responses => {
57
+ const [itemDataResponse] = responses;
58
+ if (itemDataResponse) {
59
+ const resource = common.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
60
+ itemTemplate.properties[resource.filename] = resource.mimeType;
61
+ const storageName = common.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
62
+ ? common.SolutionResourceType.data
63
+ : common.SolutionResourceType.fakezip));
64
+ // Add the data file to the template so that it can be uploaded with the other resources in the solution
65
+ const dataFile = {
66
+ itemId: itemTemplate.itemId,
67
+ file: resource.blob,
68
+ folder: storageName.folder,
69
+ filename: storageName.filename
70
+ };
71
+ itemTemplate.dataFile = dataFile;
72
+ // Update the template's resources
73
+ itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
74
+ resolve(itemTemplate);
75
+ }
76
+ else {
77
+ resolve(itemTemplate);
78
+ }
79
+ });
80
+ });
81
+ }
82
+ export function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
83
+ return new Promise(resolve => {
84
+ // Interrupt process if progress callback returns `false`
85
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
86
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
87
+ resolve(common.generateEmptyCreationResponse(template.type));
88
+ return;
89
+ }
90
+ // Replace the templatized symbols in a copy of the template
91
+ let newItemTemplate = common.cloneObject(template);
92
+ newItemTemplate = common.replaceInTemplate(newItemTemplate, templateDictionary);
93
+ /* istanbul ignore else */
94
+ if (template.item.thumbnail) {
95
+ newItemTemplate.item.thumbnail = template.item.thumbnail;
96
+ }
97
+ // Create the item, then update its URL with its new id
98
+ common
99
+ .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
100
+ .then(createResponse => {
101
+ // Interrupt process if progress callback returns `false`
102
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
103
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
104
+ common
105
+ .removeItem(createResponse.id, destinationAuthentication)
106
+ .then(() => resolve(common.generateEmptyCreationResponse(template.type)), () => resolve(common.generateEmptyCreationResponse(template.type)));
107
+ }
108
+ else {
109
+ // Add the new item to the settings
110
+ newItemTemplate.itemId = createResponse.id;
111
+ templateDictionary[template.itemId] = {
112
+ itemId: createResponse.id
113
+ };
114
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
115
+ resolve({
116
+ item: newItemTemplate,
117
+ id: createResponse.id,
118
+ type: newItemTemplate.type,
119
+ postProcess: false
120
+ });
121
+ }
122
+ }, () => {
123
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
124
+ resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
125
+ });
126
+ });
127
+ }
128
128
  //# sourceMappingURL=file.js.map
@@ -1,21 +1,21 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- export * from "./file";
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ export * from "./file";
package/dist/esm/index.js CHANGED
@@ -1,22 +1,22 @@
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
- /**
17
- * Manages the creation and deployment of item types that contain files.
18
- *
19
- * @module file
20
- */
21
- export * from "./file";
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
+ /**
17
+ * Manages the creation and deployment of item types that contain files.
18
+ *
19
+ * @module file
20
+ */
21
+ export * from "./file";
22
22
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/solution-file",
3
- "version": "4.1.2",
3
+ "version": "5.0.1",
4
4
  "description": "Manages the creation and deployment of item types that contain files for @esri/solution.js.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,11 +23,11 @@
23
23
  "@esri/arcgis-rest-portal": "^3.6.0",
24
24
  "@esri/arcgis-rest-request": "^3.6.0",
25
25
  "@esri/arcgis-rest-service-admin": "^3.6.0",
26
- "@esri/hub-common": "^13.4.1",
26
+ "@esri/hub-common": "^13.46.2",
27
27
  "@esri/hub-initiatives": "^13.0.0",
28
28
  "@esri/hub-sites": "^13.0.1",
29
29
  "@esri/hub-teams": "^13.0.0",
30
- "@esri/solution-common": "^4.1.2",
30
+ "@esri/solution-common": "^5.0.1",
31
31
  "rollup": "2.79.1"
32
32
  },
33
33
  "dependencies": {
@@ -85,5 +85,5 @@
85
85
  "esri",
86
86
  "ES6"
87
87
  ],
88
- "gitHead": "13ea49fdd2fc75cabe55a19c3620580c4c47643d"
88
+ "gitHead": "8c6c036b8e0c40a4b909ba69fa57869b0701e87c"
89
89
  }