@jd-data-limited/easy-fm 1.0.2-alpha3 → 1.0.2-alpha5
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 +23 -23
- package/index.ts +23 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -30,22 +30,10 @@ class database {
|
|
|
30
30
|
getLayout(name) {
|
|
31
31
|
return new layout(this, name);
|
|
32
32
|
}
|
|
33
|
-
apiRequest(url, options = {}) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (!options.headers)
|
|
36
|
-
options.headers = {};
|
|
37
|
-
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json";
|
|
38
|
-
options.headers["authorization"] = "Bearer " + this.host.token;
|
|
39
|
-
options.rejectUnauthorized = this.host.rejectUnauthroized;
|
|
40
|
-
let _fetch = yield fetch(url, options);
|
|
41
|
-
let data = yield _fetch.json();
|
|
42
|
-
return data;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
33
|
setGlobals(globalFields) {
|
|
46
34
|
// console.log({globalFields})
|
|
47
35
|
return new Promise((resolve, reject) => {
|
|
48
|
-
this.apiRequest(`${this.endpoint}/globals`, {
|
|
36
|
+
this.host.apiRequest(`${this.endpoint}/globals`, {
|
|
49
37
|
method: "PATCH",
|
|
50
38
|
body: JSON.stringify({ globalFields })
|
|
51
39
|
}).then(res => {
|
|
@@ -120,7 +108,7 @@ export default class FileMakerConnection {
|
|
|
120
108
|
return db.pairHost(this, con);
|
|
121
109
|
});
|
|
122
110
|
if (this.databaseConDetails[0].method === "filemaker") {
|
|
123
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
111
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
124
112
|
hostname: this.hostname,
|
|
125
113
|
port: 443,
|
|
126
114
|
method: "POST",
|
|
@@ -150,7 +138,7 @@ export default class FileMakerConnection {
|
|
|
150
138
|
resolve(this.token);
|
|
151
139
|
}
|
|
152
140
|
else if (this.databaseConDetails[0].method === "oauth") {
|
|
153
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
141
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
154
142
|
method: "POST",
|
|
155
143
|
headers: {
|
|
156
144
|
"Content-Type": "application/json",
|
|
@@ -169,7 +157,7 @@ export default class FileMakerConnection {
|
|
|
169
157
|
});
|
|
170
158
|
}
|
|
171
159
|
else if (this.databaseConDetails[0].method === "claris") {
|
|
172
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
160
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
173
161
|
method: "POST",
|
|
174
162
|
headers: {
|
|
175
163
|
"Content-Type": "application/json",
|
|
@@ -195,6 +183,18 @@ export default class FileMakerConnection {
|
|
|
195
183
|
get endpoint() {
|
|
196
184
|
return `https://${this.hostname}/fmi/data/v2/databases/`;
|
|
197
185
|
}
|
|
186
|
+
apiRequest(url, options = {}) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
if (!options.headers)
|
|
189
|
+
options.headers = {};
|
|
190
|
+
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json";
|
|
191
|
+
options.headers["authorization"] = "Bearer " + this._token;
|
|
192
|
+
options.rejectUnauthorized = this.rejectUnauthroized;
|
|
193
|
+
let _fetch = yield fetch(url, options);
|
|
194
|
+
let data = yield _fetch.json();
|
|
195
|
+
return data;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
198
|
}
|
|
199
199
|
class layout {
|
|
200
200
|
constructor(database, name) {
|
|
@@ -230,7 +230,7 @@ class layout {
|
|
|
230
230
|
let url = `${this.endpoint}/script/${encodeURI(script.name)}`;
|
|
231
231
|
if (script.parameter)
|
|
232
232
|
url += "?" + encodeURI(script.parameter);
|
|
233
|
-
this.database.apiRequest(url, {
|
|
233
|
+
this.database.host.apiRequest(url, {
|
|
234
234
|
port: 443,
|
|
235
235
|
method: "GET"
|
|
236
236
|
})
|
|
@@ -250,7 +250,7 @@ class layout {
|
|
|
250
250
|
}
|
|
251
251
|
getLayoutMeta() {
|
|
252
252
|
return new Promise((resolve, reject) => {
|
|
253
|
-
this.database.apiRequest(this.endpoint).then(res => {
|
|
253
|
+
this.database.host.apiRequest(this.endpoint).then(res => {
|
|
254
254
|
this.metadata = res.response;
|
|
255
255
|
resolve(this);
|
|
256
256
|
})
|
|
@@ -302,7 +302,7 @@ class record extends EventEmitter {
|
|
|
302
302
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
303
303
|
if (!this.layout.metadata)
|
|
304
304
|
yield this.layout.getLayoutMeta();
|
|
305
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
305
|
+
this.layout.database.host.apiRequest(this.endpoint, {
|
|
306
306
|
port: 443,
|
|
307
307
|
method: "GET"
|
|
308
308
|
})
|
|
@@ -335,7 +335,7 @@ class record extends EventEmitter {
|
|
|
335
335
|
if (this.recordId === -1) {
|
|
336
336
|
// This is a new record
|
|
337
337
|
extraBody.fieldData = data.fieldData;
|
|
338
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
338
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/records`, {
|
|
339
339
|
port: 443,
|
|
340
340
|
method: "POST",
|
|
341
341
|
body: JSON.stringify(extraBody)
|
|
@@ -361,7 +361,7 @@ class record extends EventEmitter {
|
|
|
361
361
|
}
|
|
362
362
|
for (let item of Object.keys(extraBody))
|
|
363
363
|
data[item] = extraBody[item];
|
|
364
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
364
|
+
this.layout.database.host.apiRequest(this.endpoint, {
|
|
365
365
|
port: 443,
|
|
366
366
|
method: "PATCH",
|
|
367
367
|
body: JSON.stringify(data)
|
|
@@ -568,7 +568,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
568
568
|
run() {
|
|
569
569
|
return new Promise((resolve, reject) => {
|
|
570
570
|
// console.log(this.#toObject())
|
|
571
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
571
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
572
572
|
method: "GET"
|
|
573
573
|
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
574
574
|
// // console.log(res)
|
|
@@ -631,7 +631,7 @@ class find extends recordGetOperation {
|
|
|
631
631
|
run() {
|
|
632
632
|
return new Promise((resolve, reject) => {
|
|
633
633
|
// console.log(this.#toObject())
|
|
634
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
634
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
635
635
|
port: 443,
|
|
636
636
|
method: "POST",
|
|
637
637
|
body: JSON.stringify(this.toObject())
|
package/index.ts
CHANGED
|
@@ -91,7 +91,7 @@ class database {
|
|
|
91
91
|
external: boolean;
|
|
92
92
|
public name: string;
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
host: FileMakerConnection;
|
|
95
95
|
protected props: databaseOptions;
|
|
96
96
|
|
|
97
97
|
public hostname: string;
|
|
@@ -106,21 +106,10 @@ class database {
|
|
|
106
106
|
return new layout(this, name)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async apiRequest(url: string | Request, options: any = {}): Promise<any> {
|
|
110
|
-
if (!options.headers) options.headers = {}
|
|
111
|
-
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json"
|
|
112
|
-
options.headers["authorization"] = "Bearer " + this.host.token
|
|
113
|
-
options.rejectUnauthorized = this.host.rejectUnauthroized
|
|
114
|
-
|
|
115
|
-
let _fetch = await fetch(url, options)
|
|
116
|
-
let data = await _fetch.json()
|
|
117
|
-
return (data as any)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
109
|
setGlobals(globalFields): Promise<void> {
|
|
121
110
|
// console.log({globalFields})
|
|
122
111
|
return new Promise((resolve, reject) => {
|
|
123
|
-
this.apiRequest(`${this.endpoint}/globals`, {
|
|
112
|
+
this.host.apiRequest(`${this.endpoint}/globals`, {
|
|
124
113
|
method: "PATCH",
|
|
125
114
|
body: JSON.stringify({globalFields})
|
|
126
115
|
}).then(res => {
|
|
@@ -205,7 +194,7 @@ export default class FileMakerConnection {
|
|
|
205
194
|
})
|
|
206
195
|
|
|
207
196
|
if (this.databaseConDetails[0].method === "filemaker") {
|
|
208
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
197
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
209
198
|
hostname: this.hostname,
|
|
210
199
|
port: 443,
|
|
211
200
|
method: "POST",
|
|
@@ -232,7 +221,7 @@ export default class FileMakerConnection {
|
|
|
232
221
|
this._token = (<loginOptionsToken>this.databaseConDetails[0]).token
|
|
233
222
|
resolve(this.token)
|
|
234
223
|
} else if (this.databaseConDetails[0].method === "oauth") {
|
|
235
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
224
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
236
225
|
method: "POST",
|
|
237
226
|
headers: {
|
|
238
227
|
"Content-Type": "application/json",
|
|
@@ -250,7 +239,7 @@ export default class FileMakerConnection {
|
|
|
250
239
|
resolve(this.token)
|
|
251
240
|
})
|
|
252
241
|
} else if (this.databaseConDetails[0].method === "claris") {
|
|
253
|
-
fetch(`${this.endpoint}/sessions`, {
|
|
242
|
+
fetch(`${this.databases[0].endpoint}/sessions`, {
|
|
254
243
|
method: "POST",
|
|
255
244
|
headers: {
|
|
256
245
|
"Content-Type": "application/json",
|
|
@@ -279,6 +268,17 @@ export default class FileMakerConnection {
|
|
|
279
268
|
get endpoint(): string {
|
|
280
269
|
return `https://${this.hostname}/fmi/data/v2/databases/`
|
|
281
270
|
}
|
|
271
|
+
|
|
272
|
+
async apiRequest(url: string | Request, options: any = {}): Promise<any> {
|
|
273
|
+
if (!options.headers) options.headers = {}
|
|
274
|
+
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json"
|
|
275
|
+
options.headers["authorization"] = "Bearer " + this._token
|
|
276
|
+
options.rejectUnauthorized = this.rejectUnauthroized
|
|
277
|
+
|
|
278
|
+
let _fetch = await fetch(url, options)
|
|
279
|
+
let data = await _fetch.json()
|
|
280
|
+
return (data as any)
|
|
281
|
+
}
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
class layout {
|
|
@@ -324,7 +324,7 @@ class layout {
|
|
|
324
324
|
return new Promise(async (resolve, reject) => {
|
|
325
325
|
let url = `${this.endpoint}/script/${encodeURI(script.name)}`
|
|
326
326
|
if (script.parameter) url += "?" + encodeURI(script.parameter)
|
|
327
|
-
this.database.apiRequest(url, {
|
|
327
|
+
this.database.host.apiRequest(url, {
|
|
328
328
|
port: 443,
|
|
329
329
|
method: "GET"
|
|
330
330
|
})
|
|
@@ -344,7 +344,7 @@ class layout {
|
|
|
344
344
|
|
|
345
345
|
public getLayoutMeta(): Promise<layout | FMError> {
|
|
346
346
|
return new Promise((resolve, reject) => {
|
|
347
|
-
this.database.apiRequest(this.endpoint).then(res => {
|
|
347
|
+
this.database.host.apiRequest(this.endpoint).then(res => {
|
|
348
348
|
this.metadata = res.response
|
|
349
349
|
resolve(this)
|
|
350
350
|
})
|
|
@@ -408,7 +408,7 @@ class record extends EventEmitter {
|
|
|
408
408
|
return new Promise(async (resolve, reject) => {
|
|
409
409
|
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
410
410
|
|
|
411
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
411
|
+
this.layout.database.host.apiRequest(this.endpoint, {
|
|
412
412
|
port: 443,
|
|
413
413
|
method: "GET"
|
|
414
414
|
})
|
|
@@ -442,7 +442,7 @@ class record extends EventEmitter {
|
|
|
442
442
|
// This is a new record
|
|
443
443
|
extraBody.fieldData = data.fieldData
|
|
444
444
|
|
|
445
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
445
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/records`, {
|
|
446
446
|
port: 443,
|
|
447
447
|
method: "POST",
|
|
448
448
|
body: JSON.stringify(extraBody)
|
|
@@ -467,7 +467,7 @@ class record extends EventEmitter {
|
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
for (let item of Object.keys(extraBody)) data[item] = extraBody[item]
|
|
470
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
470
|
+
this.layout.database.host.apiRequest(this.endpoint, {
|
|
471
471
|
port: 443,
|
|
472
472
|
method: "PATCH",
|
|
473
473
|
body: JSON.stringify(data)
|
|
@@ -699,7 +699,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
699
699
|
run() {
|
|
700
700
|
return new Promise((resolve, reject) => {
|
|
701
701
|
// console.log(this.#toObject())
|
|
702
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
702
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
703
703
|
method: "GET"
|
|
704
704
|
}).then(async res => {
|
|
705
705
|
// // console.log(res)
|
|
@@ -765,7 +765,7 @@ class find extends recordGetOperation {
|
|
|
765
765
|
run() {
|
|
766
766
|
return new Promise((resolve, reject) => {
|
|
767
767
|
// console.log(this.#toObject())
|
|
768
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
768
|
+
this.layout.database.host.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
769
769
|
port: 443,
|
|
770
770
|
method: "POST",
|
|
771
771
|
body: JSON.stringify(this.toObject())
|