@ossy/tokens 1.7.0 → 1.9.0

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/tokens",
3
3
  "description": "Token domain — aggregate and events for the Ossy token model",
4
- "version": "1.7.0",
4
+ "version": "1.9.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "./src/index.js",
@@ -25,5 +25,5 @@
25
25
  "/src",
26
26
  "README.md"
27
27
  ],
28
- "gitHead": "46cdd391ec01ea9210543ee7b14661f77079a7e7"
28
+ "gitHead": "24df2bde0d5d8794c5a82b9e802a2594ca73a5d9"
29
29
  }
@@ -0,0 +1,12 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { Token } from '@ossy/tokens'
3
+
4
+ export const id = 'tokens/get'
5
+ export const access = 'authenticated'
6
+
7
+ export async function run({ payload, req }) {
8
+ const tokenId = payload?.tokenId ?? req?.params?.tokenId
9
+ if (!tokenId) throw Object.assign(new Error('tokenId is required'), { status: 400 })
10
+
11
+ return Aggregate.Of(Token, tokenId).then(Aggregate.View(Token.Redacted))
12
+ }
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './token.aggregate.js'
2
2
  export * from './token.events.js'
3
+ export * from './tokens.queries.js'
@@ -0,0 +1,22 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { createLogger } from '@ossy/observability'
3
+
4
+ const log = createLogger('tokens')
5
+
6
+ export class TokensQueries {
7
+
8
+ static GetTokens(_query = {}) {
9
+ log.info('[TokensQueries][GetTokens] Building query')
10
+ const query = Object.entries({
11
+ ..._query,
12
+ }).reduce((acc, [key, value]) => ({ ...acc, [`state.${key}`]: value }), {})
13
+ log.info(`[TokensQueries][GetTokens] Fetching tokens for ${query['state.subject']} with query ${JSON.stringify(query, null, 2)}`)
14
+ return Aggregate.Collection.find({ ...query, type: 'Token' }, { state: true }).toArray()
15
+ .then(resources => {
16
+ log.info(`[TokensQueries][GetTokens] Found ${resources.length} tokens`)
17
+ return resources
18
+ .map(resource => resource.state)
19
+ })
20
+ }
21
+
22
+ }