{"id":21589663,"url":"https://github.com/axtk/yd-sdk","last_synced_at":"2025-04-10T21:55:32.867Z","repository":{"id":263000991,"uuid":"889000195","full_name":"axtk/yd-sdk","owner":"axtk","description":"Typed isomorphic Yandex Disk SDK","archived":false,"fork":false,"pushed_at":"2024-12-31T18:10:00.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T21:55:21.860Z","etag":null,"topics":["sdk","yandex-api","yandex-disk","yandex-disk-sdk"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/yd-sdk","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/axtk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-15T12:16:19.000Z","updated_at":"2025-02-19T14:13:32.000Z","dependencies_parsed_at":"2024-11-15T14:42:35.890Z","dependency_job_id":null,"html_url":"https://github.com/axtk/yd-sdk","commit_stats":null,"previous_names":["axtk/yd-sdk"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fyd-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fyd-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fyd-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fyd-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axtk","download_url":"https://codeload.github.com/axtk/yd-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248305844,"owners_count":21081574,"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":["sdk","yandex-api","yandex-disk","yandex-disk-sdk"],"created_at":"2024-11-24T16:15:24.904Z","updated_at":"2025-04-10T21:55:32.855Z","avatar_url":"https://github.com/axtk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yd-sdk\n\nTyped isomorphic Yandex Disk SDK\n\nInstallation: `npm i yd-sdk`\n\n## Initialization\n\n```ts\nimport {sdk} from 'yd-sdk';\n\nlet api = sdk();\n```\n\nor with an OAuth token required to access non-public resources:\n\n```ts\nlet api = sdk({\n    token: 'xxx',\n});\n```\n\nor with a custom setup:\n\n```ts\nlet api = sdk({\n    token: 'xxx',\n    endpoint: '/yd-api',\n    headers: {\n        'x-csrf-token': 'xxx',\n    },\n});\n```\n\n## API call examples\n\n```ts\nlet {status, body: storageInfo} = await api.storage.info();\n```\n\n```ts\nlet {status, body} = await api.info({path: '/', limit: 10});\n```\n\nAll successful API calls resolve with an object containing `status` reflecting the HTTP status code (along with a corresponding `statusText`) and `body` holding the data returned from the API.\n\n## Error handling\n\nWhenever an SDK method encounters an API error, the method throws an instance of `RequestError`.\n\n```ts\nimport {RequestError} from 'yd-sdk';\n\ntry {\n    let {body: dirInfo} = await api.info({path: '/x'});\n\n    // use the successfully retrieved resource data\n}\ncatch (error) {\n    if (error instanceof RequestError \u0026\u0026 error.status === 404) {\n        // handle the missing resource error\n    }\n}\n```\n\nThe API error object is supplied with a `status` value reflecting the HTTP status code and `data` of type `YDError` containing the error description provided by the API.\n\n## List of available methods\n\n```\nMethod                 Brief description\n\napi.public.info()      Get a public resource metadata\napi.public.list()      List public resources\napi.public.download()  Get a public resource download link\napi.public.save()      Copy a public resource to the Downloads directory\n\napi.storage.info()     Get the storage info\n\napi.info()             Get a resource metadata + nested files for directories\napi.list()             Get a flat file list + filter by media type\napi.recent()           Get most recently uploaded files\napi.create()           Create a directory\napi.copy()             Copy a resource\napi.move()             Move a resource\napi.remove()           Remove a resource\napi.publish()          Open public access to a resource\napi.unpublish()        Close public access to a resource\napi.upload()           Request a file upload link\napi.uploadFromURL()    Upload a file from a given link\napi.download()         Get a resource download link\napi.update()           Update custom properties of a resource\napi.operation()        Get the status of an operation\n\napi.trash.clear()      Clear Trash or permanently delete a resource\napi.trash.restore()    Restore from Trash\n```\n\nThe method parameters are the query parameters of the corresponding [API methods](https://yandex.com/dev/disk-api/doc/en/). The only exception is the `api.update()` method requiring `{query, body}` as the parameter.\n\n## Types\n\nThe type namespaces `YDIn`, `YDOut` and `YDResponse` contain the types of the SDK methods. The types within these namespaces are named after the methods:\n\n```ts\nimport type {YDIn} from 'yd-sdk';\n\nlet params: YDIn.Public.Info = {\n    path: '/',\n    limit: 10,\n};\n\nlet {status, body} = await api.public.info(params);\n// `body` is of type `YDOut.Public.Info`\n// the entire response is of type `YDResponse.Public.Info`\n```\n\n## Utilities\n\n### `isOperationLink()`, `getOperationId()`\n\nSome API methods (and the corresponding SDK methods, like `.copy()` or `.move()`) return either a `Link` object pointing to the processed resource or an `OperationLink` object with a link to an operation in progress. The utility functions `isOperationLink()` and `getOperationId()` help handle API responses of these types.\n\n```ts\nimport {isOperationLink, getOperationId} from 'yd-sdk';\n\nlet {body: result} = await api.move({from: '/x', path: '/y'});\n\nif (isOperationLink(result)) {\n    let operationId = getOperationId(result);\n\n    // track the operation status with\n    // `await api.operation({id: operationId})`\n}\nelse {\n    // use the processed resource `Link` object\n}\n```\n\n## See also\n\n\u0026rarr; [*Yandex Disk API Docs*](https://yandex.com/dev/disk-api/doc/en/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fyd-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxtk%2Fyd-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fyd-sdk/lists"}