@byline/host-tanstack-start 3.21.0 → 4.1.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/dist/admin-shell/admin-activity/list.js +15 -5
- package/dist/admin-shell/admin-roles/delete.js +2 -1
- package/dist/admin-shell/admin-roles/list.js +2 -1
- package/dist/admin-shell/admin-users/delete.js +2 -1
- package/dist/admin-shell/admin-users/list.js +4 -7
- package/dist/admin-shell/chrome/admin-app-bar.js +2 -1
- package/dist/admin-shell/chrome/admin-menu-drawer.js +9 -8
- package/dist/admin-shell/chrome/admin-menu-provider.js +2 -1
- package/dist/admin-shell/chrome/dashboard.js +4 -3
- package/dist/admin-shell/chrome/sign-in-page.d.ts +2 -2
- package/dist/admin-shell/chrome/sign-in-page.js +2 -2
- package/dist/admin-shell/collections/create.js +4 -3
- package/dist/admin-shell/collections/document-history.js +6 -1
- package/dist/admin-shell/collections/edit.js +18 -14
- package/dist/admin-shell/collections/history.js +5 -4
- package/dist/admin-shell/collections/list.js +8 -7
- package/dist/admin-shell/collections/restore-version-modal.js +2 -1
- package/dist/admin-shell/collections/tree-list.js +53 -17
- package/dist/admin-shell/collections/view-menu.js +9 -8
- package/dist/i18n/resolve-locale.js +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/integrations/abilities.js +8 -7
- package/dist/integrations/host-bridge.d.ts +13 -0
- package/dist/integrations/host-bridge.js +22 -0
- package/dist/integrations/serve-uploads.d.ts +1 -0
- package/dist/integrations/serve-uploads.js +1 -0
- package/dist/integrations/start-errors.js +2 -1
- package/dist/routes/admin-path.d.ts +22 -0
- package/dist/routes/admin-path.js +35 -0
- package/dist/routes/create-admin-account-route.js +3 -2
- package/dist/routes/create-admin-activity-route.js +3 -2
- package/dist/routes/create-admin-dashboard-route.js +2 -1
- package/dist/routes/create-admin-layout-route.d.ts +1 -1
- package/dist/routes/create-admin-layout-route.js +3 -1
- package/dist/routes/create-admin-permissions-route.js +3 -2
- package/dist/routes/create-admin-role-edit-route.js +4 -3
- package/dist/routes/create-admin-roles-list-route.js +3 -2
- package/dist/routes/create-admin-user-edit-route.js +4 -3
- package/dist/routes/create-admin-users-list-route.js +3 -2
- package/dist/routes/create-collection-api-route.js +5 -4
- package/dist/routes/create-collection-create-route.js +4 -3
- package/dist/routes/create-collection-edit-route.js +4 -3
- package/dist/routes/create-collection-history-route.js +5 -4
- package/dist/routes/create-collection-list-route.js +3 -2
- package/dist/routes/create-sign-in-route.js +3 -2
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.js +2 -0
- package/dist/routes/sign-in-path.d.ts +13 -0
- package/dist/routes/sign-in-path.js +19 -0
- package/dist/server-fns/admin-account/change-password.js +1 -1
- package/dist/server-fns/admin-account/get.js +1 -1
- package/dist/server-fns/admin-account/update.js +1 -1
- package/dist/server-fns/admin-activity/get.js +1 -1
- package/dist/server-fns/admin-permissions/get-role-abilities.js +1 -1
- package/dist/server-fns/admin-permissions/list-registered.js +1 -1
- package/dist/server-fns/admin-permissions/set-role-abilities.js +1 -1
- package/dist/server-fns/admin-permissions/who-has.js +1 -1
- package/dist/server-fns/admin-roles/create.js +1 -1
- package/dist/server-fns/admin-roles/delete.js +1 -1
- package/dist/server-fns/admin-roles/get.js +1 -1
- package/dist/server-fns/admin-roles/list.js +1 -1
- package/dist/server-fns/admin-roles/reorder.js +1 -1
- package/dist/server-fns/admin-roles/update.js +1 -1
- package/dist/server-fns/admin-users/create.js +1 -1
- package/dist/server-fns/admin-users/delete.js +1 -1
- package/dist/server-fns/admin-users/disable.js +1 -1
- package/dist/server-fns/admin-users/enable.js +1 -1
- package/dist/server-fns/admin-users/get-user-roles.js +1 -1
- package/dist/server-fns/admin-users/get.js +1 -1
- package/dist/server-fns/admin-users/list.js +1 -1
- package/dist/server-fns/admin-users/set-password.js +1 -1
- package/dist/server-fns/admin-users/set-user-roles.js +1 -1
- package/dist/server-fns/admin-users/update.js +1 -1
- package/dist/server-fns/ai/execute.js +1 -1
- package/dist/server-fns/auth/current-user.js +1 -1
- package/dist/server-fns/auth/sign-in.js +1 -1
- package/dist/server-fns/auth/sign-out.js +1 -2
- package/dist/server-fns/collections/audit.js +1 -1
- package/dist/server-fns/collections/copy-to-locale.js +1 -1
- package/dist/server-fns/collections/create.js +1 -1
- package/dist/server-fns/collections/delete-locale.js +1 -1
- package/dist/server-fns/collections/delete-outcome.d.ts +30 -0
- package/dist/server-fns/collections/delete-outcome.js +34 -0
- package/dist/server-fns/collections/delete.d.ts +1 -4
- package/dist/server-fns/collections/delete.js +3 -5
- package/dist/server-fns/collections/duplicate.js +1 -1
- package/dist/server-fns/collections/get.js +1 -1
- package/dist/server-fns/collections/history.js +1 -1
- package/dist/server-fns/collections/index.d.ts +1 -0
- package/dist/server-fns/collections/index.js +1 -0
- package/dist/server-fns/collections/list.js +1 -1
- package/dist/server-fns/collections/reindex.js +1 -1
- package/dist/server-fns/collections/reorder.js +1 -1
- package/dist/server-fns/collections/restore-version.js +1 -1
- package/dist/server-fns/collections/stats.js +1 -1
- package/dist/server-fns/collections/status.js +1 -1
- package/dist/server-fns/collections/tree-mutation.d.ts +46 -0
- package/dist/server-fns/collections/tree-mutation.js +109 -0
- package/dist/server-fns/collections/tree-read.d.ts +6 -0
- package/dist/server-fns/collections/tree-read.js +15 -0
- package/dist/server-fns/collections/tree.d.ts +5 -4
- package/dist/server-fns/collections/tree.js +16 -13
- package/dist/server-fns/collections/update.js +3 -2
- package/dist/server-fns/collections/upload.js +1 -1
- package/dist/server-fns/i18n/set-locale.js +1 -1
- package/dist/server-fns/preview/disable.js +1 -1
- package/dist/server-fns/preview/enable.js +1 -2
- package/dist/server-fns/preview/state.js +1 -1
- package/dist/vite/client-hook-boundary.d.ts +19 -0
- package/dist/vite/client-hook-boundary.js +20 -0
- package/dist/{integrations/byline-public-client.d.ts → vite/index.d.ts} +1 -2
- package/dist/vite/index.js +1 -0
- package/package.json +15 -14
- package/src/admin-shell/admin-activity/list.tsx +13 -3
- package/src/admin-shell/admin-roles/delete.tsx +2 -1
- package/src/admin-shell/admin-roles/list.tsx +2 -1
- package/src/admin-shell/admin-users/delete.tsx +3 -2
- package/src/admin-shell/admin-users/list.tsx +9 -8
- package/src/admin-shell/chrome/admin-app-bar.tsx +2 -1
- package/src/admin-shell/chrome/admin-menu-drawer.tsx +13 -8
- package/src/admin-shell/chrome/admin-menu-provider.tsx +2 -1
- package/src/admin-shell/chrome/dashboard.tsx +4 -3
- package/src/admin-shell/chrome/sign-in-page.tsx +3 -3
- package/src/admin-shell/collections/create.tsx +4 -3
- package/src/admin-shell/collections/document-history.tsx +5 -0
- package/src/admin-shell/collections/edit.tsx +20 -13
- package/src/admin-shell/collections/history.tsx +6 -5
- package/src/admin-shell/collections/list.tsx +8 -7
- package/src/admin-shell/collections/restore-version-modal.tsx +2 -1
- package/src/admin-shell/collections/tree-list.tsx +78 -22
- package/src/admin-shell/collections/view-menu.tsx +9 -8
- package/src/i18n/resolve-locale.ts +1 -1
- package/src/index.ts +5 -6
- package/src/integrations/abilities.tsx +14 -4
- package/src/integrations/host-bridge.ts +56 -0
- package/src/integrations/serve-uploads.ts +6 -0
- package/src/integrations/start-errors.test.node.ts +22 -0
- package/src/integrations/start-errors.ts +1 -0
- package/src/routes/admin-path.test.node.ts +129 -0
- package/src/routes/admin-path.ts +66 -0
- package/src/routes/auth-routes.test.node.ts +39 -0
- package/src/routes/create-admin-account-route.tsx +3 -2
- package/src/routes/create-admin-activity-route.tsx +3 -2
- package/src/routes/create-admin-dashboard-route.tsx +2 -1
- package/src/routes/create-admin-layout-route.tsx +4 -4
- package/src/routes/create-admin-permissions-route.tsx +3 -2
- package/src/routes/create-admin-role-edit-route.tsx +7 -3
- package/src/routes/create-admin-roles-list-route.tsx +3 -2
- package/src/routes/create-admin-user-edit-route.tsx +7 -3
- package/src/routes/create-admin-users-list-route.tsx +3 -2
- package/src/routes/create-collection-api-route.tsx +8 -4
- package/src/routes/create-collection-create-route.tsx +7 -3
- package/src/routes/create-collection-edit-route.tsx +7 -3
- package/src/routes/create-collection-history-route.tsx +8 -4
- package/src/routes/create-collection-list-route.tsx +3 -2
- package/src/routes/create-sign-in-route.tsx +9 -3
- package/src/routes/index.ts +11 -0
- package/src/routes/sign-in-path.test.node.ts +79 -0
- package/src/routes/sign-in-path.ts +36 -0
- package/src/server-fns/admin-account/change-password.ts +1 -1
- package/src/server-fns/admin-account/get.ts +1 -1
- package/src/server-fns/admin-account/update.ts +1 -1
- package/src/server-fns/admin-activity/get.ts +1 -1
- package/src/server-fns/admin-permissions/get-role-abilities.ts +1 -1
- package/src/server-fns/admin-permissions/list-registered.ts +1 -1
- package/src/server-fns/admin-permissions/set-role-abilities.ts +1 -1
- package/src/server-fns/admin-permissions/who-has.ts +1 -1
- package/src/server-fns/admin-roles/create.ts +1 -1
- package/src/server-fns/admin-roles/delete.ts +1 -1
- package/src/server-fns/admin-roles/get.ts +1 -1
- package/src/server-fns/admin-roles/list.ts +1 -1
- package/src/server-fns/admin-roles/reorder.ts +1 -1
- package/src/server-fns/admin-roles/update.ts +1 -1
- package/src/server-fns/admin-users/create.ts +1 -1
- package/src/server-fns/admin-users/delete.ts +1 -1
- package/src/server-fns/admin-users/disable.ts +1 -1
- package/src/server-fns/admin-users/enable.ts +1 -1
- package/src/server-fns/admin-users/get-user-roles.ts +1 -1
- package/src/server-fns/admin-users/get.ts +1 -1
- package/src/server-fns/admin-users/list.ts +1 -1
- package/src/server-fns/admin-users/set-password.ts +1 -1
- package/src/server-fns/admin-users/set-user-roles.ts +1 -1
- package/src/server-fns/admin-users/update.ts +1 -1
- package/src/server-fns/ai/execute.ts +1 -2
- package/src/server-fns/auth/current-user.ts +1 -1
- package/src/server-fns/auth/sign-in.ts +1 -1
- package/src/server-fns/auth/sign-out.ts +5 -3
- package/src/server-fns/collections/audit.ts +1 -1
- package/src/server-fns/collections/copy-to-locale.ts +1 -1
- package/src/server-fns/collections/create.ts +1 -1
- package/src/server-fns/collections/delete-locale.ts +1 -1
- package/src/server-fns/collections/delete-outcome.test.node.ts +72 -0
- package/src/server-fns/collections/delete-outcome.ts +80 -0
- package/src/server-fns/collections/delete.ts +3 -2
- package/src/server-fns/collections/duplicate.ts +1 -1
- package/src/server-fns/collections/get.ts +3 -1
- package/src/server-fns/collections/history.ts +1 -1
- package/src/server-fns/collections/index.ts +1 -0
- package/src/server-fns/collections/list.ts +1 -1
- package/src/server-fns/collections/reindex.ts +1 -1
- package/src/server-fns/collections/reorder.ts +1 -1
- package/src/server-fns/collections/restore-version.ts +1 -1
- package/src/server-fns/collections/stats.ts +2 -1
- package/src/server-fns/collections/status.ts +1 -1
- package/src/server-fns/collections/tree-mutation.test.node.ts +225 -0
- package/src/server-fns/collections/tree-mutation.ts +165 -0
- package/src/server-fns/collections/tree-read.test.node.ts +46 -0
- package/src/server-fns/collections/tree-read.ts +26 -0
- package/src/server-fns/collections/tree.ts +27 -11
- package/src/server-fns/collections/update.ts +4 -1
- package/src/server-fns/collections/upload.ts +1 -1
- package/src/server-fns/i18n/set-locale.ts +1 -1
- package/src/server-fns/preview/disable.ts +1 -1
- package/src/server-fns/preview/enable.ts +1 -2
- package/src/server-fns/preview/state.ts +1 -1
- package/src/vite/client-hook-boundary.test.node.ts +50 -0
- package/src/vite/client-hook-boundary.ts +45 -0
- package/src/vite/index.ts +9 -0
- package/dist/auth/auth-context.d.ts +0 -37
- package/dist/auth/auth-context.js +0 -57
- package/dist/auth/auth-cookies.d.ts +0 -34
- package/dist/auth/auth-cookies.js +0 -46
- package/dist/auth/preview-cookies.d.ts +0 -19
- package/dist/auth/preview-cookies.js +0 -26
- package/dist/integrations/byline-client.d.ts +0 -24
- package/dist/integrations/byline-client.js +0 -25
- package/dist/integrations/byline-public-client.js +0 -15
- package/dist/integrations/byline-viewer-client.d.ts +0 -20
- package/dist/integrations/byline-viewer-client.js +0 -39
- package/src/auth/auth-context.test.node.ts +0 -215
- package/src/auth/auth-context.ts +0 -124
- package/src/auth/auth-cookies.ts +0 -113
- package/src/auth/preview-cookies.ts +0 -73
- package/src/integrations/byline-client.ts +0 -66
- package/src/integrations/byline-public-client.ts +0 -53
- package/src/integrations/byline-viewer-client.ts +0 -99
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineClientConfig } from '@byline/core'
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
configureSignInRoutePath,
|
|
6
|
+
createSignInRoutePathResolver,
|
|
7
|
+
getSignInRoutePath,
|
|
8
|
+
} from './sign-in-path.js'
|
|
9
|
+
|
|
10
|
+
describe('sign-in route configuration', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
defineClientConfig({
|
|
13
|
+
serverURL: 'http://localhost:3000',
|
|
14
|
+
routes: { signIn: '/staff/login/' },
|
|
15
|
+
collections: [],
|
|
16
|
+
admin: [],
|
|
17
|
+
i18n: {
|
|
18
|
+
interface: { defaultLocale: 'en', locales: [] },
|
|
19
|
+
content: { defaultLocale: 'en', locales: [] },
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('reads and normalizes routes.signIn', () => {
|
|
25
|
+
expect(getSignInRoutePath()).toBe('/staff/login')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('allows a deprecated signInPath override when it matches canonical config', () => {
|
|
29
|
+
expect(configureSignInRoutePath('staff/login/')).toBe('/staff/login')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('rejects an invalid or divergent deprecated override when resolved', () => {
|
|
33
|
+
expect(() => configureSignInRoutePath('/auth/login/')).toThrow(/must match routes\.signIn/)
|
|
34
|
+
expect(() => configureSignInRoutePath('/auth/../login')).toThrow(/routes\.signIn/)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('validates an override against configured rather than default route trees', () => {
|
|
38
|
+
defineClientConfig({
|
|
39
|
+
serverURL: 'http://localhost:3000',
|
|
40
|
+
routes: { admin: '/cms', api: '/rpc', signIn: '/admin/login' },
|
|
41
|
+
collections: [],
|
|
42
|
+
admin: [],
|
|
43
|
+
i18n: {
|
|
44
|
+
interface: { defaultLocale: 'en', locales: [] },
|
|
45
|
+
content: { defaultLocale: 'en', locales: [] },
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
expect(configureSignInRoutePath('/admin/login/')).toBe('/admin/login')
|
|
50
|
+
expect(() => configureSignInRoutePath('/cms/login')).toThrow(/routes\.signIn/)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('defers a deprecated override until parent beforeLoad config registration', () => {
|
|
54
|
+
defineClientConfig({
|
|
55
|
+
serverURL: 'http://localhost:3000',
|
|
56
|
+
routes: { signIn: '/old/login' },
|
|
57
|
+
collections: [],
|
|
58
|
+
admin: [],
|
|
59
|
+
i18n: {
|
|
60
|
+
interface: { defaultLocale: 'en', locales: [] },
|
|
61
|
+
content: { defaultLocale: 'en', locales: [] },
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
const resolveSignInPath = createSignInRoutePathResolver('/staff/login/')
|
|
65
|
+
|
|
66
|
+
defineClientConfig({
|
|
67
|
+
serverURL: 'http://localhost:3000',
|
|
68
|
+
routes: { signIn: '/staff/login' },
|
|
69
|
+
collections: [],
|
|
70
|
+
admin: [],
|
|
71
|
+
i18n: {
|
|
72
|
+
interface: { defaultLocale: 'en', locales: [] },
|
|
73
|
+
content: { defaultLocale: 'en', locales: [] },
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
expect(resolveSignInPath()).toBe('/staff/login')
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getClientConfig, resolveRoutes } from '@byline/core'
|
|
10
|
+
|
|
11
|
+
/** Read the canonical client-safe sign-in destination. */
|
|
12
|
+
export function getSignInRoutePath(): string {
|
|
13
|
+
return getClientConfig().routes.signIn
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @deprecated Configure `routes.signIn`; retained for route-factory input validation. */
|
|
17
|
+
export function configureSignInRoutePath(legacyOverride?: string): string {
|
|
18
|
+
const routes = getClientConfig().routes
|
|
19
|
+
const configured = routes.signIn
|
|
20
|
+
if (legacyOverride === undefined) return configured
|
|
21
|
+
|
|
22
|
+
const normalizedOverride = resolveRoutes({ ...routes, signIn: legacyOverride }).signIn
|
|
23
|
+
if (normalizedOverride !== configured) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`createAdminLayoutRoute signInPath (${normalizedOverride}) must match routes.signIn (${configured})`
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
return configured
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Defer deprecated override validation until the admin route's beforeLoad boundary. */
|
|
32
|
+
export function createSignInRoutePathResolver(legacyOverride?: string): () => string {
|
|
33
|
+
return legacyOverride === undefined
|
|
34
|
+
? getSignInRoutePath
|
|
35
|
+
: () => configureSignInRoutePath(legacyOverride)
|
|
36
|
+
}
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AccountResponse, changeAccountPasswordCommand } from '@byline/admin/admin-account'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface ChangeAccountPasswordInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AccountResponse, getAccountCommand } from '@byline/admin/admin-account'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AccountResponse, updateAccountCommand } from '@byline/admin/admin-account'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface UpdateAccountInput {
|
|
@@ -10,9 +10,9 @@ import { createServerFn } from '@tanstack/react-start'
|
|
|
10
10
|
|
|
11
11
|
import { assertAdminActor } from '@byline/admin'
|
|
12
12
|
import { ADMIN_ACTIVITY_ABILITIES } from '@byline/admin/admin-activity'
|
|
13
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
13
14
|
import { ERR_AUDIT_UNSUPPORTED, getLogger, getServerConfig } from '@byline/core'
|
|
14
15
|
|
|
15
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
16
16
|
import { type ActorLabelMap, resolveActorLabels } from '../collections/actors.js'
|
|
17
17
|
import type { AuditLogEntryDto } from '../collections/audit.js'
|
|
18
18
|
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
type GetRoleAbilitiesResponse,
|
|
13
13
|
getRoleAbilitiesCommand,
|
|
14
14
|
} from '@byline/admin/admin-permissions'
|
|
15
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
15
16
|
|
|
16
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
17
17
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
18
18
|
|
|
19
19
|
export const getRoleAbilities = createServerFn({ method: 'GET' })
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
type ListRegisteredAbilitiesResponse,
|
|
13
13
|
listRegisteredAbilitiesCommand,
|
|
14
14
|
} from '@byline/admin/admin-permissions'
|
|
15
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
15
16
|
|
|
16
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
17
17
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
type SetRoleAbilitiesResponse,
|
|
13
13
|
setRoleAbilitiesCommand,
|
|
14
14
|
} from '@byline/admin/admin-permissions'
|
|
15
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
15
16
|
|
|
16
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
17
17
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
18
18
|
|
|
19
19
|
export interface SetRoleAbilitiesInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type WhoHasAbilityResponse, whoHasAbilityCommand } from '@byline/admin/admin-permissions'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const whoHasAbility = createServerFn({ method: 'GET' })
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminRoleResponse, createAdminRoleCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface CreateAdminRoleInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { deleteAdminRoleCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
// Return shape mirrors `OkResponse` from `@byline/admin/admin-users`.
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminRoleResponse, getAdminRoleCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const getAdminRole = createServerFn({ method: 'GET' })
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminRoleListResponse, listAdminRolesCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { reorderAdminRolesCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const reorderAdminRoles = createServerFn({ method: 'POST' })
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminRoleResponse, updateAdminRoleCommand } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface UpdateAdminRoleInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminUserResponse, createAdminUserCommand } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface CreateAdminUserInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { deleteAdminUserCommand, type OkResponse } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const deleteAdminUser = createServerFn({ method: 'POST' })
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { disableAdminUserCommand, type OkResponse } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
// No UI affordance yet — paired with `enable.ts`, both ship ahead of the
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { enableAdminUserCommand, type OkResponse } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
// No UI affordance yet — paired with `disable.ts`, both ship ahead of the
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { getRolesForUserCommand, type UserRolesResponse } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const getUserRoles = createServerFn({ method: 'GET' })
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminUserResponse, getAdminUserCommand } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export const getAdminUser = createServerFn({ method: 'GET' })
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
type AdminUserListResponse,
|
|
14
14
|
listAdminUsersCommand,
|
|
15
15
|
} from '@byline/admin/admin-users'
|
|
16
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
16
17
|
|
|
17
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
18
18
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
19
19
|
|
|
20
20
|
export interface ListAdminUsersInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminUserResponse, setAdminUserPasswordCommand } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface SetAdminUserPasswordInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { setRolesForUserCommand, type UserRolesResponse } from '@byline/admin/admin-roles'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface SetUserRolesInput {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
11
|
import { type AdminUserResponse, updateAdminUserCommand } from '@byline/admin/admin-users'
|
|
12
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
12
13
|
|
|
13
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
14
14
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
15
15
|
|
|
16
16
|
export interface UpdateAdminUserInput {
|
|
@@ -24,8 +24,7 @@ import type { ExecuteInstructionOptions, ExecuteInstructionParams } from '@bylin
|
|
|
24
24
|
// Server-only execute API — kept on the `/server` subpath so the browser
|
|
25
25
|
// barrel for `@byline/ai` stays free of pino + the provider SDKs.
|
|
26
26
|
import { executeInstruction, executeInstructionStreaming } from '@byline/ai/server'
|
|
27
|
-
|
|
28
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
27
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* Wire shape — the same as `ExecuteInstruction` minus the in-process-only
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
import { createServerFn } from '@tanstack/react-start'
|
|
22
22
|
|
|
23
23
|
import { type Actor, AuthError } from '@byline/auth'
|
|
24
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
24
25
|
|
|
25
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
26
26
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
27
27
|
|
|
28
28
|
export interface CurrentAdminUser {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
import { createServerFn } from '@tanstack/react-start'
|
|
21
21
|
import { getRequestHeader } from '@tanstack/react-start/server'
|
|
22
22
|
|
|
23
|
+
import { setSessionCookies } from '@byline/client/server'
|
|
23
24
|
import { getServerConfig } from '@byline/core'
|
|
24
25
|
|
|
25
|
-
import { setSessionCookies } from '../../auth/auth-cookies.js'
|
|
26
26
|
import { readAdminLocaleCookie } from '../../i18n/locale-cookie.js'
|
|
27
27
|
import { bylineCore } from '../../integrations/byline-core.js'
|
|
28
28
|
|
|
@@ -23,11 +23,13 @@
|
|
|
23
23
|
|
|
24
24
|
import { createServerFn } from '@tanstack/react-start'
|
|
25
25
|
|
|
26
|
+
import {
|
|
27
|
+
clearPreviewCookie,
|
|
28
|
+
clearSessionCookies,
|
|
29
|
+
readRefreshTokenCookie,
|
|
30
|
+
} from '@byline/client/server'
|
|
26
31
|
import { getServerConfig } from '@byline/core'
|
|
27
32
|
|
|
28
|
-
import { clearSessionCookies, readRefreshTokenCookie } from '../../auth/auth-cookies.js'
|
|
29
|
-
import { clearPreviewCookie } from '../../auth/preview-cookies.js'
|
|
30
|
-
|
|
31
33
|
export const adminSignOut = createServerFn({ method: 'POST' }).handler(async () => {
|
|
32
34
|
const provider = getServerConfig().sessionProvider
|
|
33
35
|
const refreshToken = readRefreshTokenCookie()
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
|
+
import { getAdminBylineClient } from '@byline/client/server'
|
|
11
12
|
import { ERR_NOT_FOUND, getLogger } from '@byline/core'
|
|
12
13
|
|
|
13
14
|
import { ensureCollection } from '../../integrations/api-utils.js'
|
|
14
|
-
import { getAdminBylineClient } from '../../integrations/byline-client.js'
|
|
15
15
|
import { type ActorLabelMap, resolveActorLabels } from './actors.js'
|
|
16
16
|
|
|
17
17
|
// ---------------------------------------------------------------------------
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
11
12
|
import { ERR_NOT_FOUND, getLogger, getServerConfig } from '@byline/core'
|
|
12
13
|
import type { CopyToLocaleResult, DocumentLifecycleContext } from '@byline/core/services'
|
|
13
14
|
import { copyToLocale } from '@byline/core/services'
|
|
14
15
|
|
|
15
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
16
16
|
import { ensureCollection } from '../../integrations/api-utils.js'
|
|
17
17
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
11
12
|
import { ERR_NOT_FOUND, getLogger, getServerConfig } from '@byline/core'
|
|
12
13
|
import type { DocumentLifecycleContext } from '@byline/core/services'
|
|
13
14
|
import { createDocument } from '@byline/core/services'
|
|
14
15
|
|
|
15
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
16
16
|
import { ensureCollection } from '../../integrations/api-utils.js'
|
|
17
17
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServerFn } from '@tanstack/react-start'
|
|
10
10
|
|
|
11
|
+
import { getAdminRequestContext } from '@byline/client/server'
|
|
11
12
|
import { ERR_NOT_FOUND, getLogger, getServerConfig } from '@byline/core'
|
|
12
13
|
import type { DeleteLocaleResult, DocumentLifecycleContext } from '@byline/core/services'
|
|
13
14
|
import { deleteLocale } from '@byline/core/services'
|
|
14
15
|
|
|
15
|
-
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
16
16
|
import { ensureCollection } from '../../integrations/api-utils.js'
|
|
17
17
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { DeleteDocumentResult, DeleteDocumentSideEffectPhase } from '@byline/core'
|
|
10
|
+
import { describe, expect, it } from 'vitest'
|
|
11
|
+
|
|
12
|
+
import { hasDeleteSideEffectFailures, toDeleteDocumentResponse } from './delete-outcome.js'
|
|
13
|
+
|
|
14
|
+
describe('delete outcome transport and admin interpretation', () => {
|
|
15
|
+
it('returns only allowlisted phase/code data for a committed warning', () => {
|
|
16
|
+
// Simulate malformed runtime data from an older or compromised source. The
|
|
17
|
+
// core type rejects this shape, but the transport still sanitizes it.
|
|
18
|
+
const unsafeResult = {
|
|
19
|
+
deletedVersionCount: 2,
|
|
20
|
+
outcome: 'committed-with-side-effect-failures',
|
|
21
|
+
sideEffectFailures: [
|
|
22
|
+
{ phase: 'afterDelete', message: 'secret hook details', code: 'ERR_SEARCH' },
|
|
23
|
+
{ phase: 'storageCleanup', message: 'private/path.pdf', code: 'ERR_STORAGE' },
|
|
24
|
+
{
|
|
25
|
+
phase: 'internalOnly' as DeleteDocumentSideEffectPhase,
|
|
26
|
+
message: 'internal phase details',
|
|
27
|
+
code: 'ERR_INTERNAL',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
} as unknown as DeleteDocumentResult
|
|
31
|
+
const response = toDeleteDocumentResponse(unsafeResult)
|
|
32
|
+
|
|
33
|
+
expect(response).toEqual({
|
|
34
|
+
status: 'ok',
|
|
35
|
+
deletedVersionCount: 2,
|
|
36
|
+
outcome: 'committed-with-side-effect-failures',
|
|
37
|
+
sideEffectFailures: [
|
|
38
|
+
{ phase: 'afterDelete', code: 'ERR_UNHANDLED' },
|
|
39
|
+
{ phase: 'storageCleanup', code: 'ERR_STORAGE' },
|
|
40
|
+
{ phase: 'unknown', code: 'ERR_UNHANDLED' },
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
expect(JSON.parse(JSON.stringify(response))).toEqual(response)
|
|
44
|
+
expect(JSON.stringify(response)).not.toContain('secret hook details')
|
|
45
|
+
expect(JSON.stringify(response)).not.toContain('private/path.pdf')
|
|
46
|
+
expect(JSON.stringify(response)).not.toContain('internal phase details')
|
|
47
|
+
expect(hasDeleteSideEffectFailures(response)).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('preserves the committed success discriminant and empty failures', () => {
|
|
51
|
+
const response = toDeleteDocumentResponse({
|
|
52
|
+
deletedVersionCount: 2,
|
|
53
|
+
outcome: 'committed',
|
|
54
|
+
sideEffectFailures: [],
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
expect(response).toEqual({
|
|
58
|
+
status: 'ok',
|
|
59
|
+
deletedVersionCount: 2,
|
|
60
|
+
outcome: 'committed',
|
|
61
|
+
sideEffectFailures: [],
|
|
62
|
+
})
|
|
63
|
+
expect(hasDeleteSideEffectFailures(response)).toBe(false)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('classifies only committed side-effect failures as an admin warning', () => {
|
|
67
|
+
expect(hasDeleteSideEffectFailures({ outcome: 'committed' })).toBe(false)
|
|
68
|
+
expect(hasDeleteSideEffectFailures({ outcome: 'committed-with-side-effect-failures' })).toBe(
|
|
69
|
+
true
|
|
70
|
+
)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
DeleteDocumentResult,
|
|
11
|
+
DeleteDocumentSideEffectCode,
|
|
12
|
+
DeleteDocumentSideEffectPhase,
|
|
13
|
+
} from '@byline/core'
|
|
14
|
+
import { ErrorCodes } from '@byline/core'
|
|
15
|
+
|
|
16
|
+
export type DeleteDocumentPublicSideEffectPhase = DeleteDocumentSideEffectPhase | 'unknown'
|
|
17
|
+
export type DeleteDocumentPublicSideEffectCode = DeleteDocumentSideEffectCode
|
|
18
|
+
|
|
19
|
+
export interface DeleteDocumentPublicSideEffectFailure {
|
|
20
|
+
phase: DeleteDocumentPublicSideEffectPhase
|
|
21
|
+
code: DeleteDocumentPublicSideEffectCode
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type DeleteDocumentResponse =
|
|
25
|
+
| {
|
|
26
|
+
status: 'ok'
|
|
27
|
+
deletedVersionCount: number
|
|
28
|
+
outcome: 'committed'
|
|
29
|
+
sideEffectFailures: []
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
status: 'ok'
|
|
33
|
+
deletedVersionCount: number
|
|
34
|
+
outcome: 'committed-with-side-effect-failures'
|
|
35
|
+
sideEffectFailures: [
|
|
36
|
+
DeleteDocumentPublicSideEffectFailure,
|
|
37
|
+
...DeleteDocumentPublicSideEffectFailure[],
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function sanitizePhase(phase: DeleteDocumentSideEffectPhase): DeleteDocumentPublicSideEffectPhase {
|
|
42
|
+
if (phase === 'storageCleanup' || phase === 'afterTreeChange' || phase === 'afterDelete') {
|
|
43
|
+
return phase
|
|
44
|
+
}
|
|
45
|
+
return 'unknown'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sanitizeCode(code: string): DeleteDocumentPublicSideEffectCode {
|
|
49
|
+
return code === ErrorCodes.STORAGE ? ErrorCodes.STORAGE : ErrorCodes.UNHANDLED
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function sanitizeFailure({
|
|
53
|
+
phase,
|
|
54
|
+
code,
|
|
55
|
+
}: {
|
|
56
|
+
phase: DeleteDocumentSideEffectPhase
|
|
57
|
+
code: string
|
|
58
|
+
}): DeleteDocumentPublicSideEffectFailure {
|
|
59
|
+
return { phase: sanitizePhase(phase), code: sanitizeCode(code) }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function toDeleteDocumentResponse(result: DeleteDocumentResult): DeleteDocumentResponse {
|
|
63
|
+
if (result.outcome === 'committed') {
|
|
64
|
+
return { status: 'ok', ...result }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const [firstFailure, ...remainingFailures] = result.sideEffectFailures
|
|
68
|
+
return {
|
|
69
|
+
status: 'ok',
|
|
70
|
+
deletedVersionCount: result.deletedVersionCount,
|
|
71
|
+
outcome: result.outcome,
|
|
72
|
+
sideEffectFailures: [sanitizeFailure(firstFailure), ...remainingFailures.map(sanitizeFailure)],
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function hasDeleteSideEffectFailures(
|
|
77
|
+
result: Pick<DeleteDocumentResult, 'outcome'>
|
|
78
|
+
): boolean {
|
|
79
|
+
return result.outcome === 'committed-with-side-effect-failures'
|
|
80
|
+
}
|