@porulle/plugin-channel-connector 0.60.0 → 0.62.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.
@@ -77,7 +77,9 @@ export function mockChannelConnector(options = {}) {
77
77
  return Ok(ids ? inventory.filter((item) => ids.includes(item.externalId)) : inventory);
78
78
  },
79
79
  async pushOrder(_store, slice) {
80
- const remoteOrderId = `mock-order-${orders.size + 1}`;
80
+ // Derived from the order, not counted: the count lived in this in-memory Map, which every
81
+ // Worker isolate starts empty, so two different orders both came back as mock-order-1.
82
+ const remoteOrderId = `mock-order-${slice.orderId}`;
81
83
  orders.set(remoteOrderId, structuredClone(slice));
82
84
  return Ok({
83
85
  remoteOrderId,
package/dist/service.js CHANGED
@@ -4196,6 +4196,9 @@ export class ChannelConnectorService {
4196
4196
  if (customer) {
4197
4197
  email = customer.email;
4198
4198
  name = `${customer.firstName ?? ""} ${customer.lastName ?? ""}`.trim();
4199
+ // The saved default is a FALLBACK. It was read first and the order's own address only when it
4200
+ // was missing, so a shopper who typed an address, or picked a non-default one, had the order
4201
+ // shipped to their default. The order's address is applied below and wins.
4199
4202
  const addresses = await this.db.select().from(customerAddresses).where(and(eq(customerAddresses.customerId, customer.id), eq(customerAddresses.type, "shipping")));
4200
4203
  const address = addresses.find((item) => item.isDefault) ?? addresses[0];
4201
4204
  if (address)
@@ -4206,9 +4209,9 @@ export class ChannelConnectorService {
4206
4209
  const guest = (metadata.customer ?? metadata.guestCustomer ?? {});
4207
4210
  email ??= typeof guest.email === "string" ? guest.email : null;
4208
4211
  name ||= typeof guest.name === "string" ? guest.name : `${typeof guest.firstName === "string" ? guest.firstName : ""} ${typeof guest.lastName === "string" ? guest.lastName : ""}`.trim();
4209
- const guestShipping = metadata.shippingAddress ?? metadata.guestShippingAddress ?? (typeof metadata.guestCustomer === "object" && metadata.guestCustomer ? metadata.guestCustomer.shippingAddress : undefined);
4210
- if (!shippingAddress && guestShipping && typeof guestShipping === "object")
4211
- shippingAddress = guestShipping;
4212
+ const orderShipping = metadata.shippingAddress ?? metadata.guestShippingAddress ?? (typeof metadata.guestCustomer === "object" && metadata.guestCustomer ? metadata.guestCustomer.shippingAddress : undefined);
4213
+ if (orderShipping && typeof orderShipping === "object")
4214
+ shippingAddress = orderShipping;
4212
4215
  if (!email || !shippingAddress)
4213
4216
  return PluginErr("Customer email and shipping address are required for channel order export.", "CUSTOMER_DATA_MISSING");
4214
4217
  return Ok({ orderId, currency: order.currency, grandTotal: lines.reduce((sum, line) => sum + line.totalPrice, 0), lines, customer: { name, email, shippingAddress } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/plugin-channel-connector",
3
- "version": "0.60.0",
3
+ "version": "0.62.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@hono/zod-openapi": "^1.2.2",
21
21
  "hono": "^4.12.5",
22
- "@porulle/core": "0.60.0"
22
+ "@porulle/core": "0.62.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^24.5.2",
@@ -104,7 +104,9 @@ export function mockChannelConnector(options: MockChannelConnectorOptions = {})
104
104
  return Ok(ids ? inventory.filter((item) => ids.includes(item.externalId)) : inventory);
105
105
  },
106
106
  async pushOrder(_store, slice) {
107
- const remoteOrderId = `mock-order-${orders.size + 1}`;
107
+ // Derived from the order, not counted: the count lived in this in-memory Map, which every
108
+ // Worker isolate starts empty, so two different orders both came back as mock-order-1.
109
+ const remoteOrderId = `mock-order-${slice.orderId}`;
108
110
  orders.set(remoteOrderId, structuredClone(slice));
109
111
  return Ok({
110
112
  remoteOrderId,
package/src/service.ts CHANGED
@@ -5345,6 +5345,9 @@ export class ChannelConnectorService {
5345
5345
  if (customer) {
5346
5346
  email = customer.email;
5347
5347
  name = `${customer.firstName ?? ""} ${customer.lastName ?? ""}`.trim();
5348
+ // The saved default is a FALLBACK. It was read first and the order's own address only when it
5349
+ // was missing, so a shopper who typed an address, or picked a non-default one, had the order
5350
+ // shipped to their default. The order's address is applied below and wins.
5348
5351
  const addresses = await this.db.select().from(customerAddresses).where(and(eq(customerAddresses.customerId, customer.id), eq(customerAddresses.type, "shipping")));
5349
5352
  const address = addresses.find((item) => item.isDefault) ?? addresses[0];
5350
5353
  if (address) shippingAddress = { first_name: address.firstName, last_name: address.lastName, address1: address.line1, ...(address.line2 ? { address2: address.line2 } : {}), city: address.city, ...(address.state ? { state: address.state } : {}), ...(address.postalCode ? { zip: address.postalCode } : {}), country: address.country, ...(address.phone ? { phone: address.phone } : {}) };
@@ -5354,8 +5357,8 @@ export class ChannelConnectorService {
5354
5357
  const guest = (metadata.customer ?? metadata.guestCustomer ?? {}) as Record<string, unknown>;
5355
5358
  email ??= typeof guest.email === "string" ? guest.email : null;
5356
5359
  name ||= typeof guest.name === "string" ? guest.name : `${typeof guest.firstName === "string" ? guest.firstName : ""} ${typeof guest.lastName === "string" ? guest.lastName : ""}`.trim();
5357
- const guestShipping = metadata.shippingAddress ?? metadata.guestShippingAddress ?? (typeof metadata.guestCustomer === "object" && metadata.guestCustomer ? (metadata.guestCustomer as Record<string, unknown>).shippingAddress : undefined);
5358
- if (!shippingAddress && guestShipping && typeof guestShipping === "object") shippingAddress = guestShipping as Record<string, unknown>;
5360
+ const orderShipping = metadata.shippingAddress ?? metadata.guestShippingAddress ?? (typeof metadata.guestCustomer === "object" && metadata.guestCustomer ? (metadata.guestCustomer as Record<string, unknown>).shippingAddress : undefined);
5361
+ if (orderShipping && typeof orderShipping === "object") shippingAddress = orderShipping as Record<string, unknown>;
5359
5362
  if (!email || !shippingAddress) return PluginErr("Customer email and shipping address are required for channel order export.", "CUSTOMER_DATA_MISSING");
5360
5363
  return Ok({ orderId, currency: order.currency, grandTotal: lines.reduce((sum, line) => sum + line.totalPrice, 0), lines, customer: { name, email, shippingAddress } });
5361
5364
  }