@jd-data-limited/easy-fm 1.1.3-alpha3 → 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.
Files changed (3) hide show
  1. package/index.js +7 -2
  2. package/index.ts +7 -2
  3. 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
  }
@@ -218,7 +223,7 @@ class layout {
218
223
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
219
224
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`;
220
225
  if (script.parameter)
221
- url += "?" + encodeURIComponent(script.parameter);
226
+ url += "?script.param=" + encodeURIComponent(script.parameter);
222
227
  this.database.apiRequest(url, {
223
228
  port: 443,
224
229
  method: "GET"
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
 
@@ -302,7 +307,7 @@ class layout {
302
307
  runScript(script): Promise<string | FMError | Error> {
303
308
  return new Promise(async (resolve, reject) => {
304
309
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
305
- if (script.parameter) url += "?" + encodeURIComponent(script.parameter)
310
+ if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
306
311
  this.database.apiRequest(url, {
307
312
  port: 443,
308
313
  method: "GET"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "1.1.3alpha3",
3
+ "version": "1.1.4alpha1",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",