Skip to content

Commit

Permalink
Merge branch 'master' of github.com:itswadesh/svelte-commerce
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapmaharana committed May 7, 2023
2 parents 5495b5d + 29aacc4 commit c87339c
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 177 deletions.
222 changes: 111 additions & 111 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lib/services/bigcommerce/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
youtubeUrl,
IMAGE_CDN_URL
} from '$lib/config'
import { fetchInit } from './InitService'
import { fetchInit } from './init-service'

export const getStoreData = async ({
cookieStore,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/shopify/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
youtubeUrl,
IMAGE_CDN_URL
} from '$lib/config'
import { fetchInit } from './InitService'
import { fetchInit } from './init-service'

export const getStoreData = async ({
cookieStore,
Expand Down
2 changes: 0 additions & 2 deletions src/lib/services/woocommerce/init-service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { error } from '@sveltejs/kit'
import { getBySid } from '$lib/utils/server'
import { DOMAIN } from '$lib/config'

export const fetchInit = async (host) => {
// This is called once during hard reload + everytime footer is hit through /server/store/server.ts
try {
let res: any = {}
// DOMAIN value is proviede in case of self hosted and host value in case of SaaS
res = await getBySid(`init?domain=${DOMAIN ? DOMAIN : host}`)
return res || {}
} catch (e) {
throw error(e.status, e.data?.message || e.message)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/woocommerce/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
youtubeUrl,
IMAGE_CDN_URL
} from '$lib/config'
import { fetchInit } from './InitService'
import { fetchInit } from './init-service'

export const getStoreData = async ({
cookieStore,
Expand Down
13 changes: 9 additions & 4 deletions src/lib/services/woocommerce/zip-service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Error, Product } from '$lib/types'
import { error } from '@sveltejs/kit'
import { getBySid } from '$lib/utils/server'

import { serializeNonPOJOs } from '$lib/utils/validations'
import { getWoocommerceApi } from '$lib/utils/server'

export const findByCity = async (locals: App.Locals, q: string): Promise<Product> => {
try {
const data = serializeNonPOJOs<Product>((await getBySid(`pincodes?${q}`)).data)
const data = serializeNonPOJOs<Product>((await getWoocommerceApi(`pincodes?${q}`)).data)
return data
} catch (err) {
const e = err as Error
Expand All @@ -15,7 +16,9 @@ export const findByCity = async (locals: App.Locals, q: string): Promise<Product

export const groupByCity = async (locals: App.Locals, id: string): Promise<Product> => {
try {
const data = serializeNonPOJOs<Product>((await getBySid(`pincodes/group-by-city`)).data)
const data = serializeNonPOJOs<Product>(
(await getWoocommerceApi(`pincodes/group-by-city`)).data
)
return data
} catch (err) {
const e = err as Error
Expand All @@ -25,7 +28,9 @@ export const groupByCity = async (locals: App.Locals, id: string): Promise<Produ

export const groupByState = async (locals: App.Locals, id: string): Promise<Product> => {
try {
const data = serializeNonPOJOs<Product>((await getBySid(`pincodes/group-by-state`)).data)
const data = serializeNonPOJOs<Product>(
(await getWoocommerceApi(`pincodes/group-by-state`)).data
)
return data
} catch (err) {
const e = err as Error
Expand Down
44 changes: 22 additions & 22 deletions src/routes/(app)/+page.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { CollectionService, DealsService, HomeService } from '$lib/services'
const isServer = import.meta.env.SSR

export async function load({ parent }) {
const { store, origin } = await parent()

return {
streamed: {
home: HomeService.fetchHome({ origin, storeId: store?.id, server: isServer }),

deals: DealsService.fetchDeals({ origin, storeId: store?.id, server: isServer }),

collections: CollectionService.fetchCollections({
origin,
storeId: store?.id,
server: isServer
})
},

origin
}
}
import { CollectionService, DealsService, HomeService } from '$lib/services'
const isServer = import.meta.env.SSR

export async function load({ parent }) {
const { store, origin } = await parent()

return {
streamed: {
home: HomeService.fetchHome({ origin, storeId: store?.id, server: isServer }),

deals: DealsService.fetchDeals({ origin, storeId: store?.id, server: isServer }),

collections: CollectionService.fetchCollections({
origin,
storeId: store?.id,
server: isServer
})
},

origin
}
}
70 changes: 35 additions & 35 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
export const prerender = false

import { DOMAIN, HTTP_ENDPOINT } from '$lib/config'
import { error } from '@sveltejs/kit'
import type { LayoutServerLoad } from './$types'

export const load: LayoutServerLoad = async ({ url, locals, cookies }) => {
try {
const currentPage = +url.searchParams.get('page') || 1
const q = url.searchParams.get('q') || ''
const { pathname } = url

// setHeaders({
// 'cache-control': 'public, max-age=300'
// })
const zip = cookies.get('zip')
locals.url = url.href
locals.currentPage = currentPage
locals.q = q
locals.sid = cookies.get('connect.sid')
locals.cartQty = cookies.get('cartQty')
if (zip) locals.zip = JSON.parse(zip)
// me,
return { ...locals, pathname }
} catch (e) {
throw error(
404,
`Store Not Found @Layout
<br/>ID: ${locals.store.id}
<br/>ORIGIN: ${locals.origin}
<br/>DOMAIN(env): ${DOMAIN}
<br/>HTTP_ENDPOINT(env): ${HTTP_ENDPOINT}`
)
}
}
export const prerender = false

import { DOMAIN, HTTP_ENDPOINT } from '$lib/config'
import { error } from '@sveltejs/kit'
import type { LayoutServerLoad } from './$types'

export const load: LayoutServerLoad = async ({ url, locals, cookies }) => {
try {
const currentPage = +url.searchParams.get('page') || 1
const q = url.searchParams.get('q') || ''
const { pathname } = url

// setHeaders({
// 'cache-control': 'public, max-age=300'
// })
const zip = cookies.get('zip')
locals.url = url.href
locals.currentPage = currentPage
locals.q = q
locals.sid = cookies.get('connect.sid')
locals.cartQty = cookies.get('cartQty')
if (zip) locals.zip = JSON.parse(zip)
// me,
return { ...locals, pathname }
} catch (e) {
throw error(
404,
`Store Not Found @Layout
<br/>ID: ${locals.store.id}
<br/>ORIGIN: ${locals.origin}
<br/>DOMAIN(env): ${DOMAIN}
<br/>HTTP_ENDPOINT(env): ${HTTP_ENDPOINT}`
)
}
}

1 comment on commit c87339c

@vercel
Copy link

@vercel vercel bot commented on c87339c May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.