import {
  PROVISION_DEFAULT_WORKSPACE_DETAIL_TYPE,
  USER_ONBOARDING_EVENT_SOURCE,
  buildProvisionDefaultWorkspaceRequestedDetail
} from "./chunk-2PM2NGXI.mjs";
import "./chunk-LZOMFHX3.mjs";

// src/components/cognito/post-confirmation.handler.ts
import {
  EventBridgeClient,
  PutEventsCommand
} from "@aws-sdk/client-eventbridge";
var eventBridgeClient = new EventBridgeClient({});
var handler = async (event, _context) => {
  try {
    const busName = process.env.CONTROL_EVENT_BUS_NAME?.trim();
    const detail = buildProvisionDefaultWorkspaceRequestedDetail(event);
    if (!busName || !detail) {
      console.warn(
        "PostConfirmation onboarding event not published; missing event bus or cognitoSub"
      );
      return event;
    }
    const result = await eventBridgeClient.send(
      new PutEventsCommand({
        Entries: [
          {
            EventBusName: busName,
            Source: USER_ONBOARDING_EVENT_SOURCE,
            DetailType: PROVISION_DEFAULT_WORKSPACE_DETAIL_TYPE,
            Detail: JSON.stringify(detail)
          }
        ]
      })
    );
    if ((result.FailedEntryCount ?? 0) > 0) {
      console.warn(
        "PostConfirmation onboarding event publication failed",
        result.Entries
      );
    }
  } catch (err) {
    console.warn(
      "PostConfirmation onboarding event publication failed; returning event unchanged",
      err
    );
  }
  return event;
};
export {
  handler
};
//# sourceMappingURL=post-confirmation.handler.mjs.map