@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
package/dist/umd/form.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/solution-form - v1.
|
|
2
|
+
* @esri/solution-form - v1.2.0 - Apache-2.0
|
|
3
3
|
* Copyright (c) 2018-2021 Esri, Inc.
|
|
4
|
-
*
|
|
4
|
+
* Thu Dec 09 2021 16:04:54 GMT-0800 (Pacific Standard Time)
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,8 +18,28 @@
|
|
|
18
18
|
(function (global, factory) {
|
|
19
19
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-simple-types'), require('@esri/solution-common'), require('@esri/arcgis-rest-request'), require('@esri/arcgis-rest-portal')) :
|
|
20
20
|
typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-simple-types', '@esri/solution-common', '@esri/arcgis-rest-request', '@esri/arcgis-rest-portal'], factory) :
|
|
21
|
-
(global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisSolution, global.arcgisRest, global.arcgisRest));
|
|
22
|
-
}(this, (function (exports, solutionSimpleTypes, common, arcgisRestRequest, arcgisRestPortal) { 'use strict';
|
|
21
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisSolution, global.arcgisRest, global.arcgisRest));
|
|
22
|
+
})(this, (function (exports, solutionSimpleTypes, common, arcgisRestRequest, arcgisRestPortal) { '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);
|
|
23
43
|
|
|
24
44
|
/** @license
|
|
25
45
|
* Copyright 2018 Esri
|
|
@@ -41,13 +61,14 @@
|
|
|
41
61
|
*
|
|
42
62
|
* @param {string} solutionItemId The solution item ID
|
|
43
63
|
* @param {any} itemInfo: The base item info
|
|
44
|
-
* @param {UserSession}
|
|
64
|
+
* @param {UserSession} destAuthentication Credentials for requests to the destination organization
|
|
65
|
+
* @param {UserSession} srcAuthentication Credentials for requests to source items
|
|
45
66
|
* @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
|
|
46
67
|
* @returns {Promise<IItemTemplate>}
|
|
47
68
|
*/
|
|
48
|
-
function convertItemToTemplate(solutionItemId, itemInfo,
|
|
69
|
+
function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
|
|
49
70
|
// Delegate to simple types
|
|
50
|
-
return solutionSimpleTypes.simpleTypes.convertItemToTemplate(solutionItemId, itemInfo,
|
|
71
|
+
return solutionSimpleTypes.simpleTypes.convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
/** @license
|
|
@@ -74,50 +95,7 @@
|
|
|
74
95
|
*/
|
|
75
96
|
function isHubFormTemplate(template) {
|
|
76
97
|
// relying on basic duck typing vs adding extraneous props during migration
|
|
77
|
-
return !!
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/*! *****************************************************************************
|
|
81
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
82
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
83
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
84
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
85
|
-
|
|
86
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
87
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
88
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
89
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
90
|
-
|
|
91
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
92
|
-
and limitations under the License.
|
|
93
|
-
***************************************************************************** */
|
|
94
|
-
|
|
95
|
-
var __assign = function() {
|
|
96
|
-
__assign = Object.assign || function __assign(t) {
|
|
97
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
98
|
-
s = arguments[i];
|
|
99
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
100
|
-
}
|
|
101
|
-
return t;
|
|
102
|
-
};
|
|
103
|
-
return __assign.apply(this, arguments);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
function __read(o, n) {
|
|
107
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
108
|
-
if (!m) return o;
|
|
109
|
-
var i = m.call(o), r, ar = [], e;
|
|
110
|
-
try {
|
|
111
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
112
|
-
}
|
|
113
|
-
catch (error) { e = { error: error }; }
|
|
114
|
-
finally {
|
|
115
|
-
try {
|
|
116
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
117
|
-
}
|
|
118
|
-
finally { if (e) throw e.error; }
|
|
119
|
-
}
|
|
120
|
-
return ar;
|
|
98
|
+
return !!common__namespace.getProp(template, "properties.services");
|
|
121
99
|
}
|
|
122
100
|
|
|
123
101
|
/** @license
|
|
@@ -148,22 +126,24 @@
|
|
|
148
126
|
* @throws Will throw if the Survey123 API returns an error response
|
|
149
127
|
* @returns {Promise<ISurvey123CreateResult>}
|
|
150
128
|
*/
|
|
151
|
-
function createSurvey(params, survey123Url) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var ro = {
|
|
129
|
+
function createSurvey(params, survey123Url = "https://survey123.arcgis.com") {
|
|
130
|
+
const createUrl = `${survey123Url}/api/survey/create`;
|
|
131
|
+
const ro = {
|
|
155
132
|
credentials: "same-origin",
|
|
156
133
|
method: "POST",
|
|
157
|
-
body: arcgisRestRequest.encodeFormData(
|
|
134
|
+
body: arcgisRestRequest.encodeFormData({
|
|
135
|
+
f: "json",
|
|
136
|
+
...params
|
|
137
|
+
}, true)
|
|
158
138
|
};
|
|
159
139
|
// Using @esri/arcgis-request "request" method was resulting in a 404 for
|
|
160
140
|
// a CORS preflight request related to this request, but calling fetch directly
|
|
161
141
|
// circumvents the issue.
|
|
162
142
|
return fetch(createUrl, ro)
|
|
163
|
-
.then(
|
|
164
|
-
.then(
|
|
143
|
+
.then(response => response.json())
|
|
144
|
+
.then(response => {
|
|
165
145
|
if (!response.success) {
|
|
166
|
-
throw new Error(
|
|
146
|
+
throw new Error(`Failed to create survey: ${response.error.message}`);
|
|
167
147
|
}
|
|
168
148
|
return {
|
|
169
149
|
formId: response.id,
|
|
@@ -200,29 +180,30 @@
|
|
|
200
180
|
* @param {any} form Unencoded form data
|
|
201
181
|
* @returns {any} Encoded form data
|
|
202
182
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
183
|
+
const encodeSurveyForm = function encodeForm(form) {
|
|
184
|
+
const clone = common.cloneObject(form);
|
|
185
|
+
const props = [
|
|
206
186
|
["header", "content"],
|
|
207
187
|
["subHeader", "content"],
|
|
208
188
|
["footer", "content"],
|
|
209
189
|
["settings", "thankYouScreenContent"]
|
|
210
190
|
];
|
|
211
|
-
|
|
191
|
+
const encode = (obj, key) => {
|
|
212
192
|
if (obj && obj[key]) {
|
|
213
193
|
obj[key] = encodeURIComponent(obj[key]);
|
|
214
194
|
}
|
|
215
195
|
return obj;
|
|
216
196
|
};
|
|
217
197
|
// encode props from array above
|
|
218
|
-
props.forEach(
|
|
219
|
-
|
|
220
|
-
return encode(clone[objKey], propKey);
|
|
221
|
-
});
|
|
198
|
+
props.forEach(([objKey, propKey]) => encode(clone[objKey], propKey));
|
|
199
|
+
const encodeQuestion = (question) => encode(question, "description");
|
|
222
200
|
// encode question descriptions
|
|
223
|
-
clone.questions = (clone.questions || []).map(
|
|
224
|
-
|
|
225
|
-
|
|
201
|
+
clone.questions = (clone.questions || []).map((question) => !question.questions
|
|
202
|
+
? encodeQuestion(question)
|
|
203
|
+
: {
|
|
204
|
+
...question,
|
|
205
|
+
questions: question.questions.map(encodeQuestion)
|
|
206
|
+
});
|
|
226
207
|
return clone;
|
|
227
208
|
};
|
|
228
209
|
|
|
@@ -255,36 +236,45 @@
|
|
|
255
236
|
* @returns {Promise<ISurvey123CreateParams>}
|
|
256
237
|
*/
|
|
257
238
|
function buildCreateParams(template, templateDictionary, destinationAuthentication) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return common.getPortalDefaultBasemap(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(
|
|
239
|
+
const { item: { title: originalTitle, description, tags, typeKeywords }, properties: { form: unencodedForm } } = template;
|
|
240
|
+
const { user: { username }, portalBaseUrl: portalUrl, organization: { basemapGalleryGroupQuery, defaultBasemap: { title: basemapTitle } } } = templateDictionary;
|
|
241
|
+
const { token } = destinationAuthentication.toCredential();
|
|
242
|
+
return common.getPortalDefaultBasemap(basemapGalleryGroupQuery, basemapTitle, destinationAuthentication).then(defaultBasemap => {
|
|
262
243
|
// The S123 API appends "Survey-" to the survey title when computing
|
|
263
244
|
// the folder name. We need to use the same prefix to successfully
|
|
264
245
|
// calculate a unique folder name. Afterwards, we can safely remove the
|
|
265
246
|
// prefix from the title
|
|
266
|
-
|
|
267
|
-
|
|
247
|
+
const folderPrefix = "Survey-";
|
|
248
|
+
const title = common.getUniqueTitle(`${folderPrefix}${originalTitle}`, templateDictionary, "user.folders").replace(folderPrefix, "");
|
|
268
249
|
// set any map question's basemaps to default org basemap
|
|
269
250
|
if (unencodedForm.questions) {
|
|
270
|
-
|
|
251
|
+
const updateBasemap = (question) => {
|
|
271
252
|
if (question.maps) {
|
|
272
|
-
question.maps = question.maps.map(
|
|
253
|
+
question.maps = question.maps.map((map) => ({
|
|
254
|
+
...map,
|
|
255
|
+
itemId: defaultBasemap.id
|
|
256
|
+
}));
|
|
273
257
|
}
|
|
274
258
|
return question;
|
|
275
|
-
}
|
|
259
|
+
};
|
|
260
|
+
unencodedForm.questions = unencodedForm.questions.map((question) => !question.questions
|
|
261
|
+
? updateBasemap(question)
|
|
262
|
+
: {
|
|
263
|
+
...question,
|
|
264
|
+
questions: question.questions.map(updateBasemap)
|
|
265
|
+
});
|
|
276
266
|
}
|
|
277
|
-
|
|
267
|
+
const form = encodeSurveyForm(unencodedForm);
|
|
278
268
|
// intentionally undefined, handled downstream by core logic now
|
|
279
269
|
return {
|
|
280
|
-
description
|
|
281
|
-
form
|
|
282
|
-
portalUrl
|
|
283
|
-
tags
|
|
284
|
-
title
|
|
285
|
-
token
|
|
286
|
-
typeKeywords
|
|
287
|
-
username
|
|
270
|
+
description,
|
|
271
|
+
form,
|
|
272
|
+
portalUrl,
|
|
273
|
+
tags,
|
|
274
|
+
title,
|
|
275
|
+
token,
|
|
276
|
+
typeKeywords,
|
|
277
|
+
username
|
|
288
278
|
};
|
|
289
279
|
});
|
|
290
280
|
}
|
|
@@ -320,23 +310,23 @@
|
|
|
320
310
|
* @returns {Promise<ICreateItemFromTemplateResponse>}
|
|
321
311
|
*/
|
|
322
312
|
function createItemFromHubTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
|
|
323
|
-
|
|
324
|
-
|
|
313
|
+
const interpolatedTemplate = common.replaceInTemplate(template, templateDictionary);
|
|
314
|
+
const { survey123Url } = templateDictionary;
|
|
325
315
|
return buildCreateParams(interpolatedTemplate, templateDictionary, destinationAuthentication)
|
|
326
|
-
.then(
|
|
316
|
+
.then((params) => {
|
|
327
317
|
return createSurvey(params, survey123Url);
|
|
328
318
|
})
|
|
329
|
-
.then(
|
|
330
|
-
|
|
319
|
+
.then((createSurveyResponse) => {
|
|
320
|
+
const { formId, featureServiceId } = createSurveyResponse;
|
|
331
321
|
// Update the item with its thumbnail
|
|
332
|
-
|
|
322
|
+
let thumbDef = Promise.resolve(null);
|
|
333
323
|
/* istanbul ignore else */
|
|
334
324
|
if (template.item.thumbnail) {
|
|
335
325
|
thumbDef = common.updateItemExtended({ id: formId }, null, destinationAuthentication, template.item.thumbnail);
|
|
336
326
|
}
|
|
337
327
|
return thumbDef
|
|
338
|
-
.then(
|
|
339
|
-
.then(
|
|
328
|
+
.then(() => common.getItemBase(formId, destinationAuthentication))
|
|
329
|
+
.then(item => {
|
|
340
330
|
templateDictionary[interpolatedTemplate.itemId] = {
|
|
341
331
|
itemId: formId
|
|
342
332
|
};
|
|
@@ -345,14 +335,18 @@
|
|
|
345
335
|
};
|
|
346
336
|
itemProgressCallback(interpolatedTemplate.itemId, common.EItemProgressStatus.Finished, interpolatedTemplate.estimatedDeploymentCostFactor, formId);
|
|
347
337
|
return {
|
|
348
|
-
item:
|
|
338
|
+
item: {
|
|
339
|
+
...template,
|
|
340
|
+
item,
|
|
341
|
+
itemId: formId
|
|
342
|
+
},
|
|
349
343
|
id: formId,
|
|
350
344
|
type: "Form",
|
|
351
345
|
postProcess: true
|
|
352
346
|
};
|
|
353
347
|
});
|
|
354
348
|
})
|
|
355
|
-
.catch(
|
|
349
|
+
.catch(e => {
|
|
356
350
|
itemProgressCallback(interpolatedTemplate.itemId, common.EItemProgressStatus.Failed, 0);
|
|
357
351
|
throw e;
|
|
358
352
|
});
|
|
@@ -423,11 +417,11 @@
|
|
|
423
417
|
* @returns {Promise<any>}
|
|
424
418
|
*/
|
|
425
419
|
function postProcessHubSurvey(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return common.getItemBase(featureServiceResultId, authentication).then(
|
|
430
|
-
|
|
420
|
+
const featureServiceSourceId = template.properties.info.serviceInfo.itemId;
|
|
421
|
+
const { itemId: featureServiceResultId } = templateDictionary[featureServiceSourceId];
|
|
422
|
+
const interpolated = common.replaceInTemplate(template, templateDictionary);
|
|
423
|
+
return common.getItemBase(featureServiceResultId, authentication).then(featureServiceResultBase => {
|
|
424
|
+
const itemUpdates = [
|
|
431
425
|
// fix/update form properties we couldn't control via the API
|
|
432
426
|
{
|
|
433
427
|
id: itemId,
|
|
@@ -440,32 +434,26 @@
|
|
|
440
434
|
{
|
|
441
435
|
id: featureServiceResultId,
|
|
442
436
|
extent: interpolated.item.extent,
|
|
443
|
-
typeKeywords: [
|
|
437
|
+
typeKeywords: [`source-${featureServiceSourceId}`].concat(featureServiceResultBase.typeKeywords)
|
|
444
438
|
}
|
|
445
439
|
];
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
};
|
|
449
|
-
var updatePromises = itemUpdates.map(toUpdatePromise);
|
|
440
|
+
const toUpdatePromise = (updatedItem) => common.updateItem(updatedItem, authentication);
|
|
441
|
+
const updatePromises = itemUpdates.map(toUpdatePromise);
|
|
450
442
|
return Promise.all(updatePromises)
|
|
451
|
-
.then(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
};
|
|
460
|
-
var movePromises = itemIdsToMove.map(toMovePromise);
|
|
443
|
+
.then(() => {
|
|
444
|
+
const itemIdsToMove = [itemId, featureServiceResultId];
|
|
445
|
+
const toMovePromise = (id) => arcgisRestPortal.moveItem({
|
|
446
|
+
itemId: id,
|
|
447
|
+
folderId: templateDictionary.folderId,
|
|
448
|
+
authentication: authentication
|
|
449
|
+
});
|
|
450
|
+
const movePromises = itemIdsToMove.map(toMovePromise);
|
|
461
451
|
return Promise.all(movePromises);
|
|
462
452
|
})
|
|
463
|
-
.then(
|
|
464
|
-
|
|
465
|
-
})
|
|
466
|
-
.then(function () {
|
|
453
|
+
.then(() => common.removeFolder(featureServiceResultBase.ownerFolder, authentication))
|
|
454
|
+
.then(() => {
|
|
467
455
|
// Create a template item for the Feature Service that was created by the API
|
|
468
|
-
|
|
456
|
+
const featureServiceTemplate = common.createInitializedItemTemplate(featureServiceResultBase);
|
|
469
457
|
templates.push(featureServiceTemplate);
|
|
470
458
|
template.dependencies.push(featureServiceResultBase.id);
|
|
471
459
|
return true;
|
|
@@ -511,5 +499,5 @@
|
|
|
511
499
|
|
|
512
500
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
513
501
|
|
|
514
|
-
}))
|
|
502
|
+
}));
|
|
515
503
|
//# sourceMappingURL=form.umd.js.map
|
package/dist/umd/form.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.umd.js","sources":["../../src/convert-item-to-template.ts","../../src/helpers/is-hub-form-template.ts","../../src/helpers/create-survey.ts","../../src/helpers/encode-survey-form.ts","../../src/helpers/build-create-params.ts","../../src/helpers/create-item-from-hub-template.ts","../../src/create-item-from-template.ts","../../src/helpers/post-process-survey.ts","../../src/post-process.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 of Form templates\r\n *\r\n * @module convert-item-to-template\r\n */\r\n\r\nimport { UserSession, IItemTemplate } from \"@esri/solution-common\";\r\nimport { simpleTypes } from \"@esri/solution-simple-types\";\r\n\r\n/**\r\n * Creates a template from a Form item\r\n *\r\n * @param {string} solutionItemId The solution item ID\r\n * @param {any} itemInfo: The base item info\r\n * @param {UserSession} authentication The source user session information\r\n * @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns {Promise<IItemTemplate>}\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n authentication: UserSession,\r\n templateDictionary: any\r\n): Promise<IItemTemplate> {\r\n // Delegate to simple types\r\n return simpleTypes.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n authentication,\r\n templateDictionary\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * Determines if the given template is a Hub Survey\r\n * template vs Solutions.js Survey template.\r\n *\r\n * @param {IITemTemplate} template A template\r\n * @returns {boolean}\r\n */\r\nexport function isHubFormTemplate(template: common.IItemTemplate): boolean {\r\n // relying on basic duck typing vs adding extraneous props during migration\r\n return !!common.getProp(template, \"properties.services\");\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n ISurvey123CreateParams,\r\n ISurvey123CreateResult\r\n} from \"@esri/solution-common\";\r\nimport { encodeFormData } from \"@esri/arcgis-rest-request\";\r\n\r\n/**\r\n * Provides utility method to call Survey123 create endpoint\r\n *\r\n * @module create-survey\r\n */\r\n\r\n/**\r\n * Calls the Survey123 create API with the given parameters\r\n *\r\n * @param {ISurvey123CreateParams} params\r\n * @param {string} [survey123Url=https://survey123.arcgis.com] An optional, Survey123 base URL override\r\n * @throws Will throw if the Survey123 API returns an error response\r\n * @returns {Promise<ISurvey123CreateResult>}\r\n */\r\nexport function createSurvey(\r\n params: ISurvey123CreateParams,\r\n survey123Url = \"https://survey123.arcgis.com\"\r\n): Promise<ISurvey123CreateResult> {\r\n const createUrl = `${survey123Url}/api/survey/create`;\r\n const ro = {\r\n credentials: \"same-origin\" as RequestCredentials,\r\n method: \"POST\",\r\n body: encodeFormData(\r\n {\r\n f: \"json\",\r\n ...params\r\n },\r\n true\r\n )\r\n };\r\n // Using @esri/arcgis-request \"request\" method was resulting in a 404 for\r\n // a CORS preflight request related to this request, but calling fetch directly\r\n // circumvents the issue.\r\n return fetch(createUrl, ro)\r\n .then(response => response.json())\r\n .then(response => {\r\n if (!response.success) {\r\n throw new Error(`Failed to create survey: ${response.error.message}`);\r\n }\r\n return {\r\n formId: response.id,\r\n featureServiceId: response.featureService.source.itemId,\r\n folderId: response.formItemInfo.ownerFolder\r\n };\r\n });\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport { cloneObject } from \"@esri/solution-common\";\r\n\r\n/**\r\n * Manages Survey123 parameter encoding\r\n *\r\n * @module encode-survey-form\r\n */\r\n\r\n/**\r\n * URI Encodes Survey123 form content parameter\r\n * values\r\n *\r\n * @param {any} form Unencoded form data\r\n * @returns {any} Encoded form data\r\n */\r\nexport const encodeSurveyForm = function encodeForm(form: any) {\r\n const clone = cloneObject(form);\r\n const props = [\r\n [\"header\", \"content\"],\r\n [\"subHeader\", \"content\"],\r\n [\"footer\", \"content\"],\r\n [\"settings\", \"thankYouScreenContent\"]\r\n ];\r\n const encode = (\r\n obj: { [key: string]: string },\r\n key: string\r\n ): { [key: string]: string } => {\r\n if (obj && obj[key]) {\r\n obj[key] = encodeURIComponent(obj[key]);\r\n }\r\n return obj;\r\n };\r\n\r\n // encode props from array above\r\n props.forEach(([objKey, propKey]) => encode(clone[objKey], propKey));\r\n\r\n // encode question descriptions\r\n clone.questions = (clone.questions || []).map((question: any) =>\r\n encode(question, \"description\")\r\n );\r\n\r\n return clone;\r\n};\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n IItemTemplate,\r\n UserSession,\r\n getUniqueTitle,\r\n ISurvey123CreateParams,\r\n getPortalDefaultBasemap\r\n} from \"@esri/solution-common\";\r\nimport { encodeSurveyForm } from \"./encode-survey-form\";\r\n\r\n/**\r\n * Utility method for creating Survey123 parameters\r\n *\r\n * @module build-create-params\r\n */\r\n\r\n/**\r\n * Builds the Survey123 create API parameters\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination session info\r\n * @returns {Promise<ISurvey123CreateParams>}\r\n */\r\nexport function buildCreateParams(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession\r\n): Promise<ISurvey123CreateParams> {\r\n const {\r\n item: { title: originalTitle, description, tags, typeKeywords },\r\n properties: { form: unencodedForm }\r\n } = template;\r\n const {\r\n user: { username },\r\n portalBaseUrl: portalUrl,\r\n organization: {\r\n basemapGalleryGroupQuery,\r\n defaultBasemap: { title: basemapTitle }\r\n }\r\n } = templateDictionary;\r\n const { token } = destinationAuthentication.toCredential();\r\n return getPortalDefaultBasemap(\r\n basemapGalleryGroupQuery,\r\n basemapTitle,\r\n destinationAuthentication\r\n ).then(defaultBasemap => {\r\n // The S123 API appends \"Survey-\" to the survey title when computing\r\n // the folder name. We need to use the same prefix to successfully\r\n // calculate a unique folder name. Afterwards, we can safely remove the\r\n // prefix from the title\r\n const folderPrefix = \"Survey-\";\r\n const title = getUniqueTitle(\r\n `${folderPrefix}${originalTitle}`,\r\n templateDictionary,\r\n \"user.folders\"\r\n ).replace(folderPrefix, \"\");\r\n // set any map question's basemaps to default org basemap\r\n if (unencodedForm.questions) {\r\n unencodedForm.questions = unencodedForm.questions.map((question: any) => {\r\n if (question.maps) {\r\n question.maps = question.maps.map((map: any) => ({\r\n ...map,\r\n itemId: defaultBasemap.id\r\n }));\r\n }\r\n return question;\r\n });\r\n }\r\n const form = encodeSurveyForm(unencodedForm);\r\n // intentionally undefined, handled downstream by core logic now\r\n return {\r\n description,\r\n form,\r\n portalUrl,\r\n tags,\r\n title,\r\n token,\r\n typeKeywords,\r\n username\r\n };\r\n });\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n IItemTemplate,\r\n UserSession,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n replaceInTemplate,\r\n updateItemExtended,\r\n ISurvey123CreateParams,\r\n ISurvey123CreateResult,\r\n getItemBase\r\n} from \"@esri/solution-common\";\r\nimport { createSurvey } from \"./create-survey\";\r\nimport { buildCreateParams } from \"./build-create-params\";\r\n\r\n/**\r\n * Manages the creation of Surveys from Hub Templates\r\n * via the Survey123 API\r\n *\r\n * @module create-item-from-hub-template\r\n */\r\n\r\n/**\r\n * Orchestrates creation of Surveys from Hub templates\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination session info\r\n * @param {Function} itemProgressCallback A progress callback\r\n * @returns {Promise<ICreateItemFromTemplateResponse>}\r\n */\r\nexport function createItemFromHubTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n const interpolatedTemplate = replaceInTemplate(template, templateDictionary);\r\n const { survey123Url } = templateDictionary;\r\n\r\n return buildCreateParams(\r\n interpolatedTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n )\r\n .then((params: ISurvey123CreateParams) => {\r\n return createSurvey(params, survey123Url);\r\n })\r\n .then((createSurveyResponse: ISurvey123CreateResult) => {\r\n const { formId, featureServiceId } = createSurveyResponse;\r\n\r\n // Update the item with its thumbnail\r\n let thumbDef: Promise<any> = Promise.resolve(null);\r\n /* istanbul ignore else */\r\n if (template.item.thumbnail) {\r\n thumbDef = updateItemExtended(\r\n { id: formId },\r\n null,\r\n destinationAuthentication,\r\n template.item.thumbnail\r\n );\r\n }\r\n\r\n return thumbDef\r\n .then(() => getItemBase(formId, destinationAuthentication))\r\n .then(item => {\r\n templateDictionary[interpolatedTemplate.itemId] = {\r\n itemId: formId\r\n };\r\n templateDictionary[\r\n interpolatedTemplate.properties.info.serviceInfo.itemId\r\n ] = {\r\n itemId: featureServiceId\r\n };\r\n itemProgressCallback(\r\n interpolatedTemplate.itemId,\r\n EItemProgressStatus.Finished,\r\n interpolatedTemplate.estimatedDeploymentCostFactor,\r\n formId\r\n );\r\n return {\r\n item: {\r\n ...template,\r\n item,\r\n itemId: formId\r\n },\r\n id: formId,\r\n type: \"Form\",\r\n postProcess: true\r\n };\r\n });\r\n })\r\n .catch(e => {\r\n itemProgressCallback(\r\n interpolatedTemplate.itemId,\r\n EItemProgressStatus.Failed,\r\n 0\r\n );\r\n throw e;\r\n });\r\n}\r\n","/** @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 deployment items from Form templates.\r\n *\r\n * @module create-item-from-template\r\n */\r\n\r\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse\r\n} from \"@esri/solution-common\";\r\nimport { simpleTypes } from \"@esri/solution-simple-types\";\r\nimport { isHubFormTemplate } from \"./helpers/is-hub-form-template\";\r\nimport { createItemFromHubTemplate } from \"./helpers/create-item-from-hub-template\";\r\n\r\n/**\r\n * Creates a Form item from a template\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination user session info\r\n * @param itemProgressCallback An item progress callback\r\n * @returns {Promise<ICreateItemFromTemplateResponse>}\r\n */\r\nexport function createItemFromTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n // Hub Form template custom processing\r\n if (isHubFormTemplate(template)) {\r\n return createItemFromHubTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n }\r\n\r\n // otherwise delegate to simple types\r\n return simpleTypes.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n updateItem,\r\n replaceInTemplate,\r\n getItemBase,\r\n createInitializedItemTemplate,\r\n removeFolder,\r\n IItemUpdate\r\n} from \"@esri/solution-common\";\r\nimport { moveItem } from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Provides utility method to post process Hub surveys\r\n *\r\n * @module post-process-survey\r\n */\r\n\r\n/**\r\n * Performs Survey post processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template/item type\r\n * @param {any[]} itemInfos An Array of item details\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns {Promise<any>}\r\n */\r\nexport function postProcessHubSurvey(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const featureServiceSourceId = template.properties.info.serviceInfo.itemId;\r\n const { itemId: featureServiceResultId } = templateDictionary[\r\n featureServiceSourceId\r\n ];\r\n const interpolated = replaceInTemplate(template, templateDictionary);\r\n return getItemBase(featureServiceResultId, authentication).then(\r\n featureServiceResultBase => {\r\n const itemUpdates = [\r\n // fix/update form properties we couldn't control via the API\r\n {\r\n id: itemId,\r\n title: interpolated.item.title,\r\n snippet: interpolated.item.snippet,\r\n extent: interpolated.item.extent,\r\n culture: interpolated.item.culture\r\n },\r\n // fix/update feature service properties we couldn't control via the API\r\n {\r\n id: featureServiceResultId,\r\n extent: interpolated.item.extent,\r\n typeKeywords: [`source-${featureServiceSourceId}`].concat(\r\n featureServiceResultBase.typeKeywords\r\n )\r\n }\r\n ];\r\n const toUpdatePromise = (updatedItem: IItemUpdate) =>\r\n updateItem(updatedItem, authentication);\r\n const updatePromises = itemUpdates.map(toUpdatePromise);\r\n return Promise.all(updatePromises)\r\n .then(() => {\r\n const itemIdsToMove = [itemId, featureServiceResultId];\r\n const toMovePromise = (id: string) =>\r\n moveItem({\r\n itemId: id,\r\n folderId: templateDictionary.folderId as string,\r\n authentication: authentication\r\n });\r\n const movePromises = itemIdsToMove.map(toMovePromise);\r\n return Promise.all(movePromises);\r\n })\r\n .then(() =>\r\n removeFolder(featureServiceResultBase.ownerFolder, authentication)\r\n )\r\n .then(() => {\r\n // Create a template item for the Feature Service that was created by the API\r\n const featureServiceTemplate = createInitializedItemTemplate(\r\n featureServiceResultBase\r\n );\r\n templates.push(featureServiceTemplate);\r\n template.dependencies.push(featureServiceResultBase.id);\r\n return true;\r\n });\r\n }\r\n );\r\n}\r\n","/** @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 form item types.\r\n *\r\n * @module post-process\r\n */\r\n\r\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n updateItemTemplateFromDictionary\r\n} from \"@esri/solution-common\";\r\nimport { isHubFormTemplate } from \"./helpers/is-hub-form-template\";\r\nimport { postProcessHubSurvey } from \"./helpers/post-process-survey\";\r\n\r\n/**\r\n * Form post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n if (isHubFormTemplate(template)) {\r\n return postProcessHubSurvey(\r\n itemId,\r\n type,\r\n itemInfos,\r\n template,\r\n templates,\r\n templateDictionary,\r\n authentication\r\n );\r\n }\r\n\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n"],"names":["simpleTypes","common.getProp","encodeFormData","cloneObject","getPortalDefaultBasemap","getUniqueTitle","replaceInTemplate","updateItemExtended","getItemBase","EItemProgressStatus","updateItem","moveItem","removeFolder","createInitializedItemTemplate","updateItemTemplateFromDictionary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;EAyBA;;;;;;;;;WASgB,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,cAA2B,EAC3B,kBAAuB;;MAGvB,OAAOA,+BAAW,CAAC,qBAAqB,CACtC,cAAc,EACd,QAAQ,EACR,cAAc,EACd,kBAAkB,CACnB,CAAC;EACJ;;EC/CA;;;;;;;;;;;;;;;AAgBA,EAEA;;;;;;;AAOA,WAAgB,iBAAiB,CAAC,QAA8B;;MAE9D,OAAO,CAAC,CAACC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;EAC3D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EC5BD;;;;;;;;;;;;;;;EAsBA;;;;;EAMA;;;;;;;;AAQA,WAAgB,YAAY,CAC1B,MAA8B,EAC9B,YAA6C;MAA7C,6BAAA,EAAA,6CAA6C;MAE7C,IAAM,SAAS,GAAM,YAAY,uBAAoB,CAAC;MACtD,IAAM,EAAE,GAAG;UACT,WAAW,EAAE,aAAmC;UAChD,MAAM,EAAE,MAAM;UACd,IAAI,EAAEC,gCAAc,YAEhB,CAAC,EAAE,MAAM,IACN,MAAM,GAEX,IAAI,CACL;OACF,CAAC;;;;MAIF,OAAO,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;WACxB,IAAI,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,EAAE,GAAA,CAAC;WACjC,IAAI,CAAC,UAAA,QAAQ;UACZ,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;cACrB,MAAM,IAAI,KAAK,CAAC,8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C,YAAY,CAAC,CAAC;WAClC,CAAC;eACD,IAAI,CAAC;cACJ,OAAAC,mBAAY,CAAC,wBAAwB,CAAC,WAAW,EAAE,cAAc,CAAC;WAAA,CACnE;eACA,IAAI,CAAC;;cAEJ,IAAM,sBAAsB,GAAGC,oCAA6B,CAC1D,wBAAwB,CACzB,CAAC;cACF,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;cACvC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC;cACxD,OAAO,IAAI,CAAC;WACb,CAAC,CAAC;OACN,CACF,CAAC;EACJ,CAAC;;EC5GD;;;;;;;;;;;;;;;AAgBA,EAcA;;;;;;;;;;AAUA,WAAgB,WAAW,CACzB,MAAc,EACd,IAAY,EACZ,SAAgB,EAChB,QAAuB,EACvB,SAA0B,EAC1B,kBAAuB,EACvB,cAA2B;MAE3B,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE;UAC/B,OAAO,oBAAoB,CACzB,MAAM,EACN,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,cAAc,CACf,CAAC;OACH;MAED,OAAOC,uCAAgC,CACrC,MAAM,EACN,kBAAkB,EAClB,cAAc,CACf,CAAC;EACJ,CAAC;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"form.umd.js","sources":["../../src/convert-item-to-template.ts","../../src/helpers/is-hub-form-template.ts","../../src/helpers/create-survey.ts","../../src/helpers/encode-survey-form.ts","../../src/helpers/build-create-params.ts","../../src/helpers/create-item-from-hub-template.ts","../../src/create-item-from-template.ts","../../src/helpers/post-process-survey.ts","../../src/post-process.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 of Form templates\r\n *\r\n * @module convert-item-to-template\r\n */\r\n\r\nimport { UserSession, IItemTemplate } from \"@esri/solution-common\";\r\nimport { simpleTypes } from \"@esri/solution-simple-types\";\r\n\r\n/**\r\n * Creates a template from a Form item\r\n *\r\n * @param {string} solutionItemId The solution item ID\r\n * @param {any} itemInfo: The base item info\r\n * @param {UserSession} destAuthentication Credentials for requests to the destination organization\r\n * @param {UserSession} srcAuthentication Credentials for requests to source items\r\n * @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements\r\n * @returns {Promise<IItemTemplate>}\r\n */\r\nexport function convertItemToTemplate(\r\n solutionItemId: string,\r\n itemInfo: any,\r\n destAuthentication: UserSession,\r\n srcAuthentication: UserSession,\r\n templateDictionary: any\r\n): Promise<IItemTemplate> {\r\n // Delegate to simple types\r\n return simpleTypes.convertItemToTemplate(\r\n solutionItemId,\r\n itemInfo,\r\n destAuthentication,\r\n srcAuthentication,\r\n templateDictionary\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport * as common from \"@esri/solution-common\";\r\n\r\n/**\r\n * Determines if the given template is a Hub Survey\r\n * template vs Solutions.js Survey template.\r\n *\r\n * @param {IITemTemplate} template A template\r\n * @returns {boolean}\r\n */\r\nexport function isHubFormTemplate(template: common.IItemTemplate): boolean {\r\n // relying on basic duck typing vs adding extraneous props during migration\r\n return !!common.getProp(template, \"properties.services\");\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n ISurvey123CreateParams,\r\n ISurvey123CreateResult\r\n} from \"@esri/solution-common\";\r\nimport { encodeFormData } from \"@esri/arcgis-rest-request\";\r\n\r\n/**\r\n * Provides utility method to call Survey123 create endpoint\r\n *\r\n * @module create-survey\r\n */\r\n\r\n/**\r\n * Calls the Survey123 create API with the given parameters\r\n *\r\n * @param {ISurvey123CreateParams} params\r\n * @param {string} [survey123Url=https://survey123.arcgis.com] An optional, Survey123 base URL override\r\n * @throws Will throw if the Survey123 API returns an error response\r\n * @returns {Promise<ISurvey123CreateResult>}\r\n */\r\nexport function createSurvey(\r\n params: ISurvey123CreateParams,\r\n survey123Url = \"https://survey123.arcgis.com\"\r\n): Promise<ISurvey123CreateResult> {\r\n const createUrl = `${survey123Url}/api/survey/create`;\r\n const ro = {\r\n credentials: \"same-origin\" as RequestCredentials,\r\n method: \"POST\",\r\n body: encodeFormData(\r\n {\r\n f: \"json\",\r\n ...params\r\n },\r\n true\r\n )\r\n };\r\n // Using @esri/arcgis-request \"request\" method was resulting in a 404 for\r\n // a CORS preflight request related to this request, but calling fetch directly\r\n // circumvents the issue.\r\n return fetch(createUrl, ro)\r\n .then(response => response.json())\r\n .then(response => {\r\n if (!response.success) {\r\n throw new Error(`Failed to create survey: ${response.error.message}`);\r\n }\r\n return {\r\n formId: response.id,\r\n featureServiceId: response.featureService.source.itemId,\r\n folderId: response.formItemInfo.ownerFolder\r\n };\r\n });\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport { cloneObject } from \"@esri/solution-common\";\r\n\r\n/**\r\n * Manages Survey123 parameter encoding\r\n *\r\n * @module encode-survey-form\r\n */\r\n\r\n/**\r\n * URI Encodes Survey123 form content parameter\r\n * values\r\n *\r\n * @param {any} form Unencoded form data\r\n * @returns {any} Encoded form data\r\n */\r\nexport const encodeSurveyForm = function encodeForm(form: any) {\r\n const clone = cloneObject(form);\r\n const props = [\r\n [\"header\", \"content\"],\r\n [\"subHeader\", \"content\"],\r\n [\"footer\", \"content\"],\r\n [\"settings\", \"thankYouScreenContent\"]\r\n ];\r\n const encode = (\r\n obj: { [key: string]: string },\r\n key: string\r\n ): { [key: string]: string } => {\r\n if (obj && obj[key]) {\r\n obj[key] = encodeURIComponent(obj[key]);\r\n }\r\n return obj;\r\n };\r\n\r\n // encode props from array above\r\n props.forEach(([objKey, propKey]) => encode(clone[objKey], propKey));\r\n\r\n const encodeQuestion = (question: any) => encode(question, \"description\");\r\n\r\n // encode question descriptions\r\n clone.questions = (clone.questions || []).map((question: any) =>\r\n !question.questions\r\n ? encodeQuestion(question)\r\n : {\r\n ...question,\r\n questions: question.questions.map(encodeQuestion)\r\n }\r\n );\r\n\r\n return clone;\r\n};\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n IItemTemplate,\r\n UserSession,\r\n getUniqueTitle,\r\n ISurvey123CreateParams,\r\n getPortalDefaultBasemap\r\n} from \"@esri/solution-common\";\r\nimport { encodeSurveyForm } from \"./encode-survey-form\";\r\n\r\n/**\r\n * Utility method for creating Survey123 parameters\r\n *\r\n * @module build-create-params\r\n */\r\n\r\n/**\r\n * Builds the Survey123 create API parameters\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination session info\r\n * @returns {Promise<ISurvey123CreateParams>}\r\n */\r\nexport function buildCreateParams(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession\r\n): Promise<ISurvey123CreateParams> {\r\n const {\r\n item: { title: originalTitle, description, tags, typeKeywords },\r\n properties: { form: unencodedForm }\r\n } = template;\r\n const {\r\n user: { username },\r\n portalBaseUrl: portalUrl,\r\n organization: {\r\n basemapGalleryGroupQuery,\r\n defaultBasemap: { title: basemapTitle }\r\n }\r\n } = templateDictionary;\r\n const { token } = destinationAuthentication.toCredential();\r\n return getPortalDefaultBasemap(\r\n basemapGalleryGroupQuery,\r\n basemapTitle,\r\n destinationAuthentication\r\n ).then(defaultBasemap => {\r\n // The S123 API appends \"Survey-\" to the survey title when computing\r\n // the folder name. We need to use the same prefix to successfully\r\n // calculate a unique folder name. Afterwards, we can safely remove the\r\n // prefix from the title\r\n const folderPrefix = \"Survey-\";\r\n const title = getUniqueTitle(\r\n `${folderPrefix}${originalTitle}`,\r\n templateDictionary,\r\n \"user.folders\"\r\n ).replace(folderPrefix, \"\");\r\n // set any map question's basemaps to default org basemap\r\n if (unencodedForm.questions) {\r\n const updateBasemap = (question: any) => {\r\n if (question.maps) {\r\n question.maps = question.maps.map((map: any) => ({\r\n ...map,\r\n itemId: defaultBasemap.id\r\n }));\r\n }\r\n return question;\r\n };\r\n unencodedForm.questions = unencodedForm.questions.map((question: any) =>\r\n !question.questions\r\n ? updateBasemap(question)\r\n : {\r\n ...question,\r\n questions: question.questions.map(updateBasemap)\r\n }\r\n );\r\n }\r\n const form = encodeSurveyForm(unencodedForm);\r\n // intentionally undefined, handled downstream by core logic now\r\n return {\r\n description,\r\n form,\r\n portalUrl,\r\n tags,\r\n title,\r\n token,\r\n typeKeywords,\r\n username\r\n };\r\n });\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n IItemTemplate,\r\n UserSession,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse,\r\n EItemProgressStatus,\r\n replaceInTemplate,\r\n updateItemExtended,\r\n ISurvey123CreateParams,\r\n ISurvey123CreateResult,\r\n getItemBase\r\n} from \"@esri/solution-common\";\r\nimport { createSurvey } from \"./create-survey\";\r\nimport { buildCreateParams } from \"./build-create-params\";\r\n\r\n/**\r\n * Manages the creation of Surveys from Hub Templates\r\n * via the Survey123 API\r\n *\r\n * @module create-item-from-hub-template\r\n */\r\n\r\n/**\r\n * Orchestrates creation of Surveys from Hub templates\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination session info\r\n * @param {Function} itemProgressCallback A progress callback\r\n * @returns {Promise<ICreateItemFromTemplateResponse>}\r\n */\r\nexport function createItemFromHubTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n const interpolatedTemplate = replaceInTemplate(template, templateDictionary);\r\n const { survey123Url } = templateDictionary;\r\n\r\n return buildCreateParams(\r\n interpolatedTemplate,\r\n templateDictionary,\r\n destinationAuthentication\r\n )\r\n .then((params: ISurvey123CreateParams) => {\r\n return createSurvey(params, survey123Url);\r\n })\r\n .then((createSurveyResponse: ISurvey123CreateResult) => {\r\n const { formId, featureServiceId } = createSurveyResponse;\r\n\r\n // Update the item with its thumbnail\r\n let thumbDef: Promise<any> = Promise.resolve(null);\r\n /* istanbul ignore else */\r\n if (template.item.thumbnail) {\r\n thumbDef = updateItemExtended(\r\n { id: formId },\r\n null,\r\n destinationAuthentication,\r\n template.item.thumbnail\r\n );\r\n }\r\n\r\n return thumbDef\r\n .then(() => getItemBase(formId, destinationAuthentication))\r\n .then(item => {\r\n templateDictionary[interpolatedTemplate.itemId] = {\r\n itemId: formId\r\n };\r\n templateDictionary[\r\n interpolatedTemplate.properties.info.serviceInfo.itemId\r\n ] = {\r\n itemId: featureServiceId\r\n };\r\n itemProgressCallback(\r\n interpolatedTemplate.itemId,\r\n EItemProgressStatus.Finished,\r\n interpolatedTemplate.estimatedDeploymentCostFactor,\r\n formId\r\n );\r\n return {\r\n item: {\r\n ...template,\r\n item,\r\n itemId: formId\r\n },\r\n id: formId,\r\n type: \"Form\",\r\n postProcess: true\r\n };\r\n });\r\n })\r\n .catch(e => {\r\n itemProgressCallback(\r\n interpolatedTemplate.itemId,\r\n EItemProgressStatus.Failed,\r\n 0\r\n );\r\n throw e;\r\n });\r\n}\r\n","/** @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 deployment items from Form templates.\r\n *\r\n * @module create-item-from-template\r\n */\r\n\r\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n IItemProgressCallback,\r\n ICreateItemFromTemplateResponse\r\n} from \"@esri/solution-common\";\r\nimport { simpleTypes } from \"@esri/solution-simple-types\";\r\nimport { isHubFormTemplate } from \"./helpers/is-hub-form-template\";\r\nimport { createItemFromHubTemplate } from \"./helpers/create-item-from-hub-template\";\r\n\r\n/**\r\n * Creates a Form item from a template\r\n *\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} destinationAuthentication The destination user session info\r\n * @param itemProgressCallback An item progress callback\r\n * @returns {Promise<ICreateItemFromTemplateResponse>}\r\n */\r\nexport function createItemFromTemplate(\r\n template: IItemTemplate,\r\n templateDictionary: any,\r\n destinationAuthentication: UserSession,\r\n itemProgressCallback: IItemProgressCallback\r\n): Promise<ICreateItemFromTemplateResponse> {\r\n // Hub Form template custom processing\r\n if (isHubFormTemplate(template)) {\r\n return createItemFromHubTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n }\r\n\r\n // otherwise delegate to simple types\r\n return simpleTypes.createItemFromTemplate(\r\n template,\r\n templateDictionary,\r\n destinationAuthentication,\r\n itemProgressCallback\r\n );\r\n}\r\n","/** @license\r\n * Copyright 2020 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\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n updateItem,\r\n replaceInTemplate,\r\n getItemBase,\r\n createInitializedItemTemplate,\r\n removeFolder,\r\n IItemUpdate\r\n} from \"@esri/solution-common\";\r\nimport { moveItem } from \"@esri/arcgis-rest-portal\";\r\n\r\n/**\r\n * Provides utility method to post process Hub surveys\r\n *\r\n * @module post-process-survey\r\n */\r\n\r\n/**\r\n * Performs Survey post processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template/item type\r\n * @param {any[]} itemInfos An Array of item details\r\n * @param {IItemTemplate} template The template\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns {Promise<any>}\r\n */\r\nexport function postProcessHubSurvey(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n const featureServiceSourceId = template.properties.info.serviceInfo.itemId;\r\n const { itemId: featureServiceResultId } = templateDictionary[\r\n featureServiceSourceId\r\n ];\r\n const interpolated = replaceInTemplate(template, templateDictionary);\r\n return getItemBase(featureServiceResultId, authentication).then(\r\n featureServiceResultBase => {\r\n const itemUpdates = [\r\n // fix/update form properties we couldn't control via the API\r\n {\r\n id: itemId,\r\n title: interpolated.item.title,\r\n snippet: interpolated.item.snippet,\r\n extent: interpolated.item.extent,\r\n culture: interpolated.item.culture\r\n },\r\n // fix/update feature service properties we couldn't control via the API\r\n {\r\n id: featureServiceResultId,\r\n extent: interpolated.item.extent,\r\n typeKeywords: [`source-${featureServiceSourceId}`].concat(\r\n featureServiceResultBase.typeKeywords\r\n )\r\n }\r\n ];\r\n const toUpdatePromise = (updatedItem: IItemUpdate) =>\r\n updateItem(updatedItem, authentication);\r\n const updatePromises = itemUpdates.map(toUpdatePromise);\r\n return Promise.all(updatePromises)\r\n .then(() => {\r\n const itemIdsToMove = [itemId, featureServiceResultId];\r\n const toMovePromise = (id: string) =>\r\n moveItem({\r\n itemId: id,\r\n folderId: templateDictionary.folderId as string,\r\n authentication: authentication\r\n });\r\n const movePromises = itemIdsToMove.map(toMovePromise);\r\n return Promise.all(movePromises);\r\n })\r\n .then(() =>\r\n removeFolder(featureServiceResultBase.ownerFolder, authentication)\r\n )\r\n .then(() => {\r\n // Create a template item for the Feature Service that was created by the API\r\n const featureServiceTemplate = createInitializedItemTemplate(\r\n featureServiceResultBase\r\n );\r\n templates.push(featureServiceTemplate);\r\n template.dependencies.push(featureServiceResultBase.id);\r\n return true;\r\n });\r\n }\r\n );\r\n}\r\n","/** @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 form item types.\r\n *\r\n * @module post-process\r\n */\r\n\r\nimport {\r\n UserSession,\r\n IItemTemplate,\r\n updateItemTemplateFromDictionary\r\n} from \"@esri/solution-common\";\r\nimport { isHubFormTemplate } from \"./helpers/is-hub-form-template\";\r\nimport { postProcessHubSurvey } from \"./helpers/post-process-survey\";\r\n\r\n/**\r\n * Form post-processing actions\r\n *\r\n * @param {string} itemId The item ID\r\n * @param {string} type The template type\r\n * @param {any[]} itemInfos Array of {id: 'ef3', type: 'Web Map'} objects\r\n * @param {any} templateDictionary The template dictionary\r\n * @param {UserSession} authentication The destination session info\r\n * @returns Promise resolving to successfulness of update\r\n */\r\nexport function postProcess(\r\n itemId: string,\r\n type: string,\r\n itemInfos: any[],\r\n template: IItemTemplate,\r\n templates: IItemTemplate[],\r\n templateDictionary: any,\r\n authentication: UserSession\r\n): Promise<any> {\r\n if (isHubFormTemplate(template)) {\r\n return postProcessHubSurvey(\r\n itemId,\r\n type,\r\n itemInfos,\r\n template,\r\n templates,\r\n templateDictionary,\r\n authentication\r\n );\r\n }\r\n\r\n return updateItemTemplateFromDictionary(\r\n itemId,\r\n templateDictionary,\r\n authentication\r\n );\r\n}\r\n"],"names":["simpleTypes","common","encodeFormData","cloneObject","getPortalDefaultBasemap","getUniqueTitle","replaceInTemplate","updateItemExtended","getItemBase","EItemProgressStatus","updateItem","moveItem","removeFolder","createInitializedItemTemplate","updateItemTemplateFromDictionary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;EAyBA;;;;;;;;;;WAUgB,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,kBAA+B,EAC/B,iBAA8B,EAC9B,kBAAuB;;MAGvB,OAAOA,+BAAW,CAAC,qBAAqB,CACtC,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;EACJ;;EClDA;;;;;;;;;;;;;;;EAkBA;;;;;;;WAOgB,iBAAiB,CAAC,QAA8B;;MAE9D,OAAO,CAAC,CAACC,iBAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;EAC3D;;EC5BA;;;;;;;;;;;;;;;EAsBA;;;;;EAMA;;;;;;;;WAQgB,YAAY,CAC1B,MAA8B,EAC9B,YAAY,GAAG,8BAA8B;MAE7C,MAAM,SAAS,GAAG,GAAG,YAAY,oBAAoB,CAAC;MACtD,MAAM,EAAE,GA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AO,oBAAoB,CACzB,MAAM,EACN,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,cAAc,CACf,CAAC;OACH;MAED,OAAOC,uCAAgC,CACrC,MAAM,EACN,kBAAkB,EAClB,cAAc,CACf,CAAC;EACJ;;;;;;;;;;;;"}
|
package/dist/umd/form.umd.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/solution-form - v1.
|
|
2
|
+
* @esri/solution-form - v1.2.0 - Apache-2.0
|
|
3
3
|
* Copyright (c) 2018-2021 Esri, Inc.
|
|
4
|
-
*
|
|
4
|
+
* Thu Dec 09 2021 16:04:59 GMT-0800 (Pacific Standard Time)
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/solution-simple-types"),require("@esri/solution-common"),require("@esri/arcgis-rest-request"),require("@esri/arcgis-rest-portal")):"function"==typeof define&&define.amd?define(["exports","@esri/solution-simple-types","@esri/solution-common","@esri/arcgis-rest-request","@esri/arcgis-rest-portal"],t):t((e=e||self).arcgisSolution=e.arcgisSolution||{},e.arcgisSolution,e.arcgisSolution,e.arcgisRest,e.arcgisRest)}(this,function(e,t,r,n
|
|
18
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/solution-simple-types"),require("@esri/solution-common"),require("@esri/arcgis-rest-request"),require("@esri/arcgis-rest-portal")):"function"==typeof define&&define.amd?define(["exports","@esri/solution-simple-types","@esri/solution-common","@esri/arcgis-rest-request","@esri/arcgis-rest-portal"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisSolution=e.arcgisSolution||{},e.arcgisSolution,e.arcgisSolution,e.arcgisRest,e.arcgisRest)}(this,(function(e,t,r,o,n){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=s(r);function u(e){return!!i.getProp(e,"properties.services")}function a(e,t,o){const{item:{title:n,description:s,tags:i,typeKeywords:u},properties:{form:a}}=e,{user:{username:c},portalBaseUrl:m,organization:{basemapGalleryGroupQuery:l,defaultBasemap:{title:p}}}=t,{token:d}=o.toCredential();return r.getPortalDefaultBasemap(l,p,o).then((e=>{const o="Survey-",l=r.getUniqueTitle(`Survey-${n}`,t,"user.folders").replace(o,"");if(a.questions){const t=t=>(t.maps&&(t.maps=t.maps.map((t=>({...t,itemId:e.id})))),t);a.questions=a.questions.map((e=>e.questions?{...e,questions:e.questions.map(t)}:t(e)))}const p=function(e){const t=r.cloneObject(e),o=(e,t)=>(e&&e[t]&&(e[t]=encodeURIComponent(e[t])),e);[["header","content"],["subHeader","content"],["footer","content"],["settings","thankYouScreenContent"]].forEach((([e,r])=>o(t[e],r)));const n=e=>o(e,"description");return t.questions=(t.questions||[]).map((e=>e.questions?{...e,questions:e.questions.map(n)}:n(e))),t}(a);return{description:s,form:p,portalUrl:m,tags:i,title:l,token:d,typeKeywords:u,username:c}}))}function c(e,t,n,s){const i=r.replaceInTemplate(e,t),{survey123Url:u}=t;return a(i,t,n).then((e=>function(e,t="https://survey123.arcgis.com"){const r=`${t}/api/survey/create`,n={credentials:"same-origin",method:"POST",body:o.encodeFormData({f:"json",...e},!0)};return fetch(r,n).then((e=>e.json())).then((e=>{if(!e.success)throw new Error(`Failed to create survey: ${e.error.message}`);return{formId:e.id,featureServiceId:e.featureService.source.itemId,folderId:e.formItemInfo.ownerFolder}}))}(e,u))).then((o=>{const{formId:u,featureServiceId:a}=o;let c=Promise.resolve(null);return e.item.thumbnail&&(c=r.updateItemExtended({id:u},null,n,e.item.thumbnail)),c.then((()=>r.getItemBase(u,n))).then((o=>(t[i.itemId]={itemId:u},t[i.properties.info.serviceInfo.itemId]={itemId:a},s(i.itemId,r.EItemProgressStatus.Finished,i.estimatedDeploymentCostFactor,u),{item:{...e,item:o,itemId:u},id:u,type:"Form",postProcess:!0})))})).catch((e=>{throw s(i.itemId,r.EItemProgressStatus.Failed,0),e}))}e.convertItemToTemplate=function(e,r,o,n,s){return t.simpleTypes.convertItemToTemplate(e,r,o,n,s)},e.createItemFromTemplate=function(e,r,o,n){return u(e)?c(e,r,o,n):t.simpleTypes.createItemFromTemplate(e,r,o,n)},e.postProcess=function(e,t,o,s,i,a,c){return u(s)?function(e,t,o,s,i,u,a){const c=s.properties.info.serviceInfo.itemId,{itemId:m}=u[c],l=r.replaceInTemplate(s,u);return r.getItemBase(m,a).then((t=>{const o=[{id:e,title:l.item.title,snippet:l.item.snippet,extent:l.item.extent,culture:l.item.culture},{id:m,extent:l.item.extent,typeKeywords:[`source-${c}`].concat(t.typeKeywords)}].map((e=>r.updateItem(e,a)));return Promise.all(o).then((()=>{const t=[e,m].map((e=>n.moveItem({itemId:e,folderId:u.folderId,authentication:a})));return Promise.all(t)})).then((()=>r.removeFolder(t.ownerFolder,a))).then((()=>{const e=r.createInitializedItemTemplate(t);return i.push(e),s.dependencies.push(t.id),!0}))}))}(e,0,0,s,i,a,c):r.updateItemTemplateFromDictionary(e,a,c)},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
19
19
|
//# sourceMappingURL=form.umd.min.js.map
|