@porulle/core 0.64.0 → 0.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/dist/adapters/email-render.d.ts +18 -0
  2. package/dist/adapters/email-render.d.ts.map +1 -0
  3. package/dist/adapters/email-render.js +37 -0
  4. package/dist/auth/actor.d.ts.map +1 -1
  5. package/dist/auth/actor.js +11 -0
  6. package/dist/auth/auth-failure.d.ts +0 -2
  7. package/dist/auth/auth-failure.d.ts.map +1 -1
  8. package/dist/auth/auth-failure.js +0 -4
  9. package/dist/auth/middleware.d.ts +0 -1
  10. package/dist/auth/middleware.d.ts.map +1 -1
  11. package/dist/auth/middleware.js +7 -6
  12. package/dist/auth/permissions.d.ts +2 -0
  13. package/dist/auth/permissions.d.ts.map +1 -1
  14. package/dist/auth/permissions.js +8 -6
  15. package/dist/auth/role-authority.d.ts +0 -1
  16. package/dist/auth/role-authority.d.ts.map +1 -1
  17. package/dist/auth/role-authority.js +1 -8
  18. package/dist/auth/setup.d.ts.map +1 -1
  19. package/dist/auth/setup.js +5 -0
  20. package/dist/auth/strict-org-resolution.d.ts +8 -1
  21. package/dist/auth/strict-org-resolution.d.ts.map +1 -1
  22. package/dist/auth/strict-org-resolution.js +9 -19
  23. package/dist/auth/system-actor.d.ts +3 -2
  24. package/dist/auth/system-actor.d.ts.map +1 -1
  25. package/dist/auth/system-actor.js +3 -3
  26. package/dist/config/defaults.d.ts.map +1 -1
  27. package/dist/config/defaults.js +3 -20
  28. package/dist/config/define-config.d.ts +2 -2
  29. package/dist/config/define-config.d.ts.map +1 -1
  30. package/dist/config/define-config.js +3 -2
  31. package/dist/config/types.d.ts +2 -3
  32. package/dist/config/types.d.ts.map +1 -1
  33. package/dist/hooks/checkout.d.ts +2 -15
  34. package/dist/hooks/checkout.d.ts.map +1 -1
  35. package/dist/hooks/checkout.js +2 -51
  36. package/dist/index.d.ts +11 -19
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +11 -12
  39. package/dist/interfaces/rest/router.js +3 -3
  40. package/dist/interfaces/rest/routes/admin/compensation-failures.d.ts.map +1 -1
  41. package/dist/interfaces/rest/routes/admin/compensation-failures.js +5 -5
  42. package/dist/interfaces/rest/routes/admin/entity-field-definitions.js +5 -5
  43. package/dist/interfaces/rest/routes/admin/staff.d.ts.map +1 -1
  44. package/dist/interfaces/rest/routes/admin/staff.js +2 -3
  45. package/dist/interfaces/rest/routes/analytics.d.ts.map +1 -1
  46. package/dist/interfaces/rest/routes/analytics.js +2 -2
  47. package/dist/interfaces/rest/routes/carts.d.ts.map +1 -1
  48. package/dist/interfaces/rest/routes/carts.js +12 -12
  49. package/dist/interfaces/rest/routes/catalog.js +37 -37
  50. package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -1
  51. package/dist/interfaces/rest/routes/checkout.js +9 -10
  52. package/dist/interfaces/rest/routes/customers.d.ts.map +1 -1
  53. package/dist/interfaces/rest/routes/customers.js +12 -12
  54. package/dist/interfaces/rest/routes/documents.d.ts.map +1 -1
  55. package/dist/interfaces/rest/routes/documents.js +9 -9
  56. package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -1
  57. package/dist/interfaces/rest/routes/inventory.js +8 -8
  58. package/dist/interfaces/rest/routes/media.d.ts.map +1 -1
  59. package/dist/interfaces/rest/routes/media.js +5 -5
  60. package/dist/interfaces/rest/routes/orders.d.ts.map +1 -1
  61. package/dist/interfaces/rest/routes/orders.js +32 -32
  62. package/dist/interfaces/rest/routes/payments.d.ts.map +1 -1
  63. package/dist/interfaces/rest/routes/payments.js +2 -2
  64. package/dist/interfaces/rest/routes/pricing.d.ts.map +1 -1
  65. package/dist/interfaces/rest/routes/pricing.js +8 -8
  66. package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
  67. package/dist/interfaces/rest/routes/promotions.js +7 -7
  68. package/dist/interfaces/rest/routes/search.d.ts.map +1 -1
  69. package/dist/interfaces/rest/routes/search.js +3 -3
  70. package/dist/interfaces/rest/routes/settings.d.ts.map +1 -1
  71. package/dist/interfaces/rest/routes/settings.js +4 -4
  72. package/dist/interfaces/rest/routes/shipping.d.ts.map +1 -1
  73. package/dist/interfaces/rest/routes/shipping.js +9 -9
  74. package/dist/interfaces/rest/routes/tax.d.ts.map +1 -1
  75. package/dist/interfaces/rest/routes/tax.js +9 -9
  76. package/dist/interfaces/rest/routes/webhooks.d.ts.map +1 -1
  77. package/dist/interfaces/rest/routes/webhooks.js +4 -4
  78. package/dist/interfaces/rest/utils.d.ts +1 -1
  79. package/dist/interfaces/rest/utils.d.ts.map +1 -1
  80. package/dist/interfaces/rest/utils.js +4 -13
  81. package/dist/jobs.d.ts +1 -0
  82. package/dist/jobs.d.ts.map +1 -1
  83. package/dist/jobs.js +1 -0
  84. package/dist/kernel/database/adapter.d.ts +9 -0
  85. package/dist/kernel/database/adapter.d.ts.map +1 -1
  86. package/dist/kernel/database/adapter.js +1 -1
  87. package/dist/kernel/database/migrate.d.ts +0 -4
  88. package/dist/kernel/database/migrate.d.ts.map +1 -1
  89. package/dist/kernel/database/migrate.js +2 -14
  90. package/dist/kernel/database/pglite-transaction.d.ts +28 -0
  91. package/dist/kernel/database/pglite-transaction.d.ts.map +1 -0
  92. package/dist/kernel/database/pglite-transaction.js +52 -0
  93. package/dist/kernel/database/tx-context.d.ts +0 -1
  94. package/dist/kernel/database/tx-context.d.ts.map +1 -1
  95. package/dist/kernel/database/tx-context.js +2 -14
  96. package/dist/kernel/database/unique-violation.d.ts +3 -0
  97. package/dist/kernel/database/unique-violation.d.ts.map +1 -0
  98. package/dist/kernel/database/unique-violation.js +9 -0
  99. package/dist/kernel/error-mapper.d.ts.map +1 -1
  100. package/dist/kernel/error-mapper.js +1 -0
  101. package/dist/kernel/errors.d.ts +12 -0
  102. package/dist/kernel/errors.d.ts.map +1 -1
  103. package/dist/kernel/errors.js +16 -0
  104. package/dist/kernel/hooks/create-context.d.ts +18 -9
  105. package/dist/kernel/hooks/create-context.d.ts.map +1 -1
  106. package/dist/kernel/hooks/create-context.js +24 -3
  107. package/dist/kernel/hooks/registry.d.ts +0 -19
  108. package/dist/kernel/hooks/registry.d.ts.map +1 -1
  109. package/dist/kernel/hooks/registry.js +0 -32
  110. package/dist/kernel/jobs/drizzle-adapter.d.ts.map +1 -1
  111. package/dist/kernel/jobs/drizzle-adapter.js +3 -10
  112. package/dist/kernel/jobs/prepare-enqueue.d.ts +20 -0
  113. package/dist/kernel/jobs/prepare-enqueue.d.ts.map +1 -0
  114. package/dist/kernel/jobs/prepare-enqueue.js +24 -0
  115. package/dist/kernel/jobs/types.d.ts +0 -4
  116. package/dist/kernel/jobs/types.d.ts.map +1 -1
  117. package/dist/kernel/jobs/types.js +0 -4
  118. package/dist/kernel/local-api.d.ts +0 -33
  119. package/dist/kernel/local-api.d.ts.map +1 -1
  120. package/dist/kernel/local-api.js +0 -36
  121. package/dist/kernel/plugin/manifest.d.ts +3 -5
  122. package/dist/kernel/plugin/manifest.d.ts.map +1 -1
  123. package/dist/modules/analytics/service.d.ts +0 -6
  124. package/dist/modules/analytics/service.d.ts.map +1 -1
  125. package/dist/modules/analytics/service.js +0 -32
  126. package/dist/modules/cart/service.d.ts.map +1 -1
  127. package/dist/modules/cart/service.js +5 -17
  128. package/dist/modules/catalog/entity-service.d.ts.map +1 -1
  129. package/dist/modules/catalog/entity-service.js +9 -17
  130. package/dist/modules/catalog/import-service.d.ts.map +1 -1
  131. package/dist/modules/catalog/import-service.js +4 -13
  132. package/dist/modules/catalog/service.d.ts +1 -81
  133. package/dist/modules/catalog/service.d.ts.map +1 -1
  134. package/dist/modules/catalog/service.js +1 -8
  135. package/dist/modules/customers/service.d.ts.map +1 -1
  136. package/dist/modules/customers/service.js +5 -17
  137. package/dist/modules/documents/render.d.ts +0 -3
  138. package/dist/modules/documents/render.d.ts.map +1 -1
  139. package/dist/modules/documents/render.js +2 -17
  140. package/dist/modules/fulfillment/service.d.ts.map +1 -1
  141. package/dist/modules/fulfillment/service.js +8 -26
  142. package/dist/modules/inventory/service.d.ts.map +1 -1
  143. package/dist/modules/inventory/service.js +3 -20
  144. package/dist/modules/media/service.d.ts.map +1 -1
  145. package/dist/modules/media/service.js +2 -10
  146. package/dist/modules/orders/quote.d.ts.map +1 -1
  147. package/dist/modules/orders/quote.js +1 -2
  148. package/dist/modules/orders/service.d.ts.map +1 -1
  149. package/dist/modules/orders/service.js +4 -17
  150. package/dist/modules/pricing/service.d.ts.map +1 -1
  151. package/dist/modules/pricing/service.js +7 -18
  152. package/dist/modules/promotions/service.d.ts.map +1 -1
  153. package/dist/modules/promotions/service.js +4 -16
  154. package/dist/modules/tax/service.d.ts +1 -3
  155. package/dist/modules/tax/service.d.ts.map +1 -1
  156. package/dist/modules/tax/service.js +16 -52
  157. package/dist/modules/webhooks/hook.d.ts.map +1 -1
  158. package/dist/modules/webhooks/hook.js +3 -2
  159. package/dist/modules/webhooks/service.d.ts.map +1 -1
  160. package/dist/modules/webhooks/service.js +1 -50
  161. package/dist/runtime/commerce.d.ts.map +1 -1
  162. package/dist/runtime/commerce.js +4 -11
  163. package/dist/runtime/kernel-modules.d.ts +38 -1799
  164. package/dist/runtime/kernel-modules.d.ts.map +1 -1
  165. package/dist/runtime/kernel-modules.js +160 -66
  166. package/dist/runtime/kernel-types.d.ts +3 -15
  167. package/dist/runtime/kernel-types.d.ts.map +1 -1
  168. package/dist/runtime/kernel-types.js +0 -10
  169. package/dist/runtime/kernel.d.ts +2 -3
  170. package/dist/runtime/kernel.d.ts.map +1 -1
  171. package/dist/runtime/kernel.js +10 -51
  172. package/dist/runtime/server.d.ts +1 -1
  173. package/dist/runtime/server.d.ts.map +1 -1
  174. package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
  175. package/dist/test-utils/create-pglite-adapter.js +5 -62
  176. package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -1
  177. package/dist/test-utils/create-plugin-test-app.js +13 -32
  178. package/dist/test-utils/rest-api-test-utils.d.ts +0 -12
  179. package/dist/test-utils/rest-api-test-utils.d.ts.map +1 -1
  180. package/dist/test-utils/rest-api-test-utils.js +3 -70
  181. package/dist/test-utils/test-actors.d.ts +9 -0
  182. package/dist/test-utils/test-actors.d.ts.map +1 -1
  183. package/dist/test-utils/test-actors.js +62 -0
  184. package/dist/testing.d.ts +1 -4
  185. package/dist/testing.d.ts.map +1 -1
  186. package/dist/testing.js +1 -4
  187. package/dist/utils/escape-html.d.ts +3 -0
  188. package/dist/utils/escape-html.d.ts.map +1 -0
  189. package/dist/utils/escape-html.js +9 -0
  190. package/dist/utils/id.d.ts +0 -1
  191. package/dist/utils/id.d.ts.map +1 -1
  192. package/dist/utils/id.js +0 -3
  193. package/dist/utils/logger.d.ts +1 -1
  194. package/dist/utils/logger.d.ts.map +1 -1
  195. package/dist/utils/logger.js +1 -1
  196. package/dist/utils/money.d.ts +13 -0
  197. package/dist/utils/money.d.ts.map +1 -0
  198. package/dist/utils/money.js +58 -0
  199. package/package.json +5 -6
  200. package/src/adapters/email-render.ts +63 -0
  201. package/src/auth/actor.ts +14 -0
  202. package/src/auth/auth-failure.ts +0 -5
  203. package/src/auth/middleware.ts +7 -6
  204. package/src/auth/permissions.ts +12 -6
  205. package/src/auth/role-authority.ts +1 -10
  206. package/src/auth/setup.ts +8 -0
  207. package/src/auth/strict-org-resolution.ts +9 -16
  208. package/src/auth/system-actor.ts +3 -3
  209. package/src/config/defaults.ts +3 -20
  210. package/src/config/define-config.ts +5 -4
  211. package/src/config/types.ts +2 -2
  212. package/src/hooks/checkout.ts +2 -86
  213. package/src/index.ts +9 -36
  214. package/src/interfaces/rest/router.ts +3 -3
  215. package/src/interfaces/rest/routes/admin/compensation-failures.ts +5 -5
  216. package/src/interfaces/rest/routes/admin/entity-field-definitions.ts +5 -5
  217. package/src/interfaces/rest/routes/admin/staff.ts +2 -3
  218. package/src/interfaces/rest/routes/analytics.ts +2 -2
  219. package/src/interfaces/rest/routes/carts.ts +12 -12
  220. package/src/interfaces/rest/routes/catalog.ts +37 -37
  221. package/src/interfaces/rest/routes/checkout.ts +8 -10
  222. package/src/interfaces/rest/routes/customers.ts +12 -12
  223. package/src/interfaces/rest/routes/documents.ts +9 -9
  224. package/src/interfaces/rest/routes/inventory.ts +8 -8
  225. package/src/interfaces/rest/routes/media.ts +5 -5
  226. package/src/interfaces/rest/routes/orders.ts +32 -32
  227. package/src/interfaces/rest/routes/payments.ts +2 -2
  228. package/src/interfaces/rest/routes/pricing.ts +8 -8
  229. package/src/interfaces/rest/routes/promotions.ts +7 -7
  230. package/src/interfaces/rest/routes/search.ts +3 -3
  231. package/src/interfaces/rest/routes/settings.ts +4 -4
  232. package/src/interfaces/rest/routes/shipping.ts +9 -9
  233. package/src/interfaces/rest/routes/tax.ts +9 -9
  234. package/src/interfaces/rest/routes/webhooks.ts +4 -4
  235. package/src/interfaces/rest/utils.ts +4 -14
  236. package/src/jobs.ts +2 -1
  237. package/src/kernel/database/adapter.ts +1 -1
  238. package/src/kernel/database/migrate.ts +2 -17
  239. package/src/kernel/database/pglite-transaction.ts +61 -0
  240. package/src/kernel/database/tx-context.ts +2 -20
  241. package/src/kernel/database/unique-violation.ts +7 -0
  242. package/src/kernel/error-mapper.ts +1 -0
  243. package/src/kernel/errors.ts +18 -0
  244. package/src/kernel/hooks/create-context.ts +38 -8
  245. package/src/kernel/hooks/registry.ts +0 -37
  246. package/src/kernel/jobs/drizzle-adapter.ts +4 -15
  247. package/src/kernel/jobs/prepare-enqueue.ts +42 -0
  248. package/src/kernel/jobs/types.ts +0 -5
  249. package/src/kernel/local-api.ts +0 -44
  250. package/src/kernel/plugin/manifest.ts +3 -5
  251. package/src/modules/analytics/service.ts +0 -36
  252. package/src/modules/cart/service.ts +6 -29
  253. package/src/modules/catalog/entity-service.ts +9 -19
  254. package/src/modules/catalog/import-service.ts +4 -11
  255. package/src/modules/catalog/service.ts +2 -286
  256. package/src/modules/customers/service.ts +6 -27
  257. package/src/modules/documents/render.ts +2 -19
  258. package/src/modules/fulfillment/service.ts +8 -27
  259. package/src/modules/inventory/service.ts +3 -21
  260. package/src/modules/media/service.ts +2 -8
  261. package/src/modules/orders/quote.ts +1 -2
  262. package/src/modules/orders/service.ts +5 -30
  263. package/src/modules/pricing/service.ts +12 -30
  264. package/src/modules/promotions/service.ts +5 -28
  265. package/src/modules/tax/service.ts +20 -48
  266. package/src/modules/webhooks/hook.ts +3 -2
  267. package/src/modules/webhooks/service.ts +1 -42
  268. package/src/runtime/commerce.ts +4 -11
  269. package/src/runtime/kernel-modules.ts +191 -67
  270. package/src/runtime/kernel-types.ts +3 -26
  271. package/src/runtime/kernel.ts +11 -66
  272. package/src/runtime/server.ts +1 -3
  273. package/src/test-utils/create-pglite-adapter.ts +5 -67
  274. package/src/test-utils/create-plugin-test-app.ts +13 -52
  275. package/src/test-utils/rest-api-test-utils.ts +3 -70
  276. package/src/test-utils/test-actors.ts +66 -0
  277. package/src/testing.ts +1 -3
  278. package/src/utils/escape-html.ts +9 -0
  279. package/src/utils/id.ts +0 -4
  280. package/src/utils/logger.ts +1 -1
  281. package/src/utils/money.ts +62 -0
  282. package/dist/auth/access.d.ts +0 -101
  283. package/dist/auth/access.d.ts.map +0 -1
  284. package/dist/auth/access.js +0 -128
  285. package/dist/generated/plugin-manifest.d.ts +0 -51
  286. package/dist/generated/plugin-manifest.d.ts.map +0 -1
  287. package/dist/generated/plugin-manifest.js +0 -21
  288. package/dist/kernel/factory/repository-factory.d.ts +0 -71
  289. package/dist/kernel/factory/repository-factory.d.ts.map +0 -1
  290. package/dist/kernel/factory/repository-factory.js +0 -138
  291. package/dist/kernel/http-error.d.ts +0 -30
  292. package/dist/kernel/http-error.d.ts.map +0 -1
  293. package/dist/kernel/http-error.js +0 -35
  294. package/dist/kernel/jobs/builtin-job-tasks.d.ts +0 -3
  295. package/dist/kernel/jobs/builtin-job-tasks.d.ts.map +0 -1
  296. package/dist/kernel/jobs/builtin-job-tasks.js +0 -6
  297. package/dist/kernel/module/define.d.ts +0 -21
  298. package/dist/kernel/module/define.d.ts.map +0 -1
  299. package/dist/kernel/module/define.js +0 -3
  300. package/dist/kernel/module/index.d.ts +0 -4
  301. package/dist/kernel/module/index.d.ts.map +0 -1
  302. package/dist/kernel/module/index.js +0 -2
  303. package/dist/kernel/module/topo-sort.d.ts +0 -7
  304. package/dist/kernel/module/topo-sort.d.ts.map +0 -1
  305. package/dist/kernel/module/topo-sort.js +0 -89
  306. package/dist/kernel/query/executor.d.ts +0 -21
  307. package/dist/kernel/query/executor.d.ts.map +0 -1
  308. package/dist/kernel/query/executor.js +0 -128
  309. package/dist/kernel/query/registry.d.ts +0 -33
  310. package/dist/kernel/query/registry.d.ts.map +0 -1
  311. package/dist/kernel/query/registry.js +0 -20
  312. package/dist/kernel/service-registry.d.ts +0 -109
  313. package/dist/kernel/service-registry.d.ts.map +0 -1
  314. package/dist/kernel/service-registry.js +0 -26
  315. package/dist/modules/analytics/hooks.d.ts +0 -13
  316. package/dist/modules/analytics/hooks.d.ts.map +0 -1
  317. package/dist/modules/analytics/hooks.js +0 -12
  318. package/dist/modules/analytics/module.d.ts +0 -3
  319. package/dist/modules/analytics/module.d.ts.map +0 -1
  320. package/dist/modules/analytics/module.js +0 -24
  321. package/dist/modules/analytics/repository/index.d.ts +0 -5
  322. package/dist/modules/analytics/repository/index.d.ts.map +0 -1
  323. package/dist/modules/analytics/repository/index.js +0 -1
  324. package/dist/modules/audit/index.d.ts +0 -2
  325. package/dist/modules/audit/index.d.ts.map +0 -1
  326. package/dist/modules/audit/index.js +0 -1
  327. package/dist/modules/audit/module.d.ts +0 -180
  328. package/dist/modules/audit/module.d.ts.map +0 -1
  329. package/dist/modules/audit/module.js +0 -8
  330. package/dist/modules/cart/access.d.ts +0 -11
  331. package/dist/modules/cart/access.d.ts.map +0 -1
  332. package/dist/modules/cart/access.js +0 -18
  333. package/dist/modules/cart/module.d.ts +0 -14
  334. package/dist/modules/cart/module.d.ts.map +0 -1
  335. package/dist/modules/cart/module.js +0 -17
  336. package/dist/modules/catalog/module.d.ts +0 -26
  337. package/dist/modules/catalog/module.d.ts.map +0 -1
  338. package/dist/modules/catalog/module.js +0 -33
  339. package/dist/modules/customers/index.d.ts +0 -2
  340. package/dist/modules/customers/index.d.ts.map +0 -1
  341. package/dist/modules/customers/index.js +0 -1
  342. package/dist/modules/customers/module.d.ts +0 -563
  343. package/dist/modules/customers/module.d.ts.map +0 -1
  344. package/dist/modules/customers/module.js +0 -20
  345. package/dist/modules/documents/module.d.ts +0 -7
  346. package/dist/modules/documents/module.d.ts.map +0 -1
  347. package/dist/modules/documents/module.js +0 -13
  348. package/dist/modules/fulfillment/module.d.ts +0 -13
  349. package/dist/modules/fulfillment/module.d.ts.map +0 -1
  350. package/dist/modules/fulfillment/module.js +0 -23
  351. package/dist/modules/inventory/module.d.ts +0 -13
  352. package/dist/modules/inventory/module.d.ts.map +0 -1
  353. package/dist/modules/inventory/module.js +0 -20
  354. package/dist/modules/media/index.d.ts +0 -2
  355. package/dist/modules/media/index.d.ts.map +0 -1
  356. package/dist/modules/media/index.js +0 -1
  357. package/dist/modules/media/module.d.ts +0 -360
  358. package/dist/modules/media/module.d.ts.map +0 -1
  359. package/dist/modules/media/module.js +0 -24
  360. package/dist/modules/orders/module.d.ts +0 -25
  361. package/dist/modules/orders/module.d.ts.map +0 -1
  362. package/dist/modules/orders/module.js +0 -33
  363. package/dist/modules/organization/index.d.ts +0 -2
  364. package/dist/modules/organization/index.d.ts.map +0 -1
  365. package/dist/modules/organization/index.js +0 -1
  366. package/dist/modules/organization/module.d.ts +0 -205
  367. package/dist/modules/organization/module.d.ts.map +0 -1
  368. package/dist/modules/organization/module.js +0 -8
  369. package/dist/modules/payments/module.d.ts +0 -3
  370. package/dist/modules/payments/module.d.ts.map +0 -1
  371. package/dist/modules/payments/module.js +0 -7
  372. package/dist/modules/payments/repository/index.d.ts +0 -5
  373. package/dist/modules/payments/repository/index.d.ts.map +0 -1
  374. package/dist/modules/payments/repository/index.js +0 -1
  375. package/dist/modules/pricing/index.d.ts +0 -2
  376. package/dist/modules/pricing/index.d.ts.map +0 -1
  377. package/dist/modules/pricing/index.js +0 -1
  378. package/dist/modules/pricing/module.d.ts +0 -14
  379. package/dist/modules/pricing/module.d.ts.map +0 -1
  380. package/dist/modules/pricing/module.js +0 -17
  381. package/dist/modules/promotions/module.d.ts +0 -14
  382. package/dist/modules/promotions/module.d.ts.map +0 -1
  383. package/dist/modules/promotions/module.js +0 -19
  384. package/dist/modules/search/module.d.ts +0 -8
  385. package/dist/modules/search/module.d.ts.map +0 -1
  386. package/dist/modules/search/module.js +0 -22
  387. package/dist/modules/search/repository/index.d.ts +0 -5
  388. package/dist/modules/search/repository/index.d.ts.map +0 -1
  389. package/dist/modules/search/repository/index.js +0 -1
  390. package/dist/modules/settings/module.d.ts +0 -6
  391. package/dist/modules/settings/module.d.ts.map +0 -1
  392. package/dist/modules/settings/module.js +0 -12
  393. package/dist/modules/shipping/module.d.ts +0 -12
  394. package/dist/modules/shipping/module.d.ts.map +0 -1
  395. package/dist/modules/shipping/module.js +0 -14
  396. package/dist/modules/tax/module.d.ts +0 -7
  397. package/dist/modules/tax/module.d.ts.map +0 -1
  398. package/dist/modules/tax/module.js +0 -13
  399. package/dist/modules/webhooks/index.d.ts +0 -2
  400. package/dist/modules/webhooks/index.d.ts.map +0 -1
  401. package/dist/modules/webhooks/index.js +0 -1
  402. package/dist/modules/webhooks/module.d.ts +0 -403
  403. package/dist/modules/webhooks/module.d.ts.map +0 -1
  404. package/dist/modules/webhooks/module.js +0 -16
  405. package/dist/test-utils/create-repository-test-harness.d.ts +0 -8
  406. package/dist/test-utils/create-repository-test-harness.d.ts.map +0 -1
  407. package/dist/test-utils/create-repository-test-harness.js +0 -7
  408. package/dist/test-utils/create-test-plugin-context.d.ts +0 -38
  409. package/dist/test-utils/create-test-plugin-context.d.ts.map +0 -1
  410. package/dist/test-utils/create-test-plugin-context.js +0 -39
  411. package/dist/test-utils/typed-hooks.d.ts +0 -44
  412. package/dist/test-utils/typed-hooks.d.ts.map +0 -1
  413. package/dist/test-utils/typed-hooks.js +0 -36
  414. package/dist/types/commerce-types.d.ts +0 -34
  415. package/dist/types/commerce-types.d.ts.map +0 -1
  416. package/dist/types/commerce-types.js +0 -1
  417. package/src/auth/access.ts +0 -187
  418. package/src/generated/plugin-capabilities.d.ts +0 -21
  419. package/src/generated/plugin-manifest.ts +0 -24
  420. package/src/generated/plugin-repositories.d.ts +0 -21
  421. package/src/kernel/factory/repository-factory.ts +0 -244
  422. package/src/kernel/http-error.ts +0 -44
  423. package/src/kernel/jobs/builtin-job-tasks.ts +0 -17
  424. package/src/kernel/module/define.ts +0 -36
  425. package/src/kernel/module/index.ts +0 -3
  426. package/src/kernel/module/topo-sort.ts +0 -99
  427. package/src/kernel/query/executor.ts +0 -184
  428. package/src/kernel/query/registry.ts +0 -46
  429. package/src/kernel/service-registry.ts +0 -76
  430. package/src/modules/analytics/hooks.ts +0 -11
  431. package/src/modules/analytics/module.ts +0 -35
  432. package/src/modules/analytics/repository/index.ts +0 -5
  433. package/src/modules/audit/index.ts +0 -1
  434. package/src/modules/audit/module.ts +0 -11
  435. package/src/modules/cart/access.ts +0 -27
  436. package/src/modules/cart/module.ts +0 -32
  437. package/src/modules/catalog/module.ts +0 -80
  438. package/src/modules/customers/index.ts +0 -1
  439. package/src/modules/customers/module.ts +0 -29
  440. package/src/modules/documents/module.ts +0 -21
  441. package/src/modules/fulfillment/module.ts +0 -44
  442. package/src/modules/inventory/module.ts +0 -37
  443. package/src/modules/media/index.ts +0 -1
  444. package/src/modules/media/module.ts +0 -27
  445. package/src/modules/orders/module.ts +0 -67
  446. package/src/modules/organization/index.ts +0 -1
  447. package/src/modules/organization/module.ts +0 -11
  448. package/src/modules/payments/module.ts +0 -14
  449. package/src/modules/payments/repository/index.ts +0 -5
  450. package/src/modules/pricing/index.ts +0 -1
  451. package/src/modules/pricing/module.ts +0 -32
  452. package/src/modules/promotions/module.ts +0 -34
  453. package/src/modules/search/module.ts +0 -32
  454. package/src/modules/search/repository/index.ts +0 -5
  455. package/src/modules/settings/module.ts +0 -20
  456. package/src/modules/shipping/module.ts +0 -27
  457. package/src/modules/tax/module.ts +0 -21
  458. package/src/modules/webhooks/index.ts +0 -1
  459. package/src/modules/webhooks/module.ts +0 -24
  460. package/src/test-utils/create-repository-test-harness.ts +0 -16
  461. package/src/test-utils/create-test-plugin-context.ts +0 -66
  462. package/src/test-utils/typed-hooks.ts +0 -55
  463. package/src/types/commerce-types.ts +0 -34
@@ -18,29 +18,20 @@
18
18
  */
19
19
 
20
20
  import { OpenAPIHono } from "@hono/zod-openapi";
21
- import { createRequire } from "node:module";
22
21
  import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
23
22
  import type { CommerceConfig, CommercePlugin } from "../config/types.js";
24
23
  import type { Actor } from "../auth/types.js";
25
24
  import { createTestConfig } from "./create-test-config.js";
26
25
  import { createKernel } from "../runtime/kernel.js";
27
26
  import type { Kernel } from "../runtime/kernel.js";
28
- import { buildSchema } from "../kernel/database/migrate.js";
29
- import { unwrapDb } from "../kernel/database/adapter.js";
27
+ import { pushSchema } from "../kernel/database/migrate.js";
30
28
  import { ensureDefaultOrg } from "../auth/org.js";
31
- import { mapErrorToStatus } from "../kernel/error-mapper.js";
29
+ import { mapErrorToResponse } from "../kernel/error-mapper.js";
30
+ import { buildConfigRoutesKernel } from "../kernel/plugin/manifest.js";
32
31
  import { createAuth, type AuthInstance } from "../auth/setup.js";
33
32
  import { authMiddleware } from "../auth/middleware.js";
34
33
 
35
- // drizzle-kit/api uses CJS internally; createRequire provides ESM compat.
36
- const require = createRequire(import.meta.url);
37
34
 
38
- type DrizzleKitPushResult = {
39
- hasDataLoss: boolean;
40
- warnings: string[];
41
- statementsToExecute: string[];
42
- apply: () => Promise<void>;
43
- };
44
35
 
45
36
  /**
46
37
  * Hono environment type for the test app. Declares the `actor` context
@@ -84,24 +75,9 @@ export async function createPluginTestApp(
84
75
  // 2. Boot kernel (creates core services, hook registry)
85
76
  const kernel = createKernel(config);
86
77
 
87
- // 3. Merge core + plugin schemas
88
- const mergedSchema = buildSchema(config);
89
-
90
- // 4. Programmatic schema push via drizzle-kit/api
91
- // Diffs current DB state against pgTable definitions, generates DDL, applies it.
92
- // On fresh PGlite: creates all tables. On existing DB: creates only missing tables.
93
- const drizzleKit = require("drizzle-kit/api") as {
94
- pushSchema(
95
- imports: Record<string, unknown>,
96
- drizzleInstance: PgDatabase<PgQueryResultHKT>,
97
- ): Promise<DrizzleKitPushResult>;
98
- };
99
- const { apply } = await drizzleKit.pushSchema(
100
- mergedSchema,
101
- // drizzle-kit needs the native driver result shape; unwrap the normalized db.
102
- unwrapDb(kernel.database.db) as PgDatabase<PgQueryResultHKT>,
103
- );
104
- await apply();
78
+ // 3. Create core + plugin tables (drizzle-kit diffs the live database and
79
+ // applies only the missing DDL).
80
+ await pushSchema(kernel.database.db, config);
105
81
 
106
82
  // Ensure the default organization exists for plugin tests
107
83
  await ensureDefaultOrg(kernel.database.db);
@@ -128,33 +104,18 @@ export async function createPluginTestApp(
128
104
  return authMiddleware(auth, config)(c as never, next);
129
105
  });
130
106
 
131
- // 7. Register plugin routes (deferred via config.routes) — with the auth
132
- // instance, matching server.ts's config.routes(app, kernel, auth).
107
+ // 7. Register plugin routes (deferred via config.routes) exactly as
108
+ // server.ts does: with the tenant-scoped route kernel and the auth instance.
133
109
  const routes = config.routes as
134
110
  | ((app: unknown, kernel: unknown, auth?: unknown) => void)
135
111
  | undefined;
136
- routes?.(app, kernel, auth);
112
+ routes?.(app, buildConfigRoutesKernel(kernel), auth);
137
113
 
138
- // 8. Error handler matching production server.ts — maps CommerceError
139
- // subclasses (CommerceForbiddenError, CommerceNotFoundError, etc.)
140
- // to their proper HTTP status codes (403, 404, 409, 422, 503).
141
- // Without this, route handlers that throw assertPermission() etc.
142
- // surface as 500 in tests, masking real status assertions.
114
+ // 8. The production error handler: CommerceError subclasses map to their
115
+ // status (403, 404, 409, 422, 503) instead of surfacing as 500.
143
116
  app.onError((err, c) => {
144
- if (err instanceof Error && "code" in err && typeof (err as { code?: unknown }).code === "string") {
145
- const status = mapErrorToStatus(err);
146
- if (status !== 500) {
147
- const errorCode = (err as { code: string }).code;
148
- return c.json(
149
- { error: { code: errorCode, message: err.message } },
150
- status,
151
- );
152
- }
153
- }
154
- return c.json(
155
- { error: { code: "INTERNAL_ERROR", message: err.message } },
156
- 500,
157
- );
117
+ const { body, status } = mapErrorToResponse(err, false);
118
+ return c.json(body, status);
158
119
  });
159
120
 
160
121
  return {
@@ -16,6 +16,7 @@ import { Ok, Err } from "../kernel/result.js";
16
16
  import type { CommerceConfig } from "../config/types.js";
17
17
  import type { Actor } from "../auth/types.js";
18
18
  import type { AuthInstance } from "../auth/setup.js";
19
+ import { testActor } from "./test-actors.js";
19
20
 
20
21
  type ServerEnv = {
21
22
  Variables: {
@@ -122,9 +123,9 @@ export async function createTestServer(
122
123
  await next();
123
124
  } catch (error) {
124
125
  // Import error handling utilities
125
- const { mapErrorToResponse, mapErrorToStatus } = await import("../interfaces/rest/utils.js");
126
+ const { errorBody, mapErrorToStatus } = await import("../interfaces/rest/utils.js");
126
127
  return c.json(
127
- mapErrorToResponse(error),
128
+ errorBody(error),
128
129
  mapErrorToStatus(error),
129
130
  );
130
131
  }
@@ -143,76 +144,8 @@ export async function parseJsonResponse<T = unknown>(response: Response): Promis
143
144
  return response.json() as Promise<T>;
144
145
  }
145
146
 
146
- /**
147
- * Common test actor with staff permissions
148
- */
149
- export const testActor: Actor = {
150
- type: "user",
151
- userId: "00000000-0000-0000-0000-000000000001",
152
- email: "test@example.com",
153
- name: "Test Staff",
154
- vendorId: null,
155
- organizationId: "org_default",
156
- role: "staff",
157
- permissions: [
158
- "catalog:create",
159
- "catalog:update",
160
- "catalog:read",
161
- "catalog:read:unpublished",
162
- "inventory:adjust",
163
- "inventory:read",
164
- "orders:create",
165
- "orders:create:on-behalf",
166
- "orders:read",
167
- "orders:update",
168
- "orders:manage",
169
- "cart:create",
170
- "cart:update",
171
- "cart:read",
172
- "cart:manage",
173
- "customers:update:self",
174
- "webhooks:manage",
175
- "pricing:manage",
176
- "shipping:manage",
177
- "tax:manage",
178
- "settings:manage",
179
- "analytics:read",
180
- "staff:manage",
181
- "promotions:manage",
182
- "promotions:read",
183
- "audit:read",
184
- "media:write",
185
- "compensation:admin",
186
- ],
187
- };
188
147
 
189
- /**
190
- * Test actor with read-only permissions
191
- */
192
- export const readonlyActor: Actor = {
193
- type: "user",
194
- userId: "00000000-0000-0000-0000-000000000002",
195
- email: "readonly@example.com",
196
- name: "Read Only User",
197
- vendorId: null,
198
- organizationId: "org_default",
199
- role: "customer",
200
- permissions: ["catalog:read", "cart:read", "orders:read:own"],
201
- };
202
148
 
203
- /**
204
- * Test actor with no permissions
205
- */
206
- export const noPermActor: Actor = {
207
- type: "user",
208
- userId: "00000000-0000-0000-0000-000000000003",
209
- email: "noperm@example.com",
210
- name: "No Perm",
211
- vendorId: null,
212
- organizationId: "org_default",
213
- role: "customer",
214
- permissions: [],
215
- };
216
149
 
217
150
  /**
218
151
  * Helper to create a mock request with actor context
@@ -9,6 +9,72 @@ import { DEFAULT_ORG_ID } from "../auth/org.js";
9
9
  */
10
10
  export const TEST_ORG_ID = DEFAULT_ORG_ID;
11
11
 
12
+ /**
13
+ * A test actor in {@link TEST_ORG_ID}. Pass only what the test is about —
14
+ * usually `permissions` (and `role`); everything else has a stable default.
15
+ */
16
+ export function createTestActor(overrides: Partial<Actor> = {}): Actor {
17
+ return {
18
+ type: "user",
19
+ userId: "test-user-1",
20
+ email: "user@test.local",
21
+ name: "Test User",
22
+ vendorId: null,
23
+ organizationId: TEST_ORG_ID,
24
+ role: "staff",
25
+ permissions: [],
26
+ ...overrides,
27
+ };
28
+ }
29
+
30
+ /** Staff with the permissions the REST suites exercise. */
31
+ export const testActor: Actor = createTestActor({
32
+ userId: "00000000-0000-0000-0000-000000000001",
33
+ email: "test@example.com",
34
+ name: "Test Staff",
35
+ role: "staff",
36
+ permissions: [
37
+ "catalog:create",
38
+ "catalog:update",
39
+ "catalog:read",
40
+ "catalog:read:unpublished",
41
+ "inventory:adjust",
42
+ "inventory:read",
43
+ "orders:create",
44
+ "orders:create:on-behalf",
45
+ "orders:read",
46
+ "orders:update",
47
+ "orders:manage",
48
+ "cart:create",
49
+ "cart:update",
50
+ "cart:read",
51
+ "cart:manage",
52
+ "customers:update:self",
53
+ "webhooks:manage",
54
+ "pricing:manage",
55
+ "shipping:manage",
56
+ "tax:manage",
57
+ "settings:manage",
58
+ "analytics:read",
59
+ "staff:manage",
60
+ "promotions:manage",
61
+ "promotions:read",
62
+ "audit:read",
63
+ "media:write",
64
+ "compensation:admin",
65
+ ],
66
+ });
67
+
68
+ /** Read-only shopper: browses and reads its own orders, cannot create a cart. */
69
+ export const readonlyActor: Actor = createTestActor({
70
+ userId: "00000000-0000-0000-0000-000000000002",
71
+ email: "readonly@example.com",
72
+ name: "Read Only User",
73
+ role: "customer",
74
+ permissions: ["catalog:read", "cart:read", "orders:read:own"],
75
+
76
+ });
77
+
12
78
  /** Admin with wildcard permissions. Use for setup operations in beforeAll. */
13
79
  export const testAdminActor: Actor = {
14
80
  type: "user",
package/src/testing.ts CHANGED
@@ -10,15 +10,13 @@ export { createTestKernel } from "./test-utils/create-test-kernel.js";
10
10
  // The query log is the only honest statement counter: the PGlite logger sees every statement core
11
11
  // issues, which a proxy around a plugin's own handle cannot.
12
12
  export { createPGliteTestAdapter, type PGliteTestAdapter, type QueryLog } from "./test-utils/create-pglite-adapter.js";
13
- export { createTestPluginContext } from "./test-utils/create-test-plugin-context.js";
14
- export { createRepositoryTestHarness } from "./test-utils/create-repository-test-harness.js";
15
13
  export { createPluginTestApp, type PluginTestApp, type TestAppEnv } from "./test-utils/create-plugin-test-app.js";
16
14
  export {
17
15
  TEST_ORG_ID,
16
+ createTestActor,
18
17
  testAdminActor, testStaffActor, testCustomerActor, testNoPermActor,
19
18
  jsonHeaders,
20
19
  } from "./test-utils/test-actors.js";
21
- export { beforeHook, afterHook } from "./test-utils/typed-hooks.js";
22
20
  export { markOrderPaidForTest } from "./test-utils/order-test-helpers.js";
23
21
 
24
22
  // The after-commit boundary predicate, so a suite can assert that the code under test really is
@@ -0,0 +1,9 @@
1
+ /** Escape a value for interpolation into HTML text or a quoted attribute. */
2
+ export function escapeHtml(value: unknown): string {
3
+ return String(value ?? "")
4
+ .replaceAll("&", "&amp;")
5
+ .replaceAll("<", "&lt;")
6
+ .replaceAll(">", "&gt;")
7
+ .replaceAll('"', "&quot;")
8
+ .replaceAll("'", "&#39;");
9
+ }
package/src/utils/id.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  import type { Actor } from "../auth/types.js";
2
2
 
3
- export function makeId(): string {
4
- return crypto.randomUUID();
5
- }
6
-
7
3
  export async function makeDeterministicId(value: string): Promise<string> {
8
4
  const digest = new Uint8Array(
9
5
  await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)),
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from "../kernel/hooks/types.js";
2
2
 
3
- export function createLogger(scope: string): Logger {
3
+ export function createConsoleLogger(scope: string): Logger {
4
4
  return {
5
5
  info(message: string, data?: unknown) {
6
6
  // eslint-disable-next-line no-console
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Currencies whose minor unit IS the major unit (ISO 4217 exponent 0), so an
3
+ * amount of 1500 JPY is stored as 1500, not 150000.
4
+ *
5
+ * ponytail: zero- vs two-decimal only. Three-decimal currencies (KWD, BHD, OMR,
6
+ * JOD, TND) are treated as two-decimal everywhere in core; give them exponent 3
7
+ * here once pricing and documents are audited for it.
8
+ */
9
+ const ZERO_DECIMAL_CURRENCIES = new Set([
10
+ "BIF",
11
+ "CLP",
12
+ "DJF",
13
+ "GNF",
14
+ "ISK",
15
+ "JPY",
16
+ "KMF",
17
+ "KRW",
18
+ "PYG",
19
+ "RWF",
20
+ "UGX",
21
+ "VND",
22
+ "VUV",
23
+ "XAF",
24
+ "XOF",
25
+ "XPF",
26
+ ]);
27
+
28
+ /** Number of minor-unit digits for an ISO 4217 code: 0 for JPY, 2 for USD. */
29
+ export function currencyExponent(currency: string): number {
30
+ return ZERO_DECIMAL_CURRENCIES.has(currency.trim().toUpperCase()) ? 0 : 2;
31
+ }
32
+
33
+ /**
34
+ * A major-unit amount ("15.00", 15) as integer minor units in `currency`.
35
+ * Blank or non-numeric input answers `undefined` rather than 0, so a missing
36
+ * price is never mistaken for a free one.
37
+ */
38
+ export function toMinorUnits(
39
+ amount: string | number | null | undefined,
40
+ currency: string,
41
+ ): number | undefined {
42
+ if (amount == null) return undefined;
43
+ if (typeof amount === "string" && amount.trim() === "") return undefined;
44
+ const parsed = Number(amount);
45
+ if (!Number.isFinite(parsed)) return undefined;
46
+ return Math.round(parsed * 10 ** currencyExponent(currency));
47
+ }
48
+
49
+ /** Minor units → "1,234.50 LKR" (or "1,500 JPY"). */
50
+ export function formatAmount(minor: number, currency: string): string {
51
+ const exponent = currencyExponent(currency);
52
+ const formatted = (minor / 10 ** exponent).toLocaleString("en-US", {
53
+ minimumFractionDigits: exponent,
54
+ maximumFractionDigits: exponent,
55
+ });
56
+ return `${formatted} ${currency}`;
57
+ }
58
+
59
+ /** An ISO 4217 code as stored: trimmed and upper-cased. */
60
+ export function normalizeCurrency(currency: string): string {
61
+ return currency.trim().toUpperCase();
62
+ }
@@ -1,101 +0,0 @@
1
- import type { Actor } from "./types.js";
2
- /**
3
- * A WhereClause is a plain object representing database filter conditions.
4
- * The shape mirrors what services and repositories can accept to narrow queries.
5
- *
6
- * Example: { customerId: "abc-123" } narrows results to that customer's records.
7
- * Composite: { or: [{ customerId: "x" }, { organizationId: "y" }] }
8
- */
9
- export type WhereClause = Record<string, unknown>;
10
- /**
11
- * AccessResult: the return value of an access function.
12
- *
13
- * - `true`: full access, no filter needed
14
- * - `false`: no access at all
15
- * - `WhereClause`: partial access — the caller should apply this as a query filter
16
- */
17
- export type AccessResult = boolean | WhereClause;
18
- /**
19
- * AccessContext carries everything an access function needs to make a decision.
20
- *
21
- * - `actor`: the authenticated user/api-key/null (anonymous)
22
- * - `data`: the document being accessed (for document-level checks)
23
- * - `id`: the document ID (when data isn't loaded yet)
24
- */
25
- export interface AccessContext<TData = unknown> {
26
- actor: Actor | null;
27
- data?: TData;
28
- id?: string;
29
- req?: Request;
30
- }
31
- /**
32
- * An AccessFn evaluates access for a given context.
33
- * Returns boolean (full/no access) or WhereClause (filtered access).
34
- */
35
- export type AccessFn<TData = unknown> = (ctx: AccessContext<TData>) => AccessResult | Promise<AccessResult>;
36
- /**
37
- * Composes access functions with OR semantics.
38
- *
39
- * - If ANY function returns `true`, grants full access immediately (short-circuit).
40
- * - If one or more return WhereClause, combines them with OR.
41
- * - If ALL return `false`, denies access.
42
- *
43
- * Example:
44
- * ```typescript
45
- * const orderReadAccess = accessOR(isAdmin, isDocumentOwner("customerId"))
46
- * // Admins see all orders; customers see only their own
47
- * ```
48
- */
49
- export declare const accessOR: <TData = unknown>(...fns: Array<AccessFn<TData>>) => AccessFn<TData>;
50
- /**
51
- * Composes access functions with AND semantics.
52
- *
53
- * - If ANY function returns `false`, denies access immediately (short-circuit).
54
- * - If one or more return WhereClause, combines them with AND.
55
- * - If ALL return `true`, grants full access.
56
- *
57
- * Example:
58
- * ```typescript
59
- * const restrictedAccess = accessAND(isAuthenticated, isDocumentOwner("customerId"))
60
- * // Must be logged in AND own the document
61
- * ```
62
- */
63
- export declare const accessAND: <TData = unknown>(...fns: Array<AccessFn<TData>>) => AccessFn<TData>;
64
- /**
65
- * Switches between two access functions based on a condition.
66
- *
67
- * Example:
68
- * ```typescript
69
- * const accessByRole = conditional(
70
- * ({ actor }) => actor?.role === "vendor",
71
- * isDocumentOwner("vendorId"),
72
- * isAdmin,
73
- * )
74
- * ```
75
- */
76
- export declare const conditional: <TData = unknown>(condition: ((ctx: AccessContext<TData>) => boolean) | boolean, accessFn: AccessFn<TData>, fallback?: AccessFn<TData>) => AccessFn<TData>;
77
- /**
78
- * Grants access if the actor has admin or owner role (wildcard permissions).
79
- */
80
- export declare const isAdmin: AccessFn;
81
- /**
82
- * Grants access if the actor is authenticated (any role).
83
- */
84
- export declare const isAuthenticated: AccessFn;
85
- /**
86
- * Returns a WhereClause that filters to documents owned by the actor.
87
- * The ownerField is the column name that holds the owner's user ID.
88
- *
89
- * For document-level checks (when data is provided), returns true/false.
90
- * For list-level checks (when data is not provided), returns a WhereClause.
91
- */
92
- export declare const isDocumentOwner: (ownerField?: string) => AccessFn;
93
- /**
94
- * Grants access to everyone, including anonymous users.
95
- */
96
- export declare const publicAccess: AccessFn;
97
- /**
98
- * Denies access to everyone.
99
- */
100
- export declare const denyAll: AccessFn;
101
- //# sourceMappingURL=access.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/auth/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,GAAG,OAAO;IAC5C,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,GAAG,OAAO,IAAI,CACtC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KACtB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,GAAG,OAAO,EACtC,GAAG,KAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAC7B,QAAQ,CAAC,KAAK,CAWhB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,OAAO,EACvC,GAAG,KAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAC7B,QAAQ,CAAC,KAAK,CAahB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,OAAO,EACzC,WAAW,CAAC,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,GAAG,OAAO,EAC7D,UAAU,QAAQ,CAAC,KAAK,CAAC,EACzB,WAAU,QAAQ,CAAC,KAAK,CAAe,KACtC,QAAQ,CAAC,KAAK,CAMhB,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,QAGrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAE7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,mBAAyB,KACxB,QAYF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,QAAqB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,QAAsB,CAAC"}
@@ -1,128 +0,0 @@
1
- /**
2
- * Combines multiple WhereClause objects with a logical operator.
3
- * If there's only one clause, returns it directly (no unnecessary nesting).
4
- */
5
- function combineWhere(queries, operator) {
6
- if (queries.length === 1)
7
- return queries[0];
8
- return { [operator]: queries };
9
- }
10
- /**
11
- * Composes access functions with OR semantics.
12
- *
13
- * - If ANY function returns `true`, grants full access immediately (short-circuit).
14
- * - If one or more return WhereClause, combines them with OR.
15
- * - If ALL return `false`, denies access.
16
- *
17
- * Example:
18
- * ```typescript
19
- * const orderReadAccess = accessOR(isAdmin, isDocumentOwner("customerId"))
20
- * // Admins see all orders; customers see only their own
21
- * ```
22
- */
23
- export const accessOR = (...fns) => {
24
- return async (ctx) => {
25
- const queries = [];
26
- for (const fn of fns) {
27
- const result = await fn(ctx);
28
- if (result === true)
29
- return true;
30
- if (result && typeof result === "object")
31
- queries.push(result);
32
- }
33
- if (queries.length > 0)
34
- return combineWhere(queries, "or");
35
- return false;
36
- };
37
- };
38
- /**
39
- * Composes access functions with AND semantics.
40
- *
41
- * - If ANY function returns `false`, denies access immediately (short-circuit).
42
- * - If one or more return WhereClause, combines them with AND.
43
- * - If ALL return `true`, grants full access.
44
- *
45
- * Example:
46
- * ```typescript
47
- * const restrictedAccess = accessAND(isAuthenticated, isDocumentOwner("customerId"))
48
- * // Must be logged in AND own the document
49
- * ```
50
- */
51
- export const accessAND = (...fns) => {
52
- return async (ctx) => {
53
- const queries = [];
54
- for (const fn of fns) {
55
- const result = await fn(ctx);
56
- if (result === false)
57
- return false;
58
- if (result !== true && result && typeof result === "object") {
59
- queries.push(result);
60
- }
61
- }
62
- if (queries.length > 0)
63
- return combineWhere(queries, "and");
64
- return true;
65
- };
66
- };
67
- /**
68
- * Switches between two access functions based on a condition.
69
- *
70
- * Example:
71
- * ```typescript
72
- * const accessByRole = conditional(
73
- * ({ actor }) => actor?.role === "vendor",
74
- * isDocumentOwner("vendorId"),
75
- * isAdmin,
76
- * )
77
- * ```
78
- */
79
- export const conditional = (condition, accessFn, fallback = () => false) => {
80
- return async (ctx) => {
81
- const applies = typeof condition === "function" ? condition(ctx) : condition;
82
- return applies ? accessFn(ctx) : fallback(ctx);
83
- };
84
- };
85
- // ─────────────────────────────────────────────────────────────────────────────
86
- // Built-in access functions
87
- // ─────────────────────────────────────────────────────────────────────────────
88
- /**
89
- * Grants access if the actor has admin or owner role (wildcard permissions).
90
- */
91
- export const isAdmin = ({ actor }) => {
92
- if (!actor)
93
- return false;
94
- return actor.permissions.includes("*:*");
95
- };
96
- /**
97
- * Grants access if the actor is authenticated (any role).
98
- */
99
- export const isAuthenticated = ({ actor }) => {
100
- return actor != null;
101
- };
102
- /**
103
- * Returns a WhereClause that filters to documents owned by the actor.
104
- * The ownerField is the column name that holds the owner's user ID.
105
- *
106
- * For document-level checks (when data is provided), returns true/false.
107
- * For list-level checks (when data is not provided), returns a WhereClause.
108
- */
109
- export const isDocumentOwner = (ownerField = "customerId") => {
110
- return ({ actor, data }) => {
111
- if (!actor)
112
- return false;
113
- // Document-level check: compare directly
114
- if (data) {
115
- return data[ownerField] === actor.userId;
116
- }
117
- // List-level check: return a filter clause
118
- return { [ownerField]: actor.userId };
119
- };
120
- };
121
- /**
122
- * Grants access to everyone, including anonymous users.
123
- */
124
- export const publicAccess = () => true;
125
- /**
126
- * Denies access to everyone.
127
- */
128
- export const denyAll = () => false;
@@ -1,51 +0,0 @@
1
- export declare const resolvedPluginManifest: readonly [{
2
- readonly id: "appointments";
3
- readonly directory: "plugin-appointments";
4
- }, {
5
- readonly id: "channel-connector";
6
- readonly directory: "plugin-channel-connector";
7
- }, {
8
- readonly id: "gift-cards";
9
- readonly directory: "plugin-gift-cards";
10
- }, {
11
- readonly id: "layaway";
12
- readonly directory: "plugin-layaway";
13
- }, {
14
- readonly id: "loyalty";
15
- readonly directory: "plugin-loyalty";
16
- }, {
17
- readonly id: "marketplace";
18
- readonly directory: "plugin-marketplace";
19
- }, {
20
- readonly id: "notifications";
21
- readonly directory: "plugin-notifications";
22
- }, {
23
- readonly id: "pos";
24
- readonly directory: "plugin-pos";
25
- }, {
26
- readonly id: "pos-restaurant";
27
- readonly directory: "plugin-pos-restaurant";
28
- }, {
29
- readonly id: "procurement";
30
- readonly directory: "plugin-procurement";
31
- }, {
32
- readonly id: "production";
33
- readonly directory: "plugin-production";
34
- }, {
35
- readonly id: "reviews";
36
- readonly directory: "plugin-reviews";
37
- }, {
38
- readonly id: "scheduled-orders";
39
- readonly directory: "plugin-scheduled-orders";
40
- }, {
41
- readonly id: "uom";
42
- readonly directory: "plugin-uom";
43
- }, {
44
- readonly id: "warehouse";
45
- readonly directory: "plugin-warehouse";
46
- }, {
47
- readonly id: "wishlist";
48
- readonly directory: "plugin-wishlist";
49
- }];
50
- export type ResolvedPluginId = (typeof resolvedPluginManifest)[number]["id"];
51
- //# sourceMappingURL=plugin-manifest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-manifest.d.ts","sourceRoot":"","sources":["../../src/generated/plugin-manifest.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBzB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC"}