@helix3/helix-sdk 0.1.1-helix3.20
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/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/camera.d.ts +14 -0
- package/dist/camera.js +72 -0
- package/dist/camera.js.map +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +704 -0
- package/dist/index.js.map +1 -0
- package/dist/multiplayer-contract/credential.d.ts +42 -0
- package/dist/multiplayer-contract/credential.js +5 -0
- package/dist/multiplayer-contract/credential.js.map +1 -0
- package/dist/multiplayer-contract/index.d.ts +14 -0
- package/dist/multiplayer-contract/index.js +30 -0
- package/dist/multiplayer-contract/index.js.map +1 -0
- package/dist/multiplayer-contract/messages.d.ts +284 -0
- package/dist/multiplayer-contract/messages.js +111 -0
- package/dist/multiplayer-contract/messages.js.map +1 -0
- package/dist/multiplayer-contract/room.d.ts +126 -0
- package/dist/multiplayer-contract/room.js +17 -0
- package/dist/multiplayer-contract/room.js.map +1 -0
- package/dist/multiplayer-contract/state.d.ts +61 -0
- package/dist/multiplayer-contract/state.js +15 -0
- package/dist/multiplayer-contract/state.js.map +1 -0
- package/dist/multiplayer.d.ts +133 -0
- package/dist/multiplayer.js +334 -0
- package/dist/multiplayer.js.map +1 -0
- package/dist/protocol.d.ts +219 -0
- package/dist/protocol.js +25 -0
- package/dist/protocol.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hypersonic Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @hypersoniclabs/helix-sdk
|
|
2
|
+
|
|
3
|
+
The **HELIX Instant browser SDK** — the runtime a world embeds to talk to the HELIX shell
|
|
4
|
+
(the play page that iframes it). v0.1 provides identity; later versions add multiplayer, voice,
|
|
5
|
+
wallet, and inventory.
|
|
6
|
+
|
|
7
|
+
A world is a static bundle that runs inside a **sandboxed iframe**. The shell hands it a
|
|
8
|
+
short-lived, world-scoped session token (minted by the backend at
|
|
9
|
+
`POST /api/v1/instant-worlds/:worldId/session`) over `postMessage`. The SDK wraps that handshake.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @hypersoniclabs/helix-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Helix } from '@hypersoniclabs/helix-sdk';
|
|
21
|
+
|
|
22
|
+
const { embedded, world, user } = await Helix.init(); // call once, at startup
|
|
23
|
+
|
|
24
|
+
if (Helix.auth.isAuthenticated()) {
|
|
25
|
+
const me = await Helix.auth.getUser(); // { id, username, displayName }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Raise the shell's login overlay (no-op reload — world state is preserved):
|
|
29
|
+
loginButton.onclick = async () => {
|
|
30
|
+
try {
|
|
31
|
+
const user = await Helix.auth.requestLogin();
|
|
32
|
+
console.log('signed in as', user.username);
|
|
33
|
+
} catch {
|
|
34
|
+
/* dismissed or unavailable */
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Helix.auth.onAuthChanged((user) => updateUi(user)); // login + logout
|
|
39
|
+
|
|
40
|
+
// Ask the HELIX shell to render native status notifications.
|
|
41
|
+
Helix.notify.success('Prize claimed', 'Welcome Chip added to inventory');
|
|
42
|
+
Helix.notify.failure('Purchase failed', 'Not enough LIX');
|
|
43
|
+
Helix.notify.notification('Quest updated', 'Return to the VIP lounge');
|
|
44
|
+
Helix.notify.message('Nova', 'Meet me by the arcade machines');
|
|
45
|
+
|
|
46
|
+
// Publish a current interaction prompt without tying your world to a renderer.
|
|
47
|
+
Helix.prompts.set({
|
|
48
|
+
id: 'fortune-arcade.vip',
|
|
49
|
+
title: 'VIP Room',
|
|
50
|
+
description: 'Buy a keycard to enter.',
|
|
51
|
+
input: { key: 'E', label: 'Interact' },
|
|
52
|
+
actionLabel: 'Buy keycard',
|
|
53
|
+
state: 'available',
|
|
54
|
+
});
|
|
55
|
+
Helix.prompts.clear('fortune-arcade.vip');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
When the world is opened directly (e.g. a local `vite dev` server with no shell), `init()` resolves
|
|
59
|
+
with `embedded: false` and all identity APIs return `null`/`false` — so the same build runs locally
|
|
60
|
+
and embedded.
|
|
61
|
+
|
|
62
|
+
### API
|
|
63
|
+
|
|
64
|
+
- `Helix.init(): Promise<{ embedded, world, user }>` — handshake; call once before anything else.
|
|
65
|
+
- `Helix.auth.getUser(): Promise<HelixUser | null>`
|
|
66
|
+
- `Helix.auth.isAuthenticated(): boolean`
|
|
67
|
+
- `Helix.auth.requestLogin(): Promise<HelixUser>` — resolves on login, rejects on dismiss/unavailable.
|
|
68
|
+
- `Helix.auth.onAuthChanged(fn): () => void` — fires on login and logout; returns an unsubscribe fn.
|
|
69
|
+
- `Helix.notify.show({ kind, title, message?, timeoutMs?, actionLabel?, actionHref? }): boolean`
|
|
70
|
+
- `Helix.notify.success|failure|notification|message(title, message?): boolean` — returns `false` when
|
|
71
|
+
the world is running standalone without a shell.
|
|
72
|
+
- `Helix.prompts.set({ id, title, description?, input?, actionLabel?, state?, priority? }): boolean`
|
|
73
|
+
- `Helix.prompts.clear(promptId?): boolean`
|
|
74
|
+
- `Helix.getSessionToken(): string | null` — the world-scoped token, for advanced direct API calls.
|
|
75
|
+
|
|
76
|
+
### Economy & items (v2, shell-mediated)
|
|
77
|
+
|
|
78
|
+
All of these are **server-authoritative**: the world *requests*, the shell (which holds the player's
|
|
79
|
+
session) settles with the backend and renders the purchase popup. Reads degrade to empty defaults
|
|
80
|
+
when not embedded; a purchase returns `Unauthorized` (never a fake success).
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const { lix, coins } = await Helix.wallet.getBalance();
|
|
84
|
+
Helix.wallet.onBalanceChanged((b) => updateHud(b));
|
|
85
|
+
|
|
86
|
+
// Buy a marketplace item or a world-registered product. completed === player owns it now.
|
|
87
|
+
const res = await Helix.marketplace.purchaseItem('premium_sword_001');
|
|
88
|
+
if (res.completed) equip('premium_sword_001'); // Granted | Claimed | AlreadyOwned
|
|
89
|
+
else showToast(res.status); // InsufficientFunds | Cancelled | …
|
|
90
|
+
|
|
91
|
+
await Helix.marketplace.purchaseProduct('golden_key'); // a world product
|
|
92
|
+
const items = await Helix.marketplace.getListings({ kind: 'home_item' });
|
|
93
|
+
|
|
94
|
+
// Ownership gating — works across worlds & creators (VIP / season passes).
|
|
95
|
+
if (await Helix.inventory.hasItem('vip_pass_001')) openBackstage();
|
|
96
|
+
const owned = await Helix.inventory.getMyItems();
|
|
97
|
+
await Helix.inventory.equipItem('vip_hat_001');
|
|
98
|
+
Helix.inventory.onInventoryChanged(refreshInventory);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `Helix.wallet.getBalance()` / `onBalanceChanged(fn)`
|
|
102
|
+
- `Helix.marketplace.purchaseItem(itemId)` / `purchaseProduct(productId)` / `getListings(query?)` / `getPurchaseContext(ref)`
|
|
103
|
+
- `Helix.inventory.hasItem(id)` / `getQuantity(id)` / `getMyItems()` / `equipItem(id)` / `onInventoryChanged(fn)`
|
|
104
|
+
|
|
105
|
+
The SDK mints a stable idempotency key per purchase (reused across the popup's retries) so a dropped
|
|
106
|
+
network can never double-charge. See the backend `/api/v1/iwp/*` endpoints for the settlement layer.
|
|
107
|
+
|
|
108
|
+
### Interaction prompts
|
|
109
|
+
|
|
110
|
+
`Helix.prompts` is intentionally engine-agnostic. A Three.js, Phaser, Unity WebGL, or plain DOM world
|
|
111
|
+
can all publish the same contract: a stable prompt id, display text, optional keyboard/gamepad labels,
|
|
112
|
+
and a coarse state (`default`, `available`, `locked`, or `busy`). The shell decides how to render it.
|
|
113
|
+
|
|
114
|
+
## Protocol
|
|
115
|
+
|
|
116
|
+
[`src/protocol.ts`](src/protocol.ts) is the wire contract (`postMessage` messages between world and
|
|
117
|
+
shell) and is imported by both sides. Any breaking change must bump `PROTOCOL_VERSION`. The
|
|
118
|
+
`HelixSession` shape matches the backend's `InstantWorldSessionResponseDto`, so the shell forwards
|
|
119
|
+
the backend response verbatim.
|
|
120
|
+
|
|
121
|
+
## Develop
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm install
|
|
125
|
+
npm test # jest + jsdom
|
|
126
|
+
npm run build # tsc → dist/ (ESM)
|
|
127
|
+
npm run lint
|
|
128
|
+
```
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CameraAspect } from './protocol';
|
|
2
|
+
export type CaptureOptions = {
|
|
3
|
+
aspect?: CameraAspect;
|
|
4
|
+
type?: string;
|
|
5
|
+
quality?: number;
|
|
6
|
+
};
|
|
7
|
+
export type CropRect = {
|
|
8
|
+
sx: number;
|
|
9
|
+
sy: number;
|
|
10
|
+
sw: number;
|
|
11
|
+
sh: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function cropRectForAspect(w: number, h: number, aspect?: CameraAspect): CropRect;
|
|
14
|
+
export declare function captureCanvas(source: HTMLCanvasElement, opts?: CaptureOptions): Promise<Blob>;
|
package/dist/camera.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Camera capture helpers — the in-iframe pixel side of the universal world camera.
|
|
2
|
+
//
|
|
3
|
+
// The SDK core (index.ts) owns the shell-mediated `Helix.camera.savePhoto`. This
|
|
4
|
+
// file holds the pure/DOM-only capture glue so it can be unit-tested without the
|
|
5
|
+
// postMessage shell: the crop math is pure; `captureCanvas` is the one DOM call.
|
|
6
|
+
//
|
|
7
|
+
// WebGL gotcha: the drawing buffer is cleared after each frame, so reading a
|
|
8
|
+
// WebGL canvas a frame later yields black. Callers must either render into the
|
|
9
|
+
// canvas immediately before capturing (same tick), capture inside the rAF right
|
|
10
|
+
// after the world's render, or create the context with preserveDrawingBuffer.
|
|
11
|
+
// Aspect ratios as width/height. `free`/`square` are handled in cropRectForAspect.
|
|
12
|
+
const ASPECT_RATIO = {
|
|
13
|
+
portrait: 3 / 4,
|
|
14
|
+
landscape: 4 / 3,
|
|
15
|
+
};
|
|
16
|
+
// Centre-crop rectangle for a source canvas of (w×h) at the requested aspect.
|
|
17
|
+
// `free` returns the full frame; `square` is 1:1. Pure — no DOM.
|
|
18
|
+
export function cropRectForAspect(w, h, aspect = 'free') {
|
|
19
|
+
if (w <= 0 || h <= 0)
|
|
20
|
+
return { sx: 0, sy: 0, sw: Math.max(0, w), sh: Math.max(0, h) };
|
|
21
|
+
if (aspect === 'free')
|
|
22
|
+
return { sx: 0, sy: 0, sw: w, sh: h };
|
|
23
|
+
const target = aspect === 'square' ? 1 : ASPECT_RATIO[aspect];
|
|
24
|
+
const current = w / h;
|
|
25
|
+
let sw = w;
|
|
26
|
+
let sh = h;
|
|
27
|
+
if (current > target) {
|
|
28
|
+
// too wide → crop width
|
|
29
|
+
sw = Math.round(h * target);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// too tall → crop height
|
|
33
|
+
sh = Math.round(w / target);
|
|
34
|
+
}
|
|
35
|
+
const sx = Math.round((w - sw) / 2);
|
|
36
|
+
const sy = Math.round((h - sh) / 2);
|
|
37
|
+
return { sx, sy, sw, sh };
|
|
38
|
+
}
|
|
39
|
+
// Capture a (rendered) canvas to an encoded Blob, centre-cropped to `aspect`.
|
|
40
|
+
// DOM-only. Throws if the environment has no 2D canvas (non-browser) or the
|
|
41
|
+
// canvas is empty. The caller is responsible for rendering into `source` first.
|
|
42
|
+
export async function captureCanvas(source, opts = {}) {
|
|
43
|
+
const type = opts.type ?? 'image/jpeg';
|
|
44
|
+
const quality = opts.quality ?? 0.92;
|
|
45
|
+
const { sx, sy, sw, sh } = cropRectForAspect(source.width, source.height, opts.aspect ?? 'free');
|
|
46
|
+
if (sw <= 0 || sh <= 0) {
|
|
47
|
+
throw new Error('Helix.camera: nothing to capture (empty canvas)');
|
|
48
|
+
}
|
|
49
|
+
// Crop via an offscreen 2D canvas. When aspect is 'free' and no crop is needed
|
|
50
|
+
// we still copy through a 2D canvas so toBlob works uniformly across a WebGL
|
|
51
|
+
// source canvas.
|
|
52
|
+
const out = typeof OffscreenCanvas !== 'undefined'
|
|
53
|
+
? new OffscreenCanvas(sw, sh)
|
|
54
|
+
: Object.assign(document.createElement('canvas'), { width: sw, height: sh });
|
|
55
|
+
const ctx = out.getContext('2d');
|
|
56
|
+
if (!ctx)
|
|
57
|
+
throw new Error('Helix.camera: 2D canvas context unavailable');
|
|
58
|
+
ctx.drawImage(source, sx, sy, sw, sh, 0, 0, sw, sh);
|
|
59
|
+
return canvasToBlob(out, type, quality);
|
|
60
|
+
}
|
|
61
|
+
function canvasToBlob(canvas, type, quality) {
|
|
62
|
+
// OffscreenCanvas exposes convertToBlob; HTMLCanvasElement exposes toBlob.
|
|
63
|
+
const offscreen = canvas;
|
|
64
|
+
if (typeof offscreen.convertToBlob === 'function') {
|
|
65
|
+
return offscreen.convertToBlob({ type, quality });
|
|
66
|
+
}
|
|
67
|
+
const el = canvas;
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
el.toBlob((blob) => blob ? resolve(blob) : reject(new Error('Helix.camera: toBlob returned null')), type, quality);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAa9E,mFAAmF;AACnF,MAAM,YAAY,GAA6D;IAC7E,QAAQ,EAAE,CAAC,GAAG,CAAC;IACf,SAAS,EAAE,CAAC,GAAG,CAAC;CACjB,CAAC;AAEF,8EAA8E;AAC9E,iEAAiE;AACjE,MAAM,UAAU,iBAAiB,CAC/B,CAAS,EACT,CAAS,EACT,SAAuB,MAAM;IAE7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACtF,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,EAA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AE,CAAC,MAAM,CACP,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,EAChF,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { HelixInteractionPrompt, HelixNotification, HelixWorldContext, HelixUser, DebugLogEntry, Balance, PurchaseResult, PurchaseContext, InventoryItem, EquippedAvatar, AvatarLoadout, AvatarLoadoutPatch, MarketplaceListing, MarketplaceQuery, CameraAspect, SavedPhoto } from './protocol';
|
|
2
|
+
import { HelixMultiplayer } from './multiplayer';
|
|
3
|
+
import { CaptureOptions } from './camera';
|
|
4
|
+
export type { HelixInteractionPrompt, HelixNotification, HelixNotificationKind, HelixPromptState, HelixDeviceFormFactor, HelixWorldContext, HelixSession, HelixUser, DebugLogEntry, DebugLogLevel, Balance, PurchaseResult, PurchaseStatus, PurchaseContext, InventoryItem, EquippedAvatar, AvatarLoadout, AvatarLoadoutPatch, MarketplaceListing, MarketplaceQuery, CameraAspect, SavedPhoto, } from './protocol';
|
|
5
|
+
export type { CaptureOptions, CropRect } from './camera';
|
|
6
|
+
export { cropRectForAspect, captureCanvas } from './camera';
|
|
7
|
+
export type { HelixRoom, JoinRoomOptions, ReplicaInput } from './multiplayer';
|
|
8
|
+
export * from './multiplayer-contract';
|
|
9
|
+
export type HelixInitResult = {
|
|
10
|
+
embedded: boolean;
|
|
11
|
+
world: HelixWorldContext | null;
|
|
12
|
+
user: HelixUser | null;
|
|
13
|
+
};
|
|
14
|
+
type AuthListener = (user: HelixUser | null) => void;
|
|
15
|
+
type AnalyticsEventName = 'world_entered' | 'world_loaded' | 'world_load_failed' | 'world_exited' | 'world_heartbeat' | 'instance_joined' | 'instance_left' | 'creator_product_viewed' | 'client_error_seen' | 'api_error_seen';
|
|
16
|
+
type AnalyticsTrackInput = {
|
|
17
|
+
eventId?: string;
|
|
18
|
+
instanceId?: string | null;
|
|
19
|
+
itemId?: string | null;
|
|
20
|
+
inviteId?: string | null;
|
|
21
|
+
referrer?: string | null;
|
|
22
|
+
properties?: Record<string, string | number | boolean | null | undefined>;
|
|
23
|
+
};
|
|
24
|
+
declare class HelixSdk {
|
|
25
|
+
private shellOrigin;
|
|
26
|
+
private session;
|
|
27
|
+
private world;
|
|
28
|
+
private initialized;
|
|
29
|
+
private listeners;
|
|
30
|
+
private debugEnabled;
|
|
31
|
+
private debugRing;
|
|
32
|
+
private debugListeners;
|
|
33
|
+
private consoleHooked;
|
|
34
|
+
private pendingLogins;
|
|
35
|
+
private pendingRequests;
|
|
36
|
+
private balanceListeners;
|
|
37
|
+
private inventoryListeners;
|
|
38
|
+
private avatarListeners;
|
|
39
|
+
init(): Promise<HelixInitResult>;
|
|
40
|
+
readonly multiplayer: HelixMultiplayer;
|
|
41
|
+
readonly debug: {
|
|
42
|
+
enabled: () => boolean;
|
|
43
|
+
log: (...args: unknown[]) => void;
|
|
44
|
+
onLog: (cb: (entry: DebugLogEntry) => void) => (() => void);
|
|
45
|
+
recent: () => DebugLogEntry[];
|
|
46
|
+
};
|
|
47
|
+
readonly auth: {
|
|
48
|
+
getUser: () => Promise<HelixUser | null>;
|
|
49
|
+
isAuthenticated: () => boolean;
|
|
50
|
+
requestLogin: () => Promise<HelixUser>;
|
|
51
|
+
onAuthChanged: (listener: AuthListener) => (() => void);
|
|
52
|
+
};
|
|
53
|
+
readonly notify: {
|
|
54
|
+
show: (notification: HelixNotification) => boolean;
|
|
55
|
+
success: (title: string, message?: string) => boolean;
|
|
56
|
+
failure: (title: string, message?: string) => boolean;
|
|
57
|
+
notification: (title: string, message?: string) => boolean;
|
|
58
|
+
message: (title: string, message?: string) => boolean;
|
|
59
|
+
};
|
|
60
|
+
readonly prompts: {
|
|
61
|
+
set: (prompt: HelixInteractionPrompt) => boolean;
|
|
62
|
+
clear: (promptId?: string) => boolean;
|
|
63
|
+
};
|
|
64
|
+
readonly device: {
|
|
65
|
+
openTablet: () => boolean;
|
|
66
|
+
openPhone: () => boolean;
|
|
67
|
+
};
|
|
68
|
+
getSessionToken(): string | null;
|
|
69
|
+
readonly wallet: {
|
|
70
|
+
getBalance: () => Promise<Balance>;
|
|
71
|
+
onBalanceChanged: (cb: (b: Balance) => void) => (() => void);
|
|
72
|
+
};
|
|
73
|
+
readonly marketplace: {
|
|
74
|
+
purchaseItem: (itemId: string) => Promise<PurchaseResult>;
|
|
75
|
+
purchaseProduct: (productId: string) => Promise<PurchaseResult>;
|
|
76
|
+
getListings: (query?: MarketplaceQuery) => Promise<MarketplaceListing[]>;
|
|
77
|
+
getPurchaseContext: (ref: string) => Promise<PurchaseContext | null>;
|
|
78
|
+
};
|
|
79
|
+
readonly analytics: {
|
|
80
|
+
track: (eventName: AnalyticsEventName, input?: AnalyticsTrackInput) => Promise<void>;
|
|
81
|
+
};
|
|
82
|
+
readonly inventory: {
|
|
83
|
+
hasItem: (itemId: string) => Promise<boolean>;
|
|
84
|
+
getQuantity: (itemId: string) => Promise<number>;
|
|
85
|
+
getMyItems: () => Promise<InventoryItem[]>;
|
|
86
|
+
equipItem: (itemId: string) => Promise<void>;
|
|
87
|
+
onInventoryChanged: (cb: () => void) => (() => void);
|
|
88
|
+
};
|
|
89
|
+
readonly dataStore: {
|
|
90
|
+
get: <T = unknown>(key: string) => Promise<T | null>;
|
|
91
|
+
set: <T = unknown>(key: string, value: T) => Promise<void>;
|
|
92
|
+
delete: (key: string) => Promise<void>;
|
|
93
|
+
list: (prefix?: string) => Promise<string[]>;
|
|
94
|
+
};
|
|
95
|
+
readonly camera: {
|
|
96
|
+
available: () => boolean;
|
|
97
|
+
capture: (canvas: HTMLCanvasElement, opts?: CaptureOptions) => Promise<Blob>;
|
|
98
|
+
savePhoto: (image: Blob | ArrayBuffer | Uint8Array, meta?: {
|
|
99
|
+
caption?: string;
|
|
100
|
+
aspect?: CameraAspect;
|
|
101
|
+
contentType?: string;
|
|
102
|
+
}) => Promise<SavedPhoto | null>;
|
|
103
|
+
};
|
|
104
|
+
readonly avatar: {
|
|
105
|
+
openCreator: () => Promise<boolean>;
|
|
106
|
+
getLoadout: () => Promise<AvatarLoadout | null>;
|
|
107
|
+
updateLoadout: (patch: AvatarLoadoutPatch) => Promise<AvatarLoadout | null>;
|
|
108
|
+
getEquipped: () => Promise<EquippedAvatar | null>;
|
|
109
|
+
onAvatarChanged: (cb: () => void) => (() => void);
|
|
110
|
+
};
|
|
111
|
+
private purchase;
|
|
112
|
+
private trackAnalytics;
|
|
113
|
+
private safeAnalyticsProperties;
|
|
114
|
+
private openDevice;
|
|
115
|
+
private onKeyDown;
|
|
116
|
+
private request;
|
|
117
|
+
private newId;
|
|
118
|
+
private fetchAvatarLoadout;
|
|
119
|
+
private emitAvatarChanged;
|
|
120
|
+
private snapshot;
|
|
121
|
+
private assertInitialized;
|
|
122
|
+
private waitForInit;
|
|
123
|
+
private onMessage;
|
|
124
|
+
private setSession;
|
|
125
|
+
private enableDebug;
|
|
126
|
+
private hookConsole;
|
|
127
|
+
private captureLog;
|
|
128
|
+
private post;
|
|
129
|
+
private postToShell;
|
|
130
|
+
}
|
|
131
|
+
export declare const Helix: HelixSdk;
|