@ossy/workspaces 1.17.2 → 3.0.1

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.
Files changed (67) hide show
  1. package/README.md +4 -0
  2. package/package.json +8 -4
  3. package/src/AuthenticationGuard.jsx +3 -3
  4. package/src/CreateWorkspacePage.jsx +7 -16
  5. package/src/Definition.js +2 -1
  6. package/src/GeneralSettings.jsx +77 -19
  7. package/src/Invitations.jsx +7 -7
  8. package/src/Invitations.page.jsx +1 -1
  9. package/src/Invite.jsx +13 -25
  10. package/src/Invite.page.jsx +1 -1
  11. package/src/SchemasReadBootstrap.jsx +20 -0
  12. package/src/SelectWorkspacePage.jsx +8 -11
  13. package/src/Users.jsx +7 -7
  14. package/src/Users.page.jsx +3 -3
  15. package/src/WorkspaceSettings.page.jsx +1 -1
  16. package/src/accept-invitation.action.js +1 -1
  17. package/src/accept-invitation.api.js +46 -0
  18. package/src/accept-invitation.task.js +6 -5
  19. package/src/create-api-token.action.js +1 -1
  20. package/src/create-api-token.task.js +1 -1
  21. package/src/create.action.js +1 -1
  22. package/src/create.task.js +1 -1
  23. package/src/disable-service.action.js +1 -1
  24. package/src/disable-service.task.js +3 -15
  25. package/src/en.translations.json +36 -30
  26. package/src/enable-service.action.js +1 -1
  27. package/src/enable-service.task.js +3 -15
  28. package/src/entitlements.js +199 -0
  29. package/src/entitlements.spec.js +88 -0
  30. package/src/get-api-tokens.action.js +1 -1
  31. package/src/get-api-tokens.task.js +1 -1
  32. package/src/get-invitations.action.js +1 -1
  33. package/src/get-invitations.task.js +1 -1
  34. package/src/get-schemas.action.js +1 -0
  35. package/src/get-schemas.task.js +14 -0
  36. package/src/get-users.action.js +1 -1
  37. package/src/get-users.task.js +1 -1
  38. package/src/get.action.js +1 -1
  39. package/src/get.task.js +1 -1
  40. package/src/import-schemas.action.js +1 -0
  41. package/src/import-schemas.task.js +26 -0
  42. package/src/index.js +3 -2
  43. package/src/invite-user.action.js +1 -1
  44. package/src/invite-user.task.js +4 -3
  45. package/src/list.action.js +1 -1
  46. package/src/list.task.js +1 -1
  47. package/src/merge-workspace-schemas.js +13 -0
  48. package/src/merge-workspace-schemas.spec.js +16 -0
  49. package/src/remove-member.action.js +1 -1
  50. package/src/remove-member.task.js +1 -1
  51. package/src/schema-ids.js +3 -0
  52. package/src/select-workspace.api.js +50 -0
  53. package/src/selectWorkspace.js +11 -0
  54. package/src/service-keys.js +1 -0
  55. package/src/sv.translations.json +36 -30
  56. package/src/sync-workspace-membership.task.js +7 -6
  57. package/src/workspace-invitation.email.jsx +1 -1
  58. package/src/workspace-users.component.jsx +3 -3
  59. package/src/workspace.aggregate.js +35 -47
  60. package/src/workspace.schema.js +9 -0
  61. package/src/workspaces.events.js +61 -155
  62. package/src/{workspaces.spec.js → workspaces.integration.spec.js} +40 -38
  63. package/src/workspaces.queries.js +27 -12
  64. package/src/get-resource-templates.action.js +0 -1
  65. package/src/get-resource-templates.task.js +0 -18
  66. package/src/import-resource-templates.action.js +0 -1
  67. package/src/import-resource-templates.task.js +0 -26
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from '@jest/globals'
2
+ import { mergeWorkspaceSchemas } from './merge-workspace-schemas.js'
3
+
4
+ describe('mergeWorkspaceSchemas', () => {
5
+ it('appends workspace-only schemas', () => {
6
+ const system = [{ id: 'a', name: 'A', fields: [] }]
7
+ const workspace = [{ id: 'b', name: 'B', fields: [] }]
8
+ expect(mergeWorkspaceSchemas(system, workspace).map(s => s.id)).toEqual(['a', 'b'])
9
+ })
10
+
11
+ it('lets workspace schemas override system ids', () => {
12
+ const system = [{ id: 'a', name: 'System', fields: [] }]
13
+ const workspace = [{ id: 'a', name: 'Custom', fields: [] }]
14
+ expect(mergeWorkspaceSchemas(system, workspace)[0].name).toBe('Custom')
15
+ })
16
+ })
@@ -1 +1 @@
1
- export const metadata = { id: 'workspaces/remove-member', access: 'workspace' }
1
+ export const metadata = { id: '@ossy/workspaces/actions/remove-member', access: 'workspace' }
@@ -1,7 +1,7 @@
1
1
  import { Aggregate } from '@ossy/event-store'
2
2
  import { Workspace, WorkspacesEvents } from '@ossy/workspaces/server'
3
3
 
4
- export const metadata = { id: 'workspaces/remove-member' }
4
+ export const metadata = { id: '@ossy/workspaces/tasks/remove-member' }
5
5
 
6
6
  export async function run({ payload, req }) {
7
7
  const createdBy = payload?.userId ?? req?.userId
@@ -0,0 +1,3 @@
1
+ export const WorkspaceSchema = Object.freeze({
2
+ workspace: '@ossy/workspaces/schema/workspace',
3
+ })
@@ -0,0 +1,50 @@
1
+ import {
2
+ ActionService,
3
+ mergeUserAppSettingsCookie,
4
+ } from '@ossy/platform'
5
+
6
+ export const metadata = {
7
+ id: 'users.select-workspace',
8
+ path: '/api/v0/users/select-workspace',
9
+ method: 'GET',
10
+ query: ['workspaceId', 'redirect'],
11
+ }
12
+
13
+ export default async function handle (req, res) {
14
+ if (req.method !== 'GET') {
15
+ res.setHeader('Allow', 'GET')
16
+ res.status(405).json({ error: 'Method Not Allowed' })
17
+ return
18
+ }
19
+
20
+ if (!req.userId || req.userId === 'anonymous') {
21
+ res.status(401).json({ error: 'Unauthorized' })
22
+ return
23
+ }
24
+
25
+ const workspaceId = req.query.workspaceId
26
+ if (!workspaceId || typeof workspaceId !== 'string') {
27
+ res.status(400).json({ message: 'No workspaceId provided' })
28
+ return
29
+ }
30
+
31
+ try {
32
+ const workspaces = await ActionService.invoke('@ossy/workspaces/actions/list', { req })
33
+ if (!workspaces.some((w) => w.id === workspaceId)) {
34
+ res.status(403).json({ message: 'Forbidden' })
35
+ return
36
+ }
37
+
38
+ mergeUserAppSettingsCookie(req, res, { workspaceId })
39
+
40
+ const redirect = req.query.redirect
41
+ if (redirect && typeof redirect === 'string') {
42
+ res.redirect(302, redirect)
43
+ return
44
+ }
45
+
46
+ res.status(200).json('')
47
+ } catch (err) {
48
+ res.status(err.status || 500).json({ message: err.message || 'Internal Server Error' })
49
+ }
50
+ }
@@ -0,0 +1,11 @@
1
+ export function selectWorkspaceHref (workspaceId, redirect) {
2
+ const params = new URLSearchParams({ workspaceId: String(workspaceId) })
3
+ if (redirect != null && redirect !== '') {
4
+ params.set('redirect', String(redirect))
5
+ }
6
+ return `/api/v0/users/select-workspace?${params}`
7
+ }
8
+
9
+ export function selectWorkspace (workspaceId, redirect) {
10
+ window.location.assign(selectWorkspaceHref(workspaceId, redirect))
11
+ }
@@ -0,0 +1 @@
1
+ export { assertEnableableService } from './entitlements.js'
@@ -8,41 +8,41 @@
8
8
  "workspaces.select.title": "Mina workspaces",
9
9
  "workspaces.select.newWorkspace": "Nytt workspace",
10
10
  "workspaces.select.loading": "Laddar...",
11
- "workspaces.select.description": "Workspaces är separata miljöer där du kan hantera resurser, mallar, tjänster och fakturering.",
11
+ "workspaces.select.description": "Workspaces är separata miljöer där du kan hantera resurser, scheman, tjänster och fakturering.",
12
12
  "workspaces.select.errorTitle": "Vi kunde inte ladda dina workspaces",
13
13
  "workspaces.select.errorText": "Något gick fel när dina workspaces skulle laddas. Kanske har din session gått ut, eller så har vi klantat till det. Prova att börja om från startsidan.",
14
14
  "workspaces.select.errorAction": "Gå till startsidan",
15
15
  "workspaces.select.emptyTitle": "Nu sätter vi igång",
16
- "workspaces.select.emptyText": "För att komma igång behöver vi skapa ett workspace. Ett workspace kapslar in resurser, resursmallar, faktureringsinformation och vilka användare som har tillgång.",
16
+ "workspaces.select.emptyText": "För att komma igång behöver vi skapa ett workspace. Ett workspace kapslar in resurser, scheman, faktureringsinformation och vilka användare som har tillgång.",
17
17
  "workspaces.select.emptyAction": "Skapa ett workspace",
18
- "workspaces/create.label": "Skapa workspace",
19
- "workspaces/create.description": "Skapa ett nytt workspace för den inloggade användaren",
20
- "workspaces/accept-invitation.label": "Acceptera inbjudan",
21
- "workspaces/accept-invitation.description": "Acceptera en workspace-inbjudan",
22
- "workspaces/create-api-token.label": "Skapa workspace API-nyckel",
23
- "workspaces/create-api-token.description": "Skapa en API-nyckel kopplad till workspace",
24
- "workspaces/disable-service.label": "Inaktivera tjänst",
25
- "workspaces/disable-service.description": "Inaktivera en tjänst för workspace",
26
- "workspaces/enable-service.label": "Aktivera tjänst",
27
- "workspaces/enable-service.description": "Aktivera en tjänst för workspace",
28
- "workspaces/get-api-tokens.label": "Hämta workspace API-nycklar",
29
- "workspaces/get-api-tokens.description": "Lista API-nycklar för workspace",
30
- "workspaces/get-invitations.label": "Hämta inbjudningar",
31
- "workspaces/get-invitations.description": "Lista väntande workspace-inbjudningar",
32
- "workspaces/get-resource-templates.label": "Hämta resursmallar",
33
- "workspaces/get-resource-templates.description": "Lista resursmallar tillgängliga för workspace",
34
- "workspaces/get-users.label": "Hämta workspace-användare",
35
- "workspaces/get-users.description": "Lista medlemmar i workspace",
36
- "workspaces/get.label": "Hämta workspace",
37
- "workspaces/get.description": "Ladda ett workspace via id",
38
- "workspaces/import-resource-templates.label": "Importera resursmallar",
39
- "workspaces/import-resource-templates.description": "Importera resursmallar till workspace",
40
- "workspaces/invite-user.label": "Bjud in användare",
41
- "workspaces/invite-user.description": "Skicka en workspace-inbjudan till en användare",
42
- "workspaces/remove-member.label": "Ta bort medlem",
43
- "workspaces/remove-member.description": "Ta bort en användare från workspace",
44
- "workspaces/list.label": "Lista workspaces",
45
- "workspaces/list.description": "Lista workspaces för den inloggade användaren",
18
+ "@ossy/workspaces/actions/create.label": "Skapa workspace",
19
+ "@ossy/workspaces/actions/create.description": "Skapa ett nytt workspace för den inloggade användaren",
20
+ "@ossy/workspaces/actions/accept-invitation.label": "Acceptera inbjudan",
21
+ "@ossy/workspaces/actions/accept-invitation.description": "Acceptera en workspace-inbjudan",
22
+ "@ossy/workspaces/actions/create-api-token.label": "Skapa workspace API-nyckel",
23
+ "@ossy/workspaces/actions/create-api-token.description": "Skapa en API-nyckel kopplad till workspace",
24
+ "@ossy/workspaces/actions/disable-service.label": "Inaktivera tjänst",
25
+ "@ossy/workspaces/actions/disable-service.description": "Inaktivera en tjänst för workspace",
26
+ "@ossy/workspaces/actions/enable-service.label": "Aktivera tjänst",
27
+ "@ossy/workspaces/actions/enable-service.description": "Aktivera en tjänst för workspace",
28
+ "@ossy/workspaces/actions/get-api-tokens.label": "Hämta workspace API-nycklar",
29
+ "@ossy/workspaces/actions/get-api-tokens.description": "Lista API-nycklar för workspace",
30
+ "@ossy/workspaces/actions/get-invitations.label": "Hämta inbjudningar",
31
+ "@ossy/workspaces/actions/get-invitations.description": "Lista väntande workspace-inbjudningar",
32
+ "@ossy/workspaces/actions/get-schemas.label": "Hämta scheman",
33
+ "@ossy/workspaces/actions/get-schemas.description": "Lista scheman tillgängliga för workspace",
34
+ "@ossy/workspaces/actions/get-users.label": "Hämta workspace-användare",
35
+ "@ossy/workspaces/actions/get-users.description": "Lista medlemmar i workspace",
36
+ "@ossy/workspaces/actions/get.label": "Hämta workspace",
37
+ "@ossy/workspaces/actions/get.description": "Ladda ett workspace via id",
38
+ "@ossy/workspaces/actions/import-schemas.label": "Importera scheman",
39
+ "@ossy/workspaces/actions/import-schemas.description": "Importera scheman till workspace",
40
+ "@ossy/workspaces/actions/invite-user.label": "Bjud in användare",
41
+ "@ossy/workspaces/actions/invite-user.description": "Skicka en workspace-inbjudan till en användare",
42
+ "@ossy/workspaces/actions/remove-member.label": "Ta bort medlem",
43
+ "@ossy/workspaces/actions/remove-member.description": "Ta bort en användare från workspace",
44
+ "@ossy/workspaces/actions/list.label": "Lista workspaces",
45
+ "@ossy/workspaces/actions/list.description": "Lista workspaces för den inloggade användaren",
46
46
  "workspace/settings.documentTitle": "Workspace-inställningar",
47
47
  "workspace.settings.title": "Workspace-inställningar",
48
48
  "workspace/users.documentTitle": "Användare",
@@ -54,10 +54,16 @@
54
54
  "workspace/invitations/add.documentTitle": "Bjud in användare",
55
55
  "workspace.invitations.title": "Inbjudningar",
56
56
  "workspace.settings.detailsTitle": "Workspace-detaljer",
57
+ "workspace.settings.detailsDescription": "Hantera workspace-namn, tjänster och metadata.",
57
58
  "workspace.settings.edit": "Redigera",
58
59
  "workspace.settings.name": "Namn",
59
60
  "workspace.settings.created": "Skapad",
60
61
  "workspace.settings.services": "Tjänster",
62
+ "workspace.settings.service.booking": "Bokning",
63
+ "workspace.settings.service.on": "på",
64
+ "workspace.settings.service.off": "av",
65
+ "workspace.settings.service.enable": "Aktivera",
66
+ "workspace.settings.service.disable": "Inaktivera",
61
67
  "workspace.settings.loading": "Laddar...",
62
68
  "workspace.invitations.description": "Bjud in användare till ditt workspace för att samarbeta.",
63
69
  "workspace.invitations.invite": "Bjud in användare",
@@ -1,20 +1,21 @@
1
1
  import { Aggregate } from '@ossy/event-store'
2
2
  import { User, UsersEvents } from '@ossy/users/server'
3
3
  import { JoinWorkspace, LeaveWorkspace } from '@ossy/users'
4
+ import { WorkspaceSchema } from './schema-ids.js'
4
5
 
5
6
  export const metadata = {
6
- id: 'sync-workspace-membership',
7
+ id: '@ossy/workspaces/tasks/sync-workspace-membership',
7
8
  triggers: [
8
- { aggregateType: 'Workspace', event: 'Created' },
9
- { aggregateType: 'Workspace', event: 'UserInvitationAccepted' },
10
- { aggregateType: 'Workspace', event: 'UserRemoved' },
9
+ { type: WorkspaceSchema.workspace, event: 'Created' },
10
+ { type: WorkspaceSchema.workspace, event: 'UserInvitationAccepted' },
11
+ { type: WorkspaceSchema.workspace, event: 'UserRemoved' },
11
12
  ],
12
13
  }
13
14
 
14
15
  export async function run ({ event, sdk }) {
15
- const workspaceId = event.aggregateId
16
+ const workspaceId = event.resourceId
16
17
 
17
- if (event.type === 'UserRemoved') {
18
+ if (event.event === 'UserRemoved') {
18
19
  const userId = event.payload.userId
19
20
 
20
21
  if (sdk) {
@@ -1,6 +1,6 @@
1
1
  import { EmailLayout, EmailButton, EmailText } from '@ossy/email'
2
2
 
3
- export const id = 'workspaces/invitation'
3
+ export const id = '@ossy/workspaces/emails/invitation'
4
4
  export const subject = 'You have been invited'
5
5
 
6
6
  export default function WorkspaceInvitationEmail({ workspace, invitedBy, verificationToken, baseUrl = 'https://app.ossy.se', theme }) {
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { View } from '@ossy/design-system'
2
+ import { Page } from '@ossy/design-system'
3
3
  import { Users } from './Users.jsx'
4
4
 
5
5
  export const metadata = {
@@ -7,9 +7,9 @@ export const metadata = {
7
7
  }
8
8
 
9
9
  export const WorkspaceUsersContent = () => (
10
- <View gap="m" surface="primary" style={{ padding: 'var(--space-m) var(--space-l)', height: '100%', overflowY: 'auto' }}>
10
+ <Page>
11
11
  <Users />
12
- </View>
12
+ </Page>
13
13
  )
14
14
 
15
15
  export default WorkspaceUsersContent
@@ -1,50 +1,42 @@
1
+ import { normalizeWorkspaceServices } from './entitlements.js'
2
+ import { WorkspaceSchema } from './schema-ids.js'
3
+
1
4
  export class Workspace {
2
5
 
6
+ static kind = 'entity'
7
+ static SchemaId = WorkspaceSchema.workspace
3
8
  static AggregateType = 'Workspace'
4
9
 
5
- static View(events, state = {}) {
6
- return events
7
- .reduce((workspace, event) => {
8
-
9
- switch (event.type) {
10
+ static View (events, state = {}) {
11
+ const folded = events.reduce((workspace, event) => {
12
+ switch (event.event) {
10
13
 
11
14
  case 'Created':
12
15
  return {
13
16
  ...workspace,
14
- id: event.aggregateId,
17
+ id: event.resourceId,
18
+ type: event.type,
15
19
  name: event.payload.name,
16
20
  createdBy: event.createdBy,
17
21
  created: event.created,
18
22
  apiTokens: [],
19
23
  users: [event.createdBy],
20
24
  invitations: [],
21
- resourceTemplates: [],
22
- services: {
23
- // '@ossy/visual-content-classifiers': true,
24
- '@ossy/tasks/resize-common-web': true,
25
- '@ossy/apps': true,
26
- '@ossy/domains': true,
27
- }
25
+ schemas: [],
26
+ services: {},
28
27
  }
29
28
 
30
- case 'ResourceTemplatesImported':
29
+ case 'SchemasImported':
31
30
  return {
32
31
  ...workspace,
33
- resourceTemplates: [
34
- ...(event.payload.templates || []),
35
- ]
32
+ schemas: [...(event.payload.schemas || [])],
36
33
  }
37
34
 
38
35
  case 'UserInvited': {
39
36
  const oneWeek = 1000 * 60 * 60 * 24 * 7
40
37
  const expired = event.payload.expiresAt < Date.now()
41
- // show expired workspace invitations for 7 days
42
38
  const showInvitation = (event.payload.expiresAt + oneWeek) > Date.now()
43
-
44
- if (!showInvitation) {
45
- return workspace
46
- }
47
-
39
+ if (!showInvitation) return workspace
48
40
  return {
49
41
  ...workspace,
50
42
  invitations: [
@@ -53,42 +45,35 @@ export class Workspace {
53
45
  email: event.payload.email,
54
46
  invitedAt: event.created,
55
47
  expiresAt: event.payload.expiresAt,
56
- expired: expired
57
- }
58
- ]
48
+ expired,
49
+ },
50
+ ],
59
51
  }
60
52
  }
61
53
 
62
- case 'UserInvitationAccepted': {
54
+ case 'UserInvitationAccepted':
63
55
  return {
64
56
  ...workspace,
65
- users: [
66
- ...workspace.users,
67
- event.createdBy
68
- ],
69
- invitations: workspace.invitations.filter(invitation => invitation.email !== event.payload.email)
57
+ users: [...workspace.users, event.createdBy],
58
+ invitations: workspace.invitations.filter(invitation => invitation.email !== event.payload.email),
70
59
  }
71
- }
72
60
 
73
61
  case 'ApiTokenCreated':
74
62
  return {
75
63
  ...workspace,
76
64
  apiTokens: [
77
- ...(apiTokens || []),
78
- {
79
- id: event.id,
80
- description: event.payload.description
81
- }
82
- ]
65
+ ...(workspace.apiTokens || []),
66
+ { id: event.id, description: event.payload.description },
67
+ ],
83
68
  }
84
-
69
+
85
70
  case 'ServiceEnabled':
86
71
  return {
87
72
  ...workspace,
88
73
  services: {
89
74
  ...(workspace.services || {}),
90
- [event.payload.service]: true
91
- }
75
+ [event.payload.service]: { enabled: true },
76
+ },
92
77
  }
93
78
 
94
79
  case 'ServiceDisabled':
@@ -96,23 +81,26 @@ export class Workspace {
96
81
  ...workspace,
97
82
  services: {
98
83
  ...(workspace.services || {}),
99
- [event.payload.service]: false
100
- }
84
+ [event.payload.service]: { enabled: false },
85
+ },
101
86
  }
102
87
 
103
88
  case 'UserRemoved':
104
89
  return {
105
90
  ...workspace,
106
- users: (workspace.users || []).filter(id => id !== event.payload.userId)
91
+ users: (workspace.users || []).filter(id => id !== event.payload.userId),
107
92
  }
108
93
 
109
94
  default:
110
95
  return workspace
111
-
112
96
  }
113
97
  }, state)
114
- }
115
98
 
99
+ return {
100
+ ...folded,
101
+ services: normalizeWorkspaceServices(folded.services),
102
+ }
103
+ }
116
104
  }
117
105
 
118
106
  export { Workspace as Aggregate }
@@ -0,0 +1,9 @@
1
+ export default {
2
+ id: '@ossy/workspaces/schema/workspace',
3
+ name: 'Workspace',
4
+ categoryName: 'Workspaces',
5
+ icon: 'building',
6
+ fields: [
7
+ { name: 'name', type: 'text' },
8
+ ],
9
+ }
@@ -1,171 +1,77 @@
1
- /**
2
- * Field
3
- * @typedef {Object} Field
4
- * @property {string} type - field type
5
- * @property {string} name - name of field
6
- */
7
-
8
- /**
9
- * ResourceTemplate
10
- * @typedef {Object} ResourceTemplate
11
- * @property {string} name - Displayname of the resource template
12
- * @property {Field[]} fields - Allowed fields
13
- */
14
-
1
+ import { nanoid } from 'nanoid'
2
+ import { WorkspaceSchema } from './schema-ids.js'
15
3
 
16
4
  /**
17
- * @class
18
- */
5
+ * ADR 0008 workspace entity events.
6
+ */
19
7
  export class WorkspacesEvents {
20
8
 
21
- /**
22
- * Return type of WorkspacesEvents.Created
23
- * @typedef {Object} Created
24
- * @property {string} type - Created
25
- * @property {string} createdBy - userId of user who created the workspace
26
- * @property {CreatedPayload} payload - event payload
27
- */
9
+ static Created ({ resourceId, createdBy, name }) {
10
+ return {
11
+ type: WorkspaceSchema.workspace,
12
+ resourceId: resourceId ?? nanoid(),
13
+ event: 'Created',
14
+ createdBy,
15
+ payload: { name },
16
+ }
17
+ }
28
18
 
29
- /**
30
- * Payload of Workspace.Created event
31
- * @typedef {Object} CreatedPayload
32
- * @property {string} name - Name of workspace
33
- */
19
+ static SchemasImported ({ createdBy, schemas }) {
20
+ return {
21
+ event: 'SchemasImported',
22
+ createdBy,
23
+ payload: { schemas },
24
+ }
25
+ }
34
26
 
35
- /**
36
- * Input for WorkspacesEvents.Created
37
- * @typedef {Object} CreatedInput
38
- * @property {string} name - Name of workspace
39
- * @property {string} createdBy - userId of user who created the workspace
40
- */
27
+ static ApiTokenCreated ({ createdBy, description, token }) {
28
+ return {
29
+ event: 'ApiTokenCreated',
30
+ createdBy,
31
+ payload: { description, token },
32
+ }
33
+ }
41
34
 
42
- /**
43
- * Use this to indicate that a new workspace have been created
44
- *
45
- * @param {CreatedInput} input
46
- * @return {Created} - Workspace created event
47
- *
48
- * @example
49
- * const name = 'ossy.se'
50
- * const createdBy = 'fake-user-id-123'
51
- *
52
- * const event = WorkspacesEvents.Created({ name, createdBy })
53
- *
54
- * Aggregate.Of(Workspace, event)
55
- */
56
- static Created({ createdBy, name }) {
57
- return ({
58
- type: 'Created',
59
- createdBy: createdBy,
35
+ static UserInvited ({ createdBy, email, expiresAt }) {
36
+ return {
37
+ event: 'UserInvited',
38
+ createdBy,
60
39
  payload: {
61
- name: name
62
- }
63
- })
64
- }
65
-
66
- /**
67
- * Return type of WorkspacesEvents.ResourceTemplatesImported
68
- * @typedef {Object} ResourceTemplatesImported
69
- * @property {string} type - ResourceTemplatesImported
70
- * @property {string} createdBy - userId of user who created the workspace
71
- * @property {ResourceTemplate[]} payload - event payload
72
- */
73
-
74
- /**
75
- * Input for WorkspacesEvents.Created
76
- * @typedef {Object} ResourceTemplatesImportedInput
77
- * @property {ResourceTemplate[]} templates - List of resource templates
78
- * @property {string} createdBy - userId of user who created the workspace
79
- */
80
-
81
- /**
82
- * Use this to save imported resource templates
83
- *
84
- * @param {ResourceTemplatesImportedInput} input
85
- * @return {ResourceTemplatesImported} - Resource templates imported event
86
- *
87
- * @example
88
- * const templates = []
89
- * const createdBy = 'fake-user-123'
90
- *
91
- * const event = WorkspacesEvents.Created({ templates, createdBy })
92
- *
93
- * Aggregate.Of(Workspace, userId)
94
- * .then(Aggregate.Add(event))
95
- */
96
- static ResourceTemplatesImported({ createdBy, templates }) {
97
- return ({
98
- type: 'ResourceTemplatesImported',
99
- createdBy: createdBy,
100
- payload: {
101
- templates: templates
102
- }
103
- })
104
- }
105
-
106
- // Not in use atm, use API TOKENS in the user aggregate instead.
107
- // Caller is responsible for generating the token value.
108
- static ApiTokenCreated({ createdBy, description, token }) {
109
- return ({
110
- type: 'ApiTokenCreated',
111
- createdBy: createdBy,
112
- payload: {
113
- description: description,
114
- token: token
115
- }
116
- })
117
- }
118
-
119
-
120
- static UserInvited({ createdBy, email, expiresAt }) {
121
- return ({
122
- type: 'UserInvited',
123
- createdBy: createdBy,
124
- payload: {
125
- email: email,
126
- expiresAt: new Date().getTime() + 1000 * 60 * 60 * 24 * 7, // One week
127
- }
128
- })
129
- }
40
+ email,
41
+ expiresAt: expiresAt ?? Date.now() + 1000 * 60 * 60 * 24 * 7,
42
+ },
43
+ }
44
+ }
130
45
 
131
- static UserInvitationAccepted({ createdBy, email }) {
132
- return ({
133
- type: 'UserInvitationAccepted',
134
- createdBy: createdBy,
135
- payload: {
136
- email: email
137
- }
138
- })
139
- }
140
-
141
- static ServiceEnabled({ createdBy, service }) {
142
- return ({
143
- type: 'ServiceEnabled',
144
- createdBy: createdBy,
145
- payload: {
146
- service: service
147
- }
148
- })
46
+ static UserInvitationAccepted ({ createdBy, email }) {
47
+ return {
48
+ event: 'UserInvitationAccepted',
49
+ createdBy,
50
+ payload: { email },
51
+ }
149
52
  }
150
53
 
151
- static ServiceDisabled({ createdBy, service }) {
152
- return ({
153
- type: 'ServiceDisabled',
154
- createdBy: createdBy,
155
- payload: {
156
- service: service
157
- }
158
- })
54
+ static ServiceEnabled ({ createdBy, service }) {
55
+ return {
56
+ event: 'ServiceEnabled',
57
+ createdBy,
58
+ payload: { service },
59
+ }
159
60
  }
160
61
 
161
- static UserRemoved({ createdBy, userId }) {
162
- return ({
163
- type: 'UserRemoved',
164
- createdBy: createdBy,
165
- payload: {
166
- userId: userId
167
- }
168
- })
62
+ static ServiceDisabled ({ createdBy, service }) {
63
+ return {
64
+ event: 'ServiceDisabled',
65
+ createdBy,
66
+ payload: { service },
67
+ }
169
68
  }
170
69
 
70
+ static UserRemoved ({ createdBy, userId }) {
71
+ return {
72
+ event: 'UserRemoved',
73
+ createdBy,
74
+ payload: { userId },
75
+ }
76
+ }
171
77
  }