@awarevue/agent-sdk 1.0.1 → 1.0.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.
@@ -1,10 +1,11 @@
1
1
  import { Transport } from './transport';
2
- import { ProviderSpecs, PushEventRq, PushStateUpdateRq } from '@awarevue/api-types';
2
+ import { AccessControlCapabilityReport, ProviderSpecs, PushEventRq, PushStateUpdateRq } from '@awarevue/api-types';
3
3
  import { Agent } from './agent';
4
4
  export type DeviceActivity = Omit<PushStateUpdateRq, 'provider'> | Omit<PushEventRq, 'provider'>;
5
5
  export type AgentOptions = {
6
6
  version: number;
7
7
  providers: Record<string, ProviderSpecs>;
8
+ accessControlProviders?: Record<string, AccessControlCapabilityReport>;
8
9
  agentId: string;
9
10
  replyTimeout?: number;
10
11
  transport: Transport;
package/dist/agent-app.js CHANGED
@@ -33,10 +33,12 @@ class AgentApp {
33
33
  });
34
34
  this.runProvider$ = (context) => {
35
35
  return (0, rxjs_1.merge)(
36
- // run the agent
36
+ // run the agent monitor
37
37
  this.agent
38
38
  .run$(context)
39
- .pipe((0, rxjs_1.tap)((message) => this.options.transport.send(this.addEnvelope({ ...message, provider: context.provider })))), this.options.transport.messages$.pipe((0, rxjs_1.mergeMap)((message) => {
39
+ .pipe((0, rxjs_1.tap)((message) => this.options.transport.send(this.addEnvelope({ ...message, provider: context.provider })))),
40
+ // handle messages to agent
41
+ this.options.transport.messages$.pipe((0, rxjs_1.mergeMap)((message) => {
40
42
  switch (message.kind) {
41
43
  // handle commands
42
44
  case 'command':
@@ -75,6 +77,46 @@ class AgentApp {
75
77
  error: (_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error',
76
78
  });
77
79
  }), (0, rxjs_1.tap)((rs) => this.options.transport.send(this.addEnvelope(rs))));
80
+ case 'validate-change':
81
+ // validate access change
82
+ const validateOb$ = !this.agent.validateAccessChange$
83
+ ? (0, rxjs_1.throwError)(() => new Error(`Agent ${context.provider} does not support access change validation`))
84
+ : this.agent.validateAccessChange$(context, message);
85
+ return validateOb$.pipe((0, rxjs_1.map)((issues) => ({
86
+ kind: 'validate-change-rs',
87
+ requestId: message.id,
88
+ issues,
89
+ })), (0, rxjs_1.catchError)((error) => {
90
+ var _a;
91
+ return (0, rxjs_1.of)({
92
+ kind: 'error-rs',
93
+ requestId: message.id,
94
+ error: (_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error',
95
+ });
96
+ }), (0, rxjs_1.tap)((rs) => this.options.transport.send(this.addEnvelope(rs))));
97
+ case 'apply-change':
98
+ // apply access change
99
+ const applyOb$ = !this.agent.applyAccessChange$
100
+ ? (0, rxjs_1.throwError)(() => new Error(`Agent ${context.provider} does not support access change application`))
101
+ : this.agent.applyAccessChange$(context, message);
102
+ return applyOb$.pipe((0, rxjs_1.map)((result) => typeof result === 'number'
103
+ ? {
104
+ kind: 'apply-change-progress',
105
+ requestId: message.id,
106
+ mutationIndex: result,
107
+ }
108
+ : {
109
+ kind: 'apply-change-complete',
110
+ requestId: message.id,
111
+ refs: result,
112
+ }), (0, rxjs_1.catchError)((error) => {
113
+ var _a;
114
+ return (0, rxjs_1.of)({
115
+ kind: 'error-rs',
116
+ requestId: message.id,
117
+ error: (_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error',
118
+ });
119
+ }), (0, rxjs_1.tap)((rs) => this.options.transport.send(this.addEnvelope(rs))));
78
120
  default:
79
121
  return rxjs_1.EMPTY;
80
122
  }
@@ -85,6 +127,7 @@ class AgentApp {
85
127
  ? this.getReply$('register-rs', {
86
128
  kind: 'register',
87
129
  providers: this.options.providers,
130
+ accessControlProviders: this.options.accessControlProviders,
88
131
  }).pipe((0, rxjs_1.retry)({ delay: 3000 }))
89
132
  : rxjs_1.EMPTY));
90
133
  const startStop$ = this.options.transport.messages$.pipe((0, rxjs_1.filter)((message) => message.kind === 'start' || message.kind === 'stop'), (0, rxjs_1.switchMap)((message) => message.kind === 'start'
package/dist/agent.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ValidateProviderConfigRs, DeviceDiscoveryDto, RunCommandRq } from '@awarevue/api-types';
1
+ import { ValidateProviderConfigRs, DeviceDiscoveryDto, RunCommandRq, AccessValidateChangeRq, AccessChangeIssue, AccessApplyChange } from '@awarevue/api-types';
2
2
  import { Observable } from 'rxjs';
3
3
  import { DeviceActivity } from './agent-app';
4
4
  export type Context = {
@@ -14,4 +14,6 @@ export interface Agent {
14
14
  getDevicesAndRelations$: (context: Context) => Observable<DeviceDiscoveryDto>;
15
15
  run$: (context: RunContext) => Observable<DeviceActivity>;
16
16
  runCommand$: (context: Context, command: RunCommandRq) => Observable<unknown>;
17
+ validateAccessChange$?: (context: Context, change: AccessValidateChangeRq) => Observable<AccessChangeIssue[]>;
18
+ applyAccessChange$?: (context: Context, change: AccessApplyChange) => Observable<number | Record<string, Record<string, string>>>;
17
19
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/agent-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "SDK for building Agent implementations that speak the Aware protocol.",
5
5
  "author": "Yaser Awajan",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/agent-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "SDK for building Agent implementations that speak the Aware protocol.",
5
5
  "author": "Yaser Awajan",
6
6
  "license": "MIT",