@audius/sdk 0.0.2 → 0.0.3-beta.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/dist/types.d.ts CHANGED
@@ -456,6 +456,10 @@ declare type AttestationResult = {
456
456
  phase?: string;
457
457
  reason?: string;
458
458
  };
459
+ declare type Reaction = {
460
+ reactedTo: string;
461
+ reactionValue: number;
462
+ };
459
463
  declare type IdentityServiceConfig = {
460
464
  identityServiceEndpoint: string;
461
465
  captcha?: Captcha;
@@ -579,6 +583,10 @@ declare class IdentityService {
579
583
  *
580
584
  */
581
585
  sendAttestationResult(data: AttestationResult): Promise<unknown>;
586
+ /**
587
+ * Post a reaction to identity.
588
+ */
589
+ submitReaction(data: Reaction): Promise<unknown>;
582
590
  _makeRequest<T = unknown>(axiosRequestObj: AxiosRequestConfig): Promise<T>;
583
591
  _signData(): Promise<{
584
592
  "Encoded-Data-Message": string;
@@ -1681,7 +1689,11 @@ declare type UserProfile = {
1681
1689
  name: string;
1682
1690
  handle: string;
1683
1691
  verified: boolean;
1684
- imageURL?: string;
1692
+ profilePicture: {
1693
+ '150x150': string;
1694
+ '480x480': string;
1695
+ '1000x1000': string;
1696
+ } | null | undefined;
1685
1697
  sub: number;
1686
1698
  iat: string;
1687
1699
  };
@@ -63,6 +63,7 @@ async function initAudiusLibs(
63
63
  ethContractsConfig.ownerWallet
64
64
  ),
65
65
  creatorNodeConfig: AudiusLibs.configCreatorNode(creatorNodeEndpoint),
66
+ discoveryProviderConfig: {},
66
67
  identityServiceConfig: AudiusLibs.configIdentityService(
67
68
  identityServiceEndpoint
68
69
  ),
@@ -60,6 +60,7 @@ async function initializeVersionServiceProviderContracts() {
60
60
  ethWeb3,
61
61
  ownerWallet
62
62
  ),
63
+ discoveryProviderConfig: {},
63
64
  isServer: isServer
64
65
  }
65
66
  let audiusLibs = new AudiusLibs(audiusLibsConfig)
@@ -127,6 +127,7 @@ function getLibsConfig(config, privateKey, ownerWallet) {
127
127
  ethWeb3,
128
128
  ownerWallet
129
129
  ),
130
+ discoveryProviderConfig: {},
130
131
  isServer: isServer
131
132
  }
132
133
  return audiusLibsConfig
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types.d.ts",
7
7
  "browser": "dist/browser.js",
8
+ "sdkBrowserDistFile": "dist/sdk.js",
9
+ "sdkBrowserDistFileMini": "dist/sdk.min.js",
8
10
  "legacy": "dist/legacy.js",
9
11
  "legacyTypes": "dist/legacy.d.ts",
10
12
  "core": "dist/core.js",
@@ -26,13 +28,14 @@
26
28
  "dependencies": {
27
29
  "@audius/anchor-audius-data": "0.0.2",
28
30
  "@audius/hedgehog": "1.0.12",
31
+ "@babel/runtime": "^7.18.3",
29
32
  "@certusone/wormhole-sdk": "0.1.1",
30
33
  "@ethersproject/solidity": "5.0.5",
31
34
  "@improbable-eng/grpc-web-node-http-transport": "0.15.0",
32
35
  "@project-serum/anchor": "0.24.1",
33
36
  "@solana/spl-token": "0.1.6",
34
37
  "@solana/web3.js": "1.37.1",
35
- "abi-decoder": "1.2.0",
38
+ "abi-decoder": "2.4.0",
36
39
  "ajv": "6.12.2",
37
40
  "async-retry": "1.3.1",
38
41
  "axios": "0.19.2",
@@ -61,9 +64,11 @@
61
64
  "secp256k1": "4.0.2",
62
65
  "semver": "6.3.0",
63
66
  "stream-browserify": "3.0.0",
64
- "web3": "1.7.1"
67
+ "web3": "1.7.1",
68
+ "xmlhttprequest": "1.8.0"
65
69
  },
66
70
  "devDependencies": {
71
+ "@babel/plugin-transform-runtime": "^7.18.2",
67
72
  "@babel/preset-env": "7.16.11",
68
73
  "@openzeppelin/test-helpers": "0.5.6",
69
74
  "@rollup/plugin-alias": "3.1.9",
@@ -103,6 +108,7 @@
103
108
  "rollup-plugin-dts": "4.2.0",
104
109
  "rollup-plugin-ignore": "1.0.10",
105
110
  "rollup-plugin-polyfill-node": "0.9.0",
111
+ "rollup-plugin-terser": "^7.0.2",
106
112
  "sinon": "9.0.2",
107
113
  "standard": "16.0.4",
108
114
  "ts-mocha": "9.0.2",
package/rollup.config.js CHANGED
@@ -3,6 +3,7 @@ import babel from '@rollup/plugin-babel'
3
3
  import json from '@rollup/plugin-json'
4
4
  import resolve from '@rollup/plugin-node-resolve'
5
5
  import typescript from '@rollup/plugin-typescript'
6
+ import { terser } from 'rollup-plugin-terser'
6
7
  import dts from 'rollup-plugin-dts'
7
8
  import nodePolyfills from 'rollup-plugin-polyfill-node'
8
9
  import alias from '@rollup/plugin-alias'
@@ -73,6 +74,33 @@ const browserConfig = {
73
74
  external: external.filter((dep) => !browserInternal.includes(dep))
74
75
  }
75
76
 
77
+ const browserDistFileConfig = {
78
+ plugins: [
79
+ ignore(['web3', 'graceful-fs', 'node-localstorage']),
80
+ resolve({ extensions, preferBuiltins: false, browser: true }),
81
+ commonjs({
82
+ extensions,
83
+ transformMixedEsModules: true,
84
+ dynamicRequireTargets: [
85
+ 'data-contracts/ABIs/*.json',
86
+ 'eth-contracts/ABIs/*.json'
87
+ ]
88
+ }),
89
+ alias({
90
+ entries: [{ find: 'stream', replacement: 'stream-browserify' }]
91
+ }),
92
+ nodePolyfills(),
93
+ babel({
94
+ babelHelpers: 'runtime',
95
+ extensions,
96
+ plugins: ['@babel/plugin-transform-runtime']
97
+ }),
98
+ json(),
99
+ typescript()
100
+ ],
101
+ external: ['web3']
102
+ }
103
+
76
104
  const browserLegacyConfig = {
77
105
  plugins: [
78
106
  ignore(['web3', 'graceful-fs', 'node-localstorage']),
@@ -128,6 +156,27 @@ export default [
128
156
  ...browserConfig
129
157
  },
130
158
 
159
+ /**
160
+ * SDK bundled for prebuilt package file to be used in browser
161
+ * Does not include libs but does include polyfills and all deps/dev deps
162
+ */
163
+ {
164
+ input: 'src/sdk/sdkBrowserDist.ts',
165
+ output: [
166
+ {
167
+ file: pkg.sdkBrowserDistFile,
168
+ globals: {
169
+ web3: 'window.Web3'
170
+ },
171
+ format: 'iife',
172
+ esModule: false,
173
+ sourcemap: true,
174
+ plugins: [terser()]
175
+ }
176
+ ],
177
+ ...browserDistFileConfig
178
+ },
179
+
131
180
  /**
132
181
  * Legacy bundle for a browser environment
133
182
  * Includes libs but does not include polyfills
@@ -0,0 +1,4 @@
1
+ // Placeholder type for base.js
2
+ declare const Base: any
3
+
4
+ export { Base }
@@ -0,0 +1,39 @@
1
+ import { Base } from './base'
2
+
3
+ export class Reactions extends Base {
4
+ constructor(...args: any[]) {
5
+ super(...args)
6
+ this.submitReaction = this.submitReaction.bind(this)
7
+ }
8
+
9
+ /**
10
+ * Submit a user's reaction, represented by a numberic ID,
11
+ * to an entity e.g. a notification for a received tip.
12
+ */
13
+ async submitReaction({
14
+ reactedTo,
15
+ reactionValue,
16
+ logger = console
17
+ }: {
18
+ reactedTo: string
19
+ reactionValue: number
20
+ logger: any
21
+ }): Promise<{ success: boolean; error: string | null }> {
22
+ try {
23
+ await this.identityService.submitReaction({
24
+ reactedTo,
25
+ reactionValue
26
+ })
27
+ logger.info(
28
+ `Successfully submitted reaction for entity ${reactedTo} and reaction value ${reactionValue}.`
29
+ )
30
+ return { success: true, error: null }
31
+ } catch (e) {
32
+ const errorMessage = (e as Error).message
33
+ logger.error(
34
+ `Could not successfully submit reaction for entity ${reactedTo} and reaction value ${reactionValue}. Error: ${errorMessage}`
35
+ )
36
+ return { success: false, error: errorMessage }
37
+ }
38
+ }
39
+ }
package/src/libs.js CHANGED
@@ -33,6 +33,8 @@ const { PublicKey } = require('@solana/web3.js')
33
33
  const {
34
34
  RewardsAttester
35
35
  } = require('./services/solanaWeb3Manager/rewardsAttester')
36
+ const { Reactions } = require('./api/reactions')
37
+
36
38
  class AudiusLibs {
37
39
  /**
38
40
  * Configures an identity service wrapper
@@ -356,6 +358,7 @@ class AudiusLibs {
356
358
  this.Playlist = null
357
359
  this.File = null
358
360
  this.Rewards = null
361
+ this.Reactions = null
359
362
 
360
363
  this.preferHigherPatchForPrimary = preferHigherPatchForPrimary
361
364
  this.preferHigherPatchForSecondaries = preferHigherPatchForSecondaries
@@ -485,13 +488,15 @@ class AudiusLibs {
485
488
  }
486
489
 
487
490
  /** Discovery Provider */
488
- this.discoveryProvider = new DiscoveryProvider({
489
- userStateManager: this.userStateManager,
490
- ethContracts: this.ethContracts,
491
- web3Manager: this.web3Manager,
492
- ...this.discoveryProviderConfig
493
- })
494
- await this.discoveryProvider.init()
491
+ if (this.discoveryProviderConfig) {
492
+ this.discoveryProvider = new DiscoveryProvider({
493
+ userStateManager: this.userStateManager,
494
+ ethContracts: this.ethContracts,
495
+ web3Manager: this.web3Manager,
496
+ ...this.discoveryProviderConfig
497
+ })
498
+ await this.discoveryProvider.init()
499
+ }
495
500
 
496
501
  /** Creator Node */
497
502
  if (this.creatorNodeConfig) {
@@ -551,6 +556,7 @@ class AudiusLibs {
551
556
  this.Playlist = new Playlist(...services)
552
557
  this.File = new File(this.User, ...services)
553
558
  this.Rewards = new Rewards(this.ServiceProvider, ...services)
559
+ this.Reactions = new Reactions(...services)
554
560
  }
555
561
  }
556
562
 
@@ -0,0 +1,3 @@
1
+ import { sdk } from './sdk'
2
+
3
+ window.audiusSdk = sdk
@@ -50,7 +50,10 @@ export type UserProfile = {
50
50
  name: string
51
51
  handle: string
52
52
  verified: boolean
53
- imageURL?: string
53
+ profilePicture:
54
+ | { '150x150': string; '480x480': string; '1000x1000': string }
55
+ | null
56
+ | undefined
54
57
  sub: number
55
58
  iat: string
56
59
  }
@@ -615,11 +618,11 @@ export class DiscoveryProvider {
615
618
  */
616
619
  async verifyToken(token: string): Promise<UserProfile | false> {
617
620
  const req = Requests.verifyToken(token)
618
- const res = await this._makeRequest<UserProfile[]>(req)
619
- if (res == null || res[0] == null) {
621
+ const res = await this._makeRequest<UserProfile | null>(req)
622
+ if (res == null) {
620
623
  return false
621
624
  } else {
622
- return res[0]
625
+ return res
623
626
  }
624
627
  }
625
628
 
@@ -55,6 +55,11 @@ type AttestationResult = {
55
55
  reason?: string
56
56
  }
57
57
 
58
+ type Reaction = {
59
+ reactedTo: string
60
+ reactionValue: number
61
+ }
62
+
58
63
  // Only probabilistically capture 50% of relay captchas
59
64
  const RELAY_CAPTCHA_SAMPLE_RATE = 0.5
60
65
 
@@ -502,6 +507,20 @@ export class IdentityService {
502
507
  })
503
508
  }
504
509
 
510
+ /**
511
+ * Post a reaction to identity.
512
+ */
513
+ async submitReaction(data: Reaction) {
514
+ const headers = await this._signData()
515
+
516
+ return await this._makeRequest({
517
+ url: '/reactions',
518
+ method: 'post',
519
+ data,
520
+ headers
521
+ })
522
+ }
523
+
505
524
  /* ------- INTERNAL FUNCTIONS ------- */
506
525
 
507
526
  async _makeRequest<T = unknown>(axiosRequestObj: AxiosRequestConfig) {
@@ -86,7 +86,7 @@ async function getAccountNonce ({
86
86
  mintKey,
87
87
  claimableTokenProgramKey
88
88
  })
89
- const accInfo = await connection.getAccountInfoAndContext(transferNonceAccount)
89
+ const accInfo = await connection.getAccountInfoAndContext(transferNonceAccount, 'confirmed')
90
90
  if (accInfo.value) {
91
91
  const nonceAccount = borsh.deserialize(NonceAccountSchema, NonceAccount, accInfo.value.data)
92
92
  nonce = nonceAccount.nonce
@@ -1,7 +1,7 @@
1
1
  import bs58 from 'bs58'
2
2
  import Web3 from '../web3'
3
3
  import axios, { AxiosResponse } from 'axios'
4
- import Hashids from 'hashids/cjs'
4
+ import Hashids from 'hashids'
5
5
  import { MultiProvider } from './multiProvider'
6
6
  import { uuid } from './uuid'
7
7
  import {