{"_id":"@booksakura/backlog-client-ts","_rev":"1-58beba929a7d302658601e6238404f33","name":"@booksakura/backlog-client-ts","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.1":{"name":"@booksakura/backlog-client-ts","version":"0.1.1","keywords":["backlog","api"],"author":{"name":"sawamura"},"license":"MIT","_id":"@booksakura/backlog-client-ts@0.1.1","maintainers":[{"name":"sawamura","email":"yzf.r6.08.liquid.silver+npm@gmail.com"}],"homepage":"https://gitlab.com/booksakura/backlog-client-ts","bugs":{"url":"https://gitlab.com/booksakura/backlog-client-ts/-/issues"},"dist":{"shasum":"b38b6b73c5e5aabb126b1de603e6f92593cf8a72","tarball":"https://registry.npmjs.org/@booksakura/backlog-client-ts/-/backlog-client-ts-0.1.1.tgz","fileCount":1729,"integrity":"sha512-xuDeTC6/UF9E3Pdhjq8zQGAMEbNyoMMHEY8Vw5MJxiRM5AIi05sbSICMkbgJ5QMhCEnSJREacRpF4TuMa+IDsQ==","signatures":[{"sig":"MEQCIHqByIPjttWgiYXgE1bgZh8MHcfy+rg63lGMF/HcUK6BAiAzYvSdNEerVZt9DuNkgatQxvRtfoL9RoPzCXiefNUvAg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1828011},"main":"dist/cjs/index.js","types":"./dist/cjs/index.d.ts","module":"dist/esm/index.js","exports":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"private":false,"scripts":{"test":"vitest --config ./vitest/vitest.config.ts","build":"npm run clean && npm run build:cjs && npm run build:esm && npm run build:umd","clean":"command rm -rf dist","ts-node":"npx ts-node --require tsconfig-paths/register --project tsconfig.cjs.json","version":"bash ./build/version.sh","build:cjs":"npx tsc --project tsconfig.cjs.json","build:esm":"npx tsc --project tsconfig.esm.json","build:umd":"npx webpack --mode production --config webpack.config.js && npx webpack --mode development --config webpack.config.js","test:spec":"vitest --config ./vitest/spec.vitest.config.ts","build:docs":"npx typedoc --tsconfig tsconfig.cjs.json --out docs src/index.ts"},"_npmUser":{"name":"sawamura","email":"yzf.r6.08.liquid.silver+npm@gmail.com"},"repository":{"url":"git+https://gitlab.com/booksakura/backlog-client-ts.git","type":"git"},"_npmVersion":"10.8.2","description":"Backlog Client TS is a JavaScript (TypeScript) client library for using the Backlog API v2","directories":{},"sideEffects":false,"_nodeVersion":"20.16.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.3","ts-node":"^10.9.2","typedoc":"^0.26.5","webpack":"^5.93.0","ts-loader":"^9.5.1","typescript":"^5.5.3","@types/node":"^20.14.10","webpack-cli":"^5.1.4","@biomejs/biome":"^1.8.3","tsconfig-paths":"^4.2.0"},"_npmOperationalInternal":{"tmp":"tmp/backlog-client-ts_0.1.1_1722530201799_0.2783741788524514","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@booksakura/backlog-client-ts","description":"Backlog Client TS is a JavaScript (TypeScript) client library for using the Backlog API v2","version":"0.2.0","author":{"name":"sawamura"},"main":"dist/cjs/index.js","module":"dist/esm/index.js","exports":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"devDependencies":{"@biomejs/biome":"^1.8.3","@types/node":"^20.14.10","ts-loader":"^9.5.1","ts-node":"^10.9.2","tsconfig-paths":"^4.2.0","typedoc":"^0.26.5","typescript":"^5.5.3","vitest":"^2.0.3","webpack":"^5.93.0","webpack-cli":"^5.1.4"},"scripts":{"clean":"command rm -rf dist","build":"npm run clean && npm run build:generate-code && npm run build:cjs && npm run build:esm && npm run build:umd","build:cjs":"npx tsc --project tsconfig.cjs.json","build:esm":"npx tsc --project tsconfig.esm.json","build:umd":"npx webpack --mode production --config webpack.config.js && npx webpack --mode development --config webpack.config.js","build:docs":"npx typedoc --tsconfig tsconfig.cjs.json --out docs src/index.ts","build:generate-code":"npm run ts-node ./code_generator/generate.ts","update:api-docs":"npm run ts-node ./code_generator/generate_api_docs.ts","test":"vitest --config ./vitest/vitest.config.ts","test:spec":"vitest --config ./vitest/spec.vitest.config.ts","ts-node":"npx ts-node --require tsconfig-paths/register --project tsconfig.cjs.json","version":"bash ./build/version.sh"},"keywords":["backlog","api"],"license":"MIT","homepage":"https://gitlab.com/booksakura/backlog-client-ts","bugs":{"url":"https://gitlab.com/booksakura/backlog-client-ts/-/issues"},"repository":{"type":"git","url":"git+https://gitlab.com/booksakura/backlog-client-ts.git"},"private":false,"sideEffects":false,"_id":"@booksakura/backlog-client-ts@0.2.0","types":"./dist/cjs/index.d.ts","_nodeVersion":"20.16.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-mMjTbyRY/yxj96dkUxQNpzEfV0USSj49e746F3ff6ugBb8OPXSOdiOEmrOOcBoA4ypKoPt4xIeOq7U4+QSqFmg==","shasum":"95f747342716e41ee62b66f00573834346c5fd98","tarball":"https://registry.npmjs.org/@booksakura/backlog-client-ts/-/backlog-client-ts-0.2.0.tgz","fileCount":1957,"unpackedSize":3341874,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCf++sDEHM9F/r0f4dM31wLx6B+XS1SG3MnAgjiWPFccAIhAN4MxCc+j4xAQxAgvDa0mziD/ZrKnhVcbEHJUwLU6RLA"}]},"_npmUser":{"name":"sawamura","email":"yzf.r6.08.liquid.silver+npm@gmail.com"},"directories":{},"maintainers":[{"name":"sawamura","email":"yzf.r6.08.liquid.silver+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/backlog-client-ts_0.2.0_1723139309435_0.1613588272537998"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-01T16:36:41.699Z","modified":"2024-08-08T17:48:29.972Z","0.1.1":"2024-08-01T16:36:42.250Z","0.2.0":"2024-08-08T17:48:29.758Z"},"bugs":{"url":"https://gitlab.com/booksakura/backlog-client-ts/-/issues"},"author":{"name":"sawamura"},"license":"MIT","homepage":"https://gitlab.com/booksakura/backlog-client-ts","keywords":["backlog","api"],"repository":{"type":"git","url":"git+https://gitlab.com/booksakura/backlog-client-ts.git"},"description":"Backlog Client TS is a JavaScript (TypeScript) client library for using the Backlog API v2","maintainers":[{"name":"sawamura","email":"yzf.r6.08.liquid.silver+npm@gmail.com"}],"readme":"# Backlog Client TS\n\n[GitLab repository](https://gitlab.com/booksakura/backlog-client-ts)\n\n## What is Backlog Client TS?\n\nBacklog Client TS is a JavaScript (TypeScript) client library for using the Backlog API v2 (https://developer.nulab.com/ja/docs/backlog). \n\nThis library allows you to easily interact with the Backlog API v2.\n\n## Documentation\n\n* [API Docs](https://booksakura.gitlab.io/backlog-client-ts/)\n\n## Installation\n\n### JSR\n\nInstall using the [JSR](https://jsr.io/@booksakura/backlog-client-ts) package manager:\n\n```bash\n# npm\nnpx jsr add @booksakura/backlog-client-ts\n# deno\ndeno add @booksakura/backlog-client-ts\n# bun\nbunx jsr add @booksakura/backlog-client-ts\n```\n\n### NPM\n\nInstall using the [npm](https://www.npmjs.com/package/@booksakura/backlog-client-ts) package manager:\n\n```bash\nnpm install --save @booksakura/backlog-client-ts\n```\n\n### Browser\n\n#### CDN\n\n```html\n<!-- UNPKG -->\n<script src=\"https://unpkg.com/@booksakura/backlog-client-ts/dist/umd/backlog-client-ts.min.js\"></script>\n<!-- jsDelivr -->\n<script src=\"https://cdn.jsdelivr.net/npm/@booksakura/backlog-client-ts/dist/umd/backlog-client-ts.min.js\"></script>\n```\n\n#### Manual Build\n\n```bash\n# UMD build\ncd backlog-client-ts/source\nnpm run build:umd\n```\n\nAfter building, include the script in your HTML:\n\n```html\n<script src=\"path/to/dist/umd/backlog-client-ts.min.js\"></script>\n```\n\n## Usage\n\n### Node.js\n\nLoad the library as follows:\n\n```js\nconst backlogclient = require(\"@booksakura/backlog-client-ts\");\n\n// or \nconst { BacklogConfig, BacklogApiClient } = require(\"@booksakura/backlog-client-ts\");\n```\n\nOr in TypeScript:\n\n```ts\nimport * as backlogclient from \"@booksakura/backlog-client-ts\";\n\n// or\nimport {BacklogConfig, BacklogApiClient} from \"@booksakura/backlog-client-ts\";\n```\n\n#### Client Configuration and Usage Example\n\n```js\nconst config = new backlogclient.BacklogConfig({\n  host: \"****.backlog.com\", // ****.backlog.com or ****.backlog.jp or 'your enterprise host'\n  apiKey: \"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\", // API key\n});\n\nconst client = new backlogclient.BacklogApiClient({\n  config: config\n});\n\n// get space (callback style)\nclient.getSpace().then(data => {\n  const space = data.data();\n  console.log('success:', space);\n}).catch((err) => {\n  console.log('error:', err.message);\n});\n\n// get project list \nasync function fetchProjects() {\n  try {\n    const project_list = await client.getProjectList();\n    project_list.data().forEach((project, _) => {\n      console.log('success:', project);\n    });\n  } catch (error) {\n    console.log('error:', error.message);\n  }\n}\n\nfetchProjects();\n```\n\n#### Functional Style Usage Example\n\n```js\nconst { BacklogConfig, getSpace } = require(\"@booksakura/backlog-client-ts\");\n\nconst config = new BacklogConfig({\n  host: \"****.backlog.com\",\n  apiKey: \"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n});\n\nasync function fetchSpace() {\n  const space = await getSpace(config);\n  console.log(space.data());\n}\n\nfetchSpace();\n```\n\n### Browser\n\nAfter loading the UMD build in your HTML, use it as follows:\n\n```js\nconst config = new BacklogClientTs.BacklogConfig({\n  host: \"****.backlog.com\",\n  apiKey: \"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n});\n\nconst client = new BacklogClientTs.BacklogApiClient({\n  config: config\n});\n\nasync function fetchSpace() {\n  const space = await client.getSpace();\n  console.log(space.data());\n}\n\nfetchSpace();\n```\n\n\n## Example\n\n### Download File\n\n```js\n// Node.js\nconst { BacklogConfig, getSpaceLogo } = require(\"@booksakura/backlog-client-ts\");\nconst fs = require(\"node:fs\");\n\nconst date = (await getSpaceLogo(config)).data();\nconst buffer = Buffer.from(await date.arrayBuffer());\n\nfs.writeFileSync(\"spacelogo.png\", buffer);\n\n// browser\nconst date = (await client.getSpaceLogo()).data();\nconst blob = await date.blob();\n\nconst object_url = URL.createObjectURL(blob);\nconst element = window.document.querySelector(\"#logo\");\nelement.src = object_url;\n```\n\n### Uoload File\n\n```js\n// Node.js\nconst { BacklogConfig, postAttachmentFile } = require(\"@booksakura/backlog-client-ts\");\nconst fs = require(\"node:fs\");\nconst { Blob } = require(\"node:buffer\");\n\nconst buffer = fs.readFileSync(\"logo.png\");\nconst blob = new Blob([buffer]);\n\nconst date = (\n  await postAttachmentFile(config, {\n    contents: blob,\n    filename: \"logo.png\",\n  })\n).data();\nconsole.log(date); // { id: 1234567890, name: 'logo.png', size: 12345 }\n\n// text file\nconst contents = \"AttachmentFile Sample Text\";\nconst date = (\n  await postAttachmentFile(config, {\n    contents: contents,\n    filename: \"sample.txt\",\n  })\n).data();\nconsole.log(date); // { id: 1234567890, name: 'sample.txt', size: 26 }\n\n// browser\n// <input type=\"file\" id=\"upload_file\" >\nconst element = window.document.querySelector(\"#upload_file\");\nconst file = element.files[0];\n\nconst date = (\n  await client.postAttachmentFile({\n    contents: file,\n    // filename omitted, file.name is used.\n  })\n).data();\nconsole.log(date); // { id: 1234567890, name: 'abc.png', size: 12345 }\n```\n\n### Aborting Requests\n\n```js\ntry {\n  const space = await getSpace(config, {\n    requestOptions: {\n      signal: AbortSignal.timeout(1000 * 5), // timeout 5 sec.\n    },\n  });\n  console.log(space.data());\n} catch (error) {\n  if (error instanceof BacklogApiAbortError) {\n    console.log(\"timeout\", error);\n  }\n}\n```\n\n### Get Response Header\n\n```js\nconst space = await getSpace(config);\n\nconst response = space.getResponse();\n// Get Response Header\nconsole.log(response.getHeader(\"date\"));\n// Rate Limit\nconsole.log(response.getRateLimitLimit());\nconsole.log(response.getRateLimitRemaining());\nconsole.log(response.getRateLimitReset());\n\n```\n\n### Using Metadata\n\nTo use metadata, you need to call `loadBacklogMetadata()` beforehand.\n\nNote that if you use `BacklogApiClient`, `loadBacklogMetadata()` is implicitly called.\n\n```js\nconst { loadBacklogMetadata, getSpace } = require(\"@booksakura/backlog-client-ts\");\n\n// Call once at the beginning\nloadBacklogMetadata();\n\nconst space = await getSpace(config);\n\n// Get API specifications\nconst spec = space.getSpec();\nconsole.log(spec.info);\n\n// Validate response data\nconst validator = space.validator();\nconst validation_result = await validator.validate();\nconsole.log(validation_result.isValid);\nconsole.log(validation_result.errors);\n```\n\n### Custom Fetch\n\n```js\nconst { BacklogConfig, getOwnUser, utils: { bindBacklogContainer, resolveBacklogContainer } } = require(\"@booksakura/backlog-client-ts\");\n\nclass CustomFetcher {\n    /**\n     * @param {URL} url\n     * @param {object} options\n     * @returns {Promise<BacklogHttpResponse>}\n     */\n    async fetch(url, options) {\n        console.log(\"srat-log\", url, options);\n        const fetch_response = await fetch(url, options);\n        const response = resolveBacklogContainer(\"BacklogHttpResponse\", {\n            response: fetch_response,\n        });\n        return response;\n    }\n}\nbindBacklogContainer(\"BacklogHttpFetcher\", CustomFetcher);\n\nasync function fetchUserData() {\n    const config = new BacklogConfig(\n        {\n          host: \"****.backlog.com\",\n          apiKey: \"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n        }\n    );\n    const date = (await getOwnUser(config)).data();\n    console.log(date);\n}\n\nfetchUserData();\n```\n\n## TODO\n\n- [ ] add Unit Tests\n- [ ] OAuth 2.0 Support\n","readmeFilename":"README.md"}