Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .oagen-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@
"lib/Resource/DirectoryMetadata.php",
"lib/Resource/DirectoryMetadataUser.php",
"lib/Resource/DirectoryState.php",
"lib/Resource/DirectorySyncRateLimitError.php",
"lib/Resource/DirectorySyncResponse.php",
"lib/Resource/DirectoryType.php",
"lib/Resource/DirectoryUser.php",
"lib/Resource/DirectoryUserEmail.php",
Expand Down Expand Up @@ -1009,6 +1011,8 @@
"tests/Fixtures/directory_group.json",
"tests/Fixtures/directory_metadata.json",
"tests/Fixtures/directory_metadata_user.json",
"tests/Fixtures/directory_sync_rate_limit_error.json",
"tests/Fixtures/directory_sync_response.json",
"tests/Fixtures/directory_user.json",
"tests/Fixtures/directory_user_email.json",
"tests/Fixtures/directory_user_with_groups.json",
Expand Down Expand Up @@ -2447,6 +2451,10 @@
"GET /audit_logs/exports/{auditLogExportId}": {
"sdkMethod": "getExport",
"service": "auditLogs"
},
"POST /directories/{id}/sync": {
"sdkMethod": "syncDirectory",
"service": "directorySync"
}
}
}
40 changes: 40 additions & 0 deletions lib/Resource/DirectorySyncRateLimitError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

// This file is auto-generated by oagen. Do not edit.

namespace WorkOS\Resource;

readonly class DirectorySyncRateLimitError implements \JsonSerializable
{
use JsonSerializableTrait;

public function __construct(
/** The error code identifying the type of error. */
public string $code,
/** A human-readable description of the error. */
public string $message,
/** The number of seconds to wait before requesting another manual sync of this directory. */
public int $retryAfterSeconds,
) {
}

public static function fromArray(array $data): self
{
return new self(
code: $data['code'] ?? 'directory_sync_rate_limited',
message: $data['message'],
retryAfterSeconds: $data['retry_after_seconds'],
);
}

public function toArray(): array
{
return [
'code' => $this->code,
'message' => $this->message,
'retry_after_seconds' => $this->retryAfterSeconds,
];
}
}
32 changes: 32 additions & 0 deletions lib/Resource/DirectorySyncResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

// This file is auto-generated by oagen. Do not edit.

namespace WorkOS\Resource;

readonly class DirectorySyncResponse implements \JsonSerializable
{
use JsonSerializableTrait;

public function __construct(
/** The sync request was queued for asynchronous processing. This does not indicate that the sync has started or completed. */
public string $status,
) {
}

public static function fromArray(array $data): self
{
return new self(
status: $data['status'] ?? 'queued',
);
}

public function toArray(): array
{
return [
'status' => $this->status,
];
}
}
21 changes: 21 additions & 0 deletions lib/Service/DirectorySync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use WorkOS\Resource\Directory;
use WorkOS\Resource\DirectoryGroup;
use WorkOS\Resource\DirectorySyncResponse;
use WorkOS\Resource\DirectoryUserWithGroups;

class DirectorySync
Expand Down Expand Up @@ -98,6 +99,26 @@ public function deleteDirectory(
);
}

/**
* Sync a Directory
*
* Request an asynchronous sync from the directory provider. Currently supports Google Workspace directories in linked or validating state. Manual requests share a five-minute per-directory cooldown across the API, Dashboard, Admin Portal, and MCP. Acceptance means the request was queued, not that the sync has started or completed. A running sync prevents another request from being queued.
* @param string $id Unique identifier for the Directory.
* @return \WorkOS\Resource\DirectorySyncResponse
* @throws \WorkOS\Exception\WorkOSException
*/
public function syncDirectory(
string $id,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\DirectorySyncResponse {
$response = $this->client->request(
method: 'POST',
path: 'directories/' . rawurlencode($id) . '/sync',
options: $options,
);
return DirectorySyncResponse::fromArray($response);
}

/**
* List Directory Groups
*
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/directory_sync_rate_limit_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"code": "directory_sync_rate_limited",
"message": "Request could not be processed.",
"retry_after_seconds": 120
}
3 changes: 3 additions & 0 deletions tests/Fixtures/directory_sync_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "queued"
}
12 changes: 12 additions & 0 deletions tests/Service/DirectorySyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public function testDeleteDirectory(): void
$this->assertStringEndsWith('directories/test_id', $request->getUri()->getPath());
}

public function testSyncDirectory(): void
{
$fixture = $this->loadFixture('directory_sync_response');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->directorySync()->syncDirectory('test_id');
$this->assertInstanceOf(\WorkOS\Resource\DirectorySyncResponse::class, $result);
$this->assertIsArray($result->toArray());
$request = $this->getLastRequest();
$this->assertSame('POST', $request->getMethod());
$this->assertStringEndsWith('directories/test_id/sync', $request->getUri()->getPath());
}

public function testListGroups(): void
{
$fixture = $this->loadFixture('list_directory_group');
Expand Down
Loading