@dodopayments/convex 0.2.2 → 0.2.6

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.js CHANGED
@@ -22,7 +22,7 @@ class DodoPayments {
22
22
  },
23
23
  /**
24
24
  * Retrieves a URL for the customer portal.
25
- * This function is designed to be called from a public Convex query in your app.
25
+ * Requires the user to be identified via the identify function in the config.
26
26
  */
27
27
  customerPortal: async (ctx, args) => {
28
28
  const identity = await this.config.identify(ctx);
@@ -4957,351 +4957,346 @@ ZodPromise.create;
4957
4957
  ZodOptional.create;
4958
4958
  ZodNullable.create;
4959
4959
 
4960
+ // src/schemas/webhook.ts
4960
4961
  var PaymentSchema = objectType({
4961
- payload_type: literalType("Payment"),
4962
- billing: objectType({
4963
- city: stringType().nullable(),
4964
- country: stringType().nullable(),
4965
- state: stringType().nullable(),
4966
- street: stringType().nullable(),
4967
- zipcode: stringType().nullable(),
4968
- }),
4969
- brand_id: stringType(),
4970
- business_id: stringType(),
4971
- card_issuing_country: stringType().nullable(),
4972
- card_last_four: stringType().nullable(),
4973
- card_network: stringType().nullable(),
4974
- card_type: stringType().nullable(),
4975
- created_at: stringType().transform(function (d) { return new Date(d); }),
4976
- currency: stringType(),
4977
- customer: objectType({
4978
- customer_id: stringType(),
4979
- email: stringType(),
4980
- name: stringType().nullable(),
4981
- }),
4982
- digital_products_delivered: booleanType(),
4983
- discount_id: stringType().nullable(),
4984
- disputes: arrayType(objectType({
4985
- amount: stringType(),
4986
- business_id: stringType(),
4987
- created_at: stringType().transform(function (d) { return new Date(d); }),
4988
- currency: stringType(),
4989
- dispute_id: stringType(),
4990
- dispute_stage: enumType([
4991
- "pre_dispute",
4992
- "dispute_opened",
4993
- "dispute_won",
4994
- "dispute_lost",
4995
- ]),
4996
- dispute_status: enumType([
4997
- "dispute_opened",
4998
- "dispute_won",
4999
- "dispute_lost",
5000
- "dispute_accepted",
5001
- "dispute_cancelled",
5002
- "dispute_challenged",
5003
- ]),
5004
- payment_id: stringType(),
5005
- remarks: stringType().nullable(),
5006
- }))
5007
- .nullable(),
5008
- error_code: stringType().nullable(),
5009
- error_message: stringType().nullable(),
5010
- metadata: recordType(anyType()).nullable(),
5011
- payment_id: stringType(),
5012
- payment_link: stringType().nullable(),
5013
- payment_method: stringType().nullable(),
5014
- payment_method_type: stringType().nullable(),
5015
- product_cart: arrayType(objectType({
5016
- product_id: stringType(),
5017
- quantity: numberType(),
5018
- }))
5019
- .nullable(),
5020
- refunds: arrayType(objectType({
5021
- amount: numberType(),
5022
- business_id: stringType(),
5023
- created_at: stringType().transform(function (d) { return new Date(d); }),
5024
- currency: stringType(),
5025
- is_partial: booleanType(),
5026
- payment_id: stringType(),
5027
- reason: stringType().nullable(),
5028
- refund_id: stringType(),
5029
- status: enumType(["succeeded", "failed", "pending"]),
5030
- }))
5031
- .nullable(),
5032
- settlement_amount: numberType(),
5033
- settlement_currency: stringType(),
5034
- settlement_tax: numberType().nullable(),
5035
- status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
5036
- subscription_id: stringType().nullable(),
5037
- tax: numberType().nullable(),
5038
- total_amount: numberType(),
5039
- updated_at: stringType()
5040
- .transform(function (d) { return new Date(d); })
5041
- .nullable(),
5042
- });
5043
- var SubscriptionSchema = objectType({
5044
- payload_type: literalType("Subscription"),
5045
- addons: arrayType(objectType({
5046
- addon_id: stringType(),
5047
- quantity: numberType(),
5048
- }))
5049
- .nullable(),
5050
- billing: objectType({
5051
- city: stringType().nullable(),
5052
- country: stringType().nullable(),
5053
- state: stringType().nullable(),
5054
- street: stringType().nullable(),
5055
- zipcode: stringType().nullable(),
5056
- }),
5057
- cancel_at_next_billing_date: booleanType(),
5058
- cancelled_at: stringType()
5059
- .transform(function (d) { return new Date(d); })
5060
- .nullable(),
5061
- created_at: stringType().transform(function (d) { return new Date(d); }),
5062
- currency: stringType(),
5063
- customer: objectType({
5064
- customer_id: stringType(),
5065
- email: stringType(),
5066
- name: stringType().nullable(),
5067
- }),
5068
- discount_id: stringType().nullable(),
5069
- metadata: recordType(anyType()).nullable(),
5070
- next_billing_date: stringType()
5071
- .transform(function (d) { return new Date(d); })
5072
- .nullable(),
5073
- on_demand: booleanType(),
5074
- payment_frequency_count: numberType(),
5075
- payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
5076
- previous_billing_date: stringType()
5077
- .transform(function (d) { return new Date(d); })
5078
- .nullable(),
5079
- product_id: stringType(),
5080
- quantity: numberType(),
5081
- recurring_pre_tax_amount: numberType(),
5082
- status: enumType([
5083
- "pending",
5084
- "active",
5085
- "on_hold",
5086
- "paused",
5087
- "cancelled",
5088
- "expired",
5089
- "failed",
5090
- ]),
5091
- subscription_id: stringType(),
5092
- subscription_period_count: numberType(),
5093
- subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
5094
- tax_inclusive: booleanType(),
5095
- trial_period_days: numberType(),
5096
- });
5097
- var RefundSchema = objectType({
5098
- payload_type: literalType("Refund"),
5099
- amount: numberType(),
5100
- business_id: stringType(),
5101
- created_at: stringType().transform(function (d) { return new Date(d); }),
5102
- currency: stringType(),
5103
- is_partial: booleanType(),
5104
- payment_id: stringType(),
5105
- reason: stringType().nullable(),
5106
- refund_id: stringType(),
5107
- status: enumType(["succeeded", "failed", "pending"]),
5108
- });
5109
- var DisputeSchema = objectType({
5110
- payload_type: literalType("Dispute"),
5111
- amount: stringType(),
5112
- business_id: stringType(),
5113
- created_at: stringType().transform(function (d) { return new Date(d); }),
5114
- currency: stringType(),
5115
- dispute_id: stringType(),
5116
- dispute_stage: enumType([
4962
+ payload_type: literalType("Payment"),
4963
+ billing: objectType({
4964
+ city: stringType().nullable(),
4965
+ country: stringType().nullable(),
4966
+ state: stringType().nullable(),
4967
+ street: stringType().nullable(),
4968
+ zipcode: stringType().nullable()
4969
+ }),
4970
+ brand_id: stringType(),
4971
+ business_id: stringType(),
4972
+ card_issuing_country: stringType().nullable(),
4973
+ card_last_four: stringType().nullable(),
4974
+ card_network: stringType().nullable(),
4975
+ card_type: stringType().nullable(),
4976
+ created_at: stringType().transform((d) => new Date(d)),
4977
+ currency: stringType(),
4978
+ customer: objectType({
4979
+ customer_id: stringType(),
4980
+ email: stringType(),
4981
+ name: stringType().nullable()
4982
+ }),
4983
+ digital_products_delivered: booleanType(),
4984
+ discount_id: stringType().nullable(),
4985
+ disputes: arrayType(
4986
+ objectType({
4987
+ amount: stringType(),
4988
+ business_id: stringType(),
4989
+ created_at: stringType().transform((d) => new Date(d)),
4990
+ currency: stringType(),
4991
+ dispute_id: stringType(),
4992
+ dispute_stage: enumType([
5117
4993
  "pre_dispute",
5118
4994
  "dispute_opened",
5119
4995
  "dispute_won",
5120
- "dispute_lost",
5121
- ]),
5122
- dispute_status: enumType([
4996
+ "dispute_lost"
4997
+ ]),
4998
+ dispute_status: enumType([
5123
4999
  "dispute_opened",
5124
5000
  "dispute_won",
5125
5001
  "dispute_lost",
5126
5002
  "dispute_accepted",
5127
5003
  "dispute_cancelled",
5128
- "dispute_challenged",
5129
- ]),
5130
- payment_id: stringType(),
5131
- remarks: stringType().nullable(),
5004
+ "dispute_challenged"
5005
+ ]),
5006
+ payment_id: stringType(),
5007
+ remarks: stringType().nullable()
5008
+ })
5009
+ ).nullable(),
5010
+ error_code: stringType().nullable(),
5011
+ error_message: stringType().nullable(),
5012
+ metadata: recordType(anyType()).nullable(),
5013
+ payment_id: stringType(),
5014
+ payment_link: stringType().nullable(),
5015
+ payment_method: stringType().nullable(),
5016
+ payment_method_type: stringType().nullable(),
5017
+ product_cart: arrayType(
5018
+ objectType({
5019
+ product_id: stringType(),
5020
+ quantity: numberType()
5021
+ })
5022
+ ).nullable(),
5023
+ refunds: arrayType(
5024
+ objectType({
5025
+ amount: numberType(),
5026
+ business_id: stringType(),
5027
+ created_at: stringType().transform((d) => new Date(d)),
5028
+ currency: stringType(),
5029
+ is_partial: booleanType(),
5030
+ payment_id: stringType(),
5031
+ reason: stringType().nullable(),
5032
+ refund_id: stringType(),
5033
+ status: enumType(["succeeded", "failed", "pending"])
5034
+ })
5035
+ ).nullable(),
5036
+ settlement_amount: numberType(),
5037
+ settlement_currency: stringType(),
5038
+ settlement_tax: numberType().nullable(),
5039
+ status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
5040
+ subscription_id: stringType().nullable(),
5041
+ tax: numberType().nullable(),
5042
+ total_amount: numberType(),
5043
+ updated_at: stringType().transform((d) => new Date(d)).nullable()
5132
5044
  });
5133
- var LicenseKeySchema = objectType({
5134
- payload_type: literalType("LicenseKey"),
5135
- activations_limit: numberType(),
5136
- business_id: stringType(),
5137
- created_at: stringType().transform(function (d) { return new Date(d); }),
5045
+ var SubscriptionSchema = objectType({
5046
+ payload_type: literalType("Subscription"),
5047
+ addons: arrayType(
5048
+ objectType({
5049
+ addon_id: stringType(),
5050
+ quantity: numberType()
5051
+ })
5052
+ ).nullable(),
5053
+ billing: objectType({
5054
+ city: stringType().nullable(),
5055
+ country: stringType().nullable(),
5056
+ state: stringType().nullable(),
5057
+ street: stringType().nullable(),
5058
+ zipcode: stringType().nullable()
5059
+ }),
5060
+ cancel_at_next_billing_date: booleanType(),
5061
+ cancelled_at: stringType().transform((d) => new Date(d)).nullable(),
5062
+ created_at: stringType().transform((d) => new Date(d)),
5063
+ currency: stringType(),
5064
+ customer: objectType({
5138
5065
  customer_id: stringType(),
5139
- expires_at: stringType()
5140
- .transform(function (d) { return new Date(d); })
5141
- .nullable(),
5142
- id: stringType(),
5143
- instances_count: numberType(),
5144
- key: stringType(),
5145
- payment_id: stringType(),
5146
- product_id: stringType(),
5147
- status: enumType(["active", "inactive", "expired"]),
5148
- subscription_id: stringType().nullable(),
5066
+ email: stringType(),
5067
+ name: stringType().nullable()
5068
+ }),
5069
+ discount_id: stringType().nullable(),
5070
+ metadata: recordType(anyType()).nullable(),
5071
+ next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
5072
+ on_demand: booleanType(),
5073
+ payment_frequency_count: numberType(),
5074
+ payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
5075
+ previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
5076
+ product_id: stringType(),
5077
+ quantity: numberType(),
5078
+ recurring_pre_tax_amount: numberType(),
5079
+ status: enumType([
5080
+ "pending",
5081
+ "active",
5082
+ "on_hold",
5083
+ "paused",
5084
+ "cancelled",
5085
+ "expired",
5086
+ "failed"
5087
+ ]),
5088
+ subscription_id: stringType(),
5089
+ subscription_period_count: numberType(),
5090
+ subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
5091
+ tax_inclusive: booleanType(),
5092
+ trial_period_days: numberType()
5093
+ });
5094
+ var RefundSchema = objectType({
5095
+ payload_type: literalType("Refund"),
5096
+ amount: numberType(),
5097
+ business_id: stringType(),
5098
+ created_at: stringType().transform((d) => new Date(d)),
5099
+ currency: stringType(),
5100
+ is_partial: booleanType(),
5101
+ payment_id: stringType(),
5102
+ reason: stringType().nullable(),
5103
+ refund_id: stringType(),
5104
+ status: enumType(["succeeded", "failed", "pending"])
5105
+ });
5106
+ var DisputeSchema = objectType({
5107
+ payload_type: literalType("Dispute"),
5108
+ amount: stringType(),
5109
+ business_id: stringType(),
5110
+ created_at: stringType().transform((d) => new Date(d)),
5111
+ currency: stringType(),
5112
+ dispute_id: stringType(),
5113
+ dispute_stage: enumType([
5114
+ "pre_dispute",
5115
+ "dispute_opened",
5116
+ "dispute_won",
5117
+ "dispute_lost"
5118
+ ]),
5119
+ dispute_status: enumType([
5120
+ "dispute_opened",
5121
+ "dispute_won",
5122
+ "dispute_lost",
5123
+ "dispute_accepted",
5124
+ "dispute_cancelled",
5125
+ "dispute_challenged"
5126
+ ]),
5127
+ payment_id: stringType(),
5128
+ remarks: stringType().nullable()
5129
+ });
5130
+ var LicenseKeySchema = objectType({
5131
+ payload_type: literalType("LicenseKey"),
5132
+ activations_limit: numberType(),
5133
+ business_id: stringType(),
5134
+ created_at: stringType().transform((d) => new Date(d)),
5135
+ customer_id: stringType(),
5136
+ expires_at: stringType().transform((d) => new Date(d)).nullable(),
5137
+ id: stringType(),
5138
+ instances_count: numberType(),
5139
+ key: stringType(),
5140
+ payment_id: stringType(),
5141
+ product_id: stringType(),
5142
+ status: enumType(["active", "inactive", "expired"]),
5143
+ subscription_id: stringType().nullable()
5149
5144
  });
5150
5145
  var PaymentSucceededPayloadSchema = objectType({
5151
- business_id: stringType(),
5152
- type: literalType("payment.succeeded"),
5153
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5154
- data: PaymentSchema,
5146
+ business_id: stringType(),
5147
+ type: literalType("payment.succeeded"),
5148
+ timestamp: stringType().transform((d) => new Date(d)),
5149
+ data: PaymentSchema
5155
5150
  });
5156
5151
  var PaymentFailedPayloadSchema = objectType({
5157
- business_id: stringType(),
5158
- type: literalType("payment.failed"),
5159
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5160
- data: PaymentSchema,
5152
+ business_id: stringType(),
5153
+ type: literalType("payment.failed"),
5154
+ timestamp: stringType().transform((d) => new Date(d)),
5155
+ data: PaymentSchema
5161
5156
  });
5162
5157
  var PaymentProcessingPayloadSchema = objectType({
5163
- business_id: stringType(),
5164
- type: literalType("payment.processing"),
5165
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5166
- data: PaymentSchema,
5158
+ business_id: stringType(),
5159
+ type: literalType("payment.processing"),
5160
+ timestamp: stringType().transform((d) => new Date(d)),
5161
+ data: PaymentSchema
5167
5162
  });
5168
5163
  var PaymentCancelledPayloadSchema = objectType({
5169
- business_id: stringType(),
5170
- type: literalType("payment.cancelled"),
5171
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5172
- data: PaymentSchema,
5164
+ business_id: stringType(),
5165
+ type: literalType("payment.cancelled"),
5166
+ timestamp: stringType().transform((d) => new Date(d)),
5167
+ data: PaymentSchema
5173
5168
  });
5174
5169
  var RefundSucceededPayloadSchema = objectType({
5175
- business_id: stringType(),
5176
- type: literalType("refund.succeeded"),
5177
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5178
- data: RefundSchema,
5170
+ business_id: stringType(),
5171
+ type: literalType("refund.succeeded"),
5172
+ timestamp: stringType().transform((d) => new Date(d)),
5173
+ data: RefundSchema
5179
5174
  });
5180
5175
  var RefundFailedPayloadSchema = objectType({
5181
- business_id: stringType(),
5182
- type: literalType("refund.failed"),
5183
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5184
- data: RefundSchema,
5176
+ business_id: stringType(),
5177
+ type: literalType("refund.failed"),
5178
+ timestamp: stringType().transform((d) => new Date(d)),
5179
+ data: RefundSchema
5185
5180
  });
5186
5181
  var DisputeOpenedPayloadSchema = objectType({
5187
- business_id: stringType(),
5188
- type: literalType("dispute.opened"),
5189
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5190
- data: DisputeSchema,
5182
+ business_id: stringType(),
5183
+ type: literalType("dispute.opened"),
5184
+ timestamp: stringType().transform((d) => new Date(d)),
5185
+ data: DisputeSchema
5191
5186
  });
5192
5187
  var DisputeExpiredPayloadSchema = objectType({
5193
- business_id: stringType(),
5194
- type: literalType("dispute.expired"),
5195
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5196
- data: DisputeSchema,
5188
+ business_id: stringType(),
5189
+ type: literalType("dispute.expired"),
5190
+ timestamp: stringType().transform((d) => new Date(d)),
5191
+ data: DisputeSchema
5197
5192
  });
5198
5193
  var DisputeAcceptedPayloadSchema = objectType({
5199
- business_id: stringType(),
5200
- type: literalType("dispute.accepted"),
5201
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5202
- data: DisputeSchema,
5194
+ business_id: stringType(),
5195
+ type: literalType("dispute.accepted"),
5196
+ timestamp: stringType().transform((d) => new Date(d)),
5197
+ data: DisputeSchema
5203
5198
  });
5204
5199
  var DisputeCancelledPayloadSchema = objectType({
5205
- business_id: stringType(),
5206
- type: literalType("dispute.cancelled"),
5207
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5208
- data: DisputeSchema,
5200
+ business_id: stringType(),
5201
+ type: literalType("dispute.cancelled"),
5202
+ timestamp: stringType().transform((d) => new Date(d)),
5203
+ data: DisputeSchema
5209
5204
  });
5210
5205
  var DisputeChallengedPayloadSchema = objectType({
5211
- business_id: stringType(),
5212
- type: literalType("dispute.challenged"),
5213
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5214
- data: DisputeSchema,
5206
+ business_id: stringType(),
5207
+ type: literalType("dispute.challenged"),
5208
+ timestamp: stringType().transform((d) => new Date(d)),
5209
+ data: DisputeSchema
5215
5210
  });
5216
5211
  var DisputeWonPayloadSchema = objectType({
5217
- business_id: stringType(),
5218
- type: literalType("dispute.won"),
5219
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5220
- data: DisputeSchema,
5212
+ business_id: stringType(),
5213
+ type: literalType("dispute.won"),
5214
+ timestamp: stringType().transform((d) => new Date(d)),
5215
+ data: DisputeSchema
5221
5216
  });
5222
5217
  var DisputeLostPayloadSchema = objectType({
5223
- business_id: stringType(),
5224
- type: literalType("dispute.lost"),
5225
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5226
- data: DisputeSchema,
5218
+ business_id: stringType(),
5219
+ type: literalType("dispute.lost"),
5220
+ timestamp: stringType().transform((d) => new Date(d)),
5221
+ data: DisputeSchema
5227
5222
  });
5228
5223
  var SubscriptionActivePayloadSchema = objectType({
5229
- business_id: stringType(),
5230
- type: literalType("subscription.active"),
5231
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5232
- data: SubscriptionSchema,
5224
+ business_id: stringType(),
5225
+ type: literalType("subscription.active"),
5226
+ timestamp: stringType().transform((d) => new Date(d)),
5227
+ data: SubscriptionSchema
5233
5228
  });
5234
5229
  var SubscriptionOnHoldPayloadSchema = objectType({
5235
- business_id: stringType(),
5236
- type: literalType("subscription.on_hold"),
5237
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5238
- data: SubscriptionSchema,
5230
+ business_id: stringType(),
5231
+ type: literalType("subscription.on_hold"),
5232
+ timestamp: stringType().transform((d) => new Date(d)),
5233
+ data: SubscriptionSchema
5239
5234
  });
5240
5235
  var SubscriptionRenewedPayloadSchema = objectType({
5241
- business_id: stringType(),
5242
- type: literalType("subscription.renewed"),
5243
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5244
- data: SubscriptionSchema,
5236
+ business_id: stringType(),
5237
+ type: literalType("subscription.renewed"),
5238
+ timestamp: stringType().transform((d) => new Date(d)),
5239
+ data: SubscriptionSchema
5245
5240
  });
5246
5241
  var SubscriptionPausedPayloadSchema = objectType({
5247
- business_id: stringType(),
5248
- type: literalType("subscription.paused"),
5249
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5250
- data: SubscriptionSchema,
5242
+ business_id: stringType(),
5243
+ type: literalType("subscription.paused"),
5244
+ timestamp: stringType().transform((d) => new Date(d)),
5245
+ data: SubscriptionSchema
5251
5246
  });
5252
5247
  var SubscriptionPlanChangedPayloadSchema = objectType({
5253
- business_id: stringType(),
5254
- type: literalType("subscription.plan_changed"),
5255
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5256
- data: SubscriptionSchema,
5248
+ business_id: stringType(),
5249
+ type: literalType("subscription.plan_changed"),
5250
+ timestamp: stringType().transform((d) => new Date(d)),
5251
+ data: SubscriptionSchema
5257
5252
  });
5258
5253
  var SubscriptionCancelledPayloadSchema = objectType({
5259
- business_id: stringType(),
5260
- type: literalType("subscription.cancelled"),
5261
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5262
- data: SubscriptionSchema,
5254
+ business_id: stringType(),
5255
+ type: literalType("subscription.cancelled"),
5256
+ timestamp: stringType().transform((d) => new Date(d)),
5257
+ data: SubscriptionSchema
5263
5258
  });
5264
5259
  var SubscriptionFailedPayloadSchema = objectType({
5265
- business_id: stringType(),
5266
- type: literalType("subscription.failed"),
5267
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5268
- data: SubscriptionSchema,
5260
+ business_id: stringType(),
5261
+ type: literalType("subscription.failed"),
5262
+ timestamp: stringType().transform((d) => new Date(d)),
5263
+ data: SubscriptionSchema
5269
5264
  });
5270
5265
  var SubscriptionExpiredPayloadSchema = objectType({
5271
- business_id: stringType(),
5272
- type: literalType("subscription.expired"),
5273
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5274
- data: SubscriptionSchema,
5266
+ business_id: stringType(),
5267
+ type: literalType("subscription.expired"),
5268
+ timestamp: stringType().transform((d) => new Date(d)),
5269
+ data: SubscriptionSchema
5275
5270
  });
5276
5271
  var LicenseKeyCreatedPayloadSchema = objectType({
5277
- business_id: stringType(),
5278
- type: literalType("license_key.created"),
5279
- timestamp: stringType().transform(function (d) { return new Date(d); }),
5280
- data: LicenseKeySchema,
5272
+ business_id: stringType(),
5273
+ type: literalType("license_key.created"),
5274
+ timestamp: stringType().transform((d) => new Date(d)),
5275
+ data: LicenseKeySchema
5281
5276
  });
5282
5277
  var WebhookPayloadSchema = discriminatedUnionType("type", [
5283
- PaymentSucceededPayloadSchema,
5284
- PaymentFailedPayloadSchema,
5285
- PaymentProcessingPayloadSchema,
5286
- PaymentCancelledPayloadSchema,
5287
- RefundSucceededPayloadSchema,
5288
- RefundFailedPayloadSchema,
5289
- DisputeOpenedPayloadSchema,
5290
- DisputeExpiredPayloadSchema,
5291
- DisputeAcceptedPayloadSchema,
5292
- DisputeCancelledPayloadSchema,
5293
- DisputeChallengedPayloadSchema,
5294
- DisputeWonPayloadSchema,
5295
- DisputeLostPayloadSchema,
5296
- SubscriptionActivePayloadSchema,
5297
- SubscriptionOnHoldPayloadSchema,
5298
- SubscriptionRenewedPayloadSchema,
5299
- SubscriptionPausedPayloadSchema,
5300
- SubscriptionPlanChangedPayloadSchema,
5301
- SubscriptionCancelledPayloadSchema,
5302
- SubscriptionFailedPayloadSchema,
5303
- SubscriptionExpiredPayloadSchema,
5304
- LicenseKeyCreatedPayloadSchema,
5278
+ PaymentSucceededPayloadSchema,
5279
+ PaymentFailedPayloadSchema,
5280
+ PaymentProcessingPayloadSchema,
5281
+ PaymentCancelledPayloadSchema,
5282
+ RefundSucceededPayloadSchema,
5283
+ RefundFailedPayloadSchema,
5284
+ DisputeOpenedPayloadSchema,
5285
+ DisputeExpiredPayloadSchema,
5286
+ DisputeAcceptedPayloadSchema,
5287
+ DisputeCancelledPayloadSchema,
5288
+ DisputeChallengedPayloadSchema,
5289
+ DisputeWonPayloadSchema,
5290
+ DisputeLostPayloadSchema,
5291
+ SubscriptionActivePayloadSchema,
5292
+ SubscriptionOnHoldPayloadSchema,
5293
+ SubscriptionRenewedPayloadSchema,
5294
+ SubscriptionPausedPayloadSchema,
5295
+ SubscriptionPlanChangedPayloadSchema,
5296
+ SubscriptionCancelledPayloadSchema,
5297
+ SubscriptionFailedPayloadSchema,
5298
+ SubscriptionExpiredPayloadSchema,
5299
+ LicenseKeyCreatedPayloadSchema
5305
5300
  ]);
5306
5301
 
5307
5302
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -6155,220 +6150,108 @@ class Webhook {
6155
6150
  Webhook_1 = dist.Webhook = Webhook;
6156
6151
  Webhook.prefix = "whsec_";
6157
6152
 
6158
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6159
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6160
- return new (P || (P = Promise))(function (resolve, reject) {
6161
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6162
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6163
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6164
- step((generator = generator.apply(thisArg, _arguments || [])).next());
6165
- });
6166
- };
6167
- var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
6168
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
6169
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
6170
- function verb(n) { return function (v) { return step([n, v]); }; }
6171
- function step(op) {
6172
- if (f) throw new TypeError("Generator is already executing.");
6173
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
6174
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
6175
- if (y = 0, t) op = [op[0] & 2, t.value];
6176
- switch (op[0]) {
6177
- case 0: case 1: t = op; break;
6178
- case 4: _.label++; return { value: op[1], done: false };
6179
- case 5: _.label++; y = op[1]; op = [0]; continue;
6180
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
6181
- default:
6182
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
6183
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
6184
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
6185
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
6186
- if (t[2]) _.ops.pop();
6187
- _.trys.pop(); continue;
6188
- }
6189
- op = body.call(thisArg, _);
6190
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
6191
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6153
+ async function handleWebhookPayload(payload, config, context) {
6154
+ const callHandler = (handler, payload2) => {
6155
+ if (!handler) return;
6156
+ if (context !== void 0) {
6157
+ return handler(context, payload2);
6192
6158
  }
6193
- };
6194
- // Implementation
6195
- function handleWebhookPayload(payload, config, context) {
6196
- return __awaiter(this, void 0, void 0, function () {
6197
- var callHandler;
6198
- return __generator(this, function (_a) {
6199
- switch (_a.label) {
6200
- case 0:
6201
- callHandler = function (handler, payload) {
6202
- if (!handler)
6203
- return;
6204
- if (context !== undefined) {
6205
- return handler(context, payload);
6206
- }
6207
- return handler(payload);
6208
- };
6209
- if (!config.onPayload) return [3 /*break*/, 2];
6210
- return [4 /*yield*/, callHandler(config.onPayload, payload)];
6211
- case 1:
6212
- _a.sent();
6213
- _a.label = 2;
6214
- case 2:
6215
- if (!(payload.type === "payment.succeeded")) return [3 /*break*/, 4];
6216
- return [4 /*yield*/, callHandler(config.onPaymentSucceeded, payload)];
6217
- case 3:
6218
- _a.sent();
6219
- _a.label = 4;
6220
- case 4:
6221
- if (!(payload.type === "payment.failed")) return [3 /*break*/, 6];
6222
- return [4 /*yield*/, callHandler(config.onPaymentFailed, payload)];
6223
- case 5:
6224
- _a.sent();
6225
- _a.label = 6;
6226
- case 6:
6227
- if (!(payload.type === "payment.processing")) return [3 /*break*/, 8];
6228
- return [4 /*yield*/, callHandler(config.onPaymentProcessing, payload)];
6229
- case 7:
6230
- _a.sent();
6231
- _a.label = 8;
6232
- case 8:
6233
- if (!(payload.type === "payment.cancelled")) return [3 /*break*/, 10];
6234
- return [4 /*yield*/, callHandler(config.onPaymentCancelled, payload)];
6235
- case 9:
6236
- _a.sent();
6237
- _a.label = 10;
6238
- case 10:
6239
- if (!(payload.type === "refund.succeeded")) return [3 /*break*/, 12];
6240
- return [4 /*yield*/, callHandler(config.onRefundSucceeded, payload)];
6241
- case 11:
6242
- _a.sent();
6243
- _a.label = 12;
6244
- case 12:
6245
- if (!(payload.type === "refund.failed")) return [3 /*break*/, 14];
6246
- return [4 /*yield*/, callHandler(config.onRefundFailed, payload)];
6247
- case 13:
6248
- _a.sent();
6249
- _a.label = 14;
6250
- case 14:
6251
- if (!(payload.type === "dispute.opened")) return [3 /*break*/, 16];
6252
- return [4 /*yield*/, callHandler(config.onDisputeOpened, payload)];
6253
- case 15:
6254
- _a.sent();
6255
- _a.label = 16;
6256
- case 16:
6257
- if (!(payload.type === "dispute.expired")) return [3 /*break*/, 18];
6258
- return [4 /*yield*/, callHandler(config.onDisputeExpired, payload)];
6259
- case 17:
6260
- _a.sent();
6261
- _a.label = 18;
6262
- case 18:
6263
- if (!(payload.type === "dispute.accepted")) return [3 /*break*/, 20];
6264
- return [4 /*yield*/, callHandler(config.onDisputeAccepted, payload)];
6265
- case 19:
6266
- _a.sent();
6267
- _a.label = 20;
6268
- case 20:
6269
- if (!(payload.type === "dispute.cancelled")) return [3 /*break*/, 22];
6270
- return [4 /*yield*/, callHandler(config.onDisputeCancelled, payload)];
6271
- case 21:
6272
- _a.sent();
6273
- _a.label = 22;
6274
- case 22:
6275
- if (!(payload.type === "dispute.challenged")) return [3 /*break*/, 24];
6276
- return [4 /*yield*/, callHandler(config.onDisputeChallenged, payload)];
6277
- case 23:
6278
- _a.sent();
6279
- _a.label = 24;
6280
- case 24:
6281
- if (!(payload.type === "dispute.won")) return [3 /*break*/, 26];
6282
- return [4 /*yield*/, callHandler(config.onDisputeWon, payload)];
6283
- case 25:
6284
- _a.sent();
6285
- _a.label = 26;
6286
- case 26:
6287
- if (!(payload.type === "dispute.lost")) return [3 /*break*/, 28];
6288
- return [4 /*yield*/, callHandler(config.onDisputeLost, payload)];
6289
- case 27:
6290
- _a.sent();
6291
- _a.label = 28;
6292
- case 28:
6293
- if (!(payload.type === "subscription.active")) return [3 /*break*/, 30];
6294
- return [4 /*yield*/, callHandler(config.onSubscriptionActive, payload)];
6295
- case 29:
6296
- _a.sent();
6297
- _a.label = 30;
6298
- case 30:
6299
- if (!(payload.type === "subscription.on_hold")) return [3 /*break*/, 32];
6300
- return [4 /*yield*/, callHandler(config.onSubscriptionOnHold, payload)];
6301
- case 31:
6302
- _a.sent();
6303
- _a.label = 32;
6304
- case 32:
6305
- if (!(payload.type === "subscription.renewed")) return [3 /*break*/, 34];
6306
- return [4 /*yield*/, callHandler(config.onSubscriptionRenewed, payload)];
6307
- case 33:
6308
- _a.sent();
6309
- _a.label = 34;
6310
- case 34:
6311
- if (!(payload.type === "subscription.paused")) return [3 /*break*/, 36];
6312
- return [4 /*yield*/, callHandler(config.onSubscriptionPaused, payload)];
6313
- case 35:
6314
- _a.sent();
6315
- _a.label = 36;
6316
- case 36:
6317
- if (!(payload.type === "subscription.plan_changed")) return [3 /*break*/, 38];
6318
- return [4 /*yield*/, callHandler(config.onSubscriptionPlanChanged, payload)];
6319
- case 37:
6320
- _a.sent();
6321
- _a.label = 38;
6322
- case 38:
6323
- if (!(payload.type === "subscription.cancelled")) return [3 /*break*/, 40];
6324
- return [4 /*yield*/, callHandler(config.onSubscriptionCancelled, payload)];
6325
- case 39:
6326
- _a.sent();
6327
- _a.label = 40;
6328
- case 40:
6329
- if (!(payload.type === "subscription.failed")) return [3 /*break*/, 42];
6330
- return [4 /*yield*/, callHandler(config.onSubscriptionFailed, payload)];
6331
- case 41:
6332
- _a.sent();
6333
- _a.label = 42;
6334
- case 42:
6335
- if (!(payload.type === "subscription.expired")) return [3 /*break*/, 44];
6336
- return [4 /*yield*/, callHandler(config.onSubscriptionExpired, payload)];
6337
- case 43:
6338
- _a.sent();
6339
- _a.label = 44;
6340
- case 44:
6341
- if (!(payload.type === "license_key.created")) return [3 /*break*/, 46];
6342
- return [4 /*yield*/, callHandler(config.onLicenseKeyCreated, payload)];
6343
- case 45:
6344
- _a.sent();
6345
- _a.label = 46;
6346
- case 46: return [2 /*return*/];
6347
- }
6348
- });
6349
- });
6159
+ return handler(payload2);
6160
+ };
6161
+ if (config.onPayload) {
6162
+ await callHandler(config.onPayload, payload);
6163
+ }
6164
+ if (payload.type === "payment.succeeded") {
6165
+ await callHandler(config.onPaymentSucceeded, payload);
6166
+ }
6167
+ if (payload.type === "payment.failed") {
6168
+ await callHandler(config.onPaymentFailed, payload);
6169
+ }
6170
+ if (payload.type === "payment.processing") {
6171
+ await callHandler(config.onPaymentProcessing, payload);
6172
+ }
6173
+ if (payload.type === "payment.cancelled") {
6174
+ await callHandler(config.onPaymentCancelled, payload);
6175
+ }
6176
+ if (payload.type === "refund.succeeded") {
6177
+ await callHandler(config.onRefundSucceeded, payload);
6178
+ }
6179
+ if (payload.type === "refund.failed") {
6180
+ await callHandler(config.onRefundFailed, payload);
6181
+ }
6182
+ if (payload.type === "dispute.opened") {
6183
+ await callHandler(config.onDisputeOpened, payload);
6184
+ }
6185
+ if (payload.type === "dispute.expired") {
6186
+ await callHandler(config.onDisputeExpired, payload);
6187
+ }
6188
+ if (payload.type === "dispute.accepted") {
6189
+ await callHandler(config.onDisputeAccepted, payload);
6190
+ }
6191
+ if (payload.type === "dispute.cancelled") {
6192
+ await callHandler(config.onDisputeCancelled, payload);
6193
+ }
6194
+ if (payload.type === "dispute.challenged") {
6195
+ await callHandler(config.onDisputeChallenged, payload);
6196
+ }
6197
+ if (payload.type === "dispute.won") {
6198
+ await callHandler(config.onDisputeWon, payload);
6199
+ }
6200
+ if (payload.type === "dispute.lost") {
6201
+ await callHandler(config.onDisputeLost, payload);
6202
+ }
6203
+ if (payload.type === "subscription.active") {
6204
+ await callHandler(config.onSubscriptionActive, payload);
6205
+ }
6206
+ if (payload.type === "subscription.on_hold") {
6207
+ await callHandler(config.onSubscriptionOnHold, payload);
6208
+ }
6209
+ if (payload.type === "subscription.renewed") {
6210
+ await callHandler(config.onSubscriptionRenewed, payload);
6211
+ }
6212
+ if (payload.type === "subscription.paused") {
6213
+ await callHandler(config.onSubscriptionPaused, payload);
6214
+ }
6215
+ if (payload.type === "subscription.plan_changed") {
6216
+ await callHandler(config.onSubscriptionPlanChanged, payload);
6217
+ }
6218
+ if (payload.type === "subscription.cancelled") {
6219
+ await callHandler(config.onSubscriptionCancelled, payload);
6220
+ }
6221
+ if (payload.type === "subscription.failed") {
6222
+ await callHandler(config.onSubscriptionFailed, payload);
6223
+ }
6224
+ if (payload.type === "subscription.expired") {
6225
+ await callHandler(config.onSubscriptionExpired, payload);
6226
+ }
6227
+ if (payload.type === "license_key.created") {
6228
+ await callHandler(config.onLicenseKeyCreated, payload);
6229
+ }
6350
6230
  }
6351
- var verifyWebhookPayload = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
6352
- var standardWebhook, _c, success, payload, error;
6353
- var webhookKey = _b.webhookKey, headers = _b.headers, body = _b.body;
6354
- return __generator(this, function (_d) {
6355
- standardWebhook = new Webhook_1(webhookKey);
6356
- try {
6357
- standardWebhook.verify(body, headers);
6358
- }
6359
- catch (e) {
6360
- if (e instanceof WebhookVerificationError_1) {
6361
- throw new Error(e.message);
6362
- }
6363
- throw e;
6364
- }
6365
- _c = WebhookPayloadSchema.safeParse(JSON.parse(body)), success = _c.success, payload = _c.data, error = _c.error;
6366
- if (!success) {
6367
- throw new Error(error.message);
6368
- }
6369
- return [2 /*return*/, payload];
6370
- });
6371
- }); };
6231
+ var verifyWebhookPayload = async ({
6232
+ webhookKey,
6233
+ headers,
6234
+ body
6235
+ }) => {
6236
+ const standardWebhook = new Webhook_1(webhookKey);
6237
+ try {
6238
+ standardWebhook.verify(body, headers);
6239
+ } catch (e) {
6240
+ if (e instanceof WebhookVerificationError_1) {
6241
+ throw new Error(e.message);
6242
+ }
6243
+ throw e;
6244
+ }
6245
+ const {
6246
+ success,
6247
+ data: payload,
6248
+ error
6249
+ } = WebhookPayloadSchema.safeParse(JSON.parse(body));
6250
+ if (!success) {
6251
+ throw new Error(error.message);
6252
+ }
6253
+ return payload;
6254
+ };
6372
6255
 
6373
6256
  /**
6374
6257
  * Creates a Convex HTTP action to securely handle Dodo Payments webhooks.