Skip to content

Commit

Permalink
Merge pull request #5 from govau/feat-filter-by-template
Browse files Browse the repository at this point in the history
Allow filtering of notifications by template
  • Loading branch information
jonalport authored May 15, 2020
2 parents ed8c918 + 8334d69 commit 7f2d1f0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [5.2.0] - 2020-04-14

### Changed

- Update API key initialisation parameter to be "apiKey" (not "apiKeyId") as per docs
- Add support for filtering of notifications by template ID

## [5.1.0] - 2020-04-07

### Changed
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ Click here to expand for more information.
notifyClient
.getNotifications({
templateType: "email",
templateId: "xxxxx",
status: "delivered",
reference: "client-ref-no",
olderThanId: "xxxxx"
Expand Down Expand Up @@ -539,11 +540,15 @@ Click here to expand for more information.

##### `templateType`

If omitted all messages are returned. Otherwise you can filter by:
If omitted, all messages are returned. Otherwise you can filter by:

- `email`
- `sms`

##### `templateId`

If omitted, all messages are returned. Otherwise you can filter by a template ID string.

##### `status`

**email**
Expand Down Expand Up @@ -578,7 +583,7 @@ This is the `reference` you gave at the time of sending the notification. This c

##### `olderThanId`

If omitted all messages are returned. Otherwise you can filter to retrieve all notifications older than the given notification `id`.
If omitted, all messages are returned. Otherwise you can filter to retrieve all notifications older than the given notification `id`.

</details>

Expand Down Expand Up @@ -779,7 +784,7 @@ Click here to expand for more information.

##### `templateType`

If omitted all messages are returned. Otherwise you can filter by:
If omitted, all messages are returned. Otherwise you can filter by:

- `email`
- `sms`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@govau-platforms/notify-client",
"author": "Digital Transformation Agency",
"version": "5.1.0",
"version": "5.2.0",
"homepage": "https://github.com/govau/notify-client-node",
"description": "Notify.gov.au Node.js client ",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions spec/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ MockDate.set(1234567890000);
const baseUrl = "http://localhost";
const serviceId = "c745a8d8-b48a-4b0d-96e5-dbea0165ebd1";
const secret = "8b3aa916-ec82-434e-b0c5-d5d9b371d6a3";
const apiKeyId = `testkey-${serviceId}-${secret}`;
const apiKey = `testkey-${serviceId}-${secret}`;

function getNotifyClient() {
let baseUrl = "http://localhost";
let notifyClient = new NotifyClient({ baseUrl, apiKeyId });
let notifyClient = new NotifyClient({ baseUrl, apiKey });
return notifyClient;
}

Expand Down
8 changes: 4 additions & 4 deletions spec/integration/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ describer("notification api with a live service", function() {

beforeEach(() => {
const baseUrl = process.env.NOTIFY_API_URL;
const apiKeyId = process.env.API_KEY;
const apiKey = process.env.API_KEY;
const inboundSmsKeyId = process.env.INBOUND_SMS_QUERY_KEY;
const whitelistApiKeyId = process.env.API_SENDING_KEY;
notifyClient = new NotifyClient({ baseUrl, apiKeyId });
notifyClient = new NotifyClient({ baseUrl, apiKey });
whitelistNotifyClient = new NotifyClient({
baseUrl,
apiKeyId: whitelistApiKeyId
apiKey: whitelistApiKeyId
});
receivedTextClient = new NotifyClient({
baseUrl,
apiKeyId: inboundSmsKeyId
apiKey: inboundSmsKeyId
});
var definitions_json = require("./schemas/v2/definitions.json");
chai.tv4.addSchema("definitions.json", definitions_json);
Expand Down
18 changes: 15 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { RequestPromise } from "request-promise";
export default class Client {
httpClient: HttpClient;

constructor(params: { apiKeyId: string; baseUrl?: string }) {
this.httpClient = new HttpClient(params);
constructor(params: { apiKey: string; baseUrl?: string }) {
this.httpClient = new HttpClient({
apiKeyId: params.apiKey,
baseUrl: params.baseUrl,
});
}

public sendEmail(
Expand Down Expand Up @@ -93,6 +96,7 @@ export default class Client {
}

public getNotifications(options?: {
templateId?: string;
templateType?: string;
status?: string;
reference?: string;
Expand Down Expand Up @@ -213,6 +217,7 @@ const createPayload = (
};

const buildGetAllNotificationsQuery = (options?: {
templateId?: string;
templateType?: string;
status?: string;
reference?: string;
Expand All @@ -223,12 +228,17 @@ const buildGetAllNotificationsQuery = (options?: {
}

const payload: {
template_id?: string;
template_type?: string;
status?: string;
reference?: string;
older_than?: string;
} = {};

if (options.templateId) {
payload.template_id = options.templateId;
}

if (options.templateType) {
payload.template_type = options.templateType;
}
Expand All @@ -245,7 +255,9 @@ const buildGetAllNotificationsQuery = (options?: {
payload.older_than = options.olderThanId;
}

return buildQueryStringFromDict(payload);
const queryString = buildQueryStringFromDict(payload);

return queryString;
};

const buildQueryStringFromDict = (dictionary: object) => {
Expand Down

0 comments on commit 7f2d1f0

Please sign in to comment.