@minipim/sdk 0.2.0 → 0.3.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/README.md +3 -1
- package/dist/attributes.cjs +80 -0
- package/dist/attributes.d.cts +48 -0
- package/dist/attributes.d.ts +12 -11
- package/dist/attributes.js +46 -71
- package/dist/index.cjs +163 -0
- package/dist/index.d.cts +132 -0
- package/dist/index.d.ts +128 -13
- package/dist/index.js +117 -16
- package/dist/openapi.cjs +18 -0
- package/dist/openapi.d.cts +7204 -0
- package/dist/openapi.d.ts +345 -9
- package/dist/openapi.js +0 -6
- package/dist/webhook-edge.cjs +68 -0
- package/dist/webhook-edge.d.cts +26 -0
- package/dist/webhook-edge.d.ts +6 -4
- package/dist/webhook-edge.js +40 -31
- package/dist/{webhook-shared.d.ts → webhook-shared-CjMkFYVb.d.cts} +3 -6
- package/dist/webhook-shared-CjMkFYVb.d.ts +25 -0
- package/dist/webhook.cjs +53 -0
- package/dist/webhook.d.cts +26 -0
- package/dist/webhook.d.ts +5 -4
- package/dist/webhook.js +27 -39
- package/package.json +45 -13
- package/dist/attributes.d.ts.map +0 -1
- package/dist/attributes.js.map +0 -1
- package/dist/client.d.ts +0 -66
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/errors.d.ts +0 -27
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -30
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/openapi.d.ts.map +0 -1
- package/dist/openapi.js.map +0 -1
- package/dist/paginate.d.ts +0 -34
- package/dist/paginate.d.ts.map +0 -1
- package/dist/paginate.js +0 -43
- package/dist/paginate.js.map +0 -1
- package/dist/webhook-edge.d.ts.map +0 -1
- package/dist/webhook-edge.js.map +0 -1
- package/dist/webhook-shared.d.ts.map +0 -1
- package/dist/webhook-shared.js +0 -30
- package/dist/webhook-shared.js.map +0 -1
- package/dist/webhook.d.ts.map +0 -1
- package/dist/webhook.js.map +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* free of `node:crypto` and WebCrypto so importing this file drags neither
|
|
4
4
|
* runtime's crypto into a bundle.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
interface VerifyWebhookOptions {
|
|
7
7
|
/**
|
|
8
8
|
* The **raw** request body — bytes or a string. **Not** the parsed JSON.
|
|
9
9
|
* Re-stringifying the parsed body reorders keys / changes whitespace and
|
|
@@ -21,8 +21,5 @@ export interface VerifyWebhookOptions {
|
|
|
21
21
|
/** The secret configured on the headless connector. */
|
|
22
22
|
secret: string;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
/** Constant-time byte compare — used by the Edge verifier (Node uses crypto.timingSafeEqual). */
|
|
27
|
-
export declare function timingSafeEqualBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
28
|
-
//# sourceMappingURL=webhook-shared.d.ts.map
|
|
24
|
+
|
|
25
|
+
export type { VerifyWebhookOptions as V };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers shared by the Node and Edge webhook verifiers. Deliberately
|
|
3
|
+
* free of `node:crypto` and WebCrypto so importing this file drags neither
|
|
4
|
+
* runtime's crypto into a bundle.
|
|
5
|
+
*/
|
|
6
|
+
interface VerifyWebhookOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The **raw** request body — bytes or a string. **Not** the parsed JSON.
|
|
9
|
+
* Re-stringifying the parsed body reorders keys / changes whitespace and
|
|
10
|
+
* the HMAC will not match.
|
|
11
|
+
*
|
|
12
|
+
* Next.js route handler: `const raw = await req.text()`.
|
|
13
|
+
* Express: `express.raw({ type: 'application/json' })`, then `req.body`.
|
|
14
|
+
*/
|
|
15
|
+
rawBody: string | Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Value of the `X-MiniPim-Signature-256` header — `sha256=<hex>`. Pass it
|
|
18
|
+
* verbatim; the verifier strips the prefix.
|
|
19
|
+
*/
|
|
20
|
+
signature: string;
|
|
21
|
+
/** The secret configured on the headless connector. */
|
|
22
|
+
secret: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type { VerifyWebhookOptions as V };
|
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/webhook.ts
|
|
21
|
+
var webhook_exports = {};
|
|
22
|
+
__export(webhook_exports, {
|
|
23
|
+
verifyMinipimWebhook: () => verifyMinipimWebhook
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(webhook_exports);
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
27
|
+
|
|
28
|
+
// src/webhook-shared.ts
|
|
29
|
+
function decodeHex(s) {
|
|
30
|
+
if (s.length % 2 !== 0) return new Uint8Array(0);
|
|
31
|
+
const out = new Uint8Array(s.length / 2);
|
|
32
|
+
for (let i = 0; i < out.length; i++) {
|
|
33
|
+
const byte = parseInt(s.slice(i * 2, i * 2 + 2), 16);
|
|
34
|
+
if (Number.isNaN(byte)) return new Uint8Array(0);
|
|
35
|
+
out[i] = byte;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function stripPrefix(sig) {
|
|
40
|
+
return sig.startsWith("sha256=") ? sig.slice(7) : sig;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/webhook.ts
|
|
44
|
+
function verifyMinipimWebhook(opts) {
|
|
45
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", opts.secret).update(opts.rawBody).digest();
|
|
46
|
+
const got = decodeHex(stripPrefix(opts.signature));
|
|
47
|
+
if (got.length !== expected.length) return false;
|
|
48
|
+
return (0, import_node_crypto.timingSafeEqual)(expected, got);
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
verifyMinipimWebhook
|
|
53
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { V as VerifyWebhookOptions } from './webhook-shared-CjMkFYVb.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verify a MiniPim webhook signature in Node. Returns `true` only when the
|
|
5
|
+
* signature is valid; returns `false` on any problem (wrong signature,
|
|
6
|
+
* malformed header, length mismatch). Constant-time comparison.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { verifyMinipimWebhook } from '@minipim/sdk/webhook';
|
|
11
|
+
*
|
|
12
|
+
* export async function POST(req: Request) {
|
|
13
|
+
* const raw = await req.text();
|
|
14
|
+
* const sig = req.headers.get('x-minipim-signature-256') ?? '';
|
|
15
|
+
* if (!verifyMinipimWebhook({ rawBody: raw, signature: sig, secret })) {
|
|
16
|
+
* return new Response('invalid signature', { status: 401 });
|
|
17
|
+
* }
|
|
18
|
+
* const event = JSON.parse(raw);
|
|
19
|
+
* // ...handle event, respond 2xx
|
|
20
|
+
* return Response.json({ ok: true });
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function verifyMinipimWebhook(opts: VerifyWebhookOptions): boolean;
|
|
25
|
+
|
|
26
|
+
export { VerifyWebhookOptions, verifyMinipimWebhook };
|
package/dist/webhook.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { V as VerifyWebhookOptions } from './webhook-shared-CjMkFYVb.js';
|
|
2
|
+
|
|
3
3
|
/**
|
|
4
4
|
* Verify a MiniPim webhook signature in Node. Returns `true` only when the
|
|
5
5
|
* signature is valid; returns `false` on any problem (wrong signature,
|
|
@@ -21,5 +21,6 @@ export type { VerifyWebhookOptions } from './webhook-shared.js';
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
declare function verifyMinipimWebhook(opts: VerifyWebhookOptions): boolean;
|
|
25
|
+
|
|
26
|
+
export { VerifyWebhookOptions, verifyMinipimWebhook };
|
package/dist/webhook.js
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* signature is valid; returns `false` on any problem (wrong signature,
|
|
15
|
-
* malformed header, length mismatch). Constant-time comparison.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { verifyMinipimWebhook } from '@minipim/sdk/webhook';
|
|
20
|
-
*
|
|
21
|
-
* export async function POST(req: Request) {
|
|
22
|
-
* const raw = await req.text();
|
|
23
|
-
* const sig = req.headers.get('x-minipim-signature-256') ?? '';
|
|
24
|
-
* if (!verifyMinipimWebhook({ rawBody: raw, signature: sig, secret })) {
|
|
25
|
-
* return new Response('invalid signature', { status: 401 });
|
|
26
|
-
* }
|
|
27
|
-
* const event = JSON.parse(raw);
|
|
28
|
-
* // ...handle event, respond 2xx
|
|
29
|
-
* return Response.json({ ok: true });
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export function verifyMinipimWebhook(opts) {
|
|
34
|
-
const expected = createHmac('sha256', opts.secret).update(opts.rawBody).digest();
|
|
35
|
-
const got = decodeHex(stripPrefix(opts.signature));
|
|
36
|
-
if (got.length !== expected.length)
|
|
37
|
-
return false;
|
|
38
|
-
return timingSafeEqual(expected, got);
|
|
1
|
+
// src/webhook.ts
|
|
2
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
3
|
+
|
|
4
|
+
// src/webhook-shared.ts
|
|
5
|
+
function decodeHex(s) {
|
|
6
|
+
if (s.length % 2 !== 0) return new Uint8Array(0);
|
|
7
|
+
const out = new Uint8Array(s.length / 2);
|
|
8
|
+
for (let i = 0; i < out.length; i++) {
|
|
9
|
+
const byte = parseInt(s.slice(i * 2, i * 2 + 2), 16);
|
|
10
|
+
if (Number.isNaN(byte)) return new Uint8Array(0);
|
|
11
|
+
out[i] = byte;
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
39
14
|
}
|
|
40
|
-
|
|
15
|
+
function stripPrefix(sig) {
|
|
16
|
+
return sig.startsWith("sha256=") ? sig.slice(7) : sig;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/webhook.ts
|
|
20
|
+
function verifyMinipimWebhook(opts) {
|
|
21
|
+
const expected = createHmac("sha256", opts.secret).update(opts.rawBody).digest();
|
|
22
|
+
const got = decodeHex(stripPrefix(opts.signature));
|
|
23
|
+
if (got.length !== expected.length) return false;
|
|
24
|
+
return timingSafeEqual(expected, got);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
verifyMinipimWebhook
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minipim/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Typed TypeScript client for the MiniPim API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Epic-Design-Labs/minipim",
|
|
@@ -11,28 +11,58 @@
|
|
|
11
11
|
},
|
|
12
12
|
"bugs": "https://github.com/Epic-Design-Labs/minipim/issues",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"main": "./dist/index.
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"import":
|
|
19
|
-
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
}
|
|
20
26
|
},
|
|
21
27
|
"./webhook": {
|
|
22
|
-
"import":
|
|
23
|
-
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/webhook.d.ts",
|
|
30
|
+
"default": "./dist/webhook.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/webhook.d.cts",
|
|
34
|
+
"default": "./dist/webhook.cjs"
|
|
35
|
+
}
|
|
24
36
|
},
|
|
25
37
|
"./webhook-edge": {
|
|
26
|
-
"import":
|
|
27
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/webhook-edge.d.ts",
|
|
40
|
+
"default": "./dist/webhook-edge.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/webhook-edge.d.cts",
|
|
44
|
+
"default": "./dist/webhook-edge.cjs"
|
|
45
|
+
}
|
|
28
46
|
},
|
|
29
47
|
"./attributes": {
|
|
30
|
-
"import":
|
|
31
|
-
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./dist/attributes.d.ts",
|
|
50
|
+
"default": "./dist/attributes.js"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./dist/attributes.d.cts",
|
|
54
|
+
"default": "./dist/attributes.cjs"
|
|
55
|
+
}
|
|
32
56
|
},
|
|
33
57
|
"./openapi": {
|
|
34
|
-
"import":
|
|
35
|
-
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/openapi.d.ts",
|
|
60
|
+
"default": "./dist/openapi.js"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./dist/openapi.d.cts",
|
|
64
|
+
"default": "./dist/openapi.cjs"
|
|
65
|
+
}
|
|
36
66
|
}
|
|
37
67
|
},
|
|
38
68
|
"files": [
|
|
@@ -53,13 +83,15 @@
|
|
|
53
83
|
},
|
|
54
84
|
"devDependencies": {
|
|
55
85
|
"openapi-typescript": "^7.5.0",
|
|
86
|
+
"tsup": "^8.5.1",
|
|
56
87
|
"typescript": "^5.7.0"
|
|
57
88
|
},
|
|
58
89
|
"publishConfig": {
|
|
59
90
|
"access": "public"
|
|
60
91
|
},
|
|
92
|
+
"module": "./dist/index.js",
|
|
61
93
|
"scripts": {
|
|
62
|
-
"build": "
|
|
94
|
+
"build": "tsup",
|
|
63
95
|
"typecheck": "tsc --noEmit",
|
|
64
96
|
"gen": "openapi-typescript https://api.minipim.com/docs/json -o src/openapi.ts"
|
|
65
97
|
}
|
package/dist/attributes.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAEvE,MAAM,WAAW,KAAK;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,iBAAiB,EAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,cAAmB,GACxB,OAAO,CAgBT;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,iBAAiB,EAC7B,IAAI,GAAE,cAAmB,GACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB;AAED,4EAA4E;AAC5E,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAUpD;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAUhE;AAED,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,SAAU,GAAG,MAAM,CAKlE"}
|
package/dist/attributes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyBH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,UAA6B,EAC7B,IAAY,EACZ,OAAuB,EAAE;IAEzB,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;IACrC,MAAM,MAAM,GAA0C;QACpD,CAAC,MAAM,EAAE,OAAO,CAAC;QACjB,CAAC,MAAM,EAAE,IAAI,CAAC;QACd,CAAC,IAAI,EAAE,OAAO,CAAC;QACf,CAAC,IAAI,EAAE,IAAI,CAAC;KACb,CAAC;IACF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;QACnE,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC,KAAK,CAAC;IAC5B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA6B,EAC7B,OAAuB,EAAE;IAEzB,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,IACE,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAQ,KAAe,CAAC,YAAY,KAAK,QAAQ;QACjD,OAAQ,KAAe,CAAC,QAAQ,KAAK,QAAQ,EAC7C,CAAC;QACD,OAAO,KAAc,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IACE,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAQ,KAAqB,CAAC,MAAM,KAAK,QAAQ;QACjD,OAAQ,KAAqB,CAAC,IAAI,KAAK,QAAQ,EAC/C,CAAC;QACD,OAAO,KAAoB,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,MAAM,GAAG,OAAO;IACxD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACnC,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/client.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin wrapper around `openapi-fetch` that pre-binds the tenancy header and
|
|
3
|
-
* (optionally) an API key. Returns the standard openapi-fetch client, so all
|
|
4
|
-
* its features (request interceptors, raw response access, etc.) work as
|
|
5
|
-
* documented at https://openapi-ts.dev/openapi-fetch/.
|
|
6
|
-
*/
|
|
7
|
-
import { type Client } from 'openapi-fetch';
|
|
8
|
-
import type { paths } from './openapi.js';
|
|
9
|
-
export interface CreateMinipimClientOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Base URL of the MiniPim API, e.g. `https://api.minipim.com`. Required.
|
|
12
|
-
* Trailing slashes are normalized.
|
|
13
|
-
*/
|
|
14
|
-
baseUrl: string;
|
|
15
|
-
/**
|
|
16
|
-
* Tenant the client speaks for. Required — every authenticated endpoint
|
|
17
|
-
* needs `x-organization-id`. API keys identify the principal, not the
|
|
18
|
-
* tenant.
|
|
19
|
-
*/
|
|
20
|
-
organizationId: string;
|
|
21
|
-
/**
|
|
22
|
-
* Bearer API key (e.g. `pim_abc123…`). Issue one in the admin under
|
|
23
|
-
* /api-keys. If you're running in dev with `PIM_AUTH=header`, omit this
|
|
24
|
-
* and set `userId` instead.
|
|
25
|
-
*/
|
|
26
|
-
apiKey?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Dev-only header (`x-pim-user-id`). Only set when the deployment is in
|
|
29
|
-
* `header` auth mode. Ignored in `jwt` / `clerk` deployments.
|
|
30
|
-
*/
|
|
31
|
-
userId?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Extra headers merged onto every request — useful for tracing IDs,
|
|
34
|
-
* feature flags, etc. Don't put auth here; use `apiKey`/`userId` so the
|
|
35
|
-
* names stay consistent.
|
|
36
|
-
*/
|
|
37
|
-
headers?: Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* Override `fetch` — pass a polyfill in Node <18 or a wrapped fetch that
|
|
40
|
-
* adds timeouts, retries, telemetry. Defaults to the global `fetch`.
|
|
41
|
-
*/
|
|
42
|
-
fetch?: typeof fetch;
|
|
43
|
-
}
|
|
44
|
-
export type MinipimClient = Client<paths>;
|
|
45
|
-
/**
|
|
46
|
-
* Create a typed MiniPim client.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* import { createMinipimClient } from '@minipim/sdk';
|
|
51
|
-
*
|
|
52
|
-
* const pim = createMinipimClient({
|
|
53
|
-
* baseUrl: 'https://api.minipim.com',
|
|
54
|
-
* organizationId: '00000000-0000-0000-0000-000000000001',
|
|
55
|
-
* apiKey: process.env.MINIPIM_API_KEY!,
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* const { data, error } = await pim.GET('/v1/products', {
|
|
59
|
-
* params: { query: { limit: 50, categoryId: '…' } },
|
|
60
|
-
* });
|
|
61
|
-
* if (error) throw new Error(error.error.message);
|
|
62
|
-
* console.log(data.hasMore, data.data.length);
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export declare function createMinipimClient(opts: CreateMinipimClientOptions): MinipimClient;
|
|
66
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAqB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,0BAA0B,GAC/B,aAAa,CAaf"}
|
package/dist/client.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin wrapper around `openapi-fetch` that pre-binds the tenancy header and
|
|
3
|
-
* (optionally) an API key. Returns the standard openapi-fetch client, so all
|
|
4
|
-
* its features (request interceptors, raw response access, etc.) work as
|
|
5
|
-
* documented at https://openapi-ts.dev/openapi-fetch/.
|
|
6
|
-
*/
|
|
7
|
-
import createClient from 'openapi-fetch';
|
|
8
|
-
/**
|
|
9
|
-
* Create a typed MiniPim client.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { createMinipimClient } from '@minipim/sdk';
|
|
14
|
-
*
|
|
15
|
-
* const pim = createMinipimClient({
|
|
16
|
-
* baseUrl: 'https://api.minipim.com',
|
|
17
|
-
* organizationId: '00000000-0000-0000-0000-000000000001',
|
|
18
|
-
* apiKey: process.env.MINIPIM_API_KEY!,
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* const { data, error } = await pim.GET('/v1/products', {
|
|
22
|
-
* params: { query: { limit: 50, categoryId: '…' } },
|
|
23
|
-
* });
|
|
24
|
-
* if (error) throw new Error(error.error.message);
|
|
25
|
-
* console.log(data.hasMore, data.data.length);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function createMinipimClient(opts) {
|
|
29
|
-
const headers = {
|
|
30
|
-
'x-organization-id': opts.organizationId,
|
|
31
|
-
...(opts.headers ?? {}),
|
|
32
|
-
};
|
|
33
|
-
if (opts.apiKey)
|
|
34
|
-
headers['Authorization'] = `Bearer ${opts.apiKey}`;
|
|
35
|
-
if (opts.userId)
|
|
36
|
-
headers['x-pim-user-id'] = opts.userId;
|
|
37
|
-
return createClient({
|
|
38
|
-
baseUrl: opts.baseUrl.replace(/\/$/, ''),
|
|
39
|
-
fetch: opts.fetch,
|
|
40
|
-
headers,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,YAA6B,MAAM,eAAe,CAAC;AAyC1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAgC;IAEhC,MAAM,OAAO,GAA2B;QACtC,mBAAmB,EAAE,IAAI,CAAC,cAAc;QACxC,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;KACxB,CAAC;IACF,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;IACpE,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAExD,OAAO,YAAY,CAAQ;QACzB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACxC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error envelope + type guard. Every MiniPim 4xx/5xx returns
|
|
3
|
-
* `{ error: { code, message, details? } }`. openapi-fetch types `res.error`
|
|
4
|
-
* as a union across a path's declared error responses, which is awkward to
|
|
5
|
-
* narrow to `.error.message`. This guard collapses that to a single shape.
|
|
6
|
-
*/
|
|
7
|
-
export interface MinipimError {
|
|
8
|
-
error: {
|
|
9
|
-
code: string;
|
|
10
|
-
message: string;
|
|
11
|
-
details?: unknown;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/** True when `value` is a MiniPim `{ error: { code, message } }` envelope. */
|
|
15
|
-
export declare function isMinipimError(value: unknown): value is MinipimError;
|
|
16
|
-
/**
|
|
17
|
-
* Pull a human-readable message out of an openapi-fetch `error` value,
|
|
18
|
-
* whatever its declared union shape. Falls back to `fallback`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const { data, error } = await pim.GET('/v1/products');
|
|
23
|
-
* if (error) throw new Error(getErrorMessage(error, 'request failed'));
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function getErrorMessage(error: unknown, fallback?: string): string;
|
|
27
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CASpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAmB,GAAG,MAAM,CAEnF"}
|
package/dist/errors.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error envelope + type guard. Every MiniPim 4xx/5xx returns
|
|
3
|
-
* `{ error: { code, message, details? } }`. openapi-fetch types `res.error`
|
|
4
|
-
* as a union across a path's declared error responses, which is awkward to
|
|
5
|
-
* narrow to `.error.message`. This guard collapses that to a single shape.
|
|
6
|
-
*/
|
|
7
|
-
/** True when `value` is a MiniPim `{ error: { code, message } }` envelope. */
|
|
8
|
-
export function isMinipimError(value) {
|
|
9
|
-
if (!value || typeof value !== 'object')
|
|
10
|
-
return false;
|
|
11
|
-
const e = value.error;
|
|
12
|
-
return (!!e &&
|
|
13
|
-
typeof e === 'object' &&
|
|
14
|
-
typeof e.code === 'string' &&
|
|
15
|
-
typeof e.message === 'string');
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Pull a human-readable message out of an openapi-fetch `error` value,
|
|
19
|
-
* whatever its declared union shape. Falls back to `fallback`.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const { data, error } = await pim.GET('/v1/products');
|
|
24
|
-
* if (error) throw new Error(getErrorMessage(error, 'request failed'));
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function getErrorMessage(error, fallback = 'request failed') {
|
|
28
|
-
return isMinipimError(error) ? error.error.message : fallback;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,8EAA8E;AAC9E,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAI,KAA6B,CAAC,KAAK,CAAC;IAC/C,OAAO,CACL,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,QAAQ;QACrB,OAAQ,CAAwB,CAAC,IAAI,KAAK,QAAQ;QAClD,OAAQ,CAA2B,CAAC,OAAO,KAAK,QAAQ,CACzD,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,QAAQ,GAAG,gBAAgB;IACzE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AAChE,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,OAAO,EACP,aAAa,EACb,WAAW,EACX,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,iBAAiB,CAAC;AAOzB,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,mBAAmB,GAGpB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,QAAQ,EACR,UAAU,GAEX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,cAAc,EACd,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,OAAO,EACP,aAAa,EACb,WAAW,GAMZ,MAAM,iBAAiB,CAAC"}
|