-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/infobip lookup variable #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
template.js
Outdated
| const url = eventData.page_location || getRequestHeader('referer'); | ||
| if (url && url.lastIndexOf('https://gtm-msr.appspot.com/', 0) === 0) return true; | ||
|
|
||
| if (getType(data.baseUrl) !== 'string' || getType(data.apiKey) !== 'string') return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add it to all templates. Let the API response inform the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes needed. Check this commit with them.
template.js
Outdated
|
|
||
| if (getType(data.baseUrl) !== 'string' || getType(data.apiKey) !== 'string') return true; | ||
|
|
||
| if (!data.sender && !data.type.match('ID|EXTERNAL_ID|EMAIL|PHONE')) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use one of the two
!data.type.match('^(ID|EXTERNAL_ID|EMAIL|PHONE)$')
// or
['ID', 'EXTERNAL_ID', 'EMAIL', 'PHONE'].indexOf(data.type) === -1Add a log message stating why the variable failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template.js
Outdated
| apiBaseUrl = apiBaseUrl.match(protocolRegex) | ||
| ? apiBaseUrl.replace(protocolRegex, 'https://') | ||
| : 'https://' + apiBaseUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to worry about this. Consider https:// unless stated otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const apiBaseUrl = 'https://' + data.baseUrl.replace('https://', '').replace('http://', '');
template.js
Outdated
| ? apiBaseUrl.replace(protocolRegex, 'https://') | ||
| : 'https://' + apiBaseUrl; | ||
|
|
||
| requestConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const requestConfig = { ... }
template.js
Outdated
| url: apiBaseUrl + apiPath + apiQueries, | ||
| options: { | ||
| headers: { | ||
| 'Content-Type': 'application/json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed because no request body is being sent.
template.js
Outdated
|
|
||
| function personLookupHandler(method) { | ||
| if (method === 'requestMethod') return 'GET'; | ||
| if (method === 'path') return '/people/2/persons?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'/people/2/persons' without '?' because this character is part of the query
template.js
Outdated
| templateDataStorage.setItemCopy(cacheKeyTimestamp, now); | ||
| } | ||
| return createReturningObject(objectToStore); | ||
| } else if (result.statusCode === 404) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use only else without any other conditions because the API can return other error status codes.
template.js
Outdated
| log({ | ||
| Name: 'InfobipLookup', | ||
| Type: 'Message', | ||
| EventName: chosenApi, | ||
| Message: 'Request failure', | ||
| Reason: parsedBody.errorMessage | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to log again. The response log will already log basically the same thing.
template.js
Outdated
| let objectToStore = {}; | ||
| objectToStore = parsedBody; | ||
|
|
||
| if (data.storeResponse) { | ||
| templateDataStorage.setItemCopy(cacheKey, objectToStore); | ||
| templateDataStorage.setItemCopy(cacheKeyTimestamp, now); | ||
| } | ||
| return createReturningObject(objectToStore); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (result.statusCode === 200) {
const parsedBody = JSON.parse(result.body || '{}');
if (data.storeResponse) {
templateDataStorage.setItemCopy(cacheKey, parsedBody);
templateDataStorage.setItemCopy(cacheKeyTimestamp, now);
}
return createReturningObject(parsedBody);
}
template.js
Outdated
| data.expirationTime && makeInteger(data.expirationTime) * 60 * 60 * 1000; | ||
| const now = getTimestampMillis(); | ||
|
|
||
| if (data.storeResponse) { | ||
| let cachedValues = templateDataStorage.getItemCopy(cacheKey); | ||
| const cachedValueTimestamp = templateDataStorage.getItemCopy(cacheKeyTimestamp); | ||
|
|
||
| if (data.expirationTime) { | ||
| if ( | ||
| cachedValueTimestamp && | ||
| now - makeInteger(cachedValueTimestamp) >= cacheExpirationTimeMillis | ||
| ) { | ||
| cachedValues = ''; | ||
| templateDataStorage.removeItem(cacheKey); | ||
| templateDataStorage.removeItem(cacheKeyTimestamp); | ||
| } | ||
| } | ||
| if (cachedValues) | ||
| return Promise.create((resolve) => resolve(createReturningObject(cachedValues))); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I improved this part a bit.
const cacheExpirationTimeMillis = makeInteger(data.expirationTime || 12) * 60 * 60 * 1000;
// ...
if (data.storeResponse) {
const cachedValues = templateDataStorage.getItemCopy(cacheKey);
const cachedValueTimestamp = templateDataStorage.getItemCopy(cacheKeyTimestamp);
if (
cachedValueTimestamp &&
now - makeInteger(cachedValueTimestamp) >= cacheExpirationTimeMillis
) {
templateDataStorage.removeItem(cacheKey);
templateDataStorage.removeItem(cacheKeyTimestamp);
} else if (cachedValues) {
return Promise.create((resolve) => resolve(createReturningObject(cachedValues)));
}
}
template.tpl
Outdated
| "brand": { | ||
| "displayName": "stape.io" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is accepted by Google because the UI doesn't have a field to show it.

No description provided.