@scayle/omnichannel-nuxt 4.0.4 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,55 +0,0 @@
1
- import { defineEventHandler, readBody, setResponseStatus } from "h3";
2
- import { HttpStatusCode } from "./constants/httpStatus.js";
3
- import {
4
- getStores,
5
- getStoreVariantById,
6
- getStoresForVariant
7
- } from "./rpc/storeLocator.js";
8
- import { parseErrorData } from "./error/errorHandler.js";
9
- import { useRuntimeConfig } from "#imports";
10
- export default defineEventHandler(async (event) => {
11
- const path = event.path.split("/").reverse()[0];
12
- const runtimeConfig = useRuntimeConfig();
13
- const config = runtimeConfig.omnichannel;
14
- if (!config || !config.apiHost || !config.apiToken) {
15
- console.error(
16
- "[Omnichannel] Token and host must be set in the runtimeConfig",
17
- { config }
18
- );
19
- setResponseStatus(event, HttpStatusCode.INTERNAL_SERVER_ERROR);
20
- return {
21
- statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
22
- message: "Token and host must be set in the runtimeConfig"
23
- };
24
- }
25
- const options = {
26
- host: config.apiHost,
27
- token: config.apiToken,
28
- additionalHeaders: config.internalAccessHeader ? {
29
- "x-internal-access": config.internalAccessHeader
30
- } : {}
31
- };
32
- try {
33
- switch (path) {
34
- case "stores": {
35
- const body = await readBody(event);
36
- return await getStores(body, options);
37
- }
38
- case "storeVariantById": {
39
- const body = await readBody(event);
40
- return await getStoreVariantById(body, options);
41
- }
42
- case "variantStores": {
43
- const body = await readBody(event);
44
- return await getStoresForVariant(body, options);
45
- }
46
- default: {
47
- setResponseStatus(event, 404);
48
- }
49
- }
50
- } catch (e) {
51
- const parsedError = parseErrorData(e);
52
- setResponseStatus(event, parsedError.statusCode);
53
- return { ...parsedError };
54
- }
55
- });