@cloudparse/up-miniapps-sdk 0.6.6 → 0.6.7

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.js CHANGED
@@ -202,11 +202,61 @@ var Bridge = class {
202
202
  }
203
203
  }
204
204
  /**
205
- * Internal handler for mock message processing, overrideable in test environments
205
+ * Internal handler for mock message processing, overrideable in test environments.
206
+ *
207
+ * Every mini-app that calls a bridge method also has to run standalone in a plain
208
+ * browser (dev, and this vault's own Chrome-based verification) with no native shell
209
+ * attached — `isNative()` is false, so `send()` never round-trips through the real
210
+ * host at all. Before this switch existed, EVERY unhandled type here resolved with
211
+ * plain `undefined` (see the `default` branch below), which silently broke any caller
212
+ * checking a result shape like `{success: boolean}` — `undefined?.success` reads as
213
+ * `false`, not "no answer", so e.g. `sdk.media.saveImage()` looked like a real
214
+ * permission-denied rejection in the browser instead of "there's no native shell
215
+ * here to ask." Add a `case` here — instead of leaving every mini-app to
216
+ * individually special-case "what happens when I call this with no shell attached" —
217
+ * whenever a bridge method's mock behavior should be more than a no-op.
206
218
  */
207
219
  handleMockMessage(type, payload) {
208
- console.warn(`[Bridge] Mock mode active: Unhandled message type ${type}`);
209
- return Promise.resolve();
220
+ switch (type) {
221
+ case "SAVE_IMAGE":
222
+ return this.mockSaveImage(
223
+ payload
224
+ );
225
+ default:
226
+ console.warn(
227
+ `[Bridge] Mock mode active: Unhandled message type ${type}`
228
+ );
229
+ return Promise.resolve();
230
+ }
231
+ }
232
+ /**
233
+ * Standalone-browser stand-in for the native `SAVE_IMAGE` handler: triggers a real
234
+ * browser download (an `<a download>` click) instead of writing to a device photo
235
+ * library, which doesn't exist here. Resolves `{success: true}` on a real trigger so
236
+ * every mini-app's own `result?.success` check gets the same shape/semantics as the
237
+ * real native response — no per-app "am I in mock mode" branching needed. Consumers
238
+ * can still keep their own `catch` fallback for the genuinely different case of a
239
+ * native shell that's missing its WebView bridge (see `sendOnce`'s own rejection
240
+ * path) — that's a real native edge case, not mocking, and this method never runs
241
+ * for it (`send()` only reaches `handleMockMessage` when `!isNative()`).
242
+ */
243
+ mockSaveImage(payload) {
244
+ if (typeof document === "undefined") {
245
+ return Promise.resolve({ success: false });
246
+ }
247
+ try {
248
+ const href = payload.base64.startsWith("data:") ? payload.base64 : `data:image/png;base64,${payload.base64}`;
249
+ const link = document.createElement("a");
250
+ link.href = href;
251
+ link.download = payload.filename ? `${payload.filename}.png` : "image.png";
252
+ document.body.appendChild(link);
253
+ link.click();
254
+ link.remove();
255
+ return Promise.resolve({ success: true });
256
+ } catch (err) {
257
+ console.warn("[Bridge] Mock SAVE_IMAGE download failed:", err);
258
+ return Promise.resolve({ success: false });
259
+ }
210
260
  }
211
261
  sendOnce(type, payload, timeoutMs) {
212
262
  return new Promise((resolve, reject) => {
@@ -3490,7 +3540,7 @@ var loadImage2 = (src) => new Promise((resolve, reject) => {
3490
3540
  });
3491
3541
 
3492
3542
  // package.json
3493
- var version = "0.6.6";
3543
+ var version = "0.6.7";
3494
3544
 
3495
3545
  // src/sdk.ts
3496
3546
  function deepFreeze(obj) {
@@ -4645,7 +4695,10 @@ var RESISTANCE = 0.5;
4645
4695
  var DRAG_DEADZONE = 8;
4646
4696
  var FLING_FRICTION = 0.95;
4647
4697
  var FLING_MIN_VELOCITY = 0.02;
4648
- function DefaultIndicator({ progress, isRefreshing }) {
4698
+ function DefaultIndicator({
4699
+ progress,
4700
+ isRefreshing
4701
+ }) {
4649
4702
  return /* @__PURE__ */ jsxs14(
4650
4703
  "div",
4651
4704
  {