@unifiedcommerce/core 0.1.0 → 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 (174) hide show
  1. package/package.json +1 -2
  2. package/src/adapters/console-email.ts +0 -43
  3. package/src/auth/access.ts +0 -187
  4. package/src/auth/auth-schema.ts +0 -139
  5. package/src/auth/middleware.ts +0 -161
  6. package/src/auth/org.ts +0 -41
  7. package/src/auth/permissions.ts +0 -28
  8. package/src/auth/setup.ts +0 -169
  9. package/src/auth/system-actor.ts +0 -19
  10. package/src/auth/types.ts +0 -10
  11. package/src/config/defaults.ts +0 -82
  12. package/src/config/define-config.ts +0 -53
  13. package/src/config/types.ts +0 -299
  14. package/src/generated/plugin-capabilities.d.ts +0 -20
  15. package/src/generated/plugin-manifest.ts +0 -23
  16. package/src/generated/plugin-repositories.d.ts +0 -20
  17. package/src/hooks/checkout-completion.ts +0 -262
  18. package/src/hooks/checkout.ts +0 -677
  19. package/src/hooks/order-emails.ts +0 -62
  20. package/src/index.ts +0 -214
  21. package/src/interfaces/mcp/agent-prompt.ts +0 -174
  22. package/src/interfaces/mcp/context-enrichment.ts +0 -177
  23. package/src/interfaces/mcp/server.ts +0 -617
  24. package/src/interfaces/mcp/transport.ts +0 -68
  25. package/src/interfaces/rest/customer-portal.ts +0 -299
  26. package/src/interfaces/rest/index.ts +0 -74
  27. package/src/interfaces/rest/router.ts +0 -334
  28. package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
  29. package/src/interfaces/rest/routes/audit.ts +0 -50
  30. package/src/interfaces/rest/routes/carts.ts +0 -89
  31. package/src/interfaces/rest/routes/catalog.ts +0 -493
  32. package/src/interfaces/rest/routes/checkout.ts +0 -283
  33. package/src/interfaces/rest/routes/inventory.ts +0 -70
  34. package/src/interfaces/rest/routes/media.ts +0 -86
  35. package/src/interfaces/rest/routes/orders.ts +0 -78
  36. package/src/interfaces/rest/routes/payments.ts +0 -60
  37. package/src/interfaces/rest/routes/pricing.ts +0 -57
  38. package/src/interfaces/rest/routes/promotions.ts +0 -92
  39. package/src/interfaces/rest/routes/search.ts +0 -71
  40. package/src/interfaces/rest/routes/webhooks.ts +0 -46
  41. package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
  42. package/src/interfaces/rest/schemas/audit.ts +0 -46
  43. package/src/interfaces/rest/schemas/carts.ts +0 -125
  44. package/src/interfaces/rest/schemas/catalog.ts +0 -450
  45. package/src/interfaces/rest/schemas/checkout.ts +0 -66
  46. package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
  47. package/src/interfaces/rest/schemas/inventory.ts +0 -138
  48. package/src/interfaces/rest/schemas/media.ts +0 -75
  49. package/src/interfaces/rest/schemas/orders.ts +0 -104
  50. package/src/interfaces/rest/schemas/pricing.ts +0 -80
  51. package/src/interfaces/rest/schemas/promotions.ts +0 -110
  52. package/src/interfaces/rest/schemas/responses.ts +0 -85
  53. package/src/interfaces/rest/schemas/search.ts +0 -58
  54. package/src/interfaces/rest/schemas/shared.ts +0 -62
  55. package/src/interfaces/rest/schemas/webhooks.ts +0 -68
  56. package/src/interfaces/rest/utils.ts +0 -104
  57. package/src/interfaces/rest/webhook-router.ts +0 -50
  58. package/src/kernel/compensation/executor.ts +0 -61
  59. package/src/kernel/compensation/types.ts +0 -26
  60. package/src/kernel/database/adapter.ts +0 -13
  61. package/src/kernel/database/drizzle-db.ts +0 -56
  62. package/src/kernel/database/migrate.ts +0 -76
  63. package/src/kernel/database/plugin-types.ts +0 -34
  64. package/src/kernel/database/schema.ts +0 -49
  65. package/src/kernel/database/scoped-db.ts +0 -68
  66. package/src/kernel/database/tx-context.ts +0 -46
  67. package/src/kernel/error-mapper.ts +0 -15
  68. package/src/kernel/errors.ts +0 -89
  69. package/src/kernel/factory/repository-factory.ts +0 -242
  70. package/src/kernel/hooks/create-context.ts +0 -43
  71. package/src/kernel/hooks/executor.ts +0 -88
  72. package/src/kernel/hooks/registry.ts +0 -74
  73. package/src/kernel/hooks/types.ts +0 -52
  74. package/src/kernel/http-error.ts +0 -44
  75. package/src/kernel/jobs/adapter.ts +0 -36
  76. package/src/kernel/jobs/drizzle-adapter.ts +0 -58
  77. package/src/kernel/jobs/runner.ts +0 -153
  78. package/src/kernel/jobs/schema.ts +0 -46
  79. package/src/kernel/jobs/types.ts +0 -30
  80. package/src/kernel/local-api.ts +0 -185
  81. package/src/kernel/plugin/manifest.ts +0 -253
  82. package/src/kernel/query/executor.ts +0 -184
  83. package/src/kernel/query/registry.ts +0 -46
  84. package/src/kernel/result.ts +0 -33
  85. package/src/kernel/schema/extra-columns.ts +0 -37
  86. package/src/kernel/service-registry.ts +0 -76
  87. package/src/kernel/service-timing.ts +0 -89
  88. package/src/kernel/state-machine/machine.ts +0 -101
  89. package/src/modules/analytics/drizzle-adapter.ts +0 -426
  90. package/src/modules/analytics/hooks.ts +0 -11
  91. package/src/modules/analytics/models.ts +0 -125
  92. package/src/modules/analytics/repository/index.ts +0 -6
  93. package/src/modules/analytics/service.ts +0 -245
  94. package/src/modules/analytics/types.ts +0 -180
  95. package/src/modules/audit/hooks.ts +0 -78
  96. package/src/modules/audit/schema.ts +0 -33
  97. package/src/modules/audit/service.ts +0 -151
  98. package/src/modules/cart/access.ts +0 -27
  99. package/src/modules/cart/matcher.ts +0 -26
  100. package/src/modules/cart/repository/index.ts +0 -234
  101. package/src/modules/cart/schema.ts +0 -42
  102. package/src/modules/cart/schemas.ts +0 -38
  103. package/src/modules/cart/service.ts +0 -541
  104. package/src/modules/catalog/repository/index.ts +0 -772
  105. package/src/modules/catalog/schema.ts +0 -203
  106. package/src/modules/catalog/schemas.ts +0 -104
  107. package/src/modules/catalog/service.ts +0 -1544
  108. package/src/modules/customers/repository/index.ts +0 -327
  109. package/src/modules/customers/schema.ts +0 -64
  110. package/src/modules/customers/service.ts +0 -171
  111. package/src/modules/fulfillment/repository/index.ts +0 -426
  112. package/src/modules/fulfillment/schema.ts +0 -101
  113. package/src/modules/fulfillment/service.ts +0 -555
  114. package/src/modules/fulfillment/types.ts +0 -59
  115. package/src/modules/inventory/repository/index.ts +0 -509
  116. package/src/modules/inventory/schema.ts +0 -94
  117. package/src/modules/inventory/schemas.ts +0 -38
  118. package/src/modules/inventory/service.ts +0 -490
  119. package/src/modules/media/adapter.ts +0 -17
  120. package/src/modules/media/repository/index.ts +0 -274
  121. package/src/modules/media/schema.ts +0 -41
  122. package/src/modules/media/service.ts +0 -151
  123. package/src/modules/orders/repository/index.ts +0 -287
  124. package/src/modules/orders/schema.ts +0 -66
  125. package/src/modules/orders/service.ts +0 -619
  126. package/src/modules/orders/stale-order-cleanup.ts +0 -76
  127. package/src/modules/organization/service.ts +0 -191
  128. package/src/modules/payments/adapter.ts +0 -47
  129. package/src/modules/payments/repository/index.ts +0 -6
  130. package/src/modules/payments/service.ts +0 -107
  131. package/src/modules/pricing/repository/index.ts +0 -291
  132. package/src/modules/pricing/schema.ts +0 -71
  133. package/src/modules/pricing/schemas.ts +0 -38
  134. package/src/modules/pricing/service.ts +0 -494
  135. package/src/modules/promotions/repository/index.ts +0 -325
  136. package/src/modules/promotions/schema.ts +0 -62
  137. package/src/modules/promotions/schemas.ts +0 -38
  138. package/src/modules/promotions/service.ts +0 -598
  139. package/src/modules/search/adapter.ts +0 -57
  140. package/src/modules/search/hooks.ts +0 -12
  141. package/src/modules/search/repository/index.ts +0 -6
  142. package/src/modules/search/service.ts +0 -315
  143. package/src/modules/shipping/calculator.ts +0 -188
  144. package/src/modules/shipping/repository/index.ts +0 -6
  145. package/src/modules/shipping/service.ts +0 -51
  146. package/src/modules/tax/adapter.ts +0 -60
  147. package/src/modules/tax/repository/index.ts +0 -6
  148. package/src/modules/tax/service.ts +0 -53
  149. package/src/modules/webhooks/hook.ts +0 -34
  150. package/src/modules/webhooks/repository/index.ts +0 -278
  151. package/src/modules/webhooks/schema.ts +0 -56
  152. package/src/modules/webhooks/service.ts +0 -117
  153. package/src/modules/webhooks/signing.ts +0 -6
  154. package/src/modules/webhooks/ssrf-guard.ts +0 -71
  155. package/src/modules/webhooks/tasks.ts +0 -52
  156. package/src/modules/webhooks/worker.ts +0 -134
  157. package/src/runtime/commerce.ts +0 -145
  158. package/src/runtime/kernel.ts +0 -419
  159. package/src/runtime/logger.ts +0 -36
  160. package/src/runtime/server.ts +0 -349
  161. package/src/runtime/shutdown.ts +0 -43
  162. package/src/test-utils/create-pglite-adapter.ts +0 -129
  163. package/src/test-utils/create-plugin-test-app.ts +0 -128
  164. package/src/test-utils/create-repository-test-harness.ts +0 -16
  165. package/src/test-utils/create-test-config.ts +0 -190
  166. package/src/test-utils/create-test-kernel.ts +0 -7
  167. package/src/test-utils/create-test-plugin-context.ts +0 -75
  168. package/src/test-utils/rest-api-test-utils.ts +0 -265
  169. package/src/test-utils/test-actors.ts +0 -62
  170. package/src/test-utils/typed-hooks.ts +0 -54
  171. package/src/types/commerce-types.ts +0 -34
  172. package/src/utils/id.ts +0 -3
  173. package/src/utils/logger.ts +0 -18
  174. package/src/utils/pagination.ts +0 -22
package/src/auth/setup.ts DELETED
@@ -1,169 +0,0 @@
1
- import { drizzleAdapter } from "@better-auth/drizzle-adapter";
2
- import { betterAuth } from "better-auth";
3
- import type { Role } from "better-auth/plugins/access";
4
- import { apiKey } from "@better-auth/api-key";
5
- import { organization, twoFactor, phoneNumber, jwt, bearer } from "better-auth/plugins";
6
- import type { CommerceConfig } from "../config/types.js";
7
- import type { DatabaseAdapter } from "../kernel/database/adapter.js";
8
- import * as authSchema from "./auth-schema.js";
9
-
10
- type BetterAuthDbProvider = "pg" | "mysql" | "sqlite";
11
-
12
- function resolveAuthDbProvider(provider: string): BetterAuthDbProvider {
13
- if (
14
- provider === "postgres" ||
15
- provider === "postgresql" ||
16
- provider === "pg"
17
- ) {
18
- return "pg";
19
- }
20
- if (provider === "mysql") {
21
- return "mysql";
22
- }
23
- if (provider === "sqlite") {
24
- return "sqlite";
25
- }
26
- throw new Error(
27
- `Unsupported auth database provider "${provider}". Expected one of: postgres, mysql, sqlite.`,
28
- );
29
- }
30
-
31
- interface AuthEmailPayload {
32
- user: {
33
- email: string;
34
- name: string | null;
35
- };
36
- url: string;
37
- }
38
-
39
- export interface AuthInstance {
40
- handler(request: Request): Promise<Response>;
41
- api: {
42
- getSession(input: { headers: Headers }): Promise<unknown>;
43
- getActiveMemberRole?: (input: { headers: Headers }) => Promise<unknown>;
44
- verifyApiKey?: (input: {
45
- body: { key: string; permissions?: Record<string, string[]> };
46
- }) => Promise<{
47
- valid: boolean;
48
- error: { message: string; code: string } | null;
49
- key: Record<string, unknown> | null;
50
- }>;
51
- createApiKey?: (input: {
52
- body: {
53
- name?: string;
54
- permissions?: Record<string, string[]>;
55
- userId?: string;
56
- };
57
- headers?: Headers;
58
- }) => Promise<{ key: string; id: string }>;
59
- /** Allow access to other Better Auth API methods added by plugins */
60
- [key: string]: unknown;
61
- };
62
- options?: Record<string, unknown>;
63
- $context?: Promise<unknown>;
64
- }
65
-
66
- export function createAuth(
67
- db: DatabaseAdapter,
68
- config: CommerceConfig,
69
- ): AuthInstance {
70
- const plugins: Array<
71
- | ReturnType<typeof organization>
72
- | ReturnType<typeof twoFactor>
73
- | ReturnType<typeof apiKey>
74
- | ReturnType<typeof phoneNumber>
75
- | ReturnType<typeof jwt>
76
- | ReturnType<typeof bearer>
77
- > = [
78
- organization({
79
- roles: (config.auth?.roles ?? {}) as unknown as Record<
80
- string,
81
- Role | undefined
82
- >,
83
- }),
84
- bearer(),
85
- jwt(),
86
- ];
87
-
88
- if (config.auth?.twoFactor?.enabled) {
89
- plugins.push(twoFactor({ issuer: config.storeName ?? "UnifiedCommerce" }));
90
- }
91
-
92
- if (config.auth?.apiKeys?.enabled) {
93
- plugins.push(apiKey());
94
- }
95
-
96
- if (config.auth?.phoneAuth) {
97
- plugins.push(phoneNumber({
98
- sendOTP: config.auth.phoneAuth.sendOTP,
99
- verifyOTP: config.auth.phoneAuth.verifyOTP,
100
- otpLength: config.auth.phoneAuth.otpLength ?? 6,
101
- expiresIn: config.auth.phoneAuth.expiresIn ?? 300,
102
- signUpOnVerification: config.auth.phoneAuth.signUpOnVerification ?? {
103
- getTempEmail: (phone: string) => `${phone.replace(/\+/g, "")}@phone.local`,
104
- },
105
- }));
106
- }
107
-
108
- // API key support can be attached via external plugin package in newer better-auth versions.
109
-
110
- try {
111
- const auth = betterAuth({
112
- database: drizzleAdapter(db.db as Record<string, unknown>, {
113
- provider: resolveAuthDbProvider(db.provider),
114
- schema: authSchema,
115
- }),
116
- trustedOrigins: config.auth?.trustedOrigins ?? [],
117
- emailAndPassword: {
118
- enabled: true,
119
- requireEmailVerification: config.auth?.requireEmailVerification ?? true,
120
- sendResetPassword: async ({ user, url }: AuthEmailPayload) => {
121
- if (!config.email) return;
122
- await config.email.send({
123
- template: "password-reset",
124
- to: user.email,
125
- data: { resetUrl: url, userName: user.name },
126
- });
127
- },
128
- sendVerificationEmail: async ({ user, url }: AuthEmailPayload) => {
129
- if (!config.email) return;
130
- await config.email.send({
131
- template: "email-verification",
132
- to: user.email,
133
- data: { verifyUrl: url, userName: user.name },
134
- });
135
- },
136
- },
137
- socialProviders: config.auth?.socialProviders ?? {},
138
- session: {
139
- expiresIn: config.auth?.sessionDuration ?? 60 * 60 * 24 * 7,
140
- updateAge: 60 * 60 * 24,
141
- cookieCache: {
142
- enabled: true,
143
- maxAge: 60 * 5, // 5 minute cookie cache for performance
144
- },
145
- },
146
- advanced: {
147
- cookiePrefix: "uc",
148
- useSecureCookies: process.env.NODE_ENV === "production",
149
- },
150
- plugins,
151
- user: {
152
- additionalFields: {
153
- vendorId: { type: "string", required: false },
154
- posOperatorPin: { type: "string", required: false },
155
- },
156
- },
157
- });
158
- // Better Auth's plugin-extended return type doesn't structurally overlap
159
- // with our simplified AuthInstance interface. The double-cast bridges the
160
- // generic plugin union with our narrowed AuthInstance shape.
161
- return auth as unknown as AuthInstance;
162
- } catch (error) {
163
- const message =
164
- error instanceof Error
165
- ? error.message
166
- : "Unknown better-auth initialization error.";
167
- throw new Error(`Failed to initialize authentication: ${message}`);
168
- }
169
- }
@@ -1,19 +0,0 @@
1
- import type { Actor } from "./types.js";
2
- import { DEFAULT_ORG_ID } from "./org.js";
3
-
4
- /**
5
- * Creates a system actor for internal operations (webhooks, jobs, compensation chains).
6
- * System actors have full permissions and are scoped to a specific organization.
7
- */
8
- export function createSystemActor(orgId: string = DEFAULT_ORG_ID): Actor {
9
- return {
10
- type: "api_key",
11
- userId: "system:internal",
12
- email: null,
13
- name: "System",
14
- vendorId: null,
15
- organizationId: orgId,
16
- role: "system",
17
- permissions: ["*:*"],
18
- };
19
- }
package/src/auth/types.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface Actor {
2
- type: "user" | "api_key";
3
- userId: string;
4
- email: string | null;
5
- name: string;
6
- vendorId: string | null;
7
- organizationId: string | null;
8
- role: string;
9
- permissions: string[];
10
- }
@@ -1,82 +0,0 @@
1
- import type { CommerceConfig } from "./types.js";
2
-
3
- export const defaultConfig: Partial<CommerceConfig> = {
4
- version: "0.0.1",
5
- auth: {
6
- requireEmailVerification: true,
7
- sessionDuration: 60 * 60 * 24 * 7,
8
- twoFactor: { enabled: false },
9
- apiKeys: { enabled: false },
10
- posPin: { enabled: false },
11
- roles: {
12
- owner: { permissions: ["*:*"] },
13
- admin: { permissions: ["*:*"] },
14
- manager: {
15
- permissions: [
16
- "catalog:create",
17
- "catalog:update",
18
- "catalog:delete",
19
- "catalog:read",
20
- "inventory:read",
21
- "inventory:adjust",
22
- "orders:read",
23
- "orders:update",
24
- "cart:create",
25
- "cart:update",
26
- "customers:read:self",
27
- "customers:update:self",
28
- ],
29
- },
30
- customer: {
31
- permissions: [
32
- "catalog:read",
33
- "cart:create",
34
- "cart:read",
35
- "cart:update",
36
- "orders:create",
37
- "orders:read:own",
38
- "customers:read:self",
39
- "customers:update:self",
40
- ],
41
- },
42
- },
43
- customerPermissions: [
44
- "catalog:read",
45
- "cart:create",
46
- "cart:read",
47
- "cart:update",
48
- "orders:create",
49
- "orders:read:own",
50
- "customers:read:self",
51
- "customers:update:self",
52
- ],
53
- },
54
- cart: {
55
- ttlMinutes: 60 * 24 * 7,
56
- hooks: {},
57
- },
58
- checkout: {
59
- hooks: {
60
- beforeCreate: [],
61
- afterCreate: [],
62
- },
63
- },
64
- orders: {
65
- hooks: {
66
- beforeCreate: [],
67
- afterCreate: [],
68
- beforeStatusChange: [],
69
- afterStatusChange: [],
70
- beforeDelete: [],
71
- },
72
- },
73
- inventory: {
74
- hooks: {
75
- afterAdjust: [],
76
- },
77
- },
78
- mcp: {
79
- enabled: true,
80
- capabilities: ["catalog:read", "orders:read", "inventory:read"],
81
- },
82
- };
@@ -1,53 +0,0 @@
1
- import { defaultConfig } from "./defaults.js";
2
- import type { CommerceConfig, DefineConfigInput } from "./types.js";
3
- import { _resetRegisteredPlugins } from "../kernel/plugin/manifest.js";
4
-
5
- function isRecord(value: unknown): value is Record<string, unknown> {
6
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
7
- }
8
-
9
- function merge<T extends object>(base: T, next: Partial<T>): T {
10
- const output: Record<string, unknown> = {
11
- ...(base as Record<string, unknown>),
12
- };
13
- for (const [key, value] of Object.entries(next as Record<string, unknown>)) {
14
- if (value === undefined) continue;
15
- const baseValue = output[key];
16
- if (
17
- isRecord(value) &&
18
- isRecord(baseValue)
19
- ) {
20
- output[key] = merge(baseValue, value);
21
- } else {
22
- output[key] = value;
23
- }
24
- }
25
- return output as T;
26
- }
27
-
28
- /**
29
- * Builds the final CommerceConfig by:
30
- * 1. Merging user input with defaults
31
- * 2. Applying all plugins (each is a config transform function)
32
- * 3. Freezing the result to prevent runtime mutation
33
- */
34
- export async function defineConfig(
35
- input: DefineConfigInput,
36
- ): Promise<CommerceConfig> {
37
- let config = merge(defaultConfig as CommerceConfig, input);
38
-
39
- // Merge top-level `schema` into `customSchemas` before plugins run
40
- if (config.schema?.length) {
41
- config = {
42
- ...config,
43
- customSchemas: [...(config.customSchemas ?? []), ...config.schema],
44
- };
45
- }
46
-
47
- _resetRegisteredPlugins();
48
- for (const plugin of config.plugins ?? []) {
49
- config = await plugin(config);
50
- }
51
-
52
- return Object.freeze(config);
53
- }
@@ -1,299 +0,0 @@
1
- import type { Hono, MiddlewareHandler } from "hono";
2
- import type { Actor } from "../auth/types.js";
3
- import type { BeforeHook, AfterHook } from "../kernel/hooks/types.js";
4
- import type { PaymentAdapter } from "../modules/payments/adapter.js";
5
- import type { StorageAdapter } from "../modules/media/adapter.js";
6
- import type { DatabaseAdapter } from "../kernel/database/adapter.js";
7
- import type { TaxAdapter } from "../modules/tax/adapter.js";
8
- import type { SearchAdapter } from "../modules/search/adapter.js";
9
- import type { JobsAdapter } from "../kernel/jobs/adapter.js";
10
- import type { TaskDefinition } from "../kernel/jobs/types.js";
11
-
12
- export interface RoleDefinition {
13
- permissions: string[];
14
- }
15
-
16
- export type FieldType = "text" | "number" | "boolean" | "date" | "json" | "relation" | "select";
17
-
18
- export interface EntityFieldDefinition {
19
- name: string;
20
- type: FieldType;
21
- unit?: string;
22
- schema?: unknown;
23
- target?: string;
24
- options?: string[];
25
- }
26
-
27
- export interface EntityVariantConfig {
28
- enabled: boolean;
29
- optionTypes?: string[];
30
- }
31
-
32
- export interface EntityHooks {
33
- beforeCreate?: BeforeHook<unknown>[];
34
- afterCreate?: AfterHook<unknown>[];
35
- beforeUpdate?: BeforeHook<unknown>[];
36
- afterUpdate?: AfterHook<unknown>[];
37
- beforeDelete?: BeforeHook<unknown>[];
38
- afterDelete?: AfterHook<unknown>[];
39
- beforeRead?: BeforeHook<unknown>[];
40
- afterRead?: AfterHook<unknown>[];
41
- beforeList?: BeforeHook<unknown>[];
42
- afterList?: AfterHook<unknown>[];
43
- }
44
-
45
- export interface EntityConfig {
46
- fields: EntityFieldDefinition[];
47
- variants: EntityVariantConfig;
48
- fulfillment: string;
49
- hooks?: EntityHooks;
50
- }
51
-
52
- export interface AuthConfig {
53
- requireEmailVerification?: boolean;
54
- sessionDuration?: number;
55
- socialProviders?: Record<string, { clientId: string; clientSecret: string }>;
56
- twoFactor?: { enabled: boolean; requiredForRoles?: string[] };
57
- apiKeys?: {
58
- enabled: boolean;
59
- /** Default permissions for API keys that don't specify their own. */
60
- defaultPermissions?: string[];
61
- };
62
- posPin?: { enabled: boolean };
63
- roles?: Record<string, RoleDefinition>;
64
- customerPermissions?: string[];
65
- /** Origins allowed for CSRF protection (Better Auth `trustedOrigins`). */
66
- trustedOrigins?: string[];
67
- /** Enable a config-driven dev API key. OFF by default. Only for local development. */
68
- enableDevKey?: boolean;
69
- /** Custom dev key value. Must be set alongside enableDevKey. */
70
- devKey?: string;
71
- /**
72
- * Phone number OTP authentication via Better Auth's phoneNumber plugin.
73
- * When configured, users can sign in/up with phone + OTP instead of email/password.
74
- * You provide the SMS delivery callback; Better Auth handles OTP generation,
75
- * storage, expiry, brute force protection, and session creation.
76
- */
77
- phoneAuth?: {
78
- /** Send OTP to the phone number. Implement with Twilio, AWS SNS, or any SMS gateway. */
79
- sendOTP: (params: { phoneNumber: string; code: string }, ctx: unknown) => void | Promise<void>;
80
- /** Optional custom OTP verification (e.g., Twilio Verify). Overrides internal logic. */
81
- verifyOTP?: (params: { phoneNumber: string; code: string }, ctx: unknown) => boolean | Promise<boolean>;
82
- /** OTP length. Default: 6. */
83
- otpLength?: number;
84
- /** OTP expiry in seconds. Default: 300 (5 minutes). */
85
- expiresIn?: number;
86
- /** Auto-create user on first OTP verification. Default: generates temp email from phone. */
87
- signUpOnVerification?: {
88
- getTempEmail: (phoneNumber: string) => string;
89
- getTempName?: (phoneNumber: string) => string;
90
- };
91
- };
92
- }
93
-
94
- export interface CartConfig {
95
- ttlMinutes?: number;
96
- hooks?: {
97
- beforeAddItem?: BeforeHook<unknown>[];
98
- afterAddItem?: AfterHook<unknown>[];
99
- beforeRemoveItem?: BeforeHook<unknown>[];
100
- afterRemoveItem?: AfterHook<unknown>[];
101
- beforeUpdateQuantity?: BeforeHook<unknown>[];
102
- afterUpdateQuantity?: AfterHook<unknown>[];
103
- };
104
- }
105
-
106
- export interface CheckoutConfig {
107
- hooks?: {
108
- beforeCreate?: BeforeHook<unknown>[];
109
- afterCreate?: AfterHook<unknown>[];
110
- };
111
- }
112
-
113
- export interface OrdersConfig {
114
- hooks?: {
115
- beforeCreate?: BeforeHook<unknown>[];
116
- afterCreate?: AfterHook<unknown>[];
117
- beforeStatusChange?: BeforeHook<unknown>[];
118
- afterStatusChange?: AfterHook<unknown>[];
119
- afterGet?: AfterHook<unknown>[];
120
- beforeDelete?: BeforeHook<unknown>[];
121
- };
122
- /**
123
- * Extend the order state machine with custom transitions.
124
- * New states (e.g., "payment_initiated", "shipped", "delivered", "defaulted")
125
- * are added to the default machine. Existing transitions are preserved.
126
- * See extendOrderStateMachine() for the merge logic.
127
- */
128
- customTransitions?: Record<string, string[]>;
129
- }
130
-
131
- export interface InventoryConfig {
132
- hooks?: {
133
- afterAdjust?: AfterHook<unknown>[];
134
- };
135
- }
136
-
137
- export interface ShippingConfig {
138
- type: "flat" | "weight_based";
139
- flatRate: number;
140
- freeShippingThreshold?: number;
141
- brackets: Array<{ upToGrams: number; cost: number }>;
142
- fallbackCost: number;
143
- }
144
-
145
- export interface TaxConfig {
146
- adapter?: TaxAdapter;
147
- defaultFromAddress?: {
148
- country: string;
149
- postalCode: string;
150
- state?: string;
151
- city?: string;
152
- line1?: string;
153
- };
154
- }
155
-
156
- export interface AnalyticsConfig {
157
- customSchemaPath?: string;
158
- models?: unknown[];
159
- }
160
-
161
- export interface SearchConfig {
162
- adapter?: SearchAdapter;
163
- defaultFacets?: string[];
164
- }
165
-
166
- export interface MCPTool {
167
- name: string;
168
- description: string;
169
- inputSchema?: Record<string, unknown>;
170
- handler: (params: unknown) => Promise<unknown>;
171
- }
172
-
173
- export interface MCPResource {
174
- uri: string;
175
- name: string;
176
- description: string;
177
- mimeType: string;
178
- handler: () => Promise<{ content: Array<{ type: "text"; text: string }> }>;
179
- }
180
-
181
- /**
182
- * A CommercePlugin is a config transform function (PayloadCMS pattern).
183
- * Receives the current config, returns the modified config.
184
- * All plugins — simple or complex — are just functions.
185
- *
186
- * Use `defineCommercePlugin()` for a structured way to build plugins,
187
- * or write a raw transform function for full control.
188
- */
189
- export type CommercePlugin = (
190
- config: CommerceConfig,
191
- ) => CommerceConfig | Promise<CommerceConfig>;
192
-
193
- export interface CommerceConfig {
194
- storeName?: string;
195
- version?: string;
196
- database: {
197
- provider: "postgresql";
198
- options?: Record<string, unknown>;
199
- };
200
- databaseAdapter?: DatabaseAdapter;
201
- auth?: AuthConfig;
202
- entities?: Record<string, EntityConfig>;
203
- cart?: CartConfig;
204
- checkout?: CheckoutConfig;
205
- orders?: OrdersConfig;
206
- inventory?: InventoryConfig;
207
- shipping?: ShippingConfig;
208
- payments?: PaymentAdapter[];
209
- storage?: StorageAdapter;
210
- email?: {
211
- send(input: {
212
- template: string;
213
- to: string;
214
- data?: Record<string, unknown>;
215
- }): Promise<void>;
216
- };
217
- tax?: TaxConfig;
218
- analytics?: AnalyticsConfig;
219
- search?: SearchConfig;
220
- mcp?: {
221
- enabled?: boolean;
222
- capabilities?: string[];
223
- };
224
- jobs?: {
225
- adapter?: JobsAdapter;
226
- tasks?: TaskDefinition[];
227
- autorun?: {
228
- enabled: boolean;
229
- intervalMs?: number;
230
- };
231
- };
232
- /**
233
- * Additional Drizzle table definitions — new tables or extended core tables.
234
- * Each entry is an object of `{ exportName: pgTable(...) }`.
235
- *
236
- * These are merged with core schema by `buildSchema(config)` and must also
237
- * be listed in the app's `drizzle.config.ts` for `db:push` / `db:generate`.
238
- *
239
- * Plugins push into this array automatically via `defineCommercePlugin({ schema })`.
240
- * Apps can also add entries directly — no plugin wrapper needed:
241
- *
242
- * ```ts
243
- * import { reviewsTable } from "./schema/reviews.js";
244
- * import { extendedProducts } from "./schema/extended-products.js";
245
- *
246
- * defineConfig({
247
- * schema: [
248
- * { reviewsTable },
249
- * { extendedProducts },
250
- * ],
251
- * // ...
252
- * });
253
- * ```
254
- */
255
- schema?: Array<Record<string, unknown>>;
256
- /** @internal Merged from `schema` + plugin schemas. Use `schema` instead. */
257
- customSchemas?: Array<Record<string, unknown>>;
258
- hooks?: Record<string, Array<(...args: unknown[]) => unknown>>;
259
- plugins?: CommercePlugin[];
260
- middleware?: MiddlewareHandler[];
261
- routes?: (app: Hono, kernel: unknown) => void;
262
- mcpTools?: (kernel: unknown) => MCPTool[];
263
- /** Log level for structured logging. Default: "info". */
264
- logLevel?: "fatal" | "error" | "warn" | "info" | "debug" | "trace";
265
- /**
266
- * Expose the OpenAPI spec (`/api/doc`) and Swagger UI (`/api/reference`).
267
- * Default: `true` in development, `false` in production.
268
- */
269
- exposeOpenApiSpec?: boolean;
270
- /** Rate limiting overrides. */
271
- rateLimits?: {
272
- /** Requests per minute for general API. Default: 100. */
273
- api?: number;
274
- /** Requests per minute for auth endpoints. Default: 10. */
275
- auth?: number;
276
- /** Requests per minute for checkout. Default: 5. */
277
- checkout?: number;
278
- };
279
- }
280
-
281
- export interface DefineConfigInput extends CommerceConfig {}
282
-
283
- export interface AuthSessionLike {
284
- user: {
285
- id: string;
286
- email?: string | null;
287
- name?: string | null;
288
- vendorId?: string | null;
289
- };
290
- session: {
291
- activeOrganizationId?: string | null;
292
- activeOrganizationRole?: string | null;
293
- };
294
- }
295
-
296
- export interface KernelFactoryContext {
297
- config: CommerceConfig;
298
- actor: Actor | null;
299
- }
@@ -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
- }