elections-types 1.0.0 → 1.0.1

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.
@@ -0,0 +1,3 @@
1
+ export * from "./types/APIError.js";
2
+ export * from "./types/Tweet.js";
3
+ export * from "./types/User.js";
@@ -0,0 +1,3 @@
1
+ export * from "./types/APIError.js";
2
+ export * from "./types/Tweet.js";
3
+ export * from "./types/User.js";
@@ -0,0 +1,4 @@
1
+ export declare class APIError extends Error {
2
+ status: number;
3
+ constructor(status: number, message?: string);
4
+ }
@@ -0,0 +1,19 @@
1
+ const default_messages_by_status = {
2
+ 400: "Bad Request",
3
+ 401: "Unauthorized",
4
+ 403: "Forbidden",
5
+ 404: "Not Found",
6
+ 405: "Method Not Allowed",
7
+ 500: "Internal Server Error",
8
+ 504: "Gateway Timeout",
9
+ 600: "Failed to Parse Output"
10
+ };
11
+ export class APIError extends Error {
12
+ status;
13
+ constructor(status, message) {
14
+ const default_message = default_messages_by_status[status];
15
+ super(message !== undefined ? message : default_message !== undefined ? default_message : "Error");
16
+ this.name = "APIError";
17
+ this.status = status;
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ // import { ElectionID, OfficeID } from "./Election.js"
2
+ // import { StateID } from "./State.js"
3
+ export {};
4
+ // export class Candidate {
5
+ // readonly candidate_id : string
6
+ // readonly fec_name : string
7
+ // readonly office_id : OfficeID
8
+ // readonly state_id : StateID
9
+ // readonly election_id : ElectionID
10
+ // readonly party_id : string
11
+ // readonly active : boolean
12
+ // readonly status : boolean
13
+ // constructor(candidate : any) {
14
+ // if (!Candidate.is(candidate)) {
15
+ // throw Error("Invalid input.")
16
+ // }
17
+ // this.office_id = candidate.office_id
18
+ // this.number = candidate.number
19
+ // this.scout_id = candidate.scout_id
20
+ // this.name = candidate.name
21
+ // this.active = candidate.active
22
+ // this.state_id = candidate.state_id
23
+ // this.district = candidate.district
24
+ // this.party_id = candidate.party_id
25
+ // this.tone_description_refresh = candidate.tone_description_refresh
26
+ // this.jurisdiction_ids = candidate.jurisdiction_ids
27
+ // this.sub_scout_ids = candidate.sub_scout_ids
28
+ // this.office_class_id = candidate.office_class_id
29
+ // this.office_name = candidate.office_name
30
+ // }
31
+ // static is(candidate : any) : candidate is Candidate {
32
+ // return (
33
+ // candidate !== undefined &&
34
+ // typeof candidate.office_id === "string" &&
35
+ // typeof candidate.number === "string" &&
36
+ // typeof candidate.scout_id === "string" &&
37
+ // typeof candidate.name === "string" &&
38
+ // typeof candidate.active === "boolean" &&
39
+ // (candidate.state_id === undefined || is_state_id(candidate.state_id)) &&
40
+ // (candidate.district === undefined || typeof candidate.district === "number") &&
41
+ // is_party_id(candidate.party_id) &&
42
+ // typeof candidate.tone_description_refresh === "boolean" &&
43
+ // Array.isArray(candidate.jurisdiction_ids) &&
44
+ // candidate.jurisdiction_ids.every((jurisdiction_id : any) => typeof jurisdiction_id === "number") &&
45
+ // (candidate.sub_scout_ids === undefined || Array.isArray(candidate.sub_scout_ids) && candidate.sub_scout_ids.every((sub_scout_id : any) => typeof sub_scout_id === "string")) &&
46
+ // is_office_class_id(candidate.office_class_id) &&
47
+ // (candidate.office_name === undefined || typeof candidate.office_name === "string")
48
+ // )
49
+ // }
50
+ // }
@@ -0,0 +1,21 @@
1
+ export declare const designations: readonly ["F1", "F2", "F3", "F24"];
2
+ export type CommitteeDesignation = typeof designations[number];
3
+ export declare function is_committee_designation(designation: any): designation is CommitteeDesignation;
4
+ export declare class Committee {
5
+ readonly committee_id: string;
6
+ readonly name: string;
7
+ readonly url: string;
8
+ readonly designation: CommitteeDesignation;
9
+ readonly file_number: number;
10
+ readonly principal_committee_ids?: string[];
11
+ readonly authorized_committee_ids?: string[];
12
+ readonly sponsor_committee_ids?: string[];
13
+ readonly jfp_committee_ids?: string[];
14
+ readonly jfr_committee_ids?: string[];
15
+ readonly aff_committee_ids?: string[];
16
+ readonly candidate_ids?: string[];
17
+ readonly election_ids?: string[];
18
+ readonly [x: string]: any;
19
+ constructor(committee: any);
20
+ static is(committee: any): committee is Committee;
21
+ }
@@ -0,0 +1,53 @@
1
+ export const designations = ["F1", "F2", "F3", "F24"];
2
+ export function is_committee_designation(designation) {
3
+ return designations.includes(designation);
4
+ }
5
+ export class Committee {
6
+ committee_id;
7
+ name;
8
+ url;
9
+ designation;
10
+ file_number;
11
+ principal_committee_ids;
12
+ authorized_committee_ids;
13
+ sponsor_committee_ids;
14
+ jfp_committee_ids;
15
+ jfr_committee_ids;
16
+ aff_committee_ids;
17
+ candidate_ids;
18
+ election_ids;
19
+ constructor(committee) {
20
+ if (!Committee.is(committee)) {
21
+ throw Error("Invalid input.");
22
+ }
23
+ this.committee_id = committee.committee_id;
24
+ this.name = committee.name;
25
+ this.url = committee.url;
26
+ this.designation = committee.designation;
27
+ this.file_number = committee.file_number;
28
+ this.principal_committee_ids = committee.principal_committee_ids;
29
+ this.authorized_committee_ids = committee.authorized_committee_ids;
30
+ this.sponsor_committee_ids = committee.sponsor_committee_ids;
31
+ this.jfp_committee_ids = committee.jfp_committee_ids;
32
+ this.jfr_committee_ids = committee.jfr_committee_ids;
33
+ this.aff_committee_ids = committee.aff_committee_ids;
34
+ this.candidate_ids = committee.candidate_ids;
35
+ this.election_ids = committee.election_ids;
36
+ }
37
+ static is(committee) {
38
+ return (committee !== undefined &&
39
+ typeof committee.committee_id === "string" &&
40
+ typeof committee.name === "string" &&
41
+ typeof committee.url === "string" &&
42
+ is_committee_designation(committee.designation) &&
43
+ typeof committee.file_number === "number" &&
44
+ (committee.principal_committee_ids === undefined || Array.isArray(committee.principal_committee_ids) && committee.principal_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
45
+ (committee.authorized_committee_ids === undefined || Array.isArray(committee.authorized_committee_ids) && committee.authorized_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
46
+ (committee.sponsor_committee_ids === undefined || Array.isArray(committee.sponsor_committee_ids) && committee.sponsor_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
47
+ (committee.jfp_committee_ids === undefined || Array.isArray(committee.jfp_committee_ids) && committee.jfp_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
48
+ (committee.jfr_committee_ids === undefined || Array.isArray(committee.jfr_committee_ids) && committee.jfr_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
49
+ (committee.aff_committee_ids === undefined || Array.isArray(committee.aff_committee_ids) && committee.aff_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
50
+ (committee.candidate_ids === undefined || Array.isArray(committee.candidate_ids) && committee.candidate_ids.every((committee_id) => typeof committee_id === "string")) &&
51
+ (committee.election_ids === undefined || Array.isArray(committee.election_ids) && committee.election_ids.every((committee_id) => typeof committee_id === "string")));
52
+ }
53
+ }
@@ -0,0 +1,18 @@
1
+ import { StateID } from "./State.js";
2
+ declare const office_ids: readonly ["H", "S"];
3
+ export type OfficeID = typeof office_ids[number];
4
+ export declare function is_office_id(office_id: any): office_id is OfficeID;
5
+ export type ElectionID = string;
6
+ export declare function is_election_id(election_id: any): election_id is ElectionID;
7
+ export declare class Election {
8
+ readonly election_id: ElectionID;
9
+ readonly name: string;
10
+ readonly office_id: OfficeID;
11
+ readonly state_id: StateID;
12
+ readonly district?: string;
13
+ readonly candidate_ids?: string[];
14
+ readonly committee_ids?: string[];
15
+ constructor(election: any);
16
+ static is(election: any): election is Election;
17
+ }
18
+ export {};
@@ -0,0 +1,48 @@
1
+ import { is_state_id } from "./State.js";
2
+ const office_ids = ["H", "S"];
3
+ export function is_office_id(office_id) {
4
+ return office_ids.includes(office_id);
5
+ }
6
+ export function is_election_id(election_id) {
7
+ const parts = election_id.split("-");
8
+ const year = Number(parts[0]);
9
+ const office_id = parts[1];
10
+ const state_id = parts[2];
11
+ const district = Number(parts[3]);
12
+ return ((parts.length === 4 && office_id === "H" || parts.length === 3) &&
13
+ Number.isInteger(year) && year > 1700 && year < 3000 &&
14
+ is_office_id(office_id) &&
15
+ is_state_id(state_id) &&
16
+ (office_id === "S" || Number.isInteger(district) && district < 100));
17
+ }
18
+ export class Election {
19
+ election_id;
20
+ name;
21
+ office_id;
22
+ state_id;
23
+ district;
24
+ candidate_ids;
25
+ committee_ids;
26
+ constructor(election) {
27
+ if (!Election.is(election)) {
28
+ throw Error("Invalid input.");
29
+ }
30
+ this.election_id = election.election_id;
31
+ this.name = election.name;
32
+ this.office_id = election.office_id;
33
+ this.state_id = election.state_id;
34
+ this.district = election.district;
35
+ this.candidate_ids = election.candidate_ids;
36
+ this.committee_ids = election.committee_ids;
37
+ }
38
+ static is(election) {
39
+ return (election !== undefined &&
40
+ is_election_id(election.election_id) &&
41
+ typeof election.name === "string" &&
42
+ is_office_id(election.office_id) &&
43
+ is_state_id(election.state_id) &&
44
+ (election.district === undefined && typeof election.district === "string") &&
45
+ (election.candidate_ids === undefined || Array.isArray(election.candidate_ids) && election.candidate_ids.every((candidate_id) => typeof candidate_id === "string")) &&
46
+ (election.committee_ids === undefined || Array.isArray(election.committee_ids) && election.committee_ids.every((committee_id) => typeof committee_id === "string")));
47
+ }
48
+ }
@@ -0,0 +1,21 @@
1
+ export interface ElectionsUtilsConfig {
2
+ region: string;
3
+ scraping_bee_api_key?: string;
4
+ xai_api_key?: string;
5
+ citizenportal_api_key?: string;
6
+ youtube_api_key?: string;
7
+ [key: string]: any;
8
+ }
9
+ export interface ElectionsConfig extends ElectionsUtilsConfig {
10
+ port: number;
11
+ api_url: string;
12
+ client_url: string;
13
+ auth_url: string;
14
+ cognito_user_pool_id: string;
15
+ cognito_client_id: string;
16
+ cognito_client_secret: string;
17
+ secret_key: string;
18
+ dynamodb_donations: string;
19
+ s3_bucket: string;
20
+ s3vectors_bucket: string;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const form_type_ids: readonly ["F1", "F2", "F3", "F24"];
2
+ export type FormTypeID = typeof form_type_ids[number];
3
+ export declare function is_form_type_id(form_type_id: any): form_type_id is FormTypeID;
4
+ export declare const long_form_type_ids: readonly ["F1N", "F1A", "F1T", "F2N", "F2A", "F2T", "F3N", "F3A", "F3T", "F24N", "F24A"];
5
+ export type LongFormTypeID = typeof long_form_type_ids[number];
6
+ export declare function is_long_form_type_id(long_form_type_id: any): long_form_type_id is LongFormTypeID;
@@ -0,0 +1,13 @@
1
+ export const form_type_ids = ["F1", "F2", "F3", "F24"];
2
+ export function is_form_type_id(form_type_id) {
3
+ return form_type_ids.includes(form_type_id);
4
+ }
5
+ export const long_form_type_ids = [
6
+ "F1N", "F1A", "F1T",
7
+ "F2N", "F2A", "F2T",
8
+ "F3N", "F3A", "F3T",
9
+ "F24N", "F24A"
10
+ ];
11
+ export function is_long_form_type_id(long_form_type_id) {
12
+ return long_form_type_ids.includes(long_form_type_id);
13
+ }
@@ -0,0 +1,8 @@
1
+ export declare const state_ids: readonly ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"];
2
+ export type StateID = typeof state_ids[number];
3
+ export declare function is_state_id(state_id: any): state_id is StateID;
4
+ export interface State {
5
+ state_id: StateID;
6
+ name: string;
7
+ }
8
+ export declare const states_by_state_id: Record<StateID, State>;
@@ -0,0 +1,206 @@
1
+ export const state_ids = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"];
2
+ export function is_state_id(state_id) {
3
+ return state_ids.includes(state_id);
4
+ }
5
+ export const states_by_state_id = {
6
+ AL: {
7
+ state_id: "AL",
8
+ name: "Alabama"
9
+ },
10
+ AK: {
11
+ state_id: "AK",
12
+ name: "Alaska"
13
+ },
14
+ AZ: {
15
+ state_id: "AZ",
16
+ name: "Arizona"
17
+ },
18
+ AR: {
19
+ state_id: "AR",
20
+ name: "Arkansas"
21
+ },
22
+ CA: {
23
+ state_id: "CA",
24
+ name: "California"
25
+ },
26
+ CO: {
27
+ state_id: "CO",
28
+ name: "Colorado"
29
+ },
30
+ CT: {
31
+ state_id: "CT",
32
+ name: "Connecticut"
33
+ },
34
+ DE: {
35
+ state_id: "DE",
36
+ name: "Delaware"
37
+ },
38
+ FL: {
39
+ state_id: "FL",
40
+ name: "Florida"
41
+ },
42
+ GA: {
43
+ state_id: "GA",
44
+ name: "Georgia"
45
+ },
46
+ HI: {
47
+ state_id: "HI",
48
+ name: "Hawaii"
49
+ },
50
+ ID: {
51
+ state_id: "ID",
52
+ name: "Idaho"
53
+ },
54
+ IL: {
55
+ state_id: "IL",
56
+ name: "Illinois"
57
+ },
58
+ IN: {
59
+ state_id: "IN",
60
+ name: "Indiana"
61
+ },
62
+ IA: {
63
+ state_id: "IA",
64
+ name: "Iowa"
65
+ },
66
+ KS: {
67
+ state_id: "KS",
68
+ name: "Kansas"
69
+ },
70
+ KY: {
71
+ state_id: "KY",
72
+ name: "Kentucky"
73
+ },
74
+ LA: {
75
+ state_id: "LA",
76
+ name: "Louisiana"
77
+ },
78
+ ME: {
79
+ state_id: "ME",
80
+ name: "Maine"
81
+ },
82
+ MD: {
83
+ state_id: "MD",
84
+ name: "Maryland"
85
+ },
86
+ MA: {
87
+ state_id: "MA",
88
+ name: "Massachusetts"
89
+ },
90
+ MI: {
91
+ state_id: "MI",
92
+ name: "Michigan"
93
+ },
94
+ MN: {
95
+ state_id: "MN",
96
+ name: "Minnesota"
97
+ },
98
+ MS: {
99
+ state_id: "MS",
100
+ name: "Mississippi"
101
+ },
102
+ MO: {
103
+ state_id: "MO",
104
+ name: "Missouri"
105
+ },
106
+ MT: {
107
+ state_id: "MT",
108
+ name: "Montana"
109
+ },
110
+ NE: {
111
+ state_id: "NE",
112
+ name: "Nebraska"
113
+ },
114
+ NV: {
115
+ state_id: "NV",
116
+ name: "Nevada"
117
+ },
118
+ NH: {
119
+ state_id: "NH",
120
+ name: "New Hampshire"
121
+ },
122
+ NJ: {
123
+ state_id: "NJ",
124
+ name: "New Jersey"
125
+ },
126
+ NM: {
127
+ state_id: "NM",
128
+ name: "New Mexico"
129
+ },
130
+ NY: {
131
+ state_id: "NY",
132
+ name: "New York"
133
+ },
134
+ NC: {
135
+ state_id: "NC",
136
+ name: "North Carolina"
137
+ },
138
+ ND: {
139
+ state_id: "ND",
140
+ name: "North Dakota"
141
+ },
142
+ OH: {
143
+ state_id: "OH",
144
+ name: "Ohio"
145
+ },
146
+ OK: {
147
+ state_id: "OK",
148
+ name: "Oklahoma"
149
+ },
150
+ OR: {
151
+ state_id: "OR",
152
+ name: "Oregon"
153
+ },
154
+ PA: {
155
+ state_id: "PA",
156
+ name: "Pennsylvania"
157
+ },
158
+ RI: {
159
+ state_id: "RI",
160
+ name: "Rhode Island"
161
+ },
162
+ SC: {
163
+ state_id: "SC",
164
+ name: "South Carolina"
165
+ },
166
+ SD: {
167
+ state_id: "SD",
168
+ name: "South Dakota"
169
+ },
170
+ TN: {
171
+ state_id: "TN",
172
+ name: "Tennessee"
173
+ },
174
+ TX: {
175
+ state_id: "TX",
176
+ name: "Texas"
177
+ },
178
+ UT: {
179
+ state_id: "UT",
180
+ name: "Utah"
181
+ },
182
+ VT: {
183
+ state_id: "VT",
184
+ name: "Vermont"
185
+ },
186
+ VA: {
187
+ state_id: "VA",
188
+ name: "Virginia"
189
+ },
190
+ WA: {
191
+ state_id: "WA",
192
+ name: "Washington"
193
+ },
194
+ WV: {
195
+ state_id: "WV",
196
+ name: "West Virginia"
197
+ },
198
+ WI: {
199
+ state_id: "WI",
200
+ name: "Wisconsin"
201
+ },
202
+ WY: {
203
+ state_id: "WY",
204
+ name: "Wyoming"
205
+ }
206
+ };
@@ -0,0 +1,12 @@
1
+ export declare class Tweet {
2
+ readonly tweet_id: string;
3
+ readonly username: string;
4
+ readonly url: string;
5
+ readonly tweet_time: string;
6
+ readonly tweet_content: string;
7
+ readonly quote?: string;
8
+ readonly html: string;
9
+ readonly text: string;
10
+ constructor(tweet: any);
11
+ static is(tweet: any): tweet is Tweet;
12
+ }
@@ -0,0 +1,34 @@
1
+ export class Tweet {
2
+ tweet_id;
3
+ username;
4
+ url;
5
+ tweet_time;
6
+ tweet_content;
7
+ quote;
8
+ html;
9
+ text;
10
+ constructor(tweet) {
11
+ if (!Tweet.is(tweet)) {
12
+ throw Error("Invalid input.");
13
+ }
14
+ this.tweet_id = tweet.tweet_id;
15
+ this.username = tweet.username;
16
+ this.url = tweet.url;
17
+ this.tweet_time = tweet.tweet_time;
18
+ this.tweet_content = tweet.tweet_content;
19
+ this.quote = tweet.quote;
20
+ this.html = tweet.html;
21
+ this.text = tweet.text;
22
+ }
23
+ static is(tweet) {
24
+ return (tweet !== undefined &&
25
+ typeof tweet.tweet_id === "string" &&
26
+ typeof tweet.username === "string" &&
27
+ typeof tweet.url === "string" &&
28
+ typeof tweet.tweet_time === "string" &&
29
+ typeof tweet.tweet_content === "string" &&
30
+ (tweet.quote === undefined || typeof tweet.quote === "string") &&
31
+ (typeof tweet.html === "string") &&
32
+ (typeof tweet.text === "string"));
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ import { LongFormTypeID } from "./FormTypeID.js";
2
+ export declare class User {
3
+ readonly user_id: string;
4
+ readonly admin: boolean;
5
+ readonly premium: boolean;
6
+ readonly email: string;
7
+ readonly email_settings: Record<LongFormTypeID, boolean>;
8
+ constructor(user: any);
9
+ static is(user: any): user is User;
10
+ }
@@ -0,0 +1,29 @@
1
+ import { is_long_form_type_id } from "./FormTypeID.js";
2
+ export class User {
3
+ user_id;
4
+ admin;
5
+ premium;
6
+ email;
7
+ email_settings;
8
+ // readonly [x : string] : any
9
+ constructor(user) {
10
+ if (!User.is(user)) {
11
+ throw Error("Invalid Input.");
12
+ }
13
+ this.user_id = user.user_id;
14
+ this.admin = user.admin;
15
+ this.premium = user.premium;
16
+ this.email = user.email;
17
+ this.email_settings = user.email_settings;
18
+ }
19
+ static is(user) {
20
+ return (user !== undefined &&
21
+ typeof user.user_id === "string" &&
22
+ typeof user.admin === "boolean" &&
23
+ typeof user.premium === "boolean" &&
24
+ typeof user.email === "string" &&
25
+ Array.isArray(user.scout_ids) &&
26
+ typeof user.email_settings === "object" &&
27
+ Object.entries(user.email_settings).every(([key, value]) => is_long_form_type_id(key) && typeof value === "boolean"));
28
+ }
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elections-types",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {