appwrite/app/controllers/api/projects.php

1076 lines
44 KiB
PHP
Raw Normal View History

2019-12-14 19:33:29 +00:00
<?php
2024-05-29 08:57:25 +00:00
use Ahc\Jwt\JWT;
2024-02-11 14:51:19 +00:00
use Appwrite\Auth\Validator\MockNumber;
use Appwrite\Event\Delete;
2023-08-23 02:04:36 +00:00
use Appwrite\Extend\Exception;
2025-01-17 04:31:39 +00:00
use Appwrite\SDK\AuthType;
use Appwrite\SDK\ContentType;
use Appwrite\SDK\Deprecated;
2025-01-17 04:31:39 +00:00
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
2023-08-23 02:04:36 +00:00
use Appwrite\Template\Template;
use Appwrite\Utopia\Database\Validator\Queries\Keys;
2020-08-14 21:56:50 +00:00
use Appwrite\Utopia\Response;
2021-06-07 05:17:29 +00:00
use Utopia\Config\Config;
2021-08-16 13:27:15 +00:00
use Utopia\Database\Database;
2021-05-15 22:41:42 +00:00
use Utopia\Database\Document;
use Utopia\Database\Validator\UID;
2026-03-19 21:54:45 +00:00
use Utopia\Emails\Validator\Email;
use Utopia\Http\Http;
2024-03-08 12:57:20 +00:00
use Utopia\Locale\Locale;
2024-04-01 11:08:46 +00:00
use Utopia\System\System;
2024-10-08 07:54:40 +00:00
use Utopia\Validator\ArrayList;
use Utopia\Validator\Boolean;
use Utopia\Validator\Nullable;
2024-10-08 07:54:40 +00:00
use Utopia\Validator\Range;
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
2026-02-04 05:30:22 +00:00
Http::init()
2022-07-22 06:00:42 +00:00
->groups(['projects'])
2022-08-02 01:10:48 +00:00
->inject('project')
2022-07-22 06:00:42 +00:00
->action(function (Document $project) {
if ($project->getId() !== 'console') {
throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN);
2022-07-22 06:00:42 +00:00
}
});
2021-07-31 21:36:18 +00:00
2026-02-04 05:30:22 +00:00
Http::get('/v1/projects/:projectId')
2023-08-01 15:26:48 +00:00
->desc('Get project')
2020-06-25 18:32:12 +00:00
->groups(['api', 'projects'])
2019-12-14 19:33:29 +00:00
->label('scope', 'projects.read')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'projects',
2025-01-17 04:31:39 +00:00
name: 'get',
description: '/docs/references/projects/get.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2020-12-26 16:33:36 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2019-12-14 19:33:29 +00:00
2021-05-15 22:41:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
2020-06-30 15:46:42 +00:00
}
2019-12-14 19:33:29 +00:00
2021-07-25 14:47:18 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
2020-12-26 16:33:36 +00:00
});
2019-12-14 19:33:29 +00:00
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/service/all')
->desc('Update all service status')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->action(function () {
2026-04-09 14:08:11 +00:00
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED, 'Bulk API no longer exists for services. Please change status individually.');
2024-03-04 22:12:54 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/api/all')
2024-03-04 22:28:42 +00:00
->desc('Update all API status')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->action(function () {
2026-04-09 14:08:11 +00:00
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED, 'Bulk API no longer exists for services. Please change status individually.');
2024-03-04 22:28:42 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/oauth2')
2023-08-01 15:26:48 +00:00
->desc('Update project OAuth2')
2020-06-25 18:32:12 +00:00
->groups(['api', 'projects'])
2019-12-14 19:33:29 +00:00
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateOAuth2',
description: '/docs/references/projects/update-oauth2.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2023-10-25 17:33:23 +00:00
->param('provider', '', new WhiteList(\array_keys(Config::getParam('oAuthProviders')), true), 'Provider Name')
->param('appId', null, new Nullable(new Text(256)), 'Provider app ID. Max length: 256 chars.', true)
->param('secret', null, new Nullable(new text(512)), 'Provider secret key. Max length: 512 chars.', true)
->param('enabled', null, new Nullable(new Boolean()), 'Provider status. Set to \'false\' to disable new session creation.', true)
2020-12-26 16:33:36 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $provider, ?string $appId, ?string $secret, ?bool $enabled, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2019-12-14 19:33:29 +00:00
2021-05-15 22:41:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
2020-06-30 15:46:42 +00:00
}
2019-12-14 19:33:29 +00:00
2023-10-25 17:33:23 +00:00
$providers = $project->getAttribute('oAuthProviders', []);
2022-08-19 09:43:03 +00:00
if ($appId !== null) {
$providers[$provider . 'Appid'] = $appId;
}
2022-08-19 09:43:03 +00:00
if ($secret !== null) {
$providers[$provider . 'Secret'] = $secret;
}
2022-08-19 09:43:03 +00:00
if ($enabled !== null) {
$providers[$provider . 'Enabled'] = $enabled;
}
2021-08-06 10:35:50 +00:00
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('oAuthProviders', $providers));
2020-06-30 15:46:42 +00:00
2021-07-25 14:47:18 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
2020-12-26 16:33:36 +00:00
});
2019-12-14 19:33:29 +00:00
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/session-alerts')
2024-06-21 18:21:05 +00:00
->desc('Update project sessions emails')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateSessionAlerts',
description: '/docs/references/projects/update-session-alerts.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2024-07-03 07:11:15 +00:00
->param('alerts', false, new Boolean(true), 'Set to true to enable session emails.')
2024-06-21 18:21:05 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, bool $alerts, Response $response, Database $dbForPlatform) {
2024-06-21 18:21:05 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2024-06-21 18:21:05 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2024-07-03 07:11:15 +00:00
$auths['sessionAlerts'] = $alerts;
2024-06-21 18:21:05 +00:00
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-06-21 18:21:05 +00:00
->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/memberships-privacy')
2024-11-07 14:33:44 +00:00
->desc('Update project memberships privacy attributes')
2024-11-01 11:38:56 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateMembershipsPrivacy',
description: '/docs/references/projects/update-memberships-privacy.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2024-11-06 20:15:31 +00:00
->param('userName', true, new Boolean(true), 'Set to true to show userName to members of a team.')
->param('userEmail', true, new Boolean(true), 'Set to true to show email to members of a team.')
->param('mfa', true, new Boolean(true), 'Set to true to show mfa to members of a team.')
2024-11-01 11:38:56 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, bool $userName, bool $userEmail, bool $mfa, Response $response, Database $dbForPlatform) {
$project = $dbForPlatform->getDocument('projects', $projectId);
2024-11-01 11:38:56 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2024-11-05 16:05:21 +00:00
2024-11-06 20:15:31 +00:00
$auths['membershipsUserName'] = $userName;
$auths['membershipsUserEmail'] = $userEmail;
$auths['membershipsMfa'] = $mfa;
2024-11-01 11:38:56 +00:00
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-11-01 11:38:56 +00:00
->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/limit')
2023-08-01 15:26:48 +00:00
->desc('Update project users limit')
2021-02-28 11:40:59 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthLimit',
description: '/docs/references/projects/update-auth-limit.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2022-01-15 23:25:00 +00:00
->param('limit', false, new Range(0, APP_LIMIT_USERS), 'Set the max number of users allowed in this project. Use 0 for unlimited.')
2021-02-28 11:40:59 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2021-02-28 11:40:59 +00:00
2021-05-15 22:41:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
2021-02-28 11:40:59 +00:00
}
2021-08-06 08:34:17 +00:00
$auths = $project->getAttribute('auths', []);
$auths['limit'] = $limit;
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
2021-02-28 11:40:59 +00:00
2021-07-25 14:47:18 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
2022-11-14 09:15:55 +00:00
});
2022-11-14 09:33:49 +00:00
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/duration')
2023-08-01 15:26:48 +00:00
->desc('Update project authentication duration')
2022-11-14 09:15:55 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthDuration',
description: '/docs/references/projects/update-auth-duration.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2022-11-15 10:25:34 +00:00
->param('duration', 31536000, new Range(0, 31536000), 'Project session length in seconds. Max length: 31536000 seconds.')
2022-11-14 09:15:55 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, int $duration, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2022-11-14 09:15:55 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2022-11-15 10:25:34 +00:00
$auths['duration'] = $duration;
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
2022-11-14 09:15:55 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
2021-02-28 11:40:59 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/:method')
2023-08-01 15:26:48 +00:00
->desc('Update project auth method status. Use this endpoint to enable or disable a given auth method for this project.')
2021-02-28 11:40:59 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthStatus',
description: '/docs/references/projects/update-auth-status.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2021-06-07 05:17:29 +00:00
->param('method', '', new WhiteList(\array_keys(Config::getParam('auth')), true), 'Auth Method. Possible values: ' . implode(',', \array_keys(Config::getParam('auth'))), false)
2021-02-28 15:00:27 +00:00
->param('status', false, new Boolean(true), 'Set the status of this auth method.')
2021-02-28 11:40:59 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $method, bool $status, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2024-10-08 07:54:40 +00:00
$auth = Config::getParam('auth')[$method] ?? [];
$authKey = $auth['key'] ?? '';
2021-02-28 15:00:27 +00:00
$status = ($status === '1' || $status === 'true' || $status === 1 || $status === true);
2021-02-28 11:40:59 +00:00
2021-05-15 22:41:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
2021-02-28 11:40:59 +00:00
}
2021-08-06 07:42:31 +00:00
$auths = $project->getAttribute('auths', []);
$auths[$authKey] = $status;
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths));
2021-02-28 11:40:59 +00:00
2021-07-25 14:47:18 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
2021-02-28 11:40:59 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/password-history')
2023-01-30 06:05:32 +00:00
->desc('Update authentication password history. Use this endpoint to set the number of password history to save and 0 to disable password history.')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthPasswordHistory',
description: '/docs/references/projects/update-auth-password-history.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2022-12-19 05:07:41 +00:00
->param('limit', 0, new Range(0, APP_LIMIT_USER_PASSWORD_HISTORY), 'Set the max number of passwords to store in user history. User can\'t choose a new password that is already stored in the password history list. Max number of passwords allowed in history is' . APP_LIMIT_USER_PASSWORD_HISTORY . '. Default value is 0')
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
$auths['passwordHistory'] = $limit;
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/password-dictionary')
2023-04-11 23:01:50 +00:00
->desc('Update authentication password dictionary status. Use this endpoint to enable or disable the dicitonary check for user password')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthPasswordDictionary',
description: '/docs/references/projects/update-auth-password-dictionary.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2023-01-30 06:06:52 +00:00
->param('enabled', false, new Boolean(false), 'Set whether or not to enable checking user\'s password against most commonly used passwords. Default is false.')
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2023-01-30 06:06:52 +00:00
$auths['passwordDictionary'] = $enabled;
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/personal-data')
->desc('Update personal data check')
2023-04-11 23:01:50 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updatePersonalDataCheck',
description: '/docs/references/projects/update-personal-data-check.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('enabled', false, new Boolean(false), 'Set whether or not to check a password for similarity with personal data. Default is false.')
2023-04-11 23:01:50 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-04-11 23:01:50 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2023-07-19 22:24:32 +00:00
$auths['personalDataCheck'] = $enabled;
2023-04-11 23:01:50 +00:00
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
2023-04-11 23:01:50 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/max-sessions')
2023-08-01 15:26:48 +00:00
->desc('Update project user sessions limit')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateAuthSessionsLimit',
description: '/docs/references/projects/update-auth-sessions-limit.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('limit', false, new Range(1, APP_LIMIT_USER_SESSIONS_MAX), 'Set the max number of users allowed in this project. Value allowed is between 1-' . APP_LIMIT_USER_SESSIONS_MAX . '. Default is ' . APP_LIMIT_USER_SESSIONS_DEFAULT)
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2022-12-09 11:33:26 +00:00
$auths['maxSessions'] = $limit;
$dbForPlatform->updateDocument('projects', $project->getId(), $project
2024-10-08 07:54:40 +00:00
->setAttribute('auths', $auths));
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/mock-numbers')
2024-02-11 14:51:19 +00:00
->desc('Update the mock numbers for the project')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'updateMockNumbers',
description: '/docs/references/projects/update-mock-numbers.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2024-02-11 14:51:19 +00:00
->param('numbers', '', new ArrayList(new MockNumber(), 10), 'An array of mock numbers and their corresponding verification codes (OTPs). Each number should be a valid E.164 formatted phone number. Maximum of 10 numbers are allowed.')
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, array $numbers, Response $response, Database $dbForPlatform) {
2024-02-11 14:51:19 +00:00
2024-07-21 19:30:06 +00:00
$uniqueNumbers = [];
foreach ($numbers as $number) {
2024-07-21 19:45:39 +00:00
if (isset($uniqueNumbers[$number['phone']])) {
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Duplicate phone numbers are not allowed.');
2024-07-21 19:30:06 +00:00
}
2024-07-21 19:45:39 +00:00
$uniqueNumbers[$number['phone']] = $number['otp'];
2024-07-21 19:30:06 +00:00
}
2024-07-22 09:08:02 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2024-02-11 14:51:19 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
$auths['mockNumbers'] = $numbers;
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths));
2024-02-11 14:51:19 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
});
2026-02-04 05:30:22 +00:00
Http::delete('/v1/projects/:projectId')
2023-08-01 15:26:48 +00:00
->desc('Delete project')
2020-06-25 18:32:12 +00:00
->groups(['api', 'projects'])
2024-07-22 08:03:53 +00:00
->label('audits.event', 'projects.delete')
->label('audits.resource', 'project/{request.projectId}')
2019-12-14 19:33:29 +00:00
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'projects',
2025-01-17 04:31:39 +00:00
name: 'delete',
description: '/docs/references/projects/delete.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_NOCONTENT,
model: Response::MODEL_NONE,
)
],
contentType: ContentType::NONE
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
2020-12-26 16:33:36 +00:00
->inject('response')
->inject('user')
->inject('dbForPlatform')
2022-12-20 16:11:30 +00:00
->inject('queueForDeletes')
->action(function (string $projectId, Response $response, Document $user, Database $dbForPlatform, Delete $queueForDeletes) {
$project = $dbForPlatform->getDocument('projects', $projectId);
2019-12-14 19:33:29 +00:00
2021-05-15 22:41:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
2020-06-30 15:46:42 +00:00
}
2019-12-14 19:33:29 +00:00
2022-12-20 16:11:30 +00:00
$queueForDeletes
2024-10-01 14:17:36 +00:00
->setProject($project)
2022-04-17 20:34:32 +00:00
->setType(DELETE_TYPE_DOCUMENT)
->setDocument($project);
2021-06-07 05:17:29 +00:00
if (!$dbForPlatform->deleteDocument('projects', $projectId)) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove project from DB');
2019-12-18 10:24:54 +00:00
}
2020-06-30 15:46:42 +00:00
$response->noContent();
2020-12-26 16:33:36 +00:00
});
2019-12-18 10:24:54 +00:00
2024-05-29 08:57:25 +00:00
// JWT Keys
2026-02-04 05:30:22 +00:00
Http::post('/v1/projects/:projectId/jwts')
2024-05-29 08:57:25 +00:00
->groups(['api', 'projects'])
->desc('Create JWT')
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'auth',
2025-01-17 04:31:39 +00:00
name: 'createJWT',
description: '/docs/references/projects/create-jwt.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_CREATED,
model: Response::MODEL_JWT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for JWT key. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.')
2024-05-29 08:57:25 +00:00
->param('duration', 900, new Range(0, 3600), 'Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.', true)
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, array $scopes, int $duration, Response $response, Database $dbForPlatform) {
2024-05-29 08:57:25 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2024-05-29 08:57:25 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic(new Document(['jwt' => API_KEY_DYNAMIC . '_' . $jwt->encode([
'projectId' => $project->getId(),
'scopes' => $scopes
])]), Response::MODEL_JWT);
});
2026-02-04 05:30:22 +00:00
Http::get('/v1/projects/:projectId/templates/sms/:type/:locale')
2023-05-11 06:56:16 +00:00
->desc('Get custom SMS template')
2023-03-09 13:44:31 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->label('sdk', [
new Method(
namespace: 'projects',
group: 'templates',
name: 'getSmsTemplate',
description: '/docs/references/projects/get-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
],
deprecated: new Deprecated(
since: '1.8.0',
2025-08-23 09:36:02 +00:00
replaceWith: 'projects.getSMSTemplate',
),
public: false,
),
new Method(
namespace: 'projects',
group: 'templates',
name: 'getSMSTemplate',
description: '/docs/references/projects/get-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
]
)
])
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['sms'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-03-09 13:44:31 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
2023-08-25 15:13:25 +00:00
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-03-09 13:44:31 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2024-10-08 07:54:40 +00:00
$template = $templates['sms.' . $type . '-' . $locale] ?? null;
2023-03-09 13:44:31 +00:00
2023-05-11 06:56:16 +00:00
if (is_null($template)) {
$template = [
'message' => Template::fromFile(__DIR__ . '/../../config/locale/templates/sms-base.tpl')->render(),
2023-05-11 06:56:16 +00:00
];
}
2023-03-09 13:44:31 +00:00
2023-05-11 06:56:16 +00:00
$template['type'] = $type;
$template['locale'] = $locale;
$response->dynamic(new Document($template), Response::MODEL_SMS_TEMPLATE);
2023-03-09 13:44:31 +00:00
});
2026-02-04 05:30:22 +00:00
Http::get('/v1/projects/:projectId/templates/email/:type/:locale')
2023-05-11 06:56:16 +00:00
->desc('Get custom email template')
2023-03-09 13:44:31 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'templates',
2025-01-17 04:31:39 +00:00
name: 'getEmailTemplate',
description: '/docs/references/projects/get-email-template.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_EMAIL_TEMPLATE,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['email'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-03-09 13:44:31 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-03-09 13:44:31 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2024-10-08 07:54:40 +00:00
$template = $templates['email.' . $type . '-' . $locale] ?? null;
2023-03-09 13:44:31 +00:00
2023-05-11 06:56:16 +00:00
$localeObj = new Locale($locale);
2025-08-12 13:13:08 +00:00
$localeObj->setFallback(System::getEnv('_APP_LOCALE', 'en'));
2023-05-11 06:56:16 +00:00
if (is_null($template)) {
2025-07-20 09:10:30 +00:00
/**
* different templates, different placeholders.
*/
$templateConfigs = [
'magicSession' => [
'file' => 'email-magic-url.tpl',
'placeholders' => ['optionButton', 'buttonText', 'optionUrl', 'clientInfo', 'securityPhrase']
],
'mfaChallenge' => [
'file' => 'email-mfa-challenge.tpl',
'placeholders' => ['description', 'clientInfo']
],
'otpSession' => [
'file' => 'email-otp.tpl',
'placeholders' => ['description', 'clientInfo', 'securityPhrase']
],
'sessionAlert' => [
2025-07-20 11:09:08 +00:00
'file' => 'email-session-alert.tpl',
2025-07-20 09:10:30 +00:00
'placeholders' => ['body', 'listDevice', 'listIpAddress', 'listCountry', 'footer']
],
];
// fallback to the base template.
$config = $templateConfigs[$type] ?? [
'file' => 'email-inner-base.tpl',
'placeholders' => ['buttonText', 'body', 'footer']
];
$templateString = file_get_contents(__DIR__ . '/../../config/locale/templates/' . $config['file']);
// We use `fromString` due to the replace above
$message = Template::fromString($templateString);
// Set type-specific parameters
foreach ($config['placeholders'] as $param) {
$escapeHtml = !in_array($param, ['clientInfo', 'body', 'footer', 'description']);
$message->setParam("{{{$param}}}", $localeObj->getText("emails.{$type}.{$param}"), escapeHtml: $escapeHtml);
}
2023-08-28 08:03:55 +00:00
$message
2025-07-20 09:10:30 +00:00
// common placeholders on all the templates
2023-05-11 06:56:16 +00:00
->setParam('{{hello}}', $localeObj->getText("emails.{$type}.hello"))
->setParam('{{thanks}}', $localeObj->getText("emails.{$type}.thanks"))
2025-07-20 09:10:30 +00:00
->setParam('{{signature}}', $localeObj->getText("emails.{$type}.signature"));
// `useContent: false` will strip new lines!
$message = $message->render(useContent: true);
2023-05-17 08:25:24 +00:00
2023-05-11 06:56:16 +00:00
$template = [
'message' => $message,
'subject' => $localeObj->getText('emails.' . $type . '.subject'),
2023-08-29 09:40:30 +00:00
'senderEmail' => '',
2026-04-20 09:47:06 +00:00
'senderName' => '',
'replyToEmail' => '',
'replyToName' => ''
2023-05-11 06:56:16 +00:00
];
}
2023-03-09 13:44:31 +00:00
2023-05-11 06:56:16 +00:00
$template['type'] = $type;
$template['locale'] = $locale;
$response->dynamic(new Document($template), Response::MODEL_EMAIL_TEMPLATE);
2023-03-10 06:27:42 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/templates/sms/:type/:locale')
2023-05-11 06:56:16 +00:00
->desc('Update custom SMS template')
2023-03-10 06:27:42 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->label('sdk', [
new Method(
namespace: 'projects',
group: 'templates',
name: 'updateSmsTemplate',
description: '/docs/references/projects/update-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
],
deprecated: new Deprecated(
since: '1.8.0',
2025-08-23 09:36:02 +00:00
replaceWith: 'projects.updateSMSTemplate',
),
public: false,
),
new Method(
namespace: 'projects',
group: 'templates',
name: 'updateSMSTemplate',
description: '/docs/references/projects/update-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
]
)
])
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['sms'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-05-11 06:56:16 +00:00
->param('message', '', new Text(0), 'Template message')
2023-03-10 06:27:42 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $type, string $locale, string $message, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
2023-08-25 15:13:25 +00:00
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-03-10 06:27:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2023-05-11 06:56:16 +00:00
$templates['sms.' . $type . '-' . $locale] = [
'message' => $message
];
2023-03-10 06:27:42 +00:00
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
2023-03-10 06:27:42 +00:00
2023-05-11 06:56:16 +00:00
$response->dynamic(new Document([
'message' => $message,
'type' => $type,
'locale' => $locale,
]), Response::MODEL_SMS_TEMPLATE);
2023-03-10 06:27:42 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/templates/email/:type/:locale')
2023-05-11 06:56:16 +00:00
->desc('Update custom email templates')
2023-03-10 06:27:42 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'templates',
2025-01-17 04:31:39 +00:00
name: 'updateEmailTemplate',
description: '/docs/references/projects/update-email-template.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_EMAIL_TEMPLATE,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['email'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-05-11 06:56:16 +00:00
->param('subject', '', new Text(255), 'Email Subject')
->param('message', '', new Text(0), 'Template message')
2023-08-28 14:08:50 +00:00
->param('senderName', '', new Text(255, 0), 'Name of the email sender', true)
->param('senderEmail', '', new Email(), 'Email of the sender', true)
2026-04-20 09:47:06 +00:00
->param('replyToEmail', '', new Email(), 'Reply to email', true)
->param('replyToName', '', new Text(255, 0), 'Reply to name', true)
2023-03-10 06:27:42 +00:00
->inject('response')
->inject('dbForPlatform')
2026-04-20 09:47:06 +00:00
->action(function (string $projectId, string $type, string $locale, string $subject, string $message, string $senderName, string $senderEmail, string $replyToEmail, string $replyToName, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-03-10 06:27:42 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2023-05-11 06:56:16 +00:00
$templates['email.' . $type . '-' . $locale] = [
'senderName' => $senderName,
'senderEmail' => $senderEmail,
'subject' => $subject,
2026-04-20 09:47:06 +00:00
'replyToEmail' => $replyToEmail,
'replyToName' => $replyToName,
2023-05-11 06:56:16 +00:00
'message' => $message
];
2023-03-10 06:27:42 +00:00
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
2023-03-10 06:27:42 +00:00
2023-05-11 06:56:16 +00:00
$response->dynamic(new Document([
'type' => $type,
'locale' => $locale,
'senderName' => $senderName,
'senderEmail' => $senderEmail,
'subject' => $subject,
2026-04-20 09:47:06 +00:00
'replyToEmail' => $replyToEmail,
'replyToName' => $replyToName,
2023-05-11 06:56:16 +00:00
'message' => $message
]), Response::MODEL_EMAIL_TEMPLATE);
2023-03-09 13:44:31 +00:00
});
2023-04-19 08:44:22 +00:00
2026-02-04 05:30:22 +00:00
Http::delete('/v1/projects/:projectId/templates/sms/:type/:locale')
2023-04-19 08:44:22 +00:00
->desc('Reset custom SMS template')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->label('sdk', [
new Method(
namespace: 'projects',
group: 'templates',
name: 'deleteSmsTemplate',
description: '/docs/references/projects/delete-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
],
contentType: ContentType::JSON,
deprecated: new Deprecated(
since: '1.8.0',
2025-08-23 09:36:02 +00:00
replaceWith: 'projects.deleteSMSTemplate',
),
public: false,
),
new Method(
namespace: 'projects',
group: 'templates',
name: 'deleteSMSTemplate',
description: '/docs/references/projects/delete-sms-template.md',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_SMS_TEMPLATE,
)
],
contentType: ContentType::JSON
)
])
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['sms'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-04-19 08:44:22 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
2023-08-25 15:13:25 +00:00
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-04-19 08:44:22 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2024-10-08 07:54:40 +00:00
$template = $templates['sms.' . $type . '-' . $locale] ?? null;
2023-04-19 08:44:22 +00:00
if (is_null($template)) {
2023-05-11 06:52:27 +00:00
throw new Exception(Exception::PROJECT_TEMPLATE_DEFAULT_DELETION);
2023-04-19 08:44:22 +00:00
}
unset($template['sms.' . $type . '-' . $locale]);
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
2023-04-19 08:44:22 +00:00
$response->dynamic(new Document([
'type' => $type,
'locale' => $locale,
'message' => $template['message']
]), Response::MODEL_SMS_TEMPLATE);
});
2026-02-04 05:30:22 +00:00
Http::delete('/v1/projects/:projectId/templates/email/:type/:locale')
->desc('Delete custom email template')
2023-04-19 08:44:22 +00:00
->groups(['api', 'projects'])
->label('scope', 'projects.write')
2025-01-17 04:31:39 +00:00
->label('sdk', new Method(
namespace: 'projects',
2025-03-31 05:48:17 +00:00
group: 'templates',
2025-01-17 04:31:39 +00:00
name: 'deleteEmailTemplate',
description: '/docs/references/projects/delete-email-template.md',
2025-01-17 04:31:39 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_EMAIL_TEMPLATE,
)
],
contentType: ContentType::JSON
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('type', '', new WhiteList(Config::getParam('locale-templates')['email'] ?? [], true), 'Template type')
2024-06-07 00:54:51 +00:00
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Template locale', false, ['localeCodes'])
2023-04-19 08:44:22 +00:00
->inject('response')
->inject('dbForPlatform')
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForPlatform) {
2024-10-08 07:54:40 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
2023-04-19 08:44:22 +00:00
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$templates = $project->getAttribute('templates', []);
2024-10-08 07:54:40 +00:00
$template = $templates['email.' . $type . '-' . $locale] ?? null;
2023-04-19 08:44:22 +00:00
if (is_null($template)) {
2023-05-11 06:52:27 +00:00
throw new Exception(Exception::PROJECT_TEMPLATE_DEFAULT_DELETION);
2023-04-19 08:44:22 +00:00
}
unset($templates['email.' . $type . '-' . $locale]);
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
2023-04-19 08:44:22 +00:00
$response->dynamic(new Document([
'type' => $type,
'locale' => $locale,
'senderName' => $template['senderName'],
'senderEmail' => $template['senderEmail'],
'subject' => $template['subject'],
2026-04-20 09:47:06 +00:00
'replyToEmail' => $template['replyToEmail'] ?? '',
'replyToName' => $template['replyToName'] ?? '',
2023-04-19 08:44:22 +00:00
'message' => $template['message']
]), Response::MODEL_EMAIL_TEMPLATE);
2025-01-17 04:39:16 +00:00
});
2026-02-04 05:30:22 +00:00
Http::patch('/v1/projects/:projectId/auth/session-invalidation')
2025-06-16 18:18:08 +00:00
->desc('Update invalidate session option of the project')
->groups(['api', 'projects'])
->label('scope', 'projects.write')
->label('sdk', new Method(
namespace: 'projects',
group: 'auth',
name: 'updateSessionInvalidation',
description: '/docs/references/projects/update-session-invalidation.md',
2025-06-16 18:18:08 +00:00
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_PROJECT,
)
]
))
2025-10-21 02:04:08 +00:00
->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform'])
->param('enabled', false, new Boolean(), 'Update authentication session invalidation status. Use this endpoint to enable or disable session invalidation on password change')
2025-06-16 18:18:08 +00:00
->inject('response')
->inject('dbForPlatform')
2025-07-22 02:43:32 +00:00
->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) {
2025-06-16 18:18:08 +00:00
$project = $dbForPlatform->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$auths = $project->getAttribute('auths', []);
2025-07-22 02:43:32 +00:00
$auths['invalidateSessions'] = $enabled;
2025-06-16 18:18:08 +00:00
$dbForPlatform->updateDocument('projects', $project->getId(), $project
->setAttribute('auths', $auths));
2025-06-16 18:18:08 +00:00
$response->dynamic($project, Response::MODEL_PROJECT);
});