@fayz-ai/sdk 0.12.0 → 0.19.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/agent.d.ts CHANGED
@@ -75,6 +75,27 @@ export interface AgentAttachmentDigest {
75
75
  /** What the reader had to guess at, truncate or give up on. */
76
76
  warnings?: string[];
77
77
  }
78
+ /**
79
+ * A file the user handed over TO BE READ — bytes, not a shape.
80
+ *
81
+ * The rule above holds and this is its one exception, drawn narrowly. A
82
+ * spreadsheet of patients gets DIGESTED because nobody asked for it to be read;
83
+ * it was attached so the agent could plan an import, and shipping it to a model
84
+ * provider would be a disclosure nobody consented to.
85
+ *
86
+ * A photographed receipt is the opposite case in every respect: one document,
87
+ * handed over on purpose, by a person whose whole request is "read this". The
88
+ * gesture IS the consent, so bytes travel — and ONLY for a file that arrived
89
+ * through an explicit request to read it. Never because an attachment happened
90
+ * to be an image.
91
+ */
92
+ export interface AgentInlineFile {
93
+ name: string;
94
+ /** `image/jpeg`, `image/png`, `application/pdf`. */
95
+ mime: string;
96
+ /** Base64 of the file, without the `data:` prefix. */
97
+ data: string;
98
+ }
78
99
  export interface FayzAgentChatInput {
79
100
  /** New end-user message. Omit when replying with tool results. */
80
101
  message?: string;
@@ -94,6 +115,14 @@ export interface FayzAgentChatInput {
94
115
  context?: Record<string, unknown>;
95
116
  /** Files the user attached this turn, as digests — never as bytes. */
96
117
  attachments?: AgentAttachmentDigest[];
118
+ /**
119
+ * Files the user handed over to be READ this turn — see AgentInlineFile.
120
+ *
121
+ * Separate from `attachments` on purpose: two fields means the boundary is
122
+ * visible at every call site and in every request log, instead of being a
123
+ * flag someone can flip by accident on a digest.
124
+ */
125
+ inlineFiles?: AgentInlineFile[];
97
126
  signal?: AbortSignal;
98
127
  }
99
128
  /** A server-plane write the broker parked pending human confirmation. */
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;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CAAA;CACvD;AAED,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IACrD,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAC/D;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,kBAAkB,EAAE,SAAS,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAC3G,oEAAoE;IACpE,iBAAiB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,4BAA4B,EAAE,CAAC,CAAA;IACzG,sEAAsE;IACtE,eAAe,CACb,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,2BAA2B,CAAC,CAAA;CACxC;AAWD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAoItF"}
package/dist/agent.js CHANGED
@@ -1,3 +1,3 @@
1
- export { FayzAgentError, createFayzAgentClient } from './chunk-LSBVNW75.js';
1
+ export { FayzAgentError, createFayzAgentClient } from './chunk-KTRZI44K.js';
2
2
  //# sourceMappingURL=agent.js.map
3
3
  //# sourceMappingURL=agent.js.map
@@ -1,4 +1,4 @@
1
- import { resetDeprecationWarnings, warnDeprecated } from './chunk-HA5O3CW7.js';
1
+ import { resetDeprecationWarnings, warnDeprecated } from './chunk-LCW5ZV5S.js';
2
2
 
3
3
  // src/lib/dedupe-fetch.ts
4
4
  var DEFAULT_VARY = [
@@ -16,7 +16,11 @@ var DEFAULT_VARY = [
16
16
  // count=exact changes Content-Range
17
17
  "x-fayz-store",
18
18
  // storefront tenant scope
19
- "x-fayz-tenant"
19
+ "x-fayz-tenant",
20
+ // The active unit. Load-bearing, not decorative: two reads of the SAME url
21
+ // under different units are different questions, and without this line the
22
+ // second one joins the first and a franchisee is handed another unit's rows.
23
+ "x-fayz-unit"
20
24
  ];
21
25
  var collapsed = 0;
22
26
  var flights = /* @__PURE__ */ new Map();
@@ -87,8 +91,9 @@ function setShopAccessTokenResolver(resolver) {
87
91
  var CARRIER_QUOTE_BUDGET_MS = 2500;
88
92
  var CARRIER_OPTION_SEPARATOR = "::";
89
93
  var CHECKOUT_GATEWAYS = {
90
- abacatepay: { open: "shop-checkout-open", settle: "shop-checkout-settle" },
91
- vindi: { open: "vindi-checkout-open", settle: "vindi-checkout-settle" }
94
+ abacatepay: { open: "shop-checkout-open", settle: "shop-checkout-settle", link: false },
95
+ vindi: { open: "vindi-checkout-open", settle: "vindi-checkout-settle", link: true },
96
+ mercadopago: { open: "mercadopago-checkout-open", settle: "mercadopago-checkout-settle", link: false }
92
97
  };
93
98
  function checkoutGateway(provider) {
94
99
  const slug = String(provider ?? "").trim();
@@ -569,7 +574,7 @@ function createFayzShopProvider(options) {
569
574
  },
570
575
  async listOrders(options2) {
571
576
  const query = tenantQuery();
572
- query.set("select", "*,items:plg_shop_order_items(*),shipments:fulfillments(status,delivered_at)");
577
+ query.set("select", "*,items:plg_shop_order_items(*)");
573
578
  if (options2?.status) query.set("status", `eq.${options2.status}`);
574
579
  if (options2?.financialStatus) query.set("financial_status", `eq.${options2.financialStatus}`);
575
580
  if (options2?.fulfillmentStatus) query.set("fulfillment_status", `eq.${options2.fulfillmentStatus}`);
@@ -581,7 +586,7 @@ function createFayzShopProvider(options) {
581
586
  if (options2?.offset) query.set("offset", String(options2.offset));
582
587
  let rows = [];
583
588
  try {
584
- rows = await request("plg_shop_orders", { query });
589
+ rows = await request("v_shop_orders", { query });
585
590
  } catch (error) {
586
591
  if (!options2?.customerId) throw error;
587
592
  }
@@ -610,7 +615,7 @@ function createFayzShopProvider(options) {
610
615
  query.set("select", "*,items:plg_shop_order_items(*)");
611
616
  let rows = [];
612
617
  try {
613
- rows = await request("plg_shop_orders", { query });
618
+ rows = await request("v_shop_orders", { query });
614
619
  } catch {
615
620
  }
616
621
  if (rows[0]) return rowToOrder(rows[0]);
@@ -655,6 +660,45 @@ function createFayzShopProvider(options) {
655
660
  * its own — `settleCheckoutSession` is what turns it into an order, and only
656
661
  * after the acquirer says the money is in.
657
662
  */
663
+ /**
664
+ * Remember the contact details of whoever is signed in.
665
+ *
666
+ * Called when the buyer leaves the contact step rather than when an order
667
+ * completes: an abandoned checkout teaches the store nothing, and the person
668
+ * who most needs their phone remembered is the one who did not finish. The
669
+ * function decides which columns may be written and to whose row — a shopper
670
+ * is not a tenant member, so there is no policy that would let this be a
671
+ * plain UPDATE, and RLS could not narrow one to two columns anyway.
672
+ */
673
+ async saveCustomerContact(input) {
674
+ try {
675
+ await request("rpc/shop_save_customer_contact", {
676
+ method: "POST",
677
+ body: JSON.stringify({
678
+ p_tenant_id: storeId,
679
+ p_phone: input.phone ?? null,
680
+ p_document: input.document ?? null
681
+ })
682
+ });
683
+ } catch {
684
+ }
685
+ },
686
+ /** The acquirer's public key, for a checkout that tokenises in the browser. */
687
+ async paymentPublicKey(provider) {
688
+ const gateway = checkoutGateway(provider);
689
+ if (!gateway) return null;
690
+ try {
691
+ const response = await (options.fetcher ?? fetch)(`${functionsUrl}/${gateway.open}`, {
692
+ method: "POST",
693
+ headers: { apikey: key, Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
694
+ body: JSON.stringify({ tenantId: storeId, action: "public_key" })
695
+ });
696
+ const payload = await response.json().catch(() => null);
697
+ return response.ok ? payload?.publicKey ?? null : null;
698
+ } catch {
699
+ return null;
700
+ }
701
+ },
658
702
  async openCheckoutSession(input) {
659
703
  const provider = String(input.provider ?? "").trim() || "abacatepay";
660
704
  const gateway = checkoutGateway(provider);
@@ -670,7 +714,35 @@ function createFayzShopProvider(options) {
670
714
  })),
671
715
  customer: input.customer,
672
716
  shippingAddress: input.shippingAddress ?? null,
673
- discountCode: input.discountCode ?? null
717
+ discountCode: input.discountCode ?? null,
718
+ // O que o comprador escolheu, no vocabulário da loja. Quem traduz para
719
+ // o número do adquirente é a função, do lado de lá, onde também mora a
720
+ // lista do que o lojista habilitou.
721
+ method: input.paymentMethod ?? null,
722
+ // Para onde o adquirente devolve quem pagou fora daqui. A função confere
723
+ // este endereço contra a origem de quem pediu: é uma URL que entregamos
724
+ // a terceiro, e terceiro nenhum redireciona comprador nosso para onde
725
+ // quiser.
726
+ returnUrl: input.returnUrl ?? null,
727
+ asLink: input.asLink === true,
728
+ // O cartão digitado DENTRO da loja, quando o adquirente tokeniza no
729
+ // navegador. Não é um número de cartão: é um código de uso único que o
730
+ // Brick do Mercado Pago devolveu, e sem ele a função não tem o que
731
+ // cobrar.
732
+ //
733
+ // Este corpo é montado campo a campo, então o que não estiver nomeado
734
+ // aqui NÃO CHEGA do outro lado — a vitrine já mandava os cinco e todos
735
+ // eram descartados em silêncio, com o comprador recebendo "não
736
+ // recebemos os dados do cartão" depois de preencher tudo certo.
737
+ // Enviados como null quando ausentes, para que um Pix continue sendo um
738
+ // corpo com as mesmas chaves.
739
+ cardToken: input.cardToken ?? null,
740
+ installments: input.installments ?? null,
741
+ paymentMethodId: input.paymentMethodId ?? null,
742
+ issuerId: input.issuerId ?? null,
743
+ // A recomendação nº 1 deles para aprovação: sem a impressão digital do
744
+ // aparelho, um comprador legítimo é recusado com mais frequência.
745
+ deviceId: input.deviceId ?? null
674
746
  });
675
747
  const response = await (options.fetcher ?? fetch)(`${functionsUrl}/${gateway.open}`, {
676
748
  method: "POST",
@@ -689,6 +761,11 @@ function createFayzShopProvider(options) {
689
761
  total: Number(payload.total ?? 0),
690
762
  state: "open",
691
763
  provider,
764
+ method: payload.method ?? input.paymentMethod ?? null,
765
+ // A página do adquirente: o link que o lojista manda e o endereço para
766
+ // onde o comprador de cartão é levado. São a mesma coisa vista de dois
767
+ // lugares — quem chama decide se copia ou se vai.
768
+ paymentUrl: payload.redirectUrl ?? payload.paymentUrl ?? null,
692
769
  charge: payload.brCode ? {
693
770
  emv: payload.brCode,
694
771
  // O tipo promete base64 PURO, e a AbacatePay manda com o
@@ -696,6 +773,12 @@ function createFayzShopProvider(options) {
696
773
  // Sem tirar aqui, a tela prefixava de novo e o QR não aparecia —
697
774
  // um <img> com src inválido, silencioso.
698
775
  qrcodeBase64: (payload.brCodeBase64 ?? "").replace(/^data:image\/\w+;base64,/u, "") || null,
776
+ // Vindi hosts the QR instead of inlining it, so the image arrives
777
+ // as an https URL to an SVG. It travels beside the base64 rather
778
+ // than inside it: the two cannot be told apart at the point of use
779
+ // without guessing at the string, and drawing either as the other
780
+ // is a silently broken <img> in front of someone trying to pay.
781
+ qrcodeUrl: String(payload.qrCodeUrl ?? "").trim() || null,
699
782
  expiresAt: payload.expiresAt ?? ""
700
783
  } : null
701
784
  };
@@ -705,14 +788,17 @@ function createFayzShopProvider(options) {
705
788
  * read as "still waiting" (`unknown`) and never as a payment that failed —
706
789
  * one wrong `failed` here throws away a cart the buyer already paid for.
707
790
  */
708
- async settleCheckoutSession(sessionId, provider) {
791
+ async settleCheckoutSession(sessionId, provider, chargeToken) {
709
792
  const gateway = checkoutGateway(String(provider ?? "").trim() || "abacatepay");
710
793
  if (!gateway) return { state: "unknown" };
711
794
  try {
712
795
  const response = await (options.fetcher ?? fetch)(`${functionsUrl}/${gateway.settle}`, {
713
796
  method: "POST",
714
797
  headers: { apikey: key, Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
715
- body: JSON.stringify({ tenantId: storeId, sessionId })
798
+ // `chargeToken` é PISTA, nunca afirmação: o adquirente pendura o token
799
+ // na volta do comprador, e o servidor confere com ele antes de aceitar.
800
+ // Serve para fechar a compra na hora em vez de esperar o webhook.
801
+ body: JSON.stringify({ tenantId: storeId, sessionId, ...chargeToken ? { chargeToken } : {} })
716
802
  });
717
803
  const payload = await response.json().catch(() => null);
718
804
  if (!response.ok || !payload?.state) return { state: "unknown" };
@@ -784,7 +870,10 @@ function createFayzShopProvider(options) {
784
870
  code: row?.code ?? null,
785
871
  type: row?.type ?? null,
786
872
  value: Number(row?.value ?? 0),
787
- reason: row?.reason ?? void 0
873
+ reason: row?.reason ?? void 0,
874
+ // 0057 answers `min_subtotal` with the number. Dropped here, the cart
875
+ // could only say "inválido ou expirado" about a coupon that is neither.
876
+ ...row?.min_subtotal != null ? { minSubtotal: Number(row.min_subtotal) } : {}
788
877
  };
789
878
  },
790
879
  async cancelOrder(orderId, reason) {
@@ -837,7 +926,7 @@ function createFayzShopProvider(options) {
837
926
  const discountTotal = input.discountTotal ?? 0;
838
927
  const shippingTotal = input.shippingTotal ?? 0;
839
928
  const total = Math.round((subtotal - discountTotal + shippingTotal) * 100) / 100;
840
- const [order] = await request("plg_shop_orders", {
929
+ const [order] = await request("v_shop_orders", {
841
930
  method: "POST",
842
931
  body: JSON.stringify({
843
932
  tenant_id: storeId,
@@ -875,7 +964,7 @@ function createFayzShopProvider(options) {
875
964
  return this.getOrder(order.id);
876
965
  },
877
966
  async updateOrder(id, input) {
878
- await request("plg_shop_orders", {
967
+ await request("v_shop_orders", {
879
968
  method: "PATCH",
880
969
  query: singleById(id),
881
970
  body: JSON.stringify(updateOrderPayload(input))
@@ -1285,5 +1374,5 @@ function createBrokerShopProvider(options) {
1285
1374
  }
1286
1375
 
1287
1376
  export { FayzShopError, PRODUCT_METADATA_OVERLAY_DEPRECATION, createDedupedFetch, createFayzShopProvider, getDedupeStats, resetDedupeStats, resetProductMetadataOverlayDeprecationWarning, setShopAccessTokenResolver, setShopCarrierQuotesResolver, setShopShippingItemsResolver };
1288
- //# sourceMappingURL=chunk-4YRHC5N7.js.map
1289
- //# sourceMappingURL=chunk-4YRHC5N7.js.map
1377
+ //# sourceMappingURL=chunk-BTXIUI4E.js.map
1378
+ //# sourceMappingURL=chunk-BTXIUI4E.js.map