{"id":24755151,"url":"https://github.com/gravity-ui/sdk","last_synced_at":"2025-10-11T01:31:31.231Z","repository":{"id":190013450,"uuid":"681343947","full_name":"gravity-ui/sdk","owner":"gravity-ui","description":"SDK implementing work with REST/GRPC APIs","archived":false,"fork":false,"pushed_at":"2024-10-04T16:23:46.000Z","size":394,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T18:02:08.688Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/gravity-ui.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2023-08-21T20:04:51.000Z","updated_at":"2024-10-22T09:15:06.000Z","dependencies_parsed_at":"2024-07-16T18:41:13.074Z","dependency_job_id":"2be7c3f6-e3f2-47f4-9e46-26a493e253c2","html_url":"https://github.com/gravity-ui/sdk","commit_stats":null,"previous_names":["gravity-ui/sdk"],"tags_count":8,"template":false,"template_full_name":"gravity-ui/package-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Fsdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Fsdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Fsdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Fsdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gravity-ui","download_url":"https://codeload.github.com/gravity-ui/sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236017801,"owners_count":19081980,"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":"2025-01-28T12:36:35.505Z","updated_at":"2025-10-11T01:31:25.922Z","avatar_url":"https://github.com/gravity-ui.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @gravity-ui/sdk \u0026middot; [![npm package](https://img.shields.io/npm/v/@gravity-ui/sdk)](https://www.npmjs.com/package/@gravity-ui/sdk) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/sdk/.github/workflows/ci.yml?label=CI\u0026logo=github)](https://github.com/gravity-ui/sdk/actions/workflows/ci.yml?query=branch:main)\n\nSDK implementing work with REST/GRPC APIs\n\n## Install\n\n```shell\nnpm install --save-dev @gravity-ui/sdk\n```\n\n## Usage\n\nYou need to import `sdkFactory` and `Schema`, and create an instance of the class.\n\nIf the schema is not divided into scopes:\n\n```typescript\nimport sdkFactory from '@gravity-ui/sdk';\nimport type Schema from '\u003cschemas package\u003e';\n\nconst config = {\n  csrfToken: 'secret-token',\n  endpoint: '/gateway',\n};\n\nconst sdk = sdkFactory\u003c{root: typeof Schema}\u003e(config);\n```\n\nIf the schema is divided into scopes:\n\n```typescript\nimport sdkFactory from '@gravity-ui/sdk';\nimport type Schema from '\u003cschemas package\u003e';\nimport type LocalSchema from '../../shared/schemas';\n\nconst config = {\n  csrfToken: 'secret-token',\n  endpoint: '/gateway',\n};\n\nconst sdk = sdkFactory\u003c{root: typeof Schema; local: typeof LocalSchema}\u003e(config);\n```\n\nStructure of `config`:\n\n```typescript\nimport {AxiosRequestConfig} from 'axios';\n\ninterface SdkConfig {\n  // Custom Axios settings\n  axiosConfig?: AxiosRequestConfig;\n  // CSRF-token\n  csrfToken?: string;\n  // The endpoint to which the request from the client will be sent. By default, \"/api\" is used\n  endpoint?: string;\n  // Custom error handler. If the configuration is not specified, the default one is used\n  handleRequestError?: (error: unknown) =\u003e any;\n}\n```\n\nIn the code, the invocation of the SDK method looks like this:\n\n```javascript\nsdk.\u003cscope\u003e.\u003cservice\u003e.\u003caction\u003e(data, options); // =\u003e returns a CancelablePromise\n```\n\nIf the default endpoint value `/api` is specified, the full request path will look like this:\n\n`/api/:scope/:service/:action`\n\nThere is a special scope called `root`. Its methods can be called without explicitly specifying the scope.\n\nThe following calls are equivalent:\n\n`sdk.root.\u003cservice\u003e.\u003caction\u003e(data, options);`\n\n`sdk.\u003cservice\u003e.\u003caction\u003e(data, options);`\n\nBut the full request path will always include the scope:\n\n`/api/root/:service/:action`\n\nStructure of `options`:\n\n```typescript\ninterface SdkOptions {\n  // Request identifier. The previous request with the same identifier will be canceled\n  concurrentId?: string;\n  // Ability to specify a specific number of retries for certain endpoints. By default, the number of retries is 0\n  retries?: number;\n  // Ability to specify a specific timeout for certain endpoints.\n  // By default, the configuration is taken from axiosConfig or set to 60 seconds\n  timeout?: number;\n  // Ability to specify specific headers when making a call\n  headers?: Record\u003cstring, unknown\u003e;\n}\n```\n\n## Invoking External Methods\n\nThrough the `sdk`, you have the ability to make calls to external methods that are not defined in the schemas. Such a call looks like this:\n\n`sdk(config, options);`\n\nThe argument `config` has the type `AxiosRequestConfig`, and the argument options has the type `SdkOptions` described above.\n\n## CancellablePromise\n\nFor the convenience of creating cancelable promises, the package exports a class called `CancellablePromise(promise: Promise, cancel: () =\u003e void)`.\n\n## Additional methods\n\n### sdk.setLang()\n\nAllows setting the user's language, which will be passed to all invoked endpoints through a special `accept-language` header.\n\n### sdk.setDefaultHeader()\n\nAllows setting base headers that will be passed to all invoked endpoints.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-ui%2Fsdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgravity-ui%2Fsdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-ui%2Fsdk/lists"}