@mackenly/planningcenterkit 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-publish.yml +3 -11
- package/README.md +53 -2
- package/dist/client.d.ts +206 -0
- package/dist/client.js +250 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/modules/calendar.d.ts +5 -0
- package/dist/modules/calendar.js +11 -0
- package/dist/modules/calendar.js.map +1 -0
- package/dist/modules/checkins.d.ts +0 -0
- package/dist/modules/checkins.js +2 -0
- package/dist/modules/checkins.js.map +1 -0
- package/dist/modules/giving.d.ts +0 -0
- package/dist/modules/giving.js +2 -0
- package/dist/modules/giving.js.map +1 -0
- package/dist/modules/groups.d.ts +4 -0
- package/dist/modules/groups.js +22 -0
- package/dist/modules/groups.js.map +1 -0
- package/dist/modules/people.d.ts +66 -0
- package/dist/modules/people.js +40 -0
- package/dist/modules/people.js.map +1 -0
- package/dist/modules/publishing.d.ts +0 -0
- package/dist/modules/publishing.js +2 -0
- package/dist/modules/publishing.js.map +1 -0
- package/dist/modules/services.d.ts +0 -0
- package/dist/modules/services.js +2 -0
- package/dist/modules/services.js.map +1 -0
- package/dist/modules/webhooks.d.ts +0 -0
- package/dist/modules/webhooks.js +2 -0
- package/dist/modules/webhooks.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
- package/src/client.ts +333 -0
- package/src/index.test.ts +5 -4
- package/src/index.ts +4 -5
- package/src/modules/calendar.ts +11 -0
- package/src/modules/checkins.ts +0 -0
- package/src/modules/giving.ts +0 -0
- package/src/modules/groups.ts +7 -0
- package/src/modules/people.ts +92 -0
- package/src/modules/publishing.ts +0 -0
- package/src/modules/services.ts +0 -0
- package/src/modules/webhooks.ts +0 -0
- package/src/types.ts +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groups.js","sourceRoot":"","sources":["../../src/modules/groups.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAsC;AAEtC,MAAa,SAAU,SAAQ,kBAAS;IACvB,SAAS;;YAClB,OAAM;QACV,CAAC;KAAA;CACJ;AAJD,8BAIC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { PcoClient } from "../client";
|
|
2
|
+
interface PersonAttributes {
|
|
3
|
+
given_name: string;
|
|
4
|
+
first_name: string;
|
|
5
|
+
nickname: string;
|
|
6
|
+
middle_name: string;
|
|
7
|
+
last_name: string;
|
|
8
|
+
birthdate: string;
|
|
9
|
+
anniversary: string;
|
|
10
|
+
grade: number;
|
|
11
|
+
child: boolean;
|
|
12
|
+
graduation_year: number;
|
|
13
|
+
site_administrator: boolean;
|
|
14
|
+
accounting_administrator: boolean;
|
|
15
|
+
people_permissions: string;
|
|
16
|
+
gender: string;
|
|
17
|
+
membership: string;
|
|
18
|
+
inactivated_at: string;
|
|
19
|
+
status: string;
|
|
20
|
+
medical_notes: string;
|
|
21
|
+
mfa_configured: boolean;
|
|
22
|
+
created_at: string;
|
|
23
|
+
updated_at: string;
|
|
24
|
+
avatar: string;
|
|
25
|
+
name: string;
|
|
26
|
+
demographic_avatar_url: string;
|
|
27
|
+
directory_status: string;
|
|
28
|
+
can_create_forms: boolean;
|
|
29
|
+
can_email_lists: boolean;
|
|
30
|
+
passed_background_check: boolean;
|
|
31
|
+
school_type: string;
|
|
32
|
+
remote_id: number;
|
|
33
|
+
directory_shared_info: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface RelationshipData {
|
|
36
|
+
type: string;
|
|
37
|
+
id: string;
|
|
38
|
+
}
|
|
39
|
+
interface PersonRelationships {
|
|
40
|
+
primary_campus: {
|
|
41
|
+
data: RelationshipData;
|
|
42
|
+
};
|
|
43
|
+
gender: {
|
|
44
|
+
data: RelationshipData;
|
|
45
|
+
};
|
|
46
|
+
[key: string]: {
|
|
47
|
+
data: RelationshipData;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface Person {
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
attributes: PersonAttributes;
|
|
54
|
+
relationships: PersonRelationships;
|
|
55
|
+
}
|
|
56
|
+
interface PeopleResponse {
|
|
57
|
+
data: Person[];
|
|
58
|
+
included?: Person[];
|
|
59
|
+
meta: {
|
|
60
|
+
total_count: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export declare class PcoPeople extends PcoClient {
|
|
64
|
+
getPerson(): Promise<PeopleResponse>;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PcoPeople = void 0;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
var CanInclude;
|
|
15
|
+
(function (CanInclude) {
|
|
16
|
+
CanInclude["addresses"] = "addresses";
|
|
17
|
+
CanInclude["emails"] = "emails";
|
|
18
|
+
CanInclude["field_data"] = "field_data";
|
|
19
|
+
CanInclude["households"] = "households";
|
|
20
|
+
CanInclude["inactive_reason"] = "inactive_reason";
|
|
21
|
+
CanInclude["marital_status"] = "marital_status";
|
|
22
|
+
CanInclude["name_prefix"] = "name_prefix";
|
|
23
|
+
CanInclude["name_suffix"] = "name_suffix";
|
|
24
|
+
CanInclude["organization"] = "organization";
|
|
25
|
+
CanInclude["person_apps"] = "person_apps";
|
|
26
|
+
CanInclude["phone_numbers"] = "phone_numbers";
|
|
27
|
+
CanInclude["platform_notifications"] = "platform_notifications";
|
|
28
|
+
CanInclude["primary_campus"] = "primary_campus";
|
|
29
|
+
CanInclude["school"] = "school";
|
|
30
|
+
CanInclude["social_profiles"] = "social_profiles";
|
|
31
|
+
})(CanInclude || (CanInclude = {}));
|
|
32
|
+
class PcoPeople extends client_1.PcoClient {
|
|
33
|
+
getPerson() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return yield this.request(`/people/v2/people${this.buildQuery()}`);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.PcoPeople = PcoPeople;
|
|
40
|
+
//# sourceMappingURL=people.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"people.js","sourceRoot":"","sources":["../../src/modules/people.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAsC;AAoEtC,IAAK,UAgBJ;AAhBD,WAAK,UAAU;IACX,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;IACjB,uCAAyB,CAAA;IACzB,uCAAyB,CAAA;IACzB,iDAAmC,CAAA;IACnC,+CAAiC,CAAA;IACjC,yCAA2B,CAAA;IAC3B,yCAA2B,CAAA;IAC3B,2CAA6B,CAAA;IAC7B,yCAA2B,CAAA;IAC3B,6CAA+B,CAAA;IAC/B,+DAAiD,CAAA;IACjD,+CAAiC,CAAA;IACjC,+BAAiB,CAAA;IACjB,iDAAmC,CAAA;AACvC,CAAC,EAhBI,UAAU,KAAV,UAAU,QAgBd;AAGD,MAAa,SAAU,SAAQ,kBAAS;IACvB,SAAS;;YAClB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,IAAI,CAAC,UAAU,EAAE,EAAE,CAAmB,CAAC;QACzF,CAAC;KAAA;CACJ;AAJD,8BAIC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publishing.js","sourceRoot":"","sources":["../../src/modules/publishing.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.js","sourceRoot":"","sources":["../../src/modules/services.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/modules/webhooks.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAOA,uCAAuC"}
|
package/package.json
CHANGED
package/src/client.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Planning Center API client with OAuth
|
|
3
|
+
*/
|
|
4
|
+
export interface PcoClientConfigOAuth {
|
|
5
|
+
token: string;
|
|
6
|
+
clientId: string;
|
|
7
|
+
clientSecret: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
customApiBaseUrl?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for the Planning Center API client with a personal access token
|
|
16
|
+
*/
|
|
17
|
+
export interface PcoClientConfigPersonalAccessToken {
|
|
18
|
+
personalAccessToken: string;
|
|
19
|
+
appId: string;
|
|
20
|
+
customApiBaseUrl?: string;
|
|
21
|
+
version?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export abstract class PcoClient {
|
|
25
|
+
private customApiBaseUrl: string | boolean;
|
|
26
|
+
private version: string | undefined;
|
|
27
|
+
private authentication: string;
|
|
28
|
+
|
|
29
|
+
private includes: string[] = [];
|
|
30
|
+
private filters: { [key: string]: any } = {};
|
|
31
|
+
private order: { field: string, symbol: string } = { field: 'created_at', symbol: '' };
|
|
32
|
+
private pagination: { limit: number, offset: number } = { limit: 10, offset: 0 };
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
// Constructors
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create an instance of the Planning Center API client with a personal access token
|
|
40
|
+
* @param personalAccessToken Personal access token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
41
|
+
* @param appId Application ID - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
42
|
+
* @param customApiBaseUrl Custom API base URL (optional)
|
|
43
|
+
* @param version API version (default: 2024-06-09) (optional) {@link https://developer.planning.center/docs/#/overview/versioning}
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const client = new ApiClient({
|
|
47
|
+
* personalAccessToken,
|
|
48
|
+
* appId
|
|
49
|
+
* } as PcoClientConfigPersonalAccessToken);
|
|
50
|
+
* ```
|
|
51
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
52
|
+
*/
|
|
53
|
+
constructor({ personalAccessToken, appId, customApiBaseUrl, version }: PcoClientConfigPersonalAccessToken)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create an instance of the Planning Center API client with OAuth
|
|
57
|
+
* @param token Access token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
58
|
+
* @param clientId Client ID - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
59
|
+
* @param clientSecret Client secret - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
60
|
+
* @param refreshToken Refresh token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
61
|
+
* @param expiresAt Expiration time of the token - Use {@link PcoClient.getExpiration} to calculate
|
|
62
|
+
* @param customApiBaseUrl Custom API base URL (optional)
|
|
63
|
+
* @param version API version (default: 2024-06-09) (optional) {@link https://developer.planning.center/docs/#/overview/versioning}
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const client = new ApiClient({
|
|
67
|
+
* token,
|
|
68
|
+
* clientId,
|
|
69
|
+
* clientSecret,
|
|
70
|
+
* refreshToken,
|
|
71
|
+
* expiresAt
|
|
72
|
+
* } as PcoClientConfigOAuth);
|
|
73
|
+
* ```
|
|
74
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
75
|
+
*/
|
|
76
|
+
constructor({ token, clientId, clientSecret, refreshToken, expiresAt, customApiBaseUrl, version }: PcoClientConfigOAuth)
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Implements the overloads for the constructor
|
|
80
|
+
*/
|
|
81
|
+
constructor(config: PcoClientConfigPersonalAccessToken | PcoClientConfigOAuth) {
|
|
82
|
+
if ('version' in config && config.version) {
|
|
83
|
+
if (!config.version.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
84
|
+
throw new Error('Invalid version format');
|
|
85
|
+
}
|
|
86
|
+
this.version = config.version;
|
|
87
|
+
}
|
|
88
|
+
if ('personalAccessToken' in config) {
|
|
89
|
+
this.authentication = `Basic ${btoa(config.appId + ':' + config.personalAccessToken)}`;
|
|
90
|
+
this.customApiBaseUrl = config.customApiBaseUrl ?? false;
|
|
91
|
+
} else if ('token' in config) {
|
|
92
|
+
this.authentication = `Bearer ${config.token}`;
|
|
93
|
+
this.customApiBaseUrl = config.customApiBaseUrl ?? false;
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error('Invalid configuration');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//
|
|
100
|
+
// Static and internal methods
|
|
101
|
+
//
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get the expiration time for a token when given a lifespan
|
|
105
|
+
* @param expiresIn Time in seconds until the token expires
|
|
106
|
+
* @returns The expiration time in milliseconds
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const expiration = ApiClient.getExpiration(7200);
|
|
110
|
+
* const client = new ApiClient({
|
|
111
|
+
* ...
|
|
112
|
+
* expiresAt: expiration
|
|
113
|
+
* } as PcoClientConfigOAuth);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
public static getExpiration(expiresIn: number): number {
|
|
117
|
+
return Date.now() + expiresIn * 1000;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Format a date to be used in a request
|
|
122
|
+
* @param date Date to format
|
|
123
|
+
* @returns Formatted date string
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const date = new Date();
|
|
127
|
+
* const formattedDate: string = ApiClient.formatDate(date);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
protected static formatDate(date: Date): string {
|
|
131
|
+
// Nothing much going on here, but may be useful in the future
|
|
132
|
+
return date.toISOString();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Make a request to the Planning Center API
|
|
137
|
+
* @param endpoint The endpoint to request
|
|
138
|
+
* @param method The HTTP method to use (default: GET)
|
|
139
|
+
* @param body The body of the request (optional)
|
|
140
|
+
* @param options Request options (optional)
|
|
141
|
+
* @returns The response from the API
|
|
142
|
+
* @throws Error if the request fails
|
|
143
|
+
*/
|
|
144
|
+
protected async request(endpoint: string, options: RequestInit = {}): Promise<any> {
|
|
145
|
+
if (this.version) {
|
|
146
|
+
options.headers = {
|
|
147
|
+
...options.headers,
|
|
148
|
+
'X-PCO-API-Version': this.version
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const apiBaseUrl = this.customApiBaseUrl ? this.customApiBaseUrl : 'https://api.planningcenteronline.com';
|
|
152
|
+
const response = await fetch(`${apiBaseUrl}${endpoint}`, {
|
|
153
|
+
...options,
|
|
154
|
+
headers: {
|
|
155
|
+
...options.headers,
|
|
156
|
+
'Content-Type': 'application/json',
|
|
157
|
+
Authorization: this.authentication
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
throw new Error(`API request failed with status ${response.status}\n${response.statusText}\nMore details: https://developer.planning.center/docs/#/overview/errors`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return await response.json();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Client methods for manual requests
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get a custom endpoint from the API. This is useful for endpoints that are not covered by the client methods
|
|
175
|
+
* @param endpoint The endpoint to request with the base slash
|
|
176
|
+
* @returns The response from the API
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const data = await client.get('/people/v2');
|
|
180
|
+
* ```
|
|
181
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
182
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
183
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
184
|
+
*/
|
|
185
|
+
public get(endpoint: string) {
|
|
186
|
+
return this.request(`${endpoint}${this.buildQuery()}`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Create a new record in the API at the given endpoint. This is useful for POST requests not covered by the client methods
|
|
191
|
+
* @param endpoint The endpoint to request with the base slash
|
|
192
|
+
* @param body The body of the request
|
|
193
|
+
* @returns The response from the API
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const data = await client.post('/people/v2', { name: 'John Doe' });
|
|
197
|
+
* ```
|
|
198
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
199
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
200
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
201
|
+
*/
|
|
202
|
+
public post(endpoint: string, body: any) {
|
|
203
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'POST', body: JSON.stringify(body) });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Update a record in the API at the given endpoint. This is useful for PATCH requests not covered by the client methods
|
|
208
|
+
* @param endpoint The endpoint to request with the base slash
|
|
209
|
+
* @param body The body of the request
|
|
210
|
+
* @returns The response from the API
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const data = await client.patch('/people/v2/1', { name: 'Jane Doe' });
|
|
214
|
+
* ```
|
|
215
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
216
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
217
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
218
|
+
*/
|
|
219
|
+
public patch(endpoint: string, body: any) {
|
|
220
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'PATCH', body: JSON.stringify(body) });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Delete a record in the API at the given endpoint. This is useful for DELETE requests not covered by the client methods
|
|
225
|
+
* @param endpoint The endpoint to request with the base slash
|
|
226
|
+
* @returns The response from the API
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const data = await client.delete('/people/v2/1');
|
|
230
|
+
* ```
|
|
231
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
232
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
233
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
234
|
+
*/
|
|
235
|
+
public delete(endpoint: string) {
|
|
236
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'DELETE' });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
//
|
|
240
|
+
// Query builder methods
|
|
241
|
+
//
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Include related records in the response
|
|
245
|
+
* @param relations The relations to include
|
|
246
|
+
* @returns The client instance
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const data = await client.include(['emails']).getPerson();
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
public include(relations: string[]) {
|
|
253
|
+
this.includes = relations;
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Filter the response by a field
|
|
259
|
+
* @param field The field to filter by
|
|
260
|
+
* @param operator The operator to use in the filter
|
|
261
|
+
* @param value The value to filter by
|
|
262
|
+
* @returns The client instance
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const data = await client.where('search_name_or_email', '=', 'hello@example.com').getPerson();
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
public where(field: string, operator: string, value: any) {
|
|
269
|
+
this.filters[field] = { operator, value };
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Order the response by a field
|
|
275
|
+
* @param field The field to order by
|
|
276
|
+
* @param direction The direction to order in (default: desc)
|
|
277
|
+
* @returns The client instance
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const data = await client.orderBy('created_at', 'asc').getPerson();
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
public orderBy(field: string, direction: 'asc' | 'desc' = 'desc') {
|
|
284
|
+
let symbol = '';
|
|
285
|
+
switch (direction) {
|
|
286
|
+
case 'asc':
|
|
287
|
+
symbol = '-';
|
|
288
|
+
break;
|
|
289
|
+
case 'desc':
|
|
290
|
+
symbol = '';
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
this.order = { field, symbol };
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Paginate the response
|
|
299
|
+
* @param limit The number of records to return
|
|
300
|
+
* @param offset The number of records to skip
|
|
301
|
+
* @returns The client instance
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const data = await client.paginate(10, 0).getPerson();
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
public paginate(limit: number, offset: number) {
|
|
308
|
+
this.pagination = { limit, offset };
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Build the query string from the includes, filters, order, and pagination
|
|
314
|
+
* @returns The query string
|
|
315
|
+
*/
|
|
316
|
+
protected buildQuery() {
|
|
317
|
+
let query = `?include=${this.includes.join(',')}`;
|
|
318
|
+
for (let field in this.filters) {
|
|
319
|
+
const filter = this.filters[field];
|
|
320
|
+
query += `&where[${field}]${filter.operator}${filter.value}`;
|
|
321
|
+
}
|
|
322
|
+
query += `&order=${this.order.symbol}${this.order.field}`;
|
|
323
|
+
query += `&limit=${this.pagination.limit}&offset=${this.pagination.offset}`;
|
|
324
|
+
|
|
325
|
+
// clean up the attributes
|
|
326
|
+
this.includes = [];
|
|
327
|
+
this.filters = {};
|
|
328
|
+
this.order = { field: 'created_at', symbol: '' };
|
|
329
|
+
this.pagination = { limit: 10, offset: 0 };
|
|
330
|
+
|
|
331
|
+
return query;
|
|
332
|
+
}
|
|
333
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, test } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { PcoPeople, PcoClientConfigOAuth, PcoClientConfigPersonalAccessToken } from './index';
|
|
3
3
|
|
|
4
|
-
test('
|
|
5
|
-
expect(
|
|
6
|
-
}
|
|
4
|
+
test('PcoPeople is exported', () => {
|
|
5
|
+
expect(PcoPeople).toBeDefined();
|
|
6
|
+
}
|
|
7
|
+
);
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return 'Hello World';
|
|
4
|
-
}
|
|
1
|
+
import { PcoPeople } from './modules/people';
|
|
2
|
+
import { PcoClientConfigOAuth, PcoClientConfigPersonalAccessToken } from './client';
|
|
5
3
|
|
|
6
|
-
export
|
|
4
|
+
export { PcoPeople };
|
|
5
|
+
export type { PcoClientConfigOAuth, PcoClientConfigPersonalAccessToken };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PcoClient } from "../client";
|
|
2
|
+
|
|
3
|
+
interface PersonAttributes {
|
|
4
|
+
given_name: string;
|
|
5
|
+
first_name: string;
|
|
6
|
+
nickname: string;
|
|
7
|
+
middle_name: string;
|
|
8
|
+
last_name: string;
|
|
9
|
+
birthdate: string;
|
|
10
|
+
anniversary: string;
|
|
11
|
+
grade: number;
|
|
12
|
+
child: boolean;
|
|
13
|
+
graduation_year: number;
|
|
14
|
+
site_administrator: boolean;
|
|
15
|
+
accounting_administrator: boolean;
|
|
16
|
+
people_permissions: string;
|
|
17
|
+
gender: string;
|
|
18
|
+
membership: string;
|
|
19
|
+
inactivated_at: string;
|
|
20
|
+
status: string;
|
|
21
|
+
medical_notes: string;
|
|
22
|
+
mfa_configured: boolean;
|
|
23
|
+
created_at: string;
|
|
24
|
+
updated_at: string;
|
|
25
|
+
avatar: string;
|
|
26
|
+
name: string;
|
|
27
|
+
demographic_avatar_url: string;
|
|
28
|
+
directory_status: string;
|
|
29
|
+
can_create_forms: boolean;
|
|
30
|
+
can_email_lists: boolean;
|
|
31
|
+
passed_background_check: boolean;
|
|
32
|
+
school_type: string;
|
|
33
|
+
remote_id: number;
|
|
34
|
+
directory_shared_info: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface RelationshipData {
|
|
38
|
+
type: string;
|
|
39
|
+
id: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface PersonRelationships {
|
|
43
|
+
primary_campus: {
|
|
44
|
+
data: RelationshipData;
|
|
45
|
+
};
|
|
46
|
+
gender: {
|
|
47
|
+
data: RelationshipData;
|
|
48
|
+
};
|
|
49
|
+
[key: string]: {
|
|
50
|
+
data: RelationshipData;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface Person {
|
|
55
|
+
type: string;
|
|
56
|
+
id: string;
|
|
57
|
+
attributes: PersonAttributes;
|
|
58
|
+
relationships: PersonRelationships;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface PeopleResponse {
|
|
62
|
+
data: Person[];
|
|
63
|
+
included?: Person[];
|
|
64
|
+
meta: {
|
|
65
|
+
total_count: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
enum CanInclude {
|
|
70
|
+
addresses = 'addresses',
|
|
71
|
+
emails = 'emails',
|
|
72
|
+
field_data = 'field_data',
|
|
73
|
+
households = 'households',
|
|
74
|
+
inactive_reason = 'inactive_reason',
|
|
75
|
+
marital_status = 'marital_status',
|
|
76
|
+
name_prefix = 'name_prefix',
|
|
77
|
+
name_suffix = 'name_suffix',
|
|
78
|
+
organization = 'organization',
|
|
79
|
+
person_apps = 'person_apps',
|
|
80
|
+
phone_numbers = 'phone_numbers',
|
|
81
|
+
platform_notifications = 'platform_notifications',
|
|
82
|
+
primary_campus = 'primary_campus',
|
|
83
|
+
school = 'school',
|
|
84
|
+
social_profiles = 'social_profiles',
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export class PcoPeople extends PcoClient {
|
|
89
|
+
public async getPerson(): Promise<PeopleResponse> {
|
|
90
|
+
return await this.request(`/people/v2/people${this.buildQuery()}`) as PeopleResponse;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|