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

box / box-typescript-sdk-gen / 15612215981

12 Jun 2025 01:42PM UTC coverage: 42.287% (-0.04%) from 42.325%
15612215981

Pull #636

github

web-flow
Merge 214ee5155 into 0e941a742
Pull Request #636: chore: Update .codegen.json with commit hash of codegen and openapi spec

4253 of 17401 branches covered (24.44%)

Branch coverage included in aggregate %.

15565 of 29465 relevant lines covered (52.83%)

145.43 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 {
228✔
14
  return JSON.parse(text);
2,835✔
15
}
16

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

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

37
export function getSdValueByKey(obj: SerializedData, key: string): string {
228✔
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 {
228✔
45
  return data == null;
×
46
}
47

48
export function sdIsBoolean(data: SerializedData): data is boolean {
228✔
49
  return typeof data == 'boolean';
2,799✔
50
}
51

52
export function sdIsNumber(data: SerializedData): data is number {
228✔
53
  return typeof data == 'number';
6,147✔
54
}
55

56
export function sdIsString(data: SerializedData): data is string {
228✔
57
  return typeof data == 'string';
99,766✔
58
}
59

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

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

68
/**
69
 * Returns a string replacement for sensitive data.
70
 */
71
export function sanitizedValue(): string {
228✔
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(
228✔
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