@jd-data-limited/easy-fm 3.2.2 → 3.2.3

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",
7
7
  "moment": "^2.29.4",
8
8
  "node-fetch": "3.2.8",
9
+ "node-fetch-cookies": "^2.1.0",
9
10
  "typescript": "^5.2.2",
10
11
  "ytdl-core": "^4.11.4"
11
12
  },
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "events";
3
- import { Request } from "node-fetch";
3
+ import { Request } from "node-fetch-cookies";
4
4
  import { LayoutInterface } from "../layouts/layoutInterface.js";
5
5
  import { Layout } from "../layouts/layout.js";
6
6
  import { databaseOptionsWithExternalSources, DatabaseStructure, Script } from "../types.js";
@@ -10,7 +10,7 @@ export declare class Database<T extends DatabaseStructure> extends EventEmitter
10
10
  private _token;
11
11
  readonly host: HostBase;
12
12
  private connection_details;
13
- private cookies;
13
+ private cookieJar;
14
14
  readonly name: string;
15
15
  constructor(host: HostBase, conn: databaseOptionsWithExternalSources);
16
16
  private generateExternalSourceLogin;
@@ -24,5 +24,5 @@ export declare class Database<T extends DatabaseStructure> extends EventEmitter
24
24
  setGlobals(globalFields: any): Promise<void>;
25
25
  script(name: any, parameter?: string): Script;
26
26
  _tokenExpired(): void;
27
- streamContainer(url: any): Promise<import("node-fetch").Response>;
27
+ streamContainer(url: any): Promise<any>;
28
28
  }
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  });
12
12
  };
13
13
  import { EventEmitter } from "events";
14
- import fetch from "node-fetch";
14
+ import { fetch, CookieJar } from "node-fetch-cookies";
15
15
  import { generateAuthorizationHeaders } from "./generateAuthorizationHeaders.js";
16
16
  import { FMError } from "../FMError.js";
17
17
  import { Layout } from "../layouts/layout.js";
18
18
  export class Database extends EventEmitter {
19
19
  constructor(host, conn) {
20
20
  super();
21
- this.cookies = {};
21
+ this.cookieJar = new CookieJar();
22
22
  this.host = host;
23
23
  this.name = conn.database;
24
24
  this.connection_details = conn;
@@ -40,7 +40,7 @@ export class Database extends EventEmitter {
40
40
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
41
41
  if (!this.token)
42
42
  reject(new Error("Not logged in"));
43
- let _fetch = yield fetch(`${this.endpoint}/sessions/${this.token}`, {
43
+ let _fetch = yield fetch(this.cookieJar, `${this.endpoint}/sessions/${this.token}`, {
44
44
  method: "DELETE",
45
45
  headers: {
46
46
  "content-type": "application/json"
@@ -55,7 +55,7 @@ export class Database extends EventEmitter {
55
55
  login() {
56
56
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
57
57
  // Reset cookies
58
- this.cookies = {};
58
+ this.cookieJar = {};
59
59
  try {
60
60
  yield this.host.getMetadata();
61
61
  }
@@ -70,7 +70,7 @@ export class Database extends EventEmitter {
70
70
  resolve(this.token);
71
71
  }
72
72
  else {
73
- fetch(`${this.endpoint}/sessions`, {
73
+ fetch(this.cookieJar, `${this.endpoint}/sessions`, {
74
74
  hostname: this.host.hostname,
75
75
  port: 443,
76
76
  method: "POST",
@@ -110,11 +110,11 @@ export class Database extends EventEmitter {
110
110
  options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json";
111
111
  options.headers["authorization"] = "Bearer " + this._token;
112
112
  options.rejectUnauthorized = this.host.verify;
113
- let _fetch = yield fetch(url, options);
113
+ let _fetch = yield fetch(this.cookieJar, url, options);
114
114
  if (_fetch.headers.get('set-cookie')) {
115
115
  for (let cookie of _fetch.headers.get('set-cookie')) {
116
116
  let cookie_split = cookie.split("=");
117
- this.cookies[cookie_split[0]] = cookie_split[1];
117
+ this.cookieJar[cookie_split[0]] = cookie_split[1];
118
118
  }
119
119
  }
120
120
  let data = yield _fetch.json();
@@ -159,21 +159,21 @@ export class Database extends EventEmitter {
159
159
  streamContainer(url) {
160
160
  return __awaiter(this, void 0, void 0, function* () {
161
161
  let headers = {};
162
- if (Object.keys(this.cookies).length !== 0) {
163
- headers["Cookie"] = Object.keys(this.cookies)
162
+ if (Object.keys(this.cookieJar).length !== 0) {
163
+ headers["Cookie"] = Object.keys(this.cookieJar)
164
164
  .map(key => {
165
- return key + "=" + this.cookies[key];
165
+ return key + "=" + this.cookieJar[key];
166
166
  })
167
167
  .join("; ");
168
168
  }
169
169
  // Automatically switch between the http and https modules, based on which is needed
170
- let res = yield fetch(url, {
170
+ let res = yield fetch(this.cookieJar, url, {
171
171
  headers
172
172
  });
173
173
  if (res.headers.get('set-cookie')) {
174
174
  for (let cookie of res.headers['set-cookie']) {
175
175
  let cookie_split = cookie.split("=");
176
- this.cookies[cookie_split[0]] = cookie_split[1];
176
+ this.cookieJar[cookie_split[0]] = cookie_split[1];
177
177
  }
178
178
  res.headers.set('set-cookie', null);
179
179
  }
@@ -3,7 +3,8 @@
3
3
  */
4
4
 
5
5
  import {EventEmitter} from "events";
6
- import fetch, {HeadersInit, Request} from "node-fetch";
6
+ import {HeadersInit} from "node-fetch";
7
+ import {fetch, CookieJar, Request} from "node-fetch-cookies"
7
8
  import {generateAuthorizationHeaders} from "./generateAuthorizationHeaders.js";
8
9
  import {FMError} from "../FMError.js";
9
10
  import {LayoutInterface} from "../layouts/layoutInterface.js";
@@ -27,7 +28,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
27
28
  private _token: any;
28
29
  readonly host: HostBase;
29
30
  private connection_details: databaseOptionsWithExternalSources
30
- private cookies: { [key: string]: string } = {}
31
+ private cookieJar = new CookieJar()
31
32
  readonly name: string;
32
33
 
33
34
  constructor(host: HostBase, conn: databaseOptionsWithExternalSources) {
@@ -55,7 +56,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
55
56
  return new Promise(async (resolve, reject) => {
56
57
  if (!this.token) reject(new Error("Not logged in"))
57
58
 
58
- let _fetch = await fetch(`${this.endpoint}/sessions/${this.token}`, {
59
+ let _fetch = await fetch(this.cookieJar, `${this.endpoint}/sessions/${this.token}`, {
59
60
  method: "DELETE",
60
61
  headers: {
61
62
  "content-type": "application/json"
@@ -71,7 +72,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
71
72
  login() {
72
73
  return new Promise<string>(async (resolve, reject) => {
73
74
  // Reset cookies
74
- this.cookies = {}
75
+ this.cookieJar = {}
75
76
 
76
77
  try {
77
78
  await this.host.getMetadata()
@@ -86,7 +87,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
86
87
  resolve(this.token)
87
88
  }
88
89
  else {
89
- fetch(`${this.endpoint}/sessions`, {
90
+ fetch(this.cookieJar, `${this.endpoint}/sessions`, {
90
91
  hostname: this.host.hostname,
91
92
  port: 443,
92
93
  method: "POST",
@@ -128,11 +129,11 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
128
129
  options.headers["authorization"] = "Bearer " + this._token
129
130
  options.rejectUnauthorized = this.host.verify
130
131
 
131
- let _fetch = await fetch(url, options)
132
+ let _fetch = await fetch(this.cookieJar, url, options)
132
133
  if (_fetch.headers.get('set-cookie')) {
133
134
  for (let cookie of _fetch.headers.get('set-cookie')) {
134
135
  let cookie_split = cookie.split("=")
135
- this.cookies[cookie_split[0]] = cookie_split[1]
136
+ this.cookieJar[cookie_split[0]] = cookie_split[1]
136
137
  }
137
138
  }
138
139
  let data = await _fetch.json() as fileMakerResponse
@@ -185,23 +186,23 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
185
186
 
186
187
 
187
188
  let headers = {}
188
- if (Object.keys(this.cookies).length !== 0) {
189
- headers["Cookie"] = Object.keys(this.cookies)
189
+ if (Object.keys(this.cookieJar).length !== 0) {
190
+ headers["Cookie"] = Object.keys(this.cookieJar)
190
191
  .map(key => {
191
- return key + "=" + this.cookies[key]
192
+ return key + "=" + this.cookieJar[key]
192
193
  })
193
194
  .join("; ")
194
195
  }
195
196
 
196
197
  // Automatically switch between the http and https modules, based on which is needed
197
- let res = await fetch(url, {
198
+ let res = await fetch(this.cookieJar, url, {
198
199
  headers
199
200
  })
200
201
 
201
202
  if (res.headers.get('set-cookie')) {
202
203
  for (let cookie of res.headers['set-cookie']) {
203
204
  let cookie_split = cookie.split("=")
204
- this.cookies[cookie_split[0]] = cookie_split[1]
205
+ this.cookieJar[cookie_split[0]] = cookie_split[1]
205
206
  }
206
207
  res.headers.set('set-cookie', null)
207
208
  }