shopify-nuxt 0.0.8 → 0.0.9

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-nuxt",
3
3
  "configKey": "shopify",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -1,4 +1,13 @@
1
- export declare function useShopifyFetch(): (url: string, options?: RequestInit) => Promise<{
2
- data: any;
3
- response: Response;
4
- }>;
1
+ import type { NitroFetchRequest, TypedInternalResponse, AvailableRouterMethod } from 'nitropack/types';
2
+ import type { RouterMethod } from 'h3';
3
+ type ShopifyFetchData<T, R extends NitroFetchRequest, M extends RouterMethod> = [T] extends [undefined] ? TypedInternalResponse<R, unknown, M> : T;
4
+ interface ShopifyFetchFunction {
5
+ <T = undefined, R extends NitroFetchRequest = NitroFetchRequest, M extends AvailableRouterMethod<R> = 'get' extends AvailableRouterMethod<R> ? 'get' : AvailableRouterMethod<R>>(url: R, options?: Omit<RequestInit, 'method'> & {
6
+ method?: Uppercase<M> | M;
7
+ }): Promise<{
8
+ data: ShopifyFetchData<T, R, Extract<Lowercase<M>, RouterMethod>>;
9
+ response: Response;
10
+ }>;
11
+ }
12
+ export declare function useShopifyFetch(): ShopifyFetchFunction;
13
+ export {};
@@ -1,12 +1,30 @@
1
- import { useNuxtApp } from "#app";
1
+ import { useNuxtApp, useRequestEvent } from "#app";
2
2
  export function useShopifyFetch() {
3
3
  if (import.meta.server) {
4
- return async (_url, _options) => {
5
- return { data: null, response: null };
6
- };
4
+ const event = useRequestEvent();
5
+ return (async (url, options = {}) => {
6
+ const headers = {};
7
+ const authHeader = event?.headers.get("authorization");
8
+ if (authHeader) {
9
+ headers["Authorization"] = authHeader;
10
+ }
11
+ if (options.headers) {
12
+ const incoming = new Headers(options.headers);
13
+ incoming.forEach((value, key) => {
14
+ headers[key] = value;
15
+ });
16
+ }
17
+ const { method, ...rest } = options;
18
+ const response = await globalThis.$fetch.raw(url, {
19
+ ...rest,
20
+ method,
21
+ headers
22
+ });
23
+ return { data: response._data, response };
24
+ });
7
25
  }
8
26
  const nuxtApp = useNuxtApp();
9
- return async (url, options = {}) => {
27
+ return (async (url, options = {}) => {
10
28
  const shopify = nuxtApp.$shopify;
11
29
  if (!shopify) {
12
30
  throw new Error(
@@ -30,5 +48,5 @@ export function useShopifyFetch() {
30
48
  return { data: await response.json(), response };
31
49
  }
32
50
  return { data: await response.text(), response };
33
- };
51
+ });
34
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopify-nuxt",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Shopify app integration for Nuxt - authentication, webhooks, billing, and App Bridge",
5
5
  "repository": "kiriminaja/shopify-nuxt",
6
6
  "license": "MIT",