@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
|
@@ -4,7 +4,6 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
6
|
- main
|
|
7
|
-
- '*beta*'
|
|
8
7
|
tags:
|
|
9
8
|
- 'v*'
|
|
10
9
|
paths-ignore:
|
|
@@ -36,7 +35,7 @@ jobs:
|
|
|
36
35
|
publish:
|
|
37
36
|
needs: build-and-test
|
|
38
37
|
runs-on: ubuntu-latest
|
|
39
|
-
if : github.repository_owner == 'mackenly' &&
|
|
38
|
+
if : github.repository_owner == 'mackenly' && github.ref == 'refs/heads/main'
|
|
40
39
|
permissions:
|
|
41
40
|
contents: write
|
|
42
41
|
packages: write
|
|
@@ -58,8 +57,6 @@ jobs:
|
|
|
58
57
|
minor-wording: 'bump-minor,adds,Adds,new'
|
|
59
58
|
major-wording: 'bump-major,MAJOR,removes,Removes,delete,Delete'
|
|
60
59
|
patch-wording: 'bump-patch,fixes,Fixes,bugfix,Bugfix,patch,hotfix,Hotfix'
|
|
61
|
-
preid: ${{ contains(github.ref, 'beta') && 'beta' || '' }}
|
|
62
|
-
tag-suffix: ${{ contains(github.ref, 'beta') && '-beta' || '' }}
|
|
63
60
|
env:
|
|
64
61
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
65
62
|
- name: Publish to GitHub Packages
|
|
@@ -77,12 +74,7 @@ jobs:
|
|
|
77
74
|
env:
|
|
78
75
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
79
76
|
- name: Publish to npm
|
|
80
|
-
run:
|
|
81
|
-
if [[ "${{ github.ref }}" == *beta* ]]; then
|
|
82
|
-
npm publish --access public --tag beta
|
|
83
|
-
else
|
|
84
|
-
npm publish --access public --tag latest
|
|
85
|
-
fi
|
|
77
|
+
run: npm publish --access public --tag latest
|
|
86
78
|
env:
|
|
87
79
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
88
80
|
- name: Create GitHub Release
|
|
@@ -94,4 +86,4 @@ jobs:
|
|
|
94
86
|
release_name: Release ${{ steps.versioning.outputs.newTag }}
|
|
95
87
|
body: ${{ steps.versioning.outputs.changelog }}
|
|
96
88
|
draft: false
|
|
97
|
-
prerelease:
|
|
89
|
+
prerelease: false
|
package/README.md
CHANGED
|
@@ -1,2 +1,53 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Planning Center Kit
|
|
2
|
+
ORM for Planning Center Online's APIs
|
|
3
|
+
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> This project is very much a work in progress and is not yet ready for production use (unless you're feeling adventurous!). Please check back later for updates.
|
|
6
|
+
|
|
7
|
+
While [Planning Center Online](https://www.planningcenter.com/developers) (PCO) offers a robust set of APIs, working with them can be cumbersome and time-consuming. This library aims to simplify the process of working with PCO's APIs by providing a flexible ORM that allows you to interact with the APIs in a more intuitive way using typed objects and methods.
|
|
8
|
+
|
|
9
|
+
If you don't use TypeScript, don't worry! This library is written in TypeScript but works just as well in plain JavaScript.
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Sponsors](#sponsors)
|
|
16
|
+
- [Disclaimer](#disclaimer)
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
- [ ] Flexible ORM for PCO APIs - in progress
|
|
20
|
+
- [ ] More..
|
|
21
|
+
- [ ] React integration
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
```bash
|
|
25
|
+
npm install @mackenly/planningcenterkit
|
|
26
|
+
```
|
|
27
|
+
Or use yarn
|
|
28
|
+
```bash
|
|
29
|
+
yarn add @mackenly/planningcenterkit
|
|
30
|
+
```
|
|
31
|
+
Or use pnpm
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add @mackenly/planningcenterkit
|
|
34
|
+
```
|
|
35
|
+
Currently published on npm and GitHub Packages. Plans to add to other package registries in the future.
|
|
36
|
+
|
|
37
|
+
## Quick Start Usage
|
|
38
|
+
```javascript
|
|
39
|
+
// coming soon...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
For the full documentation, please visit the [documentation site](https://planningcenterkit.mackenly.com). There you'll find detailed information on how to use the library, including examples and API references.
|
|
44
|
+
|
|
45
|
+
## Sponsors
|
|
46
|
+
[<img alt="Tricities Media Group" src="https://tricitiesmediagroup.com/TMG-black-1080x247.png" width="250" style="background-color: white">](https://tricitiesmediagroup.com?utm_source=planningcenterkit&utm_medium=github&utm_campaign=sponsorship)
|
|
47
|
+
|
|
48
|
+
*Interested in getting your company's logo displayed here and support the project? [Contact me](https://tricitiesmediagroup.com/contact) to discuss sponsorship opportunities.*
|
|
49
|
+
|
|
50
|
+
## Disclaimer
|
|
51
|
+
This project is in no way supported or affiliated with Planning Center Online. It is a personal project that I am working on in my free time. As such, continued development is dependent on my availability, financial incentives, and interest in the project. If you would like to see this project maintained and further developed I encourage you to help contribute either with code or fiscally through [GitHub Sponsors](https://github.com/sponsors/mackenly). If you work at Planning Center and would like to support this project, I would be happy to discuss ways in which we could work together.
|
|
52
|
+
|
|
53
|
+
Copyright 2024 Tricities Media Group LLC
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
* Configuration for the Planning Center API client with a personal access token
|
|
15
|
+
*/
|
|
16
|
+
export interface PcoClientConfigPersonalAccessToken {
|
|
17
|
+
personalAccessToken: string;
|
|
18
|
+
appId: string;
|
|
19
|
+
customApiBaseUrl?: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare abstract class PcoClient {
|
|
23
|
+
private customApiBaseUrl;
|
|
24
|
+
private version;
|
|
25
|
+
private authentication;
|
|
26
|
+
private includes;
|
|
27
|
+
private filters;
|
|
28
|
+
private order;
|
|
29
|
+
private pagination;
|
|
30
|
+
/**
|
|
31
|
+
* Create an instance of the Planning Center API client with a personal access token
|
|
32
|
+
* @param personalAccessToken Personal access token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
33
|
+
* @param appId Application ID - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
34
|
+
* @param customApiBaseUrl Custom API base URL (optional)
|
|
35
|
+
* @param version API version (default: 2024-06-09) (optional) {@link https://developer.planning.center/docs/#/overview/versioning}
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = new ApiClient({
|
|
39
|
+
* personalAccessToken,
|
|
40
|
+
* appId
|
|
41
|
+
* } as PcoClientConfigPersonalAccessToken);
|
|
42
|
+
* ```
|
|
43
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
44
|
+
*/
|
|
45
|
+
constructor({ personalAccessToken, appId, customApiBaseUrl, version }: PcoClientConfigPersonalAccessToken);
|
|
46
|
+
/**
|
|
47
|
+
* Create an instance of the Planning Center API client with OAuth
|
|
48
|
+
* @param token Access token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
49
|
+
* @param clientId Client ID - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
50
|
+
* @param clientSecret Client secret - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
51
|
+
* @param refreshToken Refresh token - see {@link https://developer.planning.center/docs/#/overview/authentication}
|
|
52
|
+
* @param expiresAt Expiration time of the token - Use {@link PcoClient.getExpiration} to calculate
|
|
53
|
+
* @param customApiBaseUrl Custom API base URL (optional)
|
|
54
|
+
* @param version API version (default: 2024-06-09) (optional) {@link https://developer.planning.center/docs/#/overview/versioning}
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const client = new ApiClient({
|
|
58
|
+
* token,
|
|
59
|
+
* clientId,
|
|
60
|
+
* clientSecret,
|
|
61
|
+
* refreshToken,
|
|
62
|
+
* expiresAt
|
|
63
|
+
* } as PcoClientConfigOAuth);
|
|
64
|
+
* ```
|
|
65
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
66
|
+
*/
|
|
67
|
+
constructor({ token, clientId, clientSecret, refreshToken, expiresAt, customApiBaseUrl, version }: PcoClientConfigOAuth);
|
|
68
|
+
/**
|
|
69
|
+
* Get the expiration time for a token when given a lifespan
|
|
70
|
+
* @param expiresIn Time in seconds until the token expires
|
|
71
|
+
* @returns The expiration time in milliseconds
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const expiration = ApiClient.getExpiration(7200);
|
|
75
|
+
* const client = new ApiClient({
|
|
76
|
+
* ...
|
|
77
|
+
* expiresAt: expiration
|
|
78
|
+
* } as PcoClientConfigOAuth);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
static getExpiration(expiresIn: number): number;
|
|
82
|
+
/**
|
|
83
|
+
* Format a date to be used in a request
|
|
84
|
+
* @param date Date to format
|
|
85
|
+
* @returns Formatted date string
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const date = new Date();
|
|
89
|
+
* const formattedDate: string = ApiClient.formatDate(date);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
protected static formatDate(date: Date): string;
|
|
93
|
+
/**
|
|
94
|
+
* Make a request to the Planning Center API
|
|
95
|
+
* @param endpoint The endpoint to request
|
|
96
|
+
* @param method The HTTP method to use (default: GET)
|
|
97
|
+
* @param body The body of the request (optional)
|
|
98
|
+
* @param options Request options (optional)
|
|
99
|
+
* @returns The response from the API
|
|
100
|
+
* @throws Error if the request fails
|
|
101
|
+
*/
|
|
102
|
+
protected request(endpoint: string, options?: RequestInit): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* Get a custom endpoint from the API. This is useful for endpoints that are not covered by the client methods
|
|
105
|
+
* @param endpoint The endpoint to request with the base slash
|
|
106
|
+
* @returns The response from the API
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const data = await client.get('/people/v2');
|
|
110
|
+
* ```
|
|
111
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
112
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
113
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
114
|
+
*/
|
|
115
|
+
get(endpoint: string): Promise<any>;
|
|
116
|
+
/**
|
|
117
|
+
* Create a new record in the API at the given endpoint. This is useful for POST requests not covered by the client methods
|
|
118
|
+
* @param endpoint The endpoint to request with the base slash
|
|
119
|
+
* @param body The body of the request
|
|
120
|
+
* @returns The response from the API
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const data = await client.post('/people/v2', { name: 'John Doe' });
|
|
124
|
+
* ```
|
|
125
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
126
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
127
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
128
|
+
*/
|
|
129
|
+
post(endpoint: string, body: any): Promise<any>;
|
|
130
|
+
/**
|
|
131
|
+
* Update a record in the API at the given endpoint. This is useful for PATCH requests not covered by the client methods
|
|
132
|
+
* @param endpoint The endpoint to request with the base slash
|
|
133
|
+
* @param body The body of the request
|
|
134
|
+
* @returns The response from the API
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const data = await client.patch('/people/v2/1', { name: 'Jane Doe' });
|
|
138
|
+
* ```
|
|
139
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
140
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
141
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
142
|
+
*/
|
|
143
|
+
patch(endpoint: string, body: any): Promise<any>;
|
|
144
|
+
/**
|
|
145
|
+
* Delete a record in the API at the given endpoint. This is useful for DELETE requests not covered by the client methods
|
|
146
|
+
* @param endpoint The endpoint to request with the base slash
|
|
147
|
+
* @returns The response from the API
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const data = await client.delete('/people/v2/1');
|
|
151
|
+
* ```
|
|
152
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
153
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
154
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
155
|
+
*/
|
|
156
|
+
delete(endpoint: string): Promise<any>;
|
|
157
|
+
/**
|
|
158
|
+
* Include related records in the response
|
|
159
|
+
* @param relations The relations to include
|
|
160
|
+
* @returns The client instance
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const data = await client.include(['emails']).getPerson();
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
include(relations: string[]): this;
|
|
167
|
+
/**
|
|
168
|
+
* Filter the response by a field
|
|
169
|
+
* @param field The field to filter by
|
|
170
|
+
* @param operator The operator to use in the filter
|
|
171
|
+
* @param value The value to filter by
|
|
172
|
+
* @returns The client instance
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const data = await client.where('search_name_or_email', '=', 'hello@example.com').getPerson();
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
where(field: string, operator: string, value: any): this;
|
|
179
|
+
/**
|
|
180
|
+
* Order the response by a field
|
|
181
|
+
* @param field The field to order by
|
|
182
|
+
* @param direction The direction to order in (default: desc)
|
|
183
|
+
* @returns The client instance
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const data = await client.orderBy('created_at', 'asc').getPerson();
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
orderBy(field: string, direction?: 'asc' | 'desc'): this;
|
|
190
|
+
/**
|
|
191
|
+
* Paginate the response
|
|
192
|
+
* @param limit The number of records to return
|
|
193
|
+
* @param offset The number of records to skip
|
|
194
|
+
* @returns The client instance
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const data = await client.paginate(10, 0).getPerson();
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
paginate(limit: number, offset: number): this;
|
|
201
|
+
/**
|
|
202
|
+
* Build the query string from the includes, filters, order, and pagination
|
|
203
|
+
* @returns The query string
|
|
204
|
+
*/
|
|
205
|
+
protected buildQuery(): string;
|
|
206
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
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.PcoClient = void 0;
|
|
13
|
+
class PcoClient {
|
|
14
|
+
/**
|
|
15
|
+
* Implements the overloads for the constructor
|
|
16
|
+
*/
|
|
17
|
+
constructor(config) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
this.includes = [];
|
|
20
|
+
this.filters = {};
|
|
21
|
+
this.order = { field: 'created_at', symbol: '' };
|
|
22
|
+
this.pagination = { limit: 10, offset: 0 };
|
|
23
|
+
if ('version' in config && config.version) {
|
|
24
|
+
if (!config.version.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
25
|
+
throw new Error('Invalid version format');
|
|
26
|
+
}
|
|
27
|
+
this.version = config.version;
|
|
28
|
+
}
|
|
29
|
+
if ('personalAccessToken' in config) {
|
|
30
|
+
this.authentication = `Basic ${btoa(config.appId + ':' + config.personalAccessToken)}`;
|
|
31
|
+
this.customApiBaseUrl = (_a = config.customApiBaseUrl) !== null && _a !== void 0 ? _a : false;
|
|
32
|
+
}
|
|
33
|
+
else if ('token' in config) {
|
|
34
|
+
this.authentication = `Bearer ${config.token}`;
|
|
35
|
+
this.customApiBaseUrl = (_b = config.customApiBaseUrl) !== null && _b !== void 0 ? _b : false;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Invalid configuration');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//
|
|
42
|
+
// Static and internal methods
|
|
43
|
+
//
|
|
44
|
+
/**
|
|
45
|
+
* Get the expiration time for a token when given a lifespan
|
|
46
|
+
* @param expiresIn Time in seconds until the token expires
|
|
47
|
+
* @returns The expiration time in milliseconds
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const expiration = ApiClient.getExpiration(7200);
|
|
51
|
+
* const client = new ApiClient({
|
|
52
|
+
* ...
|
|
53
|
+
* expiresAt: expiration
|
|
54
|
+
* } as PcoClientConfigOAuth);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static getExpiration(expiresIn) {
|
|
58
|
+
return Date.now() + expiresIn * 1000;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format a date to be used in a request
|
|
62
|
+
* @param date Date to format
|
|
63
|
+
* @returns Formatted date string
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const date = new Date();
|
|
67
|
+
* const formattedDate: string = ApiClient.formatDate(date);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
static formatDate(date) {
|
|
71
|
+
// Nothing much going on here, but may be useful in the future
|
|
72
|
+
return date.toISOString();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Make a request to the Planning Center API
|
|
76
|
+
* @param endpoint The endpoint to request
|
|
77
|
+
* @param method The HTTP method to use (default: GET)
|
|
78
|
+
* @param body The body of the request (optional)
|
|
79
|
+
* @param options Request options (optional)
|
|
80
|
+
* @returns The response from the API
|
|
81
|
+
* @throws Error if the request fails
|
|
82
|
+
*/
|
|
83
|
+
request(endpoint_1) {
|
|
84
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, options = {}) {
|
|
85
|
+
if (this.version) {
|
|
86
|
+
options.headers = Object.assign(Object.assign({}, options.headers), { 'X-PCO-API-Version': this.version });
|
|
87
|
+
}
|
|
88
|
+
const apiBaseUrl = this.customApiBaseUrl ? this.customApiBaseUrl : 'https://api.planningcenteronline.com';
|
|
89
|
+
const response = yield fetch(`${apiBaseUrl}${endpoint}`, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { 'Content-Type': 'application/json', Authorization: this.authentication }) }));
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(`API request failed with status ${response.status}\n${response.statusText}\nMore details: https://developer.planning.center/docs/#/overview/errors`);
|
|
92
|
+
}
|
|
93
|
+
return yield response.json();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//
|
|
97
|
+
// Client methods for manual requests
|
|
98
|
+
//
|
|
99
|
+
/**
|
|
100
|
+
* Get a custom endpoint from the API. This is useful for endpoints that are not covered by the client methods
|
|
101
|
+
* @param endpoint The endpoint to request with the base slash
|
|
102
|
+
* @returns The response from the API
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const data = await client.get('/people/v2');
|
|
106
|
+
* ```
|
|
107
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
108
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
109
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
110
|
+
*/
|
|
111
|
+
get(endpoint) {
|
|
112
|
+
return this.request(`${endpoint}${this.buildQuery()}`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a new record in the API at the given endpoint. This is useful for POST requests not covered by the client methods
|
|
116
|
+
* @param endpoint The endpoint to request with the base slash
|
|
117
|
+
* @param body The body of the request
|
|
118
|
+
* @returns The response from the API
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const data = await client.post('/people/v2', { name: 'John Doe' });
|
|
122
|
+
* ```
|
|
123
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
124
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
125
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
126
|
+
*/
|
|
127
|
+
post(endpoint, body) {
|
|
128
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'POST', body: JSON.stringify(body) });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Update a record in the API at the given endpoint. This is useful for PATCH requests not covered by the client methods
|
|
132
|
+
* @param endpoint The endpoint to request with the base slash
|
|
133
|
+
* @param body The body of the request
|
|
134
|
+
* @returns The response from the API
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const data = await client.patch('/people/v2/1', { name: 'Jane Doe' });
|
|
138
|
+
* ```
|
|
139
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
140
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
141
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
142
|
+
*/
|
|
143
|
+
patch(endpoint, body) {
|
|
144
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'PATCH', body: JSON.stringify(body) });
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Delete a record in the API at the given endpoint. This is useful for DELETE requests not covered by the client methods
|
|
148
|
+
* @param endpoint The endpoint to request with the base slash
|
|
149
|
+
* @returns The response from the API
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const data = await client.delete('/people/v2/1');
|
|
153
|
+
* ```
|
|
154
|
+
* @link https://developer.planning.center/docs/#/overview/authentication
|
|
155
|
+
* @link https://developer.planning.center/docs/#/overview/errors
|
|
156
|
+
* @link https://developer.planning.center/docs/#/overview/versioning
|
|
157
|
+
*/
|
|
158
|
+
delete(endpoint) {
|
|
159
|
+
return this.request(`${endpoint}${this.buildQuery()}`, { method: 'DELETE' });
|
|
160
|
+
}
|
|
161
|
+
//
|
|
162
|
+
// Query builder methods
|
|
163
|
+
//
|
|
164
|
+
/**
|
|
165
|
+
* Include related records in the response
|
|
166
|
+
* @param relations The relations to include
|
|
167
|
+
* @returns The client instance
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const data = await client.include(['emails']).getPerson();
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
include(relations) {
|
|
174
|
+
this.includes = relations;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Filter the response by a field
|
|
179
|
+
* @param field The field to filter by
|
|
180
|
+
* @param operator The operator to use in the filter
|
|
181
|
+
* @param value The value to filter by
|
|
182
|
+
* @returns The client instance
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const data = await client.where('search_name_or_email', '=', 'hello@example.com').getPerson();
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
where(field, operator, value) {
|
|
189
|
+
this.filters[field] = { operator, value };
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Order the response by a field
|
|
194
|
+
* @param field The field to order by
|
|
195
|
+
* @param direction The direction to order in (default: desc)
|
|
196
|
+
* @returns The client instance
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const data = await client.orderBy('created_at', 'asc').getPerson();
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
orderBy(field, direction = 'desc') {
|
|
203
|
+
let symbol = '';
|
|
204
|
+
switch (direction) {
|
|
205
|
+
case 'asc':
|
|
206
|
+
symbol = '-';
|
|
207
|
+
break;
|
|
208
|
+
case 'desc':
|
|
209
|
+
symbol = '';
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
this.order = { field, symbol };
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Paginate the response
|
|
217
|
+
* @param limit The number of records to return
|
|
218
|
+
* @param offset The number of records to skip
|
|
219
|
+
* @returns The client instance
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const data = await client.paginate(10, 0).getPerson();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
paginate(limit, offset) {
|
|
226
|
+
this.pagination = { limit, offset };
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Build the query string from the includes, filters, order, and pagination
|
|
231
|
+
* @returns The query string
|
|
232
|
+
*/
|
|
233
|
+
buildQuery() {
|
|
234
|
+
let query = `?include=${this.includes.join(',')}`;
|
|
235
|
+
for (let field in this.filters) {
|
|
236
|
+
const filter = this.filters[field];
|
|
237
|
+
query += `&where[${field}]${filter.operator}${filter.value}`;
|
|
238
|
+
}
|
|
239
|
+
query += `&order=${this.order.symbol}${this.order.field}`;
|
|
240
|
+
query += `&limit=${this.pagination.limit}&offset=${this.pagination.offset}`;
|
|
241
|
+
// clean up the attributes
|
|
242
|
+
this.includes = [];
|
|
243
|
+
this.filters = {};
|
|
244
|
+
this.order = { field: 'created_at', symbol: '' };
|
|
245
|
+
this.pagination = { limit: 10, offset: 0 };
|
|
246
|
+
return query;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.PcoClient = PcoClient;
|
|
250
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mapp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|
|
2
|
-
|
|
1
|
+
import { PcoPeople } from './modules/people';
|
|
2
|
+
import { PcoClientConfigOAuth, PcoClientConfigPersonalAccessToken } from './client';
|
|
3
|
+
export { PcoPeople };
|
|
4
|
+
export type { PcoClientConfigOAuth, PcoClientConfigPersonalAccessToken };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return 'Hello World';
|
|
7
|
-
}
|
|
8
|
-
exports.run = run;
|
|
9
|
-
exports.default = run;
|
|
3
|
+
exports.PcoPeople = void 0;
|
|
4
|
+
const people_1 = require("./modules/people");
|
|
5
|
+
Object.defineProperty(exports, "PcoPeople", { enumerable: true, get: function () { return people_1.PcoPeople; } });
|
|
10
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAGpC,0FAHA,kBAAS,OAGA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalendarService = void 0;
|
|
4
|
+
class CalendarService {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.CalendarService = CalendarService;
|
|
10
|
+
// Similar modules for Check-ins, Giving, Groups, People, Publishing, Services
|
|
11
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../src/modules/calendar.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAGxB,YAAY,MAAiB;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAND,0CAMC;AAED,8EAA8E"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkins.js","sourceRoot":"","sources":["../../src/modules/checkins.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"giving.js","sourceRoot":"","sources":["../../src/modules/giving.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
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.PcoGroups = void 0;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
class PcoGroups extends client_1.PcoClient {
|
|
15
|
+
getGroups() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.PcoGroups = PcoGroups;
|
|
22
|
+
//# sourceMappingURL=groups.js.map
|