@ionite/adapters 0.0.0-stage → 0.1.0-beta.20261118.2
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/LICENSE +18 -0
- package/package.json +40 -4
- package/src/api.ts +335 -0
- package/src/contract/ciam.ts +65 -0
- package/src/contract/iam.ts +36 -0
- package/src/contract/index.ts +11 -0
- package/src/contract/operations.ts +206 -0
- package/src/contract/otel.ts +21 -0
- package/src/contract/scim.ts +51 -0
- package/src/contract/sso.ts +323 -0
- package/src/contract/workload.ts +144 -0
- package/src/credentials.ts +114 -0
- package/src/define.ts +235 -0
- package/src/index.ts +27 -0
- package/src/onboard-page.ts +135 -0
- package/src/serve.ts +292 -0
- package/src/stores.ts +79 -0
- package/src/testing.ts +95 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright (c) 2026 IONITE ENTERPRISE SOFTWARE INC. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and its associated documentation are closed source and
|
|
4
|
+
proprietary to IONITE ENTERPRISE SOFTWARE INC.
|
|
5
|
+
|
|
6
|
+
The published @ionite packages are licensed solely for use with ionite
|
|
7
|
+
products, under a separate written agreement or under evaluation terms
|
|
8
|
+
published by ionite. No other license is granted.
|
|
9
|
+
|
|
10
|
+
These materials do not grant any license under ionite's patents or patent
|
|
11
|
+
applications. They do not grant any right to use ionite trademarks except
|
|
12
|
+
as needed to refer to ionite products.
|
|
13
|
+
|
|
14
|
+
Documentation, including the public LLM guides, describes how to use the
|
|
15
|
+
SDK. It does not grant a right to copy, redistribute, or reimplement the
|
|
16
|
+
platform.
|
|
17
|
+
|
|
18
|
+
See https://ionite.com/legal
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ionite/adapters",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.20261118.2",
|
|
4
|
+
"description": "ionite adapter SDK: run a vendor adapter as a service ionite connects apps through (Bun)",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"author": "ionite",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"bun": ">=1.4"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./src/index.ts",
|
|
17
|
+
"./contract": "./src/contract/index.ts",
|
|
18
|
+
"./testing": "./src/testing.ts"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"typecheck": "tsc --noEmit -p ."
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@ionite/core": ">=0.0.28-beta.20261116.3",
|
|
26
|
+
"@ionite/redis": ">=0.0.28-beta.20261116.3",
|
|
27
|
+
"@ionite/server": ">=0.0.28-beta.20261116.3",
|
|
28
|
+
"@ionite/zod": ">=0.0.28-beta.20261116.3",
|
|
29
|
+
"zod": "^4.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependenciesMeta": {
|
|
32
|
+
"@ionite/core": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"@ionite/server": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"@ionite/zod": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AdapterCapability,
|
|
3
|
+
type AdapterManifest,
|
|
4
|
+
CONTRACT_VERSION,
|
|
5
|
+
connectionFactsSchema,
|
|
6
|
+
describeIssues,
|
|
7
|
+
isOperationName,
|
|
8
|
+
type ManualSetup,
|
|
9
|
+
type OperationInput,
|
|
10
|
+
type OperationName,
|
|
11
|
+
type OperationOutput,
|
|
12
|
+
operationNames,
|
|
13
|
+
operations,
|
|
14
|
+
type SignInRequest,
|
|
15
|
+
type SignInResponse,
|
|
16
|
+
signInRequestSchema,
|
|
17
|
+
} from './contract';
|
|
18
|
+
import type { CredentialStore } from './credentials';
|
|
19
|
+
import {
|
|
20
|
+
type AdapterCallContext,
|
|
21
|
+
type AdapterDefinition,
|
|
22
|
+
AdapterInputError,
|
|
23
|
+
isAdapterInputError,
|
|
24
|
+
type SsoConsumer,
|
|
25
|
+
type TenantState,
|
|
26
|
+
} from './define';
|
|
27
|
+
|
|
28
|
+
export interface AdapterLog {
|
|
29
|
+
info(message: string, attributes?: Record<string, unknown>): void;
|
|
30
|
+
warn(message: string, attributes?: Record<string, unknown>, error?: unknown): void;
|
|
31
|
+
error(message: string, attributes?: Record<string, unknown>, error?: unknown): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The fields of a tenant-management tenant the adapter API reads. */
|
|
35
|
+
export interface AdapterTenant {
|
|
36
|
+
id: string;
|
|
37
|
+
status?: string;
|
|
38
|
+
ioniteId?: string;
|
|
39
|
+
companyId?: string;
|
|
40
|
+
/** `TenantState`, as saved. */
|
|
41
|
+
vendorState?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface AdapterApiOptions<Connection> {
|
|
45
|
+
definition: AdapterDefinition<Connection>;
|
|
46
|
+
/**
|
|
47
|
+
* Who is calling, for the audit line, or the response that refuses them. Authentication alone is
|
|
48
|
+
* not enough: the caller must hold the permission that lets it drive a tenant's vendor.
|
|
49
|
+
*/
|
|
50
|
+
authenticate(request: Request): Promise<string | Response>;
|
|
51
|
+
tenants: {
|
|
52
|
+
get(id: string): Promise<AdapterTenant | null | undefined>;
|
|
53
|
+
/** Replaces the tenant's `vendorState`. */
|
|
54
|
+
saveVendorState(id: string, state: Record<string, unknown>): Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
credentials: CredentialStore<Connection>;
|
|
57
|
+
/** Mints a single-use link that signs `email` in and lands on `redirect`, an onboarding-page path. */
|
|
58
|
+
issueSignIn(request: SignInRequest): Promise<SignInResponse>;
|
|
59
|
+
log: AdapterLog;
|
|
60
|
+
/** The adapter's path prefix when its host routes by path (`/keycloak`); default none. */
|
|
61
|
+
basePath?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function json(body: unknown, status = 200): Response {
|
|
65
|
+
// Registration results carry client secrets.
|
|
66
|
+
return Response.json(body, { status, headers: { 'Cache-Control': 'no-store' } });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function serves(definition: AdapterDefinition<never>, capability: AdapterCapability): boolean {
|
|
70
|
+
const [side, key] = capability.split('.') as ['provides' | 'consumes', string];
|
|
71
|
+
const group: Record<string, unknown> | undefined = definition[side];
|
|
72
|
+
return !!group?.[key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function adapterManifest<Connection>(definition: AdapterDefinition<Connection>): AdapterManifest {
|
|
76
|
+
const untyped = definition as unknown as AdapterDefinition<never>;
|
|
77
|
+
const sso = definition.provides?.sso;
|
|
78
|
+
return {
|
|
79
|
+
contractVersion: CONTRACT_VERSION,
|
|
80
|
+
product: definition.slug,
|
|
81
|
+
// Catalog standard slugs: SCIM provisioning is the `iam` standard, as on the consumes side.
|
|
82
|
+
provides: (
|
|
83
|
+
[
|
|
84
|
+
['sso', 'sso'],
|
|
85
|
+
['workload', 'workload'],
|
|
86
|
+
['federatedWorkload', 'workload'],
|
|
87
|
+
['otel', 'otel'],
|
|
88
|
+
['scim', 'iam'],
|
|
89
|
+
['ciam', 'ciam'],
|
|
90
|
+
] as const
|
|
91
|
+
)
|
|
92
|
+
.filter(([key]) => definition.provides?.[key])
|
|
93
|
+
.map(([, slug]) => slug),
|
|
94
|
+
consumes: (['sso', 'iam', 'workload'] as const).filter((slug) => definition.consumes?.[slug]),
|
|
95
|
+
operations: operationNames.filter((name) => serves(untyped, operations[name].capability)),
|
|
96
|
+
sso: sso ? { capabilities: sso.capabilities, defaultScope: sso.defaultScope } : undefined,
|
|
97
|
+
ciam: definition.provides?.ciam ? { defaultScope: definition.provides.ciam.defaultScope } : undefined,
|
|
98
|
+
federatedWorkload: definition.provides?.federatedWorkload ? true : undefined,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `undefined` (not a promise) means the definition does not serve the operation. */
|
|
103
|
+
type Handlers<Connection> = {
|
|
104
|
+
[Op in OperationName]: (
|
|
105
|
+
connection: Connection,
|
|
106
|
+
context: AdapterCallContext,
|
|
107
|
+
input: OperationInput<Op>,
|
|
108
|
+
) => Promise<OperationOutput<Op>> | undefined;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const ok = () => ({ ok: true as const });
|
|
112
|
+
|
|
113
|
+
function handlersFor<Connection>(definition: AdapterDefinition<Connection>): Handlers<Connection> {
|
|
114
|
+
const { provides, consumes } = definition;
|
|
115
|
+
return {
|
|
116
|
+
'sso/register': (c, ctx, input) => provides?.sso?.connect(c, ctx).register(input),
|
|
117
|
+
'sso/update': (c, ctx, input) => provides?.sso?.connect(c, ctx).update(input.downstreamId, input.payload).then(ok),
|
|
118
|
+
'sso/deregister': (c, ctx, input) => provides?.sso?.connect(c, ctx).deregister(input.downstreamId).then(ok),
|
|
119
|
+
'sso/discover': (c, ctx) => provides?.ssoDiscovery?.(c, ctx).discover(),
|
|
120
|
+
'sso/discover-one': (c, ctx, input) =>
|
|
121
|
+
provides
|
|
122
|
+
?.ssoDiscovery?.(c, ctx)
|
|
123
|
+
.discoverOne(input.externalId, input.namespace || undefined)
|
|
124
|
+
.then((app) => ({ app: app ?? null })),
|
|
125
|
+
'sso/retire-discovered': (c, ctx, input) =>
|
|
126
|
+
provides
|
|
127
|
+
?.ssoDiscovery?.(c, ctx)
|
|
128
|
+
.retireDiscovered({ externalId: input.externalId, namespace: input.namespace }, input.action)
|
|
129
|
+
.then((result) => ({ result })),
|
|
130
|
+
'workload/register': (c, ctx, input) => provides?.workload?.(c, ctx).register(input),
|
|
131
|
+
'workload/register-outgoing': (c, ctx, input) => provides?.workload?.(c, ctx).registerOutgoing(input),
|
|
132
|
+
'workload/deregister': (c, ctx, input) => provides?.workload?.(c, ctx).deregister(input.downstreamId).then(ok),
|
|
133
|
+
'workload/federate': (c, ctx, input) => provides?.federatedWorkload?.(c, ctx).federate(input),
|
|
134
|
+
'workload/unfederate': (c, ctx, input) =>
|
|
135
|
+
provides?.federatedWorkload?.(c, ctx).deregister(input.downstreamId).then(ok),
|
|
136
|
+
'otel/register': (c, ctx, input) => provides?.otel?.(c, ctx).register(input),
|
|
137
|
+
'otel/deregister': (c, ctx, input) => provides?.otel?.(c, ctx).deregister(input.downstreamId).then(ok),
|
|
138
|
+
'scim/register': (c, ctx, input) => provides?.scim?.(c, ctx).register(input),
|
|
139
|
+
'scim/activate': (c, ctx, input) => {
|
|
140
|
+
const scim = provides?.scim?.(c, ctx);
|
|
141
|
+
// A tool with nothing to start answers ok, so ionite needs no per-adapter knowledge of it.
|
|
142
|
+
return scim && (scim.activate ? scim.activate(input.downstreamId) : Promise.resolve()).then(ok);
|
|
143
|
+
},
|
|
144
|
+
'scim/deregister': (c, ctx, input) => provides?.scim?.(c, ctx).deregister(input.downstreamId).then(ok),
|
|
145
|
+
'ciam/register': (c, ctx, input) => provides?.ciam?.connect(c, ctx).register(input),
|
|
146
|
+
'ciam/update': (c, ctx, input) =>
|
|
147
|
+
provides?.ciam?.connect(c, ctx).update(input.downstreamId, input.payload).then(ok),
|
|
148
|
+
'ciam/deregister': (c, ctx, input) => provides?.ciam?.connect(c, ctx).deregister(input.downstreamId).then(ok),
|
|
149
|
+
'consumes/sso/prepare': (c, ctx, input) => consumes?.sso?.(c, ctx).prepare(input),
|
|
150
|
+
'consumes/sso/register': (c, ctx, input) => {
|
|
151
|
+
const consumer = consumes?.sso?.(c, ctx);
|
|
152
|
+
return consumer && registerConsumedSso(consumer, input);
|
|
153
|
+
},
|
|
154
|
+
'consumes/sso/deregister': (c, ctx) =>
|
|
155
|
+
consumes
|
|
156
|
+
?.sso?.(c, ctx)
|
|
157
|
+
.deregister()
|
|
158
|
+
.then((removed) => ({ ok: true as const, removed })),
|
|
159
|
+
'consumes/iam/register': (c, ctx, input) => consumes?.iam?.(c, ctx).register(input),
|
|
160
|
+
'consumes/iam/deregister': (c, ctx, input) => consumes?.iam?.(c, ctx).deregister(input.downstreamId).then(ok),
|
|
161
|
+
'consumes/workload/register': (c, ctx, input) => consumes?.workload?.(c, ctx).register(input).then(ok),
|
|
162
|
+
'consumes/workload/deregister': (c, ctx) =>
|
|
163
|
+
consumes
|
|
164
|
+
?.workload?.(c, ctx)
|
|
165
|
+
.deregister()
|
|
166
|
+
.then((removed) => ({ ok: true as const, removed })),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The non-secret identifiers worth an audit line. A body is NEVER logged: results carry client secrets. */
|
|
171
|
+
const AUDITED_KEYS = ['downstreamId', 'externalId', 'namespace', 'action', 'alias', 'removed', 'result'] as const;
|
|
172
|
+
|
|
173
|
+
function auditFields(input: unknown, output: unknown): Record<string, unknown> {
|
|
174
|
+
const fields: Record<string, unknown> = {};
|
|
175
|
+
for (const source of [input, output]) {
|
|
176
|
+
if (typeof source !== 'object' || source === null) continue;
|
|
177
|
+
const record = source as Record<string, unknown>;
|
|
178
|
+
for (const key of AUDITED_KEYS) {
|
|
179
|
+
const value = record[key];
|
|
180
|
+
if (typeof value === 'string' || typeof value === 'number') fields[key] = value;
|
|
181
|
+
}
|
|
182
|
+
if (Array.isArray(record.namespaces)) {
|
|
183
|
+
const namespaces = record.namespaces as Array<{ apps?: unknown[]; error?: string }>;
|
|
184
|
+
fields.namespaces = namespaces.length;
|
|
185
|
+
fields.apps = namespaces.reduce((total, namespace) => total + (namespace.apps?.length ?? 0), 0);
|
|
186
|
+
fields.unreadable = namespaces.filter((namespace) => namespace.error).length;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return fields;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function readJsonObject(request: Request): Promise<Record<string, unknown> | undefined> {
|
|
193
|
+
const body: unknown = await request.json().catch(() => undefined);
|
|
194
|
+
return typeof body === 'object' && body !== null && !Array.isArray(body)
|
|
195
|
+
? (body as Record<string, unknown>)
|
|
196
|
+
: undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** `TenantState` over one tenant's record, read once per call and written through on every change. */
|
|
200
|
+
function tenantStateFor(tenants: AdapterApiOptions<unknown>['tenants']) {
|
|
201
|
+
return (tenant: AdapterTenant): TenantState => {
|
|
202
|
+
const values: Record<string, unknown> = { ...(tenant.vendorState ?? {}) };
|
|
203
|
+
return {
|
|
204
|
+
get: <T>(key: string) => values[key] as T | undefined,
|
|
205
|
+
async set(key, value) {
|
|
206
|
+
if (value === undefined) delete values[key];
|
|
207
|
+
else values[key] = JSON.parse(JSON.stringify(value));
|
|
208
|
+
await tenants.saveVendorState(tenant.id, { ...values });
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** One upstream to the method that takes its protocol. A vendor may implement only one. */
|
|
215
|
+
async function registerConsumedSso(
|
|
216
|
+
consumer: SsoConsumer,
|
|
217
|
+
input: OperationInput<'consumes/sso/register'>,
|
|
218
|
+
): Promise<OperationOutput<'consumes/sso/register'>> {
|
|
219
|
+
let result: { manualSetup?: ManualSetup } | undefined;
|
|
220
|
+
if ('samlUpstream' in input) {
|
|
221
|
+
if (!consumer.registerSaml) throw new AdapterInputError('This adapter does not take a SAML upstream');
|
|
222
|
+
result = (await consumer.registerSaml(input)) ?? undefined;
|
|
223
|
+
} else {
|
|
224
|
+
if (!consumer.register) throw new AdapterInputError('This adapter does not take an OIDC upstream');
|
|
225
|
+
result = (await consumer.register(input)) ?? undefined;
|
|
226
|
+
}
|
|
227
|
+
return { ok: true, ...(result?.manualSetup ? { manualSetup: result.manualSetup } : {}) };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The API ionite calls, under `/api/adapter/`. Returns `undefined` for a path that is not its own, so
|
|
232
|
+
* the caller can route on. Never throws: a vendor failure is logged here and answered with a bare
|
|
233
|
+
* 500, because the vendor's message can quote its response.
|
|
234
|
+
*/
|
|
235
|
+
export function createAdapterApi<Connection>(
|
|
236
|
+
options: AdapterApiOptions<Connection>,
|
|
237
|
+
): (request: Request) => Promise<Response | undefined> {
|
|
238
|
+
const { definition, credentials, log } = options;
|
|
239
|
+
const manifest = adapterManifest(definition);
|
|
240
|
+
const handlers = handlersFor(definition);
|
|
241
|
+
const tenantState = tenantStateFor(options.tenants);
|
|
242
|
+
|
|
243
|
+
async function tenantCall(request: Request, tenantId: string, operation: string): Promise<Response> {
|
|
244
|
+
const caller = await options.authenticate(request);
|
|
245
|
+
if (caller instanceof Response) return caller;
|
|
246
|
+
const tenant = await options.tenants.get(tenantId);
|
|
247
|
+
if (!tenant) return json({ error: 'Unknown tenant' }, 404);
|
|
248
|
+
const audit = { 'ion.operation': `adapter.${operation}`, tenantId: tenant.id, caller };
|
|
249
|
+
|
|
250
|
+
// The one call that precedes a connection: it is how the user reaches the page that makes one.
|
|
251
|
+
if (operation === 'sign-in') {
|
|
252
|
+
if (request.method !== 'POST') return json({ error: 'Method not allowed' }, 405);
|
|
253
|
+
const body = await readJsonObject(request);
|
|
254
|
+
if (!body) return json({ error: 'Expected a JSON object' }, 400);
|
|
255
|
+
const parsed = signInRequestSchema.safeParse(body);
|
|
256
|
+
if (!parsed.success) return json({ error: describeIssues(parsed.error) }, 400);
|
|
257
|
+
// Only this adapter's own onboarding page: the link must not become an open redirect.
|
|
258
|
+
const { redirect } = parsed.data;
|
|
259
|
+
if (redirect !== onboardPath && !redirect.startsWith(`${onboardPath}?`)) {
|
|
260
|
+
return json({ error: `redirect must be an ${onboardPath} path` }, 400);
|
|
261
|
+
}
|
|
262
|
+
const link = await options.issueSignIn(parsed.data);
|
|
263
|
+
log.info('Sign-in link issued for ionite', { ...audit, user: parsed.data.email });
|
|
264
|
+
return json(link);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const connection = tenant.status === 'completed' ? await credentials.get(tenant.id) : undefined;
|
|
268
|
+
if (!connection) return json({ error: `This tenant has not connected ${definition.name} yet` }, 409);
|
|
269
|
+
|
|
270
|
+
if (operation === 'connection') {
|
|
271
|
+
if (request.method !== 'GET') return json({ error: 'Method not allowed' }, 405);
|
|
272
|
+
const facts = await definition.connection.facts(connection);
|
|
273
|
+
return json(connectionFactsSchema.parse({ ...facts, ioniteId: tenant.ioniteId, companyId: tenant.companyId }));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (!isOperationName(operation)) return json({ error: 'Not found' }, 404);
|
|
277
|
+
if (request.method !== 'POST') return json({ error: 'Method not allowed' }, 405);
|
|
278
|
+
const body = await readJsonObject(request);
|
|
279
|
+
if (!body) return json({ error: 'Expected a JSON object' }, 400);
|
|
280
|
+
const spec = operations[operation];
|
|
281
|
+
const input = spec.input.safeParse(body);
|
|
282
|
+
if (!input.success) return json({ error: describeIssues(input.error) }, 400);
|
|
283
|
+
|
|
284
|
+
const handler = handlers[operation] as (
|
|
285
|
+
connection: Connection,
|
|
286
|
+
context: AdapterCallContext,
|
|
287
|
+
input: unknown,
|
|
288
|
+
) => Promise<unknown> | undefined;
|
|
289
|
+
let result: unknown;
|
|
290
|
+
try {
|
|
291
|
+
const pending = handler(connection, { tenantId: tenant.id, state: tenantState(tenant) }, input.data);
|
|
292
|
+
if (!pending) return json({ error: `This adapter does not serve ${operation}` }, 404);
|
|
293
|
+
result = await pending;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (isAdapterInputError(error)) return json({ error: error.message }, 400);
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
// Parsed on the way out too: only what the contract names leaves, whatever the vendor code returned.
|
|
299
|
+
const output = spec.output.safeParse(result);
|
|
300
|
+
if (!output.success) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
`${definition.name} adapter built an invalid ${operation} result: ${describeIssues(output.error)}`,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
log.info(`Adapter ${operation} completed`, { ...audit, ...auditFields(input.data, output.data) });
|
|
306
|
+
return json(output.data);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const apiPrefix = `${options.basePath ?? ''}/api/adapter/`;
|
|
310
|
+
const onboardPath = `${options.basePath ?? ''}/onboard`;
|
|
311
|
+
return async function handle(request: Request): Promise<Response | undefined> {
|
|
312
|
+
const { pathname } = new URL(request.url);
|
|
313
|
+
if (!pathname.startsWith(apiPrefix)) return undefined;
|
|
314
|
+
const rest = pathname.slice(apiPrefix.length);
|
|
315
|
+
if (rest === 'manifest') {
|
|
316
|
+
return request.method === 'GET' ? json(manifest) : json({ error: 'Method not allowed' }, 405);
|
|
317
|
+
}
|
|
318
|
+
const slash = rest.indexOf('/');
|
|
319
|
+
if (slash <= 0) return json({ error: 'Not found' }, 404);
|
|
320
|
+
const operation = rest.slice(slash + 1);
|
|
321
|
+
if (operation !== 'sign-in' && operation !== 'connection' && !isOperationName(operation)) {
|
|
322
|
+
return json({ error: 'Not found' }, 404);
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
return await tenantCall(request, decodeURIComponent(rest.slice(0, slash)), operation);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
log.error(
|
|
328
|
+
'Adapter request failed',
|
|
329
|
+
{ 'ion.outcome': 'failure', 'ion.operation': `adapter.${operation}`, 'http.method': request.method },
|
|
330
|
+
error,
|
|
331
|
+
);
|
|
332
|
+
return json({ error: 'Request failed' }, 500);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const text = z.string().min(1);
|
|
4
|
+
|
|
5
|
+
export const ciamProviderTypeSchema = z.enum(['oidc', 'google', 'github', 'microsoft', 'apple', 'magic-link']);
|
|
6
|
+
|
|
7
|
+
/** A customer-identity (CIAM) sign-in client for the App: customers, not the workforce, sign in with it. */
|
|
8
|
+
export const registerCiamAppPayloadSchema = z.object({
|
|
9
|
+
/** The App's customer callback URLs. */
|
|
10
|
+
redirectUris: z.array(text).min(1),
|
|
11
|
+
displayName: z.string().optional(),
|
|
12
|
+
defaultScope: z.string().optional(),
|
|
13
|
+
providerType: ciamProviderTypeSchema.optional(),
|
|
14
|
+
});
|
|
15
|
+
export type RegisterCiamAppPayload = z.infer<typeof registerCiamAppPayloadSchema>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The App's `ciam.providers` entry. Endpoint and client fields only: ionite checks each against the
|
|
19
|
+
* result's own, which it checks against the provider's well-known document. Entitlement and
|
|
20
|
+
* access-request settings are ionite's to write, never an adapter's, so they are not on the wire.
|
|
21
|
+
*/
|
|
22
|
+
export const ciamProviderConfigSchema = z.object({
|
|
23
|
+
type: ciamProviderTypeSchema,
|
|
24
|
+
enabled: z.boolean().optional(),
|
|
25
|
+
order: z.number().int().optional(),
|
|
26
|
+
branding: z
|
|
27
|
+
.object({
|
|
28
|
+
displayName: text,
|
|
29
|
+
iconUrl: z.string().optional(),
|
|
30
|
+
colors: z.object({ light: z.string(), dark: z.string(), secondary: z.string().optional() }).optional(),
|
|
31
|
+
url: z.string().optional(),
|
|
32
|
+
})
|
|
33
|
+
.optional(),
|
|
34
|
+
authority: text,
|
|
35
|
+
authorizationUrl: text,
|
|
36
|
+
tokenUrl: text,
|
|
37
|
+
jwksUri: text,
|
|
38
|
+
userInfoUrl: z.string().optional(),
|
|
39
|
+
clientId: text,
|
|
40
|
+
clientSecret: z.string().optional(),
|
|
41
|
+
scope: z.string().optional(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const registerCiamAppResultSchema = z.object({
|
|
45
|
+
registered: z.literal(true),
|
|
46
|
+
clientId: text,
|
|
47
|
+
clientSecret: z.string().optional(),
|
|
48
|
+
downstreamId: z.string().optional(),
|
|
49
|
+
secretExpiresAt: z.string().optional(),
|
|
50
|
+
authority: text,
|
|
51
|
+
tokenUrl: text,
|
|
52
|
+
authorizationUrl: text,
|
|
53
|
+
jwksUri: text,
|
|
54
|
+
userInfoUrl: z.string().optional(),
|
|
55
|
+
/** The `ciam.providers` key, e.g. "microsoft". */
|
|
56
|
+
providerKey: z.string().regex(/^[A-Za-z0-9_.-]{1,100}$/),
|
|
57
|
+
providerConfig: ciamProviderConfigSchema,
|
|
58
|
+
});
|
|
59
|
+
export type RegisterCiamAppResult = z.infer<typeof registerCiamAppResultSchema>;
|
|
60
|
+
|
|
61
|
+
export const updateCiamAppPayloadSchema = z.object({
|
|
62
|
+
redirectUris: z.array(text).optional(),
|
|
63
|
+
displayName: z.string().optional(),
|
|
64
|
+
});
|
|
65
|
+
export type UpdateCiamAppPayload = z.infer<typeof updateCiamAppPayloadSchema>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const text = z.string().min(1);
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Consumes side of IAM: the adapter's vendor is the thing an upstream IAM tool provisions users INTO
|
|
7
|
+
* over SCIM. Deliberately thin: register and deregister only stand up a credential and hand back the
|
|
8
|
+
* vendor's own SCIM endpoint. The SCIM traffic itself never passes through ionite or the adapter.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const consumeIamRegisterPayloadSchema = z.object({
|
|
12
|
+
/** Names the credential the vendor mints; the only fact about the app the adapter needs. */
|
|
13
|
+
appName: text,
|
|
14
|
+
/**
|
|
15
|
+
* The SCIM extension URN the upstream IAM sends the ECID under. A vendor that stores the ECID maps
|
|
16
|
+
* its attribute to `<URN>:ecid`.
|
|
17
|
+
*/
|
|
18
|
+
ecidExtensionUrn: text,
|
|
19
|
+
});
|
|
20
|
+
export type ConsumeIamRegisterPayload = z.infer<typeof consumeIamRegisterPayloadSchema>;
|
|
21
|
+
|
|
22
|
+
export const consumeIamRegisterResultSchema = z.object({
|
|
23
|
+
/** The vendor's real, native SCIM base URL. */
|
|
24
|
+
scimBaseUrl: text,
|
|
25
|
+
/** Credential the upstream IAM tool uses to call that URL directly. */
|
|
26
|
+
workload: z.object({
|
|
27
|
+
clientId: text,
|
|
28
|
+
clientSecret: text,
|
|
29
|
+
idpTokenUrl: text,
|
|
30
|
+
issuer: text,
|
|
31
|
+
scope: z.string().optional(),
|
|
32
|
+
}),
|
|
33
|
+
/** Stable handle for deregister. */
|
|
34
|
+
downstreamId: text,
|
|
35
|
+
});
|
|
36
|
+
export type ConsumeIamRegisterResult = z.infer<typeof consumeIamRegisterResultSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract between ionite and an adapter service (`docs/adapter-sdk.md`). No server imports:
|
|
3
|
+
* ionite's client bundle and its pipeline both load this.
|
|
4
|
+
*/
|
|
5
|
+
export * from './ciam';
|
|
6
|
+
export * from './iam';
|
|
7
|
+
export * from './operations';
|
|
8
|
+
export * from './otel';
|
|
9
|
+
export * from './scim';
|
|
10
|
+
export * from './sso';
|
|
11
|
+
export * from './workload';
|