@itentialopensource/adapter-nautobot_v2 0.3.2 → 0.5.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/adapterBase.js CHANGED
@@ -1246,6 +1246,44 @@ class AdapterBase extends EventEmitterCl {
1246
1246
  return this.requestHandlerInst.iapGetDeviceCountAuth(callOptions, callback);
1247
1247
  }
1248
1248
 
1249
+ /**
1250
+ * @summary Parse and merge iapMetadata fields into reqObj
1251
+ *
1252
+ * @function parseIapMetadata
1253
+ * @param {Object} reqObj - the request object to merge metadata into
1254
+ * @param {Object} iapMetadata - the metadata object to parse and merge
1255
+ */
1256
+ parseIapMetadata(reqObj, iapMetadata) {
1257
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
1258
+
1259
+ const result = { ...reqObj };
1260
+
1261
+ // Merge and add new iapMetadata fields in result
1262
+ Object.keys(iapMetadata).forEach((iapField) => {
1263
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
1264
+ if (Array.isArray(result[iapField]) && Array.isArray(iapMetadata[iapField])) {
1265
+ result[iapField] = result[iapField].concat(iapMetadata[iapField]); // Merge arrays
1266
+ } else if (
1267
+ result[iapField]
1268
+ && iapMetadata[iapField]
1269
+ && typeof result[iapField] === 'object'
1270
+ && typeof iapMetadata[iapField] === 'object'
1271
+ && !Array.isArray(result[iapField])
1272
+ && !Array.isArray(iapMetadata[iapField])
1273
+ ) {
1274
+ result[iapField] = { ...result[iapField], ...iapMetadata[iapField] }; // Merge objects
1275
+ } else {
1276
+ // Otherwise, add new iapMetadata fields to result
1277
+ result[iapField] = iapMetadata[iapField];
1278
+ }
1279
+ }
1280
+ });
1281
+ // Add iapMetadata to result for further work
1282
+ result.iapMetadata = iapMetadata;
1283
+
1284
+ return result;
1285
+ }
1286
+
1249
1287
  /* ********************************************** */
1250
1288
  /* */
1251
1289
  /* EXPOSES GENERIC HANDLER */