Skip to content

Commit 08e0ad9

Browse files
committed
airtable.newrecord
1 parent 6f463fc commit 08e0ad9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/appmixer/airtable/records/NewRecordWebhook/NewRecordWebhook.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const registerWebhook = async (context) => {
2626
data: body
2727
});
2828

29+
await context.log({ 'step': 'reg', data });
2930
return data;
3031
};
3132

@@ -43,6 +44,8 @@ module.exports = {
4344
state.macSecretBase64 = macSecretBase64;
4445
state.cursor = 1;
4546

47+
await context.log({ 'step': 'state - start', state });
48+
4649
return context.saveState(state);
4750
},
4851

@@ -71,6 +74,8 @@ module.exports = {
7174
}
7275
});
7376

77+
await context.log({ 'step': 'payload data ', data });
78+
7479
const { payloads } = data;
7580
if (Array.isArray(payloads) && payloads.length > 0) {
7681
const allNewRecordIds = Object.keys(payloads[0].changedTablesById[tableId].createdRecordsById);
@@ -147,10 +152,17 @@ module.exports = {
147152
}
148153

149154
// subtract 3 days
150-
const renewDate = expirationTime - 259200000;
155+
const renewDate = expirationTime - 5 * 24 * 60 * 60 * 1000; // + 60 * 54 * 1000;
151156
const now = Date.now();
152157

153158
if (now >= renewDate) {
159+
160+
await context.log({
161+
'step': 'going to refresh ' + accessToken.substr(accessToken.length - 10),
162+
renewDate: new Date(renewDate),
163+
a: context.auth
164+
});
165+
154166
try {
155167

156168
const { data } = await context.httpRequest({
@@ -162,8 +174,17 @@ module.exports = {
162174
});
163175

164176
state.expirationTime = Date.parse(data.expirationTime);
177+
178+
await context.log({ 'step': 'refresh data ', data });
165179
} catch (err) {
166-
if (err?.statusCode === 404) {
180+
if (err?.statusCode === 404 || err?.statusCode === 401) {
181+
182+
await context.log({
183+
'step': 'ERR registring... status: ' + err?.statusCode + ' ' + accessToken.substr(accessToken.length - 10),
184+
renewDate: new Date(renewDate),
185+
a: context.auth
186+
});
187+
167188
const { id, expirationTime } = await registerWebhook(context);
168189
state.webhookId = id;
169190
state.expirationTime = Date.parse(expirationTime);

0 commit comments

Comments
 (0)