@dodopayments/convex 0.2.2 → 0.2.3

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