@stamhoofd/models 2.1.1

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 (481) hide show
  1. package/dist/src/assets/Metropolis-Black.woff2 +0 -0
  2. package/dist/src/assets/Metropolis-BlackItalic.woff2 +0 -0
  3. package/dist/src/assets/Metropolis-Bold.woff2 +0 -0
  4. package/dist/src/assets/Metropolis-BoldItalic.woff2 +0 -0
  5. package/dist/src/assets/Metropolis-ExtraBold.woff2 +0 -0
  6. package/dist/src/assets/Metropolis-ExtraBoldItalic.woff2 +0 -0
  7. package/dist/src/assets/Metropolis-ExtraLight.woff2 +0 -0
  8. package/dist/src/assets/Metropolis-ExtraLightItalic.woff2 +0 -0
  9. package/dist/src/assets/Metropolis-Light.woff2 +0 -0
  10. package/dist/src/assets/Metropolis-LightItalic.woff2 +0 -0
  11. package/dist/src/assets/Metropolis-Medium.woff2 +0 -0
  12. package/dist/src/assets/Metropolis-MediumItalic.woff2 +0 -0
  13. package/dist/src/assets/Metropolis-Regular.woff2 +0 -0
  14. package/dist/src/assets/Metropolis-RegularItalic.woff2 +0 -0
  15. package/dist/src/assets/Metropolis-SemiBold.woff2 +0 -0
  16. package/dist/src/assets/Metropolis-SemiBoldItalic.woff2 +0 -0
  17. package/dist/src/assets/Metropolis-Thin.woff2 +0 -0
  18. package/dist/src/assets/Metropolis-ThinItalic.woff2 +0 -0
  19. package/dist/src/assets/assets/Metropolis-Black.woff2 +0 -0
  20. package/dist/src/assets/assets/Metropolis-BlackItalic.woff2 +0 -0
  21. package/dist/src/assets/assets/Metropolis-Bold.woff2 +0 -0
  22. package/dist/src/assets/assets/Metropolis-BoldItalic.woff2 +0 -0
  23. package/dist/src/assets/assets/Metropolis-ExtraBold.woff2 +0 -0
  24. package/dist/src/assets/assets/Metropolis-ExtraBoldItalic.woff2 +0 -0
  25. package/dist/src/assets/assets/Metropolis-ExtraLight.woff2 +0 -0
  26. package/dist/src/assets/assets/Metropolis-ExtraLightItalic.woff2 +0 -0
  27. package/dist/src/assets/assets/Metropolis-Light.woff2 +0 -0
  28. package/dist/src/assets/assets/Metropolis-LightItalic.woff2 +0 -0
  29. package/dist/src/assets/assets/Metropolis-Medium.woff2 +0 -0
  30. package/dist/src/assets/assets/Metropolis-MediumItalic.woff2 +0 -0
  31. package/dist/src/assets/assets/Metropolis-Regular.woff2 +0 -0
  32. package/dist/src/assets/assets/Metropolis-RegularItalic.woff2 +0 -0
  33. package/dist/src/assets/assets/Metropolis-SemiBold.woff2 +0 -0
  34. package/dist/src/assets/assets/Metropolis-SemiBoldItalic.woff2 +0 -0
  35. package/dist/src/assets/assets/Metropolis-Thin.woff2 +0 -0
  36. package/dist/src/assets/assets/Metropolis-ThinItalic.woff2 +0 -0
  37. package/dist/src/assets/assets/logo.png +0 -0
  38. package/dist/src/assets/logo.png +0 -0
  39. package/dist/src/factories/AddressFactory.d.ts +10 -0
  40. package/dist/src/factories/AddressFactory.d.ts.map +1 -0
  41. package/dist/src/factories/AddressFactory.js +42 -0
  42. package/dist/src/factories/AddressFactory.js.map +1 -0
  43. package/dist/src/factories/EmergencyContactFactory.d.ts +9 -0
  44. package/dist/src/factories/EmergencyContactFactory.d.ts.map +1 -0
  45. package/dist/src/factories/EmergencyContactFactory.js +42 -0
  46. package/dist/src/factories/EmergencyContactFactory.js.map +1 -0
  47. package/dist/src/factories/GroupFactory.d.ts +19 -0
  48. package/dist/src/factories/GroupFactory.d.ts.map +1 -0
  49. package/dist/src/factories/GroupFactory.js +52 -0
  50. package/dist/src/factories/GroupFactory.js.map +1 -0
  51. package/dist/src/factories/MemberFactory.d.ts +16 -0
  52. package/dist/src/factories/MemberFactory.d.ts.map +1 -0
  53. package/dist/src/factories/MemberFactory.js +98 -0
  54. package/dist/src/factories/MemberFactory.js.map +1 -0
  55. package/dist/src/factories/OrganizationFactory.d.ts +16 -0
  56. package/dist/src/factories/OrganizationFactory.d.ts.map +1 -0
  57. package/dist/src/factories/OrganizationFactory.js +40 -0
  58. package/dist/src/factories/OrganizationFactory.js.map +1 -0
  59. package/dist/src/factories/ParentFactory.d.ts +10 -0
  60. package/dist/src/factories/ParentFactory.d.ts.map +1 -0
  61. package/dist/src/factories/ParentFactory.js +44 -0
  62. package/dist/src/factories/ParentFactory.js.map +1 -0
  63. package/dist/src/factories/RecordFactory.d.ts +10 -0
  64. package/dist/src/factories/RecordFactory.d.ts.map +1 -0
  65. package/dist/src/factories/RecordFactory.js +14 -0
  66. package/dist/src/factories/RecordFactory.js.map +1 -0
  67. package/dist/src/factories/RegisterCodeFactory.d.ts +18 -0
  68. package/dist/src/factories/RegisterCodeFactory.d.ts.map +1 -0
  69. package/dist/src/factories/RegisterCodeFactory.js +19 -0
  70. package/dist/src/factories/RegisterCodeFactory.js.map +1 -0
  71. package/dist/src/factories/RegistrationFactory.d.ts +14 -0
  72. package/dist/src/factories/RegistrationFactory.d.ts.map +1 -0
  73. package/dist/src/factories/RegistrationFactory.js +26 -0
  74. package/dist/src/factories/RegistrationFactory.js.map +1 -0
  75. package/dist/src/factories/UserFactory.d.ts +21 -0
  76. package/dist/src/factories/UserFactory.d.ts.map +1 -0
  77. package/dist/src/factories/UserFactory.js +41 -0
  78. package/dist/src/factories/UserFactory.js.map +1 -0
  79. package/dist/src/factories/WebshopFactory.d.ts +16 -0
  80. package/dist/src/factories/WebshopFactory.d.ts.map +1 -0
  81. package/dist/src/factories/WebshopFactory.js +35 -0
  82. package/dist/src/factories/WebshopFactory.js.map +1 -0
  83. package/dist/src/helpers/DNSValidator.d.ts +6 -0
  84. package/dist/src/helpers/DNSValidator.d.ts.map +1 -0
  85. package/dist/src/helpers/DNSValidator.js +144 -0
  86. package/dist/src/helpers/DNSValidator.js.map +1 -0
  87. package/dist/src/helpers/EmailBuilder.d.ts +22 -0
  88. package/dist/src/helpers/EmailBuilder.d.ts.map +1 -0
  89. package/dist/src/helpers/EmailBuilder.js +100 -0
  90. package/dist/src/helpers/EmailBuilder.js.map +1 -0
  91. package/dist/src/helpers/GroupBuilder.d.ts +9 -0
  92. package/dist/src/helpers/GroupBuilder.d.ts.map +1 -0
  93. package/dist/src/helpers/GroupBuilder.js +382 -0
  94. package/dist/src/helpers/GroupBuilder.js.map +1 -0
  95. package/dist/src/helpers/Handlebars.d.ts +2 -0
  96. package/dist/src/helpers/Handlebars.d.ts.map +1 -0
  97. package/dist/src/helpers/Handlebars.js +192 -0
  98. package/dist/src/helpers/Handlebars.js.map +1 -0
  99. package/dist/src/helpers/InvoiceBuilder.d.ts +29 -0
  100. package/dist/src/helpers/InvoiceBuilder.d.ts.map +1 -0
  101. package/dist/src/helpers/InvoiceBuilder.js +406 -0
  102. package/dist/src/helpers/InvoiceBuilder.js.map +1 -0
  103. package/dist/src/helpers/InvoiceBuilder.test.d.ts +2 -0
  104. package/dist/src/helpers/InvoiceBuilder.test.d.ts.map +1 -0
  105. package/dist/src/helpers/InvoiceBuilder.test.js +52 -0
  106. package/dist/src/helpers/InvoiceBuilder.test.js.map +1 -0
  107. package/dist/src/helpers/RateLimiter.d.ts +27 -0
  108. package/dist/src/helpers/RateLimiter.d.ts.map +1 -0
  109. package/dist/src/helpers/RateLimiter.js +57 -0
  110. package/dist/src/helpers/RateLimiter.js.map +1 -0
  111. package/dist/src/helpers/WebshopCounter.d.ts +6 -0
  112. package/dist/src/helpers/WebshopCounter.d.ts.map +1 -0
  113. package/dist/src/helpers/WebshopCounter.js +36 -0
  114. package/dist/src/helpers/WebshopCounter.js.map +1 -0
  115. package/dist/src/helpers/WebshopCounter.test.d.ts +2 -0
  116. package/dist/src/helpers/WebshopCounter.test.d.ts.map +1 -0
  117. package/dist/src/helpers/WebshopCounter.test.js +17 -0
  118. package/dist/src/helpers/WebshopCounter.test.js.map +1 -0
  119. package/dist/src/index.d.ts +18 -0
  120. package/dist/src/index.d.ts.map +1 -0
  121. package/dist/src/index.js +23 -0
  122. package/dist/src/index.js.map +1 -0
  123. package/dist/src/migrations/1593773929-create-initial-tables.sql +634 -0
  124. package/dist/src/migrations/1605261999-gemeenten-tmp.sql +2820 -0
  125. package/dist/src/migrations/1605262045-import-postcodes.d.ts +16 -0
  126. package/dist/src/migrations/1605262045-import-postcodes.d.ts.map +1 -0
  127. package/dist/src/migrations/1605262045-import-postcodes.js +116 -0
  128. package/dist/src/migrations/1605262045-import-postcodes.js.map +1 -0
  129. package/dist/src/migrations/1605262046-import-postcodes-nl.d.ts +4 -0
  130. package/dist/src/migrations/1605262046-import-postcodes-nl.d.ts.map +1 -0
  131. package/dist/src/migrations/1605262046-import-postcodes-nl.js +83 -0
  132. package/dist/src/migrations/1605262046-import-postcodes-nl.js.map +1 -0
  133. package/dist/src/migrations/1605279038-drop-gemeenten-tmp.sql +1 -0
  134. package/dist/src/migrations/1648392491-default-templates.sql +9 -0
  135. package/dist/src/migrations/1651245707-default-templates-reminders.sql +6 -0
  136. package/dist/src/migrations/1708607340-tickets-deleted-at.sql +1 -0
  137. package/dist/src/migrations/1710459176-register-code-invoices.sql +3 -0
  138. package/dist/src/migrations/1712158247-discount-codes.sql +17 -0
  139. package/dist/src/migrations/1713178665-drop-invites.sql +1 -0
  140. package/dist/src/migrations/1713178666-drop-keychain.sql +1 -0
  141. package/dist/src/migrations/1713178667-drop-challenges.sql +1 -0
  142. package/dist/src/migrations/1713178668-drop-user-keys.sql +7 -0
  143. package/dist/src/migrations/1713178669-drop-organization-key.sql +2 -0
  144. package/dist/src/migrations/data/postcodes/nl/Drenthe +291 -0
  145. package/dist/src/migrations/data/postcodes/nl/Flevoland +107 -0
  146. package/dist/src/migrations/data/postcodes/nl/Friesland +518 -0
  147. package/dist/src/migrations/data/postcodes/nl/Gelderland +601 -0
  148. package/dist/src/migrations/data/postcodes/nl/Groningen +279 -0
  149. package/dist/src/migrations/data/postcodes/nl/Limburg +324 -0
  150. package/dist/src/migrations/data/postcodes/nl/Noord-Brabant +620 -0
  151. package/dist/src/migrations/data/postcodes/nl/Noord-Holland +566 -0
  152. package/dist/src/migrations/data/postcodes/nl/Overrijsel +344 -0
  153. package/dist/src/migrations/data/postcodes/nl/Utrecht +278 -0
  154. package/dist/src/migrations/data/postcodes/nl/Zeeland +179 -0
  155. package/dist/src/migrations/data/postcodes/nl/Zuid-Holland +662 -0
  156. package/dist/src/models/BalanceItem.d.ts +57 -0
  157. package/dist/src/models/BalanceItem.d.ts.map +1 -0
  158. package/dist/src/models/BalanceItem.js +346 -0
  159. package/dist/src/models/BalanceItem.js.map +1 -0
  160. package/dist/src/models/BalanceItemPayment.d.ts +31 -0
  161. package/dist/src/models/BalanceItemPayment.d.ts.map +1 -0
  162. package/dist/src/models/BalanceItemPayment.js +101 -0
  163. package/dist/src/models/BalanceItemPayment.js.map +1 -0
  164. package/dist/src/models/BuckarooPayment.d.ts +8 -0
  165. package/dist/src/models/BuckarooPayment.d.ts.map +1 -0
  166. package/dist/src/models/BuckarooPayment.js +24 -0
  167. package/dist/src/models/BuckarooPayment.js.map +1 -0
  168. package/dist/src/models/Document.d.ts +44 -0
  169. package/dist/src/models/Document.d.ts.map +1 -0
  170. package/dist/src/models/Document.js +194 -0
  171. package/dist/src/models/Document.js.map +1 -0
  172. package/dist/src/models/DocumentTemplate.d.ts +45 -0
  173. package/dist/src/models/DocumentTemplate.d.ts.map +1 -0
  174. package/dist/src/models/DocumentTemplate.js +533 -0
  175. package/dist/src/models/DocumentTemplate.js.map +1 -0
  176. package/dist/src/models/EmailTemplate.d.ts +22 -0
  177. package/dist/src/models/EmailTemplate.d.ts.map +1 -0
  178. package/dist/src/models/EmailTemplate.js +70 -0
  179. package/dist/src/models/EmailTemplate.js.map +1 -0
  180. package/dist/src/models/EmailVerificationCode.d.ts +60 -0
  181. package/dist/src/models/EmailVerificationCode.d.ts.map +1 -0
  182. package/dist/src/models/EmailVerificationCode.js +307 -0
  183. package/dist/src/models/EmailVerificationCode.js.map +1 -0
  184. package/dist/src/models/Group.d.ts +36 -0
  185. package/dist/src/models/Group.d.ts.map +1 -0
  186. package/dist/src/models/Group.js +231 -0
  187. package/dist/src/models/Group.js.map +1 -0
  188. package/dist/src/models/Image.d.ts +12 -0
  189. package/dist/src/models/Image.d.ts.map +1 -0
  190. package/dist/src/models/Image.js +137 -0
  191. package/dist/src/models/Image.js.map +1 -0
  192. package/dist/src/models/Member.d.ts +66 -0
  193. package/dist/src/models/Member.d.ts.map +1 -0
  194. package/dist/src/models/Member.js +309 -0
  195. package/dist/src/models/Member.js.map +1 -0
  196. package/dist/src/models/MemberResponsibilityRecord.d.ts +11 -0
  197. package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -0
  198. package/dist/src/models/MemberResponsibilityRecord.js +47 -0
  199. package/dist/src/models/MemberResponsibilityRecord.js.map +1 -0
  200. package/dist/src/models/MolliePayment.d.ts +8 -0
  201. package/dist/src/models/MolliePayment.d.ts.map +1 -0
  202. package/dist/src/models/MolliePayment.js +24 -0
  203. package/dist/src/models/MolliePayment.js.map +1 -0
  204. package/dist/src/models/MollieToken.d.ts +45 -0
  205. package/dist/src/models/MollieToken.d.ts.map +1 -0
  206. package/dist/src/models/MollieToken.js +333 -0
  207. package/dist/src/models/MollieToken.js.map +1 -0
  208. package/dist/src/models/OneTimeToken.d.ts +38 -0
  209. package/dist/src/models/OneTimeToken.d.ts.map +1 -0
  210. package/dist/src/models/OneTimeToken.js +126 -0
  211. package/dist/src/models/OneTimeToken.js.map +1 -0
  212. package/dist/src/models/Order.d.ts +99 -0
  213. package/dist/src/models/Order.d.ts.map +1 -0
  214. package/dist/src/models/Order.js +912 -0
  215. package/dist/src/models/Order.js.map +1 -0
  216. package/dist/src/models/Organization.d.ts +119 -0
  217. package/dist/src/models/Organization.d.ts.map +1 -0
  218. package/dist/src/models/Organization.js +900 -0
  219. package/dist/src/models/Organization.js.map +1 -0
  220. package/dist/src/models/OrganizationRegistrationPeriod.d.ts +14 -0
  221. package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -0
  222. package/dist/src/models/OrganizationRegistrationPeriod.js +62 -0
  223. package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -0
  224. package/dist/src/models/PasswordToken.d.ts +29 -0
  225. package/dist/src/models/PasswordToken.d.ts.map +1 -0
  226. package/dist/src/models/PasswordToken.js +118 -0
  227. package/dist/src/models/PasswordToken.js.map +1 -0
  228. package/dist/src/models/PayconiqPayment.d.ts +18 -0
  229. package/dist/src/models/PayconiqPayment.d.ts.map +1 -0
  230. package/dist/src/models/PayconiqPayment.js +216 -0
  231. package/dist/src/models/PayconiqPayment.js.map +1 -0
  232. package/dist/src/models/Payment.d.ts +62 -0
  233. package/dist/src/models/Payment.d.ts.map +1 -0
  234. package/dist/src/models/Payment.js +199 -0
  235. package/dist/src/models/Payment.js.map +1 -0
  236. package/dist/src/models/Platform.d.ts +15 -0
  237. package/dist/src/models/Platform.d.ts.map +1 -0
  238. package/dist/src/models/Platform.js +77 -0
  239. package/dist/src/models/Platform.js.map +1 -0
  240. package/dist/src/models/RegisterCode.d.ts +27 -0
  241. package/dist/src/models/RegisterCode.d.ts.map +1 -0
  242. package/dist/src/models/RegisterCode.js +162 -0
  243. package/dist/src/models/RegisterCode.js.map +1 -0
  244. package/dist/src/models/Registration.d.ts +47 -0
  245. package/dist/src/models/Registration.d.ts.map +1 -0
  246. package/dist/src/models/Registration.js +369 -0
  247. package/dist/src/models/Registration.js.map +1 -0
  248. package/dist/src/models/RegistrationPeriod.d.ts +15 -0
  249. package/dist/src/models/RegistrationPeriod.d.ts.map +1 -0
  250. package/dist/src/models/RegistrationPeriod.js +64 -0
  251. package/dist/src/models/RegistrationPeriod.js.map +1 -0
  252. package/dist/src/models/STCredit.d.ts +20 -0
  253. package/dist/src/models/STCredit.d.ts.map +1 -0
  254. package/dist/src/models/STCredit.js +129 -0
  255. package/dist/src/models/STCredit.js.map +1 -0
  256. package/dist/src/models/STInvoice.d.ts +51 -0
  257. package/dist/src/models/STInvoice.d.ts.map +1 -0
  258. package/dist/src/models/STInvoice.js +453 -0
  259. package/dist/src/models/STInvoice.js.map +1 -0
  260. package/dist/src/models/STPackage.d.ts +36 -0
  261. package/dist/src/models/STPackage.d.ts.map +1 -0
  262. package/dist/src/models/STPackage.js +300 -0
  263. package/dist/src/models/STPackage.js.map +1 -0
  264. package/dist/src/models/STPendingInvoice.d.ts +45 -0
  265. package/dist/src/models/STPendingInvoice.d.ts.map +1 -0
  266. package/dist/src/models/STPendingInvoice.js +284 -0
  267. package/dist/src/models/STPendingInvoice.js.map +1 -0
  268. package/dist/src/models/StripeAccount.d.ts +17 -0
  269. package/dist/src/models/StripeAccount.d.ts.map +1 -0
  270. package/dist/src/models/StripeAccount.js +81 -0
  271. package/dist/src/models/StripeAccount.js.map +1 -0
  272. package/dist/src/models/StripeCheckoutSession.d.ts +9 -0
  273. package/dist/src/models/StripeCheckoutSession.d.ts.map +1 -0
  274. package/dist/src/models/StripeCheckoutSession.js +31 -0
  275. package/dist/src/models/StripeCheckoutSession.js.map +1 -0
  276. package/dist/src/models/StripePaymentIntent.d.ts +9 -0
  277. package/dist/src/models/StripePaymentIntent.d.ts.map +1 -0
  278. package/dist/src/models/StripePaymentIntent.js +31 -0
  279. package/dist/src/models/StripePaymentIntent.js.map +1 -0
  280. package/dist/src/models/Ticket.d.ts +61 -0
  281. package/dist/src/models/Ticket.d.ts.map +1 -0
  282. package/dist/src/models/Ticket.js +143 -0
  283. package/dist/src/models/Ticket.js.map +1 -0
  284. package/dist/src/models/Token.d.ts +49 -0
  285. package/dist/src/models/Token.d.ts.map +1 -0
  286. package/dist/src/models/Token.js +218 -0
  287. package/dist/src/models/Token.js.map +1 -0
  288. package/dist/src/models/Token.test.d.ts +2 -0
  289. package/dist/src/models/Token.test.d.ts.map +1 -0
  290. package/dist/src/models/Token.test.js +60 -0
  291. package/dist/src/models/Token.test.js.map +1 -0
  292. package/dist/src/models/UsedRegisterCode.d.ts +22 -0
  293. package/dist/src/models/UsedRegisterCode.d.ts.map +1 -0
  294. package/dist/src/models/UsedRegisterCode.js +158 -0
  295. package/dist/src/models/UsedRegisterCode.js.map +1 -0
  296. package/dist/src/models/User.d.ts +55 -0
  297. package/dist/src/models/User.d.ts.map +1 -0
  298. package/dist/src/models/User.js +314 -0
  299. package/dist/src/models/User.js.map +1 -0
  300. package/dist/src/models/UserPermissions.d.ts +15 -0
  301. package/dist/src/models/UserPermissions.d.ts.map +1 -0
  302. package/dist/src/models/UserPermissions.js +57 -0
  303. package/dist/src/models/UserPermissions.js.map +1 -0
  304. package/dist/src/models/Webshop.d.ts +44 -0
  305. package/dist/src/models/Webshop.d.ts.map +1 -0
  306. package/dist/src/models/Webshop.js +184 -0
  307. package/dist/src/models/Webshop.js.map +1 -0
  308. package/dist/src/models/WebshopDiscountCode.d.ts +18 -0
  309. package/dist/src/models/WebshopDiscountCode.d.ts.map +1 -0
  310. package/dist/src/models/WebshopDiscountCode.js +88 -0
  311. package/dist/src/models/WebshopDiscountCode.js.map +1 -0
  312. package/dist/src/models/addresses/City.d.ts +14 -0
  313. package/dist/src/models/addresses/City.d.ts.map +1 -0
  314. package/dist/src/models/addresses/City.js +37 -0
  315. package/dist/src/models/addresses/City.js.map +1 -0
  316. package/dist/src/models/addresses/PostalCode.d.ts +20 -0
  317. package/dist/src/models/addresses/PostalCode.d.ts.map +1 -0
  318. package/dist/src/models/addresses/PostalCode.js +138 -0
  319. package/dist/src/models/addresses/PostalCode.js.map +1 -0
  320. package/dist/src/models/addresses/PostalCode.test.d.ts +2 -0
  321. package/dist/src/models/addresses/PostalCode.test.d.ts.map +1 -0
  322. package/dist/src/models/addresses/PostalCode.test.js +98 -0
  323. package/dist/src/models/addresses/PostalCode.test.js.map +1 -0
  324. package/dist/src/models/addresses/Province.d.ts +9 -0
  325. package/dist/src/models/addresses/Province.d.ts.map +1 -0
  326. package/dist/src/models/addresses/Province.js +24 -0
  327. package/dist/src/models/addresses/Province.js.map +1 -0
  328. package/dist/src/models/addresses/Street.d.ts +10 -0
  329. package/dist/src/models/addresses/Street.d.ts.map +1 -0
  330. package/dist/src/models/addresses/Street.js +26 -0
  331. package/dist/src/models/addresses/Street.js.map +1 -0
  332. package/dist/src/models/index.d.ts +37 -0
  333. package/dist/src/models/index.d.ts.map +1 -0
  334. package/dist/src/models/index.js +53 -0
  335. package/dist/src/models/index.js.map +1 -0
  336. package/dist/src/structures/OrganizationServerMetaData.d.ts +43 -0
  337. package/dist/src/structures/OrganizationServerMetaData.d.ts.map +1 -0
  338. package/dist/src/structures/OrganizationServerMetaData.js +128 -0
  339. package/dist/src/structures/OrganizationServerMetaData.js.map +1 -0
  340. package/dist/tests/jest.global.setup.d.ts +3 -0
  341. package/dist/tests/jest.global.setup.d.ts.map +1 -0
  342. package/dist/tests/jest.global.setup.js +20 -0
  343. package/dist/tests/jest.global.setup.js.map +1 -0
  344. package/dist/tests/jest.setup.d.ts +2 -0
  345. package/dist/tests/jest.setup.d.ts.map +1 -0
  346. package/dist/tests/jest.setup.js +15 -0
  347. package/dist/tests/jest.setup.js.map +1 -0
  348. package/package.json +30 -0
  349. package/src/assets/Metropolis-Black.woff2 +0 -0
  350. package/src/assets/Metropolis-BlackItalic.woff2 +0 -0
  351. package/src/assets/Metropolis-Bold.woff2 +0 -0
  352. package/src/assets/Metropolis-BoldItalic.woff2 +0 -0
  353. package/src/assets/Metropolis-ExtraBold.woff2 +0 -0
  354. package/src/assets/Metropolis-ExtraBoldItalic.woff2 +0 -0
  355. package/src/assets/Metropolis-ExtraLight.woff2 +0 -0
  356. package/src/assets/Metropolis-ExtraLightItalic.woff2 +0 -0
  357. package/src/assets/Metropolis-Light.woff2 +0 -0
  358. package/src/assets/Metropolis-LightItalic.woff2 +0 -0
  359. package/src/assets/Metropolis-Medium.woff2 +0 -0
  360. package/src/assets/Metropolis-MediumItalic.woff2 +0 -0
  361. package/src/assets/Metropolis-Regular.woff2 +0 -0
  362. package/src/assets/Metropolis-RegularItalic.woff2 +0 -0
  363. package/src/assets/Metropolis-SemiBold.woff2 +0 -0
  364. package/src/assets/Metropolis-SemiBoldItalic.woff2 +0 -0
  365. package/src/assets/Metropolis-Thin.woff2 +0 -0
  366. package/src/assets/Metropolis-ThinItalic.woff2 +0 -0
  367. package/src/assets/logo.png +0 -0
  368. package/src/factories/AddressFactory.ts +42 -0
  369. package/src/factories/EmergencyContactFactory.ts +43 -0
  370. package/src/factories/GroupFactory.ts +66 -0
  371. package/src/factories/MemberFactory.ts +122 -0
  372. package/src/factories/OrganizationFactory.ts +45 -0
  373. package/src/factories/ParentFactory.ts +49 -0
  374. package/src/factories/RecordFactory.ts +12 -0
  375. package/src/factories/RegisterCodeFactory.ts +25 -0
  376. package/src/factories/RegistrationFactory.ts +32 -0
  377. package/src/factories/UserFactory.ts +66 -0
  378. package/src/factories/WebshopFactory.ts +43 -0
  379. package/src/helpers/DNSValidator.ts +153 -0
  380. package/src/helpers/EmailBuilder.ts +127 -0
  381. package/src/helpers/GroupBuilder.ts +438 -0
  382. package/src/helpers/Handlebars.ts +203 -0
  383. package/src/helpers/InvoiceBuilder.test.ts +57 -0
  384. package/src/helpers/InvoiceBuilder.ts +501 -0
  385. package/src/helpers/RateLimiter.ts +75 -0
  386. package/src/helpers/WebshopCounter.test.ts +16 -0
  387. package/src/helpers/WebshopCounter.ts +36 -0
  388. package/src/index.ts +21 -0
  389. package/src/migrations/1593773929-create-initial-tables.sql +634 -0
  390. package/src/migrations/1605261999-gemeenten-tmp.sql +2820 -0
  391. package/src/migrations/1605262045-import-postcodes.ts +132 -0
  392. package/src/migrations/1605262046-import-postcodes-nl.ts +97 -0
  393. package/src/migrations/1605279038-drop-gemeenten-tmp.sql +1 -0
  394. package/src/migrations/1648392491-default-templates.sql +9 -0
  395. package/src/migrations/1651245707-default-templates-reminders.sql +6 -0
  396. package/src/migrations/1708607340-tickets-deleted-at.sql +1 -0
  397. package/src/migrations/1710459176-register-code-invoices.sql +3 -0
  398. package/src/migrations/1712158247-discount-codes.sql +17 -0
  399. package/src/migrations/1713178665-drop-invites.sql +1 -0
  400. package/src/migrations/1713178666-drop-keychain.sql +1 -0
  401. package/src/migrations/1713178667-drop-challenges.sql +1 -0
  402. package/src/migrations/1713178668-drop-user-keys.sql +7 -0
  403. package/src/migrations/1713178669-drop-organization-key.sql +2 -0
  404. package/src/migrations/1714985451-user-nullable-organization-id.sql +2 -0
  405. package/src/migrations/1714985452-email-verification-code-nullable-organization-id.sql +2 -0
  406. package/src/migrations/1714985453-user-organization-permissions.sql +2 -0
  407. package/src/migrations/1714985454-user-organization-permissions.sql +2 -0
  408. package/src/migrations/1715079362-platform.sql +6 -0
  409. package/src/migrations/1715181649-registrations-organization-id.sql +2 -0
  410. package/src/migrations/1715181650-registrations-organization-id-fill.sql +1 -0
  411. package/src/migrations/1715181651-registrations-organization-id-drop-null.sql +2 -0
  412. package/src/migrations/1716117067-members-nullable-organization-id.sql +2 -0
  413. package/src/migrations/1719567581-registration-periods.sql +13 -0
  414. package/src/migrations/1719567582-organization-registration-periods.sql +13 -0
  415. package/src/migrations/1719567881-organization-periodId.sql +2 -0
  416. package/src/migrations/1719567882-groups-periodId.sql +2 -0
  417. package/src/migrations/1719567883-platform-periodId.sql +2 -0
  418. package/src/migrations/1719568079-default-period.sql +2 -0
  419. package/src/migrations/1719568080-set-default-period-platform.sql +1 -0
  420. package/src/migrations/1719568081-set-default-period-organizations.sql +1 -0
  421. package/src/migrations/1719568082-set-default-period-groups.sql +1 -0
  422. package/src/migrations/1719580828-registrations-periodId.sql +2 -0
  423. package/src/migrations/1719580829-set-default-period-registrations.sql +1 -0
  424. package/src/migrations/data/postcodes/nl/Drenthe +291 -0
  425. package/src/migrations/data/postcodes/nl/Flevoland +107 -0
  426. package/src/migrations/data/postcodes/nl/Friesland +518 -0
  427. package/src/migrations/data/postcodes/nl/Gelderland +601 -0
  428. package/src/migrations/data/postcodes/nl/Groningen +279 -0
  429. package/src/migrations/data/postcodes/nl/Limburg +324 -0
  430. package/src/migrations/data/postcodes/nl/Noord-Brabant +620 -0
  431. package/src/migrations/data/postcodes/nl/Noord-Holland +566 -0
  432. package/src/migrations/data/postcodes/nl/Overrijsel +344 -0
  433. package/src/migrations/data/postcodes/nl/Utrecht +278 -0
  434. package/src/migrations/data/postcodes/nl/Zeeland +179 -0
  435. package/src/migrations/data/postcodes/nl/Zuid-Holland +662 -0
  436. package/src/models/BalanceItem.ts +392 -0
  437. package/src/models/BalanceItemPayment.ts +106 -0
  438. package/src/models/BuckarooPayment.ts +19 -0
  439. package/src/models/Document.ts +203 -0
  440. package/src/models/DocumentTemplate.ts +583 -0
  441. package/src/models/EmailTemplate.ts +64 -0
  442. package/src/models/EmailVerificationCode.ts +352 -0
  443. package/src/models/Group.ts +293 -0
  444. package/src/models/Image.ts +147 -0
  445. package/src/models/Member.ts +386 -0
  446. package/src/models/MemberResponsibilityRecord.ts +39 -0
  447. package/src/models/MolliePayment.ts +19 -0
  448. package/src/models/MollieToken.ts +369 -0
  449. package/src/models/OneTimeToken.ts +131 -0
  450. package/src/models/Order.ts +1030 -0
  451. package/src/models/Organization.ts +1085 -0
  452. package/src/models/OrganizationRegistrationPeriod.ts +54 -0
  453. package/src/models/PasswordToken.ts +139 -0
  454. package/src/models/PayconiqPayment.ts +241 -0
  455. package/src/models/Payment.ts +216 -0
  456. package/src/models/Platform.ts +76 -0
  457. package/src/models/RegisterCode.ts +164 -0
  458. package/src/models/Registration.ts +405 -0
  459. package/src/models/RegistrationPeriod.ts +55 -0
  460. package/src/models/STCredit.ts +134 -0
  461. package/src/models/STInvoice.ts +507 -0
  462. package/src/models/STPackage.ts +324 -0
  463. package/src/models/STPendingInvoice.ts +308 -0
  464. package/src/models/StripeAccount.ts +71 -0
  465. package/src/models/StripeCheckoutSession.ts +22 -0
  466. package/src/models/StripePaymentIntent.ts +22 -0
  467. package/src/models/Ticket.ts +145 -0
  468. package/src/models/Token.test.ts +69 -0
  469. package/src/models/Token.ts +269 -0
  470. package/src/models/UsedRegisterCode.ts +166 -0
  471. package/src/models/User.ts +445 -0
  472. package/src/models/UserPermissions.ts +54 -0
  473. package/src/models/Webshop.ts +206 -0
  474. package/src/models/WebshopDiscountCode.ts +81 -0
  475. package/src/models/addresses/City.ts +31 -0
  476. package/src/models/addresses/PostalCode.test.ts +117 -0
  477. package/src/models/addresses/PostalCode.ts +164 -0
  478. package/src/models/addresses/Province.ts +20 -0
  479. package/src/models/addresses/Street.ts +25 -0
  480. package/src/models/index.ts +49 -0
  481. package/src/structures/OrganizationServerMetaData.ts +117 -0
@@ -0,0 +1,501 @@
1
+ import { SimpleError } from "@simonbackx/simple-errors";
2
+ import { File, PaymentMethod, PaymentMethodHelper, PaymentStatus, STInvoiceItem } from "@stamhoofd/structures";
3
+ import { Formatter } from "@stamhoofd/utility";
4
+ import AWS from 'aws-sdk';
5
+ import PDFDocument from 'pdfkit';
6
+ import { v4 as uuidv4 } from "uuid";
7
+
8
+ import { Payment, STInvoice } from "../models";
9
+
10
+ // 1 mm
11
+ const MM = 2.834666666666667
12
+ const COLOR_PRIMARY = "#0053ff"
13
+ const COLOR_DARK = "#000716"
14
+ const COLOR_GRAY_DARK = "#5e5e5e"
15
+ const COLOR_GRAY = "#868686";
16
+
17
+ const PAGE_WIDTH = 595.28
18
+ const PAGE_HEIGHT = 841.89
19
+
20
+ const ITEM_MARGIN = 5*MM
21
+
22
+ const PAGE_MARGIN = 16*MM
23
+
24
+ const END_MAX_Y = 567; // End of page line for last page
25
+ const MAX_Y = PAGE_HEIGHT - 24*MM
26
+
27
+ // Can we fit everything on one page?
28
+ const FIRST_START_Y = 100*MM;
29
+ const NORMAL_START_Y = PAGE_MARGIN;
30
+
31
+ export class InvoiceBuilder {
32
+ invoice: STInvoice
33
+ payment: Payment | null = null
34
+ document: PDFKit.PDFDocument
35
+
36
+ private remainingItems: STInvoiceItem[]
37
+
38
+ private posY = 0
39
+ private page = 1
40
+
41
+ private dataBuffer: any[] = []
42
+
43
+ constructor(invoice: STInvoice) {
44
+ this.invoice = invoice
45
+ this.document = new PDFDocument({ size: [PAGE_WIDTH, PAGE_HEIGHT], margin: PAGE_MARGIN});
46
+ }
47
+
48
+ async build() {
49
+ if (!STAMHOOFD.SPACES_BUCKET || !STAMHOOFD.SPACES_ENDPOINT || !STAMHOOFD.SPACES_KEY || !STAMHOOFD.SPACES_SECRET) {
50
+ throw new SimpleError({
51
+ code: "not_available",
52
+ message: "Uploading is not available",
53
+ statusCode: 503
54
+ })
55
+ }
56
+
57
+ this.payment = (this.invoice.paymentId ? await Payment.getByID(this.invoice.paymentId) : null) ?? null
58
+
59
+ const buffer = await new Promise<Buffer>((resolve, reject) => {
60
+ try {
61
+ this.dataBuffer = [];
62
+ this.document.on('data', (d) => { this.dataBuffer.push(d); });
63
+ this.document.on('end', () => {
64
+ const buf = Buffer.concat(this.dataBuffer);
65
+ resolve(buf)
66
+ });
67
+
68
+ this.document.registerFont('Metropolis-SemiBold', __dirname +'/../assets/Metropolis-SemiBold.woff2');
69
+ this.document.registerFont('Metropolis-Medium', __dirname +'/../assets/Metropolis-Medium.woff2');
70
+
71
+ this.remainingItems = this.invoice.meta.items.slice()
72
+
73
+ // Initiate building
74
+ this.drawNextPages()
75
+ this.drawPriceFooter()
76
+ this.document.end()
77
+ } catch (e) {
78
+ reject(e)
79
+ }
80
+ });
81
+
82
+ const fileId = uuidv4();
83
+
84
+ let prefix = (STAMHOOFD.SPACES_PREFIX ?? "")
85
+ if (prefix.length > 0) {
86
+ prefix += "/"
87
+ }
88
+ const key = prefix + (STAMHOOFD.environment ?? "development") + "/invoices/" + fileId + ".pdf";
89
+
90
+ const s3 = new AWS.S3({
91
+ endpoint: STAMHOOFD.SPACES_ENDPOINT,
92
+ accessKeyId: STAMHOOFD.SPACES_KEY,
93
+ secretAccessKey: STAMHOOFD.SPACES_SECRET
94
+ });
95
+
96
+ const params = {
97
+ Bucket: STAMHOOFD.SPACES_BUCKET,
98
+ Key: key,
99
+ Body: buffer,
100
+ ContentType: 'application/pdf',
101
+ ACL: "public-read"
102
+ };
103
+
104
+ await s3.putObject(params).promise()
105
+
106
+ return new File({
107
+ id: fileId,
108
+ server: "https://"+STAMHOOFD.SPACES_BUCKET+"."+STAMHOOFD.SPACES_ENDPOINT,
109
+ path: key,
110
+ size: buffer.byteLength,
111
+ name: "Invoice "+this.invoice.id
112
+ });
113
+ }
114
+
115
+ private writeHeader() {
116
+ const logoX = 16
117
+ const logoY = 17
118
+ const logoHeight = 13
119
+
120
+ this.document.image(__dirname + '/../assets/logo.png', (logoX - 1) * MM, logoY * MM, { height: logoHeight * MM })
121
+
122
+
123
+ this.posY = 44
124
+
125
+ // Invoice number
126
+ this.document.fontSize(4.24 * MM);
127
+ this.document.fillColor(COLOR_DARK);
128
+ this.document.font('Metropolis-SemiBold')
129
+
130
+ if (this.invoice.number) {
131
+ this.document.text("Factuur", logoX * MM, this.posY * MM, { align: 'left' })
132
+ this.document.fillColor(COLOR_PRIMARY);
133
+ this.document.text(this.invoice.number + "", 43 * MM, this.posY * MM, { align: 'left' })
134
+ } else {
135
+ this.document.text("Pro-forma factuur", logoX * MM, this.posY * MM, { align: 'left' })
136
+ }
137
+
138
+ this.posY = 53
139
+ this.document.fontSize(3 * MM);
140
+ this.document.fillColor(COLOR_GRAY_DARK);
141
+ this.document.font('Metropolis-Medium')
142
+ const date = this.invoice.meta.date ?? this.invoice.paidAt ?? this.invoice.createdAt ?? new Date()
143
+
144
+ this.document.text("Datum", logoX * MM, this.posY * MM, { align: 'left' })
145
+ this.document.text(Formatter.date(date, true), 43 * MM, this.posY * MM, { align: 'left' })
146
+
147
+ if (this.invoice.number) {
148
+ this.document.moveDown()
149
+ const savedY = this.document.y
150
+ this.document.text("Vervaldatum", logoX * MM, savedY, { align: 'left' })
151
+ this.document.text(Formatter.date(((this.payment && this.payment.status === PaymentStatus.Succeeded) || (!this.payment && this.invoice.organizationId)) ? date : new Date(date.getTime() + 1000 * 60 * 60 * 24 * 30), true), 43 * MM, savedY, { align: 'left' })
152
+ }
153
+
154
+ // Write Codawood BV
155
+ const x = 120
156
+ const y = 21
157
+
158
+ this.document.fontSize(4.24 * MM);
159
+ this.document.fillColor(COLOR_DARK);
160
+ this.document.font('Metropolis-SemiBold')
161
+
162
+ this.document.text("Codawood BV", x * MM, y * MM, { align: 'left' })
163
+
164
+ this.document.fontSize(3 * MM);
165
+ this.document.fillColor(COLOR_GRAY_DARK);
166
+ this.document.font('Metropolis-Medium')
167
+
168
+ this.document.text("Collegiebaan 54, Wetteren, België\nBE0747.832.683", x * MM, this.document.y + 4*MM, { align: 'left', width: 72 * MM, lineGap: 2*MM })
169
+
170
+ // Write customer
171
+
172
+ this.document.fontSize(4.24 * MM);
173
+ this.document.fillColor(COLOR_DARK);
174
+ this.document.font('Metropolis-SemiBold')
175
+
176
+ this.document.text(this.invoice.number ? "Factuur voor" : "Voor", x * MM, this.document.y + 10*MM, { align: 'left' })
177
+
178
+ this.document.fontSize(3 * MM);
179
+ this.document.fillColor(COLOR_GRAY_DARK);
180
+ this.document.font('Metropolis-Medium')
181
+
182
+ const showNumber = this.invoice.meta.companyNumber && (!this.invoice.meta.companyVATNumber || (this.invoice.meta.companyNumber !== this.invoice.meta.companyVATNumber.substring(2) && this.invoice.meta.companyNumber !== this.invoice.meta.companyVATNumber));
183
+
184
+ this.document.text(
185
+ this.invoice.meta.companyName
186
+ + (this.invoice.meta.companyContact ? ("\n"+this.invoice.meta.companyContact) : "")
187
+ + "\n"
188
+ + this.invoice.meta.companyAddress.toString()
189
+ + (showNumber ? ("\n"+this.invoice.meta.companyNumber) : "")
190
+ + (this.invoice.meta.companyVATNumber ? ("\n"+(showNumber ? "BTW: " : "")+this.invoice.meta.companyVATNumber) : "")
191
+ , x * MM
192
+ , this.document.y + 4*MM
193
+ , { align: 'left', width: 72 * MM, lineGap: 2*MM }
194
+ )
195
+
196
+ }
197
+
198
+ drawSinglePageShape() {
199
+ const grad = this.document.linearGradient(0, 0, 0, PAGE_HEIGHT);
200
+ grad.stop(0, COLOR_PRIMARY, 0.05)
201
+ grad.stop(1, COLOR_PRIMARY, 0.0125)
202
+ this.document.path("M77.7712 218.083L171.619 235.042C243.199 247.977 296.942 170.932 260.082 108.224C227.956 53.5718 264.75 -15.7544 328.017 -19.7785L448.398 -27.4352C464.702 -28.4722 480.75 -32.0117 495.978 -37.9294L675 -107.5L620.736 657.908C632.149 683.877 636.326 712.954 632.019 741.981L599 964.5L620.736 657.908C610.866 635.452 595.586 615.319 575.701 599.553C517.911 553.731 435.178 556.051 379.56 604.487C336.64 641.865 276.285 652.913 223.063 632.745L207.613 626.89C152.353 605.95 90.367 613.137 41.3649 646.167L-82.2193 729.468C-100.412 741.73 -124.568 726.81 -121.748 705.052L-72.9101 328.306C-63.4384 255.239 5.26735 204.981 77.7712 218.083Z").fill(grad)
203
+ }
204
+
205
+ drawLastPageShape() {
206
+ const grad = this.document.linearGradient(0, 0, 0, PAGE_HEIGHT);
207
+ grad.stop(0, COLOR_PRIMARY, 0.05)
208
+ grad.stop(1, COLOR_PRIMARY, 0.0125)
209
+ this.document.path("M-0.5 217.5L0 0H596L597.916 613.667L634.755 642.877C641.094 647.903 644.268 655.931 643.081 663.933C638.973 691.617 598.15 688.669 598.062 660.681L597.916 613.667L575.701 596.053C517.911 550.231 435.178 552.551 379.56 600.987C336.64 638.365 276.285 649.413 223.063 629.245L207.613 623.39C152.353 602.45 90.367 609.637 41.3649 642.667L-76.3939 722.041C-95.0939 734.646 -119.534 717.721 -114.314 695.783L-0.5 217.5Z").fill(grad)
210
+ }
211
+
212
+ drawFirstPageShape() {
213
+ const grad = this.document.linearGradient(0, 0, 0, PAGE_HEIGHT);
214
+ grad.stop(0, COLOR_PRIMARY, 0.05)
215
+ grad.stop(1, COLOR_PRIMARY, 0.0125)
216
+ this.document.path("M75.804 217.728L171.619 235.042C243.199 247.977 296.942 170.932 260.082 108.224C227.956 53.5718 264.75 -15.7544 328.017 -19.7785L473 -29H658L617 853.5H187.043C61.057 853.5 -56.3482 789.664 -124.84 683.922C-127.52 679.785 -128.591 674.809 -127.85 669.935L-75.5533 325.915C-64.5699 253.664 3.88734 204.732 75.804 217.728Z").fill(grad)
217
+ }
218
+
219
+ drawBackground() {
220
+ // Create a linear gradient
221
+ const grad = this.document.linearGradient(0, 0, 0, PAGE_HEIGHT);
222
+ grad.stop(0, "#F1F6FF", 1)
223
+ grad.stop(1, "#FFFFFF", 1)
224
+ this.document.rect(0, 0, PAGE_WIDTH, PAGE_HEIGHT).fill(grad)
225
+ }
226
+
227
+ private remainingItemHeight() {
228
+ let y = 0
229
+ for (const item of this.remainingItems) {
230
+ y += ITEM_MARGIN
231
+ y += this.drawInvoiceItem(item, y, true)
232
+ y += ITEM_MARGIN
233
+ }
234
+
235
+ return y
236
+ }
237
+
238
+ drawNextPages() {
239
+ if (this.page == 1) {
240
+ this.posY = FIRST_START_Y
241
+ } else {
242
+ this.posY = NORMAL_START_Y
243
+ }
244
+
245
+ this.drawBackground()
246
+
247
+ if (this.remainingItemHeight() + this.posY > END_MAX_Y) {
248
+ // No end on this page
249
+ if (this.page === 1) {
250
+ // First page
251
+ this.drawFirstPageShape()
252
+
253
+ } else {
254
+ // Middle page
255
+ // No background
256
+ }
257
+ } else {
258
+ // Will end on this page
259
+ if (this.page === 1) {
260
+ // Single page
261
+ this.drawSinglePageShape()
262
+ } else {
263
+ // Last page
264
+ this.drawLastPageShape()
265
+ }
266
+ }
267
+
268
+ if (this.page === 1) {
269
+ this.posY += this.drawTableHeader(this.posY)
270
+ this.posY += ITEM_MARGIN/2;
271
+ }
272
+
273
+ for (const [index, item] of this.remainingItems.entries()) {
274
+ let h = 0
275
+ h += ITEM_MARGIN
276
+ h += this.drawInvoiceItem(item, this.posY, true)
277
+ h += ITEM_MARGIN
278
+ if (h + this.posY > MAX_Y) {
279
+ // Remove all items that were already printed (excluding the current one)
280
+ this.remainingItems.splice(0, index)
281
+
282
+ // Doesn't fit on this page
283
+ this.endPage()
284
+ this.page++
285
+ this.document.addPage()
286
+ this.drawNextPages()
287
+ return
288
+ }
289
+
290
+ if (index > 0) {
291
+ // Print line
292
+ this.document.lineWidth(1)
293
+ this.document.lineCap('round')
294
+ this.document.moveTo(28*MM, this.posY - 1) // We use the line gap of the last text
295
+ .lineTo(PAGE_WIDTH, this.posY - 1)
296
+ .strokeOpacity(0.1)
297
+ .stroke(COLOR_DARK);
298
+ }
299
+
300
+ // Does fit
301
+ this.posY += ITEM_MARGIN
302
+ this.posY += this.drawInvoiceItem(item, this.posY, false)
303
+ this.posY += ITEM_MARGIN
304
+
305
+ // TODO: print line
306
+ }
307
+
308
+ this.endPage()
309
+
310
+ // TODO: print pricing footer
311
+ }
312
+
313
+ endPage() {
314
+ if (this.page == 1) {
315
+ this.writeHeader()
316
+ }
317
+
318
+ this.drawPageFooter()
319
+ }
320
+
321
+ /**
322
+ * Returns the height of the drawn item
323
+ */
324
+ drawInvoiceItem(item: STInvoiceItem, y: number, dryRun: boolean) {
325
+ const x1 = PAGE_MARGIN;
326
+ const x2 = 28*MM;
327
+ const x4 = PAGE_WIDTH - PAGE_MARGIN - 20*MM;
328
+ const x3 = x4 - 20*MM;
329
+
330
+
331
+ this.document.fontSize(3.5 * MM);
332
+ this.document.fillColor(COLOR_DARK);
333
+ this.document.font('Metropolis-Medium')
334
+
335
+ let height = 0
336
+
337
+
338
+ if (!dryRun) {
339
+ this.document.text(item.amount+"", x1, y, { align: 'left', width: x2 - x1 })
340
+ this.document.text(item.name, x2, y, { align: 'left', width: x3 - x2 - 5*MM, lineGap: 2*MM })
341
+ }
342
+
343
+ height += this.document.heightOfString(item.name, { align: 'left', width: x3 - x2 - 5*MM, lineGap: 2*MM })
344
+
345
+ if (item.description) {
346
+ height += 1*MM
347
+ this.document.fontSize(3 * MM);
348
+ this.document.fillColor(COLOR_GRAY_DARK);
349
+ if (!dryRun) {
350
+ this.document.text(item.description, x2, this.document.y + 1*MM, { align: 'left', width: x3 - x2 - 5*MM, lineGap: 2*MM })
351
+ }
352
+ height += this.document.heightOfString(item.description, { align: 'left', width: x3 - x2 - 5*MM, lineGap: 2*MM })
353
+
354
+ this.document.fillColor(COLOR_DARK);
355
+ this.document.fontSize(3.5 * MM);
356
+ }
357
+
358
+ if (!dryRun) {
359
+ // We need to show prices exluding VAT and round here if needed
360
+ let unitPrice = item.unitPrice
361
+ let price = item.price
362
+
363
+ if (this.invoice.meta.areItemsIncludingVAT) {
364
+ unitPrice = this.invoice.meta.includingVATToExcludingVAT(unitPrice)
365
+ price = this.invoice.meta.includingVATToExcludingVAT(price)
366
+ }
367
+
368
+ // eslint-disable-next-line no-irregular-whitespace
369
+ this.document.text(Formatter.price(unitPrice).replace(/ /g, " "), x3, y, { align: 'left', width: x4 - x3 })
370
+ // eslint-disable-next-line no-irregular-whitespace
371
+ this.document.text(Formatter.price(price).replace(/ /g, " "), x4, y, { align: 'right', width: PAGE_WIDTH - x4 - PAGE_MARGIN })
372
+ }
373
+
374
+ return height
375
+ }
376
+
377
+ drawTableHeader(y: number) {
378
+ const x1 = PAGE_MARGIN;
379
+ const x2 = 28*MM;
380
+ const x4 = PAGE_WIDTH - PAGE_MARGIN - 20*MM;
381
+ const x3 = x4 - 20*MM;
382
+
383
+ this.document.fontSize(3.5 * MM);
384
+ this.document.fillColor(COLOR_DARK);
385
+ this.document.font('Metropolis-SemiBold')
386
+ this.document.text("#", x1, y, { align: 'left', width: x2 - x1 })
387
+ this.document.text("Omschrijving", x2, y, { align: 'left', width: x3 - x2 - 5*MM })
388
+ this.document.text("Per stuk", x3, y, { align: 'left', width: x4 - x3 })
389
+ this.document.text("Totaal", x4, y, { align: 'right', width: PAGE_WIDTH - x4 - PAGE_MARGIN })
390
+
391
+ return this.document.heightOfString("Omschrijving", { align: 'left', width: x3 - x2 - 5*MM })
392
+ }
393
+
394
+ drawPriceFooter() {
395
+ let y = END_MAX_Y + 40*MM;
396
+ const x4 = PAGE_WIDTH - PAGE_MARGIN - 30*MM;
397
+
398
+ this.document.fontSize(3.5 * MM);
399
+ this.document.fillColor(COLOR_DARK);
400
+ this.document.font('Metropolis-SemiBold')
401
+
402
+
403
+ this.document.text("Totaal excl. BTW", x4 - 40*MM, y, { align: 'right', width: 40*MM })
404
+ this.document.font('Metropolis-Medium')
405
+ // eslint-disable-next-line no-irregular-whitespace
406
+ this.document.text(Formatter.price(this.invoice.meta.priceWithoutVAT).replace(/ /g, " ").replace(/,00/g, ""), x4, y, { align: 'right', width: PAGE_WIDTH - x4 - PAGE_MARGIN })
407
+
408
+ y = this.document.y + 5*MM
409
+ this.document.font('Metropolis-SemiBold')
410
+ this.document.text("BTW ("+this.invoice.meta.VATPercentage+"%)", x4 - 40*MM, y, { align: 'right', width: 40*MM })
411
+ this.document.font('Metropolis-Medium')
412
+ // eslint-disable-next-line no-irregular-whitespace
413
+ this.document.text(Formatter.price(this.invoice.meta.VAT).replace(/ /g, " ").replace(/,00/g, ""), x4, y, { align: 'right', width: PAGE_WIDTH - x4 - PAGE_MARGIN })
414
+
415
+ // Keep semibold
416
+ this.document.font('Metropolis-SemiBold')
417
+ y = this.document.y + 5*MM
418
+ this.document.fontSize(4 * MM);
419
+ this.document.text("Totaal incl. BTW", x4 - 40*MM, y, { align: 'right', width: 40*MM })
420
+ this.document.fontSize(3.5 * MM);
421
+ // eslint-disable-next-line no-irregular-whitespace
422
+ this.document.text(Formatter.price(this.invoice.meta.priceWithVAT).replace(/ /g, " ").replace(/,00/g, ""), x4, y, { align: 'right', width: PAGE_WIDTH - x4 - PAGE_MARGIN })
423
+
424
+ y = this.document.y - 12
425
+ this.document.fillColor(COLOR_GRAY_DARK)
426
+ this.document.translate(PAGE_MARGIN, y).path("M3.67327 2.52862C1.50134 4.01571 1.21296 6.95436 2.11388 8.30055C4.78725 6.67111 6.69703 5.33679 8.70409 3.72095C8.46387 4.06251 8.14127 4.46052 7.74941 4.90029C7.12008 5.60656 6.34856 6.38067 5.54204 7.14116C3.92626 8.66473 2.20363 10.1022 1.26444 10.7931C0.967076 11.0118 0.903352 11.4303 1.12211 11.7276C1.34087 12.025 1.75928 12.0887 2.05665 11.87C2.70394 11.3938 3.67804 10.6022 4.73273 9.68002C9.48876 10.8971 12.1197 6.08032 11.5772 0.148376C9.9992 0.814142 8.7907 0.987292 7.69217 1.14468C6.34654 1.33748 5.16591 1.50664 3.67327 2.52862Z").fill('even-odd')
427
+
428
+ let text = "Hou deze factuur bij voorkeur digitaal bij"
429
+ if (!this.invoice.number) {
430
+ text = "Druk dit document niet af. Dit is nog geen officiële factuur"
431
+ }
432
+ this.document.translate(-PAGE_MARGIN, -y)
433
+ const hh = this.document.heightOfString(text, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 })
434
+ this.document.text(text, PAGE_MARGIN + 8*MM, y + 12/2 - hh/2, { align: 'left' })
435
+
436
+ if (this.payment && this.payment.method) {
437
+ if (this.payment.status === PaymentStatus.Succeeded) {
438
+ y -= 10*MM
439
+ this.document.fillColor(COLOR_PRIMARY)
440
+ this.document.translate(PAGE_MARGIN, y).path("M6 12C9.31371 12 12 9.31371 12 6C12 2.68629 9.31371 0 6 0C2.68629 0 0 2.68629 0 6C0 9.31371 2.68629 12 6 12ZM8.88815 4.54879C9.08076 4.27914 9.0183 3.90441 8.74865 3.71181C8.479 3.5192 8.10427 3.58165 7.91167 3.8513L5.3881 7.3843L4.07991 5.64005C3.88109 5.37495 3.50501 5.32122 3.23991 5.52005C2.97481 5.71887 2.92109 6.09495 3.11991 6.36005L4.91991 8.76005C5.0347 8.91309 5.21559 9.00223 5.40689 9C5.59818 8.99778 5.77695 8.90446 5.88815 8.74879L8.88815 4.54879Z").fill('even-odd')
441
+
442
+ this.document.translate(-PAGE_MARGIN, -y)
443
+ const payText = "Deze factuur werd al betaald via "+PaymentMethodHelper.getName(this.payment.method)
444
+ const h = this.document.heightOfString(payText, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 })
445
+ this.document.text(payText, PAGE_MARGIN + 8*MM, y + 12/2 - h/2, { align: 'left' })
446
+ } else if (this.payment.method === PaymentMethod.Transfer) {
447
+ y -= 10*MM
448
+
449
+ const payText = "Over te schrijven op BE93 7330 5887 3067\nMet mededeling "+this.payment.transferDescription
450
+ const h = this.document.heightOfString(payText, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 - 30*MM - 40*MM, lineGap: 2*MM })
451
+
452
+ y += 12/2 - h/2
453
+
454
+ this.document.fillColor(COLOR_PRIMARY)
455
+ this.document.translate(PAGE_MARGIN, y).path("M1.71429 0.714233C0.767512 0.714233 0 1.48174 0 2.42852V2.85714H12V2.42852C12 1.48175 11.2325 0.714233 10.2857 0.714233H1.71429ZM12 4.57143H0V7.57138C0 8.51815 0.767512 9.28566 1.71429 9.28566H10.2857C11.2325 9.28566 12 8.51815 12 7.57138V4.57143Z").fill('even-odd')
456
+
457
+ this.document.translate(-PAGE_MARGIN, -y)
458
+
459
+ this.document.text(payText, PAGE_MARGIN + 8*MM, y + 12/2 - h/2, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 - 30*MM - 40*MM, lineGap: 2*MM })
460
+ } else if (this.payment.method === PaymentMethod.DirectDebit) {
461
+ y -= 10*MM
462
+
463
+ const payText = "De betaling gebeurt automatisch via domiciliëring"
464
+ const h = this.document.heightOfString(payText, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 - 30*MM - 40*MM, lineGap: 2*MM })
465
+
466
+ y += 12/2 - h/2
467
+
468
+ this.document.fillColor(COLOR_PRIMARY)
469
+ this.document.translate(PAGE_MARGIN, y).path("M1.71429 0.714233C0.767512 0.714233 0 1.48174 0 2.42852V2.85714H12V2.42852C12 1.48175 11.2325 0.714233 10.2857 0.714233H1.71429ZM12 4.57143H0V7.57138C0 8.51815 0.767512 9.28566 1.71429 9.28566H10.2857C11.2325 9.28566 12 8.51815 12 7.57138V4.57143Z").fill('even-odd')
470
+
471
+ this.document.translate(-PAGE_MARGIN, -y)
472
+
473
+ this.document.text(payText, PAGE_MARGIN + 8*MM, y + 12/2 - h/2 + 0.5*MM, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 - 30*MM - 40*MM, lineGap: 2*MM })
474
+ }
475
+ } else {
476
+ if (this.invoice.organizationId) {
477
+ y -= 10*MM
478
+ this.document.fillColor(COLOR_PRIMARY)
479
+ this.document.translate(PAGE_MARGIN, y).path("M6 12C9.31371 12 12 9.31371 12 6C12 2.68629 9.31371 0 6 0C2.68629 0 0 2.68629 0 6C0 9.31371 2.68629 12 6 12ZM8.88815 4.54879C9.08076 4.27914 9.0183 3.90441 8.74865 3.71181C8.479 3.5192 8.10427 3.58165 7.91167 3.8513L5.3881 7.3843L4.07991 5.64005C3.88109 5.37495 3.50501 5.32122 3.23991 5.52005C2.97481 5.71887 2.92109 6.09495 3.11991 6.36005L4.91991 8.76005C5.0347 8.91309 5.21559 9.00223 5.40689 9C5.59818 8.99778 5.77695 8.90446 5.88815 8.74879L8.88815 4.54879Z").fill('even-odd')
480
+
481
+ this.document.translate(-PAGE_MARGIN, -y)
482
+ const payText = "Het bedrag werd reeds ingehouden van jouw Stripe balans."
483
+ const h = this.document.heightOfString(payText, { align: 'left', width: PAGE_WIDTH - PAGE_MARGIN*2 })
484
+ this.document.text(payText, PAGE_MARGIN + 8*MM, y + 12/2 - h/2, { align: 'left' })
485
+ }
486
+ }
487
+ }
488
+
489
+ drawPageFooter() {
490
+ this.document.fillColor(COLOR_GRAY)
491
+ this.document.font('Metropolis-Medium')
492
+ this.document.fontSize(3 * MM);
493
+ let suffix = ''
494
+ if (this.invoice.meta.VATPercentage == 0) {
495
+ suffix = ' - BTW verlegd'
496
+ }
497
+ this.document.text(this.invoice.id+"", PAGE_MARGIN, PAGE_HEIGHT - PAGE_MARGIN, { align: 'left', baseline: "bottom", lineBreak: false, width: (PAGE_WIDTH - PAGE_MARGIN*2)/2, height: 10*MM })
498
+ this.document.text("Pagina "+this.page, PAGE_WIDTH - PAGE_MARGIN - 31*MM, PAGE_HEIGHT - PAGE_MARGIN, { align: 'right', baseline: "bottom", width: 30*MM, lineBreak: false, height: 10*MM })
499
+ }
500
+
501
+ }
@@ -0,0 +1,75 @@
1
+ import { SimpleError } from "@simonbackx/simple-errors"
2
+
3
+ export class RateLimitWindow {
4
+ start: Date = new Date()
5
+ windows: Map<string, number> = new Map()
6
+
7
+ limit: number
8
+
9
+ /**
10
+ * in ms
11
+ */
12
+ duration: number
13
+
14
+ constructor(options: {
15
+ limit: number,
16
+ duration: number
17
+ }) {
18
+ this.limit = options.limit
19
+ this.duration = options.duration
20
+ }
21
+
22
+ isExpired() {
23
+ return this.age > this.duration
24
+ }
25
+
26
+ get age() {
27
+ return Date.now() - this.start.getTime()
28
+ }
29
+
30
+ track(key: string, amount = 1) {
31
+ if (this.isExpired()) {
32
+ // We have a shared window
33
+ this.start = new Date()
34
+ this.windows.clear()
35
+ }
36
+
37
+ let w = this.windows.get(key) ?? 0
38
+ w += amount
39
+
40
+ if (w > this.limit) {
41
+ const retryAfter = Math.ceil((this.duration - this.age) / 1000)
42
+ throw new SimpleError({
43
+ code: 'rate_limit',
44
+ message: `Rate limit exceeded (${w} ${amount > 1 ? '('+amount+' added)' : ''} requests in ${Math.round(this.age/1000)}s). Retry after ${retryAfter}s. Check your code and try to reduce the number of (parallel) requests you make. Add waiting periods if needed.`,
45
+ statusCode: 429
46
+ })
47
+ }
48
+
49
+ // Save
50
+ this.windows.set(key, w)
51
+ }
52
+ }
53
+
54
+
55
+ export class RateLimiter {
56
+ windows: RateLimitWindow[] = []
57
+
58
+ constructor(options: {
59
+ limits: {duration: number, limit: number}[]
60
+ }) {
61
+
62
+ for (const limit of options.limits) {
63
+ this.windows.push(new RateLimitWindow({
64
+ limit: limit.limit,
65
+ duration: limit.duration
66
+ }))
67
+ }
68
+ }
69
+
70
+ track(key: string, amount = 1) {
71
+ for (const window of this.windows) {
72
+ window.track(key, amount)
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,16 @@
1
+ import { WebshopNumberingType } from "@stamhoofd/structures";
2
+ import { WebshopCounter } from "./WebshopCounter";
3
+
4
+ describe("WebshopCounter", () => {
5
+ test("Create multiple order numbers", async () => {
6
+ const first = WebshopCounter.getNextNumber("ADGS", WebshopNumberingType.Continuous)
7
+ const second = WebshopCounter.getNextNumber("ADGS", WebshopNumberingType.Continuous)
8
+ const other = WebshopCounter.getNextNumber("ZEGQ", WebshopNumberingType.Continuous)
9
+ const last = WebshopCounter.getNextNumber("ADGS", WebshopNumberingType.Continuous)
10
+
11
+ await expect(first).resolves.toEqual(1)
12
+ await expect(second).resolves.toEqual(2)
13
+ await expect(last).resolves.toEqual(3)
14
+ await expect(other).resolves.toEqual(1)
15
+ });
16
+ });
@@ -0,0 +1,36 @@
1
+ import { Database } from "@simonbackx/simple-database";
2
+ import { QueueHandler } from "@stamhoofd/queues";
3
+ import { WebshopNumberingType } from "@stamhoofd/structures";
4
+
5
+ export class WebshopCounter {
6
+ static numberCache: Map<string, number> = new Map()
7
+
8
+ static async getNextNumber(webshopId: string, numberingType: WebshopNumberingType): Promise<number> {
9
+ if (numberingType == WebshopNumberingType.Random) {
10
+ return Math.floor(Math.random() * 1000000000)
11
+ }
12
+
13
+ // Prevent race conditions: create a queue
14
+ // The queue can only run one at a time for the same webshop (so multiple webshops at the same time are allowed)
15
+ return await QueueHandler.schedule("webshop/numbers-"+webshopId, async () => {
16
+ if (this.numberCache.has(webshopId)) {
17
+ const nextNumber = this.numberCache.get(webshopId)!
18
+ this.numberCache.set(webshopId, nextNumber + 1)
19
+ return nextNumber
20
+ }
21
+
22
+ const [rows] = await Database.select(`select max(number) as previousNumber from webshop_orders where webshopId = ?`, [webshopId]);
23
+ let nextNumber: number | undefined
24
+
25
+ if (rows.length == 0) {
26
+ nextNumber = 1
27
+ } else {
28
+ const previousNumber: number | null = rows[0]['']['previousNumber'] as number|null;
29
+ nextNumber = (previousNumber ?? 0) + 1
30
+ }
31
+
32
+ this.numberCache.set(webshopId, nextNumber + 1 )
33
+ return nextNumber
34
+ })
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ export * from "./factories/AddressFactory"
2
+ export * from "./factories/EmergencyContactFactory"
3
+ export * from "./factories/GroupFactory"
4
+ export * from "./factories/MemberFactory"
5
+ export * from "./factories/OrganizationFactory"
6
+ export * from "./factories/ParentFactory"
7
+ export * from "./factories/RecordFactory"
8
+ export * from "./factories/RegisterCodeFactory"
9
+ export * from "./factories/RegistrationFactory"
10
+ export * from "./factories/UserFactory"
11
+ export * from "./factories/WebshopFactory"
12
+
13
+ // Helpers
14
+ export * from "./helpers/EmailBuilder"
15
+ export * from "./helpers/GroupBuilder"
16
+ export * from "./helpers/RateLimiter"
17
+ export * from "./helpers/WebshopCounter"
18
+
19
+ // Models
20
+ export * from "./models"
21
+ export * from "./structures/OrganizationServerMetaData"