@mentra/cloud-client 3.4.0-dev.1100 → 3.4.0-dev.1101

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/cloud-client",
3
- "version": "3.4.0-dev.1100",
3
+ "version": "3.4.0-dev.1101",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "exports": {
@@ -12,7 +12,7 @@
12
12
  "test": "bun test"
13
13
  },
14
14
  "dependencies": {
15
- "@mentra/cloud-protocol": "3.4.0-dev.1100",
15
+ "@mentra/cloud-protocol": "3.4.0-dev.1101",
16
16
  "tweetnacl": "^1.0.3"
17
17
  },
18
18
  "devDependencies": {
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @fileoverview `cloud.core.account`: what the phone keeps on the signed-in person's Core account, over Core's
3
+ * `/api/account` router.
4
+ *
5
+ * GET /declared-age the age the person declared and when, both null until they answer
6
+ * PUT /declared-age {age} keep a new answer, dated now
7
+ *
8
+ * The engine asks a person's age once, when a miniapp rated above the host app's own App Store rating first installs
9
+ * or opens, and keeps it here (`declared-age.ts` in `@mentra/cloud-protocol`). It is never sent to a miniapp.
10
+ *
11
+ * Each call is made as the account whose Core token it carries (see `account-call.ts`): an answer that comes back after
12
+ * the account changed is discarded as `SessionChangedError`, and a 401 refreshes the token once. A failure keeps
13
+ * Core's status and error code on a `CoreRequestError` (`invalid_request`, `rate_limited`, `network_error`); an answer
14
+ * of another shape is a `CoreResponseError`.
15
+ */
16
+ import {DeclaredAgeSchema, type DeclaredAge} from "@mentra/cloud-protocol"
17
+ import type {HttpClient} from "../../http"
18
+ import {AccountCaller, CoreResponseError, type AccountCallOptions, type CoreTokenSource} from "./account-call"
19
+
20
+ const DECLARED_AGE_PATH = "/api/account/declared-age"
21
+
22
+ export class Account {
23
+ private readonly caller: AccountCaller
24
+
25
+ constructor(
26
+ private readonly http: HttpClient,
27
+ auth?: CoreTokenSource,
28
+ ) {
29
+ this.caller = new AccountCaller(auth)
30
+ }
31
+
32
+ /** The age the signed-in person declared, and when; both null until they answer. */
33
+ async declaredAge(opts?: AccountCallOptions): Promise<DeclaredAge> {
34
+ const body = await this.caller.run(
35
+ (bearer) =>
36
+ this.http.get<unknown>(DECLARED_AGE_PATH, {
37
+ bearer,
38
+ // A read: safe to retry.
39
+ idempotent: true,
40
+ ...(opts?.signal ? {signal: opts.signal} : {}),
41
+ }),
42
+ opts,
43
+ )
44
+ return readDeclaredAge(body)
45
+ }
46
+
47
+ /** Keep `age` as the signed-in person's declared age, dated now. Resolves with what Core kept. */
48
+ async setDeclaredAge(age: number, opts?: AccountCallOptions): Promise<DeclaredAge> {
49
+ const body = await this.caller.run(
50
+ (bearer) =>
51
+ this.http.put<unknown>(
52
+ DECLARED_AGE_PATH,
53
+ {age},
54
+ {
55
+ bearer,
56
+ // Sending the same answer again keeps the same age.
57
+ idempotent: true,
58
+ ...(opts?.signal ? {signal: opts.signal} : {}),
59
+ },
60
+ ),
61
+ opts,
62
+ )
63
+ const kept = readDeclaredAge(body)
64
+ if (kept.declaredAge !== age) throw new CoreResponseError("invalid_shape")
65
+ return kept
66
+ }
67
+ }
68
+
69
+ function readDeclaredAge(body: unknown): DeclaredAge {
70
+ const parsed = DeclaredAgeSchema.safeParse(body)
71
+ if (!parsed.success) throw new CoreResponseError("invalid_shape")
72
+ return {declaredAge: parsed.data.declaredAge, declaredAgeAt: parsed.data.declaredAgeAt}
73
+ }
@@ -7,8 +7,8 @@
7
7
  * core never touches credentials itself.
8
8
  *
9
9
  * Today it exposes the unified report submission surface, the support
10
- * profile update, the Fleet report, the workspace calls and the miniapp
11
- * registry calls.
10
+ * profile update, the Fleet report, the workspace calls, the miniapp
11
+ * registry calls and the person's declared age.
12
12
  *
13
13
  * Guardrail: this is device-facing only. It deliberately carries none of the
14
14
  * Dev Console / OEM Portal / store web UI surface; those are separate clients.
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import type { HttpClient } from "../../http";
20
20
  import type {
21
+ DeclaredAge,
21
22
  FleetDesiredState,
22
23
  FleetReport,
23
24
  RegistryRegisterRequest,
@@ -33,6 +34,7 @@ import type {
33
34
  PendingInvitationsResponse,
34
35
  } from "./workspace-types";
35
36
  import type { AccountCallOptions, CoreTokenSource } from "./account-call";
37
+ import { Account } from "./account";
36
38
  import { Fleet, type FleetReportOutcome } from "./fleet";
37
39
  import { Registry } from "./registry";
38
40
  import { Workspaces } from "./workspaces";
@@ -91,8 +93,8 @@ export type {
91
93
  export interface CoreDeps {
92
94
  http: HttpClient;
93
95
  /**
94
- * Where workspace, desired-state and registry calls get the signed-in account's Core token (`cloud.auth`). Without
95
- * it those calls reject, because they must be made as one account.
96
+ * Where workspace, desired-state, registry and account calls get the signed-in account's Core token (`cloud.auth`).
97
+ * Without it those calls reject, because they must be made as one account.
96
98
  */
97
99
  auth?: CoreTokenSource;
98
100
  }
@@ -168,6 +170,13 @@ export class Core {
168
170
  /** `POST /api/client/registry/status`: one batch of installed URLs. */
169
171
  registryStatus(request: RegistryStatusRequest, opts?: AccountCallOptions): Promise<RegistryStatusResponse>;
170
172
  };
173
+ /** What the phone keeps on the signed-in person's account (`account.ts`). Each call is made as one account. */
174
+ readonly account: {
175
+ /** `GET /api/account/declared-age`: the age the person declared and when, both null until they answer. */
176
+ declaredAge(opts?: AccountCallOptions): Promise<DeclaredAge>;
177
+ /** `PUT /api/account/declared-age`: keep `age` as the person's declared age, dated now. */
178
+ setDeclaredAge(age: number, opts?: AccountCallOptions): Promise<DeclaredAge>;
179
+ };
171
180
 
172
181
  constructor(deps: CoreDeps) {
173
182
  const { http, auth } = deps;
@@ -176,6 +185,7 @@ export class Core {
176
185
  const fleet = new Fleet(http, auth);
177
186
  const workspaces = new Workspaces(http, auth);
178
187
  const registry = new Registry(http, auth);
188
+ const account = new Account(http, auth);
179
189
 
180
190
  this.reports = {
181
191
  submit: reports.submit.bind(reports),
@@ -204,5 +214,9 @@ export class Core {
204
214
  registerMiniappUrl: registry.registerMiniappUrl.bind(registry),
205
215
  registryStatus: registry.registryStatus.bind(registry),
206
216
  };
217
+ this.account = {
218
+ declaredAge: account.declaredAge.bind(account),
219
+ setDeclaredAge: account.setDeclaredAge.bind(account),
220
+ };
207
221
  }
208
222
  }