kumpara 0.1.0 → 0.1.1
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/dist/cjs/client.d.ts +13 -2
- package/dist/cjs/client.js +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/resources.d.ts +2 -2
- package/dist/cjs/resources.js +1 -1
- package/dist/cjs/webhook.d.ts +2 -2
- package/dist/cjs/webhook.js +2 -2
- package/dist/esm/client.d.ts +13 -2
- package/dist/esm/client.js +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/resources.d.ts +2 -2
- package/dist/esm/resources.js +1 -1
- package/dist/esm/webhook.d.ts +2 -2
- package/dist/esm/webhook.js +2 -2
- package/package.json +1 -1
package/dist/cjs/client.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Customers, Invoices, Products, Tenants } from './resources.js';
|
|
2
2
|
import type { KumparaObject } from './types.js';
|
|
3
|
-
export declare const VERSION = "0.1.
|
|
3
|
+
export declare const VERSION = "0.1.1";
|
|
4
4
|
export declare const DEFAULT_BASE_URL = "https://api.kumpara.no/v1";
|
|
5
|
+
/** What the client needs from an HTTP answer: the global fetch's Response has all of it. */
|
|
6
|
+
export interface FetchResponseLike {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
status: number;
|
|
9
|
+
headers: {
|
|
10
|
+
get(name: string): string | null;
|
|
11
|
+
};
|
|
12
|
+
text(): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/** A fetch function: the global one, or your own (tests, a proxy). Typed loosely so no DOM or Node types are needed. */
|
|
15
|
+
export type FetchLike = (url: string, init: any) => Promise<FetchResponseLike>;
|
|
5
16
|
export interface KumparaOptions {
|
|
6
17
|
/** kp_test_... or kp_live_...; default: the KUMPARA_API_KEY environment variable. */
|
|
7
18
|
apiKey?: string;
|
|
@@ -13,7 +24,7 @@ export interface KumparaOptions {
|
|
|
13
24
|
/** Extra attempts when it is safe to repeat. Default 2. */
|
|
14
25
|
maxRetries?: number;
|
|
15
26
|
/** Your own fetch (for tests or a proxy). Default: the global fetch. */
|
|
16
|
-
fetch?:
|
|
27
|
+
fetch?: FetchLike;
|
|
17
28
|
/** @internal How to wait between attempts (tests). */
|
|
18
29
|
sleep?: (ms: number) => Promise<void>;
|
|
19
30
|
}
|
package/dist/cjs/client.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Kumpara = exports.DEFAULT_BASE_URL = exports.VERSION = void 0;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
const resources_js_1 = require("./resources.js");
|
|
6
|
-
exports.VERSION = '0.1.
|
|
6
|
+
exports.VERSION = '0.1.1';
|
|
7
7
|
exports.DEFAULT_BASE_URL = 'https://api.kumpara.no/v1';
|
|
8
8
|
const MAX_RETRY_WAIT = 10; // seconds; a longer Retry-After is thrown to the caller
|
|
9
9
|
/**
|
|
@@ -97,7 +97,7 @@ class Kumpara {
|
|
|
97
97
|
for (let attempt = 0;; attempt++) {
|
|
98
98
|
let response;
|
|
99
99
|
try {
|
|
100
|
-
response = await this.#fetch(url, {
|
|
100
|
+
response = await this.#fetch(url.toString(), {
|
|
101
101
|
method,
|
|
102
102
|
headers,
|
|
103
103
|
body: payload,
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Kumpara, VERSION, DEFAULT_BASE_URL } from './client.js';
|
|
2
|
-
export type { KumparaOptions } from './client.js';
|
|
2
|
+
export type { KumparaOptions, FetchLike, FetchResponseLike } from './client.js';
|
|
3
3
|
export { Customers, Products, Invoices, Tenants } from './resources.js';
|
|
4
4
|
export { Webhook, constructEvent, verify, DEFAULT_TOLERANCE } from './webhook.js';
|
|
5
5
|
export type { VerifyOptions } from './webhook.js';
|
package/dist/cjs/resources.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export declare class Invoices {
|
|
|
42
42
|
credit(id: number, reason?: string): Promise<Invoice>;
|
|
43
43
|
/** The PDF as the API gives it (base64). */
|
|
44
44
|
pdf(id: number): Promise<InvoicePdf>;
|
|
45
|
-
/** The PDF file itself, ready to save or send. */
|
|
46
|
-
pdfBuffer(id: number): Promise<
|
|
45
|
+
/** The PDF file itself, ready to save or send (a Buffer in Node.js; typed as Uint8Array). */
|
|
46
|
+
pdfBuffer(id: number): Promise<Uint8Array>;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Accounts for your customers: /tenants. The key needs the `tenants` scope. Work inside one with
|
package/dist/cjs/resources.js
CHANGED
|
@@ -83,7 +83,7 @@ class Invoices {
|
|
|
83
83
|
pdf(id) {
|
|
84
84
|
return this.client.request('GET', `/invoices/${id}/pdf`);
|
|
85
85
|
}
|
|
86
|
-
/** The PDF file itself, ready to save or send. */
|
|
86
|
+
/** The PDF file itself, ready to save or send (a Buffer in Node.js; typed as Uint8Array). */
|
|
87
87
|
async pdfBuffer(id) {
|
|
88
88
|
const pdf = await this.pdf(id);
|
|
89
89
|
return Buffer.from(pdf.base64 ?? '', 'base64');
|
package/dist/cjs/webhook.d.ts
CHANGED
|
@@ -15,9 +15,9 @@ export interface VerifyOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* @throws SignatureError when the signature is missing, wrong or too old, or the body is not an event
|
|
17
17
|
*/
|
|
18
|
-
export declare function constructEvent(payload: string |
|
|
18
|
+
export declare function constructEvent(payload: string | Uint8Array, signatureHeader: string | string[] | null | undefined, secret: string, options?: VerifyOptions): WebhookEvent;
|
|
19
19
|
/** @throws SignatureError */
|
|
20
|
-
export declare function verify(payload: string |
|
|
20
|
+
export declare function verify(payload: string | Uint8Array, signatureHeader: string | string[] | null | undefined, secret: string, options?: VerifyOptions): void;
|
|
21
21
|
export declare const Webhook: {
|
|
22
22
|
constructEvent: typeof constructEvent;
|
|
23
23
|
verify: typeof verify;
|
package/dist/cjs/webhook.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.DEFAULT_TOLERANCE = 300; // seconds between the signature's time and now
|
|
|
16
16
|
* @throws SignatureError when the signature is missing, wrong or too old, or the body is not an event
|
|
17
17
|
*/
|
|
18
18
|
function constructEvent(payload, signatureHeader, secret, options = {}) {
|
|
19
|
-
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
19
|
+
const body = typeof payload === 'string' ? payload : Buffer.from(payload).toString('utf8');
|
|
20
20
|
verify(body, signatureHeader, secret, options);
|
|
21
21
|
let event;
|
|
22
22
|
try {
|
|
@@ -56,7 +56,7 @@ function verify(payload, signatureHeader, secret, options = {}) {
|
|
|
56
56
|
if (tolerance > 0 && Math.abs(now - timestamp) > tolerance) {
|
|
57
57
|
throw new errors_js_1.SignatureError('The webhook signature is too old.');
|
|
58
58
|
}
|
|
59
|
-
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
59
|
+
const body = typeof payload === 'string' ? payload : Buffer.from(payload).toString('utf8');
|
|
60
60
|
const expected = Buffer.from((0, node_crypto_1.createHmac)('sha256', secret).update(`${timestamp}.${body}`).digest('hex'));
|
|
61
61
|
for (const signature of signatures) {
|
|
62
62
|
const given = Buffer.from(signature);
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Customers, Invoices, Products, Tenants } from './resources.js';
|
|
2
2
|
import type { KumparaObject } from './types.js';
|
|
3
|
-
export declare const VERSION = "0.1.
|
|
3
|
+
export declare const VERSION = "0.1.1";
|
|
4
4
|
export declare const DEFAULT_BASE_URL = "https://api.kumpara.no/v1";
|
|
5
|
+
/** What the client needs from an HTTP answer: the global fetch's Response has all of it. */
|
|
6
|
+
export interface FetchResponseLike {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
status: number;
|
|
9
|
+
headers: {
|
|
10
|
+
get(name: string): string | null;
|
|
11
|
+
};
|
|
12
|
+
text(): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/** A fetch function: the global one, or your own (tests, a proxy). Typed loosely so no DOM or Node types are needed. */
|
|
15
|
+
export type FetchLike = (url: string, init: any) => Promise<FetchResponseLike>;
|
|
5
16
|
export interface KumparaOptions {
|
|
6
17
|
/** kp_test_... or kp_live_...; default: the KUMPARA_API_KEY environment variable. */
|
|
7
18
|
apiKey?: string;
|
|
@@ -13,7 +24,7 @@ export interface KumparaOptions {
|
|
|
13
24
|
/** Extra attempts when it is safe to repeat. Default 2. */
|
|
14
25
|
maxRetries?: number;
|
|
15
26
|
/** Your own fetch (for tests or a proxy). Default: the global fetch. */
|
|
16
|
-
fetch?:
|
|
27
|
+
fetch?: FetchLike;
|
|
17
28
|
/** @internal How to wait between attempts (tests). */
|
|
18
29
|
sleep?: (ms: number) => Promise<void>;
|
|
19
30
|
}
|
package/dist/esm/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConnectionError, errorFromResponse } from './errors.js';
|
|
2
2
|
import { Customers, Invoices, Products, Tenants } from './resources.js';
|
|
3
|
-
export const VERSION = '0.1.
|
|
3
|
+
export const VERSION = '0.1.1';
|
|
4
4
|
export const DEFAULT_BASE_URL = 'https://api.kumpara.no/v1';
|
|
5
5
|
const MAX_RETRY_WAIT = 10; // seconds; a longer Retry-After is thrown to the caller
|
|
6
6
|
/**
|
|
@@ -94,7 +94,7 @@ export class Kumpara {
|
|
|
94
94
|
for (let attempt = 0;; attempt++) {
|
|
95
95
|
let response;
|
|
96
96
|
try {
|
|
97
|
-
response = await this.#fetch(url, {
|
|
97
|
+
response = await this.#fetch(url.toString(), {
|
|
98
98
|
method,
|
|
99
99
|
headers,
|
|
100
100
|
body: payload,
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Kumpara, VERSION, DEFAULT_BASE_URL } from './client.js';
|
|
2
|
-
export type { KumparaOptions } from './client.js';
|
|
2
|
+
export type { KumparaOptions, FetchLike, FetchResponseLike } from './client.js';
|
|
3
3
|
export { Customers, Products, Invoices, Tenants } from './resources.js';
|
|
4
4
|
export { Webhook, constructEvent, verify, DEFAULT_TOLERANCE } from './webhook.js';
|
|
5
5
|
export type { VerifyOptions } from './webhook.js';
|
package/dist/esm/resources.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export declare class Invoices {
|
|
|
42
42
|
credit(id: number, reason?: string): Promise<Invoice>;
|
|
43
43
|
/** The PDF as the API gives it (base64). */
|
|
44
44
|
pdf(id: number): Promise<InvoicePdf>;
|
|
45
|
-
/** The PDF file itself, ready to save or send. */
|
|
46
|
-
pdfBuffer(id: number): Promise<
|
|
45
|
+
/** The PDF file itself, ready to save or send (a Buffer in Node.js; typed as Uint8Array). */
|
|
46
|
+
pdfBuffer(id: number): Promise<Uint8Array>;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Accounts for your customers: /tenants. The key needs the `tenants` scope. Work inside one with
|
package/dist/esm/resources.js
CHANGED
|
@@ -78,7 +78,7 @@ export class Invoices {
|
|
|
78
78
|
pdf(id) {
|
|
79
79
|
return this.client.request('GET', `/invoices/${id}/pdf`);
|
|
80
80
|
}
|
|
81
|
-
/** The PDF file itself, ready to save or send. */
|
|
81
|
+
/** The PDF file itself, ready to save or send (a Buffer in Node.js; typed as Uint8Array). */
|
|
82
82
|
async pdfBuffer(id) {
|
|
83
83
|
const pdf = await this.pdf(id);
|
|
84
84
|
return Buffer.from(pdf.base64 ?? '', 'base64');
|
package/dist/esm/webhook.d.ts
CHANGED
|
@@ -15,9 +15,9 @@ export interface VerifyOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* @throws SignatureError when the signature is missing, wrong or too old, or the body is not an event
|
|
17
17
|
*/
|
|
18
|
-
export declare function constructEvent(payload: string |
|
|
18
|
+
export declare function constructEvent(payload: string | Uint8Array, signatureHeader: string | string[] | null | undefined, secret: string, options?: VerifyOptions): WebhookEvent;
|
|
19
19
|
/** @throws SignatureError */
|
|
20
|
-
export declare function verify(payload: string |
|
|
20
|
+
export declare function verify(payload: string | Uint8Array, signatureHeader: string | string[] | null | undefined, secret: string, options?: VerifyOptions): void;
|
|
21
21
|
export declare const Webhook: {
|
|
22
22
|
constructEvent: typeof constructEvent;
|
|
23
23
|
verify: typeof verify;
|
package/dist/esm/webhook.js
CHANGED
|
@@ -11,7 +11,7 @@ export const DEFAULT_TOLERANCE = 300; // seconds between the signature's time an
|
|
|
11
11
|
* @throws SignatureError when the signature is missing, wrong or too old, or the body is not an event
|
|
12
12
|
*/
|
|
13
13
|
export function constructEvent(payload, signatureHeader, secret, options = {}) {
|
|
14
|
-
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
14
|
+
const body = typeof payload === 'string' ? payload : Buffer.from(payload).toString('utf8');
|
|
15
15
|
verify(body, signatureHeader, secret, options);
|
|
16
16
|
let event;
|
|
17
17
|
try {
|
|
@@ -51,7 +51,7 @@ export function verify(payload, signatureHeader, secret, options = {}) {
|
|
|
51
51
|
if (tolerance > 0 && Math.abs(now - timestamp) > tolerance) {
|
|
52
52
|
throw new SignatureError('The webhook signature is too old.');
|
|
53
53
|
}
|
|
54
|
-
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
54
|
+
const body = typeof payload === 'string' ? payload : Buffer.from(payload).toString('utf8');
|
|
55
55
|
const expected = Buffer.from(createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex'));
|
|
56
56
|
for (const signature of signatures) {
|
|
57
57
|
const given = Buffer.from(signature);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kumpara",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The official Node.js SDK for Kumpara, the Norwegian invoicing API: create and send invoices with KID, PDF and webhooks from your own code.",
|
|
5
5
|
"keywords": ["kumpara", "invoice", "invoicing", "faktura", "kid", "norway", "webhooks", "sdk", "api-client"],
|
|
6
6
|
"homepage": "https://kumpara.no/docs",
|