-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Algolia sample extension to sync products
- Loading branch information
1 parent
5c3eceb
commit c81e710
Showing
13 changed files
with
493 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
import { ClientBuilder } from '@commercetools/sdk-client-v2'; | ||
import { authMiddlewareOptions } from '../middlewares/auth.middleware.js'; | ||
import { httpMiddlewareOptions } from '../middlewares/http.middleware.js'; | ||
import { readConfiguration } from '../utils/config.utils.js'; | ||
|
||
/** | ||
* Create a new client builder. | ||
* This code creates a new Client that can be used to make API calls | ||
*/ | ||
export const createClient = () => | ||
new ClientBuilder() | ||
.withProjectKey(readConfiguration().projectKey) | ||
.withClientCredentialsFlow(authMiddlewareOptions) | ||
.withHttpMiddleware(httpMiddlewareOptions) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'; | ||
import { createClient } from './build.client.js'; | ||
import { readConfiguration } from '../utils/config.utils.js'; | ||
|
||
/** | ||
* Create client with apiRoot | ||
* apiRoot can now be used to build requests to de Composable Commerce API | ||
*/ | ||
export const createApiRoot = ((root) => () => { | ||
if (root) { | ||
return root; | ||
} | ||
|
||
root = createApiBuilderFromCtpClient(createClient()).withProjectKey({ | ||
projectKey: readConfiguration().projectKey, | ||
}); | ||
|
||
return root; | ||
})(); | ||
|
||
/** | ||
* Example code to get the Project details | ||
* This code has the same effect as sending a GET | ||
* request to the commercetools Composable Commerce API without any endpoints. | ||
* | ||
*/ | ||
export const getProject = async () => { | ||
return await createApiRoot().get().execute(); | ||
}; |
Oops, something went wrong.