@tolinax/ayoune-interfaces 2026.29.0 → 2026.30.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.
@@ -613,6 +613,9 @@ export declare enum aMN {
613
613
  TextLinks = "TextLinks",
614
614
  Tickets = "Tickets",
615
615
  Tips = "Tips",
616
+ TradeChannelEvents = "TradeChannelEvents",
617
+ TradeChannelOrders = "TradeChannelOrders",
618
+ TradeChannels = "TradeChannels",
616
619
  Trades = "Trades",
617
620
  Transactions = "Transactions",
618
621
  TransportOrders = "TransportOrders",
@@ -617,6 +617,9 @@ var aMN;
617
617
  aMN["TextLinks"] = "TextLinks";
618
618
  aMN["Tickets"] = "Tickets";
619
619
  aMN["Tips"] = "Tips";
620
+ aMN["TradeChannelEvents"] = "TradeChannelEvents";
621
+ aMN["TradeChannelOrders"] = "TradeChannelOrders";
622
+ aMN["TradeChannels"] = "TradeChannels";
620
623
  aMN["Trades"] = "Trades";
621
624
  aMN["Transactions"] = "Transactions";
622
625
  aMN["TransportOrders"] = "TransportOrders";
@@ -6696,6 +6696,64 @@ const modelsAndRights = [
6696
6696
  allowDuplicate: false,
6697
6697
  updateBy: "_id",
6698
6698
  },
6699
+ {
6700
+ plural: "TradeChannels",
6701
+ singular: "TradeChannel",
6702
+ module: "purchase",
6703
+ right: "purchase.tradechannels",
6704
+ readOnly: false,
6705
+ importable: false,
6706
+ allowDuplicate: false,
6707
+ updateBy: "_id",
6708
+ searchable: true,
6709
+ searchableFields: ["label", "externalAccountId", "provider"],
6710
+ },
6711
+ {
6712
+ plural: "TradeChannelOrders",
6713
+ singular: "TradeChannelOrder",
6714
+ module: "purchase",
6715
+ right: "purchase.tradechannelorders",
6716
+ readOnly: false,
6717
+ importable: false,
6718
+ allowDuplicate: false,
6719
+ updateBy: "_id",
6720
+ searchable: true,
6721
+ searchableFields: ["externalId", "provider", "status", "counterparty.name"],
6722
+ actions: [
6723
+ {
6724
+ title: "Refresh from provider",
6725
+ action: "refresh",
6726
+ availability: "single",
6727
+ method: "POST",
6728
+ icon: "refresh",
6729
+ },
6730
+ {
6731
+ title: "Match products",
6732
+ action: "match-products",
6733
+ availability: "both",
6734
+ method: "POST",
6735
+ icon: "link",
6736
+ },
6737
+ {
6738
+ title: "Promote to SupplierOrder",
6739
+ action: "promote",
6740
+ availability: "single",
6741
+ method: "POST",
6742
+ icon: "upgrade",
6743
+ confirmation: "Promote this trade-channel order into a SupplierOrder + GoodsReceipt? This cannot be undone.",
6744
+ },
6745
+ ],
6746
+ },
6747
+ {
6748
+ plural: "TradeChannelEvents",
6749
+ singular: "TradeChannelEvent",
6750
+ module: "purchase",
6751
+ right: "purchase.tradechannelevents",
6752
+ readOnly: true,
6753
+ importable: false,
6754
+ allowDuplicate: false,
6755
+ updateBy: "_id",
6756
+ },
6699
6757
  ];
6700
6758
  exports.modelsAndRights = modelsAndRights;
6701
6759
  exports.default = modelsAndRights;
@@ -0,0 +1,64 @@
1
+ import { IDefaultFields } from "./IDefaultFields";
2
+ /**
3
+ * Provider identifier for an external trade channel.
4
+ * Add new providers here as integrations land.
5
+ */
6
+ export type TradeChannelProvider = "aliexpress" | "amazon" | "ebay" | "etsy" | "otto" | "bol" | "kaufland" | "tiktokshop" | "shein";
7
+ export type TradeChannelStatus = "unconfigured" | "connected" | "disconnected" | "error" | "expired";
8
+ /**
9
+ * What this channel can do for the customer. Both flows are independent
10
+ * because some providers expose only one side (e.g. Amazon retail has no
11
+ * public buy API — buy is "scrape" only, sell is full SP-API).
12
+ */
13
+ export interface ITradeChannelCapabilities {
14
+ canBuy: "api" | "scrape" | "none";
15
+ canSell: "api" | "none";
16
+ }
17
+ /**
18
+ * One (customer × provider × external account) connection.
19
+ * A customer can have multiple AliExpress accounts, etc. — each is its own
20
+ * TradeChannel row, scoped via externalAccountId.
21
+ *
22
+ * Credentials never live here directly. The `_credential` ObjectId points
23
+ * to the standard Credentials collection (AES-256-CTR encrypted).
24
+ */
25
+ export interface ITradeChannel extends IDefaultFields {
26
+ _customerID: ObjectId;
27
+ _clientID?: ObjectId[];
28
+ _subID?: ObjectId[];
29
+ provider: TradeChannelProvider;
30
+ /**
31
+ * Provider-side account identifier (e.g. AliExpress login email,
32
+ * Amazon seller ID, eBay user id). Allows multiple accounts per
33
+ * customer × provider. Required for the unique index.
34
+ */
35
+ externalAccountId: string;
36
+ /** Human-readable label shown in admin-v2 (e.g. "AliExpress (max@firma.de)"). */
37
+ label?: string;
38
+ status: TradeChannelStatus;
39
+ capabilities: ITradeChannelCapabilities;
40
+ /** Reference to encrypted credentials in the Credentials collection. */
41
+ _credential?: ObjectId;
42
+ /** Per-channel sync settings. */
43
+ settings?: {
44
+ /** Whether scraped/imported orders should auto-promote to SupplierOrder. Default false. */
45
+ autoPromote?: boolean;
46
+ /** Sync schedule for the per-provider worker. Default "manual". */
47
+ syncSchedule?: "manual" | "hourly" | "daily" | "weekly";
48
+ /** Default destination warehouse for buy-side dropship orders. */
49
+ defaultWarehouse?: ObjectId;
50
+ };
51
+ /** Last successful sync timestamps per direction. */
52
+ lastSyncedAt?: {
53
+ inbound?: Date;
54
+ outbound?: Date;
55
+ };
56
+ /** Last error message + timestamp from a failed sync run. */
57
+ lastError?: {
58
+ at: Date;
59
+ message: string;
60
+ code?: string;
61
+ };
62
+ /** Free-form provider-specific config (rate limits, marketplace ids, fulfillment templates, etc). */
63
+ providerConfig?: any;
64
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import { IDefaultFields } from "./IDefaultFields";
2
+ import { TradeChannelProvider } from "./ITradeChannel";
3
+ /**
4
+ * Channel-level event (not order-level — order events live on the order
5
+ * document itself in `events[]`).
6
+ *
7
+ * Captures: token refreshes, sync runs, webhook receipts, OAuth callbacks,
8
+ * connection tests, errors. Append-only with TTL 90d (set in Mongoose model).
9
+ */
10
+ export type TradeChannelEventType = "channel-created" | "oauth-started" | "oauth-completed" | "oauth-failed" | "token-refreshed" | "token-refresh-failed" | "sync-started" | "sync-completed" | "sync-failed" | "test-connection" | "webhook-received" | "import-batch" | "disconnected" | "error";
11
+ export type TradeChannelEventSeverity = "info" | "warn" | "error";
12
+ export interface ITradeChannelEvent extends IDefaultFields {
13
+ _customerID: ObjectId;
14
+ _clientID?: ObjectId[];
15
+ _subID?: ObjectId[];
16
+ _channel: ObjectId;
17
+ provider: TradeChannelProvider;
18
+ type: TradeChannelEventType;
19
+ severity: TradeChannelEventSeverity;
20
+ message?: string;
21
+ code?: string;
22
+ /** Optional structured payload (sync stats, webhook body summary, etc). */
23
+ data?: any;
24
+ /** Filled by import endpoint: how many orders the batch touched. */
25
+ counts?: {
26
+ created?: number;
27
+ updated?: number;
28
+ skipped?: number;
29
+ failed?: number;
30
+ };
31
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,143 @@
1
+ import { IDefaultFields } from "./IDefaultFields";
2
+ import { TradeChannelProvider } from "./ITradeChannel";
3
+ /**
4
+ * Direction of the order from the customer's perspective.
5
+ * - outbound: WE bought something from the provider (dropship, sourcing).
6
+ * - inbound: WE sold something via the provider (we are the seller).
7
+ */
8
+ export type TradeChannelOrderDirection = "outbound" | "inbound";
9
+ /**
10
+ * Where this order's data came from.
11
+ * - provider-api: pulled via official API (DS API, SP-API, eBay Sell, Etsy OpenAPI).
12
+ * - plugin-scrape: scraped by the aYOUne Companion browser extension.
13
+ * - provider-webhook: pushed by the provider via webhook.
14
+ * - manual: hand-entered in admin-v2.
15
+ */
16
+ export type TradeChannelOrderSource = "provider-api" | "plugin-scrape" | "provider-webhook" | "manual";
17
+ export type TradeChannelOrderStatus = "placed" | "paid" | "processing" | "shipped" | "delivered" | "completed" | "cancelled" | "refunded" | "dispute" | "unknown";
18
+ /**
19
+ * Single line item on a trade-channel order. Provider-agnostic.
20
+ * `_product` is filled by the post-import "match-products" worker when
21
+ * the external SKU/product can be linked to a Products entry.
22
+ */
23
+ export interface ITradeChannelOrderItem {
24
+ externalProductId: string;
25
+ externalSkuId?: string;
26
+ title: string;
27
+ qty: number;
28
+ unitPrice: number;
29
+ lineTotal?: number;
30
+ currency?: string;
31
+ thumbnailUrl?: string;
32
+ productUrl?: string;
33
+ /** Filled when the line item is matched to an internal Product. */
34
+ _product?: ObjectId;
35
+ /** Filled when the line item is matched to an internal SKU. */
36
+ _sku?: ObjectId;
37
+ /** Provider-specific extras (variant attributes, options, etc). */
38
+ attributes?: Record<string, any>;
39
+ }
40
+ /**
41
+ * Tracking / shipment data for one parcel on this order.
42
+ */
43
+ export interface ITradeChannelOrderShipment {
44
+ carrier?: string;
45
+ trackingNumber?: string;
46
+ trackingUrl?: string;
47
+ shippedAt?: Date;
48
+ estimatedDelivery?: Date;
49
+ deliveredAt?: Date;
50
+ status?: string;
51
+ }
52
+ /**
53
+ * Append-only event log entry on the order. Captures every meaningful
54
+ * change so we can audit who-changed-what across the api/scraper/webhook
55
+ * pipelines and de-duplicate confidently.
56
+ */
57
+ export interface ITradeChannelOrderEvent {
58
+ at: Date;
59
+ source: TradeChannelOrderSource;
60
+ type: string;
61
+ data?: any;
62
+ }
63
+ /**
64
+ * Full shipping address record. Stored in full per the user's choice
65
+ * (no hashing) — required for fulfillment on the sell side and for
66
+ * dropship destination on the buy side.
67
+ */
68
+ export interface ITradeChannelAddress {
69
+ company?: string;
70
+ salutation?: string;
71
+ firstName?: string;
72
+ lastName?: string;
73
+ street?: string;
74
+ houseNumber?: string;
75
+ addressAdditional?: string;
76
+ zip?: string;
77
+ city?: string;
78
+ state?: string;
79
+ country?: string;
80
+ countryCode?: string;
81
+ phone?: string;
82
+ email?: string;
83
+ }
84
+ /**
85
+ * One order flowing through a trade channel — bidirectional via `direction`.
86
+ * Unique per (customerId, _channel, externalId) so the same provider order
87
+ * id can never be inserted twice regardless of which pipeline reported it.
88
+ */
89
+ export interface ITradeChannelOrder extends IDefaultFields {
90
+ _customerID: ObjectId;
91
+ _clientID?: ObjectId[];
92
+ _subID?: ObjectId[];
93
+ /** Reference to the TradeChannel this order flows through. */
94
+ _channel: ObjectId;
95
+ /** Cached provider for fast queries without joining _channel. */
96
+ provider: TradeChannelProvider;
97
+ direction: TradeChannelOrderDirection;
98
+ source: TradeChannelOrderSource;
99
+ /** Provider-side order id. Unique within (_customerID, _channel). */
100
+ externalId: string;
101
+ externalUrl?: string;
102
+ status: TradeChannelOrderStatus;
103
+ /** Raw provider status string before normalization. */
104
+ rawStatus?: string;
105
+ orderDate: Date;
106
+ currency: string;
107
+ subtotal?: number;
108
+ shippingTotal?: number;
109
+ taxTotal?: number;
110
+ discountTotal?: number;
111
+ total: number;
112
+ /** Counterparty: the seller on outbound (we bought from them) or the buyer on inbound (we sold to them). */
113
+ counterparty?: {
114
+ externalId?: string;
115
+ name?: string;
116
+ storeUrl?: string;
117
+ email?: string;
118
+ };
119
+ /** Shipping address — full record per user choice (no hashing). */
120
+ shippingAddress?: ITradeChannelAddress;
121
+ /** Billing address if it differs. */
122
+ billingAddress?: ITradeChannelAddress;
123
+ items: ITradeChannelOrderItem[];
124
+ shipments?: ITradeChannelOrderShipment[];
125
+ events?: ITradeChannelOrderEvent[];
126
+ /** First time this order was seen by aYOUne (set on insert, never updated). */
127
+ firstSeenAt: Date;
128
+ firstSeenSource: TradeChannelOrderSource;
129
+ /** Last time any pipeline touched this order. */
130
+ lastSyncedAt?: Date;
131
+ /** When this order was promoted into a SupplierOrder (manual action only). */
132
+ promotedAt?: Date;
133
+ /** The SupplierOrder created from this trade-channel order, if promoted. */
134
+ _supplierOrder?: ObjectId;
135
+ /** The IncomeInvoice linked to the promotion, if any. */
136
+ _incomeInvoice?: ObjectId;
137
+ /** The GoodsReceipt linked to the promotion, if any. */
138
+ _goodsReceipt?: ObjectId;
139
+ /** Last raw payload from the provider/scraper, for debugging + diffing. */
140
+ raw?: any;
141
+ /** Free-form notes (admin-entered). */
142
+ note?: string;
143
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -653,6 +653,9 @@ export * from "./ITicket";
653
653
  export * from "./ITip";
654
654
  export * from "./ITitle";
655
655
  export * from "./ITrade";
656
+ export * from "./ITradeChannel";
657
+ export * from "./ITradeChannelEvent";
658
+ export * from "./ITradeChannelOrder";
656
659
  export * from "./ITransaction";
657
660
  export * from "./ITransportOrder";
658
661
  export * from "./ITravel";
@@ -669,6 +669,9 @@ __exportStar(require("./ITicket"), exports);
669
669
  __exportStar(require("./ITip"), exports);
670
670
  __exportStar(require("./ITitle"), exports);
671
671
  __exportStar(require("./ITrade"), exports);
672
+ __exportStar(require("./ITradeChannel"), exports);
673
+ __exportStar(require("./ITradeChannelEvent"), exports);
674
+ __exportStar(require("./ITradeChannelOrder"), exports);
672
675
  __exportStar(require("./ITransaction"), exports);
673
676
  __exportStar(require("./ITransportOrder"), exports);
674
677
  __exportStar(require("./ITravel"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-interfaces",
3
- "version": "2026.29.0",
3
+ "version": "2026.30.0",
4
4
  "description": "Houses TypeScript interfaces for aYOUne",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",