{"id":20955110,"url":"https://github.com/myunisoft/loki","last_synced_at":"2025-05-14T04:32:58.993Z","repository":{"id":177722470,"uuid":"660795426","full_name":"MyUnisoft/loki","owner":"MyUnisoft","description":"Node.js Loki SDK","archived":false,"fork":false,"pushed_at":"2025-05-01T07:50:30.000Z","size":441,"stargazers_count":19,"open_issues_count":1,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-01T08:39:18.661Z","etag":null,"topics":["api","grafana","loki","nodejs","sdk"],"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/MyUnisoft.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-06-30T21:45:20.000Z","updated_at":"2025-05-01T07:50:26.000Z","dependencies_parsed_at":"2023-11-23T18:30:16.457Z","dependency_job_id":"480d64b0-3622-4a31-980f-1f236a7a0bf6","html_url":"https://github.com/MyUnisoft/loki","commit_stats":null,"previous_names":["myunisoft/loki"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyUnisoft%2Floki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyUnisoft%2Floki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyUnisoft%2Floki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyUnisoft%2Floki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MyUnisoft","download_url":"https://codeload.github.com/MyUnisoft/loki/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254071351,"owners_count":22009777,"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":["api","grafana","loki","nodejs","sdk"],"created_at":"2024-11-19T01:18:02.387Z","updated_at":"2025-05-14T04:32:58.986Z","avatar_url":"https://github.com/MyUnisoft.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003ch1 align=\"center\"\u003e\n  Loki\n\u003c/h1\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Node.js Grafana API SDK (Loki, Datasources ..)\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/MyUnisoft/loki\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/package-json/v/MyUnisoft/loki?style=for-the-badge\" alt=\"npm version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/MyUnisoft/loki\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/license/MyUnisoft/loki?style=for-the-badge\" alt=\"license\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://api.securityscorecards.dev/projects/github.com/MyUnisoft/loki\"\u003e\n      \u003cimg src=\"https://api.securityscorecards.dev/projects/github.com/MyUnisoft/loki/badge?style=for-the-badge\" alt=\"ossf scorecard\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/MyUnisoft/loki/actions?query=workflow%3A%22Node.js+CI%22\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/MyUnisoft/loki/node.js.yml?style=for-the-badge\" alt=\"github ci workflow\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/MyUnisoft/loki\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/languages/code-size/MyUnisoft/loki?style=for-the-badge\" alt=\"size\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## 🚧 Requirements\n\n- [Node.js](https://nodejs.org/en/) version 20 or higher\n- A [reverse-proxy](https://github.com/MyUnisoft/loki-reverse-proxy) to safely expose Loki to internet (if required).\n\n## 🚀 Getting Started\n\nThis package is available in the Node Package Repository and can be easily installed with [npm](https://doc.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com)\n\n```bash\n$ npm i @myunisoft/loki\n# or\n$ yarn add @myunisoft/loki\n```\n\n## 📚 Usage\n\n```ts\nimport { GrafanaApi } from \"@myunisoft/loki\";\nimport { LogQL, StreamSelector } from \"@sigyn/logql\";\n\nconst api = new GrafanaApi({\n  authentication: {\n    type: \"bearer\",\n    token: process.env.GRAFANA_API_TOKEN!\n  },\n  remoteApiURL: \"https://name.loki.com\"\n});\n\nconst ql = new LogQL(\n  new StreamSelector({ app: \"serviceName\", env: \"production\" })\n);\nconst logs = await api.Loki.queryRange(\n  ql, // or string `{app=\"serviceName\", env=\"production\"}`\n  {\n    start: \"1d\",\n    limit: 200\n  }\n);\nconsole.log(logs);\n```\n\nYou can also provide a Loki pattern to automatically parse logs (and infer the right type with TypeScript)\n\n```ts\nconst logs = await api.Loki.queryRange(\n  `{app=\"serviceName\", env=\"production\"}`\n  {\n    pattern: \"\u003cverb\u003e \u003c_\u003e \u003cendpoint\u003e\"\n  }\n);\nfor (const { verb, endpoint } of logs) {\n  console.log({verb, endpoint });\n}\n```\n\n## API\n\n### GrafanaAPI\n\n```ts\ninterface GrafanaApiOptions {\n  /**\n   * If omitted then no authorization is dispatched to requests\n   */\n  authentication?: ApiCredentialAuthorizationOptions;\n  /**\n   * User-agent HTTP header to forward to Grafana/Loki API\n   * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agents\n   */\n  userAgent?: string;\n  /**\n   * Remote Grafana root API URL\n   */\n  remoteApiURL: string | URL;\n}\n\ntype ApiCredentialAuthorizationOptions = {\n  type: \"bearer\";\n  token: string;\n} | {\n  type: \"classic\";\n  username: string;\n  password: string;\n} | {\n  type: \"custom\";\n  authorization: string;\n};\n```\n\n### Sub-class\n\n- [Loki](./docs/Loki.md)\n- [Datasources](./docs/Datasources.md)\n\n## Contributors ✨\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/fraxken\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4438263?v=4?s=100\" width=\"100px;\" alt=\"Thomas.G\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eThomas.G\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/MyUnisoft/loki/commits?author=fraxken\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#security-fraxken\" title=\"Security\"\u003e🛡️\u003c/a\u003e \u003ca href=\"https://github.com/MyUnisoft/loki/commits?author=fraxken\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/PierreDemailly\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/39910767?v=4?s=100\" width=\"100px;\" alt=\"PierreDemailly\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePierreDemailly\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/MyUnisoft/loki/commits?author=PierreDemailly\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/MyUnisoft/loki/commits?author=PierreDemailly\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/MyUnisoft/loki/commits?author=PierreDemailly\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyunisoft%2Floki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyunisoft%2Floki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyunisoft%2Floki/lists"}