Skip to content
Merged
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
15 changes: 12 additions & 3 deletions packages/contracts/scripts/generate-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ async function writeFormatted(path: string, content: string): Promise<void> {
writeFileSync(path, formatted, 'utf-8');
}

function toGlobPath(path: string): string {
return path.replace(/\\/g, '/');
}

function isWithinDir(path: string, dir: string): boolean {
const normalizedPath = toGlobPath(path);
const normalizedDir = toGlobPath(dir).replace(/\/$/, '');
return normalizedPath === normalizedDir || normalizedPath.startsWith(`${normalizedDir}/`);
}
// Parse CLI args: first = primary dir, rest = extra dirs
const args = process.argv.slice(2).map((d) => resolve(ROOT, d));
if (args.length === 0) {
Expand All @@ -169,7 +178,7 @@ const project = new Project({

// Add extra directory source files to the project so ts-morph can resolve them
for (const dir of extraDirs) {
project.addSourceFilesAtPaths(join(dir, '*.ts'));
project.addSourceFilesAtPaths(toGlobPath(join(dir, '*.ts')));
}

interface FieldEntry {
Expand Down Expand Up @@ -224,7 +233,7 @@ const fileMap = new Map<string, MetaInterface[]>();
const scanDirs = [primaryDir, ...extraDirs];

for (const scanDir of scanDirs) {
for (const sourceFile of project.getSourceFiles(join(scanDir, '*.ts'))) {
for (const sourceFile of project.getSourceFiles(toGlobPath(join(scanDir, '*.ts')))) {
const filePath = sourceFile.getFilePath();

// Skip already-generated files and the meta-types file
Expand Down Expand Up @@ -401,7 +410,7 @@ for (const [filePath, metas] of fileMap) {

const lines: string[] = [HEADER, `import type { ModelMeta } from "${importPath}";\n`];

const isPrimaryDir = filePath.startsWith(primaryDir);
const isPrimaryDir = isWithinDir(filePath, primaryDir);

for (const meta of metas) {
const varName = `${meta.interfaceName}Meta`;
Expand Down
159 changes: 149 additions & 10 deletions packages/contracts/src/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import type {
Channel,
UserReference,
Coverage,
AssetType,
ProposalSnapshotVehicle,
ProposalSnapshotProperty,
} from './common.js';
import type { CustomerPhoneNumber } from './common.js';
import type { PolicyVersionType } from './graphql/policies.js';
import type { ProposalSnapshotCustomer } from './proposals.js';

// ============================================================================
Expand Down Expand Up @@ -156,10 +158,35 @@ type PolicySnapshotElectronicDevice = Record<string, never>;
export interface GetPolicyDetailRequest {
/**
* The unique identifier of the insurance policy for which detailed information is requested.
*
* Ayrıntılı bilgisi istenen sigorta poliçesinin benzersiz tanımlayıcısı.
*/
readonly policyId: string;

/** Optional policy version to retrieve. When omitted, the latest version is returned. */
readonly version?: number;
}

/**
* Policy version source.
*/
export enum PolicyVersionSource {
Unknown = 'UNKNOWN',
AgentPanel = 'AGENT_PANEL',
PolicyTransfer = 'POLICY_TRANSFER',
Manual = 'MANUAL',
}

/**
* Summary item for a version stored on a policy.
*/
export interface PolicyVersionSummary {
readonly version: number;
readonly versionType: PolicyVersionType;
readonly timestamp: string;
readonly source: PolicyVersionSource;
readonly updateReasonText: string | null;
readonly hasSnapshotChange: boolean;
readonly hasCoverageChange: boolean;
readonly hasPremiumChange: boolean;
}

/**
Expand Down Expand Up @@ -210,7 +237,7 @@ export interface GetPolicyDetailResult {
*
* Sigorta ürününün tanımlayıcısı.
*/
readonly productId: number;
readonly productId: number | null;

/**
* The identifier of the insurance company providing the coverage.
Expand Down Expand Up @@ -238,14 +265,14 @@ export interface GetPolicyDetailResult {
*
* Vergi ve ücretler öncesi net prim tutarı.
*/
readonly netPremium: number;
readonly netPremium: number | null;

/**
* The total premium amount including all taxes and fees.
*
* Tüm vergi ve ücretler dahil toplam prim tutarı.
*/
readonly grossPremium: number;
readonly grossPremium: number | null;

/**
* The commission amount paid to the agent, if applicable.
Expand All @@ -268,6 +295,18 @@ export interface GetPolicyDetailResult {
*/
readonly currency: Currency;

/** Exchange rate used to convert policy monetary amounts to Turkish Lira. */
readonly exchangeRate: number;

/** Net premium converted to Turkish Lira. */
readonly netPremiumTL: number | null;

/** Gross premium converted to Turkish Lira. */
readonly grossPremiumTL: number | null;

/** Commission converted to Turkish Lira. */
readonly commissionTL: number | null;

/**
* The proposal number assigned by the insurance company.
*
Expand All @@ -287,7 +326,7 @@ export interface GetPolicyDetailResult {
*
* Harici sigorta hizmetlerindeki poliçe için referans tanımlayıcısı.
*/
readonly insuranceServicesPolicyReference: string;
readonly insuranceServicesPolicyReference: string | null;

/**
* The date and time when the policy was created.
Expand Down Expand Up @@ -379,6 +418,27 @@ export interface GetPolicyDetailResult {
* Bu poliçenin satıldığı satış kanalı.
*/
readonly channel: Channel;

/** Additional policy metadata. */
readonly metadata: Readonly<Record<string, unknown>> | null;

/** Branch assigned to the policy. */
readonly agentBranchId: string | null;

/** Net premium difference introduced by the current version. */
readonly netPremiumChange: number | null;

/** Gross premium difference introduced by the current version. */
readonly grossPremiumChange: number | null;

/** Commission difference introduced by the current version. */
readonly commissionChange: number | null;

/** Current policy version number. */
readonly currentVersion: number;

/** Available policy versions. */
readonly versions: readonly PolicyVersionSummary[] | null;
}

// ============================================================================
Expand Down Expand Up @@ -502,6 +562,53 @@ export interface SetPolicyBranchRequest {
readonly branchId: string;
}

// ============================================================================
// POLICY CLAIM TYPES
// ============================================================================

/**
* Request to search for an existing policy that can be claimed by the current agent user.
*/
export interface SearchPolicyForClaimRequest {
readonly insuranceCompanyId: number;
readonly policyNumber: string;
readonly endorsementNumber: number;
readonly renewalNumber: number;
}

/**
* Response for policy claim search.
*/
export interface SearchPolicyForClaimResult {
readonly found: boolean;
readonly owned: boolean;
readonly ownedBySelf: boolean;
readonly policyId: string | null;
readonly requiresBranchSelection: boolean;
readonly candidateBranchIds: readonly string[];
readonly endorsementAhead: boolean;
readonly lastEndorsementNumber: number | null;
}

/**
* Request to claim ownership of an unowned policy.
*/
export interface ClaimPolicyRequest {
readonly policyId: string;
readonly agentBranchId?: string | null;
}

/**
* Request to append a manual endorsement to an existing policy.
*/
export interface AddPolicyEndorsementRequest {
readonly policyId: string;
readonly netPremium?: number | null;
readonly grossPremium?: number | null;
readonly commission?: number | null;
readonly reason: string;
}

// ============================================================================
// MANUAL POLICY TYPES
// ============================================================================
Expand All @@ -510,13 +617,29 @@ export interface SetPolicyBranchRequest {
* Request to create manual policy
*/
export interface CreateManualPolicyRequest {
readonly customerId: string;
readonly policyNumber: string;
readonly insuranceCompanyId: number;
readonly productId?: number | null;
readonly productBranch: ProductBranch;
readonly policyNumber: string;
readonly insuredCustomerId: string;
readonly insurerCustomerId: string;
readonly coverage?: Coverage | null;
readonly startDate: string;
readonly endDate: string;
readonly premium: number;
readonly arrangementDate?: string | null;
readonly netPremium?: number | null;
readonly grossPremium?: number | null;
readonly commission?: number | null;
readonly renewalNumber: number;
readonly daskPolicyNumber?: string | null;
readonly proposalId?: string | null;
readonly currency?: Currency;
readonly exchangeRate?: number;
readonly paymentType?: PaymentOption;
readonly assetId?: string | null;
readonly assetType?: AssetType | null;
readonly metadata?: Readonly<Record<string, unknown>> | null;
readonly agentBranchId?: string | null;
}

/**
Expand All @@ -532,9 +655,25 @@ export interface CreateManualPolicyResult {
export interface UpdateManualPolicyRequest {
readonly policyId: string;
readonly policyNumber?: string;
readonly insuranceCompanyId?: number | null;
readonly productId?: number | null;
readonly productBranch?: ProductBranch | null;
readonly insuredCustomerId?: string | null;
readonly insurerCustomerId?: string | null;
readonly coverage?: Coverage | null;
readonly startDate?: string;
readonly endDate?: string;
readonly premium?: number;
readonly arrangementDate?: string | null;
readonly netPremium?: number | null;
readonly grossPremium?: number | null;
readonly commission?: number | null;
readonly daskPolicyNumber?: string | null;
readonly proposalId?: string | null;
readonly currency?: Currency | null;
readonly exchangeRate?: number | null;
readonly paymentType?: PaymentOption | null;
readonly assetId?: string | null;
readonly assetType?: AssetType | null;
}

// ============================================================================
Expand Down
55 changes: 53 additions & 2 deletions packages/sdk/src/clients/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import type {
CreateManualPolicyRequest,
CreateManualPolicyResult,
UpdateManualPolicyRequest,
SearchPolicyForClaimRequest,
SearchPolicyForClaimResult,
ClaimPolicyRequest,
AddPolicyEndorsementRequest,
GetPolicyCountAndPremiumAnalyticsRequest,
GetPolicyCountAndPremiumAnalyticsResult,
GetPolicyRenewalAnalyticsRequest,
Expand Down Expand Up @@ -95,7 +99,7 @@ export class InsurUpPolicyClient {
options?: RequestOptions
): Promise<InsurUpResult<GetPolicyDetailResult>> {
return this.http.get<GetPolicyDetailResult>(
endpoints.policies.getPolicyDetail.render(request.policyId),
endpoints.policies.getPolicyDetail.render(request.policyId, request.version),
options
);
}
Expand Down Expand Up @@ -168,7 +172,7 @@ export class InsurUpPolicyClient {
request: SetPolicyBranchRequest,
options?: RequestOptions
): Promise<InsurUpResult> {
return this.http.postNoContent(
return this.http.putNoContent(
endpoints.policies.setPolicyBranch.render(request.policyId),
request,
options
Expand Down Expand Up @@ -212,6 +216,53 @@ export class InsurUpPolicyClient {
options
);
}
/**
* Searches for an existing unowned policy that the current agent user can claim.
*
* @param request Policy claim search criteria
* @returns Policy claim search result
*/
async searchPolicyForClaim(
request: SearchPolicyForClaimRequest,
options?: RequestOptions
): Promise<InsurUpResult<SearchPolicyForClaimResult>> {
return this.http.post<SearchPolicyForClaimResult>(
endpoints.policies.searchPolicyForClaim.definition,
request,
options
);
}

/**
* Assigns an unowned policy to the current agent user and optionally to a selected branch.
*
* @param request Policy claim request
* @returns Operation result
*/
async claimPolicy(request: ClaimPolicyRequest, options?: RequestOptions): Promise<InsurUpResult> {
return this.http.postNoContent(
endpoints.policies.claimPolicy.render(request.policyId),
request,
options
);
}

/**
* Appends a manual endorsement as the next version of an existing policy.
*
* @param request Manual endorsement request
* @returns Operation result
*/
async addPolicyEndorsement(
request: AddPolicyEndorsementRequest,
options?: RequestOptions
): Promise<InsurUpResult> {
return this.http.postNoContent(
endpoints.policies.addPolicyEndorsement.render(request.policyId),
request,
options
);
}

/**
* Retrieves comprehensive policy count and gross premium analytics with flexible filtering and grouping options.
Expand Down
Loading
Loading