@esri/solution-file 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/solution-file",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Manages the creation and deployment of item types that contain files for @esri/solution.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "unpkg": "dist/umd/file.umd.min.js",
@@ -18,7 +18,7 @@
18
18
  "@esri/arcgis-rest-portal": "~3.5.0",
19
19
  "@esri/arcgis-rest-request": "~3.5.0",
20
20
  "@esri/arcgis-rest-service-admin": "~3.5.0",
21
- "@esri/solution-common": "^3.0.0",
21
+ "@esri/solution-common": "^3.1.0",
22
22
  "rollup": "2.79.1"
23
23
  },
24
24
  "peerDependencies": {
@@ -29,7 +29,7 @@
29
29
  "@esri/arcgis-rest-service-admin": "~3.5.0"
30
30
  },
31
31
  "dependencies": {
32
- "@esri/hub-common": "^12.31.1",
32
+ "@esri/hub-common": "^12.37.1",
33
33
  "@esri/hub-initiatives": "^12.4.1",
34
34
  "@esri/hub-sites": "^12.6.0",
35
35
  "@esri/hub-teams": "^12.4.1",
@@ -81,5 +81,5 @@
81
81
  "esri",
82
82
  "ES6"
83
83
  ],
84
- "gitHead": "566b1c0fa884f94279a70d932dda3cd8a55ba050"
84
+ "gitHead": "d7bddb4b7c7b98ef00eac060c639a22d0654a03f"
85
85
  }
@@ -1,32 +0,0 @@
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/node/file.js DELETED
@@ -1,134 +0,0 @@
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
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file.ts"],"names":[],"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,CACH,OAAO,CAAC,MAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAC/D,CAAC;aACL;iBAAM;gBACL,mCAAmC;gBACnC,eAAe,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,CAAC;gBAC3C,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG;oBACpC,MAAM,EAAE,cAAc,CAAC,EAAE;iBAC1B,CAAC;gBAEF,oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACf,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EACnC,QAAQ,CAAC,6BAA6B,GAAG,CAAC,EAC1C,cAAc,CAAC,EAAE,CAClB,CAAC;gBAEF,OAAO,CAAC;oBACN,IAAI,EAAE,eAAe;oBACrB,EAAE,EAAE,cAAc,CAAC,EAAE;oBACrB,IAAI,EAAE,eAAe,CAAC,IAAI;oBAC1B,WAAW,EAAE,KAAK;iBACnB,CAAC,CAAC;aACJ;QACH,CAAC,EACD,GAAG,EAAE;YACH,oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACf,MAAM,CAAC,mBAAmB,CAAC,MAAM,EACjC,CAAC,CACF,CAAC;YACF,OAAO,CAAC,MAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,uBAAuB;QACvF,CAAC,CACF,CAAC;IACN,CAAC,CAAC,CAAC;AACL,CAAC;AAnGD,wDAmGC"}
@@ -1,21 +0,0 @@
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,25 +0,0 @@
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
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH,iDAAuB"}
@@ -1,32 +0,0 @@
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,21 +0,0 @@
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,172 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-file - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:21:14 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common'], factory) :
21
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution));
22
- })(this, (function (exports, common) { 'use strict';
23
-
24
- function _interopNamespace(e) {
25
- if (e && e.__esModule) return e;
26
- var n = Object.create(null);
27
- if (e) {
28
- Object.keys(e).forEach(function (k) {
29
- if (k !== 'default') {
30
- var d = Object.getOwnPropertyDescriptor(e, k);
31
- Object.defineProperty(n, k, d.get ? d : {
32
- enumerable: true,
33
- get: function () { return e[k]; }
34
- });
35
- }
36
- });
37
- }
38
- n["default"] = e;
39
- return Object.freeze(n);
40
- }
41
-
42
- var common__namespace = /*#__PURE__*/_interopNamespace(common);
43
-
44
- /** @license
45
- * Copyright 2018 Esri
46
- *
47
- * Licensed under the Apache License, Version 2.0 (the "License");
48
- * you may not use this file except in compliance with the License.
49
- * You may obtain a copy of the License at
50
- *
51
- * http://www.apache.org/licenses/LICENSE-2.0
52
- *
53
- * Unless required by applicable law or agreed to in writing, software
54
- * distributed under the License is distributed on an "AS IS" BASIS,
55
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
- * See the License for the specific language governing permissions and
57
- * limitations under the License.
58
- */
59
- // ------------------------------------------------------------------------------------------------------------------ //
60
- /**
61
- * Converts a file item into a template.
62
- *
63
- * @param solutionItemId The solution to contain the template
64
- * @param itemInfo Info about the item
65
- * @param destAuthentication Credentials for requests to the destination organization
66
- * @param srcAuthentication Credentials for requests to source items
67
- * @returns A promise that will resolve when the template has been created
68
- */
69
- function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication) {
70
- return new Promise(resolve => {
71
- // Init template
72
- const itemTemplate = common__namespace.createInitializedItemTemplate(itemInfo);
73
- // Templatize item info property values
74
- itemTemplate.item.id = common__namespace.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
75
- // Request file
76
- const dataPromise = new Promise(dataResolve => {
77
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
78
- common__namespace
79
- .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
80
- .then(response => {
81
- if (!response || response.size === 0) {
82
- dataResolve(null);
83
- }
84
- else {
85
- dataResolve(response);
86
- }
87
- });
88
- });
89
- // Request related items
90
- const relatedPromise = Promise.resolve({});
91
- // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
92
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
93
- Promise.all([dataPromise, relatedPromise]).then(responses => {
94
- const [itemDataResponse] = responses;
95
- if (itemDataResponse) {
96
- const resource = common__namespace.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
97
- itemTemplate.properties[resource.filename] = resource.mimeType;
98
- const storageName = common__namespace.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common__namespace.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
99
- ? common__namespace.SolutionResourceType.data
100
- : common__namespace.SolutionResourceType.fakezip));
101
- // Add the data file to the template so that it can be uploaded with the other resources in the solution
102
- const dataFile = {
103
- itemId: itemTemplate.itemId,
104
- file: resource.blob,
105
- folder: storageName.folder,
106
- filename: storageName.filename
107
- };
108
- itemTemplate.dataFile = dataFile;
109
- // Update the template's resources
110
- itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
111
- resolve(itemTemplate);
112
- }
113
- else {
114
- resolve(itemTemplate);
115
- }
116
- });
117
- });
118
- }
119
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
120
- return new Promise(resolve => {
121
- // Interrupt process if progress callback returns `false`
122
- if (!itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Started, 0)) {
123
- itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Ignored, 0);
124
- resolve(common__namespace.generateEmptyCreationResponse(template.type));
125
- return;
126
- }
127
- // Replace the templatized symbols in a copy of the template
128
- let newItemTemplate = common__namespace.cloneObject(template);
129
- newItemTemplate = common__namespace.replaceInTemplate(newItemTemplate, templateDictionary);
130
- /* istanbul ignore else */
131
- if (template.item.thumbnail) {
132
- newItemTemplate.item.thumbnail = template.item.thumbnail;
133
- }
134
- // Create the item, then update its URL with its new id
135
- common__namespace
136
- .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
137
- .then(createResponse => {
138
- // Interrupt process if progress callback returns `false`
139
- if (!itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
140
- itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Cancelled, 0);
141
- common__namespace
142
- .removeItem(createResponse.id, destinationAuthentication)
143
- .then(() => resolve(common__namespace.generateEmptyCreationResponse(template.type)), () => resolve(common__namespace.generateEmptyCreationResponse(template.type)));
144
- }
145
- else {
146
- // Add the new item to the settings
147
- newItemTemplate.itemId = createResponse.id;
148
- templateDictionary[template.itemId] = {
149
- itemId: createResponse.id
150
- };
151
- itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
152
- resolve({
153
- item: newItemTemplate,
154
- id: createResponse.id,
155
- type: newItemTemplate.type,
156
- postProcess: false
157
- });
158
- }
159
- }, () => {
160
- itemProgressCallback(template.itemId, common__namespace.EItemProgressStatus.Failed, 0);
161
- resolve(common__namespace.generateEmptyCreationResponse(template.type)); // fails to create item
162
- });
163
- });
164
- }
165
-
166
- exports.convertItemToTemplate = convertItemToTemplate;
167
- exports.createItemFromTemplate = createItemFromTemplate;
168
-
169
- Object.defineProperty(exports, '__esModule', { value: true });
170
-
171
- }));
172
- //# sourceMappingURL=file.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.umd.js","sources":["../../src/file.ts"],"sourcesContent":["/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Manages the creation and deployment of item types that contain files.\r\n *\r\n * @module file\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts a file item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>(resolve => {\r\n // Init template\r\n const itemTemplate: common.IItemTemplate = common.createInitializedItemTemplate(\r\n itemInfo\r\n );\r\n\r\n // Templatize item info property values\r\n itemTemplate.item.id = common.templatizeTerm(\r\n itemTemplate.item.id,\r\n itemTemplate.item.id,\r\n \".itemId\"\r\n );\r\n\r\n // Request file\r\n const dataPromise = new Promise<File>(dataResolve => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n common\r\n .getItemDataAsFile(\r\n itemTemplate.itemId,\r\n itemTemplate.item.name,\r\n srcAuthentication\r\n )\r\n .then(response => {\r\n if (!response || response.size === 0) {\r\n dataResolve(null);\r\n } else {\r\n dataResolve(response);\r\n }\r\n });\r\n });\r\n\r\n // Request related items\r\n const relatedPromise = Promise.resolve(\r\n {} as common.IGetRelatedItemsResponse\r\n );\r\n\r\n // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n Promise.all([dataPromise, relatedPromise]).then(responses => {\r\n const [itemDataResponse] = responses;\r\n\r\n if (itemDataResponse) {\r\n const resource: common.IFileMimeTyped = common.convertBlobToSupportableResource(\r\n itemDataResponse,\r\n itemTemplate.item.name\r\n );\r\n itemTemplate.properties[resource.filename] = resource.mimeType;\r\n\r\n const storageName = common.convertItemResourceToStorageResource(\r\n itemTemplate.itemId,\r\n (resource.blob as File).name,\r\n common.SolutionTemplateFormatVersion,\r\n ((resource.blob as File).name === resource.filename\r\n ? common.SolutionResourceType.data\r\n : common.SolutionResourceType.fakezip)\r\n );\r\n\r\n // Add the data file to the template so that it can be uploaded with the other resources in the solution\r\n const dataFile: common.ISourceFile = {\r\n itemId: itemTemplate.itemId,\r\n file: resource.blob as File,\r\n folder: storageName.folder,\r\n filename: storageName.filename\r\n }\r\n itemTemplate.dataFile = dataFile;\r\n\r\n // Update the template's resources\r\n itemTemplate.resources.push(\r\n storageName.folder + \"/\" + storageName.filename\r\n );\r\n\r\n resolve(itemTemplate);\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Started,\r\n 0\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Ignored,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n return;\r\n }\r\n\r\n // Replace the templatized symbols in a copy of the template\r\n let newItemTemplate: common.IItemTemplate = common.cloneObject(template);\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n /* istanbul ignore else */\r\n if (template.item.thumbnail) {\r\n newItemTemplate.item.thumbnail = template.item.thumbnail;\r\n }\r\n\r\n // Create the item, then update its URL with its new id\r\n common\r\n .createItemWithData(\r\n newItemTemplate.item,\r\n newItemTemplate.data,\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n )\r\n .then(\r\n createResponse => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Created,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type)),\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type))\r\n );\r\n } else {\r\n // Add the new item to the settings\r\n newItemTemplate.itemId = createResponse.id;\r\n templateDictionary[template.itemId] = {\r\n itemId: createResponse.id\r\n };\r\n\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n );\r\n\r\n resolve({\r\n item: newItemTemplate,\r\n id: createResponse.id,\r\n type: newItemTemplate.type,\r\n postProcess: false\r\n });\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item\r\n }\r\n );\r\n });\r\n}\r\n"],"names":["common"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcG;EAUH;EAEA;;;;;;;;EAQG;EACG,SAAU,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,kBAAsC,EACtC,iBAAqC,EAAA;EAErC,IAAA,OAAO,IAAI,OAAO,CAAuB,OAAO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oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACfA,iBAAM,CAAC,mBAAmB,CAAC,QAAQ,EACnC,QAAQ,CAAC,6BAA6B,GAAG,CAAC,EAC1C,cAAc,CAAC,EAAE,CAClB,CAAC;EAEF,gBAAA,OAAO,CAAC;EACN,oBAAA,IAAI,EAAE,eAAe;sBACrB,EAAE,EAAE,cAAc,CAAC,EAAE;sBACrB,IAAI,EAAE,eAAe,CAAC,IAAI;EAC1B,oBAAA,WAAW,EAAE,KAAK;EACnB,iBAAA,CAAC,CAAC;EACJ,aAAA;WACF,EACD,MAAK;EACH,YAAA,oBAAoB,CAClB,QAAQ,CAAC,MAAM,EACfA,iBAAM,CAAC,mBAAmB,CAAC,MAAM,EACjC,CAAC,CACF,CAAC;EACF,YAAA,OAAO,CAACA,iBAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;EAC/D,SAAC,CACF,CAAC;EACN,KAAC,CAAC,CAAC;EACL;;;;;;;;;;;"}
@@ -1,19 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-file - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:21:17 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/solution-common")):"function"==typeof define&&define.amd?define(["exports","@esri/solution-common"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisSolution=e.arcgisSolution||{},e.arcgisSolution)}(this,(function(e,t){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var i=o(t);e.convertItemToTemplate=function(e,t,o,r){return new Promise((e=>{const o=i.createInitializedItemTemplate(t);o.item.id=i.templatizeTerm(o.item.id,o.item.id,".itemId");const n=new Promise((e=>{i.getItemDataAsFile(o.itemId,o.item.name,r).then((t=>{t&&0!==t.size?e(t):e(null)}))})),m=Promise.resolve({});Promise.all([n,m]).then((t=>{const[r]=t;if(r){const t=i.convertBlobToSupportableResource(r,o.item.name);o.properties[t.filename]=t.mimeType;const n=i.convertItemResourceToStorageResource(o.itemId,t.blob.name,i.SolutionTemplateFormatVersion,t.blob.name===t.filename?i.SolutionResourceType.data:i.SolutionResourceType.fakezip),m={itemId:o.itemId,file:t.blob,folder:n.folder,filename:n.filename};o.dataFile=m,o.resources.push(n.folder+"/"+n.filename),e(o)}else e(o)}))}))},e.createItemFromTemplate=function(e,t,o,r){return new Promise((n=>{if(!r(e.itemId,i.EItemProgressStatus.Started,0))return r(e.itemId,i.EItemProgressStatus.Ignored,0),void n(i.generateEmptyCreationResponse(e.type));let m=i.cloneObject(e);m=i.replaceInTemplate(m,t),e.item.thumbnail&&(m.item.thumbnail=e.item.thumbnail),i.createItemWithData(m.item,m.data,o,t.folderId).then((s=>{r(e.itemId,i.EItemProgressStatus.Created,e.estimatedDeploymentCostFactor/2,s.id)?(m.itemId=s.id,t[e.itemId]={itemId:s.id},r(e.itemId,i.EItemProgressStatus.Finished,e.estimatedDeploymentCostFactor/2,s.id),n({item:m,id:s.id,type:m.type,postProcess:!1})):(r(e.itemId,i.EItemProgressStatus.Cancelled,0),i.removeItem(s.id,o).then((()=>n(i.generateEmptyCreationResponse(e.type))),(()=>n(i.generateEmptyCreationResponse(e.type)))))}),(()=>{r(e.itemId,i.EItemProgressStatus.Failed,0),n(i.generateEmptyCreationResponse(e.type))}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
19
- //# sourceMappingURL=file.umd.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.umd.min.js","sources":["../../src/file.ts"],"sourcesContent":["/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Manages the creation and deployment of item types that contain files.\r\n *\r\n * @module file\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Converts a file item into a template.\r\n *\r\n * @param solutionItemId The solution to contain the template\r\n * @param itemInfo Info about the item\r\n * @param destAuthentication Credentials for requests to the destination organization\r\n * @param srcAuthentication Credentials for requests to source items\r\n * @returns A promise that will resolve when the template has been created\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: common.UserSession,\r\n srcAuthentication: common.UserSession\r\n): Promise<common.IItemTemplate> {\r\n return new Promise<common.IItemTemplate>(resolve => {\r\n // Init template\r\n const itemTemplate: common.IItemTemplate = common.createInitializedItemTemplate(\r\n itemInfo\r\n );\r\n\r\n // Templatize item info property values\r\n itemTemplate.item.id = common.templatizeTerm(\r\n itemTemplate.item.id,\r\n itemTemplate.item.id,\r\n \".itemId\"\r\n );\r\n\r\n // Request file\r\n const dataPromise = new Promise<File>(dataResolve => {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n common\r\n .getItemDataAsFile(\r\n itemTemplate.itemId,\r\n itemTemplate.item.name,\r\n srcAuthentication\r\n )\r\n .then(response => {\r\n if (!response || response.size === 0) {\r\n dataResolve(null);\r\n } else {\r\n dataResolve(response);\r\n }\r\n });\r\n });\r\n\r\n // Request related items\r\n const relatedPromise = Promise.resolve(\r\n {} as common.IGetRelatedItemsResponse\r\n );\r\n\r\n // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n Promise.all([dataPromise, relatedPromise]).then(responses => {\r\n const [itemDataResponse] = responses;\r\n\r\n if (itemDataResponse) {\r\n const resource: common.IFileMimeTyped = common.convertBlobToSupportableResource(\r\n itemDataResponse,\r\n itemTemplate.item.name\r\n );\r\n itemTemplate.properties[resource.filename] = resource.mimeType;\r\n\r\n const storageName = common.convertItemResourceToStorageResource(\r\n itemTemplate.itemId,\r\n (resource.blob as File).name,\r\n common.SolutionTemplateFormatVersion,\r\n ((resource.blob as File).name === resource.filename\r\n ? common.SolutionResourceType.data\r\n : common.SolutionResourceType.fakezip)\r\n );\r\n\r\n // Add the data file to the template so that it can be uploaded with the other resources in the solution\r\n const dataFile: common.ISourceFile = {\r\n itemId: itemTemplate.itemId,\r\n file: resource.blob as File,\r\n folder: storageName.folder,\r\n filename: storageName.filename\r\n }\r\n itemTemplate.dataFile = dataFile;\r\n\r\n // Update the template's resources\r\n itemTemplate.resources.push(\r\n storageName.folder + \"/\" + storageName.filename\r\n );\r\n\r\n resolve(itemTemplate);\r\n } else {\r\n resolve(itemTemplate);\r\n }\r\n });\r\n });\r\n}\r\n\r\nexport function createItemFromTemplate(\r\n template: common.IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: common.UserSession,\r\n itemProgressCallback: common.IItemProgressCallback\r\n): Promise<common.ICreateItemFromTemplateResponse> {\r\n return new Promise<common.ICreateItemFromTemplateResponse>(resolve => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Started,\r\n 0\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Ignored,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type));\r\n return;\r\n }\r\n\r\n // Replace the templatized symbols in a copy of the template\r\n let newItemTemplate: common.IItemTemplate = common.cloneObject(template);\r\n newItemTemplate = common.replaceInTemplate(\r\n newItemTemplate,\r\n templateDictionary\r\n );\r\n /* istanbul ignore else */\r\n if (template.item.thumbnail) {\r\n newItemTemplate.item.thumbnail = template.item.thumbnail;\r\n }\r\n\r\n // Create the item, then update its URL with its new id\r\n common\r\n .createItemWithData(\r\n newItemTemplate.item,\r\n newItemTemplate.data,\r\n destinationAuthentication,\r\n templateDictionary.folderId\r\n )\r\n .then(\r\n createResponse => {\r\n // Interrupt process if progress callback returns `false`\r\n if (\r\n !itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Created,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n )\r\n ) {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Cancelled,\r\n 0\r\n );\r\n common\r\n .removeItem(createResponse.id, destinationAuthentication)\r\n .then(\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type)),\r\n () =>\r\n resolve(common.generateEmptyCreationResponse(template.type))\r\n );\r\n } else {\r\n // Add the new item to the settings\r\n newItemTemplate.itemId = createResponse.id;\r\n templateDictionary[template.itemId] = {\r\n itemId: createResponse.id\r\n };\r\n\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Finished,\r\n template.estimatedDeploymentCostFactor / 2,\r\n createResponse.id\r\n );\r\n\r\n resolve({\r\n item: newItemTemplate,\r\n id: createResponse.id,\r\n type: newItemTemplate.type,\r\n postProcess: false\r\n });\r\n }\r\n },\r\n () => {\r\n itemProgressCallback(\r\n template.itemId,\r\n common.EItemProgressStatus.Failed,\r\n 0\r\n );\r\n resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item\r\n }\r\n );\r\n });\r\n}\r\n"],"names":["solutionItemId","itemInfo","destAuthentication","srcAuthentication","Promise","resolve","itemTemplate","common","createInitializedItemTemplate","item","id","templatizeTerm","dataPromise","dataResolve","getItemDataAsFile","itemId","name","then","response","size","relatedPromise","all","responses","itemDataResponse","resource","convertBlobToSupportableResource","properties","filename","mimeType","storageName","convertItemResourceToStorageResource","blob","SolutionTemplateFormatVersion","SolutionResourceType","data","fakezip","dataFile","file","folder","resources","push","template","templateDictionary","destinationAuthentication","itemProgressCallback","EItemProgressStatus","Started","Ignored","generateEmptyCreationResponse","type","newItemTemplate","cloneObject","replaceInTemplate","thumbnail","createItemWithData","folderId","createResponse","Created","estimatedDeploymentCostFactor","Finished","postProcess","Cancelled","removeItem","Failed"],"mappings":";;;;;;;;;;;;;;;;;spBAmCM,SACJA,EACAC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAA8BC,IAEvC,MAAMC,EAAqCC,EAAOC,8BAChDP,GAIFK,EAAaG,KAAKC,GAAKH,EAAOI,eAC5BL,EAAaG,KAAKC,GAClBJ,EAAaG,KAAKC,GAClB,WAIF,MAAME,EAAc,IAAIR,SAAcS,IAEpCN,EACGO,kBACCR,EAAaS,OACbT,EAAaG,KAAKO,KAClBb,GAEDc,MAAKC,IACCA,GAA8B,IAAlBA,EAASC,KAGxBN,EAAYK,GAFZL,EAAY,KAGb,GACD,IAIAO,EAAiBhB,QAAQC,QAC7B,CAAqC,GAKvCD,QAAQiB,IAAI,CAACT,EAAaQ,IAAiBH,MAAKK,IAC9C,MAAOC,GAAoBD,EAE3B,GAAIC,EAAkB,CACpB,MAAMC,EAAkCjB,EAAOkB,iCAC7CF,EACAjB,EAAaG,KAAKO,MAEpBV,EAAaoB,WAAWF,EAASG,UAAYH,EAASI,SAEtD,MAAMC,EAActB,EAAOuB,qCACzBxB,EAAaS,OACZS,EAASO,KAAcf,KACxBT,EAAOyB,8BAC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