@esri/solution-velocity 3.0.1 → 4.0.0-alpha.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.
@@ -1,922 +0,0 @@
1
- /* @preserve
2
- * @esri/solution-velocity - v1.7.0 - Apache-2.0
3
- * Copyright (c) 2018-2023 Esri, Inc.
4
- * Fri Apr 28 2023 11:23:03 GMT-0700 (Pacific Daylight Time)
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common'), require('@esri/arcgis-rest-portal')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common', '@esri/arcgis-rest-portal'], factory) :
21
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution, global.arcgisRest));
22
- })(this, (function (exports, solutionCommon, arcgisRestPortal) { 'use strict';
23
-
24
- /** @license
25
- * Copyright 2021 Esri
26
- *
27
- * Licensed under the Apache License, Version 2.0 (the "License");
28
- * you may not use this file except in compliance with the License.
29
- * You may obtain a copy of the License at
30
- *
31
- * http://www.apache.org/licenses/LICENSE-2.0
32
- *
33
- * Unless required by applicable law or agreed to in writing, software
34
- * distributed under the License is distributed on an "AS IS" BASIS,
35
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
- * See the License for the specific language governing permissions and
37
- * limitations under the License.
38
- */
39
- /**
40
- * Updates the template by adding variables for key properties that will
41
- * need to be swapped when deploying
42
- *
43
- * @param template velocity item info that should be templatized
44
- *
45
- * @returns void
46
- *
47
- */
48
- function templatizeVelocity(template) {
49
- _templatize(template, "data.sources", _templatizeDatasources);
50
- _templatize(template, "data.feeds", _templatizeFeeds);
51
- _templatize(template, "data.feed", _templatizeFeed);
52
- }
53
- /**
54
- * Generic wrapper for the templatize functions that
55
- * will get and set the key properties
56
- *
57
- * @param template velocity item info that should be templatized
58
- * @param prop the prop path to evaluate and set with a templatized variable
59
- * @param fn the templatize function that should be called for this prop
60
- *
61
- * @returns void
62
- *
63
- * @private
64
- */
65
- function _templatize(template, prop, fn) {
66
- const obj = solutionCommon.getProp(template, prop);
67
- /* istanbul ignore else */
68
- if (obj) {
69
- solutionCommon.setProp(template, prop, fn(obj));
70
- }
71
- }
72
- /**
73
- * Updates the template by adding variables for the itemId and the label
74
- * The label controls the name and must be unique for the org.
75
- *
76
- * @param feeds array of velocity feeds that should be templatized
77
- *
78
- * @returns The updated list of feed objects with templatized id and label
79
- *
80
- * @private
81
- */
82
- function _templatizeFeeds(feeds) {
83
- return feeds.map((feed) => {
84
- feed.label = feed.label && feed.id ? `{{${feed.id}.label}}` : feed.label;
85
- feed.id = feed.id ? `{{${feed.id}.itemId}}` : feed.id;
86
- return feed;
87
- });
88
- }
89
- /**
90
- * Updates the portal item id and feature layer id variables for the feed properties.
91
- *
92
- * @param feed the feed object from the item
93
- *
94
- * @returns the updated feed object with templatized portalItemId and layer id
95
- *
96
- * @private
97
- */
98
- function _templatizeFeed(feed) {
99
- let id = solutionCommon.getProp(feed, "properties.feature-layer.portalItemId");
100
- /* istanbul ignore else */
101
- if (feed.properties) {
102
- /* istanbul ignore else */
103
- if (feed.properties["feature-layer.portalItemId"]) {
104
- id = feed.properties["feature-layer.portalItemId"];
105
- feed.properties["feature-layer.portalItemId"] = `{{${id}.itemId}}`;
106
- }
107
- /* istanbul ignore else */
108
- if (id && feed.properties.hasOwnProperty("feature-layer.layerId")) {
109
- const flId = feed.properties["feature-layer.layerId"];
110
- feed.properties["feature-layer.layerId"] = `{{${id}.layer${flId}.layerId}}`;
111
- }
112
- }
113
- return feed;
114
- }
115
- /**
116
- * Velocity datasources share the same props as feeds so they can leverage
117
- * the same templatize function
118
- *
119
- * @param dataSources array of data sources from the item
120
- *
121
- * @returns the updated dataSources object with templatized ids and labels
122
- *
123
- * @private
124
- */
125
- function _templatizeDatasources(dataSources) {
126
- return dataSources.map((ds) => _templatizeFeed(ds));
127
- }
128
-
129
- /** @license
130
- * Copyright 2021 Esri
131
- *
132
- * Licensed under the Apache License, Version 2.0 (the "License");
133
- * you may not use this file except in compliance with the License.
134
- * You may obtain a copy of the License at
135
- *
136
- * http://www.apache.org/licenses/LICENSE-2.0
137
- *
138
- * Unless required by applicable law or agreed to in writing, software
139
- * distributed under the License is distributed on an "AS IS" BASIS,
140
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
- * See the License for the specific language governing permissions and
142
- * limitations under the License.
143
- */
144
- /**
145
- * Get the dependencies from the velocity data sources, feeds, and outputs.
146
- * Only dependencies that do NOT have the typeKeyword "IoTFeatureLayer" are returned.
147
- *
148
- * @param template The template that for the velocity item
149
- * @param authentication The credentials for any requests
150
- *
151
- * @returns a list of dependency ids
152
- */
153
- function getVelocityDependencies(template, authentication) {
154
- const dependencies = [];
155
- [
156
- solutionCommon.getProp(template, "data.feeds") ? template.data.feeds : [],
157
- solutionCommon.getProp(template, "data.feed") ? [template.data.feed] : []
158
- ].forEach(f => _getFeedDependencies(f, dependencies));
159
- [
160
- solutionCommon.getProp(template, "data.sources") ? template.data.sources : [],
161
- solutionCommon.getProp(template, "data.source") ? [template.data.source] : [],
162
- solutionCommon.getProp(template, "data.outputs") ? template.data.outputs : [],
163
- solutionCommon.getProp(template, "data.output") ? [template.data.output] : []
164
- ].forEach(d => _getDependencies(d, dependencies));
165
- return _validateDependencies(dependencies, authentication);
166
- }
167
- /**
168
- * Any feature services with the typeKeyword "IoTFeatureLayer" should not be templatized or
169
- * listed as a dependency.
170
- * We can’t create Velocity feature layers in their spatiotemporal datastore as we have no api.
171
- *
172
- * @param dependencies Any dependencies that have been found for this item
173
- * @param authentication The credentials for any requests
174
- *
175
- * @returns a list of dependency ids
176
- * @private
177
- */
178
- function _validateDependencies(dependencies, authentication) {
179
- const defs = dependencies.map(d => {
180
- return solutionCommon.getItemBase(d, authentication);
181
- });
182
- return Promise.all(defs).then(itemInfos => {
183
- return Promise.resolve(itemInfos.reduce((prev, cur) => {
184
- if (cur.typeKeywords.indexOf("IoTFeatureLayer") < 0) {
185
- prev.push(cur.id);
186
- }
187
- return prev;
188
- }, []));
189
- });
190
- }
191
- /**
192
- * Get the dependencies from the velocity feeds
193
- * This function will update the input dependencies argument
194
- *
195
- * @param feeds The list of feeds from the velocity template
196
- * @param dependencies The current list of dependencies
197
- * @private
198
- */
199
- function _getFeedDependencies(feeds, dependencies) {
200
- feeds.reduce((prev, cur) => {
201
- const id = cur.id || undefined;
202
- /* istanbul ignore else */
203
- if (id && prev.indexOf(id) < 0) {
204
- prev.push(id);
205
- }
206
- return prev;
207
- }, dependencies);
208
- // run through standard dependency check as well
209
- // in some cases the feed does not have the id property but will have
210
- // a portalItemId value in the properties
211
- _getDependencies(feeds, dependencies);
212
- }
213
- /**
214
- * Get the dependencies from the velocity outputs or dataSources.
215
- * This function will update the input dependencies argument
216
- *
217
- * @param outputs The list of outputs from the velocity item
218
- * @param dependencies The current list of dependencies
219
- * @param prop The individual prop to evaluate
220
- * @private
221
- */
222
- function _getDependencies(outputs, dependencies) {
223
- outputs.reduce((prev, cur) => {
224
- const names = solutionCommon.getProp(cur, "name") ? [cur.name] : solutionCommon.BASE_NAMES;
225
- names.forEach(n => {
226
- solutionCommon.PROP_NAMES.forEach(p => {
227
- // skip map service and stream service ids
228
- /* istanbul ignore else */
229
- if (p.indexOf("mapServicePortalItemID") < 0 && p.indexOf("streamServicePortalItemID") < 0) {
230
- const id = cur.properties ? cur.properties[n + p] : undefined;
231
- if (id && prev.indexOf(id) < 0) {
232
- prev.push(id);
233
- }
234
- }
235
- });
236
- });
237
- return prev;
238
- }, dependencies);
239
- }
240
-
241
- /** @license
242
- * Copyright 2021 Esri
243
- *
244
- * Licensed under the Apache License, Version 2.0 (the "License");
245
- * you may not use this file except in compliance with the License.
246
- * You may obtain a copy of the License at
247
- *
248
- * http://www.apache.org/licenses/LICENSE-2.0
249
- *
250
- * Unless required by applicable law or agreed to in writing, software
251
- * distributed under the License is distributed on an "AS IS" BASIS,
252
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
253
- * See the License for the specific language governing permissions and
254
- * limitations under the License.
255
- */
256
- /**
257
- * Common function to build urls for reading and interacting with the velocity api
258
- *
259
- *
260
- * @param authentication Credentials for the requests
261
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
262
- * @param type The type of velocity item we are constructing a url for
263
- * @param id Optional The id of the velocity item we are constructing a url for
264
- * @param isDeploy Optional Is this being constructed as a part of deployment
265
- * @param urlPrefix Optional prefix args necessary for some url construction
266
- * @param urlSuffix Optional suffix args necessary for some url construction
267
- *
268
- * @returns a promise that will resolve the constructed url
269
- *
270
- */
271
- function getVelocityUrl(authentication, templateDictionary, type, id = "", isDeploy = false, urlPrefix = "", urlSuffix = "") {
272
- return solutionCommon.getVelocityUrlBase(authentication, templateDictionary).then(url => {
273
- if (url) {
274
- const _type = type === "Real Time Analytic"
275
- ? "analytics/realtime"
276
- : type === "Big Data Analytic"
277
- ? "analytics/bigdata"
278
- : type.toLowerCase();
279
- const suffix = urlSuffix ? `/${urlSuffix}` : "";
280
- const prefix = urlPrefix ? `/${urlPrefix}` : "";
281
- return Promise.resolve(isDeploy
282
- ? `${url}/iot/${_type}${prefix}${suffix}`
283
- : id
284
- ? `${url}/iot/${_type}${prefix}/${id}${suffix}/?f=json&token=${authentication.token}`
285
- : `${url}/iot/${_type}${prefix}${suffix}/?f=json&token=${authentication.token}`);
286
- }
287
- else {
288
- return Promise.resolve(url);
289
- }
290
- });
291
- }
292
- /**
293
- * Handles the creation of velocity items.
294
- *
295
- * @param authentication Credentials for the requests
296
- * @param template The current itemTemplate that is being used for deployment
297
- * @param data The velocity item data used to create the items.
298
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
299
- * @param autoStart This can be leveraged to start certain velocity items after they are created.
300
- *
301
- * @returns a promise that will resolve an object containing the item, id, type, and post process flag
302
- *
303
- */
304
- function postVelocityData(authentication, template, data, templateDictionary, autoStart = false) {
305
- return getVelocityUrl(authentication, templateDictionary, template.type, undefined, true).then(url => {
306
- if (url) {
307
- return getTitle(authentication, data.label, url).then((titleInfo) => {
308
- const titles = titleInfo.titles;
309
- data.label = titleInfo.label;
310
- data.id = "";
311
- const body = solutionCommon.replaceInTemplate(data, templateDictionary);
312
- const dataOutputs = (data.outputs ? data.outputs : data.output ? [data.output] : []).map((o) => {
313
- return {
314
- id: o.id,
315
- name: o.properties[`${o.name}.name`]
316
- };
317
- });
318
- const feeds = (body.feeds ? body.feeds : body.feed ? [body.feed] : []).map((o) => {
319
- return {
320
- id: o.id ? o.id : o.properties[`${o.name}.portalItemId`] || "",
321
- name: o.label ? o.label : data.label
322
- };
323
- });
324
- return _validateOutputs(authentication, templateDictionary, template.type, body, titles, dataOutputs, feeds).then(updatedBody => {
325
- return _fetch(authentication, url, "POST", updatedBody).then(rr => {
326
- template.item.url = `${url}/${rr.id}`;
327
- template.item.title = data.label;
328
- // Update the template dictionary
329
- templateDictionary[template.itemId]["url"] = template.item.url;
330
- templateDictionary[template.itemId]["label"] = data.label;
331
- templateDictionary[template.itemId]["itemId"] = rr.id;
332
- const finalResult = {
333
- item: solutionCommon.replaceInTemplate(template.item, templateDictionary),
334
- id: rr.id,
335
- type: template.type,
336
- postProcess: false
337
- };
338
- if (autoStart) {
339
- return _validateAndStart(authentication, templateDictionary, template, rr.id).then(() => {
340
- return Promise.resolve(finalResult);
341
- });
342
- }
343
- else {
344
- return Promise.resolve(finalResult);
345
- }
346
- });
347
- });
348
- });
349
- }
350
- else {
351
- return Promise.reject(solutionCommon.fail("Velocity NOT Supported by Organization"));
352
- }
353
- });
354
- }
355
- /**
356
- * Velocity item titles must be unique across the organization.
357
- * Check and ensure we set a unique title
358
- *
359
- * @param authentication Credentials for the requests
360
- * @param label The current label of the item from the solution template
361
- * @param url The base velocity url for checking status
362
- *
363
- * @returns a promise that will resolve a unique title
364
- *
365
- */
366
- function getTitle(authentication, label, url) {
367
- return _fetch(authentication, `${url}StatusList?view=admin`, "GET").then(items => {
368
- const titles = items && Array.isArray(items)
369
- ? items.map(item => {
370
- return { title: item.label };
371
- })
372
- : [];
373
- return Promise.resolve({ label: getUniqueTitle(label, { titles }, "titles"), titles: titles.map(t => t.title) });
374
- });
375
- }
376
- /**
377
- * Validate the data that will be used and handle any reported issues with the outputs.
378
- * The output names must be unique across the organization.
379
- *
380
- * This function will update the data arg that is passed in with a unique name.
381
- *
382
- * @param authentication Credentials for the requests
383
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
384
- * @param type The type of velocity item
385
- * @param data The data used to construct the velocity item
386
- * @param titles The list of know titles that exist in the org
387
- * @param dataOutputs The velocity items output objects
388
- * @param feeds The velocity items feed objects
389
- *
390
- * @returns a promise that will resolve the data object passed in with any necessary changes.
391
- *
392
- * @private
393
- */
394
- function _validateOutputs(authentication, templateDictionary, type, data, titles, dataOutputs = [], feeds = []) {
395
- if (dataOutputs.length > 0 || feeds.length > 0) {
396
- return validate(authentication, templateDictionary, type, "", data).then((validateResults) => {
397
- const names = _validateMessages(validateResults);
398
- if (names.length > 0) {
399
- /* istanbul ignore else */
400
- if (dataOutputs.length > 0) {
401
- _updateDataOutput(dataOutputs, data, names);
402
- }
403
- /* istanbul ignore else */
404
- if (feeds.length > 0) {
405
- _updateFeed(feeds, data, names.concat(titles));
406
- }
407
- return _validateOutputs(authentication, templateDictionary, type, data, titles, dataOutputs, feeds);
408
- }
409
- else {
410
- return Promise.resolve(data);
411
- }
412
- });
413
- }
414
- else {
415
- return Promise.resolve(data);
416
- }
417
- }
418
- /**
419
- * Check the validate results for any name conflicts and store the conflicting names.
420
- *
421
- * @param validateResults The results object to check for name conflict errors
422
- *
423
- * @returns a list of names that already exist in the org
424
- *
425
- * @private
426
- */
427
- function _validateMessages(validateResults) {
428
- let messages = solutionCommon.getProp(validateResults, "validation.messages");
429
- const nodes = solutionCommon.getProp(validateResults, "nodes");
430
- /* istanbul ignore else */
431
- if (nodes && Array.isArray(nodes)) {
432
- nodes.forEach(node => {
433
- messages = messages.concat(solutionCommon.getProp(node, "validation.messages") || []);
434
- });
435
- }
436
- let names = [];
437
- /* istanbul ignore else */
438
- if (messages && Array.isArray(messages)) {
439
- messages.forEach(message => {
440
- // I don't see a way to ask for all output names that exist
441
- // velocityUrl + /outputs/ just gives you generic defaults not what currently exists
442
- const nameErrors = [
443
- "VALIDATION_ANALYTICS__MULTIPLE_CREATE_FEATURE_LAYER_OUTPUTS_REFERENCE_SAME_LAYER_NAME",
444
- "VALIDATION_ANALYTICS__MULTIPLE_CREATE_STREAM_LAYER_OUTPUTS_REFERENCE_SAME_LAYER_NAME",
445
- "ITEM_MANAGER__CREATE_ANALYTIC_FAILED_DUPLICATE_OUTPUT_NAMES_IN_ORGANIZATION_NOT_ALLOWED",
446
- "ITEM_MANAGER__CREATE_BIG_DATA_ANALYTIC_FAILED_DUPLICATE_NAMES_NOT_ALLOWED",
447
- "ITEM_MANAGER__CREATE_REAL_TIME_ANALYTIC_FAILED_DUPLICATE_NAMES_NOT_ALLOWED",
448
- "ITEM_MANAGER__CREATE_FEED_FAILED_DUPLICATE_NAME"
449
- ];
450
- // The names returned here seem to replace " " with "_" so they do not match exactly
451
- /* istanbul ignore else */
452
- if (nameErrors.indexOf(message.key) > -1) {
453
- names = names.concat(message.args);
454
- }
455
- });
456
- }
457
- return names;
458
- }
459
- /**
460
- * Updates the feed object with a new name when validation fails.
461
- *
462
- * @param feeds The feed objects from the velocity item.
463
- * @param data The full data object used for deploying the velocity item.
464
- * @param names The names that failed due to duplicate error in validation.
465
- *
466
- * @private
467
- */
468
- function _updateFeed(feeds, data, names) {
469
- feeds.forEach(f => {
470
- const update = _getOutputLabel(names, f);
471
- /* istanbul ignore else */
472
- if (update) {
473
- data.label = update.label;
474
- f.name = update.label;
475
- }
476
- });
477
- }
478
- /**
479
- * Updates the data object with a new name when validation fails.
480
- *
481
- * @param dataOutputs The data output objects from the velocity item.
482
- * @param data The full data object used for deploying the velocity item.
483
- * @param names The names that failed due to duplicate error in validation.
484
- *
485
- * @private
486
- */
487
- function _updateDataOutput(dataOutputs, data, names) {
488
- dataOutputs.forEach(dataOutput => {
489
- const update = _getOutputLabel(names, dataOutput);
490
- /* istanbul ignore else */
491
- if (update) {
492
- const _outputs = (data.outputs ? data.outputs : data.output ? [data.output] : []).map((_dataOutput) => {
493
- /* istanbul ignore else */
494
- if (_dataOutput.id === update.id) {
495
- /* istanbul ignore else */
496
- if (_dataOutput.properties) {
497
- const nameProp = `${_dataOutput.name}.name`;
498
- /* istanbul ignore else */
499
- if (Object.keys(_dataOutput.properties).indexOf(nameProp) > -1) {
500
- _dataOutput.properties[nameProp] = update.label;
501
- }
502
- }
503
- }
504
- return _dataOutput;
505
- });
506
- /* istanbul ignore else */
507
- if (data.outputs) {
508
- data.outputs = _outputs;
509
- }
510
- /* istanbul ignore else */
511
- if (data.output) {
512
- data.output = _outputs[0];
513
- }
514
- }
515
- });
516
- }
517
- /**
518
- * Get a unique label for the item.
519
- *
520
- * @param names The names that failed due to duplicate error in validation.
521
- * @param dataOutput The current data output that is being evaluated.
522
- *
523
- * @returns an object with a unique label and the outputs id when a name
524
- * conflict is found...otherwise returns undefined
525
- *
526
- * @private
527
- */
528
- function _getOutputLabel(names, dataOutput) {
529
- const titles = names.map((name) => {
530
- return { title: name };
531
- });
532
- const label = getUniqueTitle(dataOutput.name, { titles }, "titles");
533
- return label !== dataOutput.name
534
- ? {
535
- label,
536
- id: dataOutput.id
537
- }
538
- : undefined;
539
- }
540
- /**
541
- * Will return the provided title if it does not exist as a property
542
- * in one of the objects at the defined path. Otherwise the title will
543
- * have a numerical value attached.
544
- *
545
- * This is based on "getUniqueTitle" from common but adds the "_" replacement check for velocity names.
546
- * Could switch to using common if Velocity has a way to get a list of all names that are already used.
547
- *
548
- * @param title The root title to test
549
- * @param templateDictionary Hash of the facts
550
- * @param path to the objects to evaluate for potantial name clashes
551
- *
552
- * @returns string The unique title to use
553
- *
554
- */
555
- function getUniqueTitle(title, templateDictionary, path) {
556
- title = title ? title.trim() : "_";
557
- const objs = solutionCommon.getProp(templateDictionary, path) || [];
558
- const titles = objs.map(obj => {
559
- return obj.title;
560
- });
561
- let newTitle = title;
562
- let i = 0;
563
- // replace added for velocitcy
564
- // validation seems to add "_" to names listed in outputs..so no way to compare without hacking the name
565
- while (titles.indexOf(newTitle) > -1 ||
566
- titles.indexOf(newTitle.replace(/ /g, "_")) > -1) {
567
- i++;
568
- newTitle = title + " " + i;
569
- }
570
- return newTitle;
571
- }
572
- /**
573
- * Start the item if validation passes and the item is executable.
574
- *
575
- * @param authentication Credentials for the requests
576
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
577
- * @param template the item template that has the details for deployment
578
- * @param id the new id for the velocity item that was deployed
579
- *
580
- * @returns a promise that will resolve with the validation results
581
- * or the start results when validation indicates the item is executable
582
- *
583
- * @private
584
- */
585
- function _validateAndStart(authentication, templateDictionary, template, id) {
586
- return validate(authentication, templateDictionary, template.type, id).then(validateResult => {
587
- if (validateResult.executable) {
588
- return start(authentication, templateDictionary, template.type, id);
589
- }
590
- else {
591
- return Promise.resolve(validateResult);
592
- }
593
- });
594
- }
595
- /**
596
- * Validate the velocity item.
597
- * Used to help find and handle duplicate name errors.
598
- *
599
- * @param authentication Credentials for the requests
600
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
601
- * @param type The type of velocity item we are constructing a url for
602
- * @param id? Optional The id of the velocity item we are constructing a url for
603
- * @param body? Optional the request body to validate.
604
- *
605
- * @returns a promise that will resolve with an object containing messages
606
- * indicating any issues found when validating such as name conflict errors
607
- *
608
- */
609
- function validate(authentication, templateDictionary, type, id, body) {
610
- // /iot/feed/validate/{id}/
611
- // /iot/analytics/realtime/validate/{id}/
612
- return getVelocityUrl(authentication, templateDictionary, type, id, false, "validate", "").then(url => {
613
- return _fetch(authentication, url, "POST", body).then(result => {
614
- return Promise.resolve(result);
615
- });
616
- });
617
- }
618
- /**
619
- * Start the given velocity item that has been deployed.
620
- *
621
- * @param authentication Credentials for the requests
622
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
623
- * @param type The type of velocity item we are constructing a url for
624
- * @param id? Optional The id of the velocity item we are constructing a url for
625
- *
626
- * @returns a promise that will resolve with the result of the start call
627
- *
628
- */
629
- function start(authentication, templateDictionary, type, id) {
630
- // /iot/feed/{id}/start/
631
- // /iot/analytics/realtime/{id}/start/
632
- return getVelocityUrl(authentication, templateDictionary, type, id, false, "", "start").then(url => {
633
- return _fetch(authentication, url, "GET").then(result => {
634
- return Promise.resolve(result);
635
- });
636
- });
637
- }
638
- /**
639
- * Gets the required request options for requests to the velocity API.
640
- *
641
- * @param authentication Credentials for the requests
642
- * @param method Indicate if "GET" or "POST"
643
- *
644
- * @returns generic request options used for various calls to velocity api
645
- *
646
- * @private
647
- */
648
- function _getRequestOpts(authentication, method) {
649
- return {
650
- headers: {
651
- Accept: "application/json",
652
- "Content-Type": "application/json",
653
- Authorization: "token=" + authentication.token
654
- },
655
- method
656
- };
657
- }
658
- /**
659
- * Generic fetch function for making calls to the velocity API.
660
- *
661
- * @param authentication Credentials for the requests
662
- * @param url The url from the velocity API to handle reading and writing
663
- * @param method The method for the request "GET" or "POST"
664
- * @param body The body for POST requests
665
- *
666
- * @returns a promise that will resolve with the result of the fetch call
667
- *
668
- * @private
669
- */
670
- function _fetch(authentication, url, method, // GET or POST
671
- body) {
672
- const requestOpts = _getRequestOpts(authentication, method);
673
- /* istanbul ignore else */
674
- if (body) {
675
- requestOpts.body = JSON.stringify(body);
676
- }
677
- return fetch(url, requestOpts).then(r => Promise.resolve(r.json()));
678
- }
679
- /**
680
- * Remove key properties if the dependency was removed due to having the "IoTFeatureLayer" typeKeyword
681
- * This function will update the input template.
682
- *
683
- * @param template The template that for the velocity item
684
- *
685
- */
686
- function cleanDataSourcesAndFeeds(template, velocityUrl) {
687
- const dependencies = template.dependencies;
688
- [
689
- solutionCommon.getProp(template, "data.sources") ? template.data.sources : [],
690
- solutionCommon.getProp(template, "data.source") ? [template.data.source] : [],
691
- solutionCommon.getProp(template, "data.feeds") ? template.data.feeds : [],
692
- solutionCommon.getProp(template, "data.feed") ? [template.data.feed] : []
693
- ].forEach(d => _removeIdProps(d, dependencies, velocityUrl));
694
- [
695
- solutionCommon.getProp(template, "data.outputs") ? template.data.outputs : [],
696
- solutionCommon.getProp(template, "data.output") ? [template.data.output] : []
697
- ].forEach(outputs => _removeIdPropsAndSetName(outputs, dependencies));
698
- }
699
- /**
700
- * Remove key properties from the input source or feed
701
- *
702
- * @param sourcesOrFeeds The list of dataSources or feeds
703
- * @param dependencies The list of dependencies
704
- *
705
- * @private
706
- */
707
- function _removeIdProps(sourcesOrFeeds, dependencies, velocityUrl) {
708
- sourcesOrFeeds.forEach(dataSource => {
709
- const idProp = "feature-layer.portalItemId";
710
- const layerIdProp = "feature-layer.layerId";
711
- /* istanbul ignore else */
712
- if (dataSource.properties) {
713
- /* istanbul ignore else */
714
- if (dataSource.properties[idProp]) {
715
- const id = dataSource.properties[idProp];
716
- /* istanbul ignore else */
717
- if (id && dependencies.indexOf(id) < 0) {
718
- delete dataSource.properties[idProp];
719
- delete dataSource.properties[layerIdProp];
720
- }
721
- }
722
- const urlProp = "simulator.url";
723
- const url = dataSource.properties[urlProp];
724
- // only remove velocity based simulator urls
725
- // otherwise we will leave as is with no templatization
726
- /* istanbul ignore else */
727
- if (url && url.indexOf(velocityUrl) > -1) {
728
- delete dataSource.properties[urlProp];
729
- }
730
- }
731
- });
732
- }
733
- /**
734
- * Remove key properties from the outputs.
735
- *
736
- * @param outputs The list of outputs
737
- * @param dependencies The list of dependencies
738
- *
739
- * @private
740
- */
741
- function _removeIdPropsAndSetName(outputs, dependencies) {
742
- outputs.forEach(output => {
743
- /* istanbul ignore else */
744
- if (output.properties) {
745
- const names = solutionCommon.getProp(output, "name") ? [output.name] : solutionCommon.BASE_NAMES;
746
- names.forEach(n => {
747
- solutionCommon.PROP_NAMES.forEach(p => _removeProp(output.properties, n + p, dependencies));
748
- });
749
- _updateName(output.properties);
750
- }
751
- });
752
- }
753
- /**
754
- * Generic helper function to remove key properties .
755
- *
756
- * @param props the list of props to update
757
- * @param prop the individual prop to remove
758
- * @param dependencies The list of dependencies
759
- *
760
- * @private
761
- */
762
- function _removeProp(props, prop, dependencies) {
763
- const id = props[prop];
764
- /* istanbul ignore else */
765
- if (id && dependencies.indexOf(id) < 0) {
766
- delete props[prop];
767
- }
768
- }
769
- /**
770
- * Update the feature layer name to include the solution item id.
771
- *
772
- * @param props the list of props to update
773
- *
774
- * @private
775
- */
776
- function _updateName(props) {
777
- [
778
- "feat-lyr-new.name",
779
- "stream-lyr-new.name",
780
- "feat-lyr-existing.name"
781
- ].forEach(n => {
782
- const name = props[n];
783
- /* istanbul ignore else */
784
- if (name && name.indexOf("{{solutionItemId}}") < 0) {
785
- props[n] = `${name}_{{solutionItemId}}`;
786
- }
787
- });
788
- }
789
-
790
- /** @license
791
- * Copyright 2021 Esri
792
- *
793
- * Licensed under the Apache License, Version 2.0 (the "License");
794
- * you may not use this file except in compliance with the License.
795
- * You may obtain a copy of the License at
796
- *
797
- * http://www.apache.org/licenses/LICENSE-2.0
798
- *
799
- * Unless required by applicable law or agreed to in writing, software
800
- * distributed under the License is distributed on an "AS IS" BASIS,
801
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
802
- * See the License for the specific language governing permissions and
803
- * limitations under the License.
804
- */
805
- /**
806
- * Convert a Velocity item into a Template
807
- *
808
- * @param solutionItemId The solution to contain the item
809
- * @param itemInfo The basic item info
810
- * @param destAuthentication Credentials for requests to the destination organization
811
- * @param srcAuthentication Credentials for requests to source items
812
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
813
- *
814
- * @returns a promise that will resolve the constructed IItemTemplate from the input itemInfo
815
- *
816
- */
817
- function convertItemToTemplate(solutionItemId, itemInfo, destAuthentication, srcAuthentication, templateDictionary) {
818
- const template = solutionCommon.createInitializedItemTemplate(itemInfo);
819
- return getVelocityUrl(srcAuthentication, templateDictionary, itemInfo.type, itemInfo.id).then((url) => {
820
- if (url) {
821
- return fetch(url)
822
- .then(data => data.json())
823
- .then(data_json => {
824
- template.item.title = data_json.label;
825
- template.data = data_json;
826
- return getVelocityDependencies(template, srcAuthentication).then(deps => {
827
- template.dependencies = deps;
828
- cleanDataSourcesAndFeeds(template, templateDictionary.velocityUrl);
829
- templatizeVelocity(template);
830
- template.item = solutionCommon.updateVelocityReferences(template.item, template.type, templateDictionary);
831
- return Promise.resolve(template);
832
- });
833
- });
834
- }
835
- else {
836
- // In case the org used to have velocity and they still have items
837
- return Promise.reject("Velocity NOT Supported by Organization");
838
- }
839
- }, e => Promise.reject(solutionCommon.fail(e)));
840
- }
841
- /**
842
- * Create Velocity analytics and feeds from a Template
843
- *
844
- * @param template The template for the volocity items
845
- * @param templateDictionary Hash of facts: folder id, org URL, adlib replacements
846
- * @param destinationAuthentication Credentials for the deployment requests
847
- * @param itemProgressCallback Function for reporting progress updates from type-specific template handlers
848
- *
849
- * @returns a promise that will resolve with the new item info, id, type, and postProcess flag
850
- *
851
- */
852
- function createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback) {
853
- // let the progress system know we've started...
854
- const startStatus = itemProgressCallback(template.itemId, solutionCommon.EItemProgressStatus.Started, 0);
855
- // and if it returned false, just resolve out
856
- /* istanbul ignore else */
857
- if (!startStatus) {
858
- return Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type));
859
- }
860
- const orgId = template.itemId;
861
- return postVelocityData(destinationAuthentication, template, template.data, templateDictionary).then(result => {
862
- const finalStatus = itemProgressCallback(orgId, solutionCommon.EItemProgressStatus.Finished, template.estimatedDeploymentCostFactor || 2, result.id);
863
- if (!finalStatus) {
864
- return solutionCommon.removeItem(result.id, destinationAuthentication).then(() => Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type)), () => Promise.resolve(solutionCommon.generateEmptyCreationResponse(template.type)));
865
- }
866
- else {
867
- const response = {
868
- item: {
869
- ...template,
870
- ...result
871
- },
872
- id: result.item.id,
873
- type: template.type,
874
- postProcess: true
875
- };
876
- response.item.itemId = result.item.id;
877
- return response;
878
- }
879
- });
880
- }
881
- /**
882
- * Velocity post-processing actions
883
- *
884
- * Move all velocity items to the deployment folder.
885
- *
886
- * @param {string} itemId The item ID
887
- * @param {string} type The template type
888
- * @param {any[]} itemInfos Array of \{id: 'ef3', type: 'Web Map'\} objects
889
- * @param {IItemTemplate} template The item template
890
- * @param {IItemTemplate[]} templates The full collection of item templates
891
- * @param {any} templateDictionary Hash of facts such as the folder id for the deployment
892
- * @param {UserSession} authentication The destination session info
893
- * @returns Promise resolving to successfulness of update
894
- */
895
- function postProcess(itemId, type, itemInfos, template, templates, templateDictionary, authentication) {
896
- const itemUpdate = itemInfos.filter(ii => ii.id === itemId);
897
- const item = itemUpdate[0].item.item;
898
- delete item.url;
899
- delete item.origUrl;
900
- return solutionCommon.updateItem(item, authentication).then(() => {
901
- return arcgisRestPortal.moveItem({
902
- owner: authentication.username,
903
- itemId,
904
- folderId: templateDictionary.folderId,
905
- authentication
906
- });
907
- });
908
- }
909
-
910
- var velocityProcessor = /*#__PURE__*/Object.freeze({
911
- __proto__: null,
912
- convertItemToTemplate: convertItemToTemplate,
913
- createItemFromTemplate: createItemFromTemplate,
914
- postProcess: postProcess
915
- });
916
-
917
- exports.VelocityProcessor = velocityProcessor;
918
-
919
- Object.defineProperty(exports, '__esModule', { value: true });
920
-
921
- }));
922
- //# sourceMappingURL=velocity.umd.js.map