nanosaas 0.0.0-stage → 0.1.0-beta.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 (699) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +201 -0
  3. package/README.md +117 -2
  4. package/dist/common/base/actor.d.ts +40 -0
  5. package/dist/common/base/actor.js +66 -0
  6. package/dist/common/base/actor.mjs +42 -0
  7. package/dist/common/base/base.app.d.ts +11 -0
  8. package/dist/common/base/base.app.js +58 -0
  9. package/dist/common/base/base.app.mjs +34 -0
  10. package/dist/common/base/base.entity.d.ts +42 -0
  11. package/dist/common/base/base.entity.js +109 -0
  12. package/dist/common/base/base.entity.mjs +85 -0
  13. package/dist/common/base/base.use-case.d.ts +15 -0
  14. package/dist/common/base/base.use-case.js +30 -0
  15. package/dist/common/base/base.use-case.mjs +6 -0
  16. package/dist/common/base/current-session.d.ts +128 -0
  17. package/dist/common/base/current-session.js +127 -0
  18. package/dist/common/base/current-session.mjs +100 -0
  19. package/dist/common/base/current-user.d.ts +19 -0
  20. package/dist/common/base/current-user.js +91 -0
  21. package/dist/common/base/current-user.mjs +67 -0
  22. package/dist/common/base/extension-registry.d.ts +25 -0
  23. package/dist/common/base/extension-registry.js +97 -0
  24. package/dist/common/base/extension-registry.mjs +68 -0
  25. package/dist/common/base/index.d.ts +14 -0
  26. package/dist/common/base/index.js +48 -0
  27. package/dist/common/base/index.mjs +14 -0
  28. package/dist/common/base/locale.d.ts +18 -0
  29. package/dist/common/base/locale.js +41 -0
  30. package/dist/common/base/locale.mjs +17 -0
  31. package/dist/common/base/params.d.ts +2 -0
  32. package/dist/common/base/params.js +33 -0
  33. package/dist/common/base/params.mjs +9 -0
  34. package/dist/common/base/permission.d.ts +21 -0
  35. package/dist/common/base/permission.js +61 -0
  36. package/dist/common/base/permission.mjs +34 -0
  37. package/dist/common/base/request-context.d.ts +52 -0
  38. package/dist/common/base/request-context.js +89 -0
  39. package/dist/common/base/request-context.mjs +65 -0
  40. package/dist/common/base/role-catalog.d.ts +31 -0
  41. package/dist/common/base/role-catalog.js +103 -0
  42. package/dist/common/base/role-catalog.mjs +74 -0
  43. package/dist/common/base/share.d.ts +16 -0
  44. package/dist/common/base/share.js +53 -0
  45. package/dist/common/base/share.mjs +27 -0
  46. package/dist/common/base/utils/flatten-object.d.ts +1 -0
  47. package/dist/common/base/utils/flatten-object.js +45 -0
  48. package/dist/common/base/utils/flatten-object.mjs +21 -0
  49. package/dist/common/base/utils/index.d.ts +3 -0
  50. package/dist/common/base/utils/index.js +26 -0
  51. package/dist/common/base/utils/index.mjs +3 -0
  52. package/dist/common/base/utils/is-plain-object.d.ts +1 -0
  53. package/dist/common/base/utils/is-plain-object.js +32 -0
  54. package/dist/common/base/utils/is-plain-object.mjs +8 -0
  55. package/dist/common/base/utils/to-patch.d.ts +9 -0
  56. package/dist/common/base/utils/to-patch.js +46 -0
  57. package/dist/common/base/utils/to-patch.mjs +21 -0
  58. package/dist/common/config/index.d.ts +43 -0
  59. package/dist/common/config/index.js +105 -0
  60. package/dist/common/config/index.mjs +61 -0
  61. package/dist/common/crypto/cipher.d.ts +15 -0
  62. package/dist/common/crypto/cipher.js +95 -0
  63. package/dist/common/crypto/cipher.mjs +67 -0
  64. package/dist/common/crypto/contexts.d.ts +9 -0
  65. package/dist/common/crypto/contexts.js +38 -0
  66. package/dist/common/crypto/contexts.mjs +11 -0
  67. package/dist/common/crypto/errors.d.ts +12 -0
  68. package/dist/common/crypto/errors.js +47 -0
  69. package/dist/common/crypto/errors.mjs +22 -0
  70. package/dist/common/crypto/index.d.ts +5 -0
  71. package/dist/common/crypto/index.js +30 -0
  72. package/dist/common/crypto/index.mjs +5 -0
  73. package/dist/common/crypto/key-ring.d.ts +21 -0
  74. package/dist/common/crypto/key-ring.js +94 -0
  75. package/dist/common/crypto/key-ring.mjs +63 -0
  76. package/dist/common/crypto/reencrypt.d.ts +23 -0
  77. package/dist/common/crypto/reencrypt.js +76 -0
  78. package/dist/common/crypto/reencrypt.mjs +52 -0
  79. package/dist/common/db/collection.d.ts +16 -0
  80. package/dist/common/db/collection.js +48 -0
  81. package/dist/common/db/collection.mjs +23 -0
  82. package/dist/common/db/encrypted-fields.d.ts +16 -0
  83. package/dist/common/db/encrypted-fields.js +116 -0
  84. package/dist/common/db/encrypted-fields.mjs +92 -0
  85. package/dist/common/db/index.d.ts +6 -0
  86. package/dist/common/db/index.js +32 -0
  87. package/dist/common/db/index.mjs +6 -0
  88. package/dist/common/db/indexes.d.ts +6 -0
  89. package/dist/common/db/indexes.js +37 -0
  90. package/dist/common/db/indexes.mjs +13 -0
  91. package/dist/common/db/mongo-db.client.d.ts +11 -0
  92. package/dist/common/db/mongo-db.client.js +85 -0
  93. package/dist/common/db/mongo-db.client.mjs +62 -0
  94. package/dist/common/db/mongo-db.repository.d.ts +143 -0
  95. package/dist/common/db/mongo-db.repository.js +443 -0
  96. package/dist/common/db/mongo-db.repository.mjs +418 -0
  97. package/dist/common/db/org-role.d.ts +7 -0
  98. package/dist/common/db/org-role.js +39 -0
  99. package/dist/common/db/org-role.mjs +13 -0
  100. package/dist/common/db/scope.d.ts +36 -0
  101. package/dist/common/db/scope.js +94 -0
  102. package/dist/common/db/scope.mjs +69 -0
  103. package/dist/common/error/error-message.d.ts +47 -0
  104. package/dist/common/error/error-message.js +75 -0
  105. package/dist/common/error/error-message.mjs +51 -0
  106. package/dist/common/error/error-reporter.d.ts +11 -0
  107. package/dist/common/error/error-reporter.js +36 -0
  108. package/dist/common/error/error-reporter.mjs +11 -0
  109. package/dist/common/error/http-error.d.ts +11 -0
  110. package/dist/common/error/http-error.js +37 -0
  111. package/dist/common/error/http-error.mjs +13 -0
  112. package/dist/common/error/http-status.d.ts +17 -0
  113. package/dist/common/error/http-status.js +45 -0
  114. package/dist/common/error/http-status.mjs +21 -0
  115. package/dist/common/error/index.d.ts +5 -0
  116. package/dist/common/error/index.js +30 -0
  117. package/dist/common/error/index.mjs +5 -0
  118. package/dist/common/error/reportError.d.ts +2 -0
  119. package/dist/common/error/reportError.js +42 -0
  120. package/dist/common/error/reportError.mjs +18 -0
  121. package/dist/common/events/event-bus.d.ts +19 -0
  122. package/dist/common/events/event-bus.js +52 -0
  123. package/dist/common/events/event-bus.mjs +27 -0
  124. package/dist/common/events/index.d.ts +1 -0
  125. package/dist/common/events/index.js +22 -0
  126. package/dist/common/events/index.mjs +1 -0
  127. package/dist/common/helpers/escape-regex.d.ts +1 -0
  128. package/dist/common/helpers/escape-regex.js +30 -0
  129. package/dist/common/helpers/escape-regex.mjs +6 -0
  130. package/dist/common/helpers/extract-json-from-text.d.ts +1 -0
  131. package/dist/common/helpers/extract-json-from-text.js +63 -0
  132. package/dist/common/helpers/extract-json-from-text.mjs +39 -0
  133. package/dist/common/helpers/http.d.ts +22 -0
  134. package/dist/common/helpers/http.js +62 -0
  135. package/dist/common/helpers/http.mjs +36 -0
  136. package/dist/common/helpers/index.d.ts +5 -0
  137. package/dist/common/helpers/index.js +30 -0
  138. package/dist/common/helpers/index.mjs +5 -0
  139. package/dist/common/helpers/sanitize-string.d.ts +1 -0
  140. package/dist/common/helpers/sanitize-string.js +35 -0
  141. package/dist/common/helpers/sanitize-string.mjs +11 -0
  142. package/dist/common/helpers/strip-blocks.d.ts +1 -0
  143. package/dist/common/helpers/strip-blocks.js +45 -0
  144. package/dist/common/helpers/strip-blocks.mjs +21 -0
  145. package/dist/common/http/base.controller.d.ts +19 -0
  146. package/dist/common/http/base.controller.js +109 -0
  147. package/dist/common/http/base.controller.mjs +85 -0
  148. package/dist/common/http/client-context.d.ts +7 -0
  149. package/dist/common/http/client-context.js +41 -0
  150. package/dist/common/http/client-context.mjs +16 -0
  151. package/dist/common/http/http-status.d.ts +18 -0
  152. package/dist/common/http/http-status.js +56 -0
  153. package/dist/common/http/http-status.mjs +28 -0
  154. package/dist/common/http/index.d.ts +6 -0
  155. package/dist/common/http/index.js +32 -0
  156. package/dist/common/http/index.mjs +6 -0
  157. package/dist/common/http/lambda.d.ts +34 -0
  158. package/dist/common/http/lambda.js +82 -0
  159. package/dist/common/http/lambda.mjs +56 -0
  160. package/dist/common/http/response.d.ts +4 -0
  161. package/dist/common/http/response.js +39 -0
  162. package/dist/common/http/response.mjs +13 -0
  163. package/dist/common/http/types.d.ts +47 -0
  164. package/dist/common/http/types.js +16 -0
  165. package/dist/common/http/types.mjs +0 -0
  166. package/dist/common/index.d.ts +12 -0
  167. package/dist/common/index.js +53 -0
  168. package/dist/common/index.mjs +17 -0
  169. package/dist/common/logger/index.d.ts +1 -0
  170. package/dist/common/logger/index.js +22 -0
  171. package/dist/common/logger/index.mjs +1 -0
  172. package/dist/common/logger/pino.d.ts +11 -0
  173. package/dist/common/logger/pino.js +78 -0
  174. package/dist/common/logger/pino.mjs +43 -0
  175. package/dist/common/providers/email.provider.d.ts +13 -0
  176. package/dist/common/providers/email.provider.js +32 -0
  177. package/dist/common/providers/email.provider.mjs +8 -0
  178. package/dist/common/providers/index.d.ts +4 -0
  179. package/dist/common/providers/index.js +40 -0
  180. package/dist/common/providers/index.mjs +13 -0
  181. package/dist/common/rate-limit/index.d.ts +3 -0
  182. package/dist/common/rate-limit/index.js +26 -0
  183. package/dist/common/rate-limit/index.mjs +3 -0
  184. package/dist/common/rate-limit/mongo-rate-limit-store.d.ts +10 -0
  185. package/dist/common/rate-limit/mongo-rate-limit-store.js +50 -0
  186. package/dist/common/rate-limit/mongo-rate-limit-store.mjs +25 -0
  187. package/dist/common/rate-limit/rate-limit-store.d.ts +10 -0
  188. package/dist/common/rate-limit/rate-limit-store.js +16 -0
  189. package/dist/common/rate-limit/rate-limit-store.mjs +0 -0
  190. package/dist/common/rate-limit/rate-limiter.d.ts +24 -0
  191. package/dist/common/rate-limit/rate-limiter.js +101 -0
  192. package/dist/common/rate-limit/rate-limiter.mjs +74 -0
  193. package/dist/common/utils/config-context.d.ts +8 -0
  194. package/dist/common/utils/config-context.js +39 -0
  195. package/dist/common/utils/config-context.mjs +12 -0
  196. package/dist/common/utils/number-setting.d.ts +1 -0
  197. package/dist/common/utils/number-setting.js +32 -0
  198. package/dist/common/utils/number-setting.mjs +8 -0
  199. package/dist/common/utils/secret-manager.d.ts +10 -0
  200. package/dist/common/utils/secret-manager.js +62 -0
  201. package/dist/common/utils/secret-manager.mjs +37 -0
  202. package/dist/index.d.ts +2 -0
  203. package/dist/index.js +24 -0
  204. package/dist/index.mjs +2 -0
  205. package/dist/modules/activities/entities/activity.entity.d.ts +27 -0
  206. package/dist/modules/activities/entities/activity.entity.js +69 -0
  207. package/dist/modules/activities/entities/activity.entity.mjs +45 -0
  208. package/dist/modules/activities/entities/index.d.ts +1 -0
  209. package/dist/modules/activities/entities/index.js +22 -0
  210. package/dist/modules/activities/entities/index.mjs +1 -0
  211. package/dist/modules/activities/helpers/activity-catalog.d.ts +26 -0
  212. package/dist/modules/activities/helpers/activity-catalog.js +66 -0
  213. package/dist/modules/activities/helpers/activity-catalog.mjs +39 -0
  214. package/dist/modules/activities/helpers/activity-extensions.d.ts +4 -0
  215. package/dist/modules/activities/helpers/activity-extensions.js +32 -0
  216. package/dist/modules/activities/helpers/activity-extensions.mjs +7 -0
  217. package/dist/modules/activities/helpers/activity-subscribers.d.ts +7 -0
  218. package/dist/modules/activities/helpers/activity-subscribers.js +69 -0
  219. package/dist/modules/activities/helpers/activity-subscribers.mjs +44 -0
  220. package/dist/modules/activities/index.d.ts +6 -0
  221. package/dist/modules/activities/index.js +39 -0
  222. package/dist/modules/activities/index.mjs +9 -0
  223. package/dist/modules/activities/module.d.ts +5 -0
  224. package/dist/modules/activities/module.js +46 -0
  225. package/dist/modules/activities/module.mjs +20 -0
  226. package/dist/modules/activities/repositories/activity.repository.d.ts +56 -0
  227. package/dist/modules/activities/repositories/activity.repository.js +55 -0
  228. package/dist/modules/activities/repositories/activity.repository.mjs +30 -0
  229. package/dist/modules/activities/repositories/index.d.ts +1 -0
  230. package/dist/modules/activities/repositories/index.js +22 -0
  231. package/dist/modules/activities/repositories/index.mjs +1 -0
  232. package/dist/modules/activities/use-cases/list-activities.use-case.d.ts +17 -0
  233. package/dist/modules/activities/use-cases/list-activities.use-case.js +42 -0
  234. package/dist/modules/activities/use-cases/list-activities.use-case.mjs +18 -0
  235. package/dist/modules/activities/use-cases/track-activity.use-case.d.ts +21 -0
  236. package/dist/modules/activities/use-cases/track-activity.use-case.js +73 -0
  237. package/dist/modules/activities/use-cases/track-activity.use-case.mjs +48 -0
  238. package/dist/modules/authentication/entities/index.d.ts +2 -0
  239. package/dist/modules/authentication/entities/index.js +24 -0
  240. package/dist/modules/authentication/entities/index.mjs +2 -0
  241. package/dist/modules/authentication/entities/refresh-token.entity.d.ts +25 -0
  242. package/dist/modules/authentication/entities/refresh-token.entity.js +75 -0
  243. package/dist/modules/authentication/entities/refresh-token.entity.mjs +51 -0
  244. package/dist/modules/authentication/entities/revoked-token.entity.d.ts +17 -0
  245. package/dist/modules/authentication/entities/revoked-token.entity.js +68 -0
  246. package/dist/modules/authentication/entities/revoked-token.entity.mjs +44 -0
  247. package/dist/modules/authentication/helpers/auth-config.d.ts +10 -0
  248. package/dist/modules/authentication/helpers/auth-config.js +37 -0
  249. package/dist/modules/authentication/helpers/auth-config.mjs +13 -0
  250. package/dist/modules/authentication/helpers/auth-events.d.ts +14 -0
  251. package/dist/modules/authentication/helpers/auth-events.js +35 -0
  252. package/dist/modules/authentication/helpers/auth-events.mjs +11 -0
  253. package/dist/modules/authentication/helpers/delegated-token.d.ts +35 -0
  254. package/dist/modules/authentication/helpers/delegated-token.js +92 -0
  255. package/dist/modules/authentication/helpers/delegated-token.mjs +65 -0
  256. package/dist/modules/authentication/helpers/session-tokens.d.ts +16 -0
  257. package/dist/modules/authentication/helpers/session-tokens.js +60 -0
  258. package/dist/modules/authentication/helpers/session-tokens.mjs +35 -0
  259. package/dist/modules/authentication/helpers/tokens.d.ts +38 -0
  260. package/dist/modules/authentication/helpers/tokens.js +114 -0
  261. package/dist/modules/authentication/helpers/tokens.mjs +74 -0
  262. package/dist/modules/authentication/index.d.ts +9 -0
  263. package/dist/modules/authentication/index.js +53 -0
  264. package/dist/modules/authentication/index.mjs +17 -0
  265. package/dist/modules/authentication/module.d.ts +20 -0
  266. package/dist/modules/authentication/module.js +96 -0
  267. package/dist/modules/authentication/module.mjs +63 -0
  268. package/dist/modules/authentication/repositories/index.d.ts +2 -0
  269. package/dist/modules/authentication/repositories/index.js +24 -0
  270. package/dist/modules/authentication/repositories/index.mjs +2 -0
  271. package/dist/modules/authentication/repositories/refresh-token.repository.d.ts +11 -0
  272. package/dist/modules/authentication/repositories/refresh-token.repository.js +81 -0
  273. package/dist/modules/authentication/repositories/refresh-token.repository.mjs +56 -0
  274. package/dist/modules/authentication/repositories/revoked-token.repository.d.ts +7 -0
  275. package/dist/modules/authentication/repositories/revoked-token.repository.js +45 -0
  276. package/dist/modules/authentication/repositories/revoked-token.repository.mjs +21 -0
  277. package/dist/modules/authentication/use-cases/claim-refresh-token.use-case.d.ts +12 -0
  278. package/dist/modules/authentication/use-cases/claim-refresh-token.use-case.js +40 -0
  279. package/dist/modules/authentication/use-cases/claim-refresh-token.use-case.mjs +16 -0
  280. package/dist/modules/authentication/use-cases/create-refresh-token.use-case.d.ts +11 -0
  281. package/dist/modules/authentication/use-cases/create-refresh-token.use-case.js +43 -0
  282. package/dist/modules/authentication/use-cases/create-refresh-token.use-case.mjs +19 -0
  283. package/dist/modules/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +11 -0
  284. package/dist/modules/authentication/use-cases/find-refresh-token-by-hash.use-case.js +40 -0
  285. package/dist/modules/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +16 -0
  286. package/dist/modules/authentication/use-cases/is-token-revoked.use-case.d.ts +13 -0
  287. package/dist/modules/authentication/use-cases/is-token-revoked.use-case.js +42 -0
  288. package/dist/modules/authentication/use-cases/is-token-revoked.use-case.mjs +18 -0
  289. package/dist/modules/authentication/use-cases/issue-password-reset-token.use-case.d.ts +18 -0
  290. package/dist/modules/authentication/use-cases/issue-password-reset-token.use-case.js +50 -0
  291. package/dist/modules/authentication/use-cases/issue-password-reset-token.use-case.mjs +26 -0
  292. package/dist/modules/authentication/use-cases/issue-session.use-case.d.ts +13 -0
  293. package/dist/modules/authentication/use-cases/issue-session.use-case.js +49 -0
  294. package/dist/modules/authentication/use-cases/issue-session.use-case.mjs +25 -0
  295. package/dist/modules/authentication/use-cases/login.use-case.d.ts +25 -0
  296. package/dist/modules/authentication/use-cases/login.use-case.js +80 -0
  297. package/dist/modules/authentication/use-cases/login.use-case.mjs +56 -0
  298. package/dist/modules/authentication/use-cases/logout.use-case.d.ts +14 -0
  299. package/dist/modules/authentication/use-cases/logout.use-case.js +48 -0
  300. package/dist/modules/authentication/use-cases/logout.use-case.mjs +24 -0
  301. package/dist/modules/authentication/use-cases/recover-password.use-case.d.ts +18 -0
  302. package/dist/modules/authentication/use-cases/recover-password.use-case.js +70 -0
  303. package/dist/modules/authentication/use-cases/recover-password.use-case.mjs +46 -0
  304. package/dist/modules/authentication/use-cases/refresh.use-case.d.ts +23 -0
  305. package/dist/modules/authentication/use-cases/refresh.use-case.js +85 -0
  306. package/dist/modules/authentication/use-cases/refresh.use-case.mjs +61 -0
  307. package/dist/modules/authentication/use-cases/register.use-case.d.ts +26 -0
  308. package/dist/modules/authentication/use-cases/register.use-case.js +79 -0
  309. package/dist/modules/authentication/use-cases/register.use-case.mjs +55 -0
  310. package/dist/modules/authentication/use-cases/reset-password.use-case.d.ts +15 -0
  311. package/dist/modules/authentication/use-cases/reset-password.use-case.js +64 -0
  312. package/dist/modules/authentication/use-cases/reset-password.use-case.mjs +40 -0
  313. package/dist/modules/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +11 -0
  314. package/dist/modules/authentication/use-cases/revoke-refresh-token-family.use-case.js +40 -0
  315. package/dist/modules/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +16 -0
  316. package/dist/modules/authentication/use-cases/revoke-token.use-case.d.ts +12 -0
  317. package/dist/modules/authentication/use-cases/revoke-token.use-case.js +53 -0
  318. package/dist/modules/authentication/use-cases/revoke-token.use-case.mjs +29 -0
  319. package/dist/modules/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +13 -0
  320. package/dist/modules/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +40 -0
  321. package/dist/modules/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +16 -0
  322. package/dist/modules/billing/entities/billing.entity.d.ts +182 -0
  323. package/dist/modules/billing/entities/billing.entity.js +332 -0
  324. package/dist/modules/billing/entities/billing.entity.mjs +294 -0
  325. package/dist/modules/billing/entities/index.d.ts +1 -0
  326. package/dist/modules/billing/entities/index.js +22 -0
  327. package/dist/modules/billing/entities/index.mjs +1 -0
  328. package/dist/modules/billing/helpers/billing-extensions.d.ts +6 -0
  329. package/dist/modules/billing/helpers/billing-extensions.js +38 -0
  330. package/dist/modules/billing/helpers/billing-extensions.mjs +11 -0
  331. package/dist/modules/billing/index.d.ts +5 -0
  332. package/dist/modules/billing/index.js +30 -0
  333. package/dist/modules/billing/index.mjs +5 -0
  334. package/dist/modules/billing/module.d.ts +18 -0
  335. package/dist/modules/billing/module.js +89 -0
  336. package/dist/modules/billing/module.mjs +57 -0
  337. package/dist/modules/billing/providers/billing-provider.d.ts +29 -0
  338. package/dist/modules/billing/providers/billing-provider.js +37 -0
  339. package/dist/modules/billing/providers/billing-provider.mjs +12 -0
  340. package/dist/modules/billing/providers/index.d.ts +3 -0
  341. package/dist/modules/billing/providers/index.js +26 -0
  342. package/dist/modules/billing/providers/index.mjs +3 -0
  343. package/dist/modules/billing/providers/polar.provider.d.ts +23 -0
  344. package/dist/modules/billing/providers/polar.provider.js +94 -0
  345. package/dist/modules/billing/providers/polar.provider.mjs +70 -0
  346. package/dist/modules/billing/providers/standard-webhooks.d.ts +6 -0
  347. package/dist/modules/billing/providers/standard-webhooks.js +58 -0
  348. package/dist/modules/billing/providers/standard-webhooks.mjs +33 -0
  349. package/dist/modules/billing/repositories/billing.repository.d.ts +114 -0
  350. package/dist/modules/billing/repositories/billing.repository.js +97 -0
  351. package/dist/modules/billing/repositories/billing.repository.mjs +70 -0
  352. package/dist/modules/billing/repositories/index.d.ts +1 -0
  353. package/dist/modules/billing/repositories/index.js +22 -0
  354. package/dist/modules/billing/repositories/index.mjs +1 -0
  355. package/dist/modules/billing/use-cases/create-billing-portal.use-case.d.ts +8 -0
  356. package/dist/modules/billing/use-cases/create-billing-portal.use-case.js +40 -0
  357. package/dist/modules/billing/use-cases/create-billing-portal.use-case.mjs +16 -0
  358. package/dist/modules/billing/use-cases/get-billing-account.use-case.d.ts +13 -0
  359. package/dist/modules/billing/use-cases/get-billing-account.use-case.js +58 -0
  360. package/dist/modules/billing/use-cases/get-billing-account.use-case.mjs +34 -0
  361. package/dist/modules/billing/use-cases/get-entitlement.use-case.d.ts +21 -0
  362. package/dist/modules/billing/use-cases/get-entitlement.use-case.js +50 -0
  363. package/dist/modules/billing/use-cases/get-entitlement.use-case.mjs +26 -0
  364. package/dist/modules/billing/use-cases/handle-billing-webhook.use-case.d.ts +21 -0
  365. package/dist/modules/billing/use-cases/handle-billing-webhook.use-case.js +63 -0
  366. package/dist/modules/billing/use-cases/handle-billing-webhook.use-case.mjs +39 -0
  367. package/dist/modules/billing/use-cases/list-billing-accounts.use-case.d.ts +10 -0
  368. package/dist/modules/billing/use-cases/list-billing-accounts.use-case.js +41 -0
  369. package/dist/modules/billing/use-cases/list-billing-accounts.use-case.mjs +17 -0
  370. package/dist/modules/billing/use-cases/list-billing-transactions.use-case.d.ts +16 -0
  371. package/dist/modules/billing/use-cases/list-billing-transactions.use-case.js +42 -0
  372. package/dist/modules/billing/use-cases/list-billing-transactions.use-case.mjs +18 -0
  373. package/dist/modules/billing/use-cases/record-billing-transaction.use-case.d.ts +14 -0
  374. package/dist/modules/billing/use-cases/record-billing-transaction.use-case.js +67 -0
  375. package/dist/modules/billing/use-cases/record-billing-transaction.use-case.mjs +43 -0
  376. package/dist/modules/billing/use-cases/save-subscription.use-case.d.ts +17 -0
  377. package/dist/modules/billing/use-cases/save-subscription.use-case.js +68 -0
  378. package/dist/modules/billing/use-cases/save-subscription.use-case.mjs +44 -0
  379. package/dist/modules/billing/use-cases/start-checkout.use-case.d.ts +22 -0
  380. package/dist/modules/billing/use-cases/start-checkout.use-case.js +50 -0
  381. package/dist/modules/billing/use-cases/start-checkout.use-case.mjs +26 -0
  382. package/dist/modules/integrations/entities/index.d.ts +1 -0
  383. package/dist/modules/integrations/entities/index.js +22 -0
  384. package/dist/modules/integrations/entities/index.mjs +1 -0
  385. package/dist/modules/integrations/entities/integration-enums.d.ts +11 -0
  386. package/dist/modules/integrations/entities/integration-enums.js +42 -0
  387. package/dist/modules/integrations/entities/integration-enums.mjs +17 -0
  388. package/dist/modules/integrations/entities/integration.entity.d.ts +51 -0
  389. package/dist/modules/integrations/entities/integration.entity.js +107 -0
  390. package/dist/modules/integrations/entities/integration.entity.mjs +78 -0
  391. package/dist/modules/integrations/events/integration.events.d.ts +12 -0
  392. package/dist/modules/integrations/events/integration.events.js +33 -0
  393. package/dist/modules/integrations/events/integration.events.mjs +9 -0
  394. package/dist/modules/integrations/helpers/integration-extensions.d.ts +4 -0
  395. package/dist/modules/integrations/helpers/integration-extensions.js +32 -0
  396. package/dist/modules/integrations/helpers/integration-extensions.mjs +7 -0
  397. package/dist/modules/integrations/helpers/service-catalog.d.ts +16 -0
  398. package/dist/modules/integrations/helpers/service-catalog.js +61 -0
  399. package/dist/modules/integrations/helpers/service-catalog.mjs +36 -0
  400. package/dist/modules/integrations/index.d.ts +8 -0
  401. package/dist/modules/integrations/index.js +43 -0
  402. package/dist/modules/integrations/index.mjs +11 -0
  403. package/dist/modules/integrations/module.d.ts +14 -0
  404. package/dist/modules/integrations/module.js +75 -0
  405. package/dist/modules/integrations/module.mjs +45 -0
  406. package/dist/modules/integrations/purposes/index.d.ts +1 -0
  407. package/dist/modules/integrations/purposes/index.js +22 -0
  408. package/dist/modules/integrations/purposes/index.mjs +1 -0
  409. package/dist/modules/integrations/purposes/integration.purpose.d.ts +32 -0
  410. package/dist/modules/integrations/purposes/integration.purpose.js +106 -0
  411. package/dist/modules/integrations/purposes/integration.purpose.mjs +80 -0
  412. package/dist/modules/integrations/repositories/index.d.ts +1 -0
  413. package/dist/modules/integrations/repositories/index.js +22 -0
  414. package/dist/modules/integrations/repositories/index.mjs +1 -0
  415. package/dist/modules/integrations/repositories/integration.repository.d.ts +75 -0
  416. package/dist/modules/integrations/repositories/integration.repository.js +105 -0
  417. package/dist/modules/integrations/repositories/integration.repository.mjs +80 -0
  418. package/dist/modules/integrations/use-cases/check-integration-credentials.use-case.d.ts +11 -0
  419. package/dist/modules/integrations/use-cases/check-integration-credentials.use-case.js +46 -0
  420. package/dist/modules/integrations/use-cases/check-integration-credentials.use-case.mjs +22 -0
  421. package/dist/modules/integrations/use-cases/create-integration.use-case.d.ts +18 -0
  422. package/dist/modules/integrations/use-cases/create-integration.use-case.js +54 -0
  423. package/dist/modules/integrations/use-cases/create-integration.use-case.mjs +30 -0
  424. package/dist/modules/integrations/use-cases/delete-integration.use-case.d.ts +12 -0
  425. package/dist/modules/integrations/use-cases/delete-integration.use-case.js +53 -0
  426. package/dist/modules/integrations/use-cases/delete-integration.use-case.mjs +29 -0
  427. package/dist/modules/integrations/use-cases/get-access-token.use-case.d.ts +22 -0
  428. package/dist/modules/integrations/use-cases/get-access-token.use-case.js +75 -0
  429. package/dist/modules/integrations/use-cases/get-access-token.use-case.mjs +50 -0
  430. package/dist/modules/integrations/use-cases/get-integration.use-case.d.ts +12 -0
  431. package/dist/modules/integrations/use-cases/get-integration.use-case.js +44 -0
  432. package/dist/modules/integrations/use-cases/get-integration.use-case.mjs +20 -0
  433. package/dist/modules/integrations/use-cases/list-integrations.use-case.d.ts +18 -0
  434. package/dist/modules/integrations/use-cases/list-integrations.use-case.js +50 -0
  435. package/dist/modules/integrations/use-cases/list-integrations.use-case.mjs +26 -0
  436. package/dist/modules/integrations/use-cases/update-integration.use-case.d.ts +19 -0
  437. package/dist/modules/integrations/use-cases/update-integration.use-case.js +56 -0
  438. package/dist/modules/integrations/use-cases/update-integration.use-case.mjs +32 -0
  439. package/dist/modules/oauth/entities/index.d.ts +1 -0
  440. package/dist/modules/oauth/entities/index.js +22 -0
  441. package/dist/modules/oauth/entities/index.mjs +1 -0
  442. package/dist/modules/oauth/entities/oauth.entity.d.ts +75 -0
  443. package/dist/modules/oauth/entities/oauth.entity.js +65 -0
  444. package/dist/modules/oauth/entities/oauth.entity.mjs +37 -0
  445. package/dist/modules/oauth/helpers/authorization-state.d.ts +19 -0
  446. package/dist/modules/oauth/helpers/authorization-state.js +69 -0
  447. package/dist/modules/oauth/helpers/authorization-state.mjs +42 -0
  448. package/dist/modules/oauth/helpers/index.d.ts +3 -0
  449. package/dist/modules/oauth/helpers/index.js +26 -0
  450. package/dist/modules/oauth/helpers/index.mjs +3 -0
  451. package/dist/modules/oauth/helpers/pkce.d.ts +2 -0
  452. package/dist/modules/oauth/helpers/pkce.js +33 -0
  453. package/dist/modules/oauth/helpers/pkce.mjs +8 -0
  454. package/dist/modules/oauth/helpers/redirect-uri.d.ts +2 -0
  455. package/dist/modules/oauth/helpers/redirect-uri.js +32 -0
  456. package/dist/modules/oauth/helpers/redirect-uri.mjs +7 -0
  457. package/dist/modules/oauth/index.d.ts +5 -0
  458. package/dist/modules/oauth/index.js +30 -0
  459. package/dist/modules/oauth/index.mjs +5 -0
  460. package/dist/modules/oauth/module.d.ts +4 -0
  461. package/dist/modules/oauth/module.js +40 -0
  462. package/dist/modules/oauth/module.mjs +15 -0
  463. package/dist/modules/oauth/providers/google.provider.d.ts +20 -0
  464. package/dist/modules/oauth/providers/google.provider.js +63 -0
  465. package/dist/modules/oauth/providers/google.provider.mjs +36 -0
  466. package/dist/modules/oauth/providers/index.d.ts +7 -0
  467. package/dist/modules/oauth/providers/index.js +47 -0
  468. package/dist/modules/oauth/providers/index.mjs +17 -0
  469. package/dist/modules/oauth/providers/microsoft.provider.d.ts +17 -0
  470. package/dist/modules/oauth/providers/microsoft.provider.js +53 -0
  471. package/dist/modules/oauth/providers/microsoft.provider.mjs +29 -0
  472. package/dist/modules/oauth/providers/oauth-provider.d.ts +34 -0
  473. package/dist/modules/oauth/providers/oauth-provider.js +39 -0
  474. package/dist/modules/oauth/providers/oauth-provider.mjs +15 -0
  475. package/dist/modules/oauth/providers/oauth2.provider.d.ts +42 -0
  476. package/dist/modules/oauth/providers/oauth2.provider.js +116 -0
  477. package/dist/modules/oauth/providers/oauth2.provider.mjs +82 -0
  478. package/dist/modules/oauth/purposes/index.d.ts +1 -0
  479. package/dist/modules/oauth/purposes/index.js +22 -0
  480. package/dist/modules/oauth/purposes/index.mjs +1 -0
  481. package/dist/modules/oauth/purposes/oauth-purpose.d.ts +15 -0
  482. package/dist/modules/oauth/purposes/oauth-purpose.js +42 -0
  483. package/dist/modules/oauth/purposes/oauth-purpose.mjs +17 -0
  484. package/dist/modules/oauth/use-cases/complete-authorization.use-case.d.ts +24 -0
  485. package/dist/modules/oauth/use-cases/complete-authorization.use-case.js +95 -0
  486. package/dist/modules/oauth/use-cases/complete-authorization.use-case.mjs +71 -0
  487. package/dist/modules/oauth/use-cases/start-authorization.use-case.d.ts +23 -0
  488. package/dist/modules/oauth/use-cases/start-authorization.use-case.js +68 -0
  489. package/dist/modules/oauth/use-cases/start-authorization.use-case.mjs +44 -0
  490. package/dist/modules/organizations/entities/index.d.ts +1 -0
  491. package/dist/modules/organizations/entities/index.js +22 -0
  492. package/dist/modules/organizations/entities/index.mjs +1 -0
  493. package/dist/modules/organizations/entities/organization.entity.d.ts +79 -0
  494. package/dist/modules/organizations/entities/organization.entity.js +83 -0
  495. package/dist/modules/organizations/entities/organization.entity.mjs +57 -0
  496. package/dist/modules/organizations/helpers/invitation-token.d.ts +2 -0
  497. package/dist/modules/organizations/helpers/invitation-token.js +32 -0
  498. package/dist/modules/organizations/helpers/invitation-token.mjs +7 -0
  499. package/dist/modules/organizations/helpers/membership-cache.d.ts +22 -0
  500. package/dist/modules/organizations/helpers/membership-cache.js +76 -0
  501. package/dist/modules/organizations/helpers/membership-cache.mjs +49 -0
  502. package/dist/modules/organizations/helpers/membership-guard.d.ts +11 -0
  503. package/dist/modules/organizations/helpers/membership-guard.js +53 -0
  504. package/dist/modules/organizations/helpers/membership-guard.mjs +27 -0
  505. package/dist/modules/organizations/helpers/membership-resolver.d.ts +9 -0
  506. package/dist/modules/organizations/helpers/membership-resolver.js +45 -0
  507. package/dist/modules/organizations/helpers/membership-resolver.mjs +21 -0
  508. package/dist/modules/organizations/helpers/organization-config.d.ts +4 -0
  509. package/dist/modules/organizations/helpers/organization-config.js +31 -0
  510. package/dist/modules/organizations/helpers/organization-config.mjs +7 -0
  511. package/dist/modules/organizations/helpers/organization-extensions.d.ts +6 -0
  512. package/dist/modules/organizations/helpers/organization-extensions.js +38 -0
  513. package/dist/modules/organizations/helpers/organization-extensions.mjs +11 -0
  514. package/dist/modules/organizations/helpers/organization-view.d.ts +3 -0
  515. package/dist/modules/organizations/helpers/organization-view.js +36 -0
  516. package/dist/modules/organizations/helpers/organization-view.mjs +12 -0
  517. package/dist/modules/organizations/index.d.ts +10 -0
  518. package/dist/modules/organizations/index.js +57 -0
  519. package/dist/modules/organizations/index.mjs +19 -0
  520. package/dist/modules/organizations/module.d.ts +34 -0
  521. package/dist/modules/organizations/module.js +145 -0
  522. package/dist/modules/organizations/module.mjs +105 -0
  523. package/dist/modules/organizations/repositories/index.d.ts +1 -0
  524. package/dist/modules/organizations/repositories/index.js +22 -0
  525. package/dist/modules/organizations/repositories/index.mjs +1 -0
  526. package/dist/modules/organizations/repositories/organization.repository.d.ts +92 -0
  527. package/dist/modules/organizations/repositories/organization.repository.js +168 -0
  528. package/dist/modules/organizations/repositories/organization.repository.mjs +143 -0
  529. package/dist/modules/organizations/use-cases/accept-invitation.use-case.d.ts +15 -0
  530. package/dist/modules/organizations/use-cases/accept-invitation.use-case.js +57 -0
  531. package/dist/modules/organizations/use-cases/accept-invitation.use-case.mjs +33 -0
  532. package/dist/modules/organizations/use-cases/assign-member-roles.use-case.d.ts +18 -0
  533. package/dist/modules/organizations/use-cases/assign-member-roles.use-case.js +59 -0
  534. package/dist/modules/organizations/use-cases/assign-member-roles.use-case.mjs +35 -0
  535. package/dist/modules/organizations/use-cases/change-member-role.use-case.d.ts +16 -0
  536. package/dist/modules/organizations/use-cases/change-member-role.use-case.js +47 -0
  537. package/dist/modules/organizations/use-cases/change-member-role.use-case.mjs +23 -0
  538. package/dist/modules/organizations/use-cases/create-invitation.use-case.d.ts +23 -0
  539. package/dist/modules/organizations/use-cases/create-invitation.use-case.js +68 -0
  540. package/dist/modules/organizations/use-cases/create-invitation.use-case.mjs +44 -0
  541. package/dist/modules/organizations/use-cases/create-organization.use-case.d.ts +14 -0
  542. package/dist/modules/organizations/use-cases/create-organization.use-case.js +56 -0
  543. package/dist/modules/organizations/use-cases/create-organization.use-case.mjs +32 -0
  544. package/dist/modules/organizations/use-cases/delete-organization.use-case.d.ts +12 -0
  545. package/dist/modules/organizations/use-cases/delete-organization.use-case.js +53 -0
  546. package/dist/modules/organizations/use-cases/delete-organization.use-case.mjs +29 -0
  547. package/dist/modules/organizations/use-cases/ensure-personal-organization.use-case.d.ts +11 -0
  548. package/dist/modules/organizations/use-cases/ensure-personal-organization.use-case.js +56 -0
  549. package/dist/modules/organizations/use-cases/ensure-personal-organization.use-case.mjs +32 -0
  550. package/dist/modules/organizations/use-cases/get-organization.use-case.d.ts +12 -0
  551. package/dist/modules/organizations/use-cases/get-organization.use-case.js +46 -0
  552. package/dist/modules/organizations/use-cases/get-organization.use-case.mjs +22 -0
  553. package/dist/modules/organizations/use-cases/list-invitations.use-case.d.ts +12 -0
  554. package/dist/modules/organizations/use-cases/list-invitations.use-case.js +42 -0
  555. package/dist/modules/organizations/use-cases/list-invitations.use-case.mjs +18 -0
  556. package/dist/modules/organizations/use-cases/list-members.use-case.d.ts +12 -0
  557. package/dist/modules/organizations/use-cases/list-members.use-case.js +42 -0
  558. package/dist/modules/organizations/use-cases/list-members.use-case.mjs +18 -0
  559. package/dist/modules/organizations/use-cases/list-organizations.use-case.d.ts +12 -0
  560. package/dist/modules/organizations/use-cases/list-organizations.use-case.js +50 -0
  561. package/dist/modules/organizations/use-cases/list-organizations.use-case.mjs +26 -0
  562. package/dist/modules/organizations/use-cases/lookup-invitation.use-case.d.ts +19 -0
  563. package/dist/modules/organizations/use-cases/lookup-invitation.use-case.js +43 -0
  564. package/dist/modules/organizations/use-cases/lookup-invitation.use-case.mjs +19 -0
  565. package/dist/modules/organizations/use-cases/remove-member.use-case.d.ts +13 -0
  566. package/dist/modules/organizations/use-cases/remove-member.use-case.js +57 -0
  567. package/dist/modules/organizations/use-cases/remove-member.use-case.mjs +33 -0
  568. package/dist/modules/organizations/use-cases/remove-user-memberships.use-case.d.ts +11 -0
  569. package/dist/modules/organizations/use-cases/remove-user-memberships.use-case.js +39 -0
  570. package/dist/modules/organizations/use-cases/remove-user-memberships.use-case.mjs +15 -0
  571. package/dist/modules/organizations/use-cases/resolve-organization.use-case.d.ts +12 -0
  572. package/dist/modules/organizations/use-cases/resolve-organization.use-case.js +44 -0
  573. package/dist/modules/organizations/use-cases/resolve-organization.use-case.mjs +20 -0
  574. package/dist/modules/organizations/use-cases/revoke-invitation.use-case.d.ts +12 -0
  575. package/dist/modules/organizations/use-cases/revoke-invitation.use-case.js +42 -0
  576. package/dist/modules/organizations/use-cases/revoke-invitation.use-case.mjs +18 -0
  577. package/dist/modules/organizations/use-cases/update-organization.use-case.d.ts +13 -0
  578. package/dist/modules/organizations/use-cases/update-organization.use-case.js +55 -0
  579. package/dist/modules/organizations/use-cases/update-organization.use-case.mjs +31 -0
  580. package/dist/modules/plans/entities/index.d.ts +1 -0
  581. package/dist/modules/plans/entities/index.js +22 -0
  582. package/dist/modules/plans/entities/index.mjs +1 -0
  583. package/dist/modules/plans/entities/plan.d.ts +17 -0
  584. package/dist/modules/plans/entities/plan.js +33 -0
  585. package/dist/modules/plans/entities/plan.mjs +9 -0
  586. package/dist/modules/plans/helpers/plan-catalog.d.ts +21 -0
  587. package/dist/modules/plans/helpers/plan-catalog.js +70 -0
  588. package/dist/modules/plans/helpers/plan-catalog.mjs +45 -0
  589. package/dist/modules/plans/index.d.ts +3 -0
  590. package/dist/modules/plans/index.js +26 -0
  591. package/dist/modules/plans/index.mjs +3 -0
  592. package/dist/modules/plans/module.d.ts +5 -0
  593. package/dist/modules/plans/module.js +46 -0
  594. package/dist/modules/plans/module.mjs +20 -0
  595. package/dist/modules/plans/use-cases/check-limit.use-case.d.ts +20 -0
  596. package/dist/modules/plans/use-cases/check-limit.use-case.js +54 -0
  597. package/dist/modules/plans/use-cases/check-limit.use-case.mjs +30 -0
  598. package/dist/modules/plans/use-cases/resolve-plan.use-case.d.ts +20 -0
  599. package/dist/modules/plans/use-cases/resolve-plan.use-case.js +63 -0
  600. package/dist/modules/plans/use-cases/resolve-plan.use-case.mjs +39 -0
  601. package/dist/modules/users/entities/index.d.ts +1 -0
  602. package/dist/modules/users/entities/index.js +22 -0
  603. package/dist/modules/users/entities/index.mjs +1 -0
  604. package/dist/modules/users/entities/user-country.d.ts +11 -0
  605. package/dist/modules/users/entities/user-country.js +44 -0
  606. package/dist/modules/users/entities/user-country.mjs +20 -0
  607. package/dist/modules/users/entities/user-currency.d.ts +13 -0
  608. package/dist/modules/users/entities/user-currency.js +44 -0
  609. package/dist/modules/users/entities/user-currency.mjs +20 -0
  610. package/dist/modules/users/entities/user-email.value-object.d.ts +6 -0
  611. package/dist/modules/users/entities/user-email.value-object.js +44 -0
  612. package/dist/modules/users/entities/user-email.value-object.mjs +20 -0
  613. package/dist/modules/users/entities/user-language.d.ts +11 -0
  614. package/dist/modules/users/entities/user-language.js +44 -0
  615. package/dist/modules/users/entities/user-language.mjs +20 -0
  616. package/dist/modules/users/entities/user-notification-preferences.d.ts +11 -0
  617. package/dist/modules/users/entities/user-notification-preferences.js +41 -0
  618. package/dist/modules/users/entities/user-notification-preferences.mjs +17 -0
  619. package/dist/modules/users/entities/user-password.value-object.d.ts +8 -0
  620. package/dist/modules/users/entities/user-password.value-object.js +57 -0
  621. package/dist/modules/users/entities/user-password.value-object.mjs +23 -0
  622. package/dist/modules/users/entities/user-permissions.d.ts +21 -0
  623. package/dist/modules/users/entities/user-permissions.js +59 -0
  624. package/dist/modules/users/entities/user-permissions.mjs +35 -0
  625. package/dist/modules/users/entities/user-preferences.d.ts +27 -0
  626. package/dist/modules/users/entities/user-preferences.js +82 -0
  627. package/dist/modules/users/entities/user-preferences.mjs +58 -0
  628. package/dist/modules/users/entities/user-report-preferences.d.ts +16 -0
  629. package/dist/modules/users/entities/user-report-preferences.js +56 -0
  630. package/dist/modules/users/entities/user-report-preferences.mjs +32 -0
  631. package/dist/modules/users/entities/user-report-schedule.d.ts +11 -0
  632. package/dist/modules/users/entities/user-report-schedule.js +41 -0
  633. package/dist/modules/users/entities/user-report-schedule.mjs +17 -0
  634. package/dist/modules/users/entities/user-timezone.d.ts +11 -0
  635. package/dist/modules/users/entities/user-timezone.js +44 -0
  636. package/dist/modules/users/entities/user-timezone.mjs +20 -0
  637. package/dist/modules/users/entities/user.entity.d.ts +40 -0
  638. package/dist/modules/users/entities/user.entity.js +110 -0
  639. package/dist/modules/users/entities/user.entity.mjs +85 -0
  640. package/dist/modules/users/helpers/default-preferences.d.ts +4 -0
  641. package/dist/modules/users/helpers/default-preferences.js +58 -0
  642. package/dist/modules/users/helpers/default-preferences.mjs +33 -0
  643. package/dist/modules/users/helpers/profile.d.ts +3 -0
  644. package/dist/modules/users/helpers/profile.js +37 -0
  645. package/dist/modules/users/helpers/profile.mjs +13 -0
  646. package/dist/modules/users/helpers/user-context.d.ts +19 -0
  647. package/dist/modules/users/helpers/user-context.js +52 -0
  648. package/dist/modules/users/helpers/user-context.mjs +28 -0
  649. package/dist/modules/users/helpers/user-extensions.d.ts +5 -0
  650. package/dist/modules/users/helpers/user-extensions.js +34 -0
  651. package/dist/modules/users/helpers/user-extensions.mjs +8 -0
  652. package/dist/modules/users/helpers/user-roles.d.ts +11 -0
  653. package/dist/modules/users/helpers/user-roles.js +52 -0
  654. package/dist/modules/users/helpers/user-roles.mjs +26 -0
  655. package/dist/modules/users/index.d.ts +8 -0
  656. package/dist/modules/users/index.js +36 -0
  657. package/dist/modules/users/index.mjs +8 -0
  658. package/dist/modules/users/module.d.ts +12 -0
  659. package/dist/modules/users/module.js +68 -0
  660. package/dist/modules/users/module.mjs +39 -0
  661. package/dist/modules/users/repositories/index.d.ts +1 -0
  662. package/dist/modules/users/repositories/index.js +22 -0
  663. package/dist/modules/users/repositories/index.mjs +1 -0
  664. package/dist/modules/users/repositories/user.repository.d.ts +18 -0
  665. package/dist/modules/users/repositories/user.repository.js +92 -0
  666. package/dist/modules/users/repositories/user.repository.mjs +67 -0
  667. package/dist/modules/users/use-cases/change-password.use-case.d.ts +15 -0
  668. package/dist/modules/users/use-cases/change-password.use-case.js +53 -0
  669. package/dist/modules/users/use-cases/change-password.use-case.mjs +29 -0
  670. package/dist/modules/users/use-cases/create-user.use-case.d.ts +12 -0
  671. package/dist/modules/users/use-cases/create-user.use-case.js +47 -0
  672. package/dist/modules/users/use-cases/create-user.use-case.mjs +23 -0
  673. package/dist/modules/users/use-cases/delete-user.use-case.d.ts +16 -0
  674. package/dist/modules/users/use-cases/delete-user.use-case.js +49 -0
  675. package/dist/modules/users/use-cases/delete-user.use-case.mjs +25 -0
  676. package/dist/modules/users/use-cases/get-user-by-id.use-case.d.ts +12 -0
  677. package/dist/modules/users/use-cases/get-user-by-id.use-case.js +44 -0
  678. package/dist/modules/users/use-cases/get-user-by-id.use-case.mjs +20 -0
  679. package/dist/modules/users/use-cases/list-users-by-props.use-case.d.ts +17 -0
  680. package/dist/modules/users/use-cases/list-users-by-props.use-case.js +42 -0
  681. package/dist/modules/users/use-cases/list-users-by-props.use-case.mjs +18 -0
  682. package/dist/modules/users/use-cases/update-user.use-case.d.ts +13 -0
  683. package/dist/modules/users/use-cases/update-user.use-case.js +51 -0
  684. package/dist/modules/users/use-cases/update-user.use-case.mjs +27 -0
  685. package/docs/README.md +15 -0
  686. package/docs/activities.md +9 -0
  687. package/docs/actor-and-context.md +47 -0
  688. package/docs/billing-and-plans.md +37 -0
  689. package/docs/conventions.md +42 -0
  690. package/docs/encryption.md +76 -0
  691. package/docs/extensions.md +38 -0
  692. package/docs/getting-started.md +50 -0
  693. package/docs/http.md +25 -0
  694. package/docs/oauth-and-integrations.md +24 -0
  695. package/docs/organizations.md +20 -0
  696. package/docs/permissions.md +74 -0
  697. package/docs/tenants.md +36 -0
  698. package/docs/users-and-authentication.md +23 -0
  699. package/package.json +132 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0-beta.0
4
+
5
+ Architecture decisions taken before the first publication: organizations first (every user has a personal organization and tenant data always has `organizationId`), email as the only identity of the core, neutral billing names (`platform`, `externalId`), open registries for platforms, roles, services and activity types, enums for statuses, error messages and collections, `payload` for the body in every function, signing keys with `kid` and access tokens without personal data, and an extension registry plus a `properties` bag in every entity.
6
+
7
+ ### Added
8
+
9
+ - Core: scoped `MongoRepository` (soft delete, archive, optimistic locking, tenant mode), `Scope` with organizations, `BaseEntity`, `BaseUseCase`, error reporter, logger and secret manager.
10
+ - Users and authentication: create, update and delete users, login with rate limit, register, refresh with token families, logout, password recover and reset, revoked tokens.
11
+ - Organizations: memberships, roles (owner, admin, member), invitations, personal organization for every user.
12
+ - Billing: billing accounts per organization or per resource (a PaaS bills each resource apart), ledger, subscriptions that hang from the account, entitlement and plan per account, checkout that carries the `billingId` and a webhook that creates the subscription from it, `BillingProvider` port with a Polar adapter.
13
+ - `collectionPrefix` (empty by default): a prefix for the collections of the package when the solution shares its database; never for the collections of the app. All the collections keep one standard name, and the unused `x-client-ip` header was removed.
14
+ - Brand of the solution: `configure({ appName })` gives the prefix of the variables (`MYAPP_DB_URI`), the default database, the issuer of the tokens, the `source` of the error reports and the `appName` of the MongoDB connection; `NANOSAAS_` and `nanosaas` by default, each one can be overridden (`envPrefix`, `dbName`, `tokenIssuer`).
15
+ - `localeOf`: country, language and currency (with names) of the IANA timezone of the request context, for the screens before there is a user.
16
+ - OAuth2 with PKCE for Google and Microsoft, open registries of providers and purposes, and integrations with encrypted refresh tokens and access token refresh.
17
+ - HTTP layer (`BaseController`, Lambda adapter), event bus, rate limiter.
18
+ - Extensions: `registerUserExtension` (root or preferences) and the equivalent for organizations, memberships, integrations, billing accounts, subscriptions and activities, with the paths the client cannot write, typed through `<Entity>ExtensionValues` and `<Entity>ExtensionProps`, plus a `properties` bag that only trusted scopes write. Unknown preferences stay as properties of `UserPreferences`.
19
+ - Actor: an immutable `Actor` built from the claims of the token without reading the database, with `withOrganization` and `withProfile`; the routes read one membership (cached 30 s, `membershipCacheTtlSeconds`) instead of four documents, and nothing for routes that need no organization. `profileOf` reads the profile only where a use case needs it.
20
+ - Request context: `RequestContext` with three parts (`client`, `situation`, `request`) of different trust, read from `x-client-context`. `buildUserContext` joins the stored preferences with the situation of the call for agents. Activities keep it in `context`.
21
+ - Client context: `readRequestContext` reads `x-client-context` into `RouteContext.requestContext`. `register` fills language, timezone, country and currency from it (`withDefaultPreferences`, `supportedLanguages` and `defaultLanguage` in `configure`).
22
+ - Roles and permissions: a permission catalog (`Permission`, `permissions.register`), base roles plus roles of the product (`defineRole`), `roles` in the membership (`assignMemberRoles`, invitations with roles, nobody grants what they lack), effective permissions in the actor and in the organization views, `Scope.allow`, `Scope.self`, `can` in HTTP routes, and delegated tokens with scopes (`issueDelegatedToken`, `verifyDelegatedToken`) for control planes that administer isolated tenants. Billing, integrations, activities and the organization itself are checked by permission; a plain member only sees the organization and its members.
23
+ - `Scope.asAdmin(user, { organizationId })` limits the scope of an operator to one organization in the repositories that have organizations. An admin of an organization is only that: tests prove that the same user is admin in A, plain member in B, and cannot use A to act on B.
24
+ - One encryption scheme (`ENC:v2:<key id>:<data>`): AES-256-GCM with a key derived per value with HKDF from a random master key, the context of the value as authenticated data so a value only opens where it was made, key ids for rotation (`<PREFIX>_ENCRYPTION_KEY_V<N>`), strict reading, a `reencrypt` job and `encrypted` fields in `MongoRepository` (integrations encrypt `refreshToken` and `apiKey`). `runWithConfigs` takes the id of the tenant, and `runWithTenant(tenantId, configs, fn)` is the short form (see `docs/tenants.md`). The `SecretManager` was simplified: plain settings pass, `ENC:v2` values are decrypted with their name and tenant.
25
+ - `RoleSource` (`setRoleSource`) and `MembershipStore` (`setMembershipStore`) are interfaces with the code catalog and the in memory cache as defaults, so roles that each organization defines and a shared cache can be plugged in later without breaking the callers.
26
+ - The public `register` removes the control fields, the role, `properties` and the paths that an extension protects from the payload before creating the user, which it does with a trusted scope.
27
+ - Plans: `plans.configure` (plans with limits, default plan, trial), `resolvePlan`, `checkLimit` and `assertLimit` (402 `{{need_to_upgrade_subscription}}`) with a counter per resource.
28
+ - Activities: `trackActivity`, `listActivities`, a registry of activity types, optional retention and `subscribeActivityTracking`, which records the events of auth, organizations, integrations and billing.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # nanosaas
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/nanosaas/beta)](https://www.npmjs.com/package/nanosaas)
4
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
5
+ [![node](https://img.shields.io/badge/node-%3E%3D22-green)](package.json)
6
+
7
+ The core of a multitenant SaaS backend, as a package. Users, authentication, organizations, billing, OAuth integrations, plans and activity tracking for Node, TypeScript and MongoDB, exposed as ready to use functions.
8
+
9
+ Every SaaS starts by rewriting the same base: accounts, sessions, teams, roles, subscriptions. nanosaas is that base, built **organization first**, so the day you need teams you do not need a migration.
10
+
11
+ > **Status: beta.** The API can still change before 1.0. Pin the version and read the [changelog](CHANGELOG.md) when you upgrade.
12
+
13
+ ## Features
14
+
15
+ - **Users and authentication.** Register, login with rate limiting, short lived access tokens, rotating refresh tokens with reuse detection, password recovery, session revocation, signing keys with rotation.
16
+ - **Organizations.** Every user gets a personal organization. Memberships, invitations, base roles (owner, admin, member) plus roles of your own product.
17
+ - **Roles and permissions.** Code checks permissions, roles are sets of permissions, and nobody can grant a permission they do not have.
18
+ - **A scoped repository.** One `MongoRepository` where every call takes a `Scope`: tenant filtering, ownership fields stamped by the server, soft delete, optimistic locking and encrypted fields.
19
+ - **Billing.** Accounts per organization or per resource, an idempotent ledger, subscriptions, entitlements, checkout and webhooks behind a provider port (a Polar adapter is included).
20
+ - **Plans and limits.** Plans resolved from the entitlement, a trial and a default plan, with counters per limited resource.
21
+ - **OAuth2 with PKCE and integrations.** Open registries of providers and purposes, encrypted tokens, automatic refresh.
22
+ - **Encryption.** AES-256-GCM with a key derived per value, the context as authenticated data, key ids for rotation and a job to re-encrypt.
23
+ - **Activities.** An audit trail fed by the events of the other modules, which never breaks the caller.
24
+ - **Extensible.** Every entity has an extension registry and a `properties` bag, and every integration point is a port or a registry: no provider code inside the modules.
25
+ - **Multi tenant runtimes.** Run each isolated tenant with its own database and secrets in the same process.
26
+ - **HTTP layer.** A small controller and a handler for API Gateway v2 (Lambda), with permission checks per route.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ yarn add nanosaas
32
+ ```
33
+
34
+ Needs Node 22 or later and a MongoDB database. The package ships ESM and CJS and its own types.
35
+
36
+ ## Quick start
37
+
38
+ ```ts
39
+ import { configure } from 'nanosaas/common'
40
+ import { register, login } from 'nanosaas/authentication'
41
+ import { createOrganization } from 'nanosaas/organizations'
42
+
43
+ configure({
44
+ appName: 'myapp',
45
+ dbUri: process.env.MYAPP_DB_URI,
46
+ apiBaseUrl: 'https://api.myapp.com',
47
+ })
48
+
49
+ const session = await register({
50
+ payload: { email: 'ana@myapp.com', password: 'a-long-password' },
51
+ ipAddress,
52
+ rateLimit: true,
53
+ })
54
+ ```
55
+
56
+ `register` creates the user and their personal organization and answers the tokens. Set `JWT_SECRET` and a `<PREFIX>_ENCRYPTION_KEY_V1` in the environment first: [getting started](docs/getting-started.md) lists every setting.
57
+
58
+ ## One package, many entry points
59
+
60
+ Import only what you use.
61
+
62
+ | Import | What it gives you |
63
+ |---|---|
64
+ | `nanosaas/common` | `configure`, errors, `Scope`, actors, request context, encryption, tenants |
65
+ | `nanosaas/users` | users, preferences, extensions |
66
+ | `nanosaas/authentication` | register, login, refresh, logout, password reset |
67
+ | `nanosaas/organizations` | organizations, members, invitations, roles |
68
+ | `nanosaas/billing` | accounts, subscriptions, checkout, webhooks |
69
+ | `nanosaas/plans` | plans and limits |
70
+ | `nanosaas/oauth` | OAuth2 PKCE flow, providers and purposes |
71
+ | `nanosaas/integrations` | connected services and their credentials |
72
+ | `nanosaas/activities` | activity tracking |
73
+ | `nanosaas/db` | `MongoRepository`, `ensureIndexes` |
74
+ | `nanosaas/http` | `BaseController`, routes, the Lambda handler |
75
+ | `nanosaas/events` | the in process event bus |
76
+ | `nanosaas/rate-limit` | rate limiting with a pluggable store |
77
+ | `nanosaas/crypto` | encryption helpers and `reencrypt` |
78
+
79
+ ## Design principles
80
+
81
+ - **Organization first.** Tenant documents always carry `organizationId`; `ownerId` is only the creator. A single user app is just an organization of one.
82
+ - **Nothing implicit.** Every repository method takes a `Scope`, and control fields come from it, never from the payload.
83
+ - **Ports, not providers.** Email, billing, rate limit storage, OAuth state and roles are interfaces you can replace.
84
+ - **Your brand, not ours.** `appName` decides the environment variables, the database name, the token issuer and the error source. Collections keep standard names, with an optional prefix.
85
+ - **Safe by default.** Access tokens carry no personal data, secrets never travel in plain text, and the library never loads `.env` or creates databases, collections or indexes on its own: you apply the exported index specs in a deploy step.
86
+
87
+ ## Documentation
88
+
89
+ - [Getting started](docs/getting-started.md)
90
+ - [Conventions](docs/conventions.md)
91
+ - [Users and authentication](docs/users-and-authentication.md)
92
+ - [Organizations](docs/organizations.md)
93
+ - [Roles and permissions](docs/permissions.md)
94
+ - [Actor and request context](docs/actor-and-context.md)
95
+ - [Tenants](docs/tenants.md)
96
+ - [Billing and plans](docs/billing-and-plans.md)
97
+ - [OAuth and integrations](docs/oauth-and-integrations.md)
98
+ - [Encryption](docs/encryption.md)
99
+ - [Extensions](docs/extensions.md)
100
+ - [Activities](docs/activities.md)
101
+ - [HTTP](docs/http.md)
102
+
103
+ ## Contributing
104
+
105
+ Issues and pull requests are welcome. Before opening one:
106
+
107
+ ```bash
108
+ yarn install
109
+ yarn typecheck
110
+ yarn test
111
+ yarn build
112
+ ```
113
+
114
+ Tests run against an in memory fake of the Mongo client, so they need no database. Keep the code style of the repository (no semicolons, single quotes, four spaces, trailing commas, enums for fixed sets of values) and add a line to the [changelog](CHANGELOG.md) for every change a user of the package can notice.
115
+
116
+ ## License
117
+
118
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,40 @@
1
+ import { OrgRole } from '../db/org-role';
2
+ import { ScopeUser } from '../db/scope';
3
+ export interface ActorProfile {
4
+ _id?: unknown;
5
+ email?: string;
6
+ firstName?: string;
7
+ lastName?: string;
8
+ role?: string;
9
+ createdAt?: Date | string;
10
+ preferences?: Record<string, any>;
11
+ }
12
+ export interface ActorLike extends ScopeUser {
13
+ readonly userId?: string;
14
+ readonly activeOrganizationId?: string;
15
+ readonly activeOrganizationRole?: OrgRole;
16
+ readonly activeRoles: readonly string[];
17
+ readonly activePermissions: ReadonlySet<string>;
18
+ readonly profile?: ActorProfile;
19
+ can(...required: string[]): boolean;
20
+ }
21
+ export interface ActorClaims {
22
+ userId: string;
23
+ sessionId?: string;
24
+ }
25
+ export declare class Actor implements ActorLike {
26
+ readonly userId: string;
27
+ readonly sessionId?: string | undefined;
28
+ readonly activeOrganizationId?: string | undefined;
29
+ readonly activeOrganizationRole?: OrgRole | undefined;
30
+ readonly activeRoles: readonly string[];
31
+ readonly activePermissions: ReadonlySet<string>;
32
+ readonly profile?: ActorProfile | undefined;
33
+ private constructor();
34
+ static fromClaims(claims: ActorClaims): Actor;
35
+ static from(source: ActorLike): Actor;
36
+ withOrganization(organizationId: string, role: OrgRole, roles?: string[], permissions?: ReadonlySet<string>): Actor;
37
+ withProfile(profile: ActorProfile): Actor;
38
+ can(...required: string[]): boolean;
39
+ isAdmin(): boolean;
40
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var actor_exports = {};
20
+ __export(actor_exports, {
21
+ Actor: () => Actor
22
+ });
23
+ module.exports = __toCommonJS(actor_exports);
24
+ var import_user_roles = require("../../modules/users/helpers/user-roles.js");
25
+ var import_role_catalog = require("./role-catalog");
26
+ class Actor {
27
+ constructor(userId, sessionId, activeOrganizationId, activeOrganizationRole, activeRoles = [], activePermissions = /* @__PURE__ */ new Set(), profile) {
28
+ this.userId = userId;
29
+ this.sessionId = sessionId;
30
+ this.activeOrganizationId = activeOrganizationId;
31
+ this.activeOrganizationRole = activeOrganizationRole;
32
+ this.activeRoles = activeRoles;
33
+ this.activePermissions = activePermissions;
34
+ this.profile = profile;
35
+ }
36
+ userId;
37
+ sessionId;
38
+ activeOrganizationId;
39
+ activeOrganizationRole;
40
+ activeRoles;
41
+ activePermissions;
42
+ profile;
43
+ static fromClaims(claims) {
44
+ return new Actor(claims.userId, claims.sessionId);
45
+ }
46
+ static from(source) {
47
+ if (source instanceof Actor) return source;
48
+ return new Actor(source.userId, void 0, source.activeOrganizationId, source.activeOrganizationRole, [...source.activeRoles], new Set(source.activePermissions), source.profile);
49
+ }
50
+ withOrganization(organizationId, role, roles = [], permissions) {
51
+ return new Actor(this.userId, this.sessionId, organizationId, role, [...roles], permissions ?? import_role_catalog.roles.permissionsOf(role, roles), this.profile);
52
+ }
53
+ withProfile(profile) {
54
+ return new Actor(this.userId, this.sessionId, this.activeOrganizationId, this.activeOrganizationRole, this.activeRoles, this.activePermissions, profile);
55
+ }
56
+ can(...required) {
57
+ return required.length > 0 && required.every((permission) => this.activePermissions.has(permission));
58
+ }
59
+ isAdmin() {
60
+ return this.profile?.role === import_user_roles.UserRole.ADMIN;
61
+ }
62
+ }
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ Actor
66
+ });
@@ -0,0 +1,42 @@
1
+ import { UserRole } from "../../modules/users/helpers/user-roles.js";
2
+ import { roles as roleCatalog } from "./role-catalog";
3
+ class Actor {
4
+ constructor(userId, sessionId, activeOrganizationId, activeOrganizationRole, activeRoles = [], activePermissions = /* @__PURE__ */ new Set(), profile) {
5
+ this.userId = userId;
6
+ this.sessionId = sessionId;
7
+ this.activeOrganizationId = activeOrganizationId;
8
+ this.activeOrganizationRole = activeOrganizationRole;
9
+ this.activeRoles = activeRoles;
10
+ this.activePermissions = activePermissions;
11
+ this.profile = profile;
12
+ }
13
+ userId;
14
+ sessionId;
15
+ activeOrganizationId;
16
+ activeOrganizationRole;
17
+ activeRoles;
18
+ activePermissions;
19
+ profile;
20
+ static fromClaims(claims) {
21
+ return new Actor(claims.userId, claims.sessionId);
22
+ }
23
+ static from(source) {
24
+ if (source instanceof Actor) return source;
25
+ return new Actor(source.userId, void 0, source.activeOrganizationId, source.activeOrganizationRole, [...source.activeRoles], new Set(source.activePermissions), source.profile);
26
+ }
27
+ withOrganization(organizationId, role, roles = [], permissions) {
28
+ return new Actor(this.userId, this.sessionId, organizationId, role, [...roles], permissions ?? roleCatalog.permissionsOf(role, roles), this.profile);
29
+ }
30
+ withProfile(profile) {
31
+ return new Actor(this.userId, this.sessionId, this.activeOrganizationId, this.activeOrganizationRole, this.activeRoles, this.activePermissions, profile);
32
+ }
33
+ can(...required) {
34
+ return required.length > 0 && required.every((permission) => this.activePermissions.has(permission));
35
+ }
36
+ isAdmin() {
37
+ return this.profile?.role === UserRole.ADMIN;
38
+ }
39
+ }
40
+ export {
41
+ Actor
42
+ };
@@ -0,0 +1,11 @@
1
+ import { Logger } from '../logger/index.js';
2
+ import { HttpError, HttpErrorProps } from '../error/index.js';
3
+ export declare abstract class BaseApp {
4
+ logger: Logger;
5
+ secretManager: import("../utils/secret-manager.js").SecretManager;
6
+ reportError: (error: Error | HttpError | string, details?: object) => Promise<void>;
7
+ onCatch(error: Error): Promise<void>;
8
+ throwHttpError(error: HttpErrorProps): never;
9
+ throwError401(details?: unknown): never;
10
+ throwError403(details?: unknown): never;
11
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var base_app_exports = {};
20
+ __export(base_app_exports, {
21
+ BaseApp: () => BaseApp
22
+ });
23
+ module.exports = __toCommonJS(base_app_exports);
24
+ var import_logger = require("../logger/index.js");
25
+ var import_error = require("../error/index.js");
26
+ var import_error2 = require("../error/index.js");
27
+ var import_secret_manager = require("../utils/secret-manager.js");
28
+ var import_error3 = require("../error/index.js");
29
+ class BaseApp {
30
+ logger = new import_logger.Logger();
31
+ secretManager = import_secret_manager.secretManager;
32
+ reportError = import_error.reportError;
33
+ async onCatch(error) {
34
+ await (0, import_error.reportError)(error);
35
+ throw error;
36
+ }
37
+ throwHttpError(error) {
38
+ throw new import_error2.HttpError(error);
39
+ }
40
+ throwError401(details) {
41
+ this.throwHttpError({
42
+ statusCode: import_error3.HttpStatus.UNAUTHORIZED,
43
+ errorMessage: import_error3.ErrorMessage.NOT_AUTHENTICATED,
44
+ errorDetails: JSON.stringify(details ?? {})
45
+ });
46
+ }
47
+ throwError403(details) {
48
+ this.throwHttpError({
49
+ statusCode: import_error3.HttpStatus.FORBIDDEN,
50
+ errorMessage: import_error3.ErrorMessage.FORBIDDEN,
51
+ errorDetails: JSON.stringify(details ?? {})
52
+ });
53
+ }
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ BaseApp
58
+ });
@@ -0,0 +1,34 @@
1
+ import { Logger } from "../logger/index.js";
2
+ import { reportError } from "../error/index.js";
3
+ import { HttpError } from "../error/index.js";
4
+ import { secretManager } from "../utils/secret-manager.js";
5
+ import { ErrorMessage, HttpStatus } from "../error/index.js";
6
+ class BaseApp {
7
+ logger = new Logger();
8
+ secretManager = secretManager;
9
+ reportError = reportError;
10
+ async onCatch(error) {
11
+ await reportError(error);
12
+ throw error;
13
+ }
14
+ throwHttpError(error) {
15
+ throw new HttpError(error);
16
+ }
17
+ throwError401(details) {
18
+ this.throwHttpError({
19
+ statusCode: HttpStatus.UNAUTHORIZED,
20
+ errorMessage: ErrorMessage.NOT_AUTHENTICATED,
21
+ errorDetails: JSON.stringify(details ?? {})
22
+ });
23
+ }
24
+ throwError403(details) {
25
+ this.throwHttpError({
26
+ statusCode: HttpStatus.FORBIDDEN,
27
+ errorMessage: ErrorMessage.FORBIDDEN,
28
+ errorDetails: JSON.stringify(details ?? {})
29
+ });
30
+ }
31
+ }
32
+ export {
33
+ BaseApp
34
+ };
@@ -0,0 +1,42 @@
1
+ import { ObjectId } from 'mongodb';
2
+ import { Share, ShareProps } from './share';
3
+ import { ErrorMessage } from '../error/index.js';
4
+ export interface BaseEntityProps {
5
+ _id?: string | ObjectId;
6
+ __v?: number;
7
+ ownerId?: string | ObjectId;
8
+ organizationId?: string | ObjectId;
9
+ createdAt?: string | Date;
10
+ createdBy?: string | ObjectId;
11
+ updatedAt?: string | Date;
12
+ updatedBy?: string | ObjectId;
13
+ deletedAt?: string | Date;
14
+ deletedBy?: string | ObjectId;
15
+ deletedReason?: string;
16
+ archivedAt?: string | Date;
17
+ archivedBy?: string | ObjectId;
18
+ sharedWith?: ShareProps[];
19
+ }
20
+ export declare class BaseEntity {
21
+ _id?: ObjectId;
22
+ __v?: number;
23
+ ownerId?: ObjectId;
24
+ organizationId?: ObjectId;
25
+ createdAt?: Date;
26
+ createdBy?: ObjectId;
27
+ updatedAt?: Date;
28
+ updatedBy?: ObjectId;
29
+ deletedAt?: Date;
30
+ deletedBy?: ObjectId;
31
+ deletedReason?: string;
32
+ archivedAt?: Date;
33
+ archivedBy?: ObjectId;
34
+ sharedWith?: Share[];
35
+ static toObjectId(id?: string | ObjectId): ObjectId | undefined;
36
+ static toText(value?: string): string | undefined;
37
+ static toDate(value?: string | Date): Date | undefined;
38
+ static toEnum<T extends string>(values: Record<string, T>, value?: string, errorMessage?: ErrorMessage): T | undefined;
39
+ static toNumber(value?: number): number | undefined;
40
+ constructor(props: BaseEntityProps);
41
+ toJSON(): BaseEntityProps;
42
+ }