@12-apps/marketplace 1.8.0 → 1.9.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/README.md +102 -8
- package/dist/99food/index.d.ts +30 -54
- package/dist/99food/index.js +60 -418
- package/dist/99food/index.js.map +1 -1
- package/dist/chunk-PYHNM47K.js +478 -0
- package/dist/chunk-PYHNM47K.js.map +1 -0
- package/dist/client-B4EQCRD_.d.ts +20 -0
- package/dist/keeta/en-US.d.ts +19 -0
- package/dist/keeta/en-US.js +23 -0
- package/dist/keeta/en-US.js.map +1 -0
- package/dist/keeta/index.d.ts +253 -0
- package/dist/keeta/index.js +388 -0
- package/dist/keeta/index.js.map +1 -0
- package/dist/keeta/pt-BR.d.ts +23 -0
- package/dist/keeta/pt-BR.js +23 -0
- package/dist/keeta/pt-BR.js.map +1 -0
- package/package.json +14 -2
- package/src/99food/catalogue.ts +19 -89
- package/src/99food/copy.ts +4 -19
- package/src/99food/index.ts +28 -33
- package/src/99food/normalize.ts +11 -253
- package/src/99food/outbound.ts +29 -270
- package/src/99food/pause.ts +7 -22
- package/src/index.ts +2 -1
- package/src/keeta/authorization.ts +226 -0
- package/src/keeta/copy.ts +27 -0
- package/src/keeta/en-US.ts +19 -0
- package/src/keeta/index.ts +162 -0
- package/src/keeta/merchant.ts +70 -0
- package/src/keeta/normalize.ts +131 -0
- package/src/keeta/outbound.ts +55 -0
- package/src/keeta/pt-BR.ts +23 -0
- package/src/keeta/signature.ts +85 -0
- package/src/open-delivery/client.ts +185 -0
- package/src/open-delivery/merchant.ts +126 -0
- package/src/open-delivery/normalize.ts +269 -0
- package/src/open-delivery/orders.ts +241 -0
- package/src/open-delivery/reasons.ts +26 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPEN_DELIVERY_ITEM_UNAVAILABLE,
|
|
3
|
+
OPEN_DELIVERY_MERCHANT_REASON_CODES,
|
|
4
|
+
assertHttpsUrl,
|
|
5
|
+
isStop,
|
|
6
|
+
normalizeOpenDeliveryEventAs,
|
|
7
|
+
normalizeOpenDeliveryOrderAs,
|
|
8
|
+
openDeliveryCall,
|
|
9
|
+
openDeliveryConfirm,
|
|
10
|
+
openDeliveryFetchOrder,
|
|
11
|
+
openDeliveryMenuDocument,
|
|
12
|
+
openDeliveryMerchantUpdate,
|
|
13
|
+
openDeliveryRequestCancellation,
|
|
14
|
+
openDeliveryStatus,
|
|
15
|
+
openDeliverySwitchAvailability
|
|
16
|
+
} from "../chunk-PYHNM47K.js";
|
|
17
|
+
import "../chunk-M2V4RFMA.js";
|
|
18
|
+
import {
|
|
19
|
+
asString,
|
|
20
|
+
firstString,
|
|
21
|
+
pick
|
|
22
|
+
} from "../chunk-BD7DS3XM.js";
|
|
23
|
+
import {
|
|
24
|
+
outboundResultOf
|
|
25
|
+
} from "../chunk-HEXLCTOG.js";
|
|
26
|
+
import {
|
|
27
|
+
__name
|
|
28
|
+
} from "../chunk-7QVYU63E.js";
|
|
29
|
+
|
|
30
|
+
// src/keeta/authorization.ts
|
|
31
|
+
var KEETA_AUTHORIZATION_WEBHOOK_ANSWER = { code: 0, message: "success" };
|
|
32
|
+
function normalizeKeetaAuthorizationEvent(payload) {
|
|
33
|
+
const authId = firstString(payload, [["authId"]]);
|
|
34
|
+
const shopId = firstString(payload, [["shopId"]]);
|
|
35
|
+
const opType = pick(payload, "opType");
|
|
36
|
+
const change = opType === 1 ? "AUTHORIZED" : opType === 2 ? "REVOKED" : null;
|
|
37
|
+
if (!authId || !shopId || !change) return null;
|
|
38
|
+
const millis = pick(payload, "createTime");
|
|
39
|
+
return {
|
|
40
|
+
authId,
|
|
41
|
+
change,
|
|
42
|
+
shopId,
|
|
43
|
+
shopName: firstString(payload, [["shopName"]]),
|
|
44
|
+
clientId: firstString(payload, [["clientId"]]),
|
|
45
|
+
at: typeof millis === "number" && Number.isFinite(millis) ? new Date(millis) : null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
__name(normalizeKeetaAuthorizationEvent, "normalizeKeetaAuthorizationEvent");
|
|
49
|
+
var numberOr = /* @__PURE__ */ __name((value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback, "numberOr");
|
|
50
|
+
function shopOf(raw) {
|
|
51
|
+
const id = firstString(raw, [["id"]]);
|
|
52
|
+
if (!id) return null;
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
name: firstString(raw, [["name"]]),
|
|
56
|
+
address: firstString(raw, [["address"]]),
|
|
57
|
+
latitude: numberOr(pick(raw, "latitude"), null),
|
|
58
|
+
longitude: numberOr(pick(raw, "longitude"), null),
|
|
59
|
+
timeZone: firstString(raw, [["timeZone"]])
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
__name(shopOf, "shopOf");
|
|
63
|
+
function shopsOf(body) {
|
|
64
|
+
const raw = pick(body, "authorizedShops");
|
|
65
|
+
return {
|
|
66
|
+
brandId: asString(pick(body, "brandId")),
|
|
67
|
+
brandName: firstString(body, [["brandName"]]),
|
|
68
|
+
shops: (Array.isArray(raw) ? raw : []).map(shopOf).filter((shop) => shop !== null),
|
|
69
|
+
page: {
|
|
70
|
+
pageNum: numberOr(pick(body, "page", "pageNum"), 1) ?? 1,
|
|
71
|
+
totalPage: numberOr(pick(body, "page", "totalPage"), 1) ?? 1,
|
|
72
|
+
totalCount: numberOr(pick(body, "page", "totalCount"), 0) ?? 0
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
__name(shopsOf, "shopsOf");
|
|
77
|
+
async function readCall(ctx, dialect, call, read) {
|
|
78
|
+
try {
|
|
79
|
+
const response = await openDeliveryCall(ctx, dialect, call);
|
|
80
|
+
if (isStop(response)) return response;
|
|
81
|
+
const result = outboundResultOf(response);
|
|
82
|
+
if (result.kind !== "accepted") return result;
|
|
83
|
+
let body = null;
|
|
84
|
+
try {
|
|
85
|
+
body = response.body === "" ? null : JSON.parse(response.body);
|
|
86
|
+
} catch {
|
|
87
|
+
body = null;
|
|
88
|
+
}
|
|
89
|
+
const value = read(body);
|
|
90
|
+
return value === null ? { kind: "refused", status: response.status, message: "Keeta's answer is not the documented shape" } : { kind: "ok", value };
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
__name(readCall, "readCall");
|
|
96
|
+
function httpsUrl(body) {
|
|
97
|
+
const url = firstString(body, [["merchantAuthorizationUrl"]]);
|
|
98
|
+
if (!url) return null;
|
|
99
|
+
try {
|
|
100
|
+
return new URL(url).protocol === "https:" ? url : null;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
__name(httpsUrl, "httpsUrl");
|
|
106
|
+
function keetaAuthorization(dialect) {
|
|
107
|
+
return {
|
|
108
|
+
authorizationUrl: /* @__PURE__ */ __name((ctx, input) => readCall(
|
|
109
|
+
ctx,
|
|
110
|
+
dialect,
|
|
111
|
+
{
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: "/oauth/authorization/url",
|
|
114
|
+
query: { clientId: ctx.credentials.clientId, ...input.redirectUri ? { redirectUri: input.redirectUri } : {} },
|
|
115
|
+
authenticated: false
|
|
116
|
+
},
|
|
117
|
+
httpsUrl
|
|
118
|
+
), "authorizationUrl"),
|
|
119
|
+
authorizedShops: /* @__PURE__ */ __name((ctx, input) => readCall(
|
|
120
|
+
ctx,
|
|
121
|
+
dialect,
|
|
122
|
+
{
|
|
123
|
+
method: "GET",
|
|
124
|
+
path: `/oauth/authorized/${encodeURIComponent(input.authId)}/merchantInfo`,
|
|
125
|
+
query: { pageNum: String(input.pageNum ?? 1), pageSize: String(Math.min(input.pageSize ?? 100, 100)) }
|
|
126
|
+
},
|
|
127
|
+
(body) => body === null ? null : shopsOf(body)
|
|
128
|
+
), "authorizedShops"),
|
|
129
|
+
onboard: /* @__PURE__ */ __name((ctx, input) => readCall(
|
|
130
|
+
ctx,
|
|
131
|
+
dialect,
|
|
132
|
+
{
|
|
133
|
+
method: "PUT",
|
|
134
|
+
path: "/v1/merchantOnboarding",
|
|
135
|
+
query: { merchantId: input.merchantId },
|
|
136
|
+
body: {
|
|
137
|
+
keetaMerchantId: input.keetaMerchantId,
|
|
138
|
+
...input.merchantDocument ? {
|
|
139
|
+
getMerchantURL: {
|
|
140
|
+
baseURL: input.merchantDocument.url,
|
|
141
|
+
...input.merchantDocument.apiKey ? { apiKey: input.merchantDocument.apiKey } : {}
|
|
142
|
+
}
|
|
143
|
+
} : {},
|
|
144
|
+
...input.ordersWebhookUrl ? { ordersWebhookURL: input.ordersWebhookUrl } : {}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
() => true
|
|
148
|
+
), "onboard")
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
__name(keetaAuthorization, "keetaAuthorization");
|
|
152
|
+
|
|
153
|
+
// src/keeta/copy.ts
|
|
154
|
+
var KEETA_REASON_CODES = OPEN_DELIVERY_MERCHANT_REASON_CODES;
|
|
155
|
+
|
|
156
|
+
// src/keeta/merchant.ts
|
|
157
|
+
var merchantUpdatePath = /* @__PURE__ */ __name((merchantId) => `/v1/merchantUpdate/${encodeURIComponent(merchantId)}`, "merchantUpdatePath");
|
|
158
|
+
function keetaCatalogue(dialect) {
|
|
159
|
+
return {
|
|
160
|
+
mode: "pull",
|
|
161
|
+
menuDocument: openDeliveryMenuDocument,
|
|
162
|
+
notifyMenuChanged: /* @__PURE__ */ __name((ctx) => openDeliveryMerchantUpdate(ctx, dialect, { path: merchantUpdatePath(ctx.externalMerchantId) }), "notifyMenuChanged")
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
__name(keetaCatalogue, "keetaCatalogue");
|
|
166
|
+
function keetaSetMerchantStatus(ctx, dialect, merchantId, status) {
|
|
167
|
+
return openDeliveryMerchantUpdate(ctx, dialect, { path: merchantUpdatePath(merchantId), body: { merchantStatus: status } });
|
|
168
|
+
}
|
|
169
|
+
__name(keetaSetMerchantStatus, "keetaSetMerchantStatus");
|
|
170
|
+
function keetaAvailability(dialect) {
|
|
171
|
+
return openDeliverySwitchAvailability((ctx, merchantId, status) => keetaSetMerchantStatus(ctx, dialect, merchantId, status));
|
|
172
|
+
}
|
|
173
|
+
__name(keetaAvailability, "keetaAvailability");
|
|
174
|
+
|
|
175
|
+
// src/keeta/normalize.ts
|
|
176
|
+
var KEETA_PROVIDER = "KEETA";
|
|
177
|
+
var ENCRYPTED_PREFIX = "ENC_";
|
|
178
|
+
var DECRYPT_BATCH = 50;
|
|
179
|
+
function normalizeKeetaEvent(payload) {
|
|
180
|
+
return normalizeOpenDeliveryEventAs(KEETA_PROVIDER, payload);
|
|
181
|
+
}
|
|
182
|
+
__name(normalizeKeetaEvent, "normalizeKeetaEvent");
|
|
183
|
+
function normalizeKeetaOrder(order, options) {
|
|
184
|
+
return normalizeOpenDeliveryOrderAs(KEETA_PROVIDER, order, options);
|
|
185
|
+
}
|
|
186
|
+
__name(normalizeKeetaOrder, "normalizeKeetaOrder");
|
|
187
|
+
var isEncrypted = /* @__PURE__ */ __name((value) => typeof value === "string" && value.startsWith(ENCRYPTED_PREFIX), "isEncrypted");
|
|
188
|
+
function ciphersOf(value, found) {
|
|
189
|
+
if (isEncrypted(value)) found.add(value);
|
|
190
|
+
else if (Array.isArray(value)) for (const entry of value) ciphersOf(entry, found);
|
|
191
|
+
else if (typeof value === "object" && value !== null) for (const entry of Object.values(value)) ciphersOf(entry, found);
|
|
192
|
+
return found;
|
|
193
|
+
}
|
|
194
|
+
__name(ciphersOf, "ciphersOf");
|
|
195
|
+
function replaced(value, plain) {
|
|
196
|
+
if (Array.isArray(value)) return value.map((entry) => replaced(entry, plain));
|
|
197
|
+
if (typeof value === "object" && value !== null) {
|
|
198
|
+
const copy = {};
|
|
199
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
200
|
+
if (isEncrypted(entry) && !plain.has(entry)) continue;
|
|
201
|
+
copy[key] = isEncrypted(entry) ? plain.get(entry) : replaced(entry, plain);
|
|
202
|
+
}
|
|
203
|
+
return copy;
|
|
204
|
+
}
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
__name(replaced, "replaced");
|
|
208
|
+
function plainPairs(body) {
|
|
209
|
+
const infos = pick(JSON.parse(body), "plainInfos");
|
|
210
|
+
return (Array.isArray(infos) ? infos : []).flatMap((info) => {
|
|
211
|
+
const cipher = pick(info, "cipherText");
|
|
212
|
+
const text = pick(info, "plainText");
|
|
213
|
+
const code = pick(info, "errorCode");
|
|
214
|
+
return typeof cipher === "string" && typeof text === "string" && (code === void 0 || code === 0) ? [[cipher, text]] : [];
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
__name(plainPairs, "plainPairs");
|
|
218
|
+
async function decrypt(ctx, dialect, ciphers) {
|
|
219
|
+
try {
|
|
220
|
+
const response = await openDeliveryCall(ctx, dialect, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
path: "/v1/batchDecrypt",
|
|
223
|
+
body: { cipherInfos: ciphers.map((cipherText) => ({ cipherText })) }
|
|
224
|
+
});
|
|
225
|
+
if (isStop(response) || outboundResultOf(response).kind !== "accepted") return [];
|
|
226
|
+
return plainPairs(response.body);
|
|
227
|
+
} catch {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
__name(decrypt, "decrypt");
|
|
232
|
+
async function revealKeetaOrder(ctx, dialect, order) {
|
|
233
|
+
const ciphers = [...ciphersOf(order, /* @__PURE__ */ new Set())];
|
|
234
|
+
if (ciphers.length === 0) return order;
|
|
235
|
+
const plain = /* @__PURE__ */ new Map();
|
|
236
|
+
if (pick(order, "delivery", "deliveredBy") === "MERCHANT") {
|
|
237
|
+
const batches = [];
|
|
238
|
+
for (let start = 0; start < ciphers.length; start += DECRYPT_BATCH) batches.push(ciphers.slice(start, start + DECRYPT_BATCH));
|
|
239
|
+
const answers = await Promise.all(batches.map((batch) => decrypt(ctx, dialect, batch)));
|
|
240
|
+
for (const [cipher, text] of answers.flat()) plain.set(cipher, text);
|
|
241
|
+
}
|
|
242
|
+
return replaced(order, plain);
|
|
243
|
+
}
|
|
244
|
+
__name(revealKeetaOrder, "revealKeetaOrder");
|
|
245
|
+
|
|
246
|
+
// src/keeta/signature.ts
|
|
247
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
248
|
+
function canonicalJson(value) {
|
|
249
|
+
if (Array.isArray(value)) {
|
|
250
|
+
return `[${value.map((entry) => entry === void 0 ? "null" : canonicalJson(entry)).join(",")}]`;
|
|
251
|
+
}
|
|
252
|
+
if (typeof value === "object" && value !== null) {
|
|
253
|
+
const record = value;
|
|
254
|
+
const keys = Object.keys(record).filter((key) => record[key] !== void 0).sort();
|
|
255
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(",")}}`;
|
|
256
|
+
}
|
|
257
|
+
return JSON.stringify(value) ?? "null";
|
|
258
|
+
}
|
|
259
|
+
__name(canonicalJson, "canonicalJson");
|
|
260
|
+
function keetaSignatureString(url, body) {
|
|
261
|
+
const parsed = new URL(url);
|
|
262
|
+
const parts = [`${parsed.origin}${parsed.pathname}`];
|
|
263
|
+
const keys = [...new Set(parsed.searchParams.keys())].sort();
|
|
264
|
+
for (const key of keys) parts.push(`${key}=${parsed.searchParams.get(key) ?? ""}`);
|
|
265
|
+
const trimmed = body?.trim() ?? "";
|
|
266
|
+
if (trimmed !== "" && trimmed !== "{}") parts.push(body ?? "");
|
|
267
|
+
return parts.join("&");
|
|
268
|
+
}
|
|
269
|
+
__name(keetaSignatureString, "keetaSignatureString");
|
|
270
|
+
function keetaRequestSignature(url, body, clientSecret) {
|
|
271
|
+
return createHmac("sha256", clientSecret).update(keetaSignatureString(url, body), "utf8").digest("base64");
|
|
272
|
+
}
|
|
273
|
+
__name(keetaRequestSignature, "keetaRequestSignature");
|
|
274
|
+
function verifyKeetaSignature(rawBody, signature, webhookSecret) {
|
|
275
|
+
if (!webhookSecret || !signature) return false;
|
|
276
|
+
const expected = Buffer.from(createHmac("sha256", webhookSecret).update(rawBody, "utf8").digest("base64"), "utf8");
|
|
277
|
+
const given = Buffer.from(signature.trim(), "utf8");
|
|
278
|
+
return given.length === expected.length && timingSafeEqual(given, expected);
|
|
279
|
+
}
|
|
280
|
+
__name(verifyKeetaSignature, "verifyKeetaSignature");
|
|
281
|
+
|
|
282
|
+
// src/keeta/outbound.ts
|
|
283
|
+
var KEETA_API_BASE_URL = "https://open.mykeeta.com/api/open/opendelivery";
|
|
284
|
+
var KEETA_DEFAULT_API_BASE_URLS = {
|
|
285
|
+
SANDBOX: KEETA_API_BASE_URL,
|
|
286
|
+
PRODUCTION: KEETA_API_BASE_URL
|
|
287
|
+
};
|
|
288
|
+
function keetaDialect(bases) {
|
|
289
|
+
return {
|
|
290
|
+
provider: KEETA_PROVIDER,
|
|
291
|
+
name: "Keeta",
|
|
292
|
+
bases,
|
|
293
|
+
tokenGrant: /* @__PURE__ */ __name((ctx) => ({
|
|
294
|
+
contentType: "application/json",
|
|
295
|
+
body: canonicalJson({
|
|
296
|
+
client_id: ctx.credentials.clientId,
|
|
297
|
+
client_secret: ctx.credentials.clientSecret,
|
|
298
|
+
grant_type: "app_level_token"
|
|
299
|
+
})
|
|
300
|
+
}), "tokenGrant"),
|
|
301
|
+
serialize: canonicalJson,
|
|
302
|
+
sign: /* @__PURE__ */ __name((ctx, url, body) => ({ "X-App-Signature": keetaRequestSignature(url, body, ctx.credentials.clientSecret) }), "sign")
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
__name(keetaDialect, "keetaDialect");
|
|
306
|
+
|
|
307
|
+
// src/keeta/index.ts
|
|
308
|
+
var KEETA_CANCELLATION_ANSWER_WINDOW_MS = 5 * 6e4;
|
|
309
|
+
var KEETA_PORTAL_URL = "https://merchant.mykeeta.com/";
|
|
310
|
+
var STATUS = openDeliveryStatus({ takeoutPickedUp: false });
|
|
311
|
+
var assertHttps = /* @__PURE__ */ __name((name, url) => assertHttpsUrl("@12-apps/marketplace/keeta", name, url), "assertHttps");
|
|
312
|
+
function basesOf(config) {
|
|
313
|
+
const bases = { ...config.apiBaseUrl ?? KEETA_DEFAULT_API_BASE_URLS };
|
|
314
|
+
assertHttps("apiBaseUrl.SANDBOX", bases.SANDBOX);
|
|
315
|
+
assertHttps("apiBaseUrl.PRODUCTION", bases.PRODUCTION);
|
|
316
|
+
return bases;
|
|
317
|
+
}
|
|
318
|
+
__name(basesOf, "basesOf");
|
|
319
|
+
function createKeetaAdapter(config) {
|
|
320
|
+
const dialect = keetaDialect(basesOf(config));
|
|
321
|
+
const portalUrl = config.portalUrl ?? KEETA_PORTAL_URL;
|
|
322
|
+
assertHttps("portalUrl", portalUrl);
|
|
323
|
+
const reasons = KEETA_REASON_CODES.map((code) => ({
|
|
324
|
+
code,
|
|
325
|
+
label: config.copy.reasonLabels[code],
|
|
326
|
+
itemUnavailable: code === OPEN_DELIVERY_ITEM_UNAVAILABLE,
|
|
327
|
+
// `outOfStockItems` is optional: sent when the store named the SKUs, never required.
|
|
328
|
+
needsItems: false
|
|
329
|
+
}));
|
|
330
|
+
const normalizeOptions = { missingStreetNumber: config.copy.missingStreetNumber };
|
|
331
|
+
const fetchOptions = {
|
|
332
|
+
normalize: /* @__PURE__ */ __name((order) => normalizeKeetaOrder(order, normalizeOptions), "normalize"),
|
|
333
|
+
prepare: /* @__PURE__ */ __name((ctx, order) => revealKeetaOrder(ctx, dialect, order), "prepare")
|
|
334
|
+
};
|
|
335
|
+
const cancellation = { outOfStockAsSkus: true };
|
|
336
|
+
return {
|
|
337
|
+
provider: KEETA_PROVIDER,
|
|
338
|
+
capabilities: {
|
|
339
|
+
apiConfirm: true,
|
|
340
|
+
apiCancel: true,
|
|
341
|
+
// "The merchant may cancel up to 48 h after the conclusion"; the answer is Keeta's.
|
|
342
|
+
cancelAfterAccept: true,
|
|
343
|
+
// 202 ("received for analysis"), then CANCELLED, or nothing at all.
|
|
344
|
+
asyncCancellationOutcome: true,
|
|
345
|
+
perOrderAppLink: false,
|
|
346
|
+
// `OrderConfirmed.preparationTime`, in minutes.
|
|
347
|
+
confirmTakesPreparationTime: true,
|
|
348
|
+
cancellationAnswerWindowMs: KEETA_CANCELLATION_ANSWER_WINDOW_MS,
|
|
349
|
+
// readyForPickup, dispatch (merchant's bag) and delivered (merchant's bag).
|
|
350
|
+
statusSteps: ["READY", "DISPATCHED", "HANDED_OVER"]
|
|
351
|
+
},
|
|
352
|
+
normalize: normalizeKeetaEvent,
|
|
353
|
+
readSignature: /* @__PURE__ */ __name((header) => header("x-app-signature"), "readSignature"),
|
|
354
|
+
verifySignature: verifyKeetaSignature,
|
|
355
|
+
cancellationReasons: /* @__PURE__ */ __name(() => reasons, "cancellationReasons"),
|
|
356
|
+
// PULL: Keeta reads the menu the host serves (`GET /v1/merchant`) and is told when it changed.
|
|
357
|
+
catalogue: keetaCatalogue(dialect),
|
|
358
|
+
fetchOrder: /* @__PURE__ */ __name((ctx, order) => openDeliveryFetchOrder(ctx, dialect, order, fetchOptions), "fetchOrder"),
|
|
359
|
+
confirm: /* @__PURE__ */ __name((ctx, order, input) => openDeliveryConfirm(ctx, dialect, order, input), "confirm"),
|
|
360
|
+
requestCancellation: /* @__PURE__ */ __name((ctx, order, input) => openDeliveryRequestCancellation(ctx, dialect, order, input, cancellation), "requestCancellation"),
|
|
361
|
+
statusSupported: STATUS.supported,
|
|
362
|
+
informStatus: /* @__PURE__ */ __name((ctx, order, facts) => STATUS.inform(ctx, dialect, order, facts), "informStatus"),
|
|
363
|
+
appLink: /* @__PURE__ */ __name(() => portalUrl, "appLink"),
|
|
364
|
+
...config.pauseByStoreSwitch ? { availability: keetaAvailability(dialect) } : {}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
__name(createKeetaAdapter, "createKeetaAdapter");
|
|
368
|
+
function createKeetaAuthorization(config = {}) {
|
|
369
|
+
return keetaAuthorization(keetaDialect(basesOf(config)));
|
|
370
|
+
}
|
|
371
|
+
__name(createKeetaAuthorization, "createKeetaAuthorization");
|
|
372
|
+
export {
|
|
373
|
+
KEETA_API_BASE_URL,
|
|
374
|
+
KEETA_AUTHORIZATION_WEBHOOK_ANSWER,
|
|
375
|
+
KEETA_CANCELLATION_ANSWER_WINDOW_MS,
|
|
376
|
+
KEETA_PORTAL_URL,
|
|
377
|
+
KEETA_PROVIDER,
|
|
378
|
+
KEETA_REASON_CODES,
|
|
379
|
+
canonicalJson,
|
|
380
|
+
createKeetaAdapter,
|
|
381
|
+
createKeetaAuthorization,
|
|
382
|
+
keetaRequestSignature,
|
|
383
|
+
normalizeKeetaAuthorizationEvent,
|
|
384
|
+
normalizeKeetaEvent,
|
|
385
|
+
normalizeKeetaOrder,
|
|
386
|
+
verifyKeetaSignature
|
|
387
|
+
};
|
|
388
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/keeta/authorization.ts","../../src/keeta/copy.ts","../../src/keeta/merchant.ts","../../src/keeta/normalize.ts","../../src/keeta/signature.ts","../../src/keeta/outbound.ts","../../src/keeta/index.ts"],"sourcesContent":["import { outboundResultOf, type AdapterCallContext } from \"../core/adapter\";\nimport { asString, firstString, pick } from \"../core/payload-read\";\nimport { isStop, openDeliveryCall, type OpenDeliveryDialect, type OpenDeliveryStop } from \"../open-delivery/client\";\n\n/**\n * Keeta's MERCHANT AUTHORIZATION, automated from the software (Keeta's\n * \"Autorização Self-serve do Merchant\", read 2026-11-26 at\n * https://api-docs.mykeeta.com/apis/opendelivery/merchant-self-serve-authorization).\n * Not on the adapter port: connecting a store is the host's flow, and these\n * are the calls it is built from.\n *\n * 1. {@link KeetaAuthorization.authorizationUrl}: `GET\n * /oauth/authorization/url?clientId=&redirectUri=` (no token: a token\n * needs at least one authorized store), the link the merchant opens.\n * 2. The merchant authorizes; Keeta redirects to `redirectUri` with `authId`\n * (and `state`, `appId`, `timestamp`), and POSTs the authorization webhook\n * ({@link normalizeKeetaAuthorizationEvent}: `opType` 1 added, 2 revoked).\n * 3. {@link KeetaAuthorization.authorizedShops}: `GET\n * /oauth/authorized/{authId}/merchantInfo?pageNum=&pageSize=` lists the\n * stores of that authorization (Keeta's ids, names, addresses, time zones).\n * 4. The host maps a Keeta store to its own, then\n * {@link KeetaAuthorization.onboard}: `PUT /v1/merchantOnboarding?merchantId=`\n * binds the SOFTWARE's merchant id (the connection's `externalMerchantId`)\n * to `keetaMerchantId` and registers the `GET /v1/merchant` URL and the\n * orders webhook. \"Without onboarding there are no order events\"; sending\n * it again for the same id REPLACES the mapping. Answer 201.\n *\n * ESTIMATED: the JSON answer the authorization webhook wants (\"200 within\n * ~5 s, with JSON containing `code` and `message`\": the values are not\n * given, {@link KEETA_AUTHORIZATION_WEBHOOK_ANSWER} sends 0 and \"success\").\n */\n\n/** What the authorization webhook is answered with, 200, within ~5 s. ESTIMATED values. */\nexport const KEETA_AUTHORIZATION_WEBHOOK_ANSWER = { code: 0, message: \"success\" } as const;\n\n/** One authorization change Keeta reported (event 1301 added, 1302 revoked). */\nexport interface KeetaAuthorizationEvent {\n authId: string;\n change: \"AUTHORIZED\" | \"REVOKED\";\n /** Keeta's store id (an integer on the wire, text here). */\n shopId: string;\n shopName: string | null;\n /** The application's id. */\n clientId: string | null;\n at: Date | null;\n}\n\n/** Read the authorization webhook's body (`WebhookNotification`). Null when it names no authorization or store. */\nexport function normalizeKeetaAuthorizationEvent(payload: unknown): KeetaAuthorizationEvent | null {\n const authId = firstString(payload, [[\"authId\"]]);\n const shopId = firstString(payload, [[\"shopId\"]]);\n const opType = pick(payload, \"opType\");\n const change = opType === 1 ? \"AUTHORIZED\" : opType === 2 ? \"REVOKED\" : null;\n if (!authId || !shopId || !change) return null;\n const millis = pick(payload, \"createTime\");\n return {\n authId,\n change,\n shopId,\n shopName: firstString(payload, [[\"shopName\"]]),\n clientId: firstString(payload, [[\"clientId\"]]),\n at: typeof millis === \"number\" && Number.isFinite(millis) ? new Date(millis) : null,\n };\n}\n\n/** One store of an authorization, as `merchantInfo` lists it. */\nexport interface KeetaAuthorizedShop {\n /** Keeta's store id: the `keetaMerchantId` the onboarding takes. */\n id: string;\n name: string | null;\n address: string | null;\n latitude: number | null;\n longitude: number | null;\n timeZone: string | null;\n}\n\n/** One page of an authorization's stores. */\nexport interface KeetaAuthorizedShops {\n brandId: string | null;\n brandName: string | null;\n shops: KeetaAuthorizedShop[];\n page: { pageNum: number; totalPage: number; totalCount: number };\n}\n\n/** What the host registers for one store at onboarding. */\nexport interface KeetaOnboarding {\n /** The SOFTWARE's merchant id: the connection's `externalMerchantId`, the `Merchant.id` the host serves. */\n merchantId: string;\n /** Keeta's store id, from `authorizedShops` or Keeta's portal. */\n keetaMerchantId: number;\n /** Where Keeta reads this store's `GET /v1/merchant` (one URL per store), and its key if it wants one. */\n merchantDocument?: { url: string; apiKey?: string };\n /** The engine's webhook for this store: `…/webhooks/marketplace/:tenantSlug/KEETA`. */\n ordersWebhookUrl?: string;\n}\n\nexport type KeetaAuthorizationResult<T> = { kind: \"ok\"; value: T } | OpenDeliveryStop;\n\nconst numberOr = (value: unknown, fallback: number | null): number | null =>\n typeof value === \"number\" && Number.isFinite(value) ? value : fallback;\n\nfunction shopOf(raw: unknown): KeetaAuthorizedShop | null {\n const id = firstString(raw, [[\"id\"]]);\n if (!id) return null;\n return {\n id,\n name: firstString(raw, [[\"name\"]]),\n address: firstString(raw, [[\"address\"]]),\n latitude: numberOr(pick(raw, \"latitude\"), null),\n longitude: numberOr(pick(raw, \"longitude\"), null),\n timeZone: firstString(raw, [[\"timeZone\"]]),\n };\n}\n\nfunction shopsOf(body: unknown): KeetaAuthorizedShops {\n const raw = pick(body, \"authorizedShops\");\n return {\n brandId: asString(pick(body, \"brandId\")),\n brandName: firstString(body, [[\"brandName\"]]),\n shops: (Array.isArray(raw) ? raw : []).map(shopOf).filter((shop): shop is KeetaAuthorizedShop => shop !== null),\n page: {\n pageNum: numberOr(pick(body, \"page\", \"pageNum\"), 1) ?? 1,\n totalPage: numberOr(pick(body, \"page\", \"totalPage\"), 1) ?? 1,\n totalCount: numberOr(pick(body, \"page\", \"totalCount\"), 0) ?? 0,\n },\n };\n}\n\n/** One call whose 2xx answer is read by `read`: the value, or the result that ends it. */\nasync function readCall<T>(\n ctx: AdapterCallContext,\n dialect: OpenDeliveryDialect,\n call: Parameters<typeof openDeliveryCall>[2],\n read: (body: unknown) => T | null,\n): Promise<KeetaAuthorizationResult<T>> {\n try {\n const response = await openDeliveryCall(ctx, dialect, call);\n if (isStop(response)) return response;\n const result = outboundResultOf(response);\n if (result.kind !== \"accepted\") return result;\n let body: unknown = null;\n try {\n body = response.body === \"\" ? null : JSON.parse(response.body);\n } catch {\n body = null;\n }\n const value = read(body);\n return value === null\n ? { kind: \"refused\", status: response.status, message: \"Keeta's answer is not the documented shape\" }\n : { kind: \"ok\", value };\n } catch (error) {\n return { kind: \"retry\", reason: error instanceof Error ? error.message : String(error) };\n }\n}\n\n/** The self-serve authorization calls, bound to Keeta's dialect. */\nexport interface KeetaAuthorization {\n authorizationUrl(ctx: AdapterCallContext, input: { redirectUri?: string }): Promise<KeetaAuthorizationResult<string>>;\n authorizedShops(\n ctx: AdapterCallContext,\n input: { authId: string; pageNum?: number; pageSize?: number },\n ): Promise<KeetaAuthorizationResult<KeetaAuthorizedShops>>;\n onboard(ctx: AdapterCallContext, input: KeetaOnboarding): Promise<KeetaAuthorizationResult<true>>;\n}\n\n/** An https URL Keeta answered, or null. */\nfunction httpsUrl(body: unknown): string | null {\n const url = firstString(body, [[\"merchantAuthorizationUrl\"]]);\n if (!url) return null;\n try {\n return new URL(url).protocol === \"https:\" ? url : null;\n } catch {\n return null;\n }\n}\n\nexport function keetaAuthorization(dialect: OpenDeliveryDialect): KeetaAuthorization {\n return {\n authorizationUrl: (ctx, input) =>\n readCall(\n ctx,\n dialect,\n {\n method: \"GET\",\n path: \"/oauth/authorization/url\",\n query: { clientId: ctx.credentials.clientId, ...(input.redirectUri ? { redirectUri: input.redirectUri } : {}) },\n authenticated: false,\n },\n httpsUrl,\n ),\n authorizedShops: (ctx, input) =>\n readCall(\n ctx,\n dialect,\n {\n method: \"GET\",\n path: `/oauth/authorized/${encodeURIComponent(input.authId)}/merchantInfo`,\n query: { pageNum: String(input.pageNum ?? 1), pageSize: String(Math.min(input.pageSize ?? 100, 100)) },\n },\n (body) => (body === null ? null : shopsOf(body)),\n ),\n onboard: (ctx, input) =>\n readCall(\n ctx,\n dialect,\n {\n method: \"PUT\",\n path: \"/v1/merchantOnboarding\",\n query: { merchantId: input.merchantId },\n body: {\n keetaMerchantId: input.keetaMerchantId,\n ...(input.merchantDocument\n ? {\n getMerchantURL: {\n baseURL: input.merchantDocument.url,\n ...(input.merchantDocument.apiKey ? { apiKey: input.merchantDocument.apiKey } : {}),\n },\n }\n : {}),\n ...(input.ordersWebhookUrl ? { ordersWebhookURL: input.ordersWebhookUrl } : {}),\n },\n },\n () => true as const,\n ),\n };\n}\n","import { OPEN_DELIVERY_MERCHANT_REASON_CODES } from \"../open-delivery/reasons\";\n\n/**\n * The words the Keeta adapter needs from its host, and nothing else.\n *\n * Required and defaultless, like every copy port in this repo: the adapter\n * ships no language of its own. Two packs sit beside it (`./pt-BR`,\n * `./en-US`); a host passes one by hand, or its own.\n */\n\n/**\n * The cancellation codes a merchant may send: Keeta's \"códigos de\n * cancelamento (v1.0.7+)\", the same eleven as Open Delivery's\n * (`../open-delivery/reasons.ts`). Keeta still accepts its legacy codes\n * (`INSUFFICIENT_DISHES`, `SUSPENSION_OF_BUSINESS`, `INSUFFICIENT_MANPOWER`,\n * `OTHERS`) and recommends the new ones, so only the new ones are offered.\n */\nexport const KEETA_REASON_CODES = OPEN_DELIVERY_MERCHANT_REASON_CODES;\n\nexport type KeetaReasonCode = (typeof KEETA_REASON_CODES)[number];\n\nexport interface KeetaAdapterCopy {\n /** One label per reason code. Sent as the request's `reason` text when the store wrote none. */\n reasonLabels: Readonly<Record<KeetaReasonCode, string>>;\n /** What an address with no street number (or an encrypted one Keeta would not reveal) says instead. */\n missingStreetNumber: string;\n}\n","import type { AdapterCallContext, OutboundResult } from \"../core/adapter\";\nimport type { PullCatalogue } from \"../core/catalogue-port\";\nimport type { MarketplaceAvailability } from \"../core/pause-port\";\nimport type { OpenDeliveryDialect } from \"../open-delivery/client\";\nimport {\n openDeliveryMenuDocument,\n openDeliveryMerchantUpdate,\n openDeliverySwitchAvailability,\n} from \"../open-delivery/merchant\";\n\n/**\n * Keeta's MERCHANT half: the menu (FUT-4768) and the store pause (FUT-4851),\n * both on `POST /v1/merchantUpdate/{merchantId}` (Keeta's path names the\n * merchant, by the SOFTWARE's id; the standard's names none). Read\n * 2026-11-26 at https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/merchantupdate.\n *\n * MENU. Keeta's menu API takes the store's menu three ways: an empty body\n * (\"Keeta calls your `GET /v1/merchant` and reloads everything\"),\n * `merchantStatus` alone, or `entityType` + `updatedObjects`. Of the last,\n * only `ITEM_OFFER` and `OPTION` are applied as sent, and only their\n * `status`; `MENU`, `CATEGORY`, `ITEM`… still make Keeta pull the whole menu\n * (\"only full-menu update\"). So a product cannot be PUSHED to Keeta: its\n * name, photo and price reach Keeta only through the `Merchant` document the\n * host serves. The adapter is therefore PULL: `menuDocument` builds the menu\n * part of that document (shared with 99Food: every item `UN` with a status,\n * every offer with `originalValue`, which Keeta requires), and\n * `notifyMenuChanged` sends the empty-body update that makes Keeta pull it.\n *\n * What Keeta reads of the rest of the `Merchant`, the host's to serve (Keeta's\n * `getMerchant` page): `id`, `status`, `basicInfo.contactEmails` (up to 3) and\n * `basicInfo.contactPhones.commercialNumber` (required), `services[]` with\n * `serviceType: DELIVERY` (the only one Keeta uses), `menuId` and\n * `serviceHours` in UTC; `lastUpdate`, `TTL` and the offers' `currency` are\n * ignored. The document's URL is registered per merchant at onboarding\n * (`./authorization.ts`).\n *\n * PAUSE. `{ merchantStatus: \"UNAVAILABLE\" | \"AVAILABLE\" }` closes or opens the\n * store, with no end and no id: a switch, offered only when the host opts in.\n * Answer 204; 400, 401, 503.\n *\n * ESTIMATED: that an update sent with no body (no `Content-Type` either) is\n * read as the documented \"empty body\"; that the menu is PUBLISHED once Keeta\n * took the notification, not once it read the menu (as for 99Food).\n */\n\nconst merchantUpdatePath = (merchantId: string): string => `/v1/merchantUpdate/${encodeURIComponent(merchantId)}`;\n\n/** Keeta's catalogue capability. */\nexport function keetaCatalogue(dialect: OpenDeliveryDialect): PullCatalogue {\n return {\n mode: \"pull\",\n menuDocument: openDeliveryMenuDocument,\n notifyMenuChanged: (ctx) => openDeliveryMerchantUpdate(ctx, dialect, { path: merchantUpdatePath(ctx.externalMerchantId) }),\n };\n}\n\n/** Open or close the store on Keeta. */\nfunction keetaSetMerchantStatus(\n ctx: AdapterCallContext,\n dialect: OpenDeliveryDialect,\n merchantId: string,\n status: \"AVAILABLE\" | \"UNAVAILABLE\",\n): Promise<OutboundResult> {\n return openDeliveryMerchantUpdate(ctx, dialect, { path: merchantUpdatePath(merchantId), body: { merchantStatus: status } });\n}\n\n/** Keeta's availability capability: `merchantStatus`, a switch. */\nexport function keetaAvailability(dialect: OpenDeliveryDialect): MarketplaceAvailability {\n return openDeliverySwitchAvailability((ctx, merchantId, status) => keetaSetMerchantStatus(ctx, dialect, merchantId, status));\n}\n","import { outboundResultOf, type AdapterCallContext } from \"../core/adapter\";\nimport { pick } from \"../core/payload-read\";\nimport type { NormalizedEvent, NormalizedMarketplaceOrder } from \"../core/types\";\nimport { isStop, openDeliveryCall, type OpenDeliveryDialect } from \"../open-delivery/client\";\nimport { normalizeOpenDeliveryEventAs, normalizeOpenDeliveryOrderAs } from \"../open-delivery/normalize\";\n\n/**\n * The Keeta adapter's INBOUND half: Open Delivery's readers\n * (`../open-delivery/normalize.ts`) stamped with Keeta's provider id, plus\n * the one thing Keeta's `Order` does that the standard's does not: personal\n * data arrives ENCRYPTED.\n *\n * Events (Keeta's order guide, read 2026-11-26): `CREATED` → fetch;\n * `CANCELLED` (with a JSON-string `metadata` carrying `reason` and `code`) →\n * cancelled; `DISPATCHED`, `CONCLUDED` → lifecycle. Keeta has NO\n * `CANCELLATION_REQUEST_DENIED`: a store's request that Keeta does not grant\n * produces no event, so it ends TIMEOUT at the adapter's answer window. The\n * rest (`CONFIRMED`, `READY_FOR_PICKUP`, `PICKUP_ONGOING`,\n * `RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED`, `DELIVERED`,\n * `CANCELLATION_REQUESTED`, `USER_REFUND_REQUEST`, `REFUNDED`,\n * `REFUND_FAILED`, `RECOMMENDED_PREPARATION_START`) are recorded and IGNORED.\n */\n\n/** The provider id Keeta is registered under. Uppercase: the column's CHECK holds that shape. */\nexport const KEETA_PROVIDER = \"KEETA\";\n\n/** Keeta's prefix on an encrypted value (`ENC_#MQesaE=#1#`). */\nconst ENCRYPTED_PREFIX = \"ENC_\";\n/** `POST /v1/batchDecrypt` takes at most 50 values a call. */\nconst DECRYPT_BATCH = 50;\n\n/** Normalize one webhook `Event`. Null only when it names no order. */\nexport function normalizeKeetaEvent(payload: unknown): NormalizedEvent | null {\n return normalizeOpenDeliveryEventAs(KEETA_PROVIDER, payload);\n}\n\n/** Normalize one `Order`, after {@link revealKeetaOrder}. Null when it carries no id or no line. */\nexport function normalizeKeetaOrder(\n order: unknown,\n options: { missingStreetNumber: string },\n): NormalizedMarketplaceOrder | null {\n return normalizeOpenDeliveryOrderAs(KEETA_PROVIDER, order, options);\n}\n\nconst isEncrypted = (value: unknown): value is string =>\n typeof value === \"string\" && value.startsWith(ENCRYPTED_PREFIX);\n\n/** Every encrypted value anywhere in the order, once each. */\nfunction ciphersOf(value: unknown, found: Set<string>): Set<string> {\n if (isEncrypted(value)) found.add(value);\n else if (Array.isArray(value)) for (const entry of value) ciphersOf(entry, found);\n else if (typeof value === \"object\" && value !== null) for (const entry of Object.values(value)) ciphersOf(entry, found);\n return found;\n}\n\n/** A copy of the order with each encrypted value replaced by its plain text, or removed when there is none. */\nfunction replaced(value: unknown, plain: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) return value.map((entry) => replaced(entry, plain));\n if (typeof value === \"object\" && value !== null) {\n const copy: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n if (isEncrypted(entry) && !plain.has(entry)) continue;\n copy[key] = isEncrypted(entry) ? plain.get(entry) : replaced(entry, plain);\n }\n return copy;\n }\n return value;\n}\n\n/** The `{ cipherText, plainText }` pairs a `batchDecrypt` answer carries with `errorCode` 0. */\nfunction plainPairs(body: string): [string, string][] {\n const infos = pick(JSON.parse(body), \"plainInfos\");\n return (Array.isArray(infos) ? infos : []).flatMap((info): [string, string][] => {\n const cipher = pick(info, \"cipherText\");\n const text = pick(info, \"plainText\");\n const code = pick(info, \"errorCode\");\n return typeof cipher === \"string\" && typeof text === \"string\" && (code === undefined || code === 0)\n ? [[cipher, text]]\n : [];\n });\n}\n\n/** One `POST /v1/batchDecrypt` call: the plain texts it gave, none on any failure. */\nasync function decrypt(\n ctx: AdapterCallContext,\n dialect: OpenDeliveryDialect,\n ciphers: readonly string[],\n): Promise<[string, string][]> {\n try {\n const response = await openDeliveryCall(ctx, dialect, {\n method: \"POST\",\n path: \"/v1/batchDecrypt\",\n body: { cipherInfos: ciphers.map((cipherText) => ({ cipherText })) },\n });\n if (isStop(response) || outboundResultOf(response).kind !== \"accepted\") return [];\n return plainPairs(response.body);\n } catch {\n return [];\n }\n}\n\n/**\n * Keeta encrypts `customer.phone.number` and the address's `district`,\n * `number`, `complement` and `formattedAddress` (`ENC_…`). Only an order the\n * MERCHANT delivers (its own courier or its 3PL) may be decrypted, through\n * `POST /v1/batchDecrypt` (at most 50 values a call); on Keeta's own fleet\n * the data stays masked. So: a merchant bag is decrypted, and every value\n * still encrypted after that (Keeta's fleet, a value Keeta would not decrypt,\n * a failed call) is REMOVED, never shown — the address then reads the copy's\n * missing-number text, and the phone is null.\n *\n * Never fails the fetch (choice): Keeta cancels an order not accepted within\n * 5 minutes and may close the store for it, so a decrypt that failed must not\n * keep the order out of the queue; the store reads the address on Keeta.\n */\nexport async function revealKeetaOrder(\n ctx: AdapterCallContext,\n dialect: OpenDeliveryDialect,\n order: unknown,\n): Promise<unknown> {\n const ciphers = [...ciphersOf(order, new Set())];\n if (ciphers.length === 0) return order;\n const plain = new Map<string, string>();\n if (pick(order, \"delivery\", \"deliveredBy\") === \"MERCHANT\") {\n const batches: string[][] = [];\n for (let start = 0; start < ciphers.length; start += DECRYPT_BATCH) batches.push(ciphers.slice(start, start + DECRYPT_BATCH));\n const answers = await Promise.all(batches.map((batch) => decrypt(ctx, dialect, batch)));\n for (const [cipher, text] of answers.flat()) plain.set(cipher, text);\n }\n return replaced(order, plain);\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\n\n/**\n * Keeta's `X-App-Signature`, both directions (read 2026-11-26 at\n * https://api-docs.mykeeta.com/apis/opendelivery/signature-calculation and its\n * three sub-pages, and the `newEvent` and webhook guide pages).\n *\n * OUTBOUND — every request the software sends Keeta, the token grant\n * included, carries it (Keeta's change to Open Delivery: a token alone is not\n * enough, so an intercepted token cannot be replayed):\n *\n * - the string is the URL without its query, then `&key=value` for each\n * query parameter sorted by key (a null value is `key=`), then `&` and the\n * body when there is one: an empty body, a blank one or `{}` is left out,\n * and so is its `&`;\n * - the body is compact JSON canonicalized by RFC 8785 (JCS), and the SAME\n * string is sent;\n * - HMAC-SHA256 of the string (UTF-8), keyed by the application's\n * `client_secret`, encoded Base64.\n *\n * INBOUND — a webhook Keeta sends (`POST /v1/newEvent`, and the\n * authorization webhook) is signed \"HMAC-SHA256 of the body, with the\n * client_secret as key, in Base64\".\n *\n * ESTIMATED:\n * - query values are signed DECODED (the reference implementations take them\n * from a map, before any URL encoding); only the self-serve authorization\n * calls send a query, and only `redirectUri` can hold a character encoding\n * changes;\n * - the inbound signature covers the raw body bytes as received, with no URL\n * prefix (the pages say \"the body\");\n * - the authorization webhook's header uses the same Base64 HMAC (its schema\n * says only \"SHA256 hash of the request body, using the client secret as the\n * key\").\n */\n\n/**\n * RFC 8785 (JCS) for the JSON this adapter sends: object keys sorted by\n * UTF-16 code units, no whitespace, strings and numbers as ECMAScript's\n * `JSON.stringify` writes them (which is what JCS specifies). `undefined`\n * members are dropped, as `JSON.stringify` drops them.\n */\nexport function canonicalJson(value: unknown): string {\n if (Array.isArray(value)) {\n return `[${value.map((entry) => (entry === undefined ? \"null\" : canonicalJson(entry))).join(\",\")}]`;\n }\n if (typeof value === \"object\" && value !== null) {\n const record = value as Record<string, unknown>;\n const keys = Object.keys(record)\n .filter((key) => record[key] !== undefined)\n .sort();\n return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(\",\")}}`;\n }\n return JSON.stringify(value) ?? \"null\";\n}\n\n/** The string Keeta signs for one request. */\nexport function keetaSignatureString(url: string, body: string | undefined): string {\n const parsed = new URL(url);\n const parts = [`${parsed.origin}${parsed.pathname}`];\n const keys = [...new Set(parsed.searchParams.keys())].sort();\n for (const key of keys) parts.push(`${key}=${parsed.searchParams.get(key) ?? \"\"}`);\n const trimmed = body?.trim() ?? \"\";\n if (trimmed !== \"\" && trimmed !== \"{}\") parts.push(body ?? \"\");\n return parts.join(\"&\");\n}\n\n/** The `X-App-Signature` of one outbound request. */\nexport function keetaRequestSignature(url: string, body: string | undefined, clientSecret: string): string {\n return createHmac(\"sha256\", clientSecret).update(keetaSignatureString(url, body), \"utf8\").digest(\"base64\");\n}\n\n/**\n * Verify a webhook Keeta sent: Base64 HMAC-SHA256 of the raw body, keyed by\n * the application's client secret, which a connection stores as its webhook\n * secret. The key exists from the moment the store connects, so an unset\n * secret REFUSES: an unsigned CANCELLED for a known order id would otherwise\n * cancel it. Compared in constant time.\n */\nexport function verifyKeetaSignature(rawBody: string, signature: string | null, webhookSecret: string | null): boolean {\n if (!webhookSecret || !signature) return false;\n const expected = Buffer.from(createHmac(\"sha256\", webhookSecret).update(rawBody, \"utf8\").digest(\"base64\"), \"utf8\");\n const given = Buffer.from(signature.trim(), \"utf8\");\n return given.length === expected.length && timingSafeEqual(given, expected);\n}\n","import type { OpenDeliveryApiBaseUrls, OpenDeliveryDialect } from \"../open-delivery/client\";\nimport { KEETA_PROVIDER } from \"./normalize\";\nimport { canonicalJson, keetaRequestSignature } from \"./signature\";\n\n/**\n * Keeta's Open Delivery DIALECT. Keeta follows Open Delivery v1.5.0 with\n * changes of its own, and \"the definitions of this document prevail\"\n * (https://api-docs.mykeeta.com/apis/opendelivery/general-info, read\n * 2026-11-26). The calls are `../open-delivery/`'s; this file says how Keeta\n * takes them:\n *\n * - Token: `POST /oauth/token` with a JSON body `{ client_id, client_secret,\n * grant_type: \"app_level_token\" }` (v1.0.9's name for the standard's\n * `client_credentials`, which stays accepted for integrations already\n * certified). The token is the APPLICATION's: one for every store that\n * authorized it, so the cache key (provider, environment, client id) is\n * right as it is. Answer `{ access_token, token_type, expires_in }`; no\n * refresh token in this mode.\n * - Every request, the grant included, carries `X-App-Signature`\n * (`./signature.ts`), and every JSON body is RFC 8785 canonical.\n */\n\n/** Where Keeta serves Open Delivery, per environment. */\nexport type KeetaApiBaseUrls = OpenDeliveryApiBaseUrls;\n\n/**\n * The documented server (`servers[0]` of Keeta's `openapi.json`). ESTIMATED\n * for SANDBOX: Keeta documents one host, and a test application (its own\n * client id and secret, its test stores) is what makes a session a test one.\n */\nexport const KEETA_API_BASE_URL = \"https://open.mykeeta.com/api/open/opendelivery\";\n\nexport const KEETA_DEFAULT_API_BASE_URLS: KeetaApiBaseUrls = {\n SANDBOX: KEETA_API_BASE_URL,\n PRODUCTION: KEETA_API_BASE_URL,\n};\n\n/** Keeta's dialect, for the base URLs it was given. */\nexport function keetaDialect(bases: KeetaApiBaseUrls): OpenDeliveryDialect {\n return {\n provider: KEETA_PROVIDER,\n name: \"Keeta\",\n bases,\n tokenGrant: (ctx) => ({\n contentType: \"application/json\",\n body: canonicalJson({\n client_id: ctx.credentials.clientId,\n client_secret: ctx.credentials.clientSecret,\n grant_type: \"app_level_token\",\n }),\n }),\n serialize: canonicalJson,\n sign: (ctx, url, body) => ({ \"X-App-Signature\": keetaRequestSignature(url, body, ctx.credentials.clientSecret) }),\n };\n}\n","import type { AdapterCallContext, CancellationReason, MarketplaceAdapter } from \"../core/adapter\";\nimport { assertHttpsUrl } from \"../open-delivery/client\";\nimport {\n openDeliveryConfirm,\n openDeliveryFetchOrder,\n openDeliveryRequestCancellation,\n openDeliveryStatus,\n} from \"../open-delivery/orders\";\nimport { OPEN_DELIVERY_ITEM_UNAVAILABLE } from \"../open-delivery/reasons\";\nimport { keetaAuthorization, type KeetaAuthorization } from \"./authorization\";\nimport { KEETA_REASON_CODES, type KeetaAdapterCopy } from \"./copy\";\nimport { keetaAvailability, keetaCatalogue } from \"./merchant\";\nimport { KEETA_PROVIDER, normalizeKeetaEvent, normalizeKeetaOrder, revealKeetaOrder } from \"./normalize\";\nimport { KEETA_DEFAULT_API_BASE_URLS, keetaDialect, type KeetaApiBaseUrls } from \"./outbound\";\nimport { verifyKeetaSignature } from \"./signature\";\n\n/**\n * `@12-apps/marketplace/keeta` — Keeta, as one adapter on the engine.\n *\n * Keeta's API is Open Delivery v1.5.0 with Keeta's own changes\n * (https://api-docs.mykeeta.com/apis/opendelivery, `openapi.json` \"v.1.0.7\"\n * with the changelog to 1.0.9, read 2026-11-26), so the adapter is built on\n * the same Open Delivery module as 99Food's (`../open-delivery/`), which\n * speaks v1.7.1. What Keeta does differently, and where it is handled:\n *\n * | Keeta | 99Food (v1.7.1) | handled in |\n * |---|---|---|\n * | `X-App-Signature` on EVERY request: Base64 HMAC-SHA256 of URL + sorted query + RFC 8785 body, keyed by the client secret | no request signature | `./signature.ts`, `./outbound.ts` |\n * | webhook signature Base64 | lowercase hex | `./signature.ts` |\n * | token: JSON `grant_type: app_level_token`, one token per APPLICATION (every authorized store) | form-encoded `client_credentials` | `./outbound.ts` |\n * | merchant authorization by the software: authorization URL, authorized stores, onboarding, authorization webhook | none | `./authorization.ts` |\n * | `merchantUpdate/{merchantId}` (path names the merchant) | `merchantUpdate` | `./merchant.ts` |\n * | menu: full reload only (`ITEM_OFFER`/`OPTION` status excepted) | full reload | `./merchant.ts` |\n * | personal data encrypted (`ENC_…`), `batchDecrypt` for a merchant's own delivery | plain | `./normalize.ts` |\n * | no `CANCELLATION_REQUEST_DENIED`: a refused request is silent, so it ends TIMEOUT | the denial event | `./normalize.ts`, the answer window below |\n * | `outOfStockItems` carries the PDV codes (`externalCode`) | item uuids, not sent | `../open-delivery/orders.ts` option |\n * | no take-out: no `pickedUp`; `delivered` only for the merchant's bag | `pickedUp` for a take-out | `../open-delivery/orders.ts` option |\n * | one public base URL and portal | given at onboarding | defaults below |\n *\n * ```ts\n * import { createKeetaAdapter } from \"@12-apps/marketplace/keeta\";\n * import { KEETA_ADAPTER_COPY_PT_BR } from \"@12-apps/marketplace/keeta/pt-BR\";\n *\n * createMarketplaceEngine({ …ports, adapters: [createKeetaAdapter({ copy: KEETA_ADAPTER_COPY_PT_BR })] });\n * ```\n *\n * Its webhook is the engine's one route, `POST\n * /webhooks/marketplace/:tenantSlug/KEETA`, registered per store as\n * `ordersWebhookURL` at onboarding.\n */\n\nexport { KEETA_PROVIDER } from \"./normalize\";\n\n/**\n * How long Keeta may take to answer a cancellation request. ESTIMATED: Keeta\n * names none, and sends no event for a refusal, so past this the request is\n * failed as TIMEOUT. Keeta's own clock is 5 minutes for the acceptance.\n */\nexport const KEETA_CANCELLATION_ANSWER_WINDOW_MS = 5 * 60_000;\n\n/** Where \"open it on Keeta\" goes by default: the Merchant Portal (Keeta names no per-order link). */\nexport const KEETA_PORTAL_URL = \"https://merchant.mykeeta.com/\";\n\n/** Keeta has no take-out (`PICKED_UP` \"is not sent\"), so no `pickedUp`. */\nconst STATUS = openDeliveryStatus({ takeoutPickedUp: false });\n\nexport interface KeetaAdapterConfig {\n /** The words the adapter needs: reason labels and the missing-number text. Required. */\n copy: KeetaAdapterCopy;\n /** OPTIONAL. Where Keeta serves Open Delivery, per environment. Default: the documented server for both. https only. */\n apiBaseUrl?: KeetaApiBaseUrls;\n /** OPTIONAL. Where \"open it on Keeta\" goes. Default: the Merchant Portal. https only. */\n portalUrl?: string;\n /**\n * OPTIONAL, off by default. Offer the store pause (FUT-4851) through\n * `merchantStatus`, a store-wide switch with no id: a store the owner also\n * closed by hand on Keeta during the kitchen's pause is opened with it.\n */\n pauseByStoreSwitch?: boolean;\n}\n\nconst assertHttps = (name: string, url: string): void => assertHttpsUrl(\"@12-apps/marketplace/keeta\", name, url);\n\n/** The Keeta API base URLs a config names, checked. */\nfunction basesOf(config: Pick<KeetaAdapterConfig, \"apiBaseUrl\">): KeetaApiBaseUrls {\n const bases = { ...(config.apiBaseUrl ?? KEETA_DEFAULT_API_BASE_URLS) };\n assertHttps(\"apiBaseUrl.SANDBOX\", bases.SANDBOX);\n assertHttps(\"apiBaseUrl.PRODUCTION\", bases.PRODUCTION);\n return bases;\n}\n\n/** Build the Keeta adapter. Its reasons are static: a dialog never waits on Keeta. */\nexport function createKeetaAdapter(config: KeetaAdapterConfig): MarketplaceAdapter {\n const dialect = keetaDialect(basesOf(config));\n const portalUrl = config.portalUrl ?? KEETA_PORTAL_URL;\n assertHttps(\"portalUrl\", portalUrl);\n const reasons: readonly CancellationReason[] = KEETA_REASON_CODES.map((code) => ({\n code,\n label: config.copy.reasonLabels[code],\n itemUnavailable: code === OPEN_DELIVERY_ITEM_UNAVAILABLE,\n // `outOfStockItems` is optional: sent when the store named the SKUs, never required.\n needsItems: false,\n }));\n const normalizeOptions = { missingStreetNumber: config.copy.missingStreetNumber };\n const fetchOptions = {\n normalize: (order: unknown) => normalizeKeetaOrder(order, normalizeOptions),\n prepare: (ctx: AdapterCallContext, order: unknown) => revealKeetaOrder(ctx, dialect, order),\n };\n // Keeta's own example sends PDV codes in `outOfStockItems` (\"PDV-1002\"). ESTIMATED that it reads them so.\n const cancellation = { outOfStockAsSkus: true };\n return {\n provider: KEETA_PROVIDER,\n capabilities: {\n apiConfirm: true,\n apiCancel: true,\n // \"The merchant may cancel up to 48 h after the conclusion\"; the answer is Keeta's.\n cancelAfterAccept: true,\n // 202 (\"received for analysis\"), then CANCELLED, or nothing at all.\n asyncCancellationOutcome: true,\n perOrderAppLink: false,\n // `OrderConfirmed.preparationTime`, in minutes.\n confirmTakesPreparationTime: true,\n cancellationAnswerWindowMs: KEETA_CANCELLATION_ANSWER_WINDOW_MS,\n // readyForPickup, dispatch (merchant's bag) and delivered (merchant's bag).\n statusSteps: [\"READY\", \"DISPATCHED\", \"HANDED_OVER\"],\n },\n normalize: normalizeKeetaEvent,\n readSignature: (header) => header(\"x-app-signature\"),\n verifySignature: verifyKeetaSignature,\n cancellationReasons: () => reasons,\n // PULL: Keeta reads the menu the host serves (`GET /v1/merchant`) and is told when it changed.\n catalogue: keetaCatalogue(dialect),\n fetchOrder: (ctx, order) => openDeliveryFetchOrder(ctx, dialect, order, fetchOptions),\n confirm: (ctx, order, input) => openDeliveryConfirm(ctx, dialect, order, input),\n requestCancellation: (ctx, order, input) =>\n openDeliveryRequestCancellation(ctx, dialect, order, input, cancellation),\n statusSupported: STATUS.supported,\n informStatus: (ctx, order, facts) => STATUS.inform(ctx, dialect, order, facts),\n appLink: () => portalUrl,\n ...(config.pauseByStoreSwitch ? { availability: keetaAvailability(dialect) } : {}),\n };\n}\n\n/** The self-serve merchant authorization calls (`./authorization.ts`), for the same base URLs as the adapter. */\nexport function createKeetaAuthorization(config: Pick<KeetaAdapterConfig, \"apiBaseUrl\"> = {}): KeetaAuthorization {\n return keetaAuthorization(keetaDialect(basesOf(config)));\n}\n\nexport { KEETA_REASON_CODES, type KeetaAdapterCopy, type KeetaReasonCode } from \"./copy\";\nexport { normalizeKeetaEvent, normalizeKeetaOrder } from \"./normalize\";\nexport { canonicalJson, keetaRequestSignature, verifyKeetaSignature } from \"./signature\";\nexport { KEETA_API_BASE_URL, type KeetaApiBaseUrls } from \"./outbound\";\nexport {\n KEETA_AUTHORIZATION_WEBHOOK_ANSWER,\n normalizeKeetaAuthorizationEvent,\n type KeetaAuthorization,\n type KeetaAuthorizationEvent,\n type KeetaAuthorizationResult,\n type KeetaAuthorizedShop,\n type KeetaAuthorizedShops,\n type KeetaOnboarding,\n} from \"./authorization\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,qCAAqC,EAAE,MAAM,GAAG,SAAS,UAAU;AAezE,SAAS,iCAAiC,SAAkD;AACjG,QAAM,SAAS,YAAY,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;AAChD,QAAM,SAAS,YAAY,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;AAChD,QAAM,SAAS,KAAK,SAAS,QAAQ;AACrC,QAAM,SAAS,WAAW,IAAI,eAAe,WAAW,IAAI,YAAY;AACxE,MAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAQ,QAAO;AAC1C,QAAM,SAAS,KAAK,SAAS,YAAY;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,YAAY,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC;AAAA,IAC7C,UAAU,YAAY,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC;AAAA,IAC7C,IAAI,OAAO,WAAW,YAAY,OAAO,SAAS,MAAM,IAAI,IAAI,KAAK,MAAM,IAAI;AAAA,EACjF;AACF;AAfgB;AAkDhB,IAAM,WAAW,wBAAC,OAAgB,aAChC,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ,UAD/C;AAGjB,SAAS,OAAO,KAA0C;AACxD,QAAM,KAAK,YAAY,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;AACpC,MAAI,CAAC,GAAI,QAAO;AAChB,SAAO;AAAA,IACL;AAAA,IACA,MAAM,YAAY,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAAA,IACjC,SAAS,YAAY,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;AAAA,IACvC,UAAU,SAAS,KAAK,KAA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S,KAAK,GAAjF;AAAA,EACX;AAEA,QAAM,eAAe,EAAE,kBAAkB,KAAK;AAC9C,SAAO;AAAA,IACL,UAAU;AAAA,IACV,cAAc;AAAA,MACZ,YAAY;AAAA,MACZ,WAAW;AAAA;AAAA,MAEX,mBAAmB;AAAA;AAAA,MAEnB,0BAA0B;AAAA,MAC1B,iBAAiB;AAAA;AAAA,MAEjB,6BAA6B;AAAA,MAC7B,4BAA4B;AAAA;AAAA,MAE5B,aAAa,CAAC,SAAS,cAAc,aAAa;AAAA,IACpD;AAAA,IACA,WAAW;AAAA,IACX,eAAe,wBAAC,WAAW,OAAO,iBAAiB,GAApC;AAAA,IACf,iBAAiB;AAAA,IACjB,qBAAqB,6BAAM,SAAN;AAAA;AAAA,IAErB,WAAW,eAAe,OAAO;AAAA,IACjC,YAAY,wBAAC,KAAK,UAAU,uBAAuB,KAAK,SAAS,OAAO,YAAY,GAAxE;AAAA,IACZ,SAAS,wBAAC,KAAK,OAAO,UAAU,oBAAoB,KAAK,SAAS,OAAO,KAAK,GAArE;AAAA,IACT,qBAAqB,wBAAC,KAAK,OAAO,UAChC,gCAAgC,KAAK,SAAS,OAAO,OAAO,YAAY,GADrD;AAAA,IAErB,iBAAiB,OAAO;AAAA,IACxB,cAAc,wBAAC,KAAK,OAAO,UAAU,OAAO,OAAO,KAAK,SAAS,OAAO,KAAK,GAA/D;AAAA,IACd,SAAS,6BAAM,WAAN;AAAA,IACT,GAAI,OAAO,qBAAqB,EAAE,cAAc,kBAAkB,OAAO,EAAE,IAAI,CAAC;AAAA,EAClF;AACF;AAjDgB;AAoDT,SAAS,yBAAyB,SAAiD,CAAC,GAAuB;AAChH,SAAO,mBAAmB,aAAa,QAAQ,MAAM,CAAC,CAAC;AACzD;AAFgB;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Keeta adapter's pt-BR pack: each code in the words of Keeta's own
|
|
3
|
+
* cancellation table ("Significado"). A host passes this pack by hand:
|
|
4
|
+
* choosing the language is a line in the host's diff.
|
|
5
|
+
*/
|
|
6
|
+
declare const KEETA_ADAPTER_COPY_PT_BR: {
|
|
7
|
+
readonly reasonLabels: {
|
|
8
|
+
readonly SYSTEMIC_ISSUES: "Problemas sistêmicos";
|
|
9
|
+
readonly DUPLICATE_APPLICATION: "Pedido duplicado";
|
|
10
|
+
readonly UNAVAILABLE_ITEM: "Item indisponível";
|
|
11
|
+
readonly RESTAURANT_WITHOUT_DELIVERY_PERSON: "Restaurante sem entregador";
|
|
12
|
+
readonly OUTDATED_MENU: "Cardápio desatualizado";
|
|
13
|
+
readonly ORDER_OUTSIDE_THE_DELIVERY_AREA: "Fora da área de entrega";
|
|
14
|
+
readonly BLOCKED_CUSTOMER: "Cliente bloqueado";
|
|
15
|
+
readonly OUTSIDE_DELIVERY_HOURS: "Fora do horário de entrega";
|
|
16
|
+
readonly INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT: "Dificuldades internas";
|
|
17
|
+
readonly RISK_AREA: "Área de risco";
|
|
18
|
+
readonly DELIVERY_PROBLEM: "Problema na entrega";
|
|
19
|
+
};
|
|
20
|
+
readonly missingStreetNumber: "s/n";
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { KEETA_ADAPTER_COPY_PT_BR };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../chunk-7QVYU63E.js";
|
|
2
|
+
|
|
3
|
+
// src/keeta/pt-BR.ts
|
|
4
|
+
var KEETA_ADAPTER_COPY_PT_BR = {
|
|
5
|
+
reasonLabels: {
|
|
6
|
+
SYSTEMIC_ISSUES: "Problemas sist\xEAmicos",
|
|
7
|
+
DUPLICATE_APPLICATION: "Pedido duplicado",
|
|
8
|
+
UNAVAILABLE_ITEM: "Item indispon\xEDvel",
|
|
9
|
+
RESTAURANT_WITHOUT_DELIVERY_PERSON: "Restaurante sem entregador",
|
|
10
|
+
OUTDATED_MENU: "Card\xE1pio desatualizado",
|
|
11
|
+
ORDER_OUTSIDE_THE_DELIVERY_AREA: "Fora da \xE1rea de entrega",
|
|
12
|
+
BLOCKED_CUSTOMER: "Cliente bloqueado",
|
|
13
|
+
OUTSIDE_DELIVERY_HOURS: "Fora do hor\xE1rio de entrega",
|
|
14
|
+
INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT: "Dificuldades internas",
|
|
15
|
+
RISK_AREA: "\xC1rea de risco",
|
|
16
|
+
DELIVERY_PROBLEM: "Problema na entrega"
|
|
17
|
+
},
|
|
18
|
+
missingStreetNumber: "s/n"
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
KEETA_ADAPTER_COPY_PT_BR
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=pt-BR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/keeta/pt-BR.ts"],"sourcesContent":["import type { KeetaAdapterCopy } from \"./copy\";\n\n/**\n * The Keeta adapter's pt-BR pack: each code in the words of Keeta's own\n * cancellation table (\"Significado\"). A host passes this pack by hand:\n * choosing the language is a line in the host's diff.\n */\nexport const KEETA_ADAPTER_COPY_PT_BR = {\n reasonLabels: {\n SYSTEMIC_ISSUES: \"Problemas sistêmicos\",\n DUPLICATE_APPLICATION: \"Pedido duplicado\",\n UNAVAILABLE_ITEM: \"Item indisponível\",\n RESTAURANT_WITHOUT_DELIVERY_PERSON: \"Restaurante sem entregador\",\n OUTDATED_MENU: \"Cardápio desatualizado\",\n ORDER_OUTSIDE_THE_DELIVERY_AREA: \"Fora da área de entrega\",\n BLOCKED_CUSTOMER: \"Cliente bloqueado\",\n OUTSIDE_DELIVERY_HOURS: \"Fora do horário de entrega\",\n INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT: \"Dificuldades internas\",\n RISK_AREA: \"Área de risco\",\n DELIVERY_PROBLEM: \"Problema na entrega\",\n },\n missingStreetNumber: \"s/n\",\n} as const satisfies KeetaAdapterCopy;\n"],"mappings":";;;AAOO,IAAM,2BAA2B;AAAA,EACtC,cAAc;AAAA,IACZ,iBAAiB;AAAA,IACjB,uBAAuB;AAAA,IACvB,kBAAkB;AAAA,IAClB,oCAAoC;AAAA,IACpC,eAAe;AAAA,IACf,iCAAiC;AAAA,IACjC,kBAAkB;AAAA,IAClB,wBAAwB;AAAA,IACxB,yCAAyC;AAAA,IACzC,WAAW;AAAA,IACX,kBAAkB;AAAA,EACpB;AAAA,EACA,qBAAqB;AACvB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@12-apps/marketplace",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"description": "One marketplace integration engine for every marketplace: the durable inbox, the ingest pipeline, the acceptance clock and its sweep, the SKU map, the integration settings with sealed credentials, and the outbound engine (confirm, cancellation request, retries), behind an adapter port. Each marketplace is an adapter at its own subpath (./ifood, ./99food on Open Delivery, ./rappi). Framework-neutral wiring route descriptors (./server) with a Hono adapter (./hono), dep-free job blueprints, MCP tools and the package-owned Prisma partial + migrations.",
|
|
6
|
+
"description": "One marketplace integration engine for every marketplace: the durable inbox, the ingest pipeline, the acceptance clock and its sweep, the SKU map, the integration settings with sealed credentials, and the outbound engine (confirm, cancellation request, retries), behind an adapter port. Each marketplace is an adapter at its own subpath (./ifood, ./99food and ./keeta on Open Delivery, ./rappi). Framework-neutral wiring route descriptors (./server) with a Hono adapter (./hono), dep-free job blueprints, MCP tools and the package-owned Prisma partial + migrations.",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -45,6 +45,18 @@
|
|
|
45
45
|
"types": "./dist/rappi/en-US.d.ts",
|
|
46
46
|
"default": "./dist/rappi/en-US.js"
|
|
47
47
|
},
|
|
48
|
+
"./keeta": {
|
|
49
|
+
"types": "./dist/keeta/index.d.ts",
|
|
50
|
+
"default": "./dist/keeta/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./keeta/pt-BR": {
|
|
53
|
+
"types": "./dist/keeta/pt-BR.d.ts",
|
|
54
|
+
"default": "./dist/keeta/pt-BR.js"
|
|
55
|
+
},
|
|
56
|
+
"./keeta/en-US": {
|
|
57
|
+
"types": "./dist/keeta/en-US.d.ts",
|
|
58
|
+
"default": "./dist/keeta/en-US.js"
|
|
59
|
+
},
|
|
48
60
|
"./server": {
|
|
49
61
|
"types": "./dist/server/index.d.ts",
|
|
50
62
|
"default": "./dist/server/index.js"
|