-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathOrganizations.php
More file actions
269 lines (232 loc) · 8.58 KB
/
Organizations.php
File metadata and controls
269 lines (232 loc) · 8.58 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
namespace WorkOS;
/**
* Class Organizations.
*
* This class facilitates the use of operations on WorkOS Organizations.
*/
class Organizations
{
public const DEFAULT_PAGE_SIZE = 10;
/**
* List Organizations.
*
* @param null|array $domain Filter organizations to only return those that are associated with
* the provided domain.
* @param int $limit Maximum number of records to return
* @param null|string $before Organization ID to look before
* @param null|string $after Organization ID to look after
* @param Resource\Order $order The Order in which to paginate records
*
* @return array{?string, ?string, Resource\Organization[]} An array containing the Organization ID to use as before and after cursor, and an array of Organization instances
*
* @throws Exception\WorkOSException
*/
public function listOrganizations(
$domains = null,
$limit = self::DEFAULT_PAGE_SIZE,
$before = null,
$after = null,
$order = null
) {
$organizationsPath = "organizations";
$params = [
"limit" => $limit,
"before" => $before,
"after" => $after,
"domains" => $domains,
"order" => $order
];
$response = Client::request(
Client::METHOD_GET,
$organizationsPath,
null,
$params,
true
);
$organizations = [];
list($before, $after) = Util\Request::parsePaginationArgs($response);
foreach ($response["data"] as $responseData) {
\array_push($organizations, Resource\Organization::constructFromResponse($responseData));
}
return [$before, $after, $organizations];
}
/**
* Create Organization.
*
* @param string $name The name of the Organization.
* @param null|array $domains @deprecated 4.5.0 The domains of the Organization. Use domain_data instead.
* @param null|array $domain_data The domains of the Organization.
* @param null|boolean $allowProfilesOutsideOrganization @deprecated 4.5.0 If you need to allow sign-ins from
* any email domain, contact support@workos.com.
* @param null|string $idempotencyKey is a unique string that identifies a distinct organization
* @param null|string $externalId The organization's external id
* @param null|array<string, string> $metadata The organization's metadata
*
* @throws Exception\WorkOSException
*
* @return Resource\Organization
*/
public function createOrganization(
$name,
$domains = null,
$allowProfilesOutsideOrganization = null,
$idempotencyKey = null,
$domain_data = null,
$externalId = null,
$metadata = null
) {
$idempotencyKey ? $headers = array("Idempotency-Key: $idempotencyKey") : $headers = null;
$organizationsPath = "organizations";
$params = ["name" => $name];
if (isset($domains)) {
$msg = "'domains' is deprecated. Please use 'domain_data' instead.";
trigger_error($msg, E_USER_DEPRECATED);
$params["domains"] = $domains;
}
if (isset($domain_data)) {
$params["domain_data"] = $domain_data;
}
if (isset($allowProfilesOutsideOrganization)) {
$msg = "'allowProfilesOutsideOrganization' is deprecated. If you need to allow sign-ins from any email domain, contact support@workos.com.";
trigger_error($msg, E_USER_DEPRECATED);
$params["allow_profiles_outside_organization"] = $allowProfilesOutsideOrganization;
}
if (isset($externalId)) {
$params["external_id"] = $externalId;
}
if (isset($metadata)) {
$params["metadata"] = $metadata;
}
$response = Client::request(Client::METHOD_POST, $organizationsPath, $headers, $params, true);
return Resource\Organization::constructFromResponse($response);
}
/**
* Update Organization.
*
* @param string $organization An Organization identifier.
* @param null|array $domains @deprecated 4.5.0 The domains of the Organization. Use domain_data instead.
* @param null|array $domain_data The domains of the Organization.
* @param null|string $name The name of the Organization.
* @param null|boolean $allowProfilesOutsideOrganization @deprecated 4.5.0 If you need to allow sign-ins from
* any email domain, contact support@workos.com.
* @param null|string $stripeCustomerId The Stripe Customer ID of the Organization.
* @param null|string $externalId The organization's external id
* @param null|array<string, string> $metadata The organization's metadata
*
* @throws Exception\WorkOSException
*/
public function updateOrganization(
$organization,
$domains = null,
$name = null,
$allowProfilesOutsideOrganization = null,
$domain_data = null,
$stripeCustomerId = null,
$externalId = null,
$metadata = null
) {
$organizationsPath = "organizations/{$organization}";
$params = ["name" => $name];
if (isset($domains)) {
$msg = "'domains' is deprecated. Please use 'domain_data' instead.";
trigger_error($msg, E_USER_DEPRECATED);
$params["domains"] = $domains;
}
if (isset($domain_data)) {
$params["domain_data"] = $domain_data;
}
if (isset($allowProfilesOutsideOrganization)) {
$msg = "'allowProfilesOutsideOrganization' is deprecated. If you need to allow sign-ins from any email domain, contact support@workos.com.";
trigger_error($msg, E_USER_DEPRECATED);
$params["allow_profiles_outside_organization"] = $allowProfilesOutsideOrganization;
}
if (isset($stripeCustomerId)) {
$params["stripe_customer_id"] = $stripeCustomerId;
}
if (isset($externalId)) {
$params["external_id"] = $externalId;
}
if (isset($metadata)) {
$params["metadata"] = $metadata;
}
$response = Client::request(Client::METHOD_PUT, $organizationsPath, null, $params, true);
return Resource\Organization::constructFromResponse($response);
}
/**
* Get an Organization
*
* @param string $organization WorkOS organization ID
*
* @throws Exception\WorkOSException
*
* @return Resource\Organization
*/
public function getOrganization($organization)
{
$organizationsPath = "organizations/{$organization}";
$response = Client::request(Client::METHOD_GET, $organizationsPath, null, null, true);
return Resource\Organization::constructFromResponse($response);
}
/**
* Get an Organization by its external id
*
* @param string $externalId external id
*
* @throws Exception\WorkOSException
*
* @return Resource\Organization
*/
public function getOrganizationByExternalId($externalId)
{
$organizationsPath = "organizations/external_id/{$externalId}";
$response = Client::request(Client::METHOD_GET, $organizationsPath, null, null, true);
return Resource\Organization::constructFromResponse($response);
}
/**
* Delete an Organization.
*
* @param string $organization WorkOS organization ID
*
* @throws Exception\WorkOSException
*
* @return Resource\Response
*/
public function deleteOrganization($organization)
{
$organizationsPath = "organizations/{$organization}";
$response = Client::request(
Client::METHOD_DELETE,
$organizationsPath,
null,
null,
true
);
return $response;
}
/**
* List roles for an organization.
*
* @param string $organizationId WorkOS organization ID to fetch roles for
*
* @throws Exception\WorkOSException
*
* @return array{0: Resource\Role[]} An array containing the list of Role instances
*/
public function listOrganizationRoles($organizationId)
{
$organizationRolesPath = "organizations/{$organizationId}/roles";
$response = Client::request(
Client::METHOD_GET,
$organizationRolesPath,
null,
null,
true
);
$roles = [];
foreach ($response["data"] as $responseData) {
\array_push($roles, Resource\Role::constructFromResponse($responseData));
}
return [$roles];
}
}