🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@myunisoft/loki

Package Overview
Dependencies
Maintainers
11
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@myunisoft/loki

Node.js Grafana Loki SDK

latest
npmnpm
Version
6.1.0
Version published
Maintainers
11
Created
Source

Loki

Node.js Grafana API SDK (Loki, Datasources ..)

npm version license ossf scorecard github ci workflow size

🚧 Requirements

  • Node.js version 20 or higher
  • A reverse-proxy to safely expose Loki to internet (if required).

šŸš€ Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn

$ npm i @myunisoft/loki
# or
$ yarn add @myunisoft/loki

šŸ“š Usage

import { GrafanaApi } from "@myunisoft/loki";
import { LogQL, StreamSelector } from "@sigyn/logql";

const api = new GrafanaApi({
  authentication: {
    type: "bearer",
    token: process.env.GRAFANA_API_TOKEN!
  },
  remoteApiURL: "https://name.loki.com"
});

const ql = new LogQL(
  new StreamSelector({ app: "serviceName", env: "production" })
);
const logs = await api.Loki.queryRange(
  ql, // or string `{app="serviceName", env="production"}`
  {
    start: "1d",
    limit: 200
  }
);
console.log(logs);

You can also provide a Loki pattern to automatically parse logs (and infer the right type with TypeScript)

const logs = await api.Loki.queryRange(
  `{app="serviceName", env="production"}`
  {
    pattern: "<verb> <_> <endpoint>"
  }
);
for (const { verb, endpoint } of logs) {
  console.log({verb, endpoint });
}

API

GrafanaAPI

interface GrafanaApiOptions {
  /**
   * If omitted then no authorization is dispatched to requests
   */
  authentication?: ApiCredentialAuthorizationOptions;
  /**
   * User-agent HTTP header to forward to Grafana/Loki API
   * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agents
   */
  userAgent?: string;
  /**
   * Remote Grafana root API URL
   */
  remoteApiURL: string | URL;
}

type ApiCredentialAuthorizationOptions = {
  type: "bearer";
  token: string;
} | {
  type: "classic";
  username: string;
  password: string;
} | {
  type: "custom";
  authorization: string;
};

Sub-class

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Thomas.G
Thomas.G

šŸ’» šŸ›”ļø šŸ“–
PierreDemailly
PierreDemailly

šŸ’» āš ļø šŸ“–

License

MIT

Keywords

grafana

FAQs

Package last updated on 15 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts