@wix/himalaya-cli 0.1304.0 → 0.1305.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/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +1 -1
- package/dist/cli.mjs +80 -26
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/app-config.md +1 -1
- package/guides/web-page-native-sdk.md +71 -10
- package/guides/web-page-sdk-reference.md +50 -637
- package/package.json +2 -2
|
@@ -109,7 +109,7 @@ export function call<T = unknown>(capability: string, method: string, args: unkn
|
|
|
109
109
|
if (!target.post({ v: 1, id, capability, method, args })) {
|
|
110
110
|
clearTimeout(timer);
|
|
111
111
|
pending.delete(id);
|
|
112
|
-
reject(new HimalayaError("The app refused the message
|
|
112
|
+
reject(new HimalayaError("The app's bridge refused the message", "bridge_refused"));
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
}
|
|
@@ -226,7 +226,13 @@ The same page must keep working in an ordinary browser (and in Base44 / Lovable
|
|
|
226
226
|
and hide the UI when it is `false`. `true` only means the method is enabled — still read its
|
|
227
227
|
answer (`availability()` can say `{ available: false }`).
|
|
228
228
|
- **Plain JSON only.** Arguments and results cross as JSON: no functions, `Date` objects (use ISO
|
|
229
|
-
strings), `Blob`s or class instances.
|
|
229
|
+
strings), `Blob`s or class instances.
|
|
230
|
+
- **Keep what you send small.** The app checks every message a page sends and silently drops one
|
|
231
|
+
that breaks a rule — your call then times out. Per call: at most 12 arguments, nested at most
|
|
232
|
+
10 levels deep, 1 MB in total, **each string at most 2,048 characters**, and no strings
|
|
233
|
+
containing `<script`, control characters or bidirectional-override characters. So a page cannot
|
|
234
|
+
pass a long text or a base64 file *into* a call (`files.write`, a large
|
|
235
|
+
`secure_storage.write`); results coming *back* are not limited this way.
|
|
230
236
|
- **Don't flood the bridge.** About 50 messages per second is the ceiling; debounce sliders and
|
|
231
237
|
scroll handlers.
|
|
232
238
|
- **Request/response only.** Methods that return a stream (`AsyncIterable`) or take a callback are
|
|
@@ -242,8 +248,8 @@ Every failure rejects with a `HimalayaError` that has a `code`:
|
|
|
242
248
|
| `code` | Meaning | What to do |
|
|
243
249
|
|---|---|---|
|
|
244
250
|
| `not_in_app` | Ordinary browser or preview, no bridge | Render the browser fallback |
|
|
245
|
-
| `timeout` | No answer: capability or method not enabled for this site,
|
|
246
|
-
| `bridge_refused` |
|
|
251
|
+
| `timeout` | No answer: capability or method not enabled for this site, not on this app build, or the message broke a size rule (see *Keep what you send small*) | Check your arguments; otherwise hide the feature and ask the app owner to enable `capability.method` |
|
|
252
|
+
| `bridge_refused` | The app's bridge refused the message outright | Retry later; send less often |
|
|
247
253
|
| `not_authorized` | The user denied permission | Explain how to enable it in Settings |
|
|
248
254
|
| `unavailable` | Not supported on this device | Hide the feature |
|
|
249
255
|
| `invalid_argument` | Wrong argument shape | Fix the call — check the reference |
|
|
@@ -276,11 +282,66 @@ Codes other than the first three come from the capability itself; its reference
|
|
|
276
282
|
- **On a phone** — open the page inside the app build the owner configured. Check each feature
|
|
277
283
|
once with permission granted and once denied.
|
|
278
284
|
|
|
285
|
+
## More recipes
|
|
286
|
+
|
|
287
|
+
Each uses the client from Step 1. The exact types are on each capability's page (see *Reference*).
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { himalaya, HimalayaError } from "./lib/himalaya";
|
|
291
|
+
|
|
292
|
+
// Share a link through the phone's share sheet (from a tap).
|
|
293
|
+
const { completed } = await himalaya.share.share({ text: "Join me on Friday", url: "https://example.com/e/42" });
|
|
294
|
+
|
|
295
|
+
// Where am I? Ask first, then read once. getCurrent answers null when no fix arrives in time.
|
|
296
|
+
const status = await himalaya.location.requestPermission();
|
|
297
|
+
if (status === "granted") {
|
|
298
|
+
const here = await himalaya.location.getCurrent({ timeoutMs: 10_000 });
|
|
299
|
+
if (here) console.log(here.lat, here.lng, `±${here.accuracy}m`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Keep a small secret on the device (encrypted storage, not localStorage).
|
|
303
|
+
await himalaya.secure_storage.write("refresh-token", "the-token-value");
|
|
304
|
+
const saved = await himalaya.secure_storage.read("refresh-token"); // string | null
|
|
305
|
+
|
|
306
|
+
// Scan a QR code with the camera (iOS). null when the user cancels — and always on Android,
|
|
307
|
+
// which has no built-in QR decoder — so keep a way to type the code in.
|
|
308
|
+
const code = (await himalaya.camera.scanQR()) ?? window.prompt("Enter the code");
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Files arrive as handles.** Methods that return a photo, recording or file give you a
|
|
312
|
+
`FileHandle` (or an object with a device `uri`): a token for a file on the device, not the bytes.
|
|
313
|
+
You cannot put it in an `<img>` directly. Hand it to another call that takes one — share it,
|
|
314
|
+
save it to the photo library:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
const [photo] = await himalaya.photos.pick({ limit: 1 });
|
|
318
|
+
if (photo) await himalaya.share.share({ files: [photo] });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
To get the bytes into the page, read them with the `files` capability (the app owner must enable
|
|
322
|
+
it too). `files.readBase64` returns the contents as base64, up to 8 MiB:
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
const [photo] = await himalaya.photos.pick({ limit: 1 });
|
|
326
|
+
if (photo) {
|
|
327
|
+
const base64 = await himalaya.files.readBase64(photo);
|
|
328
|
+
const img = document.createElement("img");
|
|
329
|
+
img.src = `data:${photo.mimeType};base64,${base64}`;
|
|
330
|
+
document.body.append(img); // or set the src of an <img> your component renders
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
For larger files, or to keep a copy on your server, upload straight from the device with
|
|
335
|
+
`presigned_upload.putFile(url, handle)` and use the uploaded URL. Going the other way, a page
|
|
336
|
+
cannot send large content in: see the size rules below.
|
|
337
|
+
|
|
279
338
|
## Reference
|
|
280
339
|
|
|
281
|
-
- [Web page SDK reference](https://apps.wix.com/_api/himi-serve/docs/web-page-sdk-reference.md) —
|
|
282
|
-
page can call,
|
|
283
|
-
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
340
|
+
- [Web page SDK reference](https://apps.wix.com/_api/himi-serve/docs/web-page-sdk-reference.md) — the
|
|
341
|
+
index: one line per capability a page can call, each linking its own page.
|
|
342
|
+
- Each capability page — `https://apps.wix.com/_api/himi-serve/authoring/resource/web-sdk%2F<capability>?format=md`,
|
|
343
|
+
for example [health](https://apps.wix.com/_api/himi-serve/authoring/resource/web-sdk%2Fhealth?format=md)
|
|
344
|
+
and [haptic](https://apps.wix.com/_api/himi-serve/authoring/resource/web-sdk%2Fhaptic?format=md) —
|
|
345
|
+
lists the callable methods, defines every type they use and the capability's error codes, and
|
|
346
|
+
gives a typed module to save as `src/lib/himalaya-<capability>.ts` next to `himalaya.ts`.
|
|
347
|
+
**Open only the pages for the capabilities your page uses.**
|