@paykit-sdk/polar 1.1.7 → 1.1.9

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
1
+ import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, HandleWebhookParams, WebhookEventPayload } from '@paykit-sdk/core';
2
2
  import { SDKOptions } from '@polar-sh/sdk';
3
3
 
4
4
  interface PolarConfig extends PaykitProviderOptions<SDKOptions> {
@@ -29,7 +29,7 @@ declare class PolarProvider implements PayKitProvider {
29
29
  /**
30
30
  * Webhook management
31
31
  */
32
- handleWebhook: (params: $ExtWebhookHandlerConfig) => Promise<WebhookEventPayload>;
32
+ handleWebhook: (params: HandleWebhookParams) => Promise<WebhookEventPayload>;
33
33
  }
34
34
 
35
35
  declare const createPolar: (config: PolarConfig) => PolarProvider;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
1
+ import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, HandleWebhookParams, WebhookEventPayload } from '@paykit-sdk/core';
2
2
  import { SDKOptions } from '@polar-sh/sdk';
3
3
 
4
4
  interface PolarConfig extends PaykitProviderOptions<SDKOptions> {
@@ -29,7 +29,7 @@ declare class PolarProvider implements PayKitProvider {
29
29
  /**
30
30
  * Webhook management
31
31
  */
32
- handleWebhook: (params: $ExtWebhookHandlerConfig) => Promise<WebhookEventPayload>;
32
+ handleWebhook: (params: HandleWebhookParams) => Promise<WebhookEventPayload>;
33
33
  }
34
34
 
35
35
  declare const createPolar: (config: PolarConfig) => PolarProvider;
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  polar: () => polar
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
+ var import_core3 = require("@paykit-sdk/core");
27
28
 
28
29
  // src/polar-provider.ts
29
30
  var import_core2 = require("@paykit-sdk/core");
@@ -70,7 +71,8 @@ var toPaykitInvoice = (invoice) => {
70
71
  amount: invoice.totalAmount,
71
72
  currency: invoice.currency,
72
73
  metadata: (0, import_core.stringifyObjectValues)({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
73
- customer_id: invoice.customerId
74
+ customer_id: invoice.customerId,
75
+ billing_mode: invoice.billingMode
74
76
  };
75
77
  };
76
78
 
@@ -153,25 +155,17 @@ var PolarProvider = class {
153
155
  type: "$invoicePaid",
154
156
  created: parseInt(timestamp),
155
157
  id,
156
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
158
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "one_time" })
157
159
  });
158
160
  },
159
161
  "order.created": (data2) => {
160
162
  const { billingReason, metadata, status } = data2;
161
- if (billingReason == "subscription_create") {
163
+ if (["subscription_create", "subscription_cycle"].includes(billingReason)) {
162
164
  return (0, import_core2.toPaykitEvent)({
163
165
  type: "$invoicePaid",
164
166
  created: parseInt(timestamp),
165
167
  id,
166
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
167
- });
168
- }
169
- if (billingReason == "subscription_cycle") {
170
- return (0, import_core2.toPaykitEvent)({
171
- type: "$invoicePaid",
172
- created: parseInt(timestamp),
173
- id,
174
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
168
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "recurring" })
175
169
  });
176
170
  }
177
171
  return null;
@@ -217,10 +211,9 @@ var createPolar = (config) => {
217
211
  return new PolarProvider(config);
218
212
  };
219
213
  var polar = () => {
220
- const accessToken = process.env.POLAR_ACCESS_TOKEN;
214
+ const envVars = (0, import_core3.validateEnvVars)(["POLAR_ACCESS_TOKEN"], process.env);
221
215
  const isDev = process.env.NODE_ENV === "development";
222
- if (!accessToken) throw new Error("POLAR_ACCESS_TOKEN is not set");
223
- return createPolar({ debug: true, accessToken, server: isDev ? "sandbox" : "production" });
216
+ return createPolar({ debug: true, accessToken: envVars.POLAR_ACCESS_TOKEN, server: isDev ? "sandbox" : "production" });
224
217
  };
225
218
  // Annotate the CommonJS export names for ESM import in node:
226
219
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ // src/index.ts
2
+ import { validateEnvVars } from "@paykit-sdk/core";
3
+
1
4
  // src/polar-provider.ts
2
5
  import {
3
6
  toPaykitEvent,
@@ -48,7 +51,8 @@ var toPaykitInvoice = (invoice) => {
48
51
  amount: invoice.totalAmount,
49
52
  currency: invoice.currency,
50
53
  metadata: stringifyObjectValues({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
51
- customer_id: invoice.customerId
54
+ customer_id: invoice.customerId,
55
+ billing_mode: invoice.billingMode
52
56
  };
53
57
  };
54
58
 
@@ -131,25 +135,17 @@ var PolarProvider = class {
131
135
  type: "$invoicePaid",
132
136
  created: parseInt(timestamp),
133
137
  id,
134
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
138
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "one_time" })
135
139
  });
136
140
  },
137
141
  "order.created": (data2) => {
138
142
  const { billingReason, metadata, status } = data2;
139
- if (billingReason == "subscription_create") {
140
- return toPaykitEvent({
141
- type: "$invoicePaid",
142
- created: parseInt(timestamp),
143
- id,
144
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
145
- });
146
- }
147
- if (billingReason == "subscription_cycle") {
143
+ if (["subscription_create", "subscription_cycle"].includes(billingReason)) {
148
144
  return toPaykitEvent({
149
145
  type: "$invoicePaid",
150
146
  created: parseInt(timestamp),
151
147
  id,
152
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
148
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "recurring" })
153
149
  });
154
150
  }
155
151
  return null;
@@ -195,10 +191,9 @@ var createPolar = (config) => {
195
191
  return new PolarProvider(config);
196
192
  };
197
193
  var polar = () => {
198
- const accessToken = process.env.POLAR_ACCESS_TOKEN;
194
+ const envVars = validateEnvVars(["POLAR_ACCESS_TOKEN"], process.env);
199
195
  const isDev = process.env.NODE_ENV === "development";
200
- if (!accessToken) throw new Error("POLAR_ACCESS_TOKEN is not set");
201
- return createPolar({ debug: true, accessToken, server: isDev ? "sandbox" : "production" });
196
+ return createPolar({ debug: true, accessToken: envVars.POLAR_ACCESS_TOKEN, server: isDev ? "sandbox" : "production" });
202
197
  };
203
198
  export {
204
199
  createPolar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/polar",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Polar provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -24,7 +24,7 @@
24
24
  "@polar-sh/sdk": "^0.33.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "@paykit-sdk/core": "^1.1.5"
27
+ "@paykit-sdk/core": "^1.1.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@paykit-sdk/core": "workspace:*",