-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from vtex-apps/fix/B2BTEAM-1187-use-orders-en…
…dpoint Add Orders client and use it to get orders info
- Loading branch information
Showing
6 changed files
with
79 additions
and
27 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,35 @@ | ||
import type { InstanceOptions, IOContext, RequestConfig } from '@vtex/api' | ||
import { JanusClient } from '@vtex/api' | ||
|
||
import { statusToError } from '../utils' | ||
|
||
export default class OrdersClient extends JanusClient { | ||
constructor(ctx: IOContext, options?: InstanceOptions) { | ||
super(ctx, { | ||
...options, | ||
headers: { | ||
...options?.headers, | ||
VtexIdclientAutCookie: ctx.authToken, | ||
}, | ||
}) | ||
} | ||
|
||
public order = (id: string) => | ||
this.get(this.routes.order(id), { metric: 'orders' }) | ||
|
||
protected get = <T>(url: string, config: RequestConfig = {}) => { | ||
config.headers = { | ||
...config.headers, | ||
} | ||
|
||
return this.http.get<T>(url, config).catch(statusToError) | ||
} | ||
|
||
private get routes() { | ||
const base = '/api/orders' | ||
|
||
return { | ||
order: (id: string) => `${base}/pvt/document/${id}`, | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -831,10 +831,10 @@ | |
dependencies: | ||
"@types/yargs-parser" "*" | ||
|
||
"@vtex/[email protected].19": | ||
version "6.45.19" | ||
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.19.tgz#97b449850b517d6610e7123aa91caec2a29ae7b1" | ||
integrity sha512-WUsAn1Oi+Z7Ih84DcRf4HQH85Mh+zO84L0ta7zuRyb13DoAEq2qMi0Mv6vZMd9BFWOCSD8AcTHVF/gZskwh9Yw== | ||
"@vtex/[email protected].20": | ||
version "6.45.20" | ||
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.20.tgz#c1090249a424fd700499de3fed0d80d99ff53332" | ||
integrity sha512-O7RJWWr4PfvixNpc0GgQh85iKcv9j1IKkpApwJQSW/WzxoTgSrcjYHOVUmJ1GWWBmRV/qvB2VaV6Ow1QL3UOCQ== | ||
dependencies: | ||
"@types/koa" "^2.11.0" | ||
"@types/koa-compose" "^3.2.3" | ||
|
@@ -3470,7 +3470,7 @@ stack-utils@^2.0.3: | |
dependencies: | ||
escape-string-regexp "^2.0.0" | ||
|
||
stats-lite@vtex/node-stats-lite#dist: | ||
"stats-lite@github:vtex/node-stats-lite#dist": | ||
version "2.2.0" | ||
resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" | ||
dependencies: | ||
|