Skip to content
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
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.x', '14.x', '16.x']
node: ['14.x', '16.x', '18.x']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand All @@ -27,6 +27,10 @@ jobs:

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
env:
API_URL: ${{ secrets.API_URL }}
APP_KEY: ${{ secrets.APP_KEY }}
APP_SECRET: ${{ secrets.APP_SECRET }}

- name: Build
run: yarn build
12 changes: 0 additions & 12 deletions .github/workflows/size.yml

This file was deleted.

39 changes: 7 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"src"
],
"engines": {
"node": ">=12"
"node": ">=14"
},
"scripts": {
"start": "tsdx watch",
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createOrUpdateUser,
CLAIM_USER_ID,
CLAIM_IS_VERIFIED_USER,
deleteUser,
} from './lib/core';
import { createSmartLink } from './lib/smart_links';
import expressLib from './express';
Expand All @@ -26,9 +27,10 @@ const claims = {

function createInstance(config?: TConfig): IRowndClient {
const instConfig = { ...defaultConfig, ...config };
var initHandle;

if (instConfig.app_key) {
fetchAppConfig(instConfig)
initHandle = fetchAppConfig(instConfig)
.then(app => (instConfig._app = app))
.catch(err => {
throw new Error(`Failed to fetch app config: ${err.message}`);
Expand All @@ -41,9 +43,11 @@ function createInstance(config?: TConfig): IRowndClient {
fetchUserInfo: (opts: FetchUserInfoOpts) => fetchUserInfo(opts, instConfig),
createOrUpdateUser: (user: RowndUser) =>
createOrUpdateUser(user, instConfig),
deleteUser: (userId: String) => deleteUser(userId, instConfig),
createSmartLink: (opts: CreateSmartLinkOpts) =>
createSmartLink(opts, instConfig),
express: expressLib(instConfig),
appConfig: initHandle,
};
}

Expand Down
16 changes: 16 additions & 0 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ export async function createOrUpdateUser(

return resp;
}

export async function deleteUser(
userId: String,
config: TConfig
): Promise<void> {
await got.delete(
`${config.api_url}/applications/${config._app!.id}/users/${userId}/data`,
{
headers: {
'x-rownd-app-key': config.app_key,
'x-rownd-app-secret': config.app_secret,
'content-type': 'application/json',
},
}
);
}
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export interface IRowndClient {
validateToken: (token: string) => Promise<TTokenValidationPayload>;
fetchUserInfo: (token: FetchUserInfoOpts) => Promise<TUserInfo>;
createOrUpdateUser: (user: TUser) => Promise<TUser>;
deleteUser: (userId: String) => Promise<void>;
createSmartLink: (opts: TCreateSmartLinkOpts) => Promise<TSmartLink>;
express: IRowndExpressClient;
appConfig: Promise<TApp> | undefined;
}

interface IRowndExpressClient {
Expand Down
24 changes: 18 additions & 6 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createInstance } from '../src';
import { createConfig } from '../src/lib/config';
import { TConfig } from '../src/types';

const TOKEN: string = process.env.TOKEN as string;
// const TOKEN: string = process.env.TOKEN as string;

const testConfig: TConfig = createConfig({
api_url: process.env.API_URL,
Expand All @@ -13,10 +13,13 @@ const testConfig: TConfig = createConfig({
const client = createInstance(testConfig);

describe('user profile handling', () => {
it('validate a good token', async () => {
const tokenObj = await client.validateToken(TOKEN);
expect(tokenObj.user_id).toBeDefined();
beforeAll(() => {
return client.appConfig; // ensure app config has been fetched
});
// it('validate a good token', async () => {
// const tokenObj = await client.validateToken(TOKEN);
// expect(tokenObj.user_id).toBeDefined();
// });

it('fetches a user', async () => {
const user = await client.fetchUserInfo({ user_id: 'mth-test-user-1' });
Expand All @@ -27,9 +30,18 @@ describe('user profile handling', () => {
const originalUser = await client.fetchUserInfo({
user_id: 'mth-test-user-1',
});
const updatedUser = await client.createOrUpdateUser(originalUser);

expect(updatedUser.data).toBeDefined();
// Make sure the user has an email address
originalUser.data.email = 'testuser@rownd.app';

try {
const updatedUser = await client.createOrUpdateUser(originalUser);

expect(updatedUser.data).toBeDefined();
} catch (err) {
var error: any = err;
fail(error.message + ': ' + error?.response?.body);
}
});

it('creates a login link', async () => {
Expand Down
Loading