@layers/amba-web 1.0.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/README.md +129 -0
- package/dist/index.d.ts +814 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +504 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @layers/amba-web
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@layers/amba-web)
|
|
4
|
+
|
|
5
|
+
Browser SDK for [amba](https://amba.dev) — the agent-native backend-as-a-service for mobile and web apps.
|
|
6
|
+
|
|
7
|
+
Full parity with the cross-language amba surface: **auth · collections · storage · events · push · entitlements · AI · config · flags · achievements · challenges · currencies · friends · groups · inventory · leaderboards · messaging · moderation · onboarding · referrals · reviews · roles · sessions · streaks · stores · sync · xp**.
|
|
8
|
+
|
|
9
|
+
Built on top of `@layers/amba-core-wasm` — a Rust core compiled to WebAssembly, ensuring identical behavior across web, Node, React Native, Swift, Kotlin, Flutter, and Unity SDKs.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @layers/amba-web
|
|
15
|
+
# or
|
|
16
|
+
npm i @layers/amba-web
|
|
17
|
+
# or
|
|
18
|
+
yarn add @layers/amba-web
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quickstart
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Amba } from "@layers/amba-web";
|
|
25
|
+
|
|
26
|
+
// 1) configure once at app start
|
|
27
|
+
await Amba.configure({
|
|
28
|
+
apiKey: import.meta.env.VITE_AMBA_API_KEY,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 2) sign in (anonymous, email, or social)
|
|
32
|
+
const session = await Amba.auth.signInAnonymously();
|
|
33
|
+
|
|
34
|
+
// 3) track engagement
|
|
35
|
+
await Amba.events.track("app_opened", { source: "deep_link" });
|
|
36
|
+
|
|
37
|
+
// 4) read & write your typed collections (auto-RLS — only your user's rows)
|
|
38
|
+
const { data: todos } = await Amba.collections.find("todos", {
|
|
39
|
+
filter: Amba.collections.where.eq("done", false),
|
|
40
|
+
order: [{ column: "created_at", direction: "desc" }],
|
|
41
|
+
limit: 50,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await Amba.collections.insert("todos", {
|
|
45
|
+
title: "Ship the SDK",
|
|
46
|
+
done: false,
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API surface
|
|
51
|
+
|
|
52
|
+
### Auth
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
await Amba.auth.signInAnonymously();
|
|
56
|
+
await Amba.auth.signInWithEmail(email, password);
|
|
57
|
+
await Amba.auth.signUpWithEmail(email, password);
|
|
58
|
+
await Amba.auth.signInWithSocial("apple" | "google", idToken);
|
|
59
|
+
await Amba.auth.signOut(/* rotateAnonymousId? */);
|
|
60
|
+
await Amba.auth.refresh();
|
|
61
|
+
await Amba.auth.me();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Events
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
await Amba.events.track("signup_completed", { plan: "pro" });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Collections — Mongo-style filter DSL, server-enforced RLS
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const { where } = Amba.collections;
|
|
74
|
+
|
|
75
|
+
await Amba.collections.find("posts", {
|
|
76
|
+
filter: where.and(where.eq("status", "published"), where.gte("score", 100)),
|
|
77
|
+
order: [{ column: "created_at", direction: "desc" }],
|
|
78
|
+
limit: 20,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Storage — presign → PUT → commit
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const asset = await Amba.storage.upload({
|
|
86
|
+
bucket: "avatars",
|
|
87
|
+
file: fileInput.files[0],
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Push
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
await Amba.push.register(pushToken, "web");
|
|
95
|
+
await Amba.push.subscribe("breaking_news");
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Entitlements
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
if (await Amba.entitlements.has("pro")) {
|
|
102
|
+
showProFeature();
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### AI proxy
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const reply = await Amba.ai.anthropic.messages.create({
|
|
110
|
+
prompt_slug: "support_assistant",
|
|
111
|
+
variables: { user_query: input },
|
|
112
|
+
max_tokens: 1024,
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Config & flags
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const config = await Amba.config.fetch();
|
|
120
|
+
const flags = await Amba.flags.fetch();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Bundle size
|
|
124
|
+
|
|
125
|
+
≤30 KB gzipped for the entry point. The WASM binary (~150 KB gzipped) loads lazily on `Amba.configure()`.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT.
|