@xyo-network/http-call-witness 4.1.1 → 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.
@@ -1,146 +1,3 @@
1
- import * as _xylabs_object from '@xylabs/object';
2
- import { JsonArray, JsonObject } from '@xylabs/object';
3
- import { Payload, Schema } from '@xyo-network/payload-model';
4
- import { Hash } from '@xylabs/hex';
5
- import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
6
- import { AbstractWitness } from '@xyo-network/abstract-witness';
7
-
8
- declare const asApiCall: _xylabs_object.AsTypeFunction<HttpCall>;
9
-
10
- declare const asHttpCallBase64Result: _xylabs_object.AsTypeFunction<HttpCallBase64Result>;
11
-
12
- declare const asHttpCallResult: _xylabs_object.AsTypeFunction<HttpCallResult>;
13
-
14
- declare const asHttpCallXmlResult: _xylabs_object.AsTypeFunction<HttpCallXmlResult>;
15
-
16
- declare const asHttpUriCall: _xylabs_object.AsTypeFunction<HttpUriCall>;
17
-
18
- declare const asHttpUriTemplateCall: _xylabs_object.AsTypeFunction<HttpUriTemplateCall>;
19
-
20
- declare const HttpCallSchema = "network.xyo.http.call";
21
- type HttpCallSchema = typeof HttpCallSchema;
22
- declare const HttpCallResultSchema = "network.xyo.http.call.result";
23
- type HttpCallResultSchema = typeof HttpCallResultSchema;
24
-
25
- type Queries = Record<string, string>;
26
-
27
- type Verb = 'get' | 'post';
28
-
29
- interface HttpCallFields {
30
- headers?: Record<string, string | undefined>;
31
- queries?: Queries;
32
- verb?: Verb;
33
- }
34
-
35
- type HttpUriCall = Payload<HttpCallFields & {
36
- uri: string;
37
- }, HttpCallSchema>;
38
-
39
- type HttpUriTemplateCall = Payload<HttpCallFields & {
40
- params?: Record<string, string>;
41
- uriTemplate?: string;
42
- }, HttpCallSchema>;
43
-
44
- type HttpCall = HttpUriCall | HttpUriTemplateCall;
45
-
46
- type HttpCallJsonResultType = JsonArray | JsonObject;
47
- type HttpCallJsonResult<T extends HttpCallJsonResultType = HttpCallJsonResultType> = Payload<{
48
- call: Hash;
49
- contentType: 'application/json';
50
- data: T;
51
- }, HttpCallResultSchema>;
52
- declare const isHttpCallJsonResult: <T extends HttpCallJsonResultType = HttpCallJsonResultType>(x?: unknown | null) => x is HttpCallJsonResult<T>;
53
- declare const asHttpCallJsonResult: _xylabs_object.AsTypeFunction<HttpCallJsonResult<HttpCallJsonResultType>>;
54
-
55
- type HttpCallXmlResult = Payload<{
56
- call: Hash;
57
- contentType: 'application/xml' | 'text/xml';
58
- data: string;
59
- }, HttpCallResultSchema>;
60
-
61
- type HttpCallBase64Result = Payload<{
62
- call: Hash;
63
- contentType: Exclude<Exclude<string, HttpCallJsonResult['contentType']>, HttpCallXmlResult['contentType']>;
64
- data: string;
65
- }, HttpCallResultSchema>;
66
-
67
- interface HttpMeta {
68
- code?: string;
69
- status?: number;
70
- }
71
-
72
- type HttpCallErrorResult = Payload<{
73
- call: Hash;
74
- http?: HttpMeta;
75
- }, HttpCallResultSchema>;
76
-
77
- type HttpCallHtmlResult = Payload<{
78
- call: Hash;
79
- contentType: 'text/html';
80
- data: string;
81
- }, HttpCallResultSchema>;
82
-
83
- type NewType = JsonObject;
84
- type HttpCallResult<TJson extends JsonArray | JsonObject = JsonArray | NewType> = HttpCallBase64Result | HttpCallJsonResult<TJson> | HttpCallErrorResult;
85
-
86
- type MimeTypes = 'application/json' | 'application/octet-stream' | 'application/pdf' | 'application/xhtml+xml' | 'application/xml' | 'image/gif' | 'image/jpeg' | 'image/png' | 'text/html' | 'text/plain' | 'text/xml';
87
-
88
- declare const isHttpCall: (x?: unknown | null) => x is HttpCall;
89
-
90
- declare const isHttpCallBase64Result: (x?: unknown | null) => x is HttpCallBase64Result;
91
-
92
- declare const isHttpCallErrorResult: (value: unknown) => value is HttpCallErrorResult;
93
-
94
- declare const isHttpCallResult: (x?: unknown | null) => x is HttpCallResult;
95
-
96
- declare const isHttpCallXmlResult: (x?: unknown | null) => x is HttpCallXmlResult;
97
-
98
- declare const isHttpUriCall: (value?: unknown) => value is HttpUriCall;
99
-
100
- declare const isHttpUriTemplateCall: (value?: unknown) => value is HttpUriTemplateCall;
101
-
102
- declare const HttpCallWitnessConfigSchema = "network.xyo.http.call.witness.config";
103
- type HttpCallWitnessConfigSchema = typeof HttpCallWitnessConfigSchema;
104
-
105
- type HttpCallWitnessConfigBase = WitnessConfig<{
106
- accept?: MimeTypes;
107
- headers?: Record<string, string | undefined>;
108
- queries?: HttpCall['queries'];
109
- schema: HttpCallWitnessConfigSchema;
110
- timeout?: number;
111
- verb?: HttpCall['verb'];
112
- }>;
113
- type HttpUriCallWitnessConfig = WitnessConfig<HttpCallWitnessConfigBase & {
114
- uri: HttpUriCall['uri'];
115
- }>;
116
- type HttpUriTemplateCallWitnessConfig = WitnessConfig<HttpCallWitnessConfigBase & {
117
- params?: Record<string, string>;
118
- uriTemplate: HttpUriTemplateCall['uriTemplate'];
119
- }>;
120
- type HttpCallWitnessConfig = HttpUriCallWitnessConfig | HttpUriTemplateCallWitnessConfig | HttpCallWitnessConfigBase;
121
- declare const isHttpCallWitnessConfig: (x?: unknown | null) => x is HttpCallWitnessConfig;
122
- declare const asHttpCallWitnessConfig: _xylabs_object.AsTypeFunction<HttpCallWitnessConfig>;
123
- declare const isHttpUriCallWitnessConfig: (value?: unknown) => value is HttpUriCallWitnessConfig;
124
- declare const asHttpUriCallWitnessConfig: _xylabs_object.AsTypeFunction<HttpUriCallWitnessConfig>;
125
- declare const isHttpUriTemplateCallWitnessConfig: (value?: unknown) => value is HttpUriTemplateCallWitnessConfig;
126
- declare const asHttpUriTemplateCallWitnessConfig: _xylabs_object.AsTypeFunction<HttpUriTemplateCallWitnessConfig>;
127
-
128
- interface HttpCallWitnessParams extends WitnessParams<HttpCallWitnessConfig> {
129
- headers?: Record<string, string | undefined>;
130
- ipfsGateway?: string;
131
- }
132
-
133
- declare class HttpCallWitness<TParams extends HttpCallWitnessParams = HttpCallWitnessParams> extends AbstractWitness<TParams, HttpCall, HttpCallResult> {
134
- static readonly configSchemas: Schema[];
135
- static readonly defaultConfigSchema: Schema;
136
- get accept(): MimeTypes;
137
- get ipfsGateway(): string | undefined;
138
- get timeout(): number | undefined;
139
- getFullUri(call?: HttpCall): string;
140
- getHeaders(headers?: Record<string, string | undefined>): Record<string, string | undefined>;
141
- protected observeHandler(inPayloads?: HttpCall[]): Promise<HttpCallResult[]>;
142
- private httpGet;
143
- }
144
-
145
- export { HttpCallResultSchema, HttpCallSchema, HttpCallWitness, HttpCallWitnessConfigSchema, asApiCall, asHttpCallBase64Result, asHttpCallJsonResult, asHttpCallResult, asHttpCallWitnessConfig, asHttpCallXmlResult, asHttpUriCall, asHttpUriCallWitnessConfig, asHttpUriTemplateCall, asHttpUriTemplateCallWitnessConfig, isHttpCall, isHttpCallBase64Result, isHttpCallErrorResult, isHttpCallJsonResult, isHttpCallResult, isHttpCallWitnessConfig, isHttpCallXmlResult, isHttpUriCall, isHttpUriCallWitnessConfig, isHttpUriTemplateCall, isHttpUriTemplateCallWitnessConfig };
146
- export type { HttpCall, HttpCallBase64Result, HttpCallErrorResult, HttpCallFields, HttpCallHtmlResult, HttpCallJsonResult, HttpCallJsonResultType, HttpCallResult, HttpCallWitnessConfig, HttpCallWitnessConfigBase, HttpCallWitnessParams, HttpCallXmlResult, HttpMeta, HttpUriCall, HttpUriCallWitnessConfig, HttpUriTemplateCall, HttpUriTemplateCallWitnessConfig, MimeTypes, Queries, Verb };
1
+ export * from './Payload/index.ts';
2
+ export * from './Witness/index.ts';
3
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/http-call-witness",
3
- "version": "4.1.1",
3
+ "version": "5.0.0",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -28,32 +28,35 @@
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/assert": "^4.13.23",
33
- "@xylabs/axios": "^4.13.23",
34
- "@xylabs/hex": "^4.13.23",
35
- "@xylabs/object": "^4.13.23",
36
- "@xylabs/url": "^4.13.23",
37
- "@xyo-network/abstract-witness": "^4.1.7",
38
- "@xyo-network/hash": "^4.1.7",
39
- "@xyo-network/payload-builder": "^4.1.7",
40
- "@xyo-network/payload-model": "^4.1.7",
41
- "@xyo-network/witness-model": "^4.1.7",
42
- "axios": "^1.10.0",
36
+ "@xylabs/assert": "^5.0.0",
37
+ "@xylabs/axios": "^5.0.0",
38
+ "@xylabs/hex": "^5.0.0",
39
+ "@xylabs/object": "^5.0.0",
40
+ "@xylabs/url": "^5.0.0",
41
+ "@xyo-network/abstract-witness": "^5.0.0",
42
+ "@xyo-network/hash": "^5.0.0",
43
+ "@xyo-network/payload-builder": "^5.0.0",
44
+ "@xyo-network/payload-model": "^5.0.0",
45
+ "@xyo-network/witness-model": "^5.0.0",
46
+ "axios": "^1.11.0",
43
47
  "base64-js": "^1.5.1",
44
48
  "es6-dynamic-template": "^2.0.0"
45
49
  },
46
50
  "devDependencies": {
47
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.24",
48
- "@xylabs/tsconfig": "^7.0.0-rc.24",
49
- "@xylabs/vitest-extended": "^4.13.23",
50
- "@xyo-network/manifest": "^4.1.7",
51
- "@xyo-network/module-factory-locator": "^4.1.7",
52
- "@xyo-network/module-model": "^4.1.7",
53
- "@xyo-network/sentinel-model": "^4.1.7",
54
- "@xyo-network/wallet": "^4.1.7",
51
+ "@xylabs/ts-scripts-yarn3": "^7.0.2",
52
+ "@xylabs/tsconfig": "^7.0.2",
53
+ "@xylabs/vitest-extended": "^5.0.0",
54
+ "@xyo-network/manifest": "^5.0.0",
55
+ "@xyo-network/module-factory-locator": "^5.0.0",
56
+ "@xyo-network/module-model": "^5.0.0",
57
+ "@xyo-network/sentinel-model": "^5.0.0",
58
+ "@xyo-network/wallet": "^5.0.0",
55
59
  "ethers": "^6.15.0",
56
- "knip": "^5.62.0",
57
60
  "typescript": "^5.8.3",
58
61
  "vitest": "^3.2.4"
59
62
  },
@@ -0,0 +1,27 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import {
4
+ describe, expect,
5
+ it,
6
+ } from 'vitest'
7
+
8
+ import {
9
+ HttpCallResultSchema, HttpCallSchema, isHttpCallErrorResult,
10
+ } from '../../Payload/index.ts'
11
+ import { HttpCallWitnessConfigSchema } from '../Schema.ts'
12
+ import { HttpCallWitness } from '../Witness.ts'
13
+
14
+ describe('CryptoWalletNftWitness', () => {
15
+ const uri = 'https://cnn.com'
16
+ describe('observe', () => {
17
+ it('get code from contract', async () => {
18
+ const witness = await HttpCallWitness.create({
19
+ account: 'random',
20
+ config: { accept: 'text/html', schema: HttpCallWitnessConfigSchema },
21
+ })
22
+ const observation = await witness.observe([{ schema: HttpCallSchema, uri }])
23
+ expect(observation[0].schema).toBe(HttpCallResultSchema)
24
+ expect(isHttpCallErrorResult(observation[0].schema)).toBe(false)
25
+ })
26
+ })
27
+ })
@@ -0,0 +1,122 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { PackageManifestPayload } from '@xyo-network/manifest'
4
+ import { ManifestWrapper } from '@xyo-network/manifest'
5
+ import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
6
+ import { ModuleFactory } from '@xyo-network/module-model'
7
+ import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
8
+ import { asSentinelInstance } from '@xyo-network/sentinel-model'
9
+ import { HDWallet } from '@xyo-network/wallet'
10
+ import { asWitnessInstance } from '@xyo-network/witness-model'
11
+ import {
12
+ describe, expect,
13
+ it,
14
+ } from 'vitest'
15
+
16
+ import type { HttpCallJsonResult, HttpUriTemplateCall } from '../../Payload/index.ts'
17
+ import { HttpCallResultSchema, HttpCallSchema } from '../../Payload/index.ts'
18
+ import type { HttpCallWitnessParams } from '../Params.ts'
19
+ import { HttpCallWitness } from '../Witness.ts'
20
+ import openseaNftsManifest from './opensea.nft-call.json' with { type: 'json' }
21
+
22
+ describe('OpenSeaHttp', () => {
23
+ const address = '0xECA1bB9c8d3Fd8b926372f42c8D4c6c3ed0669B3' // Random Wallet
24
+
25
+ const apiKey = process.env.OPENSEA_API_KEY
26
+
27
+ describe.skipIf(!apiKey)('report', () => {
28
+ type OpenSeaNft = {
29
+ /*
30
+ * Collection slug. A unique string to identify a collection on OpenSea
31
+ */
32
+ collection: string
33
+ /*
34
+ * The unique public blockchain identifier for the contract
35
+ */
36
+ contract: string
37
+ /**
38
+ * @deprecated
39
+ */
40
+ created_at: string
41
+ /*
42
+ * Description of the NFT
43
+ */
44
+ description: string
45
+ /*
46
+ * The NFT's unique identifier within the smart contract (also referred to as token_id)
47
+ */
48
+ identifier: string
49
+ /*
50
+ * Link to the image associated with the NFT
51
+ */
52
+ image_url: string
53
+ /*
54
+ * If the item is currently able to be bought or sold using OpenSea
55
+ */
56
+ is_disabled: boolean
57
+ /*
58
+ * If the item is currently classified as 'Not Safe for Work' by OpenSea as defined in OpenSea's NSFW Policy.
59
+ */
60
+ is_nsfw: boolean
61
+ /*
62
+ * Link to the offchain metadata store
63
+ */
64
+ metadata_url: string
65
+ /*
66
+ * Name of the NFT
67
+ */
68
+ name: string
69
+ /*
70
+ * ERC standard of the token (erc721, erc1155)
71
+ */
72
+ token_standard: string
73
+ /*
74
+ * Last time that the NFT's metadata was updated by OpenSea
75
+ */
76
+ updated_at: string
77
+ }
78
+ type OpenSeaListNftsByAccountResponse = {
79
+ next: string
80
+ nfts: OpenSeaNft[]
81
+ }
82
+ it('specifying address', async () => {
83
+ const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
84
+ const wallet = await HDWallet.fromPhrase(mnemonic)
85
+ const locator = new ModuleFactoryLocator()
86
+
87
+ locator.register(
88
+ new ModuleFactory(HttpCallWitness, {
89
+ config: { uriTemplate: 'https://api.opensea.io/api/v2/chain/ethereum/account/${address}/nfts' },
90
+ headers: { 'x-api-key': apiKey },
91
+ } as HttpCallWitnessParams),
92
+ )
93
+
94
+ const manifest = new ManifestWrapper(openseaNftsManifest as PackageManifestPayload, wallet, locator)
95
+
96
+ const node = await manifest.loadNodeFromIndex(0)
97
+
98
+ const mods = await node.resolve('*')
99
+
100
+ expect(mods.length).toBeGreaterThan(1)
101
+
102
+ const resolvedWitness = await node.resolve('HttpCallWitness')
103
+ expect(resolvedWitness).toBeDefined()
104
+
105
+ const witness = asWitnessInstance(resolvedWitness)
106
+ expect(witness).toBeDefined()
107
+
108
+ const sentinel = asSentinelInstance(await node.resolve('HttpCallSentinel'))
109
+ expect(sentinel).toBeDefined()
110
+
111
+ const call: HttpUriTemplateCall = { params: { address }, schema: HttpCallSchema }
112
+
113
+ const report = await sentinel?.report([call])
114
+
115
+ const apiCallResult = report?.find(isPayloadOfSchemaType<HttpCallJsonResult<OpenSeaListNftsByAccountResponse>>(HttpCallResultSchema))
116
+ expect(apiCallResult).toBeDefined()
117
+ expect(apiCallResult?.schema).toBeString()
118
+ expect(apiCallResult?.data.nfts).toBeArrayOfSize(1)
119
+ expect(apiCallResult?.data.nfts[0].collection).toBeString()
120
+ })
121
+ })
122
+ })
package/typedoc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": ["./src/index.ts"],
4
- "tsconfig": "./tsconfig.typedoc.json"
5
- }
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