@marianmeres/collection-types 1.7.0 → 1.8.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.
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Customer and Address type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { CustomerData, AddressData } from "@marianmeres/collection-types";
8
+ * type CustomerModel = Model<CustomerData>;
9
+ * type AddressModel = Model<AddressData>;
10
+ * ```
11
+ */
12
+ /** Customer data field schema */
13
+ export interface CustomerData {
14
+ /** Customer email */
15
+ email: string;
16
+ /** Customer display name */
17
+ name: string;
18
+ /** Phone number */
19
+ phone?: string;
20
+ /** True if customer has no linked account */
21
+ guest: boolean;
22
+ /** Marketing consent */
23
+ accepts_marketing: boolean;
24
+ /** Index signature for compatibility with UserData */
25
+ [key: string]: unknown;
26
+ }
27
+ /** Address data field schema */
28
+ export interface AddressData {
29
+ /** User-friendly label (e.g., "Home", "Work") */
30
+ label?: string;
31
+ /** Recipient name */
32
+ name: string;
33
+ /** Street address */
34
+ street: string;
35
+ /** City */
36
+ city: string;
37
+ /** Postal/ZIP code */
38
+ postal_code: string;
39
+ /** Country code or name */
40
+ country: string;
41
+ /** Contact phone */
42
+ phone?: string;
43
+ /** Whether this is the default address for its type */
44
+ is_default: boolean;
45
+ /** Index signature for compatibility with UserData */
46
+ [key: string]: unknown;
47
+ }
48
+ /** Address type identifier (used as model type in collection) */
49
+ export type AddressType = "shipping" | "billing";
50
+ /** Customer type identifier */
51
+ export type CustomerType = "customer";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Customer and Address type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { CustomerData, AddressData } from "@marianmeres/collection-types";
8
+ * type CustomerModel = Model<CustomerData>;
9
+ * type AddressModel = Model<AddressData>;
10
+ * ```
11
+ */
12
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * External domain metadata for descriptor collections.
3
+ *
4
+ * When using weak relations for cross-domain references, the `related_collection_id`
5
+ * must point to a valid collection (NOT NULL constraint). We create "descriptor
6
+ * collections" that contain no models but carry metadata about the external domain.
7
+ *
8
+ * UI tooling reads this metadata to understand cross-domain references:
9
+ * - Check `meta.__external_domain__` to identify descriptor collections
10
+ * - Use `external_domain` and `external_adapter_prefix` to resolve the target
11
+ * - The actual foreign model_id is stored in `weak_related_id` on the relation
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import type { ExternalDomainMeta } from "@marianmeres/collection-types";
16
+ *
17
+ * // Create a descriptor collection
18
+ * const extAccount = await sc.createIfNotExists({
19
+ * path: "_ext_account",
20
+ * types: [], // no models stored
21
+ * is_unlisted: true,
22
+ * is_readonly: true,
23
+ * meta: {
24
+ * __external_domain__: true,
25
+ * external_domain: "account",
26
+ * external_adapter_prefix: "account_",
27
+ * external_collection_path: "account",
28
+ * description: "Cross-domain reference to stack-account",
29
+ * } satisfies ExternalDomainMeta,
30
+ * });
31
+ * ```
32
+ */
33
+ export interface ExternalDomainMeta {
34
+ /** Marker flag - always true for descriptor collections */
35
+ __external_domain__: true;
36
+ /** External domain name (e.g., "account", "customer", "order") */
37
+ external_domain: string;
38
+ /** Table prefix of the external adapter (e.g., "account_", "customer_") */
39
+ external_adapter_prefix: string;
40
+ /** Collection path in the external domain (e.g., "account", "customer") */
41
+ external_collection_path: string;
42
+ /** Human-readable description */
43
+ description?: string;
44
+ }
45
+ /**
46
+ * Type guard to check if collection meta indicates an external domain descriptor.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * if (isExternalDomainMeta(collection.meta)) {
51
+ * console.log(`External domain: ${collection.meta.external_domain}`);
52
+ * }
53
+ * ```
54
+ */
55
+ export declare function isExternalDomainMeta(meta: unknown): meta is ExternalDomainMeta;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Type guard to check if collection meta indicates an external domain descriptor.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * if (isExternalDomainMeta(collection.meta)) {
7
+ * console.log(`External domain: ${collection.meta.external_domain}`);
8
+ * }
9
+ * ```
10
+ */
11
+ export function isExternalDomainMeta(meta) {
12
+ return (typeof meta === "object" &&
13
+ meta !== null &&
14
+ "__external_domain__" in meta &&
15
+ meta.__external_domain__ === true);
16
+ }
package/dist/mod.d.ts CHANGED
@@ -26,3 +26,8 @@ export * from "./api.js";
26
26
  export * from "./asset.js";
27
27
  export * from "./linked-assets.js";
28
28
  export * from "./adapter.js";
29
+ export * from "./session.js";
30
+ export * from "./customer.js";
31
+ export * from "./order.js";
32
+ export * from "./payment.js";
33
+ export * from "./external-domain.js";
package/dist/mod.js CHANGED
@@ -33,3 +33,10 @@ export * from "./asset.js";
33
33
  export * from "./linked-assets.js";
34
34
  // Adapter (database layer)
35
35
  export * from "./adapter.js";
36
+ // E-commerce domain types
37
+ export * from "./session.js";
38
+ export * from "./customer.js";
39
+ export * from "./order.js";
40
+ export * from "./payment.js";
41
+ // Cross-domain reference support
42
+ export * from "./external-domain.js";
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Order type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { OrderData, OrderEventData } from "@marianmeres/collection-types";
8
+ * type OrderModel = Model<OrderData>;
9
+ * type OrderEventModel = Model<OrderEventData>;
10
+ * ```
11
+ */
12
+ import type { AddressData } from "./customer.js";
13
+ import type { UUID } from "./utils.js";
14
+ /** Order status progression */
15
+ export type OrderStatus = "pending" | "paid" | "processing" | "shipped" | "delivered" | "cancelled";
16
+ /** Single order line item (snapshot at purchase time) */
17
+ export interface OrderLineItem {
18
+ /** Product model_id for reference */
19
+ product_id: UUID;
20
+ /** Product SKU (snapshot) */
21
+ sku?: string;
22
+ /** Product name (snapshot) */
23
+ name: string;
24
+ /** Unit price at purchase time (snapshot) */
25
+ price: number;
26
+ /** Quantity ordered */
27
+ quantity: number;
28
+ }
29
+ /** Order price totals */
30
+ export interface OrderTotals {
31
+ /** Sum of line items before tax/shipping/discounts */
32
+ subtotal: number;
33
+ /** Tax amount */
34
+ tax: number;
35
+ /** Shipping cost */
36
+ shipping: number;
37
+ /** Discount amount */
38
+ discount: number;
39
+ /** Final total */
40
+ total: number;
41
+ }
42
+ /** Order data field schema */
43
+ export interface OrderData {
44
+ /** Current order status */
45
+ status: OrderStatus;
46
+ /** Line items (snapshots) */
47
+ items: OrderLineItem[];
48
+ /** Currency code (e.g., "EUR", "USD") */
49
+ currency: string;
50
+ /** Price totals */
51
+ totals: OrderTotals;
52
+ /** Shipping address (embedded snapshot) */
53
+ shipping_address: AddressData;
54
+ /** Billing address (embedded snapshot) */
55
+ billing_address: AddressData;
56
+ /** Order notes */
57
+ notes?: string;
58
+ /** Index signature for compatibility with UserData */
59
+ [key: string]: unknown;
60
+ }
61
+ /** Order event types for audit trail */
62
+ export type OrderEventType = "created" | "status_changed" | "payment_added" | "note_added" | "cancelled";
63
+ /** Actor who triggered an order event */
64
+ export interface OrderEventActor {
65
+ /** Actor type */
66
+ type: "customer" | "admin" | "system";
67
+ /** Actor ID (account_id or customer_id) */
68
+ id?: UUID;
69
+ }
70
+ /** Order event data field schema (audit trail) */
71
+ export interface OrderEventData {
72
+ /** Type of event */
73
+ event_type: OrderEventType;
74
+ /** Previous status (for status_changed) */
75
+ previous_status?: OrderStatus;
76
+ /** New status (for status_changed) */
77
+ new_status?: OrderStatus;
78
+ /** Who triggered the event */
79
+ actor: OrderEventActor;
80
+ /** Additional event details */
81
+ details?: Record<string, unknown>;
82
+ /** Index signature for compatibility with UserData */
83
+ [key: string]: unknown;
84
+ }
85
+ /** Order type identifier */
86
+ export type OrderType = "order";
87
+ /** Order event type identifier */
88
+ export type OrderEventModelType = "event";
package/dist/order.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Order type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { OrderData, OrderEventData } from "@marianmeres/collection-types";
8
+ * type OrderModel = Model<OrderData>;
9
+ * type OrderEventModel = Model<OrderEventData>;
10
+ * ```
11
+ */
12
+ export {};
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Payment type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { PaymentData } from "@marianmeres/collection-types";
8
+ * type PaymentModel = Model<PaymentData>;
9
+ * ```
10
+ */
11
+ import type { UUID } from "./utils.js";
12
+ /** Payment status */
13
+ export type PaymentStatus = "pending" | "completed" | "failed" | "refunded";
14
+ /** Payment data field schema */
15
+ export interface PaymentData {
16
+ /** Payment provider name (e.g., "paypal", "stripe") */
17
+ provider: string;
18
+ /** Current payment status */
19
+ status: PaymentStatus;
20
+ /** Payment amount */
21
+ amount: number;
22
+ /** Currency code */
23
+ currency: string;
24
+ /** Provider-specific reference ID */
25
+ provider_reference: string;
26
+ /** Raw provider response data */
27
+ provider_response?: Record<string, unknown>;
28
+ /** Index signature for compatibility with UserData */
29
+ [key: string]: unknown;
30
+ }
31
+ /** Payment type identifier */
32
+ export type PaymentType = "payment";
33
+ /** Result of initiating a payment */
34
+ export interface PaymentIntent {
35
+ /** Internal payment ID */
36
+ id: UUID;
37
+ /** URL to redirect customer for payment */
38
+ redirect_url: string;
39
+ /** Provider-specific data */
40
+ provider_data?: Record<string, unknown>;
41
+ }
42
+ /** Result of capturing/completing a payment */
43
+ export interface PaymentResult {
44
+ /** Whether capture succeeded */
45
+ success: boolean;
46
+ /** Provider reference ID */
47
+ provider_reference: string;
48
+ /** Error message if failed */
49
+ error?: string;
50
+ }
51
+ /** Result of a refund operation */
52
+ export interface RefundResult {
53
+ /** Whether refund succeeded */
54
+ success: boolean;
55
+ /** Refund ID from provider */
56
+ refund_id?: string;
57
+ /** Error message if failed */
58
+ error?: string;
59
+ }
60
+ /** Result of processing a webhook */
61
+ export interface WebhookResult {
62
+ /** Whether webhook was processed successfully */
63
+ success: boolean;
64
+ /** Event type from provider */
65
+ event_type?: string;
66
+ /** Related payment ID */
67
+ payment_id?: UUID;
68
+ /** Error message if failed */
69
+ error?: string;
70
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Payment type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { PaymentData } from "@marianmeres/collection-types";
8
+ * type PaymentModel = Model<PaymentData>;
9
+ * ```
10
+ */
11
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Session and Cart type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { SessionData } from "@marianmeres/collection-types";
8
+ * type SessionModel = Model<SessionData>;
9
+ * ```
10
+ */
11
+ import type { UUID } from "./utils.js";
12
+ /** Single cart item */
13
+ export interface CartItem {
14
+ /** Product model_id reference */
15
+ product_id: UUID;
16
+ /** Quantity in cart */
17
+ quantity: number;
18
+ }
19
+ /** Cart contents */
20
+ export interface CartData {
21
+ items: CartItem[];
22
+ }
23
+ /** Session data field schema */
24
+ export interface SessionData {
25
+ cart: CartData;
26
+ /** Index signature for compatibility with UserData */
27
+ [key: string]: unknown;
28
+ }
29
+ /** Session type identifier */
30
+ export type SessionType = "session";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Session and Cart type definitions for e-commerce.
3
+ *
4
+ * Usage with Model:
5
+ * ```typescript
6
+ * import type { Model } from "@marianmeres/collection-types";
7
+ * import type { SessionData } from "@marianmeres/collection-types";
8
+ * type SessionModel = Model<SessionData>;
9
+ * ```
10
+ */
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/collection-types",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "main": "dist/mod.js",
6
6
  "types": "dist/mod.d.ts",