@tallyui/connector-medusa 1.0.0 → 2.0.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 Paul Kilmurray and TallyUI 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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,36 @@
1
- import { ProductTraits, CollectionSync, ReplicationAdapter, TallyConnector } from '@tallyui/core';
1
+ import { ProductTraits, CollectionSync, ReplicationAdapter, StockReconcileAdapter, SyncContext, StoreSettingsChoice, StoreSettings, ConnectorAuth, TallyConnector, ServerCapabilities } from '@tallyui/core';
2
2
  import { RxJsonSchema } from 'rxdb';
3
3
 
4
+ /** A store API variant's `calculated_price`: the fields the connector reads. Amounts are major units. */
5
+ interface MedusaCalculatedPrice {
6
+ calculated_amount: number | null;
7
+ original_amount: number | null;
8
+ currency_code: string;
9
+ is_calculated_price_tax_inclusive: boolean;
10
+ is_original_price_tax_inclusive: boolean;
11
+ calculated_price?: {
12
+ price_list_id?: string | null;
13
+ price_list_type?: string | null;
14
+ };
15
+ }
16
+ /** A stored variant. `calculated_price`: an object when priced, `null` when not sold here, undefined in base-only mode. */
17
+ interface MedusaVariantDocument {
18
+ id: string;
19
+ prices?: Array<{
20
+ amount: number;
21
+ currency_code: string;
22
+ price_list_id?: string | null;
23
+ }>;
24
+ calculated_price?: MedusaCalculatedPrice | null;
25
+ [field: string]: unknown;
26
+ }
27
+ /** A stored product; typed for the fields the pricing code reads. */
28
+ interface MedusaProductDocument {
29
+ id: string;
30
+ status?: string;
31
+ variants?: MedusaVariantDocument[];
32
+ [field: string]: unknown;
33
+ }
4
34
  /**
5
35
  * MedusaJS v2 Product RxDB schema.
6
36
  * Mirrors the Medusa Admin API product shape.
@@ -21,11 +51,11 @@ declare const medusaProductSchema: RxJsonSchema<any>;
21
51
  *
22
52
  * Key mapping differences from WooCommerce:
23
53
  * - Product name is `title` (not `name`)
24
- * - Price lives on `variants[0].prices[0].amount` (cents, integer)
54
+ * - Price lives on `variants[0].prices[0].amount` (major units: 12 = 12.00)
25
55
  * - Images use `url` (not `src`)
26
56
  * - SKU/barcode live on variants, not the product
27
57
  * - Categories use `name`, tags use `value`
28
- * - Stock is per-variant via `inventory_quantity`
58
+ * - Stock is per-variant: `inventory_quantity` (Store API) or inventory levels (Admin API)
29
59
  */
30
60
  declare const medusaProductTraits: ProductTraits;
31
61
 
@@ -38,19 +68,87 @@ declare const medusaProductTraits: ProductTraits;
38
68
  */
39
69
  declare const medusaProductSync: CollectionSync;
40
70
 
71
+ /**
72
+ * A pass pages through every product with updated_at >= `updated_at`, in id
73
+ * order, `offset` rows in. The pass-start mark becomes the next lower bound.
74
+ */
41
75
  type MedusaProductCheckpoint = {
42
76
  offset: number;
43
77
  updated_at: string;
78
+ pass_max?: string;
79
+ pass_mark?: string;
80
+ pass_count?: number;
44
81
  };
45
82
  /**
46
83
  * Replication adapter for Medusa v2 products.
47
84
  *
48
- * Implements pull (offset-based pagination with updated_at filtering) and
49
- * push (POST to update individual products via Admin API). Designed for
50
- * use with RxDB's replicateRxCollection.
85
+ * Pull-only (id-ordered offset pages within an updated_at window) for RxDB's
86
+ * replicateRxCollection. Catalogue data is server-owned; the POS never
87
+ * writes products.
51
88
  */
52
89
  declare const medusaProductReplication: ReplicationAdapter<any, MedusaProductCheckpoint>;
53
90
 
91
+ /**
92
+ * Variant feed for Medusa products (ADR-060, amendment 8).
93
+ *
94
+ * On Medusa 2.21 a price-only edit bumps the variant's `updated_at` but not
95
+ * the product's, through both the admin's batch route and the single-variant
96
+ * route, so the product feed never sees it. This pull adapter pages changed
97
+ * variants with the same pass and offset design as `medusaProductReplication`
98
+ * and re-delivers their parent products, re-fetched with the id reconcile's
99
+ * `fetchByIds` in the same document shape, into the `products` collection.
100
+ * It runs as a sub-adapter of the connector's combined `replication.products`
101
+ * adapter (`combinePullAdapters`), not as its own replication. Parents that
102
+ * no longer exist are skipped; deletions are the id reconcile's job.
103
+ *
104
+ * On a fresh install `seedCheckpoint` starts the cursor at the variant mark,
105
+ * read before the product feed's first pass, so the catalogue downloads once.
106
+ * An upgrade (a stored product checkpoint, none for this feed) is not seeded:
107
+ * its first pass re-delivers every product that has variants, once. That is
108
+ * deliberate: it heals any price change the product feed missed before this
109
+ * feed existed.
110
+ *
111
+ * `variantPageSize` (the variant page `limit`) is for tests and tuning.
112
+ */
113
+ declare const createMedusaVariantFeedReplication: (variantPageSize?: number) => ReplicationAdapter<any, MedusaProductCheckpoint>;
114
+
115
+ /**
116
+ * Stock reconciler for Medusa v2 products (ADR-060). Inventory changes never
117
+ * touch the product, so replication misses them. Pages are keyed by
118
+ * inventory item id; each value is its location levels' quantities.
119
+ */
120
+ declare const medusaStockReconcile: StockReconcileAdapter;
121
+
122
+ /**
123
+ * Reads the store's currency, tax inclusivity and location tax rate, and the
124
+ * publishable-key channel, from Medusa's admin API only (TV4b). Read-only
125
+ * (ADR-048). Region, then country, then channel: the first ambiguity that
126
+ * needs a choice reports every choice known at that point, so the app asks
127
+ * once.
128
+ */
129
+ declare const medusaStoreSettings: (context: SyncContext, choice?: StoreSettingsChoice) => Promise<StoreSettings>;
130
+
131
+ /**
132
+ * Fills each variant's `calculated_price` from the store API, priced with
133
+ * `context.pricingContext` (`region_id`, `publishable_key`): what Medusa
134
+ * charges at checkout, sale price lists and their dates included (ADR-060
135
+ * amendment 8, D2b). A variant the store API does not list (a draft, or a
136
+ * product outside the key's sales channel) gets `null`: priced mode, not
137
+ * sellable here. Without a pricing context the documents come back
138
+ * unchanged (base-only mode, no `calculated_price` key). A failed store
139
+ * request throws, so the pull retries and never delivers a half-priced
140
+ * document.
141
+ */
142
+ declare function withCalculatedPrices<Doc extends MedusaProductDocument>(docs: Doc[], context: SyncContext): Promise<Doc[]>;
143
+
144
+ /** The calculated-price check's interval: price-list edits and sale start/end bump no timestamp (ADR-060 amendment 8). */
145
+ declare const MEDUSA_CALCULATED_PRICE_RECONCILE_INTERVAL_MS: number;
146
+
147
+ declare const medusaSecretKeyAuth: ConnectorAuth;
148
+ declare const medusaSignIn: NonNullable<ConnectorAuth['signIn']>;
149
+ /** Re-reads the store's `order.create` capability (ADR-062) for a restored session, with the connector's own headers. */
150
+ declare const medusaCapabilities: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
151
+ declare const medusaAdminUserAuth: ConnectorAuth;
54
152
  /**
55
153
  * MedusaJS v2 connector for Tally UI.
56
154
  *
@@ -67,5 +165,7 @@ declare const medusaProductReplication: ReplicationAdapter<any, MedusaProductChe
67
165
  * ```
68
166
  */
69
167
  declare const medusaConnector: TallyConnector;
168
+ /** Medusa connector using an admin user's Bearer JWT. */
169
+ declare const medusaAdminUserConnector: TallyConnector;
70
170
 
71
- export { medusaConnector, medusaProductReplication, medusaProductSchema, medusaProductSync, medusaProductTraits };
171
+ export { MEDUSA_CALCULATED_PRICE_RECONCILE_INTERVAL_MS, type MedusaCalculatedPrice, type MedusaProductDocument, type MedusaVariantDocument, createMedusaVariantFeedReplication, medusaAdminUserAuth, medusaAdminUserConnector, medusaCapabilities, medusaConnector, medusaProductReplication, medusaProductSchema, medusaProductSync, medusaProductTraits, medusaSecretKeyAuth, medusaSignIn, medusaStockReconcile, medusaStoreSettings, withCalculatedPrices };