@winible/winible-typed 1.0.10 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/migrations/20230330174702-extend-premium-content.js +35 -0
  2. package/dist/migrations/20230330174702-extend-premium-content.js.map +1 -0
  3. package/dist/migrations/20230405141245-deprecate-agencies.js +9 -0
  4. package/dist/migrations/20230405141245-deprecate-agencies.js.map +1 -0
  5. package/dist/migrations/20230405142440-deprecate-unused-tables.js +23 -0
  6. package/dist/migrations/20230405142440-deprecate-unused-tables.js.map +1 -0
  7. package/dist/migrations/20230410144940-deprecate-consent-people.js +9 -0
  8. package/dist/migrations/20230410144940-deprecate-consent-people.js.map +1 -0
  9. package/dist/migrations/20230410174328-deprecate-consent-people-table.js +9 -0
  10. package/dist/migrations/20230410174328-deprecate-consent-people-table.js.map +1 -0
  11. package/dist/migrations/20230410181920-migrate-credit-payments-to-transactions.js +9 -0
  12. package/dist/migrations/20230410181920-migrate-credit-payments-to-transactions.js.map +1 -0
  13. package/dist/migrations/20230410202433-migrate-credit-payments-fields.js +12 -0
  14. package/dist/migrations/20230410202433-migrate-credit-payments-fields.js.map +1 -0
  15. package/dist/migrations/20230410211059-deprecate-credit-purchases.js +9 -0
  16. package/dist/migrations/20230410211059-deprecate-credit-purchases.js.map +1 -0
  17. package/dist/migrations/20230410212035-deprecate-dashboard_user_permissions.js +10 -0
  18. package/dist/migrations/20230410212035-deprecate-dashboard_user_permissions.js.map +1 -0
  19. package/dist/migrations/20230410212324-deprecate-non-breaking-tables.js +34 -0
  20. package/dist/migrations/20230410212324-deprecate-non-breaking-tables.js.map +1 -0
  21. package/dist/migrations/20230411054826-create-users-table.js +141 -0
  22. package/dist/migrations/20230411054826-create-users-table.js.map +1 -0
  23. package/dist/migrations/20230411202848-migrate_transactions_table.js +24 -0
  24. package/dist/migrations/20230411202848-migrate_transactions_table.js.map +1 -0
  25. package/dist/migrations/20230411203543-migrate_league_users.js +9 -0
  26. package/dist/migrations/20230411203543-migrate_league_users.js.map +1 -0
  27. package/dist/migrations/20230411205324-migrate_league.js +13 -0
  28. package/dist/migrations/20230411205324-migrate_league.js.map +1 -0
  29. package/dist/migrations/20230411221159-migrate_media.js +9 -0
  30. package/dist/migrations/20230411221159-migrate_media.js.map +1 -0
  31. package/dist/migrations/20230411221327-migrate_media_asset.js +10 -0
  32. package/dist/migrations/20230411221327-migrate_media_asset.js.map +1 -0
  33. package/dist/migrations/20230411221842-migrate_media_asset_fields.js +10 -0
  34. package/dist/migrations/20230411221842-migrate_media_asset_fields.js.map +1 -0
  35. package/dist/migrations/20230411222018-migrate_notifications.js +25 -0
  36. package/dist/migrations/20230411222018-migrate_notifications.js.map +1 -0
  37. package/dist/scripts/cleanupRecurlyPlans.js +12 -5
  38. package/dist/scripts/cleanupRecurlyPlans.js.map +1 -1
  39. package/dist/scripts/mapCurrentPaymentsToInvoiceId.js +12 -5
  40. package/dist/scripts/mapCurrentPaymentsToInvoiceId.js.map +1 -1
  41. package/dist/src/index.js +1 -18
  42. package/dist/src/index.js.map +1 -1
  43. package/dist/typed-model/credit-payment.js +133 -82
  44. package/dist/typed-model/credit-payment.js.map +1 -1
  45. package/dist/typed-model/index.js +3 -81
  46. package/dist/typed-model/index.js.map +1 -1
  47. package/dist/typed-model/league-user.js +28 -4
  48. package/dist/typed-model/league-user.js.map +1 -1
  49. package/dist/typed-model/media-asset.js +0 -9
  50. package/dist/typed-model/media-asset.js.map +1 -1
  51. package/dist/typed-model/notification.js +34 -24
  52. package/dist/typed-model/notification.js.map +1 -1
  53. package/dist/typed-model/pb-sequelize.js +18 -4
  54. package/dist/typed-model/pb-sequelize.js.map +1 -1
  55. package/dist/typed-model/subscription-plan-on-premium-content.js +57 -0
  56. package/dist/typed-model/subscription-plan-on-premium-content.js.map +1 -0
  57. package/dist/typed-model/subscription-plan.js +0 -9
  58. package/dist/typed-model/subscription-plan.js.map +1 -1
  59. package/dist/typed-model/subscription.js +0 -14
  60. package/dist/typed-model/subscription.js.map +1 -1
  61. package/dist/typed-model/user.js +194 -0
  62. package/dist/typed-model/user.js.map +1 -0
  63. package/package.json +3 -2
  64. package/src/index.ts +0 -2
  65. package/typed-model/credit-payment.ts +124 -126
  66. package/typed-model/index.ts +1 -51
  67. package/typed-model/media-asset.ts +0 -10
  68. package/typed-model/notification.ts +39 -44
  69. package/typed-model/pb-sequelize.ts +18 -4
  70. package/typed-model/subscription-plan.ts +0 -10
  71. package/typed-model/subscription.ts +1 -15
  72. package/typed-model/user.ts +248 -0
  73. package/dist/index.d.ts +0 -3
  74. package/dist/migrations/20220601151258-custom_name_describing_your_migration.d.ts +0 -6
  75. package/dist/migrations/20220605225655-create-dashboard-user-permissions.d.ts +0 -6
  76. package/dist/migrations/20220606001300-update-dashboard-user-permissions.d.ts +0 -6
  77. package/dist/migrations/20220607091109-add-read-date-for-message.d.ts +0 -6
  78. package/dist/migrations/20220616225456-add-delete-columns.d.ts +0 -6
  79. package/dist/migrations/20220709202211-disable-feed.d.ts +0 -6
  80. package/dist/migrations/20220723215213-limit-promotion-claims.d.ts +0 -6
  81. package/dist/migrations/20220723220233-num_claims.d.ts +0 -6
  82. package/dist/migrations/20220723221907-default_false_promos.d.ts +0 -6
  83. package/dist/migrations/20220724172559-default_zero_claims.d.ts +0 -6
  84. package/dist/migrations/20220724201419-pinned_post.d.ts +0 -6
  85. package/dist/migrations/20220729164625-unsend_mass.d.ts +0 -6
  86. package/dist/migrations/20220823033002-interval-unit.d.ts +0 -6
  87. package/dist/migrations/20220830193530-processorId.d.ts +0 -6
  88. package/dist/migrations/20220907121932-add-processor-to-sub.d.ts +0 -6
  89. package/dist/migrations/20220907212232-add-trans-id.d.ts +0 -6
  90. package/dist/migrations/20220907220423-big-int-trans.d.ts +0 -6
  91. package/dist/migrations/20220909161902-add-stale.d.ts +0 -6
  92. package/dist/migrations/20220922000225-verified-spender.d.ts +0 -6
  93. package/dist/migrations/20220922212108-verified-spender-2.d.ts +0 -6
  94. package/dist/migrations/20221013223648-product-subscription-list.d.ts +0 -6
  95. package/dist/migrations/20221014001037-product-subscription-list.d.ts +0 -6
  96. package/dist/migrations/20221026055245-update-type.d.ts +0 -6
  97. package/dist/migrations/20221108060019-recurly-sub.d.ts +0 -6
  98. package/dist/migrations/20221110170148-rename-recurly-account.d.ts +0 -6
  99. package/dist/migrations/20221112212510-archive-promo.d.ts +0 -6
  100. package/dist/migrations/20221117044529-sub-status.d.ts +0 -6
  101. package/dist/migrations/20221122051433-default-plan.d.ts +0 -6
  102. package/dist/migrations/20221128034620-invoice-id.d.ts +0 -6
  103. package/dist/migrations/20230313175014-league-user.js +0 -27
  104. package/dist/migrations/20230313175014-league-user.js.map +0 -1
  105. package/dist/scripts/bet-syncing/checkForPrizePicks.js +0 -85
  106. package/dist/scripts/bet-syncing/checkForPrizePicks.js.map +0 -1
  107. package/dist/scripts/bet-syncing/pullTeams.d.ts +0 -1
  108. package/dist/scripts/cleanupRecurlyPlans.d.ts +0 -1
  109. package/dist/scripts/createDashboardLink.d.ts +0 -1
  110. package/dist/scripts/createRecurlyPlans.d.ts +0 -1
  111. package/dist/scripts/deleteMalformedImages.d.ts +0 -1
  112. package/dist/scripts/fixSaltedPasswords.js +0 -40
  113. package/dist/scripts/fixSaltedPasswords.js.map +0 -1
  114. package/dist/scripts/mapCurrentPaymentsToInvoiceId.d.ts +0 -1
  115. package/dist/scripts/payoutRecurlySubs.d.ts +0 -1
  116. package/dist/scripts/payoutSubscriptions.d.ts +0 -1
  117. package/dist/scripts/removeUnreferenceSubs.d.ts +0 -1
  118. package/dist/scripts/test.d.ts +0 -1
  119. package/dist/slack/index.d.ts +0 -1
  120. package/dist/slack/v1/bypassCreator.d.ts +0 -8
  121. package/dist/slack/v1/cancelSubscription.d.ts +0 -6
  122. package/dist/slack/v1/changeName.d.ts +0 -8
  123. package/dist/slack/v1/checkAuthSub.d.ts +0 -6
  124. package/dist/slack/v1/dashboardLink.d.ts +0 -8
  125. package/dist/slack/v1/index.d.ts +0 -7
  126. package/dist/slack/v1/refund.d.ts +0 -6
  127. package/dist/slack/v1/searchUser.d.ts +0 -6
  128. package/dist/src/index.d.ts +0 -3
  129. package/dist/src/pk-client.d.ts +0 -151
  130. package/dist/src/pk-sub.d.ts +0 -77
  131. package/dist/src/recurlyInstance.d.ts +0 -3
  132. package/dist/src/types.d.ts +0 -30
  133. package/dist/support/index.d.ts +0 -2
  134. package/dist/support/slack-client.d.ts +0 -3
  135. package/dist/support/uploadcare.d.ts +0 -14
  136. package/dist/support/utils.d.ts +0 -2
  137. package/dist/typed-model/asset-category.d.ts +0 -9
  138. package/dist/typed-model/asset-constent-person.d.ts +0 -13
  139. package/dist/typed-model/bet.d.ts +0 -12
  140. package/dist/typed-model/blocked-ip.d.ts +0 -8
  141. package/dist/typed-model/category-tag.d.ts +0 -9
  142. package/dist/typed-model/consent-person.d.ts +0 -13
  143. package/dist/typed-model/content-category-tag.d.ts +0 -9
  144. package/dist/typed-model/content-like.d.ts +0 -10
  145. package/dist/typed-model/credit-payment.d.ts +0 -34
  146. package/dist/typed-model/credit-payout.d.ts +0 -10
  147. package/dist/typed-model/credit-purchase.d.ts +0 -10
  148. package/dist/typed-model/customer-profile.d.ts +0 -17
  149. package/dist/typed-model/dashboard-user-permissions.d.ts +0 -9
  150. package/dist/typed-model/dashboard-user.d.ts +0 -20
  151. package/dist/typed-model/fan-list.d.ts +0 -10
  152. package/dist/typed-model/fraud.d.ts +0 -9
  153. package/dist/typed-model/game.d.ts +0 -56
  154. package/dist/typed-model/index.d.ts +0 -46
  155. package/dist/typed-model/league.d.ts +0 -9
  156. package/dist/typed-model/list-member.d.ts +0 -9
  157. package/dist/typed-model/mass-message.d.ts +0 -11
  158. package/dist/typed-model/media-asset.d.ts +0 -15
  159. package/dist/typed-model/media-category.d.ts +0 -10
  160. package/dist/typed-model/media.d.ts +0 -14
  161. package/dist/typed-model/message-media.d.ts +0 -9
  162. package/dist/typed-model/message.d.ts +0 -27
  163. package/dist/typed-model/notification.d.ts +0 -18
  164. package/dist/typed-model/odds.d.ts +0 -30
  165. package/dist/typed-model/parlay.d.ts +0 -8
  166. package/dist/typed-model/pb-sequelize.d.ts +0 -3
  167. package/dist/typed-model/phone-chat-participation.d.ts +0 -20
  168. package/dist/typed-model/phone-chat.d.ts +0 -16
  169. package/dist/typed-model/phone-owner.d.ts +0 -53
  170. package/dist/typed-model/phone-user.d.ts +0 -21
  171. package/dist/typed-model/player.d.ts +0 -22
  172. package/dist/typed-model/premium-content.d.ts +0 -23
  173. package/dist/typed-model/purchased-content.d.ts +0 -11
  174. package/dist/typed-model/recurly-account.d.ts +0 -9
  175. package/dist/typed-model/short-url.d.ts +0 -12
  176. package/dist/typed-model/subscription-bundle.d.ts +0 -12
  177. package/dist/typed-model/subscription-category-tags.d.ts +0 -9
  178. package/dist/typed-model/subscription-plan.d.ts +0 -27
  179. package/dist/typed-model/subscription-promotion.d.ts +0 -19
  180. package/dist/typed-model/subscription.d.ts +0 -26
  181. package/dist/typed-model/team.d.ts +0 -16
  182. package/dist/typed-model/twilio-phone.d.ts +0 -17
  183. package/dist/typed-model/user-follow.d.ts +0 -13
  184. package/dist/typed-model/verification-code.d.ts +0 -11
  185. package/dist/webhooks/index.d.ts +0 -1
  186. package/dist/webhooks/payment/index.d.ts +0 -1
  187. package/dist/webhooks/payment/refund.d.ts +0 -2
  188. package/src/pk-client.ts +0 -1650
  189. package/src/pk-sub.ts +0 -455
  190. package/typed-model/asset-category.ts +0 -57
  191. package/typed-model/asset-constent-person.ts +0 -82
  192. package/typed-model/bet.ts +0 -84
  193. package/typed-model/blocked-ip.ts +0 -52
  194. package/typed-model/category-tag.ts +0 -66
  195. package/typed-model/consent-person.ts +0 -78
  196. package/typed-model/content-category-tag.ts +0 -79
  197. package/typed-model/credit-purchase.ts +0 -67
  198. package/typed-model/customer-profile.ts +0 -71
  199. package/typed-model/dashboard-user-permissions.ts +0 -51
  200. package/typed-model/dashboard-user.ts +0 -146
  201. package/typed-model/fan-list.ts +0 -68
  202. package/typed-model/fraud.ts +0 -62
  203. package/typed-model/game.ts +0 -311
  204. package/typed-model/list-member.ts +0 -67
  205. package/typed-model/market.ts +0 -54
  206. package/typed-model/mass-message.ts +0 -64
  207. package/typed-model/media-category.ts +0 -70
  208. package/typed-model/message-media.ts +0 -74
  209. package/typed-model/message.ts +0 -258
  210. package/typed-model/odds.ts +0 -238
  211. package/typed-model/parlay.ts +0 -47
  212. package/typed-model/phone-chat-participation.ts +0 -166
  213. package/typed-model/phone-chat.ts +0 -185
  214. package/typed-model/player-result.ts +0 -93
  215. package/typed-model/player.ts +0 -118
  216. package/typed-model/short-url.ts +0 -120
  217. package/typed-model/sportsbook.ts +0 -48
  218. package/typed-model/subscription-bundle.ts +0 -80
  219. package/typed-model/subscription-category-tags.ts +0 -79
  220. package/typed-model/subscription-promotion.ts +0 -134
  221. package/typed-model/team.ts +0 -91
  222. package/typed-model/twilio-phone.ts +0 -149
  223. package/typed-model/user-follow.ts +0 -141
  224. package/typed-model/verification-code.ts +0 -74
package/src/pk-sub.ts DELETED
@@ -1,455 +0,0 @@
1
- import PhoneUser from "../typed-model/phone-user";
2
- import PhoneOwner from "../typed-model/phone-owner";
3
- import Subscription from "../typed-model/subscription";
4
- import SubscriptionPlan from "../typed-model/subscription-plan";
5
- import SubscriptionBundle from "../typed-model/subscription-bundle";
6
- import { TransactionData } from "./types";
7
-
8
- import sequelize from "../typed-model/pb-sequelize";
9
- import CreditPayments from "../typed-model/credit-payment";
10
- import { ProcessorId } from "../typed-model/customer-profile";
11
-
12
- export class SubscriptionInitException extends Error {
13
- constructor(message: string) {
14
- super(message);
15
- this.name = "SubscriptionInitException";
16
- }
17
- }
18
-
19
- export class SubscriptionChargeException extends Error {
20
- constructor(message: string) {
21
- super(message);
22
- this.name = "SubscriptionChargeException";
23
- }
24
- }
25
-
26
- export class SubscriptionChargeCreditCardException extends SubscriptionChargeException {
27
- constructor(message: string) {
28
- super(message);
29
- this.name = "SubscriptionChargeCreditCardException";
30
- }
31
- }
32
-
33
- export class SubscriptionChargeProfileException extends SubscriptionChargeException {
34
- constructor(message: string) {
35
- super(message);
36
- this.name = "SubscriptionChargeProfileException";
37
- }
38
- }
39
-
40
- export class CreatePaymentProfileException extends Error {
41
- constructor(message: string) {
42
- super(message);
43
- this.name = "CreatePaymentProfileException";
44
- }
45
- }
46
-
47
- export class InvalidSubscriptionRequestException extends Error {
48
- constructor(message: string) {
49
- super(message);
50
- this.name = "InvalidSubscriptionRequestException";
51
- }
52
- }
53
-
54
- export class CliqSubscriptionCreationException extends Error {
55
- constructor(message: string) {
56
- super(message);
57
- this.name = "CliqSubscriptionCreationException";
58
- }
59
- }
60
-
61
- export class CliqPaymentCreationException extends Error {
62
- constructor() {
63
- super("Failed to create Cliq credit payment");
64
- this.name = "CliqSubscriptionCreationException";
65
- }
66
- }
67
-
68
- export class CreatePKSubscriptionException extends Error {
69
- constructor(name: string, message: string) {
70
- super(message);
71
- this.name = name;
72
- }
73
- }
74
-
75
- import {
76
- chargeCustomerByPaymentProfile,
77
- chargeCreditCardAndCreateProfile,
78
- updateUserPaymentProfile,
79
- createSubscription,
80
- voidTransaction,
81
- createSubscriptionWithCreditCard,
82
- } from "./pk-client";
83
- import { rejects } from "assert";
84
-
85
- export class PKSub {
86
- user: PhoneUser;
87
- creator: PhoneOwner;
88
- subscriptionPlan: SubscriptionPlan;
89
- trialAmount: number;
90
- trialLength: number;
91
- amountInCents: number;
92
- intervalCount: number;
93
- intervalUnit: "months" | "days";
94
- transactionData?: TransactionData;
95
- useCoachingMid: boolean;
96
- paymentProfile?: {
97
- customerProfileId: string;
98
- customerPaymentProfileId: string;
99
- };
100
-
101
- constructor(
102
- user: PhoneUser,
103
- creator: PhoneOwner,
104
- subscriptionPlan: SubscriptionPlan,
105
- subscriptionBundle?: SubscriptionBundle,
106
- isPreviouslySubscribed?: boolean,
107
- useCoachingMid?: boolean
108
- ) {
109
- this.user = user;
110
- this.creator = creator;
111
- this.subscriptionPlan = subscriptionPlan;
112
- this.useCoachingMid = !!useCoachingMid;
113
-
114
- if (!user) {
115
- throw new SubscriptionInitException("User cannot be null");
116
- }
117
-
118
- if (!creator || !creator.id) {
119
- console.log(creator);
120
- throw new SubscriptionInitException("Creator cannot be null");
121
- }
122
-
123
- var promotion =
124
- subscriptionPlan.SubscriptionPromotions &&
125
- subscriptionPlan.SubscriptionPromotions[0];
126
-
127
- this.trialAmount = 0;
128
- this.trialLength = 0;
129
- this.amountInCents = subscriptionPlan.amountInCents!;
130
- this.intervalCount = subscriptionPlan.intervalCount || 1;
131
- this.intervalUnit = subscriptionPlan.intervalUnit || "months";
132
-
133
- if (subscriptionBundle) {
134
- promotion = null;
135
- }
136
-
137
- if (!isPreviouslySubscribed && promotion) {
138
- this.trialAmount = Math.round(
139
- (1 - promotion.trialDiscountPercentage) *
140
- subscriptionPlan.amountInCents!
141
- );
142
- this.trialLength = promotion.trialLength;
143
- }
144
-
145
- if (subscriptionBundle) {
146
- this.amountInCents = Math.round(
147
- (1 - subscriptionBundle.bundleDiscountPercentage!) *
148
- this.amountInCents *
149
- subscriptionBundle.bundleIntervalCount!
150
- );
151
- this.intervalCount = subscriptionBundle.bundleIntervalCount!;
152
- this.trialAmount = 0;
153
- this.trialLength = 0;
154
- }
155
- }
156
-
157
- async _charge(
158
- amount: number,
159
- description: string
160
- ): Promise<
161
- | {
162
- amountInCents: number;
163
- transactionId: string;
164
- pkCustomerProfileId?: string;
165
- pkCustomerPaymentProfileId?: string;
166
- processorId: ProcessorId;
167
- }
168
- | undefined
169
- > {
170
- console.log("Start Charge...");
171
- if (this.paymentProfile) {
172
- console.log("Charge by payment profile...");
173
- let response = await chargeCustomerByPaymentProfile(
174
- this.paymentProfile.customerProfileId,
175
- this.paymentProfile.customerPaymentProfileId,
176
- amount,
177
- description
178
- ).catch((err) => {
179
- throw new SubscriptionChargeProfileException(err);
180
- });
181
- return {
182
- ...response,
183
- pkCustomerProfileId: this.paymentProfile.customerProfileId,
184
- pkCustomerPaymentProfileId:
185
- this.paymentProfile.customerPaymentProfileId,
186
- };
187
- } else if (this.transactionData) {
188
- console.log("Charge by credit card...");
189
- let chargeResponse = await chargeCreditCardAndCreateProfile(
190
- this.user,
191
- this.transactionData,
192
- amount,
193
- description,
194
- true,
195
- this.useCoachingMid
196
- ).catch((err) => {
197
- throw new SubscriptionChargeCreditCardException(err);
198
- });
199
- try {
200
- // if (chargeResponse.pkCustomerProfileId) {
201
- // await updateUserPaymentProfile(
202
- // this.user.id,
203
- // chargeResponse.pkCustomerProfileId,
204
- // chargeResponse.pkCustomerPaymentProfileId!
205
- // );
206
- // this.paymentProfile = {
207
- // customerProfileId: chargeResponse.pkCustomerProfileId,
208
- // customerPaymentProfileId:
209
- // chargeResponse.pkCustomerPaymentProfileId!,
210
- // };
211
- // }
212
- return {
213
- amountInCents: chargeResponse.amountInCents,
214
- transactionId: chargeResponse.transactionId,
215
- processorId: chargeResponse.processorId,
216
- // pkCustomerProfileId: chargeResponse.pkCustomerProfileId,
217
- // pkCustomerPaymentProfileId: chargeResponse.pkCustomerPaymentProfileId,
218
- };
219
- } catch (err) {
220
- console.log(err);
221
- if (chargeResponse.transactionId) {
222
- // Void transaction
223
- await voidTransaction(
224
- chargeResponse.transactionId,
225
- chargeResponse.processorId
226
- );
227
- console.log("Failed to create customer id");
228
- }
229
- throw new CreatePaymentProfileException(
230
- "Failed to create customer profile"
231
- );
232
- }
233
- }
234
- throw new InvalidSubscriptionRequestException(
235
- "Must include transaction data or customer profile"
236
- );
237
- }
238
-
239
- async _chargeFirstPayment(): Promise<{
240
- amountInCents: number;
241
- transactionId: string;
242
- pkCustomerProfileId?: string;
243
- pkCustomerPaymentProfileId?: string;
244
- processorId: ProcessorId;
245
- }> {
246
- console.log("Charge first payment");
247
- if (this.trialLength > 0 && this.trialAmount > 0) {
248
- const charge = await this._charge(
249
- this.trialAmount,
250
- `${this.creator.name} ${
251
- this.intervalUnit == "days" ? "weekly" : "monthly"
252
- } subscriptions`
253
- );
254
- this.trialLength = this.trialLength - 1;
255
- if (this.trialLength == 0) {
256
- this.trialAmount = 0;
257
- }
258
- return charge!;
259
- } else {
260
- const charge = await this._charge(
261
- this.amountInCents,
262
- `${this.creator.name} ${
263
- this.intervalUnit == "days" ? "weekly" : "monthly"
264
- } subscriptions`
265
- );
266
- return charge!;
267
- }
268
- }
269
-
270
- async _initializePkSubscription(
271
- processorId: ProcessorId
272
- ): Promise<{ pkSubId: string }> {
273
- if (this.paymentProfile) {
274
- console.log("Creating sub with payment profile");
275
- return await createSubscription({
276
- intervalCount: this.intervalCount,
277
- intervalUnit: this.intervalUnit,
278
- trialLength: this.trialLength,
279
- trialAmountInCents: this.trialAmount,
280
- customerProfileId: this.paymentProfile!.customerProfileId,
281
- customerPaymentProfileId: this.paymentProfile!.customerPaymentProfileId,
282
- creatorName: this.creator.name!,
283
- amountInCents: this.amountInCents,
284
- processorId: processorId,
285
- }).catch((err) => {
286
- throw new CreatePKSubscriptionException(
287
- "CreatePKSubscriptionWithProfileException",
288
- "Failed to create authorize subscription with payment profile"
289
- );
290
- });
291
- } else if (this.transactionData) {
292
- console.log("Creating sub credit card");
293
- let subscriptionResponse = await createSubscriptionWithCreditCard({
294
- intervalCount: this.intervalCount,
295
- intervalUnit: this.intervalUnit,
296
- trialLength: this.trialLength,
297
- trialAmountInCents: this.trialAmount,
298
- data: this.transactionData,
299
- creatorName: this.creator.name!,
300
- amountInCents: this.amountInCents,
301
- processorId: processorId,
302
- }).catch((err) => {
303
- throw new CreatePKSubscriptionException(
304
- "CreatePKSubscriptionWithCardException",
305
- "Failed to create authorize subscription with credit card"
306
- );
307
- });
308
- if (subscriptionResponse.paymentProfile.pkCustomerProfileId) {
309
- console.log("Updating customer profile from sub response");
310
- await updateUserPaymentProfile(
311
- this.user.id,
312
- subscriptionResponse.paymentProfile.pkCustomerProfileId,
313
- processorId,
314
- subscriptionResponse.paymentProfile.pkCustomerPaymentProfileId
315
- );
316
- }
317
- return subscriptionResponse;
318
- }
319
- throw new InvalidSubscriptionRequestException(
320
- "No payment method for subscription"
321
- );
322
- }
323
-
324
- setTransactionData(transactionData: TransactionData) {
325
- this.transactionData = transactionData;
326
- }
327
-
328
- setPaymentProfile(paymentProfile: {
329
- customerProfileId: string;
330
- customerPaymentProfileId: string;
331
- }) {
332
- this.paymentProfile = paymentProfile;
333
- }
334
-
335
- /*
336
- 1) Start SQL transaction
337
- 2) Create sequelize updates
338
- - Create first payment
339
- - Create subscription
340
- 3) Create first charge
341
- - If charge fails, rollback transaction
342
- 4) Create subscription
343
- - If subscription fails
344
- - Refund transaction
345
- - Rollback transaction
346
- 5) Commit transaction
347
- */
348
-
349
- async buildSubscription(): Promise<{
350
- subscription: any;
351
- creditPayment: any;
352
- pkSubId: string;
353
- }> {
354
- let firstPayment;
355
- try {
356
- if (this.trialLength == 0 || this.trialAmount > 0) {
357
- firstPayment = await this._chargeFirstPayment();
358
- }
359
- } catch (err) {
360
- if (err instanceof Error) {
361
- throw err;
362
- } else {
363
- throw new Error("Failed to charge: " + err);
364
- }
365
- }
366
-
367
- if (!firstPayment) {
368
- throw new Error("Failed to charge credit card");
369
- }
370
-
371
- let transaction = await sequelize.transaction();
372
- let subscription;
373
- try {
374
- subscription = await Subscription.create(
375
- {
376
- userId: this.user.id,
377
- subscriptionPlanId: this.subscriptionPlan.id,
378
- lastPaymentDate: new Date(),
379
- cancelDate: this.subscriptionPlan.accessEndDate || undefined,
380
- processorId: firstPayment.processorId,
381
- },
382
- { transaction }
383
- );
384
- } catch (err) {
385
- console.log(err);
386
- await transaction.rollback();
387
- // Void first transaction
388
- await voidTransaction(
389
- firstPayment.transactionId,
390
- firstPayment.processorId
391
- );
392
- throw new CliqSubscriptionCreationException(
393
- "Failed to create subscription in CLIQ"
394
- );
395
- }
396
-
397
- let creditPayment;
398
- try {
399
- if (subscription) {
400
- creditPayment = await CreditPayments.logSubscriptionPayment(
401
- this.user.id,
402
- this.creator,
403
- firstPayment.amountInCents,
404
- subscription,
405
- transaction,
406
- firstPayment.transactionId
407
- );
408
- }
409
- } catch (err) {
410
- console.log(err);
411
- await transaction.rollback();
412
- // Void first transaction
413
- if (firstPayment) {
414
- await voidTransaction(
415
- firstPayment.transactionId,
416
- firstPayment.processorId
417
- );
418
- }
419
- throw new CliqPaymentCreationException();
420
- }
421
-
422
- let pkSub;
423
- let setRecurring =
424
- !this.subscriptionPlan.accessEndDate &&
425
- !this.subscriptionPlan.oneTimePurchase;
426
- try {
427
- if (setRecurring) {
428
- pkSub = await this._initializePkSubscription(firstPayment.processorId);
429
- }
430
- } catch (err) {
431
- console.log(err);
432
- await transaction.rollback();
433
- // Void first transaction
434
- await voidTransaction(
435
- firstPayment.transactionId,
436
- firstPayment.processorId
437
- );
438
- throw new CreatePKSubscriptionException(
439
- "CreatePKSubscriptionException",
440
- "Failed to create subscription: " + err
441
- );
442
- }
443
-
444
- await transaction.commit();
445
- if (subscription && setRecurring) {
446
- subscription.pkSubscriptionId = pkSub.pkSubId;
447
- await subscription.save();
448
- }
449
- return {
450
- subscription,
451
- creditPayment,
452
- pkSubId: pkSub && pkSub.pkSubId,
453
- };
454
- }
455
- }
@@ -1,57 +0,0 @@
1
- import {
2
- Model,
3
- InferAttributes,
4
- InferCreationAttributes,
5
- CreationOptional,
6
- DataTypes,
7
- fn,
8
- } from "sequelize";
9
-
10
- import sequelize from "./pb-sequelize";
11
-
12
- // order of InferAttributes & InferCreationAttributes is important.
13
- class AssetCategory extends Model<
14
- InferAttributes<AssetCategory>,
15
- InferCreationAttributes<AssetCategory>
16
- > {
17
- // 'CreationOptional' is a special type that marks the field as optional
18
- // when creating an instance of the model (such as using Model.create()).
19
- declare id: CreationOptional<string>;
20
- declare mediaAssetId: string;
21
- declare mediaCategoryId: string;
22
- declare createdAt: CreationOptional<Date>;
23
- declare updatedAt: CreationOptional<Date>;
24
- }
25
-
26
- AssetCategory.init(
27
- {
28
- id: {
29
- type: DataTypes.BIGINT,
30
- primaryKey: true,
31
- allowNull: false,
32
- defaultValue: sequelize.fn("next_id"),
33
- },
34
- mediaAssetId: {
35
- type: DataTypes.BIGINT,
36
- field: "media_asset_id",
37
- },
38
- mediaCategoryId: {
39
- type: DataTypes.BIGINT,
40
- field: "media_category_id",
41
- },
42
- createdAt: DataTypes.DATE,
43
- updatedAt: DataTypes.DATE,
44
- },
45
- {
46
- tableName: "asset_categories",
47
- sequelize,
48
- }
49
- );
50
-
51
- /*
52
- ====================================================================
53
- Class functions
54
- ====================================================================
55
- */
56
-
57
- export default AssetCategory;
@@ -1,82 +0,0 @@
1
- import {
2
- Model,
3
- InferAttributes,
4
- InferCreationAttributes,
5
- CreationOptional,
6
- DataTypes,
7
- fn,
8
- NonAttribute,
9
- } from "sequelize";
10
-
11
- import sequelize from "./pb-sequelize";
12
-
13
- import ConsentPerson from "./consent-person";
14
- import MediaAsset from "./media-asset";
15
-
16
- // order of InferAttributes & InferCreationAttributes is important.
17
- class AssetConsentPerson extends Model<
18
- InferAttributes<AssetConsentPerson>,
19
- InferCreationAttributes<AssetConsentPerson>
20
- > {
21
- // 'CreationOptional' is a special type that marks the field as optional
22
- // when creating an instance of the model (such as using Model.create()).
23
- declare id: CreationOptional<string>;
24
- declare consentPersonId: string;
25
- declare mediaAssetId: string;
26
- declare createdAt: CreationOptional<Date>;
27
- declare updatedAt: CreationOptional<Date>;
28
-
29
- declare consent_person?: NonAttribute<ConsentPerson>;
30
- declare media_asset?: NonAttribute<MediaAsset[]>;
31
- }
32
-
33
- AssetConsentPerson.init(
34
- {
35
- id: {
36
- type: DataTypes.BIGINT,
37
- primaryKey: true,
38
- allowNull: false,
39
- defaultValue: fn("next_id"),
40
- },
41
- consentPersonId: {
42
- type: DataTypes.BIGINT,
43
- field: "consent_person_id",
44
- },
45
- mediaAssetId: {
46
- type: DataTypes.BIGINT,
47
- field: "media_asset_id",
48
- },
49
- createdAt: DataTypes.DATE,
50
- updatedAt: DataTypes.DATE,
51
- },
52
- {
53
- sequelize,
54
- tableName: "asset_consent_people",
55
- }
56
- );
57
-
58
- /*
59
- ====================================================================
60
- Class functions
61
- ====================================================================
62
- */
63
-
64
- AssetConsentPerson.hasOne(ConsentPerson, {
65
- foreignKey: "id",
66
- sourceKey: "consentPersonId",
67
- });
68
- ConsentPerson.hasMany(AssetConsentPerson, {
69
- foreignKey: "consent_person_id",
70
- sourceKey: "id",
71
- });
72
-
73
- AssetConsentPerson.hasOne(MediaAsset, {
74
- foreignKey: "id",
75
- sourceKey: "mediaAssetId",
76
- });
77
- MediaAsset.hasMany(AssetConsentPerson, {
78
- foreignKey: "media_asset_id",
79
- sourceKey: "id",
80
- });
81
-
82
- export default AssetConsentPerson;
@@ -1,84 +0,0 @@
1
- import {
2
- Model,
3
- InferAttributes,
4
- InferCreationAttributes,
5
- CreationOptional,
6
- DataTypes,
7
- fn,
8
- } from "sequelize";
9
- import Parlay from "./parlay";
10
-
11
- import sequelize from "./pb-sequelize";
12
- import PhoneUser from "./phone-user";
13
-
14
- // order of InferAttributes & InferCreationAttributes is important.
15
- class Bet extends Model<InferAttributes<Bet>, InferCreationAttributes<Bet>> {
16
- // 'CreationOptional' is a special type that marks the field as optional
17
- // when creating an instance of the model (such as using Model.create()).
18
- declare id: CreationOptional<string>;
19
- declare oddsJamOddsId: string;
20
- declare oddsId: string;
21
- declare price: number;
22
- declare userId: string;
23
- declare parlayId?: string;
24
- declare createdAt: CreationOptional<Date>;
25
- declare updatedAt: CreationOptional<Date>;
26
- }
27
-
28
- Bet.init(
29
- {
30
- id: {
31
- type: DataTypes.BIGINT,
32
- primaryKey: true,
33
- allowNull: false,
34
- defaultValue: sequelize.fn("next_id"),
35
- },
36
- oddsJamOddsId: {
37
- type: DataTypes.STRING,
38
- field: "odds_jam_odds_id",
39
- },
40
- oddsId: {
41
- type: DataTypes.STRING,
42
- field: "odds_id",
43
- },
44
- price: {
45
- type: DataTypes.DOUBLE,
46
- field: "price",
47
- },
48
- userId: {
49
- type: DataTypes.STRING,
50
- field: "user_id",
51
- },
52
- parlayId: {
53
- type: DataTypes.STRING,
54
- field: "parlay_id",
55
- },
56
- createdAt: DataTypes.DATE,
57
- updatedAt: DataTypes.DATE,
58
- },
59
- {
60
- // Other model options go here
61
- tableName: "bets",
62
- sequelize,
63
- }
64
- );
65
-
66
- Bet.hasOne(Parlay, {
67
- foreignKey: "id",
68
- sourceKey: "parlayId",
69
- });
70
- Parlay.hasMany(Bet, {
71
- foreignKey: "parlay_id",
72
- sourceKey: "id",
73
- });
74
-
75
- Bet.hasOne(PhoneUser, {
76
- foreignKey: "id",
77
- sourceKey: "userId",
78
- });
79
- PhoneUser.hasMany(Bet, {
80
- foreignKey: "user_id",
81
- sourceKey: "id",
82
- });
83
-
84
- export default Bet;