@teleporthq/teleport-shared 0.43.75 → 0.44.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/__tests__/page-arrival/page-export.test.ts +109 -0
- package/__tests__/page-arrival/runtime.test.ts +209 -0
- package/__tests__/utils/table-access-trusted-reader-roles.ts +144 -0
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/page-arrival/constants.d.ts +14 -0
- package/dist/cjs/page-arrival/constants.d.ts.map +1 -0
- package/dist/cjs/page-arrival/constants.js +17 -0
- package/dist/cjs/page-arrival/constants.js.map +1 -0
- package/dist/cjs/page-arrival/index.d.ts +4 -0
- package/dist/cjs/page-arrival/index.d.ts.map +1 -0
- package/dist/cjs/page-arrival/index.js +20 -0
- package/dist/cjs/page-arrival/index.js.map +1 -0
- package/dist/cjs/page-arrival/page-export.d.ts +14 -0
- package/dist/cjs/page-arrival/page-export.d.ts.map +1 -0
- package/dist/cjs/page-arrival/page-export.js +88 -0
- package/dist/cjs/page-arrival/page-export.js.map +1 -0
- package/dist/cjs/page-arrival/runtime.d.ts +21 -0
- package/dist/cjs/page-arrival/runtime.d.ts.map +1 -0
- package/dist/cjs/page-arrival/runtime.js +26 -0
- package/dist/cjs/page-arrival/runtime.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/table-access.d.ts +17 -4
- package/dist/cjs/utils/table-access.d.ts.map +1 -1
- package/dist/cjs/utils/table-access.js +55 -14
- package/dist/cjs/utils/table-access.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/page-arrival/constants.d.ts +14 -0
- package/dist/esm/page-arrival/constants.d.ts.map +1 -0
- package/dist/esm/page-arrival/constants.js +14 -0
- package/dist/esm/page-arrival/constants.js.map +1 -0
- package/dist/esm/page-arrival/index.d.ts +4 -0
- package/dist/esm/page-arrival/index.d.ts.map +1 -0
- package/dist/esm/page-arrival/index.js +4 -0
- package/dist/esm/page-arrival/index.js.map +1 -0
- package/dist/esm/page-arrival/page-export.d.ts +14 -0
- package/dist/esm/page-arrival/page-export.d.ts.map +1 -0
- package/dist/esm/page-arrival/page-export.js +61 -0
- package/dist/esm/page-arrival/page-export.js.map +1 -0
- package/dist/esm/page-arrival/runtime.d.ts +21 -0
- package/dist/esm/page-arrival/runtime.d.ts.map +1 -0
- package/dist/esm/page-arrival/runtime.js +22 -0
- package/dist/esm/page-arrival/runtime.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/table-access.d.ts +17 -4
- package/dist/esm/utils/table-access.d.ts.map +1 -1
- package/dist/esm/utils/table-access.js +53 -13
- package/dist/esm/utils/table-access.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/page-arrival/constants.ts +15 -0
- package/src/page-arrival/index.ts +3 -0
- package/src/page-arrival/page-export.ts +58 -0
- package/src/page-arrival/runtime.ts +75 -0
- package/src/utils/table-access.ts +50 -12
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import generator from '@babel/generator'
|
|
2
|
+
import * as types from '@babel/types'
|
|
3
|
+
import { ChunkType, ComponentStructure, FileType } from '@teleporthq/teleport-types'
|
|
4
|
+
import { PageArrival } from '../../src'
|
|
5
|
+
|
|
6
|
+
const makeStructure = (
|
|
7
|
+
params: {
|
|
8
|
+
folderPath?: string[]
|
|
9
|
+
exportContent?: types.Node | null
|
|
10
|
+
withExtractedResources?: boolean
|
|
11
|
+
} = {}
|
|
12
|
+
): ComponentStructure => {
|
|
13
|
+
const {
|
|
14
|
+
folderPath = [],
|
|
15
|
+
exportContent = types.exportDefaultDeclaration(types.identifier('Customers')),
|
|
16
|
+
withExtractedResources = true,
|
|
17
|
+
} = params
|
|
18
|
+
return {
|
|
19
|
+
uidl: {
|
|
20
|
+
name: 'Customers',
|
|
21
|
+
node: { type: 'element', content: { elementType: 'container' } },
|
|
22
|
+
outputOptions: { folderPath },
|
|
23
|
+
},
|
|
24
|
+
chunks: exportContent
|
|
25
|
+
? [
|
|
26
|
+
{
|
|
27
|
+
name: 'export',
|
|
28
|
+
type: ChunkType.AST,
|
|
29
|
+
fileType: FileType.JS,
|
|
30
|
+
content: exportContent,
|
|
31
|
+
linkAfter: ['jsx-component'],
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
: [],
|
|
35
|
+
dependencies: {},
|
|
36
|
+
options: {
|
|
37
|
+
pagesPath: ['pages'],
|
|
38
|
+
...(withExtractedResources ? { extractedResources: {} } : {}),
|
|
39
|
+
},
|
|
40
|
+
} as unknown as ComponentStructure
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const exportCode = (structure: ComponentStructure): string =>
|
|
44
|
+
generator(structure.chunks.find((chunk) => chunk.name === 'export')?.content as types.Node).code
|
|
45
|
+
|
|
46
|
+
describe('PageArrival.remountPageOnArrival', () => {
|
|
47
|
+
it('wraps the default export, imports the wrapper and emits it once', () => {
|
|
48
|
+
const structure = makeStructure()
|
|
49
|
+
|
|
50
|
+
PageArrival.remountPageOnArrival(structure)
|
|
51
|
+
|
|
52
|
+
expect(exportCode(structure)).toBe('export default remountOnPageArrival(Customers);')
|
|
53
|
+
expect(structure.dependencies.remountOnPageArrival).toEqual({
|
|
54
|
+
type: 'local',
|
|
55
|
+
path: '../utils/page-arrival',
|
|
56
|
+
})
|
|
57
|
+
expect(structure.options.extractedResources?.['utils/page-arrival']).toEqual({
|
|
58
|
+
fileName: 'page-arrival',
|
|
59
|
+
fileType: FileType.JS,
|
|
60
|
+
path: ['utils'],
|
|
61
|
+
content: PageArrival.generatePageArrivalRuntime(),
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('reaches the wrapper from a page in a subfolder', () => {
|
|
66
|
+
const structure = makeStructure({ folderPath: ['profile'] })
|
|
67
|
+
|
|
68
|
+
PageArrival.remountPageOnArrival(structure)
|
|
69
|
+
|
|
70
|
+
expect(structure.dependencies.remountOnPageArrival).toEqual({
|
|
71
|
+
type: 'local',
|
|
72
|
+
path: '../../utils/page-arrival',
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('wraps a page only once when several plugins ask for it', () => {
|
|
77
|
+
const structure = makeStructure()
|
|
78
|
+
|
|
79
|
+
PageArrival.remountPageOnArrival(structure)
|
|
80
|
+
PageArrival.remountPageOnArrival(structure)
|
|
81
|
+
|
|
82
|
+
expect(exportCode(structure)).toBe('export default remountOnPageArrival(Customers);')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('changes nothing when the runtime cannot be emitted', () => {
|
|
86
|
+
const structure = makeStructure({ withExtractedResources: false })
|
|
87
|
+
|
|
88
|
+
PageArrival.remountPageOnArrival(structure)
|
|
89
|
+
|
|
90
|
+
expect(exportCode(structure)).toBe('export default Customers;')
|
|
91
|
+
expect(structure.dependencies).toEqual({})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('changes nothing when there is no plain default export to wrap', () => {
|
|
95
|
+
const withoutExport = makeStructure({ exportContent: null })
|
|
96
|
+
PageArrival.remountPageOnArrival(withoutExport)
|
|
97
|
+
expect(withoutExport.dependencies).toEqual({})
|
|
98
|
+
expect(withoutExport.options.extractedResources).toEqual({})
|
|
99
|
+
|
|
100
|
+
const wrappedElsewhere = makeStructure({
|
|
101
|
+
exportContent: types.exportDefaultDeclaration(
|
|
102
|
+
types.callExpression(types.identifier('withLayout'), [types.identifier('Customers')])
|
|
103
|
+
),
|
|
104
|
+
})
|
|
105
|
+
PageArrival.remountPageOnArrival(wrappedElsewhere)
|
|
106
|
+
expect(exportCode(wrappedElsewhere)).toBe('export default withLayout(Customers);')
|
|
107
|
+
expect(wrappedElsewhere.dependencies).toEqual({})
|
|
108
|
+
})
|
|
109
|
+
})
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { transformSync } from '@babel/core'
|
|
2
|
+
import { PageArrival } from '../../src'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Runs the emitted `utils/page-arrival.js` against a one-component hook
|
|
6
|
+
* runtime and a scriptable `next/router`, and reads the key the page is
|
|
7
|
+
* rendered with — a new key is a remount, which is what re-runs everything the
|
|
8
|
+
* page computes on arrival.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type Handler = (...args: unknown[]) => void
|
|
12
|
+
|
|
13
|
+
const createFakeRouter = (pathname: string) => {
|
|
14
|
+
const handlers: Record<string, Handler[]> = {}
|
|
15
|
+
return {
|
|
16
|
+
pathname,
|
|
17
|
+
handlers,
|
|
18
|
+
events: {
|
|
19
|
+
on: (event: string, handler: Handler) => {
|
|
20
|
+
handlers[event] = [...(handlers[event] || []), handler]
|
|
21
|
+
},
|
|
22
|
+
off: (event: string, handler: Handler) => {
|
|
23
|
+
handlers[event] = (handlers[event] || []).filter((candidate) => candidate !== handler)
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
emit(event: string, ...args: unknown[]) {
|
|
27
|
+
;(handlers[event] || []).slice().forEach((handler) => handler(...args))
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type FakeRouter = ReturnType<typeof createFakeRouter>
|
|
33
|
+
|
|
34
|
+
const loadWrapper = (router: FakeRouter) => {
|
|
35
|
+
const source = PageArrival.generatePageArrivalRuntime()
|
|
36
|
+
.replace(/^import .*$/gm, '')
|
|
37
|
+
.replace('export default function', 'function')
|
|
38
|
+
const code = transformSync(source, {
|
|
39
|
+
presets: ['@babel/preset-react'],
|
|
40
|
+
babelrc: false,
|
|
41
|
+
configFile: false,
|
|
42
|
+
})?.code
|
|
43
|
+
|
|
44
|
+
// One mounted component: state slots survive re-renders, an effect with
|
|
45
|
+
// `[]` runs on the first render only and its cleanup on unmount.
|
|
46
|
+
const states: unknown[] = []
|
|
47
|
+
const cleanups: Array<() => void> = []
|
|
48
|
+
let stateCursor = 0
|
|
49
|
+
let effectCursor = 0
|
|
50
|
+
let onUpdate: () => void = () => undefined
|
|
51
|
+
|
|
52
|
+
const React = {
|
|
53
|
+
createElement: (type: unknown, config: { key?: unknown } & Record<string, unknown>) => ({
|
|
54
|
+
type,
|
|
55
|
+
key: config.key,
|
|
56
|
+
props: config,
|
|
57
|
+
}),
|
|
58
|
+
}
|
|
59
|
+
const useState = (initial: unknown) => {
|
|
60
|
+
const slot = stateCursor++
|
|
61
|
+
if (!(slot in states)) {
|
|
62
|
+
states[slot] = initial
|
|
63
|
+
}
|
|
64
|
+
const setState = (next: unknown) => {
|
|
65
|
+
states[slot] =
|
|
66
|
+
typeof next === 'function' ? (next as (v: unknown) => unknown)(states[slot]) : next
|
|
67
|
+
onUpdate()
|
|
68
|
+
}
|
|
69
|
+
return [states[slot], setState]
|
|
70
|
+
}
|
|
71
|
+
const useEffect = (effect: () => (() => void) | void) => {
|
|
72
|
+
const slot = effectCursor++
|
|
73
|
+
if (!(slot in cleanups)) {
|
|
74
|
+
cleanups[slot] = (effect() as () => void) || (() => undefined)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// tslint:disable-next-line:function-constructor
|
|
79
|
+
const factory = new Function(
|
|
80
|
+
'React',
|
|
81
|
+
'useState',
|
|
82
|
+
'useEffect',
|
|
83
|
+
'Router',
|
|
84
|
+
`${code}\nreturn remountOnPageArrival`
|
|
85
|
+
)
|
|
86
|
+
const remountOnPageArrival = factory(React, useState, useEffect, router)
|
|
87
|
+
|
|
88
|
+
function Customers(): null {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
const Wrapped = remountOnPageArrival(Customers)
|
|
92
|
+
|
|
93
|
+
let updates = 0
|
|
94
|
+
const render = () => {
|
|
95
|
+
stateCursor = 0
|
|
96
|
+
effectCursor = 0
|
|
97
|
+
return Wrapped({ title: 'Customers' }) as { type: unknown; key: unknown; props: object }
|
|
98
|
+
}
|
|
99
|
+
onUpdate = () => {
|
|
100
|
+
updates++
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
Wrapped,
|
|
105
|
+
Customers,
|
|
106
|
+
render,
|
|
107
|
+
unmount: () => cleanups.forEach((cleanup) => cleanup()),
|
|
108
|
+
updates: () => updates,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const navigate = (router: FakeRouter, to: string, options: { shallow: boolean }) => {
|
|
113
|
+
router.emit('routeChangeStart', to, options)
|
|
114
|
+
router.pathname = to.split('?')[0]
|
|
115
|
+
router.emit('routeChangeComplete', to, options)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
describe('page-arrival runtime', () => {
|
|
119
|
+
it('renders the page with its props and a stable first key', () => {
|
|
120
|
+
const router = createFakeRouter('/customers')
|
|
121
|
+
const page = loadWrapper(router)
|
|
122
|
+
|
|
123
|
+
const element = page.render()
|
|
124
|
+
|
|
125
|
+
expect(element.type).toBe(page.Customers)
|
|
126
|
+
expect(element.key).toBe(0)
|
|
127
|
+
expect(element.props).toMatchObject({ title: 'Customers' })
|
|
128
|
+
expect(page.render().key).toBe(0)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('remounts the page when a navigation lands on the page already on screen', () => {
|
|
132
|
+
const router = createFakeRouter('/customers')
|
|
133
|
+
const page = loadWrapper(router)
|
|
134
|
+
page.render()
|
|
135
|
+
|
|
136
|
+
navigate(router, '/customers', { shallow: false })
|
|
137
|
+
expect(page.render().key).toBe(1)
|
|
138
|
+
|
|
139
|
+
navigate(router, '/customers?status=open', { shallow: false })
|
|
140
|
+
expect(page.render().key).toBe(2)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('keeps the page as it is for shallow navigations', () => {
|
|
144
|
+
const router = createFakeRouter('/customers')
|
|
145
|
+
const page = loadWrapper(router)
|
|
146
|
+
page.render()
|
|
147
|
+
|
|
148
|
+
navigate(router, '/customers?page=2', { shallow: true })
|
|
149
|
+
|
|
150
|
+
expect(page.updates()).toBe(0)
|
|
151
|
+
expect(page.render().key).toBe(0)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('does not count the navigation that brought the page in', () => {
|
|
155
|
+
const router = createFakeRouter('/customers')
|
|
156
|
+
const page = loadWrapper(router)
|
|
157
|
+
page.render()
|
|
158
|
+
|
|
159
|
+
// The page mounted while this navigation was in flight, so it only sees
|
|
160
|
+
// the completion.
|
|
161
|
+
router.emit('routeChangeComplete', '/customers', { shallow: false })
|
|
162
|
+
|
|
163
|
+
expect(page.updates()).toBe(0)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('ignores a navigation that ends on another route', () => {
|
|
167
|
+
const router = createFakeRouter('/customers')
|
|
168
|
+
const page = loadWrapper(router)
|
|
169
|
+
page.render()
|
|
170
|
+
|
|
171
|
+
navigate(router, '/', { shallow: false })
|
|
172
|
+
|
|
173
|
+
expect(page.updates()).toBe(0)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('forgets a navigation that failed or was cancelled', () => {
|
|
177
|
+
const router = createFakeRouter('/customers')
|
|
178
|
+
const page = loadWrapper(router)
|
|
179
|
+
page.render()
|
|
180
|
+
|
|
181
|
+
router.emit('routeChangeStart', '/customers?id=1', { shallow: false })
|
|
182
|
+
router.emit('routeChangeError', new Error('cancelled'), '/customers?id=1', { shallow: false })
|
|
183
|
+
router.emit('routeChangeComplete', '/customers?id=1', { shallow: true })
|
|
184
|
+
|
|
185
|
+
expect(page.updates()).toBe(0)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it('stops listening once the page unmounts', () => {
|
|
189
|
+
const router = createFakeRouter('/customers')
|
|
190
|
+
const page = loadWrapper(router)
|
|
191
|
+
page.render()
|
|
192
|
+
|
|
193
|
+
expect(router.handlers.routeChangeStart).toHaveLength(1)
|
|
194
|
+
expect(router.handlers.routeChangeComplete).toHaveLength(1)
|
|
195
|
+
expect(router.handlers.routeChangeError).toHaveLength(1)
|
|
196
|
+
|
|
197
|
+
page.unmount()
|
|
198
|
+
|
|
199
|
+
expect(router.handlers.routeChangeStart).toHaveLength(0)
|
|
200
|
+
expect(router.handlers.routeChangeComplete).toHaveLength(0)
|
|
201
|
+
expect(router.handlers.routeChangeError).toHaveLength(0)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('names the wrapper after the page for React DevTools', () => {
|
|
205
|
+
const page = loadWrapper(createFakeRouter('/customers'))
|
|
206
|
+
|
|
207
|
+
expect(page.Wrapped.displayName).toBe('PageArrival(Customers)')
|
|
208
|
+
})
|
|
209
|
+
})
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* tslint:disable:function-constructor */
|
|
2
|
+
import type { UIDLAuthentication } from '@teleporthq/teleport-types'
|
|
3
|
+
import {
|
|
4
|
+
generateTableAccessHelperCode,
|
|
5
|
+
resolveTrustedReaderRoles,
|
|
6
|
+
} from '../../src/utils/table-access'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Who may read the store's private tables (accounts, sent emails, orders,
|
|
10
|
+
* gift cards …) from a browser: the roles the generated admin panel's FOLDER
|
|
11
|
+
* admits. Some admin pages also admit another role (staff screens: the
|
|
12
|
+
* dashboard, a table's list and views), and a role on one of those pages must
|
|
13
|
+
* never become a reader of every protected table.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const authWith = (
|
|
17
|
+
pageProtection: UIDLAuthentication['pageProtection'],
|
|
18
|
+
folderProtection: UIDLAuthentication['folderProtection']
|
|
19
|
+
): UIDLAuthentication => ({
|
|
20
|
+
enabled: true,
|
|
21
|
+
dataSourceId: 'ds-1',
|
|
22
|
+
dataSourceType: 'teleport',
|
|
23
|
+
passwordAuthEnabled: true,
|
|
24
|
+
providers: [],
|
|
25
|
+
roles: ['admin', 'staff', 'user'],
|
|
26
|
+
tables: {},
|
|
27
|
+
pageProtection,
|
|
28
|
+
folderProtection,
|
|
29
|
+
authPages: {},
|
|
30
|
+
callbackBaseUrl: '/api/auth/callback',
|
|
31
|
+
envKeys: {},
|
|
32
|
+
customUserProperties: [],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const page = (route: string, allowedRoles: string[]) => ({
|
|
36
|
+
requiresAuth: true,
|
|
37
|
+
allowedRoles,
|
|
38
|
+
pageName: route.split('/').pop() || 'home',
|
|
39
|
+
route,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const folder = (
|
|
43
|
+
folderName: string,
|
|
44
|
+
allowedRoles: string[],
|
|
45
|
+
parentId: string | null,
|
|
46
|
+
children: Record<string, 'page' | 'folder'>
|
|
47
|
+
) => ({ requiresAuth: true, allowedRoles, folderName, parentId, children })
|
|
48
|
+
|
|
49
|
+
// An admin panel whose folder admits admins, some of whose screens (and their
|
|
50
|
+
// entity folder) admit staff too, and whose built-in entities stay admin only.
|
|
51
|
+
const STAFF_SCREENS_AUTH = authWith(
|
|
52
|
+
{
|
|
53
|
+
'p-dashboard': page('/admin/dashboard', ['admin', 'staff']),
|
|
54
|
+
'p-tasks': page('/admin/tasks', ['admin', 'staff']),
|
|
55
|
+
'p-tasks-create': page('/admin/tasks/create', ['admin', 'staff']),
|
|
56
|
+
'p-tasks-board': page('/admin/tasks/board', ['admin', 'staff']),
|
|
57
|
+
'p-users': page('/admin/users', ['admin']),
|
|
58
|
+
'p-sent-emails': page('/admin/sent-emails', ['admin']),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
'f-admin': folder('admin-panel', ['admin'], 'pages', {
|
|
62
|
+
'p-dashboard': 'page',
|
|
63
|
+
'f-tasks': 'folder',
|
|
64
|
+
'f-users': 'folder',
|
|
65
|
+
'f-sent-emails': 'folder',
|
|
66
|
+
}),
|
|
67
|
+
'f-tasks': folder('tasks', ['admin', 'staff'], 'f-admin', {
|
|
68
|
+
'p-tasks': 'page',
|
|
69
|
+
'p-tasks-create': 'page',
|
|
70
|
+
'p-tasks-board': 'page',
|
|
71
|
+
}),
|
|
72
|
+
'f-users': folder('users', ['admin'], 'f-admin', { 'p-users': 'page' }),
|
|
73
|
+
'f-sent-emails': folder('sent-emails', ['admin'], 'f-admin', { 'p-sent-emails': 'page' }),
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
describe('resolveTrustedReaderRoles', () => {
|
|
78
|
+
it("trusts the admin folder's roles, never the staff an admin page admits", () => {
|
|
79
|
+
expect(resolveTrustedReaderRoles(STAFF_SCREENS_AUTH)).toEqual(['admin'])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('answers what it always did for an admin panel without staff pages', () => {
|
|
83
|
+
const storeAuth = authWith(
|
|
84
|
+
{
|
|
85
|
+
'p-dashboard': page('/admin/dashboard', ['admin']),
|
|
86
|
+
'p-orders': page('/admin/orders', ['admin']),
|
|
87
|
+
},
|
|
88
|
+
{ 'f-admin': folder('admin-panel', ['admin'], 'pages', { 'p-dashboard': 'page' }) }
|
|
89
|
+
)
|
|
90
|
+
expect(resolveTrustedReaderRoles(storeAuth)).toEqual(['admin'])
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('falls back to the roles EVERY admin page admits when the folder records none', () => {
|
|
94
|
+
const pages = STAFF_SCREENS_AUTH.pageProtection
|
|
95
|
+
expect(resolveTrustedReaderRoles(authWith(pages, {}))).toEqual(['admin'])
|
|
96
|
+
const roleless = authWith(pages, {
|
|
97
|
+
'f-admin': folder('admin-panel', [], 'pages', { 'p-dashboard': 'page' }),
|
|
98
|
+
})
|
|
99
|
+
expect(resolveTrustedReaderRoles(roleless)).toEqual(['admin'])
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('ignores pages outside the admin panel, and trusts nobody without one', () => {
|
|
103
|
+
const noPanel = authWith(
|
|
104
|
+
{
|
|
105
|
+
'p-profile': page('/profile', ['user']),
|
|
106
|
+
'p-administration': page('/administration', ['staff']),
|
|
107
|
+
},
|
|
108
|
+
{ 'f-members': folder('members', ['user'], null, {}) }
|
|
109
|
+
)
|
|
110
|
+
expect(resolveTrustedReaderRoles(noPanel)).toEqual([])
|
|
111
|
+
expect(resolveTrustedReaderRoles(undefined)).toEqual([])
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('the emitted guard with those roles', () => {
|
|
116
|
+
const bootGuard = (trustedReaderRoles: string[]) => {
|
|
117
|
+
let session: { role: string } | null = null
|
|
118
|
+
const guardRead = new Function(
|
|
119
|
+
'process',
|
|
120
|
+
'__tqSessionToken',
|
|
121
|
+
`${generateTableAccessHelperCode({ trustedReaderRoles })}
|
|
122
|
+
return __taGuardRead`
|
|
123
|
+
)({ env: { NEXTAUTH_SECRET: 'server-secret' } }, async () =>
|
|
124
|
+
session ? { sub: 'u1', role: session.role } : null
|
|
125
|
+
) as (req: unknown, tableName: string, rawQuery: string | null) => Promise<unknown>
|
|
126
|
+
return async (role: string, tableName: string) => {
|
|
127
|
+
session = { role }
|
|
128
|
+
return guardRead({ headers: {} }, tableName, null)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
it('refuses staff admitted to some admin pages every account, email and order', async () => {
|
|
133
|
+
const readAs = bootGuard(resolveTrustedReaderRoles(STAFF_SCREENS_AUTH))
|
|
134
|
+
for (const table of [
|
|
135
|
+
'users',
|
|
136
|
+
'teleport_sent_emails',
|
|
137
|
+
'teleport_orders',
|
|
138
|
+
'teleport_gift_cards',
|
|
139
|
+
]) {
|
|
140
|
+
expect(await readAs('staff', table)).toMatchObject({ status: 403 })
|
|
141
|
+
expect(await readAs('admin', table)).toBeNull()
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
})
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -31,11 +31,12 @@ import * as RichTextContent from './utils/rich-text-content';
|
|
|
31
31
|
import * as RichTextContentCodegen from './utils/rich-text-content-codegen';
|
|
32
32
|
import * as DataCache from './cache';
|
|
33
33
|
import * as PageRevalidate from './page-revalidate';
|
|
34
|
+
import * as PageArrival from './page-arrival';
|
|
34
35
|
import * as ScrollSceneRuntime from './scroll-scene';
|
|
35
36
|
import * as MotionRuntime from './motion-runtime';
|
|
36
37
|
import * as PageTransition from './page-transition';
|
|
37
38
|
import * as StateBindings from './state-bindings';
|
|
38
39
|
import * as WebPush from './utils/web-push';
|
|
39
40
|
import * as InlineScriptErrorGuard from './utils/inline-script-error-guard';
|
|
40
|
-
export { Constants, StringUtils, UIDLUtils, GenericUtils, LocalImports, JSIdentifiers, ASTScope, ASTStatementOrder, ASTEffectCleanup, RoutePaths, LayoutTopology, HtmlContentModel, StyleDeclarations, StorefrontTax, ProductDiscounts, ProductRatings, RegionalPricing, DiscountEngine, ProductOptions, CartLinePricing, CartCurrency, TableAccess, ContentTables, SessionCookieResolver, SubscriptionAccess, FontPreconnect, EmailDate, RichTextEmbeds, RichTextEmbedsCodegen, RichTextContent, RichTextContentCodegen, DataCache, PageRevalidate, ScrollSceneRuntime, MotionRuntime, PageTransition, StateBindings, WebPush, InlineScriptErrorGuard, };
|
|
41
|
+
export { Constants, StringUtils, UIDLUtils, GenericUtils, LocalImports, JSIdentifiers, ASTScope, ASTStatementOrder, ASTEffectCleanup, RoutePaths, LayoutTopology, HtmlContentModel, StyleDeclarations, StorefrontTax, ProductDiscounts, ProductRatings, RegionalPricing, DiscountEngine, ProductOptions, CartLinePricing, CartCurrency, TableAccess, ContentTables, SessionCookieResolver, SubscriptionAccess, FontPreconnect, EmailDate, RichTextEmbeds, RichTextEmbedsCodegen, RichTextContent, RichTextContentCodegen, DataCache, PageRevalidate, PageArrival, ScrollSceneRuntime, MotionRuntime, PageTransition, StateBindings, WebPush, InlineScriptErrorGuard, };
|
|
41
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[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,MAAM,2BAA2B,CAAA;AAC5D,OAAO,KAAK,sBAAsB,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,SAAS,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,kBAAkB,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,sBAAsB,MAAM,mCAAmC,CAAA;AAE3E,OAAO,EACL,SAAS,EACT,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,EACZ,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,aAAa,EACb,OAAO,EACP,sBAAsB,GACvB,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.InlineScriptErrorGuard = exports.WebPush = exports.StateBindings = exports.PageTransition = exports.MotionRuntime = exports.ScrollSceneRuntime = exports.PageRevalidate = exports.DataCache = exports.RichTextContentCodegen = exports.RichTextContent = exports.RichTextEmbedsCodegen = exports.RichTextEmbeds = exports.EmailDate = exports.FontPreconnect = exports.SubscriptionAccess = exports.SessionCookieResolver = exports.ContentTables = exports.TableAccess = exports.CartCurrency = exports.CartLinePricing = exports.ProductOptions = exports.DiscountEngine = exports.RegionalPricing = exports.ProductRatings = exports.ProductDiscounts = exports.StorefrontTax = exports.StyleDeclarations = exports.HtmlContentModel = exports.LayoutTopology = exports.RoutePaths = exports.ASTEffectCleanup = exports.ASTStatementOrder = exports.ASTScope = exports.JSIdentifiers = exports.LocalImports = exports.GenericUtils = exports.UIDLUtils = exports.StringUtils = exports.Constants = void 0;
|
|
26
|
+
exports.InlineScriptErrorGuard = exports.WebPush = exports.StateBindings = exports.PageTransition = exports.MotionRuntime = exports.ScrollSceneRuntime = exports.PageArrival = exports.PageRevalidate = exports.DataCache = exports.RichTextContentCodegen = exports.RichTextContent = exports.RichTextEmbedsCodegen = exports.RichTextEmbeds = exports.EmailDate = exports.FontPreconnect = exports.SubscriptionAccess = exports.SessionCookieResolver = exports.ContentTables = exports.TableAccess = exports.CartCurrency = exports.CartLinePricing = exports.ProductOptions = exports.DiscountEngine = exports.RegionalPricing = exports.ProductRatings = exports.ProductDiscounts = exports.StorefrontTax = exports.StyleDeclarations = exports.HtmlContentModel = exports.LayoutTopology = exports.RoutePaths = exports.ASTEffectCleanup = exports.ASTStatementOrder = exports.ASTScope = exports.JSIdentifiers = exports.LocalImports = exports.GenericUtils = exports.UIDLUtils = exports.StringUtils = exports.Constants = void 0;
|
|
27
27
|
var Constants = __importStar(require("./constants"));
|
|
28
28
|
exports.Constants = Constants;
|
|
29
29
|
var StringUtils = __importStar(require("./utils/string-utils"));
|
|
@@ -90,6 +90,8 @@ var DataCache = __importStar(require("./cache"));
|
|
|
90
90
|
exports.DataCache = DataCache;
|
|
91
91
|
var PageRevalidate = __importStar(require("./page-revalidate"));
|
|
92
92
|
exports.PageRevalidate = PageRevalidate;
|
|
93
|
+
var PageArrival = __importStar(require("./page-arrival"));
|
|
94
|
+
exports.PageArrival = PageArrival;
|
|
93
95
|
var ScrollSceneRuntime = __importStar(require("./scroll-scene"));
|
|
94
96
|
exports.ScrollSceneRuntime = ScrollSceneRuntime;
|
|
95
97
|
var MotionRuntime = __importStar(require("./motion-runtime"));
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAwC;AA0CtC,8BAAS;AAzCX,gEAAmD;AA0CjD,kCAAW;AAzCb,4DAA+C;AA0C7C,8BAAS;AAzCX,4DAA+C;AA0C7C,oCAAY;AAzCd,kEAAqD;AA0CnD,oCAAY;AAzCd,oEAAuD;AA0CrD,sCAAa;AAzCf,0DAA6C;AA0C3C,4BAAQ;AAzCV,6EAAgE;AA0C9D,8CAAiB;AAzCnB,2EAA8D;AA0C5D,4CAAgB;AAzClB,8DAAiD;AA0C/C,gCAAU;AAzCZ,sEAAyD;AA0CvD,wCAAc;AAzChB,2EAA8D;AA0C5D,4CAAgB;AAzClB,4EAA+D;AA0C7D,8CAAiB;AAzCnB,oEAAuD;AA0CrD,sCAAa;AAzCf,0EAA6D;AA0C3D,4CAAgB;AAzClB,sEAAyD;AA0CvD,wCAAc;AAzChB,wEAA2D;AA0CzD,0CAAe;AAzCjB,sEAAyD;AA0CvD,wCAAc;AAzChB,sEAAyD;AA0CvD,wCAAc;AAzChB,yEAA4D;AA0C1D,0CAAe;AAzCjB,kEAAqD;AA0CnD,oCAAY;AAzCd,gEAAmD;AA0CjD,kCAAW;AAzCb,oEAAuD;AA0CrD,sCAAa;AAzCf,qFAAwE;AA0CtE,sDAAqB;AAzCvB,8EAAiE;AA0C/D,gDAAkB;AAzCpB,sEAAyD;AA0CvD,wCAAc;AAzChB,4DAA+C;AA0C7C,8BAAS;AAzCX,uEAA0D;AA0CxD,wCAAc;AAzChB,sFAAyE;AA0CvE,sDAAqB;AAzCvB,yEAA4D;AA0C1D,0CAAe;AAzCjB,wFAA2E;AA0CzE,wDAAsB;AAzCxB,iDAAoC;AA0ClC,8BAAS;AAzCX,gEAAmD;AA0CjD,wCAAc;AAzChB,0DAA6C;AA0C3C,kCAAW;AAzCb,iEAAoD;AA0ClD,gDAAkB;AAzCpB,8DAAiD;AA0C/C,sCAAa;AAzCf,gEAAmD;AA0CjD,wCAAc;AAzChB,8DAAiD;AA0C/C,sCAAa;AAzCf,wDAA2C;AA0CzC,0BAAO;AAzCT,wFAA2E;AA0CzE,wDAAsB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the generated page-arrival wrapper lives and what pages import it as.
|
|
3
|
+
*
|
|
4
|
+
* Lives in `teleport-shared` because two page plugins in two packages ask for
|
|
5
|
+
* it — the workflows plugin (page-load and element-visible triggers) and the
|
|
6
|
+
* state data-source plugin (state seeded from a data source) — and they must
|
|
7
|
+
* emit the same file under the same name.
|
|
8
|
+
*/
|
|
9
|
+
/** Folder of the emitted runtime, relative to the generated project root. */
|
|
10
|
+
export declare const PAGE_ARRIVAL_DIR: string[];
|
|
11
|
+
export declare const PAGE_ARRIVAL_FILE_NAME = "page-arrival";
|
|
12
|
+
/** The default export of the runtime, as the page module imports it. */
|
|
13
|
+
export declare const PAGE_ARRIVAL_WRAPPER = "remountOnPageArrival";
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/page-arrival/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,UAAY,CAAA;AACzC,eAAO,MAAM,sBAAsB,iBAAiB,CAAA;AAEpD,wEAAwE;AACxE,eAAO,MAAM,oBAAoB,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Where the generated page-arrival wrapper lives and what pages import it as.
|
|
4
|
+
*
|
|
5
|
+
* Lives in `teleport-shared` because two page plugins in two packages ask for
|
|
6
|
+
* it — the workflows plugin (page-load and element-visible triggers) and the
|
|
7
|
+
* state data-source plugin (state seeded from a data source) — and they must
|
|
8
|
+
* emit the same file under the same name.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PAGE_ARRIVAL_WRAPPER = exports.PAGE_ARRIVAL_FILE_NAME = exports.PAGE_ARRIVAL_DIR = void 0;
|
|
12
|
+
/** Folder of the emitted runtime, relative to the generated project root. */
|
|
13
|
+
exports.PAGE_ARRIVAL_DIR = ['utils'];
|
|
14
|
+
exports.PAGE_ARRIVAL_FILE_NAME = 'page-arrival';
|
|
15
|
+
/** The default export of the runtime, as the page module imports it. */
|
|
16
|
+
exports.PAGE_ARRIVAL_WRAPPER = 'remountOnPageArrival';
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/page-arrival/constants.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,6EAA6E;AAChE,QAAA,gBAAgB,GAAG,CAAC,OAAO,CAAC,CAAA;AAC5B,QAAA,sBAAsB,GAAG,cAAc,CAAA;AAEpD,wEAAwE;AAC3D,QAAA,oBAAoB,GAAG,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/page-arrival/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./runtime"), exports);
|
|
19
|
+
__exportStar(require("./page-export"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/page-arrival/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,4CAAyB;AACzB,gDAA6B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentStructure } from '@teleporthq/teleport-types';
|
|
2
|
+
/**
|
|
3
|
+
* Makes the page start fresh on every arrival — see `generatePageArrivalRuntime`
|
|
4
|
+
* for why Next.js does not do it on its own.
|
|
5
|
+
*
|
|
6
|
+
* Rewrites `export default Page` into `export default remountOnPageArrival(Page)`,
|
|
7
|
+
* imports the wrapper and emits it once per project. Several plugins may ask for
|
|
8
|
+
* the same page, so a page that is already wrapped is left alone. Nothing is
|
|
9
|
+
* changed when the page has no plain default export to wrap, or when the
|
|
10
|
+
* generation has nowhere to emit the runtime — an import of a file that is never
|
|
11
|
+
* written would break the build.
|
|
12
|
+
*/
|
|
13
|
+
export declare const remountPageOnArrival: (structure: ComponentStructure) => void;
|
|
14
|
+
//# sourceMappingURL=page-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-export.d.ts","sourceRoot":"","sources":["../../../src/page-arrival/page-export.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAY,MAAM,4BAA4B,CAAA;AAazE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,cAAe,kBAAkB,KAAG,IAgCpE,CAAA"}
|