Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix exchangeId override for Quote, Order, OrderStatus, and Close
Browse files Browse the repository at this point in the history
  • Loading branch information
mistermoe committed Sep 5, 2023
1 parent a0ec665 commit 7a188fa
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/tbdex",
"version": "0.4.0",
"version": "0.5.0",
"type": "module",
"description": "Library that includes type definitions for tbdex messages",
"license": "Apache-2.0",
Expand Down
8 changes: 3 additions & 5 deletions js/src/message-kinds/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ export class Close extends Message<'close'> {
readonly validNext = new Set<MessageKind>([])

static create(opts: CreateCloseOptions) {
const id = Message.generateId('close')
const metadata: MessageMetadata<'close'> = {
...opts.metadata,
kind : 'close',
id : id,
exchangeId : id,
createdAt : new Date().toISOString()
kind : 'close',
id : Message.generateId('close'),
createdAt : new Date().toISOString()
}

const message = { metadata, data: opts.data }
Expand Down
8 changes: 3 additions & 5 deletions js/src/message-kinds/order-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ export class OrderStatus extends Message<'orderstatus'> {
readonly validNext = new Set<MessageKind>([])

static create(opts: CreateOrderStatusOptions) {
const id = Message.generateId('orderstatus')
const metadata: MessageMetadata<'orderstatus'> = {
...opts.metadata,
kind : 'orderstatus',
id : id,
exchangeId : id,
createdAt : new Date().toISOString()
kind : 'orderstatus',
id : Message.generateId('orderstatus'),
createdAt : new Date().toISOString()
}

const message = { metadata, data: opts.data }
Expand Down
8 changes: 3 additions & 5 deletions js/src/message-kinds/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export class Order extends Message<'order'> {
readonly validNext = new Set<MessageKind>(['orderstatus'])

static create(opts: CreateOrderOptions) {
const id = Message.generateId('order')
const metadata: MessageMetadata<'order'> = {
...opts.metadata,
kind : 'order',
id : id,
exchangeId : id,
createdAt : new Date().toISOString()
kind : 'order',
id : Message.generateId('order'),
createdAt : new Date().toISOString()
}

const message = { metadata, data: {} }
Expand Down
8 changes: 3 additions & 5 deletions js/src/message-kinds/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ export class Quote extends Message<'quote'> {
readonly validNext = new Set<MessageKind>(['order', 'close'])

static create(opts: CreateQuoteOptions) {
const id = Message.generateId('quote')
const metadata: MessageMetadata<'quote'> = {
...opts.metadata,
kind : 'quote',
id : id,
exchangeId : id,
createdAt : new Date().toISOString()
kind : 'quote',
id : Message.generateId('quote'),
createdAt : new Date().toISOString()
}

const message = { metadata, data: opts.data }
Expand Down
2 changes: 1 addition & 1 deletion js/src/message-kinds/rfq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PEXv2 } from '@sphereon/pex'

const pex = new PEXv2()

/** options passed to {@link Quote.create} */
/** options passed to {@link Rfq.create} */
export type CreateRfqOptions = {
data: MessageKindModel<'rfq'>
metadata: Omit<MessageMetadata<'rfq'>, 'id' |'kind' | 'createdAt' | 'exchangeId'>
Expand Down
16 changes: 16 additions & 0 deletions js/tests/close.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Close, Message } from '../src/main.js'
import { expect } from 'chai'

describe('Close', () => {
describe('create', () => {
it('sets exchangeId to whatever is passed in', () => {
const exchangeId = Message.generateId('rfq')
const closeMessage = Close.create({
metadata : { from: 'did:ex:alice', to: 'did:ex:pfi', exchangeId },
data : { reason: 'life is hard' }
})

expect(closeMessage.exchangeId).to.equal(exchangeId)
})
})
})

0 comments on commit 7a188fa

Please sign in to comment.