Skip to content

Commit

Permalink
Add typescript (#58)
Browse files Browse the repository at this point in the history
* Add typescript

* Add typescript config

* Convert src/constants.js to typescript

* Convert src/helpers to typescript

* Convert src/signature to ts

* Add shared.ts for shared types

* convert utilities to ts

* Convert web-token to s

* Convert id-api to ts

* Convert web-api to ts

* Convert index.js to ts

* Resolve id spread issue in webapi

* Add typescript support for jest
Change tests to typescript

* Remove es exports, defer to typescript export

* Chnange require to import
Fix test: object check error

* Add typescript lint support
Use es2021 in typescript config
Change tests to typescript

* Move examples into single folder
Fix lint issue
Update eslint config
Build js files in ci before test and deployment
Install example dependency before lint

* Fix failing test
Remove example package install from ci

* Fix types

* Change biometric kyc example to ts

* Fix lint

* change document verfication example to ts

* Fix lint

* Change enhasned kyc to typescript

* Change smart selfie example to typescript

* Update package.json

Co-authored-by: Michael <michael.l.dangelo@gmail.com>

* Fix helpers test

* remove npm build from workflow

* Export interface inline

* Add babel cli

* Compile js in prepublish using babel
Build declaration in prepublish
Add tsc check in lint
Remove comments from tsconfigs

* Change console error to warn, since execution will still continue

* Add tsconfig to generate single d.ts file for all declarations
Add js and type generation in prepublish

* Fix index path in package.json

* Add contributors field in package.json

* Use require for server.js

* Upgrade json5 json5/json5#295

* Add source map to config

* restrict sidServerMapping keys to number

Co-authored-by: Michael <michael.l.dangelo@gmail.com>
  • Loading branch information
ayinloya and mldangelo committed Jan 5, 2023
1 parent 3d02162 commit ad6ef3d
Show file tree
Hide file tree
Showing 37 changed files with 1,821 additions and 283 deletions.
22 changes: 21 additions & 1 deletion .eslintrc.js
Expand Up @@ -7,18 +7,38 @@ module.exports = {
},
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:jest/recommended',
'plugin:jsdoc/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 13,
project: './tsconfig.eslint.json',
},
plugins: ['jest', 'jsdoc'],
plugins: ['jest', 'jsdoc', '@typescript-eslint'],
ignorePatterns: ['coverage/**/*', 'dist/**/*'],
rules: {
camelcase: 0,
'compat/compat': 0,
'no-restricted-imports': 'off',
'import/prefer-default-export': 'off',
'no-console': ['error', {
allow: ['warn', 'error', 'info'],
}],
'@typescript-eslint/naming-convention': [ // TODO:remove custom convention in future versions
'warn',
{
selector: 'variable',
format: ['camelCase', 'PascalCase', 'snake_case', 'UPPER_CASE'],
},
],
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
},
},
},
};
5 changes: 4 additions & 1 deletion babel.config.js
Expand Up @@ -6,5 +6,8 @@ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.jso
const nodeVersionNumber = packageJson.engines.node.replace(/^>=v/, '');

module.exports = {
presets: [['@babel/preset-env', { targets: { node: nodeVersionNumber } }]],
presets: [
['@babel/preset-env', { targets: { node: nodeVersionNumber } }],
'@babel/preset-typescript',
],
};
File renamed without changes.
3 changes: 2 additions & 1 deletion examples/biometric_kyc.js → examples/biometric_kyc.ts
Expand Up @@ -4,7 +4,8 @@
*/

// Change to smile-identity-core if you're using this snippet in your project.
const { WebApi } = require('..');
/* eslint-disable import/no-relative-packages */
import { WebApi } from '..';

// Initialize
// Login to the Smile Identity Portal to view your partner id.
Expand Down
Expand Up @@ -4,7 +4,8 @@
*/

// Change to smile-identity-core if you're using this snippet in your project.
const { WebApi } = require('..');
/* eslint-disable import/no-relative-packages */
import { WebApi } from '..';

// Initialize
// login to the Smile Identity portal to view your partner id.
Expand Down
3 changes: 2 additions & 1 deletion examples/enhanced_kyc.js → examples/enhanced_kyc.ts
@@ -1,5 +1,6 @@
// Change to smile-identity-core if you're using this snippet in your project.
const { IDApi } = require('..');
/* eslint-disable import/no-relative-packages */
import { IDApi } from '..';

// Initialize
// login to the Smile Identity Portal to view your partner id.
Expand Down
29 changes: 0 additions & 29 deletions examples/example-project/package.json

This file was deleted.

10 changes: 8 additions & 2 deletions examples/package.json
Expand Up @@ -5,7 +5,9 @@
"main": "server.js",
"scripts": {},
"dependencies": {
"smile-identity-core": "latest",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"smile-identity-core": "file:../",
"uuid": "^9.0.0"
},
"engines": {
Expand All @@ -20,5 +22,9 @@
"glitch",
"express",
"Smile Identity"
]
],
"devDependencies": {
"@types/express": "^4.17.15",
"@types/uuid": "^9.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions examples/example-project/server.js → examples/server.js
Expand Up @@ -68,7 +68,6 @@ app.post('/', async (req, res) => {

// NOTE: This can be used to process responses. Don't forget to add it as a
// callback option in the `connection` config on L22.
// eslint-disable-next-line no-unused-vars
app.post('/callback', (_req, _res, _next) => { });
app.post('/callback');

app.listen(process.env.PORT || 4000);
Expand Up @@ -2,7 +2,8 @@
// how to setup and retrieve configuration values for the WebApi class.

// Change to smile-identity-core if you're using this snippet in your project.
const { WebApi } = require('..');
/* eslint-disable import/no-relative-packages */
import { WebApi } from '..';

// Initialize
const partner_id = '<Your partner ID>'; // login to the Smile Identity portal to view your partner id
Expand Down
18 changes: 0 additions & 18 deletions index.js

This file was deleted.

13 changes: 13 additions & 0 deletions index.ts
@@ -0,0 +1,13 @@
import { IDApi } from './src/id-api';
import Signature from './src/signature';
import { Utilities } from './src/utilities';
import { WebApi } from './src/web-api';
import { JOB_TYPE, IMAGE_TYPE } from './src/constants';

if ((typeof process === 'undefined' && typeof (process as NodeJS.Process).versions.node === 'undefined') || typeof window !== 'undefined') {
console.warn('This is a server-side library meant for a node.js (or compatible) runtime, and is not meant to work in the browser.');
}

export {
IDApi, Signature, Utilities, WebApi, JOB_TYPE, IMAGE_TYPE,
};
9 changes: 9 additions & 0 deletions jest.config.ts
@@ -0,0 +1,9 @@
import type { Config } from 'jest';
import { defaults } from 'jest-config';

const config: Config = {
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'],
modulePathIgnorePatterns: ['<rootDir>/dist'],
};

export default config;

0 comments on commit ad6ef3d

Please sign in to comment.