@neetru/sdk 3.4.2 → 3.4.4

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/ai.d.cts +1 -1
  3. package/dist/ai.d.ts +1 -1
  4. package/dist/auth.cjs +17 -7
  5. package/dist/auth.cjs.map +1 -1
  6. package/dist/auth.d.cts +1 -1
  7. package/dist/auth.d.ts +1 -1
  8. package/dist/auth.mjs +17 -7
  9. package/dist/auth.mjs.map +1 -1
  10. package/dist/build-guard.cjs +98 -0
  11. package/dist/build-guard.cjs.map +1 -1
  12. package/dist/build-guard.d.cts +63 -1
  13. package/dist/build-guard.d.ts +63 -1
  14. package/dist/build-guard.mjs +93 -1
  15. package/dist/build-guard.mjs.map +1 -1
  16. package/dist/catalog.d.cts +1 -1
  17. package/dist/catalog.d.ts +1 -1
  18. package/dist/checkout.cjs +17 -7
  19. package/dist/checkout.cjs.map +1 -1
  20. package/dist/checkout.d.cts +1 -1
  21. package/dist/checkout.d.ts +1 -1
  22. package/dist/checkout.mjs +17 -7
  23. package/dist/checkout.mjs.map +1 -1
  24. package/dist/db-react.d.cts +1 -1
  25. package/dist/db-react.d.ts +1 -1
  26. package/dist/db.d.cts +1 -1
  27. package/dist/db.d.ts +1 -1
  28. package/dist/entitlements.d.cts +1 -1
  29. package/dist/entitlements.d.ts +1 -1
  30. package/dist/firestore-compat.d.cts +1 -1
  31. package/dist/firestore-compat.d.ts +1 -1
  32. package/dist/index.cjs +18 -8
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +2 -2
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.mjs +18 -8
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/mocks.d.cts +1 -1
  39. package/dist/mocks.d.ts +1 -1
  40. package/dist/notifications.d.cts +1 -1
  41. package/dist/notifications.d.ts +1 -1
  42. package/dist/react.cjs +62 -3
  43. package/dist/react.cjs.map +1 -1
  44. package/dist/react.d.cts +38 -7
  45. package/dist/react.d.ts +38 -7
  46. package/dist/react.mjs +62 -3
  47. package/dist/react.mjs.map +1 -1
  48. package/dist/support.d.cts +1 -1
  49. package/dist/support.d.ts +1 -1
  50. package/dist/telemetry.d.cts +1 -1
  51. package/dist/telemetry.d.ts +1 -1
  52. package/dist/{types-BlOLDMR0.d.ts → types-Bzxb5rlF.d.ts} +26 -8
  53. package/dist/{types-D-QdG502.d.cts → types-Dw0fqhHm.d.cts} +26 -8
  54. package/dist/usage.d.cts +1 -1
  55. package/dist/usage.d.ts +1 -1
  56. package/dist/webhooks.d.cts +1 -1
  57. package/dist/webhooks.d.ts +1 -1
  58. package/package.json +1 -1
package/dist/mocks.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-D-QdG502.cjs';
1
+ import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-Dw0fqhHm.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
package/dist/mocks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-BlOLDMR0.js';
1
+ import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-Bzxb5rlF.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
@@ -1,3 +1,3 @@
1
- export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-D-QdG502.cjs';
1
+ export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-Dw0fqhHm.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
@@ -1,3 +1,3 @@
1
- export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-BlOLDMR0.js';
1
+ export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-Bzxb5rlF.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
package/dist/react.cjs CHANGED
@@ -610,8 +610,44 @@ function normalizeOp(op) {
610
610
  }
611
611
 
612
612
  // src/react.ts
613
+ async function startCheckoutViaBff(startPath, input) {
614
+ const res = await fetch(startPath, {
615
+ method: "POST",
616
+ headers: { "content-type": "application/json", accept: "application/json" },
617
+ credentials: "include",
618
+ body: JSON.stringify(input)
619
+ });
620
+ let payload = null;
621
+ try {
622
+ payload = await res.json();
623
+ } catch {
624
+ payload = null;
625
+ }
626
+ if (!res.ok) {
627
+ const p = payload;
628
+ const msg = p && (typeof p.error === "object" && p.error?.message || typeof p.error === "string" && p.error || typeof p.message === "string" && p.message) || `Checkout BFF respondeu HTTP ${res.status}`;
629
+ throw new Error(typeof msg === "string" ? msg : `Checkout BFF respondeu HTTP ${res.status}`);
630
+ }
631
+ const intent = payload?.intent ?? payload ?? {};
632
+ const redirectUrl = payload?.redirectUrl ?? intent.redirectUrl;
633
+ if (!redirectUrl || typeof redirectUrl !== "string") {
634
+ throw new Error("Resposta do route BFF de checkout sem `redirectUrl`.");
635
+ }
636
+ return {
637
+ intentId: String(payload?.intentId ?? intent.intentId ?? ""),
638
+ redirectUrl,
639
+ status: payload?.status ?? intent.status ?? "pending",
640
+ expiresAt: typeof payload?.expiresAt === "string" ? payload.expiresAt : typeof intent.expiresAt === "string" ? intent.expiresAt : "",
641
+ requiresKyc: payload?.requiresKyc === true || intent.requiresKyc === true
642
+ };
643
+ }
644
+ function checkoutRedirect(url) {
645
+ const loc = globalThis.location;
646
+ if (loc && typeof loc.assign === "function") loc.assign(url);
647
+ }
613
648
  function CheckoutLink({
614
649
  client,
650
+ startPath,
615
651
  productId,
616
652
  planId,
617
653
  callbackUrl,
@@ -624,13 +660,36 @@ function CheckoutLink({
624
660
  ...rest
625
661
  }) {
626
662
  const [submitting, setSubmitting] = React2__namespace.useState(false);
627
- const checkout = client.checkout;
663
+ const checkout = client?.checkout;
628
664
  const handleClick = React2__namespace.useCallback(
629
665
  async (event) => {
630
666
  event.preventDefault();
631
667
  if (submitting) return;
668
+ if (startPath) {
669
+ setSubmitting(true);
670
+ try {
671
+ const result = await startCheckoutViaBff(startPath, {
672
+ productId,
673
+ planId,
674
+ callbackUrl,
675
+ tenantType,
676
+ tenantId
677
+ });
678
+ onIntentCreated?.(result);
679
+ if (!noAutoRedirect) checkoutRedirect(result.redirectUrl);
680
+ } catch (err) {
681
+ onError?.(err instanceof Error ? err : new Error(String(err)));
682
+ } finally {
683
+ setSubmitting(false);
684
+ }
685
+ return;
686
+ }
632
687
  if (!checkout || typeof checkout.start !== "function") {
633
- onError?.(new Error("SDK client missing `checkout` namespace. Upgrade @neetru/sdk to 1.1+."));
688
+ onError?.(
689
+ new Error(
690
+ "CheckoutLink: passe `startPath` (padr\xE3o BFF/cookie recomendado) OU um `client` com o namespace `checkout` (SDK 1.1+)."
691
+ )
692
+ );
634
693
  return;
635
694
  }
636
695
  setSubmitting(true);
@@ -650,7 +709,7 @@ function CheckoutLink({
650
709
  setSubmitting(false);
651
710
  }
652
711
  },
653
- [submitting, checkout, productId, planId, callbackUrl, tenantType, tenantId, noAutoRedirect, onIntentCreated, onError]
712
+ [submitting, checkout, startPath, productId, planId, callbackUrl, tenantType, tenantId, noAutoRedirect, onIntentCreated, onError]
654
713
  );
655
714
  return React2__namespace.createElement(
656
715
  "a",