@statoss/sdk 0.1.1 → 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.
- package/README.md +102 -15
- package/dist/cjs/client.d.ts +9 -2
- package/dist/cjs/client.js +39 -2
- package/dist/cjs/debug-ids.d.ts +16 -0
- package/dist/cjs/debug-ids.js +112 -0
- package/dist/cjs/index.d.ts +11 -2
- package/dist/cjs/index.js +11 -6
- package/dist/cjs/levels.d.ts +4 -1
- package/dist/cjs/levels.js +23 -12
- package/dist/cjs/schema.d.ts +199 -0
- package/dist/cjs/schema.js +119 -0
- package/dist/cjs/types.d.ts +10 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +9 -2
- package/dist/esm/client.js +39 -2
- package/dist/esm/debug-ids.d.ts +16 -0
- package/dist/esm/debug-ids.js +108 -0
- package/dist/esm/index.d.ts +11 -2
- package/dist/esm/index.js +9 -5
- package/dist/esm/levels.d.ts +4 -1
- package/dist/esm/levels.js +20 -10
- package/dist/esm/schema.d.ts +199 -0
- package/dist/esm/schema.js +114 -0
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/dist/esm/levels.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Logger } from "./logger.js";
|
|
2
2
|
import type { SentryLevel } from "./types.js";
|
|
3
3
|
export declare const SENTRY_LEVELS: readonly SentryLevel[];
|
|
4
|
+
export declare const LEVEL_RULE = "use 1 to 32 lowercase letters, digits, dots, dashes or underscores";
|
|
5
|
+
export declare const CATEGORY_RULE = "use 1 to 64 lowercase letters, digits, dots, dashes or underscores";
|
|
4
6
|
export declare const LEVEL_TAG = "statoss.level";
|
|
5
7
|
export declare const CATEGORY_TAG = "statoss.category";
|
|
6
8
|
export declare function isSentryLevel(value: unknown): value is SentryLevel;
|
|
7
|
-
export declare function
|
|
9
|
+
export declare function isLevelName(value: unknown): value is string;
|
|
10
|
+
export declare function isCategoryName(value: unknown): value is string;
|
|
8
11
|
/** Keeps the entries of init's `levels` that are usable, logging the rest in debug mode. */
|
|
9
12
|
export declare function readLevels(input: unknown, logger: Logger): Record<string, SentryLevel>;
|
|
10
13
|
export interface LevelChoice {
|
package/dist/esm/levels.js
CHANGED
|
@@ -6,16 +6,26 @@ export const SENTRY_LEVELS = [
|
|
|
6
6
|
"info",
|
|
7
7
|
"debug",
|
|
8
8
|
];
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Names of your own: lowercase letters, digits, dots, dashes and
|
|
11
|
+
* underscores. A level is at most 32 characters, as the server keeps it; a
|
|
12
|
+
* category at most 64.
|
|
13
|
+
*/
|
|
14
|
+
const LEVEL_RE = /^[a-z0-9._-]{1,32}$/;
|
|
15
|
+
const CATEGORY_RE = /^[a-z0-9._-]{1,64}$/;
|
|
16
|
+
export const LEVEL_RULE = "use 1 to 32 lowercase letters, digits, dots, dashes or underscores";
|
|
17
|
+
export const CATEGORY_RULE = "use 1 to 64 lowercase letters, digits, dots, dashes or underscores";
|
|
11
18
|
export const LEVEL_TAG = "statoss.level";
|
|
12
19
|
export const CATEGORY_TAG = "statoss.category";
|
|
13
20
|
export function isSentryLevel(value) {
|
|
14
21
|
return (typeof value === "string" &&
|
|
15
22
|
SENTRY_LEVELS.includes(value));
|
|
16
23
|
}
|
|
17
|
-
export function
|
|
18
|
-
return typeof value === "string" &&
|
|
24
|
+
export function isLevelName(value) {
|
|
25
|
+
return typeof value === "string" && LEVEL_RE.test(value);
|
|
26
|
+
}
|
|
27
|
+
export function isCategoryName(value) {
|
|
28
|
+
return typeof value === "string" && CATEGORY_RE.test(value);
|
|
19
29
|
}
|
|
20
30
|
/** Keeps the entries of init's `levels` that are usable, logging the rest in debug mode. */
|
|
21
31
|
export function readLevels(input, logger) {
|
|
@@ -30,8 +40,8 @@ export function readLevels(input, logger) {
|
|
|
30
40
|
if (isSentryLevel(name)) {
|
|
31
41
|
logger.warn(`Ignored level "${name}" in \`levels\`: it is already a Sentry level.`);
|
|
32
42
|
}
|
|
33
|
-
else if (!
|
|
34
|
-
logger.warn(`Ignored level "${name}" in \`levels\`:
|
|
43
|
+
else if (!isLevelName(name)) {
|
|
44
|
+
logger.warn(`Ignored level "${name}" in \`levels\`: ${LEVEL_RULE}.`);
|
|
35
45
|
}
|
|
36
46
|
else if (!isSentryLevel(level)) {
|
|
37
47
|
logger.warn(`Ignored level "${name}" in \`levels\`: map it to fatal, error, warning, info or debug.`);
|
|
@@ -52,18 +62,18 @@ export function chooseLevel(candidates, levels, fallback, logger) {
|
|
|
52
62
|
continue;
|
|
53
63
|
if (isSentryLevel(candidate))
|
|
54
64
|
return { level: candidate };
|
|
55
|
-
if (
|
|
65
|
+
if (isLevelName(candidate)) {
|
|
56
66
|
return { level: levels[candidate] ?? "error", custom: candidate };
|
|
57
67
|
}
|
|
58
|
-
logger.warn(`Ignored level "${safeString(candidate)}": use a Sentry level or 1 to
|
|
68
|
+
logger.warn(`Ignored level "${safeString(candidate)}": use a Sentry level or 1 to 32 lowercase letters, digits, dots, dashes or underscores.`);
|
|
59
69
|
}
|
|
60
70
|
return { level: fallback };
|
|
61
71
|
}
|
|
62
72
|
export function readCategory(value, logger) {
|
|
63
73
|
if (value === undefined || value === null)
|
|
64
74
|
return undefined;
|
|
65
|
-
if (
|
|
75
|
+
if (isCategoryName(value))
|
|
66
76
|
return value;
|
|
67
|
-
logger.warn(`Ignored category "${safeString(value)}":
|
|
77
|
+
logger.warn(`Ignored category "${safeString(value)}": ${CATEGORY_RULE}.`);
|
|
68
78
|
return undefined;
|
|
69
79
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { Logger } from "./logger.js";
|
|
2
|
+
import type { CaptureContext, Event, Level, SentryLevel } from "./types.js";
|
|
3
|
+
/** The ranges a level ranks in: Sentry's five and OpenTelemetry's trace. */
|
|
4
|
+
export declare const LIKES: readonly ["fatal", "error", "warning", "info", "debug", "trace"];
|
|
5
|
+
export type Like = (typeof LIKES)[number];
|
|
6
|
+
/** The colours a level or a category takes, by name. */
|
|
7
|
+
export declare const SCHEMA_COLORS: readonly ["crimson", "red", "orange", "amber", "yellow", "green", "aqua", "teal", "blue", "violet", "indigo", "magenta", "plum", "grey"];
|
|
8
|
+
export type SchemaColor = (typeof SCHEMA_COLORS)[number];
|
|
9
|
+
/** What a rule tests: a tag by key, the logger, or one of the event's own fields. */
|
|
10
|
+
export declare const RULE_SUBJECTS: readonly ["tag", "logger", "exception", "culprit", "title", "message"];
|
|
11
|
+
export type RuleSubject = (typeof RULE_SUBJECTS)[number];
|
|
12
|
+
export declare const RULE_MATCHES: readonly ["is", "starts", "contains"];
|
|
13
|
+
export type RuleMatch = (typeof RULE_MATCHES)[number];
|
|
14
|
+
export declare const FIELD_TYPES: readonly ["text", "number"];
|
|
15
|
+
export type FieldType = (typeof FIELD_TYPES)[number];
|
|
16
|
+
/** Each range's severities, as OpenTelemetry numbers them. */
|
|
17
|
+
interface Severities {
|
|
18
|
+
fatal: 21 | 22 | 23 | 24;
|
|
19
|
+
error: 17 | 18 | 19 | 20;
|
|
20
|
+
warning: 13 | 14 | 15 | 16;
|
|
21
|
+
info: 9 | 10 | 11 | 12;
|
|
22
|
+
debug: 5 | 6 | 7 | 8;
|
|
23
|
+
trace: 1 | 2 | 3 | 4;
|
|
24
|
+
}
|
|
25
|
+
export type Severity = Severities[Like];
|
|
26
|
+
/** A level of your own. Null clears a setting. */
|
|
27
|
+
export interface LevelSettings {
|
|
28
|
+
/** The range it ranks in. Without it (and without severity) it ranks as error. */
|
|
29
|
+
like?: Like;
|
|
30
|
+
/** 1 to 24, inside the range of `like`. */
|
|
31
|
+
severity?: Severity;
|
|
32
|
+
label?: string | null;
|
|
33
|
+
color?: SchemaColor | null;
|
|
34
|
+
}
|
|
35
|
+
/** A category. Null clears a setting. */
|
|
36
|
+
export interface CategorySettings {
|
|
37
|
+
label?: string | null;
|
|
38
|
+
color?: SchemaColor | null;
|
|
39
|
+
/** Left out of filters and lists; its events still carry it. */
|
|
40
|
+
hidden?: boolean;
|
|
41
|
+
/** A team member's email. */
|
|
42
|
+
owner?: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** A field: a tag key. Null clears a setting. */
|
|
45
|
+
export interface FieldSettings {
|
|
46
|
+
label?: string | null;
|
|
47
|
+
type?: FieldType;
|
|
48
|
+
unit?: string | null;
|
|
49
|
+
/** Gets a picker in Explore's filters. */
|
|
50
|
+
filterable?: boolean;
|
|
51
|
+
}
|
|
52
|
+
type RuleTests = {
|
|
53
|
+
subject: "tag";
|
|
54
|
+
tagKey: string;
|
|
55
|
+
} | {
|
|
56
|
+
subject: Exclude<RuleSubject, "tag">;
|
|
57
|
+
tagKey?: undefined;
|
|
58
|
+
};
|
|
59
|
+
type RuleSets<L extends string, C extends string> = {
|
|
60
|
+
level: L;
|
|
61
|
+
category?: C;
|
|
62
|
+
} | {
|
|
63
|
+
level?: L;
|
|
64
|
+
category: C;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Sets a level, a category or both for events that match: the first rule
|
|
68
|
+
* that matches wins. `match` defaults to "is".
|
|
69
|
+
*/
|
|
70
|
+
export type SchemaRule<L extends string = string, C extends string = string> = RuleTests & {
|
|
71
|
+
match?: RuleMatch;
|
|
72
|
+
value: string;
|
|
73
|
+
} & RuleSets<L, C>;
|
|
74
|
+
/** An app's levels, categories, fields and rules, as the server takes them. */
|
|
75
|
+
export interface SchemaSpec {
|
|
76
|
+
/** Each name with the range it ranks in, or with its settings. */
|
|
77
|
+
levels?: {
|
|
78
|
+
readonly [name: string]: Like | LevelSettings;
|
|
79
|
+
};
|
|
80
|
+
categories?: readonly string[] | {
|
|
81
|
+
readonly [name: string]: CategorySettings;
|
|
82
|
+
};
|
|
83
|
+
fields?: readonly string[] | {
|
|
84
|
+
readonly [name: string]: FieldSettings;
|
|
85
|
+
};
|
|
86
|
+
rules?: readonly SchemaRule[];
|
|
87
|
+
}
|
|
88
|
+
type NamesIn<T> = T extends readonly (infer N)[] ? N & string : T extends object ? keyof T & string : never;
|
|
89
|
+
type LevelNames<S> = S extends {
|
|
90
|
+
levels?: infer L;
|
|
91
|
+
} ? NamesIn<NonNullable<L>> : never;
|
|
92
|
+
type CategoryNames<S> = S extends {
|
|
93
|
+
categories?: infer C;
|
|
94
|
+
} ? NamesIn<NonNullable<C>> : never;
|
|
95
|
+
type FieldNames<S> = S extends {
|
|
96
|
+
fields?: infer F;
|
|
97
|
+
} ? NamesIn<NonNullable<F>> : never;
|
|
98
|
+
/** A Sentry level or a level of the schema. */
|
|
99
|
+
export type LevelOf<S> = string extends LevelNames<S> ? Level : SentryLevel | LevelNames<S>;
|
|
100
|
+
/** A category of the schema. */
|
|
101
|
+
export type CategoryOf<S> = CategoryNames<S>;
|
|
102
|
+
/** A field of the schema. */
|
|
103
|
+
export type FieldOf<S> = FieldNames<S>;
|
|
104
|
+
type NameChar = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "-" | "_";
|
|
105
|
+
/** True for 1 to Max of NameChar. A name only known as string passes. */
|
|
106
|
+
type IsName<S extends string, Max extends number, Seen extends 0[] = []> = string extends S ? true : S extends `${infer C}${infer Rest}` ? C extends NameChar ? Seen["length"] extends Max ? false : IsName<Rest, Max, [...Seen, 0]> : false : Seen extends [] ? false : true;
|
|
107
|
+
type LevelRule = "Level names are 1 to 32 lowercase letters, digits, dots, dashes or underscores";
|
|
108
|
+
type CategoryRule = "Category names are 1 to 64 lowercase letters, digits, dots, dashes or underscores";
|
|
109
|
+
type FieldRule = "Field names are not empty and do not start statoss.";
|
|
110
|
+
type Only<V, Keys extends PropertyKey, Message extends string> = {
|
|
111
|
+
[P in Exclude<keyof V, Keys>]: {
|
|
112
|
+
[M in Message]: true;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
type LevelCheck<V> = V extends string ? Like : {
|
|
116
|
+
like?: Like;
|
|
117
|
+
severity?: V extends {
|
|
118
|
+
like: infer K extends Like;
|
|
119
|
+
} ? Severities[K] : Severity;
|
|
120
|
+
label?: string | null;
|
|
121
|
+
color?: SchemaColor | null;
|
|
122
|
+
} & Only<V, keyof LevelSettings, "A level takes like, severity, label and color">;
|
|
123
|
+
/** Sentry's own levels rank as themselves: a label and a colour only. */
|
|
124
|
+
type BuiltinLevelCheck<K extends SentryLevel, V> = V extends string ? K : {
|
|
125
|
+
like?: K;
|
|
126
|
+
label?: string | null;
|
|
127
|
+
color?: SchemaColor | null;
|
|
128
|
+
} & Only<V, "like" | "label" | "color", "A built-in level takes label and color, and ranks as itself">;
|
|
129
|
+
type CheckLevels<T> = {
|
|
130
|
+
[K in keyof T]: K extends SentryLevel ? BuiltinLevelCheck<K, T[K]> : K extends string ? IsName<K, 32> extends true ? LevelCheck<T[K]> : {
|
|
131
|
+
[M in LevelRule]: true;
|
|
132
|
+
} : never;
|
|
133
|
+
};
|
|
134
|
+
type CheckCategories<T> = T extends readonly unknown[] ? {
|
|
135
|
+
[I in keyof T]: T[I] extends string ? IsName<T[I], 64> extends true ? T[I] : {
|
|
136
|
+
[M in CategoryRule]: true;
|
|
137
|
+
} : string;
|
|
138
|
+
} : {
|
|
139
|
+
[K in keyof T]: K extends string ? IsName<K, 64> extends true ? CategorySettings & Only<T[K], keyof CategorySettings, "A category takes label, color, hidden and owner"> : {
|
|
140
|
+
[M in CategoryRule]: true;
|
|
141
|
+
} : never;
|
|
142
|
+
};
|
|
143
|
+
type IsField<K extends string> = K extends "" | `statoss.${string}` ? false : true;
|
|
144
|
+
type CheckFields<T> = T extends readonly unknown[] ? {
|
|
145
|
+
[I in keyof T]: T[I] extends string ? IsField<T[I]> extends true ? T[I] : {
|
|
146
|
+
[M in FieldRule]: true;
|
|
147
|
+
} : string;
|
|
148
|
+
} : {
|
|
149
|
+
[K in keyof T]: K extends string ? IsField<K> extends true ? FieldSettings & Only<T[K], keyof FieldSettings, "A field takes label, type, unit and filterable"> : {
|
|
150
|
+
[M in FieldRule]: true;
|
|
151
|
+
} : never;
|
|
152
|
+
};
|
|
153
|
+
type CheckRules<T, L extends string, C extends string> = {
|
|
154
|
+
[I in keyof T]: SchemaRule<L, C> & Only<T[I], "subject" | "tagKey" | "match" | "value" | "level" | "category", "A rule takes subject, tagKey, match, value, level and category">;
|
|
155
|
+
};
|
|
156
|
+
/** What defineSchema holds a schema to, read from the schema itself. */
|
|
157
|
+
export type CheckSchema<S> = {
|
|
158
|
+
[K in keyof S]: K extends "levels" ? CheckLevels<S[K]> : K extends "categories" ? CheckCategories<S[K]> : K extends "fields" ? CheckFields<S[K]> : K extends "rules" ? CheckRules<S[K], SentryLevel | LevelNames<S>, CategoryNames<S>> : {
|
|
159
|
+
"A schema takes levels, categories, fields and rules": true;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Declares an app's levels, categories, fields and rules. Returns the schema
|
|
164
|
+
* as given: plain data in the shape the server takes, so it can be sent as
|
|
165
|
+
* it is. Its names become types: pass it to init as `schema` and the capture
|
|
166
|
+
* functions init returns take only these names.
|
|
167
|
+
*/
|
|
168
|
+
export declare function defineSchema<const S extends SchemaSpec & CheckSchema<S>>(schema: S): S;
|
|
169
|
+
/** A field's value; sent as a tag. */
|
|
170
|
+
export type FieldValue = string | number | boolean;
|
|
171
|
+
/** What the capture functions of init's handle take, typed by the schema. */
|
|
172
|
+
export interface SchemaContext<S = SchemaSpec> extends Omit<CaptureContext, "level" | "category"> {
|
|
173
|
+
/** A Sentry level or a level of the schema. */
|
|
174
|
+
level?: LevelOf<S>;
|
|
175
|
+
/** A category of the schema, sent as the `statoss.category` tag. */
|
|
176
|
+
category?: CategoryOf<S>;
|
|
177
|
+
/**
|
|
178
|
+
* Fields of the schema, sent as tags; a schema that declares none takes
|
|
179
|
+
* none here.
|
|
180
|
+
*/
|
|
181
|
+
fields?: [FieldOf<S>] extends [never] ? never : {
|
|
182
|
+
[K in FieldOf<S>]?: FieldValue;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** The capture functions, typed by the schema given to init. */
|
|
186
|
+
export interface Handle<S = SchemaSpec> {
|
|
187
|
+
/** Sends an error (or anything thrown). Returns the event id. */
|
|
188
|
+
captureException(error: unknown, context?: SchemaContext<S>): string;
|
|
189
|
+
/** Sends a message, with a level or a context. Returns the event id. */
|
|
190
|
+
captureMessage(message: string, levelOrContext?: LevelOf<S> | SchemaContext<S>): string;
|
|
191
|
+
/** Sends an event you built in Sentry's schema. Returns the event id. */
|
|
192
|
+
captureEvent(event: Event, context?: SchemaContext<S>): string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The Sentry level each level of init's `schema` is sent as. Built-in
|
|
196
|
+
* levels are left out; names the SDK cannot send are logged in debug mode.
|
|
197
|
+
*/
|
|
198
|
+
export declare function readSchema(schema: unknown, logger: Logger): Record<string, SentryLevel>;
|
|
199
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { CATEGORY_RULE, isCategoryName, isLevelName, isSentryLevel, LEVEL_RULE, } from "./levels.js";
|
|
2
|
+
import { isObject, safeString } from "./utils.js";
|
|
3
|
+
// The server's own lists (src/lib/app-schema.ts, src/lib/schema-colors.ts,
|
|
4
|
+
// src/db/schema.ts), kept equal by a test.
|
|
5
|
+
/** The ranges a level ranks in: Sentry's five and OpenTelemetry's trace. */
|
|
6
|
+
export const LIKES = [
|
|
7
|
+
"fatal",
|
|
8
|
+
"error",
|
|
9
|
+
"warning",
|
|
10
|
+
"info",
|
|
11
|
+
"debug",
|
|
12
|
+
"trace",
|
|
13
|
+
];
|
|
14
|
+
/** The colours a level or a category takes, by name. */
|
|
15
|
+
export const SCHEMA_COLORS = [
|
|
16
|
+
"crimson",
|
|
17
|
+
"red",
|
|
18
|
+
"orange",
|
|
19
|
+
"amber",
|
|
20
|
+
"yellow",
|
|
21
|
+
"green",
|
|
22
|
+
"aqua",
|
|
23
|
+
"teal",
|
|
24
|
+
"blue",
|
|
25
|
+
"violet",
|
|
26
|
+
"indigo",
|
|
27
|
+
"magenta",
|
|
28
|
+
"plum",
|
|
29
|
+
"grey",
|
|
30
|
+
];
|
|
31
|
+
/** What a rule tests: a tag by key, the logger, or one of the event's own fields. */
|
|
32
|
+
export const RULE_SUBJECTS = [
|
|
33
|
+
"tag",
|
|
34
|
+
"logger",
|
|
35
|
+
"exception",
|
|
36
|
+
"culprit",
|
|
37
|
+
"title",
|
|
38
|
+
"message",
|
|
39
|
+
];
|
|
40
|
+
export const RULE_MATCHES = ["is", "starts", "contains"];
|
|
41
|
+
export const FIELD_TYPES = ["text", "number"];
|
|
42
|
+
/**
|
|
43
|
+
* Declares an app's levels, categories, fields and rules. Returns the schema
|
|
44
|
+
* as given: plain data in the shape the server takes, so it can be sent as
|
|
45
|
+
* it is. Its names become types: pass it to init as `schema` and the capture
|
|
46
|
+
* functions init returns take only these names.
|
|
47
|
+
*/
|
|
48
|
+
export function defineSchema(schema) {
|
|
49
|
+
return schema;
|
|
50
|
+
}
|
|
51
|
+
// At runtime
|
|
52
|
+
/** The Sentry level a level of the schema is sent as. */
|
|
53
|
+
function sentAs(name, value, logger) {
|
|
54
|
+
const settings = isObject(value) ? value : {};
|
|
55
|
+
const like = typeof value === "string" ? value : settings.like;
|
|
56
|
+
if (isSentryLevel(like))
|
|
57
|
+
return like;
|
|
58
|
+
if (like === "trace")
|
|
59
|
+
return "debug";
|
|
60
|
+
if (like !== undefined || (typeof value !== "string" && !isObject(value))) {
|
|
61
|
+
logger.warn(`Level "${name}" in the schema: like should be ${LIKES.join(", ")}; sent as error.`);
|
|
62
|
+
return "error";
|
|
63
|
+
}
|
|
64
|
+
const severity = settings.severity;
|
|
65
|
+
if (typeof severity !== "number" || severity < 1 || severity > 24)
|
|
66
|
+
return "error";
|
|
67
|
+
if (severity >= 21)
|
|
68
|
+
return "fatal";
|
|
69
|
+
if (severity >= 17)
|
|
70
|
+
return "error";
|
|
71
|
+
if (severity >= 13)
|
|
72
|
+
return "warning";
|
|
73
|
+
if (severity >= 9)
|
|
74
|
+
return "info";
|
|
75
|
+
return "debug";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The Sentry level each level of init's `schema` is sent as. Built-in
|
|
79
|
+
* levels are left out; names the SDK cannot send are logged in debug mode.
|
|
80
|
+
*/
|
|
81
|
+
export function readSchema(schema, logger) {
|
|
82
|
+
const out = {};
|
|
83
|
+
if (schema === undefined || schema === null)
|
|
84
|
+
return out;
|
|
85
|
+
if (!isObject(schema) || Array.isArray(schema)) {
|
|
86
|
+
logger.warn("Ignored `schema`: pass what defineSchema returns.");
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
const { levels, categories } = schema;
|
|
90
|
+
if (isObject(levels) && !Array.isArray(levels)) {
|
|
91
|
+
for (const [name, value] of Object.entries(levels)) {
|
|
92
|
+
// A built-in level, given a label or a colour.
|
|
93
|
+
if (isSentryLevel(name))
|
|
94
|
+
continue;
|
|
95
|
+
if (isLevelName(name))
|
|
96
|
+
out[name] = sentAs(name, value, logger);
|
|
97
|
+
else
|
|
98
|
+
logger.warn(`Ignored level "${name}" in the schema: ${LEVEL_RULE}.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (levels !== undefined && levels !== null) {
|
|
102
|
+
logger.warn('Ignored the schema\'s levels: they should be an object such as { "payment-failed": "error" }.');
|
|
103
|
+
}
|
|
104
|
+
const names = Array.isArray(categories)
|
|
105
|
+
? categories
|
|
106
|
+
: isObject(categories)
|
|
107
|
+
? Object.keys(categories)
|
|
108
|
+
: [];
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
if (!isCategoryName(name))
|
|
111
|
+
logger.warn(`Category "${safeString(name)}" in the schema cannot be sent: ${CATEGORY_RULE}.`);
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -64,6 +64,13 @@ export interface SdkInfo {
|
|
|
64
64
|
version: string;
|
|
65
65
|
}[];
|
|
66
66
|
}
|
|
67
|
+
/** A file the event's frames ran in; type "sourcemap" names its debug id. */
|
|
68
|
+
export interface DebugImage {
|
|
69
|
+
type: string;
|
|
70
|
+
code_file?: string;
|
|
71
|
+
debug_id?: string;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
67
74
|
/** An event in Sentry's schema, as the SDK sends it. */
|
|
68
75
|
export interface Event {
|
|
69
76
|
event_id?: string;
|
|
@@ -91,6 +98,9 @@ export interface Event {
|
|
|
91
98
|
request?: RequestInfo;
|
|
92
99
|
fingerprint?: string[];
|
|
93
100
|
sdk?: SdkInfo;
|
|
101
|
+
debug_meta?: {
|
|
102
|
+
images?: DebugImage[];
|
|
103
|
+
};
|
|
94
104
|
[key: string]: unknown;
|
|
95
105
|
}
|
|
96
106
|
/** What `captureException`, `captureMessage` and `captureEvent` take as context. */
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/package.json
CHANGED