@ganeshdole/brainbox-core 0.1.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import type { Identity } from "@ganeshdole/brainbox-shared";
1
+ import type { Identity, ReportField } from "@ganeshdole/brainbox-shared";
2
2
  import { type Draft, type DraftOptions } from "./draft.ts";
3
3
  import type { SubmitResult, Transport } from "./transport.ts";
4
4
  export interface BrainboxOptions {
@@ -6,6 +6,9 @@ export interface BrainboxOptions {
6
6
  transport: Transport;
7
7
  /** Who is filing. Can be set later with `identify()`. */
8
8
  identity?: Identity;
9
+ /** Your app's own details for every report (clinic, plan, ...). Can be set
10
+ * later with `setFields()`. */
11
+ fields?: ReportField[];
9
12
  /** Called after every successful submit. */
10
13
  onSubmitted?: (result: SubmitResult) => void;
11
14
  }
@@ -13,7 +16,9 @@ export interface BrainboxOptions {
13
16
  * created and hands out drafts; `destroy()` undoes all of it. */
14
17
  export interface Brainbox {
15
18
  identify(identity: Identity): void;
19
+ /** Replaces the details sent with every report from now on. */
20
+ setFields(fields: ReportField[]): void;
16
21
  draft(options?: DraftOptions): Draft;
17
22
  destroy(): void;
18
23
  }
19
- export declare function createBrainbox({ transport, identity, onSubmitted }: BrainboxOptions): Brainbox;
24
+ export declare function createBrainbox({ transport, identity, fields, onSubmitted }: BrainboxOptions): Brainbox;
package/dist/brainbox.js CHANGED
@@ -1,17 +1,22 @@
1
1
  import { createDraft } from "./draft.js";
2
2
  import { captureErrors } from "./metadata.js";
3
- export function createBrainbox({ transport, identity, onSubmitted }) {
3
+ export function createBrainbox({ transport, identity, fields, onSubmitted }) {
4
4
  let who = identity;
5
+ let details = fields;
5
6
  const errors = captureErrors();
6
7
  const drafts = new Set();
7
8
  return {
8
9
  identify(next) {
9
10
  who = next;
10
11
  },
12
+ setFields(next) {
13
+ details = next;
14
+ },
11
15
  draft(options) {
12
16
  const draft = createDraft({
13
17
  transport,
14
18
  identity: () => who,
19
+ fields: () => details,
15
20
  consoleErrors: () => errors.snapshot(),
16
21
  onSubmitted,
17
22
  }, options);
package/dist/draft.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Identity } from "@ganeshdole/brainbox-shared";
1
+ import type { Identity, ReportField } from "@ganeshdole/brainbox-shared";
2
2
  import { type Annotations } from "./annotate.ts";
3
3
  import { type Mark } from "./marks.ts";
4
4
  import type { SubmitResult, Transport } from "./transport.ts";
@@ -68,6 +68,7 @@ export interface Draft {
68
68
  export interface DraftContext {
69
69
  transport: Transport;
70
70
  identity(): Identity | undefined;
71
+ fields(): ReportField[] | undefined;
71
72
  consoleErrors(): string[];
72
73
  onSubmitted?: (result: SubmitResult) => void;
73
74
  }
package/dist/draft.js CHANGED
@@ -161,6 +161,7 @@ export function createDraft(ctx, { exclude } = {}) {
161
161
  metadata: captureMetadata({
162
162
  consoleErrors: ctx.consoleErrors(),
163
163
  identity: ctx.identity(),
164
+ fields: ctx.fields(),
164
165
  selector: region?.selector,
165
166
  }),
166
167
  screenshot: screenshot ?? undefined,
package/dist/index.d.ts CHANGED
@@ -6,4 +6,4 @@ export { canSessionRecord } from "./session.ts";
6
6
  export { preloadCapture } from "./lazy.ts";
7
7
  export { startAudioRecording, type AudioRecorder } from "./audio.ts";
8
8
  export * from "./marks.ts";
9
- export type { CapturedMetadata, Identity, ProjectKey, Region } from "@ganeshdole/brainbox-shared";
9
+ export type { CapturedMetadata, Identity, ProjectKey, Region, ReportField, ReportFieldType, } from "@ganeshdole/brainbox-shared";
@@ -1,4 +1,4 @@
1
- import type { CapturedMetadata, Identity } from "@ganeshdole/brainbox-shared";
1
+ import type { CapturedMetadata, Identity, ReportField } from "@ganeshdole/brainbox-shared";
2
2
  /** A rolling buffer of the host page's recent console errors and uncaught
3
3
  * exceptions, owned by one `createBrainbox()` instance. */
4
4
  export interface ErrorLog {
@@ -10,8 +10,9 @@ export interface ErrorLog {
10
10
  /** Start collecting console errors into a new buffer. */
11
11
  export declare function captureErrors(max?: number): ErrorLog;
12
12
  /** Snapshot of the host page at submit time. */
13
- export declare function captureMetadata({ consoleErrors, identity, selector, }: {
13
+ export declare function captureMetadata({ consoleErrors, identity, fields, selector, }: {
14
14
  consoleErrors: string[];
15
15
  identity?: Identity;
16
+ fields?: ReportField[];
16
17
  selector?: string;
17
18
  }): CapturedMetadata;
package/dist/metadata.js CHANGED
@@ -50,7 +50,7 @@ export function captureErrors(max = MAX_ERRORS) {
50
50
  };
51
51
  }
52
52
  /** Snapshot of the host page at submit time. */
53
- export function captureMetadata({ consoleErrors, identity, selector, }) {
53
+ export function captureMetadata({ consoleErrors, identity, fields, selector, }) {
54
54
  return {
55
55
  url: location.href,
56
56
  title: document.title,
@@ -62,6 +62,8 @@ export function captureMetadata({ consoleErrors, identity, selector, }) {
62
62
  selector,
63
63
  consoleErrors,
64
64
  identity,
65
+ // An empty list says nothing; leave it out like an unset one.
66
+ ...(fields?.length && { fields }),
65
67
  };
66
68
  }
67
69
  function stringify(v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ganeshdole/brainbox-core",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "The Brainbox capture engine: screenshots, marks, session recording, console errors and a Transport that sends the report. No React, no UI.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://www.brainbox.sh",
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "modern-screenshot": "^4.6.0",
31
31
  "rrweb": "^2.1.0",
32
- "@ganeshdole/brainbox-shared": "0.1.0"
32
+ "@ganeshdole/brainbox-shared": "0.3.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@eslint/js": "^10.0.1",