Skip to content

Commit

Permalink
Add actionparticipants group
Browse files Browse the repository at this point in the history
  • Loading branch information
nad-au committed Mar 8, 2024
1 parent 5466533 commit 13a0ad9
Show file tree
Hide file tree
Showing 19 changed files with 850 additions and 380 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Two token clients are provided: `actionStepTokenClient` and `actionStepLegacyTok
Either way, create an instance of your token client and pass in the url of the service which is providing the token, and the ActionStep API URL:

```ts
import { actionStepTokenClient } from '@dbc-tech/actionstep'

const tokenClient = actionStepTokenClient(
process.env.ACTIONSTEP_TOKEN_URL,
process.env.ACTIONSTEP_API_URL,
Expand All @@ -40,6 +42,8 @@ const tokenClient = actionStepTokenClient(
With the token client you can now create an instance of the `actionStepClient`:

```ts
import { actionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

const client = actionStepClient(tokenClient)
```

Expand Down Expand Up @@ -69,6 +73,10 @@ else {

As a response could contain an error, it is important first to check the error status. **Note:** `data` and `error` are mutually exclusive. If there is no error then the data shape will match that described in the API documentation. In this case an array of actions is found under the `actions` property.

### Testing endpoints

A sandbox project is available to test individual endpoints. See [readme](monorepo/actionstep-sandbox/README.md) for more information.

## Building Source

1. Install or update [nvm](https://github.com/nvm-sh/nvm#installing-and-updating)
Expand Down
2 changes: 1 addition & 1 deletion monorepo/actionstep-sandbox/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ACTIONSTEP_API_URL=https://ap-southeast-2.actionstep.com/api/rest
ACTIONSTEP_TOKEN_URL=https://tools.thinkconveyancing.com.au/api/actionstep/key/get
ACTIONSTEP_TOKEN_URL=
66 changes: 66 additions & 0 deletions monorepo/actionstep-sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# actionstep-sandbox

Test ActionStep endpoints

## Getting Started

Buid monorepo

```
cd monorepo
npm i
npm run build
```

Copy `.env.example` and edit to suit

```
cd actionstep-sandbox
cp .env.example .env
```

Edit `.env` file and set value for `ACTIONSTEP_TOKEN_URL` which is the endpoint which returns the stored ActionStep token.

Determine if token service is considered current or legacy and edit `runner.ts` and use the appropriate `actionStepTokenClient` or `actionStepLegacyTokenClient`.

A token service should return tokens in the following format:

```json
{
"access_token": "...",
"api_endpoint": "https://ap-southeast-2.actionstep.com/api/",
"expires_at": "2024-03-08T09:04:49.747Z",
"expires_in": 28800,
"orgkey": "...",
"refresh_token": "...",
"token_type": "bearer"
}
```

A legacy token service should return tokens in the following format:

```json
{
"status": 200,
"message": "OK",
"data": {
"actionstep": {
"id": "1",
"access_token": "...",
"token_type": "bearer",
"expires_in": "28800",
"api_endpoint": "https://ap-southeast-2.actionstep.com/api/",
"orgkey": "...",
"refresh_token": "...",
"generated": "2024-03-08 11:40:25",
"date_expiry": "2024-03-08 19:40:25"
}
}
}
```

Test endpoints by passing endpoint name to the runner eg. `getActions`

```
npm run runner getActions
```
4 changes: 2 additions & 2 deletions monorepo/actionstep-sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"lint": "eslint . --fix",
"test": "jest --passWithNoTests",
"build": "rimraf ./dist && tsc --build tsconfig.build.json",
"run:actions": "npm run start ./src/actions.ts",
"run:got": "npm run start ./src/got.ts"
"runner": "npm run start ./src/runner.ts",
"got": "npm run start ./src/got.ts"
},
"dependencies": {
"@dbc-tech/actionstep": "*",
Expand Down
78 changes: 0 additions & 78 deletions monorepo/actionstep-sandbox/src/actions.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const createActionParticipant = async (
tokenClient: ActionStepTokenClient,
) => {
const { actionParticipants: client } = actionStepClient(tokenClient)

const testActionId = 68330 // or 84407
const testParticipantId = 113702
const testParticipantType = 71

const { data: createdActionParticipant, error } =
await client.createActionParticipant({
actionparticipants: {
links: {
action: testActionId,
participant: testParticipantId,
participantType: testParticipantType,
},
},
})
if (error) console.error('error:', error)
else
console.log('created action participant:', {
id: createdActionParticipant.actionparticipants.id,
number: createdActionParticipant.actionparticipants.participantNumber,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const deleteActionParticipant = async (
tokenClient: ActionStepTokenClient,
) => {
const { actionParticipants: client } = actionStepClient(tokenClient)

const testParticipantId = '68330--71--113702'

const response = await client.deleteActionParticipant(testParticipantId)
if (response.error) console.error('error:', response.error)
else {
console.log(`Status code:${response.response.status}`)
}
}
16 changes: 16 additions & 0 deletions monorepo/actionstep-sandbox/src/endpoints/getAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const getAction = async (tokenClient: ActionStepTokenClient) => {
const { actions: client } = actionStepClient(tokenClient)

const testActionId = 68330 // or 84407

const { data: action, error } = await client.getAction(testActionId)
if (error) console.error('error:', error)
else
console.log('get action:', {
id: action.actions.id,
name: action.actions.name,
reference: action.actions.reference,
})
}
19 changes: 19 additions & 0 deletions monorepo/actionstep-sandbox/src/endpoints/getActionParticipant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const getActionParticipant = async (
tokenClient: ActionStepTokenClient,
) => {
const { actionParticipants: client } = actionStepClient(tokenClient)

const testParticipantId = '113702'

const { data: actionParticipant, error } =
await client.getActionParticipant(testParticipantId)
if (error) console.error('error:', error)
else {
console.log('get action participant:', {
id: actionParticipant.actionparticipants.id,
number: actionParticipant.actionparticipants.participantNumber,
})
}
}
18 changes: 18 additions & 0 deletions monorepo/actionstep-sandbox/src/endpoints/getActionParticipants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const getActionParticipants = async (
tokenClient: ActionStepTokenClient,
) => {
const { actionParticipants: client } = actionStepClient(tokenClient)

const { data, error } = await client.getActionParticipants(1, 5)
if (error) console.error('error:', error)
else {
for (const participant of data.actionparticipants) {
console.log('get action participant:', {
id: participant.id,
number: participant.participantNumber,
})
}
}
}
17 changes: 17 additions & 0 deletions monorepo/actionstep-sandbox/src/endpoints/getActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const getActions = async (tokenClient: ActionStepTokenClient) => {
const { actions: client } = actionStepClient(tokenClient)

const { data, error } = await client.getActions(1, 5)
if (error) console.error('error:', error)
else {
for (const action of data.actions) {
console.log('get action:', {
id: action.id,
name: action.name,
reference: action.reference,
})
}
}
}
23 changes: 23 additions & 0 deletions monorepo/actionstep-sandbox/src/endpoints/updateAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ActionStepTokenClient, actionStepClient } from '@dbc-tech/actionstep'

export const updateAction = async (tokenClient: ActionStepTokenClient) => {
const { actions: client } = actionStepClient(tokenClient)

const testActionId = 68330 // or 84407

const { data: updatedAction, error } = await client.updateAction(
testActionId,
{
actions: {
reference: 'TEST07',
},
},
)
if (error) console.error('error:', error)
else
console.log('updated action:', {
id: updatedAction.actions.id,
name: updatedAction.actions.name,
reference: updatedAction.actions.reference,
})
}
44 changes: 44 additions & 0 deletions monorepo/actionstep-sandbox/src/runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { actionStepLegacyTokenClient } from '@dbc-tech/actionstep'
import * as dotenv from 'dotenv'
import { getActions } from './endpoints/getActions'
import { getAction } from './endpoints/getAction'
import { updateAction } from './endpoints/updateAction'
import { getActionParticipants } from './endpoints/getActionParticipants'
import { getActionParticipant } from './endpoints/getActionParticipant'
import { createActionParticipant } from './endpoints/createActionParticipant'
import { deleteActionParticipant } from './endpoints/deleteActionParticipant'
dotenv.config()

const runner = async (endpointName: string) => {
console.log('running:', endpointName)

// const tokenClient = actionStepTokenClient(
// process.env.ACTIONSTEP_TOKEN_URL,
// process.env.ACTIONSTEP_API_URL,
// )
const tokenClient = actionStepLegacyTokenClient(
process.env.ACTIONSTEP_TOKEN_URL,
process.env.ACTIONSTEP_API_URL,
)

switch (endpointName) {
case 'getActions':
return getActions(tokenClient)
case 'getAction':
return getAction(tokenClient)
case 'updateAction':
return updateAction(tokenClient)
case 'getActionParticipants':
return getActionParticipants(tokenClient)
case 'getActionParticipant':
return getActionParticipant(tokenClient)
case 'createActionParticipant':
return createActionParticipant(tokenClient)
case 'deleteActionParticipant':
return deleteActionParticipant(tokenClient)
}
}

runner(process.argv[2])
.then(() => console.log('done'))
.catch(console.error)
2 changes: 2 additions & 0 deletions monorepo/actionstep/src/action-step-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ActionStepTokenClient } from './types/action-step-auth.type'
import { actionsClient } from './api/actions'
import { actionParticipantsClient } from './api/actionparticipants'

export const actionStepClient = (tokenClient: ActionStepTokenClient) => {
return {
actions: actionsClient(tokenClient),
actionParticipants: actionParticipantsClient(tokenClient),
}
}
Loading

0 comments on commit 13a0ad9

Please sign in to comment.