@xyo-network/api-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/api-call-witness",
3
- "version": "4.2.0",
3
+ "version": "5.0.1",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -28,31 +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.15.1",
33
- "@xylabs/axios": "^4.15.1",
34
- "@xylabs/hex": "^4.15.1",
35
- "@xylabs/object": "^4.15.1",
36
- "@xylabs/url": "^4.15.1",
37
- "@xyo-network/abstract-witness": "^4.3.0",
38
- "@xyo-network/payload-builder": "^4.3.0",
39
- "@xyo-network/payload-model": "^4.3.0",
40
- "@xyo-network/witness-model": "^4.3.0",
41
- "axios": "^1.11.0",
42
- "base64-js": "^1.5.1",
43
- "es6-dynamic-template": "^2.0.0"
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/payload-builder": "~5.0.2",
43
+ "@xyo-network/payload-model": "~5.0.2",
44
+ "@xyo-network/witness-model": "~5.0.2",
45
+ "axios": "~1.11.0",
46
+ "base64-js": "~1.5.1",
47
+ "es6-dynamic-template": "~2.0.0"
44
48
  },
45
49
  "devDependencies": {
46
- "@xylabs/ts-scripts-yarn3": "^7.0.1",
47
- "@xylabs/tsconfig": "^7.0.1",
48
- "@xylabs/vitest-extended": "^4.15.1",
49
- "@xyo-network/manifest": "^4.3.0",
50
- "@xyo-network/module-factory-locator": "^4.3.0",
51
- "@xyo-network/module-model": "^4.3.0",
52
- "@xyo-network/sentinel-model": "^4.3.0",
53
- "@xyo-network/wallet": "^4.3.0",
54
- "typescript": "^5.8.3",
55
- "vitest": "^3.2.4"
50
+ "@xylabs/ts-scripts-yarn3": "~7.1.0",
51
+ "@xylabs/tsconfig": "~7.1.0",
52
+ "@xylabs/vitest-extended": "~5.0.7",
53
+ "@xyo-network/manifest": "~5.0.2",
54
+ "@xyo-network/module-factory-locator": "~5.0.2",
55
+ "@xyo-network/module-model": "~5.0.2",
56
+ "@xyo-network/sentinel-model": "~5.0.2",
57
+ "@xyo-network/wallet": "~5.0.2",
58
+ "typescript": "~5.9.2",
59
+ "vitest": "~3.2.4"
56
60
  },
57
61
  "publishConfig": {
58
62
  "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
+ ApiCallResultSchema, ApiCallSchema, isApiCallErrorResult,
10
+ } from '../../Payload/index.ts'
11
+ import { ApiCallWitnessConfigSchema } from '../Schema.ts'
12
+ import { ApiCallWitness } 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 ApiCallWitness.create({
19
+ account: 'random',
20
+ config: { accept: 'application/json', schema: ApiCallWitnessConfigSchema },
21
+ })
22
+ const observation = await witness.observe([{ schema: ApiCallSchema, uri }])
23
+ expect(observation[0].schema).toBe(ApiCallResultSchema)
24
+ expect(isApiCallErrorResult(observation[0].schema)).toBe(false)
25
+ })
26
+ })
27
+ })
@@ -0,0 +1,123 @@
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 type { ModuleParams } from '@xyo-network/module-model'
7
+ import { ModuleFactory } from '@xyo-network/module-model'
8
+ import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
9
+ import { asSentinelInstance } from '@xyo-network/sentinel-model'
10
+ import { HDWallet } from '@xyo-network/wallet'
11
+ import { asWitnessInstance } from '@xyo-network/witness-model'
12
+ import {
13
+ describe, expect,
14
+ it,
15
+ } from 'vitest'
16
+
17
+ import type { ApiCallJsonResult, ApiUriTemplateCallPayload } from '../../Payload/index.ts'
18
+ import { ApiCallResultSchema, ApiCallSchema } from '../../Payload/index.ts'
19
+ import type { ApiCallWitnessConfig } from '../Config.ts'
20
+ import { ApiCallWitness } from '../Witness.ts'
21
+ import openseaNftsManifest from './opensea.nft-call.json' with { type: 'json' }
22
+
23
+ describe('OpenSeaApi', () => {
24
+ const address = '0xECA1bB9c8d3Fd8b926372f42c8D4c6c3ed0669B3' // Random Wallet
25
+
26
+ const apiKey = process.env.OPENSEA_API_KEY
27
+
28
+ describe.skipIf(!apiKey)('report', () => {
29
+ type OpenSeaNft = {
30
+ /*
31
+ * Collection slug. A unique string to identify a collection on OpenSea
32
+ */
33
+ collection: string
34
+ /*
35
+ * The unique public blockchain identifier for the contract
36
+ */
37
+ contract: string
38
+ /**
39
+ * @deprecated
40
+ */
41
+ created_at: string
42
+ /*
43
+ * Description of the NFT
44
+ */
45
+ description: string
46
+ /*
47
+ * The NFT's unique identifier within the smart contract (also referred to as token_id)
48
+ */
49
+ identifier: string
50
+ /*
51
+ * Link to the image associated with the NFT
52
+ */
53
+ image_url: string
54
+ /*
55
+ * If the item is currently able to be bought or sold using OpenSea
56
+ */
57
+ is_disabled: boolean
58
+ /*
59
+ * If the item is currently classified as 'Not Safe for Work' by OpenSea as defined in OpenSea's NSFW Policy.
60
+ */
61
+ is_nsfw: boolean
62
+ /*
63
+ * Link to the offchain metadata store
64
+ */
65
+ metadata_url: string
66
+ /*
67
+ * Name of the NFT
68
+ */
69
+ name: string
70
+ /*
71
+ * ERC standard of the token (erc721, erc1155)
72
+ */
73
+ token_standard: string
74
+ /*
75
+ * Last time that the NFT's metadata was updated by OpenSea
76
+ */
77
+ updated_at: string
78
+ }
79
+ type OpenSeaListNftsByAccountResponse = {
80
+ next: string
81
+ nfts: OpenSeaNft[]
82
+ }
83
+ it('specifying address', async () => {
84
+ const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
85
+ const wallet = await HDWallet.fromPhrase(mnemonic)
86
+ const locator = new ModuleFactoryLocator()
87
+
88
+ locator.register(
89
+ new ModuleFactory(ApiCallWitness, {
90
+ config: { uriTemplate: 'https://api.opensea.io/api/v2/chain/ethereum/account/${address}/nfts' },
91
+ headers: { 'x-api-key': apiKey },
92
+ } as ModuleParams<ApiCallWitnessConfig>),
93
+ )
94
+
95
+ const manifest = new ManifestWrapper(openseaNftsManifest as PackageManifestPayload, wallet, locator)
96
+
97
+ const node = await manifest.loadNodeFromIndex(0)
98
+
99
+ const mods = await node.resolve('*')
100
+
101
+ expect(mods.length).toBeGreaterThan(1)
102
+
103
+ const resolvedWitness = await node.resolve('ApiCallWitness')
104
+ expect(resolvedWitness).toBeDefined()
105
+
106
+ const witness = asWitnessInstance(resolvedWitness)
107
+ expect(witness).toBeDefined()
108
+
109
+ const sentinel = asSentinelInstance(await node.resolve('ApiCallSentinel'))
110
+ expect(sentinel).toBeDefined()
111
+
112
+ const call: ApiUriTemplateCallPayload = { params: { address }, schema: ApiCallSchema }
113
+
114
+ const report = await sentinel?.report([call])
115
+
116
+ const apiCallResult = report?.find(isPayloadOfSchemaType<ApiCallJsonResult<OpenSeaListNftsByAccountResponse>>(ApiCallResultSchema))
117
+ expect(apiCallResult).toBeDefined()
118
+ expect(apiCallResult?.schema).toBeString()
119
+ expect(apiCallResult?.data.nfts).toBeArrayOfSize(1)
120
+ expect(apiCallResult?.data.nfts[0].collection).toBeString()
121
+ })
122
+ })
123
+ })
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