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

SDK-2421 TypeScript Support #428

Merged
merged 17 commits into from
Jan 12, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/node_modules
types
58 changes: 34 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
module.exports = {
"plugins": ["node", "jest"],
"extends": ["plugin:node/recommended", "airbnb-base"],
plugins: ['node', 'jest'],
extends: ['plugin:node/recommended', 'airbnb-base'],
rules: {
"node/exports-style": ["error", "module.exports"],
"prefer-destructuring": ["error", {"object": false, "array": false}],
"strict": 0,
"comma-dangle": ["error", {
"arrays": "always-multiline",
"exports": "always-multiline",
"functions": "never",
"imports": "always-multiline",
"objects": "always-multiline"
'node/exports-style': ['error', 'module.exports'],
'prefer-destructuring': ['error', { object: false, array: false }],
strict: 0,
'comma-dangle': ['error', {
arrays: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
imports: 'always-multiline',
objects: 'always-multiline',
}],
'no-console': 0,
'prefer-object-spread': 0,
'default-param-last': 'off',
'prefer-regex-literals': 'off',
'max-len': ['error', {
code: 100,
tabWidth: 2,
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignorePattern: '\\* @typedef \\{import',
}],
"no-console": 0,
"prefer-object-spread": 0,
"default-param-last": "off",
"prefer-regex-literals": "off"
},
env: {
"node": true,
"jest/globals": true
node: true,
'jest/globals': true,
},
"overrides": [{
"files": "\"./tests/**/*.spec.js\"",
"rules": {
"node/no-unpublished-require": 0,
"node/no-missing-require": 0
}
}]
overrides: [{
files: '"./tests/**/*.spec.js"',
rules: {
'node/no-unpublished-require': 0,
'node/no-missing-require': 0,
},
}],
};
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ const {
RequestedTypeListSourcesBuilder,
CreateFaceCaptureResourcePayloadBuilder,
UploadFaceCaptureImagePayloadBuilder,
IDVService,
} = require('./src/idv_service');

const YotiCommon = require('./src/yoti_common');
const { YotiRequest } = require('./src/request/request');
const IDVError = require('./src/idv_service/idv.error');

module.exports = {
internals: {
IDVService,
YotiCommon,
YotiRequest,
IDVError,
},
Client: YotiClient,
IDVClient,
DigitalIdentityClient,
Expand Down
19 changes: 9 additions & 10 deletions package-lock.json

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

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
"engines": {
"node": ">=14"
},
"types": "./types/index.d.ts",
"scripts": {
"lint": "npx eslint *.js './src/**/*.js' './tests/**/*.spec.js' config/*.js",
"test": "jest",
"audit": "audit-ci --config ./audit-ci.jsonc",
"pre-commit": "npm run test"
"types:generate": "tsc index.js --declaration --allowJs --checkJs --resolveJsonModule --emitDeclarationOnly --skipLibCheck --outDir types",
"types:refresh": "rm -rf types && npm run types:generate && git add types",
"pre-commit": "npm run test && npm run types:refresh"
},
"jest": {
"verbose": true,
Expand Down Expand Up @@ -46,6 +49,7 @@
"eslint-plugin-node": "11.1.0",
"husky": "8.0.3",
"jest": "29.5.0",
"nock": "13.2.9"
"nock": "13.2.9",
"typescript": "5.3.3"
}
}
8 changes: 5 additions & 3 deletions src/aml_service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ class AmlService {
/**
* @param {string} sdkId
* @param {string|Buffer} pem
* @param {Object} options
* @param {string} options.apiUrl
* @param {{apiUrl?: string}} options
*/
constructor(sdkId, pem, { apiUrl = DEFAULT_API_URL } = {}) {
Validation.isString(sdkId, 'sdkId');
Validation.notNullOrEmpty(pem, 'pem');

/** @private */
this.sdkId = sdkId;
/** @private */
this.pem = pem;
/** @private */
this.apiUrl = apiUrl;
}

Expand All @@ -65,7 +67,7 @@ class AmlService {

const requestBuilder = new RequestBuilder()
.withBaseUrl(this.apiUrl)
.withPemString(this.pem)
.withPemString(this.pem.toString())
.withEndpoint('/aml-check')
.withQueryParam('appId', this.sdkId)
.withMethod('POST')
Expand Down
1 change: 0 additions & 1 deletion src/aml_type/aml.address.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module.exports.AmlAddress = class AmlAddress {
}

/**
* @param countryCode
*
* @deprecated Replaced by Validation.notNullOrEmpty()
*/
Expand Down
26 changes: 19 additions & 7 deletions src/client/digital.identity.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,68 @@ class DigitalIdentityClient {
/**
* @param {string} sdkId
* @param {string|Buffer} pem
* @param {Object} options
* @param {string} options.apiUrl
* @param {{apiUrl?: string}} options
*/
constructor(sdkId, pem, { apiUrl } = {}) {
const options = {
apiUrl: apiUrl || config.yoti.digitalIdentityApi,
};

/** @private */
this.digitalIdentityService = new DigitalIdentityService(sdkId, pem, options);
}

/**
* @typedef {import('../digital_identity_service/share.session.configuration.js')} ShareSessionConfig
*
* @param {ShareSessionConfig} shareSessionConfig
*
* @typedef {import('../digital_identity_service/create.share.session.result.js')} CreateShareSessionResult
*
* @param shareSessionConfig
* @returns {Promise<CreateShareSessionResult>}
*/
async createShareSession(shareSessionConfig) {
return this.digitalIdentityService.createShareSession(shareSessionConfig);
}

/**
* @param {string} sessionId
*
* @typedef {import('../digital_identity_service/get.share.session.result.js')} GetShareSessionResult
*
* @param sessionId
* @returns {Promise<GetShareSessionResult>}
*/
async getShareSession(sessionId) {
return this.digitalIdentityService.getShareSession(sessionId);
}

/**
* @param {string} sessionId
*
* @typedef {import('../digital_identity_service/create.share.qr.code.result.js')} CreateShareQrCodeResult
*
* @param sessionId
* @returns {Promise<CreateShareQrCodeResult>}
*/
async createShareQrCode(sessionId) {
return this.digitalIdentityService.createShareQrCode(sessionId);
}

/**
* @param {string} qrCodeId
*
* @typedef {import('../digital_identity_service/get.share.qr.code.result.js')} GetShareQrCodeResult
*
* @param qrCodeId
* @returns {Promise<GetShareQrCodeResult>}
*/
async getShareQrCode(qrCodeId) {
return this.digitalIdentityService.getShareQrCode(qrCodeId);
}

/**
*
* @param {string} receiptId
*
* @typedef {import('../digital_identity_service/get.share.receipt.result.js')} GetShareReceiptResult
*
* @returns {Promise<GetShareReceiptResult>}
*/
async getShareReceipt(receiptId) {
Expand Down
30 changes: 25 additions & 5 deletions src/client/idv.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ class IDVClient {
/**
* @param {string} sdkId
* @param {string|Buffer} pem
* @param {Object} options
* @param {string} options.apiUrl
* @param {{apiUrl?: string}} options
*/
constructor(sdkId, pem, { apiUrl } = {}) {
const options = {
apiUrl: apiUrl || config.yoti.idvApi,
};
/** @private */
this.idvService = new IDVService(sdkId, pem, options);
}

/**
* Creates a IDV session using the supplied session specification
*
* @typedef {import('../idv_service/session/create/session.specification.js')} SessionSpecification
*
* @param {SessionSpecification} sessionSpecification
*
* @typedef {import('../idv_service/session/create/create.session.result')} CreateSessionResult
*
* @returns {Promise<CreateSessionResult>}
*/
createSession(sessionSpecification) {
Expand All @@ -40,6 +44,8 @@ class IDVClient {
*
* @param {string} sessionId
*
* @typedef {import('../idv_service/session/retrieve/get.session.result.js')} GetSessionResult
*
* @returns {Promise<GetSessionResult>}
*/
getSession(sessionId) {
Expand All @@ -52,7 +58,7 @@ class IDVClient {
*
* @param {string} sessionId
*
* @returns {Promise}
* @returns {Promise<void>}
*/
deleteSession(sessionId) {
return this.idvService.deleteSession(sessionId);
Expand All @@ -65,6 +71,8 @@ class IDVClient {
* @param {string} sessionId
* @param {string} mediaId
*
* @typedef {import('../data_type/media.js')} Media
*
* @returns {Promise<Media>}
*/
getMediaContent(sessionId, mediaId) {
Expand All @@ -78,7 +86,7 @@ class IDVClient {
* @param {string} sessionId
* @param {string} mediaId
*
* @returns {Promise}
* @returns {Promise<void>}
*/
deleteMediaContent(sessionId, mediaId) {
return this.idvService.deleteMediaContent(sessionId, mediaId);
Expand All @@ -89,6 +97,8 @@ class IDVClient {
*
* @param {boolean} includeNonLatin
*
* @typedef {import('../idv_service/support/supported.documents.response.js')} SupportedDocumentsResponse
*
* @returns {Promise<SupportedDocumentsResponse>}
*/
getSupportedDocuments(includeNonLatin) {
Expand All @@ -98,8 +108,13 @@ class IDVClient {
/**
* Creates a face capture resource
* @param {string} sessionId
*
* @typedef {import('../idv_service/session/create/face_capture/create.face.capture.resource.payload.js')} CreateFaceCaptureResourcePayload
*
* @param {CreateFaceCaptureResourcePayload} createFaceCaptureResourcePayload
*
* @typedef {import('../idv_service/session/retrieve/create.face.capture.resource.response.js')} CreateFaceCaptureResourceResponse
*
* @returns {Promise<CreateFaceCaptureResourceResponse>}
*/
createFaceCaptureResource(sessionId, createFaceCaptureResourcePayload) {
Expand All @@ -113,9 +128,12 @@ class IDVClient {
* Uploads a face capture image
* @param {string} sessionId
* @param {string} resourceId
*
* @typedef {import('../idv_service/session/create/face_capture/upload.face.capture.image.payload.js')} UploadFaceCaptureImagePayload
*
* @param {UploadFaceCaptureImagePayload} uploadFaceCaptureImagePayload
*
* @returns {Promise<CreateFaceCaptureResourceResponse>}
* @returns {Promise<void>}
*/
uploadFaceCaptureImage(sessionId, resourceId, uploadFaceCaptureImagePayload) {
return this.idvService.uploadFaceCaptureImage(
Expand All @@ -130,6 +148,8 @@ class IDVClient {
*
* @param {string} sessionId
*
* @typedef {import('../idv_service/session/retrieve/configuration/session.configuration.response.js')} SessionConfigurationResponse
*
* @returns {Promise<SessionConfigurationResponse>}
*/
getSessionConfiguration(sessionId) {
Expand Down
Loading
Loading