@aifeatures/admin-react 0.3.1 → 0.5.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/dist/index.d.cts CHANGED
@@ -10,7 +10,6 @@ interface Form {
10
10
  endpoint_url: string;
11
11
  email_recipients: string[];
12
12
  redirect_url: string | null;
13
- webhook_url: string | null;
14
13
  turnstile_sitekey: string | null;
15
14
  created_at: string;
16
15
  updated_at: string;
@@ -70,7 +69,6 @@ interface CreateFormInput {
70
69
  name: string;
71
70
  email_recipients?: string[];
72
71
  redirect_url?: string;
73
- webhook_url?: string;
74
72
  }
75
73
  /**
76
74
  * Input for updating a form
@@ -79,7 +77,6 @@ interface UpdateFormInput {
79
77
  name?: string;
80
78
  email_recipients?: string[];
81
79
  redirect_url?: string | null;
82
- webhook_url?: string | null;
83
80
  }
84
81
  /**
85
82
  * Options for fetching submissions
@@ -833,6 +830,138 @@ interface PersonDetail {
833
830
  orders: PersonOrder[];
834
831
  submissions: PersonSubmission[];
835
832
  }
833
+ /**
834
+ * One subscription mirror row from GET /api/v1/subscriptions. Amounts are
835
+ * integers in the currency's minor unit. Read-only in this package: cancel /
836
+ * teardown are org-key-only endpoints proxied through the host app — the
837
+ * dashboard's site token cannot call them.
838
+ */
839
+ interface Subscription {
840
+ id: string;
841
+ /**
842
+ * Mirrored Stripe status, stored VERBATIM — a full-Dashboard merchant can
843
+ * produce states beyond the modeled set (trialing, paused, unpaid, …).
844
+ * Render unknown values generically ("Managed in Stripe"), never as an
845
+ * error and never by guessing a modeled meaning for them.
846
+ */
847
+ status: string;
848
+ /** The subscriber (from the durable customer record). */
849
+ customer_email: string | null;
850
+ product_id: string;
851
+ plan_title: string | null;
852
+ /** Stripe recurring interval ("month", "year", …). */
853
+ plan_interval: string;
854
+ plan_interval_count: number;
855
+ /**
856
+ * The LOCKED signup recurring amount (minor units) — the grandfathering
857
+ * record. Never changes; shown as provenance when it differs from
858
+ * `current_amount`.
859
+ */
860
+ plan_amount: number;
861
+ /**
862
+ * The CURRENT recurring amount mirrored from Stripe (minor units) —
863
+ * Dashboard repricing lands here. This is the display figure.
864
+ */
865
+ current_amount: number;
866
+ currency: string;
867
+ /** Next renewal (mirrored). Null when Stripe hasn't told us one. */
868
+ current_period_end: string | null;
869
+ /** Scheduled to cancel — the subscriber keeps access until the period lapses. */
870
+ cancel_at_period_end: boolean;
871
+ canceled_at: string | null;
872
+ /** Cancel provenance ('subscriber' | 'merchant'), when known. */
873
+ canceled_by: string | null;
874
+ /** Set only by the org-key teardown endpoint on rows it flipped. */
875
+ teardown_at: string | null;
876
+ /** Simulator/preview data — badge it and exclude it from any aggregate. */
877
+ is_test: boolean;
878
+ created_at: string;
879
+ }
880
+ /** Response from GET /api/v1/subscriptions (server-side total, like orders). */
881
+ interface PaginatedSubscriptions {
882
+ subscriptions: Subscription[];
883
+ total: number;
884
+ limit: number;
885
+ offset: number;
886
+ }
887
+ /** Options for fetching subscriptions. */
888
+ interface GetSubscriptionsOptions {
889
+ /** Exact status filter (verbatim Stripe values, e.g. "active"). */
890
+ status?: string;
891
+ limit?: number;
892
+ offset?: number;
893
+ }
894
+ /**
895
+ * An outbound webhook destination.
896
+ *
897
+ * The API calls these "event destinations" (the eventdestinations.org term,
898
+ * which leaves room for a queue or bus destination later); the dashboard says
899
+ * "Webhooks", the word a merchant wiring up Zapier already knows. Today every
900
+ * destination is an HTTPS webhook, so the two describe one object.
901
+ */
902
+ interface EventDestination {
903
+ id: string;
904
+ site_id: string;
905
+ /** Set when the destination is scoped to a single form. Null = site-wide. */
906
+ form_id: string | null;
907
+ url: string;
908
+ /** Subscribed topics. `["*"]` receives every topic. */
909
+ topics: string[];
910
+ /**
911
+ * Payload version, pinned at creation and never rewritten. A future payload
912
+ * shape ships as a new version and this destination keeps receiving the one
913
+ * it was created with.
914
+ */
915
+ api_version: string;
916
+ status: 'active' | 'disabled';
917
+ /** Why it was auto-disabled after repeated failures. Null while active. */
918
+ disabled_reason: string | null;
919
+ consecutive_failures: number;
920
+ created_at: string;
921
+ updated_at: string;
922
+ }
923
+ /**
924
+ * The signing secret has exactly one endpoint. It is re-readable on demand
925
+ * rather than shown once, because verifying deliveries is optional and most
926
+ * merchants never do it — a copy-it-now moment would be a task imposed on
927
+ * everyone for the benefit of a few.
928
+ */
929
+ interface EventDestinationSecretResponse {
930
+ secret: string;
931
+ }
932
+ interface EventDestinationsListResponse {
933
+ destinations: EventDestination[];
934
+ }
935
+ interface CreateEventDestinationInput {
936
+ url: string;
937
+ topics?: string[];
938
+ /** Required: every destination belongs to exactly one form. */
939
+ form_id: string;
940
+ }
941
+ interface UpdateEventDestinationInput {
942
+ url?: string;
943
+ topics?: string[];
944
+ status?: 'active' | 'disabled';
945
+ }
946
+ /** One attempt record from a destination's delivery log. */
947
+ interface EventDelivery {
948
+ id: string;
949
+ destination_id: string;
950
+ /** Sent as the webhook-id header; stable across retries. */
951
+ event_id: string;
952
+ type: string;
953
+ /** The exact JSON body that was (or will be) POSTed. */
954
+ payload: string;
955
+ attempts: number;
956
+ next_attempt_at: string;
957
+ delivered_at: string | null;
958
+ last_error: string | null;
959
+ last_status: number | null;
960
+ created_at: string;
961
+ }
962
+ interface EventDeliveriesListResponse {
963
+ deliveries: EventDelivery[];
964
+ }
836
965
 
837
966
  declare class AifeaturesApiError extends Error {
838
967
  status: number;
@@ -880,12 +1009,22 @@ interface AifeaturesApiClient {
880
1009
  * disputed.
881
1010
  */
882
1011
  setOrderFulfillment(orderId: string, input: SetOrderFulfillmentInput): Promise<Order>;
1012
+ getSubscriptions(options?: GetSubscriptionsOptions): Promise<PaginatedSubscriptions>;
883
1013
  /** One-look business summary: revenue windows, needs-attention list, product counts. */
884
1014
  getBusinessSummary(options: GetBusinessSummaryOptions): Promise<BusinessSummary>;
885
1015
  /** Merged people list (customers ∪ form leads, grouped by email). */
886
1016
  getPeople(options?: GetPeopleOptions): Promise<PeopleListResponse>;
887
1017
  /** Everything known about one person (customer record, orders, submissions). */
888
1018
  getPerson(email: string): Promise<PersonDetail>;
1019
+ getEventDestinations(): Promise<EventDestination[]>;
1020
+ createEventDestination(input: CreateEventDestinationInput): Promise<EventDestination>;
1021
+ updateEventDestination(destinationId: string, input: UpdateEventDestinationInput): Promise<EventDestination>;
1022
+ deleteEventDestination(destinationId: string): Promise<void>;
1023
+ rotateEventDestinationSecret(destinationId: string): Promise<EventDestination>;
1024
+ /** Readable whenever needed; rotating replaces it. */
1025
+ getEventDestinationSecret(destinationId: string): Promise<string>;
1026
+ getEventDeliveries(destinationId: string, limit?: number): Promise<EventDelivery[]>;
1027
+ retryEventDelivery(destinationId: string, deliveryId: string): Promise<EventDelivery>;
889
1028
  }
890
1029
  declare function createApiClient(siteToken: string, apiUrl?: string): AifeaturesApiClient;
891
1030
 
@@ -1298,6 +1437,102 @@ interface LeadsViewProps {
1298
1437
  */
1299
1438
  declare function LeadsView({ refreshKey, onBackToWebsite, className, }: LeadsViewProps): react_jsx_runtime.JSX.Element;
1300
1439
 
1440
+ interface SubscriptionsViewProps {
1441
+ /**
1442
+ * Bump to refetch (view data freshness, plan D11) — the host increments it
1443
+ * when a turn's tools changed business data.
1444
+ */
1445
+ refreshKey?: number;
1446
+ /** Host-app callback that swaps the panel back to the website preview (plan D13). */
1447
+ onBackToWebsite?: () => void;
1448
+ className?: string;
1449
+ }
1450
+ /**
1451
+ * SubscriptionsView — the merchant view the AI swaps in for "show me my
1452
+ * subscriptions" (subscriptions plan Unit 12). A read-only projection of the
1453
+ * mirror rows: no cancel button lives here on purpose — cancel is an
1454
+ * org-key-only endpoint proxied through the host app, and a browser-held site
1455
+ * token must not be able to end a customer's billing. Ephemeral by design
1456
+ * (plan D12): it mounts at first-page state and keeps nothing across swaps.
1457
+ *
1458
+ * No revenue tiles: one site's subscriptions can mix currencies, and a sum
1459
+ * across them would be a guess. Rows only; is_test rows are badged.
1460
+ */
1461
+ declare function SubscriptionsView({ refreshKey, onBackToWebsite, className, }: SubscriptionsViewProps): react_jsx_runtime.JSX.Element;
1462
+
1463
+ interface WebhookSettingsProps {
1464
+ /**
1465
+ * The form these webhooks are attached to.
1466
+ *
1467
+ * Required today because the API requires `form_id` on create, which is
1468
+ * true only while every topic is a form topic. When payments topics land
1469
+ * (order.paid and friends have no form), that requirement relaxes and this
1470
+ * becomes optional in the same change — see the note on the component.
1471
+ */
1472
+ formId: string;
1473
+ /**
1474
+ * Topics new webhooks subscribe to. Defaults to `['*']` — everything,
1475
+ * including topics added later.
1476
+ *
1477
+ * This is the knob that makes the component context-scoped rather than
1478
+ * form-specific: a payments surface mounts the same component with payment
1479
+ * topics, and the merchant sees "webhooks for this thing" wherever they
1480
+ * already are.
1481
+ */
1482
+ topics?: string[];
1483
+ /** Blurb above the list. Defaults to the form wording. */
1484
+ description?: string;
1485
+ className?: string;
1486
+ }
1487
+ /**
1488
+ * Webhook management, scoped to whatever context it is mounted in.
1489
+ *
1490
+ * The API calls these "event destinations"; this surface says "Webhooks",
1491
+ * which is the word a merchant connecting Zapier or Make already has.
1492
+ *
1493
+ * NOT a forms component. Webhooks carry every kind of event we emit; showing
1494
+ * them inside a form's settings is a way of SCOPING them to the context the
1495
+ * merchant is already thinking in, not a statement about what they can carry.
1496
+ * A payments surface mounts this same component with payment topics.
1497
+ *
1498
+ * There is deliberately no "all webhooks" screen. Offering one would ask
1499
+ * every merchant to choose between scopes that are the same thing for them —
1500
+ * the typical site has a single form — so each mounting stays contextual.
1501
+ *
1502
+ * Two things here are load-bearing rather than decorative:
1503
+ *
1504
+ * - Adding a webhook is not an event. The row simply appears; there is no
1505
+ * dialog to dismiss, because there is nothing the merchant must do next.
1506
+ * The signing secret is OPTIONAL and re-readable, fetched only when
1507
+ * someone opens its panel, so it never becomes a copy-it-now task imposed
1508
+ * on people who will never verify a signature.
1509
+ * - A destination that failed repeatedly is auto-disabled by the backend.
1510
+ * That state has to be visible and self-serviceable, or the first a
1511
+ * merchant hears of it is a customer asking why leads stopped arriving.
1512
+ */
1513
+ declare function WebhookSettings({ formId, topics, description, className, }: WebhookSettingsProps): react_jsx_runtime.JSX.Element;
1514
+
1515
+ interface WebhookDeliveriesProps {
1516
+ destinationId: string;
1517
+ /** How many rows to load. The API caps this at 100. */
1518
+ limit?: number;
1519
+ className?: string;
1520
+ }
1521
+ /**
1522
+ * The delivery log for one webhook: what we sent, when, and what came back.
1523
+ *
1524
+ * This is the answer to the only two questions a merchant ever asks about a
1525
+ * webhook — "did it fire?" and "why didn't it work?" — and it is why the
1526
+ * backend materialises one row per destination per event rather than one row
1527
+ * per event. Without it the merchant's only recourse is to ask support, and
1528
+ * support's only recourse is to read Workers logs.
1529
+ *
1530
+ * Retry re-sends the STORED bytes, so the consumer sees the same webhook-id
1531
+ * and can deduplicate. That also means a retry is safe to offer for rows that
1532
+ * already delivered — replaying into a rebuilt consumer is a real use.
1533
+ */
1534
+ declare function WebhookDeliveries({ destinationId, limit, className, }: WebhookDeliveriesProps): react_jsx_runtime.JSX.Element;
1535
+
1301
1536
  interface UseFormsReturn {
1302
1537
  forms: Form[];
1303
1538
  isLoading: boolean;
@@ -1501,6 +1736,56 @@ interface UsePersonReturn {
1501
1736
  */
1502
1737
  declare function usePerson(email: string | null, { refreshKey }?: UsePersonOptions): UsePersonReturn;
1503
1738
 
1739
+ interface UseSubscriptionsReturn {
1740
+ subscriptions: Subscription[];
1741
+ total: number;
1742
+ isLoading: boolean;
1743
+ error: Error | null;
1744
+ page: number;
1745
+ pageSize: number;
1746
+ hasNextPage: boolean;
1747
+ hasPreviousPage: boolean;
1748
+ setPage: (page: number) => void;
1749
+ setPageSize: (size: number) => void;
1750
+ /**
1751
+ * Exact-status filter, sent server-side (verbatim Stripe values — the API
1752
+ * stores whatever Stripe said). Undefined = all statuses. Resets to the
1753
+ * first page.
1754
+ */
1755
+ status: string | undefined;
1756
+ setStatus: (status: string | undefined) => void;
1757
+ refetch: () => Promise<void>;
1758
+ }
1759
+ interface UseSubscriptionsOptions {
1760
+ initialPageSize?: number;
1761
+ /**
1762
+ * Bump to force a refetch with the current filters (view data freshness,
1763
+ * plan D11) — the host increments it when a turn's tools changed business
1764
+ * data. Optional and additive; leaving it undefined changes nothing.
1765
+ */
1766
+ refreshKey?: number;
1767
+ }
1768
+ /**
1769
+ * The site's subscription mirror rows, newest first — offset paging against
1770
+ * the server total (same shape as useOrders; the endpoint reports `total`, so
1771
+ * hasNextPage counts against it rather than guessing from page fullness).
1772
+ */
1773
+ declare function useSubscriptions({ initialPageSize, refreshKey, }?: UseSubscriptionsOptions): UseSubscriptionsReturn;
1774
+
1775
+ interface UseEventDestinationsReturn {
1776
+ destinations: EventDestination[];
1777
+ isLoading: boolean;
1778
+ error: Error | null;
1779
+ refetch: () => Promise<void>;
1780
+ createDestination: (input: CreateEventDestinationInput) => Promise<EventDestination>;
1781
+ updateDestination: (destinationId: string, input: UpdateEventDestinationInput) => Promise<EventDestination>;
1782
+ deleteDestination: (destinationId: string) => Promise<void>;
1783
+ rotateSecret: (destinationId: string) => Promise<EventDestination>;
1784
+ /** Read on demand; there is no shown-once moment to catch. */
1785
+ getSecret: (destinationId: string) => Promise<string>;
1786
+ }
1787
+ declare function useEventDestinations(): UseEventDestinationsReturn;
1788
+
1504
1789
  declare function isZeroDecimalCurrency(currency: string): boolean;
1505
1790
  /**
1506
1791
  * Format a minor-unit amount for display ("$29.00", "¥1,500").
@@ -1543,4 +1828,4 @@ declare function toMinorUnits(major: string | number, currency: string): number
1543
1828
  */
1544
1829
  declare function toMajorUnits(minor: number, currency: string): number;
1545
1830
 
1546
- export { type AdjustInventoryInput, type AifeaturesApiClient, AifeaturesApiError, type AifeaturesContextValue, AifeaturesProvider, type AifeaturesProviderProps, type ApiError, type Attachment, type BusinessSummary, type CreateFormInput, type CreateOptionInput, type CreateProductInput, type CreateVariantInput, type Customer, type CustomerAddress, CustomerDetail, type CustomerDetail$1 as CustomerDetailData, type CustomerDetailProps, CustomersList, type CustomersListProps, type CustomersListResponse, type EmailSideStatus, type Form, FormSettings, type FormSettingsProps, FormSubmissions, type FormSubmissionsProps, FormsDashboard, type FormsDashboardProps, FormsList, type FormsListProps, type FormsListResponse, type GetBusinessSummaryOptions, type GetCustomersOptions, type GetOrdersOptions, type GetPeopleOptions, type GetProductsOptions, type GetSubmissionsOptions, LeadsView, type LeadsViewProps, type LowStockProduct, type NeedsAttentionItem, type NeedsAttentionType, type Order, OrderDetail, type OrderDetailProps, type OrderStatus, OrderStatusBadge, OrdersList, type OrdersListProps, OrdersView, type OrdersViewProps, type PaginatedOrders, type PaginatedSubmissions, PaymentsDashboard, type PaymentsDashboardProps, PaymentsSetup, type PaymentsSetupProps, type PaymentsStatus, type PaymentsStatusReason, type PaymentsStatusResponse, type PeopleListResponse, type Person, type PersonDetail, type PersonOrder, type PersonSource, type PersonSubmission, type Product, type ProductDetail, type ProductFulfillment, type ProductFulfillmentType, type ProductOption, ProductSettings, type ProductSettingsProps, type ProductStats, type ProductVariant, ProductsList, type ProductsListProps, type ProductsListResponse, ProductsView, type ProductsViewProps, type RefundRequest, type RevenueCurrencyTotal, type RevenuePeriod, type SetInventoryInput, type SetOrderFulfillmentInput, type SettledRevenue, type Submission, SubmissionDetail, type SubmissionDetailProps, type SubmissionMetadata, type UpdateFormInput, type UpdateOptionInput, type UpdateProductInput, type UpdateVariantInput, type UseBusinessSummaryOptions, type UseBusinessSummaryReturn, type UseCustomersOptions, type UseCustomersReturn, type UseFormsReturn, type UseOrdersOptions, type UseOrdersReturn, type UsePaymentsStatusReturn, type UsePeopleOptions, type UsePeopleReturn, type UsePersonOptions, type UsePersonReturn, type UseProductsOptions, type UseProductsReturn, type UseSubmissionsOptions, type UseSubmissionsReturn, type VariantInventory, type VariantOptionValue, VariantsEditor, type VariantsEditorProps, ViewShell, type ViewShellProps, chargedTotal, createApiClient, formatPrice, isZeroDecimalCurrency, toMajorUnits, toMinorUnits, useAifeaturesContext as useAifeatures, useAifeaturesContext, useBusinessSummary, useCustomers, useForms, useOrders, usePaymentsStatus, usePeople, usePerson, useProducts, useSubmissions };
1831
+ export { type AdjustInventoryInput, type AifeaturesApiClient, AifeaturesApiError, type AifeaturesContextValue, AifeaturesProvider, type AifeaturesProviderProps, type ApiError, type Attachment, type BusinessSummary, type CreateEventDestinationInput, type CreateFormInput, type CreateOptionInput, type CreateProductInput, type CreateVariantInput, type Customer, type CustomerAddress, CustomerDetail, type CustomerDetail$1 as CustomerDetailData, type CustomerDetailProps, CustomersList, type CustomersListProps, type CustomersListResponse, type EmailSideStatus, type EventDeliveriesListResponse, type EventDelivery, type EventDestination, type EventDestinationSecretResponse, type EventDestinationsListResponse, type Form, FormSettings, type FormSettingsProps, FormSubmissions, type FormSubmissionsProps, FormsDashboard, type FormsDashboardProps, FormsList, type FormsListProps, type FormsListResponse, type GetBusinessSummaryOptions, type GetCustomersOptions, type GetOrdersOptions, type GetPeopleOptions, type GetProductsOptions, type GetSubmissionsOptions, type GetSubscriptionsOptions, LeadsView, type LeadsViewProps, type LowStockProduct, type NeedsAttentionItem, type NeedsAttentionType, type Order, OrderDetail, type OrderDetailProps, type OrderStatus, OrderStatusBadge, OrdersList, type OrdersListProps, OrdersView, type OrdersViewProps, type PaginatedOrders, type PaginatedSubmissions, type PaginatedSubscriptions, PaymentsDashboard, type PaymentsDashboardProps, PaymentsSetup, type PaymentsSetupProps, type PaymentsStatus, type PaymentsStatusReason, type PaymentsStatusResponse, type PeopleListResponse, type Person, type PersonDetail, type PersonOrder, type PersonSource, type PersonSubmission, type Product, type ProductDetail, type ProductFulfillment, type ProductFulfillmentType, type ProductOption, ProductSettings, type ProductSettingsProps, type ProductStats, type ProductVariant, ProductsList, type ProductsListProps, type ProductsListResponse, ProductsView, type ProductsViewProps, type RefundRequest, type RevenueCurrencyTotal, type RevenuePeriod, type SetInventoryInput, type SetOrderFulfillmentInput, type SettledRevenue, type Submission, SubmissionDetail, type SubmissionDetailProps, type SubmissionMetadata, type Subscription, SubscriptionsView, type SubscriptionsViewProps, type UpdateEventDestinationInput, type UpdateFormInput, type UpdateOptionInput, type UpdateProductInput, type UpdateVariantInput, type UseBusinessSummaryOptions, type UseBusinessSummaryReturn, type UseCustomersOptions, type UseCustomersReturn, type UseEventDestinationsReturn, type UseFormsReturn, type UseOrdersOptions, type UseOrdersReturn, type UsePaymentsStatusReturn, type UsePeopleOptions, type UsePeopleReturn, type UsePersonOptions, type UsePersonReturn, type UseProductsOptions, type UseProductsReturn, type UseSubmissionsOptions, type UseSubmissionsReturn, type UseSubscriptionsOptions, type UseSubscriptionsReturn, type VariantInventory, type VariantOptionValue, VariantsEditor, type VariantsEditorProps, ViewShell, type ViewShellProps, WebhookDeliveries, type WebhookDeliveriesProps, WebhookSettings, type WebhookSettingsProps, chargedTotal, createApiClient, formatPrice, isZeroDecimalCurrency, toMajorUnits, toMinorUnits, useAifeaturesContext as useAifeatures, useAifeaturesContext, useBusinessSummary, useCustomers, useEventDestinations, useForms, useOrders, usePaymentsStatus, usePeople, usePerson, useProducts, useSubmissions, useSubscriptions };