@torrow/sdk-client 0.18.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -52,8 +52,37 @@ var TorrowSdkErrorDomain = /* @__PURE__ */ ((TorrowSdkErrorDomain2) => {
52
52
  TorrowSdkErrorDomain2["BehaviorSettings"] = "BehaviorSettings";
53
53
  TorrowSdkErrorDomain2["Otp"] = "Otp";
54
54
  TorrowSdkErrorDomain2["AuthSession"] = "AuthSession";
55
+ TorrowSdkErrorDomain2["Profiles"] = "Profiles";
55
56
  return TorrowSdkErrorDomain2;
56
57
  })(TorrowSdkErrorDomain || {});
58
+ var ProfileErrorReason = /* @__PURE__ */ ((ProfileErrorReason2) => {
59
+ ProfileErrorReason2["TargetNotProfile"] = "TargetNotProfile";
60
+ ProfileErrorReason2["LastProfile"] = "LastProfile";
61
+ ProfileErrorReason2["SelectedDefault"] = "SelectedDefault";
62
+ ProfileErrorReason2["UnusableProfileList"] = "UnusableProfileList";
63
+ ProfileErrorReason2["UnusableDefault"] = "UnusableDefault";
64
+ return ProfileErrorReason2;
65
+ })(ProfileErrorReason || {});
66
+ var ProfileOperation = /* @__PURE__ */ ((ProfileOperation2) => {
67
+ ProfileOperation2["SetDefaultProfileByContactId"] = "setDefaultProfileByContactId";
68
+ ProfileOperation2["Remove"] = "remove";
69
+ return ProfileOperation2;
70
+ })(ProfileOperation || {});
71
+ var ProfileFailureAt = /* @__PURE__ */ ((ProfileFailureAt2) => {
72
+ ProfileFailureAt2["ValidateInput"] = "ValidateInput";
73
+ ProfileFailureAt2["ReadProfiles"] = "ReadProfiles";
74
+ ProfileFailureAt2["ValidateProfiles"] = "ValidateProfiles";
75
+ ProfileFailureAt2["ReadDefault"] = "ReadDefault";
76
+ ProfileFailureAt2["ValidateDefault"] = "ValidateDefault";
77
+ ProfileFailureAt2["Write"] = "Write";
78
+ ProfileFailureAt2["ValidateWriteResponse"] = "ValidateWriteResponse";
79
+ ProfileFailureAt2["ProjectResponse"] = "ProjectResponse";
80
+ return ProfileFailureAt2;
81
+ })(ProfileFailureAt || {});
82
+ var ProfileEffectStep = /* @__PURE__ */ ((ProfileEffectStep2) => {
83
+ ProfileEffectStep2["Write"] = "Write";
84
+ return ProfileEffectStep2;
85
+ })(ProfileEffectStep || {});
57
86
  var FileMetadataErrorReason = /* @__PURE__ */ ((FileMetadataErrorReason2) => {
58
87
  FileMetadataErrorReason2["ContentTypeUnavailable"] = "ContentTypeUnavailable";
59
88
  FileMetadataErrorReason2["SubscriptionIsNotValid"] = "SubscriptionIsNotValid";
@@ -10169,9 +10198,38 @@ function projectItemSocial(item) {
10169
10198
  return result;
10170
10199
  }
10171
10200
 
10201
+ // ../../src/resources/calendars/calendar-view-type.ts
10202
+ var CalendarViewTypeValues = /* @__PURE__ */ ((CalendarViewTypeValues2) => {
10203
+ CalendarViewTypeValues2[CalendarViewTypeValues2["Day"] = 0] = "Day";
10204
+ CalendarViewTypeValues2[CalendarViewTypeValues2["Poster"] = 4] = "Poster";
10205
+ CalendarViewTypeValues2[CalendarViewTypeValues2["Schedule"] = 5] = "Schedule";
10206
+ return CalendarViewTypeValues2;
10207
+ })(CalendarViewTypeValues || {});
10208
+ function normalizeCalendarViewIndex(value) {
10209
+ switch (value) {
10210
+ case 4 /* Poster */:
10211
+ return 4 /* Poster */;
10212
+ case 5 /* Schedule */:
10213
+ return 5 /* Schedule */;
10214
+ default:
10215
+ return 0 /* Day */;
10216
+ }
10217
+ }
10218
+
10172
10219
  // ../../src/resources/calendars/read-projection.ts
10173
10220
  function projectCalendarItem(item) {
10174
- return projectItemSocial(item);
10221
+ const projected = projectItemSocial(item);
10222
+ if (projected !== null && typeof projected === "object" && !Array.isArray(projected)) {
10223
+ const result = {
10224
+ ...projected,
10225
+ calendarViewIndex: normalizeCalendarViewIndex(
10226
+ "calendarViewIndex" in projected ? projected.calendarViewIndex : void 0
10227
+ )
10228
+ };
10229
+ Reflect.deleteProperty(result, "scheduleRangeExceptions");
10230
+ return result;
10231
+ }
10232
+ return projected;
10175
10233
  }
10176
10234
 
10177
10235
  // ../../src/resources/notes/read-projection.ts
@@ -12069,67 +12127,12 @@ async function patchItem(http, itemId, fields, options, adapter) {
12069
12127
  }
12070
12128
  }
12071
12129
 
12072
- // ../../src/resources/common/schedule-rids.ts
12073
- function record3(value) {
12074
- return value !== null && typeof value === "object" && !Array.isArray(value);
12075
- }
12076
- function normalizeRangeList(value, path) {
12077
- if (!Array.isArray(value)) {
12078
- return;
12079
- }
12080
- value.forEach((range, index) => {
12081
- if (record3(range)) {
12082
- ensureNestedRidForWrite(range, `${path}[${index}]`);
12083
- }
12084
- });
12085
- }
12086
- function normalizeScheduleRidsForWrite(value, path) {
12087
- if (!record3(value)) {
12088
- return;
12089
- }
12090
- normalizeRangeList(value.scheduleRanges, `${path}.scheduleRanges`);
12091
- const exceptions = value.scheduleRangeExceptions;
12092
- if (record3(exceptions)) {
12093
- normalizeRangeList(exceptions.replacedTimeRanges, `${path}.scheduleRangeExceptions.replacedTimeRanges`);
12094
- normalizeRangeList(exceptions.excludedTimeRanges, `${path}.scheduleRangeExceptions.excludedTimeRanges`);
12095
- }
12096
- }
12097
- function normalizeItemScheduleRidsForWrite(body, path) {
12098
- normalizeScheduleRidsForWrite(body.schedule, `${path}.schedule`);
12099
- const priceInfo = body.priceInfo;
12100
- if (!record3(priceInfo) || !Array.isArray(priceInfo.settings)) {
12101
- return;
12102
- }
12103
- priceInfo.settings.forEach((setting, index) => {
12104
- if (record3(setting)) {
12105
- normalizeScheduleRidsForWrite(setting.schedule, `${path}.priceInfo.settings[${index}].schedule`);
12106
- }
12107
- });
12108
- }
12109
-
12110
12130
  // ../../src/resources/calendars/calendar-patch.ts
12111
- function isRecord2(value) {
12112
- return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
12113
- }
12114
12131
  function isCalendarPatchViewIndex(value) {
12115
- return typeof value === "number" && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
12116
- }
12117
- function isTimeRange(value, allowMissingRid = false) {
12118
- const rid2 = isRecord2(value) ? value.rid : void 0;
12119
- return isRecord2(value) && Object.keys(value).every((key) => ["rid", "begin", "end", "name"].includes(key)) && (isValidRid(rid2) || allowMissingRid && (rid2 == null || typeof rid2 === "string" && rid2.trim() === "")) && value.begin instanceof Date && Number.isFinite(value.begin.getTime()) && value.end instanceof Date && Number.isFinite(value.end.getTime()) && (value.name == null || typeof value.name === "string");
12120
- }
12121
- function isCalendarPatchExceptions(value) {
12122
- return isRecord2(value) && Object.keys(value).every((key) => ["replacedTimeRanges", "excludedTimeRanges"].includes(key)) && Object.values(value).every(
12123
- (ranges) => ranges == null || Array.isArray(ranges) && ranges.every((range) => isTimeRange(range))
12124
- );
12125
- }
12126
- function isCalendarPatchInputExceptions(value) {
12127
- return isRecord2(value) && Object.keys(value).every((key) => ["replacedTimeRanges", "excludedTimeRanges"].includes(key)) && Object.values(value).every(
12128
- (ranges) => ranges == null || Array.isArray(ranges) && ranges.every((range) => isTimeRange(range, true))
12129
- );
12132
+ return value === 0 /* Day */ || value === 4 /* Poster */ || value === 5 /* Schedule */;
12130
12133
  }
12131
12134
  function projectCalendarPatchItem(item) {
12132
- if (item.description != null && typeof item.description !== "string" || item.name != null && typeof item.name !== "string" || item.calendarViewIndex != null && !isCalendarPatchViewIndex(item.calendarViewIndex) || item.scheduleRangeExceptions != null && !isCalendarPatchExceptions(item.scheduleRangeExceptions)) {
12135
+ if (item.description != null && typeof item.description !== "string" || item.name != null && typeof item.name !== "string") {
12133
12136
  throw itemPatchError("InvalidResponse" /* InvalidResponse */);
12134
12137
  }
12135
12138
  return item;
@@ -12146,26 +12149,13 @@ function assertCalendarPatchSnapshot(item) {
12146
12149
  function createCalendarPatchAdapter() {
12147
12150
  return {
12148
12151
  operation: "CalendarsFacade.patch",
12149
- ridPaths: calendarPatchRidPaths,
12150
12152
  basePath: "/api/v1/calendars",
12151
12153
  objectType: TorrowObjectTypeCode.Calendar,
12152
12154
  discriminator: "CalendarItem" /* CalendarItem */,
12153
12155
  fields: {
12154
12156
  ...commonItemPatchFields,
12155
12157
  description: { kind: "String" /* String */, nullable: true },
12156
- calendarViewIndex: { kind: "Integer" /* Integer */, nullable: true, validate: isCalendarPatchViewIndex },
12157
- scheduleRangeExceptions: {
12158
- kind: "Object" /* Object */,
12159
- nullable: true,
12160
- validate: isCalendarPatchInputExceptions
12161
- }
12162
- },
12163
- validateFields: (fields) => {
12164
- try {
12165
- normalizeScheduleRidsForWrite(fields, "calendar");
12166
- } catch {
12167
- throw itemPatchError("InvalidInput" /* InvalidInput */);
12168
- }
12158
+ calendarViewIndex: { kind: "Integer" /* Integer */, validate: isCalendarPatchViewIndex }
12169
12159
  },
12170
12160
  assertSnapshot: assertCalendarPatchSnapshot,
12171
12161
  project: (item) => projectCalendarItem(projectCalendarPatchItem(item)),
@@ -12190,12 +12180,26 @@ var CalendarsFacade = class extends TorrowItemFacade {
12190
12180
  }
12191
12181
  /** Частично изменяет календарь: полный GET и максимум один CAS PUT, без deep merge/readback/retry. */
12192
12182
  patch(itemId, fields, options) {
12193
- return patchItem(this.http, itemId, fields, options, createCalendarPatchAdapter());
12183
+ let selected = fields;
12184
+ if (fields !== null && typeof fields === "object") {
12185
+ try {
12186
+ const view = Object.getOwnPropertyDescriptor(fields, "calendarViewIndex");
12187
+ if (view && Object.hasOwn(view, "value")) {
12188
+ const descriptors = Object.getOwnPropertyDescriptors(fields);
12189
+ descriptors.calendarViewIndex = { ...view, value: normalizeCalendarViewIndex(view.value) };
12190
+ selected = Object.create(Object.getPrototypeOf(fields), descriptors);
12191
+ }
12192
+ } catch {
12193
+ selected = fields;
12194
+ }
12195
+ }
12196
+ return patchItem(this.http, itemId, selected, options, createCalendarPatchAdapter());
12194
12197
  }
12195
12198
  /** `POST /api/v1/calendars` */
12196
12199
  create(body, options) {
12197
12200
  const payload = applyItemCreateDefaults(structuredClone(body), "CalendarItem" /* CalendarItem */, options?.publicityType);
12198
- normalizeScheduleRidsForWrite(payload, "calendar");
12201
+ payload.calendarViewIndex = normalizeCalendarViewIndex(payload.calendarViewIndex);
12202
+ Reflect.deleteProperty(payload, "scheduleRangeExceptions");
12199
12203
  return this.http.requestJson({
12200
12204
  method: "POST",
12201
12205
  path: BASE,
@@ -12211,7 +12215,8 @@ var CalendarsFacade = class extends TorrowItemFacade {
12211
12215
  update(body, options) {
12212
12216
  const itemId = requireItemUpdateId(body, "Calendar");
12213
12217
  const payload = structuredClone(body);
12214
- normalizeScheduleRidsForWrite(payload, "calendar");
12218
+ payload.calendarViewIndex = normalizeCalendarViewIndex(payload.calendarViewIndex);
12219
+ Reflect.deleteProperty(payload, "scheduleRangeExceptions");
12215
12220
  return this.http.requestJson({
12216
12221
  method: "PUT",
12217
12222
  path: `${BASE}/${encodePathSegment(itemId)}`,
@@ -12449,6 +12454,44 @@ function isItemPatchObjectArray(value) {
12449
12454
  return Array.isArray(value) && value.every(isItemPatchDtoObject);
12450
12455
  }
12451
12456
 
12457
+ // ../../src/resources/common/schedule-rids.ts
12458
+ function record3(value) {
12459
+ return value !== null && typeof value === "object" && !Array.isArray(value);
12460
+ }
12461
+ function normalizeRangeList(value, path) {
12462
+ if (!Array.isArray(value)) {
12463
+ return;
12464
+ }
12465
+ value.forEach((range, index) => {
12466
+ if (record3(range)) {
12467
+ ensureNestedRidForWrite(range, `${path}[${index}]`);
12468
+ }
12469
+ });
12470
+ }
12471
+ function normalizeScheduleRidsForWrite(value, path) {
12472
+ if (!record3(value)) {
12473
+ return;
12474
+ }
12475
+ normalizeRangeList(value.scheduleRanges, `${path}.scheduleRanges`);
12476
+ const exceptions = value.scheduleRangeExceptions;
12477
+ if (record3(exceptions)) {
12478
+ normalizeRangeList(exceptions.replacedTimeRanges, `${path}.scheduleRangeExceptions.replacedTimeRanges`);
12479
+ normalizeRangeList(exceptions.excludedTimeRanges, `${path}.scheduleRangeExceptions.excludedTimeRanges`);
12480
+ }
12481
+ }
12482
+ function normalizeItemScheduleRidsForWrite(body, path) {
12483
+ normalizeScheduleRidsForWrite(body.schedule, `${path}.schedule`);
12484
+ const priceInfo = body.priceInfo;
12485
+ if (!record3(priceInfo) || !Array.isArray(priceInfo.settings)) {
12486
+ return;
12487
+ }
12488
+ priceInfo.settings.forEach((setting, index) => {
12489
+ if (record3(setting)) {
12490
+ normalizeScheduleRidsForWrite(setting.schedule, `${path}.priceInfo.settings[${index}].schedule`);
12491
+ }
12492
+ });
12493
+ }
12494
+
12452
12495
  // ../../src/resources/common/case-action-rids.ts
12453
12496
  function normalizeCaseActionRidsForWrite(body, path) {
12454
12497
  if (!Array.isArray(body.caseActionList)) {
@@ -15652,6 +15695,63 @@ function prepareUserProfileItemForAdd(body) {
15652
15695
  return payload;
15653
15696
  }
15654
15697
 
15698
+ // ../../src/resources/user-profiles/profile-list-response-error.ts
15699
+ var ProfileListResponseError = class extends Error {
15700
+ constructor(message, cause) {
15701
+ super(message, { cause });
15702
+ }
15703
+ };
15704
+
15705
+ // ../../src/resources/user-profiles/read-default-profile.ts
15706
+ async function readDefaultProfile(http, listProfiles, options) {
15707
+ const dto = await http.requestJson({
15708
+ method: "GET",
15709
+ path: "/api/v1/user/defaultprofile",
15710
+ signal: options?.signal
15711
+ });
15712
+ if (dto !== null && dto !== void 0) {
15713
+ return projectContactItem(dto);
15714
+ }
15715
+ return (await listProfiles())[0] ?? null;
15716
+ }
15717
+
15718
+ // ../../src/resources/user-profiles/profile-write-guard.ts
15719
+ function assertUsableProfileIds(profiles) {
15720
+ const ids = /* @__PURE__ */ new Set();
15721
+ if (!Array.isArray(profiles) || profiles.length === 0 || profiles.some((profile) => {
15722
+ const id = profile?.id;
15723
+ if (typeof id !== "string" || id.trim().length === 0 || ids.has(id)) {
15724
+ return true;
15725
+ }
15726
+ ids.add(id);
15727
+ return false;
15728
+ })) {
15729
+ throw new TorrowSdkError({
15730
+ category: "InsufficientData" /* InsufficientData */,
15731
+ detail: { domain: "Profiles" /* Profiles */, reason: "UnusableProfileList" /* UnusableProfileList */ }
15732
+ });
15733
+ }
15734
+ return ids;
15735
+ }
15736
+ function contextualizeProfileWriteError(cause, operation, failureAt, dispatched, effect) {
15737
+ const error = cause instanceof TorrowSdkError ? cause : new TorrowSdkError({
15738
+ category: cause instanceof ProfileListResponseError || failureAt === "ProjectResponse" /* ProjectResponse */ && cause instanceof Error ? "InvalidResponse" /* InvalidResponse */ : "Unknown" /* Unknown */,
15739
+ sensitive: { cause }
15740
+ });
15741
+ const detail = cause instanceof ProfileListResponseError ? {
15742
+ domain: "Profiles" /* Profiles */,
15743
+ reason: failureAt === "ReadProfiles" /* ReadProfiles */ ? "UnusableProfileList" /* UnusableProfileList */ : "UnusableDefault" /* UnusableDefault */
15744
+ } : error.detail?.domain === "Profiles" /* Profiles */ ? error.detail : { domain: "Profiles" /* Profiles */ };
15745
+ const writeState = effect === "Applied" /* Applied */ ? effect : dispatched ? "Unknown" /* Unknown */ : "NotApplied" /* NotApplied */;
15746
+ return error.withContext({
15747
+ detail,
15748
+ operation,
15749
+ failureAt,
15750
+ request: dispatched ? "Started" /* Started */ : "NotStarted" /* NotStarted */,
15751
+ effects: [{ area: "Remote" /* Remote */, step: "Write" /* Write */, state: writeState }]
15752
+ });
15753
+ }
15754
+
15655
15755
  // ../../src/resources/user-profiles/ProfilesFacade.ts
15656
15756
  var BASE11 = "/api/v1/user/profiles";
15657
15757
  var ProfilesFacade = class {
@@ -15671,16 +15771,20 @@ var ProfilesFacade = class {
15671
15771
  signal: options?.signal
15672
15772
  });
15673
15773
  if (resp === null || typeof resp !== "object") {
15674
- throw new Error("GET /api/v1/user/profiles: expected a JSON object body");
15774
+ throw new ProfileListResponseError("GET /api/v1/user/profiles: expected a JSON object body");
15675
15775
  }
15676
15776
  const pl = resp.profileList;
15677
15777
  if (pl === void 0 || pl === null) {
15678
15778
  return projectReadList([], (dto) => projectContactItem(dto));
15679
15779
  }
15680
15780
  if (!Array.isArray(pl)) {
15681
- throw new Error("GET /api/v1/user/profiles: profileList must be an array when present");
15781
+ throw new ProfileListResponseError("GET /api/v1/user/profiles: profileList must be an array when present");
15782
+ }
15783
+ try {
15784
+ return projectReadList(pl, (dto) => projectContactItem(dto));
15785
+ } catch (cause) {
15786
+ throw new ProfileListResponseError("GET /api/v1/user/profiles: invalid profile projection", cause);
15682
15787
  }
15683
- return projectReadList(pl, (dto) => projectContactItem(dto));
15684
15788
  }
15685
15789
  /**
15686
15790
  * `POST /api/v1/user/profiles` — создать Профиль по телу **`UserProfileItemForAdd`** (контакт для write + поля Профиля).
@@ -15724,14 +15828,65 @@ var ProfilesFacade = class {
15724
15828
  });
15725
15829
  return unwrapTorrowObjectFromProfilePropertiesUpdate(resp);
15726
15830
  }
15727
- /** `DELETE /api/v1/user/profiles/{profileId}` — удалить Профиль; возвращает актуальный **`personalContactList`**. */
15831
+ /**
15832
+ * `DELETE /api/v1/user/profiles/{profileId}` — снять связь Профиля, сохранив другой Профиль и выбранный SDK default.
15833
+ * Проверяет список и default до DELETE; fallback default может повторно прочитать список, но первый снимок остаётся условием.
15834
+ * Успех возвращает `personalContactList` как `ContactItem[]`; Contact не удаляется. GET→DELETE не атомарны.
15835
+ * @param profileId Точный ID привязанного Contact; на wire кодируется как сегмент пути.
15836
+ * @param options Общий signal предварительных чтений и целевого DELETE.
15837
+ */
15728
15838
  async remove(profileId, options) {
15729
- const resp = await this.http.requestJson({
15730
- method: "DELETE",
15731
- path: `${BASE11}/${encodePathSegment(profileId)}`,
15732
- signal: options?.signal
15733
- });
15734
- return projectReadList(unwrapRemoveProfileList(resp), (dto) => projectContactItem(dto));
15839
+ let failureAt = "ValidateInput" /* ValidateInput */;
15840
+ let dispatched = false;
15841
+ let effect = "NotApplied" /* NotApplied */;
15842
+ try {
15843
+ if (typeof profileId !== "string" || profileId.trim().length === 0) {
15844
+ throw new TorrowSdkError({ category: "InvalidInput" /* InvalidInput */ });
15845
+ }
15846
+ failureAt = "ReadProfiles" /* ReadProfiles */;
15847
+ const profiles = await this.list(options);
15848
+ failureAt = "ValidateProfiles" /* ValidateProfiles */;
15849
+ const ids = assertUsableProfileIds(profiles);
15850
+ if (!ids.has(profileId)) {
15851
+ throw new TorrowSdkError({
15852
+ category: "InvalidState" /* InvalidState */,
15853
+ detail: { domain: "Profiles" /* Profiles */, reason: "TargetNotProfile" /* TargetNotProfile */ }
15854
+ });
15855
+ }
15856
+ if (profiles.length === 1) {
15857
+ throw new TorrowSdkError({
15858
+ category: "InvalidState" /* InvalidState */,
15859
+ detail: { domain: "Profiles" /* Profiles */, reason: "LastProfile" /* LastProfile */ }
15860
+ });
15861
+ }
15862
+ failureAt = "ReadDefault" /* ReadDefault */;
15863
+ const selected = await readDefaultProfile(this.http, () => this.list(options), options);
15864
+ failureAt = "ValidateDefault" /* ValidateDefault */;
15865
+ if (typeof selected?.id !== "string" || selected.id.trim().length === 0 || !ids.has(selected.id)) {
15866
+ throw new TorrowSdkError({
15867
+ category: "InsufficientData" /* InsufficientData */,
15868
+ detail: { domain: "Profiles" /* Profiles */, reason: "UnusableDefault" /* UnusableDefault */ }
15869
+ });
15870
+ }
15871
+ if (selected.id === profileId) {
15872
+ throw new TorrowSdkError({
15873
+ category: "InvalidState" /* InvalidState */,
15874
+ detail: { domain: "Profiles" /* Profiles */, reason: "SelectedDefault" /* SelectedDefault */ }
15875
+ });
15876
+ }
15877
+ failureAt = "Write" /* Write */;
15878
+ const resp = await this.http.requestJson(
15879
+ { method: "DELETE", path: `${BASE11}/${encodePathSegment(profileId)}`, signal: options?.signal },
15880
+ () => {
15881
+ dispatched = true;
15882
+ }
15883
+ );
15884
+ effect = "Applied" /* Applied */;
15885
+ failureAt = "ProjectResponse" /* ProjectResponse */;
15886
+ return projectReadList(unwrapRemoveProfileList(resp), (dto) => projectContactItem(dto));
15887
+ } catch (cause) {
15888
+ throw contextualizeProfileWriteError(cause, "remove" /* Remove */, failureAt, dispatched, effect);
15889
+ }
15735
15890
  }
15736
15891
  };
15737
15892
 
@@ -17088,25 +17243,61 @@ var UserFacade = class {
17088
17243
  * @param options Параметры чтения: signal — отмена всей цепочки запросов.
17089
17244
  */
17090
17245
  async getDefaultProfile(options) {
17091
- const dto = await this.http.requestJson({
17092
- method: "GET",
17093
- path: `${BASE20}/defaultprofile`,
17094
- signal: options?.signal
17095
- });
17096
- if (dto !== null && dto !== void 0) {
17097
- return projectContactItem(dto);
17098
- }
17099
- return (await this.profiles.list(options))[0] ?? null;
17246
+ return readDefaultProfile(this.http, () => this.profiles.list(options), options);
17100
17247
  }
17101
- /** `PUT /api/v1/user/defaultprofile` */
17248
+ /**
17249
+ * `PUT /api/v1/user/defaultprofile` — назначает только Contact, доказанно входящий в Профили учётной записи.
17250
+ * Предварительный список и целевой PUT используют один signal; между ними возможна серверная гонка.
17251
+ * При отказе `TorrowSdkError.effects` описывает только целевой PUT, а не предварительный GET.
17252
+ * @param contactId Точный ID Contact из `profiles.list`; не нормализуется.
17253
+ * @param options Параметры всей цепочки, включая общий signal отмены.
17254
+ */
17102
17255
  async setDefaultProfileByContactId(contactId, options) {
17103
- const resp = await this.http.requestJson({
17104
- method: "PUT",
17105
- path: `${BASE20}/defaultprofile`,
17106
- body: contactId,
17107
- signal: options?.signal
17108
- });
17109
- return projectContactItem(unwrapAddProfileContact(resp));
17256
+ let failureAt = "ValidateInput" /* ValidateInput */;
17257
+ let dispatched = false;
17258
+ let effect = "NotApplied" /* NotApplied */;
17259
+ try {
17260
+ if (typeof contactId !== "string" || contactId.trim().length === 0) {
17261
+ throw new TorrowSdkError({ category: "InvalidInput" /* InvalidInput */ });
17262
+ }
17263
+ failureAt = "ReadProfiles" /* ReadProfiles */;
17264
+ const profiles = await this.profiles.list(options);
17265
+ failureAt = "ValidateProfiles" /* ValidateProfiles */;
17266
+ const ids = assertUsableProfileIds(profiles);
17267
+ if (!ids.has(contactId)) {
17268
+ throw new TorrowSdkError({
17269
+ category: "InvalidState" /* InvalidState */,
17270
+ detail: { domain: "Profiles" /* Profiles */, reason: "TargetNotProfile" /* TargetNotProfile */ }
17271
+ });
17272
+ }
17273
+ failureAt = "Write" /* Write */;
17274
+ const resp = await this.http.requestJson(
17275
+ { method: "PUT", path: `${BASE20}/defaultprofile`, body: contactId, signal: options?.signal },
17276
+ () => {
17277
+ dispatched = true;
17278
+ }
17279
+ );
17280
+ effect = "Unknown" /* Unknown */;
17281
+ failureAt = "ValidateWriteResponse" /* ValidateWriteResponse */;
17282
+ const profile = resp?.profile;
17283
+ if (!profile || typeof profile !== "object" || Array.isArray(profile) || profile.id !== contactId) {
17284
+ throw new TorrowSdkError({
17285
+ category: "InvalidResponse" /* InvalidResponse */,
17286
+ sensitive: { body: resp }
17287
+ });
17288
+ }
17289
+ effect = "Applied" /* Applied */;
17290
+ failureAt = "ProjectResponse" /* ProjectResponse */;
17291
+ return projectContactItem(profile);
17292
+ } catch (cause) {
17293
+ throw contextualizeProfileWriteError(
17294
+ cause,
17295
+ "setDefaultProfileByContactId" /* SetDefaultProfileByContactId */,
17296
+ failureAt,
17297
+ dispatched,
17298
+ effect
17299
+ );
17300
+ }
17110
17301
  }
17111
17302
  /**
17112
17303
  * `POST /api/v1/user/defaultprofile` — создать и назначить дефолтный профиль.
@@ -19066,6 +19257,7 @@ export {
19066
19257
  AvailableResourcesValues,
19067
19258
  BehaviorSettingsEffectStep,
19068
19259
  BlockReasonsFacade,
19260
+ CalendarViewTypeValues,
19069
19261
  CalendarsFacade,
19070
19262
  CaseStateValues,
19071
19263
  CaseTypeValues,
@@ -19112,6 +19304,10 @@ export {
19112
19304
  ParticipationFieldTypeValues,
19113
19305
  PaymentProviderTypeValues,
19114
19306
  PinnedViewsFacade,
19307
+ ProfileEffectStep,
19308
+ ProfileErrorReason,
19309
+ ProfileFailureAt,
19310
+ ProfileOperation,
19115
19311
  ProfileTypeValues,
19116
19312
  ProfilesFacade,
19117
19313
  RawClient,