Skip to content

Commit

Permalink
chore(package): add nuxt layer package
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMunizOdoo committed Oct 23, 2023
1 parent 6197d18 commit 369d839
Show file tree
Hide file tree
Showing 32 changed files with 669 additions and 36 deletions.
12 changes: 12 additions & 0 deletions packages/nuxt-layer/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions packages/nuxt-layer/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["@nuxt/eslint-config"],
};
21 changes: 21 additions & 0 deletions packages/nuxt-layer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules
*.log
.nuxt
nuxt.d.ts
.output
.data
.env
package-lock.json
framework
dist
.DS_Store

# Yarn
.yarn/cache
.yarn/*state*

# Local History
.history

# VSCode
.vscode/
1 change: 1 addition & 0 deletions packages/nuxt-layer/.nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typescript.includeWorkspace = true
73 changes: 73 additions & 0 deletions packages/nuxt-layer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Nuxt Layer Starter

Create Nuxt extendable layer with this GitHub template.

## Setup

Make sure to install the dependencies:

```bash
pnpm install
```

## Working on your theme

Your theme is at the root of this repository, it is exactly like a regular Nuxt project, except you can publish it on NPM.

The `.playground` directory should help you on trying your theme during development.

Running `pnpm dev` will prepare and boot `.playground` directory, which imports your theme itself.

## Distributing your theme

Your Nuxt layer is shaped exactly the same as any other Nuxt project, except you can publish it on NPM.

To do so, you only have to check if `files` in `package.json` are valid, then run:

```bash
npm publish --access public
```

Once done, your users will only have to run:

```bash
npm install --save your-theme
```

Then add the dependency to their `extends` in `nuxt.config`:

```ts
defineNuxtConfig({
extends: 'your-theme'
})
```

## Development Server

Start the development server on http://localhost:3000

```bash
pnpm dev
```

## Production

Build the application for production:

```bash
pnpm build
```

Or statically generate it with:

```bash
pnpm generate
```

Locally preview production build:

```bash
pnpm preview
```

Checkout the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
7 changes: 7 additions & 0 deletions packages/nuxt-layer/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default defineAppConfig({
})

declare module '@nuxt/schema' {
interface AppConfigInput {
}
}
3 changes: 3 additions & 0 deletions packages/nuxt-layer/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<NuxtWelcome />
</template>
7 changes: 7 additions & 0 deletions packages/nuxt-layer/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
build: {
transpile: ['tslib', '@apollo/client', '@apollo/client/core', '@vue/apollo-composable', '@vue/apollo-option', 'ts-invariant', 'vue-toastification', '@erpgap/odoo-sdk-api-client']
},
})
24 changes: 24 additions & 0 deletions packages/nuxt-layer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@erpgap/odoo-nuxt-layer",
"type": "module",
"version": "0.0.1",
"main": "./nuxt.config.ts",
"files": [
"server"
],
"scripts": {
"dev": "nuxi dev",
"build": "nuxt build",
"generate": "nuxt generate",
"preview": "nuxt preview",
"lint": "eslint .",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@erpgap/odoo-sdk-api-client": "*",
"@nuxt/eslint-config": "^0.1.1",
"eslint": "^8.28.0",
"nuxt": "^3.8.0",
"typescript": "^4.9.3"
}
}
20 changes: 20 additions & 0 deletions packages/nuxt-layer/server/api/odoo/mutation.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Endpoints } from '@erpgap/odoo-sdk-api-client';

export default defineEventHandler(async (event) => {
const body = await readBody(event);

const api: Endpoints = event.context.apolloClient.api;

const response = await api.mutation(body?.[0], body?.[1]);

if ((response.data as any)?.cookie) {
appendResponseHeader(event, 'Set-cookie', (response.data as any)?.cookie);
}

if (response.errors) {
throw createError({ statusCode: 400, data: response.errors });
}

return response.data;
});

21 changes: 21 additions & 0 deletions packages/nuxt-layer/server/api/odoo/query.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Endpoints } from '@erpgap/odoo-sdk-api-client';
import { getCached } from '~/server/utils/getCached';

export default defineEventHandler(async (event) => {
const body = await readBody(event);
const api: Endpoints = event.context.apolloClient.api;

// const data = await getCached(event, body);
const response = await api.query(body?.[0], body?.[1]);

if ((response.data as any)?.cookie) {
appendResponseHeader(event, 'Set-cookie', (response.data as any)?.cookie);
}

if (response.errors) {
throw createError(response.errors[0].message);
}

return response.data;
});

20 changes: 20 additions & 0 deletions packages/nuxt-layer/server/middleware/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createApiClient, MiddlewareConfig } from '@erpgap/odoo-sdk-api-client/server';
import { Queries } from '~/server/queries';
import { Mutations } from '~/server/mutations';

export default defineEventHandler((event) => {

const config : MiddlewareConfig = {
// https://odoo-cla.ce.promptequation.com/graphql/vsf
odooGraphqlUrl: `${process.env.ODOO_BASE_URL}graphql/vsf`,
queries: { ...Queries, ...Mutations },
headers: {
'REAL-IP': getRequestIP(event) || '',
Cookie: `session_id=${parseCookies(event).session_id}`,
'resquest-host': getRequestHost(event)
}
};

event.context.apolloClient = createApiClient(config);
});

10 changes: 10 additions & 0 deletions packages/nuxt-layer/server/mutations/ChangePasswordMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { gql } from '@apollo/client/core';
export default gql`
mutation($newPassword: String!, $token: String!) {
changePassword(newPassword: $newPassword, token: $token) {
id
name
email
}
}
`;
25 changes: 25 additions & 0 deletions packages/nuxt-layer/server/mutations/CreateNewAccountMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { gql } from '@apollo/client/core';

export default gql`
mutation register($companyName: String!, $firstName: String!, $lastName: String!, $email: String!, $location : String!$password: String!, $phoneNumber: String!) {
register(companyName: $companyName, firstName: $firstName, lastName: $lastName, email: $email, location: $location, password: $password, phoneNumber: $phoneNumber) {
partner{
id
name
street
street2
city
state
{
id
}
country
{
id
}
email
phone
}
}
}`;

23 changes: 23 additions & 0 deletions packages/nuxt-layer/server/mutations/LoginMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { gql } from '@apollo/client/core';
export default gql`
mutation($email: String!, $password: String!) {
login(email: $email, password: $password) {
partner{
id
name
street
street2
city
state
{
id
}
country
{
id
}
email
phone
}
}
}`;
6 changes: 6 additions & 0 deletions packages/nuxt-layer/server/mutations/LogoutMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { gql } from '@apollo/client/core';
export default gql`
mutation {
logout
}
`;
10 changes: 10 additions & 0 deletions packages/nuxt-layer/server/mutations/SendResetPasswordMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { gql } from '@apollo/client/core';
export default gql`
mutation($email: String!) {
resetPassword(email: $email) {
id
name
email
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { gql } from '@apollo/client/core';
export default gql`
mutation($currentPassword: String!, $newPassword: String!){
updatePassword(currentPassword: $currentPassword, newPassword: $newPassword) {
id
}
}
`;
30 changes: 30 additions & 0 deletions packages/nuxt-layer/server/mutations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DocumentNode } from '@apollo/client';
import LoginMutation from './LoginMutation';
import LogoutMutation from './LogoutMutation';
import CreateNewAccountMutation from './CreateNewAccountMutation';
import SendResetPasswordMutation from './SendResetPasswordMutation';
import UpdatePasswordMutation from './UpdatePasswordMutation';
import ChangePasswordMutation from './ChangePasswordMutation';

enum MutationName {
LoginMutation = 'LoginMutation',
LogoutMutation = 'LogoutMutation',
CreateNewAccountMutation = 'CreateNewAccountMutation',
SendResetPasswordMutation = 'SendResetPasswordMutation',
UpdatePasswordMutation = 'UpdatePasswordMutation',
ChangePasswordMutation = 'ChangePasswordMutation'
}

const Mutations : Record<MutationName, DocumentNode> = {
LoginMutation,
LogoutMutation,
CreateNewAccountMutation,
SendResetPasswordMutation,
UpdatePasswordMutation,
ChangePasswordMutation
};

export {
Mutations,
MutationName
};
7 changes: 7 additions & 0 deletions packages/nuxt-layer/server/queries/LoadUserQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { gql } from '@apollo/client/core';
import {partnerFragment} from './fragments';
export default gql`
query LoadUser {
${partnerFragment}
}
`;
29 changes: 29 additions & 0 deletions packages/nuxt-layer/server/queries/ProductVariantQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { gql } from '@apollo/client/core';
export default gql`
query ProductVariant($productTemplateId: Int, $combinationId: [Int]) {
productVariant( productTemplateId: $productTemplateId combinationId: $combinationId) {
product {
id
image
variantPrice
variantPriceAfterDiscount
variantHasDiscountedPrice
alternativeProducts{
id
typeId
visibility
status
name
displayName
sku
barcode
description
}
}
productTemplateId
displayName
price
listPrice
hasDiscountedPrice
}
}`;
1 change: 1 addition & 0 deletions packages/nuxt-layer/server/queries/fragments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as partnerFragment } from './partnerFragment';
Loading

0 comments on commit 369d839

Please sign in to comment.