feat(uuid): implement UUID generation for non-secure contexts and replace crypto.randomUUID() usage
This commit is contained in:
@@ -3,6 +3,7 @@ import { Observable, BehaviorSubject, firstValueFrom, throwError } from 'rxjs';
|
||||
import { tap, catchError } from 'rxjs/operators';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { HttpService } from '../http-request/http.service';
|
||||
import { uuid } from '../../shared/utils/uuid';
|
||||
|
||||
export interface AuthUser {
|
||||
id: string;
|
||||
@@ -92,7 +93,7 @@ export class AuthService {
|
||||
|
||||
/** Per-request correlation id shared with the server's `X-Request-ID`. */
|
||||
private correlationHeaders(): Record<string, string> {
|
||||
return { 'X-Request-ID': crypto.randomUUID() };
|
||||
return { 'X-Request-ID': uuid() };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ import { HttpErrorResponse, HttpEventType, HttpHeaders, HttpParams } from '@angu
|
||||
import { map, filter, Observable, tap } from 'rxjs';
|
||||
import { HttpService } from '../http-request/http.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { uuid } from '../../shared/utils/uuid';
|
||||
import {
|
||||
DocumentDetail,
|
||||
DocumentListParams,
|
||||
@@ -34,7 +35,7 @@ export class DocumentsService {
|
||||
* (from the login/`/me` flow) and a per-request correlation id.
|
||||
*/
|
||||
private csrfHeaders(): Record<string, string> {
|
||||
const headers: Record<string, string> = { 'X-Request-ID': crypto.randomUUID() };
|
||||
const headers: Record<string, string> = { 'X-Request-ID': uuid() };
|
||||
const token = this.auth.getCsrfToken();
|
||||
if (token) {
|
||||
headers['X-CSRF-Token'] = token;
|
||||
@@ -91,7 +92,7 @@ export class DocumentsService {
|
||||
title: string | undefined,
|
||||
onProgress: (percent: number) => void,
|
||||
signal?: AbortSignal,
|
||||
idempotencyKey: string = crypto.randomUUID(),
|
||||
idempotencyKey: string = uuid(),
|
||||
): Observable<DocumentUploadResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
@@ -123,7 +124,7 @@ export class DocumentsService {
|
||||
submitReviewDecision(
|
||||
documentId: string,
|
||||
request: ReviewDecisionRequest,
|
||||
idempotencyKey: string = crypto.randomUUID(),
|
||||
idempotencyKey: string = uuid(),
|
||||
): Observable<ReviewDecisionResponse> {
|
||||
return this.http.postRaw<ReviewDecisionResponse>(
|
||||
`${API}/documents/${encodeURIComponent(documentId)}/extraction-review/decisions`,
|
||||
@@ -147,7 +148,7 @@ export class DocumentsService {
|
||||
/** D04 — retry processing of a document. */
|
||||
retryDocument(
|
||||
documentId: string,
|
||||
idempotencyKey: string = crypto.randomUUID(),
|
||||
idempotencyKey: string = uuid(),
|
||||
): Observable<RetryResult> {
|
||||
return this.http.postRaw<RetryResult>(
|
||||
`${API}/documents/${encodeURIComponent(documentId)}/retry`,
|
||||
|
||||
@@ -52,7 +52,7 @@ export class HttpService {
|
||||
* and is sent automatically; no bearer token is used for the MVP endpoints.
|
||||
*
|
||||
* NOTE: the origin MUST stay empty (`''`). Pointing these at an absolute host
|
||||
* (e.g. `http://10.2.8.3:8080`) turns every request cross-origin, and browsers
|
||||
* (e.g. `http://192.168.180.151:8080`) turns every request cross-origin, and browsers
|
||||
* refuse to send the session cookie cross-origin over plain HTTP — the backend
|
||||
* then answers 401 AUTH_REQUIRED even though the user is logged in.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { uuid } from '../../shared/utils/uuid';
|
||||
import { VOICE_STREAM_CONFIG, VoiceSessionStatus } from './voice-stream.types';
|
||||
|
||||
/**
|
||||
@@ -165,7 +166,7 @@ export class VoiceApiService {
|
||||
}
|
||||
|
||||
private readOptions() {
|
||||
return { withCredentials: true, headers: new HttpHeaders({ 'X-Request-ID': crypto.randomUUID() }) };
|
||||
return { withCredentials: true, headers: new HttpHeaders({ 'X-Request-ID': uuid() }) };
|
||||
}
|
||||
|
||||
private writeOptions(csrf: string) {
|
||||
@@ -173,7 +174,7 @@ export class VoiceApiService {
|
||||
withCredentials: true,
|
||||
headers: new HttpHeaders({
|
||||
'X-CSRF-Token': csrf,
|
||||
'X-Request-ID': crypto.randomUUID(),
|
||||
'X-Request-ID': uuid(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user