@antelopejs/dms-api 0.1.6 → 0.2.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/README.md +99 -8
- package/dist/automation/get-api-health.js +4 -3
- package/dist/automation/get-api-health.js.map +1 -1
- package/dist/automation/route-unhealthy.js +2 -2
- package/dist/automation/route-unhealthy.js.map +1 -1
- package/dist/automation/scope.d.ts +0 -1
- package/dist/automation/scope.js +0 -7
- package/dist/automation/scope.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.js +15 -9
- package/dist/config.js.map +1 -1
- package/dist/db/models/request_log.model.d.ts +37 -2
- package/dist/db/models/request_log.model.js +130 -35
- package/dist/db/models/request_log.model.js.map +1 -1
- package/dist/db/models/request_log.search.d.ts +5 -0
- package/dist/db/models/request_log.search.js +35 -0
- package/dist/db/models/request_log.search.js.map +1 -0
- package/dist/db/models/request_log.status.d.ts +5 -0
- package/dist/db/models/request_log.status.js +9 -0
- package/dist/db/models/request_log.status.js.map +1 -0
- package/dist/db/models/routes.model.d.ts +1 -0
- package/dist/db/models/routes.model.js +5 -1
- package/dist/db/models/routes.model.js.map +1 -1
- package/dist/db/models/routes_statistics.model.js +1 -1
- package/dist/db/models/routes_statistics.model.js.map +1 -1
- package/dist/db/tables/api_settings.table.d.ts +1 -0
- package/dist/db/tables/api_settings.table.js +4 -0
- package/dist/db/tables/api_settings.table.js.map +1 -1
- package/dist/db/tables/request_log.table.d.ts +18 -3
- package/dist/db/tables/request_log.table.js +34 -1
- package/dist/db/tables/request_log.table.js.map +1 -1
- package/dist/db/tables/routes.table.d.ts +1 -2
- package/dist/db/tables/routes.table.js.map +1 -1
- package/dist/db/tables/routes_statistics.table.d.ts +4 -3
- package/dist/db/tables/routes_statistics.table.js +5 -1
- package/dist/db/tables/routes_statistics.table.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/memo.d.ts +5 -0
- package/dist/memo.js +36 -0
- package/dist/memo.js.map +1 -0
- package/dist/pages/blocks.d.ts +3 -0
- package/dist/pages/blocks.js +31 -0
- package/dist/pages/blocks.js.map +1 -0
- package/dist/pages/displays.d.ts +7 -0
- package/dist/pages/displays.js +23 -0
- package/dist/pages/displays.js.map +1 -0
- package/dist/pages/index.d.ts +5 -2
- package/dist/pages/index.js +5 -2
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/logs.d.ts +18 -0
- package/dist/pages/logs.js +112 -0
- package/dist/pages/logs.js.map +1 -0
- package/dist/pages/module.d.ts +3 -0
- package/dist/pages/module.js +102 -6
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.d.ts +14 -0
- package/dist/pages/overview.js +215 -0
- package/dist/pages/overview.js.map +1 -0
- package/dist/pages/period.d.ts +9 -0
- package/dist/pages/period.js +24 -0
- package/dist/pages/period.js.map +1 -0
- package/dist/pages/request-table.d.ts +11 -0
- package/dist/pages/request-table.js +187 -0
- package/dist/pages/request-table.js.map +1 -0
- package/dist/pages/routes.d.ts +15 -0
- package/dist/pages/routes.js +269 -0
- package/dist/pages/routes.js.map +1 -0
- package/dist/pages/scope-chip.d.ts +9 -0
- package/dist/pages/scope-chip.js +28 -0
- package/dist/pages/scope-chip.js.map +1 -0
- package/dist/pages/{logs/page.d.ts → settings.d.ts} +3 -3
- package/dist/pages/settings.js +218 -0
- package/dist/pages/settings.js.map +1 -0
- package/dist/pages/toolbar.d.ts +9 -0
- package/dist/pages/toolbar.js +33 -0
- package/dist/pages/toolbar.js.map +1 -0
- package/dist/realtime.d.ts +2 -0
- package/dist/realtime.js +21 -0
- package/dist/realtime.js.map +1 -0
- package/dist/routes/index.d.ts +2 -2
- package/dist/routes/index.js +2 -2
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/logs.d.ts +173 -2
- package/dist/routes/logs.js +177 -86
- package/dist/routes/logs.js.map +1 -1
- package/dist/routes/overview.d.ts +27 -0
- package/dist/routes/overview.js +131 -0
- package/dist/routes/overview.js.map +1 -0
- package/dist/routes/routes.d.ts +92 -28
- package/dist/routes/routes.js +165 -97
- package/dist/routes/routes.js.map +1 -1
- package/dist/routes/settings.d.ts +16 -11
- package/dist/routes/settings.js +62 -54
- package/dist/routes/settings.js.map +1 -1
- package/dist/routes/tester.d.ts +7 -0
- package/dist/routes/tester.js +34 -0
- package/dist/routes/tester.js.map +1 -0
- package/dist/services/activity.d.ts +49 -0
- package/dist/services/activity.js +207 -0
- package/dist/services/activity.js.map +1 -0
- package/dist/services/aggregate-cache.d.ts +3 -0
- package/dist/services/aggregate-cache.js +16 -0
- package/dist/services/aggregate-cache.js.map +1 -0
- package/dist/services/api-origin.d.ts +1 -0
- package/dist/services/api-origin.js +9 -0
- package/dist/services/api-origin.js.map +1 -0
- package/dist/services/attention.d.ts +45 -0
- package/dist/services/attention.js +203 -0
- package/dist/services/attention.js.map +1 -0
- package/dist/services/composed-text.d.ts +6 -0
- package/dist/services/composed-text.js +23 -0
- package/dist/services/composed-text.js.map +1 -0
- package/dist/services/health-rules.d.ts +49 -0
- package/dist/services/health-rules.js +233 -0
- package/dist/services/health-rules.js.map +1 -0
- package/dist/services/index.d.ts +1 -3
- package/dist/services/index.js +3 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/introspection/decorators.d.ts +14 -0
- package/dist/services/introspection/decorators.js +192 -0
- package/dist/services/introspection/decorators.js.map +1 -0
- package/dist/services/introspection/errors.js +4 -4
- package/dist/services/introspection/errors.js.map +1 -1
- package/dist/services/introspection/index.d.ts +6 -8
- package/dist/services/introspection/index.js +96 -32
- package/dist/services/introspection/index.js.map +1 -1
- package/dist/services/introspection/probe.d.ts +2 -1
- package/dist/services/introspection/probe.js +11 -0
- package/dist/services/introspection/probe.js.map +1 -1
- package/dist/services/links.d.ts +25 -0
- package/dist/services/links.js +72 -0
- package/dist/services/links.js.map +1 -0
- package/dist/services/live-feed.d.ts +6 -0
- package/dist/services/live-feed.js +18 -0
- package/dist/services/live-feed.js.map +1 -0
- package/dist/services/live.d.ts +16 -0
- package/dist/services/live.js +32 -0
- package/dist/services/live.js.map +1 -0
- package/dist/services/overview.d.ts +122 -0
- package/dist/services/overview.js +324 -0
- package/dist/services/overview.js.map +1 -0
- package/dist/services/period.d.ts +0 -9
- package/dist/services/period.js +5 -52
- package/dist/services/period.js.map +1 -1
- package/dist/services/request-log/access.d.ts +5 -0
- package/dist/services/request-log/access.js +21 -0
- package/dist/services/request-log/access.js.map +1 -0
- package/dist/services/request-log/capture.d.ts +30 -0
- package/dist/services/request-log/capture.js +216 -39
- package/dist/services/request-log/capture.js.map +1 -1
- package/dist/services/request-log/list.d.ts +36 -0
- package/dist/services/request-log/list.js +201 -0
- package/dist/services/request-log/list.js.map +1 -0
- package/dist/services/request-log/read.d.ts +15 -2
- package/dist/services/request-log/read.js +47 -4
- package/dist/services/request-log/read.js.map +1 -1
- package/dist/services/request-log/redaction.d.ts +16 -3
- package/dist/services/request-log/redaction.js +149 -27
- package/dist/services/request-log/redaction.js.map +1 -1
- package/dist/services/request-log/util.d.ts +10 -3
- package/dist/services/request-log/util.js +39 -22
- package/dist/services/request-log/util.js.map +1 -1
- package/dist/services/route-catalog.d.ts +62 -0
- package/dist/services/route-catalog.js +163 -0
- package/dist/services/route-catalog.js.map +1 -0
- package/dist/services/route-contract.d.ts +66 -0
- package/dist/services/route-contract.js +266 -0
- package/dist/services/route-contract.js.map +1 -0
- package/dist/services/route-health.d.ts +35 -0
- package/dist/services/route-health.js +179 -0
- package/dist/services/route-health.js.map +1 -0
- package/dist/services/route-statistics.d.ts +68 -0
- package/dist/services/route-statistics.js +277 -0
- package/dist/services/route-statistics.js.map +1 -0
- package/dist/services/routes-sync.d.ts +7 -3
- package/dist/services/routes-sync.js +96 -20
- package/dist/services/routes-sync.js.map +1 -1
- package/dist/services/scope.d.ts +0 -1
- package/dist/services/scope.js +4 -17
- package/dist/services/scope.js.map +1 -1
- package/dist/services/settings-form.d.ts +131 -0
- package/dist/services/settings-form.js +210 -0
- package/dist/services/settings-form.js.map +1 -0
- package/dist/services/settings.d.ts +2 -0
- package/dist/services/settings.js +5 -0
- package/dist/services/settings.js.map +1 -1
- package/dist/services/statistics-aggregate.d.ts +6 -41
- package/dist/services/statistics-aggregate.js +55 -280
- package/dist/services/statistics-aggregate.js.map +1 -1
- package/dist/services/statistics-utils.d.ts +7 -12
- package/dist/services/statistics-utils.js +36 -51
- package/dist/services/statistics-utils.js.map +1 -1
- package/dist/services/statistics-write.js +64 -22
- package/dist/services/statistics-write.js.map +1 -1
- package/dist/services/tester-source.d.ts +11 -0
- package/dist/services/tester-source.js +48 -0
- package/dist/services/tester-source.js.map +1 -0
- package/dist/services/traffic-samples.d.ts +18 -0
- package/dist/services/traffic-samples.js +134 -0
- package/dist/services/traffic-samples.js.map +1 -0
- package/dist/services/traffic.d.ts +43 -0
- package/dist/services/traffic.js +270 -0
- package/dist/services/traffic.js.map +1 -0
- package/dist/services/window.d.ts +48 -0
- package/dist/services/window.js +179 -0
- package/dist/services/window.js.map +1 -0
- package/dist/types/constants.d.ts +11 -20
- package/dist/types/constants.js +15 -25
- package/dist/types/constants.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/statistics.d.ts +5 -3
- package/dist/types/statistics.js +5 -0
- package/dist/types/statistics.js.map +1 -1
- package/frontend-vue/app/components/blocks/BetaBadge.vue +20 -0
- package/frontend-vue/app/components/blocks/HealthHero.vue +708 -0
- package/frontend-vue/app/components/blocks/LiveTraffic.vue +356 -0
- package/frontend-vue/app/components/blocks/LogsEmptyState.vue +228 -0
- package/frontend-vue/app/components/blocks/LogsFilters.vue +279 -0
- package/frontend-vue/app/components/blocks/RequestDetail.vue +722 -0
- package/frontend-vue/app/components/blocks/RetentionInput.vue +227 -0
- package/frontend-vue/app/components/blocks/RouteDocumentation.vue +611 -0
- package/frontend-vue/app/components/blocks/RouteHeader.vue +320 -0
- package/frontend-vue/app/components/blocks/RouteTester.vue +1879 -0
- package/frontend-vue/app/components/blocks/RouteTree.vue +676 -0
- package/frontend-vue/app/components/blocks/ScopeChip.vue +89 -0
- package/frontend-vue/app/components/blocks/SettingNumberInput.vue +65 -0
- package/frontend-vue/app/components/blocks/SplitLayout.vue +41 -0
- package/frontend-vue/app/components/internal/ApiBody.vue +129 -0
- package/frontend-vue/app/components/internal/ApiJsonTree.vue +82 -0
- package/frontend-vue/app/components/internal/ApiKeyValues.vue +41 -0
- package/frontend-vue/app/components/internal/ApiMethodBadge.vue +19 -19
- package/frontend-vue/app/components/internal/ApiPath.vue +33 -0
- package/frontend-vue/app/components/internal/ApiStatusBadge.vue +20 -15
- package/frontend-vue/app/components/internal/ApiTesterBadge.vue +17 -0
- package/frontend-vue/app/composables/useApiOrigin.ts +19 -0
- package/frontend-vue/app/composables/useApiPeriod.ts +19 -0
- package/frontend-vue/app/composables/useApiResource.ts +92 -0
- package/frontend-vue/app/composables/useDateFormat.ts +23 -0
- package/frontend-vue/app/composables/useLiveMissedErrors.ts +33 -0
- package/frontend-vue/app/composables/useRouteDetail.ts +253 -0
- package/frontend-vue/app/composables/useRouteSelection.ts +43 -0
- package/frontend-vue/app/config/shortcuts-registry.ts +30 -0
- package/frontend-vue/app/plugins/displays.ts +92 -0
- package/frontend-vue/app/utils/format.ts +281 -0
- package/frontend-vue/app/utils/http.ts +127 -0
- package/frontend-vue/app/utils/logsQuery.ts +261 -0
- package/frontend-vue/app/utils/minuteHistogram.ts +116 -0
- package/frontend-vue/app/utils/requestDrawer.ts +257 -0
- package/frontend-vue/app/utils/routeExplorer.ts +206 -0
- package/frontend-vue/app/utils/search.ts +45 -0
- package/frontend-vue/app/utils/settingsForm.ts +119 -0
- package/frontend-vue/app/utils/snippets.ts +501 -0
- package/frontend-vue/app/utils/testerHistory.ts +354 -0
- package/frontend-vue/app/utils/testerRequest.ts +632 -11
- package/frontend-vue/dms.frontend.build.ts +7 -0
- package/frontend-vue/dms.frontend.ts +10 -3
- package/frontend-vue/i18n/locales/api-en-GB.json +866 -0
- package/frontend-vue/i18n/locales/api-fr-FR.json +866 -0
- package/frontend-vue/package.json +4 -5
- package/frontend-vue/pnpm-lock.yaml +97 -3375
- package/frontend-vue/tests/format.test.ts +180 -0
- package/frontend-vue/tests/http.test.ts +61 -0
- package/frontend-vue/tests/logsQuery.test.ts +255 -0
- package/frontend-vue/tests/minuteHistogram.test.ts +94 -0
- package/frontend-vue/tests/registration.test.ts +24 -7
- package/frontend-vue/tests/requestDrawer.test.ts +179 -0
- package/frontend-vue/tests/routeExplorer.test.ts +206 -0
- package/frontend-vue/tests/settingsForm.test.ts +155 -0
- package/frontend-vue/tests/snippets.test.ts +285 -0
- package/frontend-vue/tests/testerHistory.test.ts +295 -0
- package/frontend-vue/tests/testerRequest.test.ts +471 -76
- package/frontend-vue/tests/tooltipTriggers.test.ts +51 -0
- package/package.json +8 -8
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -18
- package/dist/middlewares/index.js.map +0 -1
- package/dist/middlewares/request-log-capture.d.ts +0 -1
- package/dist/middlewares/request-log-capture.js +0 -6
- package/dist/middlewares/request-log-capture.js.map +0 -1
- package/dist/pages/all.d.ts +0 -4
- package/dist/pages/all.js +0 -21
- package/dist/pages/all.js.map +0 -1
- package/dist/pages/logs/page.js +0 -29
- package/dist/pages/logs/page.js.map +0 -1
- package/dist/pages/routes/page.d.ts +0 -9
- package/dist/pages/routes/page.js +0 -29
- package/dist/pages/routes/page.js.map +0 -1
- package/dist/pages/settings/form.d.ts +0 -3
- package/dist/pages/settings/form.js +0 -80
- package/dist/pages/settings/form.js.map +0 -1
- package/dist/pages/settings/page.d.ts +0 -9
- package/dist/pages/settings/page.js +0 -26
- package/dist/pages/settings/page.js.map +0 -1
- package/dist/pages/summary/page.d.ts +0 -9
- package/dist/pages/summary/page.js +0 -29
- package/dist/pages/summary/page.js.map +0 -1
- package/dist/routes/monitoring.d.ts +0 -17
- package/dist/routes/monitoring.js +0 -101
- package/dist/routes/monitoring.js.map +0 -1
- package/dist/routes/summary.d.ts +0 -32
- package/dist/routes/summary.js +0 -181
- package/dist/routes/summary.js.map +0 -1
- package/dist/services/request-log/index.d.ts +0 -3
- package/dist/services/request-log/index.js +0 -12
- package/dist/services/request-log/index.js.map +0 -1
- package/dist/services/statistics-read.d.ts +0 -4
- package/dist/services/statistics-read.js +0 -48
- package/dist/services/statistics-read.js.map +0 -1
- package/dist/services/tree.d.ts +0 -10
- package/dist/services/tree.js +0 -128
- package/dist/services/tree.js.map +0 -1
- package/dist/types/charts.d.ts +0 -9
- package/dist/types/charts.js +0 -3
- package/dist/types/charts.js.map +0 -1
- package/frontend-vue/app/components/ConfigurationView.vue +0 -187
- package/frontend-vue/app/components/DocumentationView.vue +0 -224
- package/frontend-vue/app/components/LogDetailDrawer.vue +0 -178
- package/frontend-vue/app/components/LogsView.vue +0 -347
- package/frontend-vue/app/components/RouteDetailTabs.vue +0 -179
- package/frontend-vue/app/components/RouteTree.vue +0 -196
- package/frontend-vue/app/components/RoutesView.vue +0 -79
- package/frontend-vue/app/components/StatsView.vue +0 -268
- package/frontend-vue/app/components/SummaryView.vue +0 -657
- package/frontend-vue/app/components/TesterPanel.vue +0 -499
- package/frontend-vue/app/components/internal/PeriodSelect.vue +0 -58
- package/frontend-vue/app/components/internal/RouteTreeNode.vue +0 -168
- package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +0 -162
- package/frontend-vue/app/components/internal/StatusDonut.vue +0 -84
- package/frontend-vue/app/components/internal/UnitAreaChart.vue +0 -73
- package/frontend-vue/app/composables/useApiIntrospection.ts +0 -350
- package/frontend-vue/app/composables/useLogDetailDrawer.ts +0 -50
- package/frontend-vue/app/composables/useSelectedPeriod.ts +0 -107
- package/frontend-vue/app/composables/useStatsPeriods.ts +0 -139
- package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
- package/frontend-vue/app/custom-pages/.gitkeep +0 -0
- package/frontend-vue/app/utils/httpMethod.ts +0 -49
- package/frontend-vue/app/utils/statusClass.ts +0 -49
- package/frontend-vue/i18n/locales/en-GB.json +0 -240
- package/frontend-vue/i18n/locales/fr-FR.json +0 -240
- package/frontend-vue/public/.gitkeep +0 -0
- package/frontend-vue/server/.gitkeep +0 -0
- package/frontend-vue/tests/periods.test.ts +0 -145
- package/frontend-vue/tests/persistence.test.ts +0 -45
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { byteLength } from './format'
|
|
2
|
+
import { startsWithRequestBody } from './http'
|
|
3
|
+
import {
|
|
4
|
+
type BodyMode,
|
|
5
|
+
decodedValue,
|
|
6
|
+
type KeyValue,
|
|
7
|
+
type TesterResult,
|
|
8
|
+
} from './testerRequest'
|
|
9
|
+
|
|
10
|
+
// What the tester keeps between two visits: a draft per route for the
|
|
11
|
+
// session (sessionStorage), the calls made per route and the headers sent to
|
|
12
|
+
// every route in this browser (localStorage), and the routes a write was
|
|
13
|
+
// confirmed on. A credential typed in a header (Authorization, Cookie,
|
|
14
|
+
// X-Api-Key) is never written to storage: it stays in memory until reload.
|
|
15
|
+
|
|
16
|
+
/** The editable part of the tester: what is sent. */
|
|
17
|
+
export interface DraftRequest {
|
|
18
|
+
bodyMode: BodyMode
|
|
19
|
+
body: string
|
|
20
|
+
form: KeyValue[]
|
|
21
|
+
headers: KeyValue[]
|
|
22
|
+
query: KeyValue[]
|
|
23
|
+
pathValues: Record<string, string>
|
|
24
|
+
useSession: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Where the body in the editor comes from, for the line under it. */
|
|
28
|
+
export type BodyOrigin = 'example' | 'replay' | 'history' | 'edited'
|
|
29
|
+
|
|
30
|
+
/** The captured request a draft was replayed from, and what it could not restore. */
|
|
31
|
+
export interface ReplayInfo {
|
|
32
|
+
id: string
|
|
33
|
+
at: string
|
|
34
|
+
skippedHeaders: string[]
|
|
35
|
+
bodyMissing: boolean
|
|
36
|
+
bodyOmitted: string | null
|
|
37
|
+
bodyTruncated: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A route's work in progress, kept across tabs, routes and pages. */
|
|
41
|
+
export interface TesterDraft {
|
|
42
|
+
request: DraftRequest
|
|
43
|
+
origin: BodyOrigin
|
|
44
|
+
replay: ReplayInfo | null
|
|
45
|
+
result: TesterResult | null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What the tester remembers of one call, to restore it from the history. */
|
|
49
|
+
export interface HistoryEntry {
|
|
50
|
+
at: number
|
|
51
|
+
method: string
|
|
52
|
+
/** The path as sent, query included. */
|
|
53
|
+
path: string
|
|
54
|
+
request: DraftRequest
|
|
55
|
+
/** Credential headers left out of the entry, by name. */
|
|
56
|
+
secretsRemoved?: string[]
|
|
57
|
+
result: TesterResult
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Calls kept per route. */
|
|
61
|
+
export const HISTORY_MAX = 25
|
|
62
|
+
|
|
63
|
+
/** A stored response is cut here: the history is a reminder, not an archive. */
|
|
64
|
+
const STORED_BODY_MAX = 4096
|
|
65
|
+
|
|
66
|
+
const HISTORY_PREFIX = 'dmsApi.tester.history.'
|
|
67
|
+
const DRAFT_PREFIX = 'dmsApi.tester.draft.'
|
|
68
|
+
const COMMON_HEADERS_KEY = 'dmsApi.tester.commonHeaders'
|
|
69
|
+
const CONFIRMED_WRITES_KEY = 'dmsApi.tester.confirmedWrites'
|
|
70
|
+
|
|
71
|
+
/** Headers a credential travels in: typed in the tester, never stored. */
|
|
72
|
+
const SECRET_HEADERS = new Set(['authorization', 'cookie', 'x-api-key'])
|
|
73
|
+
|
|
74
|
+
/** The credentials of the drafts and the common headers, until reload. */
|
|
75
|
+
const secrets = new Map<string, KeyValue[]>()
|
|
76
|
+
|
|
77
|
+
type StorageName = 'localStorage' | 'sessionStorage'
|
|
78
|
+
|
|
79
|
+
function read<T>(storage: StorageName, key: string): T | null {
|
|
80
|
+
if (typeof window === 'undefined') return null
|
|
81
|
+
try {
|
|
82
|
+
const raw = window[storage].getItem(key)
|
|
83
|
+
return raw ? (JSON.parse(raw) as T) : null
|
|
84
|
+
} catch {
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function write(storage: StorageName, key: string, value: unknown): void {
|
|
90
|
+
if (typeof window === 'undefined') return
|
|
91
|
+
try {
|
|
92
|
+
if (value === null) window[storage].removeItem(key)
|
|
93
|
+
else window[storage].setItem(key, JSON.stringify(value))
|
|
94
|
+
} catch {
|
|
95
|
+
// Storage full or disabled: the tester's memory is a convenience, never a blocker.
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isSecretHeader(name: string): boolean {
|
|
100
|
+
return SECRET_HEADERS.has(name.toLowerCase())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** `headers` split into what may be stored and the credentials. */
|
|
104
|
+
export function splitSecrets(headers: KeyValue[]): {
|
|
105
|
+
kept: KeyValue[]
|
|
106
|
+
removed: KeyValue[]
|
|
107
|
+
} {
|
|
108
|
+
return {
|
|
109
|
+
kept: headers.filter((entry) => !isSecretHeader(entry.name)),
|
|
110
|
+
removed: headers.filter((entry) => isSecretHeader(entry.name)),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Names of the credential headers a request sends. */
|
|
115
|
+
export function secretNames(headers: Record<string, string>): string[] {
|
|
116
|
+
return Object.keys(headers).filter(isSecretHeader)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Of the credentials a call was sent with, those `headers` no longer hold:
|
|
121
|
+
* dropped from storage, or from memory by a reload. One per name.
|
|
122
|
+
*/
|
|
123
|
+
export function lostSecrets(sent: string[], headers: KeyValue[]): string[] {
|
|
124
|
+
const held = new Set(
|
|
125
|
+
headers
|
|
126
|
+
.filter((entry) => entry.value)
|
|
127
|
+
.map((entry) => entry.name.toLowerCase()),
|
|
128
|
+
)
|
|
129
|
+
const lost = new Map<string, string>()
|
|
130
|
+
for (const name of sent) {
|
|
131
|
+
const key = name.toLowerCase()
|
|
132
|
+
if (!held.has(key) && !lost.has(key)) lost.set(key, name)
|
|
133
|
+
}
|
|
134
|
+
return [...lost.values()]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// --- History ---
|
|
138
|
+
|
|
139
|
+
function isEntry(value: unknown): value is HistoryEntry {
|
|
140
|
+
const entry = value as HistoryEntry | null
|
|
141
|
+
return (
|
|
142
|
+
!!entry && typeof entry.at === 'number' && !!entry.result && !!entry.request
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The calls made to `route` from this browser, newest first. */
|
|
147
|
+
export function loadHistory(route: string): HistoryEntry[] {
|
|
148
|
+
const parsed = read<unknown>('localStorage', `${HISTORY_PREFIX}${route}`)
|
|
149
|
+
return Array.isArray(parsed) ? parsed.filter(isEntry) : []
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** `entries` with the result of the call sent as `requestId` patched. */
|
|
153
|
+
export function patchResult(
|
|
154
|
+
entries: HistoryEntry[],
|
|
155
|
+
requestId: string,
|
|
156
|
+
patch: Partial<TesterResult>,
|
|
157
|
+
): HistoryEntry[] {
|
|
158
|
+
return entries.map((entry) =>
|
|
159
|
+
entry.result.requestId === requestId
|
|
160
|
+
? { ...entry, result: { ...entry.result, ...patch } }
|
|
161
|
+
: entry,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Store the calls made to `route`. A response body is cut short, with its
|
|
167
|
+
* real size kept, and credentials are never part of an entry: `useSession`
|
|
168
|
+
* only says the session was on.
|
|
169
|
+
*/
|
|
170
|
+
export function saveHistory(route: string, entries: HistoryEntry[]): void {
|
|
171
|
+
const trimmed = entries.slice(0, HISTORY_MAX).map((entry) => {
|
|
172
|
+
const { body } = entry.result
|
|
173
|
+
const cut = body.length > STORED_BODY_MAX
|
|
174
|
+
return {
|
|
175
|
+
...entry,
|
|
176
|
+
request: {
|
|
177
|
+
...entry.request,
|
|
178
|
+
headers: splitSecrets(entry.request.headers).kept,
|
|
179
|
+
},
|
|
180
|
+
result: {
|
|
181
|
+
...entry.result,
|
|
182
|
+
body: cut ? body.slice(0, STORED_BODY_MAX) : body,
|
|
183
|
+
bodySize: entry.result.bodySize ?? byteLength(body),
|
|
184
|
+
bodyTruncated: entry.result.bodyTruncated || cut,
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
write(
|
|
189
|
+
'localStorage',
|
|
190
|
+
`${HISTORY_PREFIX}${route}`,
|
|
191
|
+
trimmed.length ? trimmed : null,
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A history entry for a call, without the credentials it was sent with. */
|
|
196
|
+
export function historyEntry(
|
|
197
|
+
method: string,
|
|
198
|
+
path: string,
|
|
199
|
+
request: DraftRequest,
|
|
200
|
+
result: TesterResult,
|
|
201
|
+
): HistoryEntry {
|
|
202
|
+
const { kept, removed } = splitSecrets(request.headers)
|
|
203
|
+
return {
|
|
204
|
+
at: result.at,
|
|
205
|
+
method,
|
|
206
|
+
path,
|
|
207
|
+
request: { ...request, headers: kept },
|
|
208
|
+
...(removed.length
|
|
209
|
+
? { secretsRemoved: removed.map((entry) => entry.name) }
|
|
210
|
+
: {}),
|
|
211
|
+
result,
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The path values of the last call that succeeded with all of them set. */
|
|
216
|
+
export function lastSuccessfulPathValues(
|
|
217
|
+
entries: HistoryEntry[],
|
|
218
|
+
names: string[],
|
|
219
|
+
): Record<string, string> {
|
|
220
|
+
if (names.length === 0) return {}
|
|
221
|
+
const entry = entries.find(
|
|
222
|
+
(item) =>
|
|
223
|
+
item.result.status >= 200 &&
|
|
224
|
+
item.result.status < 300 &&
|
|
225
|
+
names.every((name) => item.request.pathValues[name]),
|
|
226
|
+
)
|
|
227
|
+
return entry
|
|
228
|
+
? Object.fromEntries(
|
|
229
|
+
names.map((name) => [name, entry.request.pathValues[name]]),
|
|
230
|
+
)
|
|
231
|
+
: {}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// --- Drafts ---
|
|
235
|
+
|
|
236
|
+
/** A route's draft, its credentials put back. */
|
|
237
|
+
export function loadDraft(route: string): TesterDraft | null {
|
|
238
|
+
const draft = read<TesterDraft>('sessionStorage', `${DRAFT_PREFIX}${route}`)
|
|
239
|
+
if (!draft?.request) return null
|
|
240
|
+
const kept = secrets.get(`${DRAFT_PREFIX}${route}`) ?? []
|
|
241
|
+
return {
|
|
242
|
+
...draft,
|
|
243
|
+
request: { ...draft.request, headers: [...draft.request.headers, ...kept] },
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function saveDraft(route: string, draft: TesterDraft | null): void {
|
|
248
|
+
const key = `${DRAFT_PREFIX}${route}`
|
|
249
|
+
if (!draft) {
|
|
250
|
+
secrets.delete(key)
|
|
251
|
+
write('sessionStorage', key, null)
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
const { kept, removed } = splitSecrets(draft.request.headers)
|
|
255
|
+
secrets.set(key, removed)
|
|
256
|
+
write('sessionStorage', key, {
|
|
257
|
+
...draft,
|
|
258
|
+
request: { ...draft.request, headers: kept },
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Whether two requests send the same thing, empty rows aside. */
|
|
263
|
+
export function sameRequest(a: DraftRequest, b: DraftRequest): boolean {
|
|
264
|
+
const rows = (list: KeyValue[]) =>
|
|
265
|
+
list
|
|
266
|
+
.filter((entry) => entry.name || entry.value)
|
|
267
|
+
.map((entry) => [entry.name, entry.value])
|
|
268
|
+
const shape = (request: DraftRequest) =>
|
|
269
|
+
JSON.stringify([
|
|
270
|
+
request.bodyMode,
|
|
271
|
+
request.bodyMode === 'none' ? '' : request.body,
|
|
272
|
+
rows(request.form),
|
|
273
|
+
rows(request.headers),
|
|
274
|
+
rows(request.query),
|
|
275
|
+
Object.entries(request.pathValues).sort(),
|
|
276
|
+
request.useSession,
|
|
277
|
+
])
|
|
278
|
+
return shape(a) === shape(b)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* A route's starting point: the last body it accepted (none for GET, HEAD
|
|
283
|
+
* and DELETE), the path values of the last call that succeeded from here,
|
|
284
|
+
* else of the last one the route answered with success, and the session
|
|
285
|
+
* only when the route requires it, surely or probably: a public handler (a
|
|
286
|
+
* webhook) does not get the owner's token.
|
|
287
|
+
*/
|
|
288
|
+
export function exampleRequest(
|
|
289
|
+
route: {
|
|
290
|
+
method: string
|
|
291
|
+
pathParams: string[]
|
|
292
|
+
exampleBody: unknown
|
|
293
|
+
examplePath?: Record<string, string>
|
|
294
|
+
authStatus: 'required' | 'probable' | 'unknown'
|
|
295
|
+
},
|
|
296
|
+
history: HistoryEntry[],
|
|
297
|
+
): DraftRequest {
|
|
298
|
+
const withBody = startsWithRequestBody(route.method)
|
|
299
|
+
const own = lastSuccessfulPathValues(history, route.pathParams)
|
|
300
|
+
const last = Object.keys(own).length
|
|
301
|
+
? own
|
|
302
|
+
: Object.fromEntries(
|
|
303
|
+
Object.entries(route.examplePath ?? {}).map(([name, value]) => [
|
|
304
|
+
name,
|
|
305
|
+
decodedValue(String(value)),
|
|
306
|
+
]),
|
|
307
|
+
)
|
|
308
|
+
return {
|
|
309
|
+
bodyMode: withBody ? 'json' : 'none',
|
|
310
|
+
body:
|
|
311
|
+
withBody && route.exampleBody !== undefined && route.exampleBody !== null
|
|
312
|
+
? JSON.stringify(route.exampleBody, null, 2)
|
|
313
|
+
: '',
|
|
314
|
+
form: [],
|
|
315
|
+
headers: [],
|
|
316
|
+
query: [],
|
|
317
|
+
pathValues: Object.fromEntries(
|
|
318
|
+
route.pathParams.map((name) => [name, last[name] ?? '']),
|
|
319
|
+
),
|
|
320
|
+
useSession: route.authStatus !== 'unknown',
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// --- Headers sent to every route ---
|
|
325
|
+
|
|
326
|
+
export function loadCommonHeaders(): KeyValue[] {
|
|
327
|
+
const stored = read<KeyValue[]>('localStorage', COMMON_HEADERS_KEY)
|
|
328
|
+
return [
|
|
329
|
+
...(Array.isArray(stored) ? stored : []),
|
|
330
|
+
...(secrets.get(COMMON_HEADERS_KEY) ?? []),
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function saveCommonHeaders(headers: KeyValue[]): void {
|
|
335
|
+
const { kept, removed } = splitSecrets(
|
|
336
|
+
headers.filter((entry) => entry.name || entry.value),
|
|
337
|
+
)
|
|
338
|
+
secrets.set(COMMON_HEADERS_KEY, removed)
|
|
339
|
+
write('localStorage', COMMON_HEADERS_KEY, kept.length ? kept : null)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// --- Writes confirmed this session ---
|
|
343
|
+
|
|
344
|
+
export function hasConfirmedWrite(route: string): boolean {
|
|
345
|
+
const confirmed = read<string[]>('sessionStorage', CONFIRMED_WRITES_KEY)
|
|
346
|
+
return Array.isArray(confirmed) && confirmed.includes(route)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export function rememberConfirmedWrite(route: string): void {
|
|
350
|
+
const confirmed = read<string[]>('sessionStorage', CONFIRMED_WRITES_KEY)
|
|
351
|
+
const list = Array.isArray(confirmed) ? confirmed : []
|
|
352
|
+
if (!list.includes(route))
|
|
353
|
+
write('sessionStorage', CONFIRMED_WRITES_KEY, [...list, route])
|
|
354
|
+
}
|