@datadog/mobile-react-native 3.2.0 → 3.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.
Files changed (67) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +1 -0
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/ios/Sources/Attributes.swift +25 -0
  5. package/ios/Sources/SdkVersion.swift +1 -1
  6. package/lib/commonjs/DdAttributes.js +7 -1
  7. package/lib/commonjs/DdAttributes.js.map +1 -1
  8. package/lib/commonjs/index.js +12 -0
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  11. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  12. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +4 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +51 -0
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +35 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +170 -0
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  22. package/lib/commonjs/version.js +1 -1
  23. package/lib/module/DdAttributes.js +7 -1
  24. package/lib/module/DdAttributes.js.map +1 -1
  25. package/lib/module/index.js +2 -2
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  28. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  29. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +3 -2
  30. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  31. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +45 -0
  32. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  33. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  34. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  35. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +36 -2
  36. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  37. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +161 -0
  38. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  39. package/lib/module/version.js +1 -1
  40. package/lib/typescript/DdAttributes.d.ts +6 -0
  41. package/lib/typescript/DdAttributes.d.ts.map +1 -1
  42. package/lib/typescript/index.d.ts +2 -2
  43. package/lib/typescript/index.d.ts.map +1 -1
  44. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +2 -0
  45. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
  46. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts +7 -0
  47. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts.map +1 -0
  48. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  49. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts +36 -0
  50. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts.map +1 -0
  51. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +11 -0
  52. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  53. package/lib/typescript/version.d.ts +1 -1
  54. package/package.json +2 -2
  55. package/src/DdAttributes.ts +8 -1
  56. package/src/index.tsx +5 -1
  57. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +1 -1
  58. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +69 -0
  59. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlUtils.test.ts +143 -0
  60. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +4 -2
  61. package/src/rum/instrumentation/resourceTracking/graphql/graphqlUtils.ts +61 -0
  62. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +10 -0
  63. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +46 -5
  64. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +787 -0
  65. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.ts +175 -0
  66. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +9 -0
  67. package/src/version.ts +1 -1
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { InternalLog } from '../../../../../InternalLog';
8
+ import { SdkVerbosity } from '../../../../../config/types';
9
+
10
+ /**
11
+ * Safely parses a JSON string.
12
+ *
13
+ * @param text - JSON string to parse.
14
+ * @returns Parsed value or `null` if parsing fails.
15
+ */
16
+ export function safeJsonParse<T = any>(
17
+ text: string | null | undefined
18
+ ): T | null {
19
+ if (!text) {
20
+ return null;
21
+ }
22
+
23
+ try {
24
+ return JSON.parse(text) as T;
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Safely reads `responseText` from an XHR object.
32
+ *
33
+ * @param xhr - XHR-like object.
34
+ * @returns Response text or `null` if unavailable.
35
+ */
36
+ export function safeGetResponseText(xhr: any): string | null {
37
+ // RN can throw if responseType is "blob"
38
+ try {
39
+ return typeof xhr?.responseText === 'string' ? xhr.responseText : null;
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Converts a Blob-like object to text.
47
+ *
48
+ * @param blob - Blob or Blob-like value.
49
+ * @returns Text content or `null` if conversion fails.
50
+ */
51
+ export async function blobToText(blob: any): Promise<string | null> {
52
+ if (!blob) {
53
+ return null;
54
+ }
55
+
56
+ // The 'data' field is sometimes available in a blob, use that if available
57
+ const data = blob?._data;
58
+ if (typeof data === 'string') {
59
+ return data;
60
+ }
61
+
62
+ if (typeof blob.text === 'function') {
63
+ try {
64
+ return await blob.text();
65
+ } catch (error) {
66
+ const errorData = getErrorData(error);
67
+ if (errorData) {
68
+ InternalLog.log(
69
+ `Unable to transform blob to text using 'blob.text()': ${errorData}`,
70
+ SdkVerbosity.WARN
71
+ );
72
+ }
73
+ }
74
+ }
75
+
76
+ if (typeof FileReader !== 'undefined') {
77
+ try {
78
+ return await new Promise<string>((resolve, reject) => {
79
+ const reader = new FileReader();
80
+ reader.onload = () => resolve(String(reader.result ?? ''));
81
+ reader.onerror = () => reject(new Error('FileReader error'));
82
+ reader.readAsText(blob);
83
+ });
84
+ } catch (error) {
85
+ const errorData = getErrorData(error);
86
+ if (errorData) {
87
+ InternalLog.log(
88
+ `Unable to transform blob to text using 'FileReader': ${errorData}`,
89
+ SdkVerbosity.WARN
90
+ );
91
+ }
92
+ }
93
+ }
94
+
95
+ return null;
96
+ }
97
+
98
+ /**
99
+ * Reads and parses an XHR response body as JSON.
100
+ *
101
+ * @param xhr - XHR-like object.
102
+ * @returns Parsed JSON or `null` if not readable.
103
+ */
104
+ export async function readXhrJsonBody(xhr: any): Promise<any | null> {
105
+ // If responseType allows it, responseText is the simplest
106
+ if (xhr?.responseType === '' || xhr?.responseType === 'text') {
107
+ const t = safeGetResponseText(xhr);
108
+ const parsed = safeJsonParse(t);
109
+
110
+ if (parsed !== null) {
111
+ return parsed;
112
+ }
113
+ }
114
+
115
+ // Use xhr.response
116
+ const response = xhr?.response;
117
+ if (response == null) {
118
+ return null;
119
+ }
120
+
121
+ // String
122
+ if (typeof response === 'string') {
123
+ return safeJsonParse(response);
124
+ }
125
+
126
+ // Blob-like object (RN blobs have _data, standard Blobs have .text())
127
+ if (typeof response === 'object' && isBlob(response)) {
128
+ const text = await blobToText(response);
129
+ return safeJsonParse(text);
130
+ }
131
+
132
+ // Already parsed JSON (e.g. responseType is 'json')
133
+ if (typeof response === 'object') {
134
+ return response;
135
+ }
136
+
137
+ return null;
138
+ }
139
+
140
+ /**
141
+ * Detects whether a value is a Blob or a React Native Blob-like object.
142
+ */
143
+ function isBlob(value: any): boolean {
144
+ // React Native Blob-like object
145
+ if ('_data' in value) {
146
+ return true;
147
+ }
148
+ // Standard Blob
149
+ if (typeof value.text === 'function') {
150
+ return true;
151
+ }
152
+ // Blob constructor available in environment
153
+ if (typeof Blob !== 'undefined' && value instanceof Blob) {
154
+ return true;
155
+ }
156
+ return false;
157
+ }
158
+
159
+ /**
160
+ * Extracts basic error data for logging.
161
+ *
162
+ * @param error - Unknown error value.
163
+ * @returns Serialized error info or `null`.
164
+ */
165
+ export function getErrorData(error: unknown) {
166
+ if (error instanceof Error) {
167
+ return JSON.stringify({
168
+ name: error.name,
169
+ message: error.message,
170
+ stack: error.stack
171
+ });
172
+ }
173
+
174
+ return null;
175
+ }
@@ -28,8 +28,17 @@ export interface RUMResource {
28
28
  resourceContext?: XMLHttpRequest;
29
29
  }
30
30
 
31
+ export type DdRumResourceGraphqlError = {
32
+ message: string;
33
+ code?: string;
34
+ locations?: Array<{ line: number; column: number }>;
35
+ path?: Array<string | number>;
36
+ };
37
+
31
38
  export type DdRumResourceGraphqlAttributes = {
32
39
  operationType?: string;
33
40
  operationName?: string;
34
41
  variables?: string;
42
+ payload?: string;
43
+ errors?: DdRumResourceGraphqlError[];
35
44
  };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.2.0';
2
+ export const version = '3.3.0';