n8n-nodes-withings 0.6.3 → 0.7.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/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 -469
- 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 +210 -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,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RETRY_ENDPOINTS = exports.FALLBACK_ENDPOINTS = exports.REFRESH_STRATEGIES = exports.VALIDATION_ENDPOINTS = exports.TOKEN_ERROR_PATTERNS = exports.DEFAULT_SCOPES = exports.CACHE_HEADERS = exports.JITTER = exports.TOKEN_CONFIG = exports.ENDPOINTS = exports.WITHINGS_API = void 0;
|
|
4
|
+
exports.WITHINGS_API = {
|
|
5
|
+
BASE_URL: 'https://wbsapi.withings.net',
|
|
6
|
+
AUTH_URL: 'https://account.withings.com/oauth2_user/authorize2',
|
|
7
|
+
TOKEN_URL: 'https://wbsapi.withings.net/v2/oauth2?action=requesttoken',
|
|
8
|
+
SIGNATURE_URL: 'https://wbsapi.withings.net/v2/signature',
|
|
9
|
+
};
|
|
10
|
+
exports.ENDPOINTS = {
|
|
11
|
+
USER: '/v2/user',
|
|
12
|
+
MEASURE: '/v2/measure',
|
|
13
|
+
MEASURE_V1: '/measure',
|
|
14
|
+
SLEEP: '/v2/sleep',
|
|
15
|
+
NOTIFY: '/notify',
|
|
16
|
+
};
|
|
17
|
+
exports.TOKEN_CONFIG = {
|
|
18
|
+
EXPIRES_IN: 15,
|
|
19
|
+
MAX_RETRIES: 5,
|
|
20
|
+
BASE_DELAY: 1000,
|
|
21
|
+
PRE_VALIDATION_ATTEMPTS: 7,
|
|
22
|
+
DIRECT_REFRESH_ATTEMPTS: 5,
|
|
23
|
+
INITIAL_DELAY: 1500,
|
|
24
|
+
TOKEN_REFRESH_DELAY: 2000,
|
|
25
|
+
VALIDATION_DELAY: 2000,
|
|
26
|
+
SLEEP_VALIDATION_DELAY: 2500,
|
|
27
|
+
REQUEST_TIMEOUT: 10000,
|
|
28
|
+
};
|
|
29
|
+
exports.JITTER = {
|
|
30
|
+
MIN: 0.8,
|
|
31
|
+
MAX: 1.2,
|
|
32
|
+
RANGE: 0.4,
|
|
33
|
+
};
|
|
34
|
+
exports.CACHE_HEADERS = {
|
|
35
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
36
|
+
'Pragma': 'no-cache',
|
|
37
|
+
'Expires': '0',
|
|
38
|
+
};
|
|
39
|
+
exports.DEFAULT_SCOPES = 'user.info,user.metrics,user.activity,user.sleepevents';
|
|
40
|
+
exports.TOKEN_ERROR_PATTERNS = [
|
|
41
|
+
'token',
|
|
42
|
+
'sign',
|
|
43
|
+
'auth',
|
|
44
|
+
'unauthorized',
|
|
45
|
+
'expired',
|
|
46
|
+
'authentication',
|
|
47
|
+
'credentials',
|
|
48
|
+
'access',
|
|
49
|
+
'permission',
|
|
50
|
+
'invalid',
|
|
51
|
+
'oauth',
|
|
52
|
+
'401',
|
|
53
|
+
'403',
|
|
54
|
+
'denied',
|
|
55
|
+
'reject',
|
|
56
|
+
'login',
|
|
57
|
+
'signature',
|
|
58
|
+
'identity',
|
|
59
|
+
'verify',
|
|
60
|
+
'key',
|
|
61
|
+
'secret',
|
|
62
|
+
];
|
|
63
|
+
exports.VALIDATION_ENDPOINTS = [
|
|
64
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`, action: 'getdevice' },
|
|
65
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.MEASURE}`, action: 'getactivity' },
|
|
66
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.SLEEP}`, action: 'get' },
|
|
67
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.SLEEP}`, action: 'getsummary' },
|
|
68
|
+
];
|
|
69
|
+
exports.REFRESH_STRATEGIES = [
|
|
70
|
+
{
|
|
71
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`,
|
|
72
|
+
action: 'getdevice',
|
|
73
|
+
waitTime: 1200,
|
|
74
|
+
description: 'User endpoint with getdevice action (most reliable)',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.MEASURE}`,
|
|
78
|
+
action: 'getactivity',
|
|
79
|
+
waitTime: 1500,
|
|
80
|
+
description: 'Measure endpoint (different service)',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`,
|
|
84
|
+
action: 'get',
|
|
85
|
+
waitTime: 1800,
|
|
86
|
+
description: 'User endpoint with simpler action',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.SLEEP}`,
|
|
90
|
+
action: 'get',
|
|
91
|
+
waitTime: 2000,
|
|
92
|
+
description: 'Sleep endpoint (different service)',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.NOTIFY}`,
|
|
96
|
+
action: 'list',
|
|
97
|
+
waitTime: 2500,
|
|
98
|
+
description: 'Notification endpoint (completely different API area)',
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
exports.FALLBACK_ENDPOINTS = [
|
|
102
|
+
{
|
|
103
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.SLEEP}`,
|
|
104
|
+
action: 'get',
|
|
105
|
+
waitTime: 2000,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.MEASURE}`,
|
|
109
|
+
action: 'getactivity',
|
|
110
|
+
waitTime: 2200,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`,
|
|
114
|
+
action: 'getdevice',
|
|
115
|
+
waitTime: 2500,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.NOTIFY}`,
|
|
119
|
+
action: 'list',
|
|
120
|
+
waitTime: 3000,
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
exports.RETRY_ENDPOINTS = [
|
|
124
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`, action: 'get' },
|
|
125
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.USER}`, action: 'getdevice' },
|
|
126
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.MEASURE}`, action: 'getactivity' },
|
|
127
|
+
{ url: `${exports.WITHINGS_API.BASE_URL}${exports.ENDPOINTS.SLEEP}`, action: 'get' },
|
|
128
|
+
];
|
|
129
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"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export declare function calculateJitter(baseValue: number): number;
|
|
4
|
+
export declare function generateUniqueTimestamp(): number;
|
|
5
|
+
export declare function createRequestHeaders(additionalHeaders?: IDataObject): IDataObject;
|
|
6
|
+
export declare function isTokenError(error: any): boolean;
|
|
7
|
+
export declare function calculateBackoffDelay(retries: number, baseDelay?: number): number;
|
|
8
|
+
export declare function makeValidationRequest(context: IExecuteFunctions, endpoint: IEndpointConfig): Promise<IValidationAttemptResult>;
|
|
9
|
+
export declare function performPreValidation(context: IExecuteFunctions): Promise<void>;
|
|
10
|
+
export declare function performDirectTokenRefresh(context: IExecuteFunctions): Promise<ITokenRefreshResult>;
|
|
11
|
+
export declare function refreshTokenForRetry(context: IExecuteFunctions, retryCount: number): Promise<ITokenRefreshResult>;
|
|
12
|
+
export declare function executeRefreshStrategies(context: IExecuteFunctions): Promise<ITokenRefreshResult>;
|
|
13
|
+
export declare function validateSleepToken(context: IExecuteFunctions, operation: string): Promise<void>;
|
|
14
|
+
export declare function createTokenErrorMessage(maxRetries: number, error: any, tokenRefreshed: boolean): string;
|
|
@@ -0,0 +1,210 @@
|
|
|
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[0].url,
|
|
163
|
+
qs: {
|
|
164
|
+
action: 'getdevice',
|
|
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
|
+
try {
|
|
178
|
+
await (0, n8n_workflow_1.sleep)(2000);
|
|
179
|
+
const uniqueTimestamp = generateUniqueTimestamp();
|
|
180
|
+
await context.helpers.requestWithAuthentication.call(context, 'withingsOAuth2Api', {
|
|
181
|
+
method: 'GET',
|
|
182
|
+
url: constants_1.VALIDATION_ENDPOINTS[0].url,
|
|
183
|
+
qs: {
|
|
184
|
+
action: 'get',
|
|
185
|
+
_ts: uniqueTimestamp,
|
|
186
|
+
},
|
|
187
|
+
json: true,
|
|
188
|
+
headers: createRequestHeaders(),
|
|
189
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
190
|
+
});
|
|
191
|
+
await (0, n8n_workflow_1.sleep)(constants_1.TOKEN_CONFIG.SLEEP_VALIDATION_DELAY);
|
|
192
|
+
}
|
|
193
|
+
catch (retryError) {
|
|
194
|
+
await (0, n8n_workflow_1.sleep)(3000);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function createTokenErrorMessage(maxRetries, error, tokenRefreshed) {
|
|
199
|
+
return `Failed after ${maxRetries} attempts: ${error.message}.
|
|
200
|
+
Error type: ${error.name || 'Unknown'}, Status code: ${error.statusCode || 'N/A'}.
|
|
201
|
+
Token refresh status: ${tokenRefreshed ? 'Refreshed' : 'Not refreshed'}.
|
|
202
|
+
|
|
203
|
+
The token may be invalid or revoked. Please try the following:
|
|
204
|
+
1. Reconnect your Withings account in the credentials
|
|
205
|
+
2. Ensure your Withings Developer account is active
|
|
206
|
+
3. Check that your application has the required scopes
|
|
207
|
+
4. Verify that your Withings account is active and properly configured
|
|
208
|
+
5. Try again in a few minutes as Withings API may be experiencing temporary issues`;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=tokenHelpers.js.map
|
|
@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/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":";;;;;;;;;;;;;;;;;;;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