mnfst 0.5.18 → 0.5.20

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.
@@ -966,6 +966,45 @@ function initializeAuthMagic() {
966
966
  if (typeof value === 'function') {
967
967
  return value.bind(store);
968
968
  }
969
+ // CRITICAL: If property exists but is not a function, check if it should be a convenience method
970
+ // This handles cases where the store was recreated and methods are missing
971
+ if (typeof prop === 'string') {
972
+ const convenienceMethodNames = [
973
+ 'isCreatingTeam', 'isUpdatingTeam', 'isDeletingTeam', 'isInvitingMember',
974
+ 'isUpdatingMember', 'isDeletingMember', 'createTeamFromName', 'updateCurrentTeamName',
975
+ 'inviteToCurrentTeam', 'viewTeam', 'isCurrentTeamOwner', 'isTeamDeletable',
976
+ 'isTeamRenamable', 'hasTeamPermission', 'hasTeamPermissionSync', 'canManageRoles',
977
+ 'canInviteMembers', 'canUpdateMembers', 'canRemoveMembers', 'canRenameTeam',
978
+ 'canDeleteTeam', 'isRoleDeletable', 'isRoleBeingEdited', 'getCurrentTeamRoles',
979
+ 'getUserRole', 'getUserRoles', 'getAllAvailablePermissions'
980
+ ];
981
+
982
+ if (convenienceMethodNames.includes(prop)) {
983
+ // This should be a function but isn't - try to reinitialize synchronously
984
+ if (window.ManifestAppwriteAuthTeamsConvenience && window.ManifestAppwriteAuthTeamsConvenience.initialize) {
985
+ try {
986
+ // Call initialize which will check and re-add methods if needed
987
+ window.ManifestAppwriteAuthTeamsConvenience.initialize();
988
+ // Immediately check again - initialize should have added the method
989
+ const reinitializedValue = store[prop];
990
+ if (typeof reinitializedValue === 'function') {
991
+ return reinitializedValue.bind(store);
992
+ }
993
+ } catch (error) {
994
+ // Failed to reinitialize, continue to fallback
995
+ }
996
+ }
997
+ // Return a safe fallback function that returns false/empty
998
+ // This prevents "is not a function" errors while methods are being reinitialized
999
+ if (prop.startsWith('is') || prop.startsWith('can') || prop.startsWith('has')) {
1000
+ return () => false;
1001
+ }
1002
+ if (prop.startsWith('get')) {
1003
+ return () => null;
1004
+ }
1005
+ return () => ({ success: false, error: 'Method not initialized' });
1006
+ }
1007
+ }
969
1008
  // CRITICAL: Handle null values - return loading proxy to allow safe chaining
970
1009
  // This prevents errors when accessing $auth.user.email when user is null
971
1010
  if (value === null || value === undefined) {
@@ -4495,6 +4534,10 @@ function initializeTeamsConvenience() {
4495
4534
  const waitForStore = () => {
4496
4535
  const store = Alpine.store('auth');
4497
4536
  if (store) {
4537
+ // CRITICAL: Check if convenience methods exist - use isCreatingTeam as the key check
4538
+ // This ensures methods are re-added if the store was replaced or methods were lost after idle
4539
+ const needsReinitialization = !store.isCreatingTeam || typeof store.isCreatingTeam !== 'function';
4540
+
4498
4541
  // Ensure cache properties are initialized (methods are already in store)
4499
4542
  if (!store._permissionCache) store._permissionCache = {};
4500
4543
  if (store._userRoleCache === undefined) store._userRoleCache = null;
@@ -4576,7 +4619,7 @@ function initializeTeamsConvenience() {
4576
4619
 
4577
4620
  // CRITICAL: Check if convenience methods exist - use isCreatingTeam as the key check
4578
4621
  // This ensures methods are re-added if the store was replaced or methods were lost after idle
4579
- if (!store.isCreatingTeam || typeof store.isCreatingTeam !== 'function') {
4622
+ if (needsReinitialization) {
4580
4623
  // Convenience method: create team using newTeamName property
4581
4624
  store.createTeamFromName = async function () {
4582
4625
  // Ensure newTeamName is a string and has content
@@ -350,6 +350,19 @@ window.ManifestComponentsProcessor = {
350
350
  // magic methods are available. This prevents "i is not a function" errors.
351
351
  if (window.Alpine && typeof window.Alpine.initTree === 'function') {
352
352
  const initAlpine = () => {
353
+ // CRITICAL: Ensure auth convenience methods are initialized before Alpine evaluates expressions
354
+ // This prevents "$auth.isCreatingTeam is not a function" errors after idle/reinitialization
355
+ if (window.ManifestAppwriteAuthTeamsConvenience && window.ManifestAppwriteAuthTeamsConvenience.initialize) {
356
+ try {
357
+ const authStore = window.Alpine.store('auth');
358
+ if (authStore && (!authStore.isCreatingTeam || typeof authStore.isCreatingTeam !== 'function')) {
359
+ window.ManifestAppwriteAuthTeamsConvenience.initialize();
360
+ }
361
+ } catch (error) {
362
+ // Failed to reinitialize, continue anyway
363
+ }
364
+ }
365
+
353
366
  // Re-initialize Alpine on the swapped elements
354
367
  // This ensures magic methods are available when expressions are evaluated
355
368
  topLevelElements.forEach(el => {
@@ -703,22 +716,14 @@ function initializeComponents() {
703
716
  window.dispatchEvent(new CustomEvent('manifest:components-ready'));
704
717
  }
705
718
 
706
- // Wait for data plugin to be ready before initializing components
707
- // This ensures $x magic method is available when components are processed
719
+ // Wait for data plugin to be ready (including content pre-load) before initializing components
720
+ // manifest:data-ready fires after critical data sources are loaded, so $x.content is ready when components render
708
721
  function waitForDataThenInitialize() {
709
- // Check if data plugin is already ready
710
- if (window.__manifestDataMagicRegistered) {
711
- initializeComponents();
712
- return;
713
- }
714
-
715
- // Wait for data-ready event
716
722
  window.addEventListener('manifest:data-ready', () => {
717
723
  initializeComponents();
718
724
  }, { once: true });
719
725
 
720
726
  // Fallback: if data plugin doesn't fire event within reasonable time, initialize anyway
721
- // This handles cases where data plugin isn't loaded or doesn't use magic methods
722
727
  setTimeout(() => {
723
728
  if (!window.__manifestComponentsInitialized) {
724
729
  initializeComponents();