Skip to content

Commit

Permalink
feat(action-menu)!: move to separate package (#1049)
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>

BREAKING CHANGE: action-menu module has been removed from the core and moved to a separate package. To integrate it in an Agent instance, it can be injected in constructor like this:
```ts
const agent = new Agent({
  config: { /* config */ },
  dependencies: agentDependencies,
  modules: {
    actionMenu: new ActionMenuModule(),
    /* other custom modules */
   }
})
```

Then, module API can be accessed in `agent.modules.actionMenu`.
  • Loading branch information
genaris authored Oct 12, 2022
1 parent 97d3073 commit e0df0d8
Show file tree
Hide file tree
Showing 49 changed files with 350 additions and 200 deletions.
78 changes: 78 additions & 0 deletions packages/action-menu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<p align="center">
<br />
<img
alt="Hyperledger Aries logo"
src="https://raw.githubusercontent.com/hyperledger/aries-framework-javascript/aa31131825e3331dc93694bc58414d955dcb1129/images/aries-logo.png"
height="250px"
/>
</p>
<h1 align="center"><b>Aries Framework JavaScript Action Menu Plugin</b></h1>
<p align="center">
<a
href="https://raw.githubusercontent.com/hyperledger/aries-framework-javascript/main/LICENSE"
><img
alt="License"
src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"
/></a>
<a href="https://www.typescriptlang.org/"
><img
alt="typescript"
src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg"
/></a>
<a href="https://www.npmjs.com/package/@aries-framework/action-menu"
><img
alt="@aries-framework/action-menu version"
src="https://img.shields.io/npm/v/@aries-framework/action-menu"
/></a>

</p>
<br />

Action Menu plugin for [Aries Framework JavaScript](https://github.com/hyperledger/aries-framework-javascript.git). Implements [Aries RFC 0509](https://github.com/hyperledger/aries-rfcs/blob/1795d5c2d36f664f88f5e8045042ace8e573808c/features/0509-action-menu/README.md).

### Installation

Make sure you have set up the correct version of Aries Framework JavaScript according to the AFJ repository. To find out which version of AFJ you need to have installed you can run the following command. This will list the required peer dependency for `@aries-framework/core`.

```sh
npm info "@aries-framework/action-menu" peerDependencies
```

Then add the action-menu plugin to your project.

```sh
yarn add @aries-framework/action-menu
```

### Quick start

In order for this plugin to work, we have to inject it into the agent to access agent functionality. See the example for more information.

### Example of usage

```ts
import { ActionMenuModule } from '@aries-framework/action-menu'

const agent = new Agent({
config: {
/* config */
},
dependencies: agentDependencies,
modules: {
actionMenu: new ActionMenuModule(),
/* other custom modules */
},
})

await agent.initialize()

// To request root menu to a given connection (menu will be received
// asynchronously in a ActionMenuStateChangedEvent)
await agent.modules.actionMenu.requestMenu({ connectionId })

// To select an option from the action menu
await agent.modules.actionMenu.performAction({
connectionId,
performedAction: { name: 'option-1' },
})
```
13 changes: 13 additions & 0 deletions packages/action-menu/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from '@jest/types'

import base from '../../jest.config.base'

import packageJson from './package.json'

const config: Config.InitialOptions = {
...base,
name: packageJson.name,
displayName: packageJson.name,
}

export default config
41 changes: 41 additions & 0 deletions packages/action-menu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@aries-framework/action-menu",
"main": "build/index",
"types": "build/index",
"version": "0.2.4",
"private": true,
"files": [
"build"
],
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/hyperledger/aries-framework-javascript/tree/main/packages/action-menu",
"repository": {
"type": "git",
"url": "https://github.com/hyperledger/aries-framework-javascript",
"directory": "packages/action-menu"
},
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./build",
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
"test": "jest"
},
"dependencies": {
"rxjs": "^7.2.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.1"
},
"peerDependencies": {
"@aries-framework/core": "0.2.4"
},
"devDependencies": {
"@aries-framework/node": "0.2.4",
"reflect-metadata": "^0.1.13",
"rimraf": "~3.0.2",
"typescript": "~4.3.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import type {
SendMenuOptions,
} from './ActionMenuApiOptions'

import { AgentContext } from '../../agent'
import { Dispatcher } from '../../agent/Dispatcher'
import { MessageSender } from '../../agent/MessageSender'
import { createOutboundMessage } from '../../agent/helpers'
import { AriesFrameworkError } from '../../error'
import { injectable } from '../../plugins'
import { ConnectionService } from '../connections/services'
import {
AgentContext,
AriesFrameworkError,
ConnectionService,
Dispatcher,
MessageSender,
createOutboundMessage,
injectable,
} from '@aries-framework/core'

import { ActionMenuRole } from './ActionMenuRole'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ActionMenuRole } from './ActionMenuRole'
import type { ActionMenu } from './models/ActionMenu'
import type { ActionMenuSelection } from './models/ActionMenuSelection'
import type { ActionMenu, ActionMenuSelection } from './models'

export interface FindActiveMenuOptions {
connectionId: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BaseEvent } from '../../agent/Events'
import type { ActionMenuState } from './ActionMenuState'
import type { ActionMenuRecord } from './repository'
import type { BaseEvent } from '@aries-framework/core'

export enum ActionMenuEventTypes {
ActionMenuStateChanged = 'ActionMenuStateChanged',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FeatureRegistry } from '../../agent/FeatureRegistry'
import type { DependencyManager, Module } from '../../plugins'
import type { DependencyManager, FeatureRegistry, Module } from '@aries-framework/core'

import { Protocol } from '../../agent/models'
import { Protocol } from '@aries-framework/core'

import { ActionMenuApi } from './ActionMenuApi'
import { ActionMenuRole } from './ActionMenuRole'
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions packages/action-menu/src/__tests__/ActionMenuModule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { DependencyManager, FeatureRegistry } from '@aries-framework/core'

import { Protocol } from '@aries-framework/core'

import {
ActionMenuApi,
ActionMenuModule,
ActionMenuRepository,
ActionMenuRole,
ActionMenuService,
} from '@aries-framework/action-menu'

const dependencyManager = {
registerInstance: jest.fn(),
registerSingleton: jest.fn(),
registerContextScoped: jest.fn(),
} as unknown as DependencyManager

const featureRegistry = {
register: jest.fn(),
} as unknown as FeatureRegistry

describe('ActionMenuModule', () => {
test('registers dependencies on the dependency manager', () => {
const actionMenuModule = new ActionMenuModule()
actionMenuModule.register(dependencyManager, featureRegistry)

expect(dependencyManager.registerContextScoped).toHaveBeenCalledTimes(1)
expect(dependencyManager.registerContextScoped).toHaveBeenCalledWith(ActionMenuApi)

expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(2)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuService)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuRepository)

expect(featureRegistry.register).toHaveBeenCalledTimes(1)
expect(featureRegistry.register).toHaveBeenCalledWith(
new Protocol({
id: 'https://didcomm.org/action-menu/1.0',
roles: [ActionMenuRole.Requester, ActionMenuRole.Responder],
})
)
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ProblemReportErrorOptions } from '../../problem-reports'
import type { ActionMenuProblemReportReason } from './ActionMenuProblemReportReason'
import type { ProblemReportErrorOptions } from '@aries-framework/core'

import { ProblemReportError } from '@aries-framework/core'

import { ProblemReportError } from '../../problem-reports'
import { ActionMenuProblemReportMessage } from '../messages'

interface ActionMenuProblemReportErrorOptions extends ProblemReportErrorOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { ActionMenuService } from '../services'
import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { ActionMenuProblemReportMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { ActionMenuService } from '../services'
import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { MenuMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { ActionMenuService } from '../services'
import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { MenuRequestMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { ActionMenuService } from '../services'
import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { PerformMessage } from '../messages'

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ProblemReportMessageOptions } from '../../problem-reports/messages/ProblemReportMessage'
import type { ProblemReportMessageOptions } from '@aries-framework/core'

import { IsValidMessageType, parseMessageType } from '../../../utils/messageType'
import { ProblemReportMessage } from '../../problem-reports/messages/ProblemReportMessage'
import { IsValidMessageType, parseMessageType, ProblemReportMessage } from '@aries-framework/core'

export type ActionMenuProblemReportMessageOptions = ProblemReportMessageOptions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ActionMenuOptionOptions } from '../models'

import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { Expose, Type } from 'class-transformer'
import { IsInstance, IsOptional, IsString } from 'class-validator'

import { AgentMessage } from '../../../agent/AgentMessage'
import { IsValidMessageType, parseMessageType } from '../../../utils/messageType'
import { ActionMenuOption } from '../models'

export interface MenuMessageOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AgentMessage } from '../../../agent/AgentMessage'
import { IsValidMessageType, parseMessageType } from '../../../utils/messageType'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'

export interface MenuRequestMessageOptions {
id?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { IsOptional, IsString } from 'class-validator'

import { AgentMessage } from '../../../agent/AgentMessage'
import { IsValidMessageType, parseMessageType } from '../../../utils/messageType'

export interface PerformMessageOptions {
id?: string
name: string
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { TagsBase } from '../../../storage/BaseRecord'
import type { ActionMenuRole } from '../ActionMenuRole'
import type { ActionMenuState } from '../ActionMenuState'
import type { TagsBase } from '@aries-framework/core'

import { AriesFrameworkError, BaseRecord, utils } from '@aries-framework/core'
import { Type } from 'class-transformer'

import { AriesFrameworkError } from '../../../error'
import { BaseRecord } from '../../../storage/BaseRecord'
import { uuid } from '../../../utils/uuid'
import { ActionMenuSelection, ActionMenu } from '../models'

export interface ActionMenuRecordProps {
Expand Down Expand Up @@ -51,7 +49,7 @@ export class ActionMenuRecord
super()

if (props) {
this.id = props.id ?? uuid()
this.id = props.id ?? utils.uuid()
this.createdAt = props.createdAt ?? new Date()
this.connectionId = props.connectionId
this.threadId = props.threadId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { EventEmitter } from '../../../agent/EventEmitter'
import { InjectionSymbols } from '../../../constants'
import { inject, injectable } from '../../../plugins'
import { Repository } from '../../../storage/Repository'
import { StorageService } from '../../../storage/StorageService'
import { EventEmitter, InjectionSymbols, inject, injectable, Repository, StorageService } from '@aries-framework/core'

import { ActionMenuRecord } from './ActionMenuRecord'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type { AgentContext } from '../../../agent'
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { Query } from '../../../storage/StorageService'
import type { ActionMenuStateChangedEvent } from '../ActionMenuEvents'
import type { ActionMenuProblemReportMessage } from '../messages'
import type {
Expand All @@ -11,12 +7,10 @@ import type {
CreateRequestOptions,
FindMenuOptions,
} from './ActionMenuServiceOptions'
import type { AgentContext, InboundMessageContext, Logger, Query } from '@aries-framework/core'

import { AgentConfig, EventEmitter, AriesFrameworkError, injectable, JsonTransformer } from '@aries-framework/core'

import { AgentConfig } from '../../../agent/AgentConfig'
import { EventEmitter } from '../../../agent/EventEmitter'
import { AriesFrameworkError } from '../../../error'
import { injectable } from '../../../plugins'
import { JsonTransformer } from '../../../utils'
import { ActionMenuEventTypes } from '../ActionMenuEvents'
import { ActionMenuRole } from '../ActionMenuRole'
import { ActionMenuState } from '../ActionMenuState'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ConnectionRecord } from '../../connections'
import type { ActionMenuRole } from '../ActionMenuRole'
import type { ActionMenuSelection } from '../models'
import type { ActionMenu } from '../models/ActionMenu'
import type { ActionMenuRecord } from '../repository'
import type { ConnectionRecord } from '@aries-framework/core'

export interface CreateRequestOptions {
connection: ConnectionRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { AgentContext } from '../../../../agent'
import type { AgentConfig } from '../../../../agent/AgentConfig'
import type { Repository } from '../../../../storage/Repository'
import type { ActionMenuStateChangedEvent } from '../../ActionMenuEvents'
import type { ActionMenuSelection } from '../../models'
import type { AgentContext, AgentConfig, Repository } from '@aries-framework/core'

import { DidExchangeState, EventEmitter, InboundMessageContext } from '@aries-framework/core'
import { Subject } from 'rxjs'

import {
Expand All @@ -12,10 +11,7 @@ import {
getAgentContext,
getMockConnection,
mockFunction,
} from '../../../../../tests/helpers'
import { EventEmitter } from '../../../../agent/EventEmitter'
import { InboundMessageContext } from '../../../../agent/models/InboundMessageContext'
import { DidExchangeState } from '../../../connections'
} from '../../../../core/tests/helpers'
import { ActionMenuEventTypes } from '../../ActionMenuEvents'
import { ActionMenuRole } from '../../ActionMenuRole'
import { ActionMenuState } from '../../ActionMenuState'
Expand Down
File renamed without changes.
Loading

0 comments on commit e0df0d8

Please sign in to comment.