@xyo-network/http-call-witness 4.2.0 → 5.0.1
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 +29 -25
- package/src/Witness/spec/Witness.spec.ts +27 -0
- package/src/Witness/spec/opensea.nft-call.spec.ts +122 -0
- package/typedoc.json +0 -5
- package/xy.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/http-call-witness",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,33 +28,37 @@
|
|
|
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": "
|
|
33
|
-
"@xylabs/axios": "
|
|
34
|
-
"@xylabs/hex": "
|
|
35
|
-
"@xylabs/object": "
|
|
36
|
-
"@xylabs/url": "
|
|
37
|
-
"@xyo-network/abstract-witness": "
|
|
38
|
-
"@xyo-network/hash": "
|
|
39
|
-
"@xyo-network/payload-builder": "
|
|
40
|
-
"@xyo-network/payload-model": "
|
|
41
|
-
"@xyo-network/witness-model": "
|
|
42
|
-
"axios": "
|
|
43
|
-
"base64-js": "
|
|
44
|
-
"es6-dynamic-template": "
|
|
36
|
+
"@xylabs/assert": "~5.0.7",
|
|
37
|
+
"@xylabs/axios": "~5.0.7",
|
|
38
|
+
"@xylabs/hex": "~5.0.7",
|
|
39
|
+
"@xylabs/object": "~5.0.7",
|
|
40
|
+
"@xylabs/url": "~5.0.7",
|
|
41
|
+
"@xyo-network/abstract-witness": "~5.0.2",
|
|
42
|
+
"@xyo-network/hash": "~5.0.2",
|
|
43
|
+
"@xyo-network/payload-builder": "~5.0.2",
|
|
44
|
+
"@xyo-network/payload-model": "~5.0.2",
|
|
45
|
+
"@xyo-network/witness-model": "~5.0.2",
|
|
46
|
+
"axios": "~1.11.0",
|
|
47
|
+
"base64-js": "~1.5.1",
|
|
48
|
+
"es6-dynamic-template": "~2.0.0"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
|
-
"@xylabs/ts-scripts-yarn3": "
|
|
48
|
-
"@xylabs/tsconfig": "
|
|
49
|
-
"@xylabs/vitest-extended": "
|
|
50
|
-
"@xyo-network/manifest": "
|
|
51
|
-
"@xyo-network/module-factory-locator": "
|
|
52
|
-
"@xyo-network/module-model": "
|
|
53
|
-
"@xyo-network/sentinel-model": "
|
|
54
|
-
"@xyo-network/wallet": "
|
|
55
|
-
"ethers": "
|
|
56
|
-
"typescript": "
|
|
57
|
-
"vitest": "
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.0",
|
|
52
|
+
"@xylabs/tsconfig": "~7.1.0",
|
|
53
|
+
"@xylabs/vitest-extended": "~5.0.7",
|
|
54
|
+
"@xyo-network/manifest": "~5.0.2",
|
|
55
|
+
"@xyo-network/module-factory-locator": "~5.0.2",
|
|
56
|
+
"@xyo-network/module-model": "~5.0.2",
|
|
57
|
+
"@xyo-network/sentinel-model": "~5.0.2",
|
|
58
|
+
"@xyo-network/wallet": "~5.0.2",
|
|
59
|
+
"ethers": "~6.15.0",
|
|
60
|
+
"typescript": "~5.9.2",
|
|
61
|
+
"vitest": "~3.2.4"
|
|
58
62
|
},
|
|
59
63
|
"publishConfig": {
|
|
60
64
|
"access": "public"
|
|
@@ -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