@fayz-ai/plugin-orders 0.10.0 → 0.11.1
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/dist/{OrdersPage-YTSYE573.js → OrdersPage-CQ7O74ZW.js} +4 -4
- package/dist/{OrdersPage-YTSYE573.js.map → OrdersPage-CQ7O74ZW.js.map} +1 -1
- package/dist/{chunk-LUFSNZYT.js → chunk-MTVIXIPL.js} +2 -2
- package/dist/{chunk-LUFSNZYT.js.map → chunk-MTVIXIPL.js.map} +1 -1
- package/dist/data/platform.d.ts +4 -3
- package/dist/data/platform.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +327 -43
- package/dist/index.js.map +1 -1
- package/dist/integrations/aiqfome/connectorDef.d.ts +5 -0
- package/dist/integrations/aiqfome/connectorDef.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +3 -0
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/rappi/connectorDef.d.ts +5 -0
- package/dist/integrations/rappi/connectorDef.d.ts.map +1 -0
- package/dist/integrations/ubereats/connectorDef.d.ts +5 -0
- package/dist/integrations/ubereats/connectorDef.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNextStatus, STATUS_FLOW } from './chunk-
|
|
1
|
+
import { getNextStatus, STATUS_FLOW } from './chunk-MTVIXIPL.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { createStore } from 'zustand/vanilla';
|
|
4
4
|
import { fayzConnectorOAuth, PluginSettingsPanel, dedup } from '@fayz-ai/admin';
|
|
@@ -931,9 +931,219 @@ var keetaConnectorDef = {
|
|
|
931
931
|
disconnect: () => store3.disconnect(),
|
|
932
932
|
disconnectNote: "Desconectar para de trazer pedidos novos. Os pedidos que j\xE1 entraram continuam aqui."
|
|
933
933
|
};
|
|
934
|
+
var UBER_EATS_CONNECTOR_ID = "ubereats";
|
|
935
|
+
var SERVICE_MODE_LABELS3 = { DELIVERY: "Entrega", PICKUP: "Retirada" };
|
|
936
|
+
var UBER_EATS_SETTINGS = [
|
|
937
|
+
{
|
|
938
|
+
key: "serviceModes",
|
|
939
|
+
label: "Quais pedidos trazer",
|
|
940
|
+
description: "O Uber Eats entrega e deixa retirar; estes s\xE3o os que viram pedido aqui.",
|
|
941
|
+
type: "multi-select",
|
|
942
|
+
options: [
|
|
943
|
+
{ value: "DELIVERY", label: SERVICE_MODE_LABELS3.DELIVERY },
|
|
944
|
+
{ value: "PICKUP", label: SERVICE_MODE_LABELS3.PICKUP }
|
|
945
|
+
],
|
|
946
|
+
requiredToOperate: true,
|
|
947
|
+
defaultValue: ["DELIVERY"]
|
|
948
|
+
},
|
|
949
|
+
AUTO_ACCEPT_SETTING,
|
|
950
|
+
PREP_TIME_SETTING
|
|
951
|
+
];
|
|
952
|
+
var store4 = createConnectionStore(UBER_EATS_CONNECTOR_ID, {
|
|
953
|
+
settings: UBER_EATS_SETTINGS,
|
|
954
|
+
settingsKeys: ["storeId"]
|
|
955
|
+
});
|
|
956
|
+
var uberEatsConnectorDef = {
|
|
957
|
+
id: UBER_EATS_CONNECTOR_ID,
|
|
958
|
+
hostPluginId: "orders",
|
|
959
|
+
name: "Uber Eats",
|
|
960
|
+
description: "Traga para a cozinha cada pedido feito no Uber Eats, e avise o Uber Eats quando ele for confirmado e sair.",
|
|
961
|
+
icon: "Bike",
|
|
962
|
+
category: "marketplace",
|
|
963
|
+
// Two grants, one merchant-facing: `client_credentials` for the day-to-day
|
|
964
|
+
// calls and `authorization_code` for the store activation. It is the second
|
|
965
|
+
// that this button opens.
|
|
966
|
+
authKind: "oauth",
|
|
967
|
+
// `inbound` is about the data, not who dials: Uber Eats pushes, like Keeta.
|
|
968
|
+
direction: "inbound",
|
|
969
|
+
planes: ["sync"],
|
|
970
|
+
docsUrl: "https://developer.uber.com/docs/eats/introduction",
|
|
971
|
+
// No rateLimit: a budget describes what we spend, and nothing here polls Uber.
|
|
972
|
+
permissions: marketplacePermissions("Uber Eats"),
|
|
973
|
+
fields: [],
|
|
974
|
+
settings: UBER_EATS_SETTINGS,
|
|
975
|
+
howItSyncs: [
|
|
976
|
+
"O Uber Eats avisa assim que um pedido \xE9 feito, e ele entra na tela de Pedidos.",
|
|
977
|
+
"Um pedido j\xE1 trazido n\xE3o entra duas vezes: ele guarda o n\xFAmero que tem no Uber Eats.",
|
|
978
|
+
"Confirmar, despachar ou cancelar aqui \xE9 o que avisa o Uber Eats."
|
|
979
|
+
],
|
|
980
|
+
...connectionStatus(
|
|
981
|
+
UBER_EATS_CONNECTOR_ID,
|
|
982
|
+
(connection) => ({
|
|
983
|
+
connected: !!connection?.active,
|
|
984
|
+
detail: serviceModesDetail(SERVICE_MODE_LABELS3, connection?.settings?.serviceModes),
|
|
985
|
+
plane: "sync",
|
|
986
|
+
...settingsStatus(UBER_EATS_SETTINGS, connection)
|
|
987
|
+
}),
|
|
988
|
+
{ store: () => store4 }
|
|
989
|
+
),
|
|
990
|
+
...connectionSettings(store4),
|
|
991
|
+
...connectionRuns(store4),
|
|
992
|
+
startOAuth: fayzConnectorOAuth(UBER_EATS_CONNECTOR_ID),
|
|
993
|
+
saveConnection: async () => {
|
|
994
|
+
await store4.save({ active: true });
|
|
995
|
+
},
|
|
996
|
+
disconnect: () => store4.disconnect(),
|
|
997
|
+
disconnectNote: "Desconectar para de trazer pedidos novos. Os pedidos que j\xE1 entraram continuam aqui."
|
|
998
|
+
};
|
|
999
|
+
var RAPPI_CONNECTOR_ID = "rappi";
|
|
1000
|
+
var SERVICE_MODE_LABELS4 = { DELIVERY: "Entrega", PICKUP: "Retirada" };
|
|
1001
|
+
var RAPPI_SETTINGS = [
|
|
1002
|
+
{
|
|
1003
|
+
key: "serviceModes",
|
|
1004
|
+
label: "Quais pedidos trazer",
|
|
1005
|
+
description: "O Rappi entrega e deixa retirar; estes s\xE3o os que viram pedido aqui.",
|
|
1006
|
+
type: "multi-select",
|
|
1007
|
+
options: [
|
|
1008
|
+
{ value: "DELIVERY", label: SERVICE_MODE_LABELS4.DELIVERY },
|
|
1009
|
+
{ value: "PICKUP", label: SERVICE_MODE_LABELS4.PICKUP }
|
|
1010
|
+
],
|
|
1011
|
+
requiredToOperate: true,
|
|
1012
|
+
defaultValue: ["DELIVERY"]
|
|
1013
|
+
},
|
|
1014
|
+
AUTO_ACCEPT_SETTING,
|
|
1015
|
+
PREP_TIME_SETTING
|
|
1016
|
+
];
|
|
1017
|
+
var store5 = createConnectionStore(RAPPI_CONNECTOR_ID, {
|
|
1018
|
+
settings: RAPPI_SETTINGS,
|
|
1019
|
+
settingsKeys: ["storeId"]
|
|
1020
|
+
});
|
|
1021
|
+
var rappiConnectorDef = {
|
|
1022
|
+
id: RAPPI_CONNECTOR_ID,
|
|
1023
|
+
hostPluginId: "orders",
|
|
1024
|
+
name: "Rappi",
|
|
1025
|
+
description: "Traga para a cozinha cada pedido feito no Rappi, e avise o Rappi quando ele for confirmado e sair.",
|
|
1026
|
+
icon: "Bike",
|
|
1027
|
+
category: "marketplace",
|
|
1028
|
+
authKind: "api-key",
|
|
1029
|
+
direction: "inbound",
|
|
1030
|
+
planes: ["sync"],
|
|
1031
|
+
docsUrl: "https://dev-portal.rappi.com/pt/",
|
|
1032
|
+
// No `providerInstall`: there is no panel where the restaurant fetches a key,
|
|
1033
|
+
// because there is no key for the restaurant to fetch.
|
|
1034
|
+
//
|
|
1035
|
+
// No rateLimit: Rappi's own standard is a request every 45 seconds, and that
|
|
1036
|
+
// budget belongs with the job that spends it — which is not written yet.
|
|
1037
|
+
permissions: marketplacePermissions("Rappi"),
|
|
1038
|
+
// Nothing to fill in: the pair is registered in Fayz, and the connect step
|
|
1039
|
+
// says exactly that instead of drawing an empty grid.
|
|
1040
|
+
fields: [],
|
|
1041
|
+
settings: RAPPI_SETTINGS,
|
|
1042
|
+
howItSyncs: [
|
|
1043
|
+
"De tempos em tempos, os pedidos novos do Rappi entram na tela de Pedidos.",
|
|
1044
|
+
"Um pedido j\xE1 trazido n\xE3o entra duas vezes: ele guarda o n\xFAmero que tem no Rappi.",
|
|
1045
|
+
"Confirmar, despachar ou cancelar aqui \xE9 o que avisa o Rappi."
|
|
1046
|
+
],
|
|
1047
|
+
...connectionStatus(
|
|
1048
|
+
RAPPI_CONNECTOR_ID,
|
|
1049
|
+
(connection) => ({
|
|
1050
|
+
connected: !!connection?.active,
|
|
1051
|
+
detail: serviceModesDetail(SERVICE_MODE_LABELS4, connection?.settings?.serviceModes),
|
|
1052
|
+
plane: "sync",
|
|
1053
|
+
...settingsStatus(RAPPI_SETTINGS, connection)
|
|
1054
|
+
}),
|
|
1055
|
+
{ store: () => store5 }
|
|
1056
|
+
),
|
|
1057
|
+
...connectionSettings(store5),
|
|
1058
|
+
...connectionRuns(store5),
|
|
1059
|
+
// No `testConnection`, for PlugBank's reason: the credential is not in this
|
|
1060
|
+
// app, so there is nothing this side can validate — and ConnectorDetail
|
|
1061
|
+
// renders the button only when the verb exists.
|
|
1062
|
+
saveConnection: async () => {
|
|
1063
|
+
await store5.save({ active: true });
|
|
1064
|
+
},
|
|
1065
|
+
disconnect: () => store5.disconnect(),
|
|
1066
|
+
disconnectNote: "Desconectar para de trazer pedidos novos. Os pedidos que j\xE1 entraram continuam aqui."
|
|
1067
|
+
};
|
|
1068
|
+
var AIQFOME_CONNECTOR_ID = "aiqfome";
|
|
1069
|
+
var SERVICE_MODE_LABELS5 = { DELIVERY: "Entrega", PICKUP: "Retirada" };
|
|
1070
|
+
var AIQFOME_SETTINGS = [
|
|
1071
|
+
{
|
|
1072
|
+
key: "serviceModes",
|
|
1073
|
+
label: "Quais pedidos trazer",
|
|
1074
|
+
description: "O aiqfome entrega e deixa retirar; estes s\xE3o os que viram pedido aqui.",
|
|
1075
|
+
type: "multi-select",
|
|
1076
|
+
options: [
|
|
1077
|
+
{ value: "DELIVERY", label: SERVICE_MODE_LABELS5.DELIVERY },
|
|
1078
|
+
{ value: "PICKUP", label: SERVICE_MODE_LABELS5.PICKUP }
|
|
1079
|
+
],
|
|
1080
|
+
requiredToOperate: true,
|
|
1081
|
+
defaultValue: ["DELIVERY"]
|
|
1082
|
+
},
|
|
1083
|
+
AUTO_ACCEPT_SETTING,
|
|
1084
|
+
PREP_TIME_SETTING
|
|
1085
|
+
];
|
|
1086
|
+
var store6 = createConnectionStore(AIQFOME_CONNECTOR_ID, {
|
|
1087
|
+
settings: AIQFOME_SETTINGS,
|
|
1088
|
+
settingsKeys: ["storeId"]
|
|
1089
|
+
});
|
|
1090
|
+
var aiqfomeConnectorDef = {
|
|
1091
|
+
id: AIQFOME_CONNECTOR_ID,
|
|
1092
|
+
hostPluginId: "orders",
|
|
1093
|
+
name: "aiqfome",
|
|
1094
|
+
description: "Traga para a cozinha cada pedido feito no aiqfome, e avise o aiqfome quando ele for confirmado e sair.",
|
|
1095
|
+
icon: "Bike",
|
|
1096
|
+
category: "marketplace",
|
|
1097
|
+
// Magalu ID: authorization code, `access_token` + `refresh_token`, and the
|
|
1098
|
+
// consent lives on the seller's own panel.
|
|
1099
|
+
authKind: "oauth",
|
|
1100
|
+
direction: "inbound",
|
|
1101
|
+
planes: ["sync"],
|
|
1102
|
+
docsUrl: "https://developer.aiqfome.com/docs/api/versions",
|
|
1103
|
+
// No rateLimit: how often the orders are read is part of what is unverified.
|
|
1104
|
+
permissions: marketplacePermissions("aiqfome"),
|
|
1105
|
+
fields: [],
|
|
1106
|
+
settings: AIQFOME_SETTINGS,
|
|
1107
|
+
howItSyncs: [
|
|
1108
|
+
"Cada pedido novo no aiqfome entra na tela de Pedidos.",
|
|
1109
|
+
"Um pedido j\xE1 trazido n\xE3o entra duas vezes: ele guarda o n\xFAmero que tem no aiqfome.",
|
|
1110
|
+
"Confirmar, despachar ou cancelar aqui \xE9 o que avisa o aiqfome."
|
|
1111
|
+
],
|
|
1112
|
+
...connectionStatus(
|
|
1113
|
+
AIQFOME_CONNECTOR_ID,
|
|
1114
|
+
(connection) => ({
|
|
1115
|
+
connected: !!connection?.active,
|
|
1116
|
+
detail: serviceModesDetail(SERVICE_MODE_LABELS5, connection?.settings?.serviceModes),
|
|
1117
|
+
plane: "sync",
|
|
1118
|
+
...settingsStatus(AIQFOME_SETTINGS, connection)
|
|
1119
|
+
}),
|
|
1120
|
+
{ store: () => store6 }
|
|
1121
|
+
),
|
|
1122
|
+
...connectionSettings(store6),
|
|
1123
|
+
...connectionRuns(store6),
|
|
1124
|
+
startOAuth: fayzConnectorOAuth(AIQFOME_CONNECTOR_ID),
|
|
1125
|
+
saveConnection: async () => {
|
|
1126
|
+
await store6.save({ active: true });
|
|
1127
|
+
},
|
|
1128
|
+
disconnect: () => store6.disconnect(),
|
|
1129
|
+
disconnectNote: "Desconectar para de trazer pedidos novos. Os pedidos que j\xE1 entraram continuam aqui."
|
|
1130
|
+
};
|
|
934
1131
|
var DEFAULT_ORDERS_TABLE = "orders";
|
|
935
1132
|
var DEFAULT_ORDER_ITEMS_TABLE = "order_items";
|
|
1133
|
+
var ORDERS_METADATA_KEY = "fayzOrders";
|
|
936
1134
|
var ACTIVE_STATUSES = /* @__PURE__ */ new Set(["new", "confirmed", "preparing", "ready", "served", "dispatched"]);
|
|
1135
|
+
var RESTAURANT_STATUSES = /* @__PURE__ */ new Set([
|
|
1136
|
+
"new",
|
|
1137
|
+
"confirmed",
|
|
1138
|
+
"preparing",
|
|
1139
|
+
"ready",
|
|
1140
|
+
"served",
|
|
1141
|
+
"picked_up",
|
|
1142
|
+
"dispatched",
|
|
1143
|
+
"delivered",
|
|
1144
|
+
"completed",
|
|
1145
|
+
"cancelled"
|
|
1146
|
+
]);
|
|
937
1147
|
function nowIso() {
|
|
938
1148
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
939
1149
|
}
|
|
@@ -948,10 +1158,40 @@ function dateKey(value) {
|
|
|
948
1158
|
function referenceNumber() {
|
|
949
1159
|
return `ORD-${Date.now().toString().slice(-6)}`;
|
|
950
1160
|
}
|
|
951
|
-
function
|
|
1161
|
+
function objectValue(value) {
|
|
1162
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1163
|
+
}
|
|
1164
|
+
function canonicalStatus(status) {
|
|
1165
|
+
if (status === "new") return "draft";
|
|
1166
|
+
if (status === "completed" || status === "cancelled") return status;
|
|
1167
|
+
return "confirmed";
|
|
1168
|
+
}
|
|
1169
|
+
function restaurantStatus(rowStatus, metadata) {
|
|
1170
|
+
if (rowStatus === "completed" || rowStatus === "cancelled") return rowStatus;
|
|
1171
|
+
const stored = metadata.restaurantStatus;
|
|
1172
|
+
if (typeof stored === "string" && RESTAURANT_STATUSES.has(stored)) return stored;
|
|
1173
|
+
if (rowStatus === "draft") return "new";
|
|
1174
|
+
if (typeof rowStatus === "string" && RESTAURANT_STATUSES.has(rowStatus)) return rowStatus;
|
|
1175
|
+
return "confirmed";
|
|
1176
|
+
}
|
|
1177
|
+
function ordersMetadata(metadata) {
|
|
1178
|
+
return objectValue(metadata?.[ORDERS_METADATA_KEY]);
|
|
1179
|
+
}
|
|
1180
|
+
function mergeOrdersMetadata(metadata, patch) {
|
|
1181
|
+
const base = { ...metadata ?? {} };
|
|
1182
|
+
const current = ordersMetadata(base);
|
|
1183
|
+
const definedPatch = Object.fromEntries(
|
|
1184
|
+
Object.entries(patch).filter(([, value]) => value !== void 0)
|
|
1185
|
+
);
|
|
1186
|
+
const next = { ...current, ...definedPatch };
|
|
1187
|
+
return { ...base, [ORDERS_METADATA_KEY]: next };
|
|
1188
|
+
}
|
|
1189
|
+
function itemToRow(item, orderId, sortOrder, tenantId, unitId) {
|
|
952
1190
|
const discount = item.discount ?? 0;
|
|
953
1191
|
return {
|
|
954
1192
|
order_id: orderId,
|
|
1193
|
+
...tenantId ? { tenant_id: tenantId } : {},
|
|
1194
|
+
...unitId ? { unit_id: unitId } : {},
|
|
955
1195
|
product_id: item.productId ?? null,
|
|
956
1196
|
name: item.name,
|
|
957
1197
|
quantity: item.quantity,
|
|
@@ -959,14 +1199,17 @@ function itemToRow(item, orderId, sortOrder) {
|
|
|
959
1199
|
discount,
|
|
960
1200
|
total: item.quantity * item.unitPrice - discount,
|
|
961
1201
|
sort_order: sortOrder,
|
|
962
|
-
|
|
963
|
-
|
|
1202
|
+
metadata: mergeOrdersMetadata(void 0, {
|
|
1203
|
+
modifiers: item.modifiers ?? null,
|
|
1204
|
+
kitchenNotes: item.kitchenNotes ?? null
|
|
1205
|
+
})
|
|
964
1206
|
};
|
|
965
1207
|
}
|
|
966
1208
|
function rowToItem(row) {
|
|
967
1209
|
const quantity = numberValue(row.quantity);
|
|
968
1210
|
const unitPrice = numberValue(row.unit_price);
|
|
969
1211
|
const discount = numberValue(row.discount);
|
|
1212
|
+
const restaurant = ordersMetadata(row.metadata);
|
|
970
1213
|
return {
|
|
971
1214
|
id: row.id,
|
|
972
1215
|
orderId: row.order_id ?? "",
|
|
@@ -978,8 +1221,8 @@ function rowToItem(row) {
|
|
|
978
1221
|
discount,
|
|
979
1222
|
total: numberValue(row.total) || quantity * unitPrice - discount,
|
|
980
1223
|
sortOrder: row.sort_order ?? 0,
|
|
981
|
-
modifiers: row.modifiers ?? void 0,
|
|
982
|
-
kitchenNotes: row.kitchen_notes ?? void 0,
|
|
1224
|
+
modifiers: row.modifiers ?? (typeof restaurant.modifiers === "string" ? restaurant.modifiers : void 0),
|
|
1225
|
+
kitchenNotes: row.kitchen_notes ?? (typeof restaurant.kitchenNotes === "string" ? restaurant.kitchenNotes : void 0),
|
|
983
1226
|
metadata: row.metadata ?? {},
|
|
984
1227
|
createdAt: row.created_at ?? nowIso()
|
|
985
1228
|
};
|
|
@@ -988,15 +1231,16 @@ function rowToOrder(row, items = []) {
|
|
|
988
1231
|
const subtotal = numberValue(row.subtotal) || items.reduce((sum, item) => sum + item.total, 0);
|
|
989
1232
|
const discount = numberValue(row.discount);
|
|
990
1233
|
const tax = numberValue(row.tax);
|
|
1234
|
+
const restaurant = ordersMetadata(row.metadata);
|
|
991
1235
|
return {
|
|
992
1236
|
id: row.id,
|
|
993
1237
|
referenceNumber: row.reference_number ?? row.id,
|
|
994
1238
|
kind: row.kind ?? "dine_in",
|
|
995
|
-
status: row.status
|
|
1239
|
+
status: restaurantStatus(row.status, restaurant),
|
|
996
1240
|
partyId: row.party_id ?? void 0,
|
|
997
|
-
partyName: row.party_name ?? void 0,
|
|
1241
|
+
partyName: row.party_name ?? (typeof restaurant.partyName === "string" ? restaurant.partyName : void 0),
|
|
998
1242
|
assigneeId: row.assignee_id ?? void 0,
|
|
999
|
-
assigneeName: row.assignee_name ?? void 0,
|
|
1243
|
+
assigneeName: row.assignee_name ?? (typeof restaurant.assigneeName === "string" ? restaurant.assigneeName : void 0),
|
|
1000
1244
|
locationId: row.location_id ?? void 0,
|
|
1001
1245
|
subtotal,
|
|
1002
1246
|
discount,
|
|
@@ -1005,13 +1249,14 @@ function rowToOrder(row, items = []) {
|
|
|
1005
1249
|
currency: row.currency ?? "BRL",
|
|
1006
1250
|
notes: row.notes ?? void 0,
|
|
1007
1251
|
tags: row.tags ?? [],
|
|
1008
|
-
source: row.source ?? "pos",
|
|
1009
|
-
tableId: row.table_id ?? void 0,
|
|
1010
|
-
tableName: row.table_name ?? void 0,
|
|
1011
|
-
estimatedMinutes: row.estimated_minutes ?? void 0,
|
|
1252
|
+
source: row.source ?? (typeof restaurant.source === "string" ? restaurant.source : "pos"),
|
|
1253
|
+
tableId: row.table_id ?? (typeof restaurant.tableId === "string" ? restaurant.tableId : void 0),
|
|
1254
|
+
tableName: row.table_name ?? (typeof restaurant.tableName === "string" ? restaurant.tableName : void 0),
|
|
1255
|
+
estimatedMinutes: row.estimated_minutes ?? (typeof restaurant.estimatedMinutes === "number" ? restaurant.estimatedMinutes : void 0),
|
|
1012
1256
|
items,
|
|
1013
1257
|
metadata: row.metadata ?? {},
|
|
1014
1258
|
tenantId: row.tenant_id ?? "runtime-tenant",
|
|
1259
|
+
unitId: row.unit_id ?? void 0,
|
|
1015
1260
|
createdAt: row.created_at ?? nowIso(),
|
|
1016
1261
|
updatedAt: row.updated_at ?? row.created_at ?? nowIso(),
|
|
1017
1262
|
completedAt: row.completed_at ?? void 0
|
|
@@ -1022,30 +1267,31 @@ function orderPayload(input) {
|
|
|
1022
1267
|
return {
|
|
1023
1268
|
reference_number: referenceNumber(),
|
|
1024
1269
|
kind: input.kind,
|
|
1025
|
-
status: "
|
|
1026
|
-
source: input.source ?? "pos",
|
|
1027
|
-
table_id: input.tableId ?? null,
|
|
1270
|
+
status: "draft",
|
|
1028
1271
|
party_id: input.partyId ?? null,
|
|
1029
1272
|
assignee_id: input.assigneeId ?? null,
|
|
1030
1273
|
notes: input.notes ?? null,
|
|
1031
|
-
estimated_minutes: input.estimatedMinutes ?? null,
|
|
1032
1274
|
subtotal,
|
|
1033
1275
|
discount: 0,
|
|
1034
1276
|
tax: 0,
|
|
1035
1277
|
total: subtotal,
|
|
1036
1278
|
currency: "BRL",
|
|
1037
|
-
tags: []
|
|
1279
|
+
tags: [],
|
|
1280
|
+
metadata: mergeOrdersMetadata(void 0, {
|
|
1281
|
+
source: input.source ?? "pos",
|
|
1282
|
+
tableId: input.tableId ?? null,
|
|
1283
|
+
estimatedMinutes: input.estimatedMinutes ?? null,
|
|
1284
|
+
restaurantStatus: "new"
|
|
1285
|
+
})
|
|
1038
1286
|
};
|
|
1039
1287
|
}
|
|
1040
|
-
function updatePayload(data) {
|
|
1288
|
+
function updatePayload(data, existingMetadata) {
|
|
1041
1289
|
const payload = {};
|
|
1042
1290
|
if (data.referenceNumber !== void 0) payload.reference_number = data.referenceNumber;
|
|
1043
1291
|
if (data.kind !== void 0) payload.kind = data.kind;
|
|
1044
|
-
if (data.status !== void 0) payload.status = data.status;
|
|
1292
|
+
if (data.status !== void 0) payload.status = canonicalStatus(data.status);
|
|
1045
1293
|
if (data.partyId !== void 0) payload.party_id = data.partyId;
|
|
1046
|
-
if (data.partyName !== void 0) payload.party_name = data.partyName;
|
|
1047
1294
|
if (data.assigneeId !== void 0) payload.assignee_id = data.assigneeId;
|
|
1048
|
-
if (data.assigneeName !== void 0) payload.assignee_name = data.assigneeName;
|
|
1049
1295
|
if (data.locationId !== void 0) payload.location_id = data.locationId;
|
|
1050
1296
|
if (data.subtotal !== void 0) payload.subtotal = data.subtotal;
|
|
1051
1297
|
if (data.discount !== void 0) payload.discount = data.discount;
|
|
@@ -1054,26 +1300,35 @@ function updatePayload(data) {
|
|
|
1054
1300
|
if (data.currency !== void 0) payload.currency = data.currency;
|
|
1055
1301
|
if (data.notes !== void 0) payload.notes = data.notes;
|
|
1056
1302
|
if (data.tags !== void 0) payload.tags = data.tags;
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1303
|
+
const metadataBase = data.metadata !== void 0 ? { ...existingMetadata ?? {}, ...data.metadata } : existingMetadata;
|
|
1304
|
+
const metadataPatch = {
|
|
1305
|
+
partyName: data.partyName,
|
|
1306
|
+
assigneeName: data.assigneeName,
|
|
1307
|
+
source: data.source,
|
|
1308
|
+
tableId: data.tableId,
|
|
1309
|
+
tableName: data.tableName,
|
|
1310
|
+
estimatedMinutes: data.estimatedMinutes,
|
|
1311
|
+
restaurantStatus: data.status
|
|
1312
|
+
};
|
|
1313
|
+
if (data.metadata !== void 0 || Object.values(metadataPatch).some((value) => value !== void 0)) {
|
|
1314
|
+
payload.metadata = mergeOrdersMetadata(metadataBase, metadataPatch);
|
|
1315
|
+
}
|
|
1062
1316
|
if (data.completedAt !== void 0) payload.completed_at = data.completedAt;
|
|
1063
1317
|
return payload;
|
|
1064
1318
|
}
|
|
1065
1319
|
function filtersFromQuery(query) {
|
|
1066
1320
|
const filters = [];
|
|
1067
1321
|
if (query.kind && !Array.isArray(query.kind)) filters.push({ column: "kind", operator: "eq", value: query.kind });
|
|
1068
|
-
if (query.status && !Array.isArray(query.status)) filters.push({ column: "status", operator: "eq", value: query.status });
|
|
1069
|
-
if (query.source) filters.push({ column: "source", operator: "eq", value: query.source });
|
|
1070
|
-
if (query.tableId) filters.push({ column: "table_id", operator: "eq", value: query.tableId });
|
|
1071
1322
|
if (query.assigneeId) filters.push({ column: "assignee_id", operator: "eq", value: query.assigneeId });
|
|
1072
1323
|
return filters;
|
|
1073
1324
|
}
|
|
1074
1325
|
function matchesClientQuery(order, query) {
|
|
1075
1326
|
if (Array.isArray(query.kind) && !query.kind.includes(order.kind)) return false;
|
|
1076
1327
|
if (Array.isArray(query.status) && !query.status.includes(order.status)) return false;
|
|
1328
|
+
if (query.status && !Array.isArray(query.status) && order.status !== query.status) return false;
|
|
1329
|
+
if (query.source && order.source !== query.source) return false;
|
|
1330
|
+
if (query.tableId && order.tableId !== query.tableId) return false;
|
|
1331
|
+
if (query.assigneeId && order.assigneeId !== query.assigneeId) return false;
|
|
1077
1332
|
if (query.dateRange) {
|
|
1078
1333
|
const created = dateKey(order.createdAt);
|
|
1079
1334
|
if (created < query.dateRange.from || created > query.dateRange.to) return false;
|
|
@@ -1133,6 +1388,10 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1133
1388
|
const value = typeof options.tenantId === "function" ? options.tenantId() : options.tenantId;
|
|
1134
1389
|
return value ?? void 0;
|
|
1135
1390
|
}
|
|
1391
|
+
function resolveUnit() {
|
|
1392
|
+
const value = typeof options.unitId === "function" ? options.unitId() : options.unitId;
|
|
1393
|
+
return value ?? void 0;
|
|
1394
|
+
}
|
|
1136
1395
|
function withTenant(filters) {
|
|
1137
1396
|
const tenantId = resolveTenant();
|
|
1138
1397
|
return tenantId ? [{ column: "tenant_id", operator: "eq", value: tenantId }, ...filters] : filters;
|
|
@@ -1194,15 +1453,20 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1194
1453
|
},
|
|
1195
1454
|
async createOrder(input) {
|
|
1196
1455
|
const tenantId = resolveTenant();
|
|
1456
|
+
const unitId = resolveUnit();
|
|
1197
1457
|
const orderRow = await client.data.createRow({
|
|
1198
1458
|
...tableOptions,
|
|
1199
1459
|
table: ordersTable,
|
|
1200
|
-
row:
|
|
1460
|
+
row: {
|
|
1461
|
+
...orderPayload(input),
|
|
1462
|
+
...tenantId ? { tenant_id: tenantId } : {},
|
|
1463
|
+
...unitId ? { unit_id: unitId } : {}
|
|
1464
|
+
}
|
|
1201
1465
|
});
|
|
1202
1466
|
await Promise.all(input.items.map((item, index) => client.data.createRow({
|
|
1203
1467
|
...tableOptions,
|
|
1204
1468
|
table: orderItemsTable,
|
|
1205
|
-
row: itemToRow(item, orderRow.id, index)
|
|
1469
|
+
row: itemToRow(item, orderRow.id, index, tenantId, unitId)
|
|
1206
1470
|
})));
|
|
1207
1471
|
return await getById(orderRow.id) ?? rowToOrder(orderRow);
|
|
1208
1472
|
},
|
|
@@ -1211,11 +1475,12 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1211
1475
|
return this.updateOrder(input.orderId, { status: input.status, completedAt });
|
|
1212
1476
|
},
|
|
1213
1477
|
async updateOrder(id, data) {
|
|
1478
|
+
const existing = await getById(id);
|
|
1214
1479
|
const row = await client.data.updateRow({
|
|
1215
1480
|
...tableOptions,
|
|
1216
1481
|
table: ordersTable,
|
|
1217
1482
|
primaryKeys: { id },
|
|
1218
|
-
row: updatePayload(data)
|
|
1483
|
+
row: updatePayload(data, existing?.metadata)
|
|
1219
1484
|
});
|
|
1220
1485
|
return await getById(row.id) ?? rowToOrder(row);
|
|
1221
1486
|
},
|
|
@@ -1232,7 +1497,7 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1232
1497
|
const row = await client.data.createRow({
|
|
1233
1498
|
...tableOptions,
|
|
1234
1499
|
table: orderItemsTable,
|
|
1235
|
-
row: itemToRow(item, orderId, order?.items.length ?? 0)
|
|
1500
|
+
row: itemToRow(item, orderId, order?.items.length ?? 0, order?.tenantId, order?.unitId ?? resolveUnit())
|
|
1236
1501
|
});
|
|
1237
1502
|
const created = rowToItem(row);
|
|
1238
1503
|
const items = [...order?.items ?? [], created];
|
|
@@ -1253,6 +1518,17 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1253
1518
|
}
|
|
1254
1519
|
},
|
|
1255
1520
|
async updateOrderItem(itemId, data) {
|
|
1521
|
+
const existingResult = await client.data.listRows({
|
|
1522
|
+
...tableOptions,
|
|
1523
|
+
table: orderItemsTable,
|
|
1524
|
+
filters: [{ column: "id", operator: "eq", value: itemId }],
|
|
1525
|
+
limit: 1
|
|
1526
|
+
});
|
|
1527
|
+
const existingMetadata = existingResult.rows[0]?.metadata ?? void 0;
|
|
1528
|
+
const metadataPatch = {
|
|
1529
|
+
modifiers: data.modifiers,
|
|
1530
|
+
kitchenNotes: data.kitchenNotes
|
|
1531
|
+
};
|
|
1256
1532
|
const row = await client.data.updateRow({
|
|
1257
1533
|
...tableOptions,
|
|
1258
1534
|
table: orderItemsTable,
|
|
@@ -1266,9 +1542,10 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1266
1542
|
discount: data.discount,
|
|
1267
1543
|
total: data.total,
|
|
1268
1544
|
sort_order: data.sortOrder,
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1545
|
+
metadata: data.metadata !== void 0 || Object.values(metadataPatch).some((value) => value !== void 0) ? mergeOrdersMetadata(
|
|
1546
|
+
data.metadata !== void 0 ? { ...existingMetadata ?? {}, ...data.metadata } : existingMetadata,
|
|
1547
|
+
metadataPatch
|
|
1548
|
+
) : void 0
|
|
1272
1549
|
}
|
|
1273
1550
|
});
|
|
1274
1551
|
return rowToItem(row);
|
|
@@ -1280,7 +1557,7 @@ function createFayzOrdersProvider(options = {}) {
|
|
|
1280
1557
|
}
|
|
1281
1558
|
|
|
1282
1559
|
// src/index.ts
|
|
1283
|
-
var OrdersPage = React.lazy(() => import('./OrdersPage-
|
|
1560
|
+
var OrdersPage = React.lazy(() => import('./OrdersPage-CQ7O74ZW.js').then((m) => ({ default: m.OrdersPage })));
|
|
1284
1561
|
var DEFAULT_LABELS = {
|
|
1285
1562
|
pageTitle: "Orders",
|
|
1286
1563
|
kanban: "Orders",
|
|
@@ -1309,14 +1586,15 @@ function resolveConfig(options) {
|
|
|
1309
1586
|
function createOrdersPlugin(options) {
|
|
1310
1587
|
const config = resolveConfig(options);
|
|
1311
1588
|
const provider = options?.dataProvider ?? createMockOrdersProvider();
|
|
1312
|
-
const
|
|
1589
|
+
const store7 = createOrdersStore(provider);
|
|
1313
1590
|
const PageComponent = () => React.createElement(
|
|
1314
1591
|
React.Suspense,
|
|
1315
1592
|
{ fallback: null },
|
|
1316
|
-
React.createElement(OrdersPage, { config, provider, store:
|
|
1593
|
+
React.createElement(OrdersPage, { config, provider, store: store7, registries: ordersRegistries })
|
|
1317
1594
|
);
|
|
1318
1595
|
return {
|
|
1319
1596
|
id: "orders",
|
|
1597
|
+
defaultAgentRole: "operations",
|
|
1320
1598
|
name: config.labels.pageTitle,
|
|
1321
1599
|
icon: "ClipboardList",
|
|
1322
1600
|
version: "1.0.0",
|
|
@@ -1416,7 +1694,6 @@ function createOrdersPlugin(options) {
|
|
|
1416
1694
|
component: (() => {
|
|
1417
1695
|
const OrdersSettingsTab = () => React.createElement(PluginSettingsPanel, {
|
|
1418
1696
|
title: "Orders Settings",
|
|
1419
|
-
subtitle: "Order sources and preferences",
|
|
1420
1697
|
registries: ordersRegistries,
|
|
1421
1698
|
routeBase: "/settings/orders"
|
|
1422
1699
|
});
|
|
@@ -1430,10 +1707,17 @@ function createOrdersPlugin(options) {
|
|
|
1430
1707
|
locales: ordersLocales,
|
|
1431
1708
|
// Offered regardless of `modules.delivery` — a takeout-only house still takes
|
|
1432
1709
|
// iFood retirada orders. Control plane only: src/integrations/DELIVERY-MARKETPLACES.md.
|
|
1433
|
-
connectors: [
|
|
1710
|
+
connectors: [
|
|
1711
|
+
ifoodConnectorDef,
|
|
1712
|
+
nineNineFoodConnectorDef,
|
|
1713
|
+
keetaConnectorDef,
|
|
1714
|
+
uberEatsConnectorDef,
|
|
1715
|
+
rappiConnectorDef,
|
|
1716
|
+
aiqfomeConnectorDef
|
|
1717
|
+
]
|
|
1434
1718
|
};
|
|
1435
1719
|
}
|
|
1436
1720
|
|
|
1437
|
-
export { AUTO_ACCEPT_SETTING, IFOOD_CONNECTOR_ID, IFOOD_SETTINGS, KEETA_CONNECTOR_ID, KEETA_SETTINGS, NINETY_NINE_FOOD_CONNECTOR_ID, NINETY_NINE_FOOD_SETTINGS, PREP_TIME_SETTING, createFayzOrdersProvider, createOrdersPlugin, ifoodConnectorDef, keetaConnectorDef, marketplacePermissions, nineNineFoodConnectorDef };
|
|
1721
|
+
export { AIQFOME_CONNECTOR_ID, AIQFOME_SETTINGS, AUTO_ACCEPT_SETTING, IFOOD_CONNECTOR_ID, IFOOD_SETTINGS, KEETA_CONNECTOR_ID, KEETA_SETTINGS, NINETY_NINE_FOOD_CONNECTOR_ID, NINETY_NINE_FOOD_SETTINGS, PREP_TIME_SETTING, RAPPI_CONNECTOR_ID, RAPPI_SETTINGS, UBER_EATS_CONNECTOR_ID, UBER_EATS_SETTINGS, aiqfomeConnectorDef, createFayzOrdersProvider, createOrdersPlugin, ifoodConnectorDef, keetaConnectorDef, marketplacePermissions, nineNineFoodConnectorDef, rappiConnectorDef, uberEatsConnectorDef };
|
|
1438
1722
|
//# sourceMappingURL=index.js.map
|
|
1439
1723
|
//# sourceMappingURL=index.js.map
|