mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-06 08:53:39 +00:00
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { api as apiClient } from "../auth/http";
|
|
import { URL_CONSTANTS } from "../constants/URLS";
|
|
import type { ResetChannel } from "../types/shippingLineCompany";
|
|
|
|
export interface TransitAgent {
|
|
id: string;
|
|
name: string;
|
|
validFrom: string;
|
|
validTo: string;
|
|
isActive: boolean;
|
|
/** Null on every agent that exists only as a GL-assignable roster entry. */
|
|
email?: string | null;
|
|
phoneNumber?: string | null;
|
|
/** True once an IAM account backs the agent — i.e. it can sign in. */
|
|
hasAccount?: boolean;
|
|
}
|
|
|
|
export interface InviteTransitAgentDto {
|
|
email: string;
|
|
phoneNumber?: string;
|
|
username?: string;
|
|
}
|
|
|
|
/** What the API reports back about an activation send. */
|
|
export interface ActivationSendResult {
|
|
maskedTarget: string;
|
|
channel: string;
|
|
expiresAt: string;
|
|
}
|
|
|
|
export const transitAgentsService = {
|
|
/** Active + currently inside its validity window — the assignment dropdown. */
|
|
async listAssignable() {
|
|
const response = await apiClient.get<TransitAgent[]>(
|
|
URL_CONSTANTS.RULE_ENGINE.TRANSIT_AGENTS_ASSIGNABLE,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Create the portal account for an agent that has none and send its
|
|
* activation link. Separate from the rule-engine CRUD update because it mints
|
|
* an IAM user, which a field edit must never do implicitly.
|
|
*/
|
|
async invite(id: string, dto: InviteTransitAgentDto) {
|
|
const response = await apiClient.post<{
|
|
agent: TransitAgent;
|
|
activationSentTo: string | null;
|
|
}>(URL_CONSTANTS.RULE_ENGINE.TRANSIT_AGENT_INVITE(id), dto);
|
|
return response.data;
|
|
},
|
|
|
|
async resendActivation(id: string, channel: ResetChannel) {
|
|
const response = await apiClient.post<ActivationSendResult>(
|
|
URL_CONSTANTS.RULE_ENGINE.TRANSIT_AGENT_RESEND_ACTIVATION(id),
|
|
{ channel },
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|