{"id":18930037,"url":"https://github.com/labd/commercetools-utilities-javascript","last_synced_at":"2025-08-03T17:36:03.721Z","repository":{"id":38309846,"uuid":"329608178","full_name":"labd/commercetools-utilities-javascript","owner":"labd","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-22T16:39:38.000Z","size":292,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T22:51:11.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/labd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-14T12:25:26.000Z","updated_at":"2023-06-05T12:00:38.000Z","dependencies_parsed_at":"2024-11-08T11:51:35.145Z","dependency_job_id":null,"html_url":"https://github.com/labd/commercetools-utilities-javascript","commit_stats":{"total_commits":55,"total_committers":5,"mean_commits":11.0,"dds":"0.34545454545454546","last_synced_commit":"2eaecc4438558239f128f32ecbcaa853a6dad759"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-utilities-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-utilities-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-utilities-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-utilities-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labd","download_url":"https://codeload.github.com/labd/commercetools-utilities-javascript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586241,"owners_count":21128998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:36:20.482Z","updated_at":"2025-04-15T15:31:14.065Z","avatar_url":"https://github.com/labd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lab Digital Commercetools Utilities\n\n## CommercetoolsClient\n\nThis is a more straight-forward helper to create a commercetools client for\ninteracting with Commercetools.\n\n```ts\nconst client = CommercetoolsClient({\n  host: 'https://api.europe-west1.gcp.commercetools.com/',\n  projectKey: 'my-project',\n  auth: {\n    host: 'https://auth.europe-west1.gcp.commercetools.com/',\n    credentials: {\n      clientId: 'my-client-id',\n      clientSecret: 'my-client-secret',\n    },\n    scopes: ['view_orders:my-project', 'view_products:my-project'],\n  },\n});\n\nconst projectApi = await client.getProjectApi();\nprojectApi.products().get().execute()\n```\n\nWhen the options are not passed it will read it from the ENV vars:\n\n- `CT_PROJECT_KEY`\n- `CT_API_URL`\n- `CT_AUTH_URL`\n- `CT_CLIENT_ID`\n- `CT_CLIENT_SECRET`\n- `CT_SCOPES`\n\n```ts\nconst client = CommercetoolsClient();\nclient.getProjectApi();\n```\n\nYou can also pass a callable to `auth` which returns a token to be used.\n\n```ts\nconst client = createClient({\n  host: process.env.CT_API_URL,\n  projectKey,\n  auth: async () =\u003e {\n    return 'mytoken';\n  },\n});\n\nclient.getProjectApi();\n```\n\nNote that the ApiRoot object is cached on the client instance for 900 seconds\n\n### Pass custom middleware to the Commercetools client\n\n```ts\nconst client = CommercetoolsClient({\n  host: 'https://api.europe-west1.gcp.commercetools.com/',\n  projectKey: 'my-project',\n  auth: {\n    host: 'https://auth.europe-west1.gcp.commercetools.com/',\n    credentials: {\n      clientId: 'my-client-id',\n      clientSecret: 'my-client-secret',\n    },\n    scopes: ['view_orders:my-project', 'view_products:my-project'],\n  },\n  middlewares: [yourMiddleware]\n});\n```\n\nSee the [commercetools sdk docs](https://docs.commercetools.com/sdk/js-sdk-middleware#custom-middleware) for an example of custom middleware or check the tests in `client.test.ts`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-utilities-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabd%2Fcommercetools-utilities-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-utilities-javascript/lists"}