Skip to content
Open
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
30 changes: 22 additions & 8 deletions npm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Connection,
IDirectorySyncController,
JacksonOption,
JacksonOptionWithRequiredLogger,
Expand Down Expand Up @@ -153,19 +154,32 @@ export const controllers = async (
eventController,
});

// write pre-loaded connections if present
// write pre-loaded connections if present (in-memory array — bundler-safe, no dynamic imports)
const preLoadedConnections = opts.preLoadedConnections;
const preLoadedConnection = opts.preLoadedConnection;

const writeConnection = async (connection: Connection) => {
if ('oidcDiscoveryUrl' in connection || 'oidcMetadata' in connection) {
await connectionAPIController.createOIDCConnection(connection);
} else {
await connectionAPIController.createSAMLConnection(connection);
}

logger.info(`loaded connection for tenant "${connection.tenant}" and product "${connection.product}"`);
};

if (preLoadedConnections && preLoadedConnections.length > 0) {
for (const connection of preLoadedConnections) {
await writeConnection(connection);
}
}

// existing path-based approach — kept for backward compatibility
if (preLoadedConnection && preLoadedConnection.length > 0) {
const connections = await loadConnection(preLoadedConnection);

for (const connection of connections) {
if ('oidcDiscoveryUrl' in connection || 'oidcMetadata' in connection) {
await connectionAPIController.createOIDCConnection(connection);
} else {
await connectionAPIController.createSAMLConnection(connection);
}

logger.info(`loaded connection for tenant "${connection.tenant}" and product "${connection.product}"`);
await writeConnection(connection);
}
}

Expand Down
6 changes: 6 additions & 0 deletions npm/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export interface OIDCSSOConnectionWithDiscoveryUrl extends OIDCSSOConnection {
oidcDiscoveryUrl: string;
oidcMetadata?: never;
}
export type Connection =
| SAMLSSOConnectionWithEncodedMetadata
| SAMLSSOConnectionWithRawMetadata
| OIDCSSOConnectionWithDiscoveryUrl
| OIDCSSOConnectionWithMetadata;

export interface SAMLSSORecord extends SAMLSSOConnection {
clientID: string; // set by Jackson
Expand Down Expand Up @@ -428,6 +433,7 @@ export interface JacksonOption {
acsUrl?: string;
oidcPath?: string;
samlAudience?: string;
preLoadedConnections?: Connection[]; // new (in-memory, no dynamic imports)
preLoadedConnection?: string;
idpEnabled?: boolean;
db: DatabaseOption | DatabaseDriverOption;
Expand Down