@locale-labs/miniapp-sdk 0.1.0 → 0.1.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/sdk.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { UserPayload, LocationPayload, AlertButton, LocationPickerOptions } from "@locale-labs/protocol";
2
+ export type { AlertButton };
3
+ export interface AlertButtonWithAction extends AlertButton {
4
+ onPress?: () => void;
5
+ }
6
+ /**
7
+ * Localé Mini-App SDK
8
+ *
9
+ * Provides a bridge for Mini-Apps running in sandboxed iframes
10
+ * to communicate with the Localé Kernel via postMessage protocol.
11
+ *
12
+ * @example
13
+ * ```javascript
14
+ * const app = new LocaleApp();
15
+ * const { user, location, token } = await app.init();
16
+ * app.enableAutoScrollSync();
17
+ * ```
18
+ */
19
+ export interface AlertButtonWithAction extends AlertButton {
20
+ onPress?: () => void;
21
+ }
22
+ export type PickLocationOptions = LocationPickerOptions;
23
+ export interface InitResult {
24
+ user: UserPayload | null;
25
+ location: LocationPayload | null;
26
+ token: string | null;
27
+ }
28
+ export interface LocaleAppConfig {
29
+ /**
30
+ * The origin of the Kernel (parent window).
31
+ * Used for security validation of postMessage.
32
+ * Defaults to '*' in development, but should be set in production.
33
+ */
34
+ kernelOrigin?: string;
35
+ }
36
+ interface SupabaseClient {
37
+ auth: {
38
+ setSession: (params: {
39
+ access_token: string;
40
+ refresh_token: string;
41
+ }) => Promise<{
42
+ error: Error | null;
43
+ }>;
44
+ };
45
+ }
46
+ declare class LocaleApp {
47
+ private requestId;
48
+ private requests;
49
+ private kernelOrigin;
50
+ private _lastScrollY;
51
+ private _lastReportedDirection;
52
+ private _scrollListener;
53
+ private debugEnabled;
54
+ constructor(config?: LocaleAppConfig);
55
+ /**
56
+ * Logs a message if debug mode is enabled
57
+ */
58
+ private _log;
59
+ /**
60
+ * Internal method to send messages to the Kernel
61
+ * @param type - Message type identifier
62
+ * @param payload - Data to send with the message
63
+ * @returns Promise that resolves with the Kernel's response
64
+ */
65
+ private _send;
66
+ /**
67
+ * Initializes the SDK and fetches all necessary context in parallel.
68
+ * This is the recommended way to start your Mini-App.
69
+ *
70
+ * @returns Promise with user, location, and auth token
71
+ */
72
+ init(): Promise<InitResult>;
73
+ /**
74
+ * Automatically handles scroll detection to hide/show the Kernel's header.
75
+ * Call this once when your app starts if you want this behavior.
76
+ *
77
+ * @param threshold - Minimum scroll pixels before triggering (default: 50)
78
+ * @param delta - Minimum scroll change before triggering (default: 10)
79
+ */
80
+ enableAutoScrollSync(threshold?: number, delta?: number): void;
81
+ /**
82
+ * Get the current authenticated user info (public profile)
83
+ * @returns Promise with user data including id, email, place_id, etc.
84
+ */
85
+ getUser(): Promise<unknown>;
86
+ /**
87
+ * Get a signed JWT token asserting the user's identity.
88
+ * This token can be used to authenticate with the Mini App's backend.
89
+ * @returns Promise with { token: string }
90
+ */
91
+ getAuthToken(): Promise<{
92
+ token: string;
93
+ }>;
94
+ /**
95
+ * Automatically connects the Supabase Client with the current Localé User
96
+ * using the signed Auth Token.
97
+ * @param supabaseClient - The Supabase Client instance
98
+ * @returns Promise with { token: string }
99
+ */
100
+ connectSupabase(supabaseClient: SupabaseClient): Promise<{
101
+ token: string;
102
+ }>;
103
+ /**
104
+ * Get the current user's location context from Localé
105
+ * @returns Promise with location data (city, coords, etc.)
106
+ */
107
+ getLocation(): Promise<unknown>;
108
+ /**
109
+ * Show a native alert/modal via the Kernel (similar to React Native Alert)
110
+ * @param title - Modal title
111
+ * @param message - Optional message
112
+ * @param buttons - Array of buttons (if empty, shows "OK")
113
+ * @param options - Alert options (cancelable, onDismiss)
114
+ */
115
+ alert(title: string, message?: string, buttons?: AlertButtonWithAction[], options?: {
116
+ cancelable?: boolean;
117
+ onDismiss?: () => void;
118
+ }): Promise<void>;
119
+ /**
120
+ * Opens the native location picker UI from Localé Kernel
121
+ * Shows a fullscreen map where the user can tap to select a location
122
+ *
123
+ * @param options - Configuration options for the map (e.g. readonly mode, initial coordinates)
124
+ * @returns Promise with selected coordinates { lat, lng } or null if cancelled
125
+ */
126
+ pickLocation(options?: PickLocationOptions): Promise<{
127
+ lat: number;
128
+ lng: number;
129
+ } | null>;
130
+ /**
131
+ * Reports the scroll direction to the Kernel, allowing the parent app
132
+ * to hide/show UI elements based on scroll behavior.
133
+ *
134
+ * @param direction - 'up' to show header, 'down' to hide header
135
+ */
136
+ reportScrollDirection(direction: "up" | "down"): void;
137
+ /**
138
+ * Requests the Kernel to initiate the login flow.
139
+ * The Kernel will save the current URL and redirect to the login page.
140
+ *
141
+ * @param intendedView - Optional view to navigate to after login (e.g., 'create', 'my-posts')
142
+ * This will be appended to the URL hash as #view=... so the mini-app can read it on load.
143
+ */
144
+ login(intendedView?: string): Promise<void>;
145
+ /**
146
+ * Updates the parent window's URL path.
147
+ * Useful for deep linking within the Mini-App using clean URLs.
148
+ * Example: If app is at /mascotas-perdidas, updateUrlPath('ABC-123')
149
+ * makes it /mascotas-perdidas/ABC-123
150
+ *
151
+ * @param slug - The slug or path segment to append/replace
152
+ */
153
+ updateUrlPath(slug: string): Promise<void>;
154
+ }
155
+ declare global {
156
+ interface Window {
157
+ LocaleApp: typeof LocaleApp;
158
+ }
159
+ }
160
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,eAAe,EAEf,WAAW,EACX,qBAAqB,EAKtB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AAMH,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,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7B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;OAMG;IACG,KAAK,CACT,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,EAAE,EACjC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,GACzD,OAAO,CAAC,IAAI,CAAC;IA2ChB;;;;;;OAMG;IACG,YAAY,CAChB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAQ/C;;;;;OAKG;IACH,qBAAqB,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;IAMrD;;;;;;OAMG;IACG,KAAK,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD;;;;;;;OAOG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjD;AAOD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,EAAE,OAAO,SAAS,CAAC;KAC7B;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@locale-labs/miniapp-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SDK for Localé Mini-Apps - Bridge between Mini-Apps and the Localé Kernel",
5
5
  "main": "dist/sdk.js",
6
6
  "types": "dist/sdk.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "esbuild src/sdk.ts --bundle --minify --format=iife --target=es2020 --outfile=dist/sdk.js",
11
+ "build": "bun run build:types && esbuild src/sdk.ts --bundle --minify --format=iife --target=es2020 --outfile=dist/sdk.js",
12
12
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist"
13
13
  },
14
14
  "dependencies": {