Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
feat: update to AFJ 0.4.0, fix timestamp and update protocol pid
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Jun 22, 2023
1 parent 31f61f5 commit d769c14
Show file tree
Hide file tree
Showing 14 changed files with 1,258 additions and 1,380 deletions.
18 changes: 0 additions & 18 deletions .github/actions/setup-libindy/action.yml

This file was deleted.

35 changes: 10 additions & 25 deletions .github/workflows/release-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ concurrency:

jobs:
validate:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Validate
steps:
- name: Checkout aries-javascript-receipts
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -34,14 +34,10 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v16
uses: actions/setup-node@v2
- name: Setup node v18
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: yarn install
Expand All @@ -52,13 +48,13 @@ jobs:
- name: Check typescript
run: yarn check-types
release:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
environment: NPM
name: Release
needs: [validate]
steps:
- name: Checkout aries-javascript-receipts
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -78,25 +74,14 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v16
uses: actions/setup-node@v2
- name: Setup node v18
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: yarn install

# https://github.com/yarnpkg/yarn/issues/6617#issuecomment-436222106
- name: Prepend Node path
run: npm config set scripts-prepend-node-path true

- name: Set Verbose Logging
run: npm config set loglevel verbose --global

- name: Set NPM config
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> .npmrc
Expand Down
33 changes: 9 additions & 24 deletions .github/workflows/release-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ concurrency:

jobs:
validate:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Validate
steps:
- name: Checkout aries-javascript-receipts
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -38,14 +38,10 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v16
uses: actions/setup-node@v2
- name: Setup node v18
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: yarn install
Expand All @@ -56,7 +52,7 @@ jobs:
- name: Check typescript
run: yarn check-types
release:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Release
needs: [validate]
# Only run on workflow dispatch to main branch
Expand All @@ -83,25 +79,14 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v16
uses: actions/setup-node@v2
- name: Setup node v18
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: yarn install

# https://github.com/yarnpkg/yarn/issues/6617#issuecomment-436222106
- name: Prepend Node path
run: npm config set scripts-prepend-node-path true

- name: Set Verbose Logging
run: npm config set loglevel verbose --global

- name: Set NPM config
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> .npmrc
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Message Receipts plug-in for Aries Framework JavaScript
# Message Receipts extension module for Aries Framework JavaScript

This module is used to provide an Aries Agent built with Aries Framework JavaScript means to manage [Message Receipts protocol](https://github.com/2060-io/aries-rfcs/tree/feature/receipts/features/xxxx-receipts).
This module is used to provide an Aries Agent built with Aries Framework JavaScript means to manage [Message Receipts protocol](https://github.com/genaris/didcomm.org/tree/feat/receipts/site/content/protocols/receipts/1.0).

It's conceived as a plug-in for Aries Framework JavaScript which can be injected to an existing agent instance:
It's conceived as an extension module for Aries Framework JavaScript which can be injected to an existing agent instance:

```ts
import { ReceiptsModule } from 'aries-javascript-receipts'
Expand Down
12 changes: 6 additions & 6 deletions jest.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
coveragePathIgnorePatterns: ['/build/', '/node_modules/', '/__tests__/', 'test'],
coverageDirectory: '<rootDir>/coverage/',
verbose: true,
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
moduleNameMapper: {
'@2060-agent-sdk/(.+)': [
'<rootDir>/../../packages/$1/src',
'<rootDir>/../packages/$1/src',
'<rootDir>/packages/$1/src',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
isolatedModules: true,
},
],
},
}
Expand Down
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import packageJson from './package.json'

const config: Config.InitialOptions = {
...base,
name: packageJson.name,
displayName: packageJson.name,
setupFilesAfterEnv: ['./test/setup.ts'],
testTimeout: 15000,
Expand Down
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"check-types": "tsc --noEmit -p tsconfig.build.json",
"check-format": "yarn prettier --check",
"prettier": "prettier --ignore-path .gitignore '**/*.+(js|json|ts|md|yml|yaml)'",
"release": "release-it"
"release": "release-it",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -32,28 +33,35 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@aries-framework/node": "^0.3.0",
"@aries-framework/askar": "^0.4.0",
"@aries-framework/node": "^0.4.0",
"@hyperledger/aries-askar-nodejs": "^0.1.0",
"@types/jest": "^26.0.23",
"@types/node": "^16.11.7",
"@types/node-fetch": "^2.6.4",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.17.0",
"release-it": "^14.13.1",
"jest": "^27.0.4",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"jest": "^29.5.0",
"prettier": "^2.2.1",
"ts-jest": "^27.0.3",
"release-it": "^14.13.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.8.1",
"tsconfig-paths": "^3.10.1",
"typescript": "~4.3.0"
"tsconfig-paths": "^4.1.2",
"typescript": "~4.9.4"
},
"dependencies": {
"@aries-framework/core": "^0.3.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.1",
"@aries-framework/core": "^0.4.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"tsyringe": "^4.6.0",
"tsyringe": "^4.7.0",
"uuid": "^9.0.0"
},
"resolutions": {
"ref-napi": "npm:@2060.io/ref-napi"
},
"release-it": {
"github": {
"release": true
Expand Down
8 changes: 1 addition & 7 deletions src/ReceiptsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
AriesFrameworkError,
ConnectionService,
injectable,
Dispatcher,
MessageSender,
AgentContext,
OutboundMessageContext,
Expand All @@ -20,7 +19,6 @@ export class ReceiptsApi {

public constructor(
agentContext: AgentContext,
dispatcher: Dispatcher,
messageSender: MessageSender,
receiptsService: ReceiptsService,
connectionService: ConnectionService
Expand All @@ -29,7 +27,7 @@ export class ReceiptsApi {
this.messageSender = messageSender
this.receiptsService = receiptsService
this.connectionService = connectionService
this.registerHandlers(dispatcher)
this.agentContext.dependencyManager.registerMessageHandlers([new MessageReceiptsHandler(this.receiptsService)])
}

// FIXME: Only send message receipts to connections supporting message receipts protocol and also with a "receipt-required" decorator (TODO in AFJ)
Expand All @@ -48,8 +46,4 @@ export class ReceiptsApi {
new OutboundMessageContext(message, { agentContext: this.agentContext, connection })
)
}

private registerHandlers(dispatcher: Dispatcher) {
dispatcher.registerMessageHandler(new MessageReceiptsHandler(this.receiptsService))
}
}
2 changes: 1 addition & 1 deletion src/ReceiptsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ReceiptsModule implements Module {
// Feature Registry
featureRegistry.register(
new Protocol({
id: 'https://2060.io/didcomm/receipts/0.1',
id: 'https://didcomm.org/receipts/1.0',
})
)
}
Expand Down
17 changes: 12 additions & 5 deletions src/messages/MessageReceiptsMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { IsArray, IsInstance, IsString, IsDate, IsEnum, ValidateNested } from 'class-validator'
import { Expose, Type } from 'class-transformer'
import { Expose, Transform, TransformationType, Type } from 'class-transformer'

export enum MessageState {
Created = 'created',
Expand Down Expand Up @@ -29,12 +29,19 @@ export class MessageReceipt {
@IsString()
public messageId!: string

@Expose()
@IsEnum(MessageState)
public state!: MessageState

@Expose()
@Type(() => Date)
@Transform(({ value, type }) => {
if (type === TransformationType.CLASS_TO_PLAIN) {
console.log(`class to plain: ${value}`)
return Math.floor(value.getTime() / 1000)
}

if (type === TransformationType.PLAIN_TO_CLASS) {
return new Date(value * 1000)
}
})
@IsDate()
public timestamp!: Date
}
Expand All @@ -56,7 +63,7 @@ export class MessageReceiptsMessage extends AgentMessage {

@IsValidMessageType(MessageReceiptsMessage.type)
public readonly type = MessageReceiptsMessage.type.messageTypeUri
public static readonly type = parseMessageType('https://2060.io/didcomm/receipts/0.1/message-receipts')
public static readonly type = parseMessageType('https://didcomm.org/receipts/1.0/message-receipts')

@Expose()
@Type(() => MessageReceipt)
Expand Down
9 changes: 6 additions & 3 deletions test/receipts.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { agentDependencies } from '@aries-framework/node'
import { AskarModule } from '@aries-framework/askar'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'

import {
Agent,
ConnectionRecord,
Expand All @@ -8,7 +11,7 @@ import {
LogLevel,
} from '@aries-framework/core'
import { v4 as uuid } from 'uuid'
import { filter, firstValueFrom, map, ReplaySubject, Subject, timeout } from 'rxjs'
import { filter, firstValueFrom, map, Subject, timeout } from 'rxjs'
import { ReceiptsModule } from '../src/ReceiptsModule'
import { SubjectOutboundTransport } from './transport/SubjectOutboundTransport'
import { SubjectInboundTransport } from './transport/SubjectInboundTransport'
Expand Down Expand Up @@ -52,7 +55,7 @@ describe('receipts test', () => {
logger,
},
dependencies: agentDependencies,
modules: { receipts: new ReceiptsModule() },
modules: { askar: new AskarModule({ ariesAskar }), receipts: new ReceiptsModule() },
})

aliceAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
Expand All @@ -68,7 +71,7 @@ describe('receipts test', () => {
logger,
},
dependencies: agentDependencies,
modules: { receipts: new ReceiptsModule() },
modules: { askar: new AskarModule({ ariesAskar }), receipts: new ReceiptsModule() },
})

bobAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
Expand Down
Loading

0 comments on commit d769c14

Please sign in to comment.