forked from orestbida/cookieconsent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
159 lines (135 loc) · 4.76 KB
/
types.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
export {}
declare global {
type MODE = 'opt-in' | 'opt-out'
type AUTO_LANGUAGE_ORIGIN = 'browser' | 'document'
type ModalLayout = 'box' | 'cloud' | 'bar'
type ModalPosition = 'bottom left' | 'bottom right' | 'bottom center' | 'middle left' | 'middle right' | 'middle center' | 'top left' | 'top right' | 'top center'
type GUITransition = 'zoom' | 'slide'
type SettingLayout = 'box' | 'bar'
type SettingPosition = 'left' | 'right'
interface SavedCookieContent {
categories: string[]
level: string[]
revision: number
data?: null | Record<string, Record<string, any> | string>
rfc_cookie: boolean
consent_date: string
consent_uuid: string
last_consent_update: string
}
interface GUIOptions {
consent_modal?: {
layout?: ModalLayout
position?: ModalPosition
transition?: GUITransition
swap_buttons?: boolean
},
settings_modal?: {
layout?: SettingLayout
position?: SettingPosition
transition?: GUITransition
}
}
interface UserPreferences {
accept_type: string
accepted_categories: string[]
rejected_categories: string[]
}
type PrimaryButtonRole = 'accept_selected' | 'accept_all'
type SecondaryButtonRole = 'settings' | 'accept_necessary'
interface ButtonSetting<Role> {
text: string
role: Role
}
interface ConsentModalLanguageSetting {
title?: string
description?: string
primary_btn?: ButtonSetting<PrimaryButtonRole>
secondary_btn?: ButtonSetting<SecondaryButtonRole>
revision_message?: string
}
interface ToggleSetting {
value: string
enabled?: boolean
readonly?: boolean
reload?: 'on_disable' | 'on_clear'
}
interface CookieTableItem {
domain?: string
path?: string
is_regex?: boolean
[key: string]: string | boolean | undefined
}
interface BlockSetting {
title: string
description: string
toggle?: ToggleSetting
cookie_table?: CookieTableItem[]
}
interface SettingsModalLanguageSetting {
title?: string
save_settings_btn?: string
accept_all_btn?: string
reject_all_btn?: string
close_btn_label?: string
cookie_table_caption?: string
cookie_table_headers?: Record<string, string>[]
blocks?: BlockSetting[]
}
interface LanguageSetting {
consent_modal?: ConsentModalLanguageSetting
settings_modal?: SettingsModalLanguageSetting
}
interface UserConfig {
autorun?: boolean
delay?: number
mode?: MODE
cookie_expiration?: number
cookie_necessary_only_expiration?: number
cookie_path?: string
cookie_domain?: string
cookie_same_site?: string
cookie_name?: string
use_rfc_cookie?: boolean
force_consent?: boolean
revision?: number
current_lang?: string
auto_language?: AUTO_LANGUAGE_ORIGIN
autoclear_cookies?: boolean
page_scripts?: boolean
remove_cookie_tables?: boolean
hide_from_bots?: boolean
gui_options?: GUIOptions
onAccept?: (savedCookieContent: SavedCookieContent) => void
onChange?: (cookie: SavedCookieContent, changedCookieCategories: string[]) => void
onFirstAction? :(userPreferences: UserPreferences, cookie: SavedCookieContent) => void
languages?: Record<string, LanguageSetting>
}
interface ScriptAttribute {
name: string
value: any
}
interface CookieConsent {
run(config: UserConfig): void
showSettings(delay: number): void
accept(_categories: string | string[], _exclusions?: string[]): void
hideSettings(): void
hide(): void
updateLanguage(lang: string, force: boolean): boolean
getUserPreferences(): UserPreferences
loadScript(src: string, callback: () => void | typeof onload, attrs?: ScriptAttribute[]): void
updateScripts(): void
show(delay?: number, create_modal?: boolean): void
eraseCookies(_cookies: string | string[], _path?: string, _domain?: string): void
validCookie(cookie_name: string): boolean
validConsent(): boolean
allowedCategory(cookie_category: string): boolean
set(field: string, data: Record<string, any>): boolean
get(field: string, cookie_name?: string): Record<string, any>
getConfig<Field extends keyof UserConfig>(field: Field): UserConfig[Field]
}
function initCookieConsent(root?: HTMLElement): CookieConsent
interface Window {
initCookieConsent: typeof initCookieConsent
}
}