@jd-data-limited/easy-fm 1.1.3-alpha4 → 1.1.4-alpha1
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/index.js +6 -1
- package/index.ts +6 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -143,7 +143,7 @@ export default class FileMakerConnection extends EventEmitter {
|
|
|
143
143
|
get endpoint() {
|
|
144
144
|
return `https://${this.hostname}/fmi/data/v2/databases/${this.name}`;
|
|
145
145
|
}
|
|
146
|
-
apiRequest(url, options = {}) {
|
|
146
|
+
apiRequest(url, options = {}, autoRelogin = true) {
|
|
147
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
148
|
if (!options.headers)
|
|
149
149
|
options.headers = {};
|
|
@@ -152,6 +152,11 @@ export default class FileMakerConnection extends EventEmitter {
|
|
|
152
152
|
options.rejectUnauthorized = this.rejectUnauthroized;
|
|
153
153
|
let _fetch = yield fetch(url, options);
|
|
154
154
|
let data = yield _fetch.json();
|
|
155
|
+
if (data.messages[0].code == "952" && autoRelogin) {
|
|
156
|
+
this._token = null;
|
|
157
|
+
yield this.login();
|
|
158
|
+
yield this.apiRequest(url, options, false);
|
|
159
|
+
}
|
|
155
160
|
return data;
|
|
156
161
|
});
|
|
157
162
|
}
|
package/index.ts
CHANGED
|
@@ -216,7 +216,7 @@ export default class FileMakerConnection extends EventEmitter {
|
|
|
216
216
|
return `https://${this.hostname}/fmi/data/v2/databases/${this.name}`
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
async apiRequest(url: string | Request, options: any = {}): Promise<any> {
|
|
219
|
+
async apiRequest(url: string | Request, options: any = {}, autoRelogin = true): Promise<any> {
|
|
220
220
|
if (!options.headers) options.headers = {}
|
|
221
221
|
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json"
|
|
222
222
|
options.headers["authorization"] = "Bearer " + this._token
|
|
@@ -224,6 +224,11 @@ export default class FileMakerConnection extends EventEmitter {
|
|
|
224
224
|
|
|
225
225
|
let _fetch = await fetch(url, options)
|
|
226
226
|
let data = await _fetch.json()
|
|
227
|
+
if (data.messages[0].code == "952" && autoRelogin) {
|
|
228
|
+
this._token = null
|
|
229
|
+
await this.login()
|
|
230
|
+
await this.apiRequest(url, options,false)
|
|
231
|
+
}
|
|
227
232
|
return (data as any)
|
|
228
233
|
}
|
|
229
234
|
|