@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.2
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/jest.config.js +4 -4
- package/lib/index.cjs +5999 -6046
- package/lib/index.js +5977 -6040
- package/lib/src/Ad4mClient.d.ts +16 -9
- package/lib/src/Ad4mClient.js +25 -46
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.d.ts +2 -1
- package/lib/src/Literal.js +35 -38
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/SmartLiteral.d.ts +2 -1
- package/lib/src/SmartLiteral.js +15 -30
- package/lib/src/agent/AgentClient.d.ts +4 -1
- package/lib/src/agent/AgentClient.js +99 -79
- package/lib/src/ai/AIClient.d.ts +2 -1
- package/lib/src/ai/AIClient.js +220 -224
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +86 -73
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +157 -937
- package/lib/src/model/Ad4mModel.js +212 -2799
- package/lib/src/model/Ad4mModel.test.js +1002 -561
- package/lib/src/model/decorators.d.ts +94 -426
- package/lib/src/model/decorators.js +333 -741
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.js +7 -7
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +316 -240
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
- package/lib/src/perspectives/PerspectiveProxy.js +803 -444
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +412 -238
- package/lib/src/shacl/SHACLFlow.test.js +164 -105
- package/lib/src/shacl/SHACLShape.d.ts +17 -3
- package/lib/src/shacl/SHACLShape.js +127 -90
- package/lib/src/shacl/SHACLShape.test.js +244 -176
- package/lib/src/utils.d.ts +8 -0
- package/lib/src/utils.js +21 -7
- package/package.json +8 -13
- package/src/Ad4mClient.test.ts +1564 -1315
- package/src/Ad4mClient.ts +55 -54
- package/src/Literal.test.ts +45 -26
- package/src/Literal.ts +82 -66
- package/src/SmartLiteral.ts +74 -58
- package/src/agent/AgentClient.ts +144 -99
- package/src/ai/AIClient.ts +409 -359
- package/src/expression/ExpressionClient.ts +142 -96
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +137 -113
- package/src/model/Ad4mModel.test.ts +1128 -647
- package/src/model/Ad4mModel.ts +485 -3249
- package/src/model/IMPROVEMENTS.md +482 -0
- package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
- package/src/model/README.md +317 -0
- package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
- package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
- package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
- package/src/model/decorators.ts +689 -1046
- package/src/model/mutation.ts +461 -0
- package/src/model/parentUtils.ts +91 -0
- package/src/model/prolog/generatePrologFacts.ts +176 -0
- package/src/model/prolog/index.ts +1 -0
- package/src/model/query/ModelQueryBuilder.ts +173 -0
- package/src/model/query/fetchInstance.ts +181 -0
- package/src/model/query/hydration.ts +273 -0
- package/src/model/query/operations.ts +510 -0
- package/src/model/query/snapshot.ts +126 -0
- package/src/model/query/surrealCompiler.ts +376 -0
- package/src/model/schema/fromJSONSchema.ts +411 -0
- package/src/model/schema/metadata.ts +148 -0
- package/src/model/subscription.ts +307 -0
- package/src/model/transaction.ts +60 -0
- package/src/model/types.ts +207 -0
- package/src/model/util.ts +47 -48
- package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
- package/src/perspectives/PerspectiveClient.ts +779 -540
- package/src/perspectives/PerspectiveProxy.ts +2860 -2053
- package/src/runtime/RuntimeClient.ts +775 -476
- package/src/shacl/SHACLFlow.test.ts +196 -129
- package/src/shacl/SHACLShape.test.ts +284 -190
- package/src/shacl/SHACLShape.ts +225 -172
- package/src/utils.ts +31 -17
- package/tsconfig.json +9 -10
- package/src/model/Subject.ts +0 -159
package/src/agent/AgentClient.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ApolloClient, gql } from "@apollo/client/core";
|
|
2
2
|
import { PerspectiveInput } from "../perspectives/Perspective";
|
|
3
3
|
import unwrapApolloResult from "../unwrapApolloResult";
|
|
4
|
+
import { isSocketCloseError } from "../utils";
|
|
4
5
|
import {
|
|
5
6
|
Agent,
|
|
6
7
|
Apps,
|
|
@@ -87,16 +88,16 @@ export type AgentAppsUpdatedCallback = () => null;
|
|
|
87
88
|
* as well as updating the publicly shared Agent expression.
|
|
88
89
|
*/
|
|
89
90
|
export class AgentClient {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
private _apolloClient: ApolloClient<any>;
|
|
92
|
+
private _appsChangedCallback: AgentAppsUpdatedCallback[];
|
|
93
|
+
private _updatedCallbacks: AgentUpdatedCallback[];
|
|
94
|
+
private _agentStatusChangedCallbacks: AgentStatusChangedCallback[];
|
|
94
95
|
|
|
95
96
|
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
96
|
-
this
|
|
97
|
-
this
|
|
98
|
-
this
|
|
99
|
-
this
|
|
97
|
+
this._apolloClient = client;
|
|
98
|
+
this._updatedCallbacks = [];
|
|
99
|
+
this._agentStatusChangedCallbacks = [];
|
|
100
|
+
this._appsChangedCallback = [];
|
|
100
101
|
|
|
101
102
|
if (subscribe) {
|
|
102
103
|
this.subscribeAgentUpdated();
|
|
@@ -113,9 +114,9 @@ export class AgentClient {
|
|
|
113
114
|
*/
|
|
114
115
|
async me(): Promise<Agent> {
|
|
115
116
|
const { agent } = unwrapApolloResult(
|
|
116
|
-
await this
|
|
117
|
+
await this._apolloClient.query({
|
|
117
118
|
query: gql`query agent { agent { ${AGENT_SUBITEMS} } }`,
|
|
118
|
-
})
|
|
119
|
+
}),
|
|
119
120
|
);
|
|
120
121
|
let agentObject = new Agent(agent.did, agent.perspective);
|
|
121
122
|
agentObject.directMessageLanguage = agent.directMessageLanguage;
|
|
@@ -124,20 +125,20 @@ export class AgentClient {
|
|
|
124
125
|
|
|
125
126
|
async status(): Promise<AgentStatus> {
|
|
126
127
|
const { agentStatus } = unwrapApolloResult(
|
|
127
|
-
await this
|
|
128
|
+
await this._apolloClient.query({
|
|
128
129
|
query: gql`query agentStatus {
|
|
129
130
|
agentStatus {
|
|
130
131
|
${AGENT_STATUS_FIELDS}
|
|
131
132
|
}
|
|
132
133
|
}`,
|
|
133
|
-
})
|
|
134
|
+
}),
|
|
134
135
|
);
|
|
135
136
|
return new AgentStatus(agentStatus);
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
async generate(passphrase: string): Promise<AgentStatus> {
|
|
139
140
|
const { agentGenerate } = unwrapApolloResult(
|
|
140
|
-
await this
|
|
141
|
+
await this._apolloClient.mutate({
|
|
141
142
|
mutation: gql`mutation agentGenerate(
|
|
142
143
|
$passphrase: String!
|
|
143
144
|
) {
|
|
@@ -146,7 +147,7 @@ export class AgentClient {
|
|
|
146
147
|
}
|
|
147
148
|
}`,
|
|
148
149
|
variables: { passphrase },
|
|
149
|
-
})
|
|
150
|
+
}),
|
|
150
151
|
);
|
|
151
152
|
return new AgentStatus(agentGenerate);
|
|
152
153
|
}
|
|
@@ -154,7 +155,7 @@ export class AgentClient {
|
|
|
154
155
|
async import(args: InitializeArgs): Promise<AgentStatus> {
|
|
155
156
|
let { did, didDocument, keystore, passphrase } = args;
|
|
156
157
|
const { agentImport } = unwrapApolloResult(
|
|
157
|
-
await this
|
|
158
|
+
await this._apolloClient.mutate({
|
|
158
159
|
mutation: gql`mutation agentImport(
|
|
159
160
|
$did: String!,
|
|
160
161
|
$didDocument: String!,
|
|
@@ -166,49 +167,49 @@ export class AgentClient {
|
|
|
166
167
|
}
|
|
167
168
|
}`,
|
|
168
169
|
variables: { did, didDocument, keystore, passphrase },
|
|
169
|
-
})
|
|
170
|
+
}),
|
|
170
171
|
);
|
|
171
172
|
return new AgentStatus(agentImport);
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
async lock(passphrase: string): Promise<AgentStatus> {
|
|
175
176
|
const { agentLock } = unwrapApolloResult(
|
|
176
|
-
await this
|
|
177
|
+
await this._apolloClient.mutate({
|
|
177
178
|
mutation: gql`mutation agentLock($passphrase: String!) {
|
|
178
179
|
agentLock(passphrase: $passphrase) {
|
|
179
180
|
${AGENT_STATUS_FIELDS}
|
|
180
181
|
}
|
|
181
182
|
}`,
|
|
182
183
|
variables: { passphrase },
|
|
183
|
-
})
|
|
184
|
+
}),
|
|
184
185
|
);
|
|
185
186
|
return new AgentStatus(agentLock);
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
async unlock(passphrase: string, holochain = true): Promise<AgentStatus> {
|
|
189
190
|
const { agentUnlock } = unwrapApolloResult(
|
|
190
|
-
await this
|
|
191
|
+
await this._apolloClient.mutate({
|
|
191
192
|
mutation: gql`mutation agentUnlock($passphrase: String!, $holochain: Boolean!) {
|
|
192
193
|
agentUnlock(passphrase: $passphrase, holochain: $holochain) {
|
|
193
194
|
${AGENT_STATUS_FIELDS}
|
|
194
195
|
}
|
|
195
196
|
}`,
|
|
196
197
|
variables: { passphrase, holochain },
|
|
197
|
-
})
|
|
198
|
+
}),
|
|
198
199
|
);
|
|
199
200
|
return new AgentStatus(agentUnlock);
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
async byDID(did: string): Promise<Agent> {
|
|
203
204
|
const { agentByDID } = unwrapApolloResult(
|
|
204
|
-
await this
|
|
205
|
+
await this._apolloClient.query({
|
|
205
206
|
query: gql`query agentByDID($did: String!) {
|
|
206
207
|
agentByDID(did: $did) {
|
|
207
208
|
${AGENT_SUBITEMS}
|
|
208
209
|
}
|
|
209
210
|
}`,
|
|
210
211
|
variables: { did },
|
|
211
|
-
})
|
|
212
|
+
}),
|
|
212
213
|
);
|
|
213
214
|
return agentByDID as Agent;
|
|
214
215
|
}
|
|
@@ -224,14 +225,14 @@ export class AgentClient {
|
|
|
224
225
|
});
|
|
225
226
|
|
|
226
227
|
const { agentUpdatePublicPerspective } = unwrapApolloResult(
|
|
227
|
-
await this
|
|
228
|
+
await this._apolloClient.mutate({
|
|
228
229
|
mutation: gql`mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) {
|
|
229
230
|
agentUpdatePublicPerspective(perspective: $perspective) {
|
|
230
231
|
${AGENT_SUBITEMS}
|
|
231
232
|
}
|
|
232
233
|
}`,
|
|
233
234
|
variables: { perspective: cleanedPerspective },
|
|
234
|
-
})
|
|
235
|
+
}),
|
|
235
236
|
);
|
|
236
237
|
const a = agentUpdatePublicPerspective;
|
|
237
238
|
const agent = new Agent(a.did, a.perspective);
|
|
@@ -240,12 +241,12 @@ export class AgentClient {
|
|
|
240
241
|
}
|
|
241
242
|
|
|
242
243
|
async mutatePublicPerspective(mutations: LinkMutations): Promise<Agent> {
|
|
243
|
-
const perspectiveClient = new PerspectiveClient(this
|
|
244
|
-
const agentClient = new AgentClient(this
|
|
244
|
+
const perspectiveClient = new PerspectiveClient(this._apolloClient);
|
|
245
|
+
const agentClient = new AgentClient(this._apolloClient);
|
|
245
246
|
|
|
246
247
|
//Create the proxy perspective and load existing links
|
|
247
248
|
const proxyPerspective = await perspectiveClient.add(
|
|
248
|
-
"Agent Perspective Proxy"
|
|
249
|
+
"Agent Perspective Proxy",
|
|
249
250
|
);
|
|
250
251
|
const agentMe = await agentClient.me();
|
|
251
252
|
|
|
@@ -271,17 +272,17 @@ export class AgentClient {
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
async updateDirectMessageLanguage(
|
|
274
|
-
directMessageLanguage: string
|
|
275
|
+
directMessageLanguage: string,
|
|
275
276
|
): Promise<Agent> {
|
|
276
277
|
const { agentUpdateDirectMessageLanguage } = unwrapApolloResult(
|
|
277
|
-
await this
|
|
278
|
+
await this._apolloClient.mutate({
|
|
278
279
|
mutation: gql`mutation agentUpdateDirectMessageLanguage($directMessageLanguage: String!) {
|
|
279
280
|
agentUpdateDirectMessageLanguage(directMessageLanguage: $directMessageLanguage) {
|
|
280
281
|
${AGENT_SUBITEMS}
|
|
281
282
|
}
|
|
282
283
|
}`,
|
|
283
284
|
variables: { directMessageLanguage },
|
|
284
|
-
})
|
|
285
|
+
}),
|
|
285
286
|
);
|
|
286
287
|
const a = agentUpdateDirectMessageLanguage;
|
|
287
288
|
const agent = new Agent(a.did, a.perspective);
|
|
@@ -290,77 +291,77 @@ export class AgentClient {
|
|
|
290
291
|
}
|
|
291
292
|
|
|
292
293
|
async addEntanglementProofs(
|
|
293
|
-
proofs: EntanglementProofInput[]
|
|
294
|
+
proofs: EntanglementProofInput[],
|
|
294
295
|
): Promise<EntanglementProof[]> {
|
|
295
296
|
const { agentAddEntanglementProofs } = unwrapApolloResult(
|
|
296
|
-
await this
|
|
297
|
+
await this._apolloClient.mutate({
|
|
297
298
|
mutation: gql`mutation agentAddEntanglementProofs($proofs: [EntanglementProofInput!]!) {
|
|
298
299
|
agentAddEntanglementProofs(proofs: $proofs) {
|
|
299
300
|
${ENTANGLEMENT_PROOF_FIELDS}
|
|
300
301
|
}
|
|
301
302
|
}`,
|
|
302
303
|
variables: { proofs },
|
|
303
|
-
})
|
|
304
|
+
}),
|
|
304
305
|
);
|
|
305
306
|
return agentAddEntanglementProofs;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
async deleteEntanglementProofs(
|
|
309
|
-
proofs: EntanglementProofInput[]
|
|
310
|
+
proofs: EntanglementProofInput[],
|
|
310
311
|
): Promise<EntanglementProof[]> {
|
|
311
312
|
const { agentDeleteEntanglementProofs } = unwrapApolloResult(
|
|
312
|
-
await this
|
|
313
|
+
await this._apolloClient.mutate({
|
|
313
314
|
mutation: gql`mutation agentDeleteEntanglementProofs($proofs: [EntanglementProofInput!]!) {
|
|
314
315
|
agentDeleteEntanglementProofs(proofs: $proofs) {
|
|
315
316
|
${ENTANGLEMENT_PROOF_FIELDS}
|
|
316
317
|
}
|
|
317
318
|
}`,
|
|
318
319
|
variables: { proofs },
|
|
319
|
-
})
|
|
320
|
+
}),
|
|
320
321
|
);
|
|
321
322
|
return agentDeleteEntanglementProofs;
|
|
322
323
|
}
|
|
323
324
|
|
|
324
325
|
async getEntanglementProofs(): Promise<string[]> {
|
|
325
326
|
const { agentGetEntanglementProofs } = unwrapApolloResult(
|
|
326
|
-
await this
|
|
327
|
+
await this._apolloClient.query({
|
|
327
328
|
query: gql`query agentGetEntanglementProofs {
|
|
328
329
|
agentGetEntanglementProofs {
|
|
329
330
|
${ENTANGLEMENT_PROOF_FIELDS}
|
|
330
331
|
}
|
|
331
332
|
}`,
|
|
332
|
-
})
|
|
333
|
+
}),
|
|
333
334
|
);
|
|
334
335
|
return agentGetEntanglementProofs;
|
|
335
336
|
}
|
|
336
337
|
|
|
337
338
|
async entanglementProofPreFlight(
|
|
338
339
|
deviceKey: string,
|
|
339
|
-
deviceKeyType: string
|
|
340
|
+
deviceKeyType: string,
|
|
340
341
|
): Promise<EntanglementProof> {
|
|
341
342
|
const { agentEntanglementProofPreFlight } = unwrapApolloResult(
|
|
342
|
-
await this
|
|
343
|
+
await this._apolloClient.mutate({
|
|
343
344
|
mutation: gql`mutation agentEntanglementProofPreFlight($deviceKey: String!, $deviceKeyType: String!) {
|
|
344
345
|
agentEntanglementProofPreFlight(deviceKey: $deviceKey, deviceKeyType: $deviceKeyType) {
|
|
345
346
|
${ENTANGLEMENT_PROOF_FIELDS}
|
|
346
347
|
}
|
|
347
348
|
}`,
|
|
348
349
|
variables: { deviceKey, deviceKeyType },
|
|
349
|
-
})
|
|
350
|
+
}),
|
|
350
351
|
);
|
|
351
352
|
return agentEntanglementProofPreFlight;
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
addUpdatedListener(listener) {
|
|
355
|
-
this
|
|
356
|
+
this._updatedCallbacks.push(listener);
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
addAppChangedListener(listener) {
|
|
359
|
-
this
|
|
360
|
+
this._appsChangedCallback.push(listener);
|
|
360
361
|
}
|
|
361
362
|
|
|
362
363
|
subscribeAgentUpdated() {
|
|
363
|
-
this
|
|
364
|
+
this._apolloClient
|
|
364
365
|
.subscribe({
|
|
365
366
|
query: gql` subscription {
|
|
366
367
|
agentUpdated { ${AGENT_SUBITEMS} }
|
|
@@ -370,16 +371,18 @@ export class AgentClient {
|
|
|
370
371
|
.subscribe({
|
|
371
372
|
next: (result) => {
|
|
372
373
|
const agent = result.data.agentUpdated;
|
|
373
|
-
this
|
|
374
|
+
this._updatedCallbacks.forEach((cb) => {
|
|
374
375
|
cb(agent);
|
|
375
376
|
});
|
|
376
377
|
},
|
|
377
|
-
error: (e) =>
|
|
378
|
+
error: (e) => {
|
|
379
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
380
|
+
},
|
|
378
381
|
});
|
|
379
382
|
}
|
|
380
383
|
|
|
381
384
|
subscribeAppsChanged() {
|
|
382
|
-
this
|
|
385
|
+
this._apolloClient
|
|
383
386
|
.subscribe({
|
|
384
387
|
query: gql` subscription {
|
|
385
388
|
agentAppsChanged {
|
|
@@ -390,20 +393,22 @@ export class AgentClient {
|
|
|
390
393
|
})
|
|
391
394
|
.subscribe({
|
|
392
395
|
next: (result) => {
|
|
393
|
-
this
|
|
396
|
+
this._appsChangedCallback.forEach((cb) => {
|
|
394
397
|
cb();
|
|
395
398
|
});
|
|
396
399
|
},
|
|
397
|
-
error: (e) =>
|
|
400
|
+
error: (e) => {
|
|
401
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
402
|
+
},
|
|
398
403
|
});
|
|
399
404
|
}
|
|
400
405
|
|
|
401
406
|
addAgentStatusChangedListener(listener) {
|
|
402
|
-
this
|
|
407
|
+
this._agentStatusChangedCallbacks.push(listener);
|
|
403
408
|
}
|
|
404
409
|
|
|
405
410
|
subscribeAgentStatusChanged() {
|
|
406
|
-
this
|
|
411
|
+
this._apolloClient
|
|
407
412
|
.subscribe({
|
|
408
413
|
query: gql` subscription {
|
|
409
414
|
agentStatusChanged { ${AGENT_STATUS_FIELDS} }
|
|
@@ -413,178 +418,218 @@ export class AgentClient {
|
|
|
413
418
|
.subscribe({
|
|
414
419
|
next: (result) => {
|
|
415
420
|
const agent = result.data.agentStatusChanged;
|
|
416
|
-
this
|
|
421
|
+
this._agentStatusChangedCallbacks.forEach((cb) => {
|
|
417
422
|
cb(agent);
|
|
418
423
|
});
|
|
419
424
|
},
|
|
420
|
-
error: (e) =>
|
|
425
|
+
error: (e) => {
|
|
426
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
427
|
+
},
|
|
421
428
|
});
|
|
422
429
|
}
|
|
423
430
|
|
|
424
431
|
async requestCapability(authInfo: AuthInfoInput): Promise<string> {
|
|
425
432
|
const { agentRequestCapability } = unwrapApolloResult(
|
|
426
|
-
await this
|
|
433
|
+
await this._apolloClient.mutate({
|
|
427
434
|
mutation: gql`
|
|
428
435
|
mutation agentRequestCapability($authInfo: AuthInfoInput!) {
|
|
429
436
|
agentRequestCapability(authInfo: $authInfo)
|
|
430
437
|
}
|
|
431
438
|
`,
|
|
432
439
|
variables: { authInfo },
|
|
433
|
-
})
|
|
440
|
+
}),
|
|
434
441
|
);
|
|
435
442
|
return agentRequestCapability;
|
|
436
443
|
}
|
|
437
444
|
|
|
438
445
|
async permitCapability(auth: string): Promise<string> {
|
|
439
446
|
const { agentPermitCapability } = unwrapApolloResult(
|
|
440
|
-
await this
|
|
447
|
+
await this._apolloClient.mutate({
|
|
441
448
|
mutation: gql`
|
|
442
449
|
mutation agentPermitCapability($auth: String!) {
|
|
443
450
|
agentPermitCapability(auth: $auth)
|
|
444
451
|
}
|
|
445
452
|
`,
|
|
446
453
|
variables: { auth },
|
|
447
|
-
})
|
|
454
|
+
}),
|
|
448
455
|
);
|
|
449
456
|
return agentPermitCapability;
|
|
450
457
|
}
|
|
451
458
|
|
|
452
459
|
async generateJwt(requestId: string, rand: string): Promise<string> {
|
|
453
460
|
const { agentGenerateJwt } = unwrapApolloResult(
|
|
454
|
-
await this
|
|
461
|
+
await this._apolloClient.mutate({
|
|
455
462
|
mutation: gql`
|
|
456
463
|
mutation agentGenerateJwt($requestId: String!, $rand: String!) {
|
|
457
464
|
agentGenerateJwt(requestId: $requestId, rand: $rand)
|
|
458
465
|
}
|
|
459
466
|
`,
|
|
460
467
|
variables: { requestId, rand },
|
|
461
|
-
})
|
|
468
|
+
}),
|
|
462
469
|
);
|
|
463
470
|
return agentGenerateJwt;
|
|
464
471
|
}
|
|
465
472
|
|
|
466
473
|
async getApps(): Promise<Apps[]> {
|
|
467
474
|
const { agentGetApps } = unwrapApolloResult(
|
|
468
|
-
await this
|
|
475
|
+
await this._apolloClient.mutate({
|
|
469
476
|
mutation: gql`query agentGetApps {
|
|
470
477
|
agentGetApps {
|
|
471
478
|
${Apps_FIELDS}
|
|
472
479
|
}
|
|
473
480
|
}`,
|
|
474
|
-
})
|
|
481
|
+
}),
|
|
475
482
|
);
|
|
476
483
|
return agentGetApps;
|
|
477
484
|
}
|
|
478
485
|
|
|
479
486
|
async removeApp(requestId: string): Promise<Apps[]> {
|
|
480
487
|
const { agentRemoveApp } = unwrapApolloResult(
|
|
481
|
-
await this
|
|
488
|
+
await this._apolloClient.mutate({
|
|
482
489
|
mutation: gql`mutation agentRemoveApp($requestId: String!) {
|
|
483
490
|
agentRemoveApp(requestId: $requestId) {
|
|
484
491
|
${Apps_FIELDS}
|
|
485
492
|
}
|
|
486
493
|
}`,
|
|
487
494
|
variables: { requestId },
|
|
488
|
-
})
|
|
495
|
+
}),
|
|
489
496
|
);
|
|
490
497
|
return agentRemoveApp;
|
|
491
498
|
}
|
|
492
499
|
|
|
493
500
|
async revokeToken(requestId: string): Promise<Apps[]> {
|
|
494
501
|
const { agentRevokeToken } = unwrapApolloResult(
|
|
495
|
-
await this
|
|
502
|
+
await this._apolloClient.mutate({
|
|
496
503
|
mutation: gql`mutation agentRevokeToken($requestId: String!) {
|
|
497
504
|
agentRevokeToken(requestId: $requestId) {
|
|
498
505
|
${Apps_FIELDS}
|
|
499
506
|
}
|
|
500
507
|
}`,
|
|
501
508
|
variables: { requestId },
|
|
502
|
-
})
|
|
509
|
+
}),
|
|
503
510
|
);
|
|
504
511
|
return agentRevokeToken;
|
|
505
512
|
}
|
|
506
513
|
|
|
507
514
|
async isLocked(): Promise<boolean> {
|
|
508
515
|
const { agentIsLocked } = unwrapApolloResult(
|
|
509
|
-
await this
|
|
516
|
+
await this._apolloClient.mutate({
|
|
510
517
|
mutation: gql`
|
|
511
518
|
query agentIsLocked {
|
|
512
519
|
agentIsLocked
|
|
513
520
|
}
|
|
514
521
|
`,
|
|
515
|
-
})
|
|
522
|
+
}),
|
|
516
523
|
);
|
|
517
524
|
return agentIsLocked;
|
|
518
525
|
}
|
|
519
526
|
|
|
520
527
|
async signMessage(message: string): Promise<string> {
|
|
521
528
|
const { agentSignMessage } = unwrapApolloResult(
|
|
522
|
-
await this
|
|
529
|
+
await this._apolloClient.mutate({
|
|
523
530
|
mutation: gql`mutation agentSignMessage($message: String!) {
|
|
524
531
|
agentSignMessage(message: $message) {
|
|
525
532
|
${AGENT_SIGNATURE_FIELDS}
|
|
526
533
|
}
|
|
527
534
|
}`,
|
|
528
535
|
variables: { message },
|
|
529
|
-
})
|
|
536
|
+
}),
|
|
530
537
|
);
|
|
531
538
|
return agentSignMessage;
|
|
532
539
|
}
|
|
533
540
|
|
|
534
541
|
// Multi-user methods
|
|
535
|
-
async createUser(
|
|
542
|
+
async createUser(
|
|
543
|
+
email: string,
|
|
544
|
+
password: string,
|
|
545
|
+
appInfo?: AuthInfoInput,
|
|
546
|
+
): Promise<UserCreationResult> {
|
|
536
547
|
const { runtimeCreateUser } = unwrapApolloResult(
|
|
537
|
-
await this
|
|
538
|
-
mutation: gql`
|
|
539
|
-
runtimeCreateUser(
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
548
|
+
await this._apolloClient.mutate({
|
|
549
|
+
mutation: gql`
|
|
550
|
+
mutation runtimeCreateUser(
|
|
551
|
+
$email: String!
|
|
552
|
+
$password: String!
|
|
553
|
+
$appInfo: AuthInfoInput
|
|
554
|
+
) {
|
|
555
|
+
runtimeCreateUser(
|
|
556
|
+
email: $email
|
|
557
|
+
password: $password
|
|
558
|
+
appInfo: $appInfo
|
|
559
|
+
) {
|
|
560
|
+
did
|
|
561
|
+
success
|
|
562
|
+
error
|
|
563
|
+
}
|
|
543
564
|
}
|
|
544
|
-
|
|
565
|
+
`,
|
|
545
566
|
variables: { email, password, appInfo },
|
|
546
|
-
})
|
|
567
|
+
}),
|
|
547
568
|
);
|
|
548
569
|
return runtimeCreateUser;
|
|
549
570
|
}
|
|
550
571
|
|
|
551
572
|
async loginUser(email: string, password: string): Promise<string> {
|
|
552
573
|
const { runtimeLoginUser } = unwrapApolloResult(
|
|
553
|
-
await this
|
|
554
|
-
mutation: gql`
|
|
555
|
-
runtimeLoginUser(email: $
|
|
556
|
-
|
|
574
|
+
await this._apolloClient.mutate({
|
|
575
|
+
mutation: gql`
|
|
576
|
+
mutation runtimeLoginUser($email: String!, $password: String!) {
|
|
577
|
+
runtimeLoginUser(email: $email, password: $password)
|
|
578
|
+
}
|
|
579
|
+
`,
|
|
557
580
|
variables: { email, password },
|
|
558
|
-
})
|
|
581
|
+
}),
|
|
559
582
|
);
|
|
560
583
|
return runtimeLoginUser;
|
|
561
584
|
}
|
|
562
585
|
|
|
563
|
-
async requestLoginVerification(
|
|
586
|
+
async requestLoginVerification(
|
|
587
|
+
email: string,
|
|
588
|
+
appInfo?: AuthInfoInput,
|
|
589
|
+
): Promise<VerificationRequestResult> {
|
|
564
590
|
const { runtimeRequestLoginVerification } = unwrapApolloResult(
|
|
565
|
-
await this
|
|
566
|
-
mutation: gql`
|
|
567
|
-
runtimeRequestLoginVerification(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
591
|
+
await this._apolloClient.mutate({
|
|
592
|
+
mutation: gql`
|
|
593
|
+
mutation runtimeRequestLoginVerification(
|
|
594
|
+
$email: String!
|
|
595
|
+
$appInfo: AuthInfoInput
|
|
596
|
+
) {
|
|
597
|
+
runtimeRequestLoginVerification(email: $email, appInfo: $appInfo) {
|
|
598
|
+
success
|
|
599
|
+
message
|
|
600
|
+
requiresPassword
|
|
601
|
+
isExistingUser
|
|
602
|
+
}
|
|
572
603
|
}
|
|
573
|
-
|
|
604
|
+
`,
|
|
574
605
|
variables: { email, appInfo },
|
|
575
|
-
})
|
|
606
|
+
}),
|
|
576
607
|
);
|
|
577
608
|
return runtimeRequestLoginVerification;
|
|
578
609
|
}
|
|
579
610
|
|
|
580
|
-
async verifyEmailCode(
|
|
611
|
+
async verifyEmailCode(
|
|
612
|
+
email: string,
|
|
613
|
+
code: string,
|
|
614
|
+
verificationType: string,
|
|
615
|
+
): Promise<string> {
|
|
581
616
|
const { runtimeVerifyEmailCode } = unwrapApolloResult(
|
|
582
|
-
await this
|
|
583
|
-
mutation: gql`
|
|
584
|
-
runtimeVerifyEmailCode(
|
|
585
|
-
|
|
617
|
+
await this._apolloClient.mutate({
|
|
618
|
+
mutation: gql`
|
|
619
|
+
mutation runtimeVerifyEmailCode(
|
|
620
|
+
$email: String!
|
|
621
|
+
$code: String!
|
|
622
|
+
$verificationType: String!
|
|
623
|
+
) {
|
|
624
|
+
runtimeVerifyEmailCode(
|
|
625
|
+
email: $email
|
|
626
|
+
code: $code
|
|
627
|
+
verificationType: $verificationType
|
|
628
|
+
)
|
|
629
|
+
}
|
|
630
|
+
`,
|
|
586
631
|
variables: { email, code, verificationType },
|
|
587
|
-
})
|
|
632
|
+
}),
|
|
588
633
|
);
|
|
589
634
|
return runtimeVerifyEmailCode;
|
|
590
635
|
}
|