@unifiedcommerce/core 0.0.4 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/dist/auth/auth-schema.d.ts +92 -0
  2. package/dist/auth/auth-schema.d.ts.map +1 -1
  3. package/dist/auth/auth-schema.js +7 -0
  4. package/dist/auth/setup.d.ts.map +1 -1
  5. package/dist/auth/setup.js +3 -1
  6. package/package.json +1 -2
  7. package/src/adapters/console-email.ts +0 -43
  8. package/src/auth/access.ts +0 -187
  9. package/src/auth/auth-schema.ts +0 -131
  10. package/src/auth/middleware.ts +0 -161
  11. package/src/auth/org.ts +0 -41
  12. package/src/auth/permissions.ts +0 -28
  13. package/src/auth/setup.ts +0 -165
  14. package/src/auth/system-actor.ts +0 -19
  15. package/src/auth/types.ts +0 -10
  16. package/src/config/defaults.ts +0 -82
  17. package/src/config/define-config.ts +0 -53
  18. package/src/config/types.ts +0 -299
  19. package/src/generated/plugin-capabilities.d.ts +0 -20
  20. package/src/generated/plugin-manifest.ts +0 -23
  21. package/src/generated/plugin-repositories.d.ts +0 -20
  22. package/src/hooks/checkout-completion.ts +0 -262
  23. package/src/hooks/checkout.ts +0 -677
  24. package/src/hooks/order-emails.ts +0 -62
  25. package/src/index.ts +0 -214
  26. package/src/interfaces/mcp/agent-prompt.ts +0 -174
  27. package/src/interfaces/mcp/context-enrichment.ts +0 -177
  28. package/src/interfaces/mcp/server.ts +0 -617
  29. package/src/interfaces/mcp/transport.ts +0 -68
  30. package/src/interfaces/rest/customer-portal.ts +0 -299
  31. package/src/interfaces/rest/index.ts +0 -74
  32. package/src/interfaces/rest/router.ts +0 -334
  33. package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
  34. package/src/interfaces/rest/routes/audit.ts +0 -50
  35. package/src/interfaces/rest/routes/carts.ts +0 -89
  36. package/src/interfaces/rest/routes/catalog.ts +0 -493
  37. package/src/interfaces/rest/routes/checkout.ts +0 -283
  38. package/src/interfaces/rest/routes/inventory.ts +0 -70
  39. package/src/interfaces/rest/routes/media.ts +0 -86
  40. package/src/interfaces/rest/routes/orders.ts +0 -78
  41. package/src/interfaces/rest/routes/payments.ts +0 -60
  42. package/src/interfaces/rest/routes/pricing.ts +0 -57
  43. package/src/interfaces/rest/routes/promotions.ts +0 -92
  44. package/src/interfaces/rest/routes/search.ts +0 -71
  45. package/src/interfaces/rest/routes/webhooks.ts +0 -46
  46. package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
  47. package/src/interfaces/rest/schemas/audit.ts +0 -46
  48. package/src/interfaces/rest/schemas/carts.ts +0 -125
  49. package/src/interfaces/rest/schemas/catalog.ts +0 -450
  50. package/src/interfaces/rest/schemas/checkout.ts +0 -66
  51. package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
  52. package/src/interfaces/rest/schemas/inventory.ts +0 -138
  53. package/src/interfaces/rest/schemas/media.ts +0 -75
  54. package/src/interfaces/rest/schemas/orders.ts +0 -104
  55. package/src/interfaces/rest/schemas/pricing.ts +0 -80
  56. package/src/interfaces/rest/schemas/promotions.ts +0 -110
  57. package/src/interfaces/rest/schemas/responses.ts +0 -85
  58. package/src/interfaces/rest/schemas/search.ts +0 -58
  59. package/src/interfaces/rest/schemas/shared.ts +0 -62
  60. package/src/interfaces/rest/schemas/webhooks.ts +0 -68
  61. package/src/interfaces/rest/utils.ts +0 -104
  62. package/src/interfaces/rest/webhook-router.ts +0 -50
  63. package/src/kernel/compensation/executor.ts +0 -61
  64. package/src/kernel/compensation/types.ts +0 -26
  65. package/src/kernel/database/adapter.ts +0 -13
  66. package/src/kernel/database/drizzle-db.ts +0 -56
  67. package/src/kernel/database/migrate.ts +0 -76
  68. package/src/kernel/database/plugin-types.ts +0 -34
  69. package/src/kernel/database/schema.ts +0 -49
  70. package/src/kernel/database/scoped-db.ts +0 -68
  71. package/src/kernel/database/tx-context.ts +0 -46
  72. package/src/kernel/error-mapper.ts +0 -15
  73. package/src/kernel/errors.ts +0 -89
  74. package/src/kernel/factory/repository-factory.ts +0 -242
  75. package/src/kernel/hooks/create-context.ts +0 -43
  76. package/src/kernel/hooks/executor.ts +0 -88
  77. package/src/kernel/hooks/registry.ts +0 -74
  78. package/src/kernel/hooks/types.ts +0 -52
  79. package/src/kernel/http-error.ts +0 -44
  80. package/src/kernel/jobs/adapter.ts +0 -36
  81. package/src/kernel/jobs/drizzle-adapter.ts +0 -58
  82. package/src/kernel/jobs/runner.ts +0 -153
  83. package/src/kernel/jobs/schema.ts +0 -46
  84. package/src/kernel/jobs/types.ts +0 -30
  85. package/src/kernel/local-api.ts +0 -185
  86. package/src/kernel/plugin/manifest.ts +0 -253
  87. package/src/kernel/query/executor.ts +0 -184
  88. package/src/kernel/query/registry.ts +0 -46
  89. package/src/kernel/result.ts +0 -33
  90. package/src/kernel/schema/extra-columns.ts +0 -37
  91. package/src/kernel/service-registry.ts +0 -76
  92. package/src/kernel/service-timing.ts +0 -89
  93. package/src/kernel/state-machine/machine.ts +0 -101
  94. package/src/modules/analytics/drizzle-adapter.ts +0 -426
  95. package/src/modules/analytics/hooks.ts +0 -11
  96. package/src/modules/analytics/models.ts +0 -125
  97. package/src/modules/analytics/repository/index.ts +0 -6
  98. package/src/modules/analytics/service.ts +0 -245
  99. package/src/modules/analytics/types.ts +0 -180
  100. package/src/modules/audit/hooks.ts +0 -78
  101. package/src/modules/audit/schema.ts +0 -33
  102. package/src/modules/audit/service.ts +0 -151
  103. package/src/modules/cart/access.ts +0 -27
  104. package/src/modules/cart/matcher.ts +0 -26
  105. package/src/modules/cart/repository/index.ts +0 -234
  106. package/src/modules/cart/schema.ts +0 -42
  107. package/src/modules/cart/schemas.ts +0 -38
  108. package/src/modules/cart/service.ts +0 -541
  109. package/src/modules/catalog/repository/index.ts +0 -772
  110. package/src/modules/catalog/schema.ts +0 -203
  111. package/src/modules/catalog/schemas.ts +0 -104
  112. package/src/modules/catalog/service.ts +0 -1544
  113. package/src/modules/customers/repository/index.ts +0 -327
  114. package/src/modules/customers/schema.ts +0 -64
  115. package/src/modules/customers/service.ts +0 -171
  116. package/src/modules/fulfillment/repository/index.ts +0 -426
  117. package/src/modules/fulfillment/schema.ts +0 -101
  118. package/src/modules/fulfillment/service.ts +0 -555
  119. package/src/modules/fulfillment/types.ts +0 -59
  120. package/src/modules/inventory/repository/index.ts +0 -509
  121. package/src/modules/inventory/schema.ts +0 -94
  122. package/src/modules/inventory/schemas.ts +0 -38
  123. package/src/modules/inventory/service.ts +0 -490
  124. package/src/modules/media/adapter.ts +0 -17
  125. package/src/modules/media/repository/index.ts +0 -274
  126. package/src/modules/media/schema.ts +0 -41
  127. package/src/modules/media/service.ts +0 -151
  128. package/src/modules/orders/repository/index.ts +0 -287
  129. package/src/modules/orders/schema.ts +0 -66
  130. package/src/modules/orders/service.ts +0 -619
  131. package/src/modules/orders/stale-order-cleanup.ts +0 -76
  132. package/src/modules/organization/service.ts +0 -191
  133. package/src/modules/payments/adapter.ts +0 -47
  134. package/src/modules/payments/repository/index.ts +0 -6
  135. package/src/modules/payments/service.ts +0 -107
  136. package/src/modules/pricing/repository/index.ts +0 -291
  137. package/src/modules/pricing/schema.ts +0 -71
  138. package/src/modules/pricing/schemas.ts +0 -38
  139. package/src/modules/pricing/service.ts +0 -494
  140. package/src/modules/promotions/repository/index.ts +0 -325
  141. package/src/modules/promotions/schema.ts +0 -62
  142. package/src/modules/promotions/schemas.ts +0 -38
  143. package/src/modules/promotions/service.ts +0 -598
  144. package/src/modules/search/adapter.ts +0 -57
  145. package/src/modules/search/hooks.ts +0 -12
  146. package/src/modules/search/repository/index.ts +0 -6
  147. package/src/modules/search/service.ts +0 -315
  148. package/src/modules/shipping/calculator.ts +0 -188
  149. package/src/modules/shipping/repository/index.ts +0 -6
  150. package/src/modules/shipping/service.ts +0 -51
  151. package/src/modules/tax/adapter.ts +0 -60
  152. package/src/modules/tax/repository/index.ts +0 -6
  153. package/src/modules/tax/service.ts +0 -53
  154. package/src/modules/webhooks/hook.ts +0 -34
  155. package/src/modules/webhooks/repository/index.ts +0 -278
  156. package/src/modules/webhooks/schema.ts +0 -56
  157. package/src/modules/webhooks/service.ts +0 -117
  158. package/src/modules/webhooks/signing.ts +0 -6
  159. package/src/modules/webhooks/ssrf-guard.ts +0 -71
  160. package/src/modules/webhooks/tasks.ts +0 -52
  161. package/src/modules/webhooks/worker.ts +0 -134
  162. package/src/runtime/commerce.ts +0 -145
  163. package/src/runtime/kernel.ts +0 -419
  164. package/src/runtime/logger.ts +0 -36
  165. package/src/runtime/server.ts +0 -349
  166. package/src/runtime/shutdown.ts +0 -43
  167. package/src/test-utils/create-pglite-adapter.ts +0 -129
  168. package/src/test-utils/create-plugin-test-app.ts +0 -128
  169. package/src/test-utils/create-repository-test-harness.ts +0 -16
  170. package/src/test-utils/create-test-config.ts +0 -190
  171. package/src/test-utils/create-test-kernel.ts +0 -7
  172. package/src/test-utils/create-test-plugin-context.ts +0 -75
  173. package/src/test-utils/rest-api-test-utils.ts +0 -265
  174. package/src/test-utils/test-actors.ts +0 -62
  175. package/src/test-utils/typed-hooks.ts +0 -54
  176. package/src/types/commerce-types.ts +0 -34
  177. package/src/utils/id.ts +0 -3
  178. package/src/utils/logger.ts +0 -18
  179. package/src/utils/pagination.ts +0 -22
@@ -1,20 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
-
4
- export interface PluginCapabilityRegistryShape {
5
- "appointments": Record<string, unknown>;
6
- "cubejs": Record<string, unknown>;
7
- "gift-cards": Record<string, unknown>;
8
- "loyalty": Record<string, unknown>;
9
- "marketplace": Record<string, unknown>;
10
- "notifications": Record<string, unknown>;
11
- "pos": Record<string, unknown>;
12
- "pos-restaurant": Record<string, unknown>;
13
- "procurement": Record<string, unknown>;
14
- "production": Record<string, unknown>;
15
- "reviews": Record<string, unknown>;
16
- "scheduled-orders": Record<string, unknown>;
17
- "uom": Record<string, unknown>;
18
- "warehouse": Record<string, unknown>;
19
- "wishlist": Record<string, unknown>;
20
- }
@@ -1,23 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
- // DO NOT EDIT MANUALLY.
4
-
5
- export const resolvedPluginManifest = [
6
- { id: "appointments", directory: "plugin-appointments" },
7
- { id: "cubejs", directory: "plugin-cubejs" },
8
- { id: "gift-cards", directory: "plugin-gift-cards" },
9
- { id: "loyalty", directory: "plugin-loyalty" },
10
- { id: "marketplace", directory: "plugin-marketplace" },
11
- { id: "notifications", directory: "plugin-notifications" },
12
- { id: "pos", directory: "plugin-pos" },
13
- { id: "pos-restaurant", directory: "plugin-pos-restaurant" },
14
- { id: "procurement", directory: "plugin-procurement" },
15
- { id: "production", directory: "plugin-production" },
16
- { id: "reviews", directory: "plugin-reviews" },
17
- { id: "scheduled-orders", directory: "plugin-scheduled-orders" },
18
- { id: "uom", directory: "plugin-uom" },
19
- { id: "warehouse", directory: "plugin-warehouse" },
20
- { id: "wishlist", directory: "plugin-wishlist" },
21
- ] as const;
22
-
23
- export type ResolvedPluginId = (typeof resolvedPluginManifest)[number]["id"];
@@ -1,20 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
-
4
- export interface PluginRepositoryRegistryShape {
5
- "appointments": Record<string, unknown>;
6
- "cubejs": Record<string, unknown>;
7
- "gift-cards": Record<string, unknown>;
8
- "loyalty": Record<string, unknown>;
9
- "marketplace": Record<string, unknown>;
10
- "notifications": Record<string, unknown>;
11
- "pos": Record<string, unknown>;
12
- "pos-restaurant": Record<string, unknown>;
13
- "procurement": Record<string, unknown>;
14
- "production": Record<string, unknown>;
15
- "reviews": Record<string, unknown>;
16
- "scheduled-orders": Record<string, unknown>;
17
- "uom": Record<string, unknown>;
18
- "warehouse": Record<string, unknown>;
19
- "wishlist": Record<string, unknown>;
20
- }
@@ -1,262 +0,0 @@
1
- import type { Step } from "../kernel/compensation/types.js";
2
- import type { CheckoutData } from "./checkout.js";
3
- import { Ok, Err } from "../kernel/result.js";
4
- import { CommerceValidationError } from "../kernel/errors.js";
5
-
6
- // Service type narrowing — these mirror the actual service interfaces
7
- // without creating circular imports.
8
-
9
- interface InventoryServiceLike {
10
- reserve(input: {
11
- entityId: string;
12
- variantId?: string;
13
- quantity: number;
14
- orderId: string;
15
- performedBy: string;
16
- }): Promise<{ ok: boolean; error?: { message: string } }>;
17
- release(input: {
18
- entityId: string;
19
- variantId?: string;
20
- quantity: number;
21
- orderId: string;
22
- performedBy: string;
23
- }): Promise<unknown>;
24
- }
25
-
26
- interface PaymentsServiceLike {
27
- capture(
28
- paymentIntentId: string,
29
- amount?: number,
30
- ): Promise<{ ok: boolean; error?: { message: string } }>;
31
- refund(
32
- paymentId: string,
33
- amount: number,
34
- reason?: string,
35
- ): Promise<unknown>;
36
- }
37
-
38
- interface OrdersServiceLike {
39
- updateStatus?(
40
- orderId: string,
41
- status: string,
42
- reason?: string,
43
- ): Promise<unknown>;
44
- }
45
-
46
- /**
47
- * Reservation record produced by the reserve-inventory step.
48
- * Passed to compensate() so it knows exactly what to undo.
49
- */
50
- export interface InventoryReservation {
51
- entityId: string;
52
- variantId: string | undefined;
53
- quantity: number;
54
- orderId: string;
55
- }
56
-
57
- /**
58
- * Step 1: Reserve inventory.
59
- *
60
- * Output: the list of reservations created.
61
- * Compensate: release each reservation.
62
- *
63
- * Inventory reservation runs BEFORE payment capture. This is deliberate:
64
- * if stock is unavailable, we should find out before charging the customer.
65
- * The compensation for this step releases the reserved quantities.
66
- */
67
- export const reserveInventoryStep: Step<
68
- CheckoutData,
69
- InventoryReservation[]
70
- > = {
71
- id: "reserve-inventory",
72
-
73
- async run(data, ctx) {
74
- const inventory = ctx.hook.services.inventory as InventoryServiceLike;
75
- const reservations: InventoryReservation[] = [];
76
- const performedBy = ctx.hook.actor?.userId ?? "system";
77
-
78
- for (const item of data.lineItems) {
79
- const result = await inventory.reserve({
80
- entityId: item.entityId,
81
- ...(item.variantId != null ? { variantId: item.variantId } : {}),
82
- quantity: item.quantity,
83
- orderId: data.checkoutId,
84
- performedBy,
85
- });
86
-
87
- if (!result.ok) {
88
- return Err(
89
- new CommerceValidationError(
90
- `Inventory reservation failed for ${item.title ?? item.entityId}: ${result.error?.message ?? "unknown"}`,
91
- ),
92
- );
93
- }
94
-
95
- reservations.push({
96
- entityId: item.entityId,
97
- variantId: item.variantId,
98
- quantity: item.quantity,
99
- orderId: data.checkoutId,
100
- });
101
- }
102
-
103
- return Ok(reservations);
104
- },
105
-
106
- async compensate(reservations, ctx) {
107
- const inventory = ctx.hook.services.inventory as InventoryServiceLike;
108
- const performedBy = ctx.hook.actor?.userId ?? "system";
109
-
110
- for (const r of reservations) {
111
- await inventory.release({
112
- entityId: r.entityId,
113
- ...(r.variantId != null ? { variantId: r.variantId } : {}),
114
- quantity: r.quantity,
115
- orderId: r.orderId,
116
- performedBy,
117
- });
118
- }
119
- },
120
- };
121
-
122
- /**
123
- * Step 2: Capture payment.
124
- *
125
- * Output: the captured payment intent ID and amount.
126
- * Compensate: issue a full refund via the payments service.
127
- *
128
- * Runs AFTER inventory reservation. If capture fails, inventory reservations
129
- * are released by the compensation chain. If capture succeeds but a later step
130
- * fails, a refund is issued.
131
- */
132
- export const capturePaymentStep: Step<
133
- CheckoutData,
134
- { paymentIntentId: string; amount: number }
135
- > = {
136
- id: "capture-payment",
137
-
138
- async run(data, ctx) {
139
- if (!data.paymentIntentId) {
140
- return Err(
141
- new CommerceValidationError(
142
- "No authorized payment intent to capture.",
143
- ),
144
- );
145
- }
146
-
147
- const payments = ctx.hook.services.payments as PaymentsServiceLike;
148
- const result = await payments.capture(data.paymentIntentId);
149
-
150
- if (!result.ok) {
151
- return Err(
152
- new CommerceValidationError(
153
- `Payment capture failed: ${result.error?.message ?? "unknown"}`,
154
- ),
155
- );
156
- }
157
-
158
- return Ok({ paymentIntentId: data.paymentIntentId, amount: data.total });
159
- },
160
-
161
- async compensate({ paymentIntentId, amount }, ctx) {
162
- const payments = ctx.hook.services.payments as PaymentsServiceLike;
163
- await payments.refund(
164
- paymentIntentId,
165
- amount,
166
- "Checkout compensation: downstream step failed after payment capture",
167
- );
168
- },
169
- };
170
-
171
- /**
172
- * Step 3: Initiate fulfillment.
173
- *
174
- * Output: the order ID (for logging).
175
- * No compensate: fulfillment initiation is best-effort and idempotent.
176
- * A failed fulfillment should be retried through the job queue, not
177
- * compensated by rolling back the entire checkout.
178
- */
179
- export const initiateFulfillmentStep: Step<
180
- CheckoutData,
181
- { orderId: string }
182
- > = {
183
- id: "initiate-fulfillment",
184
-
185
- async run(data, ctx) {
186
- const fulfillment = ctx.hook.services.fulfillment as {
187
- fulfillOrder(orderId: string, actor?: unknown): Promise<unknown>;
188
- };
189
-
190
- try {
191
- await fulfillment.fulfillOrder(data.checkoutId, ctx.hook.actor);
192
- } catch (error) {
193
- // Fulfillment initiation failure should not fail the checkout.
194
- // The order is paid and inventory is reserved — fulfillment can be retried.
195
- ctx.hook.logger.warn(
196
- `Fulfillment initiation failed for order ${data.checkoutId}. Will need manual retry.`,
197
- { error },
198
- );
199
- }
200
-
201
- return Ok({ orderId: data.checkoutId });
202
- },
203
-
204
- // No compensate — fulfillment is best-effort at this stage
205
- };
206
-
207
- /**
208
- * Step 4: Send confirmation email.
209
- *
210
- * Output: void (best-effort).
211
- * No compensate: you cannot unsend an email.
212
- */
213
- export const sendConfirmationStep: Step<
214
- CheckoutData,
215
- { sent: boolean }
216
- > = {
217
- id: "send-confirmation",
218
-
219
- async run(data, ctx) {
220
- const customers = ctx.hook.services.customers as {
221
- getByUserId(
222
- userId: string,
223
- actor?: unknown,
224
- ): Promise<{ ok: boolean; value?: { email?: string } }>;
225
- };
226
- const email = ctx.hook.services.email as
227
- | {
228
- send(input: {
229
- template: string;
230
- to: string;
231
- data?: Record<string, unknown>;
232
- }): Promise<void>;
233
- }
234
- | undefined;
235
-
236
- if (!data.customerId || !email?.send) {
237
- return Ok({ sent: false });
238
- }
239
-
240
- try {
241
- const customer = await customers.getByUserId(data.customerId, ctx.hook.actor);
242
- if (customer.ok && customer.value?.email) {
243
- await email.send({
244
- template: "order-confirmation",
245
- to: customer.value.email,
246
- data: { orderId: data.checkoutId, total: data.total, currency: data.currency },
247
- });
248
- return Ok({ sent: true });
249
- }
250
- } catch (error) {
251
- // Email failure should not fail checkout
252
- ctx.hook.logger.warn(
253
- `Confirmation email failed for order ${data.checkoutId}.`,
254
- { error },
255
- );
256
- }
257
-
258
- return Ok({ sent: false });
259
- },
260
-
261
- // No compensate — cannot unsend an email
262
- };