@anitrack/patreon-wrapper 1.3.3 → 1.4.0

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 CHANGED
@@ -1,35 +1,52 @@
1
1
  # Patreon Wrapper 🍊
2
- An Simple Patreon Wrapper with much cleaner responses. Patreon. Why u do dis..
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
- - [Installing](#installing)
6
- - [Example](#example)
7
- - [License](#license)
10
+
11
+ - [Installing](#installing)
12
+ - [Real usage example](#Usage%20Example)
13
+ - [Sandbox for development](#Sandboxing)
14
+ - [License](#license)
8
15
 
9
16
  ## Installing
17
+
10
18
  Using NPM
19
+
11
20
  ```
12
21
  $ npm install @anitrack/patreon-wrapper
13
22
  ```
23
+
14
24
  Using YARN
25
+
15
26
  ```
16
27
  $ yarn add @anitrack/patreon-wrapper
17
28
  ```
18
29
 
19
- ## Example
30
+ ## Usage Example
20
31
 
21
32
  ### Importing
22
33
 
23
34
  CommonJS
35
+
24
36
  ```js
25
- const { Patreon } = require('@AniTrack/patreon-wrapper')
37
+ const { Patreon } = require('@anitrack/patreon-wrapper')
26
38
  ```
39
+
27
40
  Typescript ES6
41
+
28
42
  ```js
29
- import { Patreon } from '@AniTrack/patreon-wrapper'
43
+ import { Patreon } from '@anitrack/patreon-wrapper'
30
44
  ```
31
45
 
32
- Authorization
46
+ ### Authorization
47
+
48
+ > 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
49
+
33
50
  ```js
34
51
  Patreon.Authorization({
35
52
  AccessToken: 'YOUR_API_V2_ACCESS_TOKEN',
@@ -40,8 +57,9 @@ Patreon.Authorization({
40
57
  ### Fetching every Patrons on the Campaign
41
58
 
42
59
  Promies then catch
60
+
43
61
  ```js
44
- Patreon.FetchPatrons()
62
+ Patreon.FetchPatrons(['active_patron', 'declined_patron'])
45
63
  .then((Patrons) => {
46
64
  // Handle Patrons List
47
65
  console.log(Patrons)
@@ -51,14 +69,17 @@ Patreon.FetchPatrons()
51
69
  console.log(err)
52
70
  })
53
71
  ```
72
+
54
73
  Async/Await
74
+
55
75
  ```js
56
- var Patrons = await Patreon.FetchPatrons()
76
+ var Patrons = await Patreon.FetchPatrons(['active_patron', 'declined_patron'])
57
77
 
58
78
  console.log(Patrons)
59
79
  ```
60
80
 
61
81
  Clean Response Example
82
+
62
83
  ```js
63
84
  // Example response from fetching Patron list
64
85
  [
@@ -73,24 +94,24 @@ Clean Response Example
73
94
  status: 'active_patron',
74
95
  tier: {
75
96
  id: '12345678',
76
- title: 'First Tier'
97
+ title: 'My First Tier'
77
98
  },
78
99
  cents: 500, // 5 USD
79
100
  willPayCents: 500,
80
- lifetimeCents: 0,
81
- firstCharge: 'DATE',
82
- nextCharge: 'DATE',
83
- lastCharge: 'DATE'
101
+ lifetimeCents: 1500,
102
+ firstCharge: '2022-01-15 15:00:00.000', // ISO 8601 DATE
103
+ nextCharge: '2022-05-15 15:00:00.000',
104
+ lastCharge: '2022-05-15 15:00:00.000'
84
105
  }
85
106
  },
86
107
  mediaConnection: {
87
108
  patreon: {
88
109
  id: '12345678',
89
- url: 'https://www.patreon.com/api/oauth2/v2/user/12345678'
110
+ url: 'https://www.patreon.com/api/oauth2/v2/user/12345678'
90
111
  },
91
112
  discord: {
92
- id: 'DISCORD_USER_ID',
93
- url: 'https://discordapp.com/users/DISCORD_USER_ID'
113
+ id: '12345678',
114
+ url: 'https://discordapp.com/users/12345678'
94
115
  }
95
116
  }
96
117
  },
@@ -99,13 +120,71 @@ Clean Response Example
99
120
  },
100
121
  {
101
122
  ...
102
- },
103
- {
104
- ...
105
123
  }
106
124
  ]
107
125
  ```
108
126
 
127
+ <br />
128
+
129
+ ## Sandboxing
130
+
131
+ > This is great for development and working with fake patrons users. The fake patrons in FetchPatrons() will be exactly the same as real ones!
132
+
133
+ <br />
134
+
135
+ ### Importing Sandbox
136
+
137
+ ```js
138
+ import { Patreon, Sandbox } from './index'
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: string;
13
+ status: 'active_patron' | 'declined_patron';
14
14
  tier: {
15
- id: number;
15
+ id: string;
16
16
  title: string;
17
17
  };
18
18
  cents: number;
19
19
  willPayCents: number;
20
20
  lifetimeCents: number;
21
- firstCharge: Date;
22
- nextCharge: Date;
23
- lastCharge: Date;
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,aAAK,IAAI,GAAG;IACR,WAAW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L,EAAE,EAAE,MAAM,CAAA;YACV,GAAG,EAAE,MAAM,CAAA;SACd,CAAA;QACD,OAAO,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KACvC,CAAA;CACJ,CAAA;AAED,qBAAa,OAAO;IAChB,OAAO,CAAC,MAAM,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('Either Missing AccessToken or CampaignID');
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
- const Patrons = [];
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 == 'declined_patron')
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
- .currently_entitled_amount_cents,
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,"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AAA;IACrC,CAAC;IAES,MAAM,CAAC,WAAW;QACxB,OAAO,IAAI,CAAC,eAAe,CAAA;IAC/B,CAAC;;AAvKL,0BA4KC;AA3KkB,YAAI,GAAW,wCAAwC,CAAA;AAKvD,uBAAe,GAA0B,EAAE,CAAA;AAwK9D,MAAa,OAAQ,SAAQ,OAAO;IACzB,MAAM,CAAC,cAAc;QACxB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;IAC9B,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,MAAsB;QAC7C,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;CACJ;AARD,0BAQC"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@anitrack/patreon-wrapper",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
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",
@@ -18,10 +19,13 @@
18
19
  },
19
20
  "homepage": "https://github.com/AniTrack/patreon-wrapper#readme",
20
21
  "dependencies": {
21
- "axios": "^0.26.1",
22
- "typescript": "^4.6.2"
22
+ "axios": "^0.27.2",
23
+ "typescript": "^4.6.4"
23
24
  },
24
25
  "publishConfig": {
25
26
  "access": "public"
27
+ },
28
+ "devDependencies": {
29
+ "ts-node": "^10.7.0"
26
30
  }
27
31
  }
package/src/index.ts CHANGED
@@ -13,17 +13,17 @@ type PatronType = {
13
13
  subscription: {
14
14
  note: string
15
15
  currentEntitled: {
16
- status: string
16
+ status: 'active_patron' | 'declined_patron'
17
17
  tier: {
18
- id: number
18
+ id: string
19
19
  title: string
20
20
  }
21
21
  cents: number
22
22
  willPayCents: number
23
23
  lifetimeCents: number
24
- firstCharge: Date
25
- nextCharge: Date
26
- lastCharge: Date
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('Either Missing AccessToken or CampaignID')
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(pageSize: number = 450) {
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
- const Patrons: Array<PatronType> = []
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 == 'declined_patron') return
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: Patron.attributes
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
+ }