-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: HTTP Client for moduleForEndpoints #7053
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
Merged
WojtekTheWebDev
merged 9 commits into
feat/moduleFromEndpoints
from
feat/IN-3860-moduleFromEndpoints-httpClient
Mar 4, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dafd070
feat: default behaviour of HTTP Client
WojtekTheWebDev 3ef5382
remove isomorphic-fetch from depts
WojtekTheWebDev de6000e
full implementation of HTTP client
WojtekTheWebDev fda0d28
Merge branch 'feat/moduleFromEndpoints' into feat/IN-3860-moduleFromEβ¦
WojtekTheWebDev 372ce5d
test: update tests based on the review
WojtekTheWebDev 51791bd
fix issue with URL class and urls as paths
WojtekTheWebDev 1e6cdab
add test for axios
WojtekTheWebDev b9aac2f
add computed headers to http client
WojtekTheWebDev b881f78
update tsdocs
WojtekTheWebDev 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
| const { apiClientFactory } = require("@vue-storefront/middleware"); | ||
|
|
||
| const onCreate = (settings) => { | ||
| return { | ||
| config: settings, | ||
| client: null, | ||
| }; | ||
| }; | ||
|
|
||
| const { createApiClient } = apiClientFactory({ | ||
| onCreate, | ||
| api: { | ||
| getProduct: async (_context, params) => { | ||
| return { id: params.id, name: "Test Product" }; | ||
| }, | ||
| getProducts: async (_context, _params) => { | ||
| return [{ id: 1, name: "Test Product" }]; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| exports.createApiClient = createApiClient; |
This file contains hidden or 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,12 @@ | ||
| export type Endpoints = { | ||
| /** | ||
| * Get the product by id. | ||
| */ | ||
| getProduct: (params: { id: number }) => Promise<{ id: number; name: string }>; | ||
| /** | ||
| * Get the list of products. | ||
| */ | ||
| getProducts: (params: { | ||
| limit: number; | ||
| }) => Promise<{ id: number; name: string }[]>; | ||
| }; | ||
22 changes: 22 additions & 0 deletions
22
packages/sdk/src/__tests__/integration/__config__/jest.setup.global.ts
This file contains hidden or 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,22 @@ | ||
| import { createServer } from "@vue-storefront/middleware"; | ||
|
|
||
| async function runMiddleware(app) { | ||
| return new Promise((resolve) => { | ||
| const server = app.listen(8181, async () => { | ||
| resolve(server); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| export default async () => { | ||
| const app = await createServer({ | ||
| integrations: { | ||
| commerce: { | ||
| location: "./src/__tests__/__mocks__/apiClient/server", | ||
| configuration: {}, | ||
| }, | ||
| }, | ||
| }); | ||
| const server = await runMiddleware(app); | ||
| globalThis.__MIDDLEWARE__ = server; | ||
| }; |
3 changes: 3 additions & 0 deletions
3
packages/sdk/src/__tests__/integration/__config__/jest.teardown.global.ts
This file contains hidden or 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 @@ | ||
| export default () => { | ||
| globalThis.__MIDDLEWARE__.close(); | ||
| }; |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.