From f7823dcc73182bfe7202056cba46a6e9b6f4849b Mon Sep 17 00:00:00 2001 From: Prasanna Ramesh <44441571+Prasanna-ramesh@users.noreply.github.com> Date: Tue, 1 Dec 2026 23:12:36 +0530 Subject: [PATCH] feat: add Personio source connector and add the connector type to package names --- .changeset/source-connectors.md | 4 +- .github/workflows/release.yml | 2 +- README.md | 12 +- bun.lock | 21 ++- connectors/aws/CHANGELOG.md | 2 +- connectors/aws/package.json | 2 +- package.json | 1 + .../connector-sdk/lib/test/mock-fetch.test.ts | 15 ++ packages/connector-sdk/lib/test/mock-fetch.ts | 17 +- source-connectors/personio/README.md | 38 +++++ .../personio/e2e/identities.test.ts | 148 ++++++++++++++++++ source-connectors/personio/package.json | 20 +++ .../personio/src/identities/list.ts | 83 ++++++++++ .../personio/src/personio-connector.ts | 17 ++ .../personio/src/utils/client.ts | 77 +++++++++ .../personio/src/utils/identity.ts | 41 +++++ .../personio/src/utils/schema.ts | 44 ++++++ source-connectors/personio/tsconfig.app.json | 5 + source-connectors/personio/tsconfig.json | 4 + source-connectors/personio/tsconfig.test.json | 8 + 20 files changed, 545 insertions(+), 16 deletions(-) create mode 100644 packages/connector-sdk/lib/test/mock-fetch.test.ts create mode 100644 source-connectors/personio/README.md create mode 100644 source-connectors/personio/e2e/identities.test.ts create mode 100644 source-connectors/personio/package.json create mode 100644 source-connectors/personio/src/identities/list.ts create mode 100644 source-connectors/personio/src/personio-connector.ts create mode 100644 source-connectors/personio/src/utils/client.ts create mode 100644 source-connectors/personio/src/utils/identity.ts create mode 100644 source-connectors/personio/src/utils/schema.ts create mode 100644 source-connectors/personio/tsconfig.app.json create mode 100644 source-connectors/personio/tsconfig.json create mode 100644 source-connectors/personio/tsconfig.test.json diff --git a/.changeset/source-connectors.md b/.changeset/source-connectors.md index 99f5306..65c19ed 100644 --- a/.changeset/source-connectors.md +++ b/.changeset/source-connectors.md @@ -1,5 +1,5 @@ --- -'@open-iga/aws': patch +'@open-iga/aws-sink': patch --- -Differentiate source and sink connector to support onboarding HR systems \ No newline at end of file +Differentiate source and sink connector to support onboarding HR systems diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c86d695..e15a937 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/README.md b/README.md index f0fe5da..dd05a05 100644 --- a/README.md +++ b/README.md @@ -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 @@ -59,6 +60,3 @@ See `connectors/aws` for a complete reference implementation. - Linear - Mattermost - Slack - -- Following source connectors are planned to be added - - Personio diff --git a/bun.lock b/bun.lock index d7d7ac2..3337c4e 100644 --- a/bun.lock +++ b/bun.lock @@ -16,8 +16,8 @@ }, }, "connectors/aws": { - "name": "@open-iga/aws", - "version": "0.4.0", + "name": "@open-iga/aws-sink", + "version": "0.6.0", "dependencies": { "@aws-sdk/client-iam": "catalog:", "@aws-sdk/client-sts": "catalog:", @@ -46,6 +46,19 @@ "bun-types": "catalog:", }, }, + "source-connectors/personio": { + "name": "@open-iga/personio-source", + "version": "0.0.0", + "dependencies": { + "zod": "catalog:", + }, + "devDependencies": { + "@open-iga/connector-sdk": "workspace:*", + "@types/bun": "catalog:", + "bun-types": "catalog:", + "typescript": "catalog:", + }, + }, }, "catalog": { "@aws-sdk/client-iam": "3.1174.0", @@ -157,10 +170,12 @@ "@noble/hashes": ["@noble/hashes@2.2.0", "", {}, "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg=="], - "@open-iga/aws": ["@open-iga/aws@workspace:connectors/aws"], + "@open-iga/aws-sink": ["@open-iga/aws-sink@workspace:connectors/aws"], "@open-iga/connector-sdk": ["@open-iga/connector-sdk@workspace:packages/connector-sdk"], + "@open-iga/personio-source": ["@open-iga/personio-source@workspace:source-connectors/personio"], + "@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.61.0", "", { "os": "android", "cpu": "arm" }, "sha512-BaS+1OVvg9sr+Xav0+KdWedQRcAzrdoEcwMZeqoc2F6ieC1s/t5eM35YQoRPQ7vAqkZ+p3tbQb1r9I9mrV5oGA=="], "@oxfmt/binding-android-arm64": ["@oxfmt/binding-android-arm64@0.61.0", "", { "os": "android", "cpu": "arm64" }, "sha512-of8atAV0M1egGcVOMbgZCvc10sFOP3ayQBNQV5h5G3fNq8gACdEswfFk9bzGrdbM23rtg0Coxi7np7oPLcueNw=="], diff --git a/connectors/aws/CHANGELOG.md b/connectors/aws/CHANGELOG.md index 6aa5ba2..c2b9f89 100644 --- a/connectors/aws/CHANGELOG.md +++ b/connectors/aws/CHANGELOG.md @@ -1,4 +1,4 @@ -# @open-iga/aws +# @open-iga/aws-sink ## 0.6.0 diff --git a/connectors/aws/package.json b/connectors/aws/package.json index c6c584c..e6eae7b 100644 --- a/connectors/aws/package.json +++ b/connectors/aws/package.json @@ -1,5 +1,5 @@ { - "name": "@open-iga/aws", + "name": "@open-iga/aws-sink", "version": "0.6.0", "type": "module", "scripts": { diff --git a/package.json b/package.json index ef61039..1f118f8 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "workspaces": { "packages": [ "connectors/*", + "source-connectors/*", "packages/*" ], "catalog": { diff --git a/packages/connector-sdk/lib/test/mock-fetch.test.ts b/packages/connector-sdk/lib/test/mock-fetch.test.ts new file mode 100644 index 0000000..fc8df2d --- /dev/null +++ b/packages/connector-sdk/lib/test/mock-fetch.test.ts @@ -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/); + } + }); +}); diff --git a/packages/connector-sdk/lib/test/mock-fetch.ts b/packages/connector-sdk/lib/test/mock-fetch.ts index 422c9dd..1a5dc96 100644 --- a/packages/connector-sdk/lib/test/mock-fetch.ts +++ b/packages/connector-sdk/lib/test/mock-fetch.ts @@ -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 @@ -44,7 +59,7 @@ export const createFetchProxy = (mockUpstream: string, config: Record = { + '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 = { + '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 = + (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; + 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') }); + }); +}); diff --git a/source-connectors/personio/package.json b/source-connectors/personio/package.json new file mode 100644 index 0000000..4cba4a4 --- /dev/null +++ b/source-connectors/personio/package.json @@ -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:" + } +} diff --git a/source-connectors/personio/src/identities/list.ts b/source-connectors/personio/src/identities/list.ts new file mode 100644 index 0000000..f8d2020 --- /dev/null +++ b/source-connectors/personio/src/identities/list.ts @@ -0,0 +1,83 @@ +import type personioConnector from '../personio-connector.ts'; +import { buildAuthHeaders, getAccessToken, PERSONIO_API, safeFetch } from '../utils/client.ts'; +import { employmentPageSchema, type PersonPage, personPageSchema } from '../utils/schema.ts'; +import { toIdentity } from '../utils/identity.ts'; + +// ponytail: one employment request per person and no retry delay; lower this on timeouts or rate limits. +const PAGE_SIZE = 25; + +const getNextCursor = (page: PersonPage, currentCursor: string | undefined) => { + const nextLink = page._meta.links.next?.href; + + if (!nextLink) { + return undefined; + } + + const cursor = nextLink.match(/[?&]cursor=([^&]+)/)?.[1]; + const nextCursor = cursor && decodeURIComponent(cursor); + + // Fail instead of looping forever, or ending early and making people look like leavers. + if (!nextCursor || nextCursor === currentCursor) { + throw new Error('Personio returned a next page link without a new cursor'); + } + + return nextCursor; +}; + +// https://developer.personio.de/reference/get_v2-persons +const getPersonPage = async (token: string, cursor: string | undefined) => { + const cursorQuery = cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''; + + const result = await safeFetch(`${PERSONIO_API}/v2/persons?limit=${PAGE_SIZE}${cursorQuery}`, { + headers: buildAuthHeaders(token), + schema: personPageSchema, + }); + + if (!result.ok) { + throw new Error(`Personio person list failed: ${result.error}`); + } + + return result.data; +}; + +// The most recent employment comes first. +// https://developer.personio.de/reference/get_v2-persons-person-id-employments +const getLatestEmployment = async (token: string, personId: string) => { + const url = `${PERSONIO_API}/v2/persons/${encodeURIComponent(personId)}/employments?limit=1`; + const result = await safeFetch(url, { headers: buildAuthHeaders(token), schema: employmentPageSchema }); + + if (!result.ok) { + throw new Error(`Personio employment list failed: ${result.error}`); + } + + return result.data._data[0]; +}; + +export const registerEmployeeList = (plugin: typeof personioConnector) => { + plugin.registerIdentities('employee', { + type: 'list', + description: 'List employees with their status and manager', + endpoints: [ + { method: 'POST', url: `${PERSONIO_API}/v2/auth/token`, description: 'Get an access token' }, + { method: 'GET', url: `${PERSONIO_API}/v2/persons`, description: 'List persons' }, + { + method: 'GET', + url: `${PERSONIO_API}/v2/persons/{personId}/employments`, + description: 'Read the latest employment of a person', + }, + ], + handler: async ({ config, input }) => { + const token = await getAccessToken(config.PERSONIO_CLIENT_ID, config.PERSONIO_CLIENT_SECRET); + const page = await getPersonPage(token, input.cursor); + + const identities = []; + for (const person of page._data) { + identities.push(toIdentity(person, await getLatestEmployment(token, person.id))); + } + + const nextCursor = getNextCursor(page, input.cursor); + + return { identities, ...(nextCursor && { nextCursor }) }; + }, + }); +}; diff --git a/source-connectors/personio/src/personio-connector.ts b/source-connectors/personio/src/personio-connector.ts new file mode 100644 index 0000000..7069589 --- /dev/null +++ b/source-connectors/personio/src/personio-connector.ts @@ -0,0 +1,17 @@ +import { OpenIgaConnector } from '@open-iga/connector-sdk'; +import { registerEmployeeList } from './identities/list.ts'; + +export const personioConnector = new OpenIgaConnector({ + type: 'source', + name: 'Personio', + description: 'Personio source connector for OpenIGA core', + config: [ + { name: 'PERSONIO_CLIENT_ID', description: 'Client id of the Personio API credential', required: true }, + { name: 'PERSONIO_CLIENT_SECRET', description: 'Client secret of the Personio API credential', required: true }, + ], + allowedDomains: ['api.personio.de'], +}); + +registerEmployeeList(personioConnector); + +export default personioConnector; diff --git a/source-connectors/personio/src/utils/client.ts b/source-connectors/personio/src/utils/client.ts new file mode 100644 index 0000000..3791e53 --- /dev/null +++ b/source-connectors/personio/src/utils/client.ts @@ -0,0 +1,77 @@ +import * as z from 'zod/mini'; +import { tokenSchema } from './schema.ts'; + +export const PERSONIO_API = 'https://api.personio.de'; + +export type SafeFetchResult = { ok: true; data: Data } | { ok: false; error: string }; + +type FetchInit = NonNullable[1]>; + +const toSuccess = (data: Data) => ({ ok: true as const, data }); + +const toFailure = (error: string) => ({ ok: false as const, error }); + +const getBody = async (url: string, init: FetchInit): Promise> => { + try { + const response = await fetch(url, init); + + if (!response) { + return toFailure('no response'); + } + + if (!response.ok) { + return toFailure(`status ${response.status}`); + } + + const body = await response.text(); + + return body ? toSuccess(body) : toFailure('empty response'); + } catch (error) { + return toFailure(`request failed: ${error instanceof Error ? error.message : String(error)}`); + } +}; + +const parseBody = (body: string, schema: Schema): SafeFetchResult> => { + let json: unknown; + try { + json = JSON.parse(body); + } catch { + return toFailure('response is not JSON'); + } + + const result = z.safeParse(schema, json); + + return result.success ? toSuccess(result.data) : toFailure(`unexpected response: ${z.prettifyError(result.error)}`); +}; + +// Returns the validated response or an error, and does not throw. Errors never include the body: it can hold personal data. +export const safeFetch = async ( + url: string, + { schema, ...init }: FetchInit & { schema: Schema }, +): Promise>> => { + const body = await getBody(url, init); + + return body.ok ? parseBody(body.data, schema) : body; +}; + +export const buildAuthHeaders = (token: string) => ({ authorization: `Bearer ${token}`, accept: 'application/json' }); + +export const getAccessToken = async (clientId: string, clientSecret: string) => { + const form = { grant_type: 'client_credentials', client_id: clientId, client_secret: clientSecret }; + + // https://developer.personio.de/reference/post_v2-auth-token + const result = await safeFetch(`${PERSONIO_API}/v2/auth/token`, { + method: 'POST', + headers: { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json' }, + body: Object.entries(form) + .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) + .join('&'), + schema: tokenSchema, + }); + + if (!result.ok) { + throw new Error(`Personio authentication failed: ${result.error}`); + } + + return result.data.access_token; +}; diff --git a/source-connectors/personio/src/utils/identity.ts b/source-connectors/personio/src/utils/identity.ts new file mode 100644 index 0000000..f8effa7 --- /dev/null +++ b/source-connectors/personio/src/utils/identity.ts @@ -0,0 +1,41 @@ +import type { Employment, Person } from './schema.ts'; + +const STATUS_BY_PERSONIO_STATUS = { + ONBOARDING: 'pending', + ACTIVE: 'active', + LEAVE: 'active', + INACTIVE: 'inactive', +} as const; + +// The employment status is finer than the person status, which counts onboarding as active. +// An unknown status maps to `pending`, so that nobody is activated or removed by a guess. +const toStatus = (person: Person, employment: Employment | undefined) => { + const status = [employment?.status, person.status].find((value) => value && value !== 'UNSPECIFIED'); + + return STATUS_BY_PERSONIO_STATUS[status as keyof typeof STATUS_BY_PERSONIO_STATUS] ?? 'pending'; +}; + +// Org units without both values are left out. +const toOrgUnits = (employment: Employment | undefined) => + (employment?.org_units ?? []).flatMap(({ type, id }) => (type && id ? [{ type, id }] : [])); + +export const toIdentity = (person: Person, employment: Employment | undefined) => { + const orgUnits = toOrgUnits(employment); + const metadata = { + ...(person.preferred_name && { preferredName: person.preferred_name }), + ...(employment?.position?.title && { position: employment.position.title }), + ...(orgUnits.length > 0 && { orgUnits }), + ...(employment?.employment_start_date && { employmentStartDate: employment.employment_start_date }), + ...(employment?.employment_end_date && { employmentEndDate: employment.employment_end_date }), + }; + + return { + identityId: person.id, + status: toStatus(person, employment), + firstname: person.first_name ?? '', + lastname: person.last_name ?? '', + ...(person.email && { email: person.email }), + ...(employment?.supervisor?.id && { managerId: employment.supervisor.id }), + metadata, + }; +}; diff --git a/source-connectors/personio/src/utils/schema.ts b/source-connectors/personio/src/utils/schema.ts new file mode 100644 index 0000000..c3c2d06 --- /dev/null +++ b/source-connectors/personio/src/utils/schema.ts @@ -0,0 +1,44 @@ +import * as z from 'zod/mini'; + +// Only the fields this connector reads. Anything else in a response is ignored. +// The reference marks no field as required, so each required field here is our own choice. +const requiredText = z.string().check(z.minLength(1)); +const optionalText = z.nullish(z.string()); + +// https://developer.personio.de/reference/post_v2-auth-token +export const tokenSchema = z.object({ access_token: requiredText }); + +// An item of `_data`: https://developer.personio.de/reference/get_v2-persons +const personSchema = z.object({ + id: requiredText, + // An address that is not valid is left out, so that one record does not stop the sync. + email: z.catch(z.nullish(z.email()), null), + first_name: optionalText, + last_name: optionalText, + preferred_name: optionalText, + status: optionalText, +}); + +// An item of `_data`: https://developer.personio.de/reference/get_v2-persons-person-id-employments +const employmentSchema = z.object({ + status: optionalText, + supervisor: z.nullish(z.object({ id: optionalText })), + position: z.nullish(z.object({ title: optionalText })), + org_units: z.nullish(z.array(z.object({ type: optionalText, id: optionalText }))), + employment_start_date: optionalText, + employment_end_date: optionalText, +}); + +// The page links are required: without them a broken page looks like the last one. +// `links.next.href` appears only in the response example: https://developer.personio.de/reference/get_v2-persons +export const personPageSchema = z.object({ + _data: z.array(personSchema), + _meta: z.object({ links: z.object({ next: z.nullish(z.object({ href: requiredText })) }) }), +}); + +// https://developer.personio.de/reference/get_v2-persons-person-id-employments +export const employmentPageSchema = z.object({ _data: z.array(employmentSchema) }); + +export type Person = z.infer; +export type Employment = z.infer; +export type PersonPage = z.infer; diff --git a/source-connectors/personio/tsconfig.app.json b/source-connectors/personio/tsconfig.app.json new file mode 100644 index 0000000..6bb04e0 --- /dev/null +++ b/source-connectors/personio/tsconfig.app.json @@ -0,0 +1,5 @@ +{ + "extends": ["../../tsconfig.json", "@open-iga/connector-sdk/tsconfig.connector.json"], + "include": ["src"], + "exclude": ["src/**/*.test.ts"] +} diff --git a/source-connectors/personio/tsconfig.json b/source-connectors/personio/tsconfig.json new file mode 100644 index 0000000..3eded8f --- /dev/null +++ b/source-connectors/personio/tsconfig.json @@ -0,0 +1,4 @@ +{ + "files": [], + "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.test.json" }] +} diff --git a/source-connectors/personio/tsconfig.test.json b/source-connectors/personio/tsconfig.test.json new file mode 100644 index 0000000..0b5fcaf --- /dev/null +++ b/source-connectors/personio/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": ["../../tsconfig.json", "@open-iga/connector-sdk/tsconfig.connector.json"], + "include": ["e2e"], + "compilerOptions": { + "lib": ["esnext"], + "types": ["bun", "bun-types/test-globals"] + } +}