Skip to content

Repository files navigation

CongregationKit

A Swift SDK for working with Salesforce church data, made for The King's Temple Church (TKT Church).

CongregationKit connects apps and servers to The King's Temple Church Salesforce org. New code should use TKT API v2 (/services/apexrest/v2/*) through typed handlers. Legacy v1 list routes remain as deprecated shims.

What does it do?

  • Lets you log in to Salesforce using your username and password
  • Lets you fetch and work with church member data from Salesforce
  • Lets you choose which parts of member data you want (like contact info, employment, marital, or discipleship info)
  • Works with async/await in Swift
  • Can be used on macOS or iOS, and with server frameworks like Vapor

Installation

Swift Package Manager

Add CongregationKit to your Package.swift:

dependencies: [
    .package(url: "https://github.com/tktchurch/CongregationKit.git", from: "1.0.0")
]

Then depend on the product you need:

.target(
    name: "MyApp",
    dependencies: [
        .product(name: "CongregationKit", package: "CongregationKit")
    ]
)

1. Set up your Salesforce credentials

import CongregationKit

let credentials = SalesforceCredentials(
    clientId: "your_client_id",
    clientSecret: "your_client_secret",
    username: "your_salesforce_username",
    password: "your_salesforce_password"
)

2. Create the client

import AsyncHTTPClient

let httpClient = HTTPClient.shared
let congregation = try await CongregationKit(httpClient: httpClient, credentials: credentials)

3. Fetch members (choose what info you want)

import SalesforceClient // for MemberExpand

let expanded: [MemberExpand] = [
    .contactInformation,
    .employmentInformation,
    .maritalInformation,
    .discipleshipInformation
]
let response = try await congregation.salesforceClient.members.fetchAll(
    accessToken: congregation.salesforceClient.auth.accessToken,
    instanceUrl: congregation.salesforceClient.auth.instanceUrl,
    pageNumber: 1,
    pageSize: 50,
    expanded: expanded
)
for member in response.members {
    print(member.memberName)
    print(member.contactInformation?.email)
    print(member.employmentInformation?.occupation)
    print(member.maritalInformation?.maritalStatus)
    print(member.discipleshipInformation?.waterBaptism?.date)
}

4. Fetch a specific member

let member = try await congregation.salesforceClient.members.fetch(
    memberId: someMemberID,
    accessToken: congregation.salesforceClient.auth.accessToken,
    instanceUrl: congregation.salesforceClient.auth.instanceUrl,
    expanded: [.discipleshipInformation, .contactInformation]
)
if let discipleship = member.discipleshipInformation {
    print(discipleship.waterBaptism?.date)
}

What is field expansion?

When you fetch members, you can choose which parts of their data you want by passing an array of MemberExpand values. If you don't ask for a part, it will be nil in the result. This makes things faster and keeps your app simple.

Expansion Property on Member
.contactInformation member.contactInformation
.employmentInformation member.employmentInformation
.maritalInformation member.maritalInformation
.discipleshipInformation member.discipleshipInformation

Error Handling

  • SalesforceAuthError (login or network problems)
  • MemberError (not found, invalid data, etc.)

Requirements

  • Swift 6.0+
  • macOS 14.0+ / iOS 15.0+
  • Xcode 15.0+

License

MIT License. See LICENSE for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Support

For support and questions, please open an issue on GitHub or contact the development team.

About

Swift SDK for type-safe, reliable Salesforce church data management and integration.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages