@data-fair/lib-vue 1.18.2 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/format/bytes.js CHANGED
@@ -8,7 +8,11 @@ export function formatBytes (bytes, locale = 'fr') {
8
8
  for (let i = 0; i < def.length; i++) {
9
9
  const step = def[i][0]
10
10
  if (bytesInt < step || i === def.length - 1) {
11
- return (bytesInt / (def[i - 1][0] || 1)).toLocaleString(locale, { maximumFractionDigits: 0 }) + ' ' + def[i - 1][1]
11
+ const value = bytesInt / (def[i - 1][0] || 1)
12
+ let digits = 2
13
+ if (value > 1) { digits = 1 }
14
+ if (value > 10) { digits = 0 }
15
+ return value.toLocaleString(locale, { maximumFractionDigits: digits }) + ' ' + def[i - 1][1]
12
16
  }
13
17
  }
14
18
  return '' // this is only for strict typing, but the code cannot go there, the return in the loop is always called
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-vue",
3
- "version": "1.18.2",
3
+ "version": "1.20.0",
4
4
  "description": "Composables and other utilities for Vue applications in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -28,7 +28,7 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@data-fair/lib-common-types": "^1.5.3",
31
+ "@data-fair/lib-common-types": "^1.7.1",
32
32
  "@data-fair/lib-utils": "^1.0.0",
33
33
  "jwt-decode": "^4.0.0",
34
34
  "universal-cookie": "^7.2.0"
package/session.d.ts CHANGED
@@ -68,6 +68,7 @@ export interface Session {
68
68
  organization: ComputedRef<SessionState['organization']>;
69
69
  account: ComputedRef<SessionState['account']>;
70
70
  accountRole: ComputedRef<SessionState['accountRole']>;
71
+ siteRole: ComputedRef<SessionState['siteRole']>;
71
72
  lang: ComputedRef<SessionState['lang']>;
72
73
  theme: Ref<null | Theme>;
73
74
  site: Ref<SiteInfo | null>;
@@ -101,6 +102,7 @@ export declare function createSession(initOptions: Partial<SessionOptions>): Pro
101
102
  organization: ComputedRef<SessionState["organization"]>;
102
103
  account: ComputedRef<SessionState["account"]>;
103
104
  accountRole: ComputedRef<SessionState["accountRole"]>;
105
+ siteRole: ComputedRef<SessionState["siteRole"]>;
104
106
  lang: ComputedRef<SessionState["lang"]>;
105
107
  theme: Ref<null | Theme>;
106
108
  site: Ref<SiteInfo | null>;
package/session.js CHANGED
@@ -121,6 +121,14 @@ export async function getSession (initOptions) {
121
121
  }
122
122
  state.accountRole = 'admin'
123
123
  }
124
+ if (state.user?.siteOwner) {
125
+ if (state.user.siteOwner.type === 'user' && state.user.siteOwner.id === state.user.id) {
126
+ state.siteRole = 'admin'
127
+ }
128
+ if (state.user.siteOwner.type === 'organization' && state.user.siteOwner.id === state.organization?.id) {
129
+ state.siteRole = state.organization.role
130
+ }
131
+ }
124
132
  }
125
133
  readState()
126
134
  debug('initial state', state)
@@ -283,6 +291,7 @@ export async function getSession (initOptions) {
283
291
  user: computed(() => state.user),
284
292
  account: computed(() => state.account),
285
293
  accountRole: computed(() => state.accountRole),
294
+ siteRole: computed(() => state.siteRole),
286
295
  lang: computed(() => state.lang),
287
296
  theme: readonly(theme),
288
297
  site: shallowReadonly(site),