Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .changeset/source-connectors.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'@open-iga/aws': patch
'@open-iga/aws-sink': patch
---

Differentiate source and sink connector to support onboarding HR systems
Differentiate source and sink connector to support onboarding HR systems
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="@open-iga/aws@$(jq -r .version connectors/aws/package.json)"
TAG="@open-iga/aws-sink@$(jq -r .version connectors/aws/package.json)"
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists; nothing to do."
exit 0
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ against the connector SDK, which compiles them to WASM modules using [Extism](ht

This is a [Bun workspaces](https://bun.sh/docs/install/workspaces) monorepo.

| Path | Package | Role |
| ------------------------ | ------------------------- | -------------------------------------------------------------------------------- |
| `packages/connector-sdk` | `@open-iga/connector-sdk` | Build toolchain + runtime that connector authors depend on; compiles TS to WASM. |
| `connectors/aws` | `aws` | AWS connector built on the SDK — account actions (IAM users) and entitlements. |
| Path | Package | Role |
| ---------------------------- | --------------------------- | -------------------------------------------------------------------------------- |
| `packages/connector-sdk` | `@open-iga/connector-sdk` | Build toolchain + runtime that connector authors depend on; compiles TS to WASM. |
| `connectors/aws` | `@open-iga/aws-sink` | AWS connector built on the SDK — account actions (IAM users) and entitlements. |
| `source-connectors/personio` | `@open-iga/personio-source` | Personio source connector — lists employees. |

## Getting started

Expand Down Expand Up @@ -59,6 +60,3 @@ See `connectors/aws` for a complete reference implementation.
- Linear
- Mattermost
- Slack

- Following source connectors are planned to be added
- Personio
21 changes: 18 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectors/aws/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @open-iga/aws
# @open-iga/aws-sink

## 0.6.0

Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@open-iga/aws",
"name": "@open-iga/aws-sink",
"version": "0.6.0",
"type": "module",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"workspaces": {
"packages": [
"connectors/*",
"source-connectors/*",
"packages/*"
],
"catalog": {
Expand Down
15 changes: 15 additions & 0 deletions packages/connector-sdk/lib/test/mock-fetch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, it, expect } from 'bun:test';
import { createFetchProxy } from './mock-fetch.ts';

describe('createFetchProxy', () => {
it('should deny paths that do not match a path parameter endpoint', () => {
const proxy = createFetchProxy('http://localhost:1', {});
proxy.setAllowedEndpoint([
{ method: 'GET', url: 'https://domain.com/persons/{personId}/employments', description: 'endpoint' },
]);

for (const path of ['persons//employments', 'persons/1/2/employments', 'persons/1/salaries', 'persons/1']) {
expect(() => proxy.fetch(`https://domain.com/${path}`)).toThrow(/Denying the request/);
}
});
});
17 changes: 16 additions & 1 deletion packages/connector-sdk/lib/test/mock-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import type { ConnectorOperation } from '../iga/connector/validation-schema/conn
* */
const CONFIG_PLACEHOLDERS = /\{\{\s*([A-Za-z0-9_-]+)\s*\}\}/g;

// A `{name}` path segment in a declared endpoint matches any one segment. The URL parser escapes the braces.
const PATH_PARAMETER = /^%7B\w+%7D$/;

const matchesPath = (declaredPath: string, targetPath: string) => {
const declared = declaredPath.split('/');
const target = targetPath.split('/');

return (
declared.length === target.length &&
declared.every((segment, index) =>
PATH_PARAMETER.test(segment) ? target[index] !== '' : segment === target[index],
)
);
};

/**
* Host functionality: Every handler must specify the endpoint upfront. After approval, only these endpoint are allowed
* The same is applicable for testing
Expand Down Expand Up @@ -44,7 +59,7 @@ export const createFetchProxy = (mockUpstream: string, config: Record<string, un
targetMethod.toUpperCase() === method.toUpperCase() &&
userDefinedUrl.protocol === targetUrl.protocol &&
userDefinedUrl.host === targetUrl.host &&
userDefinedUrl.pathname === targetUrl.pathname
matchesPath(userDefinedUrl.pathname, targetUrl.pathname)
);
});

Expand Down
38 changes: 38 additions & 0 deletions source-connectors/personio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Personio

Source connector that reads employees from the [Personio v2 API](https://developer.personio.de/reference/auth).

## Configuration

| Key | Description |
| ------------------------ | -------------------------------------------- |
| `PERSONIO_CLIENT_ID` | Client id of the Personio API credential |
| `PERSONIO_CLIENT_SECRET` | Client secret of the Personio API credential |

Give the credential read access to persons and employments only. The connector requests no specific scope, so the
token gets every scope of the credential.

## Identities

`employee` / `list` returns 25 people per call.

| Identity field | Personio source |
| -------------------------------- | ------------------------------------------------------------------------------- |
| `identityId` | Person `id` |
| `email`, `firstname`, `lastname` | Person |
| `status` | Latest employment: `ONBOARDING` is `pending`, `ACTIVE` and `LEAVE` are `active` |
| `managerId` | Supervisor of the latest employment |
| `metadata` | Preferred name, position, org unit ids, employment start and end date |

Without an employment status, the person status is used. If both are unknown, the status is `pending`.

## Response checks

Every response is validated. The sync fails on an empty or unexpected response, so that nobody is treated as gone.
An email address that is not valid is left out.

## Host requirements

The Host must allow `{personId}` in an endpoint path to match one path segment.

Each page makes up to 27 requests: one token, one person list and one employment request per person.
148 changes: 148 additions & 0 deletions source-connectors/personio/e2e/identities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { createMockedHost, type MockedHost } from '@open-iga/connector-sdk/test';
import personioConnector from '../src/personio-connector.ts';
import type { Employment, Person } from '../src/utils/schema.ts';

// Stand-in for the Personio API, shaped after the official reference.
const persons: Person[] = [
{ id: '1', email: 'ada@openiga.dev', first_name: 'Ada', last_name: 'Active', status: 'ACTIVE' },
{ id: '2', email: 'nia@openiga.dev', first_name: 'Nia', last_name: 'New', status: 'ACTIVE' },
{ id: '3', email: 'not-an-email', first_name: 'Ina', last_name: 'Inactive', status: 'INACTIVE' },
];

const employmentsByPersonId: Record<string, Employment[]> = {
'1': [{ status: 'LEAVE', position: { title: 'Engineer' }, employment_end_date: null }],
'2': [{ status: 'ONBOARDING', supervisor: { id: '1' }, employment_start_date: '2027-01-01' }],
'3': [],
};

const nextLink = (cursor: string) => ({
links: { next: { href: `https://api.personio.de/v2/persons?cursor=${cursor}` } },
});

const brokenPages: Record<string, string> = {
'empty body': '',
'no data': JSON.stringify({ _meta: { links: {} } }),
stuck: JSON.stringify({ _data: [], _meta: nextLink('stuck') }),
};

const issueToken = async (request: Request) => {
const form = new URLSearchParams(await request.text());
const valid = form.get('client_id') === 'client' && form.get('client_secret') === 's&cret=+';

return valid ? Response.json({ access_token: 'token' }) : new Response('{}', { status: 400 });
};

const requireToken =
<Req extends Request>(handler: (request: Req) => Response) =>
(request: Req) =>
request.headers.get('authorization') === 'Bearer token'
? handler(request)
: new Response('{}', { status: 401 });

const listPersons = (request: Request) => {
const cursor = new URL(request.url).searchParams.get('cursor');
const brokenPage = brokenPages[cursor ?? ''];

if (brokenPage !== undefined) {
return new Response(brokenPage);
}

return cursor === 'page 2'
? Response.json({ _data: persons.slice(2), _meta: { links: {} } })
: Response.json({ _data: persons.slice(0, 2), _meta: nextLink('page%202') });
};

const listEmployments = (request: Bun.BunRequest<'/v2/persons/:personId/employments'>) =>
Response.json({ _data: employmentsByPersonId[request.params.personId] });

const startPersonioApi = () =>
Bun.serve({
port: 0,
routes: {
'/v2/auth/token': { POST: issueToken },
'/v2/persons': { GET: requireToken(listPersons) },
'/v2/persons/:personId/employments': { GET: requireToken(listEmployments) },
},
fetch: () => new Response('{}', { status: 404 }),
});

const tenant = { id: 'tenant-1' };

describe('identities.list', () => {
let server: ReturnType<typeof startPersonioApi>;
let host: MockedHost;
let hostWithWrongSecret: MockedHost;

beforeAll(async () => {
server = startPersonioApi();
const connect = (secret: string) =>
createMockedHost({
plugin: personioConnector,
config: { PERSONIO_CLIENT_ID: 'client', PERSONIO_CLIENT_SECRET: secret },
mockUpstream: server.url.href,
});
host = await connect('s&cret=+');
hostWithWrongSecret = await connect('wrong');
});

afterAll(async () => {
await host.close();
await hostWithWrongSecret.close();
await server.stop();
});

it('should list the first page with status and manager', async () => {
const result = await host.callIdentities('employee', 'list', { tenant });

expect(result).toEqual({
ok: true,
output: {
identities: [
{
identityId: '1',
status: 'active',
email: 'ada@openiga.dev',
firstname: 'Ada',
lastname: 'Active',
metadata: { position: 'Engineer' },
},
{
identityId: '2',
status: 'pending',
email: 'nia@openiga.dev',
firstname: 'Nia',
lastname: 'New',
managerId: '1',
metadata: { employmentStartDate: '2027-01-01' },
},
],
nextCursor: 'page 2',
},
});
});

it('should end on the last page and fall back to the person status', async () => {
const result = await host.callIdentities('employee', 'list', { tenant, cursor: 'page 2' });

expect(result).toEqual({
ok: true,
output: {
identities: [
{ identityId: '3', status: 'inactive', firstname: 'Ina', lastname: 'Inactive', metadata: {} },
],
},
});
});

it.each(Object.keys(brokenPages))('should fail the sync on a broken person page: %s', async (cursor) => {
const result = await host.callIdentities('employee', 'list', { tenant, cursor });

expect(result).toMatchObject({ ok: false, error: expect.stringContaining('Personio') });
});

it('should fail when authentication fails', async () => {
const result = await hostWithWrongSecret.callIdentities('employee', 'list', { tenant });

expect(result).toMatchObject({ ok: false, error: expect.stringContaining('authentication failed') });
});
});
20 changes: 20 additions & 0 deletions source-connectors/personio/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@open-iga/personio-source",
"version": "0.0.0",
"type": "module",
"scripts": {
"compile": "open-iga compile --entryPoint src/personio-connector.ts",
"test": "bun test",
"compile-and-test": "bun run compile && bun run test",
"typecheck": "bun --check"
},
"dependencies": {
"zod": "catalog:"
},
"devDependencies": {
"@open-iga/connector-sdk": "workspace:*",
"@types/bun": "catalog:",
"bun-types": "catalog:",
"typescript": "catalog:"
}
}
Loading
Loading