@paykit-sdk/polar 1.0.1-alpha.2 → 1.0.1-alpha.4
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/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +12 -13
- package/dist/index.mjs +5 -5
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { PayKitProvider } from '@paykit-sdk/core
|
|
2
|
-
import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
|
|
3
|
-
import { PaykitProviderOptions } from '@paykit-sdk/core/src/types';
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core';
|
|
4
2
|
import { SDKOptions } from '@polar-sh/sdk';
|
|
5
3
|
|
|
6
4
|
interface PolarConfig extends PaykitProviderOptions<SDKOptions> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { PayKitProvider } from '@paykit-sdk/core
|
|
2
|
-
import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
|
|
3
|
-
import { PaykitProviderOptions } from '@paykit-sdk/core/src/types';
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core';
|
|
4
2
|
import { SDKOptions } from '@polar-sh/sdk';
|
|
5
3
|
|
|
6
4
|
interface PolarConfig extends PaykitProviderOptions<SDKOptions> {
|
package/dist/index.js
CHANGED
|
@@ -26,13 +26,12 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/polar-provider.ts
|
|
29
|
-
var
|
|
30
|
-
var import_webhook = require("@paykit-sdk/core/src/tools/webhook");
|
|
29
|
+
var import_core2 = require("@paykit-sdk/core");
|
|
31
30
|
var import_sdk = require("@polar-sh/sdk");
|
|
32
|
-
var import_webhooks = require("@polar-sh/sdk/
|
|
31
|
+
var import_webhooks = require("@polar-sh/sdk/webhooks");
|
|
33
32
|
|
|
34
33
|
// lib/mapper.ts
|
|
35
|
-
var
|
|
34
|
+
var import_core = require("@paykit-sdk/core");
|
|
36
35
|
var toPaykitCheckout = (checkout) => {
|
|
37
36
|
return {
|
|
38
37
|
id: checkout.id,
|
|
@@ -52,7 +51,7 @@ var toPaykitSubscription = (subscription) => {
|
|
|
52
51
|
return {
|
|
53
52
|
id: subscription.id,
|
|
54
53
|
customer_id: subscription.customerId,
|
|
55
|
-
status: (0,
|
|
54
|
+
status: (0, import_core.toPaykitSubscriptionStatus)(subscription.status),
|
|
56
55
|
current_period_start: new Date(subscription.currentPeriodStart),
|
|
57
56
|
current_period_end: new Date(subscription.currentPeriodEnd)
|
|
58
57
|
};
|
|
@@ -117,7 +116,7 @@ var PolarProvider = class {
|
|
|
117
116
|
*/
|
|
118
117
|
this.handleWebhook = async (params) => {
|
|
119
118
|
const { body, headers, webhookSecret } = params;
|
|
120
|
-
const webhookHeaders = (0,
|
|
119
|
+
const webhookHeaders = (0, import_core2.headersExtractor)(headers, ["webhook-id", "webhook-timestamp", "webhook-signature"]).reduce(
|
|
121
120
|
(acc, kv) => {
|
|
122
121
|
acc[kv.key] = Array.isArray(kv.value) ? kv.value.join(",") : kv.value;
|
|
123
122
|
return acc;
|
|
@@ -129,24 +128,24 @@ var PolarProvider = class {
|
|
|
129
128
|
const timestamp = webhookHeaders["webhook-timestamp"];
|
|
130
129
|
if (webhookEvent.type === "subscription.updated") {
|
|
131
130
|
const subscription = await this.retrieveSubscription(webhookEvent.data.id);
|
|
132
|
-
return (0,
|
|
131
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.updated", created: parseInt(timestamp), id, data: subscription });
|
|
133
132
|
} else if (webhookEvent.type === "subscription.created") {
|
|
134
133
|
const subscription = await this.retrieveSubscription(webhookEvent.data.id);
|
|
135
|
-
return (0,
|
|
134
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.created", created: parseInt(timestamp), id, data: subscription });
|
|
136
135
|
} else if (webhookEvent.type === "subscription.revoked") {
|
|
137
136
|
const subscription = await this.retrieveSubscription(webhookEvent.data.id);
|
|
138
|
-
return (0,
|
|
137
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.canceled", created: parseInt(timestamp), id, data: subscription });
|
|
139
138
|
} else if (webhookEvent.type === "customer.created") {
|
|
140
139
|
const customer = await this.retrieveCustomer(webhookEvent.data.id);
|
|
141
|
-
return (0,
|
|
140
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.created", created: parseInt(timestamp), id, data: customer });
|
|
142
141
|
} else if (webhookEvent.type === "customer.updated") {
|
|
143
142
|
const customer = await this.retrieveCustomer(webhookEvent.data.id);
|
|
144
|
-
return (0,
|
|
143
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.updated", created: parseInt(timestamp), id, data: customer });
|
|
145
144
|
} else if (webhookEvent.type === "customer.deleted") {
|
|
146
|
-
return (0,
|
|
145
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.deleted", created: parseInt(timestamp), id, data: null });
|
|
147
146
|
} else if (webhookEvent.type === "checkout.created") {
|
|
148
147
|
const checkout = await this.retrieveCheckout(webhookEvent.data.id);
|
|
149
|
-
return (0,
|
|
148
|
+
return (0, import_core2.toPaykitEvent)({ type: "checkout.created", created: parseInt(timestamp), id, data: checkout });
|
|
150
149
|
}
|
|
151
150
|
throw new Error(`Unknown event type: ${webhookEvent.type}`);
|
|
152
151
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/polar-provider.ts
|
|
2
2
|
import {
|
|
3
|
-
toPaykitEvent
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
toPaykitEvent,
|
|
4
|
+
headersExtractor
|
|
5
|
+
} from "@paykit-sdk/core";
|
|
6
6
|
import { Polar, ServerList } from "@polar-sh/sdk";
|
|
7
|
-
import { validateEvent } from "@polar-sh/sdk/
|
|
7
|
+
import { validateEvent } from "@polar-sh/sdk/webhooks";
|
|
8
8
|
|
|
9
9
|
// lib/mapper.ts
|
|
10
10
|
import {
|
|
11
11
|
toPaykitSubscriptionStatus
|
|
12
|
-
} from "@paykit-sdk/core
|
|
12
|
+
} from "@paykit-sdk/core";
|
|
13
13
|
var toPaykitCheckout = (checkout) => {
|
|
14
14
|
return {
|
|
15
15
|
id: checkout.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/polar",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.4",
|
|
4
4
|
"description": "Polar provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
11
15
|
"keywords": [
|
|
12
16
|
"polar",
|
|
13
17
|
"paykit",
|
|
@@ -25,7 +29,7 @@
|
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"tsup": "^8.0.0",
|
|
27
31
|
"typescript": "^5.0.0",
|
|
28
|
-
"@paykit-sdk/core": "
|
|
32
|
+
"@paykit-sdk/core": "workspace:*"
|
|
29
33
|
},
|
|
30
34
|
"publishConfig": {
|
|
31
35
|
"access": "public"
|
|
@@ -36,8 +40,5 @@
|
|
|
36
40
|
},
|
|
37
41
|
"bugs": {
|
|
38
42
|
"url": "https://github.com/devodii/paykit/issues"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "tsup src/index.ts --format cjs,esm --dts"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|