@marianmeres/ecsuite 1.2.0 → 1.3.2

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/AGENTS.md CHANGED
@@ -169,6 +169,19 @@ const suite = createECSuite({
169
169
  });
170
170
  ```
171
171
 
172
+ ### Selective Initialization
173
+
174
+ ```typescript
175
+ // Skip auth-gated domains for guest users
176
+ const suite = createECSuite({
177
+ adapters: { cart: myCartAdapter, order: myOrderAdapter },
178
+ initializeDomains: ["cart", "wishlist", "payment"],
179
+ });
180
+
181
+ // Later, when user authenticates
182
+ await suite.initialize(["order", "customer"]);
183
+ ```
184
+
172
185
  ### Subscribing to Store (Svelte-compatible)
173
186
 
174
187
  ```typescript
package/dist/suite.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  import { type Subscriber, type Unsubscriber } from "@marianmeres/pubsub";
8
8
  import type { CartAdapter, CustomerAdapter, OrderAdapter, PaymentAdapter, ProductAdapter, WishlistAdapter } from "./types/adapter.js";
9
9
  import type { DomainContext, DomainError, DomainState } from "./types/state.js";
10
- import type { DomainName, ECSuiteEvent, ECSuiteEventType } from "./types/events.js";
10
+ import type { DomainName, ECSuiteEvent, ECSuiteEventType, InitializableDomainName } from "./types/events.js";
11
11
  import { CartManager } from "./domains/cart.js";
12
12
  import { WishlistManager } from "./domains/wishlist.js";
13
13
  import { OrderManager } from "./domains/order.js";
@@ -41,6 +41,8 @@ export interface ECSuiteConfig {
41
41
  productCacheTtl?: number;
42
42
  /** Auto-initialize on creation (default: true) */
43
43
  autoInitialize?: boolean;
44
+ /** Domains to initialize (default: all). Used by both autoInitialize and manual initialize(). */
45
+ initializeDomains?: InitializableDomainName[];
44
46
  }
45
47
  /**
46
48
  * Main ECSuite class - orchestrates all e-commerce domain managers.
@@ -74,8 +76,24 @@ export declare class ECSuite {
74
76
  /** Product domain manager (read-only with caching) */
75
77
  readonly product: ProductManager;
76
78
  constructor(config?: ECSuiteConfig);
77
- /** Initialize all domains */
78
- initialize(): Promise<void>;
79
+ /** Initialize domains. When called without arguments, initializes all domains.
80
+ * Pass an array of domain names to selectively initialize specific domains.
81
+ *
82
+ * @param domains - Optional list of domains to initialize (default: all)
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // Initialize all domains (default)
87
+ * await suite.initialize();
88
+ *
89
+ * // Initialize only cart and wishlist (skip auth-gated domains for guests)
90
+ * await suite.initialize(["cart", "wishlist"]);
91
+ *
92
+ * // Later, initialize order domain when user authenticates
93
+ * await suite.initialize(["order", "customer"]);
94
+ * ```
95
+ */
96
+ initialize(domains?: InitializableDomainName[]): Promise<void>;
79
97
  /** Update context across all domains */
80
98
  setContext(context: DomainContext): void;
81
99
  /** Get the current context */
package/dist/suite.js CHANGED
@@ -91,21 +91,38 @@ export class ECSuite {
91
91
  });
92
92
  // Auto-initialize if configured
93
93
  if (config.autoInitialize !== false) {
94
- this.initialize();
94
+ this.initialize(config.initializeDomains);
95
95
  }
96
96
  }
97
- /** Initialize all domains */
98
- async initialize() {
99
- this.#clog.debug("initializing all domains");
100
- await Promise.all([
101
- this.cart.initialize(),
102
- this.wishlist.initialize(),
103
- this.order.initialize(),
104
- this.customer.initialize(),
105
- this.payment.initialize(),
106
- // Note: ProductManager doesn't have initialize() - it's lazy-loaded
107
- ]);
108
- this.#clog.debug("all domains initialized");
97
+ /** Initialize domains. When called without arguments, initializes all domains.
98
+ * Pass an array of domain names to selectively initialize specific domains.
99
+ *
100
+ * @param domains - Optional list of domains to initialize (default: all)
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // Initialize all domains (default)
105
+ * await suite.initialize();
106
+ *
107
+ * // Initialize only cart and wishlist (skip auth-gated domains for guests)
108
+ * await suite.initialize(["cart", "wishlist"]);
109
+ *
110
+ * // Later, initialize order domain when user authenticates
111
+ * await suite.initialize(["order", "customer"]);
112
+ * ```
113
+ */
114
+ async initialize(domains) {
115
+ const all = [
116
+ "cart",
117
+ "wishlist",
118
+ "order",
119
+ "customer",
120
+ "payment",
121
+ ];
122
+ const toInit = domains ?? all;
123
+ this.#clog.debug("initializing domains", toInit);
124
+ await Promise.all(toInit.map((name) => this[name].initialize()));
125
+ this.#clog.debug("domains initialized", toInit);
109
126
  }
110
127
  /** Update context across all domains */
111
128
  setContext(context) {
@@ -8,6 +8,8 @@ import type { UUID } from "@marianmeres/collection-types";
8
8
  import type { DomainError, DomainState } from "./state.js";
9
9
  /** Domain identifiers */
10
10
  export type DomainName = "cart" | "wishlist" | "order" | "customer" | "payment" | "product";
11
+ /** Domain names that support initialize() (excludes product which is fully lazy) */
12
+ export type InitializableDomainName = Exclude<DomainName, "product">;
11
13
  /** Event types emitted by the suite */
12
14
  export type ECSuiteEventType = "domain:state:changed" | "domain:error" | "domain:synced" | "cart:item:added" | "cart:item:updated" | "cart:item:removed" | "cart:cleared" | "wishlist:item:added" | "wishlist:item:removed" | "wishlist:cleared" | "order:created" | "order:fetched" | "customer:updated" | "customer:fetched" | "payment:fetched" | "payment:initiated" | "payment:captured" | "product:fetched";
13
15
  /** Base event data */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/ecsuite",
3
- "version": "1.2.0",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "main": "dist/mod.js",
6
6
  "types": "dist/mod.d.ts",