@xyo-network/domain-payload-plugin 5.3.22 → 5.3.25
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 +17 -21
- package/src/Payload.ts +0 -22
- package/src/Plugin.ts +0 -14
- package/src/Schema.ts +0 -4
- package/src/Template.ts +0 -25
- package/src/Wrapper.ts +0 -113
- package/src/index.ts +0 -5
- package/src/schemadef.json +0 -115
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/domain-payload-plugin",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.25",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,42 +30,38 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src",
|
|
34
33
|
"!**/*.bench.*",
|
|
35
34
|
"!**/*.spec.*",
|
|
36
35
|
"!**/*.test.*",
|
|
37
36
|
"README.md"
|
|
38
37
|
],
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@xyo-network/dns": "~5.3.
|
|
41
|
-
"@xyo-network/
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/payload-builder": "~5.3.
|
|
44
|
-
"@xyo-network/payload-model": "~5.3.
|
|
45
|
-
"@xyo-network/payload-plugin": "~5.3.
|
|
46
|
-
"@xyo-network/payload-wrapper": "~5.3.
|
|
39
|
+
"@xyo-network/dns": "~5.3.25",
|
|
40
|
+
"@xyo-network/network": "~5.3.25",
|
|
41
|
+
"@xyo-network/huri": "~5.3.25",
|
|
42
|
+
"@xyo-network/payload-builder": "~5.3.25",
|
|
43
|
+
"@xyo-network/payload-model": "~5.3.25",
|
|
44
|
+
"@xyo-network/payload-plugin": "~5.3.25",
|
|
45
|
+
"@xyo-network/payload-wrapper": "~5.3.25"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@opentelemetry/api": "^1.9.1",
|
|
50
49
|
"@types/node": "^25.5.0",
|
|
51
|
-
"@xylabs/sdk-js": "^5.0.
|
|
52
|
-
"@xylabs/ts-scripts-common": "~7.6.
|
|
53
|
-
"@xylabs/ts-scripts-
|
|
54
|
-
"@xylabs/tsconfig": "~7.6.
|
|
55
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
56
|
-
"@xyo-network/api-models": "~5.3.22",
|
|
50
|
+
"@xylabs/sdk-js": "^5.0.93",
|
|
51
|
+
"@xylabs/ts-scripts-common": "~7.6.16",
|
|
52
|
+
"@xylabs/ts-scripts-pnpm": "~7.6.16",
|
|
53
|
+
"@xylabs/tsconfig": "~7.6.16",
|
|
54
|
+
"@xylabs/vitest-extended": "~5.0.93",
|
|
57
55
|
"acorn": "^8.16.0",
|
|
58
56
|
"axios": "^1.14.0",
|
|
59
|
-
"
|
|
60
|
-
"esbuild": "^0.27.4",
|
|
61
|
-
"eslint": "^10.1.0",
|
|
57
|
+
"esbuild": "^0.28.0",
|
|
62
58
|
"ethers": "^6.16.0",
|
|
63
|
-
"rollup": "^4.60.1",
|
|
64
59
|
"tslib": "^2.8.1",
|
|
65
60
|
"typescript": "~5.9.3",
|
|
66
61
|
"vite": "^8.0.3",
|
|
67
62
|
"vitest": "~4.1.2",
|
|
68
|
-
"zod": "^4.3.6"
|
|
63
|
+
"zod": "^4.3.6",
|
|
64
|
+
"@xyo-network/api-models": "~5.3.25"
|
|
69
65
|
},
|
|
70
66
|
"peerDependencies": {
|
|
71
67
|
"@xylabs/sdk-js": "^5",
|
|
@@ -76,4 +72,4 @@
|
|
|
76
72
|
"publishConfig": {
|
|
77
73
|
"access": "public"
|
|
78
74
|
}
|
|
79
|
-
}
|
|
75
|
+
}
|
package/src/Payload.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NetworkPayload } from '@xyo-network/network'
|
|
2
|
-
import { isPayloadOfSchemaType, type Payload } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import { DomainSchema } from './Schema.ts'
|
|
5
|
-
|
|
6
|
-
export interface Alias {
|
|
7
|
-
/** @field huri to the aliased payload */
|
|
8
|
-
huri: string
|
|
9
|
-
/** @field canonical name (ex. network.xyo.example) */
|
|
10
|
-
name?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type DomainPayload = Payload<{
|
|
14
|
-
/** @field Additional config files [huri] [out] */
|
|
15
|
-
additional?: string[]
|
|
16
|
-
/** @field Values associated with this domain [out] */
|
|
17
|
-
aliases?: Record<string, Alias>
|
|
18
|
-
/** @field Known networks [out] */
|
|
19
|
-
networks?: NetworkPayload[]
|
|
20
|
-
}, DomainSchema>
|
|
21
|
-
|
|
22
|
-
export const isDomainPayload = isPayloadOfSchemaType<DomainPayload>(DomainSchema)
|
package/src/Plugin.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import { createPayloadPlugin } from '@xyo-network/payload-plugin'
|
|
3
|
-
|
|
4
|
-
import type { DomainPayload } from './Payload.ts'
|
|
5
|
-
import { DomainSchema } from './Schema.ts'
|
|
6
|
-
import { domainConfigTemplate } from './Template.ts'
|
|
7
|
-
import { DomainPayloadWrapper } from './Wrapper.ts'
|
|
8
|
-
|
|
9
|
-
export const DomainPayloadPlugin = () =>
|
|
10
|
-
createPayloadPlugin<DomainPayload>({
|
|
11
|
-
schema: DomainSchema,
|
|
12
|
-
template: domainConfigTemplate,
|
|
13
|
-
wrap: (payload: Payload) => DomainPayloadWrapper.wrap(payload as DomainPayload),
|
|
14
|
-
})
|
package/src/Schema.ts
DELETED
package/src/Template.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
2
|
-
|
|
3
|
-
import type { DomainPayload } from './Payload.ts'
|
|
4
|
-
import { DomainSchema } from './Schema.ts'
|
|
5
|
-
|
|
6
|
-
export const domainConfigTemplate = (): DomainPayload => ({
|
|
7
|
-
aliases: { 'com.example.id': { huri: '' } },
|
|
8
|
-
networks: [
|
|
9
|
-
{
|
|
10
|
-
name: '',
|
|
11
|
-
nodes: [
|
|
12
|
-
{
|
|
13
|
-
name: '',
|
|
14
|
-
schema: asSchema('network.xyo.network.node', true),
|
|
15
|
-
slug: '',
|
|
16
|
-
type: 'archivist',
|
|
17
|
-
uri: '',
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
schema: asSchema('network.xyo.network', true),
|
|
21
|
-
slug: '',
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
schema: DomainSchema,
|
|
25
|
-
})
|
package/src/Wrapper.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
axiosJson, Base, isBrowser,
|
|
3
|
-
isString,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import { type Hash, isHash } from '@xylabs/sdk-js'
|
|
6
|
-
import type { ApiEnvelope } from '@xyo-network/api-models'
|
|
7
|
-
import { DnsRecordType, domainResolve } from '@xyo-network/dns'
|
|
8
|
-
import type { FetchedPayload, HuriOptions } from '@xyo-network/huri'
|
|
9
|
-
import { Huri } from '@xyo-network/huri'
|
|
10
|
-
import type { NetworkPayload } from '@xyo-network/network'
|
|
11
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
12
|
-
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
13
|
-
import type { AxiosError } from 'axios'
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
type Alias, type DomainPayload, isDomainPayload,
|
|
17
|
-
} from './Payload.ts'
|
|
18
|
-
|
|
19
|
-
export interface FetchedAlias extends FetchedPayload {
|
|
20
|
-
alias: Alias
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class DomainPayloadWrapper<T extends DomainPayload = DomainPayload> extends PayloadWrapper<T> {
|
|
24
|
-
aliases?: FetchedAlias[] | null
|
|
25
|
-
|
|
26
|
-
static async discover(reverseDomainName: string, proxy?: string) {
|
|
27
|
-
const parts = reverseDomainName.split('.')
|
|
28
|
-
for (let i = 2; i <= parts.length; i++) {
|
|
29
|
-
const domainToCheck = parts.filter((_, index) => index < i).toReversed().join('.')
|
|
30
|
-
const result = (await this.discoverDNSEntry(domainToCheck)) ?? (await this.discoverRootFile(domainToCheck, proxy))
|
|
31
|
-
if (result) {
|
|
32
|
-
return result
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static async discoverDNSEntry(domain: string) {
|
|
38
|
-
try {
|
|
39
|
-
const hash = (await domainResolve(`_xyo.${domain}`, DnsRecordType.TXT))?.Answer?.[0]?.data
|
|
40
|
-
if (isHash(hash)) {
|
|
41
|
-
const huri = new Huri(hash)
|
|
42
|
-
const payload = (await huri.fetch())
|
|
43
|
-
if (isDomainPayload(payload)) {
|
|
44
|
-
return new DomainPayloadWrapper(payload)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} catch {
|
|
48
|
-
Base.defaultLogger?.log(`DomainConfig dns reading error entry not found [${domain}]`)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static async discoverRootFile(domain: string, proxy?: string) {
|
|
53
|
-
return isBrowser() || isString(proxy) ? await this.discoverRootFileWithProxy(domain, proxy) : await this.discoverRootFileDirect(domain)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static async discoverRootFileDirect(domain: string) {
|
|
57
|
-
try {
|
|
58
|
-
const config = (await axiosJson.get<DomainPayload>(`https://${domain}/xyo-config.json`)).data
|
|
59
|
-
return new DomainPayloadWrapper(config)
|
|
60
|
-
} catch {
|
|
61
|
-
console.log(`DomainConfig root file not found [${domain}]`)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static async discoverRootFileWithProxy(domain: string, proxy = 'https://api.archivist.xyo.network/domain') {
|
|
66
|
-
try {
|
|
67
|
-
const requestUrl = `${proxy}/${domain.split('.').toReversed().join('.')}`
|
|
68
|
-
const config = (await axiosJson.get<ApiEnvelope<DomainPayload>>(requestUrl)).data.data
|
|
69
|
-
return new DomainPayloadWrapper(config)
|
|
70
|
-
} catch (ex) {
|
|
71
|
-
const error = ex as AxiosError
|
|
72
|
-
console.log(`DomainConfig root file not found using proxy [${domain}] [${error.code}]`)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async fetch(networkSlug?: Hash) {
|
|
77
|
-
await this.fetchAliases(networkSlug)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async fetchAliases(networkSlug?: Hash) {
|
|
81
|
-
// set it to null to signify fetch ran
|
|
82
|
-
this.aliases = null
|
|
83
|
-
|
|
84
|
-
const archivistUri = await this.findArchivistUri(networkSlug)
|
|
85
|
-
if (this.payload.aliases) {
|
|
86
|
-
const fetchedAliases = await Promise.all(
|
|
87
|
-
Object.entries(this.payload.aliases ?? {}).map(([, alias]) => {
|
|
88
|
-
return this.fetchAlias(alias, { archivistUri })
|
|
89
|
-
}),
|
|
90
|
-
)
|
|
91
|
-
// cast to FetchedPayload[] after we filter out any null/undefined entries
|
|
92
|
-
this.aliases = fetchedAliases.filter(Boolean) as FetchedAlias[]
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private async fetchAlias(alias: Alias, huriOptions?: HuriOptions): Promise<FetchedAlias | null> {
|
|
97
|
-
const huri = new Huri(alias.huri, huriOptions)
|
|
98
|
-
const payload = await huri.fetch()
|
|
99
|
-
return payload
|
|
100
|
-
? {
|
|
101
|
-
alias, huri, payload: payload,
|
|
102
|
-
}
|
|
103
|
-
: null
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private async findArchivistUri(hash?: Hash): Promise<string | undefined> {
|
|
107
|
-
return (await this.getNetwork(hash))?.nodes?.find(payload => (payload.type === 'archivist' ? payload : undefined))?.uri
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private async getNetwork(hash?: Hash): Promise<NetworkPayload | undefined> {
|
|
111
|
-
return isHash(hash) ? await PayloadBuilder.findByDataHash(this.payload.networks, hash) : this.payload.networks?.[0]
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/index.ts
DELETED
package/src/schemadef.json
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"additionalProperties": false,
|
|
4
|
-
"definitions": {
|
|
5
|
-
"alias": {
|
|
6
|
-
"additionalProperties": false,
|
|
7
|
-
"properties": {
|
|
8
|
-
"huri": {
|
|
9
|
-
"type": "string"
|
|
10
|
-
},
|
|
11
|
-
"name": {
|
|
12
|
-
"type": "string"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"required": [
|
|
16
|
-
"name",
|
|
17
|
-
"huri"
|
|
18
|
-
],
|
|
19
|
-
"type": "object"
|
|
20
|
-
},
|
|
21
|
-
"network": {
|
|
22
|
-
"additionalProperties": false,
|
|
23
|
-
"properties": {
|
|
24
|
-
"name": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
},
|
|
27
|
-
"nodes": {
|
|
28
|
-
"items": {
|
|
29
|
-
"$ref": "#/definitions/node"
|
|
30
|
-
},
|
|
31
|
-
"type": "array"
|
|
32
|
-
},
|
|
33
|
-
"slug": {
|
|
34
|
-
"type": "string"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"required": [
|
|
38
|
-
"slug"
|
|
39
|
-
],
|
|
40
|
-
"type": "object"
|
|
41
|
-
},
|
|
42
|
-
"node": {
|
|
43
|
-
"additionalProperties": false,
|
|
44
|
-
"properties": {
|
|
45
|
-
"name": {
|
|
46
|
-
"type": "string"
|
|
47
|
-
},
|
|
48
|
-
"slug": {
|
|
49
|
-
"type": "string"
|
|
50
|
-
},
|
|
51
|
-
"type": {
|
|
52
|
-
"$ref": "#/definitions/node_type"
|
|
53
|
-
},
|
|
54
|
-
"uri": {
|
|
55
|
-
"type": "string"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"required": [
|
|
59
|
-
"slug",
|
|
60
|
-
"type"
|
|
61
|
-
],
|
|
62
|
-
"type": "object"
|
|
63
|
-
},
|
|
64
|
-
"node_type": {
|
|
65
|
-
"enum": [
|
|
66
|
-
"sentinel",
|
|
67
|
-
"bridge",
|
|
68
|
-
"archivist",
|
|
69
|
-
"diviner"
|
|
70
|
-
],
|
|
71
|
-
"type": "string"
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
"properties": {
|
|
75
|
-
"additional": {
|
|
76
|
-
"description": "List of HURIs to additional configs for this domain",
|
|
77
|
-
"items": {
|
|
78
|
-
"type": "string"
|
|
79
|
-
},
|
|
80
|
-
"nullable": false,
|
|
81
|
-
"type": "array"
|
|
82
|
-
},
|
|
83
|
-
"aliases": {
|
|
84
|
-
"description": "List of HURIs to that are officially defined by this domain",
|
|
85
|
-
"items": {
|
|
86
|
-
"type": "string"
|
|
87
|
-
},
|
|
88
|
-
"nullable": false,
|
|
89
|
-
"type": "array"
|
|
90
|
-
},
|
|
91
|
-
"domain": {
|
|
92
|
-
"description": "The name of the domain that this config applies to",
|
|
93
|
-
"nullable": false,
|
|
94
|
-
"type": "string"
|
|
95
|
-
},
|
|
96
|
-
"networks": {
|
|
97
|
-
"description": "List of networks that this domain participates in",
|
|
98
|
-
"items": {
|
|
99
|
-
"$ref": "#/definitions/network"
|
|
100
|
-
},
|
|
101
|
-
"nullable": false,
|
|
102
|
-
"type": "array"
|
|
103
|
-
},
|
|
104
|
-
"schema": {
|
|
105
|
-
"description": "The schema name (must be network.xyo.domain)",
|
|
106
|
-
"nullable": false,
|
|
107
|
-
"pattern": "/^network.xyo.domain$/",
|
|
108
|
-
"type": "string"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
"required": [
|
|
112
|
-
"domain",
|
|
113
|
-
"schema"
|
|
114
|
-
]
|
|
115
|
-
}
|