Skip to content

Commit bfd7336

Browse files
Merge pull request #27 from telstra/maintain/MessagingAPI-V3-SDK
release 3.0.3
2 parents a5be54b + 53ba1be commit bfd7336

File tree

7 files changed

+25
-74
lines changed

7 files changed

+25
-74
lines changed

package-lock.json

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.0.2",
2+
"version": "3.0.3",
33
"license": "Apache-2.0",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
@@ -57,6 +57,7 @@
5757
"dependencies": {
5858
"ajv": "^6.12.6",
5959
"axios": "^1.3.6",
60+
"moment": "^2.30.1",
6061
"uuid": "^9.0.0"
6162
}
6263
}

src/messaging/classes/HttpClient.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { URLSearchParams } from 'url';
1111
import { RequestError, AuthError } from './Errors';
1212
import {
1313
getAuthToken,
14-
setAuthToken,
15-
getAuthTokenRetryCount,
16-
setAuthTokenRetryCount,
14+
setAuthToken
1715
} from '../utils';
1816

1917
declare module 'axios' {
@@ -23,7 +21,6 @@ declare module 'axios' {
2321
export abstract class HttpClient {
2422
protected readonly instance: AxiosInstance;
2523
private auth: Auth;
26-
private authRetryCount: number = 0;
2724

2825
public constructor(public authConfig?: AuthConfigProps) {
2926
this.instance = axios.create({
@@ -123,18 +120,11 @@ export abstract class HttpClient {
123120
);
124121
}
125122

126-
this.authRetryCount = await getAuthTokenRetryCount();
127-
128123
// attempt to refresh an auth token
129124
if (
130125
error.response?.status === 401 &&
131-
error.response?.config.url !== '/v2/oauth/token' &&
132-
this.authRetryCount < 3
126+
error.response?.config.url !== '/v2/oauth/token'
133127
) {
134-
// increment auth token retry count
135-
this.authRetryCount++;
136-
await setAuthTokenRetryCount(this.authRetryCount);
137-
138128
// retrieve auth credentials
139129
const authCredentials = await this.auth.getCredentials();
140130

src/messaging/constants/Constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export abstract class Constants {
99
static readonly SHARED_CREDENTIALS: string = `${os.homedir()}/.telstra/credentials`;
1010
static readonly API_URL: string = 'https://products.api.telstra.com/';
1111
static readonly BUCKET_AUTH_STORE: string = 'authStore';
12-
static readonly BUCKET_KEY_AUTH_RETRY_COUNT: string = 'tokenRetryAttempt';
1312
static readonly BUCKET_KEY_ACCESS_TOKEN: string = 'accessToken';
1413
static readonly BUCKET_KEY_CLIENT_CREDENTIALS: string = 'clientCredentials';
1514
static readonly USER_AGENT: string = 'Telstra Messaging SDK/0.3.18';

src/messaging/utils/config.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,3 @@ export const getAuthToken = async (): Promise<string | boolean> => {
6767
}
6868
};
6969

70-
export const setAuthTokenRetryCount = async (
71-
retryCount: number
72-
): Promise<boolean> => {
73-
try {
74-
if (!retryCount)
75-
throw new StorageError(Constants.ERRORS.STORAGE_ERROR_SET);
76-
await storage().set({
77-
bucket: Constants.BUCKET_AUTH_STORE,
78-
key: Constants.BUCKET_KEY_AUTH_RETRY_COUNT,
79-
data: JSON.stringify(retryCount),
80-
});
81-
return true;
82-
} catch (error) {
83-
return false;
84-
}
85-
};
86-
87-
export const getAuthTokenRetryCount = async (): Promise<number> => {
88-
try {
89-
const data = await storage().get({
90-
bucket: Constants.BUCKET_AUTH_STORE,
91-
key: Constants.BUCKET_KEY_AUTH_RETRY_COUNT,
92-
});
93-
return parseInt(JSON.parse(data));
94-
} catch (error) {
95-
return 0;
96-
}
97-
};

test/src/messaging/classes/Reports.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { server, rest } = require('../testServer');
33
const { Reports, AssertionError } = require('../../../../src/messaging/classes');
44
const AUTH_CONFIG = require('../credentials.json');
55
const { Constants } = require('../Constants');
6+
const moment = require('moment');
67

78
const reports = new Reports(AUTH_CONFIG);
89

@@ -11,7 +12,9 @@ describe("Reports", () => {
1112
describe("request a messages report", () => {
1213
describe('when the client sends a valid request', () => {
1314
it("should pass", async () => {
14-
const data = { startDate: "2024-05-01", endDate: "2024-05-10", reportCallbackUrl: "https://www.example.com", filter:"test"}
15+
const startDate = moment().subtract(3, 'days').format('YYYY-MM-DD');
16+
const endDate = moment().format('YYYY-MM-DD');
17+
const data = { startDate, endDate, reportCallbackUrl: "https://www.example.com", filter: "test" };
1518
await expect(reports.create(data)).resolves.toEqual(Constants.CREATE_MESSAGES_REPORT_RESPONSE);
1619
});
1720
});

test/src/messaging/utils/config.spec.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ const {
33
setAuthConfig,
44
getAuthConfig,
55
setAuthToken,
6-
getAuthToken,
7-
setAuthTokenRetryCount,
8-
getAuthTokenRetryCount,
6+
getAuthToken
97
} = require('../../../../src/messaging/utils');
108

119
const AUTH_CONFIG = require('../credentials.json');
@@ -46,31 +44,5 @@ describe('config', () => {
4644
});
4745
});
4846

49-
describe('when getAuthTokenRetryCount is called', () => {
50-
it('should return 0 as a number', async () => {
51-
expect(await getAuthTokenRetryCount()).toEqual(0);
52-
});
53-
});
54-
55-
describe('when setAuthTokenRetryCount is called', () => {
56-
it('should get auth token retry count of 0 when storage not yet initialised', async () => {
57-
expect(await getAuthTokenRetryCount()).toEqual(0);
58-
});
59-
});
60-
61-
describe('when setAuthTokenRetryCount is called', () => {
62-
it('should return true given a number', async () => {
63-
expect(await setAuthTokenRetryCount(1)).toBeTruthy();
64-
});
65-
it('should return false given no payload', async () => {
66-
expect(await setAuthTokenRetryCount()).toBeFalsy();
67-
});
68-
});
69-
70-
describe('when getAuthTokenRetryCount is called', () => {
71-
it('should return 1 as a number', async () => {
72-
expect(await getAuthTokenRetryCount()).toEqual(1);
73-
});
74-
});
7547

7648
});

0 commit comments

Comments
 (0)