@esri/solution-file 5.2.3 → 5.2.5

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.
@@ -0,0 +1,31 @@
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 itemInfo Info about the item
26
+ * @param destAuthentication Credentials for requests to the destination organization
27
+ * @param srcAuthentication Credentials for requests to source items
28
+ * @returns A promise that will resolve when the template has been created
29
+ */
30
+ export declare function convertItemToTemplate(itemInfo: any, destAuthentication: common.UserSession, srcAuthentication: common.UserSession): Promise<common.IItemTemplate>;
31
+ export declare function createItemFromTemplate(template: common.IItemTemplate, templateDictionary: any, destinationAuthentication: common.UserSession, itemProgressCallback: common.IItemProgressCallback): Promise<common.ICreateItemFromTemplateResponse>;
@@ -0,0 +1,133 @@
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 itemInfo Info about the item
31
+ * @param destAuthentication Credentials for requests to the destination organization
32
+ * @param srcAuthentication Credentials for requests to source items
33
+ * @returns A promise that will resolve when the template has been created
34
+ */
35
+ function convertItemToTemplate(itemInfo, destAuthentication, srcAuthentication) {
36
+ return new Promise(resolve => {
37
+ // Init template
38
+ const itemTemplate = common.createInitializedItemTemplate(itemInfo);
39
+ // Templatize item info property values
40
+ itemTemplate.item.id = common.templatizeTerm(itemTemplate.item.id, itemTemplate.item.id, ".itemId");
41
+ // Request file
42
+ const dataPromise = new Promise(dataResolve => {
43
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
44
+ common
45
+ .getItemDataAsFile(itemTemplate.itemId, itemTemplate.item.name, srcAuthentication)
46
+ .then(response => {
47
+ if (!response || response.size === 0) {
48
+ dataResolve(null);
49
+ }
50
+ else {
51
+ dataResolve(response);
52
+ }
53
+ });
54
+ });
55
+ // Request related items
56
+ const relatedPromise = Promise.resolve({});
57
+ // Errors are handled as resolved empty values; this means that there's no `reject` clause to handle, hence:
58
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
59
+ Promise.all([dataPromise, relatedPromise]).then(responses => {
60
+ const [itemDataResponse] = responses;
61
+ if (itemDataResponse) {
62
+ const resource = common.convertBlobToSupportableResource(itemDataResponse, itemTemplate.item.name);
63
+ itemTemplate.properties[resource.filename] = resource.mimeType;
64
+ const storageName = common.convertItemResourceToStorageResource(itemTemplate.itemId, resource.blob.name, common.SolutionTemplateFormatVersion, (resource.blob.name === resource.filename
65
+ ? common.SolutionResourceType.data
66
+ : common.SolutionResourceType.fakezip));
67
+ // Add the data file to the template so that it can be uploaded with the other resources in the solution
68
+ const dataFile = {
69
+ itemId: itemTemplate.itemId,
70
+ file: resource.blob,
71
+ folder: storageName.folder,
72
+ filename: storageName.filename
73
+ };
74
+ itemTemplate.dataFile = dataFile;
75
+ // Update the template's resources
76
+ itemTemplate.resources.push(storageName.folder + "/" + storageName.filename);
77
+ resolve(itemTemplate);
78
+ }
79
+ else {
80
+ resolve(itemTemplate);
81
+ }
82
+ });
83
+ });
84
+ }
85
+ exports.convertItemToTemplate = convertItemToTemplate;
86
+ function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
87
+ return new Promise(resolve => {
88
+ // Interrupt process if progress callback returns `false`
89
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Started, 0)) {
90
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Ignored, 0);
91
+ resolve(common.generateEmptyCreationResponse(template.type));
92
+ return;
93
+ }
94
+ // Replace the templatized symbols in a copy of the template
95
+ let newItemTemplate = common.cloneObject(template);
96
+ newItemTemplate = common.replaceInTemplate(newItemTemplate, templateDictionary);
97
+ /* istanbul ignore else */
98
+ if (template.item.thumbnail) {
99
+ newItemTemplate.item.thumbnail = template.item.thumbnail;
100
+ }
101
+ // Create the item, then update its URL with its new id
102
+ common
103
+ .createItemWithData(newItemTemplate.item, newItemTemplate.data, destinationAuthentication, templateDictionary.folderId)
104
+ .then(createResponse => {
105
+ // Interrupt process if progress callback returns `false`
106
+ if (!itemProgressCallback(template.itemId, common.EItemProgressStatus.Created, template.estimatedDeploymentCostFactor / 2, createResponse.id)) {
107
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Cancelled, 0);
108
+ common
109
+ .removeItem(createResponse.id, destinationAuthentication)
110
+ .then(() => resolve(common.generateEmptyCreationResponse(template.type)), () => resolve(common.generateEmptyCreationResponse(template.type)));
111
+ }
112
+ else {
113
+ // Add the new item to the settings
114
+ newItemTemplate.itemId = createResponse.id;
115
+ templateDictionary[template.itemId] = {
116
+ itemId: createResponse.id
117
+ };
118
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor / 2, createResponse.id);
119
+ resolve({
120
+ item: newItemTemplate,
121
+ id: createResponse.id,
122
+ type: newItemTemplate.type,
123
+ postProcess: false
124
+ });
125
+ }
126
+ }, () => {
127
+ itemProgressCallback(template.itemId, common.EItemProgressStatus.Failed, 0);
128
+ resolve(common.generateEmptyCreationResponse(template.type)); // fails to create item
129
+ });
130
+ });
131
+ }
132
+ exports.createItemFromTemplate = createItemFromTemplate;
133
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;AAEH;;;;GAIG;AAEH,sEAAgD;AAEhD,wHAAwH;AAExH;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,QAAa,EACb,kBAAsC,EACtC,iBAAqC;IAErC,OAAO,IAAI,OAAO,CAAuB,OAAO,CAAC,EAAE;QACjD,gBAAgB;QAChB,MAAM,YAAY,GAAyB,MAAM,CAAC,6BAA6B,CAC7E,QAAQ,CACT,CAAC;QAEF,uCAAuC;QACvC,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,cAAc,CAC1C,YAAY,CAAC,IAAI,CAAC,EAAE,EACpB,YAAY,CAAC,IAAI,CAAC,EAAE,EACpB,SAAS,CACV,CAAC;QAEF,eAAe;QACf,MAAM,WAAW,GAAG,IAAI,OAAO,CAAO,WAAW,CAAC,EAAE;YAClD,mEAAmE;YACnE,MAAM;iBACH,iBAAiB,CAChB,YAAY,CAAC,MAAM,EACnB,YAAY,CAAC,IAAI,CAAC,IAAI,EACtB,iBAAiB,CAClB;iBACA,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACf,IAA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,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"}
@@ -0,0 +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";
@@ -0,0 +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);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH,iDAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/solution-file",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
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",
@@ -27,7 +27,7 @@
27
27
  "@esri/hub-initiatives": "^14.0.0",
28
28
  "@esri/hub-sites": "^14.2.2",
29
29
  "@esri/hub-teams": "^14.1.0",
30
- "@esri/solution-common": "^5.2.3",
30
+ "@esri/solution-common": "^5.2.5",
31
31
  "@types/jasmine": "^5.1.4",
32
32
  "fetch-mock": "^7.7.3",
33
33
  "jasmine": "^5.1.0",
@@ -88,5 +88,5 @@
88
88
  "esri",
89
89
  "ES6"
90
90
  ],
91
- "gitHead": "bcf0907f47cf8a2970f8da38f8e1e2a4ac7beccb"
91
+ "gitHead": "1a9ab55a2b6fbfb307b4afbb09c2502f5578de73"
92
92
  }