@peable.to/sdk 0.2.2 → 0.2.3-oxy-one.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/dist/cjs/resources/billing.js +3 -0
- package/dist/cjs/resources/webhooks.js +12 -1
- package/dist/esm/package.json +1 -0
- package/dist/esm/resources/billing.js +3 -0
- package/dist/esm/resources/webhooks.js +12 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/resources/billing.d.ts +5 -2
- package/package.json +5 -3
|
@@ -15,6 +15,9 @@ class BillingResource {
|
|
|
15
15
|
createPortalSession(params, options) {
|
|
16
16
|
return this.client.request('POST', '/v1/billing/portal_sessions', { body: params, idempotencyKey: options.idempotencyKey });
|
|
17
17
|
}
|
|
18
|
+
retrieveCheckout(ref) { return this.client.request('GET', `/v1/billing/checkout_sessions/${encodeURIComponent(ref)}`); }
|
|
19
|
+
retrievePaidInvoice(subscriptionRef, invoiceRef) { return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(subscriptionRef)}/paid_invoices/${encodeURIComponent(invoiceRef)}`); }
|
|
20
|
+
retrieveInvoiceState(subscriptionRef, invoiceRef) { return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(subscriptionRef)}/invoice_states/${encodeURIComponent(invoiceRef)}`); }
|
|
18
21
|
retrieveSubscription(ref) {
|
|
19
22
|
return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(ref)}`);
|
|
20
23
|
}
|
|
@@ -20,6 +20,7 @@ const WEBHOOK_EVENT_TYPES = {
|
|
|
20
20
|
'payment_intent.partially_refunded': true,
|
|
21
21
|
'payment_intent.disputed': true,
|
|
22
22
|
'payment_intent.dispute_closed': true,
|
|
23
|
+
'billing.observation.updated': true,
|
|
23
24
|
'connected_account.updated': true,
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
@@ -32,7 +33,7 @@ function isWebhookEventShape(value) {
|
|
|
32
33
|
if (typeof value !== 'object' || value === null)
|
|
33
34
|
return false;
|
|
34
35
|
const candidate = value;
|
|
35
|
-
|
|
36
|
+
const valid = (typeof candidate.id === 'string' &&
|
|
36
37
|
candidate.object === 'event' &&
|
|
37
38
|
typeof candidate.type === 'string' &&
|
|
38
39
|
Object.prototype.hasOwnProperty.call(WEBHOOK_EVENT_TYPES, candidate.type) &&
|
|
@@ -40,6 +41,16 @@ function isWebhookEventShape(value) {
|
|
|
40
41
|
typeof candidate.data === 'object' &&
|
|
41
42
|
candidate.data !== null &&
|
|
42
43
|
'object' in candidate.data);
|
|
44
|
+
if (!valid)
|
|
45
|
+
return false;
|
|
46
|
+
if (candidate.type === 'billing.observation.updated') {
|
|
47
|
+
const data = candidate.data?.object;
|
|
48
|
+
if (!data || typeof data !== 'object')
|
|
49
|
+
return false;
|
|
50
|
+
const v = data;
|
|
51
|
+
return v.object === 'billing_observation' && (v.resourceKind === 'subscription' || v.resourceKind === 'invoice') && typeof v.resourceId === 'string' && v.resourceId.length > 0 && typeof v.revision === 'number' && Number.isSafeInteger(v.revision) && v.revision > 0 && typeof v.observedAt === 'string' && Number.isFinite(Date.parse(v.observedAt)) && Object.keys(v).every(k => ['object', 'resourceKind', 'resourceId', 'revision', 'observedAt'].includes(k));
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
43
54
|
}
|
|
44
55
|
class WebhooksResource {
|
|
45
56
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -12,6 +12,9 @@ export class BillingResource {
|
|
|
12
12
|
createPortalSession(params, options) {
|
|
13
13
|
return this.client.request('POST', '/v1/billing/portal_sessions', { body: params, idempotencyKey: options.idempotencyKey });
|
|
14
14
|
}
|
|
15
|
+
retrieveCheckout(ref) { return this.client.request('GET', `/v1/billing/checkout_sessions/${encodeURIComponent(ref)}`); }
|
|
16
|
+
retrievePaidInvoice(subscriptionRef, invoiceRef) { return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(subscriptionRef)}/paid_invoices/${encodeURIComponent(invoiceRef)}`); }
|
|
17
|
+
retrieveInvoiceState(subscriptionRef, invoiceRef) { return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(subscriptionRef)}/invoice_states/${encodeURIComponent(invoiceRef)}`); }
|
|
15
18
|
retrieveSubscription(ref) {
|
|
16
19
|
return this.client.request('GET', `/v1/billing/subscriptions/${encodeURIComponent(ref)}`);
|
|
17
20
|
}
|
|
@@ -17,6 +17,7 @@ const WEBHOOK_EVENT_TYPES = {
|
|
|
17
17
|
'payment_intent.partially_refunded': true,
|
|
18
18
|
'payment_intent.disputed': true,
|
|
19
19
|
'payment_intent.dispute_closed': true,
|
|
20
|
+
'billing.observation.updated': true,
|
|
20
21
|
'connected_account.updated': true,
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
@@ -29,7 +30,7 @@ function isWebhookEventShape(value) {
|
|
|
29
30
|
if (typeof value !== 'object' || value === null)
|
|
30
31
|
return false;
|
|
31
32
|
const candidate = value;
|
|
32
|
-
|
|
33
|
+
const valid = (typeof candidate.id === 'string' &&
|
|
33
34
|
candidate.object === 'event' &&
|
|
34
35
|
typeof candidate.type === 'string' &&
|
|
35
36
|
Object.prototype.hasOwnProperty.call(WEBHOOK_EVENT_TYPES, candidate.type) &&
|
|
@@ -37,6 +38,16 @@ function isWebhookEventShape(value) {
|
|
|
37
38
|
typeof candidate.data === 'object' &&
|
|
38
39
|
candidate.data !== null &&
|
|
39
40
|
'object' in candidate.data);
|
|
41
|
+
if (!valid)
|
|
42
|
+
return false;
|
|
43
|
+
if (candidate.type === 'billing.observation.updated') {
|
|
44
|
+
const data = candidate.data?.object;
|
|
45
|
+
if (!data || typeof data !== 'object')
|
|
46
|
+
return false;
|
|
47
|
+
const v = data;
|
|
48
|
+
return v.object === 'billing_observation' && (v.resourceKind === 'subscription' || v.resourceKind === 'invoice') && typeof v.resourceId === 'string' && v.resourceId.length > 0 && typeof v.revision === 'number' && Number.isSafeInteger(v.revision) && v.revision > 0 && typeof v.observedAt === 'string' && Number.isFinite(Date.parse(v.observedAt)) && Object.keys(v).every(k => ['object', 'resourceKind', 'resourceId', 'revision', 'observedAt'].includes(k));
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
40
51
|
}
|
|
41
52
|
export class WebhooksResource {
|
|
42
53
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BillingResource } from './resources/billing';
|
|
2
2
|
export type { BillingRequestOptions } from './resources/billing';
|
|
3
|
-
export type { BillingCustomer, BillingHostedSession, BillingSubscription, CreateBillingCheckoutParams, CreateBillingPortalParams, EnsureBillingCustomerParams } from '@peable.to/shared-types';
|
|
3
|
+
export type { BillingObservation, BillingCustomer, BillingHostedSession, BillingCheckoutSession, BillingCheckoutObservation, BillingPaidInvoice, BillingInvoiceState, BillingSubscription, CreateBillingCheckoutParams, CreateBillingPortalParams, EnsureBillingCustomerParams } from '@peable.to/shared-types';
|
|
4
4
|
import { type PeableConfig } from './core/config';
|
|
5
5
|
import { PaymentIntentsResource } from './resources/paymentIntents';
|
|
6
6
|
import { PaymentLinksResource } from './resources/paymentLinks';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BillingCustomer, BillingHostedSession, BillingSubscription, CreateBillingCheckoutParams, CreateBillingPortalParams, EnsureBillingCustomerParams } from '@peable.to/shared-types';
|
|
1
|
+
import type { BillingCustomer, BillingHostedSession, BillingCheckoutSession, BillingCheckoutObservation, BillingPaidInvoice, BillingInvoiceState, BillingSubscription, CreateBillingCheckoutParams, CreateBillingPortalParams, EnsureBillingCustomerParams } from '@peable.to/shared-types';
|
|
2
2
|
import type { RestClient } from '../core/client';
|
|
3
3
|
export interface BillingRequestOptions {
|
|
4
4
|
idempotencyKey: string;
|
|
@@ -8,8 +8,11 @@ export declare class BillingResource {
|
|
|
8
8
|
private readonly client;
|
|
9
9
|
constructor(client: RestClient);
|
|
10
10
|
ensureCustomer(params: EnsureBillingCustomerParams, options: BillingRequestOptions): Promise<BillingCustomer>;
|
|
11
|
-
createCheckoutSession(params: CreateBillingCheckoutParams, options: BillingRequestOptions): Promise<
|
|
11
|
+
createCheckoutSession(params: CreateBillingCheckoutParams, options: BillingRequestOptions): Promise<BillingCheckoutSession>;
|
|
12
12
|
createPortalSession(params: CreateBillingPortalParams, options: BillingRequestOptions): Promise<BillingHostedSession>;
|
|
13
|
+
retrieveCheckout(ref: string): Promise<BillingCheckoutObservation>;
|
|
14
|
+
retrievePaidInvoice(subscriptionRef: string, invoiceRef: string): Promise<BillingPaidInvoice>;
|
|
15
|
+
retrieveInvoiceState(subscriptionRef: string, invoiceRef: string): Promise<BillingInvoiceState>;
|
|
13
16
|
retrieveSubscription(ref: string): Promise<BillingSubscription>;
|
|
14
17
|
cancelAtPeriodEnd(ref: string, options: BillingRequestOptions): Promise<BillingSubscription>;
|
|
15
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peable.to/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3-oxy-one.0",
|
|
4
4
|
"description": "Peable SDK — a Stripe-ergonomics TypeScript client over the Peable Gateway REST + realtime contract. Server entry (`@peable.to/sdk`) mints Oxy service tokens from an ApplicationCredential and exposes paymentIntents/paymentLinks/checkout.sessions/webhooks; browser entry (`@peable.to/sdk/checkout`) is the anonymous payer-side client core.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"source": "src/index.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org/",
|
|
13
|
+
"tag": "oxy-one"
|
|
12
14
|
},
|
|
13
15
|
"exports": {
|
|
14
16
|
".": {
|
|
@@ -71,7 +73,7 @@
|
|
|
71
73
|
"prepublishOnly": "bun run clean && bun run build"
|
|
72
74
|
},
|
|
73
75
|
"dependencies": {
|
|
74
|
-
"@peable.to/shared-types": "
|
|
76
|
+
"@peable.to/shared-types": "0.3.1-oxy-one.0",
|
|
75
77
|
"qrcode-generator": "^2.0.4",
|
|
76
78
|
"socket.io-client": "^4.8.3"
|
|
77
79
|
},
|