init
This commit is contained in:
parent
0dec65f979
commit
d7eabe3347
|
@ -282,6 +282,17 @@ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
|||
|
||||
The Runtimes for all supported cloud functions (multicore builds) can be found at the [appwrite/php-runtimes](https://github.com/appwrite/php-runtimes) repository.
|
||||
|
||||
## Generate SDK
|
||||
|
||||
For generating a new console SDK follow the next steps:
|
||||
|
||||
1. Update the console spec file located at `app/config/specs/0.10.x.console.json` from the dynamic version located at `https://localhost/specs/swagger2?platform=console`
|
||||
2. Generate a new SDK using the command `php app/cli.php sdks`
|
||||
3. Change your working dir using `cd app/sdks/console-web`
|
||||
4. Build the new SDK `npm run build`
|
||||
5. Copy `iife/sdk.js` to `appwrite.js`
|
||||
6. Go back to the root of the project `run npm run build`
|
||||
|
||||
## Debug
|
||||
|
||||
Appwrite uses [yasd](https://github.com/swoole/yasd) debugger, which can be made available during build of Appwrite. You can connect to the debugger using VS Code [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension or if you are in PHP Storm you don't need any plugin. Below are the settings required for remote debugger connection.
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -21,9 +21,12 @@ use Utopia\Database\Validator\UID;
|
|||
use Utopia\Database\Exception\Authorization as AuthorizationException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Appwrite\Utopia\Response;
|
||||
use DeviceDetector\DeviceDetector;
|
||||
use Utopia\Audit\Audit;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
|
||||
$attributesCallback = function ($attribute, $response, $dbForExternal, $database, $audits) {
|
||||
/** @var Utopia\Database\Document $document*/
|
||||
|
@ -224,6 +227,100 @@ App::get('/v1/database/collections/:collectionId')
|
|||
$response->dynamic($collection, Response::MODEL_COLLECTION);
|
||||
});
|
||||
|
||||
App::get('/v1/database/collections/:collectionId/logs')
|
||||
->desc('Get Collection Logs')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.method', 'getCollectionLogs')
|
||||
->label('sdk.description', '/docs/references/database/get-collection-logs.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_LOG_LIST)
|
||||
->param('collectionId', '', new UID(), 'Collection unique ID.')
|
||||
->inject('response')
|
||||
->inject('dbForInternal')
|
||||
->inject('dbForExternal')
|
||||
->inject('locale')
|
||||
->inject('geodb')
|
||||
->action(function ($collectionId, $response, $dbForInternal, $dbForExternal, $locale, $geodb) {
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Document $project */
|
||||
/** @var Utopia\Database\Database $dbForInternal */
|
||||
/** @var Utopia\Database\Database $dbForExternal */
|
||||
/** @var Utopia\Locale\Locale $locale */
|
||||
/** @var MaxMind\Db\Reader $geodb */
|
||||
|
||||
$collection = $dbForExternal->getCollection($collectionId);
|
||||
|
||||
if ($collection->isEmpty()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
$audit = new Audit($dbForInternal);
|
||||
|
||||
$logs = $audit->getLogsByResource('database/collection/'.$collection->getId());
|
||||
|
||||
$output = [];
|
||||
|
||||
foreach ($logs as $i => &$log) {
|
||||
$log['userAgent'] = (!empty($log['userAgent'])) ? $log['userAgent'] : 'UNKNOWN';
|
||||
|
||||
$dd = new DeviceDetector($log['userAgent']);
|
||||
|
||||
$dd->skipBotDetection(); // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
|
||||
|
||||
$dd->parse();
|
||||
|
||||
$os = $dd->getOs();
|
||||
$osCode = (isset($os['short_name'])) ? $os['short_name'] : '';
|
||||
$osName = (isset($os['name'])) ? $os['name'] : '';
|
||||
$osVersion = (isset($os['version'])) ? $os['version'] : '';
|
||||
|
||||
$client = $dd->getClient();
|
||||
$clientType = (isset($client['type'])) ? $client['type'] : '';
|
||||
$clientCode = (isset($client['short_name'])) ? $client['short_name'] : '';
|
||||
$clientName = (isset($client['name'])) ? $client['name'] : '';
|
||||
$clientVersion = (isset($client['version'])) ? $client['version'] : '';
|
||||
$clientEngine = (isset($client['engine'])) ? $client['engine'] : '';
|
||||
$clientEngineVersion = (isset($client['engine_version'])) ? $client['engine_version'] : '';
|
||||
|
||||
$output[$i] = new Document([
|
||||
'event' => $log['event'],
|
||||
'ip' => $log['ip'],
|
||||
'time' => $log['time'],
|
||||
|
||||
'osCode' => $osCode,
|
||||
'osName' => $osName,
|
||||
'osVersion' => $osVersion,
|
||||
'clientType' => $clientType,
|
||||
'clientCode' => $clientCode,
|
||||
'clientName' => $clientName,
|
||||
'clientVersion' => $clientVersion,
|
||||
'clientEngine' => $clientEngine,
|
||||
'clientEngineVersion' => $clientEngineVersion,
|
||||
'deviceName' => $dd->getDeviceName(),
|
||||
'deviceBrand' => $dd->getBrandName(),
|
||||
'deviceModel' => $dd->getModel(),
|
||||
]);
|
||||
|
||||
$record = $geodb->get($log['ip']);
|
||||
|
||||
if ($record) {
|
||||
$output[$i]['countryCode'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), false) ? \strtolower($record['country']['iso_code']) : '--';
|
||||
$output[$i]['countryName'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), $locale->getText('locale.country.unknown'));
|
||||
} else {
|
||||
$output[$i]['countryCode'] = '--';
|
||||
$output[$i]['countryName'] = $locale->getText('locale.country.unknown');
|
||||
}
|
||||
}
|
||||
|
||||
$response->dynamic(new Document(['logs' => $output]), Response::MODEL_LOG_LIST);
|
||||
});
|
||||
|
||||
|
||||
|
||||
App::put('/v1/database/collections/:collectionId')
|
||||
->desc('Update Collection')
|
||||
->groups(['api', 'database'])
|
||||
|
|
|
@ -63,7 +63,8 @@ services:
|
|||
- ./psalm.xml:/usr/src/code/psalm.xml
|
||||
- ./tests:/usr/src/code/tests
|
||||
- ./app:/usr/src/code/app
|
||||
# - ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
- ./vendor/utopia-php/audit:/usr/src/code/vendor/utopia-php/audit
|
||||
- ./docs:/usr/src/code/docs
|
||||
- ./public:/usr/src/code/public
|
||||
- ./src:/usr/src/code/src
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.teams.getMembership('[TEAM_ID]', '[MEMBERSHIP_ID]');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.account.create('email@example.com', 'password');
|
||||
let promise = sdk.account.create('', 'email@example.com', 'password');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createBooleanAttribute('[COLLECTION_ID]', '', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createCollection('[NAME]', '', '');
|
||||
let promise = sdk.database.createCollection('', '[NAME]', '', '');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createDocument('[COLLECTION_ID]', {});
|
||||
let promise = sdk.database.createDocument('[COLLECTION_ID]', '', {});
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createEmailAttribute('[COLLECTION_ID]', '', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createFloatAttribute('[COLLECTION_ID]', '', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createIndex('[COLLECTION_ID]', '', 'text', []);
|
||||
let promise = sdk.database.createIndex('[COLLECTION_ID]', '', 'key', []);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createIntegerAttribute('[COLLECTION_ID]', '', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createIpAttribute('[COLLECTION_ID]', '', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createStringAttribute('[COLLECTION_ID]', '', null, false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.createUrlAttribute('[COLLECTION_ID]', '', null, false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.database.getCollectionLogs('[COLLECTION_ID]');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.functions.create('[NAME]', [], 'java-11.0');
|
||||
let promise = sdk.functions.create('', '[NAME]', [], 'java-11.0');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.projects.create('[NAME]', '[TEAM_ID]');
|
||||
let promise = sdk.projects.create('', '[NAME]', '[TEAM_ID]');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.projects.updateServiceStatus('[PROJECT_ID]', 'account');
|
||||
let promise = sdk.projects.updateServiceStatus('[PROJECT_ID]', 'account', false);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.storage.createFile(document.getElementById('uploader').files[0]);
|
||||
let promise = sdk.storage.createFile('', document.getElementById('uploader').files[0]);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.teams.create('[NAME]');
|
||||
let promise = sdk.teams.create('', '[NAME]');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
let sdk = new Appwrite();
|
||||
|
||||
sdk
|
||||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
||||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.teams.getMembership('[TEAM_ID]', '[MEMBERSHIP_ID]');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -5,7 +5,7 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let promise = sdk.users.create('email@example.com', 'password');
|
||||
let promise = sdk.users.create('', 'email@example.com', 'password');
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
|
|
1
docs/references/database/get-collection-logs.md
Normal file
1
docs/references/database/get-collection-logs.md
Normal file
|
@ -0,0 +1 @@
|
|||
Get the collection activity logs list by its unique ID.
|
|
@ -1 +1 @@
|
|||
Get a user activity logs list by its unique ID.
|
||||
Get the user activity logs list by its unique ID.
|
|
@ -1720,6 +1720,26 @@
|
|||
return yield this.call('delete', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}),
|
||||
/**
|
||||
* Get Collection Logs
|
||||
*
|
||||
* Get the collection activity logs list by its unique ID.
|
||||
*
|
||||
* @param {string} collectionId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getCollectionLogs: (collectionId) => __awaiter(this, void 0, void 0, function* () {
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
let path = '/database/collections/{collectionId}/logs'.replace('{collectionId}', collectionId);
|
||||
let payload = {};
|
||||
const uri = new URL(this.config.endpoint + path);
|
||||
return yield this.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
})
|
||||
};
|
||||
this.functions = {
|
||||
|
@ -4174,7 +4194,7 @@
|
|||
/**
|
||||
* Get User Logs
|
||||
*
|
||||
* Get a user activity logs list by its unique ID.
|
||||
* Get the user activity logs list by its unique ID.
|
||||
*
|
||||
* @param {string} userId
|
||||
* @throws {AppwriteException}
|
||||
|
@ -4522,4 +4542,4 @@
|
|||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
}(this.window = this.window || {}, null, window));
|
||||
}(this.window = this.window || {}, null, window));
|
|
@ -16,6 +16,12 @@ class Log extends Model
|
|||
'default' => '',
|
||||
'example' => 'account.sessions.create',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'User ID.',
|
||||
'default' => '',
|
||||
'example' => '610fc2f985ee0',
|
||||
])
|
||||
->addRule('ip', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'IP session in use when the session was created.',
|
||||
|
|
Loading…
Reference in a new issue