Skip to content

Commit

Permalink
updated logs and settings services
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Aug 21, 2022
1 parent c7e6e2f commit c9cf870
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const client = new PocketBase(
| 🔐`client.users.delete(id, queryParams = {})` | Deletes an existing user by its id. |
| **[Realtime](https://pocketbase.io/docs/api-realtime)** <br/> _(for node environments you'll have to install an EventSource polyfill beforehand, eg. https://github.com/EventSource/eventsource)_ | |
| 🔓`client.realtime.subscribe(subscription, callback)` | Inits the sse connection (if not already) and register the subscription. |
| 🔓`client.realtime.unsubscribe(subscription = "")` | Unsubscribe from a subscription (if empty - unsubscribe from all registered subscriptions). |
| 🔓`client.realtime.unsubscribe(subscription = "")` | Unsubscribe from a subscription (if empty - unsubscribe from all registered subscriptions). |
| **[Collections](https://pocketbase.io/docs/api-collections)** | |
| 🔐`client.collections.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated collections list. |
| 🔐`client.collections.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all collections batch fetched at once. |
Expand All @@ -352,6 +352,8 @@ const client = new PocketBase(
| **[Settings](https://pocketbase.io/docs/api-records)** | |
| 🔐`client.settings.getAll(queryParams = {})` | Fetch all available app settings. |
| 🔐`client.settings.update(bodyParams = {}, queryParams = {})` | Bulk updates app settings. |
| 🔐`client.settings.testS3(queryParams = {})` | Performs a S3 storage connection test. |
| 🔐`client.settings.testEmail(toEmail, emailTemplate, queryParams = {})` | Sends a test email. |


## Development
Expand Down
16 changes: 15 additions & 1 deletion dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ declare class Settings extends BaseService {
update(bodyParams?: {}, queryParams?: {}): Promise<{
[key: string]: any;
}>;
/**
* Performs a S3 storage connection test.
*/
testS3(queryParams?: {}): Promise<boolean>;
/**
* Sends a test email.
*
* The possible `emailTemplate` values are:
* - verification
* - password-reset
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: {}): Promise<boolean>;
}
declare class ListResult<M extends BaseModel> {
page: number;
Expand Down Expand Up @@ -424,7 +437,8 @@ declare class LogRequest extends BaseModel {
method: string;
status: number;
auth: string;
ip: string;
remoteIp: string;
userIp: string;
referer: string;
userAgent: string;
meta: null | {
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ declare class Settings extends BaseService {
update(bodyParams?: {}, queryParams?: {}): Promise<{
[key: string]: any;
}>;
/**
* Performs a S3 storage connection test.
*/
testS3(queryParams?: {}): Promise<boolean>;
/**
* Sends a test email.
*
* The possible `emailTemplate` values are:
* - verification
* - password-reset
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: {}): Promise<boolean>;
}
declare class ListResult<M extends BaseModel> {
page: number;
Expand Down Expand Up @@ -424,7 +437,8 @@ declare class LogRequest extends BaseModel {
method: string;
status: number;
auth: string;
ip: string;
remoteIp: string;
userIp: string;
referer: string;
userAgent: string;
meta: null | {
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion dist/pocketbase.iife.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ declare class Settings extends BaseService {
update(bodyParams?: {}, queryParams?: {}): Promise<{
[key: string]: any;
}>;
/**
* Performs a S3 storage connection test.
*/
testS3(queryParams?: {}): Promise<boolean>;
/**
* Sends a test email.
*
* The possible `emailTemplate` values are:
* - verification
* - password-reset
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: {}): Promise<boolean>;
}
declare class ListResult<M extends BaseModel> {
page: number;
Expand Down Expand Up @@ -424,7 +437,8 @@ declare class LogRequest extends BaseModel {
method: string;
status: number;
auth: string;
ip: string;
remoteIp: string;
userIp: string;
referer: string;
userAgent: string;
meta: null | {
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion dist/pocketbase.umd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ declare class Settings extends BaseService {
update(bodyParams?: {}, queryParams?: {}): Promise<{
[key: string]: any;
}>;
/**
* Performs a S3 storage connection test.
*/
testS3(queryParams?: {}): Promise<boolean>;
/**
* Sends a test email.
*
* The possible `emailTemplate` values are:
* - verification
* - password-reset
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: {}): Promise<boolean>;
}
declare class ListResult<M extends BaseModel> {
page: number;
Expand Down Expand Up @@ -424,7 +437,8 @@ declare class LogRequest extends BaseModel {
method: string;
status: number;
auth: string;
ip: string;
remoteIp: string;
userIp: string;
referer: string;
userAgent: string;
meta: null | {
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.1",
"version": "0.5.0",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
9 changes: 7 additions & 2 deletions src/models/LogRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class LogRequest extends BaseModel {
method!: string;
status!: number;
auth!: string;
ip!: string;
remoteIp!: string;
userIp!: string;
referer!: string;
userAgent!: string;
meta!: null|{ [key: string]: any };
Expand All @@ -16,11 +17,15 @@ export default class LogRequest extends BaseModel {
load(data: { [key: string]: any }) {
super.load(data);

// fallback to the ip field for backward compatability
data.remoteIp = data.remoteIp || data.ip;

this.url = typeof data.url === 'string' ? data.url : '';
this.method = typeof data.method === 'string' ? data.method : 'GET';
this.status = typeof data.status === 'number' ? data.status : 200;
this.auth = typeof data.auth === 'string' ? data.auth : 'guest';
this.ip = typeof data.ip === 'string' ? data.ip : '';
this.remoteIp = typeof data.remoteIp === 'string' ? data.remoteIp : '';
this.userIp = typeof data.userIp === 'string' ? data.userIp : '';
this.referer = typeof data.referer === 'string' ? data.referer : '';
this.userAgent = typeof data.userAgent === 'string' ? data.userAgent : '';
this.meta = typeof data.meta === 'object' && data.meta !== null ? data.meta : {};
Expand Down
31 changes: 31 additions & 0 deletions src/services/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,35 @@ export default class Settings extends BaseService {
'body': bodyParams,
}).then((responseData) => responseData || {});
}

/**
* Performs a S3 storage connection test.
*/
testS3(queryParams = {}): Promise<boolean> {
return this.client.send('/api/settings/test/s3', {
'method': 'POST',
'params': queryParams,
}).then(() => true);
}

/**
* Sends a test email.
*
* The possible `emailTemplate` values are:
* - verification
* - password-reset
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams = {}): Promise<boolean> {
const bodyParams = {
'email': toEmail,
'template': emailTemplate,
};

return this.client.send('/api/settings/test/email', {
'method': 'POST',
'params': queryParams,
'body': bodyParams,
}).then(() => true);
}
}
31 changes: 31 additions & 0 deletions tests/services/Settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,35 @@ describe('Settings', function () {
assert.deepEqual(result, { 'test': 'abc' });
});
});

describe('testS3()', function () {
it('Should send S3 connection test request', async function () {
fetchMock.on({
method: 'POST',
url: service.client.buildUrl('/api/settings/test/s3')+ '?q1=123',
replyCode: 204,
replyBody: true,
});

const result = await service.testS3({ 'q1': 123 });

assert.isTrue(result);
});
});

describe('testEmail()', function () {
it('Should send a test email request', async function () {
fetchMock.on({
method: 'POST',
url: service.client.buildUrl('/api/settings/test/email')+ '?q1=123',
body: { 'template': "abc", "email": "[email protected]" },
replyCode: 204,
replyBody: true,
});

const result = await service.testEmail("[email protected]", "abc", { "q1": 123 });

assert.isTrue(result);
});
});
});

0 comments on commit c9cf870

Please sign in to comment.