@scayle/storefront-nuxt 7.36.3
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 +598 -0
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +2 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +8 -0
- package/dist/module.d.ts +8 -0
- package/dist/module.json +8 -0
- package/dist/module.mjs +173 -0
- package/dist/rpc.d.mts +12 -0
- package/dist/rpc.d.ts +12 -0
- package/dist/rpc.mjs +18 -0
- package/dist/runtime/api/cacheAuth.d.ts +12 -0
- package/dist/runtime/api/cacheAuth.mjs +40 -0
- package/dist/runtime/api/purgeAll.d.ts +2 -0
- package/dist/runtime/api/purgeAll.mjs +14 -0
- package/dist/runtime/api/purgeTags.d.ts +2 -0
- package/dist/runtime/api/purgeTags.mjs +19 -0
- package/dist/runtime/api/rpcHandler.d.ts +2 -0
- package/dist/runtime/api/rpcHandler.mjs +15 -0
- package/dist/runtime/api/up.d.ts +4 -0
- package/dist/runtime/api/up.mjs +4 -0
- package/dist/runtime/composables/core/useAvailableShops.d.ts +2 -0
- package/dist/runtime/composables/core/useAvailableShops.mjs +4 -0
- package/dist/runtime/composables/core/useCurrentShop.d.ts +3 -0
- package/dist/runtime/composables/core/useCurrentShop.mjs +8 -0
- package/dist/runtime/composables/core/useEventListener.d.ts +2 -0
- package/dist/runtime/composables/core/useEventListener.mjs +2 -0
- package/dist/runtime/composables/core/useLog.d.ts +1 -0
- package/dist/runtime/composables/core/useLog.mjs +8 -0
- package/dist/runtime/composables/core/useRpc.d.ts +17 -0
- package/dist/runtime/composables/core/useRpc.mjs +56 -0
- package/dist/runtime/composables/core/useSession.d.ts +21 -0
- package/dist/runtime/composables/core/useSession.mjs +21 -0
- package/dist/runtime/composables/core/useUser.d.ts +16 -0
- package/dist/runtime/composables/core/useUser.mjs +68 -0
- package/dist/runtime/composables/storefront/useBasket.d.ts +54 -0
- package/dist/runtime/composables/storefront/useBasket.mjs +165 -0
- package/dist/runtime/composables/storefront/useBrand.d.ts +16 -0
- package/dist/runtime/composables/storefront/useBrand.mjs +20 -0
- package/dist/runtime/composables/storefront/useBrands.d.ts +16 -0
- package/dist/runtime/composables/storefront/useBrands.mjs +20 -0
- package/dist/runtime/composables/storefront/useCategories.d.ts +20 -0
- package/dist/runtime/composables/storefront/useCategories.mjs +30 -0
- package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +16 -0
- package/dist/runtime/composables/storefront/useCurrentPromotions.mjs +20 -0
- package/dist/runtime/composables/storefront/useFacet.d.ts +48 -0
- package/dist/runtime/composables/storefront/useFacet.mjs +193 -0
- package/dist/runtime/composables/storefront/useFilters.d.ts +16 -0
- package/dist/runtime/composables/storefront/useFilters.mjs +20 -0
- package/dist/runtime/composables/storefront/useNavigationTree.d.ts +16 -0
- package/dist/runtime/composables/storefront/useNavigationTree.mjs +20 -0
- package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +16 -0
- package/dist/runtime/composables/storefront/useNavigationTrees.mjs +20 -0
- package/dist/runtime/composables/storefront/useOrder.d.ts +89 -0
- package/dist/runtime/composables/storefront/useOrder.mjs +17 -0
- package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +89 -0
- package/dist/runtime/composables/storefront/useOrderConfirmation.mjs +17 -0
- package/dist/runtime/composables/storefront/useProduct.d.ts +16 -0
- package/dist/runtime/composables/storefront/useProduct.mjs +20 -0
- package/dist/runtime/composables/storefront/useProducts.d.ts +20 -0
- package/dist/runtime/composables/storefront/useProducts.mjs +20 -0
- package/dist/runtime/composables/storefront/useProductsByIds.d.ts +16 -0
- package/dist/runtime/composables/storefront/useProductsByIds.mjs +20 -0
- package/dist/runtime/composables/storefront/useProductsCount.d.ts +16 -0
- package/dist/runtime/composables/storefront/useProductsCount.mjs +20 -0
- package/dist/runtime/composables/storefront/usePromotions.d.ts +16 -0
- package/dist/runtime/composables/storefront/usePromotions.mjs +20 -0
- package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +16 -0
- package/dist/runtime/composables/storefront/usePromotionsByIds.mjs +20 -0
- package/dist/runtime/composables/storefront/useQueryFilterState.d.ts +12 -0
- package/dist/runtime/composables/storefront/useQueryFilterState.mjs +66 -0
- package/dist/runtime/composables/storefront/useSearch.d.ts +13 -0
- package/dist/runtime/composables/storefront/useSearch.mjs +49 -0
- package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +13 -0
- package/dist/runtime/composables/storefront/useShopConfiguration.mjs +19 -0
- package/dist/runtime/composables/storefront/useUserAddresses.d.ts +13 -0
- package/dist/runtime/composables/storefront/useUserAddresses.mjs +19 -0
- package/dist/runtime/composables/storefront/useVariant.d.ts +16 -0
- package/dist/runtime/composables/storefront/useVariant.mjs +20 -0
- package/dist/runtime/composables/storefront/useWishlist.d.ts +48 -0
- package/dist/runtime/composables/storefront/useWishlist.mjs +119 -0
- package/dist/runtime/composables/useCoreLog.d.ts +1 -0
- package/dist/runtime/composables/useCoreLog.mjs +4 -0
- package/dist/runtime/context.d.ts +12 -0
- package/dist/runtime/context.mjs +98 -0
- package/dist/runtime/createLog.d.ts +3 -0
- package/dist/runtime/createLog.mjs +39 -0
- package/dist/runtime/error/handler.d.ts +14 -0
- package/dist/runtime/error/handler.mjs +53 -0
- package/dist/runtime/handler.d.ts +8 -0
- package/dist/runtime/handler.mjs +26 -0
- package/dist/runtime/log.d.ts +38 -0
- package/dist/runtime/log.mjs +68 -0
- package/dist/runtime/plugin/log.client.d.ts +8 -0
- package/dist/runtime/plugin/log.client.mjs +24 -0
- package/dist/runtime/plugin/log.server.d.ts +2 -0
- package/dist/runtime/plugin/log.server.mjs +11 -0
- package/dist/runtime/plugin/shop.d.ts +8 -0
- package/dist/runtime/plugin/shop.mjs +17 -0
- package/dist/runtime/rpc/rpcCall.d.ts +9 -0
- package/dist/runtime/rpc/rpcCall.mjs +16 -0
- package/dist/runtime/server/middleware/bootstrap.d.ts +12 -0
- package/dist/runtime/server/middleware/bootstrap.mjs +188 -0
- package/dist/runtime/server/middleware/bootstrap.test.d.ts +6 -0
- package/dist/runtime/server/middleware/bootstrap.test.mjs +277 -0
- package/dist/runtime/server/middleware/bootstrap.utils.d.ts +7 -0
- package/dist/runtime/server/middleware/bootstrap.utils.mjs +59 -0
- package/dist/runtime/server/middleware/cache.d.ts +12 -0
- package/dist/runtime/server/middleware/cache.mjs +44 -0
- package/dist/runtime/server/middleware/oauth.d.ts +3 -0
- package/dist/runtime/server/middleware/oauth.mjs +123 -0
- package/dist/runtime/server/middleware/redirects.d.ts +2 -0
- package/dist/runtime/server/middleware/redirects.mjs +86 -0
- package/dist/runtime/server/middleware/redirects.test.d.ts +1 -0
- package/dist/runtime/server/middleware/redirects.test.mjs +66 -0
- package/dist/runtime/server/middleware/redirects.utils.d.ts +18 -0
- package/dist/runtime/server/middleware/redirects.utils.mjs +28 -0
- package/dist/runtime/utils/error.d.ts +5 -0
- package/dist/runtime/utils/error.mjs +7 -0
- package/dist/runtime/utils/price.d.ts +11 -0
- package/dist/runtime/utils/price.mjs +32 -0
- package/dist/runtime/utils/price.test.d.ts +1 -0
- package/dist/runtime/utils/price.test.mjs +83 -0
- package/dist/runtime/utils/route.d.ts +2 -0
- package/dist/runtime/utils/route.mjs +3 -0
- package/dist/runtime/utils/route.test.d.ts +1 -0
- package/dist/runtime/utils/route.test.mjs +15 -0
- package/dist/shared/storefront-nuxt.9548700f.d.mts +161 -0
- package/dist/shared/storefront-nuxt.9548700f.d.ts +161 -0
- package/dist/types.d.mts +15 -0
- package/dist/types.d.ts +15 -0
- package/package.json +103 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { M as ModuleOptions } from './shared/storefront-nuxt.9548700f.mjs';
|
|
3
|
+
export { e as AdditionalShopConfig, A as AppKeys, d as AuthenticationConfig, B as BapiConfig, b as CacheConfig, i as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, c as RedirectsConfig, R as RedisConfig, a as SessionConfig, f as ShopConfig, g as ShopConfigIndexed, S as StorageProvider, h as StorefrontConfig } from './shared/storefront-nuxt.9548700f.mjs';
|
|
4
|
+
import '@scayle/storefront-core';
|
|
5
|
+
|
|
6
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
7
|
+
|
|
8
|
+
export { ModuleOptions, _default as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { M as ModuleOptions } from './shared/storefront-nuxt.9548700f.js';
|
|
3
|
+
export { e as AdditionalShopConfig, A as AppKeys, d as AuthenticationConfig, B as BapiConfig, b as CacheConfig, i as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, c as RedirectsConfig, R as RedisConfig, a as SessionConfig, f as ShopConfig, g as ShopConfigIndexed, S as StorageProvider, h as StorefrontConfig } from './shared/storefront-nuxt.9548700f.js';
|
|
4
|
+
import '@scayle/storefront-core';
|
|
5
|
+
|
|
6
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
7
|
+
|
|
8
|
+
export { ModuleOptions, _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, extendViteConfig, addServerHandler, addTypeTemplate, addPlugin, addImportsDir } from '@nuxt/kit';
|
|
2
|
+
import yn from 'yn';
|
|
3
|
+
import { rpcMethods } from '@scayle/storefront-core';
|
|
4
|
+
import { defu } from 'defu';
|
|
5
|
+
|
|
6
|
+
const module = defineNuxtModule({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "@scayle/storefront-nuxt",
|
|
9
|
+
configKey: "storefront",
|
|
10
|
+
compatibility: {
|
|
11
|
+
nuxt: "^3.7.0"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
// Default configuration options of the Nuxt module
|
|
15
|
+
defaults: {
|
|
16
|
+
// TODO: Nuxt is making us give a default for each options
|
|
17
|
+
// How do we mark some as required?
|
|
18
|
+
session: {
|
|
19
|
+
cookieName: "$session",
|
|
20
|
+
sameSite: "none"
|
|
21
|
+
// TODO: If we give a default value here, nuxt will generate the runtime type incorrectly
|
|
22
|
+
// secret needs to be typed as string | string[]
|
|
23
|
+
// secret: 'current-secret',
|
|
24
|
+
// if we set maxAge explicitly to undefined `useRuntimeConfig` will set it default to '' which leads to no sessions not being saved
|
|
25
|
+
// maxAge: undefined,
|
|
26
|
+
},
|
|
27
|
+
bapi: {
|
|
28
|
+
host: "https://bapi.scayle.cloud/",
|
|
29
|
+
token: ""
|
|
30
|
+
},
|
|
31
|
+
redis: {
|
|
32
|
+
port: 6379,
|
|
33
|
+
host: "localhost"
|
|
34
|
+
},
|
|
35
|
+
shopSelector: "domain",
|
|
36
|
+
stores: {},
|
|
37
|
+
log: {
|
|
38
|
+
name: ""
|
|
39
|
+
},
|
|
40
|
+
auth: {
|
|
41
|
+
redirect: {
|
|
42
|
+
home: "/",
|
|
43
|
+
logout: "/"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
oauth: {
|
|
47
|
+
apiHost: "",
|
|
48
|
+
clientId: "",
|
|
49
|
+
clientSecret: ""
|
|
50
|
+
},
|
|
51
|
+
appKeys: {
|
|
52
|
+
wishlistKey: "wishlist_{shopId}_{userId}",
|
|
53
|
+
basketKey: "basket_{shopId}_{userId}",
|
|
54
|
+
hashAlgorithm: "sha256"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
setup(options, nuxt) {
|
|
58
|
+
const { resolve } = createResolver(import.meta.url);
|
|
59
|
+
const { resolve: appResolve } = createResolver(nuxt.options.srcDir);
|
|
60
|
+
nuxt.options.runtimeConfig.storefront = defu(
|
|
61
|
+
nuxt.options.runtimeConfig.storefront,
|
|
62
|
+
options
|
|
63
|
+
);
|
|
64
|
+
nuxt.options.runtimeConfig.cache = {
|
|
65
|
+
auth: options.cache?.auth
|
|
66
|
+
};
|
|
67
|
+
nuxt.options.runtimeConfig.public.publicShopData = options.publicShopData;
|
|
68
|
+
nuxt.options.runtimeConfig.public.log = options.log;
|
|
69
|
+
nuxt.options.runtimeConfig.public.auth = options.auth;
|
|
70
|
+
extendViteConfig((config) => {
|
|
71
|
+
config.optimizeDeps = config.optimizeDeps || {};
|
|
72
|
+
config.optimizeDeps.include = config.optimizeDeps.include || [];
|
|
73
|
+
config.optimizeDeps.include.push(
|
|
74
|
+
"@scayle/storefront-nuxt",
|
|
75
|
+
"@scayle/storefront-core",
|
|
76
|
+
"@aboutyou/backbone",
|
|
77
|
+
"isomorphic-dompurify",
|
|
78
|
+
"slugify"
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
addServerHandler({
|
|
82
|
+
middleware: true,
|
|
83
|
+
handler: resolve("./runtime/server/middleware/bootstrap")
|
|
84
|
+
});
|
|
85
|
+
const apiBasePath = nuxt.options.runtimeConfig.storefront.apiBasePath || "/api";
|
|
86
|
+
addServerHandler({
|
|
87
|
+
route: `${apiBasePath}/purge/all`,
|
|
88
|
+
handler: resolve("./runtime/api/purgeAll"),
|
|
89
|
+
method: "post"
|
|
90
|
+
});
|
|
91
|
+
addServerHandler({
|
|
92
|
+
route: `${apiBasePath}/purge/tags`,
|
|
93
|
+
handler: resolve("./runtime/api/purgeTags"),
|
|
94
|
+
method: "post"
|
|
95
|
+
});
|
|
96
|
+
addServerHandler({
|
|
97
|
+
route: `${apiBasePath}/up`,
|
|
98
|
+
handler: resolve("./runtime/api/up"),
|
|
99
|
+
method: "get"
|
|
100
|
+
});
|
|
101
|
+
const template = addTypeTemplate({
|
|
102
|
+
filename: "types/storefront-bootstrap.d.ts",
|
|
103
|
+
getContents: () => `// Auto-generated
|
|
104
|
+
import type { RpcContext, Cache } from '@scayle/storefront-core'
|
|
105
|
+
import type { PublicShopConfig } from '@scayle/storefront-nuxt';
|
|
106
|
+
declare module 'h3' {
|
|
107
|
+
interface H3EventContext {
|
|
108
|
+
$rpcContext: RpcContext,
|
|
109
|
+
$cache: Cache
|
|
110
|
+
$currentShop: PublicShopConfig,
|
|
111
|
+
$availableShops: PublicShopConfig[]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export {}`
|
|
115
|
+
});
|
|
116
|
+
nuxt.hook("prepare:types", ({ references }) => {
|
|
117
|
+
references.push({ path: template.dst });
|
|
118
|
+
});
|
|
119
|
+
const rpcMethodNames = /* @__PURE__ */ new Set([
|
|
120
|
+
...Object.keys(rpcMethods),
|
|
121
|
+
...options.rpcMethodNames ?? []
|
|
122
|
+
]);
|
|
123
|
+
rpcMethodNames.forEach((methodName) => {
|
|
124
|
+
addServerHandler({
|
|
125
|
+
route: `${apiBasePath}/rpc/${methodName}`,
|
|
126
|
+
handler: resolve("./runtime/api/rpcHandler"),
|
|
127
|
+
method: "post"
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
131
|
+
nitroConfig.externals = nitroConfig.externals || {};
|
|
132
|
+
nitroConfig.externals.inline = nitroConfig.externals.inline || [];
|
|
133
|
+
const runtimePaths = [
|
|
134
|
+
"handler",
|
|
135
|
+
"error/handler",
|
|
136
|
+
"context",
|
|
137
|
+
"createLog",
|
|
138
|
+
"log",
|
|
139
|
+
"api/cacheAuth",
|
|
140
|
+
"rpc/rpcCall",
|
|
141
|
+
"rpc/rpcRequest",
|
|
142
|
+
"server/middleware/oauth",
|
|
143
|
+
"server/middleware/redirects",
|
|
144
|
+
"server/middleware/cache"
|
|
145
|
+
];
|
|
146
|
+
runtimePaths.forEach((path) => {
|
|
147
|
+
const file = resolve(`./runtime/${path}`);
|
|
148
|
+
nitroConfig.externals?.inline?.push(file);
|
|
149
|
+
});
|
|
150
|
+
nitroConfig.replace = nitroConfig.replace || {};
|
|
151
|
+
nitroConfig.replace["process.env.SFC_OMIT_MD5"] = yn(
|
|
152
|
+
process.env.SFC_OMIT_MD5
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
nuxt.options.alias["#rpcMethods"] = appResolve(
|
|
156
|
+
options.rpcDir ?? "./rpcMethods"
|
|
157
|
+
);
|
|
158
|
+
addPlugin(resolve("./runtime/plugin/shop"));
|
|
159
|
+
addPlugin({
|
|
160
|
+
src: resolve("./runtime/plugin/log.client"),
|
|
161
|
+
mode: "client"
|
|
162
|
+
});
|
|
163
|
+
addPlugin({
|
|
164
|
+
src: resolve("./runtime/plugin/log.server"),
|
|
165
|
+
mode: "server"
|
|
166
|
+
});
|
|
167
|
+
addImportsDir(resolve("runtime/composables/storefront"));
|
|
168
|
+
addImportsDir(resolve("runtime/composables/core"));
|
|
169
|
+
addImportsDir(resolve("runtime/utils"));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export { module as default };
|
package/dist/rpc.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
|
|
2
|
+
import { NuxtApp } from 'nuxt/app';
|
|
3
|
+
import { P as PublicShopConfig } from './shared/storefront-nuxt.9548700f.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* rpcCall can be used to invoke an RPC method either on the client or server
|
|
7
|
+
* It makes an HTTP request on the client and direct call on the server using $fetch
|
|
8
|
+
* https://nuxt.com/docs/api/utils/dollarfetch
|
|
9
|
+
*/
|
|
10
|
+
declare const rpcCall: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TakesParameters = P extends RpcContext ? undefined : boolean>(nuxtApp: NuxtApp, method: N, shop: PublicShopConfig) => TakesParameters extends undefined ? () => Promise<TResult> : (params: P) => Promise<TResult>;
|
|
11
|
+
|
|
12
|
+
export { rpcCall };
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
|
|
2
|
+
import { NuxtApp } from 'nuxt/app';
|
|
3
|
+
import { P as PublicShopConfig } from './shared/storefront-nuxt.9548700f.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* rpcCall can be used to invoke an RPC method either on the client or server
|
|
7
|
+
* It makes an HTTP request on the client and direct call on the server using $fetch
|
|
8
|
+
* https://nuxt.com/docs/api/utils/dollarfetch
|
|
9
|
+
*/
|
|
10
|
+
declare const rpcCall: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TakesParameters = P extends RpcContext ? undefined : boolean>(nuxtApp: NuxtApp, method: N, shop: PublicShopConfig) => TakesParameters extends undefined ? () => Promise<TResult> : (params: P) => Promise<TResult>;
|
|
11
|
+
|
|
12
|
+
export { rpcCall };
|
package/dist/rpc.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const rpcCall = (nuxtApp, method, shop) => {
|
|
2
|
+
const fetch = nuxtApp.ssrContext?.event.$fetch ?? $fetch;
|
|
3
|
+
return async (params = void 0) => {
|
|
4
|
+
const data = await fetch(`${shop.apiBasePath ?? "/api"}/rpc/${method}`, {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
method: "POST",
|
|
7
|
+
body: {
|
|
8
|
+
payload: params
|
|
9
|
+
},
|
|
10
|
+
headers: {
|
|
11
|
+
"x-shop-id": shop.shopId + ""
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { rpcCall };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventHandler } from 'h3';
|
|
2
|
+
/**
|
|
3
|
+
* Wrap an event handler protected by the authentication specified in cache.auth
|
|
4
|
+
* @param handler
|
|
5
|
+
*/
|
|
6
|
+
export declare const eventHandlerWithCacheAuth: (handler: EventHandler) => EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
7
|
+
/**
|
|
8
|
+
* Wrap an event handler with basic auth
|
|
9
|
+
* @param handler
|
|
10
|
+
* @param auth
|
|
11
|
+
*/
|
|
12
|
+
export declare const eventHandlerWithBasicAuth: (handler: EventHandler, auth: string) => EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRequestHeaders,
|
|
3
|
+
defineEventHandler,
|
|
4
|
+
setResponseStatus,
|
|
5
|
+
setResponseHeader
|
|
6
|
+
} from "h3";
|
|
7
|
+
import { HttpStatusCode } from "@scayle/storefront-core";
|
|
8
|
+
import { useRuntimeConfig } from "#imports";
|
|
9
|
+
export const eventHandlerWithCacheAuth = (handler) => defineEventHandler(async (event) => {
|
|
10
|
+
const config = useRuntimeConfig();
|
|
11
|
+
const auth = config.cache.auth;
|
|
12
|
+
if (!auth) {
|
|
13
|
+
return await handler(event);
|
|
14
|
+
}
|
|
15
|
+
return await eventHandlerWithBasicAuth(
|
|
16
|
+
handler,
|
|
17
|
+
`${auth.username}:${auth.password}`
|
|
18
|
+
)(event);
|
|
19
|
+
});
|
|
20
|
+
export const eventHandlerWithBasicAuth = (handler, auth) => defineEventHandler(async (event) => {
|
|
21
|
+
const headers = getRequestHeaders(event);
|
|
22
|
+
const authenticationFailed = () => {
|
|
23
|
+
setResponseHeader(
|
|
24
|
+
event,
|
|
25
|
+
"WWW-Authenticate",
|
|
26
|
+
'Basic realm="Authentication required"'
|
|
27
|
+
);
|
|
28
|
+
setResponseStatus(event, HttpStatusCode.UNAUTHORIZED);
|
|
29
|
+
return "Authentication required";
|
|
30
|
+
};
|
|
31
|
+
if (!headers.authorization) {
|
|
32
|
+
return authenticationFailed();
|
|
33
|
+
}
|
|
34
|
+
const b64auth = headers.authorization.split(" ")[1] || "";
|
|
35
|
+
const decodedAuthHeader = Buffer.from(b64auth, "base64").toString();
|
|
36
|
+
if (decodedAuthHeader !== auth) {
|
|
37
|
+
return authenticationFailed();
|
|
38
|
+
}
|
|
39
|
+
return await handler(event);
|
|
40
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseStatus } from "h3";
|
|
2
|
+
import { HttpStatusCode } from "@scayle/storefront-core";
|
|
3
|
+
import { eventHandlerWithCacheAuth } from "./cacheAuth.mjs";
|
|
4
|
+
export default eventHandlerWithCacheAuth(
|
|
5
|
+
defineEventHandler(async (event) => {
|
|
6
|
+
try {
|
|
7
|
+
await event.context.$cache.purgeAll();
|
|
8
|
+
} catch (e) {
|
|
9
|
+
setResponseStatus(event, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
10
|
+
return { success: false };
|
|
11
|
+
}
|
|
12
|
+
return { success: true };
|
|
13
|
+
})
|
|
14
|
+
);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseStatus, readBody } from "h3";
|
|
2
|
+
import { HttpStatusCode } from "@scayle/storefront-core";
|
|
3
|
+
import { eventHandlerWithCacheAuth } from "./cacheAuth.mjs";
|
|
4
|
+
export default eventHandlerWithCacheAuth(
|
|
5
|
+
defineEventHandler(async (event) => {
|
|
6
|
+
const tags = await readBody(event);
|
|
7
|
+
if (!tags?.length) {
|
|
8
|
+
setResponseStatus(event, HttpStatusCode.BAD_REQUEST);
|
|
9
|
+
return { success: false };
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await event.context.$cache.purgeTags(tags);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
setResponseStatus(event, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
15
|
+
return { success: false };
|
|
16
|
+
}
|
|
17
|
+
return { success: true };
|
|
18
|
+
})
|
|
19
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineEventHandler, readBody, createError } from "h3";
|
|
2
|
+
import { handler } from "../handler.mjs";
|
|
3
|
+
import { resolveError } from "../error/handler.mjs";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const pathComponents = event.path.split("?")[0].split("/");
|
|
6
|
+
const method = pathComponents[pathComponents.length - 1];
|
|
7
|
+
const body = await readBody(event);
|
|
8
|
+
event.context.$rpcContext.log.space("sfc").debug(`RPC Handler: ${method}`);
|
|
9
|
+
try {
|
|
10
|
+
return await handler(method, body?.payload, event.context.$rpcContext);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
const data = resolveError(e);
|
|
13
|
+
return createError(data);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLog(subSpace?: string): any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
|
|
2
|
+
import { AsyncDataOptions, NuxtError } from 'nuxt/app';
|
|
3
|
+
type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
|
|
4
|
+
export type RpcAsyncDataOptions<TResult> = AsyncDataOptions<TResult, TResult, KeysOf<TResult>, TResult>;
|
|
5
|
+
export interface RpcOptions {
|
|
6
|
+
autoFetch?: boolean;
|
|
7
|
+
lazy?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
10
|
+
export declare const useRpc: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TParams = P extends RpcContext ? undefined : P>(method: N, key: string, params?: any, options?: RpcOptions) => Promise<{
|
|
11
|
+
data: import("vue").Ref<TResult>;
|
|
12
|
+
fetching: import("vue").Ref<boolean>;
|
|
13
|
+
fetch: () => Promise<void>;
|
|
14
|
+
error: import("vue").Ref<NuxtError | undefined>;
|
|
15
|
+
status: import("vue").Ref<Status>;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useNuxtApp, useState } from "nuxt/app";
|
|
2
|
+
import { useCoreLog } from "../useCoreLog.mjs";
|
|
3
|
+
import { handleError } from "../../utils/error.mjs";
|
|
4
|
+
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
5
|
+
import { toValue } from "#imports";
|
|
6
|
+
export const useRpc = async (method, key, params, options = { autoFetch: true, lazy: false }) => {
|
|
7
|
+
const currentShop = useCurrentShop();
|
|
8
|
+
const log = useCoreLog("rpc");
|
|
9
|
+
const isAutoFetchEnabled = options?.autoFetch ?? true;
|
|
10
|
+
log.debug(`useRpc: ${method}`);
|
|
11
|
+
const data = useState(`${method}-${key}-data`);
|
|
12
|
+
const fetching = useState(`${method}-${key}-fetching`, () => false);
|
|
13
|
+
const error = useState(
|
|
14
|
+
`${method}-${key}-error`,
|
|
15
|
+
() => void 0
|
|
16
|
+
);
|
|
17
|
+
const status = useState(`${method}-${key}-status`, () => "idle");
|
|
18
|
+
const fetch = async () => {
|
|
19
|
+
try {
|
|
20
|
+
status.value = "pending";
|
|
21
|
+
fetching.value = true;
|
|
22
|
+
const apiBasePath = currentShop.value?.apiBasePath ?? "/api";
|
|
23
|
+
const fetch2 = useNuxtApp().ssrContext?.event.$fetch ?? $fetch;
|
|
24
|
+
data.value = await fetch2(`/rpc/${method}`, {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: {
|
|
28
|
+
payload: toValue(params)
|
|
29
|
+
},
|
|
30
|
+
baseURL: apiBasePath,
|
|
31
|
+
headers: {
|
|
32
|
+
"x-shop-id": currentShop.value?.shopId + ""
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
} catch (e) {
|
|
36
|
+
error.value = handleError(e);
|
|
37
|
+
} finally {
|
|
38
|
+
fetching.value = false;
|
|
39
|
+
status.value = error.value ? "error" : "success";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (isAutoFetchEnabled && status.value === "idle") {
|
|
43
|
+
if (process.server) {
|
|
44
|
+
await fetch();
|
|
45
|
+
} else {
|
|
46
|
+
options.lazy ? fetch() : await fetch();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
data,
|
|
51
|
+
fetching,
|
|
52
|
+
fetch,
|
|
53
|
+
error,
|
|
54
|
+
status
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function useSession(): {
|
|
2
|
+
login: (params: import("@scayle/storefront-core").LoginRequest) => Promise<{
|
|
3
|
+
oauth: import("@scayle/storefront-core").Oauth | null;
|
|
4
|
+
}>;
|
|
5
|
+
register: (params: import("@scayle/storefront-core").RegisterRequest) => Promise<{
|
|
6
|
+
oauth: import("@scayle/storefront-core").Oauth | null;
|
|
7
|
+
}>;
|
|
8
|
+
guestLogin: (params: import("@scayle/storefront-core").GuestRequest) => Promise<{
|
|
9
|
+
oauth: import("@scayle/storefront-core").Oauth | null;
|
|
10
|
+
}>;
|
|
11
|
+
refreshToken: () => Promise<import("@scayle/storefront-core").Oauth | null>;
|
|
12
|
+
revokeToken: () => Promise<{
|
|
13
|
+
result: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
forgetPassword: (params: import("@scayle/storefront-core").SendResetPasswordEmailRequest) => Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
resetPasswordByHash: (params: import("@scayle/storefront-core").UpdatePasswordByHashRequest) => Promise<{
|
|
19
|
+
oauth: import("@scayle/storefront-core").Oauth | null;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useNuxtApp } from "nuxt/app";
|
|
2
|
+
import { rpcCall } from "../../rpc/rpcCall.mjs";
|
|
3
|
+
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
4
|
+
import { toValue } from "#imports";
|
|
5
|
+
export function useSession() {
|
|
6
|
+
const nuxtApp = useNuxtApp();
|
|
7
|
+
const shop = useCurrentShop();
|
|
8
|
+
return {
|
|
9
|
+
login: rpcCall(nuxtApp, "oauthLogin", toValue(shop)),
|
|
10
|
+
register: rpcCall(nuxtApp, "oauthRegister", toValue(shop)),
|
|
11
|
+
guestLogin: rpcCall(nuxtApp, "oauthGuestLogin", toValue(shop)),
|
|
12
|
+
refreshToken: rpcCall(nuxtApp, "refreshAccessToken", toValue(shop)),
|
|
13
|
+
revokeToken: rpcCall(nuxtApp, "oauthRevokeToken", toValue(shop)),
|
|
14
|
+
forgetPassword: rpcCall(nuxtApp, "oauthForgetPassword", toValue(shop)),
|
|
15
|
+
resetPasswordByHash: rpcCall(
|
|
16
|
+
nuxtApp,
|
|
17
|
+
"updatePasswordByHash",
|
|
18
|
+
toValue(shop)
|
|
19
|
+
)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ShopUser, UpdatePasswordParams, UseUserParams } from '@scayle/storefront-core';
|
|
2
|
+
export type ExtendedUseUserParams = UseUserParams & {
|
|
3
|
+
lazy?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function useUser({ autoFetch, lazy, key, }?: ExtendedUseUserParams): Promise<{
|
|
6
|
+
user: import("vue").ComputedRef<ShopUser | undefined>;
|
|
7
|
+
isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
8
|
+
customerType: import("vue").ComputedRef<"guest" | "new" | "existing">;
|
|
9
|
+
fetching: import("vue").Ref<boolean>;
|
|
10
|
+
fetch: () => Promise<void>;
|
|
11
|
+
forceRefresh: () => Promise<void>;
|
|
12
|
+
updateUser: (payload: Partial<ShopUser>) => Promise<void>;
|
|
13
|
+
updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
|
|
14
|
+
error: import("vue").Ref<import("nuxt/app").NuxtError | undefined>;
|
|
15
|
+
status: import("vue").Ref<import("./useRpc").Status>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useNuxtApp } from "nuxt/app";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { rpcCall } from "../../rpc/rpcCall.mjs";
|
|
4
|
+
import { useCoreLog } from "../useCoreLog.mjs";
|
|
5
|
+
import { useRpc } from "./useRpc.mjs";
|
|
6
|
+
import { useCurrentShop } from "./useCurrentShop.mjs";
|
|
7
|
+
import { toValue } from "#imports";
|
|
8
|
+
export async function useUser({
|
|
9
|
+
autoFetch = true,
|
|
10
|
+
lazy = false,
|
|
11
|
+
key = "useUser"
|
|
12
|
+
} = {}) {
|
|
13
|
+
const nuxtApp = useNuxtApp();
|
|
14
|
+
const shop = useCurrentShop();
|
|
15
|
+
const log = useCoreLog("useUser");
|
|
16
|
+
const { data, fetching, fetch, error, status } = await useRpc(
|
|
17
|
+
"getUser",
|
|
18
|
+
key,
|
|
19
|
+
void 0,
|
|
20
|
+
{
|
|
21
|
+
autoFetch,
|
|
22
|
+
lazy
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
const updateUser = async (payload) => {
|
|
26
|
+
log.debug("Update user");
|
|
27
|
+
data.value = await rpcCall(
|
|
28
|
+
nuxtApp,
|
|
29
|
+
"updateShopUser",
|
|
30
|
+
toValue(shop)
|
|
31
|
+
)(payload);
|
|
32
|
+
};
|
|
33
|
+
const updatePassword = async (payload) => {
|
|
34
|
+
log.debug("Update password");
|
|
35
|
+
const response = await rpcCall(
|
|
36
|
+
nuxtApp,
|
|
37
|
+
"updatePassword",
|
|
38
|
+
toValue(shop)
|
|
39
|
+
)(payload);
|
|
40
|
+
if (response) {
|
|
41
|
+
data.value = response;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const user = computed(() => data.value?.user);
|
|
45
|
+
const isLoggedIn = computed(() => !!user.value);
|
|
46
|
+
const customerType = computed(() => {
|
|
47
|
+
if (!isLoggedIn.value) {
|
|
48
|
+
return "guest";
|
|
49
|
+
}
|
|
50
|
+
return user.value?.groups?.includes("new") ? "new" : "existing";
|
|
51
|
+
});
|
|
52
|
+
const forceRefresh = async () => {
|
|
53
|
+
log.debug("Refresh user");
|
|
54
|
+
data.value = await rpcCall(nuxtApp, "refreshUser", toValue(shop))();
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
user,
|
|
58
|
+
isLoggedIn,
|
|
59
|
+
customerType,
|
|
60
|
+
fetching,
|
|
61
|
+
fetch,
|
|
62
|
+
forceRefresh,
|
|
63
|
+
updateUser,
|
|
64
|
+
updatePassword,
|
|
65
|
+
error,
|
|
66
|
+
status
|
|
67
|
+
};
|
|
68
|
+
}
|