@xyo-network/huri 5.3.20 → 5.3.24

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.
Files changed (3) hide show
  1. package/package.json +24 -10
  2. package/src/Huri.ts +0 -169
  3. package/src/index.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/huri",
3
- "version": "5.3.20",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,28 +30,42 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@xyo-network/account": "~5.3.20",
40
- "@xyo-network/payload-model": "~5.3.20"
39
+ "@xyo-network/account": "~5.3.24",
40
+ "@xyo-network/payload-model": "~5.3.24"
41
41
  },
42
42
  "devDependencies": {
43
- "@xylabs/sdk-js": "^5.0.90",
44
- "@xylabs/tsconfig": "~7.5.6",
45
- "@xylabs/vitest-extended": "~5.0.90",
43
+ "@opentelemetry/api": "^1.9.1",
44
+ "@types/node": "^25.5.0",
45
+ "@xylabs/sdk-js": "^5.0.93",
46
+ "@xylabs/ts-scripts-common": "~7.6.16",
47
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
48
+ "@xylabs/tsconfig": "~7.6.16",
49
+ "@xylabs/vitest-extended": "~5.0.93",
50
+ "acorn": "^8.16.0",
51
+ "axios": "^1.14.0",
52
+ "esbuild": "^0.28.0",
53
+ "ethers": "^6.16.0",
54
+ "tslib": "^2.8.1",
46
55
  "typescript": "~5.9.3",
56
+ "vite": "^8.0.3",
47
57
  "vitest": "~4.1.2",
48
- "zod": "^4.3.6"
58
+ "zod": "^4.3.6",
59
+ "@xyo-network/payload-model": "~5.3.24",
60
+ "@xyo-network/account": "~5.3.24"
49
61
  },
50
62
  "peerDependencies": {
51
63
  "@xylabs/sdk-js": "^5",
64
+ "ethers": "^6",
65
+ "tslib": "^2.8.1",
52
66
  "zod": "^4"
53
67
  },
54
68
  "publishConfig": {
55
69
  "access": "public"
56
70
  }
57
- }
71
+ }
package/src/Huri.ts DELETED
@@ -1,169 +0,0 @@
1
- import type { Address, Hash } from '@xylabs/sdk-js'
2
- import {
3
- assertEx,
4
- axiosJson,
5
- isDefined, isHash, isString,
6
- } from '@xylabs/sdk-js'
7
- import { AddressValue } from '@xyo-network/account'
8
- import type { Payload } from '@xyo-network/payload-model'
9
-
10
- export type ObjectCategory = 'block' | 'payload'
11
-
12
- export type HuriFetchFunction = (huri: Huri) => Promise<Payload | undefined>
13
-
14
- /*
15
- Valid Huri:
16
-
17
- [<protocol>://][<archivist>/[<archive>/]]<hash>
18
-
19
- defaults:
20
- protocol: https
21
- archivist: api.archivist.xyo.network
22
- */
23
-
24
- export interface HuriOptions {
25
- archivistUri?: string
26
- token?: string
27
- }
28
-
29
- export interface FetchedPayload<T extends Payload = Payload> {
30
- huri?: Huri
31
- payload: T
32
- }
33
-
34
- export class Huri<T extends Payload = Payload> {
35
- archive?: string
36
- archivist?: Address | string
37
- hash: Hash
38
- originalHref: string
39
- protocol?: string
40
- token?: string
41
-
42
- private isHuri = true
43
-
44
- constructor(huri: Hash | Huri | string, { archivistUri, token }: HuriOptions = {}) {
45
- const huriString
46
- = Huri.isHuri(huri)?.href
47
- ?? (typeof huri === 'string'
48
- ? (huri as string)
49
- : huri instanceof ArrayBuffer
50
- ? new AddressValue(huri).hex
51
- : huri.href)
52
- this.originalHref = huriString
53
-
54
- const protocol = Huri.parseProtocol(huriString)
55
- this.protocol = protocol ?? 'https'
56
-
57
- const path = assertEx(Huri.parsePath(huriString), () => 'Missing path')
58
- this.hash = assertEx(this.parsePath(path, protocol !== undefined), () => 'Missing hash') as Hash
59
-
60
- assertEx(isHash(this.hash), () => `Invalid hash [${this.hash}]`)
61
-
62
- // if archivistUri sent, overwrite protocol and archivist
63
- if (isString(archivistUri)) {
64
- const archivistUriParts = archivistUri.split('://')
65
- this.protocol = archivistUriParts[0]
66
- this.archivist = archivistUriParts[1]
67
- }
68
-
69
- this.token = token
70
-
71
- this.validateParse()
72
- }
73
-
74
- /*
75
- The full href or the hash
76
- */
77
- get href() {
78
- const parts: string[] = []
79
- if (isDefined(this.protocol)) {
80
- parts.push(`${this.protocol}:/`)
81
- }
82
- if (isDefined(this.archive)) {
83
- parts.push(`${this.archive}`)
84
- }
85
- if (isDefined(this.archivist)) {
86
- parts.push(`${this.archivist}`)
87
- }
88
- parts.push(this.hash)
89
- return parts.join('/')
90
- }
91
-
92
- static async fetch<T extends Payload = Payload>(huri: Huri): Promise<T | undefined> {
93
- const AuthHeader = isDefined(huri.token) ? { Authorization: `Bearer ${huri.token}` } : undefined
94
- return (await axiosJson.get<T>(huri.href, { headers: AuthHeader })).data
95
- }
96
-
97
- static isHuri(value: unknown) {
98
- if (typeof value === 'object') {
99
- return (value as Huri).isHuri ? (value as Huri) : undefined
100
- }
101
- }
102
-
103
- private static parsePath(huri: string) {
104
- const protocolSplit = huri.split('//')
105
- assertEx(protocolSplit.length <= 2, () => `Invalid format [${huri}]`)
106
- if (protocolSplit.length === 1) {
107
- return huri
108
- }
109
- if (protocolSplit.length === 2) {
110
- return protocolSplit[1]
111
- }
112
- }
113
-
114
- private static parseProtocol(huri: string) {
115
- const protocolSplit = huri.split('//')
116
- assertEx(protocolSplit.length <= 2, () => `Invalid second protocol [${protocolSplit[2]}]`)
117
- const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined
118
- if (isString(rawProtocol)) {
119
- const protocolParts = rawProtocol?.split(':')
120
- assertEx(protocolParts.length === 2, () => `Invalid protocol format [${rawProtocol}]`)
121
- assertEx(protocolParts[1].length === 0, () => `Invalid protocol format (post :) [${rawProtocol}]`)
122
- return protocolParts.shift()
123
- }
124
- }
125
-
126
- async fetch(): Promise<T | undefined> {
127
- return await Huri.fetch<T>(this)
128
- }
129
-
130
- toString() {
131
- return this.href
132
- }
133
-
134
- private parsePath(path: string, hasProtocol: boolean) {
135
- const pathParts = path.split('/')
136
-
137
- // if the protocol was found, then there is not allowed to be a leading /
138
- assertEx(!(hasProtocol && pathParts[0].length === 0), () => 'Invalid protocol separator')
139
-
140
- // remove leading '/' if needed
141
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
142
- pathParts[0].length === 0 ? pathParts.shift() : null
143
-
144
- // hash is assumed to be the last part
145
- const hash = assertEx(pathParts.pop(), () => 'No hash specified')
146
-
147
- // archivist is assumed to be the first part
148
- this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
149
-
150
- // the archive is whatever is left
151
- this.archive = pathParts.pop()
152
-
153
- // after we pull off all the path parts, there should be nothing left
154
- assertEx(pathParts.length === 0, () => 'Too many path parts')
155
-
156
- return hash
157
- }
158
-
159
- private validateParse() {
160
- // the archivist should not be zero length
161
- assertEx(this.archivist?.length !== 0, () => 'Invalid archivist length')
162
-
163
- // the archivist should not be zero length (can be undefined)
164
- assertEx(this.archive?.length !== 0, () => 'Invalid archive length')
165
-
166
- // the archive should not be set if the archivist is not set
167
- assertEx(!(isString(this.archive) && !isString(this.archivist)), () => 'If specifying archive, archivist is also required')
168
- }
169
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Huri.ts'