@xyo-network/api 2.41.10 → 2.41.12
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/dist/cjs/Api/Addresses/Address/Api.d.ts +1 -1
- package/dist/cjs/Api/Addresses/Address/Api.d.ts.map +1 -1
- package/dist/cjs/Api/Addresses/Address/Api.js.map +1 -1
- package/dist/cjs/Api/Addresses/Api.d.ts +2 -2
- package/dist/cjs/Api/Addresses/Api.d.ts.map +1 -1
- package/dist/cjs/Api/Addresses/Api.js.map +1 -1
- package/dist/cjs/Api/Addresses/index.d.ts +0 -2
- package/dist/cjs/Api/Addresses/index.d.ts.map +1 -1
- package/dist/cjs/Api/Addresses/index.js +0 -2
- package/dist/cjs/Api/Addresses/index.js.map +1 -1
- package/dist/cjs/Api/Api.d.ts +10 -16
- package/dist/cjs/Api/Api.d.ts.map +1 -1
- package/dist/cjs/Api/Api.js +2 -16
- package/dist/cjs/Api/Api.js.map +1 -1
- package/dist/cjs/Api/Archive/Settings/Key/Api.d.ts +0 -1
- package/dist/cjs/Api/Archive/Settings/Key/Api.d.ts.map +1 -1
- package/dist/cjs/Api/Archive/Settings/Key/Api.js +0 -3
- package/dist/cjs/Api/Archive/Settings/Key/Api.js.map +1 -1
- package/dist/cjs/Archivist/XyoRemoteArchivist.d.ts +1 -1
- package/dist/cjs/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/cjs/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.d.ts +1 -1
- package/dist/cjs/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.d.ts.map +1 -1
- package/dist/docs.json +7508 -6698
- package/dist/esm/Api/Addresses/Address/Api.d.ts +1 -1
- package/dist/esm/Api/Addresses/Address/Api.d.ts.map +1 -1
- package/dist/esm/Api/Addresses/Address/Api.js.map +1 -1
- package/dist/esm/Api/Addresses/Api.d.ts +2 -2
- package/dist/esm/Api/Addresses/Api.d.ts.map +1 -1
- package/dist/esm/Api/Addresses/Api.js.map +1 -1
- package/dist/esm/Api/Addresses/index.d.ts +0 -2
- package/dist/esm/Api/Addresses/index.d.ts.map +1 -1
- package/dist/esm/Api/Addresses/index.js +0 -2
- package/dist/esm/Api/Addresses/index.js.map +1 -1
- package/dist/esm/Api/Api.d.ts +10 -16
- package/dist/esm/Api/Api.d.ts.map +1 -1
- package/dist/esm/Api/Api.js +3 -14
- package/dist/esm/Api/Api.js.map +1 -1
- package/dist/esm/Api/Archive/Settings/Key/Api.d.ts +0 -1
- package/dist/esm/Api/Archive/Settings/Key/Api.d.ts.map +1 -1
- package/dist/esm/Api/Archive/Settings/Key/Api.js +0 -6
- package/dist/esm/Api/Archive/Settings/Key/Api.js.map +1 -1
- package/dist/esm/Archivist/XyoRemoteArchivist.d.ts +1 -1
- package/dist/esm/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/esm/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.d.ts +1 -1
- package/dist/esm/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/Api/Account/Api.spec.ts +20 -31
- package/src/Api/Addresses/Address/Api.spec.ts +4 -5
- package/src/Api/Addresses/Address/Api.ts +1 -1
- package/src/Api/Addresses/Api.spec.ts +12 -10
- package/src/Api/Addresses/Api.ts +2 -2
- package/src/Api/Addresses/index.ts +0 -2
- package/src/Api/Api.spec.ts +11 -201
- package/src/Api/Api.ts +8 -25
- package/src/Api/ApiUtil.spec.ts +17 -2
- package/src/Api/Archive/Api.spec.ts +22 -0
- package/src/Api/Archive/Settings/Key/Api.spec.ts +39 -0
- package/src/Api/Archive/Settings/Key/Api.ts +1 -8
- package/src/Api/Archives/Api.spec.ts +12 -0
- package/src/Api/Block/Api.spec.ts +57 -0
- package/src/Api/Payload/Api.spec.ts +14 -36
- package/src/Api/Payload/Schema/Api.spec.ts +1 -2
- package/src/Archivist/XyoRemoteArchivist.spec.ts +10 -8
- package/src/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.spec.ts +12 -12
- package/src/Diviner/ArchiveListApiDiviner/ArchiveListApiDiviner.spec.ts +2 -9
- package/src/Diviner/LocationDiviner/LocationDivinerApi.spec.ts +17 -34
- package/src/Diviner/SchemaListApiDiviner/SchemaListApiDiviner.spec.ts +1 -5
- package/src/Diviner/SchemaStatsApiDiviner/SchemaStatsApiDiviner.spec.ts +2 -9
- package/src/User/Api.spec.ts +4 -10
- package/typedoc.json +1 -1
- package/dist/cjs/Api/Addresses/ModuleDescription.d.ts +0 -5
- package/dist/cjs/Api/Addresses/ModuleDescription.d.ts.map +0 -1
- package/dist/cjs/Api/Addresses/ModuleDescription.js +0 -3
- package/dist/cjs/Api/Addresses/ModuleDescription.js.map +0 -1
- package/dist/cjs/Api/Addresses/NodeModuleDescription.d.ts +0 -5
- package/dist/cjs/Api/Addresses/NodeModuleDescription.d.ts.map +0 -1
- package/dist/cjs/Api/Addresses/NodeModuleDescription.js +0 -3
- package/dist/cjs/Api/Addresses/NodeModuleDescription.js.map +0 -1
- package/dist/esm/Api/Addresses/ModuleDescription.d.ts +0 -5
- package/dist/esm/Api/Addresses/ModuleDescription.d.ts.map +0 -1
- package/dist/esm/Api/Addresses/ModuleDescription.js +0 -2
- package/dist/esm/Api/Addresses/ModuleDescription.js.map +0 -1
- package/dist/esm/Api/Addresses/NodeModuleDescription.d.ts +0 -5
- package/dist/esm/Api/Addresses/NodeModuleDescription.d.ts.map +0 -1
- package/dist/esm/Api/Addresses/NodeModuleDescription.js +0 -2
- package/dist/esm/Api/Addresses/NodeModuleDescription.js.map +0 -1
- package/src/Api/Addresses/ModuleDescription.ts +0 -4
- package/src/Api/Addresses/NodeModuleDescription.ts +0 -5
package/src/Api/Api.spec.ts
CHANGED
|
@@ -1,207 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { XyoApiConfig, XyoApiError } from '@xyo-network/api-models'
|
|
3
|
-
import { BoundWitnessBuilder, XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
1
|
+
import { getApi } from './ApiUtil.spec'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
import { XyoArchivistApi } from './Api'
|
|
7
|
-
import { getNewArchive, getRandomArchiveName } from './ApiUtil.spec'
|
|
8
|
-
|
|
9
|
-
const configData: XyoApiConfig = {
|
|
10
|
-
apiDomain: process.env.API_DOMAIN || 'https://beta.api.archivist.xyo.network',
|
|
11
|
-
onError: (error) => console.error(`Error: ${JSON.stringify(error)}`),
|
|
12
|
-
onFailure: (response) => response, //console.error(`Failure: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
|
|
13
|
-
onSuccess: (response) => response, //console.log(`Success: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe('postBoundWitness', () => {
|
|
17
|
-
it.each([true, false])('posts a single bound witness', async (inlinePayloads) => {
|
|
18
|
-
const builder = new BoundWitnessBuilder({ inlinePayloads }).witness(XyoAccount.random()).payload(testPayload)
|
|
19
|
-
const api = new XyoArchivistApi(configData)
|
|
20
|
-
const [boundWitness] = builder.build()
|
|
21
|
-
try {
|
|
22
|
-
const response = await api.archives.archive().block.post([boundWitness])
|
|
23
|
-
|
|
24
|
-
expect(response?.length).toEqual(1)
|
|
25
|
-
} catch (ex) {
|
|
26
|
-
const error = ex as XyoApiError
|
|
27
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
28
|
-
expect(error === undefined)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('postBoundWitnesses', () => {
|
|
34
|
-
it.each([true, false])('posts multiple bound witnesses', async (inlinePayloads) => {
|
|
35
|
-
const builder = new BoundWitnessBuilder({ inlinePayloads }).witness(XyoAccount.random()).payload(testPayload)
|
|
36
|
-
const api = new XyoArchivistApi(configData)
|
|
37
|
-
const [json] = builder.build()
|
|
38
|
-
const boundWitnesses: XyoBoundWitness[] = [json, json]
|
|
39
|
-
|
|
40
|
-
//TODO: We are casting the result here since the server has not yet been updated to return the actual saved data
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const response = await api.archives.archive().block.post(boundWitnesses)
|
|
44
|
-
expect(response?.length).toEqual(2)
|
|
45
|
-
} catch (ex) {
|
|
46
|
-
const error = ex as XyoApiError
|
|
47
|
-
console.log(JSON.stringify(error, null, 2))
|
|
48
|
-
expect(error === undefined)
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
describe.skip('XyoArchivistApi', () => {
|
|
3
|
+
describe('XyoArchivistApi', () => {
|
|
54
4
|
describe('get', () => {
|
|
55
|
-
it('returns
|
|
56
|
-
const api =
|
|
5
|
+
it('returns Node Description', async () => {
|
|
6
|
+
const api = getApi()
|
|
57
7
|
expect(api).toBeDefined()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
it('gets an array of archives owned', async () => {
|
|
67
|
-
const api = new XyoArchivistApi(configData)
|
|
68
|
-
try {
|
|
69
|
-
await api.archives.archive(archive).put()
|
|
70
|
-
const archives = await api.archives.get()
|
|
71
|
-
expect(Array.isArray(archives)).toBe(true)
|
|
72
|
-
const archiveNames = archives?.map((x) => x.archive)
|
|
73
|
-
expect(archiveNames).toContain(archive)
|
|
74
|
-
} catch (ex) {
|
|
75
|
-
const error = ex as XyoApiError
|
|
76
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
77
|
-
expect(error === undefined)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
describe('getArchive', function () {
|
|
83
|
-
let archive = ''
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
archive = getRandomArchiveName()
|
|
86
|
-
})
|
|
87
|
-
it('gets the archive', async () => {
|
|
88
|
-
const api = new XyoArchivistApi(configData)
|
|
89
|
-
try {
|
|
90
|
-
await api.archives.archive(archive).get()
|
|
91
|
-
const response = await api.archives.archive(archive).get()
|
|
92
|
-
expect(response?.archive).toBe(archive)
|
|
93
|
-
} catch (ex) {
|
|
94
|
-
const error = ex as XyoApiError
|
|
95
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
96
|
-
expect(error === undefined)
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
describe('putArchive', function () {
|
|
102
|
-
let archive = ''
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
archive = getRandomArchiveName()
|
|
105
|
-
})
|
|
106
|
-
it('returns the archive owned', async () => {
|
|
107
|
-
const api = new XyoArchivistApi(configData)
|
|
108
|
-
try {
|
|
109
|
-
const response = await api.archives.archive(archive).put()
|
|
110
|
-
expect(response?.archive).toEqual(archive)
|
|
111
|
-
} catch (ex) {
|
|
112
|
-
const error = ex as XyoApiError
|
|
113
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
114
|
-
expect(error === undefined)
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
describe('getArchiveKeys', function () {
|
|
120
|
-
it('Returns the keys for the archive', async () => {
|
|
121
|
-
try {
|
|
122
|
-
const archive = getRandomArchiveName()
|
|
123
|
-
const api = new XyoArchivistApi({ ...configData })
|
|
124
|
-
const archiveApi = api.archives.archive(archive)
|
|
125
|
-
await archiveApi.put()
|
|
126
|
-
const key = await archiveApi.settings.key.post()
|
|
127
|
-
const response = await archiveApi.settings.key.get()
|
|
128
|
-
expect(response?.length).toEqual(1)
|
|
129
|
-
expect(response?.[0]).toEqual(key)
|
|
130
|
-
} catch (ex) {
|
|
131
|
-
const error = ex as XyoApiError
|
|
132
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
133
|
-
expect(error === undefined)
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
describe('postArchiveKey', function () {
|
|
139
|
-
it('Creates an archive key', async () => {
|
|
140
|
-
try {
|
|
141
|
-
const archive = getRandomArchiveName()
|
|
142
|
-
const api = new XyoArchivistApi({ ...configData })
|
|
143
|
-
const archiveApi = api.archives.archive(archive)
|
|
144
|
-
await archiveApi.put()
|
|
145
|
-
const response = await archiveApi.settings.key.post()
|
|
146
|
-
expect(response?.keys.length).toBe(1)
|
|
147
|
-
} catch (ex) {
|
|
148
|
-
const error = ex as XyoApiError
|
|
149
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
150
|
-
expect(error === undefined)
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
describe('findBoundWitnessesStats', function () {
|
|
156
|
-
it('returns stats for boundwitness', async () => {
|
|
157
|
-
let api = new XyoArchivistApi(configData)
|
|
158
|
-
try {
|
|
159
|
-
api = new XyoArchivistApi({ ...configData })
|
|
160
|
-
const stats = await api.archives.archive().block.stats.get()
|
|
161
|
-
expect(stats?.count).toBeGreaterThan(0)
|
|
162
|
-
} catch (ex) {
|
|
163
|
-
const error = ex as XyoApiError
|
|
164
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
165
|
-
expect(error === undefined)
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
describe('findBoundWitnessesBefore', function () {
|
|
171
|
-
it('returns bound witnesses from before the timestamp', async () => {
|
|
172
|
-
let api = new XyoArchivistApi(configData)
|
|
173
|
-
try {
|
|
174
|
-
api = new XyoArchivistApi({ ...configData })
|
|
175
|
-
const [boundWitness] = new BoundWitnessBuilder().witness(XyoAccount.random()).build()
|
|
176
|
-
await api.archives.archive().block.post([boundWitness])
|
|
177
|
-
const timestamp = Date.now() + 10000
|
|
178
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
179
|
-
const response = await api.archives.archive('temp').block.findBefore(timestamp)
|
|
180
|
-
expect(response?.length).toBe(1)
|
|
181
|
-
} catch (ex) {
|
|
182
|
-
const error = ex as XyoApiError
|
|
183
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
184
|
-
expect(error === undefined)
|
|
185
|
-
}
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
describe('findBoundWitnessesAfter', function () {
|
|
190
|
-
it('returns bound witnesses from before the timestamp', async () => {
|
|
191
|
-
let api = new XyoArchivistApi(configData)
|
|
192
|
-
try {
|
|
193
|
-
const archive = await getNewArchive(api)
|
|
194
|
-
api = new XyoArchivistApi({ ...configData })
|
|
195
|
-
const [boundWitness] = new BoundWitnessBuilder().witness(XyoAccount.random()).build()
|
|
196
|
-
await api.archives.archive(archive).block.post([boundWitness])
|
|
197
|
-
const timestamp = Date.now() - 10000
|
|
198
|
-
const response = await api.archives.archive(archive).block.find({ order: 'asc', timestamp })
|
|
199
|
-
expect(response?.length).toBe(1)
|
|
200
|
-
} catch (ex) {
|
|
201
|
-
const error = ex as XyoApiError
|
|
202
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
203
|
-
expect(error === undefined)
|
|
204
|
-
}
|
|
8
|
+
const response = await api.get()
|
|
9
|
+
expect(response).toBeObject()
|
|
10
|
+
expect(response?.address).toBeString()
|
|
11
|
+
expect(response?.queries).toBeArray()
|
|
12
|
+
expect(response?.queries?.length).toBeGreaterThan(0)
|
|
13
|
+
expect(response?.children).toBeArray()
|
|
14
|
+
expect(response?.children?.length).toBeGreaterThan(0)
|
|
205
15
|
})
|
|
206
16
|
})
|
|
207
17
|
})
|
package/src/Api/Api.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AddressValue } from '@xyo-network/account'
|
|
2
|
+
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
3
3
|
import { XyoBoundWitness } from '@xyo-network/boundwitness'
|
|
4
|
-
import {
|
|
4
|
+
import { DataLike } from '@xyo-network/core'
|
|
5
|
+
import { ModuleDescription } from '@xyo-network/module'
|
|
5
6
|
import { Huri, XyoPayload } from '@xyo-network/payload'
|
|
6
7
|
|
|
7
|
-
import { XyoApiBase } from '../Base'
|
|
8
8
|
import { XyoApiSimple } from '../Simple'
|
|
9
9
|
import { XyoUserApi } from '../User'
|
|
10
10
|
import { XyoAccountApi } from './Account'
|
|
@@ -13,7 +13,7 @@ import { XyoArchivistArchiveApi } from './Archive'
|
|
|
13
13
|
import { XyoArchivistArchivesApi } from './Archives'
|
|
14
14
|
import { XyoArchivistNodeApi } from './Node'
|
|
15
15
|
|
|
16
|
-
export class XyoArchivistApi extends
|
|
16
|
+
export class XyoArchivistApi<C extends XyoApiConfig = XyoApiConfig> extends XyoApiSimple<ModuleDescription, C> {
|
|
17
17
|
private _addresses?: XyoAddressesApi
|
|
18
18
|
private _archives?: XyoArchivistArchivesApi
|
|
19
19
|
private _stats?: XyoApiSimple<unknown[]>
|
|
@@ -59,10 +59,10 @@ export class XyoArchivistApi extends XyoApiBase {
|
|
|
59
59
|
return this._user
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public account(address:
|
|
62
|
+
public account(address: DataLike) {
|
|
63
63
|
return new XyoAccountApi({
|
|
64
64
|
...this.config,
|
|
65
|
-
root: `${this.root}wallet/${new
|
|
65
|
+
root: `${this.root}wallet/${new AddressValue(address).hex}/`,
|
|
66
66
|
})
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -74,23 +74,6 @@ export class XyoArchivistApi extends XyoApiBase {
|
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** @deprecated use huri(huri) instead */
|
|
78
|
-
public async get(huri: Huri | string): Promise<XyoApiResponseBody<XyoPayload>>
|
|
79
|
-
/** @deprecated use huri(huri) instead */
|
|
80
|
-
public async get(huri: Huri | string, responseType?: 'body'): Promise<XyoApiResponseBody<XyoPayload>>
|
|
81
|
-
/** @deprecated use huri(huri) instead */
|
|
82
|
-
public async get(huri: Huri | string, responseType?: 'tuple'): Promise<XyoApiResponseTuple<XyoPayload>>
|
|
83
|
-
/** @deprecated use huri(huri) instead */
|
|
84
|
-
public async get(huri: Huri | string, responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<XyoPayload>> {
|
|
85
|
-
const huriObj = typeof huri === 'string' ? new Huri(huri) : huri
|
|
86
|
-
switch (responseType) {
|
|
87
|
-
case 'tuple':
|
|
88
|
-
return await this.getEndpoint(huriObj.href, 'tuple')
|
|
89
|
-
default:
|
|
90
|
-
return await this.getEndpoint(huriObj.href, 'body')
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
77
|
public huri(huri: Huri | string) {
|
|
95
78
|
const huriObj = typeof huri === 'string' ? new Huri(huri) : huri
|
|
96
79
|
return new XyoApiSimple<XyoPayload>({
|
|
@@ -112,7 +95,7 @@ export class XyoArchivistApi extends XyoApiBase {
|
|
|
112
95
|
}
|
|
113
96
|
|
|
114
97
|
/** @deprecated use account instead */
|
|
115
|
-
public wallet(address:
|
|
98
|
+
public wallet(address: DataLike) {
|
|
116
99
|
return this.account(address)
|
|
117
100
|
}
|
|
118
101
|
}
|
package/src/Api/ApiUtil.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Wallet } from '@ethersproject/wallet'
|
|
2
2
|
import { assertEx } from '@xylabs/assert'
|
|
3
|
-
import {
|
|
3
|
+
import { Account } from '@xyo-network/account'
|
|
4
|
+
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
4
5
|
import { uuid } from '@xyo-network/core'
|
|
5
6
|
|
|
6
7
|
import { XyoArchivistApi } from './Api'
|
|
@@ -9,13 +10,27 @@ test('Must have tests defined', () => {
|
|
|
9
10
|
expect(true).toBeTruthy()
|
|
10
11
|
})
|
|
11
12
|
|
|
13
|
+
export const getApiConfig = (configData: Partial<XyoApiConfig> = {}): XyoApiConfig => {
|
|
14
|
+
const defaults: XyoApiConfig = {
|
|
15
|
+
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
16
|
+
onError: (error) => error,
|
|
17
|
+
onFailure: (response) => response,
|
|
18
|
+
onSuccess: (response) => response,
|
|
19
|
+
}
|
|
20
|
+
return Object.assign({}, defaults, configData)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getApi = (configData: Partial<XyoApiConfig> = {}): XyoArchivistApi => {
|
|
24
|
+
return new XyoArchivistApi(getApiConfig(configData))
|
|
25
|
+
}
|
|
26
|
+
|
|
12
27
|
export const getRandomArchiveName = (): string => {
|
|
13
28
|
const randomString = (Math.random() + 1).toString(36).substring(7).toLowerCase()
|
|
14
29
|
return `test-archive-${randomString}`
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
export const getTokenForNewUser = async (api: XyoArchivistApi): Promise<string> => {
|
|
18
|
-
const account =
|
|
33
|
+
const account = Account.random()
|
|
19
34
|
const address = new Wallet(account.private.bytes)
|
|
20
35
|
const challenge = await api.account(account.public).challenge.post()
|
|
21
36
|
const message = assertEx(challenge?.state, 'Missing state from login challenge')
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getApi, getRandomArchiveName, getTokenForNewUser } from '../ApiUtil.spec'
|
|
2
|
+
|
|
3
|
+
describe('XyoArchivistArchiveApi', () => {
|
|
4
|
+
const api = getApi()
|
|
5
|
+
const archive = getRandomArchiveName()
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
const token = await getTokenForNewUser(api)
|
|
8
|
+
api.config.jwtToken = token
|
|
9
|
+
})
|
|
10
|
+
describe('put', () => {
|
|
11
|
+
it('creates the archive', async () => {
|
|
12
|
+
const response = await api.archives.archive(archive).put()
|
|
13
|
+
expect(response?.archive).toEqual(archive)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
describe('get', () => {
|
|
17
|
+
it('gets the archive', async () => {
|
|
18
|
+
const response = await api.archives.archive(archive).get()
|
|
19
|
+
expect(response?.archive).toBe(archive)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
|
|
3
|
+
import { XyoArchiveKey } from '../../../../models'
|
|
4
|
+
import { XyoArchivistApi } from '../../../Api'
|
|
5
|
+
import { getApi, getRandomArchiveName, getTokenForNewUser } from '../../../ApiUtil.spec'
|
|
6
|
+
|
|
7
|
+
describe('XyoArchivistArchiveSettingsKeyApi', () => {
|
|
8
|
+
let api: XyoArchivistApi
|
|
9
|
+
let archive = ''
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
archive = getRandomArchiveName()
|
|
12
|
+
api = getApi()
|
|
13
|
+
const token = await getTokenForNewUser(api)
|
|
14
|
+
api.config.jwtToken = token
|
|
15
|
+
await api.archives.archive(archive).put()
|
|
16
|
+
})
|
|
17
|
+
describe('post', () => {
|
|
18
|
+
it('Creates an archive key', async () => {
|
|
19
|
+
const response = await api.archives.archive(archive).settings.key.post()
|
|
20
|
+
expect(response).toBeArrayOfSize(1)
|
|
21
|
+
const key = response?.[0]
|
|
22
|
+
expect(key).toBeObject()
|
|
23
|
+
expect(key?.archive).toBeString()
|
|
24
|
+
expect(key?.key).toBeString()
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
describe('get', () => {
|
|
28
|
+
let key: XyoArchiveKey
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
const response = await api.archives.archive(archive).settings.key.post()
|
|
31
|
+
key = assertEx(response?.[0])
|
|
32
|
+
})
|
|
33
|
+
it('Returns the keys for the archive', async () => {
|
|
34
|
+
const response = await api.archives.archive(archive).settings.key.get()
|
|
35
|
+
expect(response).toBeArrayOfSize(1)
|
|
36
|
+
expect(response).toContainEqual(key)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { XyoArchiveKey } from '../../../../models'
|
|
2
2
|
import { XyoApiSimple } from '../../../../Simple'
|
|
3
3
|
|
|
4
|
-
export class XyoArchivistArchiveSettingsKeyApi extends XyoApiSimple<XyoArchiveKey[]> {
|
|
5
|
-
public key(key: string) {
|
|
6
|
-
return new XyoApiSimple<XyoArchiveKey>({
|
|
7
|
-
...this.config,
|
|
8
|
-
root: `${this.root}${key}/`,
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
}
|
|
4
|
+
export class XyoArchivistArchiveSettingsKeyApi extends XyoApiSimple<XyoArchiveKey[]> {}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getApi } from '../ApiUtil.spec'
|
|
2
|
+
|
|
3
|
+
describe('XyoArchivistArchivesApi', () => {
|
|
4
|
+
describe('get', function () {
|
|
5
|
+
it('gets an array of archives owned', async () => {
|
|
6
|
+
const api = getApi()
|
|
7
|
+
const response = await api.archives.get()
|
|
8
|
+
expect(response).toBeArray()
|
|
9
|
+
expect(response?.length).toBeGreaterThan(0)
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BoundWitnessBuilder } from '@xyo-network/boundwitness'
|
|
2
|
+
|
|
3
|
+
import { testPayload } from '../../Test'
|
|
4
|
+
import { getApi, getNewArchive } from '../ApiUtil.spec'
|
|
5
|
+
|
|
6
|
+
describe('XyoArchivistArchiveBlockApi', () => {
|
|
7
|
+
const api = getApi()
|
|
8
|
+
describe('post', function () {
|
|
9
|
+
it.each([true, false])('posts a single bound witness', async (inlinePayloads) => {
|
|
10
|
+
const builder = new BoundWitnessBuilder({ inlinePayloads }).payload(testPayload)
|
|
11
|
+
const [bw] = builder.build()
|
|
12
|
+
const blocks = [bw]
|
|
13
|
+
const response = await api.archives.archive().block.post(blocks)
|
|
14
|
+
expect(response?.length).toEqual(blocks.length)
|
|
15
|
+
})
|
|
16
|
+
it.each([true, false])('posts multiple bound witnesses', async (inlinePayloads) => {
|
|
17
|
+
const builder = new BoundWitnessBuilder({ inlinePayloads }).payload(testPayload)
|
|
18
|
+
const [bw] = builder.build()
|
|
19
|
+
const blocks = [bw, bw]
|
|
20
|
+
const response = await api.archives.archive().block.post(blocks)
|
|
21
|
+
expect(response?.length).toEqual(blocks.length)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
describe('stats', () => {
|
|
25
|
+
const [bw] = new BoundWitnessBuilder().build()
|
|
26
|
+
const blocks = [bw]
|
|
27
|
+
let archive = ''
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
archive = await getNewArchive(api)
|
|
30
|
+
})
|
|
31
|
+
it('returns stats for boundwitness', async () => {
|
|
32
|
+
await api.archives.archive(archive).block.post(blocks)
|
|
33
|
+
const stats = await api.archives.archive(archive).block.stats.get()
|
|
34
|
+
expect(stats?.count).toBeGreaterThanOrEqual(blocks.length)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
describe('find', () => {
|
|
38
|
+
const [bw] = new BoundWitnessBuilder().build()
|
|
39
|
+
const blocks = [bw]
|
|
40
|
+
let archive = ''
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
archive = await getNewArchive(api)
|
|
43
|
+
})
|
|
44
|
+
it('returns bound witnesses from before the timestamp', async () => {
|
|
45
|
+
const timestamp = Date.now() - 10000
|
|
46
|
+
await api.archives.archive(archive).block.post(blocks)
|
|
47
|
+
const response = await api.archives.archive(archive).block.find({ order: 'asc', timestamp })
|
|
48
|
+
expect(response?.length).toBe(blocks.length)
|
|
49
|
+
})
|
|
50
|
+
it('returns bound witnesses from after the timestamp', async () => {
|
|
51
|
+
await api.archives.archive(archive).block.post(blocks)
|
|
52
|
+
const timestamp = Date.now() + 10000
|
|
53
|
+
const response = await api.archives.archive(archive).block.find({ order: 'desc', timestamp })
|
|
54
|
+
expect(response?.length).toBe(blocks.length)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { XyoAccount } from '@xyo-network/account'
|
|
2
|
-
import { XyoApiConfig, XyoApiError } from '@xyo-network/api-models'
|
|
3
1
|
import { BoundWitnessBuilder } from '@xyo-network/boundwitness'
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
import { getNewArchive, getTimestampMinutesFromNow } from '../ApiUtil.spec'
|
|
7
|
-
|
|
8
|
-
const configData: XyoApiConfig = {
|
|
9
|
-
apiDomain: process.env.API_DOMAIN || 'https://beta.api.archivist.xyo.network',
|
|
10
|
-
onError: (error) => console.error(`Error: ${JSON.stringify(error)}`),
|
|
11
|
-
onFailure: (response) => response, //console.error(`Failure: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
|
|
12
|
-
onSuccess: (response) => response, //console.log(`Success: ${response.statusText} [${response.status}] [${JSON.stringify(response.data)}]`),
|
|
13
|
-
}
|
|
3
|
+
import { getApi, getNewArchive, getTimestampMinutesFromNow } from '../ApiUtil.spec'
|
|
14
4
|
|
|
15
5
|
describe('XyoArchivistPayloadApi', () => {
|
|
16
6
|
describe('find', () => {
|
|
17
|
-
const api =
|
|
7
|
+
const api = getApi()
|
|
18
8
|
let archive = ''
|
|
19
9
|
beforeEach(async () => {
|
|
20
10
|
archive = await getNewArchive(api)
|
|
@@ -22,34 +12,22 @@ describe('XyoArchivistPayloadApi', () => {
|
|
|
22
12
|
})
|
|
23
13
|
describe('when order is ascending', () => {
|
|
24
14
|
it('returns payloads greater than or equal to timestamp', async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
expect(response?.length).toBe(1)
|
|
32
|
-
} catch (ex) {
|
|
33
|
-
const error = ex as XyoApiError
|
|
34
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
35
|
-
expect(error === undefined)
|
|
36
|
-
}
|
|
15
|
+
const timestamp = getTimestampMinutesFromNow(-1)
|
|
16
|
+
const [boundWitness] = new BoundWitnessBuilder().build()
|
|
17
|
+
const blockResult = await api.archive(archive).block.post([boundWitness])
|
|
18
|
+
expect(blockResult?.length).toBe(1)
|
|
19
|
+
const response = await api.archive(archive).block.find({ order: 'asc', timestamp })
|
|
20
|
+
expect(response?.length).toBe(1)
|
|
37
21
|
})
|
|
38
22
|
})
|
|
39
23
|
describe('when order is descending', () => {
|
|
40
24
|
it('returns payloads less than or equal to timestamp', async () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(response?.length).toBe(1)
|
|
48
|
-
} catch (ex) {
|
|
49
|
-
const error = ex as XyoApiError
|
|
50
|
-
console.log(JSON.stringify(error.response?.data, null, 2))
|
|
51
|
-
expect(error === undefined)
|
|
52
|
-
}
|
|
25
|
+
const [boundWitness] = new BoundWitnessBuilder().build()
|
|
26
|
+
const blockResult = await api.archive(archive).block.post([boundWitness])
|
|
27
|
+
expect(blockResult?.length).toBe(1)
|
|
28
|
+
const timestamp = getTimestampMinutesFromNow(1)
|
|
29
|
+
const response = await api.archive(archive).block.find({ order: 'desc', timestamp })
|
|
30
|
+
expect(response?.length).toBe(1)
|
|
53
31
|
})
|
|
54
32
|
})
|
|
55
33
|
})
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { XyoAccount } from '@xyo-network/account'
|
|
2
1
|
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
3
2
|
import { BoundWitnessBuilder } from '@xyo-network/boundwitness'
|
|
4
3
|
import { XyoSchemaPayload, XyoSchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
@@ -24,7 +23,7 @@ describe('XyoArchivistArchiveSchemaApi', () => {
|
|
|
24
23
|
let archive = ''
|
|
25
24
|
beforeAll(async () => {
|
|
26
25
|
archive = await getNewArchive(api)
|
|
27
|
-
const [boundWitness] = new BoundWitnessBuilder({ inlinePayloads: true }).
|
|
26
|
+
const [boundWitness] = new BoundWitnessBuilder({ inlinePayloads: true }).payload(payload).build()
|
|
28
27
|
await api.archives.archive(archive).block.post([boundWitness])
|
|
29
28
|
})
|
|
30
29
|
describe('get', () => {
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
2
2
|
import { ArchivistWrapper } from '@xyo-network/archivist'
|
|
3
|
+
import { XyoBoundWitnessSchema } from '@xyo-network/boundwitness'
|
|
3
4
|
import { PayloadWrapper } from '@xyo-network/payload'
|
|
5
|
+
import { XyoIdSchema } from '@xyo-network/payload-plugins'
|
|
4
6
|
|
|
5
7
|
import { XyoArchivistApi } from '../Api'
|
|
6
8
|
import { XyoRemoteArchivist } from './XyoRemoteArchivist'
|
|
7
9
|
import { XyoRemoteArchivistConfigSchema } from './XyoRemoteArchivistConfig'
|
|
8
10
|
|
|
9
11
|
const configData: XyoApiConfig = {
|
|
10
|
-
apiDomain: process.env.API_DOMAIN || '
|
|
11
|
-
onError: (error) =>
|
|
12
|
-
onFailure: (response) => response,
|
|
13
|
-
onSuccess: (response) => response,
|
|
12
|
+
apiDomain: process.env.API_DOMAIN || 'http://locahost:8080',
|
|
13
|
+
onError: (error) => error,
|
|
14
|
+
onFailure: (response) => response,
|
|
15
|
+
onSuccess: (response) => response,
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
const payload = {
|
|
17
19
|
salt: `${Math.random() * 10000}`,
|
|
18
|
-
schema:
|
|
20
|
+
schema: XyoIdSchema,
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
describe('XyoRemoteArchivist', () => {
|
|
@@ -42,12 +44,12 @@ describe('XyoRemoteArchivist', () => {
|
|
|
42
44
|
it('get returns boundwitness', async () => {
|
|
43
45
|
const payload = {
|
|
44
46
|
payload_hashes: ['123456'],
|
|
45
|
-
payload_schemas: [
|
|
46
|
-
schema:
|
|
47
|
+
payload_schemas: [XyoIdSchema],
|
|
48
|
+
schema: XyoBoundWitnessSchema,
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
await archivist.insert([payload])
|
|
50
52
|
const getResult = await archivist.get([new PayloadWrapper(payload).hash])
|
|
51
|
-
expect(getResult?.[0].schema).toBe(
|
|
53
|
+
expect(getResult?.[0].schema).toBe(XyoBoundWitnessSchema)
|
|
52
54
|
})
|
|
53
55
|
})
|