@scayle/omnichannel-nuxt 4.0.4 → 4.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scayle/omnichannel-nuxt
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Refactored the module to use `@scayle/storefront-nuxt` custom RPC methods.
8
+
9
+ This internal change simplifies server interactions by using RPC methods instead of manually adding server handlers. No functional changes are expected for the exported composables, however `@scayle/storefront-nuxt@^8.7.1` is now required as a peer dependency.
10
+
11
+ ### Patch Changes
12
+
13
+ - Remove the `FetchStoresForVariantParams` type as it is a duplicate of `VariantLocatorSearchParams`
14
+
3
15
  ## 4.0.4
4
16
 
5
17
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 SCAYLE GmbH
3
+ Copyright (c) 2025 SCAYLE GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.d.mts CHANGED
@@ -159,19 +159,10 @@ interface VariantLocatorSearchParams {
159
159
  perPage?: number;
160
160
  with?: StoreWithProperty[];
161
161
  }
162
- interface FetchStoresForVariantParams {
163
- variantId: number;
164
- filters: {
165
- address: string;
166
- radius: number;
167
- };
168
- perPage?: number;
169
- with?: StoreWithProperty[];
170
- }
171
162
  interface FetchStoreVariantByIdParams {
172
163
  storeId: number;
173
164
  variantId: number;
174
165
  with?: StoreWithProperty[];
175
166
  }
176
167
 
177
- export { type FetchStoreVariantByIdParams, type FetchStoresForVariantParams, type FiltersAddressParams, type FiltersCoordinatesParams, type GeoPoint, type OmnichannelLinks, type OmnichannelMeta, OpeningTime, type OpeningTimeException, type OpeningTimeInterval, type OpeningTimes, type Store, type StoreAddress, type StoreAvailabilityCheck, type StoreAvailabilityCheckResponse, type StoreImage, type StoreItem, type StoreItemVariant, type StoreLocation, type StoreLocationResponse, type StoreLocatorConfig, type StoreLocatorSearchParams, type StoreVariantLocation, type StoreWithProperty, type VariantLocation, type VariantLocationResponse, type VariantLocatorSearchParams };
168
+ export { type FetchStoreVariantByIdParams, type FiltersAddressParams, type FiltersCoordinatesParams, type GeoPoint, type OmnichannelLinks, type OmnichannelMeta, OpeningTime, type OpeningTimeException, type OpeningTimeInterval, type OpeningTimes, type Store, type StoreAddress, type StoreAvailabilityCheck, type StoreAvailabilityCheckResponse, type StoreImage, type StoreItem, type StoreItemVariant, type StoreLocation, type StoreLocationResponse, type StoreLocatorConfig, type StoreLocatorSearchParams, type StoreVariantLocation, type StoreWithProperty, type VariantLocation, type VariantLocationResponse, type VariantLocatorSearchParams };
package/dist/index.d.ts CHANGED
@@ -159,19 +159,10 @@ interface VariantLocatorSearchParams {
159
159
  perPage?: number;
160
160
  with?: StoreWithProperty[];
161
161
  }
162
- interface FetchStoresForVariantParams {
163
- variantId: number;
164
- filters: {
165
- address: string;
166
- radius: number;
167
- };
168
- perPage?: number;
169
- with?: StoreWithProperty[];
170
- }
171
162
  interface FetchStoreVariantByIdParams {
172
163
  storeId: number;
173
164
  variantId: number;
174
165
  with?: StoreWithProperty[];
175
166
  }
176
167
 
177
- export { type FetchStoreVariantByIdParams, type FetchStoresForVariantParams, type FiltersAddressParams, type FiltersCoordinatesParams, type GeoPoint, type OmnichannelLinks, type OmnichannelMeta, OpeningTime, type OpeningTimeException, type OpeningTimeInterval, type OpeningTimes, type Store, type StoreAddress, type StoreAvailabilityCheck, type StoreAvailabilityCheckResponse, type StoreImage, type StoreItem, type StoreItemVariant, type StoreLocation, type StoreLocationResponse, type StoreLocatorConfig, type StoreLocatorSearchParams, type StoreVariantLocation, type StoreWithProperty, type VariantLocation, type VariantLocationResponse, type VariantLocatorSearchParams };
168
+ export { type FetchStoreVariantByIdParams, type FiltersAddressParams, type FiltersCoordinatesParams, type GeoPoint, type OmnichannelLinks, type OmnichannelMeta, OpeningTime, type OpeningTimeException, type OpeningTimeInterval, type OpeningTimes, type Store, type StoreAddress, type StoreAvailabilityCheck, type StoreAvailabilityCheckResponse, type StoreImage, type StoreItem, type StoreItemVariant, type StoreLocation, type StoreLocationResponse, type StoreLocatorConfig, type StoreLocatorSearchParams, type StoreVariantLocation, type StoreWithProperty, type VariantLocation, type VariantLocationResponse, type VariantLocatorSearchParams };
package/dist/module.d.mts CHANGED
@@ -7,4 +7,15 @@ type ModuleOptions = {
7
7
  };
8
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
9
9
 
10
+ interface OmnichannelRuntimeConfig {
11
+ apiHost: string;
12
+ apiToken: string;
13
+ internalAccessHeader?: string;
14
+ }
15
+ declare module '@nuxt/schema' {
16
+ interface RuntimeConfig {
17
+ omnichannel: OmnichannelRuntimeConfig;
18
+ }
19
+ }
20
+
10
21
  export { _default as default };
package/dist/module.d.ts CHANGED
@@ -7,4 +7,15 @@ type ModuleOptions = {
7
7
  };
8
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
9
9
 
10
+ interface OmnichannelRuntimeConfig {
11
+ apiHost: string;
12
+ apiToken: string;
13
+ internalAccessHeader?: string;
14
+ }
15
+ declare module '@nuxt/schema' {
16
+ interface RuntimeConfig {
17
+ omnichannel: OmnichannelRuntimeConfig;
18
+ }
19
+ }
20
+
10
21
  export { _default as default };
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@scayle/omnichannel-nuxt",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "configKey": "@scayle/omnichannel-nuxt",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
- "unbuild": "3.2.0"
7
+ "unbuild": "3.3.1"
8
8
  }
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,40 +1,34 @@
1
- import { defineNuxtModule, isNuxt2, createResolver, addServerHandler, addImportsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, isNuxtMajorVersion, createResolver, addImportsDir } from '@nuxt/kit';
2
2
 
3
3
  const PACKAGE_NAME = "@scayle/omnichannel-nuxt";
4
- const PACKAGE_VERSION = "4.0.4";
4
+ const PACKAGE_VERSION = "4.1.0";
5
5
  const module = defineNuxtModule({
6
6
  meta: {
7
7
  name: PACKAGE_NAME,
8
8
  version: PACKAGE_VERSION
9
9
  },
10
10
  async setup(moduleOptions, nuxt) {
11
- if (isNuxt2()) {
11
+ if (isNuxtMajorVersion(2, nuxt)) {
12
12
  throw new Error(
13
13
  "Nuxt 2 is not supported in this version of @scayle/omnichannel-nuxt"
14
14
  );
15
15
  } else {
16
- const { resolve } = createResolver(import.meta.url);
16
+ const { resolve, resolvePath } = createResolver(import.meta.url);
17
17
  nuxt.options.runtimeConfig.omnichannel = {
18
18
  apiToken: moduleOptions.token ?? "",
19
19
  apiHost: moduleOptions.host ?? "",
20
20
  internalAccessHeader: moduleOptions.internalAccessHeader ?? ""
21
21
  };
22
- addServerHandler({
23
- route: `/api/omnichannel/**`,
24
- handler: resolve("./runtime/handler"),
25
- method: "post"
22
+ nuxt.hook("storefront:custom-rpc:extend", async (customRpcs) => {
23
+ customRpcs.push({
24
+ source: await resolvePath("./runtime/rpc/storeLocator"),
25
+ names: ["getStores", "getStoresForVariant", "getStoreVariantById"]
26
+ });
26
27
  });
27
28
  nuxt.hooks.hook("nitro:config", (nitroConfig) => {
28
29
  nitroConfig.externals = nitroConfig.externals || {};
29
30
  nitroConfig.externals.inline = nitroConfig.externals.inline || [];
30
- nitroConfig.externals.inline.push(resolve("./runtime/rpc/storeLocator"));
31
31
  nitroConfig.externals.inline.push(resolve("./runtime/lib/init"));
32
- nitroConfig.externals.inline.push(
33
- resolve("./runtime/error/errorHandler")
34
- );
35
- nitroConfig.externals.inline.push(
36
- resolve("./runtime/constants/httpStatus")
37
- );
38
32
  });
39
33
  nuxt.options.alias["#omnichannel/composables"] = resolve(
40
34
  "./runtime/composables"
@@ -1,6 +1,6 @@
1
1
  import type { StoreWithProperty } from '../../types/index.js';
2
2
  export declare function useStoreLocator(key?: string, withProperties?: StoreWithProperty[]): {
3
- storesData: import("vue").ComputedRef<import("../../types").StoreLocation[] | undefined>;
3
+ storesData: import("vue").ComputedRef<import("../../types").StoreLocation[] | null>;
4
4
  refreshStores: (searchParams: import("../../types").StoreLocatorSearchParams) => Promise<void>;
5
5
  storeVariantData: import("vue").ComputedRef<import("../../types").StoreAvailabilityCheck | null>;
6
6
  refreshStoreVariant: (variantId: number, storeId: number) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { StoreAvailabilityCheck, StoreWithProperty } from '../../types/index.js';
2
2
  export declare function useStoreVariantById(key?: string, withProperties?: StoreWithProperty[]): {
3
- data: import("#imports").ComputedRef<StoreAvailabilityCheck | null>;
3
+ data: import("vue").ComputedRef<StoreAvailabilityCheck | null>;
4
4
  getData: (variantId: number, storeId: number) => Promise<void>;
5
5
  };
@@ -1,18 +1,14 @@
1
1
  import { computed, useState } from "#imports";
2
+ import { useRpcCall } from "@scayle/storefront-nuxt/composables";
2
3
  export function useStoreVariantById(key = "useStoreVariantById", withProperties = []) {
3
4
  const response = useState(key, () => null);
5
+ const rpcCall = useRpcCall("getStoreVariantById");
4
6
  const getData = async (variantId, storeId) => {
5
- response.value = (await $fetch(
6
- "/api/omnichannel/storeVariantById",
7
- {
8
- body: {
9
- storeId,
10
- variantId,
11
- with: withProperties
12
- },
13
- method: "POST"
14
- }
15
- )).data;
7
+ response.value = (await rpcCall({
8
+ storeId,
9
+ variantId,
10
+ with: withProperties
11
+ })).data;
16
12
  };
17
13
  return {
18
14
  data: computed(() => response.value),
@@ -1,5 +1,5 @@
1
- import type { StoreLocatorSearchParams, StoreWithProperty } from '../../types/index.js';
1
+ import type { StoreLocatorSearchParams, StoreLocation, StoreWithProperty } from '../../types/index.js';
2
2
  export declare function useStores(key?: string, withProperties?: StoreWithProperty[]): {
3
- data: import("#imports").ComputedRef<import("../../types").StoreLocation[] | undefined>;
3
+ data: import("vue").ComputedRef<StoreLocation[] | null>;
4
4
  getData: (searchParams: StoreLocatorSearchParams) => Promise<void>;
5
5
  };
@@ -1,14 +1,13 @@
1
1
  import { useState, computed } from "#imports";
2
+ import { useRpcCall } from "@scayle/storefront-nuxt/composables";
2
3
  export function useStores(key = "useStores", withProperties = []) {
3
4
  const response = useState(key, () => null);
5
+ const rpcCall = useRpcCall("getStores");
4
6
  const getData = async (searchParams) => {
5
- response.value = await $fetch(
6
- "/api/omnichannel/stores",
7
- { body: { ...searchParams, with: withProperties }, method: "POST" }
8
- );
7
+ response.value = (await rpcCall({ ...searchParams, with: withProperties })).data;
9
8
  };
10
9
  return {
11
- data: computed(() => response.value?.data),
10
+ data: computed(() => response.value),
12
11
  getData
13
12
  };
14
13
  }
@@ -1,5 +1,5 @@
1
1
  import type { VariantLocatorSearchParams, VariantLocation, StoreWithProperty } from '../../types/index.js';
2
2
  export declare function useVariantStores(key?: string, withProperties?: StoreWithProperty[]): {
3
- data: import("#imports").ComputedRef<VariantLocation | null>;
3
+ data: import("vue").ComputedRef<VariantLocation | null>;
4
4
  getData: (searchParams: VariantLocatorSearchParams) => Promise<void>;
5
5
  };
@@ -1,11 +1,10 @@
1
1
  import { useState, computed } from "#imports";
2
+ import { useRpcCall } from "@scayle/storefront-nuxt/composables";
2
3
  export function useVariantStores(key = "useVariantStores", withProperties = []) {
3
4
  const response = useState(key, () => null);
5
+ const rpcCall = useRpcCall("getStoresForVariant");
4
6
  const getData = async (searchParams) => {
5
- response.value = (await $fetch("/api/omnichannel/variantStores", {
6
- body: { ...searchParams, with: withProperties },
7
- method: "POST"
8
- })).data;
7
+ response.value = (await rpcCall({ ...searchParams, with: withProperties })).data;
9
8
  };
10
9
  return {
11
10
  data: computed(() => response.value),
@@ -1,8 +1,4 @@
1
- import type { StoreLocation, StoreLocatorConfig, StoreLocatorSearchParams, StoreAvailabilityCheckResponse, VariantLocationResponse, FetchStoresForVariantParams, FetchStoreVariantByIdParams } from '../../types/index.js';
2
- export interface PaginatedResponse<DataType> {
3
- nextPage: null;
4
- data: DataType;
5
- }
1
+ import type { StoreLocationResponse, StoreLocatorConfig, StoreLocatorSearchParams, StoreAvailabilityCheckResponse, VariantLocationResponse, VariantLocatorSearchParams, FetchStoreVariantByIdParams } from '../../types/index.js';
6
2
  /**
7
3
  * A custom Error type for errors that occur in a fetch() request
8
4
  * Contains the Response object from the request, and optionally the response data
@@ -12,6 +8,7 @@ export declare class FetchError extends Error {
12
8
  data?: unknown;
13
9
  constructor(response: Response, data?: unknown);
14
10
  }
11
+ type DistributiveOmit<T, K extends PropertyKey> = T extends T ? Omit<T, K> : never;
15
12
  export declare class OmnichannelClient {
16
13
  private readonly host;
17
14
  private readonly token;
@@ -19,8 +16,13 @@ export declare class OmnichannelClient {
19
16
  constructor(host: string, token: string, additionalHeaders?: HeadersInit);
20
17
  get headers(): HeadersInit;
21
18
  private handleResponse;
22
- getStores(options: StoreLocatorSearchParams): Promise<PaginatedResponse<StoreLocation[]>>;
23
- getStoresForVariant(options: FetchStoresForVariantParams): Promise<PaginatedResponse<VariantLocationResponse>>;
19
+ getStores(options: StoreLocatorSearchParams): Promise<StoreLocationResponse>;
20
+ getStoresForVariant(options: Omit<VariantLocatorSearchParams, 'filters'> & {
21
+ filters: DistributiveOmit<VariantLocatorSearchParams['filters'], 'radius'> & {
22
+ radius?: number;
23
+ };
24
+ }): Promise<VariantLocationResponse>;
24
25
  getStoreVariantById(options: FetchStoreVariantByIdParams): Promise<StoreAvailabilityCheckResponse>;
25
26
  }
26
27
  export declare const init: (config?: StoreLocatorConfig) => OmnichannelClient | null;
28
+ export {};
@@ -55,7 +55,7 @@ export class OmnichannelClient {
55
55
  async getStoresForVariant(options) {
56
56
  const fetchOptions = {
57
57
  filters: {
58
- address: options.filters.address,
58
+ ...options.filters,
59
59
  radius: options.filters.radius ?? DEFAULT_SEARCH_RADIUS
60
60
  },
61
61
  variantId: options.variantId,
@@ -1,4 +1,5 @@
1
- import type { StoreLocatorConfig, StoreLocatorSearchParams, FetchStoresForVariantParams, FetchStoreVariantByIdParams } from '../../types/index.js';
2
- export declare const getStores: (options: StoreLocatorSearchParams, storeLocator: StoreLocatorConfig) => Promise<import("../lib/init").PaginatedResponse<import("../../types").StoreLocation[]>>;
3
- export declare const getStoresForVariant: (options: FetchStoresForVariantParams, storeLocator: StoreLocatorConfig) => Promise<import("../lib/init").PaginatedResponse<import("../../types").VariantLocationResponse>>;
4
- export declare const getStoreVariantById: (options: FetchStoreVariantByIdParams, storeLocator: StoreLocatorConfig) => Promise<import("../../types").StoreAvailabilityCheckResponse>;
1
+ import type { RpcContext } from '@scayle/storefront-nuxt';
2
+ import type { StoreLocatorSearchParams, VariantLocatorSearchParams, FetchStoreVariantByIdParams, VariantLocationResponse, StoreAvailabilityCheckResponse, StoreLocationResponse } from '../../types/index.js';
3
+ export declare const getStores: (options: StoreLocatorSearchParams, context: RpcContext) => Promise<StoreLocationResponse>;
4
+ export declare const getStoresForVariant: (options: VariantLocatorSearchParams, context: RpcContext) => Promise<VariantLocationResponse>;
5
+ export declare const getStoreVariantById: (options: FetchStoreVariantByIdParams, context: RpcContext) => Promise<StoreAvailabilityCheckResponse>;
@@ -1,18 +1,38 @@
1
1
  import { init } from "../lib/init.js";
2
2
  const noClientMessage = "Client not configured";
3
- export const getStores = async function getStores2(options, storeLocator) {
3
+ function getOmnichannelConfig(runtimeConfig) {
4
+ const config = runtimeConfig.omnichannel;
5
+ if (!config || !config.apiHost || !config.apiToken) {
6
+ console.error(
7
+ "[Omnichannel] Token and host must be set in the runtimeConfig",
8
+ { config }
9
+ );
10
+ throw new Error("Token and host must be set in the runtimeConfig");
11
+ }
12
+ return {
13
+ host: config.apiHost,
14
+ token: config.apiToken,
15
+ additionalHeaders: config.internalAccessHeader ? {
16
+ "x-internal-access": config.internalAccessHeader
17
+ } : {}
18
+ };
19
+ }
20
+ export const getStores = async function getStores2(options, context) {
21
+ const storeLocator = getOmnichannelConfig(
22
+ context.runtimeConfiguration
23
+ );
4
24
  const omnichannelClient = init(storeLocator);
5
25
  if (!omnichannelClient) {
6
26
  throw new Error(noClientMessage);
7
27
  }
8
28
  return await omnichannelClient.getStores(options);
9
29
  };
10
- export const getStoresForVariant = async function getStoresForVariant2(options, storeLocator) {
30
+ export const getStoresForVariant = async function getStoresForVariant2(options, context) {
31
+ const storeLocator = getOmnichannelConfig(
32
+ context.runtimeConfiguration
33
+ );
11
34
  const fetchOptions = {
12
- filters: {
13
- address: options.filters.address,
14
- radius: options.filters.radius
15
- },
35
+ filters: options.filters,
16
36
  variantId: options.variantId,
17
37
  perPage: 10,
18
38
  with: options.with
@@ -23,7 +43,10 @@ export const getStoresForVariant = async function getStoresForVariant2(options,
23
43
  }
24
44
  return await omnichannelClient.getStoresForVariant(fetchOptions);
25
45
  };
26
- export const getStoreVariantById = async function getStoreVariantById2(options, storeLocator) {
46
+ export const getStoreVariantById = async function getStoreVariantById2(options, context) {
47
+ const storeLocator = getOmnichannelConfig(
48
+ context.runtimeConfiguration
49
+ );
27
50
  const omnichannelClient = init(storeLocator);
28
51
  if (!omnichannelClient) {
29
52
  throw new Error(noClientMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/omnichannel-nuxt",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Collection of essential utilities to work with omnichannel",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -50,7 +50,10 @@
50
50
  "typecheck": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
51
51
  "test": "vitest --run --passWithNoTests",
52
52
  "test:watch": "vitest --passWithNoTests",
53
- "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
53
+ "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./coverage/junit.xml"
54
+ },
55
+ "peerDependencies": {
56
+ "@scayle/storefront-nuxt": "^8.7.1"
54
57
  },
55
58
  "dependencies": {
56
59
  "@nuxt/kit": "^3.12.2",
@@ -58,23 +61,24 @@
58
61
  "utility-types": "^3.11.0"
59
62
  },
60
63
  "devDependencies": {
61
- "@nuxt/eslint": "0.7.4",
64
+ "@nuxt/eslint": "1.0.1",
62
65
  "@nuxt/module-builder": "0.8.4",
63
66
  "@nuxt/schema": "3.14.1592",
64
- "@scayle/eslint-config-storefront": "4.4.0",
65
- "@types/node": "22.10.5",
66
- "@types/qs": "6.9.17",
67
- "dprint": "0.48.0",
68
- "eslint": "9.17.0",
67
+ "@scayle/eslint-config-storefront": "4.4.1",
68
+ "@scayle/storefront-nuxt": "8.9.1",
69
+ "@types/node": "22.13.4",
70
+ "@types/qs": "6.9.18",
71
+ "dprint": "0.49.0",
72
+ "eslint": "9.20.1",
69
73
  "eslint-formatter-gitlab": "5.1.0",
70
- "h3": "1.13.0",
71
- "nuxi": "3.19.1",
74
+ "h3": "1.15.0",
75
+ "nuxi": "3.21.1",
72
76
  "nuxt": "3.14.1592",
73
77
  "typescript": "5.7.3",
74
- "vitest": "2.1.8",
78
+ "vitest": "2.1.9",
75
79
  "vue-tsc": "2.2.0"
76
80
  },
77
81
  "volta": {
78
- "node": "22.12.0"
82
+ "node": "22.13.1"
79
83
  }
80
84
  }