@stndrds/schema 1.0.0-alpha.77 → 1.0.0-alpha.78

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.
@@ -15,9 +15,6 @@ var _chunkNEVERCM3js = require('./chunk-NEVERCM3.js');
15
15
  var _chunk3WTK7ESHjs = require('./chunk-3WTK7ESH.js');
16
16
 
17
17
 
18
- var _chunkJZO52C3Fjs = require('./chunk-JZO52C3F.js');
19
-
20
-
21
18
  var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
22
19
 
23
20
  // src/runtime/auth/workflow-jwt.service.ts
@@ -4590,8 +4587,6 @@ function createMockPermissionsRepository(stores) {
4590
4587
  getEffectivePermissions(userProfileId) {
4591
4588
  const tenantId = getTenantId();
4592
4589
  const userRoleIds = Array.from(stores.userRoles.values()).filter((ur) => ur.userProfileId === userProfileId && ur.tenantId === tenantId).map((ur) => ur.roleId);
4593
- const userRoles = Array.from(stores.roles.values()).filter((r) => userRoleIds.includes(r.id));
4594
- const hasAdmin = userRoles.some((r) => _chunkJZO52C3Fjs.isAdminRole.call(void 0, r.name));
4595
4590
  const userPermissions = Array.from(stores.permissions.values()).filter(
4596
4591
  (p) => userRoleIds.includes(p.roleId)
4597
4592
  );
@@ -4618,7 +4613,7 @@ function createMockPermissionsRepository(stores) {
4618
4613
  }
4619
4614
  }
4620
4615
  }
4621
- return Promise.resolve({ isAdmin: hasAdmin, objectPermissions, systemPermissions });
4616
+ return Promise.resolve({ objectPermissions, systemPermissions });
4622
4617
  },
4623
4618
  countUsersWithRole(roleName) {
4624
4619
  const tenantId = getTenantId();
@@ -9867,21 +9862,37 @@ var AuditService = class extends BaseService {
9867
9862
  if (!this.adapter.audit) {
9868
9863
  return;
9869
9864
  }
9865
+ const resolved = await this.resolveActorEmail(entry);
9870
9866
  if (_optionalChain([this, 'access', _183 => _183.options, 'optionalAccess', _184 => _184.async])) {
9871
- this.buffer.push(entry);
9867
+ this.buffer.push(resolved);
9872
9868
  const batchSize = _nullishCoalesce(this.options.batchSize, () => ( 10));
9873
9869
  if (this.buffer.length >= batchSize) {
9874
9870
  await this.flush();
9875
9871
  }
9876
9872
  } else {
9877
- await this.adapter.audit.create(entry);
9873
+ await this.adapter.audit.create(resolved);
9874
+ }
9875
+ }
9876
+ /**
9877
+ * Resolve actorEmail from user profiles if not already set
9878
+ */
9879
+ async resolveActorEmail(entry) {
9880
+ if (!entry.actorEmail && entry.actorId) {
9881
+ try {
9882
+ const profile = await this.adapter.userProfiles.findById(entry.actorId);
9883
+ if (_optionalChain([profile, 'optionalAccess', _185 => _185.email])) {
9884
+ return { ...entry, actorEmail: profile.email };
9885
+ }
9886
+ } catch (e13) {
9887
+ }
9878
9888
  }
9889
+ return entry;
9879
9890
  }
9880
9891
  /**
9881
9892
  * Start the flush timer for async mode
9882
9893
  */
9883
9894
  startFlushTimer() {
9884
- const intervalMs = _nullishCoalesce(_optionalChain([this, 'access', _185 => _185.options, 'optionalAccess', _186 => _186.flushIntervalMs]), () => ( 1e3));
9895
+ const intervalMs = _nullishCoalesce(_optionalChain([this, 'access', _186 => _186.options, 'optionalAccess', _187 => _187.flushIntervalMs]), () => ( 1e3));
9885
9896
  this.flushTimer = setInterval(() => {
9886
9897
  this.flush().catch(() => {
9887
9898
  });
@@ -9911,13 +9922,13 @@ var browserStub4 = {
9911
9922
  run: (_store, callback) => callback()
9912
9923
  };
9913
9924
  var AsyncLocalStorageClass4 = null;
9914
- if (typeof process !== "undefined" && _optionalChain([process, 'access', _187 => _187.versions, 'optionalAccess', _188 => _188.node])) {
9925
+ if (typeof process !== "undefined" && _optionalChain([process, 'access', _188 => _188.versions, 'optionalAccess', _189 => _189.node])) {
9915
9926
  try {
9916
9927
  if (typeof _chunk3RG5ZIWIjs.__require !== "undefined") {
9917
9928
  const asyncHooks = _chunk3RG5ZIWIjs.__require.call(void 0, "async_hooks");
9918
9929
  AsyncLocalStorageClass4 = asyncHooks.AsyncLocalStorage;
9919
9930
  }
9920
- } catch (e13) {
9931
+ } catch (e14) {
9921
9932
  try {
9922
9933
  const dynamicRequire = new Function(
9923
9934
  "m",
@@ -9927,7 +9938,7 @@ if (typeof process !== "undefined" && _optionalChain([process, 'access', _187 =>
9927
9938
  if (asyncHooks) {
9928
9939
  AsyncLocalStorageClass4 = asyncHooks.AsyncLocalStorage;
9929
9940
  }
9930
- } catch (e14) {
9941
+ } catch (e15) {
9931
9942
  }
9932
9943
  }
9933
9944
  }
@@ -9970,7 +9981,7 @@ var BilateralSyncService = class extends BaseService {
9970
9981
  }
9971
9982
  const ctx = getSyncContext().getStore();
9972
9983
  const syncKey = `${sourceSchema.name}:${sourceRecordId}:${attributeName}`;
9973
- if (_optionalChain([ctx, 'optionalAccess', _189 => _189.syncing, 'access', _190 => _190.has, 'call', _191 => _191(syncKey)])) {
9984
+ if (_optionalChain([ctx, 'optionalAccess', _190 => _190.syncing, 'access', _191 => _191.has, 'call', _192 => _192(syncKey)])) {
9974
9985
  return;
9975
9986
  }
9976
9987
  await this.runWithSyncContext(syncKey, async () => {
@@ -10195,7 +10206,7 @@ var BilateralSyncService = class extends BaseService {
10195
10206
  const storage = getSyncContext();
10196
10207
  const existingCtx = storage.getStore();
10197
10208
  const ctx = {
10198
- syncing: new Set(_nullishCoalesce(_optionalChain([existingCtx, 'optionalAccess', _192 => _192.syncing]), () => ( [])))
10209
+ syncing: new Set(_nullishCoalesce(_optionalChain([existingCtx, 'optionalAccess', _193 => _193.syncing]), () => ( [])))
10199
10210
  };
10200
10211
  ctx.syncing.add(syncKey);
10201
10212
  return await storage.run(ctx, fn);
@@ -10303,7 +10314,7 @@ var UserService = class extends BaseService {
10303
10314
  if (roleErrors.length > 0) {
10304
10315
  errors.push({
10305
10316
  attribute: attrName,
10306
- message: `Users do not have required role for ${attr.label}. Allowed roles: ${_optionalChain([attr, 'access', _193 => _193.allowedRoles, 'optionalAccess', _194 => _194.join, 'call', _195 => _195(", ")])}`,
10317
+ message: `Users do not have required role for ${attr.label}. Allowed roles: ${_optionalChain([attr, 'access', _194 => _194.allowedRoles, 'optionalAccess', _195 => _195.join, 'call', _196 => _196(", ")])}`,
10307
10318
  invalidIds: roleErrors
10308
10319
  });
10309
10320
  }
@@ -10827,7 +10838,7 @@ var RelationPropertiesService = class extends BaseService {
10827
10838
  }
10828
10839
  }
10829
10840
  }
10830
- const shouldStoreAsInverse = _optionalChain([attribute, 'access', _196 => _196.bilateral, 'optionalAccess', _197 => _197.storageOwner]) === false;
10841
+ const shouldStoreAsInverse = _optionalChain([attribute, 'access', _197 => _197.bilateral, 'optionalAccess', _198 => _198.storageOwner]) === false;
10831
10842
  let storageFromObject = schema.name;
10832
10843
  let storageFromAttribute = attributeName;
10833
10844
  if (shouldStoreAsInverse && attribute.bilateral) {
@@ -10839,7 +10850,7 @@ var RelationPropertiesService = class extends BaseService {
10839
10850
  if (shouldStoreAsInverse) {
10840
10851
  const results = await Promise.all(
10841
10852
  normalized.map(
10842
- (item) => _optionalChain([adapter, 'access', _198 => _198.relationAttributes, 'optionalAccess', _199 => _199.findBySource, 'call', _200 => _200(
10853
+ (item) => _optionalChain([adapter, 'access', _199 => _199.relationAttributes, 'optionalAccess', _200 => _200.findBySource, 'call', _201 => _201(
10843
10854
  storageFromObject,
10844
10855
  item.id,
10845
10856
  storageFromAttribute
@@ -10978,7 +10989,7 @@ var RecordQueryService = class extends BaseService {
10978
10989
  super(adapter);
10979
10990
  this.schemaService = schemaService;
10980
10991
  this.options = options;
10981
- this.policyRegistry = _optionalChain([options, 'optionalAccess', _201 => _201.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _202 => _202.policyRegistry]), () => ( defaultPolicyRegistry));
10992
+ this.policyRegistry = _optionalChain([options, 'optionalAccess', _202 => _202.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _203 => _203.policyRegistry]), () => ( defaultPolicyRegistry));
10982
10993
  this.relationPropertiesService = new RelationPropertiesService(adapter);
10983
10994
  }
10984
10995
  // ============================================================================
@@ -11029,12 +11040,12 @@ var RecordQueryService = class extends BaseService {
11029
11040
  * Internal list query execution
11030
11041
  */
11031
11042
  async executeListQuery(schema, objectId, options) {
11032
- if (_optionalChain([this, 'access', _203 => _203.options, 'optionalAccess', _204 => _204.permissionService]) && this.userId) {
11043
+ if (_optionalChain([this, 'access', _204 => _204.options, 'optionalAccess', _205 => _205.permissionService]) && this.userId) {
11033
11044
  await checkPermission(this.options.permissionService, this.userId, schema.name, "read");
11034
11045
  }
11035
- const policy = _optionalChain([options, 'optionalAccess', _205 => _205.skipPolicyFilter]) ? void 0 : getPolicy(this.policyRegistry, this.userId, schema.name);
11046
+ const policy = _optionalChain([options, 'optionalAccess', _206 => _206.skipPolicyFilter]) ? void 0 : getPolicy(this.policyRegistry, this.userId, schema.name);
11036
11047
  let effectiveOptions = options;
11037
- if (_optionalChain([policy, 'optionalAccess', _206 => _206.applyListFilter]) && this.userId) {
11048
+ if (_optionalChain([policy, 'optionalAccess', _207 => _207.applyListFilter]) && this.userId) {
11038
11049
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
11039
11050
  effectiveOptions = policy.applyListFilter(ctx, options);
11040
11051
  }
@@ -11044,10 +11055,10 @@ var RecordQueryService = class extends BaseService {
11044
11055
  );
11045
11056
  let filteredRecords = result.records;
11046
11057
  let effectiveTotal = result.total;
11047
- if (_optionalChain([policy, 'optionalAccess', _207 => _207.canAccessRecord]) && this.userId) {
11058
+ if (_optionalChain([policy, 'optionalAccess', _208 => _208.canAccessRecord]) && this.userId) {
11048
11059
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
11049
- const requestedLimit = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _208 => _208.limit]), () => ( 20));
11050
- const requestedOffset = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _209 => _209.offset]), () => ( 0));
11060
+ const requestedLimit = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _209 => _209.limit]), () => ( 20));
11061
+ const requestedOffset = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _210 => _210.offset]), () => ( 0));
11051
11062
  const overfetchMultiplier = 5;
11052
11063
  const batchSize = requestedLimit * overfetchMultiplier;
11053
11064
  const maxScanRecords = 1e4;
@@ -11069,7 +11080,7 @@ var RecordQueryService = class extends BaseService {
11069
11080
  exhausted = true;
11070
11081
  break;
11071
11082
  }
11072
- const filtered = batch.records.filter((record) => _optionalChain([policy, 'access', _210 => _210.canAccessRecord, 'optionalCall', _211 => _211(ctx, record)]));
11083
+ const filtered = batch.records.filter((record) => _optionalChain([policy, 'access', _211 => _211.canAccessRecord, 'optionalCall', _212 => _212(ctx, record)]));
11073
11084
  collected.push(...filtered);
11074
11085
  dbOffset += batch.records.length;
11075
11086
  totalScanned += batch.records.length;
@@ -11085,7 +11096,7 @@ var RecordQueryService = class extends BaseService {
11085
11096
  filteredRecords,
11086
11097
  schema
11087
11098
  );
11088
- if (!_optionalChain([options, 'optionalAccess', _212 => _212.skipFormulas])) {
11099
+ if (!_optionalChain([options, 'optionalAccess', _213 => _213.skipFormulas])) {
11089
11100
  return {
11090
11101
  records: enrichRecordsWithFormulas(filteredRecords, schema),
11091
11102
  total: effectiveTotal
@@ -11145,21 +11156,21 @@ var RecordQueryService = class extends BaseService {
11145
11156
  * Internal search query execution
11146
11157
  */
11147
11158
  async executeSearchQuery(schema, objectId, query, options) {
11148
- if (_optionalChain([this, 'access', _213 => _213.options, 'optionalAccess', _214 => _214.permissionService]) && this.userId) {
11159
+ if (_optionalChain([this, 'access', _214 => _214.options, 'optionalAccess', _215 => _215.permissionService]) && this.userId) {
11149
11160
  await checkPermission(this.options.permissionService, this.userId, schema.name, "read");
11150
11161
  }
11151
11162
  let result;
11152
11163
  if (this.adapter.search) {
11153
11164
  try {
11154
11165
  result = await this.adapter.search.searchRecords(objectId, query, {
11155
- limit: _optionalChain([options, 'optionalAccess', _215 => _215.limit]),
11156
- offset: _optionalChain([options, 'optionalAccess', _216 => _216.offset]),
11157
- sorts: _optionalChain([options, 'optionalAccess', _217 => _217.sorts]),
11158
- filters: _optionalChain([options, 'optionalAccess', _218 => _218.filters]),
11166
+ limit: _optionalChain([options, 'optionalAccess', _216 => _216.limit]),
11167
+ offset: _optionalChain([options, 'optionalAccess', _217 => _217.offset]),
11168
+ sorts: _optionalChain([options, 'optionalAccess', _218 => _218.sorts]),
11169
+ filters: _optionalChain([options, 'optionalAccess', _219 => _219.filters]),
11159
11170
  attributes: schema.attributes
11160
11171
  });
11161
11172
  result = await this.healSearchResults(result);
11162
- } catch (e15) {
11173
+ } catch (e16) {
11163
11174
  result = await runWithSchemaContext(
11164
11175
  [schema],
11165
11176
  () => this.adapter.objectRecords.search(objectId, query, options)
@@ -11175,7 +11186,7 @@ var RecordQueryService = class extends BaseService {
11175
11186
  result.records,
11176
11187
  schema
11177
11188
  );
11178
- if (!_optionalChain([options, 'optionalAccess', _219 => _219.skipFormulas])) {
11189
+ if (!_optionalChain([options, 'optionalAccess', _220 => _220.skipFormulas])) {
11179
11190
  return {
11180
11191
  records: enrichRecordsWithFormulas(enrichedRecords, schema),
11181
11192
  total: result.total
@@ -11384,7 +11395,7 @@ var RelationService = class extends BaseService {
11384
11395
  }
11385
11396
  const isUniversal = attr.targets.length === 1 && attr.targets[0].object === RELATION_TARGET_ANY;
11386
11397
  const validObjectIds = isUniversal ? null : await this.getValidObjectIds(attr.targets);
11387
- if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _220 => _220.size]) === 0) {
11398
+ if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _221 => _221.size]) === 0) {
11388
11399
  errors.push({
11389
11400
  attribute: attr.name,
11390
11401
  message: `No valid target objects found for ${attr.label}`
@@ -11437,10 +11448,10 @@ var RelationService = class extends BaseService {
11437
11448
  for (const target of targets) {
11438
11449
  try {
11439
11450
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11440
- if (_optionalChain([objectSchema, 'optionalAccess', _221 => _221.id])) {
11451
+ if (_optionalChain([objectSchema, 'optionalAccess', _222 => _222.id])) {
11441
11452
  objectIds.add(objectSchema.id);
11442
11453
  }
11443
- } catch (e16) {
11454
+ } catch (e17) {
11444
11455
  }
11445
11456
  }
11446
11457
  return objectIds;
@@ -11506,7 +11517,7 @@ var RelationService = class extends BaseService {
11506
11517
  const targetResults = await Promise.all(
11507
11518
  filteredTargets.map(async (target) => {
11508
11519
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11509
- if (!_optionalChain([objectSchema, 'optionalAccess', _222 => _222.id])) return { options: [], total: 0 };
11520
+ if (!_optionalChain([objectSchema, 'optionalAccess', _223 => _223.id])) return { options: [], total: 0 };
11510
11521
  const objectId = objectSchema.id;
11511
11522
  const result = query ? await queryService.searchRecords(objectId, query, queryOptions) : await queryService.listRecords(objectId, queryOptions);
11512
11523
  const options = await Promise.all(
@@ -11663,8 +11674,8 @@ var RelationService = class extends BaseService {
11663
11674
  continue;
11664
11675
  }
11665
11676
  const attribute = attributeMap.get(attributeId);
11666
- const targetConfig = _optionalChain([attribute, 'optionalAccess', _223 => _223.targets, 'optionalAccess', _224 => _224.find, 'call', _225 => _225((t) => t.object === objectSchema.name)]);
11667
- const customTemplate = _optionalChain([targetConfig, 'optionalAccess', _226 => _226.displayTemplate]);
11677
+ const targetConfig = _optionalChain([attribute, 'optionalAccess', _224 => _224.targets, 'optionalAccess', _225 => _225.find, 'call', _226 => _226((t) => t.object === objectSchema.name)]);
11678
+ const customTemplate = _optionalChain([targetConfig, 'optionalAccess', _227 => _227.displayTemplate]);
11668
11679
  const label = await this.resolveLabel(record, objectSchema, customTemplate);
11669
11680
  resolved.push({
11670
11681
  _compositeId: compositeId,
@@ -11827,14 +11838,14 @@ var RollupService = class extends BaseService {
11827
11838
  const sourceSchema = getSchemaByNameFromContext(sourceObjectName);
11828
11839
  let sourceObjectId;
11829
11840
  let reverseRelationAttrName;
11830
- if (_optionalChain([sourceSchema, 'optionalAccess', _227 => _227.id])) {
11841
+ if (_optionalChain([sourceSchema, 'optionalAccess', _228 => _228.id])) {
11831
11842
  sourceObjectId = sourceSchema.id;
11832
11843
  const reverseRelationAttr = sourceSchema.attributes.find((attr) => {
11833
11844
  if (attr.type !== "relation") return false;
11834
11845
  const relationConfig = attr;
11835
- return _optionalChain([relationConfig, 'optionalAccess', _228 => _228.targets, 'optionalAccess', _229 => _229.some, 'call', _230 => _230((t) => t.object === schema.name)]);
11846
+ return _optionalChain([relationConfig, 'optionalAccess', _229 => _229.targets, 'optionalAccess', _230 => _230.some, 'call', _231 => _231((t) => t.object === schema.name)]);
11836
11847
  });
11837
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _231 => _231.name]);
11848
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _232 => _232.name]);
11838
11849
  } else {
11839
11850
  const sourceObject = await this.adapter.objects.findByName(sourceObjectName);
11840
11851
  if (!sourceObject) {
@@ -11845,9 +11856,9 @@ var RollupService = class extends BaseService {
11845
11856
  const reverseRelationAttr = sourceAttributes.find((attr) => {
11846
11857
  if (attr.type !== "relation") return false;
11847
11858
  const relationConfig = attr.config;
11848
- return _optionalChain([relationConfig, 'optionalAccess', _232 => _232.targets, 'optionalAccess', _233 => _233.some, 'call', _234 => _234((t) => t.object === schema.name)]);
11859
+ return _optionalChain([relationConfig, 'optionalAccess', _233 => _233.targets, 'optionalAccess', _234 => _234.some, 'call', _235 => _235((t) => t.object === schema.name)]);
11849
11860
  });
11850
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _235 => _235.name]);
11861
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _236 => _236.name]);
11851
11862
  }
11852
11863
  if (!reverseRelationAttrName) {
11853
11864
  return { value: null, recordCount: 0 };
@@ -12103,13 +12114,13 @@ var RollupService = class extends BaseService {
12103
12114
  if (!obj) continue;
12104
12115
  for (const rollupDbAttr of rollupAttrs) {
12105
12116
  const rollupConfig = rollupDbAttr.config;
12106
- if (!_optionalChain([rollupConfig, 'optionalAccess', _236 => _236.relationAttribute])) continue;
12117
+ if (!_optionalChain([rollupConfig, 'optionalAccess', _237 => _237.relationAttribute])) continue;
12107
12118
  const relationAttr = attributes.find(
12108
12119
  (a) => a.type === "relation" && a.name === rollupConfig.relationAttribute
12109
12120
  );
12110
12121
  if (!relationAttr) continue;
12111
12122
  const relationConfig = relationAttr.config;
12112
- const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _237 => _237.targets, 'optionalAccess', _238 => _238.some, 'call', _239 => _239(
12123
+ const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _238 => _238.targets, 'optionalAccess', _239 => _239.some, 'call', _240 => _240(
12113
12124
  (t) => t.object === changedSchema.name
12114
12125
  )]);
12115
12126
  if (!targetsChangedObject) continue;
@@ -12134,11 +12145,11 @@ var RecordService = class extends BaseService {
12134
12145
  constructor(adapter, options) {
12135
12146
  super(adapter);
12136
12147
  this.schemaService = new ObjectSchemaService(adapter, registry, {
12137
- auditService: _optionalChain([options, 'optionalAccess', _240 => _240.auditService])
12148
+ auditService: _optionalChain([options, 'optionalAccess', _241 => _241.auditService])
12138
12149
  });
12139
- this.permissionService = _optionalChain([options, 'optionalAccess', _241 => _241.permissionService]);
12140
- this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _242 => _242.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
12141
- this.policyRegistry = _optionalChain([options, 'optionalAccess', _243 => _243.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _244 => _244.policyRegistry]), () => ( defaultPolicyRegistry));
12150
+ this.permissionService = _optionalChain([options, 'optionalAccess', _242 => _242.permissionService]);
12151
+ this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _243 => _243.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
12152
+ this.policyRegistry = _optionalChain([options, 'optionalAccess', _244 => _244.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _245 => _245.policyRegistry]), () => ( defaultPolicyRegistry));
12142
12153
  this.recordResolver = new RecordResolverService(adapter);
12143
12154
  this.queryService = new RecordQueryService(adapter, this.schemaService, {
12144
12155
  permissionService: this.permissionService,
@@ -12153,7 +12164,7 @@ var RecordService = class extends BaseService {
12153
12164
  recordResolver: this.recordResolver
12154
12165
  });
12155
12166
  this.userService = new UserService(adapter);
12156
- this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _245 => _245.hookRegistry]), () => ( new NoopHookRegistry()));
12167
+ this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _246 => _246.hookRegistry]), () => ( new NoopHookRegistry()));
12157
12168
  this.bilateralSyncService = new BilateralSyncService(
12158
12169
  adapter,
12159
12170
  this.schemaService,
@@ -12193,25 +12204,25 @@ var RecordService = class extends BaseService {
12193
12204
  schema,
12194
12205
  this.tenantId,
12195
12206
  dataWithDefaults,
12196
- _optionalChain([options, 'optionalAccess', _246 => _246.hookMetadata])
12207
+ _optionalChain([options, 'optionalAccess', _247 => _247.hookMetadata])
12197
12208
  );
12198
- if (!_optionalChain([options, 'optionalAccess', _247 => _247.skipHooks])) {
12209
+ if (!_optionalChain([options, 'optionalAccess', _248 => _248.skipHooks])) {
12199
12210
  await this.hookRegistry.execute("beforeCreate", schema.name, hookCtx);
12200
12211
  }
12201
12212
  const normalizedData = this.relationPropertiesService.normalizeRelationValuesForStorage(
12202
12213
  schema,
12203
12214
  dataWithDefaults
12204
12215
  );
12205
- if (_optionalChain([options, 'optionalAccess', _248 => _248.validate]) !== false) {
12206
- if (_optionalChain([options, 'optionalAccess', _249 => _249.allowDraft])) {
12216
+ if (_optionalChain([options, 'optionalAccess', _249 => _249.validate]) !== false) {
12217
+ if (_optionalChain([options, 'optionalAccess', _250 => _250.allowDraft])) {
12207
12218
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedData);
12208
12219
  } else {
12209
12220
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedData);
12210
12221
  }
12211
- if (!_optionalChain([options, 'optionalAccess', _250 => _250.skipRelationValidation])) {
12222
+ if (!_optionalChain([options, 'optionalAccess', _251 => _251.skipRelationValidation])) {
12212
12223
  await this.relationService.validateRelationsOrThrow(schema, normalizedData);
12213
12224
  }
12214
- if (!_optionalChain([options, 'optionalAccess', _251 => _251.skipUserValidation])) {
12225
+ if (!_optionalChain([options, 'optionalAccess', _252 => _252.skipUserValidation])) {
12215
12226
  await this.userService.validateUsersOrThrow(schema, normalizedData);
12216
12227
  }
12217
12228
  }
@@ -12222,12 +12233,12 @@ var RecordService = class extends BaseService {
12222
12233
  data: normalizedData,
12223
12234
  label,
12224
12235
  completionStatus,
12225
- metadata: _optionalChain([options, 'optionalAccess', _252 => _252.metadata]),
12236
+ metadata: _optionalChain([options, 'optionalAccess', _253 => _253.metadata]),
12226
12237
  createdBy: this.userId
12227
12238
  });
12228
12239
  for (const [attrName, value] of Object.entries(dataWithDefaults)) {
12229
12240
  const attr = schema.attributes.find((a) => a.name === attrName);
12230
- if (_optionalChain([attr, 'optionalAccess', _253 => _253.type]) === "relation") {
12241
+ if (_optionalChain([attr, 'optionalAccess', _254 => _254.type]) === "relation") {
12231
12242
  const hasProperties2 = attr.properties !== void 0;
12232
12243
  const isBilateral = isBilateralRelation(attr);
12233
12244
  if (hasProperties2 || isBilateral) {
@@ -12243,7 +12254,7 @@ var RecordService = class extends BaseService {
12243
12254
  }
12244
12255
  for (const [attrName, value] of Object.entries(normalizedData)) {
12245
12256
  const attr = schema.attributes.find((a) => a.name === attrName);
12246
- if (_optionalChain([attr, 'optionalAccess', _254 => _254.type]) === "relation" && isBilateralRelation(attr)) {
12257
+ if (_optionalChain([attr, 'optionalAccess', _255 => _255.type]) === "relation" && isBilateralRelation(attr)) {
12247
12258
  await this.bilateralSyncService.syncBilateralRelation(
12248
12259
  schema,
12249
12260
  record.id,
@@ -12254,7 +12265,7 @@ var RecordService = class extends BaseService {
12254
12265
  );
12255
12266
  }
12256
12267
  }
12257
- if (!_optionalChain([options, 'optionalAccess', _255 => _255.skipHooks])) {
12268
+ if (!_optionalChain([options, 'optionalAccess', _256 => _256.skipHooks])) {
12258
12269
  const afterCtx = {
12259
12270
  ...hookCtx,
12260
12271
  recordId: record.id,
@@ -12264,11 +12275,11 @@ var RecordService = class extends BaseService {
12264
12275
  }
12265
12276
  await recalculateParentRollups(record, schema, this.rollupContext);
12266
12277
  await this.invalidateRecordCaches(record.id, objectId);
12267
- _optionalChain([this, 'access', _256 => _256.adapter, 'access', _257 => _257.search, 'optionalAccess', _258 => _258.indexRecord, 'call', _259 => _259(record, {
12278
+ _optionalChain([this, 'access', _257 => _257.adapter, 'access', _258 => _258.search, 'optionalAccess', _259 => _259.indexRecord, 'call', _260 => _260(record, {
12268
12279
  objectName: schema.name,
12269
12280
  objectLabel: schema.label,
12270
12281
  attributes: schema.attributes
12271
- }), 'access', _260 => _260.catch, 'call', _261 => _261((err) => console.error("[search] Failed to index created record", record.id, err))]);
12282
+ }), 'access', _261 => _261.catch, 'call', _262 => _262((err) => console.error("[search] Failed to index created record", record.id, err))]);
12272
12283
  if (this.auditService && this.userId) {
12273
12284
  this.auditService.logRecordAction({
12274
12285
  action: "record.created",
@@ -12277,7 +12288,7 @@ var RecordService = class extends BaseService {
12277
12288
  objectId: schema.id,
12278
12289
  recordId: record.id,
12279
12290
  recordLabel: record.label,
12280
- metadata: _optionalChain([options, 'optionalAccess', _262 => _262.hookMetadata])
12291
+ metadata: _optionalChain([options, 'optionalAccess', _263 => _263.hookMetadata])
12281
12292
  }).catch(() => {
12282
12293
  });
12283
12294
  }
@@ -12300,7 +12311,7 @@ var RecordService = class extends BaseService {
12300
12311
  return null;
12301
12312
  }
12302
12313
  const schema = await this.schemaService.getObjectSchema(record.objectId);
12303
- if (!_optionalChain([options, 'optionalAccess', _263 => _263.skipPolicyCheck])) {
12314
+ if (!_optionalChain([options, 'optionalAccess', _264 => _264.skipPolicyCheck])) {
12304
12315
  const policy = getPolicy(this.policyRegistry, this.userId, schema.name);
12305
12316
  if (policy) {
12306
12317
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
@@ -12310,11 +12321,11 @@ var RecordService = class extends BaseService {
12310
12321
  }
12311
12322
  }
12312
12323
  let enrichedRecord = record;
12313
- if (!_optionalChain([options, 'optionalAccess', _264 => _264.skipFormulas])) {
12324
+ if (!_optionalChain([options, 'optionalAccess', _265 => _265.skipFormulas])) {
12314
12325
  enrichedRecord = enrichWithFormulas(record, schema);
12315
12326
  }
12316
12327
  enrichedRecord = await this.enrichRelationProperties(enrichedRecord, schema);
12317
- if (_optionalChain([options, 'optionalAccess', _265 => _265.includeSchema])) {
12328
+ if (_optionalChain([options, 'optionalAccess', _266 => _266.includeSchema])) {
12318
12329
  const recordWithSchema = enrichedRecord;
12319
12330
  recordWithSchema.schema = schema;
12320
12331
  return recordWithSchema;
@@ -12364,7 +12375,7 @@ var RecordService = class extends BaseService {
12364
12375
  if (oldVal !== null && newVal !== null && typeof oldVal === "object" && typeof newVal === "object") {
12365
12376
  try {
12366
12377
  return JSON.stringify(oldVal) !== JSON.stringify(newVal);
12367
- } catch (e17) {
12378
+ } catch (e18) {
12368
12379
  return true;
12369
12380
  }
12370
12381
  }
@@ -12376,9 +12387,9 @@ var RecordService = class extends BaseService {
12376
12387
  existing,
12377
12388
  mergedData,
12378
12389
  changedAttributes,
12379
- _optionalChain([options, 'optionalAccess', _266 => _266.hookMetadata])
12390
+ _optionalChain([options, 'optionalAccess', _267 => _267.hookMetadata])
12380
12391
  );
12381
- if (!_optionalChain([options, 'optionalAccess', _267 => _267.skipHooks])) {
12392
+ if (!_optionalChain([options, 'optionalAccess', _268 => _268.skipHooks])) {
12382
12393
  await this.hookRegistry.execute("beforeUpdate", schema.name, hookCtx);
12383
12394
  }
12384
12395
  const hookModifiedValues = {};
@@ -12393,16 +12404,16 @@ var RecordService = class extends BaseService {
12393
12404
  dataToUpdate
12394
12405
  );
12395
12406
  const normalizedMergedData = { ...existing.values, ...normalizedUpdate };
12396
- if (_optionalChain([options, 'optionalAccess', _268 => _268.validate]) !== false) {
12397
- if (_optionalChain([options, 'optionalAccess', _269 => _269.partial])) {
12407
+ if (_optionalChain([options, 'optionalAccess', _269 => _269.validate]) !== false) {
12408
+ if (_optionalChain([options, 'optionalAccess', _270 => _270.partial])) {
12398
12409
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedMergedData);
12399
12410
  } else {
12400
12411
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedMergedData);
12401
12412
  }
12402
- if (!_optionalChain([options, 'optionalAccess', _270 => _270.skipRelationValidation])) {
12413
+ if (!_optionalChain([options, 'optionalAccess', _271 => _271.skipRelationValidation])) {
12403
12414
  await this.relationService.validateRelationsOrThrow(schema, normalizedUpdate);
12404
12415
  }
12405
- if (!_optionalChain([options, 'optionalAccess', _271 => _271.skipUserValidation])) {
12416
+ if (!_optionalChain([options, 'optionalAccess', _272 => _272.skipUserValidation])) {
12406
12417
  await this.userService.validateUsersOrThrow(schema, normalizedUpdate);
12407
12418
  }
12408
12419
  }
@@ -12415,7 +12426,7 @@ var RecordService = class extends BaseService {
12415
12426
  __lastUpdatedBy: this.userId,
12416
12427
  __expectedUpdatedAt: existing.updatedAt instanceof Date ? existing.updatedAt.toISOString() : existing.updatedAt
12417
12428
  };
12418
- if (_optionalChain([options, 'optionalAccess', _272 => _272.metadata]) !== void 0) {
12429
+ if (_optionalChain([options, 'optionalAccess', _273 => _273.metadata]) !== void 0) {
12419
12430
  const existingMetadata = _nullishCoalesce(existing.metadata, () => ( {}));
12420
12431
  const mergedMetadata = { ...existingMetadata, ...options.metadata };
12421
12432
  const cleanedMetadata = Object.fromEntries(
@@ -12426,20 +12437,20 @@ var RecordService = class extends BaseService {
12426
12437
  const bilateralOldValues = {};
12427
12438
  for (const attrName of Object.keys(normalizedUpdate)) {
12428
12439
  const attr = schema.attributes.find((a) => a.name === attrName);
12429
- if (_optionalChain([attr, 'optionalAccess', _273 => _273.type]) === "relation" && isBilateralRelation(attr)) {
12440
+ if (_optionalChain([attr, 'optionalAccess', _274 => _274.type]) === "relation" && isBilateralRelation(attr)) {
12430
12441
  bilateralOldValues[attrName] = existing.values[attrName];
12431
12442
  }
12432
12443
  }
12433
12444
  const updated = await this.adapter.objectRecords.update(recordId, updatePayload);
12434
12445
  await this.invalidateRecordCaches(recordId, existing.objectId);
12435
- _optionalChain([this, 'access', _274 => _274.adapter, 'access', _275 => _275.search, 'optionalAccess', _276 => _276.indexRecord, 'call', _277 => _277(updated, {
12446
+ _optionalChain([this, 'access', _275 => _275.adapter, 'access', _276 => _276.search, 'optionalAccess', _277 => _277.indexRecord, 'call', _278 => _278(updated, {
12436
12447
  objectName: schema.name,
12437
12448
  objectLabel: schema.label,
12438
12449
  attributes: schema.attributes
12439
- }), 'access', _278 => _278.catch, 'call', _279 => _279((err) => console.error("[search] Failed to index updated record", updated.id, err))]);
12450
+ }), 'access', _279 => _279.catch, 'call', _280 => _280((err) => console.error("[search] Failed to index updated record", updated.id, err))]);
12440
12451
  for (const [attrName, value] of Object.entries(dataToUpdate)) {
12441
12452
  const attr = schema.attributes.find((a) => a.name === attrName);
12442
- if (_optionalChain([attr, 'optionalAccess', _280 => _280.type]) === "relation") {
12453
+ if (_optionalChain([attr, 'optionalAccess', _281 => _281.type]) === "relation") {
12443
12454
  const hasProperties2 = attr.properties !== void 0;
12444
12455
  const isBilateral = isBilateralRelation(attr);
12445
12456
  if (hasProperties2 || isBilateral) {
@@ -12455,7 +12466,7 @@ var RecordService = class extends BaseService {
12455
12466
  }
12456
12467
  for (const [attrName, value] of Object.entries(normalizedUpdate)) {
12457
12468
  const attr = schema.attributes.find((a) => a.name === attrName);
12458
- if (_optionalChain([attr, 'optionalAccess', _281 => _281.type]) === "relation" && isBilateralRelation(attr)) {
12469
+ if (_optionalChain([attr, 'optionalAccess', _282 => _282.type]) === "relation" && isBilateralRelation(attr)) {
12459
12470
  const oldValue = bilateralOldValues[attrName];
12460
12471
  await this.bilateralSyncService.syncBilateralRelation(
12461
12472
  schema,
@@ -12466,7 +12477,7 @@ var RecordService = class extends BaseService {
12466
12477
  );
12467
12478
  }
12468
12479
  }
12469
- if (!_optionalChain([options, 'optionalAccess', _282 => _282.skipHooks])) {
12480
+ if (!_optionalChain([options, 'optionalAccess', _283 => _283.skipHooks])) {
12470
12481
  const afterCtx = {
12471
12482
  ...hookCtx,
12472
12483
  record: updated
@@ -12481,7 +12492,7 @@ var RecordService = class extends BaseService {
12481
12492
  if (this.auditService && this.userId && allChangedAttributes.length > 0) {
12482
12493
  const changes = allChangedAttributes.map((attr) => ({
12483
12494
  field: attr,
12484
- oldValue: _optionalChain([hookCtx, 'access', _283 => _283.oldValues, 'optionalAccess', _284 => _284[attr]]),
12495
+ oldValue: _optionalChain([hookCtx, 'access', _284 => _284.oldValues, 'optionalAccess', _285 => _285[attr]]),
12485
12496
  newValue: hookCtx.newValues[attr]
12486
12497
  }));
12487
12498
  this.auditService.logRecordAction({
@@ -12492,7 +12503,7 @@ var RecordService = class extends BaseService {
12492
12503
  recordId: updated.id,
12493
12504
  recordLabel: updated.label,
12494
12505
  changes,
12495
- metadata: _optionalChain([options, 'optionalAccess', _285 => _285.hookMetadata])
12506
+ metadata: _optionalChain([options, 'optionalAccess', _286 => _286.hookMetadata])
12496
12507
  }).catch(() => {
12497
12508
  });
12498
12509
  }
@@ -12524,17 +12535,17 @@ var RecordService = class extends BaseService {
12524
12535
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
12525
12536
  checkRecordDeleteOrThrow(policy, record, ctx);
12526
12537
  }
12527
- if (_optionalChain([options, 'optionalAccess', _286 => _286.checkSystem]) && schema.system) {
12538
+ if (_optionalChain([options, 'optionalAccess', _287 => _287.checkSystem]) && schema.system) {
12528
12539
  throw new ProtectedResourceError("object", schema.name, "delete");
12529
12540
  }
12530
- if (!_optionalChain([options, 'optionalAccess', _287 => _287.skipReferenceCheck])) {
12541
+ if (!_optionalChain([options, 'optionalAccess', _288 => _288.skipReferenceCheck])) {
12531
12542
  const references = await this.adapter.objectRecords.countRecordsReferencingId(recordId);
12532
12543
  if (references.length > 0) {
12533
12544
  throw new RecordReferencedError(recordId, references);
12534
12545
  }
12535
12546
  }
12536
- const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _288 => _288.hookMetadata]));
12537
- if (!_optionalChain([options, 'optionalAccess', _289 => _289.skipHooks])) {
12547
+ const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _289 => _289.hookMetadata]));
12548
+ if (!_optionalChain([options, 'optionalAccess', _290 => _290.skipHooks])) {
12538
12549
  await this.hookRegistry.execute("beforeDelete", schema.name, hookCtx);
12539
12550
  }
12540
12551
  for (const attr of schema.attributes) {
@@ -12552,8 +12563,8 @@ var RecordService = class extends BaseService {
12552
12563
  }
12553
12564
  await this.adapter.objectRecords.delete(recordId);
12554
12565
  await this.invalidateRecordCaches(recordId, record.objectId);
12555
- _optionalChain([this, 'access', _290 => _290.adapter, 'access', _291 => _291.search, 'optionalAccess', _292 => _292.removeRecord, 'call', _293 => _293(recordId), 'access', _294 => _294.catch, 'call', _295 => _295((err) => console.error("[search] Failed to remove deleted record", recordId, err))]);
12556
- if (!_optionalChain([options, 'optionalAccess', _296 => _296.skipHooks])) {
12566
+ _optionalChain([this, 'access', _291 => _291.adapter, 'access', _292 => _292.search, 'optionalAccess', _293 => _293.removeRecord, 'call', _294 => _294(recordId), 'access', _295 => _295.catch, 'call', _296 => _296((err) => console.error("[search] Failed to remove deleted record", recordId, err))]);
12567
+ if (!_optionalChain([options, 'optionalAccess', _297 => _297.skipHooks])) {
12557
12568
  await this.hookRegistry.execute("afterDelete", schema.name, hookCtx);
12558
12569
  }
12559
12570
  await recalculateParentRollups(record, schema, this.rollupContext);
@@ -12565,7 +12576,7 @@ var RecordService = class extends BaseService {
12565
12576
  objectId: schema.id,
12566
12577
  recordId: record.id,
12567
12578
  recordLabel: record.label,
12568
- metadata: _optionalChain([options, 'optionalAccess', _297 => _297.hookMetadata])
12579
+ metadata: _optionalChain([options, 'optionalAccess', _298 => _298.hookMetadata])
12569
12580
  }).catch(() => {
12570
12581
  });
12571
12582
  }
@@ -12626,18 +12637,18 @@ var RecordService = class extends BaseService {
12626
12637
  this.tenantId
12627
12638
  );
12628
12639
  await checkPermission(this.permissionService, this.userId, schema.name, "update");
12629
- const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _298 => _298.hookMetadata]));
12630
- if (!_optionalChain([options, 'optionalAccess', _299 => _299.skipHooks])) {
12640
+ const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _299 => _299.hookMetadata]));
12641
+ if (!_optionalChain([options, 'optionalAccess', _300 => _300.skipHooks])) {
12631
12642
  await this.hookRegistry.execute("beforeRestore", schema.name, hookCtx);
12632
12643
  }
12633
12644
  const restored = await this.adapter.objectRecords.restore(recordId);
12634
12645
  await this.invalidateRecordCaches(recordId, record.objectId);
12635
- _optionalChain([this, 'access', _300 => _300.adapter, 'access', _301 => _301.search, 'optionalAccess', _302 => _302.indexRecord, 'call', _303 => _303(restored, {
12646
+ _optionalChain([this, 'access', _301 => _301.adapter, 'access', _302 => _302.search, 'optionalAccess', _303 => _303.indexRecord, 'call', _304 => _304(restored, {
12636
12647
  objectName: schema.name,
12637
12648
  objectLabel: schema.label,
12638
12649
  attributes: schema.attributes
12639
- }), 'access', _304 => _304.catch, 'call', _305 => _305((err) => console.error("[search] Failed to index restored record", restored.id, err))]);
12640
- if (!_optionalChain([options, 'optionalAccess', _306 => _306.skipHooks])) {
12650
+ }), 'access', _305 => _305.catch, 'call', _306 => _306((err) => console.error("[search] Failed to index restored record", restored.id, err))]);
12651
+ if (!_optionalChain([options, 'optionalAccess', _307 => _307.skipHooks])) {
12641
12652
  const afterCtx = {
12642
12653
  ...hookCtx,
12643
12654
  record: restored
@@ -12652,7 +12663,7 @@ var RecordService = class extends BaseService {
12652
12663
  objectId: schema.id,
12653
12664
  recordId: restored.id,
12654
12665
  recordLabel: restored.label,
12655
- metadata: _optionalChain([options, 'optionalAccess', _307 => _307.hookMetadata])
12666
+ metadata: _optionalChain([options, 'optionalAccess', _308 => _308.hookMetadata])
12656
12667
  }).catch(() => {
12657
12668
  });
12658
12669
  }
@@ -13083,7 +13094,7 @@ var DocumentRendererService = class {
13083
13094
  throw new StorageDownloadNotSupportedError();
13084
13095
  }
13085
13096
  let storagePath = fileId;
13086
- if (_optionalChain([this, 'access', _308 => _308.options, 'optionalAccess', _309 => _309.filesRepository])) {
13097
+ if (_optionalChain([this, 'access', _309 => _309.options, 'optionalAccess', _310 => _310.filesRepository])) {
13087
13098
  const file2 = await this.options.filesRepository.findById(fileId);
13088
13099
  if (!file2) {
13089
13100
  throw new Error(`Template file not found: ${fileId}`);
@@ -13101,8 +13112,8 @@ var DocumentRendererService = class {
13101
13112
  for (const field of fields) {
13102
13113
  const rawValue = getContextValue(context, field.contextPath);
13103
13114
  const attrInfo = await this.getAttributeInfo(field.contextPath, workflow2);
13104
- if (_optionalChain([attrInfo, 'optionalAccess', _310 => _310.attribute])) {
13105
- if (attrInfo.attribute.type === "relation" && rawValue && _optionalChain([this, 'access', _311 => _311.options, 'optionalAccess', _312 => _312.relationService])) {
13115
+ if (_optionalChain([attrInfo, 'optionalAccess', _311 => _311.attribute])) {
13116
+ if (attrInfo.attribute.type === "relation" && rawValue && _optionalChain([this, 'access', _312 => _312.options, 'optionalAccess', _313 => _313.relationService])) {
13106
13117
  const ids = Array.isArray(rawValue) ? rawValue : [rawValue];
13107
13118
  const stringIds = ids.filter((id) => typeof id === "string");
13108
13119
  if (stringIds.length > 0) {
@@ -13123,7 +13134,7 @@ var DocumentRendererService = class {
13123
13134
  resolved.set(field.id, this.formatValueSimple(rawValue, field.fallback));
13124
13135
  }
13125
13136
  }
13126
- if (relationBatch.length > 0 && _optionalChain([this, 'access', _313 => _313.options, 'optionalAccess', _314 => _314.relationService])) {
13137
+ if (relationBatch.length > 0 && _optionalChain([this, 'access', _314 => _314.options, 'optionalAccess', _315 => _315.relationService])) {
13127
13138
  try {
13128
13139
  const batchResult = await this.options.relationService.resolveIdsBatch(
13129
13140
  relationBatch.map((r) => ({ attributeId: r.attributeId, ids: r.ids }))
@@ -13132,12 +13143,12 @@ var DocumentRendererService = class {
13132
13143
  const options = _nullishCoalesce(batchResult[attributeId], () => ( []));
13133
13144
  const labels = options.map((o) => o.label);
13134
13145
  const field = fields.find((f) => f.id === fieldId);
13135
- resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _315 => _315.fallback]) || "");
13146
+ resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _316 => _316.fallback]) || "");
13136
13147
  }
13137
- } catch (e18) {
13148
+ } catch (e19) {
13138
13149
  for (const { fieldId, ids } of relationBatch) {
13139
13150
  const field = fields.find((f) => f.id === fieldId);
13140
- resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _316 => _316.fallback]) || "");
13151
+ resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _317 => _317.fallback]) || "");
13141
13152
  }
13142
13153
  }
13143
13154
  }
@@ -13148,7 +13159,7 @@ var DocumentRendererService = class {
13148
13159
  * Parses paths like "slots.client.firstName" to find the attribute definition
13149
13160
  */
13150
13161
  async getAttributeInfo(contextPath, workflow2) {
13151
- const schemaService = _optionalChain([this, 'access', _317 => _317.options, 'optionalAccess', _318 => _318.schemaService]);
13162
+ const schemaService = _optionalChain([this, 'access', _318 => _318.options, 'optionalAccess', _319 => _319.schemaService]);
13152
13163
  if (!schemaService) {
13153
13164
  return null;
13154
13165
  }
@@ -13161,7 +13172,7 @@ var DocumentRendererService = class {
13161
13172
  }
13162
13173
  const slotId = parts[1];
13163
13174
  const attributeName = parts[2];
13164
- const slot = _optionalChain([workflow2, 'access', _319 => _319.slots, 'optionalAccess', _320 => _320.find, 'call', _321 => _321((s) => s.id === slotId)]);
13175
+ const slot = _optionalChain([workflow2, 'access', _320 => _320.slots, 'optionalAccess', _321 => _321.find, 'call', _322 => _322((s) => s.id === slotId)]);
13165
13176
  if (!slot) {
13166
13177
  return null;
13167
13178
  }
@@ -13170,7 +13181,7 @@ var DocumentRendererService = class {
13170
13181
  try {
13171
13182
  schema = await schemaService.getObjectSchemaByName(slot.objectName);
13172
13183
  this.schemaCache.set(slot.objectName, schema);
13173
- } catch (e19) {
13184
+ } catch (e20) {
13174
13185
  return null;
13175
13186
  }
13176
13187
  }
@@ -13360,7 +13371,7 @@ var DocumentProcessingHook = class extends BaseService {
13360
13371
  const pendingIds = [];
13361
13372
  for (const [nodeId, doc] of Object.entries(context.documents)) {
13362
13373
  const metadata = doc.metadata;
13363
- if (_optionalChain([metadata, 'optionalAccess', _322 => _322.status]) === "pending") {
13374
+ if (_optionalChain([metadata, 'optionalAccess', _323 => _323.status]) === "pending") {
13364
13375
  pendingIds.push(nodeId);
13365
13376
  }
13366
13377
  }
@@ -13411,12 +13422,12 @@ var DocumentProcessingHook = class extends BaseService {
13411
13422
  }
13412
13423
  for (const slotId of targetSlotIds) {
13413
13424
  try {
13414
- const recordId = _optionalChain([context, 'access', _323 => _323.createdRecordIds, 'optionalAccess', _324 => _324[slotId]]);
13425
+ const recordId = _optionalChain([context, 'access', _324 => _324.createdRecordIds, 'optionalAccess', _325 => _325[slotId]]);
13415
13426
  if (!recordId) {
13416
13427
  continue;
13417
13428
  }
13418
- const slotDef = _optionalChain([workflow2, 'access', _325 => _325.slots, 'optionalAccess', _326 => _326.find, 'call', _327 => _327((s) => s.id === slotId)]);
13419
- const objectName = _optionalChain([slotDef, 'optionalAccess', _328 => _328.objectName]);
13429
+ const slotDef = _optionalChain([workflow2, 'access', _326 => _326.slots, 'optionalAccess', _327 => _327.find, 'call', _328 => _328((s) => s.id === slotId)]);
13430
+ const objectName = _optionalChain([slotDef, 'optionalAccess', _329 => _329.objectName]);
13420
13431
  if (!objectName) {
13421
13432
  continue;
13422
13433
  }
@@ -13433,14 +13444,14 @@ var DocumentProcessingHook = class extends BaseService {
13433
13444
  attachedDocumentIds.push(result.document.id);
13434
13445
  const record = await recordService.getRecord(recordId);
13435
13446
  if (record) {
13436
- const attachments = _nullishCoalesce(_optionalChain([record, 'access', _329 => _329.values, 'optionalAccess', _330 => _330.attachments]), () => ( []));
13447
+ const attachments = _nullishCoalesce(_optionalChain([record, 'access', _330 => _330.values, 'optionalAccess', _331 => _331.attachments]), () => ( []));
13437
13448
  await recordService.updateRecord(
13438
13449
  recordId,
13439
13450
  { attachments: [...attachments, result.document.id] },
13440
13451
  { partial: true }
13441
13452
  );
13442
13453
  }
13443
- } catch (e20) {
13454
+ } catch (e21) {
13444
13455
  }
13445
13456
  }
13446
13457
  return attachedDocumentIds;
@@ -13699,7 +13710,7 @@ var WorkflowAccessGrantService = class extends BaseService {
13699
13710
  * Check if a specific token has been revoked.
13700
13711
  */
13701
13712
  isTokenRevoked(dbGrant, jti) {
13702
- return _nullishCoalesce(_optionalChain([dbGrant, 'access', _331 => _331.revoked_token_jtis, 'optionalAccess', _332 => _332.includes, 'call', _333 => _333(jti)]), () => ( false));
13713
+ return _nullishCoalesce(_optionalChain([dbGrant, 'access', _332 => _332.revoked_token_jtis, 'optionalAccess', _333 => _333.includes, 'call', _334 => _334(jti)]), () => ( false));
13703
13714
  }
13704
13715
  /**
13705
13716
  * Validate access token payload against the grant.
@@ -13751,10 +13762,10 @@ var WorkflowInstanceService = class extends BaseService {
13751
13762
  constructor(adapter, workflowService, options) {
13752
13763
  super(adapter);
13753
13764
  this.workflowService = workflowService;
13754
- this.executorRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _334 => _334.executorRegistry]), () => ( getDefaultExecutorRegistry()));
13755
- this.schemaService = _optionalChain([options, 'optionalAccess', _335 => _335.schemaService]);
13756
- this.recordService = _optionalChain([options, 'optionalAccess', _336 => _336.recordService]);
13757
- this.documentProcessingHook = _optionalChain([options, 'optionalAccess', _337 => _337.documentProcessingHook]);
13765
+ this.executorRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _335 => _335.executorRegistry]), () => ( getDefaultExecutorRegistry()));
13766
+ this.schemaService = _optionalChain([options, 'optionalAccess', _336 => _336.schemaService]);
13767
+ this.recordService = _optionalChain([options, 'optionalAccess', _337 => _337.recordService]);
13768
+ this.documentProcessingHook = _optionalChain([options, 'optionalAccess', _338 => _338.documentProcessingHook]);
13758
13769
  }
13759
13770
  /**
13760
13771
  * Start a new workflow instance
@@ -13936,7 +13947,7 @@ var WorkflowInstanceService = class extends BaseService {
13936
13947
  if (!this.adapter.workflowInstances) {
13937
13948
  return { instances: [], total: 0 };
13938
13949
  }
13939
- if (_optionalChain([options, 'optionalAccess', _338 => _338.workflowName])) {
13950
+ if (_optionalChain([options, 'optionalAccess', _339 => _339.workflowName])) {
13940
13951
  const allDbInstances = await this.adapter.workflowInstances.findByWorkflowName(
13941
13952
  options.workflowName,
13942
13953
  { status: options.status }
@@ -13950,11 +13961,11 @@ var WorkflowInstanceService = class extends BaseService {
13950
13961
  return { instances: instances2, total: total2 };
13951
13962
  }
13952
13963
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.list({
13953
- limit: _optionalChain([options, 'optionalAccess', _339 => _339.limit]),
13954
- offset: _optionalChain([options, 'optionalAccess', _340 => _340.offset])
13964
+ limit: _optionalChain([options, 'optionalAccess', _340 => _340.limit]),
13965
+ offset: _optionalChain([options, 'optionalAccess', _341 => _341.offset])
13955
13966
  });
13956
13967
  let instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13957
- if (_optionalChain([options, 'optionalAccess', _341 => _341.status])) {
13968
+ if (_optionalChain([options, 'optionalAccess', _342 => _342.status])) {
13958
13969
  instances = instances.filter((i) => i.status === options.status);
13959
13970
  }
13960
13971
  instances = await this.markExpiredInstances(instances);
@@ -13975,9 +13986,9 @@ var WorkflowInstanceService = class extends BaseService {
13975
13986
  return { instances: [], total: 0 };
13976
13987
  }
13977
13988
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.findByRecordInSlots(objectName, recordId, {
13978
- status: _optionalChain([options, 'optionalAccess', _342 => _342.status]),
13979
- limit: _optionalChain([options, 'optionalAccess', _343 => _343.limit]),
13980
- offset: _optionalChain([options, 'optionalAccess', _344 => _344.offset])
13989
+ status: _optionalChain([options, 'optionalAccess', _343 => _343.status]),
13990
+ limit: _optionalChain([options, 'optionalAccess', _344 => _344.limit]),
13991
+ offset: _optionalChain([options, 'optionalAccess', _345 => _345.offset])
13981
13992
  });
13982
13993
  const instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13983
13994
  return { instances, total };
@@ -14043,13 +14054,13 @@ var WorkflowInstanceService = class extends BaseService {
14043
14054
  try {
14044
14055
  const schemas = await Promise.all(
14045
14056
  current.workflowSnapshot.slots.map(
14046
- (slot) => _optionalChain([this, 'access', _345 => _345.schemaService, 'optionalAccess', _346 => _346.getObjectSchemaByName, 'call', _347 => _347(slot.objectName)])
14057
+ (slot) => _optionalChain([this, 'access', _346 => _346.schemaService, 'optionalAccess', _347 => _347.getObjectSchemaByName, 'call', _348 => _348(slot.objectName)])
14047
14058
  )
14048
14059
  );
14049
14060
  objectDefinitions = schemas.filter(
14050
14061
  (s) => s !== void 0
14051
14062
  );
14052
- } catch (e21) {
14063
+ } catch (e22) {
14053
14064
  }
14054
14065
  }
14055
14066
  const executorContext = {
@@ -14308,9 +14319,9 @@ var WorkflowInstanceService = class extends BaseService {
14308
14319
  */
14309
14320
  async snapshotRecord(recordId) {
14310
14321
  try {
14311
- const record = await _optionalChain([this, 'access', _348 => _348.recordService, 'optionalAccess', _349 => _349.getRecord, 'call', _350 => _350(recordId, { skipPolicyCheck: true })]);
14312
- return _optionalChain([record, 'optionalAccess', _351 => _351.values]);
14313
- } catch (e22) {
14322
+ const record = await _optionalChain([this, 'access', _349 => _349.recordService, 'optionalAccess', _350 => _350.getRecord, 'call', _351 => _351(recordId, { skipPolicyCheck: true })]);
14323
+ return _optionalChain([record, 'optionalAccess', _352 => _352.values]);
14324
+ } catch (e23) {
14314
14325
  return void 0;
14315
14326
  }
14316
14327
  }
@@ -14328,18 +14339,18 @@ var WorkflowInstanceService = class extends BaseService {
14328
14339
  for (const op of [...operations].reverse()) {
14329
14340
  try {
14330
14341
  if (op.operation === "create") {
14331
- await _optionalChain([this, 'access', _352 => _352.recordService, 'optionalAccess', _353 => _353.deleteRecord, 'call', _354 => _354(op.recordId, {
14342
+ await _optionalChain([this, 'access', _353 => _353.recordService, 'optionalAccess', _354 => _354.deleteRecord, 'call', _355 => _355(op.recordId, {
14332
14343
  skipHooks: true,
14333
14344
  skipReferenceCheck: true
14334
14345
  })]);
14335
14346
  rolledBack.push(op.slotId);
14336
14347
  } else if (op.operation === "update" && op.previousData) {
14337
- await _optionalChain([this, 'access', _355 => _355.recordService, 'optionalAccess', _356 => _356.updateRecord, 'call', _357 => _357(op.recordId, op.previousData, {
14348
+ await _optionalChain([this, 'access', _356 => _356.recordService, 'optionalAccess', _357 => _357.updateRecord, 'call', _358 => _358(op.recordId, op.previousData, {
14338
14349
  partial: false
14339
14350
  })]);
14340
14351
  rolledBack.push(op.slotId);
14341
14352
  }
14342
- } catch (e23) {
14353
+ } catch (e24) {
14343
14354
  }
14344
14355
  }
14345
14356
  return rolledBack;
@@ -14458,7 +14469,7 @@ var WorkflowInstanceService = class extends BaseService {
14458
14469
  if (!this.adapter.workflowInstances) {
14459
14470
  return;
14460
14471
  }
14461
- const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _358 => _358.context, 'access', _359 => _359.variables, 'optionalAccess', _360 => _360.__version]), () => ( 0));
14472
+ const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _359 => _359.context, 'access', _360 => _360.variables, 'optionalAccess', _361 => _361.__version]), () => ( 0));
14462
14473
  const nextVersion = currentVersion + 1;
14463
14474
  const instanceWithVersion = {
14464
14475
  ...instance,
@@ -14739,7 +14750,7 @@ var WorkflowRelationService = class extends BaseService {
14739
14750
  if (attr.type !== "relation") continue;
14740
14751
  for (const slot of slots) {
14741
14752
  const slotData = context.slots[slot.id];
14742
- const slotRecordId = _optionalChain([slotData, 'optionalAccess', _361 => _361.id]);
14753
+ const slotRecordId = _optionalChain([slotData, 'optionalAccess', _362 => _362.id]);
14743
14754
  if (!slotRecordId) continue;
14744
14755
  const targetsSlotObject = attr.targets.some(
14745
14756
  (t) => t.object === slot.objectName
@@ -14807,7 +14818,7 @@ var WorkflowService = class extends BaseService {
14807
14818
  if (Array.isArray(options)) {
14808
14819
  this.systemWorkflows = new Map(options.map((w) => [w.name, w]));
14809
14820
  } else {
14810
- this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _362 => _362.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14821
+ this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _363 => _363.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14811
14822
  }
14812
14823
  }
14813
14824
  // ============================================================================
@@ -15105,7 +15116,7 @@ var WorkflowService = class extends BaseService {
15105
15116
  var UserProfileService = class extends BaseService {
15106
15117
  constructor(adapter, options) {
15107
15118
  super(adapter);
15108
- this.auditService = _optionalChain([options, 'optionalAccess', _363 => _363.auditService]);
15119
+ this.auditService = _optionalChain([options, 'optionalAccess', _364 => _364.auditService]);
15109
15120
  }
15110
15121
  // ============================================================================
15111
15122
  // CACHE MANAGEMENT
@@ -15123,6 +15134,74 @@ var UserProfileService = class extends BaseService {
15123
15134
  await this.invalidateCache(cacheKeys.userProfileByEmail(this.tenantId, email));
15124
15135
  }
15125
15136
  }
15137
+ // ============================================================================
15138
+ // AVATAR URL RESOLUTION
15139
+ // ============================================================================
15140
+ /**
15141
+ * Resolve avatar storage path to a signed URL.
15142
+ * External URLs (https://) pass through unchanged.
15143
+ * Storage paths are resolved to fresh signed URLs (1h expiry).
15144
+ */
15145
+ async resolveAvatarUrl(profile) {
15146
+ if (!profile.avatarUrl || profile.avatarUrl.startsWith("https://")) {
15147
+ return profile;
15148
+ }
15149
+ if (!this.adapter.storage) return profile;
15150
+ try {
15151
+ const signedUrl = await this.adapter.storage.getSignedUrl(profile.avatarUrl, {
15152
+ expiresIn: 3600
15153
+ });
15154
+ return { ...profile, avatarUrl: signedUrl };
15155
+ } catch (e25) {
15156
+ return profile;
15157
+ }
15158
+ }
15159
+ async resolveAvatarUrls(profiles) {
15160
+ return Promise.all(profiles.map((p) => this.resolveAvatarUrl(p)));
15161
+ }
15162
+ // ============================================================================
15163
+ // AVATAR MANAGEMENT
15164
+ // ============================================================================
15165
+ /**
15166
+ * Upload a new avatar for the user.
15167
+ * Deletes previous avatar from storage if it was an internal upload.
15168
+ * Stores the storagePath — resolved to signed URL at read time.
15169
+ */
15170
+ async uploadAvatar(profileId, input) {
15171
+ if (!this.adapter.storage) {
15172
+ throw new Error("StorageAdapter is not configured.");
15173
+ }
15174
+ if (!input.mimeType.startsWith("image/")) {
15175
+ throw new Error("Only image files are allowed for avatars.");
15176
+ }
15177
+ const profile = await this.getProfileOrThrow(profileId);
15178
+ if (profile.avatarUrl && !profile.avatarUrl.startsWith("https://")) {
15179
+ await this.adapter.storage.delete(profile.avatarUrl).catch(() => void 0);
15180
+ }
15181
+ const result = await this.adapter.storage.upload({
15182
+ content: input.content,
15183
+ fileName: input.fileName,
15184
+ mimeType: input.mimeType,
15185
+ size: input.size,
15186
+ tenantId: this.tenantId,
15187
+ folderPath: "avatars"
15188
+ });
15189
+ return await this.updateProfile(profileId, { avatarUrl: result.storagePath });
15190
+ }
15191
+ /**
15192
+ * Delete the user's avatar.
15193
+ * Removes file from storage if it was an internal upload, then clears avatarUrl.
15194
+ */
15195
+ async deleteAvatar(profileId) {
15196
+ const profile = await this.getProfileOrThrow(profileId);
15197
+ if (profile.avatarUrl && !profile.avatarUrl.startsWith("https://")) {
15198
+ await _optionalChain([this, 'access', _365 => _365.adapter, 'access', _366 => _366.storage, 'optionalAccess', _367 => _367.delete, 'call', _368 => _368(profile.avatarUrl), 'access', _369 => _369.catch, 'call', _370 => _370(() => void 0)]);
15199
+ }
15200
+ return await this.updateProfile(profileId, { avatarUrl: null });
15201
+ }
15202
+ // ============================================================================
15203
+ // CREATE
15204
+ // ============================================================================
15126
15205
  /**
15127
15206
  * Create a new user profile (typically after first auth).
15128
15207
  * Automatically uses tenant context from AsyncLocalStorage.
@@ -15163,18 +15242,19 @@ var UserProfileService = class extends BaseService {
15163
15242
  targetUserEmail: profile.email
15164
15243
  });
15165
15244
  }
15166
- return profile;
15245
+ return this.resolveAvatarUrl(profile);
15167
15246
  }
15168
15247
  /**
15169
15248
  * Get user profile by ID.
15170
15249
  * Results are cached if a CacheAdapter is configured.
15171
15250
  */
15172
15251
  async getProfile(profileId) {
15173
- return this.cachedBy(
15252
+ const profile = await this.cachedBy(
15174
15253
  "userProfileById",
15175
15254
  profileId,
15176
15255
  () => this.adapter.userProfiles.findById(profileId)
15177
15256
  );
15257
+ return profile ? this.resolveAvatarUrl(profile) : null;
15178
15258
  }
15179
15259
  /**
15180
15260
  * Get user profile by ID or throw
@@ -15196,11 +15276,12 @@ var UserProfileService = class extends BaseService {
15196
15276
  * @returns User profile or null
15197
15277
  */
15198
15278
  async getProfileByAuthId(authId) {
15199
- return this.cachedBy(
15279
+ const profile = await this.cachedBy(
15200
15280
  "userProfileByAuthId",
15201
15281
  authId,
15202
15282
  () => this.adapter.userProfiles.findByAuthId(authId)
15203
15283
  );
15284
+ return profile ? this.resolveAvatarUrl(profile) : null;
15204
15285
  }
15205
15286
  /**
15206
15287
  * Get or create user profile (idempotent operation)
@@ -15239,11 +15320,11 @@ var UserProfileService = class extends BaseService {
15239
15320
  const updated = await this.adapter.userProfiles.update(profileId, data);
15240
15321
  await this.invalidateProfileCache(updated.id, updated.authId, updated.email);
15241
15322
  if (this.auditService && this.userId) {
15242
- const changes = buildAuditChanges(existing, data, [
15243
- "firstName",
15244
- "lastName",
15245
- "status"
15246
- ]);
15323
+ const changes = buildAuditChanges(
15324
+ existing,
15325
+ data,
15326
+ ["firstName", "lastName", "status"]
15327
+ );
15247
15328
  if (changes.length > 0) {
15248
15329
  await this.auditService.logUserAction({
15249
15330
  action: "user.updated",
@@ -15254,7 +15335,7 @@ var UserProfileService = class extends BaseService {
15254
15335
  });
15255
15336
  }
15256
15337
  }
15257
- return updated;
15338
+ return this.resolveAvatarUrl(updated);
15258
15339
  }
15259
15340
  /**
15260
15341
  * Delete user profile.
@@ -15265,7 +15346,7 @@ var UserProfileService = class extends BaseService {
15265
15346
  */
15266
15347
  async deleteProfile(profileId, options) {
15267
15348
  const profile = await this.getProfileOrThrow(profileId);
15268
- if (_optionalChain([options, 'optionalAccess', _364 => _364.checkAdmin]) && this.adapter.permissions) {
15349
+ if (_optionalChain([options, 'optionalAccess', _371 => _371.checkAdmin]) && this.adapter.permissions) {
15269
15350
  const ownerCount = await this.adapter.permissions.countUsersWithRole("owner");
15270
15351
  if (ownerCount <= 1) {
15271
15352
  const userRoles = await this.adapter.permissions.getUserRoles(profileId);
@@ -15291,7 +15372,8 @@ var UserProfileService = class extends BaseService {
15291
15372
  * Automatically uses tenant context from AsyncLocalStorage.
15292
15373
  */
15293
15374
  async listProfiles(options) {
15294
- return await this.adapter.userProfiles.list(options);
15375
+ const profiles = await this.adapter.userProfiles.list(options);
15376
+ return this.resolveAvatarUrls(profiles);
15295
15377
  }
15296
15378
  /**
15297
15379
  * Update last login timestamp
@@ -15322,11 +15404,12 @@ var UserProfileService = class extends BaseService {
15322
15404
  * Automatically uses tenant context from AsyncLocalStorage.
15323
15405
  */
15324
15406
  async getProfileByEmail(email) {
15325
- return this.cachedBy(
15407
+ const profile = await this.cachedBy(
15326
15408
  "userProfileByEmail",
15327
15409
  email,
15328
15410
  () => this.adapter.userProfiles.findByEmail(email)
15329
15411
  );
15412
+ return profile ? this.resolveAvatarUrl(profile) : null;
15330
15413
  }
15331
15414
  /**
15332
15415
  * Invite a new user by email.
@@ -15359,6 +15442,21 @@ var UserProfileService = class extends BaseService {
15359
15442
  throw new Error(`User with email "${data.email}" already exists in this tenant`);
15360
15443
  }
15361
15444
  const profile = await this.adapter.userProfiles.invite(data);
15445
+ if (this.adapter.permissions) {
15446
+ try {
15447
+ const roles = await this.adapter.permissions.getRoles();
15448
+ const defaultRole = roles.find((r) => r.name === "member" && r.system);
15449
+ if (defaultRole) {
15450
+ await this.adapter.permissions.assignRole({
15451
+ userProfileId: profile.id,
15452
+ roleId: defaultRole.id,
15453
+ tenantId: this.tenantId,
15454
+ assignedBy: _nullishCoalesce(this.userId, () => ( void 0))
15455
+ });
15456
+ }
15457
+ } catch (e26) {
15458
+ }
15459
+ }
15362
15460
  await this.invalidateProfileCache(profile.id, profile.authId, profile.email);
15363
15461
  if (this.auditService && this.userId) {
15364
15462
  await this.auditService.logUserAction({
@@ -15368,7 +15466,7 @@ var UserProfileService = class extends BaseService {
15368
15466
  targetUserEmail: profile.email
15369
15467
  });
15370
15468
  }
15371
- return profile;
15469
+ return this.resolveAvatarUrl(profile);
15372
15470
  }
15373
15471
  };
15374
15472
 
@@ -15753,7 +15851,7 @@ var DocumentTemplateService = class extends BaseService {
15753
15851
  * Includes both system templates and tenant-specific templates.
15754
15852
  */
15755
15853
  async listTemplates(options) {
15756
- if (_optionalChain([options, 'optionalAccess', _365 => _365.systemOnly])) {
15854
+ if (_optionalChain([options, 'optionalAccess', _372 => _372.systemOnly])) {
15757
15855
  return SYSTEM_TEMPLATES;
15758
15856
  }
15759
15857
  const templates = [...SYSTEM_TEMPLATES];
@@ -15836,8 +15934,8 @@ var DocumentTemplateService = class extends BaseService {
15836
15934
  var DocumentService = class extends BaseService {
15837
15935
  constructor(adapter, options) {
15838
15936
  super(adapter);
15839
- this.templateService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _366 => _366.templateService]), () => ( new DocumentTemplateService(adapter)));
15840
- this.fileService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _367 => _367.fileService]), () => ( null));
15937
+ this.templateService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _373 => _373.templateService]), () => ( new DocumentTemplateService(adapter)));
15938
+ this.fileService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _374 => _374.fileService]), () => ( null));
15841
15939
  }
15842
15940
  // ============================================================================
15843
15941
  // CREATE
@@ -16088,7 +16186,7 @@ var DocumentService = class extends BaseService {
16088
16186
  */
16089
16187
  async isComplete(documentId) {
16090
16188
  const document2 = await this.getDocument(documentId);
16091
- return _optionalChain([document2, 'optionalAccess', _368 => _368.status]) !== "draft";
16189
+ return _optionalChain([document2, 'optionalAccess', _375 => _375.status]) !== "draft";
16092
16190
  }
16093
16191
  /**
16094
16192
  * Get document with its template and slots.
@@ -16346,7 +16444,7 @@ var DocumentProcessingService = class extends BaseService {
16346
16444
  type: "signature",
16347
16445
  provider: this.config.signatureAdapter.name,
16348
16446
  input: { signers, ...options },
16349
- expiresAt: _optionalChain([options, 'optionalAccess', _369 => _369.expiresAt])
16447
+ expiresAt: _optionalChain([options, 'optionalAccess', _376 => _376.expiresAt])
16350
16448
  });
16351
16449
  return job;
16352
16450
  }
@@ -16503,7 +16601,7 @@ var DocumentProcessingService = class extends BaseService {
16503
16601
  }
16504
16602
  const document2 = await this.documentService.getDocumentOrThrow(documentId);
16505
16603
  const template = await this.templateService.getTemplateOrThrow(document2.templateId);
16506
- if (!_optionalChain([template, 'access', _370 => _370.autoProcessing, 'optionalAccess', _371 => _371.identityVerification, 'optionalAccess', _372 => _372.enabled])) {
16604
+ if (!_optionalChain([template, 'access', _377 => _377.autoProcessing, 'optionalAccess', _378 => _378.identityVerification, 'optionalAccess', _379 => _379.enabled])) {
16507
16605
  throw new Error("Identity verification is not enabled for this document type");
16508
16606
  }
16509
16607
  const job = await this.adapter.documentJobs.create({
@@ -16589,13 +16687,13 @@ var DocumentProcessingService = class extends BaseService {
16589
16687
  const template = await this.templateService.getTemplateOrThrow(document2.templateId);
16590
16688
  const slots = await this.documentService.getSlots(documentId);
16591
16689
  const jobs = [];
16592
- if (_optionalChain([template, 'access', _373 => _373.autoProcessing, 'optionalAccess', _374 => _374.ocr, 'optionalAccess', _375 => _375.enabled]) && this.config.ocrAdapter) {
16690
+ if (_optionalChain([template, 'access', _380 => _380.autoProcessing, 'optionalAccess', _381 => _381.ocr, 'optionalAccess', _382 => _382.enabled]) && this.config.ocrAdapter) {
16593
16691
  for (const slot of slots) {
16594
16692
  const job = await this.processOcr(documentId, slot.slotName);
16595
16693
  jobs.push(job);
16596
16694
  }
16597
16695
  }
16598
- if (_optionalChain([template, 'access', _376 => _376.autoProcessing, 'optionalAccess', _377 => _377.identityVerification, 'optionalAccess', _378 => _378.enabled]) && this.config.identityAdapter) {
16696
+ if (_optionalChain([template, 'access', _383 => _383.autoProcessing, 'optionalAccess', _384 => _384.identityVerification, 'optionalAccess', _385 => _385.enabled]) && this.config.identityAdapter) {
16599
16697
  const job = await this.verifyIdentity(documentId);
16600
16698
  jobs.push(job);
16601
16699
  }
@@ -16666,15 +16764,15 @@ var DocumentProcessingService = class extends BaseService {
16666
16764
  return {
16667
16765
  ocr: {
16668
16766
  available: !!this.config.ocrAdapter,
16669
- provider: _optionalChain([this, 'access', _379 => _379.config, 'access', _380 => _380.ocrAdapter, 'optionalAccess', _381 => _381.name])
16767
+ provider: _optionalChain([this, 'access', _386 => _386.config, 'access', _387 => _387.ocrAdapter, 'optionalAccess', _388 => _388.name])
16670
16768
  },
16671
16769
  signature: {
16672
16770
  available: !!this.config.signatureAdapter,
16673
- provider: _optionalChain([this, 'access', _382 => _382.config, 'access', _383 => _383.signatureAdapter, 'optionalAccess', _384 => _384.name])
16771
+ provider: _optionalChain([this, 'access', _389 => _389.config, 'access', _390 => _390.signatureAdapter, 'optionalAccess', _391 => _391.name])
16674
16772
  },
16675
16773
  identityVerification: {
16676
16774
  available: !!this.config.identityAdapter,
16677
- provider: _optionalChain([this, 'access', _385 => _385.config, 'access', _386 => _386.identityAdapter, 'optionalAccess', _387 => _387.name])
16775
+ provider: _optionalChain([this, 'access', _392 => _392.config, 'access', _393 => _393.identityAdapter, 'optionalAccess', _394 => _394.name])
16678
16776
  }
16679
16777
  };
16680
16778
  }
@@ -16684,7 +16782,7 @@ var DocumentProcessingService = class extends BaseService {
16684
16782
  var FileService = class extends BaseService {
16685
16783
  constructor(adapter, options) {
16686
16784
  super(adapter);
16687
- this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _388 => _388.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
16785
+ this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _395 => _395.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
16688
16786
  }
16689
16787
  // ============================================================================
16690
16788
  // UPLOAD (requires StorageAdapter)
@@ -16823,7 +16921,7 @@ var FileService = class extends BaseService {
16823
16921
  */
16824
16922
  async getFile(fileId) {
16825
16923
  const file2 = await this.adapter.files.findById(fileId);
16826
- if (_optionalChain([file2, 'optionalAccess', _389 => _389.deletedAt])) {
16924
+ if (_optionalChain([file2, 'optionalAccess', _396 => _396.deletedAt])) {
16827
16925
  return null;
16828
16926
  }
16829
16927
  return file2;
@@ -16885,12 +16983,12 @@ var FileService = class extends BaseService {
16885
16983
  */
16886
16984
  async deleteFile(fileId, options) {
16887
16985
  const file2 = await this.getFileOrThrow(fileId);
16888
- if (_optionalChain([options, 'optionalAccess', _390 => _390.checkOwnership]) && options.userId) {
16986
+ if (_optionalChain([options, 'optionalAccess', _397 => _397.checkOwnership]) && options.userId) {
16889
16987
  if (file2.uploadedBy !== options.userId) {
16890
16988
  throw new Error("You can only delete files you uploaded");
16891
16989
  }
16892
16990
  }
16893
- if (_optionalChain([options, 'optionalAccess', _391 => _391.hard])) {
16991
+ if (_optionalChain([options, 'optionalAccess', _398 => _398.hard])) {
16894
16992
  await this.adapter.files.hardDelete(fileId);
16895
16993
  } else {
16896
16994
  await this.adapter.files.delete(fileId);
@@ -16921,7 +17019,7 @@ var FileService = class extends BaseService {
16921
17019
  }
16922
17020
  const file2 = await this.getFileOrThrow(fileId);
16923
17021
  await this.adapter.storage.delete(file2.storagePath);
16924
- if (_optionalChain([options, 'optionalAccess', _392 => _392.hard])) {
17022
+ if (_optionalChain([options, 'optionalAccess', _399 => _399.hard])) {
16925
17023
  await this.adapter.files.hardDelete(fileId);
16926
17024
  } else {
16927
17025
  await this.adapter.files.delete(fileId);
@@ -16947,15 +17045,15 @@ var FileService = class extends BaseService {
16947
17045
  const fileResults = await Promise.all(fileIds.map((id) => this.getFile(id)));
16948
17046
  const files = fileResults.filter((f) => f !== null);
16949
17047
  if (files.length === 0) return;
16950
- if (_optionalChain([options, 'optionalAccess', _393 => _393.deleteFromStorage]) && this.adapter.storage) {
17048
+ if (_optionalChain([options, 'optionalAccess', _400 => _400.deleteFromStorage]) && this.adapter.storage) {
16951
17049
  const BATCH_SIZE = 10;
16952
17050
  for (let i = 0; i < files.length; i += BATCH_SIZE) {
16953
17051
  const batch = files.slice(i, i + BATCH_SIZE);
16954
- await Promise.all(batch.map((file2) => _optionalChain([this, 'access', _394 => _394.adapter, 'access', _395 => _395.storage, 'optionalAccess', _396 => _396.delete, 'call', _397 => _397(file2.storagePath)])));
17052
+ await Promise.all(batch.map((file2) => _optionalChain([this, 'access', _401 => _401.adapter, 'access', _402 => _402.storage, 'optionalAccess', _403 => _403.delete, 'call', _404 => _404(file2.storagePath)])));
16955
17053
  }
16956
17054
  }
16957
17055
  const idsToDelete = files.map((f) => f.id);
16958
- if (_optionalChain([options, 'optionalAccess', _398 => _398.hard])) {
17056
+ if (_optionalChain([options, 'optionalAccess', _405 => _405.hard])) {
16959
17057
  await Promise.all(idsToDelete.map((id) => this.adapter.files.hardDelete(id)));
16960
17058
  } else {
16961
17059
  await Promise.all(idsToDelete.map((id) => this.adapter.files.delete(id)));
@@ -16963,12 +17061,12 @@ var FileService = class extends BaseService {
16963
17061
  if (this.auditService && this.userId) {
16964
17062
  await Promise.all(
16965
17063
  files.map(
16966
- (file2) => _optionalChain([this, 'access', _399 => _399.auditService, 'optionalAccess', _400 => _400.logFileAction, 'call', _401 => _401({
17064
+ (file2) => _optionalChain([this, 'access', _406 => _406.auditService, 'optionalAccess', _407 => _407.logFileAction, 'call', _408 => _408({
16967
17065
  action: "file.deleted",
16968
17066
  actorId: _nullishCoalesce(this.userId, () => ( "")),
16969
17067
  fileId: file2.id,
16970
17068
  fileName: file2.name,
16971
- metadata: { deletedFromStorage: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _402 => _402.deleteFromStorage]), () => ( false)) }
17069
+ metadata: { deletedFromStorage: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _409 => _409.deleteFromStorage]), () => ( false)) }
16972
17070
  })])
16973
17071
  )
16974
17072
  );
@@ -17041,14 +17139,11 @@ var FileService = class extends BaseService {
17041
17139
  * @param userId - User ID to check
17042
17140
  * @returns true if user can access the file
17043
17141
  */
17044
- async checkAccess(fileId, userId, options) {
17142
+ async checkAccess(fileId, userId) {
17045
17143
  const file2 = await this.getFile(fileId);
17046
17144
  if (!file2) {
17047
17145
  return false;
17048
17146
  }
17049
- if (_optionalChain([options, 'optionalAccess', _403 => _403.isAdmin])) {
17050
- return true;
17051
- }
17052
17147
  if (file2.visibility === "public") {
17053
17148
  return true;
17054
17149
  }
@@ -17056,7 +17151,7 @@ var FileService = class extends BaseService {
17056
17151
  return true;
17057
17152
  }
17058
17153
  if (file2.visibility === "restricted") {
17059
- return _nullishCoalesce(_optionalChain([file2, 'access', _404 => _404.allowedUsers, 'optionalAccess', _405 => _405.includes, 'call', _406 => _406(userId)]), () => ( false));
17154
+ return _nullishCoalesce(_optionalChain([file2, 'access', _410 => _410.allowedUsers, 'optionalAccess', _411 => _411.includes, 'call', _412 => _412(userId)]), () => ( false));
17060
17155
  }
17061
17156
  return false;
17062
17157
  }
@@ -17151,7 +17246,7 @@ function withTimeout(promise, ms, label) {
17151
17246
  var GeocodingService = class {
17152
17247
  constructor(adapter, options) {
17153
17248
  this.adapter = adapter;
17154
- this.timeoutMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _407 => _407.timeoutMs]), () => ( GEOCODING_TIMEOUT_MS));
17249
+ this.timeoutMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _413 => _413.timeoutMs]), () => ( GEOCODING_TIMEOUT_MS));
17155
17250
  }
17156
17251
  /**
17157
17252
  * Search for address suggestions as the user types
@@ -17210,9 +17305,9 @@ var GlobalSearchService = class extends BaseService {
17210
17305
  if (this.adapter.search) {
17211
17306
  try {
17212
17307
  const raw = await this.adapter.search.globalSearch(trimmed, {
17213
- objectNames: _optionalChain([options, 'optionalAccess', _408 => _408.objectNames]),
17214
- limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _409 => _409.limit]), () => ( 20)),
17215
- offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _410 => _410.offset]), () => ( 0))
17308
+ objectNames: _optionalChain([options, 'optionalAccess', _414 => _414.objectNames]),
17309
+ limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _415 => _415.limit]), () => ( 20)),
17310
+ offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _416 => _416.offset]), () => ( 0))
17216
17311
  });
17217
17312
  return await this.healGlobalSearchResults(raw);
17218
17313
  } catch (err) {
@@ -17220,9 +17315,9 @@ var GlobalSearchService = class extends BaseService {
17220
17315
  }
17221
17316
  }
17222
17317
  return this.adapter.objectRecords.globalSearch(trimmed, {
17223
- limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _411 => _411.limit]), () => ( 20)),
17224
- offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _412 => _412.offset]), () => ( 0)),
17225
- objectNames: _optionalChain([options, 'optionalAccess', _413 => _413.objectNames])
17318
+ limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _417 => _417.limit]), () => ( 20)),
17319
+ offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _418 => _418.offset]), () => ( 0)),
17320
+ objectNames: _optionalChain([options, 'optionalAccess', _419 => _419.objectNames])
17226
17321
  });
17227
17322
  }
17228
17323
  /**
@@ -17241,7 +17336,7 @@ var GlobalSearchService = class extends BaseService {
17241
17336
  if (this.adapter.search) {
17242
17337
  try {
17243
17338
  const raw = await this.adapter.search.globalSearchGrouped(trimmed, {
17244
- objectNames: _optionalChain([options, 'optionalAccess', _414 => _414.objectNames])
17339
+ objectNames: _optionalChain([options, 'optionalAccess', _420 => _420.objectNames])
17245
17340
  });
17246
17341
  return await this.healGroupedSearchResults(raw);
17247
17342
  } catch (err) {
@@ -17249,8 +17344,8 @@ var GlobalSearchService = class extends BaseService {
17249
17344
  }
17250
17345
  }
17251
17346
  return this.adapter.objectRecords.globalSearchGrouped(trimmed, {
17252
- objectNames: _optionalChain([options, 'optionalAccess', _415 => _415.objectNames]),
17253
- limitPerGroup: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _416 => _416.limitPerGroup]), () => ( 5))
17347
+ objectNames: _optionalChain([options, 'optionalAccess', _421 => _421.objectNames]),
17348
+ limitPerGroup: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _422 => _422.limitPerGroup]), () => ( 5))
17254
17349
  });
17255
17350
  }
17256
17351
  // ==========================================================================
@@ -17317,7 +17412,7 @@ var PermissionService = class extends BaseService {
17317
17412
  }
17318
17413
  this.permissionsRepo = adapter.permissions;
17319
17414
  this.permissionCache = _nullishCoalesce(adapter.cache, () => ( new NoopCacheAdapter()));
17320
- this.auditService = _optionalChain([options, 'optionalAccess', _417 => _417.auditService]);
17415
+ this.auditService = _optionalChain([options, 'optionalAccess', _423 => _423.auditService]);
17321
17416
  }
17322
17417
  // ============================================================================
17323
17418
  // PERMISSION CHECKS
@@ -17332,15 +17427,12 @@ var PermissionService = class extends BaseService {
17332
17427
  */
17333
17428
  async canAccessObject(userProfileId, objectName, action) {
17334
17429
  const permissions = await this.getEffectivePermissions(userProfileId);
17335
- if (permissions.isAdmin) {
17336
- return true;
17337
- }
17338
17430
  const wildcardPerms = permissions.objectPermissions["*"];
17339
- if (_optionalChain([wildcardPerms, 'optionalAccess', _418 => _418.includes, 'call', _419 => _419(action)])) {
17431
+ if (_optionalChain([wildcardPerms, 'optionalAccess', _424 => _424.includes, 'call', _425 => _425(action)])) {
17340
17432
  return true;
17341
17433
  }
17342
17434
  const objectPerms = permissions.objectPermissions[objectName];
17343
- return _nullishCoalesce(_optionalChain([objectPerms, 'optionalAccess', _420 => _420.includes, 'call', _421 => _421(action)]), () => ( false));
17435
+ return _nullishCoalesce(_optionalChain([objectPerms, 'optionalAccess', _426 => _426.includes, 'call', _427 => _427(action)]), () => ( false));
17344
17436
  }
17345
17437
  /**
17346
17438
  * Check if user can access an object, throw ForbiddenError if not.
@@ -17366,9 +17458,6 @@ var PermissionService = class extends BaseService {
17366
17458
  */
17367
17459
  async getObjectPermissions(userProfileId, objectName) {
17368
17460
  const permissions = await this.getEffectivePermissions(userProfileId);
17369
- if (permissions.isAdmin) {
17370
- return { canRead: true, canCreate: true, canUpdate: true, canDelete: true };
17371
- }
17372
17461
  const wildcardPerms = _nullishCoalesce(permissions.objectPermissions["*"], () => ( []));
17373
17462
  const objectPerms = _nullishCoalesce(permissions.objectPermissions[objectName], () => ( []));
17374
17463
  const allPerms = /* @__PURE__ */ new Set([...wildcardPerms, ...objectPerms]);
@@ -17392,15 +17481,12 @@ var PermissionService = class extends BaseService {
17392
17481
  */
17393
17482
  async canAccessSystem(userProfileId, resource, action) {
17394
17483
  const permissions = await this.getEffectivePermissions(userProfileId);
17395
- if (permissions.isAdmin) {
17484
+ const wildcardPerms = _optionalChain([permissions, 'access', _428 => _428.systemPermissions, 'optionalAccess', _429 => _429["*"]]);
17485
+ if (_optionalChain([wildcardPerms, 'optionalAccess', _430 => _430.includes, 'call', _431 => _431(action)])) {
17396
17486
  return true;
17397
17487
  }
17398
- const wildcardPerms = _optionalChain([permissions, 'access', _422 => _422.systemPermissions, 'optionalAccess', _423 => _423["*"]]);
17399
- if (_optionalChain([wildcardPerms, 'optionalAccess', _424 => _424.includes, 'call', _425 => _425(action)])) {
17400
- return true;
17401
- }
17402
- const resourcePerms = _optionalChain([permissions, 'access', _426 => _426.systemPermissions, 'optionalAccess', _427 => _427[resource]]);
17403
- return _nullishCoalesce(_optionalChain([resourcePerms, 'optionalAccess', _428 => _428.includes, 'call', _429 => _429(action)]), () => ( false));
17488
+ const resourcePerms = _optionalChain([permissions, 'access', _432 => _432.systemPermissions, 'optionalAccess', _433 => _433[resource]]);
17489
+ return _nullishCoalesce(_optionalChain([resourcePerms, 'optionalAccess', _434 => _434.includes, 'call', _435 => _435(action)]), () => ( false));
17404
17490
  }
17405
17491
  /**
17406
17492
  * Check if user can access a system resource, throw ForbiddenError if not.
@@ -17426,11 +17512,8 @@ var PermissionService = class extends BaseService {
17426
17512
  */
17427
17513
  async getSystemPermissions(userProfileId, resource) {
17428
17514
  const permissions = await this.getEffectivePermissions(userProfileId);
17429
- if (permissions.isAdmin) {
17430
- return { canRead: true, canCreate: true, canUpdate: true, canDelete: true };
17431
- }
17432
- const wildcardPerms = _nullishCoalesce(_optionalChain([permissions, 'access', _430 => _430.systemPermissions, 'optionalAccess', _431 => _431["*"]]), () => ( []));
17433
- const resourcePerms = _nullishCoalesce(_optionalChain([permissions, 'access', _432 => _432.systemPermissions, 'optionalAccess', _433 => _433[resource]]), () => ( []));
17515
+ const wildcardPerms = _nullishCoalesce(_optionalChain([permissions, 'access', _436 => _436.systemPermissions, 'optionalAccess', _437 => _437["*"]]), () => ( []));
17516
+ const resourcePerms = _nullishCoalesce(_optionalChain([permissions, 'access', _438 => _438.systemPermissions, 'optionalAccess', _439 => _439[resource]]), () => ( []));
17434
17517
  const allPerms = /* @__PURE__ */ new Set([...wildcardPerms, ...resourcePerms]);
17435
17518
  return {
17436
17519
  canRead: allPerms.has("read"),
@@ -17573,7 +17656,7 @@ var PermissionService = class extends BaseService {
17573
17656
  action: "role.updated",
17574
17657
  actorId: this.userId,
17575
17658
  roleId,
17576
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _434 => _434.label]), () => ( roleId)),
17659
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _440 => _440.label]), () => ( roleId)),
17577
17660
  metadata: { permissionsUpdated: true, permissionCount: permissions.length }
17578
17661
  });
17579
17662
  }
@@ -17603,7 +17686,7 @@ var PermissionService = class extends BaseService {
17603
17686
  action: "role.assigned",
17604
17687
  actorId: this.userId,
17605
17688
  roleId,
17606
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _435 => _435.label]), () => ( roleId)),
17689
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _441 => _441.label]), () => ( roleId)),
17607
17690
  targetUserId: userProfileId
17608
17691
  });
17609
17692
  }
@@ -17621,7 +17704,7 @@ var PermissionService = class extends BaseService {
17621
17704
  action: "role.revoked",
17622
17705
  actorId: this.userId,
17623
17706
  roleId,
17624
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _436 => _436.label]), () => ( roleId)),
17707
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _442 => _442.label]), () => ( roleId)),
17625
17708
  targetUserId: userProfileId
17626
17709
  });
17627
17710
  }
@@ -17633,9 +17716,8 @@ var PermissionService = class extends BaseService {
17633
17716
  * Initialize default roles for the tenant if they don't exist.
17634
17717
  *
17635
17718
  * Creates the following roles with their default permissions:
17636
- * - **admin**: Full access to all system resources and objects
17637
- * - **member**: No system access, can read/create/update objects (no delete)
17638
- * - **guest**: No system access, read-only access to objects
17719
+ * - **owner**: Full access to all system resources and objects
17720
+ * - **member**: Full CRUD on business data, read-only on system resources (people, workspace)
17639
17721
  *
17640
17722
  * This method is idempotent - it only creates roles that don't already exist.
17641
17723
  * Should be called during tenant bootstrap or on first admin login.
@@ -17652,7 +17734,7 @@ var PermissionService = class extends BaseService {
17652
17734
  DEFAULT_ROLE_LABELS,
17653
17735
  DEFAULT_ROLE_DESCRIPTIONS,
17654
17736
  DEFAULT_ROLE_PERMISSIONS
17655
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./default-roles-76HUWY6T.js")));
17737
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require("./default-roles-5K3GHJTS.js")));
17656
17738
  const existingRoles = await this.getRoles();
17657
17739
  const existingRoleNames = existingRoles.reduce((set, r) => set.add(r.name), /* @__PURE__ */ new Set());
17658
17740
  for (const roleName of Object.values(DEFAULT_ROLES)) {
@@ -18096,7 +18178,7 @@ var ViewService = class extends BaseService {
18096
18178
  dbView.objectName,
18097
18179
  dbView.type,
18098
18180
  objectDefinition,
18099
- dbView.type === "detail" ? _nullishCoalesce(_optionalChain([dbView, 'access', _437 => _437.config, 'optionalAccess', _438 => _438.layout]), () => ( "page")) : void 0
18181
+ dbView.type === "detail" ? _nullishCoalesce(_optionalChain([dbView, 'access', _443 => _443.config, 'optionalAccess', _444 => _444.layout]), () => ( "page")) : void 0
18100
18182
  );
18101
18183
  const newConfig = generated.config;
18102
18184
  const updated = await this.adapter.views.update(viewId, { config: newConfig });
@@ -18591,9 +18673,7 @@ async function cleanupOrphanObjects(adapter, nativeObjects, result, options) {
18591
18673
  const registryNames = nativeObjects.map((obj) => obj.name);
18592
18674
  if (options.dryRun) {
18593
18675
  const allObjects = await adapter.objects.list();
18594
- const orphans = allObjects.filter(
18595
- (obj) => obj.system && !registryNames.includes(obj.name)
18596
- );
18676
+ const orphans = allObjects.filter((obj) => obj.system && !registryNames.includes(obj.name));
18597
18677
  result.objectsDeleted += orphans.length;
18598
18678
  if (options.verbose && orphans.length > 0) {
18599
18679
  console.info(