-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: easypost integration #175
Open
edyespinal
wants to merge
4
commits into
main
Choose a base branch
from
feat/easypost-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -16,16 +16,17 @@ | |
"@vtex/tsconfig": "^0.6.0", | ||
"tslint": "^6.1.3", | ||
"tslint-config-vtex": "^2.1.0", | ||
"vtex.apps-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.apps-graphql", | ||
"vtex.catalog-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.catalog-graphql", | ||
"vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.css-handles", | ||
"vtex.easypost": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.easypost", | ||
"vtex.format-currency": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.format-currency", | ||
"vtex.my-account": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.my-account", | ||
"vtex.my-account-commons": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.my-account-commons", | ||
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.render-runtime", | ||
"vtex.return-app": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.return-app", | ||
"vtex.return-app": "https://rraep--powerplanet.myvtex.com/_v/private/typings/linked/v1/[email protected]+build1662483831/public/@types/vtex.return-app", | ||
"vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.store-graphql", | ||
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected].1/public/@types/vtex.styleguide", | ||
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected].2/public/@types/vtex.styleguide", | ||
"vtex.tenant-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.tenant-graphql" | ||
}, | ||
"scripts": { | ||
|
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,16 @@ | ||
import { sendReturnLabelService } from '../services/sendReturnLabelService' | ||
|
||
interface QuerySendReturnLabelArgs { | ||
requestId: string | ||
labelUrl: string | ||
} | ||
|
||
export const sendReturnLabel = async ( | ||
_: unknown, | ||
args: QuerySendReturnLabelArgs, | ||
ctx: Context | ||
) => { | ||
const { requestId, labelUrl } = args | ||
|
||
return sendReturnLabelService(ctx, requestId, labelUrl) | ||
} |
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,96 @@ | ||
import { ResolverError } from '@vtex/api' | ||
import type { ReturnRequest } from 'vtex.return-app' | ||
|
||
import type { ReturnLabelMailData } from '../typings/mailClient' | ||
import { templateName } from '../utils/emailTemplates' | ||
import { OMS_RETURN_REQUEST_LABEL_TEMPLATE } from '../utils/templates' | ||
import { formatRequestToPartialUpdate } from './updateRequestStatusService' | ||
|
||
export const sendReturnLabelService = async ( | ||
ctx: Context, | ||
requestId: string, | ||
labelUrl: string | ||
) => { | ||
const { | ||
clients: { mail, returnRequest: returnRequestClient }, | ||
vtex: { logger }, | ||
} = ctx | ||
|
||
if (!requestId || !labelUrl) { | ||
throw new ResolverError( | ||
'The requestId or the labelUrl was not provided', | ||
400 | ||
) | ||
} | ||
|
||
const returnRequest = (await returnRequestClient.get(requestId, [ | ||
'_all', | ||
])) as ReturnRequest | ||
|
||
const { | ||
pickupReturnData, | ||
cultureInfoData: { locale }, | ||
} = returnRequest | ||
|
||
const updatedPickupReturnData = { | ||
...pickupReturnData, | ||
labelUrl, | ||
} | ||
|
||
const updatedRequest = { | ||
...formatRequestToPartialUpdate(returnRequest), | ||
pickupReturnData: updatedPickupReturnData, | ||
} | ||
|
||
try { | ||
await returnRequestClient.update(requestId, updatedRequest) | ||
} catch (error) { | ||
const mdValidationErrors = error?.response?.data?.errors[0]?.errors | ||
|
||
const errorMessageString = mdValidationErrors | ||
? JSON.stringify( | ||
{ | ||
message: 'Schema Validation error', | ||
errors: mdValidationErrors, | ||
}, | ||
null, | ||
2 | ||
) | ||
: error.message | ||
|
||
throw new ResolverError(errorMessageString, error.response?.status || 500) | ||
} | ||
|
||
try { | ||
const templateExists = await mail.getTemplate(templateName('label', locale)) | ||
|
||
if (!templateExists) { | ||
await mail.publishTemplate(OMS_RETURN_REQUEST_LABEL_TEMPLATE(locale)) | ||
} | ||
|
||
const { customerProfileData } = updatedRequest | ||
|
||
const mailData: ReturnLabelMailData = { | ||
templateName: templateName('label', locale), | ||
jsonData: { | ||
data: { | ||
name: customerProfileData.name, | ||
DocumentId: requestId, | ||
email: customerProfileData.email, | ||
labelUrl, | ||
}, | ||
}, | ||
} | ||
|
||
await mail.sendMail(mailData) | ||
} catch (error) { | ||
logger.warn({ | ||
message: `Failed to send email for return request ${requestId}`, | ||
error, | ||
}) | ||
|
||
return false | ||
} | ||
|
||
return 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key coming from MD and mapped on
schema.json
under masterdata builder is calledreturnLabel
. In order to be consistent we should either change how we are saving it on masterdata or how we are declaring it on schema. I think the first one is the preferred one since, since changing schema on md can have side effects in the indexation process.