@knowlearning/agents 0.3.2 → 0.3.4

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.
@@ -4,12 +4,15 @@ import { onAuth, login, logout } from './firebase-auth.js'
4
4
  import GenericAgent from '../generic.js'
5
5
 
6
6
  const DEVELOPMENT_HOST = 'localhost:32001'
7
+ const REMOTE_HOST = 'api.knowlearning.systems'
8
+
9
+ function isLocal() { return localStorage.getItem('api') === 'local' }
7
10
 
8
11
  export default () => {
9
12
  const { host, protocol } = window.location
10
13
 
11
14
  const agent = GenericAgent({
12
- host: host.endsWith(DEVELOPMENT_HOST) ? DEVELOPMENT_HOST : 'api.knowlearning.systems',
15
+ host: isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST,
13
16
  protocol: protocol === 'https:' ? 'wss' : 'ws',
14
17
  token: new Promise(r => onAuth(({ getIdToken: g }) => r(g()))),
15
18
  WebSocket,
@@ -24,6 +27,18 @@ export default () => {
24
27
  const { state, mutate } = agent
25
28
  agent.state = (scope=host,user,domain) => state(scope, user, domain)
26
29
  agent.mutate = (scope=host) => mutate(scope)
30
+ agent.local = () => {
31
+ if (isLocal()) return
32
+
33
+ localStorage.setItem('api', 'local')
34
+ location.reload()
35
+ }
36
+ agent.remote = () => {
37
+ if (!isLocal()) return
38
+
39
+ localStorage.removeItem('api')
40
+ location.reload()
41
+ }
27
42
 
28
43
  return agent
29
44
  }
package/agents/generic.js CHANGED
@@ -287,6 +287,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
287
287
  }
288
288
  }
289
289
 
290
+ async function claim(domain) {
291
+ return interact('claims', [{ op: 'add', path: [domain], value: null }])
292
+ }
293
+
290
294
  async function mutate(scope, initialize=true) {
291
295
  const initial = initialize ? copy(await state(scope) || {}) : {}
292
296
  return new MutableProxy(initial, patch => interact(scope, patch))
@@ -320,6 +324,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
320
324
  download,
321
325
  interact,
322
326
  patch,
327
+ claim,
323
328
  mutate,
324
329
  reset,
325
330
  metadata,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",