Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eslint #1

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:security/recommended"
]
}
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Pretty
run: npm run-script prettier-check
# complete the test coverage
# complete the test coverage
- name: Test
run: npm test

Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/pullRequests.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: pull_request_pipeline

on:
pull_request:
branches:
- main
name: Pull Request Pipeline
jobs:
pull_request_pipeline:
name: Pull Request Pipeline
name: pull_request_pipeline
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -22,16 +24,15 @@ jobs:
path: node_modules
key: 18.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}

- name: NPM Install
- name: Install Dependencies
if: steps.cache-modules.outputs.cache-hit != 'true'
run: npm install

- name: Lint
run: npm run-script lint
run: npm run lint

- name: Pretty
run: npm run-script prettier-check
# complete the test coverage
- name: Test
run: npm test
- name: Check Prettier
run: npm run prettier-check

- name: Run Tests
run: npm test
10 changes: 5 additions & 5 deletions lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const api = async (
method: "GET" | "POST" | "PATCH" | "DELETE",
method: 'GET' | 'POST' | 'PATCH' | 'DELETE',
host: string,
resource: string,
clientId: string,
userId: string,
hashedUserId?: string,
data?: any

Check warning on line 8 in lib/api.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Argument 'data' should be typed with a non-any type

Check warning on line 8 in lib/api.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
): Promise<any> => {

Check warning on line 9 in lib/api.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
const token = generateBasicTokenForUser(clientId, userId, hashedUserId);
const res = await fetch(
`https://${host}/${clientId}/users/${encodeURIComponent(
Expand All @@ -16,8 +16,8 @@
method,
body: JSON.stringify(data),
headers: {
Authorization: `Basic ${token}`,
},
Authorization: `Basic ${token}`
}
}
);

Expand All @@ -29,14 +29,14 @@
}
};

export const generateBasicTokenForUser = (

Check warning on line 32 in lib/api.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Missing return type on function
clientId: string,
userId: string,
hashedUserId?: string
) => {
const token = hashedUserId
? btoa(clientId + ":" + userId + ":" + hashedUserId)
: btoa(clientId + ":" + userId);
? btoa(clientId + ':' + userId + ':' + hashedUserId)
: btoa(clientId + ':' + userId);

return token;
};
63 changes: 33 additions & 30 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { api } from "./api";
import { api } from './api';
import {
BaseDeliveryOptions,
Channels,
DeliveryOptionsForEmail,
DeliveryOptionsForInappWeb,
} from "./interfaces";
DeliveryOptionsForInappWeb
} from './interfaces';
import {
GetPreferencesResponse,
InAppNotification,
WebSocket_NewNotification_Message,
} from "./interfaces";
WebSocket_NewNotification_Message
} from './interfaces';

type NotificationAPIClientSDKConfig = {
userId: string;
Expand All @@ -28,17 +28,17 @@
};

const defaultConfig: NotificationAPIClientSDKConfig = {
host: "api.notificationapi.com",
websocketHost: "ws.notificationapi.com",
userId: "",
clientId: "",
hashedUserId: "",
host: 'api.notificationapi.com',
websocketHost: 'ws.notificationapi.com',
userId: '',
clientId: '',
hashedUserId: '',
getInAppDefaultCount: 100,
getInAppDefaultOldest: new Date(
Date.now() - 30 * 24 * 60 * 60 * 1000
).toISOString(),
onNewInAppNotifications: undefined,
keepWebSocketAliveForSeconds: 24 * 60 * 60, // 24 hours
keepWebSocketAliveForSeconds: 24 * 60 * 60 // 24 hours
};

type NotificationAPIClientSDK = {
Expand All @@ -51,12 +51,12 @@
): NotificationAPIClientSDK;
rest: {
generic(
method: "GET" | "POST" | "PATCH" | "DELETE",
method: 'GET' | 'POST' | 'PATCH' | 'DELETE',
resource: string,
data?: any

Check warning on line 56 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
): Promise<any>;

Check warning on line 57 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
getNotifications(before: string, count: number): Promise<any>;

Check warning on line 58 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
patchNotifications(params: any): Promise<any>;

Check warning on line 59 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type

Check warning on line 59 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
getPreferences(): Promise<GetPreferencesResponse>;
postPreferences(
params: Array<{
Expand All @@ -68,7 +68,7 @@
| DeliveryOptionsForInappWeb
| BaseDeliveryOptions;
}>
): Promise<any>;

Check warning on line 71 in lib/client.ts

View workflow job for this annotation

GitHub Actions / pull_request_pipeline

Unexpected any. Specify a different type
};
websocket: {
object: WebSocket | undefined;
Expand Down Expand Up @@ -108,7 +108,7 @@
init: function (config) {
this.config = { ...defaultConfig, ...config };
return {
...this,
...this
};
},
rest: {
Expand All @@ -125,27 +125,27 @@
},
getNotifications: function (before, count) {
return NotificationAPIClientSDK.rest.generic(
"GET",
'GET',
`notifications/INAPP_WEB?count=${count}&before=${before}`
);
},
patchNotifications: function (params) {
return NotificationAPIClientSDK.rest.generic(
"PATCH",
"notifications/INAPP_WEB",
'PATCH',
'notifications/INAPP_WEB',
params
);
},
getPreferences: function () {
return NotificationAPIClientSDK.rest.generic("GET", "preferences");
return NotificationAPIClientSDK.rest.generic('GET', 'preferences');
},
postPreferences: function (params) {
return NotificationAPIClientSDK.rest.generic(
"POST",
"preferences",
'POST',
'preferences',
params
);
},
}
},
websocket: {
object: undefined,
Expand All @@ -161,7 +161,7 @@
return;
}

if (body.route === "inapp_web/new_notifications") {
if (body.route === 'inapp_web/new_notifications') {
const message = body as WebSocket_NewNotification_Message;
if (NotificationAPIClientSDK.config.onNewInAppNotifications) {
NotificationAPIClientSDK.config.onNewInAppNotifications(
Expand All @@ -179,15 +179,18 @@
callback(NotificationAPIClientSDK.websocket.object);
}
}
},
}
},
openWebSocket: function () {
const websocket = NotificationAPIClientSDK.websocket.connect(() => {
setTimeout(() => {
this.websocket.disconnect(() => {
this.websocket.connect();
});
}, 9 * 60 * 1000);
setTimeout(
() => {
this.websocket.disconnect(() => {
this.websocket.connect();
});
},
9 * 60 * 1000
);
});
return websocket;
},
Expand Down Expand Up @@ -233,14 +236,14 @@
return {
items: result,
hasMore,
oldestReceived,
oldestReceived
};
},
updateInAppNotifications: async (params) => {
const body: {
[key: string]: any;
} = {
trackingIds: params.ids,
trackingIds: params.ids
};

if (params.archived === true) {
Expand All @@ -266,5 +269,5 @@
},
updateDeliveryOption: async (params) => {
return NotificationAPIClientSDK.rest.postPreferences([params]);
},
}
};
38 changes: 19 additions & 19 deletions lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ export interface InAppNotification {
}

export interface WebSocket_NewNotification_Message {
route: "inapp_web/new_notifications";
route: 'inapp_web/new_notifications';
payload: {
notifications: InAppNotification[];
};
}

export type Channels =
| "EMAIL"
| "INAPP_WEB"
| "SMS"
| "CALL"
| "PUSH"
| "WEB_PUSH";
| 'EMAIL'
| 'INAPP_WEB'
| 'SMS'
| 'CALL'
| 'PUSH'
| 'WEB_PUSH';

export type BaseDeliveryOptions = "off" | "instant";
export type BaseDeliveryOptions = 'off' | 'instant';

export type DeliveryOptionsForInappWeb = "off" | "instant";
export type DeliveryOptionsForInappWeb = 'off' | 'instant';

export type DeliveryOptionsForEmail =
| "off"
| "instant"
| "hourly"
| "daily"
| "weekly"
| "monthly";
| 'off'
| 'instant'
| 'hourly'
| 'daily'
| 'weekly'
| 'monthly';

export interface GetPreferencesResponse {
preferences: {
Expand All @@ -82,7 +82,7 @@ export interface GetPreferencesResponse {
notificationId: string;
title: string;
channels: Channels[];
options: NotificationConfig["options"];
options: NotificationConfig['options'];
}[];
subNotifications: {
notificationId: string;
Expand All @@ -103,9 +103,9 @@ export interface NotificationConfig {
throttling?: {
max: number;
period: number;
unit: "seconds" | "minutes" | "hours" | "days" | "months" | "years";
unit: 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years';
forever: boolean;
scope: ["userId", "notificationId"];
scope: ['userId', 'notificationId'];
};
retention?: number;
options?: {
Expand Down Expand Up @@ -135,7 +135,7 @@ export interface EmailDeliveryOptions {
monthly?: {
enabled: boolean;
hour?: string;
date?: "first" | "last";
date?: 'first' | 'last';
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { NotificationAPIClientSDK } from "./client";
export { NotificationAPIClientSDK } from './client';
Loading
Loading