@nina-protocol/nina-db 0.0.90 → 0.0.92

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.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/src/knexfile.js +38 -3
  3. package/src/migrations/20250423215722_hubs_collaborators_permissions.js +21 -0
  4. package/src/migrations/20250424215722_hubs_collaborators_added_by.js +19 -0
  5. package/yarn-error.log +6817 -0
  6. package/dist/index.js +0 -30
  7. package/dist/knexfile.js +0 -43
  8. package/dist/migrations/20220815134115_initial_migration.js +0 -211
  9. package/dist/migrations/20220930214430_add_subscriptions.js +0 -23
  10. package/dist/migrations/20221010170539_add_hub_data_uri.js +0 -15
  11. package/dist/migrations/20221010185734_add_transactions.js +0 -58
  12. package/dist/migrations/20221012230835_add_verifications.js +0 -31
  13. package/dist/migrations/20221201221013_add_hub_releases_visible.js +0 -15
  14. package/dist/migrations/20221206184748_add_gate.js +0 -29
  15. package/dist/migrations/20230104184351_add_verification_active.js +0 -15
  16. package/dist/migrations/20230306215838_add_hub_updated_at.js +0 -15
  17. package/dist/migrations/20231011163511_add_release_slug.js +0 -15
  18. package/dist/migrations/20231031200532_add_profile.js +0 -18
  19. package/dist/migrations/20231112031914_post_version.js +0 -15
  20. package/dist/migrations/20231116215117_add_tags.js +0 -40
  21. package/dist/migrations/20240131143626_release_price.js +0 -16
  22. package/dist/migrations/20240304143626_fix_tags_content.js +0 -31
  23. package/dist/migrations/20240321155034_hide_release.js +0 -15
  24. package/dist/migrations/20240821155034_release_hidden_to_archived.js +0 -18
  25. package/dist/migrations/20241121155034_subscription_public_key_nullable.js +0 -15
  26. package/dist/migrations/20250120215722_add_ref_columns.js +0 -18
  27. package/dist/models/Account.js +0 -122
  28. package/dist/models/Exchange.js +0 -62
  29. package/dist/models/Hub.js +0 -86
  30. package/dist/models/Post.js +0 -84
  31. package/dist/models/Release.js +0 -282
  32. package/dist/models/Subscription.js +0 -57
  33. package/dist/models/Tag.js +0 -39
  34. package/dist/models/TagsReleases.js +0 -17
  35. package/dist/models/Transaction.js +0 -148
  36. package/dist/models/Verification.js +0 -50
  37. package/dist/models/index.js +0 -21
  38. package/dist/seeds/1_accounts_profile.js +0 -22
  39. package/dist/utils/index.js +0 -45
@@ -1,57 +0,0 @@
1
- import { Model } from 'objection';
2
- import Account from './Account.js';
3
- import Hub from './Hub.js';
4
- class Subscription extends Model {
5
- static get tableName() {
6
- return 'subscriptions';
7
- }
8
- static get idColumn() {
9
- return 'id';
10
- }
11
- static get jsonSchema() {
12
- return {
13
- type: 'object',
14
- required: ['datetime'],
15
- properties: {
16
- datetime: { type: 'string' },
17
- from: { type: 'string' },
18
- to: { type: 'string' },
19
- subscriptionType: {
20
- type: 'string',
21
- enum: ['account', 'hub'],
22
- },
23
- },
24
- };
25
- }
26
- static async findOrCreate({ from, to, datetime, subscriptionType }) {
27
- let subscription = await Subscription.query().findOne({ from, to });
28
- if (subscription) {
29
- return subscription;
30
- }
31
- subscription = await Subscription.query().insert({
32
- from, to, datetime, subscriptionType
33
- });
34
- console.log('Inserted subscription: ', from, to);
35
- return subscription;
36
- }
37
- async format() {
38
- if (this.subscriptionType === 'account') {
39
- const accountTo = await Account.query().findOne({ publicKey: this.to });
40
- await accountTo.format();
41
- this.to = accountTo;
42
- const accountFrom = await Account.query().findOne({ publicKey: this.from });
43
- await accountFrom.format();
44
- this.from = accountFrom;
45
- }
46
- else if (this.subscriptionType === 'hub') {
47
- const hub = await Hub.query().findOne({ publicKey: this.to });
48
- await hub.format();
49
- this.to = hub;
50
- const account = await Account.query().findOne({ publicKey: this.from });
51
- await account.format();
52
- this.from = account;
53
- }
54
- delete this.id;
55
- }
56
- }
57
- export default Subscription;
@@ -1,39 +0,0 @@
1
- import { Model } from 'objection';
2
- import Release from './Release.js';
3
- export default class Tag extends Model {
4
- static tableName = 'tags';
5
- static idColumn = 'id';
6
- static jsonSchema = {
7
- type: 'object',
8
- required: ['value'],
9
- properties: {
10
- value: { type: 'string' },
11
- },
12
- };
13
- static sanitizeValue = (value) => value.toLowerCase().replace('#', '').replace(',', '');
14
- static findOrCreate = async (value) => {
15
- const sanitizedValue = this.sanitizeValue(value);
16
- let tag = await Tag.query().where('value', sanitizedValue).first();
17
- if (!tag) {
18
- tag = await Tag.query().insert({ value: sanitizedValue });
19
- }
20
- return tag;
21
- };
22
- format = () => {
23
- delete this.id;
24
- };
25
- static relationMappings = () => ({
26
- releases: {
27
- relation: Model.ManyToManyRelation,
28
- modelClass: Release,
29
- join: {
30
- from: 'tags.id',
31
- through: {
32
- from: 'tags_releases.tagId',
33
- to: 'tags_releases.releaseId',
34
- },
35
- to: 'releases.id',
36
- },
37
- },
38
- });
39
- }
@@ -1,17 +0,0 @@
1
- import { Model } from 'objection';
2
- export default class TagsRelease extends Model {
3
- static tableName = 'tags_releases';
4
- $beforeUpdate() {
5
- this.updatedAt = new Date().toISOString();
6
- }
7
- static jsonSchema = {
8
- type: 'object',
9
- required: ['tagId', 'releaseId', 'createdAt', 'updatedAt'],
10
- properties: {
11
- tagId: { type: 'integer' },
12
- releaseId: { type: 'integer' },
13
- createdAt: { type: 'string' },
14
- updatedAt: { type: 'string' },
15
- },
16
- };
17
- }
@@ -1,148 +0,0 @@
1
- import { Model } from 'objection';
2
- import Account from './Account.js';
3
- import Hub from './Hub.js';
4
- import Release from './Release.js';
5
- import Post from './Post.js';
6
- class Transaction extends Model {
7
- static get tableName() {
8
- return 'transactions';
9
- }
10
- static get idColumn() {
11
- return 'id';
12
- }
13
- static get jsonSchema() {
14
- return {
15
- type: 'object',
16
- required: ['txid', 'blocktime', 'type'],
17
- properties: {
18
- txid: { type: 'string' },
19
- blocktime: { type: 'integer' },
20
- type: {
21
- type: 'string',
22
- enum: [
23
- 'ExchangeAccept',
24
- 'ExchangeCancel',
25
- 'ExchangeInit',
26
- 'HubInit',
27
- 'HubInitWithCredit',
28
- 'HubAddCollaborator',
29
- 'HubContentToggleVisibility',
30
- 'HubRemoveCollaborator',
31
- 'HubUpdateCollaboratorPermissions',
32
- 'HubUpdateConfig',
33
- 'HubAddRelease',
34
- 'HubWithdraw',
35
- 'PostInitViaHub',
36
- 'PostInitViaHubWithReferenceRelease',
37
- 'ReleaseClaim',
38
- 'ReleaseCloseEdition',
39
- 'ReleaseInit',
40
- 'ReleaseInitWithCredit',
41
- 'ReleaseInitViaHub',
42
- 'ReleasePurchase',
43
- 'ReleasePurchaseViaHub',
44
- 'ReleaseRevenueShareCollectViaHub',
45
- 'ReleaseRevenueShareCollect',
46
- 'ReleaseRevenueShareTransfer',
47
- 'ReleaseUpdateMetadata',
48
- 'SubscriptionSubscribeAccount',
49
- 'SubscriptionSubscribeHub',
50
- 'SubscriptionUnsubscribe',
51
- 'Unknown',
52
- ],
53
- },
54
- },
55
- };
56
- }
57
- async format() {
58
- const hub = await this.$relatedQuery('hub');
59
- if (hub) {
60
- await hub.format();
61
- this.hub = hub;
62
- }
63
- delete this.hubId;
64
- const authority = await this.$relatedQuery('authority');
65
- if (authority) {
66
- await authority.format();
67
- this.authority = authority;
68
- }
69
- delete this.authorityId;
70
- const release = await this.$relatedQuery('release');
71
- if (release) {
72
- await release.format();
73
- this.release = release;
74
- }
75
- delete this.releaseId;
76
- const post = await this.$relatedQuery('post');
77
- if (post) {
78
- await post.format();
79
- this.post = post;
80
- }
81
- delete this.postId;
82
- const toAccount = await this.$relatedQuery('toAccount');
83
- if (toAccount) {
84
- await toAccount.format();
85
- this.toAccount = toAccount;
86
- }
87
- delete this.toAccountId;
88
- const toHub = await this.$relatedQuery('toHub');
89
- if (toHub) {
90
- await toHub.format();
91
- this.toHub = toHub;
92
- }
93
- delete this.toHubId;
94
- this.datetime = new Date(this.blocktime * 1000).toISOString();
95
- delete this.id;
96
- }
97
- static relationMappings = () => ({
98
- authority: {
99
- relation: Model.HasOneRelation,
100
- modelClass: Account,
101
- join: {
102
- from: 'transactions.authorityId',
103
- to: 'accounts.id',
104
- },
105
- },
106
- hub: {
107
- relation: Model.HasOneRelation,
108
- modelClass: Hub,
109
- join: {
110
- from: 'transactions.hubId',
111
- to: 'hubs.id',
112
- },
113
- },
114
- release: {
115
- relation: Model.HasOneRelation,
116
- modelClass: Release,
117
- join: {
118
- from: 'transactions.releaseId',
119
- to: 'releases.id',
120
- },
121
- },
122
- post: {
123
- relation: Model.HasOneRelation,
124
- modelClass: Post,
125
- join: {
126
- from: 'transactions.postId',
127
- to: 'posts.id',
128
- },
129
- },
130
- toAccount: {
131
- relation: Model.HasOneRelation,
132
- modelClass: Account,
133
- join: {
134
- from: 'transactions.toAccountId',
135
- to: 'accounts.id',
136
- },
137
- },
138
- toHub: {
139
- relation: Model.HasOneRelation,
140
- modelClass: Hub,
141
- join: {
142
- from: 'transactions.toHubId',
143
- to: 'hubs.id',
144
- },
145
- },
146
- });
147
- }
148
- export default Transaction;
@@ -1,50 +0,0 @@
1
- import { Model } from 'objection';
2
- import Account from './Account.js';
3
- export default class Verification extends Model {
4
- static get tableName() {
5
- return 'verifications';
6
- }
7
- static get idColumn() {
8
- return 'id';
9
- }
10
- static get jsonSchema() {
11
- return {
12
- type: 'object',
13
- required: ['publicKey', 'type', 'value'],
14
- properties: {
15
- publicKey: { type: 'string' },
16
- type: {
17
- type: 'string',
18
- enum: [
19
- 'soundcloud',
20
- 'instagram',
21
- 'twitter',
22
- 'ethereum',
23
- ],
24
- },
25
- value: { type: 'string' },
26
- displayName: { type: 'string' },
27
- image: { type: 'string' },
28
- description: { type: 'string' },
29
- },
30
- };
31
- }
32
- async format() {
33
- delete this.id;
34
- const account = await this.$relatedQuery('account');
35
- delete this.accountId;
36
- if (account) {
37
- this.account = account.publicKey;
38
- }
39
- }
40
- static relationMappings = () => ({
41
- account: {
42
- relation: Model.BelongsToOneRelation,
43
- modelClass: Account,
44
- join: {
45
- from: 'verifications.accountId',
46
- to: 'accounts.id',
47
- },
48
- },
49
- });
50
- }
@@ -1,21 +0,0 @@
1
- import Account from './Account.js';
2
- import Exchange from './Exchange.js';
3
- import Hub from './Hub.js';
4
- import Post from './Post.js';
5
- import Release from './Release.js';
6
- import Subscription from './Subscription.js';
7
- import Tag from './Tag.js';
8
- import Transaction from './Transaction.js';
9
- import Verification from './Verification.js';
10
- const models = {
11
- Account,
12
- Exchange,
13
- Hub,
14
- Post,
15
- Release,
16
- Subscription,
17
- Tag,
18
- Transaction,
19
- Verification,
20
- };
21
- export default models;
@@ -1,22 +0,0 @@
1
- import 'dotenv/config';
2
- import axios from 'axios';
3
- import { Account, connectDb } from '../index.js';
4
- export const seed = async () => {
5
- await connectDb();
6
- const accountsWithoutHandle = await Account.query().whereNull('handle');
7
- for await (let account of accountsWithoutHandle) {
8
- try {
9
- const response = await axios.get(`${process.env.ID_SERVER_ENDPOINT}/profile/${account.publicKey}`);
10
- await account.$query().patch({
11
- handle: response.data.profile.handle,
12
- displayName: response.data.profile.displayName,
13
- image: response.data.profile.image,
14
- description: response.data.profile.description,
15
- });
16
- console.log('Updated Account:', account.handle, account.publicKey);
17
- }
18
- catch (error) {
19
- console.log('Error updating Account', account.publicKey, error);
20
- }
21
- }
22
- };
@@ -1,45 +0,0 @@
1
- import striptags from 'striptags';
2
- import { TwitterApi } from 'twitter-api-v2';
3
- import Account from '../models/Account.js';
4
- const TWEET_DELAY = 360000; // 6 minutes
5
- const NINA_DOMAIN = 'https://ninaprotocol.com';
6
- const removeQuotesFromStartAndEndOfString = (string) => {
7
- return string.substring(1, string.length - 1).substring(-1, string.length - 1);
8
- };
9
- export const stripHtmlIfNeeded = (object, value) => {
10
- let strippedDescription = striptags(object[value], [], ' ');
11
- strippedDescription = strippedDescription.replace(' ', ' ');
12
- if (strippedDescription !== object[value]) {
13
- object[value + "Html"] = object[value];
14
- object[value] = removeQuotesFromStartAndEndOfString(strippedDescription);
15
- }
16
- };
17
- export const decode = (byteArray) => {
18
- return new TextDecoder().decode(new Uint8Array(byteArray)).replaceAll(/\u0000/g, '');
19
- };
20
- export const tweetNewRelease = async (metadata, publisherId, slug) => {
21
- if (process.env.TWITTER_API_SECRET) {
22
- try {
23
- await new Promise(resolve => setTimeout(resolve, TWEET_DELAY));
24
- const client = new TwitterApi({
25
- appKey: process.env.TWITTER_API_KEY,
26
- appSecret: process.env.TWITTER_API_SECRET,
27
- accessToken: process.env.TWITTER_ACCESS_TOKEN,
28
- accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
29
- });
30
- let text = (`${metadata.properties.artist ? `${metadata.properties.artist} - ` : ''}${metadata.properties.title}`).substr(0, 250);
31
- const publisher = await Account.query().findById(publisherId);
32
- if (publisher) {
33
- const twitterVerification = (await publisher.$relatedQuery('verifications').where('type', 'twitter').andWhere('active', true))[0];
34
- if (twitterVerification) {
35
- text = `${text} (@${twitterVerification.value})`;
36
- }
37
- }
38
- text = `${text} ${NINA_DOMAIN}/releases/${slug}`;
39
- await client.v2.tweet(text);
40
- }
41
- catch (error) {
42
- console.warn('error sending new release tweet: ', error, metadata);
43
- }
44
- }
45
- };