Skip to content

Commit

Permalink
feat(fetch): clientId on service request
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Feb 6, 2023
1 parent b211fd4 commit 9575a1d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@alwatr/logger": "^0.28.0",
"@alwatr/math": "^0.28.0",
"tslib": "^2.5.0"
},
"devDependencies": {
Expand Down
9 changes: 8 additions & 1 deletion core/fetch/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -38,7 +39,13 @@ export async function serviceRequest<TData = Record<string, unknown>, 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);
Expand Down
1 change: 1 addition & 0 deletions core/fetch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"exclude": [],
"references": [
{"path": "../logger"},
{"path": "../math"},
{"path": "../type"}
]
}
4 changes: 0 additions & 4 deletions uniquely/soffit-pwa/src/director/form-submit-handler.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,9 +47,6 @@ commandHandler.define<FormData, boolean>('form-submit', async (form: FormData):
form: form.formId,
},
token: config.token,
headers: {
'device-id': getDeviceUuid(),
},
bodyJson,
});
}
Expand Down

0 comments on commit 9575a1d

Please sign in to comment.