diff --git a/.eslintrc.json b/.eslintrc.json
index cccf421..8716c89 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -59,7 +59,8 @@
"allowList": {
"changeDetectorRef": true,
"iCalendarKey": true,
- "iCalendarLink": true
+ "iCalendarLink": true,
+ "NativeHttpParams": true
}
}
],
diff --git a/android/.idea/compiler.xml b/android/.idea/compiler.xml
index fb7f4a8..b589d56 100644
--- a/android/.idea/compiler.xml
+++ b/android/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/android/.idea/migrations.xml b/android/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/android/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml
index 860da66..55c0ec2 100644
--- a/android/.idea/misc.xml
+++ b/android/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/android/.idea/other.xml b/android/.idea/other.xml
new file mode 100644
index 0000000..0d3a1fb
--- /dev/null
+++ b/android/.idea/other.xml
@@ -0,0 +1,263 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/xml/config.xml b/android/app/src/main/res/xml/config.xml
index d382009..0a78296 100644
--- a/android/app/src/main/res/xml/config.xml
+++ b/android/app/src/main/res/xml/config.xml
@@ -2,10 +2,6 @@
-
-
-
-
diff --git a/ios/App/App/config.xml b/ios/App/App/config.xml
index 153aa63..f5586e8 100644
--- a/ios/App/App/config.xml
+++ b/ios/App/App/config.xml
@@ -2,10 +2,6 @@
-
-
-
-
diff --git a/ios/App/Podfile.lock b/ios/App/Podfile.lock
index 402b7fa..b568b90 100644
--- a/ios/App/Podfile.lock
+++ b/ios/App/Podfile.lock
@@ -81,7 +81,7 @@ SPEC CHECKSUMS:
CapacitorStatusBar: 2e4369f99166125435641b1908d05f561eaba6f6
CapawesomeTeamCapacitorFileOpener: 3b92b7d407c6a85e241e77ff081f0dcc4beb86b3
CapawesomeTeamCapacitorNfc: d1c1af83a57d1f385c221a50c894244e116c3160
- CordovaPlugins: e46692a88b8b37ca8bd53ae20ee33bbcb18248cd
+ CordovaPlugins: 1a820855fc3c3adb569ae18eeacc30ab15f1fed8
PODFILE CHECKSUM: baa07d86309c338c813d17409138037a1834285f
diff --git a/package-lock.json b/package-lock.json
index 0f74f84..953c79f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -50,7 +50,6 @@
"@ngneat/elf-entities": "5.0.0",
"@ngneat/elf-persist-state": "1.2.0",
"buffer": "6.0.3",
- "cordova-plugin-advanced-http": "3.2.2",
"cordova-plugin-file": "6.0.2",
"date-fns": "3.3.1",
"hammerjs": "2.0.8",
@@ -9901,17 +9900,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/cordova-plugin-advanced-http": {
- "version": "3.2.2",
- "resolved": "https://registry.npmjs.org/cordova-plugin-advanced-http/-/cordova-plugin-advanced-http-3.2.2.tgz",
- "integrity": "sha512-9djtQuRwWMqCLTNRrtAIlGyRcs2D0AJXOzkedOQ6udlg3IVE58hhxjrFOdKz6WvoJ6w2MNVeRYafYvoWLHFuMA==",
- "engines": [
- {
- "name": "cordova",
- "version": ">=4.0.0"
- }
- ]
- },
"node_modules/cordova-plugin-file": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/cordova-plugin-file/-/cordova-plugin-file-6.0.2.tgz",
diff --git a/package.json b/package.json
index 8a8e864..3aad099 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,6 @@
"@ngneat/elf-entities": "5.0.0",
"@ngneat/elf-persist-state": "1.2.0",
"buffer": "6.0.3",
- "cordova-plugin-advanced-http": "3.2.2",
"cordova-plugin-file": "6.0.2",
"date-fns": "3.3.1",
"hammerjs": "2.0.8",
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 1417cab..cd9fe58 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -7,7 +7,6 @@ import { RouteReuseStrategy } from '@angular/router';
import { CoreModule, GlobalErrorHandlerService } from '@app/core';
import { SharedModule } from '@app/shared';
import { File } from '@awesome-cordova-plugins/file/ngx';
-import { HTTP } from '@awesome-cordova-plugins/http/ngx';
import { IonicModule, IonicRouteStrategy, isPlatform } from '@ionic/angular';
import { register as registerSwiper } from 'swiper/element/bundle';
import { AppRoutingModule } from './app-routing.module';
@@ -32,7 +31,6 @@ registerSwiper();
],
providers: [
File,
- HTTP,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{
provide: ErrorHandler,
diff --git a/src/app/core/interceptors/http-native.interceptor.ts b/src/app/core/interceptors/http-native.interceptor.ts
index dcaf424..d6e1e61 100644
--- a/src/app/core/interceptors/http-native.interceptor.ts
+++ b/src/app/core/interceptors/http-native.interceptor.ts
@@ -10,15 +10,13 @@ import {
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Config } from '@app/config';
-import { HTTPResponse } from '@awesome-cordova-plugins/http/ngx';
-import { Observable } from 'rxjs';
import {
- INativeHttpRequestOptions,
- INativeHttpRequestOptionsHeaders,
- INativeHttpRequestOptionsParameters,
- NativeHttpMethod,
- NativeHttpService,
-} from '../services';
+ HttpHeaders as NativeHttpHeaders,
+ HttpParams as NativeHttpParams,
+ HttpResponse as NativeHttpResponse,
+} from '@capacitor/core';
+import { Observable } from 'rxjs';
+import { CapacitorHttpService } from '../services';
const LOGTAG = '[HttpNativeInterceptor]';
@@ -26,7 +24,7 @@ const LOGTAG = '[HttpNativeInterceptor]';
providedIn: 'root',
})
export class HttpNativeInterceptor implements HttpInterceptor {
- constructor(private readonly nativeHttpService: NativeHttpService) {}
+ constructor(private readonly capacitorHttpService: CapacitorHttpService) {}
public intercept(request: HttpRequest, next: HttpHandler): Observable> {
if (!request.url.startsWith('http')) {
@@ -40,49 +38,31 @@ export class HttpNativeInterceptor implements HttpInterceptor {
private handleNativeRequest(request: HttpRequest): Observable> {
return new Observable(subscribe => {
- const options = this.getNativeHttpRequestOptionsFrom(request);
- const requestId = this.nativeHttpService.request(
- request.url,
- options,
- response => {
- const ngHttpResponse = this.convertNativeToNgHttpResponse(response);
+ const method = request.method.toLowerCase();
+ const headers = this.convertNgToNativeHttpHeaders(request.headers);
+ const parameters = this.convertNgToNativeHttpParams(request.params);
+ this.capacitorHttpService
+ .request({
+ method,
+ url: request.url,
+ headers,
+ params: parameters,
+ data: request.body,
+ })
+ .then(result => {
+ const ngHttpResponse = this.convertNativeToNgHttpResponse(result);
subscribe.next(ngHttpResponse);
subscribe.complete();
- },
- error => {
- if (error.status === -8) {
- // Ignore errors thrown when a request is aborted
- // https://github.com/silkimen/cordova-plugin-advanced-http#abort
- subscribe.complete();
- }
+ })
+ .catch(error => {
const ngHttpErrorResponse = this.convertNativeToNgHttpErrorResponse(error);
subscribe.error(ngHttpErrorResponse);
subscribe.complete();
- },
- );
- return () => {
- this.nativeHttpService
- .abort(requestId)
- .catch(error => console.error(`${LOGTAG} Error occurred while aborting native request.`, error));
- };
+ });
});
}
- private getNativeHttpRequestOptionsFrom(request: HttpRequest): INativeHttpRequestOptions {
- const method = request.method.toUpperCase() as NativeHttpMethod;
- const data = request.body;
- const headers = this.convertNgToNativeHttpHeaders(request.headers);
- const parameters = this.convertNgToNativeHttpParams(request.params);
- const options: INativeHttpRequestOptions = {
- method: method,
- data: data,
- headers: headers,
- params: parameters,
- };
- return options;
- }
-
- private convertNativeToNgHttpResponse(response: HTTPResponse): HttpResponse {
+ private convertNativeToNgHttpResponse(response: NativeHttpResponse): HttpResponse {
return new HttpResponse({
body: response.data,
headers: new HttpHeaders(response.headers),
@@ -92,9 +72,9 @@ export class HttpNativeInterceptor implements HttpInterceptor {
});
}
- private convertNativeToNgHttpErrorResponse(response: HTTPResponse): HttpErrorResponse {
+ private convertNativeToNgHttpErrorResponse(response: NativeHttpResponse): HttpErrorResponse {
return new HttpErrorResponse({
- error: response.error,
+ error: '', // TODO
headers: new HttpHeaders(response.headers),
status: response.status,
statusText: undefined,
@@ -102,7 +82,7 @@ export class HttpNativeInterceptor implements HttpInterceptor {
});
}
- private convertNgToNativeHttpHeaders(ngHttpHeaders: HttpHeaders): INativeHttpRequestOptionsHeaders {
+ private convertNgToNativeHttpHeaders(ngHttpHeaders: HttpHeaders): NativeHttpHeaders {
const nativeHttpHeaders: { [name: string]: string } = {};
for (const headerKey of ngHttpHeaders.keys()) {
const headerValue = ngHttpHeaders.get(headerKey);
@@ -114,7 +94,7 @@ export class HttpNativeInterceptor implements HttpInterceptor {
return nativeHttpHeaders;
}
- private convertNgToNativeHttpParams(ngHttpParameters: HttpParams): INativeHttpRequestOptionsParameters {
+ private convertNgToNativeHttpParams(ngHttpParameters: HttpParams): NativeHttpParams {
const nativeHttpParameters: { [name: string]: string } = {};
for (const headerKey of ngHttpParameters.keys()) {
const headerValue = ngHttpParameters.get(headerKey);
diff --git a/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.spec.ts b/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.spec.ts
new file mode 100644
index 0000000..9932baf
--- /dev/null
+++ b/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.spec.ts
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { CapacitorHttpService } from './capacitor-http.service';
+
+describe('CapacitorHttpService', () => {
+ let service: CapacitorHttpService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(CapacitorHttpService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.ts b/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.ts
new file mode 100644
index 0000000..1d76b7c
--- /dev/null
+++ b/src/app/core/services/capacitor/capacitor-http/capacitor-http.service.ts
@@ -0,0 +1,11 @@
+import { Injectable } from '@angular/core';
+import { CapacitorHttp, HttpOptions, HttpResponse } from '@capacitor/core';
+
+@Injectable({
+ providedIn: 'root',
+})
+export class CapacitorHttpService {
+ public request(options: HttpOptions): Promise {
+ return CapacitorHttp.request(options);
+ }
+}
diff --git a/src/app/core/services/capacitor/index.ts b/src/app/core/services/capacitor/index.ts
index 2324299..b0069d3 100644
--- a/src/app/core/services/capacitor/index.ts
+++ b/src/app/core/services/capacitor/index.ts
@@ -1,2 +1,3 @@
export * from './capacitor-app/capacitor-app.service';
+export * from './capacitor-http/capacitor-http.service';
export * from './capacitor-nfc/capacitor-nfc.service';
diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts
index 9a73519..8f72586 100644
--- a/src/app/core/services/index.ts
+++ b/src/app/core/services/index.ts
@@ -2,7 +2,6 @@ export * from './api';
export * from './capacitor';
export * from './dialog/dialog.service';
export * from './global-error-handler/global-error-handler.service';
-export * from './native-http/native-http.service';
export * from './nfc';
export * from './notification/notification.service';
export * from './storage/storage.service';
diff --git a/src/app/core/services/native-http/native-http.service.spec.ts b/src/app/core/services/native-http/native-http.service.spec.ts
deleted file mode 100644
index b0b715e..0000000
--- a/src/app/core/services/native-http/native-http.service.spec.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { TestBed } from '@angular/core/testing';
-import { HTTP } from '@awesome-cordova-plugins/http/ngx';
-import { createSpyObj } from '@tests/helpers';
-import { NativeHttpService } from './native-http.service';
-
-describe('NativeHttpService', () => {
- let service: NativeHttpService;
- let httpSpy: jest.Mocked;
-
- beforeEach(() => {
- httpSpy = createSpyObj('HTTP', {
- setRequestTimeout: undefined,
- sendRequest: undefined,
- ErrorCode: undefined,
- });
- TestBed.configureTestingModule({
- providers: [{ provide: HTTP, useValue: httpSpy }],
- });
- service = TestBed.inject(NativeHttpService);
- });
-
- it('should be created', () => {
- expect(service).toBeTruthy();
- });
-});
diff --git a/src/app/core/services/native-http/native-http.service.ts b/src/app/core/services/native-http/native-http.service.ts
deleted file mode 100644
index fb393dd..0000000
--- a/src/app/core/services/native-http/native-http.service.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-import { Injectable } from '@angular/core';
-import { HTTP, HTTPResponse } from '@awesome-cordova-plugins/http/ngx';
-
-export enum NativeHttpMethod {
- GET = 'get',
- POST = 'post',
- PUT = 'put',
- PATCH = 'patch',
- HEAD = 'head',
- DELETE = 'delete',
- OPTIONS = 'options',
-}
-
-export interface INativeHttpRequestOptions {
- method: NativeHttpMethod;
- headers?: INativeHttpRequestOptionsHeaders;
- params?: INativeHttpRequestOptionsParameters;
- data?: unknown;
- serializer?: INativeHttpRequestSerializer;
-}
-
-export type INativeHttpRequestSerializer = 'urlencoded' | 'json' | 'utf8' | 'multipart' | 'raw';
-
-export type INativeHttpRequestOptionsHeaders = { [name: string]: string };
-
-export type INativeHttpRequestOptionsParameters = { [name: string]: string };
-
-export interface INativeHttpAbortedResult {
- aborted: boolean;
-}
-
-const LOGTAG = '[NativeHttpService]';
-
-@Injectable({
- providedIn: 'root',
-})
-export class NativeHttpService {
- private readonly defaultDataSerializer: INativeHttpRequestSerializer = 'json';
-
- constructor(private readonly nativeHttp: HTTP) {}
-
- /**
- * Execute a HTTP request.
- * @returns Request ID
- * @see https://github.com/silkimen/cordova-plugin-advanced-http#sendrequest
- */
- public request(
- url: string,
- options: INativeHttpRequestOptions,
- successCallback: (response: HTTPResponse) => void,
- errorCallback: (response: HTTPResponse) => void,
- ): number {
- if (!options.serializer) {
- const contentType = this.findContentTypeHeader(options.headers || {});
- const dataSerializer = this.getDataSerializerByContentType(contentType);
- options.serializer = dataSerializer || this.defaultDataSerializer;
- }
- return (window as any).cordova.plugin.http.sendRequest(
- url,
- options,
- (response: HTTPResponse) => {
- const setCookie = response.headers['set-cookie'] || response.headers['Set-Cookie'];
- if (setCookie) {
- const origin = new URL(url).origin;
- this.nativeHttp.setCookie(origin, setCookie);
- }
- successCallback(response);
- },
- errorCallback,
- );
- }
-
- /**
- * Abort a HTTP request.
- * @see https://github.com/silkimen/cordova-plugin-advanced-http#abort
- */
- public abort(requestId: number): Promise {
- return new Promise((resolve, reject) => {
- (window as any).cordova.plugin.http.abort(
- requestId,
- (result: INativeHttpAbortedResult) => {
- resolve(result);
- },
- (error: any) => {
- reject(error.error);
- },
- );
- });
- }
-
- private findContentTypeHeader(headers: INativeHttpRequestOptionsHeaders): string | undefined {
- return headers['Content-Type'] || headers['content-type'] || undefined;
- }
-
- private getDataSerializerByContentType(contentType: string | undefined): INativeHttpRequestSerializer | null {
- if (!contentType) {
- return null;
- }
- if (contentType.startsWith('application/json')) {
- return 'json';
- } else if (contentType.startsWith('application/x-www-form-urlencoded')) {
- return 'urlencoded';
- } else if (contentType.startsWith('plain/text')) {
- return 'utf8';
- } else if (contentType.startsWith('multipart/form-data')) {
- return 'multipart';
- } else if (contentType.startsWith('application/octet-stream')) {
- return 'raw';
- }
- return null;
- }
-}