n8n-nodes-withings 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/credentials/WithingsOAuth2Api.credentials.d.ts +1 -1
- package/dist/credentials/WithingsOAuth2Api.credentials.js +10 -13
- package/dist/credentials/WithingsOAuth2Api.credentials.js.map +1 -1
- package/dist/nodes/WithingsApi/WithingsApi.node.js +94 -443
- package/dist/nodes/WithingsApi/WithingsApi.node.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/constants.d.ts +106 -0
- package/dist/utils/constants.js +129 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/tokenHelpers.d.ts +14 -0
- package/dist/utils/tokenHelpers.js +192 -0
- package/dist/utils/tokenHelpers.js.map +1 -0
- package/dist/utils/types.d.ts +54 -0
- package/dist/utils/types.js +3 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/withings.js +4 -5
- package/dist/utils/withings.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateJitter = calculateJitter;
|
|
4
|
+
exports.generateUniqueTimestamp = generateUniqueTimestamp;
|
|
5
|
+
exports.createRequestHeaders = createRequestHeaders;
|
|
6
|
+
exports.isTokenError = isTokenError;
|
|
7
|
+
exports.calculateBackoffDelay = calculateBackoffDelay;
|
|
8
|
+
exports.makeValidationRequest = makeValidationRequest;
|
|
9
|
+
exports.performPreValidation = performPreValidation;
|
|
10
|
+
exports.performDirectTokenRefresh = performDirectTokenRefresh;
|
|
11
|
+
exports.refreshTokenForRetry = refreshTokenForRetry;
|
|
12
|
+
exports.executeRefreshStrategies = executeRefreshStrategies;
|
|
13
|
+
exports.validateSleepToken = validateSleepToken;
|
|
14
|
+
exports.createTokenErrorMessage = createTokenErrorMessage;
|
|
15
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
17
|
+
function calculateJitter(baseValue) {
|
|
18
|
+
const jitter = Math.random() * constants_1.JITTER.RANGE + constants_1.JITTER.MIN;
|
|
19
|
+
return Math.floor(baseValue * jitter);
|
|
20
|
+
}
|
|
21
|
+
function generateUniqueTimestamp() {
|
|
22
|
+
return Date.now() + Math.floor(Math.random() * 1000);
|
|
23
|
+
}
|
|
24
|
+
function createRequestHeaders(additionalHeaders = {}) {
|
|
25
|
+
return {
|
|
26
|
+
'Accept': 'application/json',
|
|
27
|
+
...constants_1.CACHE_HEADERS,
|
|
28
|
+
...additionalHeaders,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function isTokenError(error) {
|
|
32
|
+
const errorMsg = (error.message || '').toLowerCase();
|
|
33
|
+
return constants_1.TOKEN_ERROR_PATTERNS.some((pattern) => errorMsg.includes(pattern));
|
|
34
|
+
}
|
|
35
|
+
function calculateBackoffDelay(retries, baseDelay = constants_1.TOKEN_CONFIG.BASE_DELAY) {
|
|
36
|
+
const exponentialDelay = baseDelay * Math.pow(2, retries - 1);
|
|
37
|
+
return calculateJitter(exponentialDelay);
|
|
38
|
+
}
|
|
39
|
+
async function makeValidationRequest(context, endpoint) {
|
|
40
|
+
try {
|
|
41
|
+
const uniqueTimestamp = generateUniqueTimestamp();
|
|
42
|
+
await context.helpers.requestWithAuthentication.call(context, 'withingsOAuth2Api', {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
url: endpoint.url,
|
|
45
|
+
qs: {
|
|
46
|
+
action: endpoint.action,
|
|
47
|
+
_ts: uniqueTimestamp,
|
|
48
|
+
},
|
|
49
|
+
json: true,
|
|
50
|
+
headers: {
|
|
51
|
+
...createRequestHeaders(),
|
|
52
|
+
'X-Request-ID': `validation-${uniqueTimestamp}`,
|
|
53
|
+
},
|
|
54
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
55
|
+
});
|
|
56
|
+
return { success: true, endpoint: endpoint.url };
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return { success: false, endpoint: endpoint.url, error };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function performPreValidation(context) {
|
|
63
|
+
for (let attempt = 0; attempt < constants_1.TOKEN_CONFIG.PRE_VALIDATION_ATTEMPTS; attempt++) {
|
|
64
|
+
const result = await makeValidationRequest(context, constants_1.VALIDATION_ENDPOINTS[0]);
|
|
65
|
+
if (result.success) {
|
|
66
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.VALIDATION_DELAY);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (attempt === constants_1.TOKEN_CONFIG.PRE_VALIDATION_ATTEMPTS - 1) {
|
|
70
|
+
await (0, n8n_workflow_1.sleep)(4000);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const delay = calculateJitter(1800 * Math.pow(1.5, attempt));
|
|
74
|
+
await (0, n8n_workflow_1.sleep)(delay);
|
|
75
|
+
const alternateEndpointIndex = (attempt % (constants_1.VALIDATION_ENDPOINTS.length - 1)) + 1;
|
|
76
|
+
const alternateResult = await makeValidationRequest(context, constants_1.VALIDATION_ENDPOINTS[alternateEndpointIndex]);
|
|
77
|
+
if (alternateResult.success) {
|
|
78
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.VALIDATION_DELAY);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
await (0, n8n_workflow_1.sleep)(2500);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function performDirectTokenRefresh(context) {
|
|
85
|
+
for (let attempt = 0; attempt < constants_1.TOKEN_CONFIG.DIRECT_REFRESH_ATTEMPTS; attempt++) {
|
|
86
|
+
const result = await makeValidationRequest(context, {
|
|
87
|
+
url: constants_1.VALIDATION_ENDPOINTS[0].url,
|
|
88
|
+
action: 'get',
|
|
89
|
+
});
|
|
90
|
+
if (result.success) {
|
|
91
|
+
await (0, n8n_workflow_1.sleep)(2500);
|
|
92
|
+
return { success: true };
|
|
93
|
+
}
|
|
94
|
+
if (attempt < constants_1.FALLBACK_ENDPOINTS.length) {
|
|
95
|
+
const fallback = constants_1.FALLBACK_ENDPOINTS[attempt];
|
|
96
|
+
const fallbackResult = await makeValidationRequest(context, fallback);
|
|
97
|
+
if (fallbackResult.success) {
|
|
98
|
+
await (0, n8n_workflow_1.sleep)(fallback.waitTime || 2000);
|
|
99
|
+
return { success: true };
|
|
100
|
+
}
|
|
101
|
+
const delay = calculateJitter(1200 * Math.pow(1.5, attempt));
|
|
102
|
+
await (0, n8n_workflow_1.sleep)(delay);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
await (0, n8n_workflow_1.sleep)(3000);
|
|
106
|
+
return { success: false };
|
|
107
|
+
}
|
|
108
|
+
async function refreshTokenForRetry(context, retryCount) {
|
|
109
|
+
const endpoint = constants_1.RETRY_ENDPOINTS[retryCount % constants_1.RETRY_ENDPOINTS.length];
|
|
110
|
+
try {
|
|
111
|
+
const uniqueTimestamp = generateUniqueTimestamp();
|
|
112
|
+
await context.helpers.requestWithAuthentication.call(context, 'withingsOAuth2Api', {
|
|
113
|
+
method: 'GET',
|
|
114
|
+
url: endpoint.url,
|
|
115
|
+
qs: {
|
|
116
|
+
action: endpoint.action,
|
|
117
|
+
_ts: uniqueTimestamp,
|
|
118
|
+
},
|
|
119
|
+
json: true,
|
|
120
|
+
headers: createRequestHeaders(),
|
|
121
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
122
|
+
});
|
|
123
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.TOKEN_REFRESH_DELAY);
|
|
124
|
+
return { success: true };
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
await (0, n8n_workflow_1.sleep)(1000);
|
|
128
|
+
return { success: false, error };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function executeRefreshStrategies(context) {
|
|
132
|
+
for (const strategy of constants_1.REFRESH_STRATEGIES) {
|
|
133
|
+
try {
|
|
134
|
+
await (0, n8n_workflow_1.sleep)(strategy.waitTime);
|
|
135
|
+
const uniqueTimestamp = generateUniqueTimestamp();
|
|
136
|
+
await context.helpers.requestWithAuthentication.call(context, 'withingsOAuth2Api', {
|
|
137
|
+
method: 'GET',
|
|
138
|
+
url: strategy.url,
|
|
139
|
+
qs: {
|
|
140
|
+
action: strategy.action,
|
|
141
|
+
_ts: uniqueTimestamp,
|
|
142
|
+
},
|
|
143
|
+
json: true,
|
|
144
|
+
headers: createRequestHeaders(),
|
|
145
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
146
|
+
});
|
|
147
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.TOKEN_REFRESH_DELAY);
|
|
148
|
+
return { success: true };
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
await (0, n8n_workflow_1.sleep)(3000);
|
|
155
|
+
return { success: false };
|
|
156
|
+
}
|
|
157
|
+
async function validateSleepToken(context, operation) {
|
|
158
|
+
try {
|
|
159
|
+
const uniqueTimestamp = generateUniqueTimestamp();
|
|
160
|
+
await context.helpers.requestWithAuthentication.call(context, 'withingsOAuth2Api', {
|
|
161
|
+
method: 'GET',
|
|
162
|
+
url: constants_1.VALIDATION_ENDPOINTS[2].url,
|
|
163
|
+
qs: {
|
|
164
|
+
action: operation === 'getsummary' ? 'getsummary' : 'get',
|
|
165
|
+
_ts: uniqueTimestamp,
|
|
166
|
+
},
|
|
167
|
+
json: true,
|
|
168
|
+
headers: {
|
|
169
|
+
...createRequestHeaders(),
|
|
170
|
+
'X-Request-ID': `sleep-validation-${uniqueTimestamp}`,
|
|
171
|
+
},
|
|
172
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
173
|
+
});
|
|
174
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.SLEEP_VALIDATION_DELAY);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
await (0, n8n_workflow_1.sleep)(1500);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function createTokenErrorMessage(maxRetries, error, tokenRefreshed) {
|
|
181
|
+
return `Failed after ${maxRetries} attempts: ${error.message}.
|
|
182
|
+
Error type: ${error.name || 'Unknown'}, Status code: ${error.statusCode || 'N/A'}.
|
|
183
|
+
Token refresh status: ${tokenRefreshed ? 'Refreshed' : 'Not refreshed'}.
|
|
184
|
+
|
|
185
|
+
The token may be invalid or revoked. Please try the following:
|
|
186
|
+
1. Reconnect your Withings account in the credentials
|
|
187
|
+
2. Ensure your Withings Developer account is active
|
|
188
|
+
3. Check that your application has the required scopes
|
|
189
|
+
4. Verify that your Withings account is active and properly configured
|
|
190
|
+
5. Try again in a few minutes as Withings API may be experiencing temporary issues`;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=tokenHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenHelpers.js","sourceRoot":"","sources":["../../utils/tokenHelpers.ts"],"names":[],"mappings":";;AAsBA,0CAGC;AAMD,0DAEC;AAOD,oDAMC;AAOD,oCAGC;AAQD,sDAGC;AAQD,sDA0BC;AAOD,oDAiCC;AAOD,8DA+BC;AAQD,oDA2BC;AAOD,4DA6BC;AAQD,gDAwBC;AASD,0DAeC;AA9SD,+CAAqE;AACrE,2CASqB;AAQrB,SAAgB,eAAe,CAAC,SAAiB;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,kBAAM,CAAC,KAAK,GAAG,kBAAM,CAAC,GAAG,CAAC;IACzD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,CA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KAAK,EAAE,CAAC;QAEhB,MAAM,IAAA,oBAAK,EAAC,IAAI,CAAC,CAAC;IACnB,CAAC;AACF,CAAC;AASD,SAAgB,uBAAuB,CACtC,UAAkB,EAClB,KAAU,EACV,cAAuB;IAEvB,OAAO,gBAAgB,UAAU,cAAc,KAAK,CAAC,OAAO;cAC/C,KAAK,CAAC,IAAI,IAAI,SAAS,kBAAkB,KAAK,CAAC,UAAU,IAAI,KAAK;wBACxD,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe;;;;;;;mFAOa,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IDataObject } from 'n8n-workflow';
|
|
2
|
+
export interface IWithingsResponse {
|
|
3
|
+
status: number;
|
|
4
|
+
body?: IDataObject;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IEndpointConfig {
|
|
8
|
+
url: string;
|
|
9
|
+
action: string;
|
|
10
|
+
waitTime?: number;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ITokenRefreshResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: Error;
|
|
16
|
+
}
|
|
17
|
+
export interface IRequestOptionsWithTimestamp {
|
|
18
|
+
method: string;
|
|
19
|
+
url: string;
|
|
20
|
+
qs: IDataObject & {
|
|
21
|
+
_ts: number;
|
|
22
|
+
};
|
|
23
|
+
json: boolean;
|
|
24
|
+
headers: IDataObject;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface IValidationAttemptResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
endpoint: string;
|
|
30
|
+
error?: Error;
|
|
31
|
+
}
|
|
32
|
+
export interface IRetryContext {
|
|
33
|
+
retries: number;
|
|
34
|
+
maxRetries: number;
|
|
35
|
+
tokenRefreshed: boolean;
|
|
36
|
+
lastError?: Error;
|
|
37
|
+
}
|
|
38
|
+
export interface IFormattedResponse extends IDataObject {
|
|
39
|
+
success: boolean;
|
|
40
|
+
resource: string;
|
|
41
|
+
operation: string;
|
|
42
|
+
error?: string;
|
|
43
|
+
status?: number;
|
|
44
|
+
errorCode?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ISleepValidationOptions {
|
|
47
|
+
operation: string;
|
|
48
|
+
uniqueTimestamp: number;
|
|
49
|
+
}
|
|
50
|
+
export interface IJitterConfig {
|
|
51
|
+
min: number;
|
|
52
|
+
max: number;
|
|
53
|
+
value: number;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../utils/types.ts"],"names":[],"mappings":""}
|
package/dist/utils/withings.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.normalizeMonth = normalizeMonth;
|
|
|
40
40
|
exports.normalizeDay = normalizeDay;
|
|
41
41
|
const crypto = __importStar(require("crypto"));
|
|
42
42
|
const process = __importStar(require("process"));
|
|
43
|
+
const constants_1 = require("./constants");
|
|
43
44
|
function formatScope(scope) {
|
|
44
45
|
return scope
|
|
45
46
|
.split(',')
|
|
@@ -57,7 +58,7 @@ async function getNonce(clientId, clientSecret, makeRequest) {
|
|
|
57
58
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
58
59
|
const options = {
|
|
59
60
|
method: 'POST',
|
|
60
|
-
url:
|
|
61
|
+
url: constants_1.WITHINGS_API.SIGNATURE_URL,
|
|
61
62
|
body: {
|
|
62
63
|
action: 'getnonce',
|
|
63
64
|
client_id: clientId,
|
|
@@ -67,11 +68,9 @@ async function getNonce(clientId, clientSecret, makeRequest) {
|
|
|
67
68
|
json: true,
|
|
68
69
|
headers: {
|
|
69
70
|
'Accept': 'application/json',
|
|
70
|
-
|
|
71
|
-
'Pragma': 'no-cache',
|
|
72
|
-
'Expires': '0',
|
|
71
|
+
...constants_1.CACHE_HEADERS,
|
|
73
72
|
},
|
|
74
|
-
timeout:
|
|
73
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
75
74
|
};
|
|
76
75
|
const response = await makeRequest(options);
|
|
77
76
|
if (response.body && response.body.nonce) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withings.js","sourceRoot":"","sources":["../../utils/withings.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"withings.js","sourceRoot":"","sources":["../../utils/withings.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,kCAKC;AAcD,8CAUC;AAWD,4BAuCC;AAWD,wCAEC;AAWD,oCAEC;AAtHD,+CAAiC;AACjC,iDAAmC;AAEnC,2CAAwE;AAUxE,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;SAChC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAcD,SAAgB,iBAAiB,CAC/B,MAAc,EACd,QAAgB,EAChB,YAAoB,EACpB,SAA0B;IAE1B,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,QAAQ,IAAI,SAAS,EAAE,CAAC;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAWM,KAAK,UAAU,QAAQ,CAC5B,QAAgB,EAChB,YAAoB,EACpB,WAA2D;IAE3D,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAEhD,MAAM,OAAO,GA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