@esri/solution-form 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +9 -9
  2. package/dist/node/convert-item-to-template.d.ts +0 -32
  3. package/dist/node/convert-item-to-template.js +0 -35
  4. package/dist/node/convert-item-to-template.js.map +0 -1
  5. package/dist/node/create-item-from-template.d.ts +0 -31
  6. package/dist/node/create-item-from-template.js +0 -40
  7. package/dist/node/create-item-from-template.js.map +0 -1
  8. package/dist/node/helpers/build-create-params.d.ts +0 -30
  9. package/dist/node/helpers/build-create-params.js +0 -78
  10. package/dist/node/helpers/build-create-params.js.map +0 -1
  11. package/dist/node/helpers/create-item-from-hub-template.d.ts +0 -32
  12. package/dist/node/helpers/create-item-from-hub-template.js +0 -80
  13. package/dist/node/helpers/create-item-from-hub-template.js.map +0 -1
  14. package/dist/node/helpers/create-survey.d.ts +0 -30
  15. package/dist/node/helpers/create-survey.js +0 -60
  16. package/dist/node/helpers/create-survey.js.map +0 -1
  17. package/dist/node/helpers/encode-survey-form.d.ts +0 -28
  18. package/dist/node/helpers/encode-survey-form.js +0 -59
  19. package/dist/node/helpers/encode-survey-form.js.map +0 -1
  20. package/dist/node/helpers/is-hub-form-template.d.ts +0 -24
  21. package/dist/node/helpers/is-hub-form-template.js +0 -33
  22. package/dist/node/helpers/is-hub-form-template.js.map +0 -1
  23. package/dist/node/helpers/post-process-survey.d.ts +0 -33
  24. package/dist/node/helpers/post-process-survey.js +0 -82
  25. package/dist/node/helpers/post-process-survey.js.map +0 -1
  26. package/dist/node/index.d.ts +0 -23
  27. package/dist/node/index.js +0 -27
  28. package/dist/node/index.js.map +0 -1
  29. package/dist/node/post-process.d.ts +0 -32
  30. package/dist/node/post-process.js +0 -44
  31. package/dist/node/post-process.js.map +0 -1
  32. package/dist/umd/form/src/convert-item-to-template.d.ts +0 -32
  33. package/dist/umd/form/src/create-item-from-template.d.ts +0 -31
  34. package/dist/umd/form/src/helpers/build-create-params.d.ts +0 -30
  35. package/dist/umd/form/src/helpers/create-item-from-hub-template.d.ts +0 -32
  36. package/dist/umd/form/src/helpers/create-survey.d.ts +0 -30
  37. package/dist/umd/form/src/helpers/encode-survey-form.d.ts +0 -28
  38. package/dist/umd/form/src/helpers/is-hub-form-template.d.ts +0 -24
  39. package/dist/umd/form/src/helpers/post-process-survey.d.ts +0 -33
  40. package/dist/umd/form/src/index.d.ts +0 -23
  41. package/dist/umd/form/src/post-process.d.ts +0 -32
  42. package/dist/umd/form.umd.js +0 -503
  43. package/dist/umd/form.umd.js.map +0 -1
  44. package/dist/umd/form.umd.min.js +0 -19
  45. package/dist/umd/form.umd.min.js.map +0 -1
@@ -1,503 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-form - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:22:45 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-simple-types'), require('@esri/solution-common'), require('@esri/arcgis-rest-request'), require('@esri/arcgis-rest-portal')) :
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 = 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);
43
-
44
- /** @license
45
- * Copyright 2018 Esri
46
- *
47
- * Licensed under the Apache License, Version 2.0 (the "License");
48
- * you may not use this file except in compliance with the License.
49
- * You may obtain a copy of the License at
50
- *
51
- * http://www.apache.org/licenses/LICENSE-2.0
52
- *
53
- * Unless required by applicable law or agreed to in writing, software
54
- * distributed under the License is distributed on an "AS IS" BASIS,
55
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
- * See the License for the specific language governing permissions and
57
- * limitations under the License.
58
- */
59
- /**
60
- * Creates a template from a Form item
61
- *
62
- * @param {string} solutionItemId The solution item ID
63
- * @param {any} itemInfo: The base item info
64
- * @param {UserSession} destAuthentication Credentials for requests to the destination organization
65
- * @param {UserSession} srcAuthentication Credentials for requests to source items
66
- * @param {any} templateDictionary Hash of facts: folder id, org URL, adlib replacements
67
- * @returns {Promise<IItemTemplate>}
68
- */
69
- function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
70
- // Delegate to simple types
71
- return solutionSimpleTypes.simpleTypes.convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary);
72
- }
73
-
74
- /** @license
75
- * Copyright 2020 Esri
76
- *
77
- * Licensed under the Apache License, Version 2.0 (the "License");
78
- * you may not use this file except in compliance with the License.
79
- * You may obtain a copy of the License at
80
- *
81
- * http://www.apache.org/licenses/LICENSE-2.0
82
- *
83
- * Unless required by applicable law or agreed to in writing, software
84
- * distributed under the License is distributed on an "AS IS" BASIS,
85
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86
- * See the License for the specific language governing permissions and
87
- * limitations under the License.
88
- */
89
- /**
90
- * Determines if the given template is a Hub Survey
91
- * template vs Solutions.js Survey template.
92
- *
93
- * @param {IITemTemplate} template A template
94
- * @returns {boolean}
95
- */
96
- function isHubFormTemplate(template) {
97
- // relying on basic duck typing vs adding extraneous props during migration
98
- return !!common__namespace.getProp(template, "properties.services");
99
- }
100
-
101
- /** @license
102
- * Copyright 2020 Esri
103
- *
104
- * Licensed under the Apache License, Version 2.0 (the "License");
105
- * you may not use this file except in compliance with the License.
106
- * You may obtain a copy of the License at
107
- *
108
- * http://www.apache.org/licenses/LICENSE-2.0
109
- *
110
- * Unless required by applicable law or agreed to in writing, software
111
- * distributed under the License is distributed on an "AS IS" BASIS,
112
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113
- * See the License for the specific language governing permissions and
114
- * limitations under the License.
115
- */
116
- /**
117
- * Provides utility method to call Survey123 create endpoint
118
- *
119
- * @module create-survey
120
- */
121
- /**
122
- * Calls the Survey123 create API with the given parameters
123
- *
124
- * @param {ISurvey123CreateParams} params
125
- * @param {string} [survey123Url=https://survey123.arcgis.com] An optional, Survey123 base URL override
126
- * @throws Will throw if the Survey123 API returns an error response
127
- * @returns {Promise<ISurvey123CreateResult>}
128
- */
129
- function createSurvey(params, survey123Url = "https://survey123.arcgis.com") {
130
- const createUrl = `${survey123Url}/api/survey/create`;
131
- const ro = {
132
- credentials: "same-origin",
133
- method: "POST",
134
- body: arcgisRestRequest.encodeFormData({
135
- f: "json",
136
- ...params
137
- }, true)
138
- };
139
- // Using @esri/arcgis-request "request" method was resulting in a 404 for
140
- // a CORS preflight request related to this request, but calling fetch directly
141
- // circumvents the issue.
142
- return fetch(createUrl, ro)
143
- .then(response => response.json())
144
- .then(response => {
145
- if (!response.success) {
146
- throw new Error(`Failed to create survey: ${response.error.message}`);
147
- }
148
- return {
149
- formId: response.id,
150
- featureServiceId: response.featureService.source.itemId,
151
- folderId: response.formItemInfo.ownerFolder
152
- };
153
- });
154
- }
155
-
156
- /** @license
157
- * Copyright 2020 Esri
158
- *
159
- * Licensed under the Apache License, Version 2.0 (the "License");
160
- * you may not use this file except in compliance with the License.
161
- * You may obtain a copy of the License at
162
- *
163
- * http://www.apache.org/licenses/LICENSE-2.0
164
- *
165
- * Unless required by applicable law or agreed to in writing, software
166
- * distributed under the License is distributed on an "AS IS" BASIS,
167
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
168
- * See the License for the specific language governing permissions and
169
- * limitations under the License.
170
- */
171
- /**
172
- * Manages Survey123 parameter encoding
173
- *
174
- * @module encode-survey-form
175
- */
176
- /**
177
- * URI Encodes Survey123 form content parameter
178
- * values
179
- *
180
- * @param {any} form Unencoded form data
181
- * @returns {any} Encoded form data
182
- */
183
- const encodeSurveyForm = function encodeForm(form) {
184
- const clone = common.cloneObject(form);
185
- const props = [
186
- ["header", "content"],
187
- ["subHeader", "content"],
188
- ["footer", "content"],
189
- ["settings", "thankYouScreenContent"]
190
- ];
191
- const encode = (obj, key) => {
192
- if (obj && obj[key]) {
193
- obj[key] = encodeURIComponent(obj[key]);
194
- }
195
- return obj;
196
- };
197
- // encode props from array above
198
- props.forEach(([objKey, propKey]) => encode(clone[objKey], propKey));
199
- const encodeQuestion = (question) => encode(question, "description");
200
- // encode question descriptions
201
- clone.questions = (clone.questions || []).map((question) => !question.questions
202
- ? encodeQuestion(question)
203
- : {
204
- ...question,
205
- questions: question.questions.map(encodeQuestion)
206
- });
207
- return clone;
208
- };
209
-
210
- /** @license
211
- * Copyright 2020 Esri
212
- *
213
- * Licensed under the Apache License, Version 2.0 (the "License");
214
- * you may not use this file except in compliance with the License.
215
- * You may obtain a copy of the License at
216
- *
217
- * http://www.apache.org/licenses/LICENSE-2.0
218
- *
219
- * Unless required by applicable law or agreed to in writing, software
220
- * distributed under the License is distributed on an "AS IS" BASIS,
221
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
222
- * See the License for the specific language governing permissions and
223
- * limitations under the License.
224
- */
225
- /**
226
- * Utility method for creating Survey123 parameters
227
- *
228
- * @module build-create-params
229
- */
230
- /**
231
- * Builds the Survey123 create API parameters
232
- *
233
- * @param {IItemTemplate} template The template
234
- * @param {any} templateDictionary The template dictionary
235
- * @param {UserSession} destinationAuthentication The destination session info
236
- * @returns {Promise<ISurvey123CreateParams>}
237
- */
238
- function buildCreateParams(template, templateDictionary, destinationAuthentication) {
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 => {
243
- // The S123 API appends "Survey-" to the survey title when computing
244
- // the folder name. We need to use the same prefix to successfully
245
- // calculate a unique folder name. Afterwards, we can safely remove the
246
- // prefix from the title
247
- const folderPrefix = "Survey-";
248
- const title = common.getUniqueTitle(`${folderPrefix}${originalTitle}`, templateDictionary, "user.folders").replace(folderPrefix, "");
249
- // set any map question's basemaps to default org basemap
250
- if (unencodedForm.questions) {
251
- const updateBasemap = (question) => {
252
- if (question.maps) {
253
- question.maps = question.maps.map((map) => ({
254
- ...map,
255
- itemId: defaultBasemap.id
256
- }));
257
- }
258
- return question;
259
- };
260
- unencodedForm.questions = unencodedForm.questions.map((question) => !question.questions
261
- ? updateBasemap(question)
262
- : {
263
- ...question,
264
- questions: question.questions.map(updateBasemap)
265
- });
266
- }
267
- const form = encodeSurveyForm(unencodedForm);
268
- // intentionally undefined, handled downstream by core logic now
269
- return {
270
- description,
271
- form,
272
- portalUrl,
273
- tags,
274
- title,
275
- token,
276
- typeKeywords,
277
- username
278
- };
279
- });
280
- }
281
-
282
- /** @license
283
- * Copyright 2020 Esri
284
- *
285
- * Licensed under the Apache License, Version 2.0 (the "License");
286
- * you may not use this file except in compliance with the License.
287
- * You may obtain a copy of the License at
288
- *
289
- * http://www.apache.org/licenses/LICENSE-2.0
290
- *
291
- * Unless required by applicable law or agreed to in writing, software
292
- * distributed under the License is distributed on an "AS IS" BASIS,
293
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
294
- * See the License for the specific language governing permissions and
295
- * limitations under the License.
296
- */
297
- /**
298
- * Manages the creation of Surveys from Hub Templates
299
- * via the Survey123 API
300
- *
301
- * @module create-item-from-hub-template
302
- */
303
- /**
304
- * Orchestrates creation of Surveys from Hub templates
305
- *
306
- * @param {IItemTemplate} template The template
307
- * @param {any} templateDictionary The template dictionary
308
- * @param {UserSession} destinationAuthentication The destination session info
309
- * @param {Function} itemProgressCallback A progress callback
310
- * @returns {Promise<ICreateItemFromTemplateResponse>}
311
- */
312
- function createItemFromHubTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
313
- const interpolatedTemplate = common.replaceInTemplate(template, templateDictionary);
314
- const { survey123Url } = templateDictionary;
315
- return buildCreateParams(interpolatedTemplate, templateDictionary, destinationAuthentication)
316
- .then((params) => {
317
- return createSurvey(params, survey123Url);
318
- })
319
- .then((createSurveyResponse) => {
320
- const { formId, featureServiceId } = createSurveyResponse;
321
- // Update the item with its thumbnail
322
- let thumbDef = Promise.resolve(null);
323
- /* istanbul ignore else */
324
- if (template.item.thumbnail) {
325
- thumbDef = common.updateItemExtended({ id: formId }, null, destinationAuthentication, template.item.thumbnail);
326
- }
327
- return thumbDef
328
- .then(() => common.getItemBase(formId, destinationAuthentication))
329
- .then(item => {
330
- templateDictionary[interpolatedTemplate.itemId] = {
331
- itemId: formId
332
- };
333
- templateDictionary[interpolatedTemplate.properties.info.serviceInfo.itemId] = {
334
- itemId: featureServiceId
335
- };
336
- itemProgressCallback(interpolatedTemplate.itemId, common.EItemProgressStatus.Finished, interpolatedTemplate.estimatedDeploymentCostFactor, formId);
337
- return {
338
- item: {
339
- ...template,
340
- item,
341
- itemId: formId
342
- },
343
- id: formId,
344
- type: "Form",
345
- postProcess: true
346
- };
347
- });
348
- })
349
- .catch(e => {
350
- itemProgressCallback(interpolatedTemplate.itemId, common.EItemProgressStatus.Failed, 0);
351
- throw e;
352
- });
353
- }
354
-
355
- /** @license
356
- * Copyright 2018 Esri
357
- *
358
- * Licensed under the Apache License, Version 2.0 (the "License");
359
- * you may not use this file except in compliance with the License.
360
- * You may obtain a copy of the License at
361
- *
362
- * http://www.apache.org/licenses/LICENSE-2.0
363
- *
364
- * Unless required by applicable law or agreed to in writing, software
365
- * distributed under the License is distributed on an "AS IS" BASIS,
366
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
367
- * See the License for the specific language governing permissions and
368
- * limitations under the License.
369
- */
370
- /**
371
- * Creates a Form item from a template
372
- *
373
- * @param {IItemTemplate} template The template
374
- * @param {any} templateDictionary The template dictionary
375
- * @param {UserSession} destinationAuthentication The destination user session info
376
- * @param itemProgressCallback An item progress callback
377
- * @returns {Promise<ICreateItemFromTemplateResponse>}
378
- */
379
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
380
- // Hub Form template custom processing
381
- if (isHubFormTemplate(template)) {
382
- return createItemFromHubTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
383
- }
384
- // otherwise delegate to simple types
385
- return solutionSimpleTypes.simpleTypes.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
386
- }
387
-
388
- /** @license
389
- * Copyright 2020 Esri
390
- *
391
- * Licensed under the Apache License, Version 2.0 (the "License");
392
- * you may not use this file except in compliance with the License.
393
- * You may obtain a copy of the License at
394
- *
395
- * http://www.apache.org/licenses/LICENSE-2.0
396
- *
397
- * Unless required by applicable law or agreed to in writing, software
398
- * distributed under the License is distributed on an "AS IS" BASIS,
399
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
400
- * See the License for the specific language governing permissions and
401
- * limitations under the License.
402
- */
403
- /**
404
- * Provides utility method to post process Hub surveys
405
- *
406
- * @module post-process-survey
407
- */
408
- /**
409
- * Performs Survey post processing actions
410
- *
411
- * @param {string} itemId The item ID
412
- * @param {string} type The template/item type
413
- * @param {any[]} itemInfos An Array of item details
414
- * @param {IItemTemplate} template The template
415
- * @param {any} templateDictionary The template dictionary
416
- * @param {UserSession} authentication The destination session info
417
- * @returns {Promise<any>}
418
- */
419
- function postProcessHubSurvey(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
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 = [
425
- // fix/update form properties we couldn't control via the API
426
- {
427
- id: itemId,
428
- title: interpolated.item.title,
429
- snippet: interpolated.item.snippet,
430
- extent: interpolated.item.extent,
431
- culture: interpolated.item.culture
432
- },
433
- // fix/update feature service properties we couldn't control via the API
434
- {
435
- id: featureServiceResultId,
436
- extent: interpolated.item.extent,
437
- typeKeywords: [`source-${featureServiceSourceId}`].concat(featureServiceResultBase.typeKeywords)
438
- }
439
- ];
440
- const toUpdatePromise = (updatedItem) => common.updateItem(updatedItem, authentication);
441
- const updatePromises = itemUpdates.map(toUpdatePromise);
442
- return Promise.all(updatePromises)
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);
451
- return Promise.all(movePromises);
452
- })
453
- .then(() => common.removeFolder(featureServiceResultBase.ownerFolder, authentication))
454
- .then(() => {
455
- // Create a template item for the Feature Service that was created by the API
456
- const featureServiceTemplate = common.createInitializedItemTemplate(featureServiceResultBase);
457
- templates.push(featureServiceTemplate);
458
- template.dependencies.push(featureServiceResultBase.id);
459
- return true;
460
- });
461
- });
462
- }
463
-
464
- /** @license
465
- * Copyright 2018 Esri
466
- *
467
- * Licensed under the Apache License, Version 2.0 (the "License");
468
- * you may not use this file except in compliance with the License.
469
- * You may obtain a copy of the License at
470
- *
471
- * http://www.apache.org/licenses/LICENSE-2.0
472
- *
473
- * Unless required by applicable law or agreed to in writing, software
474
- * distributed under the License is distributed on an "AS IS" BASIS,
475
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
476
- * See the License for the specific language governing permissions and
477
- * limitations under the License.
478
- */
479
- /**
480
- * Form post-processing actions
481
- *
482
- * @param {string} itemId The item ID
483
- * @param {string} type The template type
484
- * @param {any[]} itemInfos Array of \{id: 'ef3', type: 'Web Map'\} objects
485
- * @param {any} templateDictionary The template dictionary
486
- * @param {UserSession} authentication The destination session info
487
- * @returns Promise resolving to successfulness of update
488
- */
489
- function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
490
- if (isHubFormTemplate(template)) {
491
- return postProcessHubSurvey(itemId, type, itemInfos, template, templates, templateDictionary, authentication);
492
- }
493
- return common.updateItemTemplateFromDictionary(itemId, templateDictionary, authentication);
494
- }
495
-
496
- exports.convertItemToTemplate = convertItemToTemplate;
497
- exports.createItemFromTemplate = createItemFromTemplate;
498
- exports.postProcess = postProcess;
499
-
500
- Object.defineProperty(exports, '__esModule', { value: true });
501
-
502
- }));
503
- //# sourceMappingURL=form.umd.js.map
@@ -1 +0,0 @@
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;;;;;;;;;;;;;;EAcG;EAWH;;;;;;;;;EASG;EACG,SAAU,qBAAqB,CACnC,cAAsB,EACtB,QAAa,EACb,kBAA+B,EAC/B,iBAA8B,EAC9B,kBAAuB,EAAA;;EAGvB,IAAA,OAAOA,+BAAW,CAAC,qBAAqB,CACtC,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;EACJ;;EClDA;;;;;;;;;;;;;;EAcG;EAIH;;;;;;EAMG;EACG,SAAU,iBAAiB,CAAC,QAA8B,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Ac,CACf,CAAC;EACH,KAAA;MAED,OAAOC,uCAAgC,CACrC,MAAM,EACN,kBAAkB,EAClB,cAAc,CACf,CAAC;EACJ;;;;;;;;;;;;"}
@@ -1,19 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-form - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:22:50 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/solution-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(`${o}${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
- //# sourceMappingURL=form.umd.min.js.map