@cloudparse/up-miniapps-sdk 0.1.6 → 0.2.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/package.json CHANGED
@@ -1,20 +1,34 @@
1
1
  {
2
2
  "name": "@cloudparse/up-miniapps-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "UP Mini-App SDK for bridge communication between WebView and Host Shell",
5
5
  "author": "CloudParse Team",
6
6
  "license": "MIT",
7
- "main": "./dist/index.js",
8
- "module": "./dist/index.mjs",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
9
10
  "browser": "./dist/index.browser.min.js",
10
11
  "types": "./dist/index.d.ts",
11
12
  "exports": {
12
13
  ".": {
13
14
  "types": "./dist/index.d.ts",
14
- "import": "./dist/index.mjs",
15
- "require": "./dist/index.js",
16
- "default": "./dist/index.mjs"
17
- }
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./host": {
20
+ "types": "./dist/host.d.ts",
21
+ "import": "./dist/host.js",
22
+ "require": "./dist/host.cjs",
23
+ "default": "./dist/host.js"
24
+ },
25
+ "./components/Map": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./style.css": "./dist/style.css"
18
32
  },
19
33
  "publishConfig": {
20
34
  "access": "public"
@@ -23,18 +37,46 @@
23
37
  "dist"
24
38
  ],
25
39
  "scripts": {
26
- "build": "tsc --noEmit && tsup",
40
+ "build": "tsc --noEmit --project tsconfig.json && tsup && npm run build:css",
41
+ "build:css": "npx postcss src/index.css -o dist/style.css",
27
42
  "prebuild": "npm run clean",
28
43
  "clean": "rm -rf dist",
29
- "format": "biome format --write .",
30
- "lint": "biome lint .",
31
- "lint.fix": "biome check --write .",
32
- "prepack": "npm run build"
44
+ "format": "biome format --write . --max-diagnostics 10000 --diagnostic-level error",
45
+ "lint": "biome lint . --max-diagnostics 10000 --diagnostic-level error",
46
+ "lint.fix": "biome check --write . --max-diagnostics 10000 --diagnostic-level error",
47
+ "prepack": "npm run build",
48
+ "storybook": "storybook dev -p 6006",
49
+ "build-storybook": "storybook build"
33
50
  },
34
51
  "devDependencies": {
35
52
  "@biomejs/biome": "^2.4.13",
53
+ "@chromatic-com/storybook": "^5.2.1",
54
+ "@storybook/addon-a11y": "^10.4.2",
55
+ "@storybook/addon-docs": "^10.4.2",
56
+ "@storybook/addon-mcp": "^0.6.0",
57
+ "@storybook/addon-vitest": "^10.4.2",
58
+ "@storybook/react-vite": "^10.4.2",
59
+ "@tailwindcss/postcss": "^4.3.0",
60
+ "@types/geojson": "^7946.0.16",
61
+ "@types/react": "^19.2.16",
62
+ "@types/react-dom": "^19.2.3",
63
+ "@vitest/browser-playwright": "^4.1.8",
64
+ "@vitest/coverage-v8": "^4.1.8",
65
+ "autoprefixer": "^10.5.0",
66
+ "playwright": "^1.60.0",
67
+ "postcss": "^8.5.15",
68
+ "postcss-cli": "^11.0.1",
69
+ "storybook": "^10.4.2",
70
+ "tailwindcss": "^4.3.0",
36
71
  "tsc-alias": "^1.8.8",
37
72
  "tsup": "^8.5.1",
38
- "typescript": "^5.0.0"
73
+ "typescript": "^5.0.0",
74
+ "vitest": "^4.1.8"
75
+ },
76
+ "dependencies": {
77
+ "@vis.gl/react-maplibre": "^8.1.1",
78
+ "maplibre-gl": "^5.24.0",
79
+ "react": "^19.2.7",
80
+ "react-dom": "^19.2.7"
39
81
  }
40
82
  }
package/dist/index.d.mts DELETED
@@ -1,528 +0,0 @@
1
- /**
2
- * UP Mini-App SDK Types
3
- */
4
- /**
5
- * Represents the user's profile information.
6
- */
7
- interface IUserProfile {
8
- /** Unique identifier for the user. */
9
- uuid: string;
10
- /** Full legal name of the user. */
11
- fullName: string;
12
- /** Primary email address. */
13
- email: string;
14
- /** Chosen username within the UP ecosystem. */
15
- username: string;
16
- /** ISO country code (e.g., "FR", "US"). */
17
- countryCode: string;
18
- /** Phone number without country code. */
19
- localNumber: string;
20
- }
21
- /**
22
- * Geographic location data.
23
- */
24
- interface ILocationData {
25
- coords: {
26
- /** Latitude in decimal degrees. */
27
- latitude: number;
28
- /** Longitude in decimal degrees. */
29
- longitude: number;
30
- /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */
31
- altitude: number | null;
32
- /** Accuracy of the latitude and longitude properties in meters. */
33
- accuracy: number | null;
34
- /** Accuracy of the altitude property in meters. */
35
- altitudeAccuracy: number | null;
36
- /** The direction in which the device is traveling, in degrees (0-360). */
37
- heading: number | null;
38
- /** The velocity of the device in meters per second. */
39
- speed: number | null;
40
- };
41
- /** The time at which the location was retrieved (Unix timestamp). */
42
- timestamp: number;
43
- }
44
- /**
45
- * Request payload for triggering a payment flow.
46
- */
47
- interface IPaymentRequest {
48
- /** The specific amount to charge. */
49
- amount: number;
50
- /** ISO currency code (e.g., "EUR", "USD"). */
51
- currency: string;
52
- /** Total amount including taxes/fees. */
53
- total: number;
54
- /** Itemized breakdown of the purchase. */
55
- items: Array<{
56
- /** Name or description of the item. */
57
- item: string;
58
- /** Price per unit. */
59
- price?: number;
60
- /** Number of units. */
61
- quantity?: number;
62
- }>;
63
- }
64
- /**
65
- * Style of haptic feedback.
66
- */
67
- type HapticStyleType = "light" | "medium" | "heavy" | "rigid" | "soft" | "success" | "warning" | "error";
68
- /**
69
- * Network Proxy Types
70
- */
71
- /**
72
- * The HTTP method to use as request method
73
- */
74
- type NetworkMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
75
- /**
76
- * Configuration for network proxy requests.
77
- */
78
- interface INetworkOptions {
79
- /** Full URL for the request. */
80
- url: string;
81
- /** HTTP method to use. */
82
- method: NetworkMethodType;
83
- /** Request body for POST/PUT/PATCH. */
84
- body?: unknown;
85
- /** Custom HTTP headers. */
86
- headers?: Record<string, string>;
87
- }
88
- /**
89
- * Response from a network proxy request.
90
- */
91
- interface INetworkResponse<T = unknown> {
92
- /** HTTP status code. */
93
- status: number;
94
- /** Response data payload. */
95
- data: T;
96
- /** Response headers. */
97
- headers: Headers;
98
- }
99
- /**
100
- * Fidelity & Rewards Types
101
- */
102
- /**
103
- * Fidelity program balance information.
104
- */
105
- interface IFidelityBalance {
106
- /** Current point or currency balance. */
107
- balance: number;
108
- /** Name or symbol of the fidelity currency (e.g., "FPoints"). */
109
- currency: string;
110
- }
111
- /**
112
- * Parameters for retrieving fidelity transaction history.
113
- */
114
- interface IFidelityHistoryParams {
115
- /** Maximum number of records to return. */
116
- limit?: number;
117
- /** Cursor for pagination; null for the first page. */
118
- cursor?: string | null;
119
- }
120
- /** Type of transaction: credit (add) or debit (remove). */
121
- type FidelityTransactionTypeType = "credit" | "debit";
122
- /**
123
- * A single fidelity program transaction.
124
- */
125
- interface IFidelityTransaction {
126
- /** Unique identifier for the transaction. */
127
- id: string;
128
- /** Amount of the transaction. */
129
- amount: number;
130
- /** Human-readable description. */
131
- description: string;
132
- /** ISO 8601 date string. */
133
- date: string;
134
- /** Type of transaction */
135
- type: FidelityTransactionTypeType;
136
- }
137
- /**
138
- * The initialization options required to set up the Mini-App SDK.
139
- */
140
- type IInitializationOptions = {};
141
- /**
142
- * The post initialization response
143
- */
144
- interface IInitializationResponse<Env extends Record<string, unknown> = Record<string, unknown>, UserData extends Record<string, unknown> = Record<string, unknown>, Params extends Record<string, unknown> = Record<string, unknown>> {
145
- /** The name of the mini app */
146
- name: string;
147
- /** The uuid of the mini app */
148
- uuid: string;
149
- /** The description of the mini app */
150
- description: string;
151
- /** The authors of the mini app */
152
- authors?: string;
153
- /** The current version in the registry */
154
- version?: string;
155
- /** The scoped profile based on the requested fields during initialization or the getUserProfile call */
156
- profile: Partial<IUserProfile | null>;
157
- /** The environment variables defined for the mini app in the shell's backend */
158
- env: Env;
159
- /** The user data passed during the initialization or the setUserData call */
160
- userData: UserData;
161
- /** The params passed during the initialization */
162
- params: Params;
163
- }
164
- /**
165
- * Events emitted by the UI module.
166
- */
167
- declare enum UIEvent {
168
- /** Triggered when the user performs a native "Pull-to-Refresh". */
169
- TOP_SCROLL_MORE = "TOP_SCROLL_MORE",
170
- /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */
171
- BOTTOM_SCROLL_MORE = "BOTTOM_SCROLL_MORE"
172
- }
173
- /**
174
- * Union type for all SDK events, allowing for both known enums and custom strings.
175
- * The (string & {}) pattern preserves IntelliSense for enum members.
176
- */
177
- type SDKEvent = UIEvent | (string & {});
178
- /**
179
- * Configuration for native scroll interactions managed by the Host Shell.
180
- */
181
- interface ScrollConfig {
182
- /** Configuration for Pull-to-Refresh (Top). */
183
- topScrollMore?: {
184
- /** Show/hide the native RefreshControl. */
185
- enabled: boolean;
186
- /** Set to true to show the loading spinner, false to hide it. */
187
- refreshing?: boolean;
188
- };
189
- /** Configuration for Infinite Scroll (Bottom). */
190
- bottomScrollMore?: {
191
- /** Enable/disable bottom scroll detection. */
192
- enabled: boolean;
193
- /** If false, detection stops and the indicator is hidden. */
194
- hasMore?: boolean;
195
- /** Set to true to show the bottom ActivityIndicator. */
196
- loadingMore?: boolean;
197
- };
198
- }
199
-
200
- /**
201
- * Main SDK for UP Mini-Apps.
202
- * Provides access to native device features, storage, identity, and shell UI.
203
- */
204
- declare class MiniAppSDK {
205
- private bridge;
206
- /**
207
- * Local SQLite Storage.
208
- * Data is persisted on the device and is isolated per Mini-App.
209
- */
210
- readonly storage: Readonly<{
211
- /** Retrieves a value by key. */
212
- get: (key: string) => Promise<string | null>;
213
- /** Retrieves all key-value pairs stored for this Mini-App. */
214
- getAll: () => Promise<Record<string, string>>;
215
- /** Sets a value for a specific key. */
216
- set: (key: string, value: string) => Promise<void>;
217
- }>;
218
- /**
219
- * Hardware-level Secure Storage.
220
- * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.
221
- */
222
- readonly secureStore: Readonly<{
223
- /** Retrieves a value by key from secure storage. */
224
- get: (key: string) => Promise<string | null>;
225
- /** Sets a value for a specific key in secure storage. */
226
- set: (key: string, value: string) => Promise<void>;
227
- }>;
228
- /**
229
- * Database Storage.
230
- * Access to user-app specific persistent database storage.
231
- */
232
- readonly database: Readonly<{
233
- /** Retrieves the user data stored in the backend database. */
234
- getUserData: <T = unknown>() => Promise<T>;
235
- /** Updates the user data stored in the backend database. */
236
- setUserData: <T = unknown>(data: T) => Promise<void>;
237
- }>;
238
- /**
239
- * Device Location services.
240
- */
241
- readonly location: Readonly<{
242
- /** Retrieves the current GPS position of the device. */
243
- getCurrentPosition: () => Promise<ILocationData>;
244
- }>;
245
- /**
246
- * Identity & Profile management.
247
- */
248
- readonly user: Readonly<{
249
- /**
250
- * Fetch user profile data.
251
- * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).
252
- */
253
- getProfile: <T extends keyof IUserProfile>(fields?: T[]) => Promise<Partial<IUserProfile>>;
254
- }>;
255
- /**
256
- * Explicit Permission Management.
257
- * Allows requesting access to sensitive device features or user data.
258
- */
259
- readonly permission: Readonly<{
260
- /**
261
- * Explicitly request access to sensitive data.
262
- * @param type The type of permission to request ('location' or 'profile').
263
- * @param fields If requesting 'profile', the specific fields required.
264
- */
265
- request: {
266
- (type: "location"): Promise<boolean>;
267
- (type: "profile", fields: (keyof IUserProfile)[]): Promise<boolean>;
268
- };
269
- }>;
270
- /**
271
- * Payments integration.
272
- */
273
- readonly payment: Readonly<{
274
- /**
275
- * Triggers the native payment flow.
276
- * @param payload Amount, currency, and itemized list for the payment.
277
- */
278
- request: (payload: IPaymentRequest) => Promise<{
279
- success: true;
280
- transactionId: string;
281
- }>;
282
- }>;
283
- /**
284
- * Live Activities & Notifications.
285
- * Allows the Mini-App to display real-time updates in the host shell.
286
- */
287
- readonly activity: Readonly<{
288
- /**
289
- * Starts a new live activity.
290
- * @param id Unique identifier for the activity.
291
- * @param title Display title for the activity.
292
- * @param status Initial status message.
293
- */
294
- start: (id: string, title: string, status: string) => Promise<void>;
295
- }>;
296
- /**
297
- * Haptic feedback.
298
- */
299
- readonly haptic: Readonly<{
300
- /**
301
- * Triggers a haptic vibration on the device.
302
- * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').
303
- */
304
- trigger: (style: HapticStyleType) => Promise<void>;
305
- }>;
306
- /**
307
- * Network Proxy.
308
- * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.
309
- */
310
- readonly network: Readonly<{
311
- /**
312
- * Performs a network request via the host shell.
313
- * @param options Request method, URL, headers, and body.
314
- */
315
- request: (options: INetworkOptions) => Promise<INetworkResponse>;
316
- }>;
317
- /**
318
- * Fidelity & Rewards program integration.
319
- */
320
- readonly fidelity: Readonly<{
321
- /** Returns current fidelity balance. */
322
- getFidelityBalance: () => Promise<IFidelityBalance>;
323
- /**
324
- * Retrieves fidelity transaction history.
325
- * @param params Filtering and pagination parameters.
326
- */
327
- getFidelityHistory: (params?: IFidelityHistoryParams) => Promise<IFidelityTransaction[]>;
328
- /**
329
- * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.
330
- * @param intentUuid UUID generated by your backend for the transaction.
331
- */
332
- spendFPoints: (intentUuid: string) => Promise<{
333
- success: boolean;
334
- transactionId: string;
335
- }>;
336
- }>;
337
- /**
338
- * UI and Navigation controls.
339
- */
340
- readonly ui: Readonly<{
341
- /** Closes the Mini-App and returns to the host shell. */
342
- exit: () => Promise<void>;
343
- /**
344
- * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.
345
- * @param config Scroll configuration for top/bottom detection.
346
- */
347
- setScrollConfig: (config: ScrollConfig) => Promise<void>;
348
- }>;
349
- /**
350
- * Debug controls
351
- */
352
- readonly debug: Readonly<{
353
- /**
354
- * Log to the shell app
355
- * @param message
356
- */
357
- log: (...message: unknown[]) => Promise<unknown>;
358
- }>;
359
- constructor();
360
- /**
361
- * The starting point for the Mini-App. Must be called before any other SDK methods.
362
- * @param options The options to provide to the shell app
363
- */
364
- initialize(options: IInitializationOptions): Promise<IInitializationResponse>;
365
- /**
366
- * Registers a callback for a specific event from the native shell.
367
- * @param event The name of the event to listen for.
368
- * @param callback The function to execute when the event is triggered.
369
- * @returns A function to unregister the listener.
370
- */
371
- on(event: SDKEvent, callback: (data: unknown) => void): () => void;
372
- /**
373
- * Unregisters a previously registered event listener.
374
- * @param event The name of the event.
375
- * @param callback The callback function to remove.
376
- */
377
- off(event: SDKEvent, callback: (data: unknown) => void): void;
378
- }
379
- /**
380
- * Singleton instance of the MiniAppSDK.
381
- * Frozen to prevent tampering.
382
- */
383
- declare const sdk: MiniAppSDK;
384
-
385
- /**
386
- * Internal message envelope for bridge communication.
387
- * @internal
388
- */
389
- interface IBridgeEnvelope<P = unknown, V = unknown> {
390
- /** Unique identifier to match responses with requests. */
391
- callbackId?: string;
392
- /** The type/action of the message. */
393
- type?: string;
394
- /** Data payload for the message. */
395
- payload?: P;
396
- /** Whether the operation was successful. */
397
- success?: boolean;
398
- /** Error message if success is false. */
399
- error?: string;
400
- /** The result value for successful operations. */
401
- value?: V;
402
- /** Event name for pushed notifications. */
403
- event?: string;
404
- }
405
- /**
406
- * The messages the bridge can ask for
407
- */
408
- type BridgeMessageType = {
409
- type: "STORAGE_SET";
410
- payload: {
411
- key: string;
412
- value: string;
413
- };
414
- callbackId: string;
415
- } | {
416
- type: "STORAGE_GET";
417
- payload: {
418
- key: string;
419
- };
420
- callbackId: string;
421
- } | {
422
- type: "STORAGE_GET_ALL";
423
- payload?: unknown;
424
- callbackId: string;
425
- } | {
426
- type: "GET_LOCATION";
427
- payload?: unknown;
428
- callbackId: string;
429
- } | {
430
- type: "INITIALIZE";
431
- payload: {
432
- options: IInitializationOptions;
433
- };
434
- callbackId: string;
435
- } | {
436
- type: "DEBUG_LOG";
437
- payload: {
438
- message: unknown[];
439
- };
440
- callbackId: string;
441
- } | {
442
- type: "SECURE_SET";
443
- payload: {
444
- key: string;
445
- value: string;
446
- };
447
- callbackId: string;
448
- } | {
449
- type: "SECURE_GET";
450
- payload: {
451
- key: string;
452
- };
453
- callbackId: string;
454
- } | {
455
- type: "PAYMENT_REQUEST";
456
- payload: unknown;
457
- callbackId: string;
458
- } | {
459
- type: "START_ACTIVITY";
460
- payload: unknown;
461
- callbackId: string;
462
- } | {
463
- type: "GET_USER_PROFILE";
464
- payload?: {
465
- fields?: string[];
466
- };
467
- callbackId: string;
468
- } | {
469
- type: "SPEND_FPOINTS";
470
- payload: {
471
- intentUuid: string;
472
- };
473
- callbackId: string;
474
- } | {
475
- type: "GET_FIDELITY_BALANCE";
476
- payload?: unknown;
477
- callbackId: string;
478
- } | {
479
- type: "GET_FIDELITY_HISTORY";
480
- payload: IFidelityHistoryParams;
481
- callbackId: string;
482
- } | {
483
- type: "EXIT";
484
- payload?: unknown;
485
- callbackId: string;
486
- } | {
487
- type: "DATABASE_GET_USER_DATA";
488
- payload?: unknown;
489
- callbackId: string;
490
- } | {
491
- type: "DATABASE_SET_USER_DATA";
492
- payload: {
493
- data: unknown;
494
- };
495
- callbackId: string;
496
- } | {
497
- type: "REQUEST_PERMISSION";
498
- payload: {
499
- type: "location" | "profile";
500
- fields?: string[];
501
- };
502
- callbackId: string;
503
- } | {
504
- type: "TRIGGER_HAPTIC";
505
- payload?: {
506
- style?: HapticStyleType;
507
- };
508
- callbackId: string;
509
- } | {
510
- type: "NETWORK_REQUEST";
511
- payload: {
512
- url: string;
513
- method?: string;
514
- headers?: Record<string, string>;
515
- body?: unknown;
516
- };
517
- callbackId: string;
518
- } | {
519
- type: "SET_SCROLL_CONFIG";
520
- payload: ScrollConfig;
521
- callbackId: string;
522
- } | {
523
- type: string;
524
- payload: unknown;
525
- callbackId: string;
526
- };
527
-
528
- export { type BridgeMessageType, type FidelityTransactionTypeType, type HapticStyleType, type IBridgeEnvelope, type IFidelityBalance, type IFidelityHistoryParams, type IFidelityTransaction, type IInitializationOptions, type IInitializationResponse, type ILocationData, type INetworkOptions, type INetworkResponse, type IPaymentRequest, type IUserProfile, MiniAppSDK, type NetworkMethodType, type SDKEvent, type ScrollConfig, UIEvent, sdk as default, sdk };