@inventreedb/ui 0.10.1 → 0.11.1

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.
Files changed (178) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/.vite/manifest.json +421 -1
  3. package/dist/components/Boundary.d.ts +10 -0
  4. package/dist/components/Boundary.js +37 -0
  5. package/dist/components/Boundary.js.map +1 -0
  6. package/dist/components/CopyButton.d.ts +13 -0
  7. package/dist/components/CopyButton.js +51 -0
  8. package/dist/components/CopyButton.js.map +1 -0
  9. package/dist/components/CopyableCell.d.ts +11 -0
  10. package/dist/components/CopyableCell.js +24 -0
  11. package/dist/components/CopyableCell.js.map +1 -0
  12. package/dist/components/InvenTreeTable.d.ts +17 -0
  13. package/dist/components/InvenTreeTable.js +41 -0
  14. package/dist/components/InvenTreeTable.js.map +1 -0
  15. package/dist/components/TableColumnSelect.d.ts +4 -0
  16. package/dist/components/TableColumnSelect.js +38 -0
  17. package/dist/components/TableColumnSelect.js.map +1 -0
  18. package/dist/enums/ApiEndpoints.d.ts +1 -1
  19. package/dist/enums/ApiEndpoints.js +1 -1
  20. package/dist/enums/ApiEndpoints.js.map +1 -1
  21. package/dist/enums/ModelInformation.js +17 -0
  22. package/dist/enums/ModelInformation.js.map +1 -1
  23. package/dist/enums/ModelType.d.ts +1 -0
  24. package/dist/enums/ModelType.js +1 -0
  25. package/dist/enums/ModelType.js.map +1 -1
  26. package/dist/functions/Forms.d.ts +11 -0
  27. package/dist/functions/Forms.js +27 -0
  28. package/dist/functions/Forms.js.map +1 -0
  29. package/dist/functions/Notification.d.ts +16 -0
  30. package/dist/functions/Notification.js +82 -0
  31. package/dist/functions/Notification.js.map +1 -0
  32. package/dist/functions/String.d.ts +13 -0
  33. package/dist/functions/String.js +25 -0
  34. package/dist/functions/String.js.map +1 -0
  35. package/dist/hooks/UseFilterSet.d.ts +2 -0
  36. package/dist/hooks/UseFilterSet.js +35 -0
  37. package/dist/hooks/UseFilterSet.js.map +1 -0
  38. package/dist/hooks/UseTable.d.ts +12 -0
  39. package/dist/hooks/UseTable.js +84 -0
  40. package/dist/hooks/UseTable.js.map +1 -0
  41. package/dist/index.d.ts +13 -2
  42. package/dist/index.js +32 -4
  43. package/dist/index.js.map +1 -1
  44. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/create-storage.js +129 -0
  45. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/create-storage.js.map +1 -0
  46. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/use-local-storage.js +8 -0
  47. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/use-local-storage.js.map +1 -0
  48. package/dist/node_modules/@mantine/hooks/esm/use-window-event/use-window-event.js +11 -0
  49. package/dist/node_modules/@mantine/hooks/esm/use-window-event/use-window-event.js.map +1 -0
  50. package/dist/node_modules/@mantine/hooks/esm/utils/random-id/random-id.js +7 -0
  51. package/dist/node_modules/@mantine/hooks/esm/utils/random-id/random-id.js.map +1 -0
  52. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js +5 -0
  53. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js.map +1 -0
  54. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js +6 -0
  55. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js.map +1 -0
  56. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js +54 -0
  57. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js.map +1 -0
  58. package/dist/node_modules/@sentry/core/build/esm/api.js +41 -0
  59. package/dist/node_modules/@sentry/core/build/esm/api.js.map +1 -0
  60. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js +13 -0
  61. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js.map +1 -0
  62. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js +124 -0
  63. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js.map +1 -0
  64. package/dist/node_modules/@sentry/core/build/esm/carrier.js +22 -0
  65. package/dist/node_modules/@sentry/core/build/esm/carrier.js.map +1 -0
  66. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js +34 -0
  67. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js.map +1 -0
  68. package/dist/node_modules/@sentry/core/build/esm/debug-build.js +5 -0
  69. package/dist/node_modules/@sentry/core/build/esm/debug-build.js.map +1 -0
  70. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js +13 -0
  71. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js.map +1 -0
  72. package/dist/node_modules/@sentry/core/build/esm/exports.js +13 -0
  73. package/dist/node_modules/@sentry/core/build/esm/exports.js.map +1 -0
  74. package/dist/node_modules/@sentry/core/build/esm/scope.js +577 -0
  75. package/dist/node_modules/@sentry/core/build/esm/scope.js.map +1 -0
  76. package/dist/node_modules/@sentry/core/build/esm/session.js +61 -0
  77. package/dist/node_modules/@sentry/core/build/esm/session.js.map +1 -0
  78. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js +39 -0
  79. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js.map +1 -0
  80. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js +79 -0
  81. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js.map +1 -0
  82. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js +88 -0
  83. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js.map +1 -0
  84. package/dist/node_modules/@sentry/core/build/esm/utils/is.js +35 -0
  85. package/dist/node_modules/@sentry/core/build/esm/utils/is.js.map +1 -0
  86. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js +19 -0
  87. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js.map +1 -0
  88. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js +32 -0
  89. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js.map +1 -0
  90. package/dist/node_modules/@sentry/core/build/esm/utils/object.js +18 -0
  91. package/dist/node_modules/@sentry/core/build/esm/utils/object.js.map +1 -0
  92. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js +34 -0
  93. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js.map +1 -0
  94. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js +8 -0
  95. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js.map +1 -0
  96. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js +27 -0
  97. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js.map +1 -0
  98. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js +17 -0
  99. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js.map +1 -0
  100. package/dist/node_modules/@sentry/core/build/esm/utils/string.js +10 -0
  101. package/dist/node_modules/@sentry/core/build/esm/utils/string.js.map +1 -0
  102. package/dist/node_modules/@sentry/core/build/esm/utils/time.js +26 -0
  103. package/dist/node_modules/@sentry/core/build/esm/utils/time.js.map +1 -0
  104. package/dist/node_modules/@sentry/core/build/esm/utils/version.js +5 -0
  105. package/dist/node_modules/@sentry/core/build/esm/utils/version.js.map +1 -0
  106. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js +5 -0
  107. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js.map +1 -0
  108. package/dist/node_modules/@sentry/react/build/esm/debug-build.js +5 -0
  109. package/dist/node_modules/@sentry/react/build/esm/debug-build.js.map +1 -0
  110. package/dist/node_modules/@sentry/react/build/esm/error.js +40 -0
  111. package/dist/node_modules/@sentry/react/build/esm/error.js.map +1 -0
  112. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js +103 -0
  113. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js.map +1 -0
  114. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js +0 -6
  115. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js.map +1 -1
  116. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js +0 -6
  117. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js.map +1 -1
  118. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js +8 -0
  119. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js.map +1 -0
  120. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js +0 -6
  121. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js.map +1 -1
  122. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js +8 -0
  123. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js.map +1 -0
  124. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js +0 -6
  125. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js.map +1 -1
  126. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js +0 -6
  127. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js.map +1 -1
  128. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js +0 -6
  129. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js.map +1 -1
  130. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js +0 -6
  131. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js.map +1 -1
  132. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js +0 -6
  133. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js.map +1 -1
  134. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js +0 -6
  135. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js.map +1 -1
  136. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js +0 -6
  137. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js.map +1 -1
  138. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js +0 -6
  139. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js.map +1 -1
  140. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js +0 -6
  141. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js.map +1 -1
  142. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js +1 -10
  143. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -1
  144. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js +1 -10
  145. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -1
  146. package/dist/node_modules/zustand/esm/middleware.js +202 -0
  147. package/dist/node_modules/zustand/esm/middleware.js.map +1 -0
  148. package/dist/node_modules/zustand/esm/react.js +24 -0
  149. package/dist/node_modules/zustand/esm/react.js.map +1 -0
  150. package/dist/node_modules/zustand/esm/vanilla.js +26 -0
  151. package/dist/node_modules/zustand/esm/vanilla.js.map +1 -0
  152. package/dist/states/StoredTableState.d.ts +37 -0
  153. package/dist/states/StoredTableState.js +58 -0
  154. package/dist/states/StoredTableState.js.map +1 -0
  155. package/dist/types/Forms.d.ts +2 -0
  156. package/dist/types/Plugins.d.ts +14 -7
  157. package/dist/types/Plugins.js +1 -1
  158. package/dist/types/Plugins.js.map +1 -1
  159. package/dist/types/Tables.d.ts +11 -4
  160. package/lib/components/Boundary.tsx +46 -0
  161. package/lib/components/CopyButton.tsx +76 -0
  162. package/lib/components/CopyableCell.tsx +51 -0
  163. package/lib/components/InvenTreeTable.tsx +63 -0
  164. package/lib/components/TableColumnSelect.tsx +40 -0
  165. package/lib/enums/ApiEndpoints.tsx +1 -1
  166. package/lib/enums/ModelInformation.tsx +7 -0
  167. package/lib/enums/ModelType.tsx +1 -0
  168. package/lib/functions/Forms.tsx +47 -0
  169. package/lib/functions/Notification.tsx +50 -0
  170. package/lib/functions/String.tsx +38 -0
  171. package/lib/hooks/UseFilterSet.tsx +47 -0
  172. package/lib/hooks/UseTable.tsx +149 -0
  173. package/lib/index.ts +49 -1
  174. package/lib/states/StoredTableState.tsx +91 -0
  175. package/lib/types/Forms.tsx +2 -0
  176. package/lib/types/Plugins.tsx +15 -7
  177. package/lib/types/Tables.tsx +12 -7
  178. package/package.json +2 -2
@@ -0,0 +1,577 @@
1
+ import { DEBUG_BUILD } from "./debug-build.js";
2
+ import { updateSession } from "./session.js";
3
+ import { debug } from "./utils/debug-logger.js";
4
+ import { isPlainObject } from "./utils/is.js";
5
+ import { merge } from "./utils/merge.js";
6
+ import { uuid4 } from "./utils/misc.js";
7
+ import { generateTraceId } from "./utils/propagationContext.js";
8
+ import { safeMathRandom } from "./utils/randomSafeContext.js";
9
+ import { _setSpanForScope, _getSpanForScope } from "./utils/spanOnScope.js";
10
+ import { truncate } from "./utils/string.js";
11
+ import { dateTimestampInSeconds } from "./utils/time.js";
12
+ const DEFAULT_MAX_BREADCRUMBS = 100;
13
+ class Scope {
14
+ /** Flag if notifying is happening. */
15
+ /** Callback for client to receive scope changes. */
16
+ /** Callback list that will be called during event processing. */
17
+ /** Array of breadcrumbs. */
18
+ /** User */
19
+ /** Tags */
20
+ /** Attributes */
21
+ /** Extra */
22
+ /** Contexts */
23
+ /** Attachments */
24
+ /** Propagation Context for distributed tracing */
25
+ /**
26
+ * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
27
+ * sent to Sentry
28
+ */
29
+ /** Fingerprint */
30
+ /** Severity */
31
+ /**
32
+ * Transaction Name
33
+ *
34
+ * IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.
35
+ * It's purpose is to assign a transaction to the scope that's added to non-transaction events.
36
+ */
37
+ /** Session */
38
+ /** The client on this scope */
39
+ /** Contains the last event id of a captured event. */
40
+ /** Conversation ID */
41
+ // NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
42
+ constructor() {
43
+ this._notifyingListeners = false;
44
+ this._scopeListeners = [];
45
+ this._eventProcessors = [];
46
+ this._breadcrumbs = [];
47
+ this._attachments = [];
48
+ this._user = {};
49
+ this._tags = {};
50
+ this._attributes = {};
51
+ this._extra = {};
52
+ this._contexts = {};
53
+ this._sdkProcessingMetadata = {};
54
+ this._propagationContext = {
55
+ traceId: generateTraceId(),
56
+ sampleRand: safeMathRandom()
57
+ };
58
+ }
59
+ /**
60
+ * Clone all data from this scope into a new scope.
61
+ */
62
+ clone() {
63
+ const newScope = new Scope();
64
+ newScope._breadcrumbs = [...this._breadcrumbs];
65
+ newScope._tags = { ...this._tags };
66
+ newScope._attributes = { ...this._attributes };
67
+ newScope._extra = { ...this._extra };
68
+ newScope._contexts = { ...this._contexts };
69
+ if (this._contexts.flags) {
70
+ newScope._contexts.flags = {
71
+ values: [...this._contexts.flags.values]
72
+ };
73
+ }
74
+ newScope._user = this._user;
75
+ newScope._level = this._level;
76
+ newScope._session = this._session;
77
+ newScope._transactionName = this._transactionName;
78
+ newScope._fingerprint = this._fingerprint;
79
+ newScope._eventProcessors = [...this._eventProcessors];
80
+ newScope._attachments = [...this._attachments];
81
+ newScope._sdkProcessingMetadata = { ...this._sdkProcessingMetadata };
82
+ newScope._propagationContext = { ...this._propagationContext };
83
+ newScope._client = this._client;
84
+ newScope._lastEventId = this._lastEventId;
85
+ newScope._conversationId = this._conversationId;
86
+ _setSpanForScope(newScope, _getSpanForScope(this));
87
+ return newScope;
88
+ }
89
+ /**
90
+ * Update the client assigned to this scope.
91
+ * Note that not every scope will have a client assigned - isolation scopes & the global scope will generally not have a client,
92
+ * as well as manually created scopes.
93
+ */
94
+ setClient(client) {
95
+ this._client = client;
96
+ }
97
+ /**
98
+ * Set the ID of the last captured error event.
99
+ * This is generally only captured on the isolation scope.
100
+ */
101
+ setLastEventId(lastEventId) {
102
+ this._lastEventId = lastEventId;
103
+ }
104
+ /**
105
+ * Get the client assigned to this scope.
106
+ */
107
+ getClient() {
108
+ return this._client;
109
+ }
110
+ /**
111
+ * Get the ID of the last captured error event.
112
+ * This is generally only available on the isolation scope.
113
+ */
114
+ lastEventId() {
115
+ return this._lastEventId;
116
+ }
117
+ /**
118
+ * @inheritDoc
119
+ */
120
+ addScopeListener(callback) {
121
+ this._scopeListeners.push(callback);
122
+ }
123
+ /**
124
+ * Add an event processor that will be called before an event is sent.
125
+ */
126
+ addEventProcessor(callback) {
127
+ this._eventProcessors.push(callback);
128
+ return this;
129
+ }
130
+ /**
131
+ * Set the user for this scope.
132
+ * Set to `null` to unset the user.
133
+ */
134
+ setUser(user) {
135
+ this._user = user || {
136
+ email: void 0,
137
+ id: void 0,
138
+ ip_address: void 0,
139
+ username: void 0
140
+ };
141
+ if (this._session) {
142
+ updateSession(this._session, { user });
143
+ }
144
+ this._notifyScopeListeners();
145
+ return this;
146
+ }
147
+ /**
148
+ * Get the user from this scope.
149
+ */
150
+ getUser() {
151
+ return this._user;
152
+ }
153
+ /**
154
+ * Set the conversation ID for this scope.
155
+ * Set to `null` to unset the conversation ID.
156
+ */
157
+ setConversationId(conversationId) {
158
+ this._conversationId = conversationId || void 0;
159
+ this._notifyScopeListeners();
160
+ return this;
161
+ }
162
+ /**
163
+ * Set an object that will be merged into existing tags on the scope,
164
+ * and will be sent as tags data with the event.
165
+ */
166
+ setTags(tags) {
167
+ this._tags = {
168
+ ...this._tags,
169
+ ...tags
170
+ };
171
+ this._notifyScopeListeners();
172
+ return this;
173
+ }
174
+ /**
175
+ * Set a single tag that will be sent as tags data with the event.
176
+ */
177
+ setTag(key, value) {
178
+ return this.setTags({ [key]: value });
179
+ }
180
+ /**
181
+ * Sets attributes onto the scope.
182
+ *
183
+ * These attributes are currently applied to logs and metrics.
184
+ * In the future, they will also be applied to spans.
185
+ *
186
+ * Important: For now, only strings, numbers and boolean attributes are supported, despite types allowing for
187
+ * more complex attribute types. We'll add this support in the future but already specify the wider type to
188
+ * avoid a breaking change in the future.
189
+ *
190
+ * @param newAttributes - The attributes to set on the scope. You can either pass in key-value pairs, or
191
+ * an object with a `value` and an optional `unit` (if applicable to your attribute).
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * scope.setAttributes({
196
+ * is_admin: true,
197
+ * payment_selection: 'credit_card',
198
+ * render_duration: { value: 'render_duration', unit: 'ms' },
199
+ * });
200
+ * ```
201
+ */
202
+ setAttributes(newAttributes) {
203
+ this._attributes = {
204
+ ...this._attributes,
205
+ ...newAttributes
206
+ };
207
+ this._notifyScopeListeners();
208
+ return this;
209
+ }
210
+ /**
211
+ * Sets an attribute onto the scope.
212
+ *
213
+ * These attributes are currently applied to logs and metrics.
214
+ * In the future, they will also be applied to spans.
215
+ *
216
+ * Important: For now, only strings, numbers and boolean attributes are supported, despite types allowing for
217
+ * more complex attribute types. We'll add this support in the future but already specify the wider type to
218
+ * avoid a breaking change in the future.
219
+ *
220
+ * @param key - The attribute key.
221
+ * @param value - the attribute value. You can either pass in a raw value, or an attribute
222
+ * object with a `value` and an optional `unit` (if applicable to your attribute).
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * scope.setAttribute('is_admin', true);
227
+ * scope.setAttribute('render_duration', { value: 'render_duration', unit: 'ms' });
228
+ * ```
229
+ */
230
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
+ setAttribute(key, value) {
232
+ return this.setAttributes({ [key]: value });
233
+ }
234
+ /**
235
+ * Removes the attribute with the given key from the scope.
236
+ *
237
+ * @param key - The attribute key.
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * scope.removeAttribute('is_admin');
242
+ * ```
243
+ */
244
+ removeAttribute(key) {
245
+ if (key in this._attributes) {
246
+ delete this._attributes[key];
247
+ this._notifyScopeListeners();
248
+ }
249
+ return this;
250
+ }
251
+ /**
252
+ * Set an object that will be merged into existing extra on the scope,
253
+ * and will be sent as extra data with the event.
254
+ */
255
+ setExtras(extras) {
256
+ this._extra = {
257
+ ...this._extra,
258
+ ...extras
259
+ };
260
+ this._notifyScopeListeners();
261
+ return this;
262
+ }
263
+ /**
264
+ * Set a single key:value extra entry that will be sent as extra data with the event.
265
+ */
266
+ setExtra(key, extra) {
267
+ this._extra = { ...this._extra, [key]: extra };
268
+ this._notifyScopeListeners();
269
+ return this;
270
+ }
271
+ /**
272
+ * Sets the fingerprint on the scope to send with the events.
273
+ * @param {string[]} fingerprint Fingerprint to group events in Sentry.
274
+ */
275
+ setFingerprint(fingerprint) {
276
+ this._fingerprint = fingerprint;
277
+ this._notifyScopeListeners();
278
+ return this;
279
+ }
280
+ /**
281
+ * Sets the level on the scope for future events.
282
+ */
283
+ setLevel(level) {
284
+ this._level = level;
285
+ this._notifyScopeListeners();
286
+ return this;
287
+ }
288
+ /**
289
+ * Sets the transaction name on the scope so that the name of e.g. taken server route or
290
+ * the page location is attached to future events.
291
+ *
292
+ * IMPORTANT: Calling this function does NOT change the name of the currently active
293
+ * root span. If you want to change the name of the active root span, use
294
+ * `Sentry.updateSpanName(rootSpan, 'new name')` instead.
295
+ *
296
+ * By default, the SDK updates the scope's transaction name automatically on sensible
297
+ * occasions, such as a page navigation or when handling a new request on the server.
298
+ */
299
+ setTransactionName(name) {
300
+ this._transactionName = name;
301
+ this._notifyScopeListeners();
302
+ return this;
303
+ }
304
+ /**
305
+ * Sets context data with the given name.
306
+ * Data passed as context will be normalized. You can also pass `null` to unset the context.
307
+ * Note that context data will not be merged - calling `setContext` will overwrite an existing context with the same key.
308
+ */
309
+ setContext(key, context) {
310
+ if (context === null) {
311
+ delete this._contexts[key];
312
+ } else {
313
+ this._contexts[key] = context;
314
+ }
315
+ this._notifyScopeListeners();
316
+ return this;
317
+ }
318
+ /**
319
+ * Set the session for the scope.
320
+ */
321
+ setSession(session) {
322
+ if (!session) {
323
+ delete this._session;
324
+ } else {
325
+ this._session = session;
326
+ }
327
+ this._notifyScopeListeners();
328
+ return this;
329
+ }
330
+ /**
331
+ * Get the session from the scope.
332
+ */
333
+ getSession() {
334
+ return this._session;
335
+ }
336
+ /**
337
+ * Updates the scope with provided data. Can work in three variations:
338
+ * - plain object containing updatable attributes
339
+ * - Scope instance that'll extract the attributes from
340
+ * - callback function that'll receive the current scope as an argument and allow for modifications
341
+ */
342
+ update(captureContext) {
343
+ if (!captureContext) {
344
+ return this;
345
+ }
346
+ const scopeToMerge = typeof captureContext === "function" ? captureContext(this) : captureContext;
347
+ const scopeInstance = scopeToMerge instanceof Scope ? scopeToMerge.getScopeData() : isPlainObject(scopeToMerge) ? captureContext : void 0;
348
+ const {
349
+ tags,
350
+ attributes,
351
+ extra,
352
+ user,
353
+ contexts,
354
+ level,
355
+ fingerprint = [],
356
+ propagationContext,
357
+ conversationId
358
+ } = scopeInstance || {};
359
+ this._tags = { ...this._tags, ...tags };
360
+ this._attributes = { ...this._attributes, ...attributes };
361
+ this._extra = { ...this._extra, ...extra };
362
+ this._contexts = { ...this._contexts, ...contexts };
363
+ if (user && Object.keys(user).length) {
364
+ this._user = user;
365
+ }
366
+ if (level) {
367
+ this._level = level;
368
+ }
369
+ if (fingerprint.length) {
370
+ this._fingerprint = fingerprint;
371
+ }
372
+ if (propagationContext) {
373
+ this._propagationContext = propagationContext;
374
+ }
375
+ if (conversationId) {
376
+ this._conversationId = conversationId;
377
+ }
378
+ return this;
379
+ }
380
+ /**
381
+ * Clears the current scope and resets its properties.
382
+ * Note: The client will not be cleared.
383
+ */
384
+ clear() {
385
+ this._breadcrumbs = [];
386
+ this._tags = {};
387
+ this._attributes = {};
388
+ this._extra = {};
389
+ this._user = {};
390
+ this._contexts = {};
391
+ this._level = void 0;
392
+ this._transactionName = void 0;
393
+ this._fingerprint = void 0;
394
+ this._session = void 0;
395
+ this._conversationId = void 0;
396
+ _setSpanForScope(this, void 0);
397
+ this._attachments = [];
398
+ this.setPropagationContext({
399
+ traceId: generateTraceId(),
400
+ sampleRand: safeMathRandom()
401
+ });
402
+ this._notifyScopeListeners();
403
+ return this;
404
+ }
405
+ /**
406
+ * Adds a breadcrumb to the scope.
407
+ * By default, the last 100 breadcrumbs are kept.
408
+ */
409
+ addBreadcrumb(breadcrumb, maxBreadcrumbs) {
410
+ const maxCrumbs = typeof maxBreadcrumbs === "number" ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
411
+ if (maxCrumbs <= 0) {
412
+ return this;
413
+ }
414
+ const mergedBreadcrumb = {
415
+ timestamp: dateTimestampInSeconds(),
416
+ ...breadcrumb,
417
+ // Breadcrumb messages can theoretically be infinitely large and they're held in memory so we truncate them not to leak (too much) memory
418
+ message: breadcrumb.message ? truncate(breadcrumb.message, 2048) : breadcrumb.message
419
+ };
420
+ this._breadcrumbs.push(mergedBreadcrumb);
421
+ if (this._breadcrumbs.length > maxCrumbs) {
422
+ this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
423
+ this._client?.recordDroppedEvent("buffer_overflow", "log_item");
424
+ }
425
+ this._notifyScopeListeners();
426
+ return this;
427
+ }
428
+ /**
429
+ * Get the last breadcrumb of the scope.
430
+ */
431
+ getLastBreadcrumb() {
432
+ return this._breadcrumbs[this._breadcrumbs.length - 1];
433
+ }
434
+ /**
435
+ * Clear all breadcrumbs from the scope.
436
+ */
437
+ clearBreadcrumbs() {
438
+ this._breadcrumbs = [];
439
+ this._notifyScopeListeners();
440
+ return this;
441
+ }
442
+ /**
443
+ * Add an attachment to the scope.
444
+ */
445
+ addAttachment(attachment) {
446
+ this._attachments.push(attachment);
447
+ return this;
448
+ }
449
+ /**
450
+ * Clear all attachments from the scope.
451
+ */
452
+ clearAttachments() {
453
+ this._attachments = [];
454
+ return this;
455
+ }
456
+ /**
457
+ * Get the data of this scope, which should be applied to an event during processing.
458
+ */
459
+ getScopeData() {
460
+ return {
461
+ breadcrumbs: this._breadcrumbs,
462
+ attachments: this._attachments,
463
+ contexts: this._contexts,
464
+ tags: this._tags,
465
+ attributes: this._attributes,
466
+ extra: this._extra,
467
+ user: this._user,
468
+ level: this._level,
469
+ fingerprint: this._fingerprint || [],
470
+ eventProcessors: this._eventProcessors,
471
+ propagationContext: this._propagationContext,
472
+ sdkProcessingMetadata: this._sdkProcessingMetadata,
473
+ transactionName: this._transactionName,
474
+ span: _getSpanForScope(this),
475
+ conversationId: this._conversationId
476
+ };
477
+ }
478
+ /**
479
+ * Add data which will be accessible during event processing but won't get sent to Sentry.
480
+ */
481
+ setSDKProcessingMetadata(newData) {
482
+ this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2);
483
+ return this;
484
+ }
485
+ /**
486
+ * Add propagation context to the scope, used for distributed tracing
487
+ */
488
+ setPropagationContext(context) {
489
+ this._propagationContext = context;
490
+ return this;
491
+ }
492
+ /**
493
+ * Get propagation context from the scope, used for distributed tracing
494
+ */
495
+ getPropagationContext() {
496
+ return this._propagationContext;
497
+ }
498
+ /**
499
+ * Capture an exception for this scope.
500
+ *
501
+ * @returns {string} The id of the captured Sentry event.
502
+ */
503
+ captureException(exception, hint) {
504
+ const eventId = hint?.event_id || uuid4();
505
+ if (!this._client) {
506
+ DEBUG_BUILD && debug.warn("No client configured on scope - will not capture exception!");
507
+ return eventId;
508
+ }
509
+ const syntheticException = new Error("Sentry syntheticException");
510
+ this._client.captureException(
511
+ exception,
512
+ {
513
+ originalException: exception,
514
+ syntheticException,
515
+ ...hint,
516
+ event_id: eventId
517
+ },
518
+ this
519
+ );
520
+ return eventId;
521
+ }
522
+ /**
523
+ * Capture a message for this scope.
524
+ *
525
+ * @returns {string} The id of the captured message.
526
+ */
527
+ captureMessage(message, level, hint) {
528
+ const eventId = hint?.event_id || uuid4();
529
+ if (!this._client) {
530
+ DEBUG_BUILD && debug.warn("No client configured on scope - will not capture message!");
531
+ return eventId;
532
+ }
533
+ const syntheticException = hint?.syntheticException ?? new Error(message);
534
+ this._client.captureMessage(
535
+ message,
536
+ level,
537
+ {
538
+ originalException: message,
539
+ syntheticException,
540
+ ...hint,
541
+ event_id: eventId
542
+ },
543
+ this
544
+ );
545
+ return eventId;
546
+ }
547
+ /**
548
+ * Capture a Sentry event for this scope.
549
+ *
550
+ * @returns {string} The id of the captured event.
551
+ */
552
+ captureEvent(event, hint) {
553
+ const eventId = event.event_id || hint?.event_id || uuid4();
554
+ if (!this._client) {
555
+ DEBUG_BUILD && debug.warn("No client configured on scope - will not capture event!");
556
+ return eventId;
557
+ }
558
+ this._client.captureEvent(event, { ...hint, event_id: eventId }, this);
559
+ return eventId;
560
+ }
561
+ /**
562
+ * This will be called on every set call.
563
+ */
564
+ _notifyScopeListeners() {
565
+ if (!this._notifyingListeners) {
566
+ this._notifyingListeners = true;
567
+ this._scopeListeners.forEach((callback) => {
568
+ callback(this);
569
+ });
570
+ this._notifyingListeners = false;
571
+ }
572
+ }
573
+ }
574
+ export {
575
+ Scope
576
+ };
577
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sources":["../../../../../../node_modules/@sentry/core/build/esm/scope.js"],"sourcesContent":["import { DEBUG_BUILD } from './debug-build.js';\nimport { updateSession } from './session.js';\nimport { debug } from './utils/debug-logger.js';\nimport { isPlainObject } from './utils/is.js';\nimport { merge } from './utils/merge.js';\nimport { uuid4 } from './utils/misc.js';\nimport { generateTraceId } from './utils/propagationContext.js';\nimport { safeMathRandom } from './utils/randomSafeContext.js';\nimport { _setSpanForScope, _getSpanForScope } from './utils/spanOnScope.js';\nimport { truncate } from './utils/string.js';\nimport { dateTimestampInSeconds } from './utils/time.js';\n\n/**\n * Default value for maximum number of breadcrumbs added to an event.\n */\nconst DEFAULT_MAX_BREADCRUMBS = 100;\n\n/**\n * A context to be used for capturing an event.\n * This can either be a Scope, or a partial ScopeContext,\n * or a callback that receives the current scope and returns a new scope to use.\n */\n\n/**\n * Holds additional event information.\n */\nclass Scope {\n /** Flag if notifying is happening. */\n\n /** Callback for client to receive scope changes. */\n\n /** Callback list that will be called during event processing. */\n\n /** Array of breadcrumbs. */\n\n /** User */\n\n /** Tags */\n\n /** Attributes */\n\n /** Extra */\n\n /** Contexts */\n\n /** Attachments */\n\n /** Propagation Context for distributed tracing */\n\n /**\n * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get\n * sent to Sentry\n */\n\n /** Fingerprint */\n\n /** Severity */\n\n /**\n * Transaction Name\n *\n * IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.\n * It's purpose is to assign a transaction to the scope that's added to non-transaction events.\n */\n\n /** Session */\n\n /** The client on this scope */\n\n /** Contains the last event id of a captured event. */\n\n /** Conversation ID */\n\n // NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.\n\n constructor() {\n this._notifyingListeners = false;\n this._scopeListeners = [];\n this._eventProcessors = [];\n this._breadcrumbs = [];\n this._attachments = [];\n this._user = {};\n this._tags = {};\n this._attributes = {};\n this._extra = {};\n this._contexts = {};\n this._sdkProcessingMetadata = {};\n this._propagationContext = {\n traceId: generateTraceId(),\n sampleRand: safeMathRandom(),\n };\n }\n\n /**\n * Clone all data from this scope into a new scope.\n */\n clone() {\n const newScope = new Scope();\n newScope._breadcrumbs = [...this._breadcrumbs];\n newScope._tags = { ...this._tags };\n newScope._attributes = { ...this._attributes };\n newScope._extra = { ...this._extra };\n newScope._contexts = { ...this._contexts };\n if (this._contexts.flags) {\n // We need to copy the `values` array so insertions on a cloned scope\n // won't affect the original array.\n newScope._contexts.flags = {\n values: [...this._contexts.flags.values],\n };\n }\n\n newScope._user = this._user;\n newScope._level = this._level;\n newScope._session = this._session;\n newScope._transactionName = this._transactionName;\n newScope._fingerprint = this._fingerprint;\n newScope._eventProcessors = [...this._eventProcessors];\n newScope._attachments = [...this._attachments];\n newScope._sdkProcessingMetadata = { ...this._sdkProcessingMetadata };\n newScope._propagationContext = { ...this._propagationContext };\n newScope._client = this._client;\n newScope._lastEventId = this._lastEventId;\n newScope._conversationId = this._conversationId;\n\n _setSpanForScope(newScope, _getSpanForScope(this));\n\n return newScope;\n }\n\n /**\n * Update the client assigned to this scope.\n * Note that not every scope will have a client assigned - isolation scopes & the global scope will generally not have a client,\n * as well as manually created scopes.\n */\n setClient(client) {\n this._client = client;\n }\n\n /**\n * Set the ID of the last captured error event.\n * This is generally only captured on the isolation scope.\n */\n setLastEventId(lastEventId) {\n this._lastEventId = lastEventId;\n }\n\n /**\n * Get the client assigned to this scope.\n */\n getClient() {\n return this._client ;\n }\n\n /**\n * Get the ID of the last captured error event.\n * This is generally only available on the isolation scope.\n */\n lastEventId() {\n return this._lastEventId;\n }\n\n /**\n * @inheritDoc\n */\n addScopeListener(callback) {\n this._scopeListeners.push(callback);\n }\n\n /**\n * Add an event processor that will be called before an event is sent.\n */\n addEventProcessor(callback) {\n this._eventProcessors.push(callback);\n return this;\n }\n\n /**\n * Set the user for this scope.\n * Set to `null` to unset the user.\n */\n setUser(user) {\n // If null is passed we want to unset everything, but still define keys,\n // so that later down in the pipeline any existing values are cleared.\n this._user = user || {\n email: undefined,\n id: undefined,\n ip_address: undefined,\n username: undefined,\n };\n\n if (this._session) {\n updateSession(this._session, { user });\n }\n\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Get the user from this scope.\n */\n getUser() {\n return this._user;\n }\n\n /**\n * Set the conversation ID for this scope.\n * Set to `null` to unset the conversation ID.\n */\n setConversationId(conversationId) {\n this._conversationId = conversationId || undefined;\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Set an object that will be merged into existing tags on the scope,\n * and will be sent as tags data with the event.\n */\n setTags(tags) {\n this._tags = {\n ...this._tags,\n ...tags,\n };\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Set a single tag that will be sent as tags data with the event.\n */\n setTag(key, value) {\n return this.setTags({ [key]: value });\n }\n\n /**\n * Sets attributes onto the scope.\n *\n * These attributes are currently applied to logs and metrics.\n * In the future, they will also be applied to spans.\n *\n * Important: For now, only strings, numbers and boolean attributes are supported, despite types allowing for\n * more complex attribute types. We'll add this support in the future but already specify the wider type to\n * avoid a breaking change in the future.\n *\n * @param newAttributes - The attributes to set on the scope. You can either pass in key-value pairs, or\n * an object with a `value` and an optional `unit` (if applicable to your attribute).\n *\n * @example\n * ```typescript\n * scope.setAttributes({\n * is_admin: true,\n * payment_selection: 'credit_card',\n * render_duration: { value: 'render_duration', unit: 'ms' },\n * });\n * ```\n */\n setAttributes(newAttributes) {\n this._attributes = {\n ...this._attributes,\n ...newAttributes,\n };\n\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Sets an attribute onto the scope.\n *\n * These attributes are currently applied to logs and metrics.\n * In the future, they will also be applied to spans.\n *\n * Important: For now, only strings, numbers and boolean attributes are supported, despite types allowing for\n * more complex attribute types. We'll add this support in the future but already specify the wider type to\n * avoid a breaking change in the future.\n *\n * @param key - The attribute key.\n * @param value - the attribute value. You can either pass in a raw value, or an attribute\n * object with a `value` and an optional `unit` (if applicable to your attribute).\n *\n * @example\n * ```typescript\n * scope.setAttribute('is_admin', true);\n * scope.setAttribute('render_duration', { value: 'render_duration', unit: 'ms' });\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setAttribute(\n key,\n value,\n ) {\n return this.setAttributes({ [key]: value });\n }\n\n /**\n * Removes the attribute with the given key from the scope.\n *\n * @param key - The attribute key.\n *\n * @example\n * ```typescript\n * scope.removeAttribute('is_admin');\n * ```\n */\n removeAttribute(key) {\n if (key in this._attributes) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n this._notifyScopeListeners();\n }\n return this;\n }\n\n /**\n * Set an object that will be merged into existing extra on the scope,\n * and will be sent as extra data with the event.\n */\n setExtras(extras) {\n this._extra = {\n ...this._extra,\n ...extras,\n };\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Set a single key:value extra entry that will be sent as extra data with the event.\n */\n setExtra(key, extra) {\n this._extra = { ...this._extra, [key]: extra };\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Sets the fingerprint on the scope to send with the events.\n * @param {string[]} fingerprint Fingerprint to group events in Sentry.\n */\n setFingerprint(fingerprint) {\n this._fingerprint = fingerprint;\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Sets the level on the scope for future events.\n */\n setLevel(level) {\n this._level = level;\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Sets the transaction name on the scope so that the name of e.g. taken server route or\n * the page location is attached to future events.\n *\n * IMPORTANT: Calling this function does NOT change the name of the currently active\n * root span. If you want to change the name of the active root span, use\n * `Sentry.updateSpanName(rootSpan, 'new name')` instead.\n *\n * By default, the SDK updates the scope's transaction name automatically on sensible\n * occasions, such as a page navigation or when handling a new request on the server.\n */\n setTransactionName(name) {\n this._transactionName = name;\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Sets context data with the given name.\n * Data passed as context will be normalized. You can also pass `null` to unset the context.\n * Note that context data will not be merged - calling `setContext` will overwrite an existing context with the same key.\n */\n setContext(key, context) {\n if (context === null) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._contexts[key];\n } else {\n this._contexts[key] = context;\n }\n\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Set the session for the scope.\n */\n setSession(session) {\n if (!session) {\n delete this._session;\n } else {\n this._session = session;\n }\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Get the session from the scope.\n */\n getSession() {\n return this._session;\n }\n\n /**\n * Updates the scope with provided data. Can work in three variations:\n * - plain object containing updatable attributes\n * - Scope instance that'll extract the attributes from\n * - callback function that'll receive the current scope as an argument and allow for modifications\n */\n update(captureContext) {\n if (!captureContext) {\n return this;\n }\n\n const scopeToMerge = typeof captureContext === 'function' ? captureContext(this) : captureContext;\n\n const scopeInstance =\n scopeToMerge instanceof Scope\n ? scopeToMerge.getScopeData()\n : isPlainObject(scopeToMerge)\n ? (captureContext )\n : undefined;\n\n const {\n tags,\n attributes,\n extra,\n user,\n contexts,\n level,\n fingerprint = [],\n propagationContext,\n conversationId,\n } = scopeInstance || {};\n\n this._tags = { ...this._tags, ...tags };\n this._attributes = { ...this._attributes, ...attributes };\n this._extra = { ...this._extra, ...extra };\n this._contexts = { ...this._contexts, ...contexts };\n\n if (user && Object.keys(user).length) {\n this._user = user;\n }\n\n if (level) {\n this._level = level;\n }\n\n if (fingerprint.length) {\n this._fingerprint = fingerprint;\n }\n\n if (propagationContext) {\n this._propagationContext = propagationContext;\n }\n\n if (conversationId) {\n this._conversationId = conversationId;\n }\n\n return this;\n }\n\n /**\n * Clears the current scope and resets its properties.\n * Note: The client will not be cleared.\n */\n clear() {\n // client is not cleared here on purpose!\n this._breadcrumbs = [];\n this._tags = {};\n this._attributes = {};\n this._extra = {};\n this._user = {};\n this._contexts = {};\n this._level = undefined;\n this._transactionName = undefined;\n this._fingerprint = undefined;\n this._session = undefined;\n this._conversationId = undefined;\n _setSpanForScope(this, undefined);\n this._attachments = [];\n this.setPropagationContext({\n traceId: generateTraceId(),\n sampleRand: safeMathRandom(),\n });\n\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Adds a breadcrumb to the scope.\n * By default, the last 100 breadcrumbs are kept.\n */\n addBreadcrumb(breadcrumb, maxBreadcrumbs) {\n const maxCrumbs = typeof maxBreadcrumbs === 'number' ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;\n\n // No data has been changed, so don't notify scope listeners\n if (maxCrumbs <= 0) {\n return this;\n }\n\n const mergedBreadcrumb = {\n timestamp: dateTimestampInSeconds(),\n ...breadcrumb,\n // Breadcrumb messages can theoretically be infinitely large and they're held in memory so we truncate them not to leak (too much) memory\n message: breadcrumb.message ? truncate(breadcrumb.message, 2048) : breadcrumb.message,\n };\n\n this._breadcrumbs.push(mergedBreadcrumb);\n if (this._breadcrumbs.length > maxCrumbs) {\n this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);\n this._client?.recordDroppedEvent('buffer_overflow', 'log_item');\n }\n\n this._notifyScopeListeners();\n\n return this;\n }\n\n /**\n * Get the last breadcrumb of the scope.\n */\n getLastBreadcrumb() {\n return this._breadcrumbs[this._breadcrumbs.length - 1];\n }\n\n /**\n * Clear all breadcrumbs from the scope.\n */\n clearBreadcrumbs() {\n this._breadcrumbs = [];\n this._notifyScopeListeners();\n return this;\n }\n\n /**\n * Add an attachment to the scope.\n */\n addAttachment(attachment) {\n this._attachments.push(attachment);\n return this;\n }\n\n /**\n * Clear all attachments from the scope.\n */\n clearAttachments() {\n this._attachments = [];\n return this;\n }\n\n /**\n * Get the data of this scope, which should be applied to an event during processing.\n */\n getScopeData() {\n return {\n breadcrumbs: this._breadcrumbs,\n attachments: this._attachments,\n contexts: this._contexts,\n tags: this._tags,\n attributes: this._attributes,\n extra: this._extra,\n user: this._user,\n level: this._level,\n fingerprint: this._fingerprint || [],\n eventProcessors: this._eventProcessors,\n propagationContext: this._propagationContext,\n sdkProcessingMetadata: this._sdkProcessingMetadata,\n transactionName: this._transactionName,\n span: _getSpanForScope(this),\n conversationId: this._conversationId,\n };\n }\n\n /**\n * Add data which will be accessible during event processing but won't get sent to Sentry.\n */\n setSDKProcessingMetadata(newData) {\n this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2);\n return this;\n }\n\n /**\n * Add propagation context to the scope, used for distributed tracing\n */\n setPropagationContext(context) {\n this._propagationContext = context;\n return this;\n }\n\n /**\n * Get propagation context from the scope, used for distributed tracing\n */\n getPropagationContext() {\n return this._propagationContext;\n }\n\n /**\n * Capture an exception for this scope.\n *\n * @returns {string} The id of the captured Sentry event.\n */\n captureException(exception, hint) {\n const eventId = hint?.event_id || uuid4();\n\n if (!this._client) {\n DEBUG_BUILD && debug.warn('No client configured on scope - will not capture exception!');\n return eventId;\n }\n\n const syntheticException = new Error('Sentry syntheticException');\n\n this._client.captureException(\n exception,\n {\n originalException: exception,\n syntheticException,\n ...hint,\n event_id: eventId,\n },\n this,\n );\n\n return eventId;\n }\n\n /**\n * Capture a message for this scope.\n *\n * @returns {string} The id of the captured message.\n */\n captureMessage(message, level, hint) {\n const eventId = hint?.event_id || uuid4();\n\n if (!this._client) {\n DEBUG_BUILD && debug.warn('No client configured on scope - will not capture message!');\n return eventId;\n }\n\n const syntheticException = hint?.syntheticException ?? new Error(message);\n\n this._client.captureMessage(\n message,\n level,\n {\n originalException: message,\n syntheticException,\n ...hint,\n event_id: eventId,\n },\n this,\n );\n\n return eventId;\n }\n\n /**\n * Capture a Sentry event for this scope.\n *\n * @returns {string} The id of the captured event.\n */\n captureEvent(event, hint) {\n const eventId = event.event_id || hint?.event_id || uuid4();\n\n if (!this._client) {\n DEBUG_BUILD && debug.warn('No client configured on scope - will not capture event!');\n return eventId;\n }\n\n this._client.captureEvent(event, { ...hint, event_id: eventId }, this);\n\n return eventId;\n }\n\n /**\n * This will be called on every set call.\n */\n _notifyScopeListeners() {\n // We need this check for this._notifyingListeners to be able to work on scope during updates\n // If this check is not here we'll produce endless recursion when something is done with the scope\n // during the callback.\n if (!this._notifyingListeners) {\n this._notifyingListeners = true;\n this._scopeListeners.forEach(callback => {\n callback(this);\n });\n this._notifyingListeners = false;\n }\n }\n}\n\nexport { Scope };\n//# sourceMappingURL=scope.js.map\n"],"names":[],"mappings":";;;;;;;;;;;AAeA,MAAM,0BAA0B;AAWhC,MAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiDT,cAAc;AACb,SAAK,sBAAsB;AAC3B,SAAK,kBAAkB,CAAA;AACvB,SAAK,mBAAmB,CAAA;AACxB,SAAK,eAAe,CAAA;AACpB,SAAK,eAAe,CAAA;AACpB,SAAK,QAAQ,CAAA;AACb,SAAK,QAAQ,CAAA;AACb,SAAK,cAAc,CAAA;AACnB,SAAK,SAAS,CAAA;AACd,SAAK,YAAY,CAAA;AACjB,SAAK,yBAAyB,CAAA;AAC9B,SAAK,sBAAsB;AAAA,MACzB,SAAS,gBAAe;AAAA,MACxB,YAAY,eAAc;AAAA,IAChC;AAAA,EACE;AAAA;AAAA;AAAA;AAAA,EAKC,QAAQ;AACP,UAAM,WAAW,IAAI,MAAK;AAC1B,aAAS,eAAe,CAAC,GAAG,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,MAAM,YAAY,MAAK;AAEvC,QAAI,CAAC,KAAK,SAAS;AACjB,qBAAe,MAAM,KAAK,2DAA2D;AACrF,aAAO;AAAA,IACT;AAEA,UAAM,qBAAqB,MAAM,sBAAsB,IAAI,MAAM,OAAO;AAExE,SAAK,QAAQ;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,QACE,mBAAmB;AAAA,QACnB;AAAA,QACA,GAAG;AAAA,QACH,UAAU;AAAA,MAClB;AAAA,MACM;AAAA,IACN;AAEI,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOC,aAAa,OAAO,MAAM;AACzB,UAAM,UAAU,MAAM,YAAY,MAAM,YAAY,MAAK;AAEzD,QAAI,CAAC,KAAK,SAAS;AACjB,qBAAe,MAAM,KAAK,yDAAyD;AACnF,aAAO;AAAA,IACT;AAEA,SAAK,QAAQ,aAAa,OAAO,EAAE,GAAG,MAAM,UAAU,QAAO,GAAI,IAAI;AAErE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKC,wBAAwB;AAIvB,QAAI,CAAC,KAAK,qBAAqB;AAC7B,WAAK,sBAAsB;AAC3B,WAAK,gBAAgB,QAAQ,cAAY;AACvC,iBAAS,IAAI;AAAA,MACf,CAAC;AACD,WAAK,sBAAsB;AAAA,IAC7B;AAAA,EACF;AACF;","x_google_ignoreList":[0]}
@@ -0,0 +1,61 @@
1
+ import { uuid4 } from "./utils/misc.js";
2
+ import { timestampInSeconds } from "./utils/time.js";
3
+ function updateSession(session, context = {}) {
4
+ if (context.user) {
5
+ if (!session.ipAddress && context.user.ip_address) {
6
+ session.ipAddress = context.user.ip_address;
7
+ }
8
+ if (!session.did && !context.did) {
9
+ session.did = context.user.id || context.user.email || context.user.username;
10
+ }
11
+ }
12
+ session.timestamp = context.timestamp || timestampInSeconds();
13
+ if (context.abnormal_mechanism) {
14
+ session.abnormal_mechanism = context.abnormal_mechanism;
15
+ }
16
+ if (context.ignoreDuration) {
17
+ session.ignoreDuration = context.ignoreDuration;
18
+ }
19
+ if (context.sid) {
20
+ session.sid = context.sid.length === 32 ? context.sid : uuid4();
21
+ }
22
+ if (context.init !== void 0) {
23
+ session.init = context.init;
24
+ }
25
+ if (!session.did && context.did) {
26
+ session.did = `${context.did}`;
27
+ }
28
+ if (typeof context.started === "number") {
29
+ session.started = context.started;
30
+ }
31
+ if (session.ignoreDuration) {
32
+ session.duration = void 0;
33
+ } else if (typeof context.duration === "number") {
34
+ session.duration = context.duration;
35
+ } else {
36
+ const duration = session.timestamp - session.started;
37
+ session.duration = duration >= 0 ? duration : 0;
38
+ }
39
+ if (context.release) {
40
+ session.release = context.release;
41
+ }
42
+ if (context.environment) {
43
+ session.environment = context.environment;
44
+ }
45
+ if (!session.ipAddress && context.ipAddress) {
46
+ session.ipAddress = context.ipAddress;
47
+ }
48
+ if (!session.userAgent && context.userAgent) {
49
+ session.userAgent = context.userAgent;
50
+ }
51
+ if (typeof context.errors === "number") {
52
+ session.errors = context.errors;
53
+ }
54
+ if (context.status) {
55
+ session.status = context.status;
56
+ }
57
+ }
58
+ export {
59
+ updateSession
60
+ };
61
+ //# sourceMappingURL=session.js.map