@nina-protocol/nina-db 0.0.24 → 0.0.26

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/knexfile.js CHANGED
@@ -38,5 +38,6 @@ export default {
38
38
  migrations: {
39
39
  directory: './node_modules/@nina-protocol/nina-db/dist/migrations',
40
40
  },
41
+ debug: true,
41
42
  }
42
43
  };
@@ -4,7 +4,7 @@ import Hub from './Hub.js';
4
4
  import Post from './Post.js';
5
5
  import Release from './Release.js';
6
6
  import Verification from './Verification.js';
7
- export default class Account extends Model {
7
+ class Account extends Model {
8
8
  static tableName = 'accounts';
9
9
  static idColumn = 'id';
10
10
  static jsonSchema = {
@@ -113,3 +113,4 @@ export default class Account extends Model {
113
113
  },
114
114
  });
115
115
  }
116
+ export default Account;
@@ -1,7 +1,7 @@
1
1
  import { Model } from 'objection';
2
2
  import Account from './Account.js';
3
3
  import Release from './Release.js';
4
- export default class Exchange extends Model {
4
+ class Exchange extends Model {
5
5
  static tableName = 'exchanges';
6
6
  static idColum = 'id';
7
7
  static jsonSchema = {
@@ -60,3 +60,4 @@ export default class Exchange extends Model {
60
60
  },
61
61
  });
62
62
  }
63
+ export default Exchange;
@@ -3,7 +3,7 @@ import { stripHtmlIfNeeded } from '../utils/index.js';
3
3
  import Account from './Account.js';
4
4
  import Release from './Release.js';
5
5
  import Post from './Post.js';
6
- export default class Hub extends Model {
6
+ class Hub extends Model {
7
7
  static get tableName() {
8
8
  return 'hubs';
9
9
  }
@@ -81,3 +81,4 @@ export default class Hub extends Model {
81
81
  },
82
82
  });
83
83
  }
84
+ export default Hub;
@@ -7,7 +7,7 @@ import Exchange from './Exchange.js';
7
7
  import Hub from './Hub.js';
8
8
  import Post from './Post.js';
9
9
  import axios from 'axios';
10
- export default class Release extends Model {
10
+ class Release extends Model {
11
11
  static tableName = 'releases';
12
12
  static idColumn = 'id';
13
13
  static jsonSchema = {
@@ -76,7 +76,7 @@ export default class Release extends Model {
76
76
  publisherId,
77
77
  });
78
78
  await this.processRevenueShares(releaseAccount, release);
79
- tweetNewRelease(metadata);
79
+ tweetNewRelease(metadata, publisherId);
80
80
  return release;
81
81
  };
82
82
  static processRevenueShares = async (releaseData, releaseRecord) => {
@@ -101,6 +101,7 @@ export default class Release extends Model {
101
101
  const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
102
102
  if (publishedThroughHub) {
103
103
  this.publishedThroughHub = publishedThroughHub.publicKey;
104
+ this.hub = publishedThroughHub;
104
105
  }
105
106
  this.publisher = publisher.publicKey;
106
107
  delete this.publisherId;
@@ -184,3 +185,4 @@ export default class Release extends Model {
184
185
  }
185
186
  });
186
187
  }
188
+ export default Release;
@@ -1,6 +1,6 @@
1
1
  import { Model } from 'objection';
2
2
  import Account from './Account.js';
3
- export default class Verification extends Model {
3
+ class Verification extends Model {
4
4
  static get tableName() {
5
5
  return 'verifications';
6
6
  }
@@ -48,3 +48,4 @@ export default class Verification extends Model {
48
48
  },
49
49
  });
50
50
  }
51
+ export default Verification;
@@ -1,5 +1,6 @@
1
1
  import striptags from 'striptags';
2
2
  import { TwitterApi } from 'twitter-api-v2';
3
+ import Account from '../models/Account.js';
3
4
  const removeQuotesFromStartAndEndOfString = (string) => {
4
5
  return string.substring(1, string.length - 1).substring(-1, string.length - 1);
5
6
  };
@@ -14,7 +15,7 @@ export const stripHtmlIfNeeded = (object, value) => {
14
15
  export const decode = (byteArray) => {
15
16
  return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
16
17
  };
17
- export const tweetNewRelease = async (metadata) => {
18
+ export const tweetNewRelease = async (metadata, publisherId) => {
18
19
  if (process.env.TWITTER_API_SECRET) {
19
20
  try {
20
21
  await new Promise(resolve => setTimeout(resolve, 60000));
@@ -25,6 +26,13 @@ export const tweetNewRelease = async (metadata) => {
25
26
  accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
26
27
  });
27
28
  let text = (`${metadata.properties.artist} - "${metadata.properties.title}"`).substr(0, 250);
29
+ const publisher = await Account.query().findById(publisherId);
30
+ if (publisher) {
31
+ const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0];
32
+ if (twitterVerification) {
33
+ text = `${text} (@${twitterVerification.value})`;
34
+ }
35
+ }
28
36
  text = `${text} ${metadata.external_url}`;
29
37
  await client.v2.tweet(text);
30
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nina-protocol/nina-db",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
package/src/knexfile.js CHANGED
@@ -39,5 +39,6 @@ export default {
39
39
  migrations: {
40
40
  directory: './node_modules/@nina-protocol/nina-db/dist/migrations',
41
41
  },
42
+ debug: true,
42
43
  }
43
44
  };
@@ -84,7 +84,7 @@ export default class Release extends Model {
84
84
  publisherId,
85
85
  })
86
86
  await this.processRevenueShares(releaseAccount, release);
87
- tweetNewRelease(metadata);
87
+ tweetNewRelease(metadata, publisherId);
88
88
  return release;
89
89
  }
90
90
 
@@ -110,6 +110,7 @@ export default class Release extends Model {
110
110
  const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
111
111
  if (publishedThroughHub) {
112
112
  this.publishedThroughHub = publishedThroughHub.publicKey;
113
+ this.hub = publishedThroughHub;
113
114
  }
114
115
  this.publisher = publisher.publicKey;
115
116
  delete this.publisherId
@@ -1,5 +1,6 @@
1
1
  import striptags from 'striptags';
2
2
  import { TwitterApi } from 'twitter-api-v2';
3
+ import Account from '../models/Account.js';
3
4
 
4
5
  const removeQuotesFromStartAndEndOfString = (string) => {
5
6
  return string.substring(1, string.length - 1).substring(-1, string.length - 1);
@@ -18,7 +19,7 @@ export const decode = (byteArray) => {
18
19
  return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
19
20
  }
20
21
 
21
- export const tweetNewRelease = async (metadata) => {
22
+ export const tweetNewRelease = async (metadata, publisherId) => {
22
23
  if (process.env.TWITTER_API_SECRET) {
23
24
  try {
24
25
  await new Promise(resolve => setTimeout(resolve, 60000))
@@ -28,8 +29,14 @@ export const tweetNewRelease = async (metadata) => {
28
29
  accessToken: process.env.TWITTER_ACCESS_TOKEN,
29
30
  accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
30
31
  });
31
-
32
32
  let text = (`${metadata.properties.artist} - "${metadata.properties.title}"`).substr(0, 250)
33
+ const publisher = await Account.query().findById(publisherId);
34
+ if (publisher) {
35
+ const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0]
36
+ if (twitterVerification) {
37
+ text = `${text} (@${twitterVerification.value})`
38
+ }
39
+ }
33
40
  text = `${text} ${metadata.external_url}`
34
41
  await client.v2.tweet(text);
35
42
  } catch (error) {
@@ -1,15 +0,0 @@
1
- /**
2
- * @param { import("knex").Knex } knex
3
- * @returns { Promise<void> }
4
- */
5
- exports.up = function(knex) {
6
-
7
- };
8
-
9
- /**
10
- * @param { import("knex").Knex } knex
11
- * @returns { Promise<void> }
12
- */
13
- exports.down = function(knex) {
14
-
15
- };