@anitrack/patreon-wrapper 1.4.5 → 1.5.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
@@ -4,7 +4,7 @@
4
4
 
5
5
  🌄 You can also simulates sandbox of fake Patrons for development and code testing purposes
6
6
 
7
- 🍊 This package was also used in [AniTrack](https://anitrack.co) Discord Bot
7
+ 🍊 This package was previously used in [AniTrack](https://anitrack.co) before switching to a real payment gateway
8
8
 
9
9
  ## Table of Contents
10
10
 
package/lib/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- declare type Auth = {
1
+ export type PatronStatus = 'active_patron' | 'declined_patron' | 'former_patron';
2
+ export type PatronAPIAuth = {
2
3
  AccessToken: string;
3
4
  CampaignID: string;
4
5
  };
5
- declare type PatronType = {
6
+ export type PatronType = {
6
7
  displayId: string;
7
8
  displayName: string;
8
9
  emailAddress: string;
@@ -10,7 +11,7 @@ declare type PatronType = {
10
11
  subscription: {
11
12
  note: string;
12
13
  currentEntitled: {
13
- status: 'active_patron' | 'declined_patron';
14
+ status: PatronStatus;
14
15
  tier: {
15
16
  id: string;
16
17
  title: string;
@@ -29,12 +30,12 @@ declare type PatronType = {
29
30
  url: string;
30
31
  };
31
32
  discord: {
32
- id: string;
33
- url: string;
33
+ id: string | null;
34
+ url: string | null;
34
35
  };
35
36
  };
36
37
  };
37
- declare type SandboxOptions = {
38
+ export type SandboxOptions = {
38
39
  displayId: string;
39
40
  displayName: string;
40
41
  emailAddress: string;
@@ -45,7 +46,7 @@ declare type SandboxOptions = {
45
46
  cents: number;
46
47
  willPayCents: number;
47
48
  lifetimeCents: number;
48
- patronStatus: 'active_patron' | 'declined_patron';
49
+ patronStatus: PatronStatus;
49
50
  firstCharge: string;
50
51
  nextCharge: string;
51
52
  lastCharge: string;
@@ -55,8 +56,8 @@ declare type SandboxOptions = {
55
56
  url: string;
56
57
  };
57
58
  discord: {
58
- id: string;
59
- url: string;
59
+ id: string | null;
60
+ url: string | null;
60
61
  };
61
62
  };
62
63
  };
@@ -65,16 +66,15 @@ export declare class Patreon {
65
66
  private static _AccessToken;
66
67
  private static _CampaignID;
67
68
  private static _SandboxPatrons;
68
- static Authorization(AuthInformation: Auth): void;
69
+ static Authorization(AuthCredentials: PatronAPIAuth): void;
69
70
  private static FetchAPI;
70
- private static CleanQueryURL;
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[];
71
+ private static CleanURL;
72
+ static FetchPatrons(filters?: Array<PatronStatus>, pageSize?: number): Promise<PatronType[]>;
73
+ protected static _SandboxAddPatron(Patron: SandboxOptions): void;
74
+ protected static _SandboxGetPatron(): SandboxOptions[];
74
75
  }
75
76
  export declare class Sandbox extends Patreon {
76
- static GetFakePatrons(): SandboxOptions[];
77
- static AppendPatron(Patron: SandboxOptions): void;
77
+ static GetSandboxPatrons(): SandboxOptions[];
78
+ static AddSandboxPatron(Patron: SandboxOptions): void;
78
79
  }
79
- export {};
80
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,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,eAAe,GAAG,iBAAiB,CAAA;YAC3C,IAAI,EAAE;gBACF,EAAE,EAAE,MAAM,CAAA;gBACV,KAAK,EAAE,MAAM,CAAA;a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,iBAAiB,CAAC,MAAM,EAAE,cAAc;IAIzD,SAAS,CAAC,MAAM,CAAC,iBAAiB;CAOrC;AAED,qBAAa,OAAQ,SAAQ,OAAO;WAClB,iBAAiB;WAIjB,gBAAgB,CAAC,MAAM,EAAE,cAAc;CAGxD"}
package/lib/index.js CHANGED
@@ -6,16 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Sandbox = exports.Patreon = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  class Patreon {
9
- static Authorization(AuthInformation) {
10
- if (!AuthInformation.AccessToken || !AuthInformation.CampaignID) {
9
+ static Authorization(AuthCredentials) {
10
+ if (!AuthCredentials.AccessToken || !AuthCredentials.CampaignID) {
11
11
  throw new Error('AccessToken and CampaignID are required on Authorization');
12
12
  }
13
- else if (typeof AuthInformation.AccessToken != 'string' ||
14
- typeof AuthInformation.CampaignID != 'string') {
15
- throw new Error('Invalid input, not a type of String');
16
- }
17
- this._AccessToken = AuthInformation.AccessToken;
18
- this._CampaignID = AuthInformation.CampaignID;
13
+ this._AccessToken = AuthCredentials.AccessToken;
14
+ this._CampaignID = AuthCredentials.CampaignID;
19
15
  }
20
16
  static async FetchAPI(URI) {
21
17
  if (!this._AccessToken || !this._CampaignID) {
@@ -28,90 +24,96 @@ class Patreon {
28
24
  throw new Error('Fetch API Failed...' + err);
29
25
  });
30
26
  }
31
- static CleanQueryURL(query) {
27
+ static CleanURL(query) {
32
28
  query = query.replaceAll('[', '%5B').replaceAll(']', '%5D');
33
29
  query = query.replaceAll(' ', '');
34
30
  return query;
35
31
  }
36
32
  static async FetchPatrons(filters = ['active_patron'], pageSize = 450) {
37
- const res = await this.FetchAPI(this.CleanQueryURL(`campaigns/${this._CampaignID}/` +
33
+ const { data } = await this.FetchAPI(this.CleanURL(`campaigns/${this._CampaignID}/` +
38
34
  `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`));
39
- var Patrons = [];
40
- if (!res?.data?.data)
41
- return [];
42
- if (res.data.data.length == 0)
35
+ const Patrons = [];
36
+ const PatreonAPIPatrons = data?.data || [];
37
+ if (PatreonAPIPatrons.length == 0)
43
38
  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,
39
+ // Format Sandbox Patrons
40
+ for (let x = 0; x < this._SandboxPatrons.length; x++) {
41
+ const Patron = this._SandboxPatrons[x];
42
+ Patrons.push({
43
+ displayId: Patron.displayId,
44
+ displayName: Patron.displayName,
45
+ emailAddress: Patron.emailAddress,
46
+ isFollower: false,
47
+ subscription: {
48
+ note: 'Sandbox',
49
+ currentEntitled: {
50
+ status: Patron.patronStatus,
51
+ tier: {
52
+ id: Patron.tier.id,
53
+ title: Patron.tier.title,
54
+ },
55
+ cents: Patron.cents,
56
+ willPayCents: Patron.willPayCents,
57
+ lifetimeCents: Patron.lifetimeCents,
58
+ firstCharge: Patron.firstCharge,
59
+ nextCharge: Patron.nextCharge,
60
+ lastCharge: Patron.lastCharge,
57
61
  },
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
62
  },
71
- discord: {
72
- id: Patron.mediaConnection.discord.id,
73
- url: Patron.mediaConnection.discord.url,
63
+ mediaConnection: {
64
+ patreon: {
65
+ id: Patron.mediaConnection.patreon.id,
66
+ url: Patron.mediaConnection.patreon.url,
67
+ },
68
+ discord: {
69
+ id: Patron?.mediaConnection?.discord?.id
70
+ ? Patron?.mediaConnection?.discord?.id
71
+ : null,
72
+ url: Patron?.mediaConnection?.discord?.url
73
+ ? Patron?.mediaConnection?.discord?.id
74
+ : null,
75
+ },
74
76
  },
75
- },
76
- }));
77
- // Processing Real Patrons
78
- res.data.data.forEach((Patron) => {
79
- if (!filters.includes(Patron.attributes.patron_status))
80
- return;
81
- var socialInfo = res.data.included.find((includePatron) => includePatron.id == Patron.relationships.user.data.id &&
82
- includePatron.type === 'user');
83
- var tierInfo = res.data.included.find((includePatron) => includePatron.id ==
84
- Patron.relationships.currently_entitled_tiers?.data[0]
85
- ?.id && includePatron.type === 'tier');
77
+ });
78
+ }
79
+ // Format Real Patrons
80
+ for (let x = 0; x < PatreonAPIPatrons.length; x++) {
81
+ const Relationships = PatreonAPIPatrons[x].relationships;
82
+ const Attributes = PatreonAPIPatrons[x].attributes;
83
+ if (!filters.includes(Attributes.patron_status))
84
+ continue;
85
+ const socialInfo = data.included.find((patron) => patron.id == Relationships.user.data.id &&
86
+ patron.type === 'user');
87
+ const tierInfo = data.included.find((patron) => patron.id ==
88
+ Relationships.currently_entitled_tiers?.data[0]?.id &&
89
+ patron.type === 'tier');
86
90
  Patrons.push({
87
- displayId: Patron.relationships.user.data.id,
88
- displayName: Patron.attributes.full_name,
89
- emailAddress: Patron.attributes.email,
90
- isFollower: Patron.attributes.is_follower,
91
+ displayId: Relationships.user.data.id,
92
+ displayName: Attributes.full_name,
93
+ emailAddress: Attributes.email,
94
+ isFollower: Attributes.is_follower,
91
95
  subscription: {
92
- note: Patron.attributes.note,
96
+ note: Attributes.note,
93
97
  currentEntitled: {
94
- status: Patron.attributes.patron_status,
98
+ status: Attributes.patron_status,
95
99
  tier: {
96
100
  id: tierInfo ? tierInfo.id : null,
97
- title: tierInfo ? tierInfo.attributes.title : null,
101
+ title: tierInfo ? tierInfo.Attributes.title : null,
98
102
  },
99
- cents: Patron.attributes.currently_entitled_amount_cents !=
100
- 0
101
- ? Patron.attributes
102
- .currently_entitled_amount_cents
103
+ cents: Attributes.currently_entitled_amount_cents != 0
104
+ ? Attributes.currently_entitled_amount_cents
103
105
  : null,
104
- willPayCents: Patron.attributes.will_pay_amount_cents,
105
- lifetimeCents: Patron.attributes.lifetime_support_cents,
106
- firstCharge: Patron.attributes.pledge_relationship_start,
107
- nextCharge: Patron.attributes.next_charge_date,
108
- lastCharge: Patron.attributes.last_charge_date,
106
+ willPayCents: Attributes.will_pay_amount_cents,
107
+ lifetimeCents: Attributes.lifetime_support_cents,
108
+ firstCharge: Attributes.pledge_relationship_start,
109
+ nextCharge: Attributes.next_charge_date,
110
+ lastCharge: Attributes.last_charge_date,
109
111
  },
110
112
  },
111
113
  mediaConnection: {
112
114
  patreon: {
113
- id: Patron.relationships.user.data.id,
114
- url: Patron.relationships.user.links.related,
115
+ id: Relationships.user.data.id,
116
+ url: Relationships.user.links.related,
115
117
  },
116
118
  discord: {
117
119
  id: socialInfo?.attributes?.social_connections?.discord
@@ -128,13 +130,13 @@ class Patreon {
128
130
  },
129
131
  },
130
132
  });
131
- });
133
+ }
132
134
  return Patrons;
133
135
  }
134
- static _SandboxAdd(Patron) {
136
+ static _SandboxAddPatron(Patron) {
135
137
  this._SandboxPatrons.push(Patron);
136
138
  }
137
- static _SandboxGet() {
139
+ static _SandboxGetPatron() {
138
140
  return this._SandboxPatrons;
139
141
  }
140
142
  }
@@ -142,11 +144,11 @@ exports.Patreon = Patreon;
142
144
  Patreon._URL = 'https://www.patreon.com/api/oauth2/v2/';
143
145
  Patreon._SandboxPatrons = [];
144
146
  class Sandbox extends Patreon {
145
- static GetFakePatrons() {
146
- return super._SandboxGet();
147
+ static GetSandboxPatrons() {
148
+ return super._SandboxGetPatron();
147
149
  }
148
- static AppendPatron(Patron) {
149
- super._SandboxAdd(Patron);
150
+ static AddSandboxPatron(Patron) {
151
+ super._SandboxAddPatron(Patron);
150
152
  }
151
153
  }
152
154
  exports.Sandbox = Sandbox;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
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,QAAQ,CAAC,GAAW;QACrC,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACzC,MAAM,IAAI,KAAK,CACX,0DAA0D,CAC7D,CAAA;SACJ;QAED,OAAO,MAAM,IAAA,eAAK,EAAC,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE;SAC5D,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,GAAG,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,MAAM,CAAC,aAAa,C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IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAES,MAAM,CAAC,iBAAiB;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;;AA9KL,0BAmLC;AAlLkB,YAAI,GAAW,wCAAwC,CAAC;AAIxD,uBAAe,GAA0B,EAAE,CAAC;AAgL/D,MAAa,OAAQ,SAAQ,OAAO;IACzB,MAAM,CAAC,iBAAiB;QAC3B,OAAO,KAAK,CAAC,iBAAiB,EAAE,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,MAAsB;QACjD,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACJ;AARD,0BAQC"}
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "@anitrack/patreon-wrapper",
3
- "version": "1.4.5",
4
- "description": "Universal Patron API v2 wrapper that simplifies the API's response for easier usage and lower response complexity",
5
- "main": "lib/index.js",
6
- "types": "lib",
7
- "scripts": {
8
- "build": "tsc -p .",
9
- "dev": "tsc-watch --onSuccess \"node lib/devTEST.js\""
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git://github.com/AniTrack/patreon-wrapper.git"
14
- },
15
- "author": "AniTrack",
16
- "keywords": [
17
- "patreon",
18
- "discord",
19
- "api"
20
- ],
21
- "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/AniTrack/patreon-wrapper/issues"
24
- },
25
- "homepage": "https://github.com/AniTrack/patreon-wrapper#readme",
26
- "dependencies": {
27
- "axios": "^0.27.2"
28
- },
29
- "publishConfig": {
30
- "access": "public"
31
- },
32
- "devDependencies": {
33
- "ts-node": "^10.7.0",
34
- "typescript": "^4.6.4"
35
- }
36
- }
1
+ {
2
+ "name": "@anitrack/patreon-wrapper",
3
+ "version": "1.5.0",
4
+ "description": "Universal Patron API v2 wrapper that simplifies the API's response for easier usage and lower response complexity",
5
+ "main": "lib/index.js",
6
+ "types": "lib",
7
+ "scripts": {
8
+ "build": "tsc -p .",
9
+ "dev": "tsc-watch --onSuccess \"node lib/devTEST.js\""
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git://github.com/AniTrack/patreon-wrapper.git"
14
+ },
15
+ "author": "AniTrack",
16
+ "keywords": [
17
+ "patreon",
18
+ "discord",
19
+ "api"
20
+ ],
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/AniTrack/patreon-wrapper/issues"
24
+ },
25
+ "homepage": "https://github.com/AniTrack/patreon-wrapper#readme",
26
+ "dependencies": {
27
+ "axios": "^0.27.2"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "devDependencies": {
33
+ "ts-node": "^10.7.0",
34
+ "typescript": "^4.6.4"
35
+ }
36
+ }
package/src/index.ts CHANGED
@@ -1,131 +1,135 @@
1
- import axios from 'axios'
1
+ import axios from 'axios';
2
2
 
3
- type Auth = {
4
- AccessToken: string
5
- CampaignID: string
6
- }
3
+ export type PatronStatus =
4
+ | 'active_patron'
5
+ | 'declined_patron'
6
+ | 'former_patron';
7
+
8
+ export type PatronAPIAuth = {
9
+ AccessToken: string;
10
+ CampaignID: string;
11
+ };
7
12
 
8
- type PatronType = {
9
- displayId: string
10
- displayName: string
11
- emailAddress: string
12
- isFollower: boolean
13
+ export type PatronType = {
14
+ displayId: string;
15
+ displayName: string;
16
+ emailAddress: string;
17
+ isFollower: boolean;
13
18
  subscription: {
14
- note: string
19
+ note: string;
15
20
  currentEntitled: {
16
- status: 'active_patron' | 'declined_patron'
21
+ status: PatronStatus;
17
22
  tier: {
18
- id: string
19
- title: string
20
- }
21
- cents: number
22
- willPayCents: number
23
- lifetimeCents: number
24
- firstCharge: string
25
- nextCharge: string
26
- lastCharge: string
27
- }
28
- }
23
+ id: string;
24
+ title: string;
25
+ };
26
+ cents: number;
27
+ willPayCents: number;
28
+ lifetimeCents: number;
29
+ firstCharge: string;
30
+ nextCharge: string;
31
+ lastCharge: string;
32
+ };
33
+ };
29
34
  mediaConnection: {
30
35
  patreon: {
31
- id: string
32
- url: string
33
- }
36
+ id: string;
37
+ url: string;
38
+ };
34
39
  discord: {
35
- id: string
36
- url: string
37
- }
38
- }
39
- }
40
+ id: string | null;
41
+ url: string | null;
42
+ };
43
+ };
44
+ };
40
45
 
41
- type SandboxOptions = {
42
- displayId: string
43
- displayName: string
44
- emailAddress: string
46
+ export type SandboxOptions = {
47
+ displayId: string;
48
+ displayName: string;
49
+ emailAddress: string;
45
50
  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
51
+ id: string;
52
+ title: string;
53
+ };
54
+ cents: number;
55
+ willPayCents: number;
56
+ lifetimeCents: number;
57
+ patronStatus: PatronStatus;
58
+ firstCharge: string;
59
+ nextCharge: string;
60
+ lastCharge: string;
56
61
  mediaConnection: {
57
62
  patreon: {
58
- id: string
59
- url: string
60
- }
61
- discord: { id: string; url: string }
62
- }
63
- }
63
+ id: string;
64
+ url: string;
65
+ };
66
+ discord: {
67
+ id: string | null;
68
+ url: string | null;
69
+ };
70
+ };
71
+ };
64
72
 
65
73
  export class Patreon {
66
- private static _URL: string = 'https://www.patreon.com/api/oauth2/v2/'
74
+ private static _URL: string = 'https://www.patreon.com/api/oauth2/v2/';
67
75
 
68
- private static _AccessToken: string
69
- private static _CampaignID: string
76
+ private static _AccessToken: string;
77
+ private static _CampaignID: string;
78
+ private static _SandboxPatrons: Array<SandboxOptions> = [];
70
79
 
71
- private static _SandboxPatrons: Array<SandboxOptions> = []
72
-
73
- public static Authorization(AuthInformation: Auth) {
74
- if (!AuthInformation.AccessToken || !AuthInformation.CampaignID) {
80
+ public static Authorization(AuthCredentials: PatronAPIAuth) {
81
+ if (!AuthCredentials.AccessToken || !AuthCredentials.CampaignID) {
75
82
  throw new Error(
76
83
  'AccessToken and CampaignID are required on Authorization'
77
- )
78
- } else if (
79
- typeof AuthInformation.AccessToken != 'string' ||
80
- typeof AuthInformation.CampaignID != 'string'
81
- ) {
82
- throw new Error('Invalid input, not a type of String')
84
+ );
83
85
  }
84
86
 
85
- this._AccessToken = AuthInformation.AccessToken
86
- this._CampaignID = AuthInformation.CampaignID
87
+ this._AccessToken = AuthCredentials.AccessToken;
88
+ this._CampaignID = AuthCredentials.CampaignID;
87
89
  }
88
90
 
89
91
  private static async FetchAPI(URI: string) {
90
92
  if (!this._AccessToken || !this._CampaignID) {
91
93
  throw new Error(
92
94
  'AccessToken and CampaignID are required on Authorization'
93
- )
95
+ );
94
96
  }
95
97
 
96
98
  return await axios(this._URL + URI, {
97
99
  method: 'GET',
98
100
  headers: { Authorization: 'Bearer ' + this._AccessToken },
99
101
  }).catch((err: Error) => {
100
- throw new Error('Fetch API Failed...' + err)
101
- })
102
+ throw new Error('Fetch API Failed...' + err);
103
+ });
102
104
  }
103
105
 
104
- private static CleanQueryURL(query: string) {
105
- query = query.replaceAll('[', '%5B').replaceAll(']', '%5D')
106
- query = query.replaceAll(' ', '')
106
+ private static CleanURL(query: string) {
107
+ query = query.replaceAll('[', '%5B').replaceAll(']', '%5D');
108
+ query = query.replaceAll(' ', '');
107
109
 
108
- return query
110
+ return query;
109
111
  }
110
112
 
111
113
  public static async FetchPatrons(
112
- filters: Array<'active_patron' | 'declined_patron'> = ['active_patron'],
114
+ filters: Array<PatronStatus> = ['active_patron'],
113
115
  pageSize: number = 450
114
116
  ) {
115
- const res: any = await this.FetchAPI(
116
- this.CleanQueryURL(
117
+ const { data } = await this.FetchAPI(
118
+ this.CleanURL(
117
119
  `campaigns/${this._CampaignID}/` +
118
120
  `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`
119
121
  )
120
- )
122
+ );
121
123
 
122
- var Patrons: Array<PatronType> = []
124
+ const Patrons: Array<PatronType> = [];
125
+ const PatreonAPIPatrons = data?.data || [];
123
126
 
124
- if (!res?.data?.data) return []
125
- if (res.data.data.length == 0) return []
127
+ if (PatreonAPIPatrons.length == 0) return [];
128
+
129
+ // Format Sandbox Patrons
130
+ for (let x = 0; x < this._SandboxPatrons.length; x++) {
131
+ const Patron = this._SandboxPatrons[x];
126
132
 
127
- // Processing Fake Sandbox Patrons
128
- this._SandboxPatrons.forEach((Patron: SandboxOptions) =>
129
133
  Patrons.push({
130
134
  displayId: Patron.displayId,
131
135
  displayName: Patron.displayName,
@@ -153,61 +157,65 @@ export class Patreon {
153
157
  url: Patron.mediaConnection.patreon.url,
154
158
  },
155
159
  discord: {
156
- id: Patron.mediaConnection.discord.id,
157
- url: Patron.mediaConnection.discord.url,
160
+ id: Patron?.mediaConnection?.discord?.id
161
+ ? Patron?.mediaConnection?.discord?.id
162
+ : null,
163
+ url: Patron?.mediaConnection?.discord?.url
164
+ ? Patron?.mediaConnection?.discord?.id
165
+ : null,
158
166
  },
159
167
  },
160
- })
161
- )
168
+ });
169
+ }
162
170
 
163
- // Processing Real Patrons
164
- res.data.data.forEach((Patron: any) => {
165
- if (!filters.includes(Patron.attributes.patron_status)) return
171
+ // Format Real Patrons
172
+ for (let x = 0; x < PatreonAPIPatrons.length; x++) {
173
+ const Relationships = PatreonAPIPatrons[x].relationships;
174
+ const Attributes = PatreonAPIPatrons[x].attributes;
166
175
 
167
- var socialInfo = res.data.included.find(
168
- (includePatron: any) =>
169
- includePatron.id == Patron.relationships.user.data.id &&
170
- includePatron.type === 'user'
171
- )
176
+ if (!filters.includes(Attributes.patron_status)) continue;
172
177
 
173
- var tierInfo = res.data.included.find(
174
- (includePatron: any) =>
175
- includePatron.id ==
176
- Patron.relationships.currently_entitled_tiers?.data[0]
177
- ?.id && includePatron.type === 'tier'
178
- )
178
+ const socialInfo = data.included.find(
179
+ (patron: any) =>
180
+ patron.id == Relationships.user.data.id &&
181
+ patron.type === 'user'
182
+ );
183
+
184
+ const tierInfo = data.included.find(
185
+ (patron: any) =>
186
+ patron.id ==
187
+ Relationships.currently_entitled_tiers?.data[0]?.id &&
188
+ patron.type === 'tier'
189
+ );
179
190
 
180
191
  Patrons.push({
181
- displayId: Patron.relationships.user.data.id,
182
- displayName: Patron.attributes.full_name,
183
- emailAddress: Patron.attributes.email,
184
- isFollower: Patron.attributes.is_follower,
192
+ displayId: Relationships.user.data.id,
193
+ displayName: Attributes.full_name,
194
+ emailAddress: Attributes.email,
195
+ isFollower: Attributes.is_follower,
185
196
  subscription: {
186
- note: Patron.attributes.note,
197
+ note: Attributes.note,
187
198
  currentEntitled: {
188
- status: Patron.attributes.patron_status,
199
+ status: Attributes.patron_status,
189
200
  tier: {
190
201
  id: tierInfo ? tierInfo.id : null,
191
- title: tierInfo ? tierInfo.attributes.title : null,
202
+ title: tierInfo ? tierInfo.Attributes.title : null,
192
203
  },
193
204
  cents:
194
- Patron.attributes.currently_entitled_amount_cents !=
195
- 0
196
- ? Patron.attributes
197
- .currently_entitled_amount_cents
205
+ Attributes.currently_entitled_amount_cents != 0
206
+ ? Attributes.currently_entitled_amount_cents
198
207
  : null,
199
- willPayCents: Patron.attributes.will_pay_amount_cents,
200
- lifetimeCents: Patron.attributes.lifetime_support_cents,
201
- firstCharge:
202
- Patron.attributes.pledge_relationship_start,
203
- nextCharge: Patron.attributes.next_charge_date,
204
- lastCharge: Patron.attributes.last_charge_date,
208
+ willPayCents: Attributes.will_pay_amount_cents,
209
+ lifetimeCents: Attributes.lifetime_support_cents,
210
+ firstCharge: Attributes.pledge_relationship_start,
211
+ nextCharge: Attributes.next_charge_date,
212
+ lastCharge: Attributes.last_charge_date,
205
213
  },
206
214
  },
207
215
  mediaConnection: {
208
216
  patreon: {
209
- id: Patron.relationships.user.data.id,
210
- url: Patron.relationships.user.links.related,
217
+ id: Relationships.user.data.id,
218
+ url: Relationships.user.links.related,
211
219
  },
212
220
  discord: {
213
221
  id: socialInfo?.attributes?.social_connections?.discord
@@ -224,17 +232,18 @@ export class Patreon {
224
232
  : null,
225
233
  },
226
234
  },
227
- })
228
- })
229
- return Patrons
235
+ });
236
+ }
237
+
238
+ return Patrons;
230
239
  }
231
240
 
232
- protected static _SandboxAdd(Patron: SandboxOptions) {
233
- this._SandboxPatrons.push(Patron)
241
+ protected static _SandboxAddPatron(Patron: SandboxOptions) {
242
+ this._SandboxPatrons.push(Patron);
234
243
  }
235
244
 
236
- protected static _SandboxGet() {
237
- return this._SandboxPatrons
245
+ protected static _SandboxGetPatron() {
246
+ return this._SandboxPatrons;
238
247
  }
239
248
 
240
249
  // public static FetchPatron() {}
@@ -243,11 +252,11 @@ export class Patreon {
243
252
  }
244
253
 
245
254
  export class Sandbox extends Patreon {
246
- public static GetFakePatrons() {
247
- return super._SandboxGet()
255
+ public static GetSandboxPatrons() {
256
+ return super._SandboxGetPatron();
248
257
  }
249
258
 
250
- public static AppendPatron(Patron: SandboxOptions) {
251
- super._SandboxAdd(Patron)
259
+ public static AddSandboxPatron(Patron: SandboxOptions) {
260
+ super._SandboxAddPatron(Patron);
252
261
  }
253
262
  }