/
users_private.clj
167 lines (125 loc) · 6.89 KB
/
users_private.clj
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
160
161
162
163
164
165
166
167
(ns chromex.app.users-private
"Use the chrome.usersPrivate API to manage users.
* available since Chrome master"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro get-whitelisted-users
"Gets a list of the currently whitelisted users.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [users] where:
|users| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-whitelisted-users &form)))
(defmacro is-whitelisted-user
"Checks to see if the user is already present as a whitelisted user.
|email| - ?
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [found] where:
|found| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([email] (gen-call :function ::is-whitelisted-user &form email)))
(defmacro add-whitelisted-user
"Adds a new user with the given email to the whitelist. The callback is called with true if the user was added succesfully,
or with false if not (e.g. because the user was already present, or the current user isn't the owner).
|email| - ?
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [success] where:
|success| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([email] (gen-call :function ::add-whitelisted-user &form email)))
(defmacro remove-whitelisted-user
"Removes the user with the given email from the whitelist. The callback is called with true if the user was removed
succesfully, or with false if not (e.g. because the user was not already present, or the current user isn't the owner).
|email| - ?
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [success] where:
|success| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([email] (gen-call :function ::remove-whitelisted-user &form email)))
(defmacro is-whitelist-managed
"Whether the whitelist is managed by enterprise.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [managed] where:
|managed| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::is-whitelist-managed &form)))
(defmacro get-current-user
"Returns the current user.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [user] where:
|user| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-current-user &form)))
(defmacro get-login-status
"Get login status.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [status] where:
|status| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([] (gen-call :function ::get-login-status &form)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.users-private namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.usersPrivate",
:since "master",
:functions
[{:id ::get-whitelisted-users,
:name "getWhitelistedUsers",
:callback? true,
:params
[{:name "callback",
:type :callback,
:callback {:params [{:name "users", :type "[array-of-usersPrivate.Users]"}]}}]}
{:id ::is-whitelisted-user,
:name "isWhitelistedUser",
:callback? true,
:params
[{:name "email", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "found", :type "boolean"}]}}]}
{:id ::add-whitelisted-user,
:name "addWhitelistedUser",
:callback? true,
:params
[{:name "email", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "success", :type "boolean"}]}}]}
{:id ::remove-whitelisted-user,
:name "removeWhitelistedUser",
:callback? true,
:params
[{:name "email", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "success", :type "boolean"}]}}]}
{:id ::is-whitelist-managed,
:name "isWhitelistManaged",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "managed", :type "boolean"}]}}]}
{:id ::get-current-user,
:name "getCurrentUser",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "user", :type "usersPrivate.User"}]}}]}
{:id ::get-login-status,
:name "getLoginStatus",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "status", :type "object"}]}}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))