@xyo-network/api 2.21.13 → 2.21.14

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
@@ -10,11 +10,11 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@xylabs/sdk-js": "^2.5.9",
13
- "@xyo-network/account": "^2.21.13",
14
- "@xyo-network/boundwitness": "^2.21.13",
15
- "@xyo-network/core": "^2.21.13",
16
- "@xyo-network/payload": "^2.21.13",
17
- "@xyo-network/typeof": "^2.21.13",
13
+ "@xyo-network/account": "^2.21.14",
14
+ "@xyo-network/boundwitness": "^2.21.14",
15
+ "@xyo-network/core": "^2.21.14",
16
+ "@xyo-network/payload": "^2.21.14",
17
+ "@xyo-network/typeof": "^2.21.14",
18
18
  "axios": "^0.27.2",
19
19
  "pako": "^2.0.4",
20
20
  "uuid": "^8.3.2"
@@ -61,6 +61,6 @@
61
61
  },
62
62
  "sideEffects": true,
63
63
  "types": "dist/esm/index.d.ts",
64
- "version": "2.21.13",
64
+ "version": "2.21.14",
65
65
  "packageManager": "yarn@3.1.1"
66
66
  }
@@ -8,11 +8,8 @@ import { XyoAccountApi } from './Api'
8
8
  const timeout = 20000
9
9
  const config: XyoApiConfig = {
10
10
  apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
11
- jwtToken: process.env.JWT_TOKEN || undefined,
12
11
  }
13
12
 
14
- //const describeSkipIfNoToken = config.jwtToken ? describe : describe.skip
15
-
16
13
  describe('XyoAuthApi', () => {
17
14
  describe('get', () => {
18
15
  it('returns a new XyoWalletApi', () => {
@@ -1,25 +1,18 @@
1
1
  import { XyoAccount } from '@xyo-network/account'
2
2
  import { XyoBoundWitness, XyoBoundWitnessBuilder } from '@xyo-network/boundwitness'
3
- import { config } from 'dotenv'
4
3
 
5
4
  import { XyoApiConfig, XyoApiError } from '../models'
6
5
  import { testPayload } from '../Test'
7
6
  import { XyoArchivistApi } from './Api'
8
7
  import { getNewArchive, getRandomArchiveName } from './ApiUtil.spec'
9
8
 
10
- config()
11
-
12
9
  const configData: XyoApiConfig = {
13
10
  apiDomain: process.env.API_DOMAIN || 'https://beta.api.archivist.xyo.network',
14
- apiKey: process.env.API_KEY || undefined,
15
- jwtToken: process.env.JWT_TOKEN || undefined,
16
11
  onError: (error) => console.error(`Error: ${JSON.stringify(error)}`),
17
12
  onFailure: (response) => response, //console.error(`Failure: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
18
13
  onSuccess: (response) => response, //console.log(`Success: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
19
14
  }
20
15
 
21
- const describeSkipIfNoToken = configData.jwtToken || configData.apiKey ? describe : describe.skip
22
-
23
16
  describe('postBoundWitness', () => {
24
17
  it.each([true, false])('posts a single bound witness', async (inlinePayloads) => {
25
18
  const builder = new XyoBoundWitnessBuilder({ inlinePayloads }).witness(XyoAccount.random()).payload(testPayload)
@@ -57,7 +50,7 @@ describe('postBoundWitnesses', () => {
57
50
  })
58
51
  })
59
52
 
60
- describeSkipIfNoToken('XyoArchivistApi', () => {
53
+ describe.skip('XyoArchivistApi', () => {
61
54
  describe('get', () => {
62
55
  it('returns a new XyoArchivistApi', () => {
63
56
  const api = new XyoArchivistApi(configData)
@@ -1,4 +1,5 @@
1
1
  import { Wallet } from '@ethersproject/wallet'
2
+ import { assertEx } from '@xylabs/sdk-js'
2
3
  import { XyoAccount } from '@xyo-network/account'
3
4
  import { v4 } from 'uuid'
4
5
 
@@ -13,7 +14,7 @@ export const getRandomArchiveName = (): string => {
13
14
  return `test-archive-${randomString}`
14
15
  }
15
16
 
16
- export const getNewArchive = async (api: XyoArchivistApi) => {
17
+ export const getTokenForNewUser = async (api: XyoArchivistApi): Promise<string> => {
17
18
  const account = XyoAccount.random()
18
19
  const address = new Wallet(account.private.bytes)
19
20
  const challenge = await api.account(account.public).challenge.post()
@@ -21,14 +22,17 @@ export const getNewArchive = async (api: XyoArchivistApi) => {
21
22
  const message = challenge?.state || ''
22
23
  const signature = await address.signMessage(message)
23
24
  const verify = await api.account(account.public).verify.post({ message, signature })
24
- expect(verify?.token).toBeTruthy()
25
- const jwtToken = verify?.token || ''
25
+ const jwtToken = assertEx(verify?.token, 'Missing JWT token in response')
26
+ return jwtToken
27
+ }
28
+
29
+ export const getNewArchive = async (api: XyoArchivistApi) => {
30
+ const jwtToken = await getTokenForNewUser(api)
26
31
  const authenticatedApi = new XyoArchivistApi({ ...api.config, jwtToken })
27
32
  const name = getRandomArchiveName()
28
33
  const response = await authenticatedApi.archives.archive(name).put()
29
- const archive = response?.archive
30
- expect(archive).toBeTruthy()
31
- return archive || ''
34
+ const archive = assertEx(response?.archive, 'Missing archive in response')
35
+ return archive
32
36
  }
33
37
 
34
38
  export const testSchemaPrefix = 'network.xyo.schema.test.'
@@ -1,13 +1,10 @@
1
1
  import { XyoAccount } from '@xyo-network/account'
2
2
  import { XyoBoundWitnessBuilder } from '@xyo-network/boundwitness'
3
- import { config } from 'dotenv'
4
3
 
5
4
  import { XyoApiConfig, XyoApiError } from '../../models'
6
5
  import { XyoArchivistApi } from '../Api'
7
6
  import { getNewArchive, getTimestampMinutesFromNow } from '../ApiUtil.spec'
8
7
 
9
- config()
10
-
11
8
  const configData: XyoApiConfig = {
12
9
  apiDomain: process.env.API_DOMAIN || 'https://beta.api.archivist.xyo.network',
13
10
  onError: (error) => console.error(`Error: ${JSON.stringify(error)}`),
@@ -7,11 +7,8 @@ import { XyoUserApi } from './Api'
7
7
  const timeout = 20000
8
8
  const config: XyoApiConfig = {
9
9
  apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
10
- jwtToken: process.env.JWT_TOKEN || undefined,
11
10
  }
12
11
 
13
- const describeSkipIfNoToken = config.jwtToken ? describe : describe.skip
14
-
15
12
  describe('XyoAuthApi', () => {
16
13
  describe('get', () => {
17
14
  it('returns a new XyoAuthApi', () => {
@@ -19,8 +16,7 @@ describe('XyoAuthApi', () => {
19
16
  expect(api).toBeDefined()
20
17
  })
21
18
  })
22
-
23
- describeSkipIfNoToken('walletChallenge', function () {
19
+ describe('walletChallenge', function () {
24
20
  it(
25
21
  'returns a nonce',
26
22
  async () => {