@nabasolution/commerce 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NABA Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,145 @@
1
+ import type { CountryDefinition, Money, NabaModule, ShippingProvider, StateStore, TaxEngine } from "@nabasolution/core";
2
+ export interface ProductSeed {
3
+ id: string;
4
+ sku: string;
5
+ name: string;
6
+ description?: string;
7
+ price: Money;
8
+ image?: string;
9
+ /** Optional tax category passed to the tax engine (v0.3). */
10
+ taxCategory?: string;
11
+ }
12
+ export interface Product {
13
+ id: string;
14
+ sku: string;
15
+ name: string;
16
+ description: string;
17
+ price: Money;
18
+ image?: string;
19
+ taxCategory?: string;
20
+ }
21
+ export interface CartLineInput {
22
+ productId: string;
23
+ quantity: number;
24
+ }
25
+ export interface QuoteLine {
26
+ productId: string;
27
+ sku: string;
28
+ name: string;
29
+ quantity: number;
30
+ unitPrice: Money;
31
+ lineTotal: Money;
32
+ taxCategory?: string;
33
+ }
34
+ export interface Quote {
35
+ items: QuoteLine[];
36
+ subtotal: Money;
37
+ tax: Money;
38
+ shipping: Money;
39
+ total: Money;
40
+ currency: string;
41
+ /** Effective tax rate used for this quote (additive, v0.2). */
42
+ taxRate?: number;
43
+ /** Jurisdiction label, e.g. `BD` or `US-CA` (additive, v0.2). */
44
+ taxJurisdiction?: string;
45
+ }
46
+ export interface CustomerInput {
47
+ name: string;
48
+ phone: string;
49
+ address: string;
50
+ postalCode: string;
51
+ email?: string;
52
+ /** Optional state/region, forwarded to the tax engine (v0.2). */
53
+ region?: string;
54
+ }
55
+ export interface Order {
56
+ id: string;
57
+ tenantId: string;
58
+ status: "pending_payment" | "confirmed" | "cancelled";
59
+ customer: CustomerInput;
60
+ items: QuoteLine[];
61
+ totals: Quote;
62
+ paymentId?: string;
63
+ reservationId?: string;
64
+ createdAt: string;
65
+ updatedAt: string;
66
+ }
67
+ interface PaymentLike {
68
+ id: string;
69
+ orderId: string;
70
+ provider: string;
71
+ status: string;
72
+ amount: Money;
73
+ redirectUrl?: string;
74
+ reference?: string;
75
+ createdAt?: string;
76
+ }
77
+ export interface CheckoutInput {
78
+ items?: CartLineInput[];
79
+ customer?: Partial<CustomerInput>;
80
+ paymentProvider?: string;
81
+ shippingProvider?: string;
82
+ idempotencyKey?: string;
83
+ tenantId?: string;
84
+ }
85
+ export interface CommerceService {
86
+ listProducts(tenantId?: string): Array<Product & {
87
+ stock: number;
88
+ }>;
89
+ quote(items: CartLineInput[], shippingProviderId?: string, region?: string, tenantId?: string): Promise<Quote>;
90
+ checkout(input: CheckoutInput): Promise<{
91
+ order: Order;
92
+ payment: PaymentLike;
93
+ }>;
94
+ verifyPayment(paymentId: string, tenantId?: string): Promise<{
95
+ payment: PaymentLike;
96
+ order: Order;
97
+ accounting: {
98
+ journalId: string | null;
99
+ };
100
+ }>;
101
+ /** Idempotently confirm a pending order from a succeeded payment event/webhook. */
102
+ confirmFromPayment(paymentId: string, tenantId?: string): Promise<Order | undefined>;
103
+ /** Release a pending order when its payment definitively failed. */
104
+ cancelFromFailedPayment(paymentId: string, tenantId?: string): Promise<Order | undefined>;
105
+ cancelOrder(orderId: string, tenantId?: string): Promise<Order>;
106
+ getOrder(id: string, tenantId?: string): Order | undefined;
107
+ listOrders(tenantId?: string): Order[];
108
+ }
109
+ export interface CommerceTenantState {
110
+ orders: Order[];
111
+ idempotency: Record<string, {
112
+ orderId: string;
113
+ paymentId: string;
114
+ }>;
115
+ }
116
+ /** Durable snapshot (v2): orders and idempotency keys are partitioned by tenant. */
117
+ export interface CommerceSnapshot {
118
+ version: 2;
119
+ tenants: Record<string, CommerceTenantState>;
120
+ }
121
+ /** Legacy v1 snapshot; migrated into the default tenant on load. */
122
+ export interface CommerceSnapshotV1 {
123
+ version: 1;
124
+ orders: Array<Omit<Order, "tenantId"> & {
125
+ tenantId?: string;
126
+ }>;
127
+ idempotency: Record<string, {
128
+ orderId: string;
129
+ paymentId: string;
130
+ }>;
131
+ }
132
+ export declare const COMMERCE_SNAPSHOT_VERSION = 2;
133
+ export declare const COMMERCE_STATE_KEY = "commerce";
134
+ export interface CommerceModuleOptions {
135
+ country: CountryDefinition;
136
+ shippingProviders?: ShippingProvider[];
137
+ seedProducts?: ProductSeed[];
138
+ store?: StateStore;
139
+ taxEngine?: TaxEngine;
140
+ }
141
+ export declare function createCommerceModule(options: CommerceModuleOptions): NabaModule & {
142
+ service: CommerceService;
143
+ };
144
+ export {};
145
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,SAAS,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