@xyo-network/http-call-witness 5.3.2 → 5.3.4

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 (121) hide show
  1. package/dist/neutral/Payload/Schema.d.ts +9 -0
  2. package/dist/neutral/Payload/Schema.d.ts.map +1 -0
  3. package/dist/neutral/Payload/identity/asHttpCall.d.ts +2 -0
  4. package/dist/neutral/Payload/identity/asHttpCall.d.ts.map +1 -0
  5. package/dist/neutral/Payload/identity/asHttpCallBase64Result.d.ts +2 -0
  6. package/dist/neutral/Payload/identity/asHttpCallBase64Result.d.ts.map +1 -0
  7. package/dist/neutral/Payload/identity/asHttpCallResult.d.ts +2 -0
  8. package/dist/neutral/Payload/identity/asHttpCallResult.d.ts.map +1 -0
  9. package/dist/neutral/Payload/identity/asHttpCallXmlResult.d.ts +2 -0
  10. package/dist/neutral/Payload/identity/asHttpCallXmlResult.d.ts.map +1 -0
  11. package/dist/neutral/Payload/identity/asHttpUriCall.d.ts +2 -0
  12. package/dist/neutral/Payload/identity/asHttpUriCall.d.ts.map +1 -0
  13. package/dist/neutral/Payload/identity/asHttpUriTemplateCall.d.ts +2 -0
  14. package/dist/neutral/Payload/identity/asHttpUriTemplateCall.d.ts.map +1 -0
  15. package/dist/neutral/Payload/identity/index.d.ts +14 -0
  16. package/dist/neutral/Payload/identity/index.d.ts.map +1 -0
  17. package/dist/neutral/Payload/identity/isHttpCall.d.ts +3 -0
  18. package/dist/neutral/Payload/identity/isHttpCall.d.ts.map +1 -0
  19. package/dist/neutral/Payload/identity/isHttpCallBase64Result.d.ts +3 -0
  20. package/dist/neutral/Payload/identity/isHttpCallBase64Result.d.ts.map +1 -0
  21. package/dist/neutral/Payload/identity/isHttpCallErrorResult.d.ts +3 -0
  22. package/dist/neutral/Payload/identity/isHttpCallErrorResult.d.ts.map +1 -0
  23. package/dist/neutral/Payload/identity/isHttpCallResult.d.ts +3 -0
  24. package/dist/neutral/Payload/identity/isHttpCallResult.d.ts.map +1 -0
  25. package/dist/neutral/Payload/identity/isHttpCallXmlResult.d.ts +3 -0
  26. package/dist/neutral/Payload/identity/isHttpCallXmlResult.d.ts.map +1 -0
  27. package/dist/neutral/Payload/identity/isHttpUriCall.d.ts +3 -0
  28. package/dist/neutral/Payload/identity/isHttpUriCall.d.ts.map +1 -0
  29. package/dist/neutral/Payload/identity/isHttpUriTemplateCall.d.ts +3 -0
  30. package/dist/neutral/Payload/identity/isHttpUriTemplateCall.d.ts.map +1 -0
  31. package/dist/neutral/Payload/index.d.ts +4 -0
  32. package/dist/neutral/Payload/index.d.ts.map +1 -0
  33. package/dist/neutral/Payload/types/HttpCall.d.ts +4 -0
  34. package/dist/neutral/Payload/types/HttpCall.d.ts.map +1 -0
  35. package/dist/neutral/Payload/types/HttpCallBase64Result.d.ts +11 -0
  36. package/dist/neutral/Payload/types/HttpCallBase64Result.d.ts.map +1 -0
  37. package/dist/neutral/Payload/types/HttpCallErrorResult.d.ts +9 -0
  38. package/dist/neutral/Payload/types/HttpCallErrorResult.d.ts.map +1 -0
  39. package/dist/neutral/Payload/types/HttpCallFields.d.ts +8 -0
  40. package/dist/neutral/Payload/types/HttpCallFields.d.ts.map +1 -0
  41. package/dist/neutral/Payload/types/HttpCallHtmlResult.d.ts +9 -0
  42. package/dist/neutral/Payload/types/HttpCallHtmlResult.d.ts.map +1 -0
  43. package/dist/neutral/Payload/types/HttpCallJsonResult.d.ts +12 -0
  44. package/dist/neutral/Payload/types/HttpCallJsonResult.d.ts.map +1 -0
  45. package/{src/Payload/types/HttpCallResult.ts → dist/neutral/Payload/types/HttpCallResult.d.ts} +8 -12
  46. package/dist/neutral/Payload/types/HttpCallResult.d.ts.map +1 -0
  47. package/dist/neutral/Payload/types/HttpCallXmlResult.d.ts +9 -0
  48. package/dist/neutral/Payload/types/HttpCallXmlResult.d.ts.map +1 -0
  49. package/dist/neutral/Payload/types/HttpMeta.d.ts +5 -0
  50. package/dist/neutral/Payload/types/HttpMeta.d.ts.map +1 -0
  51. package/dist/neutral/Payload/types/HttpUriCall.d.ts +7 -0
  52. package/dist/neutral/Payload/types/HttpUriCall.d.ts.map +1 -0
  53. package/dist/neutral/Payload/types/HttpUriTemplateCall.d.ts +8 -0
  54. package/dist/neutral/Payload/types/HttpUriTemplateCall.d.ts.map +1 -0
  55. package/dist/neutral/Payload/types/MimeTypes.d.ts +2 -0
  56. package/dist/neutral/Payload/types/MimeTypes.d.ts.map +1 -0
  57. package/dist/neutral/Payload/types/Queries.d.ts +2 -0
  58. package/dist/neutral/Payload/types/Queries.d.ts.map +1 -0
  59. package/dist/neutral/Payload/types/Verb.d.ts +2 -0
  60. package/dist/neutral/Payload/types/Verb.d.ts.map +1 -0
  61. package/dist/neutral/Payload/types/index.d.ts +15 -0
  62. package/dist/neutral/Payload/types/index.d.ts.map +1 -0
  63. package/dist/neutral/Witness/Config.d.ts +26 -0
  64. package/dist/neutral/Witness/Config.d.ts.map +1 -0
  65. package/dist/neutral/Witness/Params.d.ts +7 -0
  66. package/dist/neutral/Witness/Params.d.ts.map +1 -0
  67. package/dist/neutral/Witness/Schema.d.ts +5 -0
  68. package/dist/neutral/Witness/Schema.d.ts.map +1 -0
  69. package/dist/neutral/Witness/Witness.d.ts +16 -0
  70. package/dist/neutral/Witness/Witness.d.ts.map +1 -0
  71. package/dist/neutral/Witness/index.d.ts +5 -0
  72. package/dist/neutral/Witness/index.d.ts.map +1 -0
  73. package/dist/neutral/index.d.ts +3 -0
  74. package/dist/neutral/index.d.ts.map +1 -0
  75. package/dist/neutral/index.mjs +353 -0
  76. package/dist/neutral/index.mjs.map +1 -0
  77. package/dist/neutral/lib/checkIpfsUrl.d.ts +8 -0
  78. package/dist/neutral/lib/checkIpfsUrl.d.ts.map +1 -0
  79. package/dist/neutral/lib/index.d.ts +2 -0
  80. package/dist/neutral/lib/index.d.ts.map +1 -0
  81. package/package.json +9 -5
  82. package/src/Payload/Schema.ts +0 -7
  83. package/src/Payload/identity/asHttpCall.ts +0 -5
  84. package/src/Payload/identity/asHttpCallBase64Result.ts +0 -5
  85. package/src/Payload/identity/asHttpCallResult.ts +0 -5
  86. package/src/Payload/identity/asHttpCallXmlResult.ts +0 -5
  87. package/src/Payload/identity/asHttpUriCall.ts +0 -5
  88. package/src/Payload/identity/asHttpUriTemplateCall.ts +0 -5
  89. package/src/Payload/identity/index.ts +0 -13
  90. package/src/Payload/identity/isHttpCall.ts +0 -6
  91. package/src/Payload/identity/isHttpCallBase64Result.ts +0 -8
  92. package/src/Payload/identity/isHttpCallErrorResult.ts +0 -7
  93. package/src/Payload/identity/isHttpCallResult.ts +0 -6
  94. package/src/Payload/identity/isHttpCallXmlResult.ts +0 -8
  95. package/src/Payload/identity/isHttpUriCall.ts +0 -4
  96. package/src/Payload/identity/isHttpUriTemplateCall.ts +0 -5
  97. package/src/Payload/index.ts +0 -3
  98. package/src/Payload/types/HttpCall.ts +0 -4
  99. package/src/Payload/types/HttpCallBase64Result.ts +0 -15
  100. package/src/Payload/types/HttpCallErrorResult.ts +0 -13
  101. package/src/Payload/types/HttpCallFields.ts +0 -8
  102. package/src/Payload/types/HttpCallHtmlResult.ts +0 -13
  103. package/src/Payload/types/HttpCallJsonResult.ts +0 -25
  104. package/src/Payload/types/HttpCallXmlResult.ts +0 -13
  105. package/src/Payload/types/HttpMeta.ts +0 -4
  106. package/src/Payload/types/HttpUriCall.ts +0 -11
  107. package/src/Payload/types/HttpUriTemplateCall.ts +0 -12
  108. package/src/Payload/types/MimeTypes.ts +0 -13
  109. package/src/Payload/types/Queries.ts +0 -1
  110. package/src/Payload/types/Verb.ts +0 -1
  111. package/src/Payload/types/index.ts +0 -14
  112. package/src/Witness/Config.ts +0 -43
  113. package/src/Witness/Params.ts +0 -10
  114. package/src/Witness/Schema.ts +0 -4
  115. package/src/Witness/Witness.ts +0 -220
  116. package/src/Witness/index.ts +0 -4
  117. package/src/Witness/spec/opensea.nft-call.json +0 -41
  118. package/src/index.ts +0 -2
  119. package/src/lib/checkIpfsUrl.ts +0 -43
  120. package/src/lib/index.ts +0 -1
  121. package/src/types.d.ts +0 -1
@@ -1,13 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { Payload } from '@xyo-network/payload-model'
3
-
4
- import type { HttpCallResultSchema } from '../Schema.ts'
5
-
6
- export type HttpCallHtmlResult = Payload<
7
- {
8
- call: Hash
9
- contentType: 'text/html'
10
- data: string
11
- },
12
- HttpCallResultSchema
13
- >
@@ -1,25 +0,0 @@
1
- import type {
2
- Hash, JsonArray, JsonObject,
3
- } from '@xylabs/sdk-js'
4
- import { AsObjectFactory } from '@xylabs/sdk-js'
5
- import type { Payload } from '@xyo-network/payload-model'
6
- import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
7
-
8
- import { HttpCallResultSchema } from '../Schema.ts'
9
- import type { HttpCallResult } from './HttpCallResult.ts'
10
-
11
- export type HttpCallJsonResultType = JsonArray | JsonObject
12
-
13
- export type HttpCallJsonResult<T extends HttpCallJsonResultType = HttpCallJsonResultType> = Payload<
14
- {
15
- call: Hash
16
- contentType: 'application/json'
17
- data: T
18
- },
19
- HttpCallResultSchema
20
- >
21
-
22
- export const isHttpCallJsonResult = <T extends HttpCallJsonResultType = HttpCallJsonResultType>(x?: unknown | null): x is HttpCallJsonResult<T> => {
23
- return isPayloadOfSchemaType<HttpCallResult>(HttpCallResultSchema)(x) && (x as HttpCallJsonResult)?.contentType === 'application/json'
24
- }
25
- export const asHttpCallJsonResult = AsObjectFactory.create(isHttpCallJsonResult)
@@ -1,13 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { Payload } from '@xyo-network/payload-model'
3
-
4
- import type { HttpCallResultSchema } from '../Schema.ts'
5
-
6
- export type HttpCallXmlResult = Payload<
7
- {
8
- call: Hash
9
- contentType: 'application/xml' | 'text/xml'
10
- data: string
11
- },
12
- HttpCallResultSchema
13
- >
@@ -1,4 +0,0 @@
1
- export interface HttpMeta {
2
- code?: string
3
- status?: number
4
- }
@@ -1,11 +0,0 @@
1
- import type { Payload } from '@xyo-network/payload-model'
2
-
3
- import type { HttpCallSchema } from '../Schema.ts'
4
- import type { HttpCallFields } from './HttpCallFields.ts'
5
-
6
- export type HttpUriCall = Payload<
7
- HttpCallFields & {
8
- uri: string
9
- },
10
- HttpCallSchema
11
- >
@@ -1,12 +0,0 @@
1
- import type { Payload } from '@xyo-network/payload-model'
2
-
3
- import type { HttpCallSchema } from '../Schema.ts'
4
- import type { HttpCallFields } from './HttpCallFields.ts'
5
-
6
- export type HttpUriTemplateCall = Payload<
7
- HttpCallFields & {
8
- params?: Record<string, string>
9
- uriTemplate?: string
10
- },
11
- HttpCallSchema
12
- >
@@ -1,13 +0,0 @@
1
- // TODO: Bring in from some library or package for completeness
2
- export type MimeTypes
3
- = | 'application/json' // JSON format
4
- | 'application/octet-stream' // Binary data
5
- | 'application/pdf' // PDF format
6
- | 'application/xhtml+xml' // XHTML format
7
- | 'application/xml' // XML format
8
- | 'image/gif' // GIF image format
9
- | 'image/jpeg' // JPEG image format
10
- | 'image/png' // PNG image format
11
- | 'text/html' // HTML format
12
- | 'text/plain' // Plain text format
13
- | 'text/xml' // XML format (alternative)
@@ -1 +0,0 @@
1
- export type Queries = Record<string, string>
@@ -1 +0,0 @@
1
- export type Verb = 'get' | 'post'
@@ -1,14 +0,0 @@
1
- export * from './HttpCall.ts'
2
- export * from './HttpCallBase64Result.ts'
3
- export * from './HttpCallErrorResult.ts'
4
- export * from './HttpCallFields.ts'
5
- export * from './HttpCallHtmlResult.ts'
6
- export * from './HttpCallJsonResult.ts'
7
- export * from './HttpCallResult.ts'
8
- export * from './HttpCallXmlResult.ts'
9
- export * from './HttpMeta.ts'
10
- export * from './HttpUriCall.ts'
11
- export * from './HttpUriTemplateCall.ts'
12
- export * from './MimeTypes.ts'
13
- export * from './Queries.ts'
14
- export * from './Verb.ts'
@@ -1,43 +0,0 @@
1
- import { AsObjectFactory } from '@xylabs/sdk-js'
2
- import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
3
- import type { WitnessConfig } from '@xyo-network/witness-model'
4
-
5
- import type {
6
- HttpCall, HttpUriCall, HttpUriTemplateCall, MimeTypes,
7
- } from '../Payload/index.ts'
8
- import { HttpCallWitnessConfigSchema } from './Schema.ts'
9
-
10
- export type HttpCallWitnessConfigBase = WitnessConfig<{
11
- accept?: MimeTypes
12
- headers?: Record<string, string | undefined>
13
- queries?: HttpCall['queries']
14
- schema: HttpCallWitnessConfigSchema
15
- timeout?: number
16
- verb?: HttpCall['verb']
17
- }>
18
-
19
- export type HttpUriCallWitnessConfig = WitnessConfig<
20
- HttpCallWitnessConfigBase & {
21
- uri: HttpUriCall['uri']
22
- }
23
- >
24
-
25
- export type HttpUriTemplateCallWitnessConfig = WitnessConfig<
26
- HttpCallWitnessConfigBase & {
27
- params?: Record<string, string>
28
- uriTemplate: HttpUriTemplateCall['uriTemplate']
29
- }
30
- >
31
-
32
- export type HttpCallWitnessConfig = HttpUriCallWitnessConfig | HttpUriTemplateCallWitnessConfig | HttpCallWitnessConfigBase
33
-
34
- export const isHttpCallWitnessConfig = isPayloadOfSchemaType<HttpCallWitnessConfig>(HttpCallWitnessConfigSchema)
35
- export const asHttpCallWitnessConfig = AsObjectFactory.create(isHttpCallWitnessConfig)
36
-
37
- export const isHttpUriCallWitnessConfig = (value?: unknown): value is HttpUriCallWitnessConfig =>
38
- isHttpCallWitnessConfig(value) && !!(value as HttpUriCallWitnessConfig).uri
39
- export const asHttpUriCallWitnessConfig = AsObjectFactory.create(isHttpUriCallWitnessConfig)
40
-
41
- export const isHttpUriTemplateCallWitnessConfig = (value?: unknown): value is HttpUriTemplateCallWitnessConfig =>
42
- isHttpCallWitnessConfig(value) && !!(value as HttpUriTemplateCallWitnessConfig).uriTemplate
43
- export const asHttpUriTemplateCallWitnessConfig = AsObjectFactory.create(isHttpUriTemplateCallWitnessConfig)
@@ -1,10 +0,0 @@
1
- import type { WitnessParams } from '@xyo-network/witness-model'
2
-
3
- import type { HttpCallWitnessConfig } from './Config.ts'
4
-
5
- export interface HttpCallWitnessParams extends WitnessParams<
6
- HttpCallWitnessConfig>
7
- {
8
- headers?: Record<string, string | undefined>
9
- ipfsGateway?: string
10
- }
@@ -1,4 +0,0 @@
1
- import { asSchema } from '@xyo-network/payload-model'
2
-
3
- export const HttpCallWitnessConfigSchema = asSchema('network.xyo.http.call.witness.config', true)
4
- export type HttpCallWitnessConfigSchema = typeof HttpCallWitnessConfigSchema
@@ -1,220 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import type { Hash } from '@xylabs/sdk-js'
3
- import {
4
- assertEx, axiosJsonConfig, URL,
5
- } from '@xylabs/sdk-js'
6
- import { AbstractWitness } from '@xyo-network/abstract-witness'
7
- import type { Schema } from '@xyo-network/payload-model'
8
- import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
9
- import { ObjectHasher, PayloadBuilder } from '@xyo-network/sdk-js'
10
- import type { AxiosError } from 'axios'
11
- import { Axios } from 'axios'
12
- import { fromByteArray } from 'base64-js'
13
- import fillTemplate from 'es6-dynamic-template'
14
-
15
- import { checkIpfsUrl } from '../lib/index.ts'
16
- import type {
17
- HttpCall,
18
- HttpCallBase64Result,
19
- HttpCallErrorResult,
20
- HttpCallJsonResult,
21
- HttpCallJsonResultType,
22
- HttpCallResult,
23
- HttpCallXmlResult,
24
- MimeTypes,
25
- } from '../Payload/index.ts'
26
- import {
27
- asHttpUriCall,
28
- asHttpUriTemplateCall,
29
- HttpCallResultSchema,
30
- HttpCallSchema,
31
- } from '../Payload/index.ts'
32
- import type { HttpCallHtmlResult } from '../Payload/types/index.ts'
33
- import { asHttpUriCallWitnessConfig, asHttpUriTemplateCallWitnessConfig } from './Config.ts'
34
- import type { HttpCallWitnessParams } from './Params.ts'
35
- import { HttpCallWitnessConfigSchema } from './Schema.ts'
36
-
37
- export class HttpCallWitness<TParams extends HttpCallWitnessParams = HttpCallWitnessParams> extends AbstractWitness<TParams, HttpCall, HttpCallResult> {
38
- static override readonly configSchemas: Schema[] = [...super.configSchemas, HttpCallWitnessConfigSchema]
39
- static override readonly defaultConfigSchema: Schema = HttpCallWitnessConfigSchema
40
-
41
- get accept(): MimeTypes {
42
- return this.config.accept ?? 'application/json'
43
- }
44
-
45
- get ipfsGateway() {
46
- return this.params.ipfsGateway
47
- }
48
-
49
- get timeout() {
50
- return this.config.timeout
51
- }
52
-
53
- getFullUri(call?: HttpCall): string {
54
- const { uri: callUri } = asHttpUriCall(call) ?? {}
55
- const {
56
- uriTemplate: callUriTemplate, params: callParams, queries: callQueries,
57
- } = asHttpUriTemplateCall(call) ?? {}
58
- const { uri: configUri } = asHttpUriCallWitnessConfig(this.config) ?? {}
59
- const {
60
- uriTemplate: configUriTemplate, params: configParams, queries: configQueries,
61
- } = asHttpUriTemplateCallWitnessConfig(this.config) ?? {}
62
-
63
- const params = { ...configParams, ...callParams }
64
-
65
- let url: URL | undefined = undefined
66
-
67
- if (callUri) {
68
- url = new URL(callUri)
69
- } else if (callUriTemplate) {
70
- url = new URL(fillTemplate(callUriTemplate, params))
71
- } else if (configUri) {
72
- url = new URL(configUri)
73
- } else if (configUriTemplate) {
74
- url = new URL(fillTemplate(configUriTemplate, params))
75
- }
76
-
77
- if (url) {
78
- const queries = Object.entries({ ...configQueries, ...callQueries })
79
- for (let [key, value] of queries) {
80
- url?.searchParams.set(key, value)
81
- }
82
- return url.href
83
- }
84
-
85
- throw new Error('Unable to determine uri. No uri/uriTemplate specified in either the call or config.')
86
- }
87
-
88
- getHeaders(headers?: Record<string, string | undefined>): Record<string, string | undefined> {
89
- return {
90
- ...this.params.headers, ...this.config.headers, ...headers,
91
- }
92
- }
93
-
94
- protected override async observeHandler(inPayloads: HttpCall[] = []): Promise<HttpCallResult[]> {
95
- await this.started('throw')
96
- try {
97
- const observations = await Promise.all(
98
- inPayloads.filter(isPayloadOfSchemaType<HttpCall>(HttpCallSchema)).map(async (call) => {
99
- const { verb: callVerb } = call
100
- const { verb: configVerb } = this.config
101
- const verb = callVerb ?? configVerb ?? 'get'
102
- const uri = this.getFullUri(call)
103
-
104
- const validatedUri = assertEx(checkIpfsUrl(uri, this.ipfsGateway), () => 'Invalid URI')
105
-
106
- if (verb === 'get') {
107
- return this.httpGet(validatedUri, (await PayloadBuilder.dataHash(call)))
108
- }
109
-
110
- const observation: HttpCallResult = {
111
- call: await ObjectHasher.hash(call),
112
- schema: HttpCallResultSchema,
113
- }
114
- return observation
115
- }),
116
- )
117
- return observations
118
- } catch (ex) {
119
- const error = ex as Error
120
- console.error(`Error [${this.config.name}]: ${error.message}`)
121
- console.log(error.stack)
122
- throw error
123
- }
124
- }
125
-
126
- // eslint-disable-next-line complexity
127
- private async httpGet(url: string, call: Hash, headers?: Record<string, string | undefined>): Promise<HttpCallResult> {
128
- const result: HttpCallResult = {
129
- call,
130
- schema: HttpCallResultSchema,
131
- }
132
- try {
133
- switch (this.accept) {
134
- case 'application/json': {
135
- const axios = new Axios(axiosJsonConfig({
136
- headers: { ...this.getHeaders(headers), Accept: 'application/json' }, timeout: this.timeout, decompress: true,
137
- }))
138
- const response = await axios.get<HttpCallJsonResultType>(url)
139
- if (response.status >= 200 && response.status < 300) {
140
- const jsonResult = result as HttpCallJsonResult
141
- jsonResult.data = response.data
142
- jsonResult.contentType = 'application/json'
143
- } else {
144
- const errorResult = result as HttpCallErrorResult
145
- errorResult.http = { status: response.status }
146
- }
147
- break
148
- }
149
- case 'application/xml':
150
- case 'text/xml': {
151
- const axios = new Axios({
152
- headers: { ...this.getHeaders(headers), Accept: this.accept },
153
- responseType: 'arraybuffer',
154
- decompress: true,
155
- timeout: this.timeout,
156
- })
157
- const response = await axios.get(url)
158
- if (response.status >= 200 && response.status < 300) {
159
- const xmlResult = result as HttpCallXmlResult
160
- xmlResult.data = Buffer.from(response.data, 'binary').toString('utf8')
161
- xmlResult.contentType = response.headers['content-type']?.toString() ?? 'application/xml'
162
- } else {
163
- const errorResult = result as HttpCallErrorResult
164
- errorResult.http = { status: response.status }
165
- }
166
- break
167
- }
168
- case 'text/html':{
169
- const axios = new Axios({
170
- headers: { ...this.getHeaders(headers), Accept: this.accept },
171
- responseType: 'text',
172
- decompress: true,
173
- timeout: this.timeout,
174
- })
175
- const response = await axios.get(url)
176
- if (response.status >= 200 && response.status < 300) {
177
- const htmlResult = result as HttpCallHtmlResult
178
- htmlResult.data = response.data
179
- htmlResult.contentType = response.headers['content-type']?.toString() ?? 'text/html'
180
- } else {
181
- const errorResult = result as HttpCallErrorResult
182
- errorResult.http = { status: response.status }
183
- }
184
- break
185
- }
186
- default: {
187
- const axios = new Axios({
188
- headers: this.params.headers, responseType: 'arraybuffer', timeout: this.timeout, decompress: true,
189
- })
190
- const response = await axios.get(url)
191
- if (response.status >= 200 && response.status < 300) {
192
- const jsonResult = result as HttpCallBase64Result
193
- jsonResult.data = fromByteArray(response.data)
194
- jsonResult.contentType = response.headers['content-type']?.toString() ?? 'application/octet-stream'
195
- } else {
196
- const errorResult = result as HttpCallErrorResult
197
- errorResult.http = { status: response.status }
198
- }
199
- break
200
- }
201
- }
202
- } catch (ex) {
203
- const axiosError = ex as AxiosError
204
- if (axiosError.isAxiosError) {
205
- if (axiosError?.response?.status !== undefined) {
206
- result.http = result.http ?? {}
207
- result.http.status = axiosError?.response?.status
208
- }
209
- if (axiosError?.code !== undefined) {
210
- result.http = result.http ?? {}
211
- result.http.code = axiosError?.code
212
- }
213
- return result
214
- } else {
215
- throw ex
216
- }
217
- }
218
- return result
219
- }
220
- }
@@ -1,4 +0,0 @@
1
- export * from './Config.ts'
2
- export * from './Params.ts'
3
- export * from './Schema.ts'
4
- export * from './Witness.ts'
@@ -1,41 +0,0 @@
1
- {
2
- "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
3
- "nodes": [
4
- {
5
- "config": {
6
- "name": "ApiCall",
7
- "schema": "network.xyo.node.config"
8
- },
9
- "modules": {
10
- "public": [
11
- {
12
- "config": {
13
- "language": "javascript",
14
- "name": "HttpCallWitness",
15
- "queries": {
16
- "limit": 1
17
- },
18
- "schema": "network.xyo.http.call.witness.config",
19
- "uriTemplate": "https://api.opensea.io/api/v2/chain/ethereum/account/${address}/nfts"
20
- }
21
- },
22
- {
23
- "config": {
24
- "language": "javascript",
25
- "name": "HttpCallSentinel",
26
- "schema": "network.xyo.sentinel.config",
27
- "synchronous": "true",
28
- "tasks": [
29
- {
30
- "input": true,
31
- "mod": "HttpCallWitness"
32
- }
33
- ]
34
- }
35
- }
36
- ]
37
- }
38
- }
39
- ],
40
- "schema": "network.xyo.manifest"
41
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './Payload/index.ts'
2
- export * from './Witness/index.ts'
@@ -1,43 +0,0 @@
1
- import { assertEx, URL } from '@xylabs/sdk-js'
2
-
3
- const allowIpfsIoRepair = true
4
-
5
- /**
6
- * Returns the equivalent IPFS gateway URL for the supplied URL.
7
- * @param urlToCheck The URL to check
8
- * @returns If the supplied URL is an IPFS URL, it converts the URL to the
9
- * equivalent IPFS gateway URL. Otherwise, returns the original URL.
10
- */
11
- export const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {
12
- try {
13
- const url = new URL(urlToCheck)
14
- let protocol = url.protocol
15
- let host = url.host
16
- let path = url.pathname
17
- const query = url.search
18
- if (protocol === 'ipfs:') {
19
- protocol = 'https:'
20
- host = assertEx(ipfsGateway, () => 'No ipfsGateway provided')
21
- path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`
22
- const root = `${protocol}//${host}/${path}`
23
- return query?.length > 0 ? `${root}?${query}` : root
24
- } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {
25
- protocol = 'https:'
26
- host = assertEx(ipfsGateway, () => 'No ipfsGateway provided')
27
- const pathParts = path.split('/')
28
- if (pathParts[0] === 'ipfs') {
29
- pathParts.shift()
30
- }
31
- path = pathParts.join('/')
32
- const root = `${protocol}//${host}/${path}`
33
- return query?.length > 0 ? `${root}?${query}` : root
34
- } else {
35
- return urlToCheck
36
- }
37
- } catch {
38
- // const error = ex as Error
39
- // console.error(`${error.name}:${error.message} [${urlToCheck}]`)
40
- // console.log(error.stack)
41
- return urlToCheck
42
- }
43
- }
package/src/lib/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './checkIpfsUrl.ts'
package/src/types.d.ts DELETED
@@ -1 +0,0 @@
1
- declare module 'es6-dynamic-template'