• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-typescript-sdk-gen / 16225156987

11 Jul 2025 04:43PM UTC coverage: 42.399% (+0.3%) from 42.112%
16225156987

Pull #662

github

web-flow
Merge aa9b8a802 into 54c0f45aa
Pull Request #662: feat: Support common fields in Union in Java (box/box-codegen#758)

4430 of 18050 branches covered (24.54%)

Branch coverage included in aggregate %.

16152 of 30494 relevant lines covered (52.97%)

145.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/serialization/json.ts
1
export type SerializedData =
2
  | undefined
3
  | null
4
  | boolean
5
  | number
6
  | string
7
  | SerializedDataList
8
  | SerializedDataMap;
9

10
type SerializedDataList = readonly SerializedData[];
11
type SerializedDataMap = { readonly [key: string]: SerializedData | undefined };
12

13
export function jsonToSerializedData(text: string): SerializedData {
234✔
14
  return JSON.parse(text);
2,889✔
15
}
16

17
export function sdToJson(data: SerializedData): string {
234✔
18
  return JSON.stringify(data);
2,619✔
19
}
20

21
export function sdToUrlParams(data: SerializedData): string {
234✔
22
  if (!sdIsMap(data) && !sdIsString(data)) {
489!
23
    throw new Error(
×
24
      'Expecting an object or string as an argument for sdToUrlParams',
25
    );
26
  }
27
  const dataAsMap: SerializedDataMap = sdIsString(data)
489✔
28
    ? JSON.parse(data)
29
    : data;
30
  return new URLSearchParams(
489✔
31
    Object.fromEntries(
32
      Object.entries(dataAsMap).filter(([key, value]) => value != null),
7,152✔
33
    ) as Record<string, string>,
34
  ).toString();
35
}
36

37
export function getSdValueByKey(obj: SerializedData, key: string): string {
234✔
38
  if (sdIsMap(obj)) {
30✔
39
    return obj[key]!.toString();
30✔
40
  }
41
  return '';
×
42
}
43

44
export function sdIsEmpty(data: SerializedData): data is undefined | null {
234✔
45
  return data == null;
×
46
}
47

48
export function sdIsBoolean(data: SerializedData): data is boolean {
234✔
49
  return typeof data == 'boolean';
4,059✔
50
}
51

52
export function sdIsNumber(data: SerializedData): data is number {
234✔
53
  return typeof data == 'number';
5,817✔
54
}
55

56
export function sdIsString(data: SerializedData): data is string {
234✔
57
  return typeof data == 'string';
96,428✔
58
}
59

60
export function sdIsList(data: SerializedData): data is SerializedDataList {
234✔
61
  return Array.isArray(data);
6,951✔
62
}
63

64
export function sdIsMap(data: SerializedData): data is SerializedDataMap {
234✔
65
  return typeof data === 'object' && data != null && !Array.isArray(data);
43,049✔
66
}
67

68
/**
69
 * Returns a string replacement for sensitive data.
70
 */
71
export function sanitizedValue(): string {
234✔
72
  return '---[redacted]---';
×
73
}
74

75
/**
76
 * Sanitize serialized data by replacing sensitive values with a placeholder.
77
 * @param sd SerializedData to sanitize
78
 * @param keysToSanitize Keys to sanitize
79
 */
80
export function sanitizeSerializedData(
234✔
81
  sd: SerializedData,
82
  keysToSanitize: Record<string, string>,
83
): SerializedData {
84
  if (!sdIsMap(sd)) {
×
85
    return sd;
×
86
  }
87
  const sanitizedDictionary: { [key: string]: SerializedData | undefined } = {};
×
88
  for (const [key, value] of Object.entries(sd)) {
×
89
    if (key.toLowerCase() in keysToSanitize && typeof value === 'string') {
×
90
      sanitizedDictionary[key] = sanitizedValue();
×
91
    } else if (typeof value === 'object') {
×
92
      sanitizedDictionary[key] = sanitizeSerializedData(value, keysToSanitize);
×
93
    } else {
94
      sanitizedDictionary[key] = value;
×
95
    }
96
  }
97
  return sanitizedDictionary;
×
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc