@klingis/sdk 0.5.0 → 0.6.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/README.md +17 -8
- package/dist/generated/events/events.d.ts +1 -1
- package/dist/generated/events/events.js +1 -1
- package/dist/generated/klingAPI.schemas.d.ts +813 -0
- package/dist/generated/klingAPI.schemas.d.ts.map +1 -1
- package/dist/generated/payment-methods/payment-methods.d.ts +15 -3
- package/dist/generated/payment-methods/payment-methods.d.ts.map +1 -1
- package/dist/generated/payment-methods/payment-methods.js +1 -1
- package/dist/generated/payment-methods/payment-methods.js.map +1 -1
- package/dist/generated/products/products.d.ts +87 -1
- package/dist/generated/products/products.d.ts.map +1 -1
- package/dist/generated/products/products.js +27 -0
- package/dist/generated/products/products.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @klingis/sdk
|
|
|
12
12
|
|
|
13
13
|
## Quickstart
|
|
14
14
|
|
|
15
|
-
You need a Kling API key. Test keys (`sk_test_...`) are available right away from [kling.is/dashboard/api-keys](https://kling.is/dashboard/api-keys), or run `npx @klingis/cli init` and it writes `KLING_SECRET_KEY` to `.env.local` for you. Keep the key on your server; never ship it to the browser.
|
|
15
|
+
You need a Kling API key. Test keys (`sk_test_...`) are available right away from [kling.is/dashboard/api-keys](https://kling.is/dashboard/api-keys), or run `npx @klingis/cli init` and it writes `KLING_SECRET_KEY` to `.env.local` for you. If your account can already take live payments, `init` writes a live key (`sk_live_...`): check the prefix before you develop against it. Keep the key on your server; never ship it to the browser.
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
import { configure, postV1CheckoutSessions } from "@klingis/sdk";
|
|
@@ -20,15 +20,22 @@ import { configure, postV1CheckoutSessions } from "@klingis/sdk";
|
|
|
20
20
|
// Once, at startup
|
|
21
21
|
configure({
|
|
22
22
|
baseUrl: "https://api.kling.is",
|
|
23
|
-
headers: {
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${process.env.KLING_SECRET_KEY}`,
|
|
25
|
+
"Content-Type": "application/json", // required, see below
|
|
26
|
+
},
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
// Create a checkout session for 5.000 kr.
|
|
27
|
-
const res = await postV1CheckoutSessions(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const res = await postV1CheckoutSessions(
|
|
31
|
+
{
|
|
32
|
+
amount: 5000, // ISK has no decimals: 5000 means 5.000 kr.
|
|
33
|
+
currency: "ISK",
|
|
34
|
+
success_url: "https://example.is/thanks",
|
|
35
|
+
},
|
|
36
|
+
// Optional: makes a retry safe (same key, same body, same response)
|
|
37
|
+
{ headers: { "Idempotency-Key": "order-1042" } },
|
|
38
|
+
);
|
|
32
39
|
|
|
33
40
|
if (res.status === 200) {
|
|
34
41
|
// Send the customer to res.data.url, or open the overlay in the
|
|
@@ -39,7 +46,9 @@ if (res.status === 200) {
|
|
|
39
46
|
}
|
|
40
47
|
```
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
Keep the `Content-Type` header in `configure`. This version of the SDK does not send it by itself, and without it the API ignores the request body: a checkout fails with a 400, a PATCH changes nothing, and a partial refund (`amount`) refunds the full amount.
|
|
50
|
+
|
|
51
|
+
Every function returns `{ data, status, headers }`. Check `status` before reading `data`. Error responses have the shape `{ error: { type, message, code } }`, where `code` is a descriptive string such as `invalid_cursor`. A declined card is not an error response: `postV1PaymentIntents` returns 200 with `data.status` set to `"failed"` and the reason in `data.error.code` (for example `card_declined_insufficient_funds`). The money is taken only when `data.status` is `"captured"`.
|
|
43
52
|
|
|
44
53
|
Function names follow the HTTP method and path: `POST /v1/checkout/sessions` is `postV1CheckoutSessions`, `GET /v1/customers/{id}` is `getV1CustomersById`, and so on. Your editor's autocomplete on the `@klingis/sdk` import lists them all.
|
|
45
54
|
|
|
@@ -17,7 +17,7 @@ export type getV1EventsResponseSuccess = (getV1EventsResponse200) & {
|
|
|
17
17
|
export type getV1EventsResponse = (getV1EventsResponseSuccess);
|
|
18
18
|
export declare const getGetV1EventsUrl: (params: GetV1EventsParams) => string;
|
|
19
19
|
/**
|
|
20
|
-
* List events from the event ledger. Use the 'after' parameter to poll for new events since a given timestamp.
|
|
20
|
+
* List events from the event ledger. Use the 'after' parameter to poll for new events since a given timestamp. An event is stamped when it is written and becomes visible when its transaction commits, so polling with 'after' is best-effort: overlap your window by a few seconds and dedupe by event id.
|
|
21
21
|
* @summary List recent events
|
|
22
22
|
*/
|
|
23
23
|
export declare const getV1Events: (params: GetV1EventsParams, options?: Parameters<typeof customFetch>[1]) => Promise<getV1EventsResponse>;
|
|
@@ -11,7 +11,7 @@ export const getGetV1EventsUrl = (params) => {
|
|
|
11
11
|
return stringifiedParams.length > 0 ? `http://localhost:3001/v1/events?${stringifiedParams}` : `http://localhost:3001/v1/events`;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* List events from the event ledger. Use the 'after' parameter to poll for new events since a given timestamp.
|
|
14
|
+
* List events from the event ledger. Use the 'after' parameter to poll for new events since a given timestamp. An event is stamped when it is written and becomes visible when its transaction commits, so polling with 'after' is best-effort: overlap your window by a few seconds and dedupe by event id.
|
|
15
15
|
* @summary List recent events
|
|
16
16
|
*/
|
|
17
17
|
export const getV1Events = async (params, options) => {
|