-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathrequest.d.ts
141 lines (122 loc) · 4.39 KB
/
request.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import type { RequestLanguage } from './company';
export const REQUEST_TYPES = ['access', 'erasure', 'rectification', 'objection', 'custom'] as const;
export const TRANSPORT_MEDIA = ['email', 'letter', 'fax'] as const;
export type RequestType = typeof REQUEST_TYPES[number];
export type TransportMedium = typeof TRANSPORT_MEDIA[number];
export interface GeneralIdData {
/** A description of this element, e.g. 'Name'. */
desc: string;
/** The element's type, where:
* - `input` is a single-line string
* - `textarea` is a multi-line string
* - `address` is an object representing an address like this:
* `{street_1: '5 Main St.', street_2: 'Suburbia', place: 'My City 12345', country: 'A Country', primary: true}`
* - `name` is an alias for `string` but is used to insert the user's name in the letter
* - `birthdate` is the user's date of birth as a string, e.g. '1970-01-01'
*/
type: string;
/** Whether we recommend giving this piece of information (`false`) or not (`true`). */
optional?: boolean;
/** The value entered by the user for this element. */
value: string | Address;
}
export interface TextIdData extends GeneralIdData {
type: 'input' | 'textarea' | 'name' | 'birthdate' | 'email';
value: string;
}
export interface AddressIdData extends GeneralIdData {
type: 'address';
value: Address;
}
export const EMTPY_ADDRESS: Address = {
street_1: '',
street_2: '',
place: '',
country: '',
} as const;
export type IdDataElement = TextIdData | AddressIdData;
export type ResponseType = 'admonition' | 'complaint';
export type TextSignature = {
type: 'text';
name: string;
};
export type ImageSignature = {
type: 'image';
name?: string;
/** base64-encoded-image */
value: string;
};
export type Signature = TextSignature | ImageSignature;
export const ADDRESS_STRING_PROPERTIES = ['street_1', 'street_2', 'place', 'country'] as const;
export type Address = {
street_1: string;
street_2: string;
place: string;
country: string;
primary?: boolean;
};
interface RequestInterface {
type: RequestType;
transport_medium: TransportMedium;
reference: string;
date: string;
sent?: boolean;
/** The new-line delimited address of the request recipient. */
recipient_address: string;
email: string;
signature: Signature;
/** The user-defined part of the information block. */
information_block: string;
language: RequestLanguage;
id_data: IdDataElement[];
/** The slug of the company this request is addressed to (if applicable). */
slug: string;
/** A list of other entities and services the selected company is the controller for. */
recipient_runs: string[];
/** Whether the user needs to enter ID data for the request. */
is_tracking_request: boolean;
[field_name: DataFieldName]: IdDataElement[];
}
export interface AccessRequest extends RequestInterface {
type: 'access';
/** The 'Get data in a machine-readable format' flag. */
data_portability: boolean;
}
export interface ErasureRequest extends RequestInterface {
type: 'erasure';
/** The 'Erase all data' flag. */
erase_all: boolean;
/** The data the user has specified to be erased (if `this.erase_all` is `false`). */
erasure_data: string;
}
export type CustomLetterData = {
content: string;
subject: string;
sender_address: Address;
name: string;
};
export interface CustomRequest extends RequestInterface {
type: 'custom';
custom_data: CustomLetterData;
response_type?: ResponseType;
}
export const CUSTOM_TEMPLATE_OPTIONS = ['no-template', 'admonition', 'complaint'] as const;
type CustomTemplateName = typeof CUSTOM_TEMPLATE_OPTIONS[number];
export interface ObjectionRequest extends RequestInterface {
type: 'objection';
}
export interface RectificationRequest extends RequestInterface {
type: 'rectification';
rectification_data: IdDataElement[];
}
export type Request = AccessRequest | ErasureRequest | CustomRequest | ObjectionRequest | RectificationRequest;
export type DataFieldName<R extends Request> =
| 'id_data'
| (R extends RectificationRequest ? 'rectification_data' : never);
export type RequestFlag =
| {
name: 'data_portability';
value: boolean;
}
| { name: 'erase_all'; value: boolean }
| { name: 'erasure_data'; value: string };