jpdcl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +15 -0
- package/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/catalog.d.ts +141 -0
- package/dist/catalog.js +261 -0
- package/dist/catalog.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +395 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +13 -0
- package/dist/credentials.js +100 -0
- package/dist/credentials.js.map +1 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +21 -0
- package/dist/crypto.js.map +1 -0
- package/dist/dates.d.ts +5 -0
- package/dist/dates.js +20 -0
- package/dist/dates.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/http-handler.d.ts +1 -0
- package/dist/http-handler.js +46 -0
- package/dist/http-handler.js.map +1 -0
- package/dist/http.d.ts +9 -0
- package/dist/http.js +43 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +2 -0
- package/dist/launcher.js +11 -0
- package/dist/launcher.js.map +1 -0
- package/dist/ledger-client.d.ts +112 -0
- package/dist/ledger-client.js +221 -0
- package/dist/ledger-client.js.map +1 -0
- package/dist/main-client.d.ts +25 -0
- package/dist/main-client.js +221 -0
- package/dist/main-client.js.map +1 -0
- package/dist/mcp-stdio.d.ts +2 -0
- package/dist/mcp-stdio.js +6 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/mcp.d.ts +8 -0
- package/dist/mcp.js +517 -0
- package/dist/mcp.js.map +1 -0
- package/dist/runtime.d.ts +27 -0
- package/dist/runtime.js +316 -0
- package/dist/runtime.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +221 -0
- package/dist/server.js.map +1 -0
- package/dist/session.d.ts +4 -0
- package/dist/session.js +30 -0
- package/dist/session.js.map +1 -0
- package/dist/smart-client.d.ts +50 -0
- package/dist/smart-client.js +238 -0
- package/dist/smart-client.js.map +1 -0
- package/dist/tariff.d.ts +121 -0
- package/dist/tariff.js +124 -0
- package/dist/tariff.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker.d.ts +5 -0
- package/dist/worker.js +3 -0
- package/dist/worker.js.map +1 -0
- package/openapi.yaml +284 -0
- package/package.json +89 -0
- package/scripts/audit-http.ts +36 -0
- package/scripts/audit-launcher.mjs +28 -0
- package/scripts/audit-ledger-portal.ts +23 -0
- package/scripts/audit-mcp.mjs +140 -0
- package/scripts/audit-smart-portal.mjs +63 -0
- package/scripts/build.mjs +19 -0
- package/scripts/publish-smithery.mjs +47 -0
- package/src/catalog.ts +291 -0
- package/src/cli.ts +397 -0
- package/src/config.ts +15 -0
- package/src/credentials.ts +114 -0
- package/src/crypto.ts +21 -0
- package/src/dates.ts +19 -0
- package/src/errors.ts +26 -0
- package/src/http-handler.ts +48 -0
- package/src/http.ts +49 -0
- package/src/index.ts +13 -0
- package/src/launcher.ts +9 -0
- package/src/ledger-client.ts +258 -0
- package/src/main-client.ts +230 -0
- package/src/mcp-stdio.ts +6 -0
- package/src/mcp.ts +546 -0
- package/src/runtime.ts +329 -0
- package/src/server.ts +218 -0
- package/src/session.ts +29 -0
- package/src/smart-client.ts +249 -0
- package/src/tariff.ts +148 -0
- package/src/toolkit.test.ts +136 -0
- package/src/types.ts +51 -0
- package/src/worker.ts +3 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +16 -0
package/dist/dates.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JpdclError } from "./errors.js";
|
|
2
|
+
export function isIsoDate(value) {
|
|
3
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
4
|
+
return false;
|
|
5
|
+
const timestamp = Date.parse(`${value}T00:00:00Z`);
|
|
6
|
+
return Number.isFinite(timestamp) && new Date(timestamp).toISOString().slice(0, 10) === value;
|
|
7
|
+
}
|
|
8
|
+
export function assertDateRange(from, to, options = {}) {
|
|
9
|
+
if (from && !isIsoDate(from))
|
|
10
|
+
throw new JpdclError("from must be a real date in YYYY-MM-DD format", 400);
|
|
11
|
+
if (to && !isIsoDate(to))
|
|
12
|
+
throw new JpdclError("to must be a real date in YYYY-MM-DD format", 400);
|
|
13
|
+
if (options.requireBoth && (!from || !to))
|
|
14
|
+
throw new JpdclError("Both from and to dates are required", 400);
|
|
15
|
+
if (options.pairedWhenPresent && Boolean(from) !== Boolean(to))
|
|
16
|
+
throw new JpdclError("Supply both from and to dates, or neither", 400);
|
|
17
|
+
if (from && to && from > to)
|
|
18
|
+
throw new JpdclError("from must be on or before to", 400);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,EAAW,EACX,UAAkE,EAAE;IAEpE,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,+CAA+C,EAAE,GAAG,CAAC,CAAC;IACzG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,6CAA6C,EAAE,GAAG,CAAC,CAAC;IACnG,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;IAC5G,IAAI,OAAO,CAAC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;IACvI,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,GAAG,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;AACzF,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class JpdclError extends Error {
|
|
2
|
+
readonly status?: number | undefined;
|
|
3
|
+
readonly details?: unknown | undefined;
|
|
4
|
+
constructor(message: string, status?: number | undefined, details?: unknown | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthenticationError extends JpdclError {
|
|
7
|
+
constructor(message?: string, details?: unknown);
|
|
8
|
+
}
|
|
9
|
+
export declare class MutationDisabledError extends JpdclError {
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class JpdclError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
details;
|
|
4
|
+
constructor(message, status, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.name = "JpdclError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class AuthenticationError extends JpdclError {
|
|
12
|
+
constructor(message = "JPDCL authentication is required", details) {
|
|
13
|
+
super(message, 401, details);
|
|
14
|
+
this.name = "AuthenticationError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class MutationDisabledError extends JpdclError {
|
|
18
|
+
constructor() {
|
|
19
|
+
super("Mutating JPDCL operations are disabled. Set JPDCL_ENABLE_MUTATIONS=true to enable them.", 403);
|
|
20
|
+
this.name = "MutationDisabledError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGjB;IACA;IAHlB,YACE,OAAe,EACC,MAAe,EACf,OAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAU;QAGjC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AACD,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,OAAO,GAAG,kCAAkC,EAAE,OAAiB;QACzE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD;QACE,KAAK,CACH,yFAAyF,EACzF,GAAG,CACJ,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleMcpRequest(request: Request): Promise<Response>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
2
|
+
import { createJpdclMcpServer } from "./mcp.js";
|
|
3
|
+
import { JpdclRuntime } from "./runtime.js";
|
|
4
|
+
const corsHeaders = {
|
|
5
|
+
"Access-Control-Allow-Origin": "*",
|
|
6
|
+
"Access-Control-Allow-Methods": "GET, POST, DELETE, OPTIONS",
|
|
7
|
+
"Access-Control-Allow-Headers": "Content-Type, Accept, mcp-protocol-version, mcp-session-id, last-event-id, x-jpdcl-login-id, x-jpdcl-password",
|
|
8
|
+
"Access-Control-Expose-Headers": "mcp-protocol-version, mcp-session-id",
|
|
9
|
+
};
|
|
10
|
+
function withCors(response) {
|
|
11
|
+
const headers = new Headers(response.headers);
|
|
12
|
+
for (const [name, value] of Object.entries(corsHeaders))
|
|
13
|
+
headers.set(name, value);
|
|
14
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
15
|
+
}
|
|
16
|
+
export async function handleMcpRequest(request) {
|
|
17
|
+
if (request.method === "OPTIONS")
|
|
18
|
+
return new Response(null, { status: 204, headers: corsHeaders });
|
|
19
|
+
const loginId = request.headers.get("x-jpdcl-login-id")?.trim();
|
|
20
|
+
const password = request.headers.get("x-jpdcl-password")?.trim();
|
|
21
|
+
if (Boolean(loginId) !== Boolean(password)) {
|
|
22
|
+
return withCors(Response.json({
|
|
23
|
+
jsonrpc: "2.0",
|
|
24
|
+
error: { code: -32602, message: "Both x-jpdcl-login-id and x-jpdcl-password are required" },
|
|
25
|
+
id: null,
|
|
26
|
+
}, { status: 400 }));
|
|
27
|
+
}
|
|
28
|
+
const url = new URL(request.url);
|
|
29
|
+
const runtime = await JpdclRuntime.create({
|
|
30
|
+
credentials: loginId && password ? { loginId, password, source: "environment" } : undefined,
|
|
31
|
+
persistent: false,
|
|
32
|
+
allowMutations: url.searchParams.get("allowMutations") === "true",
|
|
33
|
+
});
|
|
34
|
+
const server = await createJpdclMcpServer({
|
|
35
|
+
runtime,
|
|
36
|
+
allowCredentialStorage: false,
|
|
37
|
+
credentialSource: loginId && password ? "smithery-connection" : undefined,
|
|
38
|
+
});
|
|
39
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
40
|
+
sessionIdGenerator: undefined,
|
|
41
|
+
enableJsonResponse: true,
|
|
42
|
+
});
|
|
43
|
+
await server.connect(transport);
|
|
44
|
+
return withCors(await transport.handleRequest(request));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=http-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-handler.js","sourceRoot":"","sources":["../src/http-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wCAAwC,EAAE,MAAM,+DAA+D,CAAC;AACzH,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,GAAG;IAClB,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,4BAA4B;IAC5D,8BAA8B,EAAE,+GAA+G;IAC/I,+BAA+B,EAAE,sCAAsC;CACxE,CAAC;AAEF,SAAS,QAAQ,CAAC,QAAkB;IAClC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClF,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5G,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAgB;IACrD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,QAAQ,CAAC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C7D,kBAAkB,EAAE,SAAS;QAC7B,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,QAAQ,CAAC,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CookieJar } from "tough-cookie";
|
|
2
|
+
export declare class CookieHttpClient {
|
|
3
|
+
readonly jar: CookieJar;
|
|
4
|
+
readonly fetch: typeof globalThis.fetch;
|
|
5
|
+
constructor(serializedCookies?: string);
|
|
6
|
+
serialize(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare function basicAuth(value: string): string;
|
|
9
|
+
export declare function buildUrl(baseUrl: string, path: string, params?: Record<string, string | number | boolean | null | undefined>): string;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import makeFetchCookie from "fetch-cookie";
|
|
2
|
+
import { CookieJar } from "tough-cookie";
|
|
3
|
+
export class CookieHttpClient {
|
|
4
|
+
jar;
|
|
5
|
+
fetch;
|
|
6
|
+
constructor(serializedCookies) {
|
|
7
|
+
this.jar = serializedCookies
|
|
8
|
+
? CookieJar.deserializeSync(JSON.parse(serializedCookies))
|
|
9
|
+
: new CookieJar();
|
|
10
|
+
this.fetch = makeFetchCookie(globalThis.fetch, this.jar);
|
|
11
|
+
}
|
|
12
|
+
serialize() {
|
|
13
|
+
return JSON.stringify(this.jar.serializeSync());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function basicAuth(value) {
|
|
17
|
+
return `Basic ${Buffer.from(value, "utf8").toString("base64")}`;
|
|
18
|
+
}
|
|
19
|
+
export function buildUrl(baseUrl, path, params = {}) {
|
|
20
|
+
let resolved = path;
|
|
21
|
+
const unused = { ...params };
|
|
22
|
+
for (const [key, rawValue] of Object.entries(params)) {
|
|
23
|
+
const marker = `{${key}}`;
|
|
24
|
+
if (resolved.includes(marker)) {
|
|
25
|
+
if (rawValue === undefined || rawValue === null) {
|
|
26
|
+
throw new Error(`Missing required URL parameter: ${key}`);
|
|
27
|
+
}
|
|
28
|
+
resolved = resolved.replaceAll(marker, encodeURIComponent(String(rawValue)));
|
|
29
|
+
delete unused[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const missing = [...resolved.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
|
|
33
|
+
if (missing.length)
|
|
34
|
+
throw new Error(`Missing required URL parameter(s): ${missing.join(", ")}`);
|
|
35
|
+
const base = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
36
|
+
const url = new URL(resolved.replace(/^\//, ""), base);
|
|
37
|
+
for (const [key, value] of Object.entries(unused)) {
|
|
38
|
+
if (value !== undefined && value !== null)
|
|
39
|
+
url.searchParams.set(key, String(value));
|
|
40
|
+
}
|
|
41
|
+
return url.toString();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,OAAO,gBAAgB;IAClB,GAAG,CAAY;IACf,KAAK,CAA0B;IAExC,YAAY,iBAA0B;QACpC,IAAI,CAAC,GAAG,GAAG,iBAAiB;YAC1B,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YAC1D,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAA4B,CAAC;IACtF,CAAC;IAED,SAAS;QACP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AC,CAAC;IAEhG,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC;IAC7D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./catalog.js";
|
|
2
|
+
export * from "./config.js";
|
|
3
|
+
export * from "./crypto.js";
|
|
4
|
+
export * from "./credentials.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export * from "./main-client.js";
|
|
7
|
+
export * from "./ledger-client.js";
|
|
8
|
+
export * from "./dates.js";
|
|
9
|
+
export * from "./runtime.js";
|
|
10
|
+
export * from "./session.js";
|
|
11
|
+
export * from "./smart-client.js";
|
|
12
|
+
export * from "./tariff.js";
|
|
13
|
+
export * from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./catalog.js";
|
|
2
|
+
export * from "./config.js";
|
|
3
|
+
export * from "./crypto.js";
|
|
4
|
+
export * from "./credentials.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export * from "./main-client.js";
|
|
7
|
+
export * from "./ledger-client.js";
|
|
8
|
+
export * from "./dates.js";
|
|
9
|
+
export * from "./runtime.js";
|
|
10
|
+
export * from "./session.js";
|
|
11
|
+
export * from "./smart-client.js";
|
|
12
|
+
export * from "./tariff.js";
|
|
13
|
+
export * from "./types.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/launcher.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// MCP clients start the package without arguments. Any explicit argument selects
|
|
3
|
+
// the human CLI, so `npx jpdcl` and `jpdcl auth status` can share one executable.
|
|
4
|
+
if (process.argv.length > 2) {
|
|
5
|
+
await import("./cli.js");
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await import("./mcp-stdio.js");
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=launcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.js","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":";AAEA,iFAAiF;AACjF,kFAAkF;AAClF,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IAC5B,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC;KAAM,CAAC;IACN,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { EndpointName } from "./catalog.js";
|
|
2
|
+
import type { RequestOptions } from "./types.js";
|
|
3
|
+
export declare const LEDGER_PORTAL_URL = "https://smartmeter1.jpdcl.co.in/smartmeter/";
|
|
4
|
+
export declare const LEDGER_CONSUMER_ENDPOINT: string;
|
|
5
|
+
export declare const LEDGER_ALARM_ENDPOINT: string;
|
|
6
|
+
export interface LedgerReading {
|
|
7
|
+
observedAt: string;
|
|
8
|
+
cumulative: {
|
|
9
|
+
importKwh: number;
|
|
10
|
+
exportKwh: number;
|
|
11
|
+
netImportKwh: number;
|
|
12
|
+
importKvah: number;
|
|
13
|
+
exportKvah: number;
|
|
14
|
+
netImportKvah: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface LedgerConsumerData {
|
|
18
|
+
_meta: {
|
|
19
|
+
dataClass: "observed";
|
|
20
|
+
source: "jpdcl-daily-meter-ledger";
|
|
21
|
+
sourceUrl: string;
|
|
22
|
+
fetchedAt: string;
|
|
23
|
+
publicConsumerLookup: true;
|
|
24
|
+
};
|
|
25
|
+
consumer: {
|
|
26
|
+
consumerId: string;
|
|
27
|
+
name: string | null;
|
|
28
|
+
smartMeterNumber: string | null;
|
|
29
|
+
installationDate: string | null;
|
|
30
|
+
netMeter: boolean | null;
|
|
31
|
+
earthLoading: boolean | null;
|
|
32
|
+
};
|
|
33
|
+
readings: LedgerReading[];
|
|
34
|
+
}
|
|
35
|
+
export interface LedgerPeriodOptions {
|
|
36
|
+
from?: string;
|
|
37
|
+
to?: string;
|
|
38
|
+
limit?: number;
|
|
39
|
+
}
|
|
40
|
+
export declare class JpdclLedgerClient {
|
|
41
|
+
private readonly timeoutMs;
|
|
42
|
+
private readonly cacheMs;
|
|
43
|
+
private readonly cache;
|
|
44
|
+
constructor(timeoutMs?: number, cacheMs?: number);
|
|
45
|
+
consumer(consumerId: string): Promise<LedgerConsumerData>;
|
|
46
|
+
alarms(meterNumber: string): Promise<Record<string, unknown>>;
|
|
47
|
+
request(name: EndpointName | string, options?: RequestOptions): Promise<unknown>;
|
|
48
|
+
}
|
|
49
|
+
export declare function parseLedgerHtml(html: string, expectedConsumerId: string): LedgerConsumerData;
|
|
50
|
+
export declare function ledgerPeriod(data: LedgerConsumerData, options?: LedgerPeriodOptions): {
|
|
51
|
+
_meta: {
|
|
52
|
+
dataClass: string;
|
|
53
|
+
source: "jpdcl-daily-meter-ledger";
|
|
54
|
+
fetchedAt: string;
|
|
55
|
+
calculation: string;
|
|
56
|
+
};
|
|
57
|
+
consumer: {
|
|
58
|
+
consumerId: string;
|
|
59
|
+
name: string | null;
|
|
60
|
+
smartMeterNumber: string | null;
|
|
61
|
+
installationDate: string | null;
|
|
62
|
+
netMeter: boolean | null;
|
|
63
|
+
earthLoading: boolean | null;
|
|
64
|
+
};
|
|
65
|
+
availability: {
|
|
66
|
+
firstObservation: string | null;
|
|
67
|
+
latestObservation: string | null;
|
|
68
|
+
sourceRecordCount: number;
|
|
69
|
+
freshnessHoursAtFetch: number;
|
|
70
|
+
};
|
|
71
|
+
period: {
|
|
72
|
+
from: string;
|
|
73
|
+
to: string;
|
|
74
|
+
baselineObservation: string | null;
|
|
75
|
+
latestObservation: string | null;
|
|
76
|
+
usage: {
|
|
77
|
+
importKwh: number;
|
|
78
|
+
exportKwh: number;
|
|
79
|
+
netImportKwh: number;
|
|
80
|
+
importKvah: number;
|
|
81
|
+
exportKvah: number;
|
|
82
|
+
netImportKvah: number;
|
|
83
|
+
} | null;
|
|
84
|
+
provisionalBillableKwh: number | null;
|
|
85
|
+
provisionalBillableBasis: string;
|
|
86
|
+
warning: string;
|
|
87
|
+
};
|
|
88
|
+
readings: {
|
|
89
|
+
usageSincePreviousObservation: {
|
|
90
|
+
importKwh: number;
|
|
91
|
+
exportKwh: number;
|
|
92
|
+
netImportKwh: number;
|
|
93
|
+
importKvah: number;
|
|
94
|
+
exportKvah: number;
|
|
95
|
+
netImportKvah: number;
|
|
96
|
+
} | null;
|
|
97
|
+
observedAt: string;
|
|
98
|
+
cumulative: {
|
|
99
|
+
importKwh: number;
|
|
100
|
+
exportKwh: number;
|
|
101
|
+
netImportKwh: number;
|
|
102
|
+
importKvah: number;
|
|
103
|
+
exportKvah: number;
|
|
104
|
+
netImportKvah: number;
|
|
105
|
+
};
|
|
106
|
+
}[];
|
|
107
|
+
pagination: {
|
|
108
|
+
returned: number;
|
|
109
|
+
matched: number;
|
|
110
|
+
limit: number | null;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as cheerio from "cheerio";
|
|
2
|
+
import { assertDateRange } from "./dates.js";
|
|
3
|
+
import { JpdclError } from "./errors.js";
|
|
4
|
+
export const LEDGER_PORTAL_URL = "https://smartmeter1.jpdcl.co.in/smartmeter/";
|
|
5
|
+
export const LEDGER_CONSUMER_ENDPOINT = new URL("assets/php/_getConsumerDetails.php", LEDGER_PORTAL_URL).toString();
|
|
6
|
+
export const LEDGER_ALARM_ENDPOINT = new URL("assets/php/_getAlarmDetails.php", LEDGER_PORTAL_URL).toString();
|
|
7
|
+
export class JpdclLedgerClient {
|
|
8
|
+
timeoutMs;
|
|
9
|
+
cacheMs;
|
|
10
|
+
cache = new Map();
|
|
11
|
+
constructor(timeoutMs = 20_000, cacheMs = 30_000) {
|
|
12
|
+
this.timeoutMs = timeoutMs;
|
|
13
|
+
this.cacheMs = cacheMs;
|
|
14
|
+
}
|
|
15
|
+
async consumer(consumerId) {
|
|
16
|
+
validateConsumerId(consumerId);
|
|
17
|
+
const cached = this.cache.get(consumerId);
|
|
18
|
+
if (cached && Date.now() - cached.at < this.cacheMs)
|
|
19
|
+
return cached.value;
|
|
20
|
+
const response = await postForm(LEDGER_CONSUMER_ENDPOINT, { consumercode: consumerId }, this.timeoutMs);
|
|
21
|
+
if (!response.ok)
|
|
22
|
+
throw new JpdclError(`Daily meter portal returned HTTP ${response.status}`, response.status);
|
|
23
|
+
const parsed = parseLedgerHtml(await response.text(), consumerId);
|
|
24
|
+
this.cache.set(consumerId, { at: Date.now(), value: parsed });
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
async alarms(meterNumber) {
|
|
28
|
+
if (!meterNumber.trim())
|
|
29
|
+
throw new JpdclError("A smart-meter number is required", 400);
|
|
30
|
+
const response = await postForm(LEDGER_ALARM_ENDPOINT, { meterSno: meterNumber.trim() }, this.timeoutMs);
|
|
31
|
+
if (!response.ok)
|
|
32
|
+
throw new JpdclError(`Daily meter alarm endpoint returned HTTP ${response.status}`, response.status);
|
|
33
|
+
const body = await response.text();
|
|
34
|
+
const noAlarms = /no\s+alarms/i.test(body);
|
|
35
|
+
const tables = noAlarms ? [] : parseGenericTables(body);
|
|
36
|
+
return {
|
|
37
|
+
_meta: {
|
|
38
|
+
dataClass: "observed",
|
|
39
|
+
source: "jpdcl-daily-meter-ledger-alarm-endpoint",
|
|
40
|
+
sourceUrl: LEDGER_ALARM_ENDPOINT,
|
|
41
|
+
fetchedAt: new Date().toISOString(),
|
|
42
|
+
},
|
|
43
|
+
meterNumber,
|
|
44
|
+
hasAlarms: noAlarms ? false : tables.some((table) => table.rows.length > 0),
|
|
45
|
+
tables,
|
|
46
|
+
message: noAlarms ? "No Alarms" : undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async request(name, options = {}) {
|
|
50
|
+
if (name === "ledger_consumer_readings") {
|
|
51
|
+
const consumerId = String(options.params?.consumerId ?? options.body?.consumerId ?? "");
|
|
52
|
+
return this.consumer(consumerId);
|
|
53
|
+
}
|
|
54
|
+
if (name === "ledger_meter_alarms") {
|
|
55
|
+
const meterNumber = String(options.params?.meterNumber ?? options.body?.meterNumber ?? "");
|
|
56
|
+
return this.alarms(meterNumber);
|
|
57
|
+
}
|
|
58
|
+
throw new JpdclError(`Unknown daily meter ledger endpoint: ${name}`, 400);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function parseLedgerHtml(html, expectedConsumerId) {
|
|
62
|
+
const [profileHtml, tableHtml = ""] = html.split("||||");
|
|
63
|
+
const profile = parseProfile(profileHtml ?? "");
|
|
64
|
+
const $ = cheerio.load(tableHtml);
|
|
65
|
+
const readings = [];
|
|
66
|
+
$("#readtable1 tbody tr").each((_, row) => {
|
|
67
|
+
const cells = $(row).find("td").map((__, cell) => $(cell).text().trim()).get();
|
|
68
|
+
if (cells.length < 7 || !/^\d{4}-\d{2}-\d{2}$/.test(cells[0] ?? ""))
|
|
69
|
+
return;
|
|
70
|
+
const values = cells.slice(1, 7).map(Number);
|
|
71
|
+
if (values.some((value) => !Number.isFinite(value)))
|
|
72
|
+
return;
|
|
73
|
+
readings.push({
|
|
74
|
+
observedAt: `${cells[0]}T00:00:00+05:30`,
|
|
75
|
+
cumulative: {
|
|
76
|
+
importKwh: values[0], exportKwh: values[1], netImportKwh: values[2],
|
|
77
|
+
importKvah: values[3], exportKvah: values[4], netImportKvah: values[5],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
readings.sort((a, b) => b.observedAt.localeCompare(a.observedAt));
|
|
82
|
+
if (!readings.length)
|
|
83
|
+
throw new JpdclError("No daily meter readings were returned for this consumer ID", 404);
|
|
84
|
+
const consumerId = profile["consumer id"] || expectedConsumerId;
|
|
85
|
+
return {
|
|
86
|
+
_meta: {
|
|
87
|
+
dataClass: "observed",
|
|
88
|
+
source: "jpdcl-daily-meter-ledger",
|
|
89
|
+
sourceUrl: LEDGER_CONSUMER_ENDPOINT,
|
|
90
|
+
fetchedAt: new Date().toISOString(),
|
|
91
|
+
publicConsumerLookup: true,
|
|
92
|
+
},
|
|
93
|
+
consumer: {
|
|
94
|
+
consumerId,
|
|
95
|
+
name: nullable(profile.name),
|
|
96
|
+
smartMeterNumber: nullable(profile["smart meter"]),
|
|
97
|
+
installationDate: validDate(profile["inatallation date"] ?? profile["installation date"]),
|
|
98
|
+
netMeter: yesNo(profile["net meter"]),
|
|
99
|
+
earthLoading: yesNo(profile["earth-loading"]),
|
|
100
|
+
},
|
|
101
|
+
readings,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function ledgerPeriod(data, options = {}) {
|
|
105
|
+
const newestDate = data.readings[0]?.observedAt.slice(0, 10);
|
|
106
|
+
if (!newestDate)
|
|
107
|
+
throw new JpdclError("The daily meter ledger is empty", 404);
|
|
108
|
+
const from = options.from ?? `${newestDate.slice(0, 7)}-01`;
|
|
109
|
+
const to = options.to ?? newestDate;
|
|
110
|
+
assertDateRange(from, to, { requireBoth: true });
|
|
111
|
+
const ascending = [...data.readings].sort((a, b) => a.observedAt.localeCompare(b.observedAt));
|
|
112
|
+
const selected = ascending.filter((reading) => {
|
|
113
|
+
const day = reading.observedAt.slice(0, 10);
|
|
114
|
+
return day >= from && day <= to;
|
|
115
|
+
});
|
|
116
|
+
const baseline = [...ascending].reverse().find((reading) => reading.observedAt.slice(0, 10) < from) ?? selected[0];
|
|
117
|
+
const latest = selected.at(-1);
|
|
118
|
+
const deltas = new Map();
|
|
119
|
+
for (let index = 1; index < ascending.length; index++) {
|
|
120
|
+
deltas.set(ascending[index].observedAt, subtractReadings(ascending[index], ascending[index - 1]));
|
|
121
|
+
}
|
|
122
|
+
const requestedLimit = Math.max(0, Math.floor(options.limit ?? 35));
|
|
123
|
+
const returned = (requestedLimit === 0 ? [] : [...selected].reverse().slice(0, requestedLimit)).map((reading) => ({
|
|
124
|
+
...reading,
|
|
125
|
+
usageSincePreviousObservation: deltas.get(reading.observedAt) ?? null,
|
|
126
|
+
}));
|
|
127
|
+
const periodUsage = baseline && latest ? subtractReadings(latest, baseline) : null;
|
|
128
|
+
const settlementCandidateKwh = periodUsage
|
|
129
|
+
? data.consumer.netMeter ? Math.max(0, periodUsage.netImportKwh) : Math.max(0, periodUsage.importKwh)
|
|
130
|
+
: null;
|
|
131
|
+
const latestDay = new Date(`${newestDate}T00:00:00+05:30`).getTime();
|
|
132
|
+
return {
|
|
133
|
+
_meta: {
|
|
134
|
+
dataClass: "observed-with-deterministic-deltas",
|
|
135
|
+
source: data._meta.source,
|
|
136
|
+
fetchedAt: data._meta.fetchedAt,
|
|
137
|
+
calculation: "cumulative register subtraction",
|
|
138
|
+
},
|
|
139
|
+
consumer: data.consumer,
|
|
140
|
+
availability: {
|
|
141
|
+
firstObservation: data.readings.at(-1)?.observedAt ?? null,
|
|
142
|
+
latestObservation: data.readings[0]?.observedAt ?? null,
|
|
143
|
+
sourceRecordCount: data.readings.length,
|
|
144
|
+
freshnessHoursAtFetch: Math.max(0, Math.round((new Date(data._meta.fetchedAt).getTime() - latestDay) / 360_000) / 10),
|
|
145
|
+
},
|
|
146
|
+
period: {
|
|
147
|
+
from,
|
|
148
|
+
to,
|
|
149
|
+
baselineObservation: baseline?.observedAt ?? null,
|
|
150
|
+
latestObservation: latest?.observedAt ?? null,
|
|
151
|
+
usage: periodUsage,
|
|
152
|
+
provisionalBillableKwh: settlementCandidateKwh,
|
|
153
|
+
provisionalBillableBasis: data.consumer.netMeter ? "net-import-register-difference" : "import-register-difference",
|
|
154
|
+
warning: "Register differences are meter evidence, but JPDCL may use different billing cutoffs, adjustments, carry-forward credits, or settlement rules.",
|
|
155
|
+
},
|
|
156
|
+
readings: returned,
|
|
157
|
+
pagination: { returned: returned.length, matched: selected.length, limit: requestedLimit || null },
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function subtractReadings(current, previous) {
|
|
161
|
+
const result = {};
|
|
162
|
+
for (const key of Object.keys(current.cumulative)) {
|
|
163
|
+
result[key] = round3(current.cumulative[key] - previous.cumulative[key]);
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
function parseProfile(html) {
|
|
168
|
+
const $ = cheerio.load(html);
|
|
169
|
+
const profile = {};
|
|
170
|
+
$(".row").each((_, row) => {
|
|
171
|
+
const columns = $(row).find(".col").map((__, column) => $(column).text().replace(/\s+/g, " ").trim()).get();
|
|
172
|
+
const key = columns[0]?.toLowerCase();
|
|
173
|
+
if (!key)
|
|
174
|
+
return;
|
|
175
|
+
profile[key] = $(row).find("input").attr("value")?.trim() ?? columns[1] ?? "";
|
|
176
|
+
});
|
|
177
|
+
return profile;
|
|
178
|
+
}
|
|
179
|
+
function parseGenericTables(html) {
|
|
180
|
+
const $ = cheerio.load(html);
|
|
181
|
+
return $("table").map((_, table) => {
|
|
182
|
+
const headers = $(table).find("thead th").map((__, cell) => $(cell).text().replace(/\s+/g, " ").trim()).get();
|
|
183
|
+
const rows = $(table).find("tbody tr").map((__, row) => [$(row).find("td").map((___, cell) => $(cell).text().replace(/\s+/g, " ").trim()).get()]).get();
|
|
184
|
+
return { headers, rows };
|
|
185
|
+
}).get();
|
|
186
|
+
}
|
|
187
|
+
async function postForm(url, fields, timeoutMs) {
|
|
188
|
+
return fetch(url, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: {
|
|
191
|
+
Accept: "text/html, */*; q=0.01",
|
|
192
|
+
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
193
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
194
|
+
},
|
|
195
|
+
body: new URLSearchParams(fields),
|
|
196
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function validateConsumerId(value) {
|
|
200
|
+
if (!/^\d{1,13}$/.test(value))
|
|
201
|
+
throw new JpdclError("Consumer ID must contain 1 to 13 digits", 400);
|
|
202
|
+
}
|
|
203
|
+
function nullable(value) {
|
|
204
|
+
return value?.trim() ? value.trim() : null;
|
|
205
|
+
}
|
|
206
|
+
function validDate(value) {
|
|
207
|
+
return value && /^\d{4}-\d{2}-\d{2}$/.test(value) && value !== "0000-00-00" ? value : null;
|
|
208
|
+
}
|
|
209
|
+
function yesNo(value) {
|
|
210
|
+
if (!value)
|
|
211
|
+
return null;
|
|
212
|
+
if (/^yes$/i.test(value.trim()))
|
|
213
|
+
return true;
|
|
214
|
+
if (/^no$/i.test(value.trim()))
|
|
215
|
+
return false;
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
function round3(value) {
|
|
219
|
+
return Math.round((value + Number.EPSILON) * 1000) / 1000;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=ledger-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger-client.js","sourceRoot":"","sources":["../src/ledger-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,6CAA6C,CAAC;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,oCAAoC,EAAE,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC;AACpH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,iCAAiC,EAAE,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC;AAuC9G,MAAM,OAAO,iBAAiB;IAGC;IAAqC;IAFjD,KAAK,GAAG,IAAI,GAAG,EAAqD,CAAC;IAEtF,YAA6B,YAAY,MAAM,EAAmB,UAAU,MAAM;QAArD,cAAS,GAAT,SAAS,CAAS;QAAmB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEtF,KAAK,CAAC,QAAQ,CAAC,UAAkB;QAC/B,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC;QACzE,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,wBAAwB,EAAE,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Q,CAAC,KAAyB;IACzC,OAAO,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AAED,SAAS,SAAS,CAAC,KAAyB;IAC1C,OAAO,KAAK,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,SAAS,KAAK,CAAC,KAAyB;IACtC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type EndpointName } from "./catalog.js";
|
|
2
|
+
import { type Credentials } from "./credentials.js";
|
|
3
|
+
import type { MainSession, PortalResponse, RequestOptions } from "./types.js";
|
|
4
|
+
export declare class JpdclClient {
|
|
5
|
+
private readonly baseUrl;
|
|
6
|
+
private readonly allowMutations;
|
|
7
|
+
private readonly suppliedCredentials?;
|
|
8
|
+
private readonly persistSession;
|
|
9
|
+
private readonly http;
|
|
10
|
+
private session?;
|
|
11
|
+
constructor(session?: MainSession, baseUrl?: string, allowMutations?: boolean, suppliedCredentials?: Credentials | undefined, persistSession?: (session: MainSession) => Promise<void>);
|
|
12
|
+
get currentSession(): MainSession | undefined;
|
|
13
|
+
login(loginId: string, password: string): Promise<PortalResponse>;
|
|
14
|
+
request<T = unknown>(name: EndpointName | string, options?: RequestOptions): Promise<PortalResponse<T>>;
|
|
15
|
+
private requestInternal;
|
|
16
|
+
private decodeResponse;
|
|
17
|
+
customerInfo(accountId?: string | undefined): Promise<PortalResponse>;
|
|
18
|
+
linkedAccounts(loginId?: string | undefined): Promise<PortalResponse>;
|
|
19
|
+
history(type: "BILL" | "PAYM", accountId?: string | undefined, from?: string, to?: string): Promise<PortalResponse>;
|
|
20
|
+
consumption(accountId?: string | undefined, from?: string, to?: string): Promise<PortalResponse>;
|
|
21
|
+
smartSso(accountId: string, meterNumber: string): Promise<PortalResponse>;
|
|
22
|
+
digest(accountId?: string | undefined): Promise<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
export declare function isoDate(date: Date): string;
|
|
25
|
+
export declare function sixMonthsAgo(): string;
|