@xyo-network/api 4.3.0 → 5.0.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/api",
3
- "version": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -28,26 +28,30 @@
28
28
  },
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "src"
34
+ ],
31
35
  "dependencies": {
32
- "@xylabs/axios": "^4.15.0",
33
- "@xylabs/typeof": "^4.15.0",
34
- "@xyo-network/api-models": "^4.3.0",
35
- "@xyo-network/diviner-model": "^4.3.0",
36
- "@xyo-network/huri": "^4.3.0",
37
- "@xyo-network/payload-model": "^4.3.0",
36
+ "@xylabs/axios": "^5.0.0",
37
+ "@xylabs/typeof": "^5.0.0",
38
+ "@xyo-network/api-models": "^5.0.0",
39
+ "@xyo-network/diviner-model": "^5.0.0",
40
+ "@xyo-network/huri": "^5.0.0",
41
+ "@xyo-network/payload-model": "^5.0.0",
38
42
  "axios": "^1.11.0"
39
43
  },
40
44
  "devDependencies": {
41
45
  "@types/node": "^24.1.0",
42
46
  "@types/uuid": "^10.0.0",
43
- "@xylabs/hex": "^4.15.0",
44
- "@xylabs/object": "^4.15.0",
45
- "@xylabs/ts-scripts-yarn3": "^7.0.1",
46
- "@xylabs/tsconfig": "^7.0.1",
47
- "@xylabs/vitest-extended": "^4.15.0",
48
- "@xyo-network/boundwitness-model": "^4.3.0",
49
- "@xyo-network/module-model": "^4.3.0",
50
- "@xyo-network/query-payload-plugin": "^4.3.0",
47
+ "@xylabs/hex": "^5.0.0",
48
+ "@xylabs/object": "^5.0.0",
49
+ "@xylabs/ts-scripts-yarn3": "^7.0.2",
50
+ "@xylabs/tsconfig": "^7.0.2",
51
+ "@xylabs/vitest-extended": "^5.0.0",
52
+ "@xyo-network/boundwitness-model": "^5.0.0",
53
+ "@xyo-network/module-model": "^5.0.0",
54
+ "@xyo-network/query-payload-plugin": "^5.0.0",
51
55
  "typescript": "^5.8.3",
52
56
  "uuid": "^11.1.0",
53
57
  "vitest": "^3.2.4"
@@ -0,0 +1,30 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { AddressPayload } from '@xyo-network/module-model'
4
+ import { AddressSchema } from '@xyo-network/module-model'
5
+ import type { QueryPayload } from '@xyo-network/query-payload-plugin'
6
+ import { QuerySchema } from '@xyo-network/query-payload-plugin'
7
+ import {
8
+ describe, expect, it,
9
+ } from 'vitest'
10
+
11
+ import { getApi } from './ApiUtil.spec.ts'
12
+
13
+ describe('ArchivistApi', () => {
14
+ describe('get', () => {
15
+ it('returns Node Discover', async () => {
16
+ const api = getApi()
17
+ expect(api).toBeDefined()
18
+ const response = await api.get()
19
+ expect(response).toBeArray()
20
+
21
+ expect(response).toBeArray()
22
+ const addressPayload = response?.find(p => p.schema === AddressSchema) as AddressPayload
23
+ expect(addressPayload).toBeObject()
24
+ expect(addressPayload.address).toBeString()
25
+
26
+ const queries = response?.filter(d => d.schema === QuerySchema) as QueryPayload[]
27
+ expect(queries.length).toBeGreaterThan(0)
28
+ })
29
+ })
30
+ })
@@ -0,0 +1,37 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { ApiConfig } from '@xyo-network/api-models'
4
+ import { v4 as uuid } from 'uuid'
5
+ import { expect, test } from 'vitest'
6
+
7
+ import { ArchivistApi } from '../Api.ts'
8
+
9
+ test('Must have tests defined', () => {
10
+ expect(true).toBeTruthy()
11
+ })
12
+
13
+ export const getApiConfig = (configData: Partial<ApiConfig> = {}): ApiConfig => {
14
+ const apiDomain = process.env.API_DOMAIN ?? 'http://localhost:8080'
15
+ const defaults: ApiConfig = {
16
+ apiDomain,
17
+ onError: error => error,
18
+ onFailure: response => response,
19
+ onSuccess: response => response,
20
+ }
21
+ return Object.assign({}, defaults, configData)
22
+ }
23
+
24
+ export const getApi = (configData: Partial<ApiConfig> = {}): ArchivistApi => {
25
+ return new ArchivistApi(getApiConfig(configData))
26
+ }
27
+
28
+ export const testSchemaPrefix = 'network.xyo.schema.test.'
29
+ export const getSchemaName = (): string => {
30
+ return `${testSchemaPrefix}${uuid()}`
31
+ }
32
+
33
+ export const getTimestampMinutesFromNow = (minutes = 0) => {
34
+ const t = new Date()
35
+ t.setMinutes(t.getMinutes() + minutes)
36
+ return +t
37
+ }
@@ -0,0 +1,93 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { ApiConfig } from '@xyo-network/api-models'
4
+ import {
5
+ describe, expect, it,
6
+ } from 'vitest'
7
+
8
+ import { LocationDivinerApi } from '../LocationDivinerApi.ts'
9
+ import type {
10
+ LocationHeatmapQueryCreationRequest,
11
+ LocationTimeRangeQueryCreationRequest,
12
+ } from '../Queries/index.ts'
13
+ import {
14
+ LocationHeatmapQuerySchema,
15
+ LocationTimeRangeQuerySchema,
16
+ } from '../Queries/index.ts'
17
+ import { LocationWitnessSchema } from '../Witnesses/index.ts'
18
+
19
+ const describeIf = <T>(expr?: T | null) => (expr ? describe : describe.skip)
20
+
21
+ const getLocationApiConfig = (): ApiConfig => {
22
+ return { apiDomain: process.env.LOCATION_API_DOMAIN || 'http://localhost:8082' }
23
+ }
24
+
25
+ const getArchiveConfig = (): ApiConfig => {
26
+ const apiDomain = process.env.API_DOMAIN || 'http://localhost:8080'
27
+ return { apiDomain }
28
+ }
29
+
30
+ const getDefaultStartStopTime = () => {
31
+ const startTime = new Date(0).toISOString()
32
+ const stopTime = new Date().toISOString()
33
+ return { startTime, stopTime }
34
+ }
35
+
36
+ const getLocationTimeRangeQueryCreationRequest = (): LocationTimeRangeQueryCreationRequest => {
37
+ const query = { schema: LocationWitnessSchema, ...getDefaultStartStopTime() }
38
+ const sourceArchivist = { ...getArchiveConfig() }
39
+ const resultArchivist = { ...getArchiveConfig() }
40
+ return {
41
+ query,
42
+ resultArchive: 'temp',
43
+ resultArchivist,
44
+ schema: LocationTimeRangeQuerySchema,
45
+ sourceArchive: 'temp',
46
+ sourceArchivist,
47
+ }
48
+ }
49
+
50
+ const getLocationHeatmapQueryCreationRequest = (): LocationHeatmapQueryCreationRequest => {
51
+ const query = { schema: LocationWitnessSchema, ...getDefaultStartStopTime() }
52
+ const sourceArchivist = { ...getArchiveConfig() }
53
+ const resultArchivist = { ...getArchiveConfig() }
54
+ return {
55
+ query,
56
+ resultArchive: 'temp',
57
+ resultArchivist,
58
+ schema: LocationHeatmapQuerySchema,
59
+ sourceArchive: 'temp',
60
+ sourceArchivist,
61
+ }
62
+ }
63
+
64
+ describeIf(process.env.LOCATION_API_DOMAIN)('LocationDivinerApi', () => {
65
+ describe('constructor', () => {
66
+ it('returns a new LocationDivinerApi', () => {
67
+ const api = new LocationDivinerApi(getLocationApiConfig())
68
+ expect(api).toBeDefined()
69
+ })
70
+ })
71
+ describe('postLocationQuery', () => {
72
+ it('posts a location heatmap query', async () => {
73
+ const api = new LocationDivinerApi(getLocationApiConfig())
74
+ const locationQuery = await api.postLocationQuery(getLocationHeatmapQueryCreationRequest())
75
+ const response = await api.getLocationQuery(locationQuery.hash)
76
+ expect(response.queryHash).toBe(locationQuery.hash)
77
+ })
78
+ it('posts a location time range query', async () => {
79
+ const api = new LocationDivinerApi(getLocationApiConfig())
80
+ const locationQuery = await api.postLocationQuery(getLocationTimeRangeQueryCreationRequest())
81
+ const response = await api.getLocationQuery(locationQuery.hash)
82
+ expect(response.queryHash).toBe(locationQuery.hash)
83
+ })
84
+ })
85
+ describe('getLocationQuery', function () {
86
+ it('gets the status of a previously posted location query', async () => {
87
+ const api = new LocationDivinerApi(getLocationApiConfig())
88
+ const locationQuery = await api.postLocationQuery(getLocationTimeRangeQueryCreationRequest())
89
+ const response = await api.getLocationQuery(locationQuery.hash)
90
+ expect(response.queryHash).toBe(locationQuery.hash)
91
+ })
92
+ })
93
+ })
@@ -0,0 +1,8 @@
1
+ export * from './testBoundWitness.spec.ts'
2
+ export * from './testPayload.spec.ts'
3
+
4
+ import { expect, it } from 'vitest'
5
+
6
+ it('no test', () => {
7
+ expect(true).toBeTruthy()
8
+ })
@@ -0,0 +1,22 @@
1
+ import {
2
+ asAddress, asHash, asHex,
3
+ } from '@xylabs/hex'
4
+ import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
+ import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
6
+ import { it } from 'vitest'
7
+
8
+ const testBoundWitness: BoundWitness = {
9
+ $signatures: [asHex(
10
+ '95100e5fd2012b958e96895870cfac5353c3a33a19314cfd1304ef7d01d052ec2a3ef80d6449cf88d463027fe0d868ed8cfb8b7323d37e93a08570233eea0b17',
11
+ true,
12
+ )],
13
+ addresses: [asAddress('5346a2ce56ec4177b67092bda710e150ba6fa046', true)],
14
+ payload_hashes: [asHash('20e14207f952a09f767ff614a648546c037fe524ace0bfe55db31f818aff1f1c', true)],
15
+ payload_schemas: ['network.xyo.test'],
16
+ previous_hashes: [null],
17
+ schema: BoundWitnessSchema,
18
+ } as BoundWitness
19
+
20
+ it('no test', () => {})
21
+
22
+ export { testBoundWitness }
@@ -0,0 +1,22 @@
1
+ import type { StringKeyObject } from '@xylabs/object'
2
+ import type { Payload } from '@xyo-network/payload-model'
3
+ import { expect, it } from 'vitest'
4
+
5
+ const testSchema = 'network.xyo.test'
6
+ const testPayload: Payload<StringKeyObject> = {
7
+ _hash: '20e14207f952a09f767ff614a648546c037fe524ace0bfe55db31f818aff1f1c',
8
+ _timestamp: 1_609_459_255_555,
9
+ numberField: 1,
10
+ objectField: {
11
+ numberField: 1,
12
+ stringField: 'stringValue',
13
+ },
14
+ schema: testSchema,
15
+ stringField: 'stringValue',
16
+ }
17
+
18
+ it('no test', () => {
19
+ expect(true).toBeTruthy()
20
+ })
21
+
22
+ export { testPayload, testSchema }
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- neutral: { src: true },
6
- node: {},
7
- },
8
- }
9
-
10
- export default config