-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
265 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { publicProcedure, router } from "@/lib/trpc/init" | ||
|
||
import { deleteStore, installOrUpdateStore } from "./mutations" | ||
import { getStoresQuery } from "./queries" | ||
import { | ||
deleteStoreRequestSchema, | ||
deleteStoreResponseSchema, | ||
getStoresResponseSchema, | ||
installOrUpdateStoreRequestSchema, | ||
installOrUpdateStoreResponseSchema, | ||
} from "./schemas" | ||
|
||
export const storesRouter = router({ | ||
getStores: publicProcedure.output(getStoresResponseSchema()).query(getStoresQuery), | ||
installOrUpdateStore: publicProcedure | ||
.input(installOrUpdateStoreRequestSchema()) | ||
.output(installOrUpdateStoreResponseSchema()) | ||
.mutation(installOrUpdateStore), | ||
deleteStore: publicProcedure | ||
.input(deleteStoreRequestSchema()) | ||
.output(deleteStoreResponseSchema()) | ||
.mutation(deleteStore), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { z } from "zod" | ||
|
||
import { getConfiguration, setConfiguration } from "@/lib/configuration" | ||
import { handleDeleteStore, handleDownloadStore } from "@/lib/stores" | ||
import { handleApiError } from "@/lib/utils/server-utils" | ||
import { apiInputFromSchema } from "@/types" | ||
|
||
import { | ||
deleteStoreRequestSchema, | ||
deleteStoreResponseSchema, | ||
installOrUpdateStoreRequestSchema, | ||
installOrUpdateStoreResponseSchema, | ||
} from "./schemas" | ||
|
||
export const installOrUpdateStore = async ({ | ||
input: { store }, | ||
}: apiInputFromSchema<typeof installOrUpdateStoreRequestSchema>) => { | ||
try { | ||
await handleDownloadStore(store, true) | ||
|
||
const data: z.infer<ReturnType<typeof installOrUpdateStoreResponseSchema>> = { success: true } | ||
return data | ||
} catch (error: unknown) { | ||
return handleApiError(error) | ||
} | ||
} | ||
|
||
export const deleteStore = async ({ input: { store } }: apiInputFromSchema<typeof deleteStoreRequestSchema>) => { | ||
try { | ||
const configuration = await getConfiguration() | ||
|
||
// Remove store from configuration | ||
await setConfiguration({ | ||
...configuration, | ||
plugins: configuration.plugins?.filter((p) => p.name !== store.name), | ||
stores: configuration.stores?.filter((s) => s.name !== store.name), | ||
}) | ||
|
||
// Delete form store folder | ||
await handleDeleteStore(store) | ||
|
||
const data: z.infer<ReturnType<typeof deleteStoreResponseSchema>> = { success: true } | ||
return data | ||
} catch (error: unknown) { | ||
return handleApiError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { z } from "zod" | ||
|
||
import { getStores } from "@/lib/stores" | ||
import { handleApiError } from "@/lib/utils/server-utils" | ||
import { apiInputFromSchema } from "@/types" | ||
|
||
import { getStoresResponseSchema } from "./schemas" | ||
|
||
export const getStoresQuery = async ({}: apiInputFromSchema<typeof undefined>) => { | ||
try { | ||
const stores = await getStores() | ||
|
||
const data: z.infer<ReturnType<typeof getStoresResponseSchema>> = { stores } | ||
return data | ||
} catch (error: unknown) { | ||
return handleApiError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { z } from "zod" | ||
|
||
import { fullStoreSchema } from "@/lib/stores" | ||
import { storeConfigSchema } from "@next-boilerplate/scripts/utils/template-config/index.js" | ||
|
||
export const getStoresResponseSchema = () => z.object({ stores: z.array(fullStoreSchema) }) | ||
|
||
export const installOrUpdateStoreRequestSchema = () => | ||
z.object({ | ||
store: storeConfigSchema, | ||
}) | ||
|
||
export const installOrUpdateStoreResponseSchema = () => z.object({ success: z.boolean() }) | ||
|
||
export const deleteStoreRequestSchema = () => | ||
z.object({ | ||
store: storeConfigSchema, | ||
}) | ||
|
||
export const deleteStoreResponseSchema = () => z.object({ success: z.boolean() }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.