@esri/solution-form 1.1.2 → 1.2.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/dist/esm/convert-item-to-template.d.ts +3 -2
- package/dist/esm/convert-item-to-template.js +4 -3
- package/dist/esm/convert-item-to-template.js.map +1 -1
- package/dist/esm/helpers/build-create-params.js +27 -19
- package/dist/esm/helpers/build-create-params.js.map +1 -1
- package/dist/esm/helpers/create-item-from-hub-template.js +14 -11
- package/dist/esm/helpers/create-item-from-hub-template.js.map +1 -1
- package/dist/esm/helpers/create-survey.js +10 -9
- package/dist/esm/helpers/create-survey.js.map +1 -1
- package/dist/esm/helpers/encode-survey-form.js +12 -12
- package/dist/esm/helpers/encode-survey-form.js.map +1 -1
- package/dist/esm/helpers/post-process-survey.js +19 -25
- package/dist/esm/helpers/post-process-survey.js.map +1 -1
- package/dist/node/convert-item-to-template.d.ts +3 -2
- package/dist/node/convert-item-to-template.js +5 -4
- package/dist/node/convert-item-to-template.js.map +1 -1
- package/dist/node/create-item-from-template.js +3 -3
- package/dist/node/create-item-from-template.js.map +1 -1
- package/dist/node/helpers/build-create-params.js +29 -21
- package/dist/node/helpers/build-create-params.js.map +1 -1
- package/dist/node/helpers/create-item-from-hub-template.js +17 -14
- package/dist/node/helpers/create-item-from-hub-template.js.map +1 -1
- package/dist/node/helpers/create-survey.js +11 -10
- package/dist/node/helpers/create-survey.js.map +1 -1
- package/dist/node/helpers/encode-survey-form.js +13 -13
- package/dist/node/helpers/encode-survey-form.js.map +1 -1
- package/dist/node/helpers/is-hub-form-template.js +1 -1
- package/dist/node/helpers/is-hub-form-template.js.map +1 -1
- package/dist/node/helpers/post-process-survey.js +21 -27
- package/dist/node/helpers/post-process-survey.js.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/post-process.js +3 -3
- package/dist/node/post-process.js.map +1 -1
- package/dist/umd/convert-item-to-template.d.ts +3 -2
- package/dist/umd/form.umd.js +112 -124
- package/dist/umd/form.umd.js.map +1 -1
- package/dist/umd/form.umd.min.js +3 -3
- package/dist/umd/form.umd.min.js.map +1 -1
- package/package.json +29 -29
|
@@ -24,8 +24,9 @@ import { UserSession, IItemTemplate } from "@esri/solution-common";
|
|
|
24
24
|
*
|
|
25
25
|
* @param {string} solutionItemId The solution item ID
|
|
26
26
|
* @param {any} itemInfo: The base item info
|
|
27
|
-
* @param {UserSession}
|
|
27
|
+
* @param {UserSession} destAuthentication Credentials for requests to the destination organization
|
|
28
|
+
* @param {UserSession} srcAuthentication Credentials for requests to source items
|
|
28
29
|
* @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
|
|
29
30
|
* @returns {Promise<IItemTemplate>}
|
|
30
31
|
*/
|
|
31
|
-
export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any,
|
|
32
|
+
export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: UserSession, srcAuthentication: UserSession, templateDictionary: any): Promise<IItemTemplate>;
|
|
@@ -19,12 +19,13 @@ import { simpleTypes } from "@esri/solution-simple-types";
|
|
|
19
19
|
*
|
|
20
20
|
* @param {string} solutionItemId The solution item ID
|
|
21
21
|
* @param {any} itemInfo: The base item info
|
|
22
|
-
* @param {UserSession}
|
|
22
|
+
* @param {UserSession} destAuthentication Credentials for requests to the destination organization
|
|
23
|
+
* @param {UserSession} srcAuthentication Credentials for requests to source items
|
|
23
24
|
* @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
|
|
24
25
|
* @returns {Promise<IItemTemplate>}
|
|
25
26
|
*/
|
|
26
|
-
export function convertItemToTemplate(solutionItemId, itemInfo,
|
|
27
|
+
export function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
|
|
27
28
|
// Delegate to simple types
|
|
28
|
-
return simpleTypes.convertItemToTemplate(solutionItemId, itemInfo,
|
|
29
|
+
return simpleTypes.convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=convert-item-to-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-item-to-template.js","sourceRoot":"","sources":["../../src/convert-item-to-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"convert-item-to-template.js","sourceRoot":"","sources":["../../src/convert-item-to-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,kBAA+B,EAC/B,iBAA8B,EAC9B,kBAAuB;IAEvB,2BAA2B;IAC3B,OAAO,WAAW,CAAC,qBAAqB,CACtC,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;AACJ,CAAC"}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { __assign } from "tslib";
|
|
17
16
|
import { getUniqueTitle, getPortalDefaultBasemap } from "@esri/solution-common";
|
|
18
17
|
import { encodeSurveyForm } from "./encode-survey-form";
|
|
19
18
|
/**
|
|
@@ -30,36 +29,45 @@ import { encodeSurveyForm } from "./encode-survey-form";
|
|
|
30
29
|
* @returns {Promise<ISurvey123CreateParams>}
|
|
31
30
|
*/
|
|
32
31
|
export function buildCreateParams(template, templateDictionary, destinationAuthentication) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return getPortalDefaultBasemap(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(
|
|
32
|
+
const { item: { title: originalTitle, description, tags, typeKeywords }, properties: { form: unencodedForm } } = template;
|
|
33
|
+
const { user: { username }, portalBaseUrl: portalUrl, organization: { basemapGalleryGroupQuery, defaultBasemap: { title: basemapTitle } } } = templateDictionary;
|
|
34
|
+
const { token } = destinationAuthentication.toCredential();
|
|
35
|
+
return getPortalDefaultBasemap(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(defaultBasemap => {
|
|
37
36
|
// The S123 API appends "Survey-" to the survey title when computing
|
|
38
37
|
// the folder name. We need to use the same prefix to successfully
|
|
39
38
|
// calculate a unique folder name. Afterwards, we can safely remove the
|
|
40
39
|
// prefix from the title
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const folderPrefix = "Survey-";
|
|
41
|
+
const title = getUniqueTitle(`${folderPrefix}${originalTitle}`, templateDictionary, "user.folders").replace(folderPrefix, "");
|
|
43
42
|
// set any map question's basemaps to default org basemap
|
|
44
43
|
if (unencodedForm.questions) {
|
|
45
|
-
|
|
44
|
+
const updateBasemap = (question) => {
|
|
46
45
|
if (question.maps) {
|
|
47
|
-
question.maps = question.maps.map(
|
|
46
|
+
question.maps = question.maps.map((map) => ({
|
|
47
|
+
...map,
|
|
48
|
+
itemId: defaultBasemap.id
|
|
49
|
+
}));
|
|
48
50
|
}
|
|
49
51
|
return question;
|
|
50
|
-
}
|
|
52
|
+
};
|
|
53
|
+
unencodedForm.questions = unencodedForm.questions.map((question) => !question.questions
|
|
54
|
+
? updateBasemap(question)
|
|
55
|
+
: {
|
|
56
|
+
...question,
|
|
57
|
+
questions: question.questions.map(updateBasemap)
|
|
58
|
+
});
|
|
51
59
|
}
|
|
52
|
-
|
|
60
|
+
const form = encodeSurveyForm(unencodedForm);
|
|
53
61
|
// intentionally undefined, handled downstream by core logic now
|
|
54
62
|
return {
|
|
55
|
-
description
|
|
56
|
-
form
|
|
57
|
-
portalUrl
|
|
58
|
-
tags
|
|
59
|
-
title
|
|
60
|
-
token
|
|
61
|
-
typeKeywords
|
|
62
|
-
username
|
|
63
|
+
description,
|
|
64
|
+
form,
|
|
65
|
+
portalUrl,
|
|
66
|
+
tags,
|
|
67
|
+
title,
|
|
68
|
+
token,
|
|
69
|
+
typeKeywords,
|
|
70
|
+
username
|
|
63
71
|
};
|
|
64
72
|
});
|
|
65
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-create-params.js","sourceRoot":"","sources":["../../../src/helpers/build-create-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"build-create-params.js","sourceRoot":"","sources":["../../../src/helpers/build-create-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,cAAc,EAEd,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAuB,EACvB,kBAAuB,EACvB,yBAAsC;IAEtC,MAAM,EACJ,IAAI,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,EAC/D,UAAU,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EACpC,GAAG,QAAQ,CAAC;IACb,MAAM,EACJ,IAAI,EAAE,EAAE,QAAQ,EAAE,EAClB,aAAa,EAAE,SAAS,EACxB,YAAY,EAAE,EACZ,wBAAwB,EACxB,cAAc,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EACxC,EACF,GAAG,kBAAkB,CAAC;IACvB,MAAM,EAAE,KAAK,EAAE,GAAG,yBAAyB,CAAC,YAAY,EAAE,CAAC;IAC3D,OAAO,uBAAuB,CAC5B,wBAAwB,EACxB,YAAY,EACZ,yBAAyB,CAC1B,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACtB,oEAAoE;QACpE,kEAAkE;QAClE,uEAAuE;QACvE,wBAAwB;QACxB,MAAM,YAAY,GAAG,SAAS,CAAC;QAC/B,MAAM,KAAK,GAAG,cAAc,CAC1B,GAAG,YAAY,GAAG,aAAa,EAAE,EACjC,kBAAkB,EAClB,cAAc,CACf,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC5B,yDAAyD;QACzD,IAAI,aAAa,CAAC,SAAS,EAAE;YAC3B,MAAM,aAAa,GAAG,CAAC,QAAa,EAAE,EAAE;gBACtC,IAAI,QAAQ,CAAC,IAAI,EAAE;oBACjB,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC;wBAC/C,GAAG,GAAG;wBACN,MAAM,EAAE,cAAc,CAAC,EAAE;qBAC1B,CAAC,CAAC,CAAC;iBACL;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC,CAAC;YACF,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAa,EAAE,EAAE,CACtE,CAAC,QAAQ,CAAC,SAAS;gBACjB,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;gBACzB,CAAC,CAAC;oBACA,GAAG,QAAQ;oBACX,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC;iBACjD,CACJ,CAAC;SACH;QACD,MAAM,IAAI,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAC7C,gEAAgE;QAChE,OAAO;YACL,WAAW;YACX,IAAI;YACJ,SAAS;YACT,IAAI;YACJ,KAAK;YACL,KAAK;YACL,YAAY;YACZ,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { __assign } from "tslib";
|
|
17
16
|
import { EItemProgressStatus, replaceInTemplate, updateItemExtended, getItemBase } from "@esri/solution-common";
|
|
18
17
|
import { createSurvey } from "./create-survey";
|
|
19
18
|
import { buildCreateParams } from "./build-create-params";
|
|
@@ -33,23 +32,23 @@ import { buildCreateParams } from "./build-create-params";
|
|
|
33
32
|
* @returns {Promise<ICreateItemFromTemplateResponse>}
|
|
34
33
|
*/
|
|
35
34
|
export function createItemFromHubTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const interpolatedTemplate = replaceInTemplate(template, templateDictionary);
|
|
36
|
+
const { survey123Url } = templateDictionary;
|
|
38
37
|
return buildCreateParams(interpolatedTemplate, templateDictionary, destinationAuthentication)
|
|
39
|
-
.then(
|
|
38
|
+
.then((params) => {
|
|
40
39
|
return createSurvey(params, survey123Url);
|
|
41
40
|
})
|
|
42
|
-
.then(
|
|
43
|
-
|
|
41
|
+
.then((createSurveyResponse) => {
|
|
42
|
+
const { formId, featureServiceId } = createSurveyResponse;
|
|
44
43
|
// Update the item with its thumbnail
|
|
45
|
-
|
|
44
|
+
let thumbDef = Promise.resolve(null);
|
|
46
45
|
/* istanbul ignore else */
|
|
47
46
|
if (template.item.thumbnail) {
|
|
48
47
|
thumbDef = updateItemExtended({ id: formId }, null, destinationAuthentication, template.item.thumbnail);
|
|
49
48
|
}
|
|
50
49
|
return thumbDef
|
|
51
|
-
.then(
|
|
52
|
-
.then(
|
|
50
|
+
.then(() => getItemBase(formId, destinationAuthentication))
|
|
51
|
+
.then(item => {
|
|
53
52
|
templateDictionary[interpolatedTemplate.itemId] = {
|
|
54
53
|
itemId: formId
|
|
55
54
|
};
|
|
@@ -58,14 +57,18 @@ export function createItemFromHubTemplate(template, templateDictionary, destinat
|
|
|
58
57
|
};
|
|
59
58
|
itemProgressCallback(interpolatedTemplate.itemId, EItemProgressStatus.Finished, interpolatedTemplate.estimatedDeploymentCostFactor, formId);
|
|
60
59
|
return {
|
|
61
|
-
item:
|
|
60
|
+
item: {
|
|
61
|
+
...template,
|
|
62
|
+
item,
|
|
63
|
+
itemId: formId
|
|
64
|
+
},
|
|
62
65
|
id: formId,
|
|
63
66
|
type: "Form",
|
|
64
67
|
postProcess: true
|
|
65
68
|
};
|
|
66
69
|
});
|
|
67
70
|
})
|
|
68
|
-
.catch(
|
|
71
|
+
.catch(e => {
|
|
69
72
|
itemProgressCallback(interpolatedTemplate.itemId, EItemProgressStatus.Failed, 0);
|
|
70
73
|
throw e;
|
|
71
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-item-from-hub-template.js","sourceRoot":"","sources":["../../../src/helpers/create-item-from-hub-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"create-item-from-hub-template.js","sourceRoot":"","sources":["../../../src/helpers/create-item-from-hub-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAKL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAGlB,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;GAKG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAuB,EACvB,kBAAuB,EACvB,yBAAsC,EACtC,oBAA2C;IAE3C,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;IAC7E,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC;IAE5C,OAAO,iBAAiB,CACtB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,CAC1B;SACE,IAAI,CAAC,CAAC,MAA8B,EAAE,EAAE;QACvC,OAAO,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,oBAA4C,EAAE,EAAE;QAC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
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { __assign } from "tslib";
|
|
17
16
|
import { encodeFormData } from "@esri/arcgis-rest-request";
|
|
18
17
|
/**
|
|
19
18
|
* Provides utility method to call Survey123 create endpoint
|
|
@@ -28,22 +27,24 @@ import { encodeFormData } from "@esri/arcgis-rest-request";
|
|
|
28
27
|
* @throws Will throw if the Survey123 API returns an error response
|
|
29
28
|
* @returns {Promise<ISurvey123CreateResult>}
|
|
30
29
|
*/
|
|
31
|
-
export function createSurvey(params, survey123Url) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var ro = {
|
|
30
|
+
export function createSurvey(params, survey123Url = "https://survey123.arcgis.com") {
|
|
31
|
+
const createUrl = `${survey123Url}/api/survey/create`;
|
|
32
|
+
const ro = {
|
|
35
33
|
credentials: "same-origin",
|
|
36
34
|
method: "POST",
|
|
37
|
-
body: encodeFormData(
|
|
35
|
+
body: encodeFormData({
|
|
36
|
+
f: "json",
|
|
37
|
+
...params
|
|
38
|
+
}, true)
|
|
38
39
|
};
|
|
39
40
|
// Using @esri/arcgis-request "request" method was resulting in a 404 for
|
|
40
41
|
// a CORS preflight request related to this request, but calling fetch directly
|
|
41
42
|
// circumvents the issue.
|
|
42
43
|
return fetch(createUrl, ro)
|
|
43
|
-
.then(
|
|
44
|
-
.then(
|
|
44
|
+
.then(response => response.json())
|
|
45
|
+
.then(response => {
|
|
45
46
|
if (!response.success) {
|
|
46
|
-
throw new Error(
|
|
47
|
+
throw new Error(`Failed to create survey: ${response.error.message}`);
|
|
47
48
|
}
|
|
48
49
|
return {
|
|
49
50
|
formId: response.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-survey.js","sourceRoot":"","sources":["../../../src/helpers/create-survey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"create-survey.js","sourceRoot":"","sources":["../../../src/helpers/create-survey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA8B,EAC9B,YAAY,GAAG,8BAA8B;IAE7C,MAAM,SAAS,GAAG,GAAG,YAAY,oBAAoB,CAAC;IACtD,MAAM,EAAE,GAAG;QACT,WAAW,EAAE,aAAmC;QAChD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,cAAc,CAClB;YACE,CAAC,EAAE,MAAM;YACT,GAAG,MAAM;SACV,EACD,IAAI,CACL;KACF,CAAC;IACF,yEAAyE;IACzE,+EAA+E;IAC/E,yBAAyB;IACzB,OAAO,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;SACxB,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACf,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACvE;QACD,OAAO;YACL,MAAM,EAAE,QAAQ,CAAC,EAAE;YACnB,gBAAgB,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM;YACvD,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,WAAW;SAC5C,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { __read } from "tslib";
|
|
17
16
|
import { cloneObject } from "@esri/solution-common";
|
|
18
17
|
/**
|
|
19
18
|
* Manages Survey123 parameter encoding
|
|
@@ -27,29 +26,30 @@ import { cloneObject } from "@esri/solution-common";
|
|
|
27
26
|
* @param {any} form Unencoded form data
|
|
28
27
|
* @returns {any} Encoded form data
|
|
29
28
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
export const encodeSurveyForm = function encodeForm(form) {
|
|
30
|
+
const clone = cloneObject(form);
|
|
31
|
+
const props = [
|
|
33
32
|
["header", "content"],
|
|
34
33
|
["subHeader", "content"],
|
|
35
34
|
["footer", "content"],
|
|
36
35
|
["settings", "thankYouScreenContent"]
|
|
37
36
|
];
|
|
38
|
-
|
|
37
|
+
const encode = (obj, key) => {
|
|
39
38
|
if (obj && obj[key]) {
|
|
40
39
|
obj[key] = encodeURIComponent(obj[key]);
|
|
41
40
|
}
|
|
42
41
|
return obj;
|
|
43
42
|
};
|
|
44
43
|
// encode props from array above
|
|
45
|
-
props.forEach(
|
|
46
|
-
|
|
47
|
-
return encode(clone[objKey], propKey);
|
|
48
|
-
});
|
|
44
|
+
props.forEach(([objKey, propKey]) => encode(clone[objKey], propKey));
|
|
45
|
+
const encodeQuestion = (question) => encode(question, "description");
|
|
49
46
|
// encode question descriptions
|
|
50
|
-
clone.questions = (clone.questions || []).map(
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
clone.questions = (clone.questions || []).map((question) => !question.questions
|
|
48
|
+
? encodeQuestion(question)
|
|
49
|
+
: {
|
|
50
|
+
...question,
|
|
51
|
+
questions: question.questions.map(encodeQuestion)
|
|
52
|
+
});
|
|
53
53
|
return clone;
|
|
54
54
|
};
|
|
55
55
|
//# sourceMappingURL=encode-survey-form.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-survey-form.js","sourceRoot":"","sources":["../../../src/helpers/encode-survey-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"encode-survey-form.js","sourceRoot":"","sources":["../../../src/helpers/encode-survey-form.ts"],"names":[],"mappings":"AAA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SAClD,CACJ,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -32,11 +32,11 @@ import { moveItem } from "@esri/arcgis-rest-portal";
|
|
|
32
32
|
* @returns {Promise<any>}
|
|
33
33
|
*/
|
|
34
34
|
export function postProcessHubSurvey(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return getItemBase(featureServiceResultId, authentication).then(
|
|
39
|
-
|
|
35
|
+
const featureServiceSourceId = template.properties.info.serviceInfo.itemId;
|
|
36
|
+
const { itemId: featureServiceResultId } = templateDictionary[featureServiceSourceId];
|
|
37
|
+
const interpolated = replaceInTemplate(template, templateDictionary);
|
|
38
|
+
return getItemBase(featureServiceResultId, authentication).then(featureServiceResultBase => {
|
|
39
|
+
const itemUpdates = [
|
|
40
40
|
// fix/update form properties we couldn't control via the API
|
|
41
41
|
{
|
|
42
42
|
id: itemId,
|
|
@@ -49,32 +49,26 @@ export function postProcessHubSurvey(itemId, type, itemInfos, template, template
|
|
|
49
49
|
{
|
|
50
50
|
id: featureServiceResultId,
|
|
51
51
|
extent: interpolated.item.extent,
|
|
52
|
-
typeKeywords: [
|
|
52
|
+
typeKeywords: [`source-${featureServiceSourceId}`].concat(featureServiceResultBase.typeKeywords)
|
|
53
53
|
}
|
|
54
54
|
];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
var updatePromises = itemUpdates.map(toUpdatePromise);
|
|
55
|
+
const toUpdatePromise = (updatedItem) => updateItem(updatedItem, authentication);
|
|
56
|
+
const updatePromises = itemUpdates.map(toUpdatePromise);
|
|
59
57
|
return Promise.all(updatePromises)
|
|
60
|
-
.then(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
var movePromises = itemIdsToMove.map(toMovePromise);
|
|
58
|
+
.then(() => {
|
|
59
|
+
const itemIdsToMove = [itemId, featureServiceResultId];
|
|
60
|
+
const toMovePromise = (id) => moveItem({
|
|
61
|
+
itemId: id,
|
|
62
|
+
folderId: templateDictionary.folderId,
|
|
63
|
+
authentication: authentication
|
|
64
|
+
});
|
|
65
|
+
const movePromises = itemIdsToMove.map(toMovePromise);
|
|
70
66
|
return Promise.all(movePromises);
|
|
71
67
|
})
|
|
72
|
-
.then(
|
|
73
|
-
|
|
74
|
-
})
|
|
75
|
-
.then(function () {
|
|
68
|
+
.then(() => removeFolder(featureServiceResultBase.ownerFolder, authentication))
|
|
69
|
+
.then(() => {
|
|
76
70
|
// Create a template item for the Feature Service that was created by the API
|
|
77
|
-
|
|
71
|
+
const featureServiceTemplate = createInitializedItemTemplate(featureServiceResultBase);
|
|
78
72
|
templates.push(featureServiceTemplate);
|
|
79
73
|
template.dependencies.push(featureServiceResultBase.id);
|
|
80
74
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-process-survey.js","sourceRoot":"","sources":["../../../src/helpers/post-process-survey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,6BAA6B,EAC7B,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,IAAY,EACZ,SAAgB,EAChB,QAAuB,EACvB,SAA0B,EAC1B,kBAAuB,EACvB,cAA2B;IAE3B,
|
|
1
|
+
{"version":3,"file":"post-process-survey.js","sourceRoot":"","sources":["../../../src/helpers/post-process-survey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,6BAA6B,EAC7B,YAAY,EAEb,MA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C,GAAG,CAAC,cAAc,CAAC;aAC/B,IAAI,CAAC,GAAG,EAAE;YACT,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;YACvD,MAAM,aAAa,GAAG,CAAC,EAAU,EAAE,EAAE,CACnC,QAAQ,CAAC;gBACP,MAAM,EAAE,EAAE;gBACV,QAAQ,EAAE,kBAAkB,CAAC,QAAkB;gBAC/C,cAAc,EAAE,cAAc;aAC/B,CAAC,CAAC;YACL,MAAM,YAAY,GAAG,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YACtD,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,EAAE,CACT,YAAY,CAAC,wBAAwB,CAAC,WAAW,EAAE,cAAc,CAAC,CACnE;aACA,IAAI,CAAC,GAAG,EAAE;YACT,6EAA6E;YAC7E,MAAM,sBAAsB,GAAG,6BAA6B,CAC1D,wBAAwB,CACzB,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YACvC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -24,8 +24,9 @@ import { UserSession, IItemTemplate } from "@esri/solution-common";
|
|
|
24
24
|
*
|
|
25
25
|
* @param {string} solutionItemId The solution item ID
|
|
26
26
|
* @param {any} itemInfo: The base item info
|
|
27
|
-
* @param {UserSession}
|
|
27
|
+
* @param {UserSession} destAuthentication Credentials for requests to the destination organization
|
|
28
|
+
* @param {UserSession} srcAuthentication Credentials for requests to source items
|
|
28
29
|
* @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
|
|
29
30
|
* @returns {Promise<IItemTemplate>}
|
|
30
31
|
*/
|
|
31
|
-
export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any,
|
|
32
|
+
export declare function convertItemToTemplate(solutionItemId: string, itemInfo: any, destAuthentication: UserSession, srcAuthentication: UserSession, templateDictionary: any): Promise<IItemTemplate>;
|
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.convertItemToTemplate = void 0;
|
|
19
|
-
|
|
19
|
+
const solution_simple_types_1 = require("@esri/solution-simple-types");
|
|
20
20
|
/**
|
|
21
21
|
* Creates a template from a Form item
|
|
22
22
|
*
|
|
23
23
|
* @param {string} solutionItemId The solution item ID
|
|
24
24
|
* @param {any} itemInfo: The base item info
|
|
25
|
-
* @param {UserSession}
|
|
25
|
+
* @param {UserSession} destAuthentication Credentials for requests to the destination organization
|
|
26
|
+
* @param {UserSession} srcAuthentication Credentials for requests to source items
|
|
26
27
|
* @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
|
|
27
28
|
* @returns {Promise<IItemTemplate>}
|
|
28
29
|
*/
|
|
29
|
-
function convertItemToTemplate(solutionItemId, itemInfo,
|
|
30
|
+
function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
|
|
30
31
|
// Delegate to simple types
|
|
31
|
-
return solution_simple_types_1.simpleTypes.convertItemToTemplate(solutionItemId, itemInfo,
|
|
32
|
+
return solution_simple_types_1.simpleTypes.convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
|
|
32
33
|
}
|
|
33
34
|
exports.convertItemToTemplate = convertItemToTemplate;
|
|
34
35
|
//# sourceMappingURL=convert-item-to-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-item-to-template.js","sourceRoot":"","sources":["../../src/convert-item-to-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AASH,
|
|
1
|
+
{"version":3,"file":"convert-item-to-template.js","sourceRoot":"","sources":["../../src/convert-item-to-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AASH,uEAA0D;AAE1D;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,kBAA+B,EAC/B,iBAA8B,EAC9B,kBAAuB;IAEvB,2BAA2B;IAC3B,OAAO,mCAAW,CAAC,qBAAqB,CACtC,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;AACJ,CAAC;AAfD,sDAeC"}
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.createItemFromTemplate = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const solution_simple_types_1 = require("@esri/solution-simple-types");
|
|
20
|
+
const is_hub_form_template_1 = require("./helpers/is-hub-form-template");
|
|
21
|
+
const create_item_from_hub_template_1 = require("./helpers/create-item-from-hub-template");
|
|
22
22
|
/**
|
|
23
23
|
* Creates a Form item from a template
|
|
24
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-item-from-template.js","sourceRoot":"","sources":["../../src/create-item-from-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAcH,
|
|
1
|
+
{"version":3,"file":"create-item-from-template.js","sourceRoot":"","sources":["../../src/create-item-from-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAcH,uEAA0D;AAC1D,yEAAmE;AACnE,2FAAoF;AAEpF;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CACpC,QAAuB,EACvB,kBAAuB,EACvB,yBAAsC,EACtC,oBAA2C;IAE3C,sCAAsC;IACtC,IAAI,IAAA,wCAAiB,EAAC,QAAQ,CAAC,EAAE;QAC/B,OAAO,IAAA,yDAAyB,EAC9B,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,CACrB,CAAC;KACH;IAED,qCAAqC;IACrC,OAAO,mCAAW,CAAC,sBAAsB,CACvC,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,CACrB,CAAC;AACJ,CAAC;AAvBD,wDAuBC"}
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.buildCreateParams = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var encode_survey_form_1 = require("./encode-survey-form");
|
|
19
|
+
const solution_common_1 = require("@esri/solution-common");
|
|
20
|
+
const encode_survey_form_1 = require("./encode-survey-form");
|
|
22
21
|
/**
|
|
23
22
|
* Utility method for creating Survey123 parameters
|
|
24
23
|
*
|
|
@@ -33,36 +32,45 @@ var encode_survey_form_1 = require("./encode-survey-form");
|
|
|
33
32
|
* @returns {Promise<ISurvey123CreateParams>}
|
|
34
33
|
*/
|
|
35
34
|
function buildCreateParams(template, templateDictionary, destinationAuthentication) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return (0, solution_common_1.getPortalDefaultBasemap)(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(
|
|
35
|
+
const { item: { title: originalTitle, description, tags, typeKeywords }, properties: { form: unencodedForm } } = template;
|
|
36
|
+
const { user: { username }, portalBaseUrl: portalUrl, organization: { basemapGalleryGroupQuery, defaultBasemap: { title: basemapTitle } } } = templateDictionary;
|
|
37
|
+
const { token } = destinationAuthentication.toCredential();
|
|
38
|
+
return (0, solution_common_1.getPortalDefaultBasemap)(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(defaultBasemap => {
|
|
40
39
|
// The S123 API appends "Survey-" to the survey title when computing
|
|
41
40
|
// the folder name. We need to use the same prefix to successfully
|
|
42
41
|
// calculate a unique folder name. Afterwards, we can safely remove the
|
|
43
42
|
// prefix from the title
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const folderPrefix = "Survey-";
|
|
44
|
+
const title = (0, solution_common_1.getUniqueTitle)(`${folderPrefix}${originalTitle}`, templateDictionary, "user.folders").replace(folderPrefix, "");
|
|
46
45
|
// set any map question's basemaps to default org basemap
|
|
47
46
|
if (unencodedForm.questions) {
|
|
48
|
-
|
|
47
|
+
const updateBasemap = (question) => {
|
|
49
48
|
if (question.maps) {
|
|
50
|
-
question.maps = question.maps.map(
|
|
49
|
+
question.maps = question.maps.map((map) => ({
|
|
50
|
+
...map,
|
|
51
|
+
itemId: defaultBasemap.id
|
|
52
|
+
}));
|
|
51
53
|
}
|
|
52
54
|
return question;
|
|
53
|
-
}
|
|
55
|
+
};
|
|
56
|
+
unencodedForm.questions = unencodedForm.questions.map((question) => !question.questions
|
|
57
|
+
? updateBasemap(question)
|
|
58
|
+
: {
|
|
59
|
+
...question,
|
|
60
|
+
questions: question.questions.map(updateBasemap)
|
|
61
|
+
});
|
|
54
62
|
}
|
|
55
|
-
|
|
63
|
+
const form = (0, encode_survey_form_1.encodeSurveyForm)(unencodedForm);
|
|
56
64
|
// intentionally undefined, handled downstream by core logic now
|
|
57
65
|
return {
|
|
58
|
-
description
|
|
59
|
-
form
|
|
60
|
-
portalUrl
|
|
61
|
-
tags
|
|
62
|
-
title
|
|
63
|
-
token
|
|
64
|
-
typeKeywords
|
|
65
|
-
username
|
|
66
|
+
description,
|
|
67
|
+
form,
|
|
68
|
+
portalUrl,
|
|
69
|
+
tags,
|
|
70
|
+
title,
|
|
71
|
+
token,
|
|
72
|
+
typeKeywords,
|
|
73
|
+
username
|
|
66
74
|
};
|
|
67
75
|
});
|
|
68
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-create-params.js","sourceRoot":"","sources":["../../../src/helpers/build-create-params.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"build-create-params.js","sourceRoot":"","sources":["../../../src/helpers/build-create-params.ts"],"names":[],"mappings":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cAAc,CAAC,EAAE;qBAC1B,CAAC,CAAC,CAAC;iBACL;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC,CAAC;YACF,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAa,EAAE,EAAE,CACtE,CAAC,QAAQ,CAAC,SAAS;gBACjB,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;gBACzB,CAAC,CAAC;oBACA,GAAG,QAAQ;oBACX,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC;iBACjD,CACJ,CAAC;SACH;QACD,MAAM,IAAI,GAAG,IAAA,qCAAgB,EAAC,aAAa,CAAC,CAAC;QAC7C,gEAAgE;QAChE,OAAO;YACL,WAAW;YACX,IAAI;YACJ,SAAS;YACT,IAAI;YACJ,KAAK;YACL,KAAK;YACL,YAAY;YACZ,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAlED,8CAkEC"}
|
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.createItemFromHubTemplate = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var build_create_params_1 = require("./build-create-params");
|
|
19
|
+
const solution_common_1 = require("@esri/solution-common");
|
|
20
|
+
const create_survey_1 = require("./create-survey");
|
|
21
|
+
const build_create_params_1 = require("./build-create-params");
|
|
23
22
|
/**
|
|
24
23
|
* Manages the creation of Surveys from Hub Templates
|
|
25
24
|
* via the Survey123 API
|
|
@@ -36,23 +35,23 @@ var build_create_params_1 = require("./build-create-params");
|
|
|
36
35
|
* @returns {Promise<ICreateItemFromTemplateResponse>}
|
|
37
36
|
*/
|
|
38
37
|
function createItemFromHubTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const interpolatedTemplate = (0, solution_common_1.replaceInTemplate)(template, templateDictionary);
|
|
39
|
+
const { survey123Url } = templateDictionary;
|
|
41
40
|
return (0, build_create_params_1.buildCreateParams)(interpolatedTemplate, templateDictionary, destinationAuthentication)
|
|
42
|
-
.then(
|
|
41
|
+
.then((params) => {
|
|
43
42
|
return (0, create_survey_1.createSurvey)(params, survey123Url);
|
|
44
43
|
})
|
|
45
|
-
.then(
|
|
46
|
-
|
|
44
|
+
.then((createSurveyResponse) => {
|
|
45
|
+
const { formId, featureServiceId } = createSurveyResponse;
|
|
47
46
|
// Update the item with its thumbnail
|
|
48
|
-
|
|
47
|
+
let thumbDef = Promise.resolve(null);
|
|
49
48
|
/* istanbul ignore else */
|
|
50
49
|
if (template.item.thumbnail) {
|
|
51
50
|
thumbDef = (0, solution_common_1.updateItemExtended)({ id: formId }, null, destinationAuthentication, template.item.thumbnail);
|
|
52
51
|
}
|
|
53
52
|
return thumbDef
|
|
54
|
-
.then(
|
|
55
|
-
.then(
|
|
53
|
+
.then(() => (0, solution_common_1.getItemBase)(formId, destinationAuthentication))
|
|
54
|
+
.then(item => {
|
|
56
55
|
templateDictionary[interpolatedTemplate.itemId] = {
|
|
57
56
|
itemId: formId
|
|
58
57
|
};
|
|
@@ -61,14 +60,18 @@ function createItemFromHubTemplate(template, templateDictionary, destinationAuth
|
|
|
61
60
|
};
|
|
62
61
|
itemProgressCallback(interpolatedTemplate.itemId, solution_common_1.EItemProgressStatus.Finished, interpolatedTemplate.estimatedDeploymentCostFactor, formId);
|
|
63
62
|
return {
|
|
64
|
-
item:
|
|
63
|
+
item: {
|
|
64
|
+
...template,
|
|
65
|
+
item,
|
|
66
|
+
itemId: formId
|
|
67
|
+
},
|
|
65
68
|
id: formId,
|
|
66
69
|
type: "Form",
|
|
67
70
|
postProcess: true
|
|
68
71
|
};
|
|
69
72
|
});
|
|
70
73
|
})
|
|
71
|
-
.catch(
|
|
74
|
+
.catch(e => {
|
|
72
75
|
itemProgressCallback(interpolatedTemplate.itemId, solution_common_1.EItemProgressStatus.Failed, 0);
|
|
73
76
|
throw e;
|
|
74
77
|
});
|