From 9575a1d595a0a4757581a29a66837cbe4be46ed3 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Mon, 6 Feb 2023 22:11:30 +0330 Subject: [PATCH] feat(fetch): clientId on service request --- core/fetch/package.json | 1 + core/fetch/src/fetch.ts | 9 ++++++++- core/fetch/tsconfig.json | 1 + uniquely/soffit-pwa/src/director/form-submit-handler.ts | 4 ---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/fetch/package.json b/core/fetch/package.json index 60d79b87b..b39b22c0a 100644 --- a/core/fetch/package.json +++ b/core/fetch/package.json @@ -35,6 +35,7 @@ }, "dependencies": { "@alwatr/logger": "^0.28.0", + "@alwatr/math": "^0.28.0", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/core/fetch/src/fetch.ts b/core/fetch/src/fetch.ts index a1503d0b5..c55fc27ae 100644 --- a/core/fetch/src/fetch.ts +++ b/core/fetch/src/fetch.ts @@ -1,4 +1,5 @@ import {createLogger, globalAlwatr} from '@alwatr/logger'; +import {getClientId} from '@alwatr/math'; import type {FetchOptions, CacheDuplicate, CacheStrategy} from './type.js'; import type { @@ -38,7 +39,13 @@ export async function serviceRequest, TMeta = Re let response: Response; try { - response = await fetch(options); + response = await fetch({ + ...options, + headers: { + ...options.headers, + clientId: getClientId(), + }, + }); } catch (err) { logger.error('serviceRequest', (err as Error).message || 'fetch_failed', err, options); diff --git a/core/fetch/tsconfig.json b/core/fetch/tsconfig.json index 5689e0024..f136d7ebf 100644 --- a/core/fetch/tsconfig.json +++ b/core/fetch/tsconfig.json @@ -11,6 +11,7 @@ "exclude": [], "references": [ {"path": "../logger"}, + {"path": "../math"}, {"path": "../type"} ] } diff --git a/uniquely/soffit-pwa/src/director/form-submit-handler.ts b/uniquely/soffit-pwa/src/director/form-submit-handler.ts index 9f6174b9b..87846ef56 100644 --- a/uniquely/soffit-pwa/src/director/form-submit-handler.ts +++ b/uniquely/soffit-pwa/src/director/form-submit-handler.ts @@ -1,6 +1,5 @@ import {serviceRequest} from '@alwatr/fetch'; import {message} from '@alwatr/i18n'; -import {getDeviceUuid} from '@alwatr/math'; import {commandHandler} from '@alwatr/signal'; import {snackbarSignalTrigger} from '@alwatr/ui-kit/snackbar/show-snackbar.js'; import {validator, type JsonSchema} from '@alwatr/validator'; @@ -48,9 +47,6 @@ commandHandler.define('form-submit', async (form: FormData): form: form.formId, }, token: config.token, - headers: { - 'device-id': getDeviceUuid(), - }, bodyJson, }); }