@locale-labs/miniapp-sdk 0.1.0 → 0.1.2

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