Skip to content

Commit

Permalink
feat: add nextjs implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoral committed Dec 17, 2023
1 parent 5263672 commit 1bcfab3
Show file tree
Hide file tree
Showing 62 changed files with 11,194 additions and 411 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ coverage
.DS_STORE

# Nuxt generated files
.nuxt
.nuxt

# Next generated files
.next

# Cypress generated files
**/cypress/screenshots
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@vue-storefront/jest-config": "^0.0.3",
"@vue-storefront/rollup-config": "^0.0.6",
"cross-env": "^6.0.3",
"cypress": "^13.6.1",
"husky": "^8.0.3",
"jest": "^27.0.6",
"lerna": "^6.6.2",
Expand Down
21 changes: 21 additions & 0 deletions packages/next/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Vue Storefront

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client";

import { useEffect, useState } from "react";
import { useSdk } from "../../hooks";

export function ClientComponentUsingSdk() {
const sdk = useSdk();
const [response, setResponse] = useState<any>();

useEffect(() => {
sdk.example.getSuccess().then((res) => {
setResponse(res);
});
}, []);

return <pre>{JSON.stringify(response, null, 2)}</pre>;
}
10 changes: 10 additions & 0 deletions packages/next/__tests__/apps/app-router/app/csr/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ClientComponentUsingSdk } from "./ClientComponent";

export default function ClientSidePage() {
return (
<main>
<h1>Client Side Page</h1>
<ClientComponentUsingSdk />
</main>
);
}
12 changes: 12 additions & 0 deletions packages/next/__tests__/apps/app-router/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ReactNode } from "react";
import { Providers } from "./providers";

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
);
}
11 changes: 11 additions & 0 deletions packages/next/__tests__/apps/app-router/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";

import { ReactNode, useState } from "react";
import { SdkProvider } from "../hooks";
import { getSdk } from "../sdk.config";

export function Providers({ children }: { children: ReactNode }) {
const [sdk] = useState(getSdk());

return <SdkProvider sdk={sdk}>{children}</SdkProvider>;
}
15 changes: 15 additions & 0 deletions packages/next/__tests__/apps/app-router/app/ssr/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { headers } from "next/headers";
import { getSdk } from "../../sdk.config";

export default async function SsrPage() {
const pageData = await getSdk({
getRequestHeaders: () => headers(),
}).example.getSuccess();

return (
<main>
<h1>Server Side Page</h1>
<pre>{JSON.stringify(pageData, null, 2)}</pre>
</main>
);
}
3 changes: 3 additions & 0 deletions packages/next/__tests__/apps/app-router/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createSdkContext } from "../sdk.config";

export const [SdkProvider, useSdk] = createSdkContext();
5 changes: 5 additions & 0 deletions packages/next/__tests__/apps/app-router/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
4 changes: 4 additions & 0 deletions packages/next/__tests__/apps/app-router/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
21 changes: 21 additions & 0 deletions packages/next/__tests__/apps/app-router/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@vue-storefront/next-tests-app",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.0.4"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18"
}
}
19 changes: 19 additions & 0 deletions packages/next/__tests__/apps/app-router/sdk.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable import/no-relative-packages */
import { CreateSdkOptions, createSdk } from "../../../src/index";
import { exampleSdkModule } from "../../sdk";

const options: CreateSdkOptions = {
middleware: {
apiUrl: "http://localhost:4000/",
},
};

export const { getSdk, createSdkContext } = createSdk(
options,
({ buildModule, middlewareUrl, getRequestHeaders }) => ({
example: buildModule(exampleSdkModule, {
apiUrl: `${middlewareUrl}test_integration`,
headers: getRequestHeaders(),
}),
})
);
24 changes: 24 additions & 0 deletions packages/next/__tests__/apps/app-router/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 1bcfab3

Please sign in to comment.