incyclist-services 1.7.74 → 1.7.75

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.
@@ -65,6 +65,7 @@ let IncyclistBindings = (() => {
65
65
  logging;
66
66
  serial;
67
67
  crypto;
68
+ fetch;
68
69
  ant;
69
70
  ble;
70
71
  wifi;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -108,6 +108,14 @@ let OverpassApi = (() => {
108
108
  };
109
109
  }
110
110
  async post(url, data, conf) {
111
+ const fetchBinding = this.getBindings()?.fetch;
112
+ if (fetchBinding) {
113
+ try {
114
+ return await this.postViaFetchBinding(fetchBinding, url, data);
115
+ }
116
+ catch {
117
+ }
118
+ }
111
119
  try {
112
120
  const https = require('https');
113
121
  return await this.postViaNodeHttps(https, url, data);
@@ -121,6 +129,23 @@ let OverpassApi = (() => {
121
129
  return await super.post(url, data, config);
122
130
  }
123
131
  }
132
+ async postViaFetchBinding(fetchBinding, url, data) {
133
+ const headers = this.getOverpassHeaders();
134
+ const body = typeof data === 'string' ? data : JSON.stringify(data);
135
+ const res = await fetchBinding.fetch(url, {
136
+ method: 'POST',
137
+ headers,
138
+ body,
139
+ referrerPolicy: 'unsafe-url'
140
+ });
141
+ return {
142
+ data: res.data,
143
+ status: res.status,
144
+ statusText: res.statusText,
145
+ headers: res.headers,
146
+ config: {}
147
+ };
148
+ }
124
149
  async postViaNodeHttps(https, url, data) {
125
150
  return new Promise((resolve, reject) => {
126
151
  const reqUrl = new URL(url);
@@ -62,6 +62,7 @@ let IncyclistBindings = (() => {
62
62
  logging;
63
63
  serial;
64
64
  crypto;
65
+ fetch;
65
66
  ant;
66
67
  ble;
67
68
  wifi;
@@ -0,0 +1 @@
1
+ export {};
@@ -102,6 +102,14 @@ let OverpassApi = (() => {
102
102
  };
103
103
  }
104
104
  async post(url, data, conf) {
105
+ const fetchBinding = this.getBindings()?.fetch;
106
+ if (fetchBinding) {
107
+ try {
108
+ return await this.postViaFetchBinding(fetchBinding, url, data);
109
+ }
110
+ catch {
111
+ }
112
+ }
105
113
  try {
106
114
  const https = require('https');
107
115
  return await this.postViaNodeHttps(https, url, data);
@@ -115,6 +123,23 @@ let OverpassApi = (() => {
115
123
  return await super.post(url, data, config);
116
124
  }
117
125
  }
126
+ async postViaFetchBinding(fetchBinding, url, data) {
127
+ const headers = this.getOverpassHeaders();
128
+ const body = typeof data === 'string' ? data : JSON.stringify(data);
129
+ const res = await fetchBinding.fetch(url, {
130
+ method: 'POST',
131
+ headers,
132
+ body,
133
+ referrerPolicy: 'unsafe-url'
134
+ });
135
+ return {
136
+ data: res.data,
137
+ status: res.status,
138
+ statusText: res.statusText,
139
+ headers: res.headers,
140
+ config: {}
141
+ };
142
+ }
118
143
  async postViaNodeHttps(https, url, data) {
119
144
  return new Promise((resolve, reject) => {
120
145
  const reqUrl = new URL(url);
@@ -11,6 +11,7 @@ import type { IVideoProcessor } from '../video';
11
11
  import type { ISecretBinding } from '../secret';
12
12
  import type { ISerialBinding } from '../serial/types';
13
13
  import type { ICryptoBinding } from '../crypto/types';
14
+ import type { IFetchBinding } from '../fetch/types';
14
15
  export interface IUserSettingsBinding {
15
16
  getAll(): Promise<any>;
16
17
  set(key: string, value: any): Promise<boolean>;
@@ -33,6 +34,7 @@ export declare class IncyclistBindings {
33
34
  logging: ILogBinding;
34
35
  serial: ISerialBinding;
35
36
  crypto: ICryptoBinding;
37
+ fetch?: IFetchBinding;
36
38
  ant: any;
37
39
  ble: any;
38
40
  wifi: any;
@@ -0,0 +1,16 @@
1
+ export interface IFetchRequestInit {
2
+ method?: string;
3
+ headers?: Record<string, string>;
4
+ body?: string;
5
+ referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
6
+ }
7
+ export interface IFetchResponse {
8
+ ok: boolean;
9
+ status: number;
10
+ statusText: string;
11
+ headers: Record<string, string>;
12
+ data: string;
13
+ }
14
+ export interface IFetchBinding {
15
+ fetch(url: string, init?: IFetchRequestInit): Promise<IFetchResponse>;
16
+ }
@@ -4,4 +4,5 @@ export type * from './repository/types';
4
4
  export type * from './path';
5
5
  export type * from './video';
6
6
  export type * from './crypto/types';
7
+ export type * from './fetch/types';
7
8
  export type * from './bindings/types';
@@ -2,6 +2,7 @@ import { AppApiBase } from '../../apps/base/api/base';
2
2
  import { EventLogger } from 'gd-eventlog';
3
3
  import { UserSettingsService } from '../../settings';
4
4
  import { AxiosResponse } from 'axios';
5
+ import type { IFetchBinding } from '../../api/fetch/types';
5
6
  export declare const OVERPASS_URL_DEFAULT = "https://overpass.kumi.systems/api/interpreter";
6
7
  export declare class OverpassApi extends AppApiBase {
7
8
  protected url: string;
@@ -15,6 +16,7 @@ export declare class OverpassApi extends AppApiBase {
15
16
  Referer: string;
16
17
  };
17
18
  protected post(url: string, data?: object | string, conf?: object): Promise<AxiosResponse>;
19
+ protected postViaFetchBinding(fetchBinding: IFetchBinding, url: string, data?: object | string): Promise<AxiosResponse>;
18
20
  protected postViaNodeHttps(https: any, url: string, data?: object | string): Promise<any>;
19
21
  query(queryOL: string, timeout?: number): Promise<JSON | string | undefined>;
20
22
  singleQuery(queryOL: string): Promise<JSON | string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.74",
3
+ "version": "1.7.75",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },