{"version":3,"file":"index.cjs","sources":["../src/auth.ts","../src/cache.ts","../src/common.ts","../src/messages.ts","../src/orgs.ts","../src/user.ts","../src/stores.ts"],"sourcesContent":["import { HttpResponse } from \"@metablock/core\";\nimport { action, makeObservable, observable } from \"mobx\";\nimport CommonStore from \"./common\";\nimport UserStore from \"./user\";\n\nclass AuthStore {\n  commonStore: CommonStore;\n  userStore: UserStore;\n  inProgress = false;\n  errors?: HttpResponse = undefined;\n\n  constructor(commonStore: CommonStore, userStore: UserStore) {\n    makeObservable(this, {\n      inProgress: observable,\n      errors: observable,\n      login: action,\n      setJwt: action,\n      logout: action,\n    });\n    this.commonStore = commonStore;\n    this.userStore = userStore;\n  }\n\n  get cli() {\n    return this.commonStore.cli;\n  }\n\n  async login(data: Record<string, string>): Promise<void> {\n    this.inProgress = true;\n    this.errors = undefined;\n    try {\n      const jwt = await this.cli.auth.login(data);\n      this.commonStore.setToken(jwt);\n      await this.userStore.getUser();\n    } catch (errors: any) {\n      this.errors = errors;\n    } finally {\n      this.inProgress = false;\n    }\n  }\n\n  async setJwt(jwt: string) {\n    this.inProgress = true;\n    this.errors = undefined;\n    try {\n      this.commonStore.setToken(jwt);\n      await this.userStore.getUser();\n    } catch (errors: any) {\n      this.errors = errors;\n    } finally {\n      this.inProgress = false;\n    }\n  }\n\n  async logout() {\n    await this.cli.user.logout();\n    this.userStore.forgetUser();\n    this.commonStore.setToken(\"\");\n  }\n}\n\nexport default AuthStore;\n","import { HttpClient } from \"@metablock/core\";\nimport { action, makeObservable } from \"mobx\";\n\nexport interface Common {\n  token: string;\n  appLoaded: boolean;\n  setToken: (token: string) => void;\n  setAppLoaded: () => void;\n}\n\nclass CacheStore {\n  http = new HttpClient(\"metablock-cache-store\");\n  cache: Map<string, any>;\n\n  constructor() {\n    makeObservable(this, {\n      get: action,\n    });\n    this.cache = new Map<string, any>();\n  }\n\n  async get(url: string) {\n    const data = this.cache.get(url);\n    if (data) return data;\n    const response = await this.http.get(url);\n    const newData = response.data;\n    this.cache.set(url, newData);\n    return newData;\n  }\n}\n\nexport default CacheStore;\n","import { Metablock } from \"@metablock/core\";\nimport { action, makeObservable, observable } from \"mobx\";\n\nexport interface Common {\n  token: string;\n  appLoaded: boolean;\n  setToken: (token: string) => void;\n  setAppLoaded: () => void;\n}\n\nconst tokenKey = \"metablock-key\";\n\nclass CommonStore {\n  cli: Metablock;\n  appLoaded = false;\n\n  constructor(cli: Metablock) {\n    makeObservable(this, {\n      appLoaded: observable,\n      setToken: action,\n      setAppLoaded: action,\n    });\n    this.cli = cli;\n    this.cli.jwt = window.localStorage.getItem(tokenKey) || \"\";\n  }\n\n  get token() {\n    return this.cli.jwt;\n  }\n\n  setToken(token: string) {\n    this.cli.jwt = token;\n    if (token) {\n      window.localStorage.setItem(tokenKey, token);\n    } else {\n      window.localStorage.removeItem(tokenKey);\n    }\n  }\n\n  setAppLoaded() {\n    this.appLoaded = true;\n  }\n}\n\nexport default CommonStore;\n","import { action, makeObservable, observable } from \"mobx\";\n\nconst defaultDuration = 6000;\n\nexport class Message {\n  level: string;\n  text: string;\n  duration: number;\n\n  constructor(level: string, text: string, duration: number) {\n    this.level = level;\n    this.text = text;\n    this.duration = duration;\n  }\n}\n\nclass MessageStore {\n  message?: Message = undefined;\n\n  constructor() {\n    makeObservable(this, {\n      message: observable,\n      success: action,\n      info: action,\n      error: action,\n      clear: action,\n    });\n  }\n\n  success(text: string, duration = defaultDuration) {\n    this.message = new Message(\"success\", text, duration);\n  }\n\n  info(text: string, duration = defaultDuration) {\n    this.message = new Message(\"info\", text, duration);\n  }\n\n  error(text: string, duration = defaultDuration) {\n    this.message = new Message(\"error\", text, duration);\n  }\n\n  clear() {\n    this.message = undefined;\n  }\n}\n\nexport default MessageStore;\n","import { HttpResponse, Org, UserOrg } from \"@metablock/core\";\nimport { action, makeObservable, observable } from \"mobx\";\nimport CommonStore from \"./common\";\nimport UserStore from \"./user\";\n\nclass UserOrgStore {\n  userStore: UserStore;\n  orgs?: UserOrg[] = undefined;\n  currentOrg?: Org = undefined;\n  errors?: HttpResponse = undefined;\n\n  constructor(userStore: UserStore) {\n    makeObservable(this, {\n      orgs: observable,\n      currentOrg: observable,\n      getOrgs: action,\n      getOrg: action,\n      updateOrg: action,\n      forgetOrg: action,\n      forgetOrgs: action,\n    });\n    this.userStore = userStore;\n  }\n\n  get commonStore(): CommonStore {\n    return this.userStore.commonStore;\n  }\n\n  get cli() {\n    return this.commonStore.cli;\n  }\n\n  async getOrgs() {\n    const loader = this.cli.user.orgsLoader();\n    await loader.loadData();\n    this.orgs = loader.data;\n    return this.orgs;\n  }\n\n  async getOrg(org_name_or_id: string) {\n    this.currentOrg = await this.cli.orgs.get(org_name_or_id);\n    return this.currentOrg;\n  }\n\n  async updateOrg(org_name_or_id: string, body: Record<string, any>) {\n    this.currentOrg = await this.cli.orgs.update(org_name_or_id, body);\n  }\n\n  forgetOrg() {\n    this.currentOrg = undefined;\n  }\n\n  forgetOrgs() {\n    this.currentOrg = undefined;\n    this.orgs = undefined;\n  }\n}\n\nexport default UserOrgStore;\n","import { HttpResponse, User } from \"@metablock/core\";\nimport { action, makeObservable, observable } from \"mobx\";\nimport CommonStore from \"./common\";\n\nclass UserStore {\n  commonStore: CommonStore;\n  current?: User = undefined;\n  errors?: HttpResponse = undefined;\n\n  constructor(commonStore: CommonStore) {\n    makeObservable(this, {\n      current: observable,\n      errors: observable,\n      getUser: action,\n      updateUser: action,\n      forgetUser: action,\n    });\n    this.commonStore = commonStore;\n  }\n\n  get cli() {\n    return this.commonStore.cli;\n  }\n\n  async getUser() {\n    this.errors = undefined;\n    try {\n      this.current = await this.cli.user.getUser();\n    } catch (errors: any) {\n      this.errors = errors;\n    }\n  }\n\n  async updateUser(body: any) {\n    this.errors = undefined;\n    try {\n      this.current = await this.cli.user.update(body);\n    } catch (errors: any) {\n      this.errors = errors;\n    }\n  }\n\n  forgetUser() {\n    this.current = undefined;\n  }\n}\n\nexport default UserStore;\n","import { Metablock } from \"@metablock/core\";\nimport AuthStore from \"./auth\";\nimport CacheStore from \"./cache\";\nimport CommonStore from \"./common\";\nimport MessageStore from \"./messages\";\nimport UserStore from \"./user\";\n\nexport interface MetablockStore {\n  metablock: Metablock;\n  cacheStore: CacheStore;\n  commonStore: CommonStore;\n  userStore: UserStore;\n  authStore: AuthStore;\n  messageStore: MessageStore;\n}\n\nexport const createStores = (\n  baseUrl: string,\n  name?: string\n): MetablockStore => {\n  const metablock = new Metablock({ baseUrl, name });\n  const cacheStore = new CacheStore();\n  const commonStore = new CommonStore(metablock);\n  const messageStore = new MessageStore();\n  const userStore = new UserStore(commonStore);\n  const authStore = new AuthStore(commonStore, userStore);\n  return {\n    metablock,\n    cacheStore,\n    commonStore,\n    userStore,\n    authStore,\n    messageStore,\n  };\n};\n"],"names":["makeObservable","observable","action","HttpClient","Metablock"],"mappings":";;;;;;;AAKA,MAAM,SAAS,CAAA;AACb,IAAA,WAAW,CAAc;AACzB,IAAA,SAAS,CAAY;IACrB,UAAU,GAAG,KAAK,CAAC;IACnB,MAAM,GAAkB,SAAS,CAAC;IAElC,WAAY,CAAA,WAAwB,EAAE,SAAoB,EAAA;QACxDA,mBAAc,CAAC,IAAI,EAAE;AACnB,YAAA,UAAU,EAAEC,eAAU;AACtB,YAAA,MAAM,EAAEA,eAAU;AAClB,YAAA,KAAK,EAAEC,WAAM;AACb,YAAA,MAAM,EAAEA,WAAM;AACd,YAAA,MAAM,EAAEA,WAAM;AACf,SAAA,CAAC,CAAC;AACH,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;KAC5B;AAED,IAAA,IAAI,GAAG,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;KAC7B;IAED,MAAM,KAAK,CAAC,IAA4B,EAAA;AACtC,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;AACvB,QAAA,IAAI,CAAC,MAAM,GAAG,SAAS,CA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