Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"builderMode": "application",
"main": "projects/request/src/test.ts",
"karmaConfig": "projects/request/karma.conf.js",
"tsConfig": "projects/request/tsconfig.spec.json",
"include": ["projects/request/src/**/*.spec.ts"],
"scripts": []
}
}
Expand Down
13 changes: 7 additions & 6 deletions projects/request/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ module.exports = function (config) {
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
random: false,
timeoutInterval: 10000,
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
Expand All @@ -37,8 +35,11 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
browserNoActivityTimeout: 120000,
browserDisconnectTimeout: 30000,
browserDisconnectTolerance: 3,
});
};
5 changes: 1 addition & 4 deletions projects/request/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"dest": "../../dist/request",
"lib": {
"entryFile": "src/public-api.ts"
},
"allowedNonPeerDependencies": [
"lodash"
]
}
}
5 changes: 2 additions & 3 deletions projects/request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "request",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0",
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0"
"@angular/common": "^18.0.0 || ^19.0.0",
"@angular/core": "^18.0.0 || ^19.0.0"
},
"dependencies": {
"lodash-es": "^4.17.21",
"tslib": "^2.3.0"
}
}
6 changes: 6 additions & 0 deletions projects/request/src/lib/request.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { RequestModule } from './request.module';

describe('RequestModule', () => {
Expand All @@ -12,6 +14,10 @@ describe('RequestModule', () => {
prefixUrl: 'TEST',
}),
],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
],
});

requestModule = TestBed.inject(RequestModule);
Expand Down
7 changes: 0 additions & 7 deletions projects/request/src/lib/request.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { RequestConfig, RequestService } from './request.service';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
imports: [
HttpClientModule,
],
providers: [
RequestService,
],
exports: [
HttpClientModule,
],
})
export class RequestModule {
constructor(@Optional() @SkipSelf() parentModule: RequestModule) {
Expand Down
28 changes: 15 additions & 13 deletions projects/request/src/lib/request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {

import {
HttpTestingController,
HttpClientTestingModule,
provideHttpClientTesting,
} from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';

import { RequestService, RequestConfig, DevModeService, QueryEncoder } from './request.service';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -68,12 +69,12 @@ describe('RequestService', () => {
let mockBackend: HttpTestingController;
let requestConfigSpy: RequestConfig;
let devModeServiceSpy: DevModeService;
let storageSpy: BrowserStorageService;

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
RequestService,
DevModeService,
{
Expand Down Expand Up @@ -102,7 +103,6 @@ describe('RequestService', () => {
mockBackend = TestBed.inject(HttpTestingController);
requestConfigSpy = TestBed.inject(RequestConfig);
devModeServiceSpy = TestBed.inject(DevModeService);
storageSpy = TestBed.inject(BrowserStorageService);
});

it('should be created', () => {
Expand Down Expand Up @@ -130,15 +130,16 @@ describe('RequestService', () => {
mockBackend.verify();
}));

it('should update apikey if new apikey exist', () => {
let res = { body: true, apikey: 'testapikey' };
it('should pass through response with custom headers', () => {
let res: any;
service.get(testURL, { headers: { some: 'keys' } }).subscribe(_res => {
res = _res;
});
const req = mockBackend.expectOne({ method: 'GET' });
req.flush(res);
req.flush({ body: true, apikey: 'testapikey' });

expect(storageSpy.setUser).toHaveBeenCalledWith({ apikey: res.apikey });
expect(res).toEqual({ body: true, apikey: 'testapikey' });
expect(req.request.headers.get('Content-Type')).toBe('application/json');
mockBackend.verify();
});

Expand All @@ -160,7 +161,7 @@ describe('RequestService', () => {
const req = mockBackend.expectOne({ url: testURL, method: 'GET' }).flush(ERR_MESSAGE, err);

expect(res).toBeUndefined();
expect(errRes).toEqual(ERR_MESSAGE);
expect(errRes.error).toEqual(ERR_MESSAGE);
mockBackend.verify();

}));
Expand Down Expand Up @@ -242,6 +243,7 @@ describe('RequestService', () => {
const req = mockBackend.expectOne({ url: testURL, method: 'POST' }).flush(ERR_MESSAGE, err);

expect(res).toBeUndefined();
expect(errRes.error).toEqual(ERR_MESSAGE);
mockBackend.verify();
}));
});
Expand Down Expand Up @@ -308,7 +310,7 @@ describe('RequestService', () => {
const req = mockBackend.expectOne({ url: `https://${PREFIX_URL}/${testURL}`, method: 'PUT' }).flush(ERR_MESSAGE, err);

expect(res).toBeUndefined();
expect(errRes).toEqual(ERR_MESSAGE);
expect(errRes.error).toEqual(ERR_MESSAGE);
mockBackend.verify();
}));
});
Expand Down Expand Up @@ -354,7 +356,7 @@ describe('RequestService', () => {

expect(res).toBeUndefined();
expect(console.error).not.toHaveBeenCalled();
expect(errRes).toEqual(ERR_MESSAGE);
expect(errRes.error).toEqual(ERR_MESSAGE);
mockBackend.verify();
}));
});
Expand Down Expand Up @@ -400,7 +402,7 @@ describe('RequestService', () => {
},
_err => {
errRes = _err;
expect(errRes).toEqual(ERR_MESSAGE);
expect(errRes.error).toEqual(ERR_MESSAGE);
}
);

Expand All @@ -415,7 +417,7 @@ describe('RequestService', () => {
_res => _res,
_err => {
errRes = _err;
expect(errRes.message).toEqual(badKey);
expect(errRes.error.message).toEqual(badKey);
}
);

Expand Down
27 changes: 13 additions & 14 deletions projects/request/src/lib/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Router } from '@angular/router';
import { Observable, of, throwError } from 'rxjs';
import { catchError, concatMap } from 'rxjs/operators';
import { has, isEmpty, each } from 'lodash-es';

interface RequestOptions {
headers?: any;
Expand Down Expand Up @@ -92,9 +91,9 @@ export class RequestService {
*/
setParams(options: {[key:string]: any}) {
let params: any;
if (!isEmpty(options)) {
if (options && Object.keys(options).length > 0) {
params = new HttpParams();
each(options, (value, key) => {
Object.entries(options).forEach(([key, value]) => {
params = params.append(key, value);
});
}
Expand Down Expand Up @@ -122,13 +121,13 @@ export class RequestService {
httpOptions = {};
}

if (!has(httpOptions, 'headers')) {
if (!('headers' in httpOptions)) {
httpOptions.headers = '';
}
if (!has(httpOptions, 'params')) {
if (!('params' in httpOptions)) {
httpOptions.params = '';
}
if (!has(httpOptions, 'observe')) {
if (!('observe' in httpOptions)) {
httpOptions.observe = 'body';
}

Expand All @@ -149,10 +148,10 @@ export class RequestService {
params.httpOptions = {};
}

if (!has(params.httpOptions, 'headers')) {
if (!('headers' in params.httpOptions)) {
params.httpOptions.headers = '';
}
if (!has(params.httpOptions, 'params')) {
if (!('params' in params.httpOptions)) {
params.httpOptions.params = '';
}

Expand All @@ -179,10 +178,10 @@ export class RequestService {
httpOptions = {};
}

if (!has(httpOptions, 'headers')) {
if (!('headers' in httpOptions)) {
httpOptions.headers = '';
}
if (!has(httpOptions, 'params')) {
if (!('params' in httpOptions)) {
httpOptions.params = '';
}

Expand All @@ -203,10 +202,10 @@ export class RequestService {
*
*/
delete(endPoint: string, httpOptions: RequestOptions = {}): Observable<any> {
if (!has(httpOptions, 'headers')) {
if (!('headers' in httpOptions)) {
httpOptions.headers = '';
}
if (!has(httpOptions, 'params')) {
if (!('params' in httpOptions)) {
httpOptions.params = '';
}

Expand Down Expand Up @@ -245,11 +244,11 @@ export class RequestService {
}

// log the user out if jwt expired
if (has(error, 'error.message') && [
if (error?.error?.message && [
'Request must contain an apikey',
'Expired apikey',
'Invalid apikey'
].includes(error?.error?.message) && !this.loggedOut) {
].includes(error.error.message) && !this.loggedOut) {
// in case lots of api returns the same apikey invalid at the same time
this.loggedOut = true;
setTimeout(
Expand Down
18 changes: 4 additions & 14 deletions projects/request/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
// this file is required by karma.conf.js and loads recursively all the .spec and framework files

import '@angular/localize/init';
import 'zone.js';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
Expand All @@ -8,20 +9,9 @@ import {
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
<T>(id: string): T;
keys(): string[];
};
};

// First, initialize the Angular testing environment.
// first, initialize the angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(),
{ teardown: { destroyAfterEach: true } }
);

// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
2 changes: 1 addition & 1 deletion projects/request/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
/* To learn more about this file see: https://angular.dev/reference/configs/workspace-config#tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion projects/request/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
/* To learn more about this file see: https://angular.dev/reference/configs/workspace-config#tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion projects/request/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
/* To learn more about this file see: https://angular.dev/reference/configs/workspace-config#tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion projects/v3/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { takeUntil } from "rxjs/operators";
import { ComponentCleanupService } from "./services/component-cleanup.service";

@Component({
standalone: false,
selector: "app-root",
standalone: false,
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
Expand Down
3 changes: 2 additions & 1 deletion projects/v3/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RequestInterceptor } from '@v3/services/request.interceptor';
Expand Down Expand Up @@ -32,6 +32,7 @@ import { SnowOverlayComponent } from './components/snow-overlay/snow-overlay.com
SnowOverlayComponent,
],
providers: [
provideHttpClient(withInterceptorsFromDi()),
{
provide: HTTP_INTERCEPTORS,
useClass: RequestInterceptor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, Output, OnChanges, SimpleChanges, EventEmitter, ViewEncapsulation, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, Output, OnChanges, SimpleChanges, EventEmitter, ViewEncapsulation, OnDestroy } from '@angular/core';
import { FilePreviewService } from '@v3/app/services/file-preview.service';
import { Subject, Subscription } from 'rxjs';

Expand All @@ -9,7 +9,7 @@ import { Subject, Subscription } from 'rxjs';
styleUrls: ['video-conversion.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class VideoConversionComponent implements OnInit, OnChanges, OnDestroy {
export class VideoConversionComponent implements OnChanges, OnDestroy {
@Input() video?;
@Output() preview = new EventEmitter();
result = null;
Expand All @@ -19,10 +19,6 @@ export class VideoConversionComponent implements OnInit, OnChanges, OnDestroy {

constructor(private filePreviewService: FilePreviewService) {}

ngOnInit(): void {
// no-op: conversion polling removed (filestack deprecated)
}

ngOnChanges(_changes: SimpleChanges): void {
if (this.video?.fileObject?.mimetype !== 'video/mp4') {
// filestack video conversion no longer available — show download fallback immediately
Expand Down
Loading
Loading