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
package/README.md
CHANGED
|
@@ -135,6 +135,17 @@ Most operations support the following parameters:
|
|
|
135
135
|
|
|
136
136
|
## Version History
|
|
137
137
|
|
|
138
|
+
- 0.7.1: Fix "Unable to sign without access token" error for sleep endpoints by using alternative validation strategy
|
|
139
|
+
- 0.7.0: **Major refactoring for improved code quality and maintainability**
|
|
140
|
+
- Restructured codebase with better separation of concerns
|
|
141
|
+
- Reduced main node file from 1065 to 627 lines (-41%)
|
|
142
|
+
- Added comprehensive TypeScript interfaces and type safety
|
|
143
|
+
- Centralized all constants and configuration
|
|
144
|
+
- Extracted token refresh logic into reusable helper functions
|
|
145
|
+
- Added extensive JSDoc documentation throughout codebase
|
|
146
|
+
- Eliminated code duplication in validation and retry logic
|
|
147
|
+
- Improved error handling with proper n8n error types
|
|
148
|
+
- No breaking changes - all functionality maintained
|
|
138
149
|
- 0.6.3: Fixed "Unable to sign without access token" error in sleep summary endpoint with enhanced token validation and special handling for sleep-related requests
|
|
139
150
|
- 0.6.2: Fixed "This scope is not allowed" error by ensuring proper scope formatting with "user." prefix in authorization URL
|
|
140
151
|
- 0.6.1: Version update for release
|
|
@@ -10,7 +10,7 @@ export declare class WithingsOAuth2Api implements ICredentialType {
|
|
|
10
10
|
tokenDataPostReceiveProcess: {
|
|
11
11
|
includeCredentialsOnRefreshOnBody: boolean;
|
|
12
12
|
preSend: (requestOptions: IHttpRequestOptions, credentials: IDataObject) => Promise<IHttpRequestOptions>;
|
|
13
|
-
expiresIn:
|
|
13
|
+
expiresIn: 15;
|
|
14
14
|
autoRefresh: boolean;
|
|
15
15
|
format: string;
|
|
16
16
|
property: string;
|
|
@@ -37,6 +37,7 @@ exports.WithingsOAuth2Api = void 0;
|
|
|
37
37
|
const https = __importStar(require("https"));
|
|
38
38
|
const process = __importStar(require("process"));
|
|
39
39
|
const withings_1 = require("../utils/withings");
|
|
40
|
+
const constants_1 = require("../utils/constants");
|
|
40
41
|
class WithingsOAuth2Api {
|
|
41
42
|
constructor() {
|
|
42
43
|
this.name = 'withingsOAuth2Api';
|
|
@@ -56,13 +57,13 @@ class WithingsOAuth2Api {
|
|
|
56
57
|
displayName: 'Authorization URL',
|
|
57
58
|
name: 'authUrl',
|
|
58
59
|
type: 'hidden',
|
|
59
|
-
default:
|
|
60
|
+
default: constants_1.WITHINGS_API.AUTH_URL,
|
|
60
61
|
},
|
|
61
62
|
{
|
|
62
63
|
displayName: 'Access Token URL',
|
|
63
64
|
name: 'accessTokenUrl',
|
|
64
65
|
type: 'hidden',
|
|
65
|
-
default:
|
|
66
|
+
default: constants_1.WITHINGS_API.TOKEN_URL,
|
|
66
67
|
},
|
|
67
68
|
{
|
|
68
69
|
displayName: 'Client ID',
|
|
@@ -87,7 +88,7 @@ class WithingsOAuth2Api {
|
|
|
87
88
|
displayName: 'Scope',
|
|
88
89
|
name: 'scope',
|
|
89
90
|
type: 'string',
|
|
90
|
-
default:
|
|
91
|
+
default: constants_1.DEFAULT_SCOPES,
|
|
91
92
|
description: 'Comma-separated list of scopes with the "user." prefix. Common scopes: user.info, user.metrics, user.activity, user.sleepevents',
|
|
92
93
|
},
|
|
93
94
|
];
|
|
@@ -108,9 +109,7 @@ class WithingsOAuth2Api {
|
|
|
108
109
|
if (!requestOptions.headers) {
|
|
109
110
|
requestOptions.headers = {};
|
|
110
111
|
}
|
|
111
|
-
requestOptions.headers
|
|
112
|
-
requestOptions.headers['Pragma'] = 'no-cache';
|
|
113
|
-
requestOptions.headers['Expires'] = '0';
|
|
112
|
+
Object.assign(requestOptions.headers, constants_1.CACHE_HEADERS);
|
|
114
113
|
if (credentials.clientId && credentials.clientSecret) {
|
|
115
114
|
try {
|
|
116
115
|
const nonce = await (0, withings_1.getNonce)(credentials.clientId, credentials.clientSecret, async (options) => {
|
|
@@ -158,7 +157,7 @@ class WithingsOAuth2Api {
|
|
|
158
157
|
}
|
|
159
158
|
return requestOptions;
|
|
160
159
|
},
|
|
161
|
-
expiresIn:
|
|
160
|
+
expiresIn: constants_1.TOKEN_CONFIG.EXPIRES_IN,
|
|
162
161
|
autoRefresh: true,
|
|
163
162
|
format: 'json',
|
|
164
163
|
property: 'body',
|
|
@@ -172,8 +171,7 @@ class WithingsOAuth2Api {
|
|
|
172
171
|
properties: {
|
|
173
172
|
headers: {
|
|
174
173
|
Authorization: '=Bearer {{$credentials.accessToken}}',
|
|
175
|
-
|
|
176
|
-
'Pragma': 'no-cache',
|
|
174
|
+
...constants_1.CACHE_HEADERS,
|
|
177
175
|
'X-Request-Timestamp': '={{Date.now()}}',
|
|
178
176
|
},
|
|
179
177
|
qs: {
|
|
@@ -183,7 +181,7 @@ class WithingsOAuth2Api {
|
|
|
183
181
|
};
|
|
184
182
|
this.test = {
|
|
185
183
|
request: {
|
|
186
|
-
baseURL:
|
|
184
|
+
baseURL: constants_1.WITHINGS_API.BASE_URL,
|
|
187
185
|
url: '/v2/user',
|
|
188
186
|
method: 'GET',
|
|
189
187
|
qs: {
|
|
@@ -192,10 +190,9 @@ class WithingsOAuth2Api {
|
|
|
192
190
|
},
|
|
193
191
|
headers: {
|
|
194
192
|
'Accept': 'application/json',
|
|
195
|
-
|
|
196
|
-
'Pragma': 'no-cache',
|
|
193
|
+
...constants_1.CACHE_HEADERS,
|
|
197
194
|
},
|
|
198
|
-
timeout:
|
|
195
|
+
timeout: constants_1.TOKEN_CONFIG.REQUEST_TIMEOUT,
|
|
199
196
|
},
|
|
200
197
|
};
|
|
201
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithingsOAuth2Api.credentials.js","sourceRoot":"","sources":["../../credentials/WithingsOAuth2Api.credentials.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,6CAA+B;AAC/B,iDAAmC;AAEnC,gDAA6E;
|
|
1
|
+
{"version":3,"file":"WithingsOAuth2Api.credentials.js","sourceRoot":"","sources":["../../credentials/WithingsOAuth2Api.credentials.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,6CAA+B;AAC/B,iDAAmC;AAEnC,gDAA6E;AAC7E,kDAK4B;AAE5B,MAAa,iBAAiB;IAA9B;QACE,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GAAG,qBAAqB,CAAC;QACpC,gBAAW,GAAG,mEAAmE,CAAC;QAClF,qBAAgB,GAAG,wCAAwC,CAAC;QAC5D,SAAI,GAAS,wCAAwC,CAAC;QACtD,YAAO,GAAG,CAAC,WAAW,CAAC,CAAC;QACxB,eAAU,GAAsB;YAC9B;gBACE,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,mBAAmB;aAC7B;YACD;gBACE,WAAW,EAAE,mBAAmB;gBAChC,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,w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