@tagadapay/headless-sdk 1.8.0-rc.0 → 1.8.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.
Files changed (66) hide show
  1. package/README.md +216 -1
  2. package/dist/core/client.d.ts +68 -0
  3. package/dist/core/client.js +71 -0
  4. package/dist/core/errors.d.ts +46 -0
  5. package/dist/core/errors.js +57 -0
  6. package/dist/core/helpers/autocomplete.d.ts +89 -0
  7. package/dist/core/helpers/autocomplete.js +186 -0
  8. package/dist/core/helpers/countries.d.ts +45 -0
  9. package/dist/core/helpers/countries.js +65 -0
  10. package/dist/core/helpers/currency.d.ts +26 -0
  11. package/dist/core/helpers/currency.js +72 -0
  12. package/dist/core/helpers/index.d.ts +5 -0
  13. package/dist/core/helpers/index.js +5 -0
  14. package/dist/core/helpers/iso3166.d.ts +28 -0
  15. package/dist/core/helpers/iso3166.js +84 -0
  16. package/dist/core/http.d.ts +27 -0
  17. package/dist/core/http.js +116 -0
  18. package/dist/core/index.d.ts +15 -0
  19. package/dist/core/index.js +13 -0
  20. package/dist/core/modules/catalog.d.ts +27 -0
  21. package/dist/core/modules/catalog.js +38 -0
  22. package/dist/core/modules/checkout.d.ts +268 -0
  23. package/dist/core/modules/checkout.js +470 -0
  24. package/dist/core/modules/customer.d.ts +33 -0
  25. package/dist/core/modules/customer.js +53 -0
  26. package/dist/core/modules/funnel.d.ts +38 -0
  27. package/dist/core/modules/funnel.js +138 -0
  28. package/dist/core/modules/offers.d.ts +137 -0
  29. package/dist/core/modules/offers.js +141 -0
  30. package/dist/core/modules/payment.d.ts +298 -0
  31. package/dist/core/modules/payment.js +701 -0
  32. package/dist/core/modules/rx.d.ts +162 -0
  33. package/dist/core/modules/rx.js +46 -0
  34. package/dist/core/types.d.ts +505 -0
  35. package/dist/core/types.js +5 -0
  36. package/dist/react/hooks/useCatalog.d.ts +25 -0
  37. package/dist/react/hooks/useCatalog.js +58 -0
  38. package/dist/react/hooks/useCheckout.d.ts +58 -0
  39. package/dist/react/hooks/useCheckout.js +177 -0
  40. package/dist/react/hooks/useCustomer.d.ts +28 -0
  41. package/dist/react/hooks/useCustomer.js +77 -0
  42. package/dist/react/hooks/useGoogleAutocomplete.d.ts +26 -0
  43. package/dist/react/hooks/useGoogleAutocomplete.js +70 -0
  44. package/dist/react/hooks/useISOData.d.ts +23 -0
  45. package/dist/react/hooks/useISOData.js +63 -0
  46. package/dist/react/hooks/useOffers.d.ts +134 -0
  47. package/dist/react/hooks/useOffers.js +171 -0
  48. package/dist/react/hooks/usePayment.d.ts +108 -0
  49. package/dist/react/hooks/usePayment.js +233 -0
  50. package/dist/react/hooks/useRx.d.ts +64 -0
  51. package/dist/react/hooks/useRx.js +145 -0
  52. package/dist/react/index.d.ts +22 -0
  53. package/dist/react/index.js +12 -0
  54. package/dist/react/internal/redirectGuard.d.ts +9 -0
  55. package/dist/react/internal/redirectGuard.js +25 -0
  56. package/dist/react/provider.d.ts +31 -0
  57. package/dist/react/provider.js +32 -0
  58. package/dist/stripe/StripeExpressButton.d.ts +30 -0
  59. package/dist/stripe/StripeExpressButton.js +32 -0
  60. package/dist/stripe/StripeExpressCheckout.d.ts +98 -0
  61. package/dist/stripe/StripeExpressCheckout.js +198 -0
  62. package/dist/stripe/index.d.ts +8 -0
  63. package/dist/stripe/index.js +15 -0
  64. package/dist/stripe/useStripeExpress.d.ts +54 -0
  65. package/dist/stripe/useStripeExpress.js +126 -0
  66. package/package.json +2 -3
package/README.md CHANGED
@@ -1 +1,216 @@
1
- test
1
+ # @tagadapay/headless-sdk
2
+
3
+ Use TagadaPay as a **headless checkout and CRM backend** from any website — React, Vue, vanilla JS, or plain HTML. Zero runtime dependencies in core.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @tagadapay/headless-sdk
9
+ # Optional: for card tokenization
10
+ npm install @tagadapay/core-js
11
+ ```
12
+
13
+ ## Quick Start (Vanilla JS)
14
+
15
+ ```typescript
16
+ import { createHeadlessClient } from '@tagadapay/headless-sdk';
17
+
18
+ const tagada = createHeadlessClient({
19
+ storeId: 'store_abc123',
20
+ environment: 'production',
21
+ });
22
+
23
+ // Load checkout session
24
+ const session = await tagada.checkout.loadSession(checkoutToken, sessionToken);
25
+
26
+ // Set customer info (stored in memory, sent with address)
27
+ await tagada.checkout.updateCustomer(session.id, {
28
+ email: 'john@example.com',
29
+ firstName: 'John',
30
+ lastName: 'Doe',
31
+ });
32
+
33
+ // Set address — customer fields are included automatically
34
+ await tagada.checkout.updateAddress(session.id, {
35
+ shippingAddress: { line1: '10 Rue de la Paix', city: 'Paris', postalCode: '75002', country: 'FR' },
36
+ });
37
+
38
+ // Tokenize card + pay with automatic 3DS / redirect handling
39
+ const { tagadaToken } = await tagada.payment.tokenizeCard({
40
+ cardNumber: '4242424242424242',
41
+ expiryDate: '12/28',
42
+ cvc: '123',
43
+ });
44
+
45
+ const result = await tagada.payment.processPayment({
46
+ checkoutSessionId: session.id,
47
+ tagadaToken,
48
+ });
49
+
50
+ if (result.status === 'succeeded') {
51
+ console.log('Payment succeeded!', result.order);
52
+ } else if (result.status === 'requires_redirect') {
53
+ // SDK handles this automatically in React; in vanilla JS, redirect manually:
54
+ window.location.href = result.redirectUrl;
55
+ } else if (result.status === 'failed') {
56
+ console.error(result.error);
57
+ }
58
+ ```
59
+
60
+ ## Quick Start (React)
61
+
62
+ ```tsx
63
+ import { TagadaHeadlessProvider, useCheckout, usePayment } from '@tagadapay/headless-sdk/react';
64
+
65
+ function App() {
66
+ return (
67
+ <TagadaHeadlessProvider storeId="store_abc123" environment="production">
68
+ <CheckoutPage />
69
+ </TagadaHeadlessProvider>
70
+ );
71
+ }
72
+
73
+ function CheckoutPage() {
74
+ const { session, updateCustomer, updateAddress } = useCheckout(checkoutToken, sessionToken);
75
+ const { processPayment, isProcessing, tokenizeCard } = usePayment({
76
+ onPaymentSuccess: (result) => router.push('/thank-you'),
77
+ onPaymentFailed: (result) => alert(result.error),
78
+ });
79
+
80
+ const handlePay = async () => {
81
+ // Customer + address (single atomic API call under the hood)
82
+ await updateCustomer({ email, firstName, lastName });
83
+ await updateAddress({ shippingAddress: { line1, city, postalCode, country } });
84
+
85
+ // Tokenize + pay — 3DS redirects and polling are handled automatically
86
+ const { tagadaToken } = await tokenizeCard({ cardNumber, expiryDate, cvc });
87
+ await processPayment({ checkoutSessionId: session.id, tagadaToken });
88
+ // onPaymentSuccess / onPaymentFailed callbacks fire automatically
89
+ };
90
+
91
+ return <button onClick={handlePay} disabled={isProcessing}>Pay Now</button>;
92
+ }
93
+ ```
94
+
95
+ ## Payment Flow
96
+
97
+ `processPayment()` handles the full payment lifecycle automatically:
98
+
99
+ 1. **Tokenize** → creates a payment instrument from the card
100
+ 2. **Pay** → submits payment to the processor
101
+ 3. **3DS / Redirect** → if the bank requires authentication, the SDK redirects the user and resumes automatically on return
102
+ 4. **Poll** → waits for async processing to complete
103
+ 5. **Result** → returns a typed `ProcessPaymentResult`
104
+
105
+ The return type is a discriminated union:
106
+
107
+ | Status | Meaning |
108
+ |--------|---------|
109
+ | `succeeded` | Payment confirmed. Show success screen. |
110
+ | `requires_redirect` | User must visit a URL (3DS, bank auth). Auto-handled in React. |
111
+ | `failed` | Payment declined or errored. `result.error` has details. |
112
+ | `pending` | Still processing (rare — polling timed out). |
113
+
114
+ ## Address Handling
115
+
116
+ The SDK handles both **shipped** and **digital** products:
117
+
118
+ ```typescript
119
+ // Shipped product — billing defaults to shipping
120
+ await tagada.checkout.updateAddress(sessionId, {
121
+ shippingAddress: { line1: '...', city: '...', country: 'FR' },
122
+ });
123
+
124
+ // Digital product — billing only, no shipping needed
125
+ await tagada.checkout.updateAddress(sessionId, {
126
+ billingAddress: { country: 'FR' },
127
+ });
128
+
129
+ // Separate billing and shipping
130
+ await tagada.checkout.updateAddress(sessionId, {
131
+ shippingAddress: { line1: '...', city: '...', country: 'FR' },
132
+ billingAddress: { line1: '...', city: '...', country: 'DE' },
133
+ });
134
+
135
+ // Or use the combined method
136
+ await tagada.checkout.updateCustomerAndAddress(sessionId, {
137
+ customer: { email: 'john@example.com', firstName: 'John', lastName: 'Doe' },
138
+ shippingAddress: { line1: '...', city: '...', country: 'FR' },
139
+ });
140
+ ```
141
+
142
+ ## Funnel Navigation
143
+
144
+ Send a shopper into a TagadaPay funnel using the cart from the loaded checkout
145
+ session — same flow as the WooCommerce / Shopify plugins, in one call.
146
+
147
+ ```typescript
148
+ const tagada = createHeadlessClient({
149
+ storeId: 'store_abc123',
150
+ accountId: 'acc_abc123', // required for funnel.navigate()
151
+ environment: 'production',
152
+ });
153
+
154
+ // Load (or create) a checkout session so the SDK has a cart.
155
+ await tagada.checkout.loadSession(checkoutToken, sessionToken);
156
+
157
+ // Get a funnel URL — caller decides how to redirect (SPA-friendly).
158
+ const { url } = await tagada.funnel.navigate({
159
+ funnelId: 'fnlv2_abc123',
160
+ stepId: 'step_abc123',
161
+ returnUrl: 'https://merchant.com/thank-you',
162
+ });
163
+
164
+ window.location.assign(url);
165
+ ```
166
+
167
+ `funnel.navigate()` bootstraps an anonymous CMS session on first call and
168
+ caches it for subsequent calls in the same page. The cart, currency, customer
169
+ email, and promotion code are sourced from the loaded `CheckoutSession`.
170
+
171
+ ## Modules
172
+
173
+ | Module | What it does |
174
+ |--------|-------------|
175
+ | `tagada.checkout` | Session management — load, update cart, promo codes, shipping |
176
+ | `tagada.payment` | Full payment lifecycle — APMs, tokenize, 3DS, pay, poll, express checkout |
177
+ | `tagada.offers` | Upsells & order bumps — preview, pay, post-purchase accept/decline |
178
+ | `tagada.customer` | CRM data — profile, orders, subscriptions |
179
+ | `tagada.catalog` | Product browsing — list products, variants, prices |
180
+ | `tagada.funnel` | Funnel navigation — bootstrap session and redirect into a funnel step |
181
+
182
+ ## CDN Usage
183
+
184
+ ```html
185
+ <script src="https://cdn.jsdelivr.net/npm/@tagadapay/headless-sdk/dist/tagada-headless.min.js"></script>
186
+ <script>
187
+ const tagada = TagadaHeadless.create({ storeId: 'store_abc123' });
188
+ </script>
189
+ ```
190
+
191
+ ## Example
192
+
193
+ A complete React checkout app is available as a live demo and open-source reference:
194
+
195
+ - **Live demo**: [headless-react-eta.vercel.app](https://headless-react-eta.vercel.app)
196
+ - **Source code**: [github.com/TagadaPay/examples/tree/main/headless-react](https://github.com/TagadaPay/examples/tree/main/headless-react)
197
+
198
+ ## Architecture
199
+
200
+ - **Zero dependencies** in core — native `fetch`, no axios
201
+ - **Tree-shakeable ESM** — unused modules are eliminated by bundlers
202
+ - **Framework-agnostic core** + thin React hooks layer
203
+ - **TypeScript first** — full type coverage, JSDoc on every method
204
+ - **Optional `@tagadapay/core-js`** peer — only needed for client-side card tokenization
205
+ - **Automatic 3DS** — handles redirects, iframe challenges, and polling out of the box
206
+
207
+ ## Package Exports
208
+
209
+ | Import path | What you get |
210
+ |------------|--------------|
211
+ | `@tagadapay/headless-sdk` | Core client + all modules |
212
+ | `@tagadapay/headless-sdk/react` | React hooks + provider |
213
+
214
+ ## License
215
+
216
+ MIT
@@ -0,0 +1,68 @@
1
+ import { CheckoutModule } from './modules/checkout.js';
2
+ import { PaymentModule } from './modules/payment.js';
3
+ import { OffersModule } from './modules/offers.js';
4
+ import { CustomerModule } from './modules/customer.js';
5
+ import { CatalogModule } from './modules/catalog.js';
6
+ import { FunnelModule } from './modules/funnel.js';
7
+ import { RxModule } from './modules/rx.js';
8
+ import type { HeadlessConfig } from './types.js';
9
+ /**
10
+ * Main entry point for the TagadaPay Headless SDK.
11
+ *
12
+ * Composes all domain modules (checkout, payment, offers, customer, catalog)
13
+ * over a single lightweight HTTP client built on native fetch.
14
+ *
15
+ * **PCI DSS notice:** Card tokenization via `payment.tokenizeCard()` sends
16
+ * card data directly to Basis Theory — it never reaches TagadaPay servers.
17
+ * However, because card data passes through your JavaScript environment,
18
+ * merchants using this SDK are responsible for PCI DSS SAQ-A-EP compliance.
19
+ * See https://docs.tagada.io/developer-tools/headless-sdk/pci-compliance
20
+ */
21
+ export declare class HeadlessClient {
22
+ readonly config: Required<Pick<HeadlessConfig, 'storeId' | 'environment'>> & HeadlessConfig;
23
+ private readonly http;
24
+ /** Shared session token used by all modules for authenticated API calls. */
25
+ private _sessionToken;
26
+ /** Checkout session management -- load, update cart, apply promos, shipping. */
27
+ readonly checkout: CheckoutModule;
28
+ /** Payment processing -- setup config, APMs, tokenize, pay, 3DS, poll. */
29
+ readonly payment: PaymentModule;
30
+ /** Offers -- preview, pay, accept/decline upsells and order bumps. */
31
+ readonly offers: OffersModule;
32
+ /** Customer data -- profile, orders, subscriptions. */
33
+ readonly customer: CustomerModule;
34
+ /** Product catalog -- list products, variants, and prices. */
35
+ readonly catalog: CatalogModule;
36
+ /**
37
+ * Funnel navigation -- bootstrap an anonymous CMS session and produce a
38
+ * redirect URL into a funnel step using the currently loaded checkout cart.
39
+ * Requires `config.accountId`.
40
+ */
41
+ readonly funnel: FunnelModule;
42
+ /**
43
+ * Tagada Rx -- clinical case submission and lookup for telehealth
44
+ * storefronts. Active only on stores whose merchant has paid the
45
+ * Tagada Rx setup fee and configured a clinical network.
46
+ */
47
+ readonly rx: RxModule;
48
+ constructor(config: HeadlessConfig);
49
+ /** Manually set the session token (e.g. from URL params on page load). */
50
+ setSessionToken(token: string): void;
51
+ }
52
+ /**
53
+ * Create a new HeadlessClient instance.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { createHeadlessClient } from '@tagadapay/headless-sdk';
58
+ *
59
+ * const tagada = createHeadlessClient({
60
+ * storeId: 'store_abc123',
61
+ * environment: 'production',
62
+ * });
63
+ *
64
+ * const session = await tagada.checkout.loadSession(checkoutToken);
65
+ * ```
66
+ */
67
+ export declare function createHeadlessClient(config: HeadlessConfig): HeadlessClient;
68
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,71 @@
1
+ import { HttpClient } from './http.js';
2
+ import { CheckoutModule } from './modules/checkout.js';
3
+ import { PaymentModule } from './modules/payment.js';
4
+ import { OffersModule } from './modules/offers.js';
5
+ import { CustomerModule } from './modules/customer.js';
6
+ import { CatalogModule } from './modules/catalog.js';
7
+ import { FunnelModule } from './modules/funnel.js';
8
+ import { RxModule } from './modules/rx.js';
9
+ /**
10
+ * Main entry point for the TagadaPay Headless SDK.
11
+ *
12
+ * Composes all domain modules (checkout, payment, offers, customer, catalog)
13
+ * over a single lightweight HTTP client built on native fetch.
14
+ *
15
+ * **PCI DSS notice:** Card tokenization via `payment.tokenizeCard()` sends
16
+ * card data directly to Basis Theory — it never reaches TagadaPay servers.
17
+ * However, because card data passes through your JavaScript environment,
18
+ * merchants using this SDK are responsible for PCI DSS SAQ-A-EP compliance.
19
+ * See https://docs.tagada.io/developer-tools/headless-sdk/pci-compliance
20
+ */
21
+ export class HeadlessClient {
22
+ constructor(config) {
23
+ const environment = config.environment ?? 'production';
24
+ const baseUrl = HttpClient.resolveBaseUrl(environment, config.baseUrl);
25
+ this.config = {
26
+ ...config,
27
+ environment,
28
+ baseUrl,
29
+ timeout: config.timeout ?? 30000,
30
+ };
31
+ this.http = new HttpClient({
32
+ baseUrl,
33
+ timeout: this.config.timeout,
34
+ apiKey: config.apiKey,
35
+ getToken: () => this._sessionToken,
36
+ });
37
+ const setToken = (token) => {
38
+ this._sessionToken = token;
39
+ };
40
+ this.checkout = new CheckoutModule(this.http, this.config.storeId, setToken);
41
+ this.payment = new PaymentModule(this.http, this.config.storeId, environment);
42
+ this.offers = new OffersModule(this.http, this.config.storeId, this.payment);
43
+ this.customer = new CustomerModule(this.http, this.config.storeId);
44
+ this.catalog = new CatalogModule(this.http, this.config.storeId);
45
+ this.funnel = new FunnelModule(this.http, this.config.storeId, this.checkout, this.config.accountId);
46
+ this.rx = new RxModule(this.http);
47
+ }
48
+ /** Manually set the session token (e.g. from URL params on page load). */
49
+ setSessionToken(token) {
50
+ this._sessionToken = token;
51
+ }
52
+ }
53
+ /**
54
+ * Create a new HeadlessClient instance.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { createHeadlessClient } from '@tagadapay/headless-sdk';
59
+ *
60
+ * const tagada = createHeadlessClient({
61
+ * storeId: 'store_abc123',
62
+ * environment: 'production',
63
+ * });
64
+ *
65
+ * const session = await tagada.checkout.loadSession(checkoutToken);
66
+ * ```
67
+ */
68
+ export function createHeadlessClient(config) {
69
+ return new HeadlessClient(config);
70
+ }
71
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,46 @@
1
+ /** Base error for all TagadaPay headless SDK errors. */
2
+ export declare class TagadaError extends Error {
3
+ readonly code: string;
4
+ readonly statusCode?: number;
5
+ readonly details?: Record<string, unknown>;
6
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
7
+ }
8
+ /** Thrown when the API returns 401/403. */
9
+ export declare class TagadaAuthError extends TagadaError {
10
+ constructor(message?: string);
11
+ }
12
+ /** Thrown when the API returns 422 with validation errors. */
13
+ export declare class TagadaValidationError extends TagadaError {
14
+ readonly errors: Array<{
15
+ field: string;
16
+ message: string;
17
+ }>;
18
+ constructor(message: string, errors?: Array<{
19
+ field: string;
20
+ message: string;
21
+ }>);
22
+ }
23
+ /** Thrown when a resource is not found (404). */
24
+ export declare class TagadaNotFoundError extends TagadaError {
25
+ constructor(resource: string, id: string);
26
+ }
27
+ /** Thrown when the API returns 429. */
28
+ export declare class TagadaRateLimitError extends TagadaError {
29
+ readonly retryAfterMs: number;
30
+ constructor(retryAfterMs?: number);
31
+ }
32
+ /** Thrown when a payment fails or requires action. */
33
+ export declare class TagadaPaymentError extends TagadaError {
34
+ readonly paymentId?: string;
35
+ readonly requireAction?: string;
36
+ constructor(message: string, opts?: {
37
+ paymentId?: string;
38
+ requireAction?: string;
39
+ details?: Record<string, unknown>;
40
+ });
41
+ }
42
+ /** Thrown on network / fetch failures. */
43
+ export declare class TagadaNetworkError extends TagadaError {
44
+ constructor(message?: string);
45
+ }
46
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,57 @@
1
+ /** Base error for all TagadaPay headless SDK errors. */
2
+ export class TagadaError extends Error {
3
+ constructor(message, code, statusCode, details) {
4
+ super(message);
5
+ this.name = 'TagadaError';
6
+ this.code = code;
7
+ this.statusCode = statusCode;
8
+ this.details = details;
9
+ }
10
+ }
11
+ /** Thrown when the API returns 401/403. */
12
+ export class TagadaAuthError extends TagadaError {
13
+ constructor(message = 'Authentication failed. Check your API key or checkout token.') {
14
+ super(message, 'auth_error', 401);
15
+ this.name = 'TagadaAuthError';
16
+ }
17
+ }
18
+ /** Thrown when the API returns 422 with validation errors. */
19
+ export class TagadaValidationError extends TagadaError {
20
+ constructor(message, errors = []) {
21
+ super(message, 'validation_error', 422, { errors });
22
+ this.name = 'TagadaValidationError';
23
+ this.errors = errors;
24
+ }
25
+ }
26
+ /** Thrown when a resource is not found (404). */
27
+ export class TagadaNotFoundError extends TagadaError {
28
+ constructor(resource, id) {
29
+ super(`${resource} "${id}" not found.`, 'not_found', 404);
30
+ this.name = 'TagadaNotFoundError';
31
+ }
32
+ }
33
+ /** Thrown when the API returns 429. */
34
+ export class TagadaRateLimitError extends TagadaError {
35
+ constructor(retryAfterMs = 1000) {
36
+ super(`Rate limited. Retry after ${retryAfterMs}ms.`, 'rate_limit', 429);
37
+ this.name = 'TagadaRateLimitError';
38
+ this.retryAfterMs = retryAfterMs;
39
+ }
40
+ }
41
+ /** Thrown when a payment fails or requires action. */
42
+ export class TagadaPaymentError extends TagadaError {
43
+ constructor(message, opts) {
44
+ super(message, 'payment_error', undefined, opts?.details);
45
+ this.name = 'TagadaPaymentError';
46
+ this.paymentId = opts?.paymentId;
47
+ this.requireAction = opts?.requireAction;
48
+ }
49
+ }
50
+ /** Thrown on network / fetch failures. */
51
+ export class TagadaNetworkError extends TagadaError {
52
+ constructor(message = 'Network request failed. Check your connection.') {
53
+ super(message, 'network_error');
54
+ this.name = 'TagadaNetworkError';
55
+ }
56
+ }
57
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Google Places Autocomplete — script injection + address extraction.
3
+ * Works standalone (no external dependencies beyond the Google Maps JS API).
4
+ */
5
+ declare global {
6
+ interface Window {
7
+ google?: {
8
+ maps?: {
9
+ places?: {
10
+ AutocompleteService: new () => any;
11
+ PlacesService: new (el: any) => any;
12
+ PlacesServiceStatus: {
13
+ OK: string;
14
+ ZERO_RESULTS: string;
15
+ };
16
+ };
17
+ Map: new (el: HTMLElement) => any;
18
+ };
19
+ };
20
+ }
21
+ }
22
+ export interface GooglePrediction {
23
+ place_id: string;
24
+ description: string;
25
+ structured_formatting?: {
26
+ main_text: string;
27
+ secondary_text: string;
28
+ };
29
+ }
30
+ export interface GooglePlaceDetails {
31
+ place_id: string;
32
+ formatted_address: string;
33
+ address_components: Array<{
34
+ long_name: string;
35
+ short_name: string;
36
+ types: string[];
37
+ }>;
38
+ geometry?: {
39
+ location: {
40
+ lat: number;
41
+ lng: number;
42
+ };
43
+ };
44
+ }
45
+ export interface ExtractedAddress {
46
+ subpremise: string;
47
+ streetNumber: string;
48
+ route: string;
49
+ locality: string;
50
+ administrativeAreaLevel1: string;
51
+ administrativeAreaLevel1Long: string;
52
+ administrativeAreaLevel2: string;
53
+ administrativeAreaLevel2Long: string;
54
+ country: string;
55
+ postalCode: string;
56
+ fullStreetAddress: string;
57
+ }
58
+ export interface FormattedAddress {
59
+ address1: string;
60
+ city: string;
61
+ country: string;
62
+ state: string;
63
+ postal: string;
64
+ }
65
+ /**
66
+ * Inject the Google Maps JS SDK into the page (idempotent).
67
+ * Resolves once `window.google.maps.places` is available.
68
+ */
69
+ export declare function loadGoogleMapsScript(apiKey: string, opts?: {
70
+ language?: string;
71
+ region?: string;
72
+ version?: string;
73
+ }): Promise<void>;
74
+ export declare class GoogleAutocompleteCore {
75
+ /** Search for address predictions. */
76
+ static searchPlaces(input: string, options?: {
77
+ types?: string[];
78
+ componentRestrictions?: {
79
+ country: string;
80
+ };
81
+ }): Promise<GooglePrediction[]>;
82
+ /** Get full place details by place_id. */
83
+ static getPlaceDetails(placeId: string): Promise<GooglePlaceDetails | null>;
84
+ /** Extract structured address fields from a Google PlaceDetails result. */
85
+ static extractAddressComponents(place: GooglePlaceDetails): ExtractedAddress;
86
+ /** Shorthand: extract into the flat shape used by address forms. */
87
+ static extractFormattedAddress(place: GooglePlaceDetails): FormattedAddress;
88
+ }
89
+ //# sourceMappingURL=autocomplete.d.ts.map