Skip to content

Commit

Permalink
Add Algolia sample extension to sync products
Browse files Browse the repository at this point in the history
  • Loading branch information
leungkinghin-ct committed Aug 7, 2023
1 parent 5c3eceb commit c81e710
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 8 deletions.
276 changes: 275 additions & 1 deletion full-ingestion/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions full-ingestion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
"dependencies": {
"@commercetools-backend/loggers": "^21.19.0",
"@commercetools/platform-sdk": "^4.1.0",
"@commercetools/sdk-client-v2": "^2.0.1",
"@commercetools/sdk-client-v2": "^2.2.0",
"algoliasearch": "^4.19.1",
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "4.18.2",
"lodash": "^4.17.21",
"validator": "^13.7.0"
}
}
}
15 changes: 15 additions & 0 deletions full-ingestion/src/clients/build.client.js
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();
29 changes: 29 additions & 0 deletions full-ingestion/src/clients/create.client.js
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();
};
Loading

0 comments on commit c81e710

Please sign in to comment.