@goodparty_org/sdk 1.9.0 → 1.11.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/dist/index.d.mts CHANGED
@@ -1,223 +1,7 @@
1
- import { PaginatedList, SIGN_UP_MODE, ReadUserOutput, UpdatePasswordInput } from '@goodparty_org/contracts';
2
- export { PaginatedList, PaginationMeta, ReadUserOutput, UpdatePasswordInput, ReadUserOutput as User } from '@goodparty_org/contracts';
1
+ import { ReadCampaignOutput, ListCampaignsPagination, PaginatedList, UpdateCampaignM2MInput, PaginationOptions, ListUsersPagination, ReadUserOutput, UpdateUserInput, UpdatePasswordInput, CampaignTier as CampaignTier$1, UserRole as UserRole$1, WhyBrowsing as WhyBrowsing$1 } from '@goodparty_org/contracts';
2
+ export { AiChatMessage, AiContentData, AiContentGenerationStatus, AiContentInputValues, BALLOT_READY_POSITION_LEVEL_VALUES, BallotReadyPositionLevel, CAMPAIGN_CREATED_BY_VALUES, CAMPAIGN_LAUNCH_STATUS_VALUES, CAMPAIGN_STATUS_VALUES, CAMPAIGN_TIER_VALUES, ReadCampaignOutput as Campaign, CampaignAiContent, CampaignCreatedBy, CampaignData, CampaignDetails, CampaignFinance, CampaignLaunchStatus, CampaignPlan, CampaignPlanStatus, CampaignStatus, CustomIssue, CustomVoterFile, ELECTION_LEVEL_VALUES, ElectionLevel, GENERATION_STATUS_VALUES, GenerationStatus, GeoLocation, HubSpotUpdates, ListCampaignsPagination, ListUsersPagination, ONBOARDING_STEP_VALUES, OnboardingStep, Opponent, PaginatedList, PaginationMeta, PaginationOptions, ReadCampaignOutput, ReadUserOutput, USER_ROLE_VALUES, UpdateCampaignM2MInput, UpdatePasswordInput, UpdateUserInput, ReadUserOutput as User, UserMetaData, VoterGoals, WHY_BROWSING_VALUES } from '@goodparty_org/contracts';
3
3
  import { FetchOptions } from 'ofetch';
4
4
 
5
- declare class SdkError extends Error {
6
- readonly status: number;
7
- readonly response?: Response;
8
- constructor(status: number, message: string, response?: Response);
9
- }
10
- type PaginationOptions = {
11
- offset?: number;
12
- limit?: number;
13
- sortBy?: string;
14
- sortOrder?: 'asc' | 'desc';
15
- };
16
-
17
- declare enum CampaignTier {
18
- WIN = "WIN",
19
- LOSE = "LOSE",
20
- TOSSUP = "TOSSUP"
21
- }
22
- declare enum BallotReadyPositionLevel {
23
- CITY = "CITY",
24
- COUNTY = "COUNTY",
25
- FEDERAL = "FEDERAL",
26
- LOCAL = "LOCAL",
27
- REGIONAL = "REGIONAL",
28
- STATE = "STATE",
29
- TOWNSHIP = "TOWNSHIP"
30
- }
31
- declare enum ElectionLevel {
32
- state = "state",
33
- county = "county",
34
- federal = "federal",
35
- city = "city"
36
- }
37
- declare enum CampaignCreatedBy {
38
- ADMIN = "admin"
39
- }
40
- declare enum CampaignLaunchStatus {
41
- launched = "launched"
42
- }
43
- declare enum OnboardingStep {
44
- complete = "onboarding-complete",
45
- registration = "registration"
46
- }
47
- declare enum GenerationStatus {
48
- processing = "processing",
49
- completed = "completed"
50
- }
51
- type VoterGoals = {
52
- doorKnocking?: number;
53
- calls?: number;
54
- digital?: number;
55
- directMail?: number;
56
- digitalAds?: number;
57
- text?: number;
58
- events?: number;
59
- yardSigns?: number;
60
- robocall?: number;
61
- phoneBanking?: number;
62
- socialMedia?: number;
63
- };
64
- type CustomVoterFile = {
65
- name: string;
66
- channel?: string;
67
- purpose?: string;
68
- filters: string[];
69
- createdAt: string;
70
- };
71
- type AiChatMessage = {
72
- role: 'user' | 'system' | 'assistant';
73
- content: string;
74
- createdAt?: number;
75
- id?: string;
76
- usage?: number;
77
- };
78
- type AiContentInputValues = Record<string, string | boolean | number | undefined>;
79
- type AiContentGenerationStatus = {
80
- status: GenerationStatus;
81
- createdAt: number;
82
- prompt?: string;
83
- existingChat?: AiChatMessage[];
84
- inputValues?: AiContentInputValues;
85
- };
86
- type AiContentData = {
87
- name: string;
88
- content: string;
89
- updatedAt: number;
90
- inputValues?: AiContentInputValues;
91
- };
92
- type GeoLocation = {
93
- geoHash?: string;
94
- lng?: number;
95
- lat?: number;
96
- };
97
- type CustomIssue = {
98
- title: string;
99
- position: string;
100
- };
101
- type Opponent = {
102
- name: string;
103
- party: string;
104
- description: string;
105
- };
106
- type HubSpotUpdates = Partial<Record<string, string>>;
107
- type CampaignDetails = {
108
- state?: string;
109
- ballotLevel?: BallotReadyPositionLevel;
110
- electionDate?: string;
111
- primaryElectionDate?: string;
112
- zip?: string | null;
113
- knowRun?: 'yes' | null;
114
- runForOffice?: 'yes' | 'no' | null;
115
- pledged?: boolean;
116
- isProUpdatedAt?: number;
117
- customIssues?: CustomIssue[];
118
- runningAgainst?: Opponent[];
119
- geoLocation?: GeoLocation;
120
- geoLocationFailed?: boolean;
121
- city?: string | null;
122
- county?: string | null;
123
- normalizedOffice?: string | null;
124
- otherOffice?: string;
125
- office?: string;
126
- party?: string;
127
- otherParty?: string;
128
- district?: string;
129
- raceId?: string;
130
- level?: ElectionLevel | null;
131
- noNormalizedOffice?: boolean;
132
- website?: string;
133
- pastExperience?: string | Record<string, string>;
134
- occupation?: string;
135
- funFact?: string;
136
- campaignCommittee?: string;
137
- statementName?: string;
138
- subscriptionId?: string | null;
139
- endOfElectionSubscriptionCanceled?: boolean;
140
- subscriptionCanceledAt?: number | null;
141
- subscriptionCancelAt?: number | null;
142
- filingPeriodsStart?: string | null;
143
- filingPeriodsEnd?: string | null;
144
- officeTermLength?: string;
145
- partisanType?: string;
146
- priorElectionDates?: string[];
147
- positionId?: string | null;
148
- electionId?: string | null;
149
- tier?: string;
150
- einNumber?: string | null;
151
- einSupportingDocument?: string | null;
152
- wonGeneral?: boolean;
153
- };
154
- type CampaignData = {
155
- createdBy?: CampaignCreatedBy;
156
- slug?: string;
157
- hubSpotUpdates?: HubSpotUpdates;
158
- currentStep?: OnboardingStep;
159
- launchStatus?: CampaignLaunchStatus;
160
- lastVisited?: number;
161
- claimProfile?: string;
162
- customVoterFiles?: CustomVoterFile[];
163
- reportedVoterGoals?: VoterGoals;
164
- textCampaignCount?: number;
165
- lastStepDate?: string;
166
- adminUserEmail?: string;
167
- hubspotId?: string;
168
- name?: string;
169
- };
170
- type CampaignAiContent = {
171
- generationStatus?: Record<string, AiContentGenerationStatus>;
172
- campaignPlanAttempts?: Record<string, number>;
173
- } & Record<string, AiContentData>;
174
- type Campaign = {
175
- id: number;
176
- createdAt: string;
177
- updatedAt: string;
178
- slug: string;
179
- isActive: boolean;
180
- isVerified?: boolean | null;
181
- isPro?: boolean | null;
182
- isDemo: boolean;
183
- didWin?: boolean | null;
184
- dateVerified?: string | null;
185
- tier?: CampaignTier | null;
186
- formattedAddress?: string | null;
187
- placeId?: string | null;
188
- data: CampaignData;
189
- details: CampaignDetails;
190
- aiContent: CampaignAiContent;
191
- userId: number;
192
- canDownloadFederal: boolean;
193
- completedTaskIds: string[];
194
- hasFreeTextsOffer: boolean;
195
- freeTextsOfferRedeemedAt?: string | null;
196
- };
197
- type ListCampaignsOptions = PaginationOptions & {
198
- userId?: number;
199
- slug?: string;
200
- };
201
- type UpdateCampaignInput = {
202
- slug?: string;
203
- isActive?: boolean;
204
- isVerified?: boolean | null;
205
- isPro?: boolean | null;
206
- isDemo?: boolean;
207
- didWin?: boolean | null;
208
- dateVerified?: string | null;
209
- tier?: CampaignTier | null;
210
- formattedAddress?: string | null;
211
- placeId?: string | null;
212
- data?: CampaignData;
213
- details?: CampaignDetails;
214
- aiContent?: CampaignAiContent;
215
- canDownloadFederal?: boolean;
216
- completedTaskIds?: string[];
217
- hasFreeTextsOffer?: boolean;
218
- freeTextsOfferRedeemedAt?: string | null;
219
- };
220
-
221
5
  type OfetchRequestBody = FetchOptions<'json'>['body'];
222
6
  declare class HttpClient {
223
7
  private baseUrl;
@@ -238,9 +22,9 @@ declare abstract class BaseResource {
238
22
 
239
23
  declare class CampaignsResource extends BaseResource {
240
24
  protected readonly resourceBasePath = "/campaigns";
241
- get: (id: number) => Promise<Campaign>;
242
- list: (options?: ListCampaignsOptions) => Promise<PaginatedList<Campaign>>;
243
- update: (id: number, input: UpdateCampaignInput) => Promise<Campaign>;
25
+ get: (id: number) => Promise<ReadCampaignOutput>;
26
+ list: (options?: ListCampaignsPagination) => Promise<PaginatedList<ReadCampaignOutput>>;
27
+ update: (id: number, input: UpdateCampaignM2MInput) => Promise<ReadCampaignOutput>;
244
28
  }
245
29
 
246
30
  type ElectedOffice = {
@@ -345,53 +129,9 @@ declare class PathsToVictoryResource extends BaseResource {
345
129
  update: (id: number, input: UpdatePathToVictoryInput) => Promise<PathToVictory>;
346
130
  }
347
131
 
348
- declare enum UserRole {
349
- admin = "admin",
350
- sales = "sales",
351
- candidate = "candidate",
352
- campaignManager = "campaignManager",
353
- demo = "demo"
354
- }
355
- declare enum WhyBrowsing {
356
- considering = "considering",
357
- learning = "learning",
358
- test = "test",
359
- else = "else"
360
- }
361
- type UserMetaData = {
362
- customerId?: string;
363
- checkoutSessionId?: string | null;
364
- accountType?: string | null;
365
- lastVisited?: number;
366
- sessionCount?: number;
367
- isDeleted?: boolean;
368
- fsUserId?: string;
369
- whyBrowsing?: WhyBrowsing | null;
370
- hubspotId?: string;
371
- profile_updated_count?: number;
372
- textNotifications?: boolean;
373
- } | null;
374
- type ListUsersOptions = PaginationOptions & {
375
- firstName?: string;
376
- lastName?: string;
377
- email?: string;
378
- };
379
- type UpdateUserInput = {
380
- firstName?: string;
381
- lastName?: string;
382
- email?: string;
383
- name?: string;
384
- zip?: string;
385
- phone?: string;
386
- roles?: UserRole[];
387
- signUpMode?: SIGN_UP_MODE;
388
- allowTexts?: boolean;
389
- metaData?: UserMetaData;
390
- };
391
-
392
132
  declare class UsersResource extends BaseResource {
393
133
  protected readonly resourceBasePath = "/users";
394
- list: (options?: ListUsersOptions) => Promise<PaginatedList<ReadUserOutput>>;
134
+ list: (options?: ListUsersPagination) => Promise<PaginatedList<ReadUserOutput>>;
395
135
  get: (id: number) => Promise<ReadUserOutput>;
396
136
  update: (id: number, input: UpdateUserInput) => Promise<ReadUserOutput>;
397
137
  delete: (id: number) => Promise<void>;
@@ -413,4 +153,20 @@ declare class GoodPartyClient {
413
153
  destroy: () => void;
414
154
  }
415
155
 
416
- export { type AiChatMessage, type AiContentData, type AiContentGenerationStatus, type AiContentInputValues, BallotReadyPositionLevel, type Campaign, type CampaignAiContent, CampaignCreatedBy, type CampaignData, type CampaignDetails, CampaignLaunchStatus, CampaignTier, type CustomIssue, type CustomVoterFile, type ElectedOffice, ElectionLevel, GenerationStatus, type GeoLocation, GoodPartyClient, type GoodPartyClientConfig, type HubSpotUpdates, type ListCampaignsOptions, type ListElectedOfficesOptions, type ListPathsToVictoryOptions, type ListUsersOptions, OnboardingStep, type Opponent, P2VSource, P2VStatus, type PaginationOptions, type PathToVictory, type PathToVictoryData, SdkError, type UpdateCampaignInput, type UpdateElectedOfficeInput, type UpdatePathToVictoryInput, type UpdateUserInput, type UserMetaData, UserRole, type ViabilityScore, type VoterGoals, WhyBrowsing };
156
+ declare class SdkError extends Error {
157
+ readonly status: number;
158
+ readonly response?: Response;
159
+ constructor(status: number, message: string, response?: Response);
160
+ }
161
+
162
+ type EnumObject<T extends readonly string[]> = {
163
+ [K in T[number]]: K;
164
+ };
165
+ type UserRole = UserRole$1;
166
+ declare const UserRole: EnumObject<readonly ["admin", "sales", "candidate", "campaignManager", "demo"]>;
167
+ type WhyBrowsing = WhyBrowsing$1;
168
+ declare const WhyBrowsing: EnumObject<readonly ["considering", "learning", "test", "else"]>;
169
+ type CampaignTier = CampaignTier$1;
170
+ declare const CampaignTier: EnumObject<readonly ["WIN", "LOSE", "TOSSUP"]>;
171
+
172
+ export { CampaignTier, type ElectedOffice, GoodPartyClient, type GoodPartyClientConfig, type ListElectedOfficesOptions, type ListPathsToVictoryOptions, P2VSource, P2VStatus, type PathToVictory, type PathToVictoryData, SdkError, type UpdateElectedOfficeInput, type UpdatePathToVictoryInput, UserRole, type ViabilityScore, WhyBrowsing };
package/dist/index.d.ts CHANGED
@@ -1,223 +1,7 @@
1
- import { PaginatedList, SIGN_UP_MODE, ReadUserOutput, UpdatePasswordInput } from '@goodparty_org/contracts';
2
- export { PaginatedList, PaginationMeta, ReadUserOutput, UpdatePasswordInput, ReadUserOutput as User } from '@goodparty_org/contracts';
1
+ import { ReadCampaignOutput, ListCampaignsPagination, PaginatedList, UpdateCampaignM2MInput, PaginationOptions, ListUsersPagination, ReadUserOutput, UpdateUserInput, UpdatePasswordInput, CampaignTier as CampaignTier$1, UserRole as UserRole$1, WhyBrowsing as WhyBrowsing$1 } from '@goodparty_org/contracts';
2
+ export { AiChatMessage, AiContentData, AiContentGenerationStatus, AiContentInputValues, BALLOT_READY_POSITION_LEVEL_VALUES, BallotReadyPositionLevel, CAMPAIGN_CREATED_BY_VALUES, CAMPAIGN_LAUNCH_STATUS_VALUES, CAMPAIGN_STATUS_VALUES, CAMPAIGN_TIER_VALUES, ReadCampaignOutput as Campaign, CampaignAiContent, CampaignCreatedBy, CampaignData, CampaignDetails, CampaignFinance, CampaignLaunchStatus, CampaignPlan, CampaignPlanStatus, CampaignStatus, CustomIssue, CustomVoterFile, ELECTION_LEVEL_VALUES, ElectionLevel, GENERATION_STATUS_VALUES, GenerationStatus, GeoLocation, HubSpotUpdates, ListCampaignsPagination, ListUsersPagination, ONBOARDING_STEP_VALUES, OnboardingStep, Opponent, PaginatedList, PaginationMeta, PaginationOptions, ReadCampaignOutput, ReadUserOutput, USER_ROLE_VALUES, UpdateCampaignM2MInput, UpdatePasswordInput, UpdateUserInput, ReadUserOutput as User, UserMetaData, VoterGoals, WHY_BROWSING_VALUES } from '@goodparty_org/contracts';
3
3
  import { FetchOptions } from 'ofetch';
4
4
 
5
- declare class SdkError extends Error {
6
- readonly status: number;
7
- readonly response?: Response;
8
- constructor(status: number, message: string, response?: Response);
9
- }
10
- type PaginationOptions = {
11
- offset?: number;
12
- limit?: number;
13
- sortBy?: string;
14
- sortOrder?: 'asc' | 'desc';
15
- };
16
-
17
- declare enum CampaignTier {
18
- WIN = "WIN",
19
- LOSE = "LOSE",
20
- TOSSUP = "TOSSUP"
21
- }
22
- declare enum BallotReadyPositionLevel {
23
- CITY = "CITY",
24
- COUNTY = "COUNTY",
25
- FEDERAL = "FEDERAL",
26
- LOCAL = "LOCAL",
27
- REGIONAL = "REGIONAL",
28
- STATE = "STATE",
29
- TOWNSHIP = "TOWNSHIP"
30
- }
31
- declare enum ElectionLevel {
32
- state = "state",
33
- county = "county",
34
- federal = "federal",
35
- city = "city"
36
- }
37
- declare enum CampaignCreatedBy {
38
- ADMIN = "admin"
39
- }
40
- declare enum CampaignLaunchStatus {
41
- launched = "launched"
42
- }
43
- declare enum OnboardingStep {
44
- complete = "onboarding-complete",
45
- registration = "registration"
46
- }
47
- declare enum GenerationStatus {
48
- processing = "processing",
49
- completed = "completed"
50
- }
51
- type VoterGoals = {
52
- doorKnocking?: number;
53
- calls?: number;
54
- digital?: number;
55
- directMail?: number;
56
- digitalAds?: number;
57
- text?: number;
58
- events?: number;
59
- yardSigns?: number;
60
- robocall?: number;
61
- phoneBanking?: number;
62
- socialMedia?: number;
63
- };
64
- type CustomVoterFile = {
65
- name: string;
66
- channel?: string;
67
- purpose?: string;
68
- filters: string[];
69
- createdAt: string;
70
- };
71
- type AiChatMessage = {
72
- role: 'user' | 'system' | 'assistant';
73
- content: string;
74
- createdAt?: number;
75
- id?: string;
76
- usage?: number;
77
- };
78
- type AiContentInputValues = Record<string, string | boolean | number | undefined>;
79
- type AiContentGenerationStatus = {
80
- status: GenerationStatus;
81
- createdAt: number;
82
- prompt?: string;
83
- existingChat?: AiChatMessage[];
84
- inputValues?: AiContentInputValues;
85
- };
86
- type AiContentData = {
87
- name: string;
88
- content: string;
89
- updatedAt: number;
90
- inputValues?: AiContentInputValues;
91
- };
92
- type GeoLocation = {
93
- geoHash?: string;
94
- lng?: number;
95
- lat?: number;
96
- };
97
- type CustomIssue = {
98
- title: string;
99
- position: string;
100
- };
101
- type Opponent = {
102
- name: string;
103
- party: string;
104
- description: string;
105
- };
106
- type HubSpotUpdates = Partial<Record<string, string>>;
107
- type CampaignDetails = {
108
- state?: string;
109
- ballotLevel?: BallotReadyPositionLevel;
110
- electionDate?: string;
111
- primaryElectionDate?: string;
112
- zip?: string | null;
113
- knowRun?: 'yes' | null;
114
- runForOffice?: 'yes' | 'no' | null;
115
- pledged?: boolean;
116
- isProUpdatedAt?: number;
117
- customIssues?: CustomIssue[];
118
- runningAgainst?: Opponent[];
119
- geoLocation?: GeoLocation;
120
- geoLocationFailed?: boolean;
121
- city?: string | null;
122
- county?: string | null;
123
- normalizedOffice?: string | null;
124
- otherOffice?: string;
125
- office?: string;
126
- party?: string;
127
- otherParty?: string;
128
- district?: string;
129
- raceId?: string;
130
- level?: ElectionLevel | null;
131
- noNormalizedOffice?: boolean;
132
- website?: string;
133
- pastExperience?: string | Record<string, string>;
134
- occupation?: string;
135
- funFact?: string;
136
- campaignCommittee?: string;
137
- statementName?: string;
138
- subscriptionId?: string | null;
139
- endOfElectionSubscriptionCanceled?: boolean;
140
- subscriptionCanceledAt?: number | null;
141
- subscriptionCancelAt?: number | null;
142
- filingPeriodsStart?: string | null;
143
- filingPeriodsEnd?: string | null;
144
- officeTermLength?: string;
145
- partisanType?: string;
146
- priorElectionDates?: string[];
147
- positionId?: string | null;
148
- electionId?: string | null;
149
- tier?: string;
150
- einNumber?: string | null;
151
- einSupportingDocument?: string | null;
152
- wonGeneral?: boolean;
153
- };
154
- type CampaignData = {
155
- createdBy?: CampaignCreatedBy;
156
- slug?: string;
157
- hubSpotUpdates?: HubSpotUpdates;
158
- currentStep?: OnboardingStep;
159
- launchStatus?: CampaignLaunchStatus;
160
- lastVisited?: number;
161
- claimProfile?: string;
162
- customVoterFiles?: CustomVoterFile[];
163
- reportedVoterGoals?: VoterGoals;
164
- textCampaignCount?: number;
165
- lastStepDate?: string;
166
- adminUserEmail?: string;
167
- hubspotId?: string;
168
- name?: string;
169
- };
170
- type CampaignAiContent = {
171
- generationStatus?: Record<string, AiContentGenerationStatus>;
172
- campaignPlanAttempts?: Record<string, number>;
173
- } & Record<string, AiContentData>;
174
- type Campaign = {
175
- id: number;
176
- createdAt: string;
177
- updatedAt: string;
178
- slug: string;
179
- isActive: boolean;
180
- isVerified?: boolean | null;
181
- isPro?: boolean | null;
182
- isDemo: boolean;
183
- didWin?: boolean | null;
184
- dateVerified?: string | null;
185
- tier?: CampaignTier | null;
186
- formattedAddress?: string | null;
187
- placeId?: string | null;
188
- data: CampaignData;
189
- details: CampaignDetails;
190
- aiContent: CampaignAiContent;
191
- userId: number;
192
- canDownloadFederal: boolean;
193
- completedTaskIds: string[];
194
- hasFreeTextsOffer: boolean;
195
- freeTextsOfferRedeemedAt?: string | null;
196
- };
197
- type ListCampaignsOptions = PaginationOptions & {
198
- userId?: number;
199
- slug?: string;
200
- };
201
- type UpdateCampaignInput = {
202
- slug?: string;
203
- isActive?: boolean;
204
- isVerified?: boolean | null;
205
- isPro?: boolean | null;
206
- isDemo?: boolean;
207
- didWin?: boolean | null;
208
- dateVerified?: string | null;
209
- tier?: CampaignTier | null;
210
- formattedAddress?: string | null;
211
- placeId?: string | null;
212
- data?: CampaignData;
213
- details?: CampaignDetails;
214
- aiContent?: CampaignAiContent;
215
- canDownloadFederal?: boolean;
216
- completedTaskIds?: string[];
217
- hasFreeTextsOffer?: boolean;
218
- freeTextsOfferRedeemedAt?: string | null;
219
- };
220
-
221
5
  type OfetchRequestBody = FetchOptions<'json'>['body'];
222
6
  declare class HttpClient {
223
7
  private baseUrl;
@@ -238,9 +22,9 @@ declare abstract class BaseResource {
238
22
 
239
23
  declare class CampaignsResource extends BaseResource {
240
24
  protected readonly resourceBasePath = "/campaigns";
241
- get: (id: number) => Promise<Campaign>;
242
- list: (options?: ListCampaignsOptions) => Promise<PaginatedList<Campaign>>;
243
- update: (id: number, input: UpdateCampaignInput) => Promise<Campaign>;
25
+ get: (id: number) => Promise<ReadCampaignOutput>;
26
+ list: (options?: ListCampaignsPagination) => Promise<PaginatedList<ReadCampaignOutput>>;
27
+ update: (id: number, input: UpdateCampaignM2MInput) => Promise<ReadCampaignOutput>;
244
28
  }
245
29
 
246
30
  type ElectedOffice = {
@@ -345,53 +129,9 @@ declare class PathsToVictoryResource extends BaseResource {
345
129
  update: (id: number, input: UpdatePathToVictoryInput) => Promise<PathToVictory>;
346
130
  }
347
131
 
348
- declare enum UserRole {
349
- admin = "admin",
350
- sales = "sales",
351
- candidate = "candidate",
352
- campaignManager = "campaignManager",
353
- demo = "demo"
354
- }
355
- declare enum WhyBrowsing {
356
- considering = "considering",
357
- learning = "learning",
358
- test = "test",
359
- else = "else"
360
- }
361
- type UserMetaData = {
362
- customerId?: string;
363
- checkoutSessionId?: string | null;
364
- accountType?: string | null;
365
- lastVisited?: number;
366
- sessionCount?: number;
367
- isDeleted?: boolean;
368
- fsUserId?: string;
369
- whyBrowsing?: WhyBrowsing | null;
370
- hubspotId?: string;
371
- profile_updated_count?: number;
372
- textNotifications?: boolean;
373
- } | null;
374
- type ListUsersOptions = PaginationOptions & {
375
- firstName?: string;
376
- lastName?: string;
377
- email?: string;
378
- };
379
- type UpdateUserInput = {
380
- firstName?: string;
381
- lastName?: string;
382
- email?: string;
383
- name?: string;
384
- zip?: string;
385
- phone?: string;
386
- roles?: UserRole[];
387
- signUpMode?: SIGN_UP_MODE;
388
- allowTexts?: boolean;
389
- metaData?: UserMetaData;
390
- };
391
-
392
132
  declare class UsersResource extends BaseResource {
393
133
  protected readonly resourceBasePath = "/users";
394
- list: (options?: ListUsersOptions) => Promise<PaginatedList<ReadUserOutput>>;
134
+ list: (options?: ListUsersPagination) => Promise<PaginatedList<ReadUserOutput>>;
395
135
  get: (id: number) => Promise<ReadUserOutput>;
396
136
  update: (id: number, input: UpdateUserInput) => Promise<ReadUserOutput>;
397
137
  delete: (id: number) => Promise<void>;
@@ -413,4 +153,20 @@ declare class GoodPartyClient {
413
153
  destroy: () => void;
414
154
  }
415
155
 
416
- export { type AiChatMessage, type AiContentData, type AiContentGenerationStatus, type AiContentInputValues, BallotReadyPositionLevel, type Campaign, type CampaignAiContent, CampaignCreatedBy, type CampaignData, type CampaignDetails, CampaignLaunchStatus, CampaignTier, type CustomIssue, type CustomVoterFile, type ElectedOffice, ElectionLevel, GenerationStatus, type GeoLocation, GoodPartyClient, type GoodPartyClientConfig, type HubSpotUpdates, type ListCampaignsOptions, type ListElectedOfficesOptions, type ListPathsToVictoryOptions, type ListUsersOptions, OnboardingStep, type Opponent, P2VSource, P2VStatus, type PaginationOptions, type PathToVictory, type PathToVictoryData, SdkError, type UpdateCampaignInput, type UpdateElectedOfficeInput, type UpdatePathToVictoryInput, type UpdateUserInput, type UserMetaData, UserRole, type ViabilityScore, type VoterGoals, WhyBrowsing };
156
+ declare class SdkError extends Error {
157
+ readonly status: number;
158
+ readonly response?: Response;
159
+ constructor(status: number, message: string, response?: Response);
160
+ }
161
+
162
+ type EnumObject<T extends readonly string[]> = {
163
+ [K in T[number]]: K;
164
+ };
165
+ type UserRole = UserRole$1;
166
+ declare const UserRole: EnumObject<readonly ["admin", "sales", "candidate", "campaignManager", "demo"]>;
167
+ type WhyBrowsing = WhyBrowsing$1;
168
+ declare const WhyBrowsing: EnumObject<readonly ["considering", "learning", "test", "else"]>;
169
+ type CampaignTier = CampaignTier$1;
170
+ declare const CampaignTier: EnumObject<readonly ["WIN", "LOSE", "TOSSUP"]>;
171
+
172
+ export { CampaignTier, type ElectedOffice, GoodPartyClient, type GoodPartyClientConfig, type ListElectedOfficesOptions, type ListPathsToVictoryOptions, P2VSource, P2VStatus, type PathToVictory, type PathToVictoryData, SdkError, type UpdateElectedOfficeInput, type UpdatePathToVictoryInput, UserRole, type ViabilityScore, WhyBrowsing };
package/dist/index.js CHANGED
@@ -20,18 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- BallotReadyPositionLevel: () => BallotReadyPositionLevel,
24
- CampaignCreatedBy: () => CampaignCreatedBy,
25
- CampaignLaunchStatus: () => CampaignLaunchStatus,
23
+ BALLOT_READY_POSITION_LEVEL_VALUES: () => import_contracts2.BALLOT_READY_POSITION_LEVEL_VALUES,
24
+ BallotReadyPositionLevel: () => import_contracts2.BallotReadyPositionLevel,
25
+ CAMPAIGN_CREATED_BY_VALUES: () => import_contracts2.CAMPAIGN_CREATED_BY_VALUES,
26
+ CAMPAIGN_LAUNCH_STATUS_VALUES: () => import_contracts2.CAMPAIGN_LAUNCH_STATUS_VALUES,
27
+ CAMPAIGN_STATUS_VALUES: () => import_contracts2.CAMPAIGN_STATUS_VALUES,
28
+ CAMPAIGN_TIER_VALUES: () => import_contracts2.CAMPAIGN_TIER_VALUES,
29
+ CampaignCreatedBy: () => import_contracts2.CampaignCreatedBy,
30
+ CampaignLaunchStatus: () => import_contracts2.CampaignLaunchStatus,
31
+ CampaignStatus: () => import_contracts2.CampaignStatus,
26
32
  CampaignTier: () => CampaignTier,
27
- ElectionLevel: () => ElectionLevel,
28
- GenerationStatus: () => GenerationStatus,
33
+ ELECTION_LEVEL_VALUES: () => import_contracts2.ELECTION_LEVEL_VALUES,
34
+ ElectionLevel: () => import_contracts2.ElectionLevel,
35
+ GENERATION_STATUS_VALUES: () => import_contracts2.GENERATION_STATUS_VALUES,
36
+ GenerationStatus: () => import_contracts2.GenerationStatus,
29
37
  GoodPartyClient: () => GoodPartyClient,
30
- OnboardingStep: () => OnboardingStep,
38
+ ONBOARDING_STEP_VALUES: () => import_contracts2.ONBOARDING_STEP_VALUES,
39
+ OnboardingStep: () => import_contracts2.OnboardingStep,
31
40
  P2VSource: () => P2VSource,
32
41
  P2VStatus: () => P2VStatus,
33
42
  SdkError: () => SdkError,
43
+ USER_ROLE_VALUES: () => import_contracts2.USER_ROLE_VALUES,
34
44
  UserRole: () => UserRole,
45
+ WHY_BROWSING_VALUES: () => import_contracts2.WHY_BROWSING_VALUES,
35
46
  WhyBrowsing: () => WhyBrowsing
36
47
  });
37
48
  module.exports = __toCommonJS(index_exports);
@@ -250,66 +261,15 @@ var GoodPartyClient = class _GoodPartyClient {
250
261
  };
251
262
  };
252
263
 
253
- // src/types/user.ts
254
- var import_contracts = require("@goodparty_org/contracts");
255
- var UserRole = /* @__PURE__ */ ((UserRole2) => {
256
- UserRole2["admin"] = "admin";
257
- UserRole2["sales"] = "sales";
258
- UserRole2["candidate"] = "candidate";
259
- UserRole2["campaignManager"] = "campaignManager";
260
- UserRole2["demo"] = "demo";
261
- return UserRole2;
262
- })(UserRole || {});
263
- var WhyBrowsing = /* @__PURE__ */ ((WhyBrowsing2) => {
264
- WhyBrowsing2["considering"] = "considering";
265
- WhyBrowsing2["learning"] = "learning";
266
- WhyBrowsing2["test"] = "test";
267
- WhyBrowsing2["else"] = "else";
268
- return WhyBrowsing2;
269
- })(WhyBrowsing || {});
264
+ // src/index.ts
265
+ var import_contracts2 = require("@goodparty_org/contracts");
270
266
 
271
- // src/types/campaign.ts
272
- var CampaignTier = /* @__PURE__ */ ((CampaignTier2) => {
273
- CampaignTier2["WIN"] = "WIN";
274
- CampaignTier2["LOSE"] = "LOSE";
275
- CampaignTier2["TOSSUP"] = "TOSSUP";
276
- return CampaignTier2;
277
- })(CampaignTier || {});
278
- var BallotReadyPositionLevel = /* @__PURE__ */ ((BallotReadyPositionLevel2) => {
279
- BallotReadyPositionLevel2["CITY"] = "CITY";
280
- BallotReadyPositionLevel2["COUNTY"] = "COUNTY";
281
- BallotReadyPositionLevel2["FEDERAL"] = "FEDERAL";
282
- BallotReadyPositionLevel2["LOCAL"] = "LOCAL";
283
- BallotReadyPositionLevel2["REGIONAL"] = "REGIONAL";
284
- BallotReadyPositionLevel2["STATE"] = "STATE";
285
- BallotReadyPositionLevel2["TOWNSHIP"] = "TOWNSHIP";
286
- return BallotReadyPositionLevel2;
287
- })(BallotReadyPositionLevel || {});
288
- var ElectionLevel = /* @__PURE__ */ ((ElectionLevel2) => {
289
- ElectionLevel2["state"] = "state";
290
- ElectionLevel2["county"] = "county";
291
- ElectionLevel2["federal"] = "federal";
292
- ElectionLevel2["city"] = "city";
293
- return ElectionLevel2;
294
- })(ElectionLevel || {});
295
- var CampaignCreatedBy = /* @__PURE__ */ ((CampaignCreatedBy2) => {
296
- CampaignCreatedBy2["ADMIN"] = "admin";
297
- return CampaignCreatedBy2;
298
- })(CampaignCreatedBy || {});
299
- var CampaignLaunchStatus = /* @__PURE__ */ ((CampaignLaunchStatus2) => {
300
- CampaignLaunchStatus2["launched"] = "launched";
301
- return CampaignLaunchStatus2;
302
- })(CampaignLaunchStatus || {});
303
- var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
304
- OnboardingStep2["complete"] = "onboarding-complete";
305
- OnboardingStep2["registration"] = "registration";
306
- return OnboardingStep2;
307
- })(OnboardingStep || {});
308
- var GenerationStatus = /* @__PURE__ */ ((GenerationStatus2) => {
309
- GenerationStatus2["processing"] = "processing";
310
- GenerationStatus2["completed"] = "completed";
311
- return GenerationStatus2;
312
- })(GenerationStatus || {});
267
+ // src/enums.ts
268
+ var import_contracts = require("@goodparty_org/contracts");
269
+ var toEnumObject = (values) => Object.fromEntries(values.map((v) => [v, v]));
270
+ var UserRole = toEnumObject(import_contracts.USER_ROLE_VALUES);
271
+ var WhyBrowsing = toEnumObject(import_contracts.WHY_BROWSING_VALUES);
272
+ var CampaignTier = toEnumObject(import_contracts.CAMPAIGN_TIER_VALUES);
313
273
 
314
274
  // src/types/pathToVictory.ts
315
275
  var P2VStatus = /* @__PURE__ */ ((P2VStatus2) => {
@@ -326,18 +286,29 @@ var P2VSource = /* @__PURE__ */ ((P2VSource2) => {
326
286
  })(P2VSource || {});
327
287
  // Annotate the CommonJS export names for ESM import in node:
328
288
  0 && (module.exports = {
289
+ BALLOT_READY_POSITION_LEVEL_VALUES,
329
290
  BallotReadyPositionLevel,
291
+ CAMPAIGN_CREATED_BY_VALUES,
292
+ CAMPAIGN_LAUNCH_STATUS_VALUES,
293
+ CAMPAIGN_STATUS_VALUES,
294
+ CAMPAIGN_TIER_VALUES,
330
295
  CampaignCreatedBy,
331
296
  CampaignLaunchStatus,
297
+ CampaignStatus,
332
298
  CampaignTier,
299
+ ELECTION_LEVEL_VALUES,
333
300
  ElectionLevel,
301
+ GENERATION_STATUS_VALUES,
334
302
  GenerationStatus,
335
303
  GoodPartyClient,
304
+ ONBOARDING_STEP_VALUES,
336
305
  OnboardingStep,
337
306
  P2VSource,
338
307
  P2VStatus,
339
308
  SdkError,
309
+ USER_ROLE_VALUES,
340
310
  UserRole,
311
+ WHY_BROWSING_VALUES,
341
312
  WhyBrowsing
342
313
  });
343
314
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/http/HttpClient.ts","../src/types/result.ts","../src/resources/BaseResource.ts","../src/resources/CampaignsResource.ts","../src/resources/ElectedOfficesResource.ts","../src/resources/PathsToVictoryResource.ts","../src/resources/UsersResource.ts","../src/vendor/clerk/clerk.service.ts","../src/GoodPartyClient.ts","../src/types/user.ts","../src/types/campaign.ts","../src/types/pathToVictory.ts"],"sourcesContent":["export { GoodPartyClient } from './GoodPartyClient'\nexport type { GoodPartyClientConfig } from './GoodPartyClient'\n\nexport { SdkError } from './types/result'\nexport type { PaginationOptions } from './types/result'\n\nexport type {\n PaginationMeta,\n PaginatedList,\n ReadUserOutput,\n ReadUserOutput as User,\n UpdatePasswordInput,\n} from '@goodparty_org/contracts'\n\nexport type {\n UserMetaData,\n ListUsersOptions,\n UpdateUserInput,\n} from './types/user'\n\nexport { UserRole, WhyBrowsing } from './types/user'\n\nexport type {\n Campaign,\n CampaignDetails,\n CampaignData,\n CampaignAiContent,\n VoterGoals,\n CustomVoterFile,\n AiChatMessage,\n AiContentInputValues,\n AiContentGenerationStatus,\n AiContentData,\n ListCampaignsOptions,\n UpdateCampaignInput,\n GeoLocation,\n CustomIssue,\n Opponent,\n HubSpotUpdates,\n} from './types/campaign'\n\nexport {\n CampaignTier,\n BallotReadyPositionLevel,\n ElectionLevel,\n CampaignCreatedBy,\n CampaignLaunchStatus,\n OnboardingStep,\n GenerationStatus,\n} from './types/campaign'\n\nexport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from './types/electedOffice'\n\nexport type {\n PathToVictory,\n PathToVictoryData,\n ViabilityScore,\n ListPathsToVictoryOptions,\n UpdatePathToVictoryInput,\n} from './types/pathToVictory'\n\nexport { P2VStatus, P2VSource } from './types/pathToVictory'\n","import { ofetch, FetchError, FetchOptions } from 'ofetch'\nimport { SdkError } from '../types/result'\n\nexport type OfetchRequestBody = FetchOptions<'json'>['body']\n\nexport class HttpClient {\n private baseUrl: string\n private getToken: () => Promise<string>\n\n constructor(gpApiRootUrl: string, getToken: () => Promise<string>) {\n this.baseUrl = gpApiRootUrl\n this.getToken = getToken\n }\n\n request = async <T>(\n path: string,\n init?: FetchOptions<'json'>,\n ): Promise<T> => {\n try {\n return await ofetch<T>(path, {\n baseURL: this.baseUrl,\n headers: {\n Authorization: `Bearer ${await this.getToken()}`,\n ...(init?.headers ?? {}),\n },\n ...init,\n })\n } catch (error: unknown) {\n if (error instanceof FetchError) {\n throw new SdkError(error.statusCode ?? 0, error.message, error.response)\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, message)\n }\n }\n}\n","export type { PaginationMeta, PaginatedList } from '@goodparty_org/contracts'\n\nexport class SdkError extends Error {\n readonly status: number\n readonly response?: Response\n\n constructor(status: number, message: string, response?: Response) {\n super(message)\n this.name = 'SdkError'\n this.status = status\n this.response = response\n }\n}\n\nexport type PaginationOptions = {\n offset?: number\n limit?: number\n sortBy?: string\n sortOrder?: 'asc' | 'desc'\n}\n","import type { FetchOptions } from 'ofetch'\nimport type { HttpClient, OfetchRequestBody } from '../http/HttpClient'\n\nexport abstract class BaseResource {\n protected httpClient: HttpClient\n protected abstract readonly resourceBasePath: string\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient\n }\n\n protected getRequest = <T>(\n path: string,\n query?: FetchOptions<'json'>['query'],\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'GET', query })\n\n protected postRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'POST', body })\n\n protected putRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'PUT', body })\n\n protected deleteRequest = <T>(path: string): Promise<T> =>\n this.httpClient.request<T>(path, { method: 'DELETE' })\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n Campaign,\n ListCampaignsOptions,\n UpdateCampaignInput,\n} from '../types/campaign'\nimport { BaseResource } from './BaseResource'\n\nexport class CampaignsResource extends BaseResource {\n protected readonly resourceBasePath = '/campaigns'\n\n get = (id: number): Promise<Campaign> =>\n this.getRequest<Campaign>(`${this.resourceBasePath}/${id}`)\n\n list = (options?: ListCampaignsOptions): Promise<PaginatedList<Campaign>> =>\n this.getRequest<PaginatedList<Campaign>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n update = (id: number, input: UpdateCampaignInput): Promise<Campaign> =>\n this.putRequest<Campaign>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from '../types/electedOffice'\nimport { BaseResource } from './BaseResource'\n\nexport class ElectedOfficesResource extends BaseResource {\n protected readonly resourceBasePath = '/elected-office'\n\n list = (\n options?: ListElectedOfficesOptions,\n ): Promise<PaginatedList<ElectedOffice>> =>\n this.getRequest<PaginatedList<ElectedOffice>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: string): Promise<ElectedOffice> =>\n this.getRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: string,\n input: UpdateElectedOfficeInput,\n ): Promise<ElectedOffice> =>\n this.putRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ListPathsToVictoryOptions,\n PathToVictory,\n UpdatePathToVictoryInput,\n} from '../types/pathToVictory'\nimport { BaseResource } from './BaseResource'\n\nexport class PathsToVictoryResource extends BaseResource {\n protected resourceBasePath = '/path-to-victory'\n list = (\n options?: ListPathsToVictoryOptions,\n ): Promise<PaginatedList<PathToVictory>> =>\n this.getRequest<PaginatedList<PathToVictory>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: number): Promise<PathToVictory> =>\n this.getRequest<PathToVictory>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: number,\n input: UpdatePathToVictoryInput,\n ): Promise<PathToVictory> =>\n this.putRequest<PathToVictory>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type {\n PaginatedList,\n ReadUserOutput,\n UpdatePasswordInput,\n} from '@goodparty_org/contracts'\nimport type { ListUsersOptions, UpdateUserInput } from '../types/user'\nimport { BaseResource } from './BaseResource'\n\nexport class UsersResource extends BaseResource {\n protected readonly resourceBasePath = '/users'\n\n list = (options?: ListUsersOptions): Promise<PaginatedList<ReadUserOutput>> =>\n this.getRequest<PaginatedList<ReadUserOutput>>(\n this.resourceBasePath,\n options,\n )\n\n get = (id: number): Promise<ReadUserOutput> =>\n this.getRequest<ReadUserOutput>(`/users/${id}`)\n\n update = (id: number, input: UpdateUserInput): Promise<ReadUserOutput> =>\n this.putRequest<ReadUserOutput>(`${this.resourceBasePath}/${id}`, input)\n\n delete = (id: number): Promise<void> =>\n this.deleteRequest<void>(`${this.resourceBasePath}/${id}`)\n\n updatePassword = (id: number, input: UpdatePasswordInput): Promise<void> =>\n this.putRequest<void>(`${this.resourceBasePath}/${id}/password`, input)\n}\n","import { createClerkClient } from '@clerk/backend'\nimport { SdkError } from '../../types/result'\n\nconst TOKEN_RENEWAL_BUFFER_MS = 30_000\n\nexport class ClerkService {\n private readonly m2mSecret: string\n private readonly clerkClient: ReturnType<typeof createClerkClient>\n private cachedToken: string | null = null\n private tokenExpiration: number | null = null\n private renewalTimer: ReturnType<typeof setTimeout> | null = null\n private pendingTokenPromise: Promise<string> | null = null\n private destroyed = false\n\n constructor(m2mSecret: string) {\n this.m2mSecret = m2mSecret\n this.clerkClient = createClerkClient({})\n }\n\n getToken = async (): Promise<string> => {\n if (this.cachedToken && this.isTokenValid()) {\n return this.cachedToken\n }\n\n if (this.pendingTokenPromise) {\n return this.pendingTokenPromise\n }\n\n const promise = this.createAndCacheToken()\n this.pendingTokenPromise = promise\n\n try {\n return await promise\n } finally {\n if (this.pendingTokenPromise === promise) {\n this.pendingTokenPromise = null\n }\n }\n }\n\n destroy = (): void => {\n this.destroyed = true\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n this.cachedToken = null\n this.tokenExpiration = null\n this.pendingTokenPromise = null\n }\n\n private isTokenValid = (): boolean => {\n if (!this.tokenExpiration) return true\n return Date.now() < this.tokenExpiration - TOKEN_RENEWAL_BUFFER_MS\n }\n\n private createAndCacheToken = async (): Promise<string> => {\n try {\n const m2mToken = await this.clerkClient.m2m.createToken({\n machineSecretKey: this.m2mSecret,\n })\n\n if (!m2mToken.token) {\n throw new SdkError(\n 0,\n 'Clerk M2M token creation succeeded but returned no token string',\n )\n }\n\n if (this.destroyed) return m2mToken.token\n\n this.cachedToken = m2mToken.token\n this.tokenExpiration = m2mToken.expiration\n this.scheduleRenewal()\n\n return this.cachedToken\n } catch (error: unknown) {\n if (error instanceof SdkError) {\n throw error\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, `Failed to create Clerk M2M token: ${message}`)\n }\n }\n\n private scheduleRenewal = (): void => {\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n\n if (!this.tokenExpiration) return\n\n const timeUntilRenewal =\n this.tokenExpiration - Date.now() - TOKEN_RENEWAL_BUFFER_MS\n\n if (timeUntilRenewal <= 0) return\n\n this.renewalTimer = setTimeout(() => {\n this.cachedToken = null\n this.getToken().catch((error: unknown) => {\n console.error('Proactive M2M token renewal failed:', error)\n })\n }, timeUntilRenewal)\n }\n}\n","import { HttpClient } from './http/HttpClient'\nimport { CampaignsResource } from './resources/CampaignsResource'\nimport { ElectedOfficesResource } from './resources/ElectedOfficesResource'\nimport { PathsToVictoryResource } from './resources/PathsToVictoryResource'\nimport { UsersResource } from './resources/UsersResource'\nimport { ClerkService } from './vendor/clerk/clerk.service'\n\nexport type GoodPartyClientConfig = {\n m2mSecret: string\n gpApiRootUrl: string\n}\n\nexport class GoodPartyClient {\n readonly users: UsersResource\n readonly campaigns: CampaignsResource\n readonly electedOffices: ElectedOfficesResource\n readonly pathsToVictory: PathsToVictoryResource\n private clerkService: ClerkService\n\n private constructor(clerkService: ClerkService, gpApiRootUrl: string) {\n this.clerkService = clerkService\n const httpClient = new HttpClient(gpApiRootUrl, clerkService.getToken)\n this.users = new UsersResource(httpClient)\n this.campaigns = new CampaignsResource(httpClient)\n this.electedOffices = new ElectedOfficesResource(httpClient)\n this.pathsToVictory = new PathsToVictoryResource(httpClient)\n }\n\n static create = async (\n config: GoodPartyClientConfig,\n ): Promise<GoodPartyClient> => {\n const { m2mSecret, gpApiRootUrl } = config\n const clerkService = new ClerkService(m2mSecret)\n await clerkService.getToken()\n return new GoodPartyClient(clerkService, gpApiRootUrl)\n }\n\n destroy = (): void => {\n this.clerkService.destroy()\n }\n}\n","import { SIGN_UP_MODE } from '@goodparty_org/contracts'\nimport type { PaginationOptions } from './result'\n\nexport type {\n ReadUserOutput as User,\n UpdatePasswordInput,\n} from '@goodparty_org/contracts'\n\nexport { SIGN_UP_MODE } from '@goodparty_org/contracts'\n\nexport enum UserRole {\n admin = 'admin',\n sales = 'sales',\n candidate = 'candidate',\n campaignManager = 'campaignManager',\n demo = 'demo',\n}\n\nexport enum WhyBrowsing {\n considering = 'considering',\n learning = 'learning',\n test = 'test',\n else = 'else',\n}\n\nexport type UserMetaData = {\n customerId?: string\n checkoutSessionId?: string | null\n accountType?: string | null\n lastVisited?: number\n sessionCount?: number\n isDeleted?: boolean\n fsUserId?: string\n whyBrowsing?: WhyBrowsing | null\n hubspotId?: string\n profile_updated_count?: number\n textNotifications?: boolean\n} | null\n\nexport type ListUsersOptions = PaginationOptions & {\n firstName?: string\n lastName?: string\n email?: string\n}\n\nexport type UpdateUserInput = {\n firstName?: string\n lastName?: string\n email?: string\n name?: string\n zip?: string\n phone?: string\n roles?: UserRole[]\n signUpMode?: SIGN_UP_MODE\n allowTexts?: boolean\n metaData?: UserMetaData\n}\n","import type { PaginationOptions } from './result'\n\nexport enum CampaignTier {\n WIN = 'WIN',\n LOSE = 'LOSE',\n TOSSUP = 'TOSSUP',\n}\n\nexport enum BallotReadyPositionLevel {\n CITY = 'CITY',\n COUNTY = 'COUNTY',\n FEDERAL = 'FEDERAL',\n LOCAL = 'LOCAL',\n REGIONAL = 'REGIONAL',\n STATE = 'STATE',\n TOWNSHIP = 'TOWNSHIP',\n}\n\nexport enum ElectionLevel {\n state = 'state',\n county = 'county',\n federal = 'federal',\n city = 'city',\n}\n\nexport enum CampaignCreatedBy {\n ADMIN = 'admin',\n}\n\nexport enum CampaignLaunchStatus {\n launched = 'launched',\n}\n\nexport enum OnboardingStep {\n complete = 'onboarding-complete',\n registration = 'registration',\n}\n\nexport enum GenerationStatus {\n processing = 'processing',\n completed = 'completed',\n}\n\nexport type VoterGoals = {\n doorKnocking?: number\n calls?: number\n digital?: number\n directMail?: number\n digitalAds?: number\n text?: number\n events?: number\n yardSigns?: number\n robocall?: number\n phoneBanking?: number\n socialMedia?: number\n}\n\nexport type CustomVoterFile = {\n name: string\n channel?: string\n purpose?: string\n filters: string[]\n createdAt: string\n}\n\nexport type AiChatMessage = {\n role: 'user' | 'system' | 'assistant'\n content: string\n createdAt?: number\n id?: string\n usage?: number\n}\n\nexport type AiContentInputValues = Record<\n string,\n string | boolean | number | undefined\n>\n\nexport type AiContentGenerationStatus = {\n status: GenerationStatus\n createdAt: number\n prompt?: string\n existingChat?: AiChatMessage[]\n inputValues?: AiContentInputValues\n}\n\nexport type AiContentData = {\n name: string\n content: string\n updatedAt: number\n inputValues?: AiContentInputValues\n}\n\nexport type GeoLocation = { geoHash?: string; lng?: number; lat?: number }\n\nexport type CustomIssue = { title: string; position: string }\n\nexport type Opponent = { name: string; party: string; description: string }\n\nexport type HubSpotUpdates = Partial<Record<string, string>>\n\nexport type CampaignDetails = {\n state?: string\n ballotLevel?: BallotReadyPositionLevel\n electionDate?: string\n primaryElectionDate?: string\n zip?: string | null\n knowRun?: 'yes' | null\n runForOffice?: 'yes' | 'no' | null\n pledged?: boolean\n isProUpdatedAt?: number\n customIssues?: CustomIssue[]\n runningAgainst?: Opponent[]\n geoLocation?: GeoLocation\n geoLocationFailed?: boolean\n city?: string | null\n county?: string | null\n normalizedOffice?: string | null\n otherOffice?: string\n office?: string\n party?: string\n otherParty?: string\n district?: string\n raceId?: string\n level?: ElectionLevel | null\n noNormalizedOffice?: boolean\n website?: string\n pastExperience?: string | Record<string, string>\n occupation?: string\n funFact?: string\n campaignCommittee?: string\n statementName?: string\n subscriptionId?: string | null\n endOfElectionSubscriptionCanceled?: boolean\n subscriptionCanceledAt?: number | null\n subscriptionCancelAt?: number | null\n filingPeriodsStart?: string | null\n filingPeriodsEnd?: string | null\n officeTermLength?: string\n partisanType?: string\n priorElectionDates?: string[]\n positionId?: string | null\n electionId?: string | null\n tier?: string\n einNumber?: string | null\n einSupportingDocument?: string | null\n wonGeneral?: boolean\n}\n\nexport type CampaignData = {\n createdBy?: CampaignCreatedBy\n slug?: string\n hubSpotUpdates?: HubSpotUpdates\n currentStep?: OnboardingStep\n launchStatus?: CampaignLaunchStatus\n lastVisited?: number\n claimProfile?: string\n customVoterFiles?: CustomVoterFile[]\n reportedVoterGoals?: VoterGoals\n textCampaignCount?: number\n lastStepDate?: string\n adminUserEmail?: string\n hubspotId?: string\n name?: string\n}\n\nexport type CampaignAiContent = {\n generationStatus?: Record<string, AiContentGenerationStatus>\n campaignPlanAttempts?: Record<string, number>\n} & Record<string, AiContentData>\n\nexport type Campaign = {\n id: number\n createdAt: string\n updatedAt: string\n slug: string\n isActive: boolean\n isVerified?: boolean | null\n isPro?: boolean | null\n isDemo: boolean\n didWin?: boolean | null\n dateVerified?: string | null\n tier?: CampaignTier | null\n formattedAddress?: string | null\n placeId?: string | null\n data: CampaignData\n details: CampaignDetails\n aiContent: CampaignAiContent\n userId: number\n canDownloadFederal: boolean\n completedTaskIds: string[]\n hasFreeTextsOffer: boolean\n freeTextsOfferRedeemedAt?: string | null\n}\n\nexport type ListCampaignsOptions = PaginationOptions & {\n userId?: number\n slug?: string\n}\n\nexport type UpdateCampaignInput = {\n slug?: string\n isActive?: boolean\n isVerified?: boolean | null\n isPro?: boolean | null\n isDemo?: boolean\n didWin?: boolean | null\n dateVerified?: string | null\n tier?: CampaignTier | null\n formattedAddress?: string | null\n placeId?: string | null\n data?: CampaignData\n details?: CampaignDetails\n aiContent?: CampaignAiContent\n canDownloadFederal?: boolean\n completedTaskIds?: string[]\n hasFreeTextsOffer?: boolean\n freeTextsOfferRedeemedAt?: string | null\n}\n","import type { PaginationOptions } from './result'\n\nexport enum P2VStatus {\n complete = 'Complete',\n waiting = 'Waiting',\n failed = 'Failed',\n districtMatched = 'DistrictMatched',\n}\n\nexport enum P2VSource {\n GpApi = 'GpApi',\n ElectionApi = 'ElectionApi',\n}\n\nexport type ViabilityScore = {\n level: string\n isPartisan: boolean\n isIncumbent: boolean\n isUncontested: boolean\n candidates: number\n seats: number\n candidatesPerSeat: number\n score: number\n probOfWin: number\n}\n\nexport type PathToVictoryData = {\n p2vStatus?: P2VStatus\n p2vAttempts?: number\n p2vCompleteDate?: string\n completedBy?: number\n electionType?: string\n electionLocation?: string\n voterContactGoal?: number\n winNumber?: number\n p2vNotNeeded?: boolean\n totalRegisteredVoters?: number\n republicans?: number\n democrats?: number\n indies?: number\n women?: number\n men?: number\n white?: number\n asian?: number\n africanAmerican?: number\n hispanic?: number\n averageTurnout?: number\n projectedTurnout?: number\n viability?: ViabilityScore\n source?: P2VSource\n districtId?: string\n districtManuallySet?: boolean\n officeContextFingerprint?: string\n}\n\nexport type PathToVictory = {\n id: number\n createdAt: string\n updatedAt: string\n campaignId: number\n data: PathToVictoryData\n}\n\nexport type ListPathsToVictoryOptions = PaginationOptions & {\n userId?: number\n}\n\nexport type UpdatePathToVictoryInput = {\n data: PathToVictoryData\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAiD;;;ACE1C,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,UAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AACF;;;ADPO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EACA;AAAA,EAER,YAAY,cAAsB,UAAiC;AACjE,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,UAAU,OACR,MACA,SACe;AACf,QAAI;AACF,aAAO,UAAM,sBAAU,MAAM;AAAA,QAC3B,SAAS,KAAK;AAAA,QACd,SAAS;AAAA,UACP,eAAe,UAAU,MAAM,KAAK,SAAS,CAAC;AAAA,UAC9C,GAAI,MAAM,WAAW,CAAC;AAAA,QACxB;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AAAA,IACH,SAAS,OAAgB;AACvB,UAAI,iBAAiB,0BAAY;AAC/B,cAAM,IAAI,SAAS,MAAM,cAAc,GAAG,MAAM,SAAS,MAAM,QAAQ;AAAA,MACzE;AACA,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,YAAM,IAAI,SAAS,GAAG,OAAO;AAAA,IAC/B;AAAA,EACF;AACF;;;AEhCO,IAAe,eAAf,MAA4B;A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AAAA,0BAAA,UAAO;AACP,EAAAA,0BAAA,YAAS;AACT,EAAAA,0BAAA,aAAU;AACV,EAAAA,0BAAA,WAAQ;AACR,EAAAA,0BAAA,cAAW;AACX,EAAAA,0BAAA,WAAQ;AACR,EAAAA,0BAAA,cAAW;AAPD,SAAAA;AAAA,GAAA;AAUL,IAAK,gBAAL,kBAAKC,mBAAL;AACL,EAAAA,eAAA,WAAQ;AACR,EAAAA,eAAA,YAAS;AACT,EAAAA,eAAA,aAAU;AACV,EAAAA,eAAA,UAAO;AAJG,SAAAA;AAAA,GAAA;AAOL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,WAAQ;AADE,SAAAA;AAAA,GAAA;AAIL,IAAK,uBAAL,kBAAKC,0BAAL;AACL,EAAAA,sBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AAIL,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,cAAW;AACX,EAAAA,gBAAA,kBAAe;AAFL,SAAAA;AAAA,GAAA;AAKL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,gBAAa;AACb,EAAAA,kBAAA,eAAY;AAFF,SAAAA;AAAA,GAAA;;;ACpCL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,aAAU;AACV,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,qBAAkB;AAJR,SAAAA;AAAA,GAAA;AAOL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,iBAAc;AAFJ,SAAAA;AAAA,GAAA;","names":["UserRole","WhyBrowsing","CampaignTier","BallotReadyPositionLevel","ElectionLevel","CampaignCreatedBy","CampaignLaunchStatus","OnboardingStep","GenerationStatus","P2VStatus","P2VSource"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/http/HttpClient.ts","../src/types/result.ts","../src/resources/BaseResource.ts","../src/resources/CampaignsResource.ts","../src/resources/ElectedOfficesResource.ts","../src/resources/PathsToVictoryResource.ts","../src/resources/UsersResource.ts","../src/vendor/clerk/clerk.service.ts","../src/GoodPartyClient.ts","../src/enums.ts","../src/types/pathToVictory.ts"],"sourcesContent":["export { GoodPartyClient } from './GoodPartyClient'\nexport type { GoodPartyClientConfig } from './GoodPartyClient'\n\nexport { SdkError } from './types/result'\n\nexport type {\n PaginationMeta,\n PaginatedList,\n PaginationOptions,\n ReadUserOutput,\n ReadUserOutput as User,\n UpdatePasswordInput,\n UpdateUserInput,\n UserMetaData,\n ListUsersPagination,\n ReadCampaignOutput,\n ReadCampaignOutput as Campaign,\n CampaignDetails,\n CampaignData,\n CampaignAiContent,\n VoterGoals,\n CustomVoterFile,\n AiChatMessage,\n AiContentInputValues,\n AiContentGenerationStatus,\n AiContentData,\n GeoLocation,\n CustomIssue,\n Opponent,\n HubSpotUpdates,\n CampaignFinance,\n CampaignPlan,\n CampaignPlanStatus,\n ListCampaignsPagination,\n UpdateCampaignM2MInput,\n} from '@goodparty_org/contracts'\n\nexport {\n USER_ROLE_VALUES,\n WHY_BROWSING_VALUES,\n CAMPAIGN_TIER_VALUES,\n BALLOT_READY_POSITION_LEVEL_VALUES,\n ELECTION_LEVEL_VALUES,\n CAMPAIGN_CREATED_BY_VALUES,\n CAMPAIGN_LAUNCH_STATUS_VALUES,\n CAMPAIGN_STATUS_VALUES,\n ONBOARDING_STEP_VALUES,\n GENERATION_STATUS_VALUES,\n BallotReadyPositionLevel,\n ElectionLevel,\n CampaignCreatedBy,\n CampaignLaunchStatus,\n CampaignStatus,\n OnboardingStep,\n GenerationStatus,\n} from '@goodparty_org/contracts'\n\nexport { UserRole, WhyBrowsing, CampaignTier } from './enums'\n\nexport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from './types/electedOffice'\n\nexport type {\n PathToVictory,\n PathToVictoryData,\n ViabilityScore,\n ListPathsToVictoryOptions,\n UpdatePathToVictoryInput,\n} from './types/pathToVictory'\n\nexport { P2VStatus, P2VSource } from './types/pathToVictory'\n","import { ofetch, FetchError, FetchOptions } from 'ofetch'\nimport { SdkError } from '../types/result'\n\nexport type OfetchRequestBody = FetchOptions<'json'>['body']\n\nexport class HttpClient {\n private baseUrl: string\n private getToken: () => Promise<string>\n\n constructor(gpApiRootUrl: string, getToken: () => Promise<string>) {\n this.baseUrl = gpApiRootUrl\n this.getToken = getToken\n }\n\n request = async <T>(\n path: string,\n init?: FetchOptions<'json'>,\n ): Promise<T> => {\n try {\n return await ofetch<T>(path, {\n baseURL: this.baseUrl,\n headers: {\n Authorization: `Bearer ${await this.getToken()}`,\n ...(init?.headers ?? {}),\n },\n ...init,\n })\n } catch (error: unknown) {\n if (error instanceof FetchError) {\n throw new SdkError(error.statusCode ?? 0, error.message, error.response)\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, message)\n }\n }\n}\n","export class SdkError extends Error {\n readonly status: number\n readonly response?: Response\n\n constructor(status: number, message: string, response?: Response) {\n super(message)\n this.name = 'SdkError'\n this.status = status\n this.response = response\n }\n}\n","import type { FetchOptions } from 'ofetch'\nimport type { HttpClient, OfetchRequestBody } from '../http/HttpClient'\n\nexport abstract class BaseResource {\n protected httpClient: HttpClient\n protected abstract readonly resourceBasePath: string\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient\n }\n\n protected getRequest = <T>(\n path: string,\n query?: FetchOptions<'json'>['query'],\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'GET', query })\n\n protected postRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'POST', body })\n\n protected putRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'PUT', body })\n\n protected deleteRequest = <T>(path: string): Promise<T> =>\n this.httpClient.request<T>(path, { method: 'DELETE' })\n}\n","import type {\n ListCampaignsPagination,\n PaginatedList,\n ReadCampaignOutput,\n UpdateCampaignM2MInput,\n} from '@goodparty_org/contracts'\nimport { BaseResource } from './BaseResource'\n\nexport class CampaignsResource extends BaseResource {\n protected readonly resourceBasePath = '/campaigns'\n\n get = (id: number): Promise<ReadCampaignOutput> =>\n this.getRequest<ReadCampaignOutput>(`${this.resourceBasePath}/${id}`)\n\n list = (\n options?: ListCampaignsPagination,\n ): Promise<PaginatedList<ReadCampaignOutput>> =>\n this.getRequest<PaginatedList<ReadCampaignOutput>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n update = (\n id: number,\n input: UpdateCampaignM2MInput,\n ): Promise<ReadCampaignOutput> =>\n this.putRequest<ReadCampaignOutput>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from '../types/electedOffice'\nimport { BaseResource } from './BaseResource'\n\nexport class ElectedOfficesResource extends BaseResource {\n protected readonly resourceBasePath = '/elected-office'\n\n list = (\n options?: ListElectedOfficesOptions,\n ): Promise<PaginatedList<ElectedOffice>> =>\n this.getRequest<PaginatedList<ElectedOffice>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: string): Promise<ElectedOffice> =>\n this.getRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: string,\n input: UpdateElectedOfficeInput,\n ): Promise<ElectedOffice> =>\n this.putRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ListPathsToVictoryOptions,\n PathToVictory,\n UpdatePathToVictoryInput,\n} from '../types/pathToVictory'\nimport { BaseResource } from './BaseResource'\n\nexport class PathsToVictoryResource extends BaseResource {\n protected resourceBasePath = '/path-to-victory'\n list = (\n options?: ListPathsToVictoryOptions,\n ): Promise<PaginatedList<PathToVictory>> =>\n this.getRequest<PaginatedList<PathToVictory>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: number): Promise<PathToVictory> =>\n this.getRequest<PathToVictory>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: number,\n input: UpdatePathToVictoryInput,\n ): Promise<PathToVictory> =>\n this.putRequest<PathToVictory>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type {\n ListUsersPagination,\n PaginatedList,\n ReadUserOutput,\n UpdatePasswordInput,\n UpdateUserInput,\n} from '@goodparty_org/contracts'\nimport { BaseResource } from './BaseResource'\n\nexport class UsersResource extends BaseResource {\n protected readonly resourceBasePath = '/users'\n\n list = (\n options?: ListUsersPagination,\n ): Promise<PaginatedList<ReadUserOutput>> =>\n this.getRequest<PaginatedList<ReadUserOutput>>(\n this.resourceBasePath,\n options,\n )\n\n get = (id: number): Promise<ReadUserOutput> =>\n this.getRequest<ReadUserOutput>(`/users/${id}`)\n\n update = (id: number, input: UpdateUserInput): Promise<ReadUserOutput> =>\n this.putRequest<ReadUserOutput>(`${this.resourceBasePath}/${id}`, input)\n\n delete = (id: number): Promise<void> =>\n this.deleteRequest<void>(`${this.resourceBasePath}/${id}`)\n\n updatePassword = (id: number, input: UpdatePasswordInput): Promise<void> =>\n this.putRequest<void>(`${this.resourceBasePath}/${id}/password`, input)\n}\n","import { createClerkClient } from '@clerk/backend'\nimport { SdkError } from '../../types/result'\n\nconst TOKEN_RENEWAL_BUFFER_MS = 30_000\n\nexport class ClerkService {\n private readonly m2mSecret: string\n private readonly clerkClient: ReturnType<typeof createClerkClient>\n private cachedToken: string | null = null\n private tokenExpiration: number | null = null\n private renewalTimer: ReturnType<typeof setTimeout> | null = null\n private pendingTokenPromise: Promise<string> | null = null\n private destroyed = false\n\n constructor(m2mSecret: string) {\n this.m2mSecret = m2mSecret\n this.clerkClient = createClerkClient({})\n }\n\n getToken = async (): Promise<string> => {\n if (this.cachedToken && this.isTokenValid()) {\n return this.cachedToken\n }\n\n if (this.pendingTokenPromise) {\n return this.pendingTokenPromise\n }\n\n const promise = this.createAndCacheToken()\n this.pendingTokenPromise = promise\n\n try {\n return await promise\n } finally {\n if (this.pendingTokenPromise === promise) {\n this.pendingTokenPromise = null\n }\n }\n }\n\n destroy = (): void => {\n this.destroyed = true\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n this.cachedToken = null\n this.tokenExpiration = null\n this.pendingTokenPromise = null\n }\n\n private isTokenValid = (): boolean => {\n if (!this.tokenExpiration) return true\n return Date.now() < this.tokenExpiration - TOKEN_RENEWAL_BUFFER_MS\n }\n\n private createAndCacheToken = async (): Promise<string> => {\n try {\n const m2mToken = await this.clerkClient.m2m.createToken({\n machineSecretKey: this.m2mSecret,\n })\n\n if (!m2mToken.token) {\n throw new SdkError(\n 0,\n 'Clerk M2M token creation succeeded but returned no token string',\n )\n }\n\n if (this.destroyed) return m2mToken.token\n\n this.cachedToken = m2mToken.token\n this.tokenExpiration = m2mToken.expiration\n this.scheduleRenewal()\n\n return this.cachedToken\n } catch (error: unknown) {\n if (error instanceof SdkError) {\n throw error\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, `Failed to create Clerk M2M token: ${message}`)\n }\n }\n\n private scheduleRenewal = (): void => {\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n\n if (!this.tokenExpiration) return\n\n const timeUntilRenewal =\n this.tokenExpiration - Date.now() - TOKEN_RENEWAL_BUFFER_MS\n\n if (timeUntilRenewal <= 0) return\n\n this.renewalTimer = setTimeout(() => {\n this.cachedToken = null\n this.getToken().catch((error: unknown) => {\n console.error('Proactive M2M token renewal failed:', error)\n })\n }, timeUntilRenewal)\n }\n}\n","import { HttpClient } from './http/HttpClient'\nimport { CampaignsResource } from './resources/CampaignsResource'\nimport { ElectedOfficesResource } from './resources/ElectedOfficesResource'\nimport { PathsToVictoryResource } from './resources/PathsToVictoryResource'\nimport { UsersResource } from './resources/UsersResource'\nimport { ClerkService } from './vendor/clerk/clerk.service'\n\nexport type GoodPartyClientConfig = {\n m2mSecret: string\n gpApiRootUrl: string\n}\n\nexport class GoodPartyClient {\n readonly users: UsersResource\n readonly campaigns: CampaignsResource\n readonly electedOffices: ElectedOfficesResource\n readonly pathsToVictory: PathsToVictoryResource\n private clerkService: ClerkService\n\n private constructor(clerkService: ClerkService, gpApiRootUrl: string) {\n this.clerkService = clerkService\n const httpClient = new HttpClient(gpApiRootUrl, clerkService.getToken)\n this.users = new UsersResource(httpClient)\n this.campaigns = new CampaignsResource(httpClient)\n this.electedOffices = new ElectedOfficesResource(httpClient)\n this.pathsToVictory = new PathsToVictoryResource(httpClient)\n }\n\n static create = async (\n config: GoodPartyClientConfig,\n ): Promise<GoodPartyClient> => {\n const { m2mSecret, gpApiRootUrl } = config\n const clerkService = new ClerkService(m2mSecret)\n await clerkService.getToken()\n return new GoodPartyClient(clerkService, gpApiRootUrl)\n }\n\n destroy = (): void => {\n this.clerkService.destroy()\n }\n}\n","import {\n USER_ROLE_VALUES,\n type UserRole as UserRoleType,\n WHY_BROWSING_VALUES,\n type WhyBrowsing as WhyBrowsingType,\n CAMPAIGN_TIER_VALUES,\n type CampaignTier as CampaignTierType,\n} from '@goodparty_org/contracts'\n\ntype EnumObject<T extends readonly string[]> = { [K in T[number]]: K }\n\nconst toEnumObject = <T extends readonly string[]>(values: T): EnumObject<T> =>\n Object.fromEntries(values.map((v) => [v, v])) as EnumObject<T>\n\nexport type UserRole = UserRoleType\nexport const UserRole = toEnumObject(USER_ROLE_VALUES)\n\nexport type WhyBrowsing = WhyBrowsingType\nexport const WhyBrowsing = toEnumObject(WHY_BROWSING_VALUES)\n\nexport type CampaignTier = CampaignTierType\nexport const CampaignTier = toEnumObject(CAMPAIGN_TIER_VALUES)\n","import type { PaginationOptions } from '@goodparty_org/contracts'\n\nexport enum P2VStatus {\n complete = 'Complete',\n waiting = 'Waiting',\n failed = 'Failed',\n districtMatched = 'DistrictMatched',\n}\n\nexport enum P2VSource {\n GpApi = 'GpApi',\n ElectionApi = 'ElectionApi',\n}\n\nexport type ViabilityScore = {\n level: string\n isPartisan: boolean\n isIncumbent: boolean\n isUncontested: boolean\n candidates: number\n seats: number\n candidatesPerSeat: number\n score: number\n probOfWin: number\n}\n\nexport type PathToVictoryData = {\n p2vStatus?: P2VStatus\n p2vAttempts?: number\n p2vCompleteDate?: string\n completedBy?: number\n electionType?: string\n electionLocation?: string\n voterContactGoal?: number\n winNumber?: number\n p2vNotNeeded?: boolean\n totalRegisteredVoters?: number\n republicans?: number\n democrats?: number\n indies?: number\n women?: number\n men?: number\n white?: number\n asian?: number\n africanAmerican?: number\n hispanic?: number\n averageTurnout?: number\n projectedTurnout?: number\n viability?: ViabilityScore\n source?: P2VSource\n districtId?: string\n districtManuallySet?: boolean\n officeContextFingerprint?: string\n}\n\nexport type PathToVictory = {\n id: number\n createdAt: string\n updatedAt: string\n campaignId: number\n data: PathToVictoryData\n}\n\nexport type ListPathsToVictoryOptions = PaginationOptions & {\n userId?: number\n}\n\nexport type UpdatePathToVictoryInput = {\n data: PathToVictoryData\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAiD;;;ACA1C,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,UAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AACF;;;ADLO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EACA;AAAA,EAER,YAAY,cAAsB,UAAiC;AACjE,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,UAAU,OACR,MACA,SACe;AACf,QAAI;AACF,aAAO,UAAM,sBAAU,MAAM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AAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAGvC,IAAM,WAAW,aAAa,iCAAgB;AAG9C,IAAM,cAAc,aAAa,oCAAmB;AAGpD,IAAM,eAAe,aAAa,qCAAoB;;;ACnBtD,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,aAAU;AACV,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,qBAAkB;AAJR,SAAAA;AAAA,GAAA;AAOL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,iBAAc;AAFJ,SAAAA;AAAA,GAAA;","names":["import_contracts","P2VStatus","P2VSource"]}
package/dist/index.mjs CHANGED
@@ -212,66 +212,37 @@ var GoodPartyClient = class _GoodPartyClient {
212
212
  };
213
213
  };
214
214
 
215
- // src/types/user.ts
216
- import { SIGN_UP_MODE } from "@goodparty_org/contracts";
217
- var UserRole = /* @__PURE__ */ ((UserRole2) => {
218
- UserRole2["admin"] = "admin";
219
- UserRole2["sales"] = "sales";
220
- UserRole2["candidate"] = "candidate";
221
- UserRole2["campaignManager"] = "campaignManager";
222
- UserRole2["demo"] = "demo";
223
- return UserRole2;
224
- })(UserRole || {});
225
- var WhyBrowsing = /* @__PURE__ */ ((WhyBrowsing2) => {
226
- WhyBrowsing2["considering"] = "considering";
227
- WhyBrowsing2["learning"] = "learning";
228
- WhyBrowsing2["test"] = "test";
229
- WhyBrowsing2["else"] = "else";
230
- return WhyBrowsing2;
231
- })(WhyBrowsing || {});
215
+ // src/index.ts
216
+ import {
217
+ USER_ROLE_VALUES as USER_ROLE_VALUES2,
218
+ WHY_BROWSING_VALUES as WHY_BROWSING_VALUES2,
219
+ CAMPAIGN_TIER_VALUES as CAMPAIGN_TIER_VALUES2,
220
+ BALLOT_READY_POSITION_LEVEL_VALUES,
221
+ ELECTION_LEVEL_VALUES,
222
+ CAMPAIGN_CREATED_BY_VALUES,
223
+ CAMPAIGN_LAUNCH_STATUS_VALUES,
224
+ CAMPAIGN_STATUS_VALUES,
225
+ ONBOARDING_STEP_VALUES,
226
+ GENERATION_STATUS_VALUES,
227
+ BallotReadyPositionLevel,
228
+ ElectionLevel,
229
+ CampaignCreatedBy,
230
+ CampaignLaunchStatus,
231
+ CampaignStatus,
232
+ OnboardingStep,
233
+ GenerationStatus
234
+ } from "@goodparty_org/contracts";
232
235
 
233
- // src/types/campaign.ts
234
- var CampaignTier = /* @__PURE__ */ ((CampaignTier2) => {
235
- CampaignTier2["WIN"] = "WIN";
236
- CampaignTier2["LOSE"] = "LOSE";
237
- CampaignTier2["TOSSUP"] = "TOSSUP";
238
- return CampaignTier2;
239
- })(CampaignTier || {});
240
- var BallotReadyPositionLevel = /* @__PURE__ */ ((BallotReadyPositionLevel2) => {
241
- BallotReadyPositionLevel2["CITY"] = "CITY";
242
- BallotReadyPositionLevel2["COUNTY"] = "COUNTY";
243
- BallotReadyPositionLevel2["FEDERAL"] = "FEDERAL";
244
- BallotReadyPositionLevel2["LOCAL"] = "LOCAL";
245
- BallotReadyPositionLevel2["REGIONAL"] = "REGIONAL";
246
- BallotReadyPositionLevel2["STATE"] = "STATE";
247
- BallotReadyPositionLevel2["TOWNSHIP"] = "TOWNSHIP";
248
- return BallotReadyPositionLevel2;
249
- })(BallotReadyPositionLevel || {});
250
- var ElectionLevel = /* @__PURE__ */ ((ElectionLevel2) => {
251
- ElectionLevel2["state"] = "state";
252
- ElectionLevel2["county"] = "county";
253
- ElectionLevel2["federal"] = "federal";
254
- ElectionLevel2["city"] = "city";
255
- return ElectionLevel2;
256
- })(ElectionLevel || {});
257
- var CampaignCreatedBy = /* @__PURE__ */ ((CampaignCreatedBy2) => {
258
- CampaignCreatedBy2["ADMIN"] = "admin";
259
- return CampaignCreatedBy2;
260
- })(CampaignCreatedBy || {});
261
- var CampaignLaunchStatus = /* @__PURE__ */ ((CampaignLaunchStatus2) => {
262
- CampaignLaunchStatus2["launched"] = "launched";
263
- return CampaignLaunchStatus2;
264
- })(CampaignLaunchStatus || {});
265
- var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
266
- OnboardingStep2["complete"] = "onboarding-complete";
267
- OnboardingStep2["registration"] = "registration";
268
- return OnboardingStep2;
269
- })(OnboardingStep || {});
270
- var GenerationStatus = /* @__PURE__ */ ((GenerationStatus2) => {
271
- GenerationStatus2["processing"] = "processing";
272
- GenerationStatus2["completed"] = "completed";
273
- return GenerationStatus2;
274
- })(GenerationStatus || {});
236
+ // src/enums.ts
237
+ import {
238
+ USER_ROLE_VALUES,
239
+ WHY_BROWSING_VALUES,
240
+ CAMPAIGN_TIER_VALUES
241
+ } from "@goodparty_org/contracts";
242
+ var toEnumObject = (values) => Object.fromEntries(values.map((v) => [v, v]));
243
+ var UserRole = toEnumObject(USER_ROLE_VALUES);
244
+ var WhyBrowsing = toEnumObject(WHY_BROWSING_VALUES);
245
+ var CampaignTier = toEnumObject(CAMPAIGN_TIER_VALUES);
275
246
 
276
247
  // src/types/pathToVictory.ts
277
248
  var P2VStatus = /* @__PURE__ */ ((P2VStatus2) => {
@@ -287,18 +258,29 @@ var P2VSource = /* @__PURE__ */ ((P2VSource2) => {
287
258
  return P2VSource2;
288
259
  })(P2VSource || {});
289
260
  export {
261
+ BALLOT_READY_POSITION_LEVEL_VALUES,
290
262
  BallotReadyPositionLevel,
263
+ CAMPAIGN_CREATED_BY_VALUES,
264
+ CAMPAIGN_LAUNCH_STATUS_VALUES,
265
+ CAMPAIGN_STATUS_VALUES,
266
+ CAMPAIGN_TIER_VALUES2 as CAMPAIGN_TIER_VALUES,
291
267
  CampaignCreatedBy,
292
268
  CampaignLaunchStatus,
269
+ CampaignStatus,
293
270
  CampaignTier,
271
+ ELECTION_LEVEL_VALUES,
294
272
  ElectionLevel,
273
+ GENERATION_STATUS_VALUES,
295
274
  GenerationStatus,
296
275
  GoodPartyClient,
276
+ ONBOARDING_STEP_VALUES,
297
277
  OnboardingStep,
298
278
  P2VSource,
299
279
  P2VStatus,
300
280
  SdkError,
281
+ USER_ROLE_VALUES2 as USER_ROLE_VALUES,
301
282
  UserRole,
283
+ WHY_BROWSING_VALUES2 as WHY_BROWSING_VALUES,
302
284
  WhyBrowsing
303
285
  };
304
286
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/http/HttpClient.ts","../src/types/result.ts","../src/resources/BaseResource.ts","../src/resources/CampaignsResource.ts","../src/resources/ElectedOfficesResource.ts","../src/resources/PathsToVictoryResource.ts","../src/resources/UsersResource.ts","../src/vendor/clerk/clerk.service.ts","../src/GoodPartyClient.ts","../src/types/user.ts","../src/types/campaign.ts","../src/types/pathToVictory.ts"],"sourcesContent":["import { ofetch, FetchError, FetchOptions } from 'ofetch'\nimport { SdkError } from '../types/result'\n\nexport type OfetchRequestBody = FetchOptions<'json'>['body']\n\nexport class HttpClient {\n private baseUrl: string\n private getToken: () => Promise<string>\n\n constructor(gpApiRootUrl: string, getToken: () => Promise<string>) {\n this.baseUrl = gpApiRootUrl\n this.getToken = getToken\n }\n\n request = async <T>(\n path: string,\n init?: FetchOptions<'json'>,\n ): Promise<T> => {\n try {\n return await ofetch<T>(path, {\n baseURL: this.baseUrl,\n headers: {\n Authorization: `Bearer ${await this.getToken()}`,\n ...(init?.headers ?? {}),\n },\n ...init,\n })\n } catch (error: unknown) {\n if (error instanceof FetchError) {\n throw new SdkError(error.statusCode ?? 0, error.message, error.response)\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, message)\n }\n }\n}\n","export type { PaginationMeta, PaginatedList } from '@goodparty_org/contracts'\n\nexport class SdkError extends Error {\n readonly status: number\n readonly response?: Response\n\n constructor(status: number, message: string, response?: Response) {\n super(message)\n this.name = 'SdkError'\n this.status = status\n this.response = response\n }\n}\n\nexport type PaginationOptions = {\n offset?: number\n limit?: number\n sortBy?: string\n sortOrder?: 'asc' | 'desc'\n}\n","import type { FetchOptions } from 'ofetch'\nimport type { HttpClient, OfetchRequestBody } from '../http/HttpClient'\n\nexport abstract class BaseResource {\n protected httpClient: HttpClient\n protected abstract readonly resourceBasePath: string\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient\n }\n\n protected getRequest = <T>(\n path: string,\n query?: FetchOptions<'json'>['query'],\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'GET', query })\n\n protected postRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'POST', body })\n\n protected putRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'PUT', body })\n\n protected deleteRequest = <T>(path: string): Promise<T> =>\n this.httpClient.request<T>(path, { method: 'DELETE' })\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n Campaign,\n ListCampaignsOptions,\n UpdateCampaignInput,\n} from '../types/campaign'\nimport { BaseResource } from './BaseResource'\n\nexport class CampaignsResource extends BaseResource {\n protected readonly resourceBasePath = '/campaigns'\n\n get = (id: number): Promise<Campaign> =>\n this.getRequest<Campaign>(`${this.resourceBasePath}/${id}`)\n\n list = (options?: ListCampaignsOptions): Promise<PaginatedList<Campaign>> =>\n this.getRequest<PaginatedList<Campaign>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n update = (id: number, input: UpdateCampaignInput): Promise<Campaign> =>\n this.putRequest<Campaign>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from '../types/electedOffice'\nimport { BaseResource } from './BaseResource'\n\nexport class ElectedOfficesResource extends BaseResource {\n protected readonly resourceBasePath = '/elected-office'\n\n list = (\n options?: ListElectedOfficesOptions,\n ): Promise<PaginatedList<ElectedOffice>> =>\n this.getRequest<PaginatedList<ElectedOffice>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: string): Promise<ElectedOffice> =>\n this.getRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: string,\n input: UpdateElectedOfficeInput,\n ): Promise<ElectedOffice> =>\n this.putRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ListPathsToVictoryOptions,\n PathToVictory,\n UpdatePathToVictoryInput,\n} from '../types/pathToVictory'\nimport { BaseResource } from './BaseResource'\n\nexport class PathsToVictoryResource extends BaseResource {\n protected resourceBasePath = '/path-to-victory'\n list = (\n options?: ListPathsToVictoryOptions,\n ): Promise<PaginatedList<PathToVictory>> =>\n this.getRequest<PaginatedList<PathToVictory>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: number): Promise<PathToVictory> =>\n this.getRequest<PathToVictory>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: number,\n input: UpdatePathToVictoryInput,\n ): Promise<PathToVictory> =>\n this.putRequest<PathToVictory>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type {\n PaginatedList,\n ReadUserOutput,\n UpdatePasswordInput,\n} from '@goodparty_org/contracts'\nimport type { ListUsersOptions, UpdateUserInput } from '../types/user'\nimport { BaseResource } from './BaseResource'\n\nexport class UsersResource extends BaseResource {\n protected readonly resourceBasePath = '/users'\n\n list = (options?: ListUsersOptions): Promise<PaginatedList<ReadUserOutput>> =>\n this.getRequest<PaginatedList<ReadUserOutput>>(\n this.resourceBasePath,\n options,\n )\n\n get = (id: number): Promise<ReadUserOutput> =>\n this.getRequest<ReadUserOutput>(`/users/${id}`)\n\n update = (id: number, input: UpdateUserInput): Promise<ReadUserOutput> =>\n this.putRequest<ReadUserOutput>(`${this.resourceBasePath}/${id}`, input)\n\n delete = (id: number): Promise<void> =>\n this.deleteRequest<void>(`${this.resourceBasePath}/${id}`)\n\n updatePassword = (id: number, input: UpdatePasswordInput): Promise<void> =>\n this.putRequest<void>(`${this.resourceBasePath}/${id}/password`, input)\n}\n","import { createClerkClient } from '@clerk/backend'\nimport { SdkError } from '../../types/result'\n\nconst TOKEN_RENEWAL_BUFFER_MS = 30_000\n\nexport class ClerkService {\n private readonly m2mSecret: string\n private readonly clerkClient: ReturnType<typeof createClerkClient>\n private cachedToken: string | null = null\n private tokenExpiration: number | null = null\n private renewalTimer: ReturnType<typeof setTimeout> | null = null\n private pendingTokenPromise: Promise<string> | null = null\n private destroyed = false\n\n constructor(m2mSecret: string) {\n this.m2mSecret = m2mSecret\n this.clerkClient = createClerkClient({})\n }\n\n getToken = async (): Promise<string> => {\n if (this.cachedToken && this.isTokenValid()) {\n return this.cachedToken\n }\n\n if (this.pendingTokenPromise) {\n return this.pendingTokenPromise\n }\n\n const promise = this.createAndCacheToken()\n this.pendingTokenPromise = promise\n\n try {\n return await promise\n } finally {\n if (this.pendingTokenPromise === promise) {\n this.pendingTokenPromise = null\n }\n }\n }\n\n destroy = (): void => {\n this.destroyed = true\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n this.cachedToken = null\n this.tokenExpiration = null\n this.pendingTokenPromise = null\n }\n\n private isTokenValid = (): boolean => {\n if (!this.tokenExpiration) return true\n return Date.now() < this.tokenExpiration - TOKEN_RENEWAL_BUFFER_MS\n }\n\n private createAndCacheToken = async (): Promise<string> => {\n try {\n const m2mToken = await this.clerkClient.m2m.createToken({\n machineSecretKey: this.m2mSecret,\n })\n\n if (!m2mToken.token) {\n throw new SdkError(\n 0,\n 'Clerk M2M token creation succeeded but returned no token string',\n )\n }\n\n if (this.destroyed) return m2mToken.token\n\n this.cachedToken = m2mToken.token\n this.tokenExpiration = m2mToken.expiration\n this.scheduleRenewal()\n\n return this.cachedToken\n } catch (error: unknown) {\n if (error instanceof SdkError) {\n throw error\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, `Failed to create Clerk M2M token: ${message}`)\n }\n }\n\n private scheduleRenewal = (): void => {\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n\n if (!this.tokenExpiration) return\n\n const timeUntilRenewal =\n this.tokenExpiration - Date.now() - TOKEN_RENEWAL_BUFFER_MS\n\n if (timeUntilRenewal <= 0) return\n\n this.renewalTimer = setTimeout(() => {\n this.cachedToken = null\n this.getToken().catch((error: unknown) => {\n console.error('Proactive M2M token renewal failed:', error)\n })\n }, timeUntilRenewal)\n }\n}\n","import { HttpClient } from './http/HttpClient'\nimport { CampaignsResource } from './resources/CampaignsResource'\nimport { ElectedOfficesResource } from './resources/ElectedOfficesResource'\nimport { PathsToVictoryResource } from './resources/PathsToVictoryResource'\nimport { UsersResource } from './resources/UsersResource'\nimport { ClerkService } from './vendor/clerk/clerk.service'\n\nexport type GoodPartyClientConfig = {\n m2mSecret: string\n gpApiRootUrl: string\n}\n\nexport class GoodPartyClient {\n readonly users: UsersResource\n readonly campaigns: CampaignsResource\n readonly electedOffices: ElectedOfficesResource\n readonly pathsToVictory: PathsToVictoryResource\n private clerkService: ClerkService\n\n private constructor(clerkService: ClerkService, gpApiRootUrl: string) {\n this.clerkService = clerkService\n const httpClient = new HttpClient(gpApiRootUrl, clerkService.getToken)\n this.users = new UsersResource(httpClient)\n this.campaigns = new CampaignsResource(httpClient)\n this.electedOffices = new ElectedOfficesResource(httpClient)\n this.pathsToVictory = new PathsToVictoryResource(httpClient)\n }\n\n static create = async (\n config: GoodPartyClientConfig,\n ): Promise<GoodPartyClient> => {\n const { m2mSecret, gpApiRootUrl } = config\n const clerkService = new ClerkService(m2mSecret)\n await clerkService.getToken()\n return new GoodPartyClient(clerkService, gpApiRootUrl)\n }\n\n destroy = (): void => {\n this.clerkService.destroy()\n }\n}\n","import { SIGN_UP_MODE } from '@goodparty_org/contracts'\nimport type { PaginationOptions } from './result'\n\nexport type {\n ReadUserOutput as User,\n UpdatePasswordInput,\n} from '@goodparty_org/contracts'\n\nexport { SIGN_UP_MODE } from '@goodparty_org/contracts'\n\nexport enum UserRole {\n admin = 'admin',\n sales = 'sales',\n candidate = 'candidate',\n campaignManager = 'campaignManager',\n demo = 'demo',\n}\n\nexport enum WhyBrowsing {\n considering = 'considering',\n learning = 'learning',\n test = 'test',\n else = 'else',\n}\n\nexport type UserMetaData = {\n customerId?: string\n checkoutSessionId?: string | null\n accountType?: string | null\n lastVisited?: number\n sessionCount?: number\n isDeleted?: boolean\n fsUserId?: string\n whyBrowsing?: WhyBrowsing | null\n hubspotId?: string\n profile_updated_count?: number\n textNotifications?: boolean\n} | null\n\nexport type ListUsersOptions = PaginationOptions & {\n firstName?: string\n lastName?: string\n email?: string\n}\n\nexport type UpdateUserInput = {\n firstName?: string\n lastName?: string\n email?: string\n name?: string\n zip?: string\n phone?: string\n roles?: UserRole[]\n signUpMode?: SIGN_UP_MODE\n allowTexts?: boolean\n metaData?: UserMetaData\n}\n","import type { PaginationOptions } from './result'\n\nexport enum CampaignTier {\n WIN = 'WIN',\n LOSE = 'LOSE',\n TOSSUP = 'TOSSUP',\n}\n\nexport enum BallotReadyPositionLevel {\n CITY = 'CITY',\n COUNTY = 'COUNTY',\n FEDERAL = 'FEDERAL',\n LOCAL = 'LOCAL',\n REGIONAL = 'REGIONAL',\n STATE = 'STATE',\n TOWNSHIP = 'TOWNSHIP',\n}\n\nexport enum ElectionLevel {\n state = 'state',\n county = 'county',\n federal = 'federal',\n city = 'city',\n}\n\nexport enum CampaignCreatedBy {\n ADMIN = 'admin',\n}\n\nexport enum CampaignLaunchStatus {\n launched = 'launched',\n}\n\nexport enum OnboardingStep {\n complete = 'onboarding-complete',\n registration = 'registration',\n}\n\nexport enum GenerationStatus {\n processing = 'processing',\n completed = 'completed',\n}\n\nexport type VoterGoals = {\n doorKnocking?: number\n calls?: number\n digital?: number\n directMail?: number\n digitalAds?: number\n text?: number\n events?: number\n yardSigns?: number\n robocall?: number\n phoneBanking?: number\n socialMedia?: number\n}\n\nexport type CustomVoterFile = {\n name: string\n channel?: string\n purpose?: string\n filters: string[]\n createdAt: string\n}\n\nexport type AiChatMessage = {\n role: 'user' | 'system' | 'assistant'\n content: string\n createdAt?: number\n id?: string\n usage?: number\n}\n\nexport type AiContentInputValues = Record<\n string,\n string | boolean | number | undefined\n>\n\nexport type AiContentGenerationStatus = {\n status: GenerationStatus\n createdAt: number\n prompt?: string\n existingChat?: AiChatMessage[]\n inputValues?: AiContentInputValues\n}\n\nexport type AiContentData = {\n name: string\n content: string\n updatedAt: number\n inputValues?: AiContentInputValues\n}\n\nexport type GeoLocation = { geoHash?: string; lng?: number; lat?: number }\n\nexport type CustomIssue = { title: string; position: string }\n\nexport type Opponent = { name: string; party: string; description: string }\n\nexport type HubSpotUpdates = Partial<Record<string, string>>\n\nexport type CampaignDetails = {\n state?: string\n ballotLevel?: BallotReadyPositionLevel\n electionDate?: string\n primaryElectionDate?: string\n zip?: string | null\n knowRun?: 'yes' | null\n runForOffice?: 'yes' | 'no' | null\n pledged?: boolean\n isProUpdatedAt?: number\n customIssues?: CustomIssue[]\n runningAgainst?: Opponent[]\n geoLocation?: GeoLocation\n geoLocationFailed?: boolean\n city?: string | null\n county?: string | null\n normalizedOffice?: string | null\n otherOffice?: string\n office?: string\n party?: string\n otherParty?: string\n district?: string\n raceId?: string\n level?: ElectionLevel | null\n noNormalizedOffice?: boolean\n website?: string\n pastExperience?: string | Record<string, string>\n occupation?: string\n funFact?: string\n campaignCommittee?: string\n statementName?: string\n subscriptionId?: string | null\n endOfElectionSubscriptionCanceled?: boolean\n subscriptionCanceledAt?: number | null\n subscriptionCancelAt?: number | null\n filingPeriodsStart?: string | null\n filingPeriodsEnd?: string | null\n officeTermLength?: string\n partisanType?: string\n priorElectionDates?: string[]\n positionId?: string | null\n electionId?: string | null\n tier?: string\n einNumber?: string | null\n einSupportingDocument?: string | null\n wonGeneral?: boolean\n}\n\nexport type CampaignData = {\n createdBy?: CampaignCreatedBy\n slug?: string\n hubSpotUpdates?: HubSpotUpdates\n currentStep?: OnboardingStep\n launchStatus?: CampaignLaunchStatus\n lastVisited?: number\n claimProfile?: string\n customVoterFiles?: CustomVoterFile[]\n reportedVoterGoals?: VoterGoals\n textCampaignCount?: number\n lastStepDate?: string\n adminUserEmail?: string\n hubspotId?: string\n name?: string\n}\n\nexport type CampaignAiContent = {\n generationStatus?: Record<string, AiContentGenerationStatus>\n campaignPlanAttempts?: Record<string, number>\n} & Record<string, AiContentData>\n\nexport type Campaign = {\n id: number\n createdAt: string\n updatedAt: string\n slug: string\n isActive: boolean\n isVerified?: boolean | null\n isPro?: boolean | null\n isDemo: boolean\n didWin?: boolean | null\n dateVerified?: string | null\n tier?: CampaignTier | null\n formattedAddress?: string | null\n placeId?: string | null\n data: CampaignData\n details: CampaignDetails\n aiContent: CampaignAiContent\n userId: number\n canDownloadFederal: boolean\n completedTaskIds: string[]\n hasFreeTextsOffer: boolean\n freeTextsOfferRedeemedAt?: string | null\n}\n\nexport type ListCampaignsOptions = PaginationOptions & {\n userId?: number\n slug?: string\n}\n\nexport type UpdateCampaignInput = {\n slug?: string\n isActive?: boolean\n isVerified?: boolean | null\n isPro?: boolean | null\n isDemo?: boolean\n didWin?: boolean | null\n dateVerified?: string | null\n tier?: CampaignTier | null\n formattedAddress?: string | null\n placeId?: string | null\n data?: CampaignData\n details?: CampaignDetails\n aiContent?: CampaignAiContent\n canDownloadFederal?: boolean\n completedTaskIds?: string[]\n hasFreeTextsOffer?: boolean\n freeTextsOfferRedeemedAt?: string | null\n}\n","import type { PaginationOptions } from './result'\n\nexport enum P2VStatus {\n complete = 'Complete',\n waiting = 'Waiting',\n failed = 'Failed',\n districtMatched = 'DistrictMatched',\n}\n\nexport enum P2VSource {\n GpApi = 'GpApi',\n ElectionApi = 'ElectionApi',\n}\n\nexport type ViabilityScore = {\n level: string\n isPartisan: boolean\n isIncumbent: boolean\n isUncontested: boolean\n candidates: number\n seats: number\n candidatesPerSeat: number\n score: number\n probOfWin: number\n}\n\nexport type PathToVictoryData = {\n p2vStatus?: P2VStatus\n p2vAttempts?: number\n p2vCompleteDate?: string\n completedBy?: number\n electionType?: string\n electionLocation?: string\n voterContactGoal?: number\n winNumber?: number\n p2vNotNeeded?: boolean\n totalRegisteredVoters?: number\n republicans?: number\n democrats?: number\n indies?: number\n women?: number\n men?: number\n white?: number\n asian?: number\n africanAmerican?: number\n hispanic?: number\n averageTurnout?: number\n projectedTurnout?: number\n viability?: ViabilityScore\n source?: P2VSource\n districtId?: string\n districtManuallySet?: boolean\n officeContextFingerprint?: string\n}\n\nexport type PathToVictory = {\n id: number\n createdAt: string\n updatedAt: string\n campaignId: number\n data: PathToVictoryData\n}\n\nexport type ListPathsToVictoryOptions = PaginationOptions & {\n userId?: number\n}\n\nexport type UpdatePathToVictoryInput = {\n data: PathToVictoryData\n}\n"],"mappings":";AAAA,SAAS,QAAQ,kBAAgC;;;ACE1C,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,UAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AACF;;;ADPO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EACA;AAAA,EAER,YAAY,cAAsB,UAAiC;AACjE,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,UAAU,OACR,MACA,SACe;AACf,QAAI;AACF,aAAO,MAAM,OAAU,MAAM;AAAA,QAC3B,SAAS,KAAK;AAAA,QACd,SAAS;AAAA,UACP,eAAe,UAAU,MAAM,KAAK,SAAS,CAAC;AAAA,UAC9C,GAAI,MAAM,WAAW,CAAC;AAAA,QACxB;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AAAA,IACH,SAAS,OAAgB;AACvB,UAAI,iBAAiB,YAAY;AAC/B,cAAM,IAAI,SAAS,MAAM,cAAc,GAAG,MAAM,SAAS,MAAM,QAAQ;AAAA,MACzE;AACA,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,YAAM,IAAI,SAAS,GAAG,OAAO;AAAA,IA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C,SAAAA;AAAA,GAAA;AAML,IAAK,2BAAL,kBAAKC,8BAAL;AACL,EAAAA,0BAAA,UAAO;AACP,EAAAA,0BAAA,YAAS;AACT,EAAAA,0BAAA,aAAU;AACV,EAAAA,0BAAA,WAAQ;AACR,EAAAA,0BAAA,cAAW;AACX,EAAAA,0BAAA,WAAQ;AACR,EAAAA,0BAAA,cAAW;AAPD,SAAAA;AAAA,GAAA;AAUL,IAAK,gBAAL,kBAAKC,mBAAL;AACL,EAAAA,eAAA,WAAQ;AACR,EAAAA,eAAA,YAAS;AACT,EAAAA,eAAA,aAAU;AACV,EAAAA,eAAA,UAAO;AAJG,SAAAA;AAAA,GAAA;AAOL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,WAAQ;AADE,SAAAA;AAAA,GAAA;AAIL,IAAK,uBAAL,kBAAKC,0BAAL;AACL,EAAAA,sBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AAIL,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,cAAW;AACX,EAAAA,gBAAA,kBAAe;AAFL,SAAAA;AAAA,GAAA;AAKL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,gBAAa;AACb,EAAAA,kBAAA,eAAY;AAFF,SAAAA;AAAA,GAAA;;;ACpCL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,aAAU;AACV,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,qBAAkB;AAJR,SAAAA;AAAA,GAAA;AAOL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,iBAAc;AAFJ,SAAAA;AAAA,GAAA;","names":["UserRole","WhyBrowsing","CampaignTier","BallotReadyPositionLevel","ElectionLevel","CampaignCreatedBy","CampaignLaunchStatus","OnboardingStep","GenerationStatus","P2VStatus","P2VSource"]}
1
+ {"version":3,"sources":["../src/http/HttpClient.ts","../src/types/result.ts","../src/resources/BaseResource.ts","../src/resources/CampaignsResource.ts","../src/resources/ElectedOfficesResource.ts","../src/resources/PathsToVictoryResource.ts","../src/resources/UsersResource.ts","../src/vendor/clerk/clerk.service.ts","../src/GoodPartyClient.ts","../src/index.ts","../src/enums.ts","../src/types/pathToVictory.ts"],"sourcesContent":["import { ofetch, FetchError, FetchOptions } from 'ofetch'\nimport { SdkError } from '../types/result'\n\nexport type OfetchRequestBody = FetchOptions<'json'>['body']\n\nexport class HttpClient {\n private baseUrl: string\n private getToken: () => Promise<string>\n\n constructor(gpApiRootUrl: string, getToken: () => Promise<string>) {\n this.baseUrl = gpApiRootUrl\n this.getToken = getToken\n }\n\n request = async <T>(\n path: string,\n init?: FetchOptions<'json'>,\n ): Promise<T> => {\n try {\n return await ofetch<T>(path, {\n baseURL: this.baseUrl,\n headers: {\n Authorization: `Bearer ${await this.getToken()}`,\n ...(init?.headers ?? {}),\n },\n ...init,\n })\n } catch (error: unknown) {\n if (error instanceof FetchError) {\n throw new SdkError(error.statusCode ?? 0, error.message, error.response)\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, message)\n }\n }\n}\n","export class SdkError extends Error {\n readonly status: number\n readonly response?: Response\n\n constructor(status: number, message: string, response?: Response) {\n super(message)\n this.name = 'SdkError'\n this.status = status\n this.response = response\n }\n}\n","import type { FetchOptions } from 'ofetch'\nimport type { HttpClient, OfetchRequestBody } from '../http/HttpClient'\n\nexport abstract class BaseResource {\n protected httpClient: HttpClient\n protected abstract readonly resourceBasePath: string\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient\n }\n\n protected getRequest = <T>(\n path: string,\n query?: FetchOptions<'json'>['query'],\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'GET', query })\n\n protected postRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'POST', body })\n\n protected putRequest = <T>(\n path: string,\n body: OfetchRequestBody,\n ): Promise<T> => this.httpClient.request<T>(path, { method: 'PUT', body })\n\n protected deleteRequest = <T>(path: string): Promise<T> =>\n this.httpClient.request<T>(path, { method: 'DELETE' })\n}\n","import type {\n ListCampaignsPagination,\n PaginatedList,\n ReadCampaignOutput,\n UpdateCampaignM2MInput,\n} from '@goodparty_org/contracts'\nimport { BaseResource } from './BaseResource'\n\nexport class CampaignsResource extends BaseResource {\n protected readonly resourceBasePath = '/campaigns'\n\n get = (id: number): Promise<ReadCampaignOutput> =>\n this.getRequest<ReadCampaignOutput>(`${this.resourceBasePath}/${id}`)\n\n list = (\n options?: ListCampaignsPagination,\n ): Promise<PaginatedList<ReadCampaignOutput>> =>\n this.getRequest<PaginatedList<ReadCampaignOutput>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n update = (\n id: number,\n input: UpdateCampaignM2MInput,\n ): Promise<ReadCampaignOutput> =>\n this.putRequest<ReadCampaignOutput>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from '../types/electedOffice'\nimport { BaseResource } from './BaseResource'\n\nexport class ElectedOfficesResource extends BaseResource {\n protected readonly resourceBasePath = '/elected-office'\n\n list = (\n options?: ListElectedOfficesOptions,\n ): Promise<PaginatedList<ElectedOffice>> =>\n this.getRequest<PaginatedList<ElectedOffice>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: string): Promise<ElectedOffice> =>\n this.getRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: string,\n input: UpdateElectedOfficeInput,\n ): Promise<ElectedOffice> =>\n this.putRequest<ElectedOffice>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type { PaginatedList } from '@goodparty_org/contracts'\nimport type {\n ListPathsToVictoryOptions,\n PathToVictory,\n UpdatePathToVictoryInput,\n} from '../types/pathToVictory'\nimport { BaseResource } from './BaseResource'\n\nexport class PathsToVictoryResource extends BaseResource {\n protected resourceBasePath = '/path-to-victory'\n list = (\n options?: ListPathsToVictoryOptions,\n ): Promise<PaginatedList<PathToVictory>> =>\n this.getRequest<PaginatedList<PathToVictory>>(\n `${this.resourceBasePath}/list`,\n options,\n )\n\n get = (id: number): Promise<PathToVictory> =>\n this.getRequest<PathToVictory>(`${this.resourceBasePath}/${id}`)\n\n update = (\n id: number,\n input: UpdatePathToVictoryInput,\n ): Promise<PathToVictory> =>\n this.putRequest<PathToVictory>(`${this.resourceBasePath}/${id}`, input)\n}\n","import type {\n ListUsersPagination,\n PaginatedList,\n ReadUserOutput,\n UpdatePasswordInput,\n UpdateUserInput,\n} from '@goodparty_org/contracts'\nimport { BaseResource } from './BaseResource'\n\nexport class UsersResource extends BaseResource {\n protected readonly resourceBasePath = '/users'\n\n list = (\n options?: ListUsersPagination,\n ): Promise<PaginatedList<ReadUserOutput>> =>\n this.getRequest<PaginatedList<ReadUserOutput>>(\n this.resourceBasePath,\n options,\n )\n\n get = (id: number): Promise<ReadUserOutput> =>\n this.getRequest<ReadUserOutput>(`/users/${id}`)\n\n update = (id: number, input: UpdateUserInput): Promise<ReadUserOutput> =>\n this.putRequest<ReadUserOutput>(`${this.resourceBasePath}/${id}`, input)\n\n delete = (id: number): Promise<void> =>\n this.deleteRequest<void>(`${this.resourceBasePath}/${id}`)\n\n updatePassword = (id: number, input: UpdatePasswordInput): Promise<void> =>\n this.putRequest<void>(`${this.resourceBasePath}/${id}/password`, input)\n}\n","import { createClerkClient } from '@clerk/backend'\nimport { SdkError } from '../../types/result'\n\nconst TOKEN_RENEWAL_BUFFER_MS = 30_000\n\nexport class ClerkService {\n private readonly m2mSecret: string\n private readonly clerkClient: ReturnType<typeof createClerkClient>\n private cachedToken: string | null = null\n private tokenExpiration: number | null = null\n private renewalTimer: ReturnType<typeof setTimeout> | null = null\n private pendingTokenPromise: Promise<string> | null = null\n private destroyed = false\n\n constructor(m2mSecret: string) {\n this.m2mSecret = m2mSecret\n this.clerkClient = createClerkClient({})\n }\n\n getToken = async (): Promise<string> => {\n if (this.cachedToken && this.isTokenValid()) {\n return this.cachedToken\n }\n\n if (this.pendingTokenPromise) {\n return this.pendingTokenPromise\n }\n\n const promise = this.createAndCacheToken()\n this.pendingTokenPromise = promise\n\n try {\n return await promise\n } finally {\n if (this.pendingTokenPromise === promise) {\n this.pendingTokenPromise = null\n }\n }\n }\n\n destroy = (): void => {\n this.destroyed = true\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n this.cachedToken = null\n this.tokenExpiration = null\n this.pendingTokenPromise = null\n }\n\n private isTokenValid = (): boolean => {\n if (!this.tokenExpiration) return true\n return Date.now() < this.tokenExpiration - TOKEN_RENEWAL_BUFFER_MS\n }\n\n private createAndCacheToken = async (): Promise<string> => {\n try {\n const m2mToken = await this.clerkClient.m2m.createToken({\n machineSecretKey: this.m2mSecret,\n })\n\n if (!m2mToken.token) {\n throw new SdkError(\n 0,\n 'Clerk M2M token creation succeeded but returned no token string',\n )\n }\n\n if (this.destroyed) return m2mToken.token\n\n this.cachedToken = m2mToken.token\n this.tokenExpiration = m2mToken.expiration\n this.scheduleRenewal()\n\n return this.cachedToken\n } catch (error: unknown) {\n if (error instanceof SdkError) {\n throw error\n }\n const message = error instanceof Error ? error.message : 'Unknown error'\n throw new SdkError(0, `Failed to create Clerk M2M token: ${message}`)\n }\n }\n\n private scheduleRenewal = (): void => {\n if (this.renewalTimer) {\n clearTimeout(this.renewalTimer)\n this.renewalTimer = null\n }\n\n if (!this.tokenExpiration) return\n\n const timeUntilRenewal =\n this.tokenExpiration - Date.now() - TOKEN_RENEWAL_BUFFER_MS\n\n if (timeUntilRenewal <= 0) return\n\n this.renewalTimer = setTimeout(() => {\n this.cachedToken = null\n this.getToken().catch((error: unknown) => {\n console.error('Proactive M2M token renewal failed:', error)\n })\n }, timeUntilRenewal)\n }\n}\n","import { HttpClient } from './http/HttpClient'\nimport { CampaignsResource } from './resources/CampaignsResource'\nimport { ElectedOfficesResource } from './resources/ElectedOfficesResource'\nimport { PathsToVictoryResource } from './resources/PathsToVictoryResource'\nimport { UsersResource } from './resources/UsersResource'\nimport { ClerkService } from './vendor/clerk/clerk.service'\n\nexport type GoodPartyClientConfig = {\n m2mSecret: string\n gpApiRootUrl: string\n}\n\nexport class GoodPartyClient {\n readonly users: UsersResource\n readonly campaigns: CampaignsResource\n readonly electedOffices: ElectedOfficesResource\n readonly pathsToVictory: PathsToVictoryResource\n private clerkService: ClerkService\n\n private constructor(clerkService: ClerkService, gpApiRootUrl: string) {\n this.clerkService = clerkService\n const httpClient = new HttpClient(gpApiRootUrl, clerkService.getToken)\n this.users = new UsersResource(httpClient)\n this.campaigns = new CampaignsResource(httpClient)\n this.electedOffices = new ElectedOfficesResource(httpClient)\n this.pathsToVictory = new PathsToVictoryResource(httpClient)\n }\n\n static create = async (\n config: GoodPartyClientConfig,\n ): Promise<GoodPartyClient> => {\n const { m2mSecret, gpApiRootUrl } = config\n const clerkService = new ClerkService(m2mSecret)\n await clerkService.getToken()\n return new GoodPartyClient(clerkService, gpApiRootUrl)\n }\n\n destroy = (): void => {\n this.clerkService.destroy()\n }\n}\n","export { GoodPartyClient } from './GoodPartyClient'\nexport type { GoodPartyClientConfig } from './GoodPartyClient'\n\nexport { SdkError } from './types/result'\n\nexport type {\n PaginationMeta,\n PaginatedList,\n PaginationOptions,\n ReadUserOutput,\n ReadUserOutput as User,\n UpdatePasswordInput,\n UpdateUserInput,\n UserMetaData,\n ListUsersPagination,\n ReadCampaignOutput,\n ReadCampaignOutput as Campaign,\n CampaignDetails,\n CampaignData,\n CampaignAiContent,\n VoterGoals,\n CustomVoterFile,\n AiChatMessage,\n AiContentInputValues,\n AiContentGenerationStatus,\n AiContentData,\n GeoLocation,\n CustomIssue,\n Opponent,\n HubSpotUpdates,\n CampaignFinance,\n CampaignPlan,\n CampaignPlanStatus,\n ListCampaignsPagination,\n UpdateCampaignM2MInput,\n} from '@goodparty_org/contracts'\n\nexport {\n USER_ROLE_VALUES,\n WHY_BROWSING_VALUES,\n CAMPAIGN_TIER_VALUES,\n BALLOT_READY_POSITION_LEVEL_VALUES,\n ELECTION_LEVEL_VALUES,\n CAMPAIGN_CREATED_BY_VALUES,\n CAMPAIGN_LAUNCH_STATUS_VALUES,\n CAMPAIGN_STATUS_VALUES,\n ONBOARDING_STEP_VALUES,\n GENERATION_STATUS_VALUES,\n BallotReadyPositionLevel,\n ElectionLevel,\n CampaignCreatedBy,\n CampaignLaunchStatus,\n CampaignStatus,\n OnboardingStep,\n GenerationStatus,\n} from '@goodparty_org/contracts'\n\nexport { UserRole, WhyBrowsing, CampaignTier } from './enums'\n\nexport type {\n ElectedOffice,\n ListElectedOfficesOptions,\n UpdateElectedOfficeInput,\n} from './types/electedOffice'\n\nexport type {\n PathToVictory,\n PathToVictoryData,\n ViabilityScore,\n ListPathsToVictoryOptions,\n UpdatePathToVictoryInput,\n} from './types/pathToVictory'\n\nexport { P2VStatus, P2VSource } from './types/pathToVictory'\n","import {\n USER_ROLE_VALUES,\n type UserRole as UserRoleType,\n WHY_BROWSING_VALUES,\n type WhyBrowsing as WhyBrowsingType,\n CAMPAIGN_TIER_VALUES,\n type CampaignTier as CampaignTierType,\n} from '@goodparty_org/contracts'\n\ntype EnumObject<T extends readonly string[]> = { [K in T[number]]: K }\n\nconst toEnumObject = <T extends readonly string[]>(values: T): EnumObject<T> =>\n Object.fromEntries(values.map((v) => [v, v])) as EnumObject<T>\n\nexport type UserRole = UserRoleType\nexport const UserRole = toEnumObject(USER_ROLE_VALUES)\n\nexport type WhyBrowsing = WhyBrowsingType\nexport const WhyBrowsing = toEnumObject(WHY_BROWSING_VALUES)\n\nexport type CampaignTier = CampaignTierType\nexport const CampaignTier = toEnumObject(CAMPAIGN_TIER_VALUES)\n","import type { PaginationOptions } from '@goodparty_org/contracts'\n\nexport enum P2VStatus {\n complete = 'Complete',\n waiting = 'Waiting',\n failed = 'Failed',\n districtMatched = 'DistrictMatched',\n}\n\nexport enum P2VSource {\n GpApi = 'GpApi',\n ElectionApi = 'ElectionApi',\n}\n\nexport type ViabilityScore = {\n level: string\n isPartisan: boolean\n isIncumbent: boolean\n isUncontested: boolean\n candidates: number\n seats: number\n candidatesPerSeat: number\n score: number\n probOfWin: number\n}\n\nexport type PathToVictoryData = {\n p2vStatus?: P2VStatus\n p2vAttempts?: number\n p2vCompleteDate?: string\n completedBy?: number\n electionType?: string\n electionLocation?: string\n voterContactGoal?: number\n winNumber?: number\n p2vNotNeeded?: boolean\n totalRegisteredVoters?: number\n republicans?: number\n democrats?: number\n indies?: number\n women?: number\n men?: number\n white?: number\n asian?: number\n africanAmerican?: number\n hispanic?: number\n averageTurnout?: number\n projectedTurnout?: number\n viability?: ViabilityScore\n source?: P2VSource\n districtId?: string\n districtManuallySet?: boolean\n officeContextFingerprint?: string\n}\n\nexport type PathToVictory = {\n id: number\n createdAt: string\n updatedAt: string\n campaignId: number\n data: PathToVictoryData\n}\n\nexport type ListPathsToVictoryOptions = PaginationOptions & {\n userId?: number\n}\n\nexport type UpdatePathToVictoryInput = {\n data: PathToVictoryData\n}\n"],"mappings":";AAAA,SAAS,QAAQ,kBAAgC;;;ACA1C,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,UAAqB;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW;AAAA,EAClB;AACF;;;ADLO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EACA;AAAA,EAER,YAAY,cAAsB,UAAiC;AACjE,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,UAAU,OACR,MACA,SACe;AACf,QAAI;AACF,aAAO,MAAM,OAAU,MAAM;AAAA,QAC3B,SAAS,KAAK;AAAA,QACd,SAAS;AAAA,UACP,eAAe,UAAU,MAAM,KAAK,SAAS,CAAC;AAAA,UAC9C,GAAI,MAAM,WAAW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EACA;AAAA,EACA;AAAA,OACK;;;ACvDP;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OAEK;AAIP,IAAM,eAAe,CAA8B,WACjD,OAAO,YAAY,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAGvC,IAAM,WAAW,aAAa,gBAAgB;AAG9C,IAAM,cAAc,aAAa,mBAAmB;AAGpD,IAAM,eAAe,aAAa,oBAAoB;;;ACnBtD,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,aAAU;AACV,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,qBAAkB;AAJR,SAAAA;AAAA,GAAA;AAOL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,iBAAc;AAFJ,SAAAA;AAAA,GAAA;","names":["USER_ROLE_VALUES","WHY_BROWSING_VALUES","CAMPAIGN_TIER_VALUES","P2VStatus","P2VSource"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodparty_org/sdk",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "TypeScript SDK for interacting with the GoodParty API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@clerk/backend": "^2.30.1",
52
- "@goodparty_org/contracts": "^0.0.0-rc-20260224180734",
52
+ "@goodparty_org/contracts": "^0.0.0-rc-develop.83110207c77a9c2f1eddffa0054163eb84a65f37",
53
53
  "ofetch": "^1.5.1"
54
54
  }
55
55
  }