@unifiedcommerce/core 0.4.2 → 0.4.4
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.
- package/dist/interfaces/rest/index.d.ts.map +1 -1
- package/dist/interfaces/rest/index.js +4 -17
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +33 -0
- package/package.json +1 -1
- package/src/interfaces/rest/index.ts +4 -18
- package/src/runtime/server.ts +33 -0
- package/dist/adapters/console-email.d.ts +0 -23
- package/dist/adapters/console-email.d.ts.map +0 -1
- package/dist/adapters/console-email.js +0 -38
- package/dist/auth/access.d.ts +0 -101
- package/dist/auth/access.d.ts.map +0 -1
- package/dist/auth/access.js +0 -128
- package/dist/auth/auth-schema.d.ts +0 -1475
- package/dist/auth/auth-schema.d.ts.map +0 -1
- package/dist/auth/auth-schema.js +0 -124
- package/dist/auth/middleware.d.ts +0 -5
- package/dist/auth/middleware.d.ts.map +0 -1
- package/dist/auth/middleware.js +0 -141
- package/dist/auth/org.d.ts +0 -22
- package/dist/auth/org.d.ts.map +0 -1
- package/dist/auth/org.js +0 -36
- package/dist/auth/permissions.d.ts +0 -4
- package/dist/auth/permissions.d.ts.map +0 -1
- package/dist/auth/permissions.js +0 -24
- package/dist/auth/setup.d.ts +0 -29
- package/dist/auth/setup.d.ts.map +0 -1
- package/dist/auth/setup.js +0 -117
- package/dist/auth/system-actor.d.ts +0 -7
- package/dist/auth/system-actor.d.ts.map +0 -1
- package/dist/auth/system-actor.js +0 -17
- package/dist/auth/types.d.ts +0 -11
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -1
- package/dist/config/defaults.d.ts +0 -3
- package/dist/config/defaults.d.ts.map +0 -1
- package/dist/config/defaults.js +0 -80
- package/dist/config/define-config.d.ts +0 -9
- package/dist/config/define-config.d.ts.map +0 -1
- package/dist/config/define-config.js +0 -44
- package/dist/config/types.d.ts +0 -327
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/generated/plugin-manifest.d.ts +0 -48
- package/dist/generated/plugin-manifest.d.ts.map +0 -1
- package/dist/generated/plugin-manifest.js +0 -20
- package/dist/hooks/checkout-completion.d.ts +0 -58
- package/dist/hooks/checkout-completion.d.ts.map +0 -1
- package/dist/hooks/checkout-completion.js +0 -137
- package/dist/hooks/checkout.d.ts +0 -99
- package/dist/hooks/checkout.d.ts.map +0 -1
- package/dist/hooks/checkout.js +0 -317
- package/dist/hooks/order-emails.d.ts +0 -16
- package/dist/hooks/order-emails.d.ts.map +0 -1
- package/dist/hooks/order-emails.js +0 -44
- package/dist/index.d.ts +0 -77
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -45
- package/dist/interfaces/mcp/agent-prompt.d.ts +0 -16
- package/dist/interfaces/mcp/agent-prompt.d.ts.map +0 -1
- package/dist/interfaces/mcp/agent-prompt.js +0 -172
- package/dist/interfaces/mcp/context-enrichment.d.ts +0 -39
- package/dist/interfaces/mcp/context-enrichment.d.ts.map +0 -1
- package/dist/interfaces/mcp/context-enrichment.js +0 -119
- package/dist/interfaces/mcp/server.d.ts +0 -5
- package/dist/interfaces/mcp/server.d.ts.map +0 -1
- package/dist/interfaces/mcp/server.js +0 -30
- package/dist/interfaces/mcp/tool-builder.d.ts +0 -120
- package/dist/interfaces/mcp/tool-builder.d.ts.map +0 -1
- package/dist/interfaces/mcp/tool-builder.js +0 -224
- package/dist/interfaces/mcp/tools/analytics.d.ts +0 -42
- package/dist/interfaces/mcp/tools/analytics.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/analytics.js +0 -70
- package/dist/interfaces/mcp/tools/cart.d.ts +0 -14
- package/dist/interfaces/mcp/tools/cart.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/cart.js +0 -47
- package/dist/interfaces/mcp/tools/catalog.d.ts +0 -53
- package/dist/interfaces/mcp/tools/catalog.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/catalog.js +0 -284
- package/dist/interfaces/mcp/tools/index.d.ts +0 -3
- package/dist/interfaces/mcp/tools/index.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/index.js +0 -20
- package/dist/interfaces/mcp/tools/inventory.d.ts +0 -27
- package/dist/interfaces/mcp/tools/inventory.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/inventory.js +0 -143
- package/dist/interfaces/mcp/tools/orders.d.ts +0 -18
- package/dist/interfaces/mcp/tools/orders.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/orders.js +0 -82
- package/dist/interfaces/mcp/tools/pricing.d.ts +0 -29
- package/dist/interfaces/mcp/tools/pricing.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/pricing.js +0 -90
- package/dist/interfaces/mcp/tools/promotions.d.ts +0 -44
- package/dist/interfaces/mcp/tools/promotions.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/promotions.js +0 -109
- package/dist/interfaces/mcp/tools/registry.d.ts +0 -32
- package/dist/interfaces/mcp/tools/registry.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/registry.js +0 -55
- package/dist/interfaces/mcp/tools/search.d.ts +0 -14
- package/dist/interfaces/mcp/tools/search.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/search.js +0 -39
- package/dist/interfaces/mcp/tools/webhooks.d.ts +0 -15
- package/dist/interfaces/mcp/tools/webhooks.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/webhooks.js +0 -48
- package/dist/interfaces/mcp/transport.d.ts +0 -20
- package/dist/interfaces/mcp/transport.d.ts.map +0 -1
- package/dist/interfaces/mcp/transport.js +0 -99
- package/dist/interfaces/rest/customer-portal.d.ts +0 -5
- package/dist/interfaces/rest/customer-portal.d.ts.map +0 -1
- package/dist/interfaces/rest/customer-portal.js +0 -206
- package/dist/interfaces/rest/router.d.ts +0 -164
- package/dist/interfaces/rest/router.d.ts.map +0 -1
- package/dist/interfaces/rest/router.js +0 -259
- package/dist/interfaces/rest/routes/admin-jobs.d.ts +0 -5
- package/dist/interfaces/rest/routes/admin-jobs.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/admin-jobs.js +0 -48
- package/dist/interfaces/rest/routes/audit.d.ts +0 -5
- package/dist/interfaces/rest/routes/audit.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/audit.js +0 -43
- package/dist/interfaces/rest/routes/carts.d.ts +0 -5
- package/dist/interfaces/rest/routes/carts.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/carts.js +0 -55
- package/dist/interfaces/rest/routes/catalog.d.ts +0 -5
- package/dist/interfaces/rest/routes/catalog.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/catalog.js +0 -256
- package/dist/interfaces/rest/routes/checkout.d.ts +0 -5
- package/dist/interfaces/rest/routes/checkout.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/checkout.js +0 -216
- package/dist/interfaces/rest/routes/customers.d.ts +0 -5
- package/dist/interfaces/rest/routes/customers.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/customers.js +0 -74
- package/dist/interfaces/rest/routes/entity-aliases.d.ts +0 -18
- package/dist/interfaces/rest/routes/entity-aliases.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/entity-aliases.js +0 -39
- package/dist/interfaces/rest/routes/inventory.d.ts +0 -5
- package/dist/interfaces/rest/routes/inventory.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/inventory.js +0 -72
- package/dist/interfaces/rest/routes/media.d.ts +0 -5
- package/dist/interfaces/rest/routes/media.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/media.js +0 -65
- package/dist/interfaces/rest/routes/orders.d.ts +0 -5
- package/dist/interfaces/rest/routes/orders.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/orders.js +0 -64
- package/dist/interfaces/rest/routes/payments.d.ts +0 -5
- package/dist/interfaces/rest/routes/payments.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/payments.js +0 -45
- package/dist/interfaces/rest/routes/pricing.d.ts +0 -5
- package/dist/interfaces/rest/routes/pricing.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/pricing.js +0 -48
- package/dist/interfaces/rest/routes/promotions.d.ts +0 -5
- package/dist/interfaces/rest/routes/promotions.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/promotions.js +0 -76
- package/dist/interfaces/rest/routes/search.d.ts +0 -5
- package/dist/interfaces/rest/routes/search.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/search.js +0 -60
- package/dist/interfaces/rest/routes/webhooks.d.ts +0 -5
- package/dist/interfaces/rest/routes/webhooks.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/webhooks.js +0 -39
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts +0 -327
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/admin-jobs.js +0 -37
- package/dist/interfaces/rest/schemas/audit.d.ts +0 -59
- package/dist/interfaces/rest/schemas/audit.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/audit.js +0 -43
- package/dist/interfaces/rest/schemas/carts.d.ts +0 -1456
- package/dist/interfaces/rest/schemas/carts.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/carts.js +0 -109
- package/dist/interfaces/rest/schemas/catalog.d.ts +0 -5452
- package/dist/interfaces/rest/schemas/catalog.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/catalog.js +0 -397
- package/dist/interfaces/rest/schemas/checkout.d.ts +0 -160
- package/dist/interfaces/rest/schemas/checkout.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/checkout.js +0 -60
- package/dist/interfaces/rest/schemas/customer-portal.d.ts +0 -2203
- package/dist/interfaces/rest/schemas/customer-portal.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/customer-portal.js +0 -177
- package/dist/interfaces/rest/schemas/customers.d.ts +0 -422
- package/dist/interfaces/rest/schemas/customers.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/customers.js +0 -150
- package/dist/interfaces/rest/schemas/inventory.d.ts +0 -561
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/inventory.js +0 -148
- package/dist/interfaces/rest/schemas/media.d.ts +0 -303
- package/dist/interfaces/rest/schemas/media.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/media.js +0 -69
- package/dist/interfaces/rest/schemas/orders.d.ts +0 -1792
- package/dist/interfaces/rest/schemas/orders.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/orders.js +0 -93
- package/dist/interfaces/rest/schemas/pricing.d.ts +0 -256
- package/dist/interfaces/rest/schemas/pricing.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/pricing.js +0 -72
- package/dist/interfaces/rest/schemas/promotions.d.ts +0 -363
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/promotions.js +0 -98
- package/dist/interfaces/rest/schemas/responses.d.ts +0 -4086
- package/dist/interfaces/rest/schemas/responses.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/responses.js +0 -74
- package/dist/interfaces/rest/schemas/search.d.ts +0 -247
- package/dist/interfaces/rest/schemas/search.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/search.js +0 -55
- package/dist/interfaces/rest/schemas/shared.d.ts +0 -95
- package/dist/interfaces/rest/schemas/shared.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/shared.js +0 -51
- package/dist/interfaces/rest/schemas/webhooks.d.ts +0 -221
- package/dist/interfaces/rest/schemas/webhooks.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/webhooks.js +0 -62
- package/dist/interfaces/rest/utils.d.ts +0 -45
- package/dist/interfaces/rest/utils.d.ts.map +0 -1
- package/dist/interfaces/rest/utils.js +0 -71
- package/dist/interfaces/rest/webhook-router.d.ts +0 -41
- package/dist/interfaces/rest/webhook-router.d.ts.map +0 -1
- package/dist/interfaces/rest/webhook-router.js +0 -36
- package/dist/kernel/compensation/executor.d.ts +0 -21
- package/dist/kernel/compensation/executor.d.ts.map +0 -1
- package/dist/kernel/compensation/executor.js +0 -36
- package/dist/kernel/compensation/types.d.ts +0 -25
- package/dist/kernel/compensation/types.d.ts.map +0 -1
- package/dist/kernel/compensation/types.js +0 -1
- package/dist/kernel/database/adapter.d.ts +0 -18
- package/dist/kernel/database/adapter.d.ts.map +0 -1
- package/dist/kernel/database/adapter.js +0 -3
- package/dist/kernel/database/drizzle-db.d.ts +0 -49
- package/dist/kernel/database/drizzle-db.d.ts.map +0 -1
- package/dist/kernel/database/drizzle-db.js +0 -20
- package/dist/kernel/database/migrate.d.ts +0 -38
- package/dist/kernel/database/migrate.d.ts.map +0 -1
- package/dist/kernel/database/migrate.js +0 -61
- package/dist/kernel/database/plugin-types.d.ts +0 -32
- package/dist/kernel/database/plugin-types.d.ts.map +0 -1
- package/dist/kernel/database/plugin-types.js +0 -10
- package/dist/kernel/database/schema.d.ts +0 -24
- package/dist/kernel/database/schema.d.ts.map +0 -1
- package/dist/kernel/database/schema.js +0 -36
- package/dist/kernel/database/scoped-db.d.ts +0 -20
- package/dist/kernel/database/scoped-db.d.ts.map +0 -1
- package/dist/kernel/database/scoped-db.js +0 -62
- package/dist/kernel/database/tx-context.d.ts +0 -15
- package/dist/kernel/database/tx-context.d.ts.map +0 -1
- package/dist/kernel/database/tx-context.js +0 -19
- package/dist/kernel/error-mapper.d.ts +0 -3
- package/dist/kernel/error-mapper.d.ts.map +0 -1
- package/dist/kernel/error-mapper.js +0 -12
- package/dist/kernel/errors.d.ts +0 -38
- package/dist/kernel/errors.d.ts.map +0 -1
- package/dist/kernel/errors.js +0 -69
- package/dist/kernel/factory/repository-factory.d.ts +0 -71
- package/dist/kernel/factory/repository-factory.d.ts.map +0 -1
- package/dist/kernel/factory/repository-factory.js +0 -138
- package/dist/kernel/hooks/create-context.d.ts +0 -25
- package/dist/kernel/hooks/create-context.d.ts.map +0 -1
- package/dist/kernel/hooks/create-context.js +0 -22
- package/dist/kernel/hooks/executor.d.ts +0 -12
- package/dist/kernel/hooks/executor.d.ts.map +0 -1
- package/dist/kernel/hooks/executor.js +0 -50
- package/dist/kernel/hooks/registry.d.ts +0 -28
- package/dist/kernel/hooks/registry.d.ts.map +0 -1
- package/dist/kernel/hooks/registry.js +0 -58
- package/dist/kernel/hooks/types.d.ts +0 -37
- package/dist/kernel/hooks/types.d.ts.map +0 -1
- package/dist/kernel/hooks/types.js +0 -1
- package/dist/kernel/http-error.d.ts +0 -30
- package/dist/kernel/http-error.d.ts.map +0 -1
- package/dist/kernel/http-error.js +0 -35
- package/dist/kernel/jobs/adapter.d.ts +0 -25
- package/dist/kernel/jobs/adapter.d.ts.map +0 -1
- package/dist/kernel/jobs/adapter.js +0 -9
- package/dist/kernel/jobs/drizzle-adapter.d.ts +0 -15
- package/dist/kernel/jobs/drizzle-adapter.d.ts.map +0 -1
- package/dist/kernel/jobs/drizzle-adapter.js +0 -42
- package/dist/kernel/jobs/runner.d.ts +0 -24
- package/dist/kernel/jobs/runner.d.ts.map +0 -1
- package/dist/kernel/jobs/runner.js +0 -114
- package/dist/kernel/jobs/schema.d.ts +0 -280
- package/dist/kernel/jobs/schema.d.ts.map +0 -1
- package/dist/kernel/jobs/schema.js +0 -37
- package/dist/kernel/jobs/types.d.ts +0 -30
- package/dist/kernel/jobs/types.d.ts.map +0 -1
- package/dist/kernel/jobs/types.js +0 -1
- package/dist/kernel/local-api.d.ts +0 -103
- package/dist/kernel/local-api.d.ts.map +0 -1
- package/dist/kernel/local-api.js +0 -89
- package/dist/kernel/plugin/manifest.d.ts +0 -90
- package/dist/kernel/plugin/manifest.d.ts.map +0 -1
- package/dist/kernel/plugin/manifest.js +0 -169
- package/dist/kernel/query/executor.d.ts +0 -21
- package/dist/kernel/query/executor.d.ts.map +0 -1
- package/dist/kernel/query/executor.js +0 -128
- package/dist/kernel/query/registry.d.ts +0 -33
- package/dist/kernel/query/registry.d.ts.map +0 -1
- package/dist/kernel/query/registry.js +0 -20
- package/dist/kernel/result.d.ts +0 -36
- package/dist/kernel/result.d.ts.map +0 -1
- package/dist/kernel/result.js +0 -16
- package/dist/kernel/schema/extra-columns.d.ts +0 -23
- package/dist/kernel/schema/extra-columns.d.ts.map +0 -1
- package/dist/kernel/schema/extra-columns.js +0 -10
- package/dist/kernel/service-registry.d.ts +0 -109
- package/dist/kernel/service-registry.d.ts.map +0 -1
- package/dist/kernel/service-registry.js +0 -26
- package/dist/kernel/service-timing.d.ts +0 -25
- package/dist/kernel/service-timing.d.ts.map +0 -1
- package/dist/kernel/service-timing.js +0 -62
- package/dist/kernel/state-machine/machine.d.ts +0 -24
- package/dist/kernel/state-machine/machine.d.ts.map +0 -1
- package/dist/kernel/state-machine/machine.js +0 -70
- package/dist/modules/analytics/drizzle-adapter.d.ts +0 -13
- package/dist/modules/analytics/drizzle-adapter.d.ts.map +0 -1
- package/dist/modules/analytics/drizzle-adapter.js +0 -358
- package/dist/modules/analytics/hooks.d.ts +0 -13
- package/dist/modules/analytics/hooks.d.ts.map +0 -1
- package/dist/modules/analytics/hooks.js +0 -12
- package/dist/modules/analytics/models.d.ts +0 -14
- package/dist/modules/analytics/models.d.ts.map +0 -1
- package/dist/modules/analytics/models.js +0 -118
- package/dist/modules/analytics/repository/index.d.ts +0 -5
- package/dist/modules/analytics/repository/index.d.ts.map +0 -1
- package/dist/modules/analytics/repository/index.js +0 -1
- package/dist/modules/analytics/service.d.ts +0 -45
- package/dist/modules/analytics/service.d.ts.map +0 -1
- package/dist/modules/analytics/service.js +0 -196
- package/dist/modules/analytics/types.d.ts +0 -119
- package/dist/modules/analytics/types.d.ts.map +0 -1
- package/dist/modules/analytics/types.js +0 -25
- package/dist/modules/audit/hooks.d.ts +0 -7
- package/dist/modules/audit/hooks.d.ts.map +0 -1
- package/dist/modules/audit/hooks.js +0 -67
- package/dist/modules/audit/schema.d.ts +0 -178
- package/dist/modules/audit/schema.d.ts.map +0 -1
- package/dist/modules/audit/schema.js +0 -21
- package/dist/modules/audit/service.d.ts +0 -38
- package/dist/modules/audit/service.d.ts.map +0 -1
- package/dist/modules/audit/service.js +0 -109
- package/dist/modules/cart/access.d.ts +0 -11
- package/dist/modules/cart/access.d.ts.map +0 -1
- package/dist/modules/cart/access.js +0 -18
- package/dist/modules/cart/matcher.d.ts +0 -20
- package/dist/modules/cart/matcher.d.ts.map +0 -1
- package/dist/modules/cart/matcher.js +0 -2
- package/dist/modules/cart/repository/index.d.ts +0 -45
- package/dist/modules/cart/repository/index.d.ts.map +0 -1
- package/dist/modules/cart/repository/index.js +0 -158
- package/dist/modules/cart/schema.d.ts +0 -359
- package/dist/modules/cart/schema.d.ts.map +0 -1
- package/dist/modules/cart/schema.js +0 -40
- package/dist/modules/cart/schemas.d.ts +0 -29
- package/dist/modules/cart/schemas.d.ts.map +0 -1
- package/dist/modules/cart/schemas.js +0 -14
- package/dist/modules/cart/service.d.ts +0 -63
- package/dist/modules/cart/service.d.ts.map +0 -1
- package/dist/modules/cart/service.js +0 -339
- package/dist/modules/catalog/repository/index.d.ts +0 -106
- package/dist/modules/catalog/repository/index.d.ts.map +0 -1
- package/dist/modules/catalog/repository/index.js +0 -455
- package/dist/modules/catalog/schema.d.ts +0 -1193
- package/dist/modules/catalog/schema.d.ts.map +0 -1
- package/dist/modules/catalog/schema.js +0 -149
- package/dist/modules/catalog/schemas.d.ts +0 -81
- package/dist/modules/catalog/schemas.d.ts.map +0 -1
- package/dist/modules/catalog/schemas.js +0 -62
- package/dist/modules/catalog/service.d.ts +0 -160
- package/dist/modules/catalog/service.d.ts.map +0 -1
- package/dist/modules/catalog/service.js +0 -759
- package/dist/modules/customers/repository/index.d.ts +0 -47
- package/dist/modules/customers/repository/index.d.ts.map +0 -1
- package/dist/modules/customers/repository/index.js +0 -206
- package/dist/modules/customers/schema.d.ts +0 -560
- package/dist/modules/customers/schema.d.ts.map +0 -1
- package/dist/modules/customers/schema.js +0 -60
- package/dist/modules/customers/service.d.ts +0 -27
- package/dist/modules/customers/service.d.ts.map +0 -1
- package/dist/modules/customers/service.js +0 -106
- package/dist/modules/fulfillment/repository/index.d.ts +0 -63
- package/dist/modules/fulfillment/repository/index.d.ts.map +0 -1
- package/dist/modules/fulfillment/repository/index.js +0 -268
- package/dist/modules/fulfillment/schema.d.ts +0 -655
- package/dist/modules/fulfillment/schema.d.ts.map +0 -1
- package/dist/modules/fulfillment/schema.js +0 -83
- package/dist/modules/fulfillment/service.d.ts +0 -58
- package/dist/modules/fulfillment/service.d.ts.map +0 -1
- package/dist/modules/fulfillment/service.js +0 -338
- package/dist/modules/fulfillment/types.d.ts +0 -44
- package/dist/modules/fulfillment/types.d.ts.map +0 -1
- package/dist/modules/fulfillment/types.js +0 -1
- package/dist/modules/inventory/repository/index.d.ts +0 -81
- package/dist/modules/inventory/repository/index.d.ts.map +0 -1
- package/dist/modules/inventory/repository/index.js +0 -310
- package/dist/modules/inventory/schema.d.ts +0 -570
- package/dist/modules/inventory/schema.d.ts.map +0 -1
- package/dist/modules/inventory/schema.js +0 -69
- package/dist/modules/inventory/schemas.d.ts +0 -31
- package/dist/modules/inventory/schemas.d.ts.map +0 -1
- package/dist/modules/inventory/schemas.js +0 -28
- package/dist/modules/inventory/service.d.ts +0 -69
- package/dist/modules/inventory/service.d.ts.map +0 -1
- package/dist/modules/inventory/service.js +0 -283
- package/dist/modules/media/adapter.d.ts +0 -16
- package/dist/modules/media/adapter.d.ts.map +0 -1
- package/dist/modules/media/adapter.js +0 -1
- package/dist/modules/media/repository/index.d.ts +0 -35
- package/dist/modules/media/repository/index.d.ts.map +0 -1
- package/dist/modules/media/repository/index.js +0 -176
- package/dist/modules/media/schema.d.ts +0 -289
- package/dist/modules/media/schema.d.ts.map +0 -1
- package/dist/modules/media/schema.js +0 -35
- package/dist/modules/media/service.d.ts +0 -42
- package/dist/modules/media/service.d.ts.map +0 -1
- package/dist/modules/media/service.js +0 -89
- package/dist/modules/orders/repository/index.d.ts +0 -48
- package/dist/modules/orders/repository/index.d.ts.map +0 -1
- package/dist/modules/orders/repository/index.js +0 -199
- package/dist/modules/orders/schema.d.ts +0 -672
- package/dist/modules/orders/schema.d.ts.map +0 -1
- package/dist/modules/orders/schema.js +0 -63
- package/dist/modules/orders/service.d.ts +0 -85
- package/dist/modules/orders/service.d.ts.map +0 -1
- package/dist/modules/orders/service.js +0 -313
- package/dist/modules/orders/stale-order-cleanup.d.ts +0 -27
- package/dist/modules/orders/stale-order-cleanup.d.ts.map +0 -1
- package/dist/modules/orders/stale-order-cleanup.js +0 -55
- package/dist/modules/organization/service.d.ts +0 -53
- package/dist/modules/organization/service.d.ts.map +0 -1
- package/dist/modules/organization/service.js +0 -151
- package/dist/modules/payments/adapter.d.ts +0 -42
- package/dist/modules/payments/adapter.d.ts.map +0 -1
- package/dist/modules/payments/adapter.js +0 -1
- package/dist/modules/payments/repository/index.d.ts +0 -5
- package/dist/modules/payments/repository/index.d.ts.map +0 -1
- package/dist/modules/payments/repository/index.js +0 -1
- package/dist/modules/payments/service.d.ts +0 -23
- package/dist/modules/payments/service.d.ts.map +0 -1
- package/dist/modules/payments/service.js +0 -72
- package/dist/modules/pricing/repository/index.d.ts +0 -34
- package/dist/modules/pricing/repository/index.d.ts.map +0 -1
- package/dist/modules/pricing/repository/index.js +0 -176
- package/dist/modules/pricing/schema.d.ts +0 -565
- package/dist/modules/pricing/schema.d.ts.map +0 -1
- package/dist/modules/pricing/schema.js +0 -57
- package/dist/modules/pricing/schemas.d.ts +0 -37
- package/dist/modules/pricing/schemas.d.ts.map +0 -1
- package/dist/modules/pricing/schemas.js +0 -30
- package/dist/modules/pricing/service.d.ts +0 -62
- package/dist/modules/pricing/service.d.ts.map +0 -1
- package/dist/modules/pricing/service.js +0 -308
- package/dist/modules/promotions/repository/index.d.ts +0 -41
- package/dist/modules/promotions/repository/index.d.ts.map +0 -1
- package/dist/modules/promotions/repository/index.js +0 -204
- package/dist/modules/promotions/schema.d.ts +0 -427
- package/dist/modules/promotions/schema.d.ts.map +0 -1
- package/dist/modules/promotions/schema.js +0 -52
- package/dist/modules/promotions/schemas.d.ts +0 -33
- package/dist/modules/promotions/schemas.d.ts.map +0 -1
- package/dist/modules/promotions/schemas.js +0 -32
- package/dist/modules/promotions/service.d.ts +0 -80
- package/dist/modules/promotions/service.d.ts.map +0 -1
- package/dist/modules/promotions/service.js +0 -347
- package/dist/modules/search/adapter.d.ts +0 -51
- package/dist/modules/search/adapter.d.ts.map +0 -1
- package/dist/modules/search/adapter.js +0 -1
- package/dist/modules/search/hooks.d.ts +0 -8
- package/dist/modules/search/hooks.d.ts.map +0 -1
- package/dist/modules/search/hooks.js +0 -6
- package/dist/modules/search/repository/index.d.ts +0 -5
- package/dist/modules/search/repository/index.d.ts.map +0 -1
- package/dist/modules/search/repository/index.js +0 -1
- package/dist/modules/search/service.d.ts +0 -24
- package/dist/modules/search/service.d.ts.map +0 -1
- package/dist/modules/search/service.js +0 -217
- package/dist/modules/shipping/calculator.d.ts +0 -42
- package/dist/modules/shipping/calculator.d.ts.map +0 -1
- package/dist/modules/shipping/calculator.js +0 -91
- package/dist/modules/shipping/repository/index.d.ts +0 -5
- package/dist/modules/shipping/repository/index.d.ts.map +0 -1
- package/dist/modules/shipping/repository/index.js +0 -1
- package/dist/modules/shipping/service.d.ts +0 -28
- package/dist/modules/shipping/service.d.ts.map +0 -1
- package/dist/modules/shipping/service.js +0 -20
- package/dist/modules/tax/adapter.d.ts +0 -58
- package/dist/modules/tax/adapter.d.ts.map +0 -1
- package/dist/modules/tax/adapter.js +0 -1
- package/dist/modules/tax/repository/index.d.ts +0 -5
- package/dist/modules/tax/repository/index.d.ts.map +0 -1
- package/dist/modules/tax/repository/index.js +0 -1
- package/dist/modules/tax/service.d.ts +0 -19
- package/dist/modules/tax/service.d.ts.map +0 -1
- package/dist/modules/tax/service.js +0 -34
- package/dist/modules/webhooks/hook.d.ts +0 -13
- package/dist/modules/webhooks/hook.d.ts.map +0 -1
- package/dist/modules/webhooks/hook.js +0 -29
- package/dist/modules/webhooks/repository/index.d.ts +0 -40
- package/dist/modules/webhooks/repository/index.d.ts.map +0 -1
- package/dist/modules/webhooks/repository/index.js +0 -175
- package/dist/modules/webhooks/schema.d.ts +0 -404
- package/dist/modules/webhooks/schema.d.ts.map +0 -1
- package/dist/modules/webhooks/schema.js +0 -40
- package/dist/modules/webhooks/service.d.ts +0 -23
- package/dist/modules/webhooks/service.d.ts.map +0 -1
- package/dist/modules/webhooks/service.js +0 -92
- package/dist/modules/webhooks/signing.d.ts +0 -2
- package/dist/modules/webhooks/signing.d.ts.map +0 -1
- package/dist/modules/webhooks/signing.js +0 -5
- package/dist/modules/webhooks/ssrf-guard.d.ts +0 -19
- package/dist/modules/webhooks/ssrf-guard.d.ts.map +0 -1
- package/dist/modules/webhooks/ssrf-guard.js +0 -79
- package/dist/modules/webhooks/tasks.d.ts +0 -16
- package/dist/modules/webhooks/tasks.d.ts.map +0 -1
- package/dist/modules/webhooks/tasks.js +0 -35
- package/dist/modules/webhooks/worker.d.ts +0 -21
- package/dist/modules/webhooks/worker.d.ts.map +0 -1
- package/dist/modules/webhooks/worker.js +0 -113
- package/dist/runtime/commerce.d.ts +0 -110
- package/dist/runtime/commerce.d.ts.map +0 -1
- package/dist/runtime/commerce.js +0 -37
- package/dist/runtime/kernel.d.ts +0 -71
- package/dist/runtime/kernel.d.ts.map +0 -1
- package/dist/runtime/kernel.js +0 -306
- package/dist/runtime/logger.d.ts +0 -11
- package/dist/runtime/logger.d.ts.map +0 -1
- package/dist/runtime/logger.js +0 -32
- package/dist/runtime/shutdown.d.ts +0 -15
- package/dist/runtime/shutdown.d.ts.map +0 -1
- package/dist/runtime/shutdown.js +0 -34
- package/dist/test-utils/create-pglite-adapter.d.ts +0 -32
- package/dist/test-utils/create-pglite-adapter.d.ts.map +0 -1
- package/dist/test-utils/create-pglite-adapter.js +0 -107
- package/dist/test-utils/create-plugin-test-app.d.ts +0 -50
- package/dist/test-utils/create-plugin-test-app.d.ts.map +0 -1
- package/dist/test-utils/create-plugin-test-app.js +0 -74
- package/dist/test-utils/create-repository-test-harness.d.ts +0 -8
- package/dist/test-utils/create-repository-test-harness.d.ts.map +0 -1
- package/dist/test-utils/create-repository-test-harness.js +0 -7
- package/dist/test-utils/create-test-config.d.ts +0 -18
- package/dist/test-utils/create-test-config.d.ts.map +0 -1
- package/dist/test-utils/create-test-config.js +0 -172
- package/dist/test-utils/create-test-kernel.d.ts +0 -3
- package/dist/test-utils/create-test-kernel.d.ts.map +0 -1
- package/dist/test-utils/create-test-kernel.js +0 -5
- package/dist/test-utils/create-test-plugin-context.d.ts +0 -42
- package/dist/test-utils/create-test-plugin-context.d.ts.map +0 -1
- package/dist/test-utils/create-test-plugin-context.js +0 -46
- package/dist/test-utils/rest-api-test-utils.d.ts +0 -64
- package/dist/test-utils/rest-api-test-utils.d.ts.map +0 -1
- package/dist/test-utils/rest-api-test-utils.js +0 -207
- package/dist/test-utils/test-actors.d.ts +0 -15
- package/dist/test-utils/test-actors.d.ts.map +0 -1
- package/dist/test-utils/test-actors.js +0 -57
- package/dist/test-utils/typed-hooks.d.ts +0 -43
- package/dist/test-utils/typed-hooks.d.ts.map +0 -1
- package/dist/test-utils/typed-hooks.js +0 -35
- package/dist/testing.d.ts +0 -14
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -13
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/commerce-types.d.ts +0 -34
- package/dist/types/commerce-types.d.ts.map +0 -1
- package/dist/types/commerce-types.js +0 -1
- package/dist/utils/id.d.ts +0 -2
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -3
- package/dist/utils/logger.d.ts +0 -3
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -16
- package/dist/utils/pagination.d.ts +0 -11
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -15
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
2
|
-
import { organization } from "../../auth/auth-schema.js";
|
|
3
|
-
import { sellableEntities, variants } from "../catalog/schema.js";
|
|
4
|
-
export const orders = pgTable("orders", {
|
|
5
|
-
id: uuid("id").defaultRandom().primaryKey(),
|
|
6
|
-
organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),
|
|
7
|
-
orderNumber: text("order_number").notNull(),
|
|
8
|
-
customerId: uuid("customer_id"),
|
|
9
|
-
status: text("status").notNull().default("pending"),
|
|
10
|
-
currency: text("currency").notNull(),
|
|
11
|
-
subtotal: integer("subtotal").notNull(),
|
|
12
|
-
taxTotal: integer("tax_total").notNull(),
|
|
13
|
-
shippingTotal: integer("shipping_total").notNull(),
|
|
14
|
-
discountTotal: integer("discount_total").notNull().default(0),
|
|
15
|
-
grandTotal: integer("grand_total").notNull(),
|
|
16
|
-
paymentIntentId: text("payment_intent_id"),
|
|
17
|
-
paymentMethodId: text("payment_method_id"),
|
|
18
|
-
metadata: jsonb("metadata").$type().default({}),
|
|
19
|
-
placedAt: timestamp("placed_at", { withTimezone: true }).defaultNow().notNull(),
|
|
20
|
-
fulfilledAt: timestamp("fulfilled_at", { withTimezone: true }),
|
|
21
|
-
cancelledAt: timestamp("cancelled_at", { withTimezone: true }),
|
|
22
|
-
}, (table) => ({
|
|
23
|
-
orgIdx: index("idx_orders_org").on(table.organizationId),
|
|
24
|
-
orgOrderNumberUnique: uniqueIndex("orders_org_order_number_unique").on(table.organizationId, table.orderNumber),
|
|
25
|
-
statusIdx: index("idx_orders_status").on(table.status),
|
|
26
|
-
customerIdIdx: index("idx_orders_customer_id").on(table.customerId),
|
|
27
|
-
placedAtIdx: index("idx_orders_placed_at").on(table.placedAt),
|
|
28
|
-
paymentIntentIdx: index("idx_orders_payment_intent").on(table.paymentIntentId),
|
|
29
|
-
}));
|
|
30
|
-
export const orderLineItems = pgTable("order_line_items", {
|
|
31
|
-
id: uuid("id").defaultRandom().primaryKey(),
|
|
32
|
-
orderId: uuid("order_id")
|
|
33
|
-
.references(() => orders.id, { onDelete: "cascade" })
|
|
34
|
-
.notNull(),
|
|
35
|
-
entityId: uuid("entity_id").references(() => sellableEntities.id).notNull(),
|
|
36
|
-
entityType: text("entity_type").notNull(),
|
|
37
|
-
variantId: uuid("variant_id").references(() => variants.id),
|
|
38
|
-
sku: text("sku"),
|
|
39
|
-
title: text("title").notNull(),
|
|
40
|
-
quantity: integer("quantity").notNull(),
|
|
41
|
-
unitPrice: integer("unit_price").notNull(),
|
|
42
|
-
totalPrice: integer("total_price").notNull(),
|
|
43
|
-
taxAmount: integer("tax_amount").notNull().default(0),
|
|
44
|
-
discountAmount: integer("discount_amount").notNull().default(0),
|
|
45
|
-
fulfillmentStatus: text("fulfillment_status").notNull().default("unfulfilled"),
|
|
46
|
-
metadata: jsonb("metadata").$type().default({}),
|
|
47
|
-
}, (table) => [
|
|
48
|
-
index("idx_order_line_items_order_id").on(table.orderId),
|
|
49
|
-
index("idx_order_line_items_entity_id").on(table.entityId),
|
|
50
|
-
]);
|
|
51
|
-
export const orderStatusHistory = pgTable("order_status_history", {
|
|
52
|
-
id: uuid("id").defaultRandom().primaryKey(),
|
|
53
|
-
orderId: uuid("order_id")
|
|
54
|
-
.references(() => orders.id, { onDelete: "cascade" })
|
|
55
|
-
.notNull(),
|
|
56
|
-
fromStatus: text("from_status").notNull(),
|
|
57
|
-
toStatus: text("to_status").notNull(),
|
|
58
|
-
reason: text("reason"),
|
|
59
|
-
changedBy: text("changed_by").notNull(),
|
|
60
|
-
changedAt: timestamp("changed_at", { withTimezone: true }).defaultNow().notNull(),
|
|
61
|
-
}, (table) => [
|
|
62
|
-
index("idx_order_status_history_order_id").on(table.orderId),
|
|
63
|
-
]);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { Actor } from "../../auth/types.js";
|
|
2
|
-
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
3
|
-
import { type OrderState, type StateDefinition } from "../../kernel/state-machine/machine.js";
|
|
4
|
-
import { type Result } from "../../kernel/result.js";
|
|
5
|
-
import { type Pagination } from "../../utils/pagination.js";
|
|
6
|
-
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
7
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
8
|
-
import { OrdersRepository, type Order, type OrderLineItem, type OrderStatusHistory } from "./repository/index.js";
|
|
9
|
-
export interface CreateOrderInput {
|
|
10
|
-
customerId?: string;
|
|
11
|
-
currency: string;
|
|
12
|
-
subtotal: number;
|
|
13
|
-
taxTotal: number;
|
|
14
|
-
shippingTotal: number;
|
|
15
|
-
discountTotal?: number;
|
|
16
|
-
grandTotal: number;
|
|
17
|
-
paymentIntentId?: string | undefined;
|
|
18
|
-
paymentMethodId?: string | undefined;
|
|
19
|
-
metadata?: Record<string, unknown>;
|
|
20
|
-
lineItems: Array<{
|
|
21
|
-
entityId: string;
|
|
22
|
-
entityType: string;
|
|
23
|
-
variantId?: string;
|
|
24
|
-
sku?: string;
|
|
25
|
-
title: string;
|
|
26
|
-
quantity: number;
|
|
27
|
-
unitPrice: number;
|
|
28
|
-
totalPrice: number;
|
|
29
|
-
taxAmount?: number;
|
|
30
|
-
discountAmount?: number;
|
|
31
|
-
metadata?: Record<string, unknown>;
|
|
32
|
-
}>;
|
|
33
|
-
}
|
|
34
|
-
export interface ListOrdersParams {
|
|
35
|
-
page?: number;
|
|
36
|
-
limit?: number;
|
|
37
|
-
status?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface ChangeStatusInput {
|
|
40
|
-
orderId: string;
|
|
41
|
-
newStatus: OrderState;
|
|
42
|
-
reason?: string;
|
|
43
|
-
}
|
|
44
|
-
export interface OrderServiceDeps {
|
|
45
|
-
repository: OrdersRepository;
|
|
46
|
-
hooks: HookRegistry;
|
|
47
|
-
services: Record<string, unknown>;
|
|
48
|
-
/** Custom state machine. If provided, overrides the default order transitions. */
|
|
49
|
-
stateMachine?: StateDefinition<string>;
|
|
50
|
-
/** Kernel database reference for hook contexts. Uses PluginDb to avoid circular Kernel import. */
|
|
51
|
-
kernel?: {
|
|
52
|
-
database: {
|
|
53
|
-
db: PluginDb;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export type HydratedOrder = Order & {
|
|
58
|
-
lineItems: OrderLineItem[];
|
|
59
|
-
};
|
|
60
|
-
type OrderListResult = {
|
|
61
|
-
items: HydratedOrder[];
|
|
62
|
-
pagination: Pagination;
|
|
63
|
-
};
|
|
64
|
-
export declare class OrderService {
|
|
65
|
-
private deps;
|
|
66
|
-
private readonly repo;
|
|
67
|
-
private readonly machine;
|
|
68
|
-
constructor(deps: OrderServiceDeps);
|
|
69
|
-
private hydrateOrder;
|
|
70
|
-
create(input: CreateOrderInput, actor: Actor | null, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
71
|
-
getById(id: string, actor: Actor | null, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
72
|
-
getByNumber(orderNumber: string, actor: Actor | null, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
73
|
-
list(params: ListOrdersParams, actor: Actor | null, ctx?: TxContext): Promise<Result<OrderListResult>>;
|
|
74
|
-
listByCustomer(customerId: string, params: ListOrdersParams, actor?: Actor | null, ctx?: TxContext): Promise<Result<OrderListResult>>;
|
|
75
|
-
changeStatus(input: ChangeStatusInput, actor: Actor | null, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
76
|
-
cancel(orderId: string, actor: Actor | null, reason?: string, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
77
|
-
refund(orderId: string, actor: Actor | null, reason?: string, ctx?: TxContext): Promise<Result<HydratedOrder>>;
|
|
78
|
-
getStatusHistory(orderId: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<OrderStatusHistory[]>>;
|
|
79
|
-
updateOrder(orderId: string, data: {
|
|
80
|
-
placedAt?: Date;
|
|
81
|
-
metadata?: Record<string, unknown>;
|
|
82
|
-
}, actor?: Actor | null, ctx?: TxContext): Promise<Result<Order>>;
|
|
83
|
-
}
|
|
84
|
-
export {};
|
|
85
|
-
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/orders/service.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import { resolveOrgId } from "../../auth/org.js";
|
|
2
|
-
import { assertOwnership, assertPermission } from "../../auth/permissions.js";
|
|
3
|
-
import { CommerceInvalidTransitionError, CommerceNotFoundError, CommerceValidationError, toCommerceError, } from "../../kernel/errors.js";
|
|
4
|
-
import { runAfterHooks, runBeforeHooks } from "../../kernel/hooks/executor.js";
|
|
5
|
-
import { createHookContext } from "../../kernel/hooks/create-context.js";
|
|
6
|
-
import { canTransition, orderStateMachine, } from "../../kernel/state-machine/machine.js";
|
|
7
|
-
import { Err, Ok } from "../../kernel/result.js";
|
|
8
|
-
import { createLogger } from "../../utils/logger.js";
|
|
9
|
-
import { paginate } from "../../utils/pagination.js";
|
|
10
|
-
function context(actor, services, tx = null, kernel = null) {
|
|
11
|
-
return createHookContext({
|
|
12
|
-
actor,
|
|
13
|
-
tx,
|
|
14
|
-
logger: createLogger("orders"),
|
|
15
|
-
services,
|
|
16
|
-
context: { moduleName: "orders" },
|
|
17
|
-
...(kernel != null ? { kernel } : {}),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export class OrderService {
|
|
21
|
-
deps;
|
|
22
|
-
repo;
|
|
23
|
-
machine;
|
|
24
|
-
constructor(deps) {
|
|
25
|
-
this.deps = deps;
|
|
26
|
-
this.repo = deps.repository;
|
|
27
|
-
this.machine = deps.stateMachine ?? orderStateMachine;
|
|
28
|
-
}
|
|
29
|
-
async hydrateOrder(order, ctx) {
|
|
30
|
-
const lineItems = await this.repo.findLineItemsByOrderId(order.id, ctx);
|
|
31
|
-
return { ...order, lineItems };
|
|
32
|
-
}
|
|
33
|
-
async create(input, actor, ctx) {
|
|
34
|
-
try {
|
|
35
|
-
assertPermission(actor, "orders:create");
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
return Err(toCommerceError(error));
|
|
39
|
-
}
|
|
40
|
-
if (input.lineItems.length === 0) {
|
|
41
|
-
return Err(new CommerceValidationError("Order requires at least one line item."));
|
|
42
|
-
}
|
|
43
|
-
const beforeHooks = this.deps.hooks.resolve("orders.beforeCreate");
|
|
44
|
-
const afterHooks = this.deps.hooks.resolve("orders.afterCreate");
|
|
45
|
-
const hookCtx = context(actor, this.deps.services, ctx?.tx, this.deps.kernel);
|
|
46
|
-
const processed = await runBeforeHooks(beforeHooks, input, "create", hookCtx);
|
|
47
|
-
const orderNumber = await this.repo.getNextOrderNumber(ctx);
|
|
48
|
-
const orgId = resolveOrgId(actor);
|
|
49
|
-
const order = await this.repo.create({
|
|
50
|
-
organizationId: orgId,
|
|
51
|
-
orderNumber,
|
|
52
|
-
status: "pending",
|
|
53
|
-
currency: processed.currency,
|
|
54
|
-
subtotal: processed.subtotal,
|
|
55
|
-
taxTotal: processed.taxTotal,
|
|
56
|
-
shippingTotal: processed.shippingTotal,
|
|
57
|
-
discountTotal: processed.discountTotal ?? 0,
|
|
58
|
-
grandTotal: processed.grandTotal,
|
|
59
|
-
...(processed.paymentIntentId != null ? { paymentIntentId: processed.paymentIntentId } : {}),
|
|
60
|
-
...(processed.paymentMethodId != null ? { paymentMethodId: processed.paymentMethodId } : {}),
|
|
61
|
-
metadata: processed.metadata ?? {},
|
|
62
|
-
placedAt: new Date(),
|
|
63
|
-
...(processed.customerId !== undefined
|
|
64
|
-
? { customerId: processed.customerId }
|
|
65
|
-
: {}),
|
|
66
|
-
}, ctx);
|
|
67
|
-
const lineItemsData = processed.lineItems.map((item) => ({
|
|
68
|
-
orderId: order.id,
|
|
69
|
-
entityId: item.entityId,
|
|
70
|
-
entityType: item.entityType,
|
|
71
|
-
title: item.title,
|
|
72
|
-
quantity: item.quantity,
|
|
73
|
-
unitPrice: item.unitPrice,
|
|
74
|
-
totalPrice: item.totalPrice,
|
|
75
|
-
taxAmount: item.taxAmount ?? 0,
|
|
76
|
-
discountAmount: item.discountAmount ?? 0,
|
|
77
|
-
fulfillmentStatus: "unfulfilled",
|
|
78
|
-
metadata: item.metadata ?? {},
|
|
79
|
-
...(item.variantId !== undefined ? { variantId: item.variantId } : {}),
|
|
80
|
-
...(item.sku !== undefined ? { sku: item.sku } : {}),
|
|
81
|
-
}));
|
|
82
|
-
await this.repo.createLineItems(lineItemsData, ctx);
|
|
83
|
-
await this.repo.createStatusHistory({
|
|
84
|
-
orderId: order.id,
|
|
85
|
-
fromStatus: "pending",
|
|
86
|
-
toStatus: "pending",
|
|
87
|
-
reason: "order_created",
|
|
88
|
-
changedBy: actor?.userId ?? "system",
|
|
89
|
-
}, ctx);
|
|
90
|
-
const hydrated = await this.hydrateOrder(order, ctx);
|
|
91
|
-
const report = await runAfterHooks(afterHooks, null, hydrated, "create", hookCtx);
|
|
92
|
-
return Ok(hydrated, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
93
|
-
}
|
|
94
|
-
async getById(id, actor, ctx) {
|
|
95
|
-
const orgId = resolveOrgId(actor);
|
|
96
|
-
const order = await this.repo.findById(orgId, id, ctx);
|
|
97
|
-
if (!order)
|
|
98
|
-
return Err(new CommerceNotFoundError("Order not found."));
|
|
99
|
-
try {
|
|
100
|
-
if (actor?.permissions.includes("orders:read") ||
|
|
101
|
-
actor?.permissions.includes("*:*")) {
|
|
102
|
-
// no-op
|
|
103
|
-
}
|
|
104
|
-
else if (actor?.permissions.includes("orders:read:own")) {
|
|
105
|
-
assertOwnership(actor, order.customerId ?? null);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
assertPermission(actor, "orders:read");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
return Err(toCommerceError(error));
|
|
113
|
-
}
|
|
114
|
-
const hydrated = await this.hydrateOrder(order, ctx);
|
|
115
|
-
// Run afterGet hooks — allows plugins to enrich the order (e.g., vendor fulfillment)
|
|
116
|
-
const afterGetHooks = this.deps.hooks.resolve("orders.afterGet");
|
|
117
|
-
if (afterGetHooks.length > 0) {
|
|
118
|
-
const hookCtx = context(actor, this.deps.services, ctx?.tx, this.deps.kernel);
|
|
119
|
-
await runAfterHooks(afterGetHooks, null, hydrated, "read", hookCtx);
|
|
120
|
-
}
|
|
121
|
-
return Ok(hydrated);
|
|
122
|
-
}
|
|
123
|
-
async getByNumber(orderNumber, actor, ctx) {
|
|
124
|
-
const orgId = resolveOrgId(actor);
|
|
125
|
-
const order = await this.repo.findByOrderNumber(orgId, orderNumber, ctx);
|
|
126
|
-
if (!order)
|
|
127
|
-
return Err(new CommerceNotFoundError("Order not found."));
|
|
128
|
-
return this.getById(order.id, actor, ctx);
|
|
129
|
-
}
|
|
130
|
-
async list(params, actor, ctx) {
|
|
131
|
-
try {
|
|
132
|
-
assertPermission(actor, "orders:read");
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
return Err(toCommerceError(error));
|
|
136
|
-
}
|
|
137
|
-
const orgId = resolveOrgId(actor);
|
|
138
|
-
let items;
|
|
139
|
-
if (params.status) {
|
|
140
|
-
items = await this.repo.findByStatus(orgId, params.status, ctx);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
items = await this.repo.findAll(orgId, undefined, ctx);
|
|
144
|
-
}
|
|
145
|
-
// Sort by placedAt descending (in-memory, as findAll already sorts)
|
|
146
|
-
items.sort((a, b) => b.placedAt.getTime() - a.placedAt.getTime());
|
|
147
|
-
const paged = paginate(items, params.page ?? 1, params.limit ?? 20);
|
|
148
|
-
const hydratedItems = await Promise.all(paged.items.map((order) => this.hydrateOrder(order, ctx)));
|
|
149
|
-
return Ok({
|
|
150
|
-
items: hydratedItems,
|
|
151
|
-
pagination: paged.pagination,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
async listByCustomer(customerId, params, actor, ctx) {
|
|
155
|
-
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
156
|
-
let items = await this.repo.findByCustomerId(orgId, customerId, ctx);
|
|
157
|
-
if (params.status) {
|
|
158
|
-
items = items.filter((order) => order.status === params.status);
|
|
159
|
-
}
|
|
160
|
-
items.sort((a, b) => b.placedAt.getTime() - a.placedAt.getTime());
|
|
161
|
-
const paged = paginate(items, params.page ?? 1, params.limit ?? 20);
|
|
162
|
-
const hydratedItems = await Promise.all(paged.items.map((order) => this.hydrateOrder(order, ctx)));
|
|
163
|
-
return Ok({
|
|
164
|
-
items: hydratedItems,
|
|
165
|
-
pagination: paged.pagination,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
async changeStatus(input, actor, ctx) {
|
|
169
|
-
const orgId = resolveOrgId(actor);
|
|
170
|
-
const order = await this.repo.findById(orgId, input.orderId, ctx);
|
|
171
|
-
if (!order)
|
|
172
|
-
return Err(new CommerceNotFoundError("Order not found."));
|
|
173
|
-
try {
|
|
174
|
-
assertPermission(actor, "orders:update");
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
return Err(toCommerceError(error));
|
|
178
|
-
}
|
|
179
|
-
if (!canTransition(this.machine, order.status, input.newStatus)) {
|
|
180
|
-
return Err(new CommerceInvalidTransitionError(`Cannot transition from ${order.status} to ${input.newStatus}.`));
|
|
181
|
-
}
|
|
182
|
-
const beforeHooks = this.deps.hooks.resolve("orders.beforeStatusChange");
|
|
183
|
-
const afterHooks = this.deps.hooks.resolve("orders.afterStatusChange");
|
|
184
|
-
const hookCtx = context(actor, this.deps.services, ctx?.tx, this.deps.kernel);
|
|
185
|
-
const statusHookInput = {
|
|
186
|
-
orderId: order.id,
|
|
187
|
-
fromStatus: order.status,
|
|
188
|
-
newStatus: input.newStatus,
|
|
189
|
-
...(input.reason !== undefined ? { reason: input.reason } : {}),
|
|
190
|
-
};
|
|
191
|
-
await runBeforeHooks(beforeHooks, statusHookInput, "statusChange", hookCtx);
|
|
192
|
-
const previous = order.status;
|
|
193
|
-
const lineItems = await this.repo.findLineItemsByOrderId(order.id, ctx);
|
|
194
|
-
// Handle cancellation and refund side effects
|
|
195
|
-
if (input.newStatus === "cancelled" || input.newStatus === "refunded") {
|
|
196
|
-
// 1. Release inventory reservations
|
|
197
|
-
const inventory = this.deps.services.inventory;
|
|
198
|
-
if (inventory?.release) {
|
|
199
|
-
for (const lineItem of lineItems) {
|
|
200
|
-
// Only release inventory for unfulfilled items.
|
|
201
|
-
// Fulfilled items had their reservation released during the
|
|
202
|
-
// fulfilled transition — releasing again would double-release.
|
|
203
|
-
if (lineItem.fulfillmentStatus === "unfulfilled") {
|
|
204
|
-
await inventory.release({
|
|
205
|
-
entityId: lineItem.entityId,
|
|
206
|
-
quantity: lineItem.quantity,
|
|
207
|
-
orderId: order.id,
|
|
208
|
-
performedBy: actor?.userId ?? "system",
|
|
209
|
-
...(lineItem.variantId != null
|
|
210
|
-
? { variantId: lineItem.variantId }
|
|
211
|
-
: {}),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
// 2. Refund payment (if captured)
|
|
217
|
-
const paymentIntentId = order.paymentIntentId
|
|
218
|
-
?? order.metadata?.paymentIntentId;
|
|
219
|
-
if (paymentIntentId) {
|
|
220
|
-
const payments = this.deps.services.payments;
|
|
221
|
-
if (payments?.refund) {
|
|
222
|
-
await payments.refund(paymentIntentId, order.grandTotal, input.reason ?? `order_${input.newStatus}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// 3. Void tax transaction
|
|
226
|
-
const tax = this.deps.services.tax;
|
|
227
|
-
if (tax?.voidTransaction) {
|
|
228
|
-
await tax.voidTransaction({ transactionId: order.id });
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Handle fulfillment: deduct on_hand and release reservations.
|
|
232
|
-
// Items have been shipped — on_hand decreases (stock left the warehouse)
|
|
233
|
-
// and reservations are cleared (no longer needed).
|
|
234
|
-
//
|
|
235
|
-
// Net effect per line item:
|
|
236
|
-
// on_hand -= quantity, reserved -= quantity, available unchanged
|
|
237
|
-
// Before: on_hand=100, reserved=5, available=95
|
|
238
|
-
// After: on_hand=95, reserved=0, available=95
|
|
239
|
-
if (input.newStatus === "fulfilled" || input.newStatus === "partially_fulfilled") {
|
|
240
|
-
const inventory = this.deps.services.inventory;
|
|
241
|
-
if (inventory) {
|
|
242
|
-
for (const lineItem of lineItems) {
|
|
243
|
-
if (lineItem.fulfillmentStatus === "unfulfilled") {
|
|
244
|
-
// Deduct on_hand (stock physically left warehouse)
|
|
245
|
-
await inventory.deductForFulfillment({
|
|
246
|
-
entityId: lineItem.entityId,
|
|
247
|
-
quantity: lineItem.quantity,
|
|
248
|
-
orderId: order.id,
|
|
249
|
-
...(lineItem.variantId != null
|
|
250
|
-
? { variantId: lineItem.variantId }
|
|
251
|
-
: {}),
|
|
252
|
-
});
|
|
253
|
-
// Release reservation (no longer needed)
|
|
254
|
-
await inventory.release({
|
|
255
|
-
entityId: lineItem.entityId,
|
|
256
|
-
quantity: lineItem.quantity,
|
|
257
|
-
orderId: order.id,
|
|
258
|
-
performedBy: actor?.userId ?? "system",
|
|
259
|
-
...(lineItem.variantId != null
|
|
260
|
-
? { variantId: lineItem.variantId }
|
|
261
|
-
: {}),
|
|
262
|
-
});
|
|
263
|
-
// Mark line item as fulfilled
|
|
264
|
-
await this.repo.updateLineItem(lineItem.id, { fulfillmentStatus: "fulfilled" }, ctx);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
// Update order status with atomic guard on current status
|
|
270
|
-
const updated = await this.repo.updateStatus(order.id, previous, input.newStatus, ctx);
|
|
271
|
-
if (!updated) {
|
|
272
|
-
return Err(new CommerceValidationError(`Order status changed concurrently. Refresh and retry.`));
|
|
273
|
-
}
|
|
274
|
-
await this.repo.createStatusHistory({
|
|
275
|
-
orderId: order.id,
|
|
276
|
-
fromStatus: previous,
|
|
277
|
-
toStatus: input.newStatus,
|
|
278
|
-
changedBy: actor?.userId ?? "system",
|
|
279
|
-
...(input.reason !== undefined ? { reason: input.reason } : {}),
|
|
280
|
-
}, ctx);
|
|
281
|
-
// Audit logging is now automatic via audit hooks (RFC-005)
|
|
282
|
-
// registered in kernel boot — no manual audit.record() needed.
|
|
283
|
-
const hydrated = await this.hydrateOrder(updated, ctx);
|
|
284
|
-
const report = await runAfterHooks(afterHooks, null, hydrated, "statusChange", hookCtx);
|
|
285
|
-
return Ok(hydrated, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
286
|
-
}
|
|
287
|
-
async cancel(orderId, actor, reason = "cancelled_by_user", ctx) {
|
|
288
|
-
return this.changeStatus({ orderId, newStatus: "cancelled", reason }, actor, ctx);
|
|
289
|
-
}
|
|
290
|
-
async refund(orderId, actor, reason = "refunded", ctx) {
|
|
291
|
-
return this.changeStatus({ orderId, newStatus: "refunded", reason }, actor, ctx);
|
|
292
|
-
}
|
|
293
|
-
async getStatusHistory(orderId, actor, ctx) {
|
|
294
|
-
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
295
|
-
const order = await this.repo.findById(orgId, orderId, ctx);
|
|
296
|
-
if (!order) {
|
|
297
|
-
return Err(new CommerceNotFoundError("Order not found."));
|
|
298
|
-
}
|
|
299
|
-
const items = await this.repo.findStatusHistoryByOrderId(orderId, ctx);
|
|
300
|
-
// Sort by changedAt ascending (oldest first)
|
|
301
|
-
items.sort((a, b) => a.changedAt.getTime() - b.changedAt.getTime());
|
|
302
|
-
return Ok(items);
|
|
303
|
-
}
|
|
304
|
-
async updateOrder(orderId, data, actor, ctx) {
|
|
305
|
-
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
306
|
-
const order = await this.repo.findById(orgId, orderId, ctx);
|
|
307
|
-
if (!order) {
|
|
308
|
-
return Err(new CommerceNotFoundError("Order not found."));
|
|
309
|
-
}
|
|
310
|
-
const updated = await this.repo.update(orderId, data, ctx);
|
|
311
|
-
return Ok(updated);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { TaskDefinition } from "../../kernel/jobs/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Stale Order Cleanup Task
|
|
4
|
-
*
|
|
5
|
-
* Cancels orders stuck in "pending" status for longer than the configured
|
|
6
|
-
* threshold (default: 48 hours). This releases reserved inventory and
|
|
7
|
-
* refunds captured payments, preventing phantom stock loss from abandoned
|
|
8
|
-
* orders.
|
|
9
|
-
*
|
|
10
|
-
* Register via config.jobs.tasks:
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { staleOrderCleanupTask } from "@unifiedcommerce/core";
|
|
13
|
-
* defineConfig({
|
|
14
|
-
* jobs: {
|
|
15
|
-
* tasks: [staleOrderCleanupTask],
|
|
16
|
-
* autorun: { enabled: true, intervalMs: 3600_000 }, // hourly
|
|
17
|
-
* },
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const staleOrderCleanupTask: TaskDefinition<{
|
|
22
|
-
thresholdHours?: number;
|
|
23
|
-
}, {
|
|
24
|
-
cancelledCount: number;
|
|
25
|
-
orderIds: string[];
|
|
26
|
-
}>;
|
|
27
|
-
//# sourceMappingURL=stale-order-cleanup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stale-order-cleanup.d.ts","sourceRoot":"","sources":["../../../src/modules/orders/stale-order-cleanup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,4BAA4B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAChD;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3B;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAkD/C,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { eq, and, lt } from "drizzle-orm";
|
|
2
|
-
import { orders } from "./schema.js";
|
|
3
|
-
/**
|
|
4
|
-
* Stale Order Cleanup Task
|
|
5
|
-
*
|
|
6
|
-
* Cancels orders stuck in "pending" status for longer than the configured
|
|
7
|
-
* threshold (default: 48 hours). This releases reserved inventory and
|
|
8
|
-
* refunds captured payments, preventing phantom stock loss from abandoned
|
|
9
|
-
* orders.
|
|
10
|
-
*
|
|
11
|
-
* Register via config.jobs.tasks:
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { staleOrderCleanupTask } from "@unifiedcommerce/core";
|
|
14
|
-
* defineConfig({
|
|
15
|
-
* jobs: {
|
|
16
|
-
* tasks: [staleOrderCleanupTask],
|
|
17
|
-
* autorun: { enabled: true, intervalMs: 3600_000 }, // hourly
|
|
18
|
-
* },
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const staleOrderCleanupTask = {
|
|
23
|
-
slug: "orders/stale-cleanup",
|
|
24
|
-
async handler({ input, ctx }) {
|
|
25
|
-
const thresholdHours = input.thresholdHours ?? 48;
|
|
26
|
-
const cutoff = new Date(Date.now() - thresholdHours * 60 * 60 * 1000);
|
|
27
|
-
// Find stale pending orders
|
|
28
|
-
const staleOrders = await ctx.db
|
|
29
|
-
.select()
|
|
30
|
-
.from(orders)
|
|
31
|
-
.where(and(eq(orders.status, "pending"), lt(orders.placedAt, cutoff)));
|
|
32
|
-
const cancelledIds = [];
|
|
33
|
-
// Cancel each stale order via the service (triggers inventory release + payment refund)
|
|
34
|
-
const orderService = ctx.services.orders;
|
|
35
|
-
for (const order of staleOrders) {
|
|
36
|
-
try {
|
|
37
|
-
await orderService.cancel(order.id, null, `Auto-cancelled: pending for >${thresholdHours}h`);
|
|
38
|
-
cancelledIds.push(order.id);
|
|
39
|
-
ctx.logger.info(`Stale order ${order.orderNumber} auto-cancelled`, {
|
|
40
|
-
orderId: order.id,
|
|
41
|
-
placedAt: order.placedAt,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
ctx.logger.error(`Failed to cancel stale order ${order.orderNumber}`, { error });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
output: {
|
|
50
|
-
cancelledCount: cancelledIds.length,
|
|
51
|
-
orderIds: cancelledIds,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OrganizationService — wraps Better Auth's server-side organization API.
|
|
3
|
-
*
|
|
4
|
-
* When auth.api is available (server context), uses Better Auth's
|
|
5
|
-
* createOrganization which properly creates org + member records.
|
|
6
|
-
*
|
|
7
|
-
* When auth is not available (kernel-only scripts), falls back to
|
|
8
|
-
* direct Drizzle insert into the organization table.
|
|
9
|
-
*/
|
|
10
|
-
import type { AuthInstance } from "../../auth/setup.js";
|
|
11
|
-
interface Result<T> {
|
|
12
|
-
ok: true;
|
|
13
|
-
value: T;
|
|
14
|
-
}
|
|
15
|
-
interface ResultErr {
|
|
16
|
-
ok: false;
|
|
17
|
-
error: string;
|
|
18
|
-
}
|
|
19
|
-
export interface Organization {
|
|
20
|
-
id: string;
|
|
21
|
-
name: string;
|
|
22
|
-
slug: string;
|
|
23
|
-
logo?: string | null;
|
|
24
|
-
metadata?: string | null;
|
|
25
|
-
createdAt: Date;
|
|
26
|
-
}
|
|
27
|
-
export interface OrganizationCreateInput {
|
|
28
|
-
id?: string;
|
|
29
|
-
name: string;
|
|
30
|
-
slug: string;
|
|
31
|
-
userId?: string;
|
|
32
|
-
logo?: string;
|
|
33
|
-
metadata?: Record<string, unknown>;
|
|
34
|
-
}
|
|
35
|
-
export declare class OrganizationService {
|
|
36
|
-
private auth;
|
|
37
|
-
private db;
|
|
38
|
-
constructor(db: unknown, auth?: AuthInstance | null);
|
|
39
|
-
/**
|
|
40
|
-
* Create an organization.
|
|
41
|
-
*
|
|
42
|
-
* If auth.api is available, uses Better Auth's createOrganization
|
|
43
|
-
* which creates both the org and a member record for the creator.
|
|
44
|
-
*
|
|
45
|
-
* If auth is not available, falls back to direct Drizzle insert
|
|
46
|
-
* and manually creates a member record if userId is provided.
|
|
47
|
-
*/
|
|
48
|
-
create(input: OrganizationCreateInput): Promise<Result<Organization> | ResultErr>;
|
|
49
|
-
getById(id: string): Promise<Result<Organization> | ResultErr>;
|
|
50
|
-
list(): Promise<Result<Organization[]>>;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
53
|
-
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/organization/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,UAAU,MAAM,CAAC,CAAC;IAAI,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE;AAC1C,UAAU,SAAS;IAAG,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAIhD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,EAAE,CAAY;gBAEV,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI;IAKnD;;;;;;;;OAQG;IACG,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IAsGjF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IAmB9D,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;CAW9C"}
|