@itentialopensource/adapter-pitney_bowes 0.1.1
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/.eslintignore +6 -0
- package/.eslintrc.js +18 -0
- package/.gitlab/.gitkeep +0 -0
- package/.gitlab/issue_templates/.gitkeep +0 -0
- package/.gitlab/issue_templates/Default.md +17 -0
- package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
- package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
- package/.jshintrc +0 -0
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +170 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +172 -0
- package/ENHANCE.md +69 -0
- package/LICENSE +201 -0
- package/PROPERTIES.md +641 -0
- package/README.md +337 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +3684 -0
- package/adapterBase.js +1787 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +64 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/AddressValidation/action.json +44 -0
- package/entities/AddressValidation/schema.json +20 -0
- package/entities/Authentication/action.json +24 -0
- package/entities/Authentication/schema.json +30 -0
- package/entities/CarrierInfo/action.json +87 -0
- package/entities/CarrierInfo/mockdatafiles/getCarrierLicenseAgreement-default.json +3 -0
- package/entities/CarrierInfo/schema.json +22 -0
- package/entities/Container/action.json +24 -0
- package/entities/Container/schema.json +19 -0
- package/entities/CrossBorderQuotes/action.json +44 -0
- package/entities/CrossBorderQuotes/mockdatafiles/getCrossBorderQuotes-default.json +51 -0
- package/entities/CrossBorderQuotes/schema.json +20 -0
- package/entities/Manifests/action.json +66 -0
- package/entities/Manifests/schema.json +21 -0
- package/entities/ParcelProtection/action.json +85 -0
- package/entities/ParcelProtection/mockdatafiles/cancelParcelProtection-default.json +3 -0
- package/entities/ParcelProtection/mockdatafiles/getParcelProtectionCoverage-default.json +11 -0
- package/entities/ParcelProtection/mockdatafiles/getParcelProtectionQuote-default.json +8 -0
- package/entities/ParcelProtection/schema.json +22 -0
- package/entities/Pickup/action.json +44 -0
- package/entities/Pickup/schema.json +20 -0
- package/entities/RateParcels/action.json +24 -0
- package/entities/RateParcels/schema.json +19 -0
- package/entities/Shipment/action.json +86 -0
- package/entities/Shipment/schema.json +22 -0
- package/entities/Tracking/action.json +45 -0
- package/entities/Tracking/mockdatafiles/addTrackingEvents-default.json +3 -0
- package/entities/Tracking/schema.json +20 -0
- package/entities/TransactionReports/action.json +25 -0
- package/entities/TransactionReports/schema.json +19 -0
- package/error.json +190 -0
- package/package.json +85 -0
- package/pronghorn.json +2918 -0
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +1248 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/PitneyBowes - ShippingAPI_OAS-OpenApi3Json.json +7675 -0
- package/report/creationReport.json +480 -0
- package/sampleProperties.json +197 -0
- package/test/integration/adapterTestBasicGet.js +83 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +1402 -0
- package/test/unit/adapterBaseTestUnit.js +949 -0
- package/test/unit/adapterTestUnit.js +2417 -0
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +178 -0
- package/utils/findPath.js +74 -0
- package/utils/methodDocumentor.js +225 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +32 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/tbScript.js +246 -0
- package/utils/tbUtils.js +490 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +195 -0
- package/workflows/README.md +3 -0
package/adapter.js
ADDED
|
@@ -0,0 +1,3684 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2019 (pre-modifications) */
|
|
2
|
+
|
|
3
|
+
/* eslint import/no-dynamic-require: warn */
|
|
4
|
+
/* eslint object-curly-newline: warn */
|
|
5
|
+
|
|
6
|
+
// Set globals
|
|
7
|
+
/* global log */
|
|
8
|
+
|
|
9
|
+
/* Required libraries. */
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
/* Fetch in the other needed components for the this Adaptor */
|
|
13
|
+
const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This is the adapter/interface into Pitney_bowes
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* GENERAL ADAPTER FUNCTIONS */
|
|
20
|
+
class PitneyBowes extends AdapterBaseCl {
|
|
21
|
+
/**
|
|
22
|
+
* PitneyBowes Adapter
|
|
23
|
+
* @constructor
|
|
24
|
+
*/
|
|
25
|
+
/* Working on changing the way we do Emit methods due to size and time constrainsts
|
|
26
|
+
constructor(prongid, properties) {
|
|
27
|
+
// Instantiate the AdapterBase super class
|
|
28
|
+
super(prongid, properties);
|
|
29
|
+
|
|
30
|
+
const restFunctionNames = this.iapGetAdapterWorkflowFunctions();
|
|
31
|
+
|
|
32
|
+
// Dynamically bind emit functions
|
|
33
|
+
for (let i = 0; i < restFunctionNames.length; i += 1) {
|
|
34
|
+
// Bind function to have name fnNameEmit for fnName
|
|
35
|
+
const version = restFunctionNames[i].match(/__v[0-9]+/);
|
|
36
|
+
const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
|
|
37
|
+
const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
|
|
38
|
+
this[fnNameEmit] = function (...args) {
|
|
39
|
+
// extract the callback
|
|
40
|
+
const callback = args[args.length - 1];
|
|
41
|
+
// slice the callback from args so we can insert our own
|
|
42
|
+
const functionArgs = args.slice(0, args.length - 1);
|
|
43
|
+
// create a random name for the listener
|
|
44
|
+
const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
|
|
45
|
+
// tell the calling class to start listening
|
|
46
|
+
callback({ event: eventName, status: 'received' });
|
|
47
|
+
// store parent for use of this context later
|
|
48
|
+
const parent = this;
|
|
49
|
+
// store emission function
|
|
50
|
+
const func = function (val, err) {
|
|
51
|
+
parent.removeListener(eventName, func);
|
|
52
|
+
parent.emit(eventName, val, err);
|
|
53
|
+
};
|
|
54
|
+
// Use apply to call the function in a specific context
|
|
55
|
+
this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Uncomment if you have things to add to the constructor like using your own properties.
|
|
60
|
+
// Otherwise the constructor in the adapterBase will be used.
|
|
61
|
+
// Capture my own properties - they need to be defined in propertiesSchema.json
|
|
62
|
+
// if (this.allProps && this.allProps.myownproperty) {
|
|
63
|
+
// mypropvariable = this.allProps.myownproperty;
|
|
64
|
+
// }
|
|
65
|
+
}
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @callback healthCallback
|
|
70
|
+
* @param {Object} reqObj - the request to send into the healthcheck
|
|
71
|
+
* @param {Callback} callback - The results of the call
|
|
72
|
+
*/
|
|
73
|
+
healthCheck(reqObj, callback) {
|
|
74
|
+
// you can modify what is passed into the healthcheck by changing things in the newReq
|
|
75
|
+
let newReq = null;
|
|
76
|
+
if (reqObj) {
|
|
77
|
+
newReq = Object.assign(...reqObj);
|
|
78
|
+
}
|
|
79
|
+
super.healthCheck(newReq, callback);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @iapGetAdapterWorkflowFunctions
|
|
84
|
+
*/
|
|
85
|
+
iapGetAdapterWorkflowFunctions(inIgnore) {
|
|
86
|
+
let myIgnore = [
|
|
87
|
+
'healthCheck',
|
|
88
|
+
'iapGetAdapterWorkflowFunctions',
|
|
89
|
+
'iapHasAdapterEntity',
|
|
90
|
+
'iapVerifyAdapterCapability',
|
|
91
|
+
'iapUpdateAdapterEntityCache',
|
|
92
|
+
'hasEntities'
|
|
93
|
+
];
|
|
94
|
+
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
95
|
+
myIgnore = inIgnore;
|
|
96
|
+
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
97
|
+
myIgnore = [inIgnore];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The generic adapter functions should already be ignored (e.g. healthCheck)
|
|
101
|
+
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
|
102
|
+
// myIgnore.push('myMethodNotInWorkflow');
|
|
103
|
+
|
|
104
|
+
return super.iapGetAdapterWorkflowFunctions(myIgnore);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
109
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
|
110
|
+
* file system.
|
|
111
|
+
*
|
|
112
|
+
* @function iapUpdateAdapterConfiguration
|
|
113
|
+
* @param {string} configFile - the name of the file being updated (required)
|
|
114
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
115
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
116
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
117
|
+
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
118
|
+
* @param {Callback} callback - The results of the call
|
|
119
|
+
*/
|
|
120
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
121
|
+
const meth = 'adapter-iapUpdateAdapterConfiguration';
|
|
122
|
+
const origin = `${this.id}-${meth}`;
|
|
123
|
+
log.trace(origin);
|
|
124
|
+
|
|
125
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* See if the API path provided is found in this adapter
|
|
130
|
+
*
|
|
131
|
+
* @function iapFindAdapterPath
|
|
132
|
+
* @param {string} apiPath - the api path to check on
|
|
133
|
+
* @param {Callback} callback - The results of the call
|
|
134
|
+
*/
|
|
135
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
136
|
+
const meth = 'adapter-iapFindAdapterPath';
|
|
137
|
+
const origin = `${this.id}-${meth}`;
|
|
138
|
+
log.trace(origin);
|
|
139
|
+
|
|
140
|
+
super.iapFindAdapterPath(apiPath, callback);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @summary Suspends adapter
|
|
145
|
+
*
|
|
146
|
+
* @function iapSuspendAdapter
|
|
147
|
+
* @param {Callback} callback - callback function
|
|
148
|
+
*/
|
|
149
|
+
iapSuspendAdapter(mode, callback) {
|
|
150
|
+
const meth = 'adapter-iapSuspendAdapter';
|
|
151
|
+
const origin = `${this.id}-${meth}`;
|
|
152
|
+
log.trace(origin);
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
return super.iapSuspendAdapter(mode, callback);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
log.error(`${origin}: ${error}`);
|
|
158
|
+
return callback(null, error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @summary Unsuspends adapter
|
|
164
|
+
*
|
|
165
|
+
* @function iapUnsuspendAdapter
|
|
166
|
+
* @param {Callback} callback - callback function
|
|
167
|
+
*/
|
|
168
|
+
iapUnsuspendAdapter(callback) {
|
|
169
|
+
const meth = 'adapter-iapUnsuspendAdapter';
|
|
170
|
+
const origin = `${this.id}-${meth}`;
|
|
171
|
+
log.trace(origin);
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
return super.iapUnsuspendAdapter(callback);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
log.error(`${origin}: ${error}`);
|
|
177
|
+
return callback(null, error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @summary Get the Adaoter Queue
|
|
183
|
+
*
|
|
184
|
+
* @function iapGetAdapterQueue
|
|
185
|
+
* @param {Callback} callback - callback function
|
|
186
|
+
*/
|
|
187
|
+
iapGetAdapterQueue(callback) {
|
|
188
|
+
const meth = 'adapter-iapGetAdapterQueue';
|
|
189
|
+
const origin = `${this.id}-${meth}`;
|
|
190
|
+
log.trace(origin);
|
|
191
|
+
|
|
192
|
+
return super.iapGetAdapterQueue(callback);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @summary Runs troubleshoot scripts for adapter
|
|
197
|
+
*
|
|
198
|
+
* @function iapTroubleshootAdapter
|
|
199
|
+
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
200
|
+
*
|
|
201
|
+
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
202
|
+
* @param {Callback} callback - The results of the call
|
|
203
|
+
*/
|
|
204
|
+
iapTroubleshootAdapter(props, persistFlag, callback) {
|
|
205
|
+
const meth = 'adapter-iapTroubleshootAdapter';
|
|
206
|
+
const origin = `${this.id}-${meth}`;
|
|
207
|
+
log.trace(origin);
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
log.error(`${origin}: ${error}`);
|
|
213
|
+
return callback(null, error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @summary runs healthcheck script for adapter
|
|
219
|
+
*
|
|
220
|
+
* @function iapRunAdapterHealthcheck
|
|
221
|
+
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
222
|
+
* @param {Callback} callback - callback function
|
|
223
|
+
*/
|
|
224
|
+
iapRunAdapterHealthcheck(callback) {
|
|
225
|
+
const meth = 'adapter-iapRunAdapterHealthcheck';
|
|
226
|
+
const origin = `${this.id}-${meth}`;
|
|
227
|
+
log.trace(origin);
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
return super.iapRunAdapterHealthcheck(this, callback);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
log.error(`${origin}: ${error}`);
|
|
233
|
+
return callback(null, error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @summary runs connectivity check script for adapter
|
|
239
|
+
*
|
|
240
|
+
* @function iapRunAdapterConnectivity
|
|
241
|
+
* @param {Callback} callback - callback function
|
|
242
|
+
*/
|
|
243
|
+
iapRunAdapterConnectivity(callback) {
|
|
244
|
+
const meth = 'adapter-iapRunAdapterConnectivity';
|
|
245
|
+
const origin = `${this.id}-${meth}`;
|
|
246
|
+
log.trace(origin);
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
return super.iapRunAdapterConnectivity(callback);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
log.error(`${origin}: ${error}`);
|
|
252
|
+
return callback(null, error);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @summary runs basicGet script for adapter
|
|
258
|
+
*
|
|
259
|
+
* @function iapRunAdapterBasicGet
|
|
260
|
+
* @param {Callback} callback - callback function
|
|
261
|
+
*/
|
|
262
|
+
iapRunAdapterBasicGet(callback) {
|
|
263
|
+
const meth = 'adapter-iapRunAdapterBasicGet';
|
|
264
|
+
const origin = `${this.id}-${meth}`;
|
|
265
|
+
log.trace(origin);
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
return super.iapRunAdapterBasicGet(callback);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
log.error(`${origin}: ${error}`);
|
|
271
|
+
return callback(null, error);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @summary moves entites into Mongo DB
|
|
277
|
+
*
|
|
278
|
+
* @function iapMoveAdapterEntitiesToDB
|
|
279
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
280
|
+
* or the error
|
|
281
|
+
*/
|
|
282
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
|
283
|
+
const meth = 'adapter-iapMoveAdapterEntitiesToDB';
|
|
284
|
+
const origin = `${this.id}-${meth}`;
|
|
285
|
+
log.trace(origin);
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
return super.iapMoveAdapterEntitiesToDB(callback);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
log.error(`${origin}: ${err}`);
|
|
291
|
+
return callback(null, err);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* BROKER CALLS */
|
|
296
|
+
/**
|
|
297
|
+
* @summary Determines if this adapter supports the specific entity
|
|
298
|
+
*
|
|
299
|
+
* @function iapHasAdapterEntity
|
|
300
|
+
* @param {String} entityType - the entity type to check for
|
|
301
|
+
* @param {String/Array} entityId - the specific entity we are looking for
|
|
302
|
+
*
|
|
303
|
+
* @param {Callback} callback - An array of whether the adapter can has the
|
|
304
|
+
* desired capability or an error
|
|
305
|
+
*/
|
|
306
|
+
iapHasAdapterEntity(entityType, entityId, callback) {
|
|
307
|
+
const origin = `${this.id}-adapter-iapHasAdapterEntity`;
|
|
308
|
+
log.trace(origin);
|
|
309
|
+
|
|
310
|
+
// Make the call -
|
|
311
|
+
// iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
312
|
+
return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @summary Provides a way for the adapter to tell north bound integrations
|
|
317
|
+
* whether the adapter supports type, action and specific entity
|
|
318
|
+
*
|
|
319
|
+
* @function iapVerifyAdapterCapability
|
|
320
|
+
* @param {String} entityType - the entity type to check for
|
|
321
|
+
* @param {String} actionType - the action type to check for
|
|
322
|
+
* @param {String/Array} entityId - the specific entity we are looking for
|
|
323
|
+
*
|
|
324
|
+
* @param {Callback} callback - An array of whether the adapter can has the
|
|
325
|
+
* desired capability or an error
|
|
326
|
+
*/
|
|
327
|
+
iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
|
|
328
|
+
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
|
329
|
+
const origin = `${this.id}-${meth}`;
|
|
330
|
+
log.trace(origin);
|
|
331
|
+
|
|
332
|
+
// if caching
|
|
333
|
+
if (this.caching) {
|
|
334
|
+
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
335
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
|
336
|
+
if (error) {
|
|
337
|
+
return callback(null, error);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// if the cache needs to be updated, update and try again
|
|
341
|
+
if (results && results[0] === 'needupdate') {
|
|
342
|
+
switch (entityType) {
|
|
343
|
+
case 'template_entity': {
|
|
344
|
+
// if the cache is invalid, update the cache
|
|
345
|
+
return this.getEntities(null, null, null, null, (data, err) => {
|
|
346
|
+
if (err) {
|
|
347
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
|
|
348
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
349
|
+
return callback(null, errorObj);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// need to check the cache again since it has been updated
|
|
353
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
|
354
|
+
if (verror) {
|
|
355
|
+
return callback(null, verror);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return this.capabilityResults(vcapable, callback);
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
default: {
|
|
363
|
+
// unsupported entity type
|
|
364
|
+
const result = [false];
|
|
365
|
+
|
|
366
|
+
// put false in array for all entities
|
|
367
|
+
if (Array.isArray(entityId)) {
|
|
368
|
+
for (let e = 1; e < entityId.length; e += 1) {
|
|
369
|
+
result.push(false);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return callback(result);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// return the results
|
|
379
|
+
return this.capabilityResults(results, callback);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// if no entity id
|
|
384
|
+
if (!entityId) {
|
|
385
|
+
// need to check the cache again since it has been updated
|
|
386
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
387
|
+
if (verror) {
|
|
388
|
+
return callback(null, verror);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return this.capabilityResults(vcapable, callback);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// if not caching
|
|
396
|
+
switch (entityType) {
|
|
397
|
+
case 'template_entity': {
|
|
398
|
+
// need to get the entities to check
|
|
399
|
+
return this.getEntities(null, null, null, null, (data, err) => {
|
|
400
|
+
if (err) {
|
|
401
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
|
|
402
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
403
|
+
return callback(null, errorObj);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// need to check the cache again since it has been updated
|
|
407
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
408
|
+
if (verror) {
|
|
409
|
+
return callback(null, verror);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// is the entity in the list?
|
|
413
|
+
const isEntity = this.entityInList(entityId, data.response, callback);
|
|
414
|
+
const res = [];
|
|
415
|
+
|
|
416
|
+
// not found
|
|
417
|
+
for (let i = 0; i < isEntity.length; i += 1) {
|
|
418
|
+
if (vcapable) {
|
|
419
|
+
res.push(isEntity[i]);
|
|
420
|
+
} else {
|
|
421
|
+
res.push(false);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return callback(res);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
default: {
|
|
430
|
+
// unsupported entity type
|
|
431
|
+
const result = [false];
|
|
432
|
+
|
|
433
|
+
// put false in array for all entities
|
|
434
|
+
if (Array.isArray(entityId)) {
|
|
435
|
+
for (let e = 1; e < entityId.length; e += 1) {
|
|
436
|
+
result.push(false);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return callback(result);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* @summary Updates the cache for all entities by call the get All entity method
|
|
447
|
+
*
|
|
448
|
+
* @function iapUpdateAdapterEntityCache
|
|
449
|
+
*
|
|
450
|
+
*/
|
|
451
|
+
iapUpdateAdapterEntityCache() {
|
|
452
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
|
|
453
|
+
log.trace(origin);
|
|
454
|
+
|
|
455
|
+
if (this.caching) {
|
|
456
|
+
// if the cache is invalid, update the cache
|
|
457
|
+
this.getEntities(null, null, null, null, (data, err) => {
|
|
458
|
+
if (err) {
|
|
459
|
+
log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
467
|
+
*
|
|
468
|
+
* @function hasEntities
|
|
469
|
+
* @param {String} entityType - the entity type to check for
|
|
470
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
471
|
+
*
|
|
472
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
473
|
+
* value is true or false
|
|
474
|
+
*/
|
|
475
|
+
hasEntities(entityType, entityList, callback) {
|
|
476
|
+
const meth = 'adapter-hasEntities';
|
|
477
|
+
const origin = `${this.id}-${meth}`;
|
|
478
|
+
log.trace(origin);
|
|
479
|
+
|
|
480
|
+
try {
|
|
481
|
+
return super.hasEntities(entityType, entityList, callback);
|
|
482
|
+
} catch (err) {
|
|
483
|
+
log.error(`${origin}: ${err}`);
|
|
484
|
+
return callback(null, err);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* @summary Get Appliance that match the deviceName
|
|
490
|
+
*
|
|
491
|
+
* @function getDevice
|
|
492
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
493
|
+
*
|
|
494
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
495
|
+
* (appliance) or the error
|
|
496
|
+
*/
|
|
497
|
+
getDevice(deviceName, callback) {
|
|
498
|
+
const meth = 'adapter-getDevice';
|
|
499
|
+
const origin = `${this.id}-${meth}`;
|
|
500
|
+
log.trace(origin);
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
return super.getDevice(deviceName, callback);
|
|
504
|
+
} catch (err) {
|
|
505
|
+
log.error(`${origin}: ${err}`);
|
|
506
|
+
return callback(null, err);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @summary Get Appliances that match the filter
|
|
512
|
+
*
|
|
513
|
+
* @function getDevicesFiltered
|
|
514
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
515
|
+
*
|
|
516
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
517
|
+
* (appliances) or the error
|
|
518
|
+
*/
|
|
519
|
+
getDevicesFiltered(options, callback) {
|
|
520
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
521
|
+
const origin = `${this.id}-${meth}`;
|
|
522
|
+
log.trace(origin);
|
|
523
|
+
|
|
524
|
+
try {
|
|
525
|
+
return super.getDevicesFiltered(options, callback);
|
|
526
|
+
} catch (err) {
|
|
527
|
+
log.error(`${origin}: ${err}`);
|
|
528
|
+
return callback(null, err);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* @summary Gets the status for the provided appliance
|
|
534
|
+
*
|
|
535
|
+
* @function isAlive
|
|
536
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
537
|
+
*
|
|
538
|
+
* @param {configCallback} callback - callback function to return the result
|
|
539
|
+
* (appliance isAlive) or the error
|
|
540
|
+
*/
|
|
541
|
+
isAlive(deviceName, callback) {
|
|
542
|
+
const meth = 'adapter-isAlive';
|
|
543
|
+
const origin = `${this.id}-${meth}`;
|
|
544
|
+
log.trace(origin);
|
|
545
|
+
|
|
546
|
+
try {
|
|
547
|
+
return super.isAlive(deviceName, callback);
|
|
548
|
+
} catch (err) {
|
|
549
|
+
log.error(`${origin}: ${err}`);
|
|
550
|
+
return callback(null, err);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* @summary Gets a config for the provided Appliance
|
|
556
|
+
*
|
|
557
|
+
* @function getConfig
|
|
558
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
559
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
560
|
+
*
|
|
561
|
+
* @param {configCallback} callback - callback function to return the result
|
|
562
|
+
* (appliance config) or the error
|
|
563
|
+
*/
|
|
564
|
+
getConfig(deviceName, format, callback) {
|
|
565
|
+
const meth = 'adapter-getConfig';
|
|
566
|
+
const origin = `${this.id}-${meth}`;
|
|
567
|
+
log.trace(origin);
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
return super.getConfig(deviceName, format, callback);
|
|
571
|
+
} catch (err) {
|
|
572
|
+
log.error(`${origin}: ${err}`);
|
|
573
|
+
return callback(null, err);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* @summary Gets the device count from the system
|
|
579
|
+
*
|
|
580
|
+
* @function iapGetDeviceCount
|
|
581
|
+
*
|
|
582
|
+
* @param {getCallback} callback - callback function to return the result
|
|
583
|
+
* (count) or the error
|
|
584
|
+
*/
|
|
585
|
+
iapGetDeviceCount(callback) {
|
|
586
|
+
const meth = 'adapter-iapGetDeviceCount';
|
|
587
|
+
const origin = `${this.id}-${meth}`;
|
|
588
|
+
log.trace(origin);
|
|
589
|
+
|
|
590
|
+
try {
|
|
591
|
+
return super.iapGetDeviceCount(callback);
|
|
592
|
+
} catch (err) {
|
|
593
|
+
log.error(`${origin}: ${err}`);
|
|
594
|
+
return callback(null, err);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
|
599
|
+
/**
|
|
600
|
+
* Makes the requested generic call
|
|
601
|
+
*
|
|
602
|
+
* @function genericAdapterRequest
|
|
603
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
604
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
605
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
606
|
+
* Can be a stringified Object.
|
|
607
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
608
|
+
* Can be a stringified Object.
|
|
609
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
610
|
+
* Can be a stringified Object.
|
|
611
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
612
|
+
* or the error
|
|
613
|
+
*/
|
|
614
|
+
genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
615
|
+
const meth = 'adapter-genericAdapterRequest';
|
|
616
|
+
const origin = `${this.id}-${meth}`;
|
|
617
|
+
log.trace(origin);
|
|
618
|
+
|
|
619
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
620
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
621
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
622
|
+
return callback(null, errorObj);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
626
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
627
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
628
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
629
|
+
return callback(null, errorObj);
|
|
630
|
+
}
|
|
631
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
632
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
633
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
634
|
+
return callback(null, errorObj);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
638
|
+
// remove any leading / and split the uripath into path variables
|
|
639
|
+
let myPath = uriPath;
|
|
640
|
+
while (myPath.indexOf('/') === 0) {
|
|
641
|
+
myPath = myPath.substring(1);
|
|
642
|
+
}
|
|
643
|
+
const pathVars = myPath.split('/');
|
|
644
|
+
const queryParamsAvailable = queryData;
|
|
645
|
+
const queryParams = {};
|
|
646
|
+
const bodyVars = requestBody;
|
|
647
|
+
|
|
648
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
649
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
650
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
651
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
652
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
657
|
+
const reqObj = {
|
|
658
|
+
payload: bodyVars,
|
|
659
|
+
uriPathVars: pathVars,
|
|
660
|
+
uriQuery: queryParams,
|
|
661
|
+
uriOptions: {}
|
|
662
|
+
};
|
|
663
|
+
// add headers if provided
|
|
664
|
+
if (addlHeaders) {
|
|
665
|
+
reqObj.addlHeaders = addlHeaders;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// determine the call and return flag
|
|
669
|
+
let action = 'getGenerics';
|
|
670
|
+
let returnF = true;
|
|
671
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
672
|
+
action = 'createGeneric';
|
|
673
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
674
|
+
action = 'updateGeneric';
|
|
675
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
676
|
+
action = 'patchGeneric';
|
|
677
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
678
|
+
action = 'deleteGeneric';
|
|
679
|
+
returnF = false;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
try {
|
|
683
|
+
// Make the call -
|
|
684
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
685
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
686
|
+
// if we received an error or their is no response on the results
|
|
687
|
+
// return an error
|
|
688
|
+
if (irReturnError) {
|
|
689
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
690
|
+
return callback(null, irReturnError);
|
|
691
|
+
}
|
|
692
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
693
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
|
|
694
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
695
|
+
return callback(null, errorObj);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
699
|
+
// return the response
|
|
700
|
+
return callback(irReturnData, null);
|
|
701
|
+
});
|
|
702
|
+
} catch (ex) {
|
|
703
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
704
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
705
|
+
return callback(null, errorObj);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Makes the requested generic call with no base path or version
|
|
711
|
+
*
|
|
712
|
+
* @function genericAdapterRequestNoBasePath
|
|
713
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
714
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
715
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
716
|
+
* Can be a stringified Object.
|
|
717
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
718
|
+
* Can be a stringified Object.
|
|
719
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
720
|
+
* Can be a stringified Object.
|
|
721
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
722
|
+
* or the error
|
|
723
|
+
*/
|
|
724
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
725
|
+
const meth = 'adapter-genericAdapterRequestNoBasePath';
|
|
726
|
+
const origin = `${this.id}-${meth}`;
|
|
727
|
+
log.trace(origin);
|
|
728
|
+
|
|
729
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
730
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
731
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
732
|
+
return callback(null, errorObj);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
736
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
737
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
738
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
739
|
+
return callback(null, errorObj);
|
|
740
|
+
}
|
|
741
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
742
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
743
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
744
|
+
return callback(null, errorObj);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
748
|
+
// remove any leading / and split the uripath into path variables
|
|
749
|
+
let myPath = uriPath;
|
|
750
|
+
while (myPath.indexOf('/') === 0) {
|
|
751
|
+
myPath = myPath.substring(1);
|
|
752
|
+
}
|
|
753
|
+
const pathVars = myPath.split('/');
|
|
754
|
+
const queryParamsAvailable = queryData;
|
|
755
|
+
const queryParams = {};
|
|
756
|
+
const bodyVars = requestBody;
|
|
757
|
+
|
|
758
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
759
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
760
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
761
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
762
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
767
|
+
const reqObj = {
|
|
768
|
+
payload: bodyVars,
|
|
769
|
+
uriPathVars: pathVars,
|
|
770
|
+
uriQuery: queryParams,
|
|
771
|
+
uriOptions: {}
|
|
772
|
+
};
|
|
773
|
+
// add headers if provided
|
|
774
|
+
if (addlHeaders) {
|
|
775
|
+
reqObj.addlHeaders = addlHeaders;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// determine the call and return flag
|
|
779
|
+
let action = 'getGenericsNoBase';
|
|
780
|
+
let returnF = true;
|
|
781
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
782
|
+
action = 'createGenericNoBase';
|
|
783
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
784
|
+
action = 'updateGenericNoBase';
|
|
785
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
786
|
+
action = 'patchGenericNoBase';
|
|
787
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
788
|
+
action = 'deleteGenericNoBase';
|
|
789
|
+
returnF = false;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
try {
|
|
793
|
+
// Make the call -
|
|
794
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
795
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
796
|
+
// if we received an error or their is no response on the results
|
|
797
|
+
// return an error
|
|
798
|
+
if (irReturnError) {
|
|
799
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
800
|
+
return callback(null, irReturnError);
|
|
801
|
+
}
|
|
802
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
803
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
|
|
804
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
805
|
+
return callback(null, errorObj);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
809
|
+
// return the response
|
|
810
|
+
return callback(irReturnData, null);
|
|
811
|
+
});
|
|
812
|
+
} catch (ex) {
|
|
813
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
814
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
815
|
+
return callback(null, errorObj);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* @callback healthCallback
|
|
821
|
+
* @param {Object} result - the result of the get request (contains an id and a status)
|
|
822
|
+
*/
|
|
823
|
+
/**
|
|
824
|
+
* @callback getCallback
|
|
825
|
+
* @param {Object} result - the result of the get request (entity/ies)
|
|
826
|
+
* @param {String} error - any error that occurred
|
|
827
|
+
*/
|
|
828
|
+
/**
|
|
829
|
+
* @callback createCallback
|
|
830
|
+
* @param {Object} item - the newly created entity
|
|
831
|
+
* @param {String} error - any error that occurred
|
|
832
|
+
*/
|
|
833
|
+
/**
|
|
834
|
+
* @callback updateCallback
|
|
835
|
+
* @param {String} status - the status of the update action
|
|
836
|
+
* @param {String} error - any error that occurred
|
|
837
|
+
*/
|
|
838
|
+
/**
|
|
839
|
+
* @callback deleteCallback
|
|
840
|
+
* @param {String} status - the status of the delete action
|
|
841
|
+
* @param {String} error - any error that occurred
|
|
842
|
+
*/
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* @function oauthToken
|
|
846
|
+
* @pronghornType method
|
|
847
|
+
* @name oauthToken
|
|
848
|
+
* @summary oauthToken
|
|
849
|
+
*
|
|
850
|
+
* @param {string} [grantType] - grantType param
|
|
851
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
852
|
+
* @return {object} results - An object containing the response of the action
|
|
853
|
+
*
|
|
854
|
+
* @route {POST} /oauthToken
|
|
855
|
+
* @roles admin
|
|
856
|
+
* @task true
|
|
857
|
+
*/
|
|
858
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
859
|
+
oauthToken(grantType, callback) {
|
|
860
|
+
const meth = 'adapter-oauthToken';
|
|
861
|
+
const origin = `${this.id}-${meth}`;
|
|
862
|
+
log.trace(origin);
|
|
863
|
+
|
|
864
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
865
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
866
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
867
|
+
return callback(null, errorObj);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
871
|
+
|
|
872
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
873
|
+
const queryParamsAvailable = {};
|
|
874
|
+
const queryParams = {};
|
|
875
|
+
const pathVars = [];
|
|
876
|
+
const bodyVars = {};
|
|
877
|
+
|
|
878
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
879
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
880
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
881
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
882
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
887
|
+
let thisHeaderData = null;
|
|
888
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
889
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
890
|
+
try {
|
|
891
|
+
// parse the additional headers object that was passed in
|
|
892
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
893
|
+
} catch (err) {
|
|
894
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
895
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
896
|
+
return callback(null, errorObj);
|
|
897
|
+
}
|
|
898
|
+
} else if (thisHeaderData === null) {
|
|
899
|
+
thisHeaderData = { contentType: '', authorization: '' };
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
903
|
+
// see adapter code documentation for more information on the request object's fields
|
|
904
|
+
const reqObj = {
|
|
905
|
+
payload: bodyVars,
|
|
906
|
+
uriPathVars: pathVars,
|
|
907
|
+
uriQuery: queryParams,
|
|
908
|
+
addlHeaders: thisHeaderData
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
try {
|
|
912
|
+
// Make the call -
|
|
913
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
914
|
+
return this.requestHandlerInst.identifyRequest('Authentication', 'oauthToken', reqObj, true, (irReturnData, irReturnError) => {
|
|
915
|
+
// if we received an error or their is no response on the results
|
|
916
|
+
// return an error
|
|
917
|
+
if (irReturnError) {
|
|
918
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
919
|
+
return callback(null, irReturnError);
|
|
920
|
+
}
|
|
921
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
922
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['oauthToken'], null, null, null);
|
|
923
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
924
|
+
return callback(null, errorObj);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
928
|
+
// return the response
|
|
929
|
+
return callback(irReturnData, null);
|
|
930
|
+
});
|
|
931
|
+
} catch (ex) {
|
|
932
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
933
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
934
|
+
return callback(null, errorObj);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* @function getCarrierServiceRules
|
|
940
|
+
* @pronghornType method
|
|
941
|
+
* @name getCarrierServiceRules
|
|
942
|
+
* @summary getCarrierServiceRules
|
|
943
|
+
*
|
|
944
|
+
* @param {} carrier - The carrier name. **Currently this must be set to: USPS**
|
|
945
|
+
* @param {} originCountryCode - The [two-character ISO country code](https://www.iso.org/obp/ui/#search) for the country where the shipment originates.
|
|
946
|
+
* @param {} destinationCountryCode - The [two-character ISO country code](https://www.iso.org/obp/ui/#search) for the country of the shipment's destination address.
|
|
947
|
+
* @param {string} [rateTypeId] - The type of rate requested, such as COMMERCIAL_BASE. If a rate type is not specified, all eligible rate types are returned.
|
|
948
|
+
* @param {string} [futureShipmentDate] - If the shipment is for a future date, and if a rate change is expected before the shipment date, use this field to ensure you get the correct rates and correct rate rules...(description truncated)
|
|
949
|
+
* @param {string} [returnShipment] - If set to true, provides only services applicable for return shipment.
|
|
950
|
+
* @param {boolean} [compactResponse] - If set to true, returns only summary, without special service details.
|
|
951
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
952
|
+
* @return {object} results - An object containing the response of the action
|
|
953
|
+
*
|
|
954
|
+
* @route {POST} /getCarrierServiceRules
|
|
955
|
+
* @roles admin
|
|
956
|
+
* @task true
|
|
957
|
+
*/
|
|
958
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
959
|
+
getCarrierServiceRules(carrier, originCountryCode, destinationCountryCode, rateTypeId, futureShipmentDate, returnShipment, compactResponse, callback) {
|
|
960
|
+
const meth = 'adapter-getCarrierServiceRules';
|
|
961
|
+
const origin = `${this.id}-${meth}`;
|
|
962
|
+
log.trace(origin);
|
|
963
|
+
|
|
964
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
965
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
966
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
967
|
+
return callback(null, errorObj);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
971
|
+
if (carrier === undefined || carrier === null || carrier === '') {
|
|
972
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['carrier'], null, null, null);
|
|
973
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
974
|
+
return callback(null, errorObj);
|
|
975
|
+
}
|
|
976
|
+
if (originCountryCode === undefined || originCountryCode === null || originCountryCode === '') {
|
|
977
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['originCountryCode'], null, null, null);
|
|
978
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
979
|
+
return callback(null, errorObj);
|
|
980
|
+
}
|
|
981
|
+
if (destinationCountryCode === undefined || destinationCountryCode === null || destinationCountryCode === '') {
|
|
982
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['destinationCountryCode'], null, null, null);
|
|
983
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
984
|
+
return callback(null, errorObj);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
988
|
+
const queryParamsAvailable = { carrier, originCountryCode, destinationCountryCode, rateTypeId, futureShipmentDate, returnShipment, compactResponse };
|
|
989
|
+
const queryParams = {};
|
|
990
|
+
const pathVars = [];
|
|
991
|
+
const bodyVars = {};
|
|
992
|
+
|
|
993
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
994
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
995
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
996
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
997
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1002
|
+
let thisHeaderData = null;
|
|
1003
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1004
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1005
|
+
try {
|
|
1006
|
+
// parse the additional headers object that was passed in
|
|
1007
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1008
|
+
} catch (err) {
|
|
1009
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1010
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1011
|
+
return callback(null, errorObj);
|
|
1012
|
+
}
|
|
1013
|
+
} else if (thisHeaderData === null) {
|
|
1014
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1018
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1019
|
+
const reqObj = {
|
|
1020
|
+
payload: bodyVars,
|
|
1021
|
+
uriPathVars: pathVars,
|
|
1022
|
+
uriQuery: queryParams,
|
|
1023
|
+
addlHeaders: thisHeaderData
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
try {
|
|
1027
|
+
// Make the call -
|
|
1028
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1029
|
+
return this.requestHandlerInst.identifyRequest('CarrierInfo', 'getCarrierServiceRules', reqObj, true, (irReturnData, irReturnError) => {
|
|
1030
|
+
// if we received an error or their is no response on the results
|
|
1031
|
+
// return an error
|
|
1032
|
+
if (irReturnError) {
|
|
1033
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1034
|
+
return callback(null, irReturnError);
|
|
1035
|
+
}
|
|
1036
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1037
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getCarrierServiceRules'], null, null, null);
|
|
1038
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1039
|
+
return callback(null, errorObj);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1043
|
+
// return the response
|
|
1044
|
+
return callback(irReturnData, null);
|
|
1045
|
+
});
|
|
1046
|
+
} catch (ex) {
|
|
1047
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1048
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1049
|
+
return callback(null, errorObj);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* @function getCarrierLicenseAgreement
|
|
1055
|
+
* @pronghornType method
|
|
1056
|
+
* @name getCarrierLicenseAgreement
|
|
1057
|
+
* @summary getCarrierLicenseAgreement
|
|
1058
|
+
*
|
|
1059
|
+
* @param {} carrier - The carrier name. Currently this must be set to: UPS
|
|
1060
|
+
* @param {} originCountryCode - The two-character ISO country code for the country where the shipment originates.
|
|
1061
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1062
|
+
* @return {object} results - An object containing the response of the action
|
|
1063
|
+
*
|
|
1064
|
+
* @route {POST} /getCarrierLicenseAgreement
|
|
1065
|
+
* @roles admin
|
|
1066
|
+
* @task true
|
|
1067
|
+
*/
|
|
1068
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1069
|
+
getCarrierLicenseAgreement(carrier, originCountryCode, callback) {
|
|
1070
|
+
const meth = 'adapter-getCarrierLicenseAgreement';
|
|
1071
|
+
const origin = `${this.id}-${meth}`;
|
|
1072
|
+
log.trace(origin);
|
|
1073
|
+
|
|
1074
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1075
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1076
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1077
|
+
return callback(null, errorObj);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1081
|
+
if (carrier === undefined || carrier === null || carrier === '') {
|
|
1082
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['carrier'], null, null, null);
|
|
1083
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1084
|
+
return callback(null, errorObj);
|
|
1085
|
+
}
|
|
1086
|
+
if (originCountryCode === undefined || originCountryCode === null || originCountryCode === '') {
|
|
1087
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['originCountryCode'], null, null, null);
|
|
1088
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1089
|
+
return callback(null, errorObj);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1093
|
+
const queryParamsAvailable = { carrier, originCountryCode };
|
|
1094
|
+
const queryParams = {};
|
|
1095
|
+
const pathVars = [];
|
|
1096
|
+
const bodyVars = {};
|
|
1097
|
+
|
|
1098
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1099
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1100
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1101
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1102
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1107
|
+
let thisHeaderData = null;
|
|
1108
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1109
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1110
|
+
try {
|
|
1111
|
+
// parse the additional headers object that was passed in
|
|
1112
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1113
|
+
} catch (err) {
|
|
1114
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1115
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1116
|
+
return callback(null, errorObj);
|
|
1117
|
+
}
|
|
1118
|
+
} else if (thisHeaderData === null) {
|
|
1119
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1123
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1124
|
+
const reqObj = {
|
|
1125
|
+
payload: bodyVars,
|
|
1126
|
+
uriPathVars: pathVars,
|
|
1127
|
+
uriQuery: queryParams,
|
|
1128
|
+
addlHeaders: thisHeaderData
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
try {
|
|
1132
|
+
// Make the call -
|
|
1133
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1134
|
+
return this.requestHandlerInst.identifyRequest('CarrierInfo', 'getCarrierLicenseAgreement', reqObj, true, (irReturnData, irReturnError) => {
|
|
1135
|
+
// if we received an error or their is no response on the results
|
|
1136
|
+
// return an error
|
|
1137
|
+
if (irReturnError) {
|
|
1138
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1139
|
+
return callback(null, irReturnError);
|
|
1140
|
+
}
|
|
1141
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1142
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getCarrierLicenseAgreement'], null, null, null);
|
|
1143
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1144
|
+
return callback(null, errorObj);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1148
|
+
// return the response
|
|
1149
|
+
return callback(irReturnData, null);
|
|
1150
|
+
});
|
|
1151
|
+
} catch (ex) {
|
|
1152
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1153
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1154
|
+
return callback(null, errorObj);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* @function getCarrierSupportedDestination
|
|
1160
|
+
* @pronghornType method
|
|
1161
|
+
* @name getCarrierSupportedDestination
|
|
1162
|
+
* @summary getCarrierSupportedDestination
|
|
1163
|
+
*
|
|
1164
|
+
* @param {} carrier - The carrier name. Currently this must be set to: USPS
|
|
1165
|
+
* @param {} originCountryCode - The two-character ISO country code for the country where the shipment originates.
|
|
1166
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1167
|
+
* @return {object} results - An object containing the response of the action
|
|
1168
|
+
*
|
|
1169
|
+
* @route {POST} /getCarrierSupportedDestination
|
|
1170
|
+
* @roles admin
|
|
1171
|
+
* @task true
|
|
1172
|
+
*/
|
|
1173
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1174
|
+
getCarrierSupportedDestination(carrier, originCountryCode, callback) {
|
|
1175
|
+
const meth = 'adapter-getCarrierSupportedDestination';
|
|
1176
|
+
const origin = `${this.id}-${meth}`;
|
|
1177
|
+
log.trace(origin);
|
|
1178
|
+
|
|
1179
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1180
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1181
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1182
|
+
return callback(null, errorObj);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1186
|
+
if (carrier === undefined || carrier === null || carrier === '') {
|
|
1187
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['carrier'], null, null, null);
|
|
1188
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1189
|
+
return callback(null, errorObj);
|
|
1190
|
+
}
|
|
1191
|
+
if (originCountryCode === undefined || originCountryCode === null || originCountryCode === '') {
|
|
1192
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['originCountryCode'], null, null, null);
|
|
1193
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1194
|
+
return callback(null, errorObj);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1198
|
+
const queryParamsAvailable = { carrier, originCountryCode };
|
|
1199
|
+
const queryParams = {};
|
|
1200
|
+
const pathVars = [];
|
|
1201
|
+
const bodyVars = {};
|
|
1202
|
+
|
|
1203
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1204
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1205
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1206
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1207
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1212
|
+
let thisHeaderData = null;
|
|
1213
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1214
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1215
|
+
try {
|
|
1216
|
+
// parse the additional headers object that was passed in
|
|
1217
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1220
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1221
|
+
return callback(null, errorObj);
|
|
1222
|
+
}
|
|
1223
|
+
} else if (thisHeaderData === null) {
|
|
1224
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1228
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1229
|
+
const reqObj = {
|
|
1230
|
+
payload: bodyVars,
|
|
1231
|
+
uriPathVars: pathVars,
|
|
1232
|
+
uriQuery: queryParams,
|
|
1233
|
+
addlHeaders: thisHeaderData
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
try {
|
|
1237
|
+
// Make the call -
|
|
1238
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1239
|
+
return this.requestHandlerInst.identifyRequest('CarrierInfo', 'getCarrierSupportedDestination', reqObj, true, (irReturnData, irReturnError) => {
|
|
1240
|
+
// if we received an error or their is no response on the results
|
|
1241
|
+
// return an error
|
|
1242
|
+
if (irReturnError) {
|
|
1243
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1244
|
+
return callback(null, irReturnError);
|
|
1245
|
+
}
|
|
1246
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1247
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getCarrierSupportedDestination'], null, null, null);
|
|
1248
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1249
|
+
return callback(null, errorObj);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1253
|
+
// return the response
|
|
1254
|
+
return callback(irReturnData, null);
|
|
1255
|
+
});
|
|
1256
|
+
} catch (ex) {
|
|
1257
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1258
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1259
|
+
return callback(null, errorObj);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* @function getCarrierFacilities
|
|
1265
|
+
* @pronghornType method
|
|
1266
|
+
* @name getCarrierFacilities
|
|
1267
|
+
* @summary getCarrierFacilities
|
|
1268
|
+
*
|
|
1269
|
+
* @param {object} body - body param
|
|
1270
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1271
|
+
* @return {object} results - An object containing the response of the action
|
|
1272
|
+
*
|
|
1273
|
+
* @route {POST} /getCarrierFacilities
|
|
1274
|
+
* @roles admin
|
|
1275
|
+
* @task true
|
|
1276
|
+
*/
|
|
1277
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1278
|
+
getCarrierFacilities(body, callback) {
|
|
1279
|
+
const meth = 'adapter-getCarrierFacilities';
|
|
1280
|
+
const origin = `${this.id}-${meth}`;
|
|
1281
|
+
log.trace(origin);
|
|
1282
|
+
|
|
1283
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1284
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1285
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1286
|
+
return callback(null, errorObj);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1290
|
+
if (body === undefined || body === null || body === '') {
|
|
1291
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
1292
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1293
|
+
return callback(null, errorObj);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1297
|
+
const queryParamsAvailable = {};
|
|
1298
|
+
const queryParams = {};
|
|
1299
|
+
const pathVars = [];
|
|
1300
|
+
const bodyVars = body;
|
|
1301
|
+
|
|
1302
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1303
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1304
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1305
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1306
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1307
|
+
}
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1311
|
+
let thisHeaderData = null;
|
|
1312
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1313
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1314
|
+
try {
|
|
1315
|
+
// parse the additional headers object that was passed in
|
|
1316
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1317
|
+
} catch (err) {
|
|
1318
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1319
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1320
|
+
return callback(null, errorObj);
|
|
1321
|
+
}
|
|
1322
|
+
} else if (thisHeaderData === null) {
|
|
1323
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1327
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1328
|
+
const reqObj = {
|
|
1329
|
+
payload: bodyVars,
|
|
1330
|
+
uriPathVars: pathVars,
|
|
1331
|
+
uriQuery: queryParams,
|
|
1332
|
+
addlHeaders: thisHeaderData
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
try {
|
|
1336
|
+
// Make the call -
|
|
1337
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1338
|
+
return this.requestHandlerInst.identifyRequest('CarrierInfo', 'getCarrierFacilities', reqObj, true, (irReturnData, irReturnError) => {
|
|
1339
|
+
// if we received an error or their is no response on the results
|
|
1340
|
+
// return an error
|
|
1341
|
+
if (irReturnError) {
|
|
1342
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1343
|
+
return callback(null, irReturnError);
|
|
1344
|
+
}
|
|
1345
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1346
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getCarrierFacilities'], null, null, null);
|
|
1347
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1348
|
+
return callback(null, errorObj);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1352
|
+
// return the response
|
|
1353
|
+
return callback(irReturnData, null);
|
|
1354
|
+
});
|
|
1355
|
+
} catch (ex) {
|
|
1356
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1357
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1358
|
+
return callback(null, errorObj);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* @function rateParcel
|
|
1364
|
+
* @pronghornType method
|
|
1365
|
+
* @name rateParcel
|
|
1366
|
+
* @summary rateParcel
|
|
1367
|
+
*
|
|
1368
|
+
* @param {boolean} [includeDeliveryCommitment] - When set to true, returns estimated transit time in days.
|
|
1369
|
+
* @param {string} [carrier] - Cross-Border only. Required for PB Cross-Border. Set this to PBI.
|
|
1370
|
+
* @param {object} body - Shipment request for Rates
|
|
1371
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1372
|
+
* @return {object} results - An object containing the response of the action
|
|
1373
|
+
*
|
|
1374
|
+
* @route {POST} /rateParcel
|
|
1375
|
+
* @roles admin
|
|
1376
|
+
* @task true
|
|
1377
|
+
*/
|
|
1378
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1379
|
+
rateParcel(xPBShipperRatePlan, xPBIntegratorCarrierId, xPBShipperCarrierAccountId, includeDeliveryCommitment, carrier, body, callback) {
|
|
1380
|
+
const meth = 'adapter-rateParcel';
|
|
1381
|
+
const origin = `${this.id}-${meth}`;
|
|
1382
|
+
log.trace(origin);
|
|
1383
|
+
|
|
1384
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1385
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1386
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1387
|
+
return callback(null, errorObj);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1391
|
+
if (body === undefined || body === null || body === '') {
|
|
1392
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
1393
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1394
|
+
return callback(null, errorObj);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1398
|
+
const queryParamsAvailable = { includeDeliveryCommitment, carrier };
|
|
1399
|
+
const queryParams = {};
|
|
1400
|
+
const pathVars = [];
|
|
1401
|
+
const bodyVars = body;
|
|
1402
|
+
|
|
1403
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1404
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1405
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1406
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1407
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
|
|
1411
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1412
|
+
let thisHeaderData = null;
|
|
1413
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1414
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1415
|
+
try {
|
|
1416
|
+
// parse the additional headers object that was passed in
|
|
1417
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1418
|
+
} catch (err) {
|
|
1419
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1420
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1421
|
+
return callback(null, errorObj);
|
|
1422
|
+
}
|
|
1423
|
+
} else if (thisHeaderData === null) {
|
|
1424
|
+
thisHeaderData = {
|
|
1425
|
+
'X-PB-Shipper-Rate-Plan': xPBShipperRatePlan,
|
|
1426
|
+
'X-PB-Integrator-CarrierId': xPBIntegratorCarrierId,
|
|
1427
|
+
'X-PB-Shipper-Carrier-AccountId': xPBShipperCarrierAccountId
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1432
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1433
|
+
const reqObj = {
|
|
1434
|
+
payload: bodyVars,
|
|
1435
|
+
uriPathVars: pathVars,
|
|
1436
|
+
uriQuery: queryParams,
|
|
1437
|
+
addlHeaders: thisHeaderData
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
try {
|
|
1441
|
+
// Make the call -
|
|
1442
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1443
|
+
return this.requestHandlerInst.identifyRequest('RateParcels', 'rateParcel', reqObj, true, (irReturnData, irReturnError) => {
|
|
1444
|
+
// if we received an error or their is no response on the results
|
|
1445
|
+
// return an error
|
|
1446
|
+
if (irReturnError) {
|
|
1447
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1448
|
+
return callback(null, irReturnError);
|
|
1449
|
+
}
|
|
1450
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1451
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['rateParcel'], null, null, null);
|
|
1452
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1453
|
+
return callback(null, errorObj);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1457
|
+
// return the response
|
|
1458
|
+
return callback(irReturnData, null);
|
|
1459
|
+
});
|
|
1460
|
+
} catch (ex) {
|
|
1461
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1462
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1463
|
+
return callback(null, errorObj);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* @function createShipmentLabel
|
|
1469
|
+
* @pronghornType method
|
|
1470
|
+
* @name createShipmentLabel
|
|
1471
|
+
* @summary createShipmentLabel
|
|
1472
|
+
*
|
|
1473
|
+
* @param {string} [includeDeliveryCommitment] - If set to true, returns estimated transit times in days. Only for USPS Create Shipment. See also [Pitney Bowes Delivery Guarantee](https://shipping.pitneybowes.com/faqs/d...(description truncated)
|
|
1474
|
+
* @param {object} body - request
|
|
1475
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1476
|
+
* @return {object} results - An object containing the response of the action
|
|
1477
|
+
*
|
|
1478
|
+
* @route {POST} /createShipmentLabel
|
|
1479
|
+
* @roles admin
|
|
1480
|
+
* @task true
|
|
1481
|
+
*/
|
|
1482
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1483
|
+
createShipmentLabel(xPBTransactionId, xPBIntegratorCarrierId, xPBShipperRatePlan, xPBShipmentGroupId, xPBShipperCarrierAccountId, includeDeliveryCommitment, body, callback) {
|
|
1484
|
+
const meth = 'adapter-createShipmentLabel';
|
|
1485
|
+
const origin = `${this.id}-${meth}`;
|
|
1486
|
+
log.trace(origin);
|
|
1487
|
+
|
|
1488
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1489
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1490
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1491
|
+
return callback(null, errorObj);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1495
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
1496
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
1497
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1498
|
+
return callback(null, errorObj);
|
|
1499
|
+
}
|
|
1500
|
+
if (body === undefined || body === null || body === '') {
|
|
1501
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
1502
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1503
|
+
return callback(null, errorObj);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1507
|
+
const queryParamsAvailable = { includeDeliveryCommitment };
|
|
1508
|
+
const queryParams = {};
|
|
1509
|
+
const pathVars = [];
|
|
1510
|
+
const bodyVars = body;
|
|
1511
|
+
|
|
1512
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1513
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1514
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1515
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1516
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1521
|
+
let thisHeaderData = null;
|
|
1522
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1523
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1524
|
+
try {
|
|
1525
|
+
// parse the additional headers object that was passed in
|
|
1526
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1527
|
+
} catch (err) {
|
|
1528
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1529
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1530
|
+
return callback(null, errorObj);
|
|
1531
|
+
}
|
|
1532
|
+
} else if (thisHeaderData === null) {
|
|
1533
|
+
thisHeaderData = {
|
|
1534
|
+
'X-PB-TransactionId': xPBTransactionId,
|
|
1535
|
+
'X-PB-Integrator-CarrierId': xPBIntegratorCarrierId,
|
|
1536
|
+
'X-PB-Shipper-Rate-Plan': xPBShipperRatePlan,
|
|
1537
|
+
'X-PB-ShipmentGroupId': xPBShipmentGroupId,
|
|
1538
|
+
'X-PB-Shipper-Carrier-AccountId': xPBShipperCarrierAccountId
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1543
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1544
|
+
const reqObj = {
|
|
1545
|
+
payload: bodyVars,
|
|
1546
|
+
uriPathVars: pathVars,
|
|
1547
|
+
uriQuery: queryParams,
|
|
1548
|
+
addlHeaders: thisHeaderData
|
|
1549
|
+
};
|
|
1550
|
+
|
|
1551
|
+
try {
|
|
1552
|
+
// Make the call -
|
|
1553
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1554
|
+
return this.requestHandlerInst.identifyRequest('Shipment', 'createShipmentLabel', reqObj, true, (irReturnData, irReturnError) => {
|
|
1555
|
+
// if we received an error or their is no response on the results
|
|
1556
|
+
// return an error
|
|
1557
|
+
if (irReturnError) {
|
|
1558
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1559
|
+
return callback(null, irReturnError);
|
|
1560
|
+
}
|
|
1561
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1562
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createShipmentLabel'], null, null, null);
|
|
1563
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1564
|
+
return callback(null, errorObj);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1568
|
+
// return the response
|
|
1569
|
+
return callback(irReturnData, null);
|
|
1570
|
+
});
|
|
1571
|
+
} catch (ex) {
|
|
1572
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1573
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1574
|
+
return callback(null, errorObj);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* @function retryShipment
|
|
1580
|
+
* @pronghornType method
|
|
1581
|
+
* @name retryShipment
|
|
1582
|
+
* @summary retryShipment
|
|
1583
|
+
*
|
|
1584
|
+
* @param {string} originalTransactionId - originalTransactionId param
|
|
1585
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1586
|
+
* @return {object} results - An object containing the response of the action
|
|
1587
|
+
*
|
|
1588
|
+
* @route {POST} /retryShipment
|
|
1589
|
+
* @roles admin
|
|
1590
|
+
* @task true
|
|
1591
|
+
*/
|
|
1592
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1593
|
+
retryShipment(originalTransactionId, callback) {
|
|
1594
|
+
const meth = 'adapter-retryShipment';
|
|
1595
|
+
const origin = `${this.id}-${meth}`;
|
|
1596
|
+
log.trace(origin);
|
|
1597
|
+
|
|
1598
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1599
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1600
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1601
|
+
return callback(null, errorObj);
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1605
|
+
if (originalTransactionId === undefined || originalTransactionId === null || originalTransactionId === '') {
|
|
1606
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['originalTransactionId'], null, null, null);
|
|
1607
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1608
|
+
return callback(null, errorObj);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1612
|
+
const queryParamsAvailable = { originalTransactionId };
|
|
1613
|
+
const queryParams = {};
|
|
1614
|
+
const pathVars = [];
|
|
1615
|
+
const bodyVars = {};
|
|
1616
|
+
|
|
1617
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1618
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1619
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1620
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1621
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1626
|
+
let thisHeaderData = null;
|
|
1627
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1628
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1629
|
+
try {
|
|
1630
|
+
// parse the additional headers object that was passed in
|
|
1631
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1632
|
+
} catch (err) {
|
|
1633
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1634
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1635
|
+
return callback(null, errorObj);
|
|
1636
|
+
}
|
|
1637
|
+
} else if (thisHeaderData === null) {
|
|
1638
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '', carrier: '' };
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1642
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1643
|
+
const reqObj = {
|
|
1644
|
+
payload: bodyVars,
|
|
1645
|
+
uriPathVars: pathVars,
|
|
1646
|
+
uriQuery: queryParams,
|
|
1647
|
+
addlHeaders: thisHeaderData
|
|
1648
|
+
};
|
|
1649
|
+
|
|
1650
|
+
try {
|
|
1651
|
+
// Make the call -
|
|
1652
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1653
|
+
return this.requestHandlerInst.identifyRequest('Shipment', 'retryShipment', reqObj, true, (irReturnData, irReturnError) => {
|
|
1654
|
+
// if we received an error or their is no response on the results
|
|
1655
|
+
// return an error
|
|
1656
|
+
if (irReturnError) {
|
|
1657
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1658
|
+
return callback(null, irReturnError);
|
|
1659
|
+
}
|
|
1660
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1661
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['retryShipment'], null, null, null);
|
|
1662
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1663
|
+
return callback(null, errorObj);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1667
|
+
// return the response
|
|
1668
|
+
return callback(irReturnData, null);
|
|
1669
|
+
});
|
|
1670
|
+
} catch (ex) {
|
|
1671
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1672
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1673
|
+
return callback(null, errorObj);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* @function reprintShipment
|
|
1679
|
+
* @pronghornType method
|
|
1680
|
+
* @name reprintShipment
|
|
1681
|
+
* @summary reprintShipment
|
|
1682
|
+
*
|
|
1683
|
+
* @param {string} shipmentId - Required. The shipment ID that was issued when shipment label was generated.
|
|
1684
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1685
|
+
* @return {object} results - An object containing the response of the action
|
|
1686
|
+
*
|
|
1687
|
+
* @route {POST} /reprintShipment
|
|
1688
|
+
* @roles admin
|
|
1689
|
+
* @task true
|
|
1690
|
+
*/
|
|
1691
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1692
|
+
reprintShipment(shipmentId, callback) {
|
|
1693
|
+
const meth = 'adapter-reprintShipment';
|
|
1694
|
+
const origin = `${this.id}-${meth}`;
|
|
1695
|
+
log.trace(origin);
|
|
1696
|
+
|
|
1697
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1698
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1699
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1700
|
+
return callback(null, errorObj);
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1704
|
+
if (shipmentId === undefined || shipmentId === null || shipmentId === '') {
|
|
1705
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['shipmentId'], null, null, null);
|
|
1706
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1707
|
+
return callback(null, errorObj);
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1711
|
+
const queryParamsAvailable = {};
|
|
1712
|
+
const queryParams = {};
|
|
1713
|
+
const pathVars = [shipmentId];
|
|
1714
|
+
const bodyVars = {};
|
|
1715
|
+
|
|
1716
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1717
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1718
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1719
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1720
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1725
|
+
let thisHeaderData = null;
|
|
1726
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1727
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1728
|
+
try {
|
|
1729
|
+
// parse the additional headers object that was passed in
|
|
1730
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1733
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1734
|
+
return callback(null, errorObj);
|
|
1735
|
+
}
|
|
1736
|
+
} else if (thisHeaderData === null) {
|
|
1737
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '', carrier: '' };
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1741
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1742
|
+
const reqObj = {
|
|
1743
|
+
payload: bodyVars,
|
|
1744
|
+
uriPathVars: pathVars,
|
|
1745
|
+
uriQuery: queryParams,
|
|
1746
|
+
addlHeaders: thisHeaderData
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
try {
|
|
1750
|
+
// Make the call -
|
|
1751
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1752
|
+
return this.requestHandlerInst.identifyRequest('Shipment', 'reprintShipment', reqObj, true, (irReturnData, irReturnError) => {
|
|
1753
|
+
// if we received an error or their is no response on the results
|
|
1754
|
+
// return an error
|
|
1755
|
+
if (irReturnError) {
|
|
1756
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1757
|
+
return callback(null, irReturnError);
|
|
1758
|
+
}
|
|
1759
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1760
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['reprintShipment'], null, null, null);
|
|
1761
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1762
|
+
return callback(null, errorObj);
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1766
|
+
// return the response
|
|
1767
|
+
return callback(irReturnData, null);
|
|
1768
|
+
});
|
|
1769
|
+
} catch (ex) {
|
|
1770
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1771
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1772
|
+
return callback(null, errorObj);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* @function cancelShipment
|
|
1778
|
+
* @pronghornType method
|
|
1779
|
+
* @name cancelShipment
|
|
1780
|
+
* @summary cancelShipment
|
|
1781
|
+
*
|
|
1782
|
+
* @param {string} [cancelInitiator] - Indicates that this refund request is initiated by the shipper. Set this to: SHIPPER
|
|
1783
|
+
* @param {} [carrier] - Conditional. The carrier. This is required if the carrier is not USPS
|
|
1784
|
+
* @param {string} shipmentId - shipmentId
|
|
1785
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1786
|
+
* @return {object} results - An object containing the response of the action
|
|
1787
|
+
*
|
|
1788
|
+
* @route {POST} /cancelShipment
|
|
1789
|
+
* @roles admin
|
|
1790
|
+
* @task true
|
|
1791
|
+
*/
|
|
1792
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1793
|
+
cancelShipment(xPBTransactionId, xPBShipperCarrierAccountId, cancelInitiator, carrier, shipmentId, callback) {
|
|
1794
|
+
const meth = 'adapter-cancelShipment';
|
|
1795
|
+
const origin = `${this.id}-${meth}`;
|
|
1796
|
+
log.trace(origin);
|
|
1797
|
+
|
|
1798
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1799
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1800
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1801
|
+
return callback(null, errorObj);
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1805
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
1806
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
1807
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1808
|
+
return callback(null, errorObj);
|
|
1809
|
+
}
|
|
1810
|
+
if (shipmentId === undefined || shipmentId === null || shipmentId === '') {
|
|
1811
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['shipmentId'], null, null, null);
|
|
1812
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1813
|
+
return callback(null, errorObj);
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1817
|
+
const queryParamsAvailable = { cancelInitiator, carrier };
|
|
1818
|
+
const queryParams = {};
|
|
1819
|
+
const pathVars = [shipmentId];
|
|
1820
|
+
const bodyVars = {};
|
|
1821
|
+
|
|
1822
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1823
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1824
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1825
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1826
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1827
|
+
}
|
|
1828
|
+
});
|
|
1829
|
+
|
|
1830
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1831
|
+
let thisHeaderData = null;
|
|
1832
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1833
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1834
|
+
try {
|
|
1835
|
+
// parse the additional headers object that was passed in
|
|
1836
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1837
|
+
} catch (err) {
|
|
1838
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1839
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1840
|
+
return callback(null, errorObj);
|
|
1841
|
+
}
|
|
1842
|
+
} else if (thisHeaderData === null) {
|
|
1843
|
+
thisHeaderData = {
|
|
1844
|
+
'X-PB-TransactionId': xPBTransactionId,
|
|
1845
|
+
'X-PB-Shipper-Carrier-AccountId': xPBShipperCarrierAccountId
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1850
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1851
|
+
const reqObj = {
|
|
1852
|
+
payload: bodyVars,
|
|
1853
|
+
uriPathVars: pathVars,
|
|
1854
|
+
uriQuery: queryParams,
|
|
1855
|
+
addlHeaders: thisHeaderData
|
|
1856
|
+
};
|
|
1857
|
+
|
|
1858
|
+
try {
|
|
1859
|
+
// Make the call -
|
|
1860
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1861
|
+
return this.requestHandlerInst.identifyRequest('Shipment', 'cancelShipment', reqObj, false, (irReturnData, irReturnError) => {
|
|
1862
|
+
// if we received an error or their is no response on the results
|
|
1863
|
+
// return an error
|
|
1864
|
+
if (irReturnError) {
|
|
1865
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1866
|
+
return callback(null, irReturnError);
|
|
1867
|
+
}
|
|
1868
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1869
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['cancelShipment'], null, null, null);
|
|
1870
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1871
|
+
return callback(null, errorObj);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1875
|
+
// return the response
|
|
1876
|
+
return callback(irReturnData, null);
|
|
1877
|
+
});
|
|
1878
|
+
} catch (ex) {
|
|
1879
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1880
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1881
|
+
return callback(null, errorObj);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* @function createManifest
|
|
1887
|
+
* @pronghornType method
|
|
1888
|
+
* @name createManifest
|
|
1889
|
+
* @summary createManifest
|
|
1890
|
+
*
|
|
1891
|
+
* @param {object} body - manifest
|
|
1892
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1893
|
+
* @return {object} results - An object containing the response of the action
|
|
1894
|
+
*
|
|
1895
|
+
* @route {POST} /createManifest
|
|
1896
|
+
* @roles admin
|
|
1897
|
+
* @task true
|
|
1898
|
+
*/
|
|
1899
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1900
|
+
createManifest(xPBTransactionId, body, callback) {
|
|
1901
|
+
const meth = 'adapter-createManifest';
|
|
1902
|
+
const origin = `${this.id}-${meth}`;
|
|
1903
|
+
log.trace(origin);
|
|
1904
|
+
|
|
1905
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1906
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1907
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1908
|
+
return callback(null, errorObj);
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1912
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
1913
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
1914
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1915
|
+
return callback(null, errorObj);
|
|
1916
|
+
}
|
|
1917
|
+
if (body === undefined || body === null || body === '') {
|
|
1918
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
1919
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1920
|
+
return callback(null, errorObj);
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1924
|
+
const queryParamsAvailable = {};
|
|
1925
|
+
const queryParams = {};
|
|
1926
|
+
const pathVars = [];
|
|
1927
|
+
const bodyVars = body;
|
|
1928
|
+
|
|
1929
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1930
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1931
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1932
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1933
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1934
|
+
}
|
|
1935
|
+
});
|
|
1936
|
+
|
|
1937
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
1938
|
+
let thisHeaderData = null;
|
|
1939
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
1940
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
1941
|
+
try {
|
|
1942
|
+
// parse the additional headers object that was passed in
|
|
1943
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
1944
|
+
} catch (err) {
|
|
1945
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
1946
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1947
|
+
return callback(null, errorObj);
|
|
1948
|
+
}
|
|
1949
|
+
} else if (thisHeaderData === null) {
|
|
1950
|
+
thisHeaderData = {
|
|
1951
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1956
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1957
|
+
const reqObj = {
|
|
1958
|
+
payload: bodyVars,
|
|
1959
|
+
uriPathVars: pathVars,
|
|
1960
|
+
uriQuery: queryParams,
|
|
1961
|
+
addlHeaders: thisHeaderData
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
try {
|
|
1965
|
+
// Make the call -
|
|
1966
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1967
|
+
return this.requestHandlerInst.identifyRequest('Manifests', 'createManifest', reqObj, true, (irReturnData, irReturnError) => {
|
|
1968
|
+
// if we received an error or their is no response on the results
|
|
1969
|
+
// return an error
|
|
1970
|
+
if (irReturnError) {
|
|
1971
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1972
|
+
return callback(null, irReturnError);
|
|
1973
|
+
}
|
|
1974
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1975
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createManifest'], null, null, null);
|
|
1976
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1977
|
+
return callback(null, errorObj);
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1981
|
+
// return the response
|
|
1982
|
+
return callback(irReturnData, null);
|
|
1983
|
+
});
|
|
1984
|
+
} catch (ex) {
|
|
1985
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1986
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1987
|
+
return callback(null, errorObj);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* @function retryManifest
|
|
1993
|
+
* @pronghornType method
|
|
1994
|
+
* @name retryManifest
|
|
1995
|
+
* @summary retryManifest
|
|
1996
|
+
*
|
|
1997
|
+
* @param {string} originalTransactionId - originalTransactionId param
|
|
1998
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1999
|
+
* @return {object} results - An object containing the response of the action
|
|
2000
|
+
*
|
|
2001
|
+
* @route {POST} /retryManifest
|
|
2002
|
+
* @roles admin
|
|
2003
|
+
* @task true
|
|
2004
|
+
*/
|
|
2005
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2006
|
+
retryManifest(originalTransactionId, callback) {
|
|
2007
|
+
const meth = 'adapter-retryManifest';
|
|
2008
|
+
const origin = `${this.id}-${meth}`;
|
|
2009
|
+
log.trace(origin);
|
|
2010
|
+
|
|
2011
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2012
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2013
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2014
|
+
return callback(null, errorObj);
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2018
|
+
if (originalTransactionId === undefined || originalTransactionId === null || originalTransactionId === '') {
|
|
2019
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['originalTransactionId'], null, null, null);
|
|
2020
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2021
|
+
return callback(null, errorObj);
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2025
|
+
const queryParamsAvailable = { originalTransactionId };
|
|
2026
|
+
const queryParams = {};
|
|
2027
|
+
const pathVars = [];
|
|
2028
|
+
const bodyVars = {};
|
|
2029
|
+
|
|
2030
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2031
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2032
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2033
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2034
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2035
|
+
}
|
|
2036
|
+
});
|
|
2037
|
+
|
|
2038
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2039
|
+
let thisHeaderData = null;
|
|
2040
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2041
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2042
|
+
try {
|
|
2043
|
+
// parse the additional headers object that was passed in
|
|
2044
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2045
|
+
} catch (err) {
|
|
2046
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2047
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2048
|
+
return callback(null, errorObj);
|
|
2049
|
+
}
|
|
2050
|
+
} else if (thisHeaderData === null) {
|
|
2051
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2055
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2056
|
+
const reqObj = {
|
|
2057
|
+
payload: bodyVars,
|
|
2058
|
+
uriPathVars: pathVars,
|
|
2059
|
+
uriQuery: queryParams,
|
|
2060
|
+
addlHeaders: thisHeaderData
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
try {
|
|
2064
|
+
// Make the call -
|
|
2065
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2066
|
+
return this.requestHandlerInst.identifyRequest('Manifests', 'retryManifest', reqObj, true, (irReturnData, irReturnError) => {
|
|
2067
|
+
// if we received an error or their is no response on the results
|
|
2068
|
+
// return an error
|
|
2069
|
+
if (irReturnError) {
|
|
2070
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2071
|
+
return callback(null, irReturnError);
|
|
2072
|
+
}
|
|
2073
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2074
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['retryManifest'], null, null, null);
|
|
2075
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2076
|
+
return callback(null, errorObj);
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2080
|
+
// return the response
|
|
2081
|
+
return callback(irReturnData, null);
|
|
2082
|
+
});
|
|
2083
|
+
} catch (ex) {
|
|
2084
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2085
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2086
|
+
return callback(null, errorObj);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
/**
|
|
2091
|
+
* @function reprintManifest
|
|
2092
|
+
* @pronghornType method
|
|
2093
|
+
* @name reprintManifest
|
|
2094
|
+
* @summary reprintManifest
|
|
2095
|
+
*
|
|
2096
|
+
* @param {string} manifestId - manifestId
|
|
2097
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2098
|
+
* @return {object} results - An object containing the response of the action
|
|
2099
|
+
*
|
|
2100
|
+
* @route {POST} /reprintManifest
|
|
2101
|
+
* @roles admin
|
|
2102
|
+
* @task true
|
|
2103
|
+
*/
|
|
2104
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2105
|
+
reprintManifest(manifestId, callback) {
|
|
2106
|
+
const meth = 'adapter-reprintManifest';
|
|
2107
|
+
const origin = `${this.id}-${meth}`;
|
|
2108
|
+
log.trace(origin);
|
|
2109
|
+
|
|
2110
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2111
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2112
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2113
|
+
return callback(null, errorObj);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2117
|
+
if (manifestId === undefined || manifestId === null || manifestId === '') {
|
|
2118
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['manifestId'], null, null, null);
|
|
2119
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2120
|
+
return callback(null, errorObj);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2124
|
+
const queryParamsAvailable = {};
|
|
2125
|
+
const queryParams = {};
|
|
2126
|
+
const pathVars = [manifestId];
|
|
2127
|
+
const bodyVars = {};
|
|
2128
|
+
|
|
2129
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2130
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2131
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2132
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2133
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
|
|
2137
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2138
|
+
let thisHeaderData = null;
|
|
2139
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2140
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2141
|
+
try {
|
|
2142
|
+
// parse the additional headers object that was passed in
|
|
2143
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2144
|
+
} catch (err) {
|
|
2145
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2146
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2147
|
+
return callback(null, errorObj);
|
|
2148
|
+
}
|
|
2149
|
+
} else if (thisHeaderData === null) {
|
|
2150
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2154
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2155
|
+
const reqObj = {
|
|
2156
|
+
payload: bodyVars,
|
|
2157
|
+
uriPathVars: pathVars,
|
|
2158
|
+
uriQuery: queryParams,
|
|
2159
|
+
addlHeaders: thisHeaderData
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2162
|
+
try {
|
|
2163
|
+
// Make the call -
|
|
2164
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2165
|
+
return this.requestHandlerInst.identifyRequest('Manifests', 'reprintManifest', reqObj, true, (irReturnData, irReturnError) => {
|
|
2166
|
+
// if we received an error or their is no response on the results
|
|
2167
|
+
// return an error
|
|
2168
|
+
if (irReturnError) {
|
|
2169
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2170
|
+
return callback(null, irReturnError);
|
|
2171
|
+
}
|
|
2172
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2173
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['reprintManifest'], null, null, null);
|
|
2174
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2175
|
+
return callback(null, errorObj);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2179
|
+
// return the response
|
|
2180
|
+
return callback(irReturnData, null);
|
|
2181
|
+
});
|
|
2182
|
+
} catch (ex) {
|
|
2183
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2184
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2185
|
+
return callback(null, errorObj);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* @function getTransactionReport
|
|
2191
|
+
* @pronghornType method
|
|
2192
|
+
* @name getTransactionReport
|
|
2193
|
+
* @summary getTransactionReport
|
|
2194
|
+
*
|
|
2195
|
+
* @param {string} developerId - developerId
|
|
2196
|
+
* @param {string} [fromDate] - fromDate
|
|
2197
|
+
* @param {number} [shipDetails] - shipDetails param
|
|
2198
|
+
* @param {number} [page] - page param
|
|
2199
|
+
* @param {number} [size] - size param
|
|
2200
|
+
* @param {} [printStatus] - printStatus
|
|
2201
|
+
* @param {string} [toDate] - toDate
|
|
2202
|
+
* @param {} [transactionType] - transactionType
|
|
2203
|
+
* @param {string} [merchantId] - The value of the postalReportingNumber element in the [merchant object](https://shipping.pitneybowes.com/reference/resource-objects.html). This value is also the merchant...(description truncated)
|
|
2204
|
+
* @param {string} [sort] - Defines a property to sort on and the sort order. Sort order can be ascending (asc) or descending (desc). Use the following form-
|
|
2205
|
+
|
|
2206
|
+
* **sort= , ** For example-
|
|
2207
|
+
**sort=tran...(description truncated)
|
|
2208
|
+
* @param {string} [parcelTrackingNumber] - Parcel tracking number of the shipment.
|
|
2209
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2210
|
+
* @return {object} results - An object containing the response of the action
|
|
2211
|
+
*
|
|
2212
|
+
* @route {POST} /getTransactionReport
|
|
2213
|
+
* @roles admin
|
|
2214
|
+
* @task true
|
|
2215
|
+
*/
|
|
2216
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2217
|
+
getTransactionReport(developerId, fromDate, shipDetails, page, size, printStatus, toDate, transactionType, merchantId, sort, parcelTrackingNumber, callback) {
|
|
2218
|
+
const meth = 'adapter-getTransactionReport';
|
|
2219
|
+
const origin = `${this.id}-${meth}`;
|
|
2220
|
+
log.trace(origin);
|
|
2221
|
+
|
|
2222
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2223
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2224
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2225
|
+
return callback(null, errorObj);
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2229
|
+
if (developerId === undefined || developerId === null || developerId === '') {
|
|
2230
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['developerId'], null, null, null);
|
|
2231
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2232
|
+
return callback(null, errorObj);
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2236
|
+
const queryParamsAvailable = { fromDate, shipDetails, page, size, printStatus, toDate, transactionType, merchantId, sort, parcelTrackingNumber };
|
|
2237
|
+
const queryParams = {};
|
|
2238
|
+
const pathVars = [developerId];
|
|
2239
|
+
const bodyVars = {};
|
|
2240
|
+
|
|
2241
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2242
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2243
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2244
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2245
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
|
|
2249
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2250
|
+
let thisHeaderData = null;
|
|
2251
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2252
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2253
|
+
try {
|
|
2254
|
+
// parse the additional headers object that was passed in
|
|
2255
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2256
|
+
} catch (err) {
|
|
2257
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2258
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2259
|
+
return callback(null, errorObj);
|
|
2260
|
+
}
|
|
2261
|
+
} else if (thisHeaderData === null) {
|
|
2262
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '', transactionId: '' };
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2266
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2267
|
+
const reqObj = {
|
|
2268
|
+
payload: bodyVars,
|
|
2269
|
+
uriPathVars: pathVars,
|
|
2270
|
+
uriQuery: queryParams,
|
|
2271
|
+
addlHeaders: thisHeaderData
|
|
2272
|
+
};
|
|
2273
|
+
|
|
2274
|
+
try {
|
|
2275
|
+
// Make the call -
|
|
2276
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2277
|
+
return this.requestHandlerInst.identifyRequest('TransactionReports', 'getTransactionReport', reqObj, true, (irReturnData, irReturnError) => {
|
|
2278
|
+
// if we received an error or their is no response on the results
|
|
2279
|
+
// return an error
|
|
2280
|
+
if (irReturnError) {
|
|
2281
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2282
|
+
return callback(null, irReturnError);
|
|
2283
|
+
}
|
|
2284
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2285
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getTransactionReport'], null, null, null);
|
|
2286
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2287
|
+
return callback(null, errorObj);
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2291
|
+
// return the response
|
|
2292
|
+
return callback(irReturnData, null);
|
|
2293
|
+
});
|
|
2294
|
+
} catch (ex) {
|
|
2295
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2296
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2297
|
+
return callback(null, errorObj);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
/**
|
|
2302
|
+
* @function getPickupschedule
|
|
2303
|
+
* @pronghornType method
|
|
2304
|
+
* @name getPickupschedule
|
|
2305
|
+
* @summary getPickupschedule
|
|
2306
|
+
*
|
|
2307
|
+
* @param {object} body - Schedule Pickup request.
|
|
2308
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2309
|
+
* @return {object} results - An object containing the response of the action
|
|
2310
|
+
*
|
|
2311
|
+
* @route {POST} /getPickupschedule
|
|
2312
|
+
* @roles admin
|
|
2313
|
+
* @task true
|
|
2314
|
+
*/
|
|
2315
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2316
|
+
getPickupschedule(xPBTransactionId, body, callback) {
|
|
2317
|
+
const meth = 'adapter-getPickupschedule';
|
|
2318
|
+
const origin = `${this.id}-${meth}`;
|
|
2319
|
+
log.trace(origin);
|
|
2320
|
+
|
|
2321
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2322
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2323
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2324
|
+
return callback(null, errorObj);
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2328
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
2329
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
2330
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2331
|
+
return callback(null, errorObj);
|
|
2332
|
+
}
|
|
2333
|
+
if (body === undefined || body === null || body === '') {
|
|
2334
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2335
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2336
|
+
return callback(null, errorObj);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2340
|
+
const queryParamsAvailable = {};
|
|
2341
|
+
const queryParams = {};
|
|
2342
|
+
const pathVars = [];
|
|
2343
|
+
const bodyVars = body;
|
|
2344
|
+
|
|
2345
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2346
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2347
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2348
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2349
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2350
|
+
}
|
|
2351
|
+
});
|
|
2352
|
+
|
|
2353
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2354
|
+
let thisHeaderData = null;
|
|
2355
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2356
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2357
|
+
try {
|
|
2358
|
+
// parse the additional headers object that was passed in
|
|
2359
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2360
|
+
} catch (err) {
|
|
2361
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2362
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2363
|
+
return callback(null, errorObj);
|
|
2364
|
+
}
|
|
2365
|
+
} else if (thisHeaderData === null) {
|
|
2366
|
+
thisHeaderData = {
|
|
2367
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2372
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2373
|
+
const reqObj = {
|
|
2374
|
+
payload: bodyVars,
|
|
2375
|
+
uriPathVars: pathVars,
|
|
2376
|
+
uriQuery: queryParams,
|
|
2377
|
+
addlHeaders: thisHeaderData
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
try {
|
|
2381
|
+
// Make the call -
|
|
2382
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2383
|
+
return this.requestHandlerInst.identifyRequest('Pickup', 'getPickupschedule', reqObj, true, (irReturnData, irReturnError) => {
|
|
2384
|
+
// if we received an error or their is no response on the results
|
|
2385
|
+
// return an error
|
|
2386
|
+
if (irReturnError) {
|
|
2387
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2388
|
+
return callback(null, irReturnError);
|
|
2389
|
+
}
|
|
2390
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2391
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getPickupschedule'], null, null, null);
|
|
2392
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2393
|
+
return callback(null, errorObj);
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2397
|
+
// return the response
|
|
2398
|
+
return callback(irReturnData, null);
|
|
2399
|
+
});
|
|
2400
|
+
} catch (ex) {
|
|
2401
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2402
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2403
|
+
return callback(null, errorObj);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* @function cancelPickup
|
|
2409
|
+
* @pronghornType method
|
|
2410
|
+
* @name cancelPickup
|
|
2411
|
+
* @summary cancelPickup
|
|
2412
|
+
*
|
|
2413
|
+
* @param {string} pickupId - A unique identifier for the transaction, up to 25 characters
|
|
2414
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2415
|
+
* @return {object} results - An object containing the response of the action
|
|
2416
|
+
*
|
|
2417
|
+
* @route {POST} /cancelPickup
|
|
2418
|
+
* @roles admin
|
|
2419
|
+
* @task true
|
|
2420
|
+
*/
|
|
2421
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2422
|
+
cancelPickup(xPBTransactionId, pickupId, callback) {
|
|
2423
|
+
const meth = 'adapter-cancelPickup';
|
|
2424
|
+
const origin = `${this.id}-${meth}`;
|
|
2425
|
+
log.trace(origin);
|
|
2426
|
+
|
|
2427
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2428
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2429
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2430
|
+
return callback(null, errorObj);
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2434
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
2435
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
2436
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2437
|
+
return callback(null, errorObj);
|
|
2438
|
+
}
|
|
2439
|
+
if (pickupId === undefined || pickupId === null || pickupId === '') {
|
|
2440
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['pickupId'], null, null, null);
|
|
2441
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2442
|
+
return callback(null, errorObj);
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2446
|
+
const queryParamsAvailable = {};
|
|
2447
|
+
const queryParams = {};
|
|
2448
|
+
const pathVars = [pickupId];
|
|
2449
|
+
const bodyVars = {};
|
|
2450
|
+
|
|
2451
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2452
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2453
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2454
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2455
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2456
|
+
}
|
|
2457
|
+
});
|
|
2458
|
+
|
|
2459
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2460
|
+
let thisHeaderData = null;
|
|
2461
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2462
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2463
|
+
try {
|
|
2464
|
+
// parse the additional headers object that was passed in
|
|
2465
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2466
|
+
} catch (err) {
|
|
2467
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2468
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2469
|
+
return callback(null, errorObj);
|
|
2470
|
+
}
|
|
2471
|
+
} else if (thisHeaderData === null) {
|
|
2472
|
+
thisHeaderData = {
|
|
2473
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2478
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2479
|
+
const reqObj = {
|
|
2480
|
+
payload: bodyVars,
|
|
2481
|
+
uriPathVars: pathVars,
|
|
2482
|
+
uriQuery: queryParams,
|
|
2483
|
+
addlHeaders: thisHeaderData
|
|
2484
|
+
};
|
|
2485
|
+
|
|
2486
|
+
try {
|
|
2487
|
+
// Make the call -
|
|
2488
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2489
|
+
return this.requestHandlerInst.identifyRequest('Pickup', 'cancelPickup', reqObj, true, (irReturnData, irReturnError) => {
|
|
2490
|
+
// if we received an error or their is no response on the results
|
|
2491
|
+
// return an error
|
|
2492
|
+
if (irReturnError) {
|
|
2493
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2494
|
+
return callback(null, irReturnError);
|
|
2495
|
+
}
|
|
2496
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2497
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['cancelPickup'], null, null, null);
|
|
2498
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2499
|
+
return callback(null, errorObj);
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2503
|
+
// return the response
|
|
2504
|
+
return callback(irReturnData, null);
|
|
2505
|
+
});
|
|
2506
|
+
} catch (ex) {
|
|
2507
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2508
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2509
|
+
return callback(null, errorObj);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
/**
|
|
2514
|
+
* @function verifyAddress
|
|
2515
|
+
* @pronghornType method
|
|
2516
|
+
* @name verifyAddress
|
|
2517
|
+
* @summary verifyAddress
|
|
2518
|
+
*
|
|
2519
|
+
* @param {boolean} [minimalAddressValidation] - When set to true, the complete address (delivery line and last line) is validated but only the last line (city, state, and postal code) would be changed by the validation...(description truncated)
|
|
2520
|
+
* @param {object} body - Address object that needs to be validated.
|
|
2521
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2522
|
+
* @return {object} results - An object containing the response of the action
|
|
2523
|
+
*
|
|
2524
|
+
* @route {POST} /verifyAddress
|
|
2525
|
+
* @roles admin
|
|
2526
|
+
* @task true
|
|
2527
|
+
*/
|
|
2528
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2529
|
+
verifyAddress(minimalAddressValidation, body, callback) {
|
|
2530
|
+
const meth = 'adapter-verifyAddress';
|
|
2531
|
+
const origin = `${this.id}-${meth}`;
|
|
2532
|
+
log.trace(origin);
|
|
2533
|
+
|
|
2534
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2535
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2536
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2537
|
+
return callback(null, errorObj);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2541
|
+
if (body === undefined || body === null || body === '') {
|
|
2542
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2543
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2544
|
+
return callback(null, errorObj);
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2548
|
+
const queryParamsAvailable = { minimalAddressValidation };
|
|
2549
|
+
const queryParams = {};
|
|
2550
|
+
const pathVars = [];
|
|
2551
|
+
const bodyVars = body;
|
|
2552
|
+
|
|
2553
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2554
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2555
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2556
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2557
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
|
|
2561
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2562
|
+
let thisHeaderData = null;
|
|
2563
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2564
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2565
|
+
try {
|
|
2566
|
+
// parse the additional headers object that was passed in
|
|
2567
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2568
|
+
} catch (err) {
|
|
2569
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2570
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2571
|
+
return callback(null, errorObj);
|
|
2572
|
+
}
|
|
2573
|
+
} else if (thisHeaderData === null) {
|
|
2574
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2578
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2579
|
+
const reqObj = {
|
|
2580
|
+
payload: bodyVars,
|
|
2581
|
+
uriPathVars: pathVars,
|
|
2582
|
+
uriQuery: queryParams,
|
|
2583
|
+
addlHeaders: thisHeaderData
|
|
2584
|
+
};
|
|
2585
|
+
|
|
2586
|
+
try {
|
|
2587
|
+
// Make the call -
|
|
2588
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2589
|
+
return this.requestHandlerInst.identifyRequest('AddressValidation', 'verifyAddress', reqObj, true, (irReturnData, irReturnError) => {
|
|
2590
|
+
// if we received an error or their is no response on the results
|
|
2591
|
+
// return an error
|
|
2592
|
+
if (irReturnError) {
|
|
2593
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2594
|
+
return callback(null, irReturnError);
|
|
2595
|
+
}
|
|
2596
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2597
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['verifyAddress'], null, null, null);
|
|
2598
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2599
|
+
return callback(null, errorObj);
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2603
|
+
// return the response
|
|
2604
|
+
return callback(irReturnData, null);
|
|
2605
|
+
});
|
|
2606
|
+
} catch (ex) {
|
|
2607
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2608
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2609
|
+
return callback(null, errorObj);
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
/**
|
|
2614
|
+
* @function verifyAndSuggestAddress
|
|
2615
|
+
* @pronghornType method
|
|
2616
|
+
* @name verifyAndSuggestAddress
|
|
2617
|
+
* @summary verifyAndSuggestAddress
|
|
2618
|
+
*
|
|
2619
|
+
* @param {string} returnSuggestions - To return suggested addresses, set this to true.
|
|
2620
|
+
* @param {object} body - Address object that needs to be validated.
|
|
2621
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2622
|
+
* @return {object} results - An object containing the response of the action
|
|
2623
|
+
*
|
|
2624
|
+
* @route {POST} /verifyAndSuggestAddress
|
|
2625
|
+
* @roles admin
|
|
2626
|
+
* @task true
|
|
2627
|
+
*/
|
|
2628
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2629
|
+
verifyAndSuggestAddress(returnSuggestions, body, callback) {
|
|
2630
|
+
const meth = 'adapter-verifyAndSuggestAddress';
|
|
2631
|
+
const origin = `${this.id}-${meth}`;
|
|
2632
|
+
log.trace(origin);
|
|
2633
|
+
|
|
2634
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2635
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2636
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2637
|
+
return callback(null, errorObj);
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2641
|
+
if (returnSuggestions === undefined || returnSuggestions === null || returnSuggestions === '') {
|
|
2642
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['returnSuggestions'], null, null, null);
|
|
2643
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2644
|
+
return callback(null, errorObj);
|
|
2645
|
+
}
|
|
2646
|
+
if (body === undefined || body === null || body === '') {
|
|
2647
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2648
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2649
|
+
return callback(null, errorObj);
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2653
|
+
const queryParamsAvailable = { returnSuggestions };
|
|
2654
|
+
const queryParams = {};
|
|
2655
|
+
const pathVars = [];
|
|
2656
|
+
const bodyVars = body;
|
|
2657
|
+
|
|
2658
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2659
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2660
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2661
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2662
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2663
|
+
}
|
|
2664
|
+
});
|
|
2665
|
+
|
|
2666
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2667
|
+
let thisHeaderData = null;
|
|
2668
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2669
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2670
|
+
try {
|
|
2671
|
+
// parse the additional headers object that was passed in
|
|
2672
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2673
|
+
} catch (err) {
|
|
2674
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2675
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2676
|
+
return callback(null, errorObj);
|
|
2677
|
+
}
|
|
2678
|
+
} else if (thisHeaderData === null) {
|
|
2679
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2683
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2684
|
+
const reqObj = {
|
|
2685
|
+
payload: bodyVars,
|
|
2686
|
+
uriPathVars: pathVars,
|
|
2687
|
+
uriQuery: queryParams,
|
|
2688
|
+
addlHeaders: thisHeaderData
|
|
2689
|
+
};
|
|
2690
|
+
|
|
2691
|
+
try {
|
|
2692
|
+
// Make the call -
|
|
2693
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2694
|
+
return this.requestHandlerInst.identifyRequest('AddressValidation', 'verifyAndSuggestAddress', reqObj, true, (irReturnData, irReturnError) => {
|
|
2695
|
+
// if we received an error or their is no response on the results
|
|
2696
|
+
// return an error
|
|
2697
|
+
if (irReturnError) {
|
|
2698
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2699
|
+
return callback(null, irReturnError);
|
|
2700
|
+
}
|
|
2701
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2702
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['verifyAndSuggestAddress'], null, null, null);
|
|
2703
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2704
|
+
return callback(null, errorObj);
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2708
|
+
// return the response
|
|
2709
|
+
return callback(irReturnData, null);
|
|
2710
|
+
});
|
|
2711
|
+
} catch (ex) {
|
|
2712
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2713
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2714
|
+
return callback(null, errorObj);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
/**
|
|
2719
|
+
* @function getParcelProtectionQuote
|
|
2720
|
+
* @pronghornType method
|
|
2721
|
+
* @name getParcelProtectionQuote
|
|
2722
|
+
* @summary getParcelProtectionQuote
|
|
2723
|
+
*
|
|
2724
|
+
* @param {object} body - manifest
|
|
2725
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2726
|
+
* @return {object} results - An object containing the response of the action
|
|
2727
|
+
*
|
|
2728
|
+
* @route {POST} /getParcelProtectionQuote
|
|
2729
|
+
* @roles admin
|
|
2730
|
+
* @task true
|
|
2731
|
+
*/
|
|
2732
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2733
|
+
getParcelProtectionQuote(xPBTransactionId, body, callback) {
|
|
2734
|
+
const meth = 'adapter-getParcelProtectionQuote';
|
|
2735
|
+
const origin = `${this.id}-${meth}`;
|
|
2736
|
+
log.trace(origin);
|
|
2737
|
+
|
|
2738
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2739
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2740
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2741
|
+
return callback(null, errorObj);
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2745
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
2746
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
2747
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2748
|
+
return callback(null, errorObj);
|
|
2749
|
+
}
|
|
2750
|
+
if (body === undefined || body === null || body === '') {
|
|
2751
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2752
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2753
|
+
return callback(null, errorObj);
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2757
|
+
const queryParamsAvailable = {};
|
|
2758
|
+
const queryParams = {};
|
|
2759
|
+
const pathVars = [];
|
|
2760
|
+
const bodyVars = body;
|
|
2761
|
+
|
|
2762
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2763
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2764
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2765
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2766
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2767
|
+
}
|
|
2768
|
+
});
|
|
2769
|
+
|
|
2770
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2771
|
+
let thisHeaderData = null;
|
|
2772
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2773
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2774
|
+
try {
|
|
2775
|
+
// parse the additional headers object that was passed in
|
|
2776
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2777
|
+
} catch (err) {
|
|
2778
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2779
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2780
|
+
return callback(null, errorObj);
|
|
2781
|
+
}
|
|
2782
|
+
} else if (thisHeaderData === null) {
|
|
2783
|
+
thisHeaderData = {
|
|
2784
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2789
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2790
|
+
const reqObj = {
|
|
2791
|
+
payload: bodyVars,
|
|
2792
|
+
uriPathVars: pathVars,
|
|
2793
|
+
uriQuery: queryParams,
|
|
2794
|
+
addlHeaders: thisHeaderData
|
|
2795
|
+
};
|
|
2796
|
+
|
|
2797
|
+
try {
|
|
2798
|
+
// Make the call -
|
|
2799
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2800
|
+
return this.requestHandlerInst.identifyRequest('ParcelProtection', 'getParcelProtectionQuote', reqObj, true, (irReturnData, irReturnError) => {
|
|
2801
|
+
// if we received an error or their is no response on the results
|
|
2802
|
+
// return an error
|
|
2803
|
+
if (irReturnError) {
|
|
2804
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2805
|
+
return callback(null, irReturnError);
|
|
2806
|
+
}
|
|
2807
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2808
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getParcelProtectionQuote'], null, null, null);
|
|
2809
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2810
|
+
return callback(null, errorObj);
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2814
|
+
// return the response
|
|
2815
|
+
return callback(irReturnData, null);
|
|
2816
|
+
});
|
|
2817
|
+
} catch (ex) {
|
|
2818
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2819
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2820
|
+
return callback(null, errorObj);
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
/**
|
|
2825
|
+
* @function getParcelProtectionCoverage
|
|
2826
|
+
* @pronghornType method
|
|
2827
|
+
* @name getParcelProtectionCoverage
|
|
2828
|
+
* @summary getParcelProtectionCoverage
|
|
2829
|
+
*
|
|
2830
|
+
* @param {object} body - manifest
|
|
2831
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2832
|
+
* @return {object} results - An object containing the response of the action
|
|
2833
|
+
*
|
|
2834
|
+
* @route {POST} /getParcelProtectionCoverage
|
|
2835
|
+
* @roles admin
|
|
2836
|
+
* @task true
|
|
2837
|
+
*/
|
|
2838
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2839
|
+
getParcelProtectionCoverage(xPBTransactionId, body, callback) {
|
|
2840
|
+
const meth = 'adapter-getParcelProtectionCoverage';
|
|
2841
|
+
const origin = `${this.id}-${meth}`;
|
|
2842
|
+
log.trace(origin);
|
|
2843
|
+
|
|
2844
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2845
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2846
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2847
|
+
return callback(null, errorObj);
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2851
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
2852
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
2853
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2854
|
+
return callback(null, errorObj);
|
|
2855
|
+
}
|
|
2856
|
+
if (body === undefined || body === null || body === '') {
|
|
2857
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2858
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2859
|
+
return callback(null, errorObj);
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2863
|
+
const queryParamsAvailable = {};
|
|
2864
|
+
const queryParams = {};
|
|
2865
|
+
const pathVars = [];
|
|
2866
|
+
const bodyVars = body;
|
|
2867
|
+
|
|
2868
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2869
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2870
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2871
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2872
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2875
|
+
|
|
2876
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2877
|
+
let thisHeaderData = null;
|
|
2878
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2879
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2880
|
+
try {
|
|
2881
|
+
// parse the additional headers object that was passed in
|
|
2882
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2883
|
+
} catch (err) {
|
|
2884
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2885
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2886
|
+
return callback(null, errorObj);
|
|
2887
|
+
}
|
|
2888
|
+
} else if (thisHeaderData === null) {
|
|
2889
|
+
thisHeaderData = {
|
|
2890
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
2895
|
+
// see adapter code documentation for more information on the request object's fields
|
|
2896
|
+
const reqObj = {
|
|
2897
|
+
payload: bodyVars,
|
|
2898
|
+
uriPathVars: pathVars,
|
|
2899
|
+
uriQuery: queryParams,
|
|
2900
|
+
addlHeaders: thisHeaderData
|
|
2901
|
+
};
|
|
2902
|
+
|
|
2903
|
+
try {
|
|
2904
|
+
// Make the call -
|
|
2905
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
2906
|
+
return this.requestHandlerInst.identifyRequest('ParcelProtection', 'getParcelProtectionCoverage', reqObj, true, (irReturnData, irReturnError) => {
|
|
2907
|
+
// if we received an error or their is no response on the results
|
|
2908
|
+
// return an error
|
|
2909
|
+
if (irReturnError) {
|
|
2910
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
2911
|
+
return callback(null, irReturnError);
|
|
2912
|
+
}
|
|
2913
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
2914
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getParcelProtectionCoverage'], null, null, null);
|
|
2915
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2916
|
+
return callback(null, errorObj);
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
2920
|
+
// return the response
|
|
2921
|
+
return callback(irReturnData, null);
|
|
2922
|
+
});
|
|
2923
|
+
} catch (ex) {
|
|
2924
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
2925
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2926
|
+
return callback(null, errorObj);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
/**
|
|
2931
|
+
* @function cancelParcelProtection
|
|
2932
|
+
* @pronghornType method
|
|
2933
|
+
* @name cancelParcelProtection
|
|
2934
|
+
* @summary cancelParcelProtection
|
|
2935
|
+
*
|
|
2936
|
+
* @param {string} parcelProtectionReferenceId - Required. The identifier for the PB Parcel Protection policy that is being voided.
|
|
2937
|
+
* @param {object} body - manifest
|
|
2938
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
2939
|
+
* @return {object} results - An object containing the response of the action
|
|
2940
|
+
*
|
|
2941
|
+
* @route {POST} /cancelParcelProtection
|
|
2942
|
+
* @roles admin
|
|
2943
|
+
* @task true
|
|
2944
|
+
*/
|
|
2945
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
2946
|
+
cancelParcelProtection(xPBTransactionId, parcelProtectionReferenceId, body, callback) {
|
|
2947
|
+
const meth = 'adapter-cancelParcelProtection';
|
|
2948
|
+
const origin = `${this.id}-${meth}`;
|
|
2949
|
+
log.trace(origin);
|
|
2950
|
+
|
|
2951
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
2952
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
2953
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2954
|
+
return callback(null, errorObj);
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
2958
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
2959
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
2960
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2961
|
+
return callback(null, errorObj);
|
|
2962
|
+
}
|
|
2963
|
+
if (parcelProtectionReferenceId === undefined || parcelProtectionReferenceId === null || parcelProtectionReferenceId === '') {
|
|
2964
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['parcelProtectionReferenceId'], null, null, null);
|
|
2965
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2966
|
+
return callback(null, errorObj);
|
|
2967
|
+
}
|
|
2968
|
+
if (body === undefined || body === null || body === '') {
|
|
2969
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
2970
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2971
|
+
return callback(null, errorObj);
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
2975
|
+
const queryParamsAvailable = { parcelProtectionReferenceId };
|
|
2976
|
+
const queryParams = {};
|
|
2977
|
+
const pathVars = [];
|
|
2978
|
+
const bodyVars = body;
|
|
2979
|
+
|
|
2980
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
2981
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
2982
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
2983
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
2984
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
2985
|
+
}
|
|
2986
|
+
});
|
|
2987
|
+
|
|
2988
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
2989
|
+
let thisHeaderData = null;
|
|
2990
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
2991
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
2992
|
+
try {
|
|
2993
|
+
// parse the additional headers object that was passed in
|
|
2994
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
2995
|
+
} catch (err) {
|
|
2996
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
2997
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
2998
|
+
return callback(null, errorObj);
|
|
2999
|
+
}
|
|
3000
|
+
} else if (thisHeaderData === null) {
|
|
3001
|
+
thisHeaderData = {
|
|
3002
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
3003
|
+
};
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3007
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3008
|
+
const reqObj = {
|
|
3009
|
+
payload: bodyVars,
|
|
3010
|
+
uriPathVars: pathVars,
|
|
3011
|
+
uriQuery: queryParams,
|
|
3012
|
+
addlHeaders: thisHeaderData
|
|
3013
|
+
};
|
|
3014
|
+
|
|
3015
|
+
try {
|
|
3016
|
+
// Make the call -
|
|
3017
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3018
|
+
return this.requestHandlerInst.identifyRequest('ParcelProtection', 'cancelParcelProtection', reqObj, true, (irReturnData, irReturnError) => {
|
|
3019
|
+
// if we received an error or their is no response on the results
|
|
3020
|
+
// return an error
|
|
3021
|
+
if (irReturnError) {
|
|
3022
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3023
|
+
return callback(null, irReturnError);
|
|
3024
|
+
}
|
|
3025
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3026
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['cancelParcelProtection'], null, null, null);
|
|
3027
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3028
|
+
return callback(null, errorObj);
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3032
|
+
// return the response
|
|
3033
|
+
return callback(irReturnData, null);
|
|
3034
|
+
});
|
|
3035
|
+
} catch (ex) {
|
|
3036
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3037
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3038
|
+
return callback(null, errorObj);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* @function getParcelProtectionReports
|
|
3044
|
+
* @pronghornType method
|
|
3045
|
+
* @name getParcelProtectionReports
|
|
3046
|
+
* @summary getParcelProtectionReports
|
|
3047
|
+
*
|
|
3048
|
+
* @param {string} developerId - Required. Your Pitney Bowes developer ID.
|
|
3049
|
+
* @param {string} policyCreatedFromDate - The beginning of the date range. Specify this value in UTC using the ISO 8601 standard. You must include both date and time, and you must end the time with Z to indicate ...(description truncated)
|
|
3050
|
+
* @param {string} [policyCreatedToDate] - The end of the date range. Specify this value in UTC using the ISO 8601 standard. You must include both date and time, and you must end the time with Z to indicate a zero...(description truncated)
|
|
3051
|
+
* @param {string} [policyReferenceId] - The unique identifier for the PB Parcel Protection policy.].
|
|
3052
|
+
* @param {string} [parcelTrackingNumber] - The parcel tracking number of the shipment that the policy applies to.
|
|
3053
|
+
* @param {string} [merchantId] - The merchant's Shipper ID. This is the value of the postalReportingNumber element in the Merchant Object.
|
|
3054
|
+
* @param {string} [policyStatus] - Whether the policy is active or voided.
|
|
3055
|
+
* @param {string} [size] - The number of transactions to return per page in the result set.
|
|
3056
|
+
* @param {string} [page] - The index number of the page to return. Page index numbering starts at 0. Specifying page=0 returns the first page of the result set.
|
|
3057
|
+
* @param {string} [sort] - Defines a property to sort on and the sort order. Sort order can be ascending (asc) or descending (desc).
|
|
3058
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3059
|
+
* @return {object} results - An object containing the response of the action
|
|
3060
|
+
*
|
|
3061
|
+
* @route {POST} /getParcelProtectionReports
|
|
3062
|
+
* @roles admin
|
|
3063
|
+
* @task true
|
|
3064
|
+
*/
|
|
3065
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3066
|
+
getParcelProtectionReports(xPBTransactionId, developerId, policyCreatedFromDate, policyCreatedToDate, policyReferenceId, parcelTrackingNumber, merchantId, policyStatus, size, page, sort, callback) {
|
|
3067
|
+
const meth = 'adapter-getParcelProtectionReports';
|
|
3068
|
+
const origin = `${this.id}-${meth}`;
|
|
3069
|
+
log.trace(origin);
|
|
3070
|
+
|
|
3071
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3072
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3073
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3074
|
+
return callback(null, errorObj);
|
|
3075
|
+
}
|
|
3076
|
+
|
|
3077
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3078
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
3079
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
3080
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3081
|
+
return callback(null, errorObj);
|
|
3082
|
+
}
|
|
3083
|
+
if (developerId === undefined || developerId === null || developerId === '') {
|
|
3084
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['developerId'], null, null, null);
|
|
3085
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3086
|
+
return callback(null, errorObj);
|
|
3087
|
+
}
|
|
3088
|
+
if (policyCreatedFromDate === undefined || policyCreatedFromDate === null || policyCreatedFromDate === '') {
|
|
3089
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['policyCreatedFromDate'], null, null, null);
|
|
3090
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3091
|
+
return callback(null, errorObj);
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3095
|
+
const queryParamsAvailable = { policyCreatedFromDate, policyCreatedToDate, policyReferenceId, parcelTrackingNumber, merchantId, policyStatus, size, page, sort };
|
|
3096
|
+
const queryParams = {};
|
|
3097
|
+
const pathVars = [developerId];
|
|
3098
|
+
const bodyVars = {};
|
|
3099
|
+
|
|
3100
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3101
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3102
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3103
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3104
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3105
|
+
}
|
|
3106
|
+
});
|
|
3107
|
+
|
|
3108
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3109
|
+
let thisHeaderData = null;
|
|
3110
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3111
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3112
|
+
try {
|
|
3113
|
+
// parse the additional headers object that was passed in
|
|
3114
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3115
|
+
} catch (err) {
|
|
3116
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3117
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3118
|
+
return callback(null, errorObj);
|
|
3119
|
+
}
|
|
3120
|
+
} else if (thisHeaderData === null) {
|
|
3121
|
+
thisHeaderData = {
|
|
3122
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3127
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3128
|
+
const reqObj = {
|
|
3129
|
+
payload: bodyVars,
|
|
3130
|
+
uriPathVars: pathVars,
|
|
3131
|
+
uriQuery: queryParams,
|
|
3132
|
+
addlHeaders: thisHeaderData
|
|
3133
|
+
};
|
|
3134
|
+
|
|
3135
|
+
try {
|
|
3136
|
+
// Make the call -
|
|
3137
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3138
|
+
return this.requestHandlerInst.identifyRequest('ParcelProtection', 'getParcelProtectionReports', reqObj, true, (irReturnData, irReturnError) => {
|
|
3139
|
+
// if we received an error or their is no response on the results
|
|
3140
|
+
// return an error
|
|
3141
|
+
if (irReturnError) {
|
|
3142
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3143
|
+
return callback(null, irReturnError);
|
|
3144
|
+
}
|
|
3145
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3146
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getParcelProtectionReports'], null, null, null);
|
|
3147
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3148
|
+
return callback(null, errorObj);
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3152
|
+
// return the response
|
|
3153
|
+
return callback(irReturnData, null);
|
|
3154
|
+
});
|
|
3155
|
+
} catch (ex) {
|
|
3156
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3157
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3158
|
+
return callback(null, errorObj);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
/**
|
|
3163
|
+
* @function getTrackingDetails
|
|
3164
|
+
* @pronghornType method
|
|
3165
|
+
* @name getTrackingDetails
|
|
3166
|
+
* @summary getTrackingDetails
|
|
3167
|
+
*
|
|
3168
|
+
* @param {string} trackingNumber - The tracking number for the shipment.
|
|
3169
|
+
* @param {string} packageIdentifierType - packageIdentifierType
|
|
3170
|
+
* @param {} carrier - carrier
|
|
3171
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3172
|
+
* @return {object} results - An object containing the response of the action
|
|
3173
|
+
*
|
|
3174
|
+
* @route {POST} /getTrackingDetails
|
|
3175
|
+
* @roles admin
|
|
3176
|
+
* @task true
|
|
3177
|
+
*/
|
|
3178
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3179
|
+
getTrackingDetails(trackingNumber, packageIdentifierType, carrier, callback) {
|
|
3180
|
+
const meth = 'adapter-getTrackingDetails';
|
|
3181
|
+
const origin = `${this.id}-${meth}`;
|
|
3182
|
+
log.trace(origin);
|
|
3183
|
+
|
|
3184
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3185
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3186
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3187
|
+
return callback(null, errorObj);
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3191
|
+
if (trackingNumber === undefined || trackingNumber === null || trackingNumber === '') {
|
|
3192
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['trackingNumber'], null, null, null);
|
|
3193
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3194
|
+
return callback(null, errorObj);
|
|
3195
|
+
}
|
|
3196
|
+
if (packageIdentifierType === undefined || packageIdentifierType === null || packageIdentifierType === '') {
|
|
3197
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['packageIdentifierType'], null, null, null);
|
|
3198
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3199
|
+
return callback(null, errorObj);
|
|
3200
|
+
}
|
|
3201
|
+
if (carrier === undefined || carrier === null || carrier === '') {
|
|
3202
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['carrier'], null, null, null);
|
|
3203
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3204
|
+
return callback(null, errorObj);
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3208
|
+
const queryParamsAvailable = { packageIdentifierType, carrier };
|
|
3209
|
+
const queryParams = {};
|
|
3210
|
+
const pathVars = [trackingNumber];
|
|
3211
|
+
const bodyVars = {};
|
|
3212
|
+
|
|
3213
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3214
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3215
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3216
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3217
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3218
|
+
}
|
|
3219
|
+
});
|
|
3220
|
+
|
|
3221
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3222
|
+
let thisHeaderData = null;
|
|
3223
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3224
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3225
|
+
try {
|
|
3226
|
+
// parse the additional headers object that was passed in
|
|
3227
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3228
|
+
} catch (err) {
|
|
3229
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3230
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3231
|
+
return callback(null, errorObj);
|
|
3232
|
+
}
|
|
3233
|
+
} else if (thisHeaderData === null) {
|
|
3234
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3238
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3239
|
+
const reqObj = {
|
|
3240
|
+
payload: bodyVars,
|
|
3241
|
+
uriPathVars: pathVars,
|
|
3242
|
+
uriQuery: queryParams,
|
|
3243
|
+
addlHeaders: thisHeaderData
|
|
3244
|
+
};
|
|
3245
|
+
|
|
3246
|
+
try {
|
|
3247
|
+
// Make the call -
|
|
3248
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3249
|
+
return this.requestHandlerInst.identifyRequest('Tracking', 'getTrackingDetails', reqObj, true, (irReturnData, irReturnError) => {
|
|
3250
|
+
// if we received an error or their is no response on the results
|
|
3251
|
+
// return an error
|
|
3252
|
+
if (irReturnError) {
|
|
3253
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3254
|
+
return callback(null, irReturnError);
|
|
3255
|
+
}
|
|
3256
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3257
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getTrackingDetails'], null, null, null);
|
|
3258
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3259
|
+
return callback(null, errorObj);
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3263
|
+
// return the response
|
|
3264
|
+
return callback(irReturnData, null);
|
|
3265
|
+
});
|
|
3266
|
+
} catch (ex) {
|
|
3267
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3268
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3269
|
+
return callback(null, errorObj);
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
/**
|
|
3274
|
+
* @function addTrackingEvents
|
|
3275
|
+
* @pronghornType method
|
|
3276
|
+
* @name addTrackingEvents
|
|
3277
|
+
* @summary addTrackingEvents
|
|
3278
|
+
*
|
|
3279
|
+
* @param {object} body - add track event
|
|
3280
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3281
|
+
* @return {object} results - An object containing the response of the action
|
|
3282
|
+
*
|
|
3283
|
+
* @route {POST} /addTrackingEvents
|
|
3284
|
+
* @roles admin
|
|
3285
|
+
* @task true
|
|
3286
|
+
*/
|
|
3287
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3288
|
+
addTrackingEvents(body, callback) {
|
|
3289
|
+
const meth = 'adapter-addTrackingEvents';
|
|
3290
|
+
const origin = `${this.id}-${meth}`;
|
|
3291
|
+
log.trace(origin);
|
|
3292
|
+
|
|
3293
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3294
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3295
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3296
|
+
return callback(null, errorObj);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3300
|
+
if (body === undefined || body === null || body === '') {
|
|
3301
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
3302
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3303
|
+
return callback(null, errorObj);
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3307
|
+
const queryParamsAvailable = {};
|
|
3308
|
+
const queryParams = {};
|
|
3309
|
+
const pathVars = [];
|
|
3310
|
+
const bodyVars = body;
|
|
3311
|
+
|
|
3312
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3313
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3314
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3315
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3316
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3317
|
+
}
|
|
3318
|
+
});
|
|
3319
|
+
|
|
3320
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3321
|
+
let thisHeaderData = null;
|
|
3322
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3323
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3324
|
+
try {
|
|
3325
|
+
// parse the additional headers object that was passed in
|
|
3326
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3327
|
+
} catch (err) {
|
|
3328
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3329
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3330
|
+
return callback(null, errorObj);
|
|
3331
|
+
}
|
|
3332
|
+
} else if (thisHeaderData === null) {
|
|
3333
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3337
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3338
|
+
const reqObj = {
|
|
3339
|
+
payload: bodyVars,
|
|
3340
|
+
uriPathVars: pathVars,
|
|
3341
|
+
uriQuery: queryParams,
|
|
3342
|
+
addlHeaders: thisHeaderData
|
|
3343
|
+
};
|
|
3344
|
+
|
|
3345
|
+
try {
|
|
3346
|
+
// Make the call -
|
|
3347
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3348
|
+
return this.requestHandlerInst.identifyRequest('Tracking', 'addTrackingEvents', reqObj, true, (irReturnData, irReturnError) => {
|
|
3349
|
+
// if we received an error or their is no response on the results
|
|
3350
|
+
// return an error
|
|
3351
|
+
if (irReturnError) {
|
|
3352
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3353
|
+
return callback(null, irReturnError);
|
|
3354
|
+
}
|
|
3355
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3356
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['addTrackingEvents'], null, null, null);
|
|
3357
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3358
|
+
return callback(null, errorObj);
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3362
|
+
// return the response
|
|
3363
|
+
return callback(irReturnData, null);
|
|
3364
|
+
});
|
|
3365
|
+
} catch (ex) {
|
|
3366
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3367
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3368
|
+
return callback(null, errorObj);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
/**
|
|
3373
|
+
* @function getCrossBorderQuotes
|
|
3374
|
+
* @pronghornType method
|
|
3375
|
+
* @name getCrossBorderQuotes
|
|
3376
|
+
* @summary getCrossBorderQuotes
|
|
3377
|
+
*
|
|
3378
|
+
* @param {object} body - body param
|
|
3379
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3380
|
+
* @return {object} results - An object containing the response of the action
|
|
3381
|
+
*
|
|
3382
|
+
* @route {POST} /getCrossBorderQuotes
|
|
3383
|
+
* @roles admin
|
|
3384
|
+
* @task true
|
|
3385
|
+
*/
|
|
3386
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3387
|
+
getCrossBorderQuotes(body, callback) {
|
|
3388
|
+
const meth = 'adapter-getCrossBorderQuotes';
|
|
3389
|
+
const origin = `${this.id}-${meth}`;
|
|
3390
|
+
log.trace(origin);
|
|
3391
|
+
|
|
3392
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3393
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3394
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3395
|
+
return callback(null, errorObj);
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3399
|
+
if (body === undefined || body === null || body === '') {
|
|
3400
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
3401
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3402
|
+
return callback(null, errorObj);
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3406
|
+
const queryParamsAvailable = {};
|
|
3407
|
+
const queryParams = {};
|
|
3408
|
+
const pathVars = [];
|
|
3409
|
+
const bodyVars = body;
|
|
3410
|
+
|
|
3411
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3412
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3413
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3414
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3415
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3416
|
+
}
|
|
3417
|
+
});
|
|
3418
|
+
|
|
3419
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3420
|
+
let thisHeaderData = null;
|
|
3421
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3422
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3423
|
+
try {
|
|
3424
|
+
// parse the additional headers object that was passed in
|
|
3425
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3426
|
+
} catch (err) {
|
|
3427
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3428
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3429
|
+
return callback(null, errorObj);
|
|
3430
|
+
}
|
|
3431
|
+
} else if (thisHeaderData === null) {
|
|
3432
|
+
thisHeaderData = { xPBUnifiedErrorStructure: '' };
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3436
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3437
|
+
const reqObj = {
|
|
3438
|
+
payload: bodyVars,
|
|
3439
|
+
uriPathVars: pathVars,
|
|
3440
|
+
uriQuery: queryParams,
|
|
3441
|
+
addlHeaders: thisHeaderData
|
|
3442
|
+
};
|
|
3443
|
+
|
|
3444
|
+
try {
|
|
3445
|
+
// Make the call -
|
|
3446
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3447
|
+
return this.requestHandlerInst.identifyRequest('CrossBorderQuotes', 'getCrossBorderQuotes', reqObj, true, (irReturnData, irReturnError) => {
|
|
3448
|
+
// if we received an error or their is no response on the results
|
|
3449
|
+
// return an error
|
|
3450
|
+
if (irReturnError) {
|
|
3451
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3452
|
+
return callback(null, irReturnError);
|
|
3453
|
+
}
|
|
3454
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3455
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getCrossBorderQuotes'], null, null, null);
|
|
3456
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3457
|
+
return callback(null, errorObj);
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3461
|
+
// return the response
|
|
3462
|
+
return callback(irReturnData, null);
|
|
3463
|
+
});
|
|
3464
|
+
} catch (ex) {
|
|
3465
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3466
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3467
|
+
return callback(null, errorObj);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
|
|
3471
|
+
/**
|
|
3472
|
+
* @function predictedHSCode
|
|
3473
|
+
* @pronghornType method
|
|
3474
|
+
* @name predictedHSCode
|
|
3475
|
+
* @summary PredictedHSCode
|
|
3476
|
+
*
|
|
3477
|
+
* @param {object} body - manifest
|
|
3478
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3479
|
+
* @return {object} results - An object containing the response of the action
|
|
3480
|
+
*
|
|
3481
|
+
* @route {POST} /predictedHSCode
|
|
3482
|
+
* @roles admin
|
|
3483
|
+
* @task true
|
|
3484
|
+
*/
|
|
3485
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3486
|
+
predictedHSCode(xPBTransactionId, body, callback) {
|
|
3487
|
+
const meth = 'adapter-predictedHSCode';
|
|
3488
|
+
const origin = `${this.id}-${meth}`;
|
|
3489
|
+
log.trace(origin);
|
|
3490
|
+
|
|
3491
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3492
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3493
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3494
|
+
return callback(null, errorObj);
|
|
3495
|
+
}
|
|
3496
|
+
|
|
3497
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3498
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
3499
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
3500
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3501
|
+
return callback(null, errorObj);
|
|
3502
|
+
}
|
|
3503
|
+
if (body === undefined || body === null || body === '') {
|
|
3504
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
3505
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3506
|
+
return callback(null, errorObj);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3510
|
+
const queryParamsAvailable = {};
|
|
3511
|
+
const queryParams = {};
|
|
3512
|
+
const pathVars = [];
|
|
3513
|
+
const bodyVars = body;
|
|
3514
|
+
|
|
3515
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3516
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3517
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3518
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3519
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3520
|
+
}
|
|
3521
|
+
});
|
|
3522
|
+
|
|
3523
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3524
|
+
let thisHeaderData = null;
|
|
3525
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3526
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3527
|
+
try {
|
|
3528
|
+
// parse the additional headers object that was passed in
|
|
3529
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3530
|
+
} catch (err) {
|
|
3531
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3532
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3533
|
+
return callback(null, errorObj);
|
|
3534
|
+
}
|
|
3535
|
+
} else if (thisHeaderData === null) {
|
|
3536
|
+
thisHeaderData = {
|
|
3537
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3542
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3543
|
+
const reqObj = {
|
|
3544
|
+
payload: bodyVars,
|
|
3545
|
+
uriPathVars: pathVars,
|
|
3546
|
+
uriQuery: queryParams,
|
|
3547
|
+
addlHeaders: thisHeaderData
|
|
3548
|
+
};
|
|
3549
|
+
|
|
3550
|
+
try {
|
|
3551
|
+
// Make the call -
|
|
3552
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3553
|
+
return this.requestHandlerInst.identifyRequest('CrossBorderQuotes', 'predictedHSCode', reqObj, true, (irReturnData, irReturnError) => {
|
|
3554
|
+
// if we received an error or their is no response on the results
|
|
3555
|
+
// return an error
|
|
3556
|
+
if (irReturnError) {
|
|
3557
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3558
|
+
return callback(null, irReturnError);
|
|
3559
|
+
}
|
|
3560
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3561
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['predictedHSCode'], null, null, null);
|
|
3562
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3563
|
+
return callback(null, errorObj);
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3567
|
+
// return the response
|
|
3568
|
+
return callback(irReturnData, null);
|
|
3569
|
+
});
|
|
3570
|
+
} catch (ex) {
|
|
3571
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3572
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3573
|
+
return callback(null, errorObj);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
/**
|
|
3578
|
+
* @function getContainerizedParcelsLabels
|
|
3579
|
+
* @pronghornType method
|
|
3580
|
+
* @name getContainerizedParcelsLabels
|
|
3581
|
+
* @summary getContainerizedParcelsLabels
|
|
3582
|
+
*
|
|
3583
|
+
* @param {object} body - manifest
|
|
3584
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
3585
|
+
* @return {object} results - An object containing the response of the action
|
|
3586
|
+
*
|
|
3587
|
+
* @route {POST} /getContainerizedParcelsLabels
|
|
3588
|
+
* @roles admin
|
|
3589
|
+
* @task true
|
|
3590
|
+
*/
|
|
3591
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
3592
|
+
getContainerizedParcelsLabels(xPBTransactionId, body, callback) {
|
|
3593
|
+
const meth = 'adapter-getContainerizedParcelsLabels';
|
|
3594
|
+
const origin = `${this.id}-${meth}`;
|
|
3595
|
+
log.trace(origin);
|
|
3596
|
+
|
|
3597
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
3598
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
3599
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3600
|
+
return callback(null, errorObj);
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
3604
|
+
if (xPBTransactionId === undefined || xPBTransactionId === null || xPBTransactionId === '') {
|
|
3605
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['xPBTransactionId'], null, null, null);
|
|
3606
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3607
|
+
return callback(null, errorObj);
|
|
3608
|
+
}
|
|
3609
|
+
if (body === undefined || body === null || body === '') {
|
|
3610
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
3611
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3612
|
+
return callback(null, errorObj);
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
3616
|
+
const queryParamsAvailable = {};
|
|
3617
|
+
const queryParams = {};
|
|
3618
|
+
const pathVars = [];
|
|
3619
|
+
const bodyVars = body;
|
|
3620
|
+
|
|
3621
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
3622
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
3623
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
3624
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
3625
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
|
|
3629
|
+
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
|
|
3630
|
+
let thisHeaderData = null;
|
|
3631
|
+
// if the additional headers was passed in as a string parse the json into an object
|
|
3632
|
+
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
|
|
3633
|
+
try {
|
|
3634
|
+
// parse the additional headers object that was passed in
|
|
3635
|
+
thisHeaderData = JSON.parse(thisHeaderData);
|
|
3636
|
+
} catch (err) {
|
|
3637
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
|
|
3638
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3639
|
+
return callback(null, errorObj);
|
|
3640
|
+
}
|
|
3641
|
+
} else if (thisHeaderData === null) {
|
|
3642
|
+
thisHeaderData = {
|
|
3643
|
+
'X-PB-TransactionId': xPBTransactionId
|
|
3644
|
+
};
|
|
3645
|
+
}
|
|
3646
|
+
|
|
3647
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
3648
|
+
// see adapter code documentation for more information on the request object's fields
|
|
3649
|
+
const reqObj = {
|
|
3650
|
+
payload: bodyVars,
|
|
3651
|
+
uriPathVars: pathVars,
|
|
3652
|
+
uriQuery: queryParams,
|
|
3653
|
+
addlHeaders: thisHeaderData
|
|
3654
|
+
};
|
|
3655
|
+
|
|
3656
|
+
try {
|
|
3657
|
+
// Make the call -
|
|
3658
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
3659
|
+
return this.requestHandlerInst.identifyRequest('Container', 'getContainerizedParcelsLabels', reqObj, true, (irReturnData, irReturnError) => {
|
|
3660
|
+
// if we received an error or their is no response on the results
|
|
3661
|
+
// return an error
|
|
3662
|
+
if (irReturnError) {
|
|
3663
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
3664
|
+
return callback(null, irReturnError);
|
|
3665
|
+
}
|
|
3666
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
3667
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getContainerizedParcelsLabels'], null, null, null);
|
|
3668
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3669
|
+
return callback(null, errorObj);
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
3673
|
+
// return the response
|
|
3674
|
+
return callback(irReturnData, null);
|
|
3675
|
+
});
|
|
3676
|
+
} catch (ex) {
|
|
3677
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
3678
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
3679
|
+
return callback(null, errorObj);
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
module.exports = PitneyBowes;
|