merge: bring latest origin/main into dev (main wins conflicts)

This commit is contained in:
jarvis
2026-11-15 11:44:04 +03:30
154 changed files with 20772 additions and 3734 deletions
+285 -5
View File
@@ -354,6 +354,90 @@ export interface SetStorageQuotaRequest {
/** سقف‌های آمادهٔ تعداد کاربر. بالاتر از ۲۰ توافقی و با عدد جدا ذخیره می‌شود. */
export const BILLING_USER_CAPS = [3, 10, 20] as const;
/** سطح امکانات اشتراک. دمو ۷ روزه از هسته شروع می‌شود. */
export type ProductPlanCode = "core" | "team" | "organization" | "dedicated";
export const PRODUCT_PLAN_CODES: ProductPlanCode[] = [
"core",
"team",
"organization",
"dedicated",
];
export const PRODUCT_PLAN_LABELS: Record<ProductPlanCode, string> = {
core: "هسته",
team: "تیم",
organization: "سازمان",
dedicated: "اختصاصی",
};
/** null یعنی سقف را عوض نکن؛ اختصاصی توافقی است. */
export const PRODUCT_PLAN_LIMITS: Record<
ProductPlanCode,
{ maxUsers: number | null; maxOrganizations: number | null }
> = {
core: { maxUsers: 3, maxOrganizations: 1 },
team: { maxUsers: 10, maxOrganizations: 3 },
organization: { maxUsers: 20, maxOrganizations: 5 },
dedicated: { maxUsers: null, maxOrganizations: null },
};
const PRODUCT_PLAN_CORE: OrgModuleKey[] = [
"customers",
"attachments",
"activities",
"notes",
"products",
"invoices",
"quotes",
"lead_forms",
"team_settings",
];
const PRODUCT_PLAN_TEAM: OrgModuleKey[] = [
"routines",
"conversations",
"pipeline",
"saved_views",
"leads",
"commissions",
"sales_forecast",
"reports",
"project_boards",
"sms_campaigns",
"message_automations",
"tickets",
"faq",
"cheques",
"treasury",
"workflow_automations",
"teams",
"gamification",
"custom_fields",
];
const PRODUCT_PLAN_ORGANIZATION: OrgModuleKey[] = [
"inventory",
"currencies",
"tahesab",
"workflow_automations_advanced",
"audit_logs",
"prior_data_archive",
"public_api",
"woocommerce",
"montify",
"voip",
"reservations",
"loyalty",
"behavior",
];
export function modulesForProductPlan(code: ProductPlanCode): OrgModuleKey[] {
if (code === "core") return [...PRODUCT_PLAN_CORE];
if (code === "team") return [...PRODUCT_PLAN_CORE, ...PRODUCT_PLAN_TEAM];
return [...PRODUCT_PLAN_CORE, ...PRODUCT_PLAN_TEAM, ...PRODUCT_PLAN_ORGANIZATION];
}
export interface OwnerSeatUsageDto {
usedUsers: number;
maxUsers: number | null;
@@ -562,14 +646,17 @@ export const DATA_ACCESS_LEGACY_SCOPE: Record<DataAccessSection, DataScope | nul
};
/**
* یک قانون: فیلدهای پرشده با AND.
* قوانین متعدد در SectionDataAccess با OR ترکیب می‌شوند.
* یک قانون: فیلدهای پرشده با OR (هر بُعد کافی است).
* قوانین متعدد در SectionDataAccess هم با OR ترکیب می‌شوند.
* ابعاد بلااستفاده برای یک بخش نادیده گرفته می‌شوند.
*/
export type DataAccessRule = {
/** self / team → مالک / مسئول / نویسنده (بسته به بخش) */
owners?: DataAccessOwnerKind[];
/** مشتریان: گروه‌ها */
/**
* @deprecated دید گروه مشتریان از مسئول‌گروه است، نه این فیلد.
* در پارس باقی می‌ماند برای سازگاری؛ در فیلتر دسترسی نادیده گرفته می‌شود.
*/
groupIds?: string[];
/** مشتریان: importSource/sourceRef · لیدها: source · یادداشت: noteType · تیکت: status */
sources?: string[];
@@ -636,6 +723,22 @@ export function parseUserTreasuryAccess(raw: unknown): UserTreasuryAccess | null
};
}
/**
* دسترسی مالی کاربر، اگر تنظیم شده باشد، کلیدهای مالی نقش را جایگزین می‌کند.
* null یعنی همان مجوزهای نقش.
*/
export function permissionsWithTreasuryOverride(
rolePermissions: readonly string[],
override: UserTreasuryAccess | null,
): string[] {
if (!override) return [...rolePermissions];
const rest = rolePermissions.filter(
(key) => key !== "treasury" && !key.startsWith("treasury_"),
);
if (!override.enabled) return rest;
return ["treasury", ...override.sections, ...rest];
}
export function emptySectionDataAccess(): SectionDataAccess {
return { mode: "all", rules: [] };
}
@@ -1224,6 +1327,11 @@ export interface CustomerGroupSummaryDto {
source?: "manual" | "tahesab";
}
export interface CustomerGroupAssigneeDto {
id: string;
fullName: string;
}
export interface CustomerGroupDto {
id: string;
name: string;
@@ -1236,11 +1344,14 @@ export interface CustomerGroupDto {
/** گروه اصلی؛ خالی یعنی خودش اصلی است */
parentId?: string | null;
parentName?: string | null;
/** مسئولان گروه (اختیاری) */
assignees: CustomerGroupAssigneeDto[];
}
export interface CreateCustomerGroupRequest {
name: string;
color?: CustomerGroupColor;
assigneeIds?: string[];
}
export interface UpdateCustomerGroupRequest {
@@ -1248,6 +1359,8 @@ export interface UpdateCustomerGroupRequest {
color?: CustomerGroupColor;
/** null = برداشتن گروه اصلی */
parentId?: string | null;
/** جایگزینی کامل فهرست مسئولان */
assigneeIds?: string[];
}
export interface CompanySummaryDto {
@@ -1513,6 +1626,13 @@ export interface DealDto {
lineItems: DealLineItemDto[];
createdAt: string;
updatedAt: string;
/**
* فقط در برد کانبان پر می‌شود:
* none=بدون فعالیت، overdue=عقب‌افتاده، upcoming=آینده، done=انجام‌شده
*/
activityCue?: DealActivityCue;
/** لیست مرتب‌شدهٔ فعالیت‌های باز/انجام‌شده برای پاپ‌آپ کارت */
activitySummaries?: DealActivitySummaryDto[];
}
export interface PipelineBoardStageDto extends PipelineStageDto {
@@ -1739,7 +1859,86 @@ export interface MoveDealRequest {
export type ActivityType = "call" | "meeting" | "task" | "note";
export type ActivityStatus = "open" | "done" | "canceled";
/** وضعیت فعالیت مرتبط با معامله برای نشانگر کارت کانبان */
export type DealActivityCue = "none" | "upcoming" | "overdue" | "done";
/** خلاصهٔ کوتاه فعالیت روی کارت معامله */
export interface DealActivitySummaryDto {
id: string;
title: string;
type: ActivityType;
status: ActivityStatus;
dueAt: string | null;
/** وضعیت نسبی همین آیتم برای رنگ نقطه */
cue: Exclude<DealActivityCue, "none">;
}
export type ActivityPriority = "very_low" | "low" | "medium" | "high" | "very_high";
/** ترتیب نمایش ثابت (تعداد تغییر نمی‌کند) */
export const ACTIVITY_PRIORITY_KEYS: ActivityPriority[] = [
"very_high",
"high",
"medium",
"low",
"very_low",
];
export type ActivityPrioritySetting = {
key: ActivityPriority;
label: string;
/** رنگ متن/پرچم — #RRGGBB */
color: string;
};
export const DEFAULT_ACTIVITY_PRIORITY_SETTINGS: ActivityPrioritySetting[] = [
{ key: "very_high", label: "خیلی زیاد", color: "#dc2626" },
{ key: "high", label: "زیاد", color: "#ea580c" },
{ key: "medium", label: "متوسط", color: "#eab308" },
{ key: "low", label: "کم", color: "#16a34a" },
{ key: "very_low", label: "خیلی کم", color: "#94a3b8" },
];
const PRIORITY_KEY_SET = new Set<string>(ACTIVITY_PRIORITY_KEYS);
const HEX_COLOR = /^#[0-9a-fA-F]{6}$/;
/** ادغام تنظیم ذخیره‌شده با پیش‌فرض‌ها؛ همیشه ۵ سطح کامل */
export function parseActivityPrioritySettings(raw: unknown): ActivityPrioritySetting[] {
const overrides = new Map<ActivityPriority, { label?: string; color?: string }>();
const bag =
raw && typeof raw === "object" && !Array.isArray(raw)
? (raw as Record<string, unknown>)
: Array.isArray(raw)
? Object.fromEntries(
raw
.filter((r): r is Record<string, unknown> => !!r && typeof r === "object")
.map((r) => [String(r.key ?? ""), r]),
)
: {};
for (const [key, val] of Object.entries(bag)) {
if (!PRIORITY_KEY_SET.has(key) || !val || typeof val !== "object" || Array.isArray(val)) continue;
const row = val as Record<string, unknown>;
const label = typeof row.label === "string" ? row.label.trim() : "";
const color = typeof row.color === "string" ? row.color.trim() : "";
overrides.set(key as ActivityPriority, {
...(label ? { label: label.slice(0, 40) } : {}),
...(HEX_COLOR.test(color) ? { color } : {}),
});
}
return DEFAULT_ACTIVITY_PRIORITY_SETTINGS.map((d) => {
const o = overrides.get(d.key);
return {
key: d.key,
label: o?.label || d.label,
color: o?.color || d.color,
};
});
}
export type UpdateActivityPrioritiesRequest = {
items: Array<{ key: ActivityPriority; label: string; color: string }>;
};
export type ActivityFilter = "today" | "overdue" | "upcoming" | "done" | "all";
export type ActivityStageColor = "green" | "orange" | "purple" | "blue" | "rose" | "slate";
@@ -2022,6 +2221,16 @@ export interface ActivityImageDto {
createdAt: string;
}
export type ActivityCompletionMode = "any" | "all";
/** چه کسانی می‌توانند فعالیت را ویرایش یا حذف کنند (علاوه بر owner/admin) */
export type ActivityEditPolicy = "creator" | "assignees";
export const ACTIVITY_EDIT_POLICY_LABELS: Record<ActivityEditPolicy, string> = {
creator: "فقط ایجادکننده",
assignees: "همهٔ مسئولان",
};
export interface ActivityDto {
id: string;
type: ActivityType;
@@ -2039,6 +2248,12 @@ export interface ActivityDto {
/** زمان ارسال یادآور (اگر ارسال شده باشد) */
reminderSentAt: string | null;
completedAt: string | null;
/** any = با انجام یکی کافی است؛ all = هر مسئول باید سهم خودش را بزند */
completionMode?: ActivityCompletionMode;
/** شناسهٔ مسئولانی که سهم خود را در حالت all ثبت کرده‌اند */
completedByIds?: string[];
/** پیش‌فرض creator؛ assignees یعنی همهٔ مسئولان هم می‌توانند ویرایش/حذف کنند */
editPolicy?: ActivityEditPolicy;
/** manual یا didar؛ برای جدا کردن سابقهٔ قبلی */
importSource?: string;
promotedFromPriorAt?: string | null;
@@ -2096,6 +2311,10 @@ export interface CreateActivityRequest {
assigneeId?: string | null;
/** چند مسئول؛ اولی به‌عنوان assigneeId ذخیره می‌شود */
assigneeIds?: string[];
/** پیش‌فرض any. فقط وقتی چند مسئول دارد معنی دارد */
completionMode?: ActivityCompletionMode;
/** پیش‌فرض creator */
editPolicy?: ActivityEditPolicy;
}
export interface UpdateActivityRequest {
@@ -2120,6 +2339,8 @@ export interface UpdateActivityRequest {
leadId?: string | null;
assigneeId?: string | null;
assigneeIds?: string[];
completionMode?: ActivityCompletionMode;
editPolicy?: ActivityEditPolicy;
}
export interface ActivitySummaryDto {
@@ -4705,8 +4926,11 @@ export const MESSAGE_AUTOMATION_FIELDS = [
{ token: "{نام}", label: "نام مشتری" },
{ token: "{شماره}", label: "شماره موبایل" },
{ token: "{تاریخ}", label: "تاریخ ارسال" },
{ token: "{عنوان}", label: "عنوان رکورد" },
{ token: "{شرکت}", label: "نام شرکت" },
{ token: "{عنوان}", label: "عنوان / سمت" },
{ token: "{شرکت}", label: "شرکت مشتری" },
{ token: "{از طرف}", label: "نام سازمان فرستنده" },
{ token: "{مانده ریالی}", label: "مانده مالی (ریالی)" },
{ token: "{مانده فلزی}", label: "مانده وزنی فلزات" },
] as const;
/** First-part Persian SMS limit (legacy UI estimate). Prefer countSmsParts(). */
@@ -5228,6 +5452,39 @@ export interface OutboundSmsHistoryResponse {
items: OutboundSmsLogDto[];
}
/* ——— قالب‌های آمادهٔ پیامک دستی (سازمانی) ——— */
export type SmsTemplateDto = {
id: string;
name: string;
body: string;
};
export const SMS_TEMPLATE_MAX = 40;
export const SMS_TEMPLATE_NAME_MAX = 80;
export const SMS_TEMPLATE_BODY_MAX = 500;
/** نرمال‌سازی لیست ذخیره‌شده؛ آیتم‌های ناقص حذف می‌شوند */
export function parseSmsTemplates(raw: unknown): SmsTemplateDto[] {
if (!Array.isArray(raw)) return [];
const out: SmsTemplateDto[] = [];
for (const row of raw) {
if (!row || typeof row !== "object") continue;
const rec = row as Record<string, unknown>;
const id = typeof rec.id === "string" ? rec.id.trim() : "";
const name = typeof rec.name === "string" ? rec.name.trim() : "";
const body = typeof rec.body === "string" ? rec.body.trim() : "";
if (!id || !name || body.length < 2) continue;
out.push({
id,
name: name.slice(0, SMS_TEMPLATE_NAME_MAX),
body: body.slice(0, SMS_TEMPLATE_BODY_MAX),
});
if (out.length >= SMS_TEMPLATE_MAX) break;
}
return out;
}
/* ——— پیامک گروهی ——— */
export type SmsCampaignStatus =
@@ -5553,13 +5810,21 @@ export type VoipCallStatus =
| "completed"
| "failed";
export type VoipProvider = "generic" | "daftareshoma";
export interface VoipConnectionDto {
id: string;
label: string;
provider: VoipProvider;
enabled: boolean;
webhookSecretSet: boolean;
apiTokenSet: boolean;
/** قالب URL برای شروع تماس؛ {number} جایگزین می‌شود */
clickToCallUrl: string | null;
/** شماره مبدأ تماس خروجی (دفتر شما) */
fromNumber: string | null;
/** خط/داخلی سازمان (دفتر شما) */
callerExtension: string | null;
lastEventAt: string | null;
lastError: string | null;
callCount: number;
@@ -5569,8 +5834,13 @@ export interface VoipConnectionDto {
export interface CreateVoipConnectionRequest {
label: string;
provider?: VoipProvider;
webhookSecret?: string;
clickToCallUrl?: string | null;
/** توکن Bearer API دفتر شما */
apiToken?: string;
fromNumber?: string | null;
callerExtension?: string | null;
enabled?: boolean;
}
@@ -5578,6 +5848,9 @@ export interface UpdateVoipConnectionRequest {
label?: string;
webhookSecret?: string | null;
clickToCallUrl?: string | null;
apiToken?: string | null;
fromNumber?: string | null;
callerExtension?: string | null;
enabled?: boolean;
}
@@ -5595,6 +5868,8 @@ export interface VoipCallLogDto {
status: VoipCallStatus | string;
fromNumber: string | null;
toNumber: string | null;
/** خط/داخلی سازمانی که تماس روی آن بوده */
lineExtension: string | null;
personId: string | null;
personName: string | null;
activityId: string | null;
@@ -5621,6 +5896,8 @@ export interface VoipWebhookEvent {
status: VoipCallStatus | string;
from?: string;
to?: string;
/** خط/داخلی سازمان */
lineExtension?: string;
startedAt?: string;
endedAt?: string;
durationSec?: number;
@@ -6314,6 +6591,7 @@ export interface RoutineDto {
isActive: boolean;
/** سازندهٔ روتین؛ عضو عادی فقط روتین خودش را ویرایش می‌کند */
createdById: string | null;
createdBy: UserSummaryDto | null;
recurrenceLabel: string;
/** درصد اجرا در ۳۰ روز اخیر */
executionRate: number | null;
@@ -6627,6 +6905,8 @@ export interface TreasuryPartyBalanceDto {
amount: string;
settledAmount: string;
remaining: string;
/** بخشی از مانده که با دریافت/پرداخت روی سندهای باز کم می‌شود */
documentRemaining: string;
}
export interface TreasuryDashboardDto {