@jd-data-limited/easy-fm 1.1.3-alpha1 → 1.1.3-alpha3

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 +13 -9
  2. package/index.ts +14 -9
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -22,8 +22,9 @@ import { fileURLToPath } from "url";
22
22
  import * as https from "https";
23
23
  // @ts-ignore
24
24
  const errs = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), 'fmErrors.json')).toString());
25
- export default class FileMakerConnection {
25
+ export default class FileMakerConnection extends EventEmitter {
26
26
  constructor(conn, rejectUnauthorized = true) {
27
+ super();
27
28
  this.hostname = conn.hostname;
28
29
  this.name = conn.database.database;
29
30
  this.databaseConDetails = conn;
@@ -70,7 +71,7 @@ export default class FileMakerConnection {
70
71
  method: "POST",
71
72
  headers: {
72
73
  "Content-Type": "application/json",
73
- "Authorization": "Basic " + Buffer.from(this.databaseConDetails[0].username + ":" + this.databaseConDetails[0].password).toString("base64")
74
+ "Authorization": "Basic " + Buffer.from(this.databaseConDetails.database.username + ":" + this.databaseConDetails.database.password).toString("base64")
74
75
  },
75
76
  body: JSON.stringify({
76
77
  fmDataSource: this.databaseConDetails.externalSources.map(i => {
@@ -93,7 +94,7 @@ export default class FileMakerConnection {
93
94
  });
94
95
  }
95
96
  else if (this.databaseConDetails.database.method === "token") {
96
- this._token = this.databaseConDetails[0].token;
97
+ this._token = this.databaseConDetails.database.token;
97
98
  resolve(this.token);
98
99
  }
99
100
  else if (this.databaseConDetails.database.method === "oauth") {
@@ -101,8 +102,8 @@ export default class FileMakerConnection {
101
102
  method: "POST",
102
103
  headers: {
103
104
  "Content-Type": "application/json",
104
- "X-FM-Data-OAuth-RequestId": this.databaseConDetails[0].oauth.requestId,
105
- "X-FM-Data-OAuth-Identifier": this.databaseConDetails[0].oauth.requestIdentifier
105
+ "X-FM-Data-OAuth-RequestId": this.databaseConDetails.database.oauth.requestId,
106
+ "X-FM-Data-OAuth-Identifier": this.databaseConDetails.database.oauth.requestIdentifier
106
107
  },
107
108
  body: JSON.stringify({
108
109
  fmDataSource: this.databaseConDetails.externalSources.map(i => {
@@ -123,7 +124,7 @@ export default class FileMakerConnection {
123
124
  method: "POST",
124
125
  headers: {
125
126
  "Content-Type": "application/json",
126
- "Authorization": this.databaseConDetails[0].claris.fmid,
127
+ "Authorization": this.databaseConDetails.database.claris.fmid,
127
128
  },
128
129
  body: "{}"
129
130
  })
@@ -180,6 +181,9 @@ export default class FileMakerConnection {
180
181
  script(name, parameter) {
181
182
  return { name, parameter };
182
183
  }
184
+ _tokenExpired() {
185
+ this.emit("token_expired");
186
+ }
183
187
  }
184
188
  class layout {
185
189
  constructor(database, name) {
@@ -201,7 +205,7 @@ class layout {
201
205
  fields[_field.name] = "";
202
206
  }
203
207
  resolve(new record(this, -1, 0, fields));
204
- });
208
+ }).catch(e => { reject(e); });
205
209
  });
206
210
  }
207
211
  getRecord(recordId) {
@@ -212,9 +216,9 @@ class layout {
212
216
  }
213
217
  runScript(script) {
214
218
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
215
- let url = `${this.endpoint}/script/${encodeURI(script.name)}`;
219
+ let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`;
216
220
  if (script.parameter)
217
- url += "?" + encodeURI(script.parameter);
221
+ url += "?" + encodeURIComponent(script.parameter);
218
222
  this.database.apiRequest(url, {
219
223
  port: 443,
220
224
  method: "GET"
package/index.ts CHANGED
@@ -88,7 +88,7 @@ interface recordObject {
88
88
  fieldData: any
89
89
  }
90
90
 
91
- export default class FileMakerConnection {
91
+ export default class FileMakerConnection extends EventEmitter {
92
92
  private _token: any;
93
93
  private hostname: string;
94
94
  public readonly rejectUnauthroized: boolean;
@@ -96,6 +96,7 @@ export default class FileMakerConnection {
96
96
  public name: string;
97
97
 
98
98
  constructor(conn: hostConnectionOptions, rejectUnauthorized = true) {
99
+ super()
99
100
  this.hostname = conn.hostname
100
101
  this.name = conn.database.database
101
102
  this.databaseConDetails = conn
@@ -144,7 +145,7 @@ export default class FileMakerConnection {
144
145
  method: "POST",
145
146
  headers: {
146
147
  "Content-Type": "application/json",
147
- "Authorization": "Basic " + Buffer.from((<loginOptionsFileMaker>this.databaseConDetails[0]).username + ":" + (<loginOptionsFileMaker>this.databaseConDetails[0]).password).toString("base64")
148
+ "Authorization": "Basic " + Buffer.from((<loginOptionsFileMaker>this.databaseConDetails.database).username + ":" + (<loginOptionsFileMaker>this.databaseConDetails.database).password).toString("base64")
148
149
  },
149
150
  body: JSON.stringify({
150
151
  fmDataSource: this.databaseConDetails.externalSources.map(i => {
@@ -165,15 +166,15 @@ export default class FileMakerConnection {
165
166
  reject(e)
166
167
  })
167
168
  } else if (this.databaseConDetails.database.method === "token") {
168
- this._token = (<loginOptionsToken>this.databaseConDetails[0]).token
169
+ this._token = (<loginOptionsToken>this.databaseConDetails.database).token
169
170
  resolve(this.token)
170
171
  } else if (this.databaseConDetails.database.method === "oauth") {
171
172
  fetch(`${this.endpoint}/sessions`, {
172
173
  method: "POST",
173
174
  headers: {
174
175
  "Content-Type": "application/json",
175
- "X-FM-Data-OAuth-RequestId": (<loginOptionsOAuth>this.databaseConDetails[0]).oauth.requestId,
176
- "X-FM-Data-OAuth-Identifier": (<loginOptionsOAuth>this.databaseConDetails[0]).oauth.requestIdentifier
176
+ "X-FM-Data-OAuth-RequestId": (<loginOptionsOAuth>this.databaseConDetails.database).oauth.requestId,
177
+ "X-FM-Data-OAuth-Identifier": (<loginOptionsOAuth>this.databaseConDetails.database).oauth.requestIdentifier
177
178
  },
178
179
  body: JSON.stringify({
179
180
  fmDataSource: this.databaseConDetails.externalSources.map(i => {
@@ -193,7 +194,7 @@ export default class FileMakerConnection {
193
194
  method: "POST",
194
195
  headers: {
195
196
  "Content-Type": "application/json",
196
- "Authorization": (<loginOptionsClaris>this.databaseConDetails[0]).claris.fmid,
197
+ "Authorization": (<loginOptionsClaris>this.databaseConDetails.database).claris.fmid,
197
198
  },
198
199
  body: "{}"
199
200
  })
@@ -253,6 +254,10 @@ export default class FileMakerConnection {
253
254
  script(name, parameter): Script {
254
255
  return ({name, parameter} as Script)
255
256
  }
257
+
258
+ _tokenExpired() {
259
+ this.emit("token_expired")
260
+ }
256
261
  }
257
262
 
258
263
  class layout {
@@ -282,7 +287,7 @@ class layout {
282
287
  fields[_field.name] = ""
283
288
  }
284
289
  resolve(new record(this, -1, 0, fields))
285
- })
290
+ }).catch(e => {reject(e)})
286
291
  })
287
292
  }
288
293
 
@@ -296,8 +301,8 @@ class layout {
296
301
 
297
302
  runScript(script): Promise<string | FMError | Error> {
298
303
  return new Promise(async (resolve, reject) => {
299
- let url = `${this.endpoint}/script/${encodeURI(script.name)}`
300
- if (script.parameter) url += "?" + encodeURI(script.parameter)
304
+ let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
305
+ if (script.parameter) url += "?" + encodeURIComponent(script.parameter)
301
306
  this.database.apiRequest(url, {
302
307
  port: 443,
303
308
  method: "GET"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "1.1.3alpha1",
3
+ "version": "1.1.3alpha3",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",