-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: code with some updates and allowing rebuild
- Update of node builder - Typescript Refactor - Lint issues - Changelog added - @vtex/api updated - Removed and renamed unused/unnecessary code and imports
- Loading branch information
Showing
18 changed files
with
1,811 additions
and
349 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
*.snap.ts |
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,9 @@ | ||
{ | ||
"extends": "vtex", | ||
"root": true, | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"jest": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"eslintIntegration": true | ||
} | ||
"@vtex/prettier-config" |
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,15 @@ | ||
.DS_Store | ||
.git/ | ||
.happypack/ | ||
.vscode/ | ||
node_modules/ | ||
.editorconfig | ||
.eslintrc | ||
.gitignore | ||
gulpfile.js | ||
package.json | ||
tsconfig.json | ||
tslint.json | ||
typings.d.ts | ||
yarn.lock | ||
node/node_modules/ |
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,11 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
### Fixed | ||
- Refactor code for proper build |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import {resolvers} from './resolvers' | ||
import { resolvers } from './resolvers' | ||
import { Service } from '@vtex/api' | ||
|
||
export default { | ||
graphql: resolvers | ||
} | ||
export default new Service({ | ||
graphql: { | ||
resolvers | ||
} | ||
}) |
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 |
---|---|---|
@@ -1,42 +1,66 @@ | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import FileManager from '../FileManager' | ||
import { ServiceContext } from '@vtex/api' | ||
|
||
type FileManagerArgs = { | ||
path: string | ||
width: number | ||
height: number | ||
aspect: boolean | ||
bucket: string | ||
} | ||
|
||
type UploadFileArgs = { | ||
file: Promise<any> | ||
bucket: string | ||
} | ||
|
||
export const resolvers = { | ||
Query: { | ||
getFile: async (root, args, ctx, info) => { | ||
getFile: async (_: unknown, args: FileManagerArgs, ctx: ServiceContext) => { | ||
const fileManager = new FileManager(ctx.vtex) | ||
const {path, width, height, aspect, bucket} = args | ||
return await fileManager.getFile(path, width, height, aspect, bucket) | ||
const { path, width, height, aspect, bucket } = args | ||
|
||
const file = await fileManager.getFile(path, width, height, aspect, bucket) | ||
return file | ||
}, | ||
getFileUrl: async (root, args, ctx, info) => { | ||
getFileUrl: async (_: unknown, args: FileManagerArgs, ctx: ServiceContext) => { | ||
const fileManager = new FileManager(ctx.vtex) | ||
const {path, bucket} = args | ||
return await fileManager.getFileUrl(path, bucket) | ||
const { path, bucket } = args | ||
|
||
const file = await fileManager.getFileUrl(path, bucket) | ||
return file | ||
}, | ||
settings: async (root, args, ctx, info) => ({ | ||
maxFileSizeMB: 4 | ||
settings: async () => ({ | ||
maxFileSizeMB: 4, | ||
}), | ||
}, | ||
Mutation: { | ||
uploadFile: async (obj, args, ctx, info) => { | ||
uploadFile: async (_: unknown, args: UploadFileArgs, ctx: ServiceContext) => { | ||
const fileManager = new FileManager(ctx.vtex) | ||
const {file, bucket} = args | ||
const {stream, filename: name, mimetype, encoding} = await file | ||
const { file, bucket } = args | ||
const loadedFile = await file | ||
const {filename: name, mimetype, encoding } = loadedFile | ||
const [extension] = name?.split('.')?.reverse() | ||
const filename = `${uuidv4()}.${extension}` | ||
const stream = loadedFile.createReadStream(filename) | ||
|
||
const incomingFile = { filename, mimetype, encoding } | ||
|
||
const incomingFile = {filename, mimetype, encoding} | ||
return { | ||
encoding, | ||
mimetype, | ||
fileUrl: await fileManager.saveFile(incomingFile, stream, bucket), | ||
} | ||
}, | ||
deleteFile: async (obj, args, ctx, info) => { | ||
deleteFile: async (_: unknown, args: FileManagerArgs, ctx: ServiceContext) => { | ||
const fileManager = new FileManager(ctx.vtex) | ||
const {path, bucket} = args | ||
const { path, bucket } = args | ||
|
||
await fileManager.deleteFile(path, bucket) | ||
|
||
return true | ||
} | ||
} | ||
}, | ||
}, | ||
} |
Oops, something went wrong.