@ossy/integrations 0.0.0-stage → 3.27.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/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@ossy/integrations",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Add and manage workspace integrations",
4
+ "version": "3.27.0",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js"
10
+ },
11
+ "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
12
+ "license": "MIT",
13
+ "ossy": {
14
+ "src": "./src"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.org"
19
+ },
20
+ "files": [
21
+ "/src",
22
+ "README.md"
23
+ ],
24
+ "dependencies": {
25
+ "@ossy/platform": "^3.27.0",
26
+ "@ossy/resources": "^3.27.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@ossy/app": "*",
30
+ "@ossy/design-system": "*",
31
+ "@ossy/router-react": "*",
32
+ "@ossy/sdk-react": "*",
33
+ "react": "*"
34
+ },
35
+ "gitHead": "f72042c42723468c010d0d9744ad69257143d0b9"
36
+ }
@@ -0,0 +1,10 @@
1
+ export const Definition = {
2
+ id: 'integrations',
3
+ title: 'Integrations',
4
+ titleKey: 'integrations.home.title',
5
+ description: 'Add an integration for this workspace and see which ones are connected.',
6
+ icon: 'link',
7
+ status: ['beta'],
8
+ entitlementRequired: false,
9
+ navOrder: 40,
10
+ }
package/src/catalog.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Integration rows a workspace can add or inspect.
3
+ * A row with `secrets` is connected per workspace. A row with `credentials`
4
+ * is provided by the platform environment.
5
+ *
6
+ * @param {{ packages?: Array<object> } | null | undefined} manifestSummary
7
+ * @returns {Array<{
8
+ * id: string,
9
+ * packageName: string,
10
+ * slug: string,
11
+ * secrets: string[],
12
+ * credentials: string[],
13
+ * connectActionId: string | null,
14
+ * }>}
15
+ */
16
+ export function listIntegrationRows (manifestSummary) {
17
+ /** @type {ReturnType<typeof listIntegrationRows>} */
18
+ const rows = []
19
+ for (const pkg of manifestSummary?.packages || []) {
20
+ for (const integration of pkg.integrations || []) {
21
+ if (!integration?.id) continue
22
+ const secrets = Array.isArray(integration.secrets) ? integration.secrets.filter(Boolean) : []
23
+ const credentials = Array.isArray(integration.credentials) ? integration.credentials.filter(Boolean) : []
24
+ if (!secrets.length && !credentials.length) continue
25
+ const connectActionId = (pkg.actions || [])
26
+ .map((action) => action?.id)
27
+ .find((id) => typeof id === 'string' && id.endsWith('/actions/connect')) || null
28
+ rows.push({
29
+ id: integration.id,
30
+ packageName: pkg.package || '',
31
+ slug: pkg.slug || '',
32
+ secrets,
33
+ credentials,
34
+ connectActionId,
35
+ })
36
+ }
37
+ }
38
+ rows.sort((a, b) => a.id.localeCompare(b.id))
39
+ return rows
40
+ }
@@ -0,0 +1,37 @@
1
+ import assert from 'node:assert/strict'
2
+ import { describe, it } from 'node:test'
3
+ import { listIntegrationRows } from './catalog.js'
4
+
5
+ describe('listIntegrationRows', () => {
6
+ it('keeps workspace secrets and platform credentials, and finds connect', () => {
7
+ const rows = listIntegrationRows({
8
+ packages: [
9
+ {
10
+ package: '@ossy/integration-linkedin',
11
+ slug: 'integration-linkedin',
12
+ integrations: [{ id: 'linkedin', secrets: ['ACCESS_TOKEN', 'AUTHOR_URN'] }],
13
+ actions: [
14
+ { id: '@ossy/linkedin/actions/publish' },
15
+ { id: '@ossy/linkedin/actions/connect' },
16
+ ],
17
+ },
18
+ {
19
+ package: '@ossy/integration-stripe',
20
+ slug: 'integration-stripe',
21
+ integrations: [{ id: 'stripe', credentials: ['STRIPE_SECRET_KEY'] }],
22
+ actions: [],
23
+ },
24
+ {
25
+ package: '@ossy/email',
26
+ slug: 'email',
27
+ integrations: [{ id: 'email', credentials: [] }],
28
+ actions: [],
29
+ },
30
+ ],
31
+ })
32
+
33
+ assert.deepEqual(rows.map((row) => row.id), ['linkedin', 'stripe'])
34
+ assert.equal(rows[0].connectActionId, '@ossy/linkedin/actions/connect')
35
+ assert.equal(rows[1].connectActionId, null)
36
+ })
37
+ })
@@ -0,0 +1,4 @@
1
+ export const metadata = {
2
+ id: '@ossy/integrations/actions/disconnect',
3
+ access: 'workspace',
4
+ }
@@ -0,0 +1,16 @@
1
+ import { IntegrationService, deleteWorkspaceSecret } from '@ossy/platform/integrations'
2
+
3
+ export const metadata = {
4
+ id: '@ossy/integrations/tasks/disconnect',
5
+ }
6
+
7
+ export async function run ({ req, payload }) {
8
+ const workspaceId = payload?.workspaceId || req?.workspaceId
9
+ const integrationId = typeof payload?.integrationId === 'string' ? payload.integrationId.trim() : ''
10
+ if (!workspaceId || !integrationId) {
11
+ throw Object.assign(new Error('workspaceId and integrationId are required'), { status: 400 })
12
+ }
13
+ await deleteWorkspaceSecret({ workspaceId, integrationId })
14
+ IntegrationService.invalidateWorkspaceClient({ workspaceId, integrationId })
15
+ return { integrationId }
16
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "integrations/home.documentTitle": "Integrations",
3
+ "integrations.home.title": "Integrations",
4
+ "integrations.home.description": "Integrations connected for this workspace.",
5
+ "integrations.listTitle": "Integrations",
6
+ "integrations.listEmpty": "No integrations yet.",
7
+ "integrations.loading": "Loading integrations",
8
+ "integrations.signIn": "Sign in to add an integration for this workspace.",
9
+ "integrations.addTitle": "Add integration",
10
+ "integrations.addDescription": "Choose an integration to connect for this workspace.",
11
+ "integrations.connectDescription": "Enter the values this integration needs. They are stored for this workspace.",
12
+ "integrations.addEmpty": "Every integration in this app is already connected.",
13
+ "integrations.back": "Back",
14
+ "integrations.cancel": "Cancel",
15
+ "integrations.status.connected": "Connected",
16
+ "integrations.secrets": "Secret keys",
17
+ "integrations.action.connect": "Connect",
18
+ "integrations.action.disconnect": "Disconnect",
19
+ "integrations.closePanel": "Close",
20
+ "integrations.field.ACCESS_TOKEN": "Access token",
21
+ "integrations.field.AUTHOR_URN": "Author URN",
22
+ "@ossy/integrations/actions/disconnect.label": "Disconnect integration",
23
+ "@ossy/integrations/actions/disconnect.description": "Remove this workspace's secret for an integration"
24
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Definition } from './Definition.js'
@@ -0,0 +1,379 @@
1
+ import React, { useMemo, useState } from 'react'
2
+ import {
3
+ Alert,
4
+ Button,
5
+ Icon,
6
+ Input,
7
+ List,
8
+ Overlay,
9
+ Page,
10
+ Panel,
11
+ Tags,
12
+ Text,
13
+ View,
14
+ useLocale,
15
+ } from '@ossy/design-system'
16
+ import { useApp } from '@ossy/app/shell'
17
+ import { ListPanelLayout, listPanelPageProps, useSelectedResourceId } from '@ossy/resources'
18
+ import { AsyncStatus, useSdk } from '@ossy/sdk-react'
19
+ import { listIntegrationRows } from './catalog.js'
20
+ import { Definition } from './Definition.js'
21
+
22
+ const LIST_INTEGRATIONS = { id: '@ossy/platform/actions/list-integrations' }
23
+ const DISCONNECT = { id: '@ossy/integrations/actions/disconnect' }
24
+
25
+ export const metadata = {
26
+ id: 'integrations/home',
27
+ path: {
28
+ en: '/integrations',
29
+ sv: '/integrationer',
30
+ },
31
+ }
32
+
33
+ function translateOrNull (t, key) {
34
+ if (!key) return null
35
+ const translated = t(key)
36
+ return translated && translated !== key ? translated : null
37
+ }
38
+
39
+ function fieldLabel (t, key) {
40
+ return translateOrNull(t, `integrations.field.${key}`) || key
41
+ }
42
+
43
+ function integrationTitle (row, t, definitions) {
44
+ return translateOrNull(t, `${row.slug}.home.title`)
45
+ || definitions?.[row.slug]?.title
46
+ || row.id
47
+ }
48
+
49
+ function integrationPitch (row, t, definitions) {
50
+ return translateOrNull(t, `${row.slug}.catalog.pitch`)
51
+ || translateOrNull(t, `${row.slug}.home.description`)
52
+ || definitions?.[row.slug]?.description
53
+ || ''
54
+ }
55
+
56
+ function integrationIcon (row, definitions) {
57
+ const icon = definitions?.[row.slug]?.icon
58
+ return typeof icon === 'string' && icon.trim() ? icon.trim() : 'link'
59
+ }
60
+
61
+ function IntegrationPanel ({ row, title, pitch, busy, error, onDisconnect, onClose }) {
62
+ const { t } = useLocale()
63
+
64
+ return (
65
+ <Panel
66
+ fill
67
+ scroll
68
+ data-integration-panel={row.id}
69
+ style={{ width: '100%', minWidth: 0, flexShrink: 0 }}
70
+ title={(
71
+ <Text as="h3" variant="small" weight="medium" style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
72
+ {title}
73
+ </Text>
74
+ )}
75
+ actions={(
76
+ <Button
77
+ prefix="close"
78
+ variant="command"
79
+ aria-label={t('integrations.closePanel')}
80
+ onClick={onClose}
81
+ />
82
+ )}
83
+ >
84
+ <View inset="m" gap="m">
85
+ <View layout="row" gap="m" alignItems="center">
86
+ <Icon name="link" />
87
+ <View gap="xs" style={{ minWidth: 0 }}>
88
+ <Text weight="medium">{title}</Text>
89
+ <Text variant="small" color="secondary" text="integrations.status.connected" />
90
+ </View>
91
+ </View>
92
+ {pitch && <Text color="secondary">{pitch}</Text>}
93
+ <View gap="xs">
94
+ <Text variant="small" weight="medium" text="integrations.secrets" />
95
+ {row.secrets.map((key) => (
96
+ <Text key={key} variant="small">{fieldLabel(t, key)}</Text>
97
+ ))}
98
+ </View>
99
+ {error && <Alert variant="danger">{error}</Alert>}
100
+ <Button
101
+ variant="command"
102
+ disabled={busy}
103
+ label="integrations.action.disconnect"
104
+ onClick={onDisconnect}
105
+ />
106
+ </View>
107
+ </Panel>
108
+ )
109
+ }
110
+
111
+ function AddDialogFrame ({ busy, onClose, children }) {
112
+ return (
113
+ <Overlay isVisible onClose={() => !busy && onClose()}>
114
+ <View layout="off-center-s" style={{ height: '100%' }}>
115
+ <View data-region="content" style={{ width: 'min(28rem, calc(100vw - 2rem))' }}>
116
+ <View surface="primary" roundness="m" inset="l" gap="m">
117
+ {children}
118
+ </View>
119
+ </View>
120
+ </View>
121
+ </Overlay>
122
+ )
123
+ }
124
+
125
+ function AddIntegrationOverlay ({ available, definitions, onClose, onConnected }) {
126
+ const { t } = useLocale()
127
+ const sdk = useSdk()
128
+ const [integrationId, setIntegrationId] = useState('')
129
+ const [values, setValues] = useState({})
130
+ const [busy, setBusy] = useState(false)
131
+ const [error, setError] = useState('')
132
+ const row = available.find((item) => item.id === integrationId) || null
133
+ const ready = Boolean(row) && row.secrets.every((key) => typeof values[key] === 'string' && values[key].trim())
134
+
135
+ const backToList = () => {
136
+ if (busy) return
137
+ setIntegrationId('')
138
+ setValues({})
139
+ setError('')
140
+ }
141
+
142
+ const connect = async () => {
143
+ if (!row?.connectActionId || !ready) return
144
+ setBusy(true)
145
+ setError('')
146
+ try {
147
+ const secretValues = {}
148
+ for (const key of row.secrets) secretValues[key] = values[key].trim()
149
+ await sdk.invoke({ id: row.connectActionId }, { values: secretValues })
150
+ setValues({})
151
+ await onConnected(row.id)
152
+ } catch (err) {
153
+ setError(err?.message || String(err))
154
+ } finally {
155
+ setBusy(false)
156
+ }
157
+ }
158
+
159
+ if (!row) {
160
+ return (
161
+ <AddDialogFrame onClose={onClose}>
162
+ <View gap="xs">
163
+ <Text variant="heading-tertiary" as="h3" text="integrations.addTitle" />
164
+ <Text color="secondary" text="integrations.addDescription" />
165
+ </View>
166
+ {available.length === 0 ? (
167
+ <Text color="secondary" text="integrations.addEmpty" />
168
+ ) : (
169
+ <List>
170
+ {available.map((item) => {
171
+ const title = integrationTitle(item, t, definitions)
172
+ const pitch = integrationPitch(item, t, definitions)
173
+ return (
174
+ <List.Item
175
+ key={item.id}
176
+ density="comfortable"
177
+ data-integration-choice={item.id}
178
+ leading={<Icon size="s" name={integrationIcon(item, definitions)} style={{ fill: 'hsl(0, 0%, 80%)' }} />}
179
+ onClick={() => setIntegrationId(item.id)}
180
+ >
181
+ <View gap="xs" style={{ minWidth: 0 }}>
182
+ <Text weight="medium">{title}</Text>
183
+ {pitch ? <Text variant="small" color="secondary">{pitch}</Text> : null}
184
+ </View>
185
+ </List.Item>
186
+ )
187
+ })}
188
+ </List>
189
+ )}
190
+ <View layout="row" gap="s" justifyContent="flex-end">
191
+ <Button variant="command" label="integrations.cancel" onClick={onClose} />
192
+ </View>
193
+ </AddDialogFrame>
194
+ )
195
+ }
196
+
197
+ const title = integrationTitle(row, t, definitions)
198
+
199
+ return (
200
+ <AddDialogFrame busy={busy} onClose={onClose}>
201
+ <View gap="xs">
202
+ <View layout="row" gap="s" alignItems="center">
203
+ <Button
204
+ prefix="arrow-left"
205
+ variant="command"
206
+ aria-label={t('integrations.back')}
207
+ disabled={busy}
208
+ onClick={backToList}
209
+ />
210
+ <Text variant="heading-tertiary" as="h3">{title}</Text>
211
+ </View>
212
+ <Text color="secondary" text="integrations.connectDescription" />
213
+ </View>
214
+ {error && <Alert variant="danger">{error}</Alert>}
215
+ {row.secrets.map((key) => (
216
+ <View key={key} gap="xs">
217
+ <Text variant="small" weight="medium">{fieldLabel(t, key)}</Text>
218
+ <Input
219
+ type="password"
220
+ name={key}
221
+ autoComplete="off"
222
+ aria-label={fieldLabel(t, key)}
223
+ value={values[key] || ''}
224
+ onChange={(event) => setValues((current) => ({ ...current, [key]: event.target.value }))}
225
+ />
226
+ </View>
227
+ ))}
228
+ <View layout="row" gap="s" justifyContent="flex-end">
229
+ <Button
230
+ variant="command"
231
+ disabled={busy}
232
+ label="integrations.cancel"
233
+ onClick={onClose}
234
+ />
235
+ <Button
236
+ variant="cta"
237
+ disabled={busy || !ready}
238
+ label="integrations.action.connect"
239
+ onClick={connect}
240
+ />
241
+ </View>
242
+ </AddDialogFrame>
243
+ )
244
+ }
245
+
246
+ export default function IntegrationsPage () {
247
+ const app = useApp()
248
+ const sdk = useSdk()
249
+ const { t } = useLocale()
250
+ const definitions = app?.manifestSummary?.definitions
251
+ const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
252
+ const [adding, setAdding] = useState(false)
253
+ const [busyId, setBusyId] = useState('')
254
+ const [error, setError] = useState('')
255
+ const rows = useMemo(
256
+ () => listIntegrationRows(app?.manifestSummary),
257
+ [app?.manifestSummary],
258
+ )
259
+ const canConnect = Boolean(app?.isAuthenticated && app?.workspaceId)
260
+ const { data, status, refetch } = sdk.read(LIST_INTEGRATIONS, {}, { enabled: canConnect })
261
+ const connectedIds = useMemo(
262
+ () => new Set(Array.isArray(data?.integrations) ? data.integrations : []),
263
+ [data],
264
+ )
265
+ const connected = useMemo(
266
+ () => rows.filter((row) => row.secrets.length > 0 && connectedIds.has(row.id)),
267
+ [rows, connectedIds],
268
+ )
269
+ const available = useMemo(
270
+ () => rows.filter((row) => row.secrets.length > 0 && row.connectActionId && !connectedIds.has(row.id)),
271
+ [rows, connectedIds],
272
+ )
273
+ const selected = connected.find((row) => row.id === selectedResourceId) || null
274
+ const loading = canConnect && (status === AsyncStatus.Loading || status === AsyncStatus.NotInitialized)
275
+ const statusTags = (Definition.status ?? [])
276
+ .map((tag) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[tag]))
277
+ .filter(Boolean)
278
+
279
+ const refresh = async () => {
280
+ if (typeof refetch === 'function') await refetch()
281
+ }
282
+
283
+ const disconnect = async (row) => {
284
+ setBusyId(row.id)
285
+ setError('')
286
+ try {
287
+ await sdk.invoke(DISCONNECT, { integrationId: row.id })
288
+ if (selectedResourceId === row.id) clearSelectedResourceId()
289
+ await refresh()
290
+ } catch (err) {
291
+ setError(err?.message || String(err))
292
+ } finally {
293
+ setBusyId('')
294
+ }
295
+ }
296
+
297
+ return (
298
+ <>
299
+ <Page
300
+ {...listPanelPageProps}
301
+ title="integrations.home.title"
302
+ near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
303
+ description="integrations.home.description"
304
+ far={(
305
+ <Button
306
+ variant="cta"
307
+ prefix="add"
308
+ disabled={!canConnect}
309
+ onClick={() => setAdding(true)}
310
+ >
311
+ {t('design-system.add')}
312
+ </Button>
313
+ )}
314
+ data-integrations-status={loading ? 'loading' : connected.length ? 'ready' : 'empty'}
315
+ >
316
+ <ListPanelLayout
317
+ listHeader="integrations.listTitle"
318
+ list={loading ? (
319
+ <View inset="m">
320
+ <Text color="secondary" text="integrations.loading" />
321
+ </View>
322
+ ) : !canConnect ? (
323
+ <View inset="m">
324
+ <Text color="secondary" text="integrations.signIn" />
325
+ </View>
326
+ ) : connected.length === 0 ? (
327
+ <View inset="m">
328
+ <Text color="secondary" text="integrations.listEmpty" />
329
+ </View>
330
+ ) : (
331
+ <List>
332
+ {connected.map((row) => {
333
+ const title = integrationTitle(row, t, definitions)
334
+ return (
335
+ <List.Item
336
+ key={row.id}
337
+ selectable
338
+ selected={row.id === selectedResourceId}
339
+ onClick={() => setSelectedResourceId(row.id)}
340
+ data-integration={row.id}
341
+ leading={<Icon size="s" name="link" style={{ fill: 'hsl(0, 0%, 80%)' }} />}
342
+ meta={<Text variant="small" color="secondary" text="integrations.status.connected" />}
343
+ >
344
+ {title}
345
+ </List.Item>
346
+ )
347
+ })}
348
+ </List>
349
+ )}
350
+ panel={selected
351
+ ? (
352
+ <IntegrationPanel
353
+ row={selected}
354
+ title={integrationTitle(selected, t, definitions)}
355
+ pitch={integrationPitch(selected, t, definitions)}
356
+ busy={busyId === selected.id}
357
+ error={error}
358
+ onDisconnect={() => disconnect(selected)}
359
+ onClose={clearSelectedResourceId}
360
+ />
361
+ )
362
+ : null}
363
+ />
364
+ </Page>
365
+ {adding && (
366
+ <AddIntegrationOverlay
367
+ available={available}
368
+ definitions={definitions}
369
+ onClose={() => setAdding(false)}
370
+ onConnected={async (id) => {
371
+ await refresh()
372
+ setSelectedResourceId(id)
373
+ setAdding(false)
374
+ }}
375
+ />
376
+ )}
377
+ </>
378
+ )
379
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "integrations/home.documentTitle": "Integrationer",
3
+ "integrations.home.title": "Integrationer",
4
+ "integrations.home.description": "Integrationer som är kopplade till den här arbetsytan.",
5
+ "integrations.listTitle": "Integrationer",
6
+ "integrations.listEmpty": "Inga integrationer ännu.",
7
+ "integrations.loading": "Laddar integrationer",
8
+ "integrations.signIn": "Logga in för att lägga till en integration för den här arbetsytan.",
9
+ "integrations.addTitle": "Lägg till integration",
10
+ "integrations.addDescription": "Välj en integration att koppla till den här arbetsytan.",
11
+ "integrations.connectDescription": "Fyll i värdena integrationen behöver. De sparas för den här arbetsytan.",
12
+ "integrations.addEmpty": "Alla integrationer i den här appen är redan kopplade.",
13
+ "integrations.back": "Tillbaka",
14
+ "integrations.cancel": "Avbryt",
15
+ "integrations.status.connected": "Kopplad",
16
+ "integrations.secrets": "Hemligheter",
17
+ "integrations.action.connect": "Koppla",
18
+ "integrations.action.disconnect": "Koppla från",
19
+ "integrations.closePanel": "Stäng",
20
+ "integrations.field.ACCESS_TOKEN": "Åtkomstnyckel",
21
+ "integrations.field.AUTHOR_URN": "Författar-URN",
22
+ "@ossy/integrations/actions/disconnect.label": "Koppla från integration",
23
+ "@ossy/integrations/actions/disconnect.description": "Ta bort den här arbetsytans hemlighet för en integration"
24
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.