@anitrack/patreon-wrapper 1.3.3 → 1.4.2
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/README.md +100 -21
- package/lib/index.d.ts +39 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +65 -9
- package/lib/index.js.map +1 -1
- package/package.json +13 -4
- package/src/index.ts +109 -13
package/README.md
CHANGED
|
@@ -1,35 +1,54 @@
|
|
|
1
1
|
# Patreon Wrapper 🍊
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
💎 Simple Patreon wrapper designed for Discord Bots to process user's premium subscription and lower down the Patreon API complexity...
|
|
4
|
+
|
|
5
|
+
🌄 You can also simulates sandbox of fake Patrons for development and code testing purposes
|
|
6
|
+
|
|
7
|
+
🍊 This package was also used in [AniTrack](https://anitrack.co) Discord Bot
|
|
3
8
|
|
|
4
9
|
## Table of Contents
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
10
|
+
|
|
11
|
+
- [Installing](#installing)
|
|
12
|
+
- [Real usage example](#Usage%20Example)
|
|
13
|
+
- [Sandbox for development](#Sandboxing)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
|
|
16
|
+
<br />
|
|
8
17
|
|
|
9
18
|
## Installing
|
|
19
|
+
|
|
10
20
|
Using NPM
|
|
21
|
+
|
|
11
22
|
```
|
|
12
23
|
$ npm install @anitrack/patreon-wrapper
|
|
13
24
|
```
|
|
25
|
+
|
|
14
26
|
Using YARN
|
|
27
|
+
|
|
15
28
|
```
|
|
16
29
|
$ yarn add @anitrack/patreon-wrapper
|
|
17
30
|
```
|
|
18
31
|
|
|
19
|
-
## Example
|
|
32
|
+
## Usage Example
|
|
20
33
|
|
|
21
34
|
### Importing
|
|
22
35
|
|
|
23
36
|
CommonJS
|
|
37
|
+
|
|
24
38
|
```js
|
|
25
|
-
const { Patreon } = require('@
|
|
39
|
+
const { Patreon } = require('@anitrack/patreon-wrapper')
|
|
26
40
|
```
|
|
41
|
+
|
|
27
42
|
Typescript ES6
|
|
43
|
+
|
|
28
44
|
```js
|
|
29
|
-
import { Patreon } from '@
|
|
45
|
+
import { Patreon } from '@anitrack/patreon-wrapper'
|
|
30
46
|
```
|
|
31
47
|
|
|
32
|
-
Authorization
|
|
48
|
+
### Authorization
|
|
49
|
+
|
|
50
|
+
> Where do I find Campaign ID? F12 your Patreon page and search for "campaign" then keep looking until you finds URL with campaign params that contains around 7 degits. That should be your Campaign ID
|
|
51
|
+
|
|
33
52
|
```js
|
|
34
53
|
Patreon.Authorization({
|
|
35
54
|
AccessToken: 'YOUR_API_V2_ACCESS_TOKEN',
|
|
@@ -40,8 +59,9 @@ Patreon.Authorization({
|
|
|
40
59
|
### Fetching every Patrons on the Campaign
|
|
41
60
|
|
|
42
61
|
Promies then catch
|
|
62
|
+
|
|
43
63
|
```js
|
|
44
|
-
Patreon.FetchPatrons()
|
|
64
|
+
Patreon.FetchPatrons(['active_patron', 'declined_patron'])
|
|
45
65
|
.then((Patrons) => {
|
|
46
66
|
// Handle Patrons List
|
|
47
67
|
console.log(Patrons)
|
|
@@ -51,14 +71,17 @@ Patreon.FetchPatrons()
|
|
|
51
71
|
console.log(err)
|
|
52
72
|
})
|
|
53
73
|
```
|
|
74
|
+
|
|
54
75
|
Async/Await
|
|
76
|
+
|
|
55
77
|
```js
|
|
56
|
-
var Patrons = await Patreon.FetchPatrons()
|
|
78
|
+
var Patrons = await Patreon.FetchPatrons(['active_patron', 'declined_patron'])
|
|
57
79
|
|
|
58
80
|
console.log(Patrons)
|
|
59
81
|
```
|
|
60
82
|
|
|
61
83
|
Clean Response Example
|
|
84
|
+
|
|
62
85
|
```js
|
|
63
86
|
// Example response from fetching Patron list
|
|
64
87
|
[
|
|
@@ -73,24 +96,24 @@ Clean Response Example
|
|
|
73
96
|
status: 'active_patron',
|
|
74
97
|
tier: {
|
|
75
98
|
id: '12345678',
|
|
76
|
-
title: 'First Tier'
|
|
99
|
+
title: 'My First Tier'
|
|
77
100
|
},
|
|
78
101
|
cents: 500, // 5 USD
|
|
79
102
|
willPayCents: 500,
|
|
80
|
-
lifetimeCents:
|
|
81
|
-
firstCharge: '
|
|
82
|
-
nextCharge: '
|
|
83
|
-
lastCharge: '
|
|
103
|
+
lifetimeCents: 1500,
|
|
104
|
+
firstCharge: '2022-01-15 15:00:00.000', // ISO 8601 DATE
|
|
105
|
+
nextCharge: '2022-05-15 15:00:00.000',
|
|
106
|
+
lastCharge: '2022-05-15 15:00:00.000'
|
|
84
107
|
}
|
|
85
108
|
},
|
|
86
109
|
mediaConnection: {
|
|
87
110
|
patreon: {
|
|
88
111
|
id: '12345678',
|
|
89
|
-
url: 'https://www.patreon.com/api/oauth2/v2/user/12345678'
|
|
112
|
+
url: 'https://www.patreon.com/api/oauth2/v2/user/12345678'
|
|
90
113
|
},
|
|
91
114
|
discord: {
|
|
92
|
-
id: '
|
|
93
|
-
url: 'https://discordapp.com/users/
|
|
115
|
+
id: '12345678',
|
|
116
|
+
url: 'https://discordapp.com/users/12345678'
|
|
94
117
|
}
|
|
95
118
|
}
|
|
96
119
|
},
|
|
@@ -99,13 +122,69 @@ Clean Response Example
|
|
|
99
122
|
},
|
|
100
123
|
{
|
|
101
124
|
...
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
...
|
|
105
125
|
}
|
|
106
126
|
]
|
|
107
127
|
```
|
|
108
128
|
|
|
129
|
+
<br />
|
|
130
|
+
|
|
131
|
+
## Sandboxing
|
|
132
|
+
|
|
133
|
+
> This is great for development and working with fake patrons users. The fake patrons object will be exactly the same as real ones!
|
|
134
|
+
|
|
135
|
+
### Importing Sandbox
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import { Patreon, Sandbox } from '@anitrack/patreon-wrapper'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Adding Fake Patrons to the Sandbox
|
|
142
|
+
|
|
143
|
+
You can repeat this as much as you want
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
Sandbox.AppendPatron({
|
|
147
|
+
displayId: '123', // Patreon ID
|
|
148
|
+
displayName: '123', // Patreon Username
|
|
149
|
+
emailAddress: 'email@address.com', // Patreon Email
|
|
150
|
+
tier: { id: '123', title: 'Tier 1' }, // Current Tier
|
|
151
|
+
cents: 500, // Current paying in cent 500 -> $5.00
|
|
152
|
+
willPayCents: 500, // Next pay price
|
|
153
|
+
lifetimeCents: 1500, // Total lifetime spent
|
|
154
|
+
firstCharge: '2022-01-15 15:00:00.000', // ISO 8601 String date format
|
|
155
|
+
nextCharge: '2022-05-15 15:00:00.000',
|
|
156
|
+
lastCharge: '2022-04-15 15:00:00.000',
|
|
157
|
+
patronStatus: 'active_patron', // Can be 'active_patron' & 'declined_patron'
|
|
158
|
+
mediaConnection: {
|
|
159
|
+
patreon: {
|
|
160
|
+
id: '123',
|
|
161
|
+
url: 'https://www.patreon.com/api/oauth2/v2/user/user_id',
|
|
162
|
+
},
|
|
163
|
+
discord: { id: '123', url: 'https://discord.com/users/user_id' },
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Viewing Fake Patrons Only
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
Sandbox.GetFakePatrons()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Viewing Fake Patrons + Real Patrons
|
|
175
|
+
|
|
176
|
+
Just fetch Patrons normally like you would with real ones
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
Patreon.FetchPatrons(['active_patron', 'declined_patron'])
|
|
180
|
+
.then((Patrons) => {
|
|
181
|
+
console.dir(Patrons, { depth: null })
|
|
182
|
+
})
|
|
183
|
+
.catch((err) => {
|
|
184
|
+
console.log(err)
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
109
188
|
## License
|
|
110
189
|
|
|
111
190
|
[MIT](LICENSE)
|
package/lib/index.d.ts
CHANGED
|
@@ -10,17 +10,17 @@ declare type PatronType = {
|
|
|
10
10
|
subscription: {
|
|
11
11
|
note: string;
|
|
12
12
|
currentEntitled: {
|
|
13
|
-
status:
|
|
13
|
+
status: 'active_patron' | 'declined_patron';
|
|
14
14
|
tier: {
|
|
15
|
-
id:
|
|
15
|
+
id: string;
|
|
16
16
|
title: string;
|
|
17
17
|
};
|
|
18
18
|
cents: number;
|
|
19
19
|
willPayCents: number;
|
|
20
20
|
lifetimeCents: number;
|
|
21
|
-
firstCharge:
|
|
22
|
-
nextCharge:
|
|
23
|
-
lastCharge:
|
|
21
|
+
firstCharge: string;
|
|
22
|
+
nextCharge: string;
|
|
23
|
+
lastCharge: string;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
mediaConnection: {
|
|
@@ -34,14 +34,47 @@ declare type PatronType = {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
+
declare type SandboxOptions = {
|
|
38
|
+
displayId: string;
|
|
39
|
+
displayName: string;
|
|
40
|
+
emailAddress: string;
|
|
41
|
+
tier: {
|
|
42
|
+
id: string;
|
|
43
|
+
title: string;
|
|
44
|
+
};
|
|
45
|
+
cents: number;
|
|
46
|
+
willPayCents: number;
|
|
47
|
+
lifetimeCents: number;
|
|
48
|
+
patronStatus: 'active_patron' | 'declined_patron';
|
|
49
|
+
firstCharge: string;
|
|
50
|
+
nextCharge: string;
|
|
51
|
+
lastCharge: string;
|
|
52
|
+
mediaConnection: {
|
|
53
|
+
patreon: {
|
|
54
|
+
id: string;
|
|
55
|
+
url: string;
|
|
56
|
+
};
|
|
57
|
+
discord: {
|
|
58
|
+
id: string;
|
|
59
|
+
url: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
37
63
|
export declare class Patreon {
|
|
38
64
|
private static _URL;
|
|
39
65
|
private static _AccessToken;
|
|
40
66
|
private static _CampaignID;
|
|
67
|
+
private static _SandboxPatrons;
|
|
41
68
|
static Authorization(AuthInformation: Auth): void;
|
|
42
69
|
private static FetchAPI;
|
|
43
70
|
private static CleanQueryURL;
|
|
44
|
-
static FetchPatrons(pageSize?: number): Promise<PatronType[]>;
|
|
71
|
+
static FetchPatrons(filters?: Array<'active_patron' | 'declined_patron'>, pageSize?: number): Promise<PatronType[]>;
|
|
72
|
+
protected static _SandboxAdd(Patron: SandboxOptions): void;
|
|
73
|
+
protected static _SandboxGet(): SandboxOptions[];
|
|
74
|
+
}
|
|
75
|
+
export declare class Sandbox extends Patreon {
|
|
76
|
+
static GetFakePatrons(): SandboxOptions[];
|
|
77
|
+
static AppendPatron(Patron: SandboxOptions): void;
|
|
45
78
|
}
|
|
46
79
|
export {};
|
|
47
80
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,aAAK,IAAI,GAAG;IACR,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,aAAK,UAAU,GAAG;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,eAAe,EAAE;YACb,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,aAAK,IAAI,GAAG;IACR,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,aAAK,UAAU,GAAG;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,eAAe,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AAM,CAAC,IAAI,CAAmD;IAEtE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAQ;IACnC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAQ;IAElC,OAAO,CAAC,MAAM,CAAC,eAAe,CAA4B;WAE5C,aAAa,CAAC,eAAe,EAAE,IAAI;mBAgB5B,QAAQ;IAe7B,OAAO,CAAC,MAAM,CAAC,aAAa;WAOR,YAAY,CAC5B,OAAO,GAAE,KAAK,CAAC,eAAe,GAAG,iBAAiB,CAAqB,EACvE,QAAQ,GAAE,MAAY;IAiH1B,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc;IAInD,SAAS,CAAC,MAAM,CAAC,WAAW;CAO/B;AAED,qBAAa,OAAQ,SAAQ,OAAO;WAClB,cAAc;WAId,YAAY,CAAC,MAAM,EAAE,cAAc;CAGpD"}
|
package/lib/index.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Patreon = void 0;
|
|
6
|
+
exports.Sandbox = exports.Patreon = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
class Patreon {
|
|
9
9
|
static Authorization(AuthInformation) {
|
|
10
10
|
if (!AuthInformation.AccessToken || !AuthInformation.CampaignID) {
|
|
11
|
-
throw new Error('
|
|
11
|
+
throw new Error('AccessToken and CampaignID are required on Authorization');
|
|
12
12
|
}
|
|
13
13
|
else if (typeof AuthInformation.AccessToken != 'string' ||
|
|
14
14
|
typeof AuthInformation.CampaignID != 'string') {
|
|
@@ -18,6 +18,9 @@ class Patreon {
|
|
|
18
18
|
this._CampaignID = AuthInformation.CampaignID;
|
|
19
19
|
}
|
|
20
20
|
static async FetchAPI(URI) {
|
|
21
|
+
if (!this._AccessToken || !this._CampaignID) {
|
|
22
|
+
throw new Error('AccessToken and CampaignID are required on Authorization');
|
|
23
|
+
}
|
|
21
24
|
return await (0, axios_1.default)(this._URL + URI, {
|
|
22
25
|
method: 'GET',
|
|
23
26
|
headers: { Authorization: 'Bearer ' + this._AccessToken },
|
|
@@ -30,16 +33,50 @@ class Patreon {
|
|
|
30
33
|
query = query.replaceAll(' ', '');
|
|
31
34
|
return query;
|
|
32
35
|
}
|
|
33
|
-
static async FetchPatrons(pageSize = 450) {
|
|
36
|
+
static async FetchPatrons(filters = ['active_patron'], pageSize = 450) {
|
|
34
37
|
const res = await this.FetchAPI(this.CleanQueryURL(`campaigns/${this._CampaignID}/` +
|
|
35
38
|
`members ? include = user, currently_entitled_tiers & page[count] = ${pageSize} & fields[member] = campaign_lifetime_support_cents, currently_entitled_amount_cents, email, full_name, is_follower, last_charge_date, last_charge_status, lifetime_support_cents, next_charge_date, note, patron_status, pledge_cadence, pledge_relationship_start, will_pay_amount_cents & fields[user] = social_connections & fields[tier] = title`));
|
|
36
|
-
|
|
39
|
+
var Patrons = [];
|
|
37
40
|
if (!res?.data?.data)
|
|
38
41
|
return [];
|
|
39
42
|
if (res.data.data.length == 0)
|
|
40
43
|
return [];
|
|
44
|
+
// Processing Fake Sandbox Patrons
|
|
45
|
+
this._SandboxPatrons.forEach((Patron) => Patrons.push({
|
|
46
|
+
displayId: Patron.displayId,
|
|
47
|
+
displayName: Patron.displayName,
|
|
48
|
+
emailAddress: Patron.emailAddress,
|
|
49
|
+
isFollower: false,
|
|
50
|
+
subscription: {
|
|
51
|
+
note: 'Sandbox',
|
|
52
|
+
currentEntitled: {
|
|
53
|
+
status: Patron.patronStatus,
|
|
54
|
+
tier: {
|
|
55
|
+
id: Patron.tier.id,
|
|
56
|
+
title: Patron.tier.title,
|
|
57
|
+
},
|
|
58
|
+
cents: Patron.cents,
|
|
59
|
+
willPayCents: Patron.willPayCents,
|
|
60
|
+
lifetimeCents: Patron.lifetimeCents,
|
|
61
|
+
firstCharge: Patron.firstCharge,
|
|
62
|
+
nextCharge: Patron.nextCharge,
|
|
63
|
+
lastCharge: Patron.lastCharge,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
mediaConnection: {
|
|
67
|
+
patreon: {
|
|
68
|
+
id: Patron.mediaConnection.patreon.id,
|
|
69
|
+
url: Patron.mediaConnection.patreon.url,
|
|
70
|
+
},
|
|
71
|
+
discord: {
|
|
72
|
+
id: Patron.mediaConnection.discord.id,
|
|
73
|
+
url: Patron.mediaConnection.discord.url,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
}));
|
|
77
|
+
// Processing Real Patrons
|
|
41
78
|
res.data.data.forEach((Patron) => {
|
|
42
|
-
if (Patron.attributes.patron_status
|
|
79
|
+
if (!filters.includes(Patron.attributes.patron_status))
|
|
43
80
|
return;
|
|
44
81
|
var socialInfo = res.data.included.find((includePatron) => includePatron.id == Patron.relationships.user.data.id &&
|
|
45
82
|
includePatron.type === 'user');
|
|
@@ -56,11 +93,14 @@ class Patreon {
|
|
|
56
93
|
currentEntitled: {
|
|
57
94
|
status: Patron.attributes.patron_status,
|
|
58
95
|
tier: {
|
|
59
|
-
id: tierInfo.id,
|
|
60
|
-
title: tierInfo.attributes.title,
|
|
96
|
+
id: tierInfo ? tierInfo.id : null,
|
|
97
|
+
title: tierInfo ? tierInfo.attributes.title : null,
|
|
61
98
|
},
|
|
62
|
-
cents: Patron.attributes
|
|
63
|
-
|
|
99
|
+
cents: Patron.attributes.currently_entitled_amount_cents !=
|
|
100
|
+
0
|
|
101
|
+
? Patron.attributes
|
|
102
|
+
.currently_entitled_amount_cents
|
|
103
|
+
: null,
|
|
64
104
|
willPayCents: Patron.attributes.will_pay_amount_cents,
|
|
65
105
|
lifetimeCents: Patron.attributes.lifetime_support_cents,
|
|
66
106
|
firstCharge: Patron.attributes.pledge_relationship_start,
|
|
@@ -85,7 +125,23 @@ class Patreon {
|
|
|
85
125
|
});
|
|
86
126
|
return Patrons;
|
|
87
127
|
}
|
|
128
|
+
static _SandboxAdd(Patron) {
|
|
129
|
+
this._SandboxPatrons.push(Patron);
|
|
130
|
+
}
|
|
131
|
+
static _SandboxGet() {
|
|
132
|
+
return this._SandboxPatrons;
|
|
133
|
+
}
|
|
88
134
|
}
|
|
89
135
|
exports.Patreon = Patreon;
|
|
90
136
|
Patreon._URL = 'https://www.patreon.com/api/oauth2/v2/';
|
|
137
|
+
Patreon._SandboxPatrons = [];
|
|
138
|
+
class Sandbox extends Patreon {
|
|
139
|
+
static GetFakePatrons() {
|
|
140
|
+
return super._SandboxGet();
|
|
141
|
+
}
|
|
142
|
+
static AppendPatron(Patron) {
|
|
143
|
+
super._SandboxAdd(Patron);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.Sandbox = Sandbox;
|
|
91
147
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAgEzB,MAAa,OAAO;IAQT,MAAM,CAAC,aAAa,CAAC,eAAqB;QAC7C,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;YAC7D,MAAM,IAAI,KAAK,CACX,0DAA0D,CAC7D,CAAA;SACJ;aAAM,IACH,OAAO,eAAe,CAAC,WAAW,IAAI,QAAQ;YAC9C,OAAO,eAAe,CAAC,UAAU,IAAI,QAAQ,EAC/C;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;SACzD;QAED,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC,WAAW,CAAA;QAC/C,IAAI,CAAC,WAAW,GAAG,eAAe,CAAC,UAAU,CAAA;IACjD,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,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|
|
1
1
|
{
|
|
2
2
|
"name": "@anitrack/patreon-wrapper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Discord Patreon wrapper for AniTrack",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc -p ."
|
|
8
|
+
"build": "tsc -p .",
|
|
9
|
+
"dev": "tsc-watch --onSuccess \"node lib/devTEST.js\""
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
13
|
"url": "git://github.com/AniTrack/patreon-wrapper.git"
|
|
13
14
|
},
|
|
14
15
|
"author": "AniTrack",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"patreon",
|
|
18
|
+
"discord",
|
|
19
|
+
"api"
|
|
20
|
+
],
|
|
15
21
|
"license": "MIT",
|
|
16
22
|
"bugs": {
|
|
17
23
|
"url": "https://github.com/AniTrack/patreon-wrapper/issues"
|
|
18
24
|
},
|
|
19
25
|
"homepage": "https://github.com/AniTrack/patreon-wrapper#readme",
|
|
20
26
|
"dependencies": {
|
|
21
|
-
"axios": "^0.
|
|
22
|
-
"typescript": "^4.6.
|
|
27
|
+
"axios": "^0.27.2",
|
|
28
|
+
"typescript": "^4.6.4"
|
|
23
29
|
},
|
|
24
30
|
"publishConfig": {
|
|
25
31
|
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"ts-node": "^10.7.0"
|
|
26
35
|
}
|
|
27
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,17 +13,17 @@ type PatronType = {
|
|
|
13
13
|
subscription: {
|
|
14
14
|
note: string
|
|
15
15
|
currentEntitled: {
|
|
16
|
-
status:
|
|
16
|
+
status: 'active_patron' | 'declined_patron'
|
|
17
17
|
tier: {
|
|
18
|
-
id:
|
|
18
|
+
id: string
|
|
19
19
|
title: string
|
|
20
20
|
}
|
|
21
21
|
cents: number
|
|
22
22
|
willPayCents: number
|
|
23
23
|
lifetimeCents: number
|
|
24
|
-
firstCharge:
|
|
25
|
-
nextCharge:
|
|
26
|
-
lastCharge:
|
|
24
|
+
firstCharge: string
|
|
25
|
+
nextCharge: string
|
|
26
|
+
lastCharge: string
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
mediaConnection: {
|
|
@@ -38,15 +38,43 @@ type PatronType = {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
type SandboxOptions = {
|
|
42
|
+
displayId: string
|
|
43
|
+
displayName: string
|
|
44
|
+
emailAddress: string
|
|
45
|
+
tier: {
|
|
46
|
+
id: string
|
|
47
|
+
title: string
|
|
48
|
+
}
|
|
49
|
+
cents: number
|
|
50
|
+
willPayCents: number
|
|
51
|
+
lifetimeCents: number
|
|
52
|
+
patronStatus: 'active_patron' | 'declined_patron'
|
|
53
|
+
firstCharge: string
|
|
54
|
+
nextCharge: string
|
|
55
|
+
lastCharge: string
|
|
56
|
+
mediaConnection: {
|
|
57
|
+
patreon: {
|
|
58
|
+
id: string
|
|
59
|
+
url: string
|
|
60
|
+
}
|
|
61
|
+
discord: { id: string; url: string }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
41
65
|
export class Patreon {
|
|
42
66
|
private static _URL: string = 'https://www.patreon.com/api/oauth2/v2/'
|
|
43
67
|
|
|
44
68
|
private static _AccessToken: string
|
|
45
69
|
private static _CampaignID: string
|
|
46
70
|
|
|
71
|
+
private static _SandboxPatrons: Array<SandboxOptions> = []
|
|
72
|
+
|
|
47
73
|
public static Authorization(AuthInformation: Auth) {
|
|
48
74
|
if (!AuthInformation.AccessToken || !AuthInformation.CampaignID) {
|
|
49
|
-
throw new Error(
|
|
75
|
+
throw new Error(
|
|
76
|
+
'AccessToken and CampaignID are required on Authorization'
|
|
77
|
+
)
|
|
50
78
|
} else if (
|
|
51
79
|
typeof AuthInformation.AccessToken != 'string' ||
|
|
52
80
|
typeof AuthInformation.CampaignID != 'string'
|
|
@@ -59,6 +87,12 @@ export class Patreon {
|
|
|
59
87
|
}
|
|
60
88
|
|
|
61
89
|
private static async FetchAPI(URI: string) {
|
|
90
|
+
if (!this._AccessToken || !this._CampaignID) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
'AccessToken and CampaignID are required on Authorization'
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
62
96
|
return await axios(this._URL + URI, {
|
|
63
97
|
method: 'GET',
|
|
64
98
|
headers: { Authorization: 'Bearer ' + this._AccessToken },
|
|
@@ -74,7 +108,10 @@ export class Patreon {
|
|
|
74
108
|
return query
|
|
75
109
|
}
|
|
76
110
|
|
|
77
|
-
public static async FetchPatrons(
|
|
111
|
+
public static async FetchPatrons(
|
|
112
|
+
filters: Array<'active_patron' | 'declined_patron'> = ['active_patron'],
|
|
113
|
+
pageSize: number = 450
|
|
114
|
+
) {
|
|
78
115
|
const res: any = await this.FetchAPI(
|
|
79
116
|
this.CleanQueryURL(
|
|
80
117
|
`campaigns/${this._CampaignID}/` +
|
|
@@ -82,13 +119,50 @@ export class Patreon {
|
|
|
82
119
|
)
|
|
83
120
|
)
|
|
84
121
|
|
|
85
|
-
|
|
122
|
+
var Patrons: Array<PatronType> = []
|
|
86
123
|
|
|
87
124
|
if (!res?.data?.data) return []
|
|
88
125
|
if (res.data.data.length == 0) return []
|
|
89
126
|
|
|
127
|
+
// Processing Fake Sandbox Patrons
|
|
128
|
+
this._SandboxPatrons.forEach((Patron: SandboxOptions) =>
|
|
129
|
+
Patrons.push({
|
|
130
|
+
displayId: Patron.displayId,
|
|
131
|
+
displayName: Patron.displayName,
|
|
132
|
+
emailAddress: Patron.emailAddress,
|
|
133
|
+
isFollower: false,
|
|
134
|
+
subscription: {
|
|
135
|
+
note: 'Sandbox',
|
|
136
|
+
currentEntitled: {
|
|
137
|
+
status: Patron.patronStatus,
|
|
138
|
+
tier: {
|
|
139
|
+
id: Patron.tier.id,
|
|
140
|
+
title: Patron.tier.title,
|
|
141
|
+
},
|
|
142
|
+
cents: Patron.cents,
|
|
143
|
+
willPayCents: Patron.willPayCents,
|
|
144
|
+
lifetimeCents: Patron.lifetimeCents,
|
|
145
|
+
firstCharge: Patron.firstCharge,
|
|
146
|
+
nextCharge: Patron.nextCharge,
|
|
147
|
+
lastCharge: Patron.lastCharge,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
mediaConnection: {
|
|
151
|
+
patreon: {
|
|
152
|
+
id: Patron.mediaConnection.patreon.id,
|
|
153
|
+
url: Patron.mediaConnection.patreon.url,
|
|
154
|
+
},
|
|
155
|
+
discord: {
|
|
156
|
+
id: Patron.mediaConnection.discord.id,
|
|
157
|
+
url: Patron.mediaConnection.discord.url,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
// Processing Real Patrons
|
|
90
164
|
res.data.data.forEach((Patron: any) => {
|
|
91
|
-
if (Patron.attributes.patron_status
|
|
165
|
+
if (!filters.includes(Patron.attributes.patron_status)) return
|
|
92
166
|
|
|
93
167
|
var socialInfo = res.data.included.find(
|
|
94
168
|
(includePatron: any) =>
|
|
@@ -113,11 +187,15 @@ export class Patreon {
|
|
|
113
187
|
currentEntitled: {
|
|
114
188
|
status: Patron.attributes.patron_status,
|
|
115
189
|
tier: {
|
|
116
|
-
id: tierInfo.id,
|
|
117
|
-
title: tierInfo.attributes.title,
|
|
190
|
+
id: tierInfo ? tierInfo.id : null,
|
|
191
|
+
title: tierInfo ? tierInfo.attributes.title : null,
|
|
118
192
|
},
|
|
119
|
-
cents:
|
|
120
|
-
.currently_entitled_amount_cents
|
|
193
|
+
cents:
|
|
194
|
+
Patron.attributes.currently_entitled_amount_cents !=
|
|
195
|
+
0
|
|
196
|
+
? Patron.attributes
|
|
197
|
+
.currently_entitled_amount_cents
|
|
198
|
+
: null,
|
|
121
199
|
willPayCents: Patron.attributes.will_pay_amount_cents,
|
|
122
200
|
lifetimeCents: Patron.attributes.lifetime_support_cents,
|
|
123
201
|
firstCharge:
|
|
@@ -145,7 +223,25 @@ export class Patreon {
|
|
|
145
223
|
return Patrons
|
|
146
224
|
}
|
|
147
225
|
|
|
226
|
+
protected static _SandboxAdd(Patron: SandboxOptions) {
|
|
227
|
+
this._SandboxPatrons.push(Patron)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
protected static _SandboxGet() {
|
|
231
|
+
return this._SandboxPatrons
|
|
232
|
+
}
|
|
233
|
+
|
|
148
234
|
// public static FetchPatron() {}
|
|
149
235
|
|
|
150
236
|
// public static FetchCampaign() {}
|
|
151
237
|
}
|
|
238
|
+
|
|
239
|
+
export class Sandbox extends Patreon {
|
|
240
|
+
public static GetFakePatrons() {
|
|
241
|
+
return super._SandboxGet()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static AppendPatron(Patron: SandboxOptions) {
|
|
245
|
+
super._SandboxAdd(Patron)
|
|
246
|
+
}
|
|
247
|
+
}
|