Socket
Socket
Sign inDemoInstall

@unumid/server-sdk

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unumid/server-sdk - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

14

build/utils/networkRequestHelper.js
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -63,3 +74,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

body: JSON.stringify(inputObj.data),
headers: restHdr
headers: __assign(__assign({}, restHdr), { version: '1.0.0' // The api version to hit the UnumID SaaS with in the this version of the SDK
})
};

@@ -66,0 +78,0 @@ respObj = {};

7

build/verifier/sendEmail.d.ts

@@ -7,9 +7,8 @@ import { UnumDto } from '../types';

* Handler to send an email using UnumID's SaaS.
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param subject
* @param textBody
* @param htmlBody
* @param deeplink
*/
export declare const sendEmail: (authorization: string, to: string, subject: string, textBody?: string | undefined, htmlBody?: string | undefined) => Promise<UnumDto<undefined>>;
export declare const sendEmail: (authorization: string, to: string, deeplink: string) => Promise<UnumDto<undefined>>;
//# sourceMappingURL=sendEmail.d.ts.map

@@ -53,37 +53,27 @@ "use strict";

var validateEmailRequestBody = function (body) {
var to = body.to, subject = body.subject, textBody = body.textBody, htmlBody = body.htmlBody;
var to = body.to, deeplink = body.deeplink;
if (!to) {
throw new error_1.CustError(400, 'to is required.');
}
if (!subject) {
throw new error_1.CustError(400, 'subject is required.');
if (!deeplink) {
throw new error_1.CustError(400, 'deeplink is required.');
}
if (!textBody && !htmlBody) {
throw new error_1.CustError(400, 'Either textBody or htmlBody is required.');
}
if (textBody && htmlBody) {
throw new error_1.CustError(400, 'Either textBody or htmlBody is required, not both.');
}
if (typeof to !== 'string') {
throw new error_1.CustError(400, 'Invalid to: expected string.');
}
if (typeof subject !== 'string') {
throw new error_1.CustError(400, 'Invalid subject: expected string.');
if (typeof deeplink !== 'string') {
throw new error_1.CustError(400, 'Invalid deeplink: expected string.');
}
if (textBody && (typeof textBody !== 'string')) {
throw new error_1.CustError(400, 'Invalid textBody: expected string.');
if (deeplink.split('presentationRequest/').length !== 2) {
throw new error_1.CustError(400, 'Invalid deeplink: expected to end in the format presentationRequest/<uuid>.');
}
if (htmlBody && (typeof htmlBody !== 'string')) {
throw new error_1.CustError(400, 'Invalid htmlBody: expected string.');
}
};
/**
* Handler to send an email using UnumID's SaaS.
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param subject
* @param textBody
* @param htmlBody
* @param deeplink
*/
exports.sendEmail = function (authorization, to, subject, textBody, htmlBody) { return __awaiter(void 0, void 0, void 0, function () {
exports.sendEmail = function (authorization, to, deeplink) { return __awaiter(void 0, void 0, void 0, function () {
var body, data, apiResponse, authToken, result, e_1;

@@ -95,3 +85,3 @@ return __generator(this, function (_a) {

requireAuth_1.requireAuth(authorization);
body = { to: to, subject: subject, textBody: textBody, htmlBody: htmlBody };
body = { to: to, deeplink: deeplink };
validateEmailRequestBody(body);

@@ -98,0 +88,0 @@ data = {

@@ -7,9 +7,8 @@ import { UnumDto } from '../types';

* Handler to send a SMS using UnumID's SaaS.
* Designed to be used to present a deeplink.
*
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param msg
* @param deeplink
*/
export declare const sendSms: (authorization: string, to: string, msg: string) => Promise<UnumDto<undefined>>;
export declare const sendSms: (authorization: string, to: string, deeplink: string) => Promise<UnumDto<undefined>>;
//# sourceMappingURL=sendSms.d.ts.map

@@ -53,8 +53,8 @@ "use strict";

var validateSmsRequestBody = function (body) {
var to = body.to, msg = body.msg;
var to = body.to, deeplink = body.deeplink;
if (!to) {
throw new error_1.CustError(400, 'to is required.');
}
if (!msg) {
throw new error_1.CustError(400, 'msg is required.');
if (!deeplink) {
throw new error_1.CustError(400, 'deeplink is required.');
}

@@ -64,15 +64,17 @@ if (typeof to !== 'string') {

}
if (typeof msg !== 'string') {
throw new error_1.CustError(400, 'Invalid msg: expected string.');
if (typeof deeplink !== 'string') {
throw new error_1.CustError(400, 'Invalid deeplink: expected string.');
}
if (deeplink.split('presentationRequest/').length !== 2) {
throw new error_1.CustError(400, 'Invalid deeplink: expected to end in the format presentationRequest/<uuid>.');
}
};
/**
* Handler to send a SMS using UnumID's SaaS.
* Designed to be used to present a deeplink.
*
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param msg
* @param deeplink
*/
exports.sendSms = function (authorization, to, msg) { return __awaiter(void 0, void 0, void 0, function () {
exports.sendSms = function (authorization, to, deeplink) { return __awaiter(void 0, void 0, void 0, function () {
var body, data, apiResponse, authToken, result, e_1;

@@ -83,3 +85,3 @@ return __generator(this, function (_a) {

_a.trys.push([0, 2, , 3]);
body = { to: to, msg: msg };
body = { to: to, deeplink: deeplink };
requireAuth_1.requireAuth(authorization);

@@ -86,0 +88,0 @@ validateSmsRequestBody(body);

{
"name": "@unumid/server-sdk",
"version": "1.2.3",
"version": "1.3.0",
"main": "build/index.js",

@@ -46,3 +46,3 @@ "repository": "git@github.com:UnumID/Server-SDK-TypeScript.git",

"@unumid/library-crypto": "https://github.com/UnumID/Library-Crypto-TypeScript.git#v1.2.0",
"@unumid/types": "https://github.com/UnumID/types.git#v1.3.0",
"@unumid/types": "https://github.com/UnumID/types.git#1.4.0",
"dotenv": "^8.2.0",

@@ -49,0 +49,0 @@ "express": "^4.17.1",

@@ -21,3 +21,6 @@ import fetch from 'node-fetch';

body: JSON.stringify(inputObj.data),
headers: restHdr
headers: {
...restHdr,
version: '1.0.0' // The api version to hit the UnumID SaaS with in the this version of the SDK
}
};

@@ -24,0 +27,0 @@ const respObj = {} as RESTResponse<T>;

@@ -0,1 +1,2 @@

import { MessageInput } from '@unumid/types';
import { configData } from '../config';

@@ -8,9 +9,2 @@ import logger from '../logger';

interface EmailRequestBody {
to: string;
subject: string;
textBody?: string;
htmlBody?: string;
}
export interface EmailResponseBody {

@@ -24,4 +18,4 @@ success: boolean;

*/
const validateEmailRequestBody = (body: EmailRequestBody): void => {
const { to, subject, textBody, htmlBody } = body;
const validateEmailRequestBody = (body: MessageInput): void => {
const { to, deeplink } = body;

@@ -32,14 +26,6 @@ if (!to) {

if (!subject) {
throw new CustError(400, 'subject is required.');
if (!deeplink) {
throw new CustError(400, 'deeplink is required.');
}
if (!textBody && !htmlBody) {
throw new CustError(400, 'Either textBody or htmlBody is required.');
}
if (textBody && htmlBody) {
throw new CustError(400, 'Either textBody or htmlBody is required, not both.');
}
if (typeof to !== 'string') {

@@ -49,13 +35,9 @@ throw new CustError(400, 'Invalid to: expected string.');

if (typeof subject !== 'string') {
throw new CustError(400, 'Invalid subject: expected string.');
if (typeof deeplink !== 'string') {
throw new CustError(400, 'Invalid deeplink: expected string.');
}
if (textBody && (typeof textBody !== 'string')) {
throw new CustError(400, 'Invalid textBody: expected string.');
if (deeplink.split('presentationRequest/').length !== 2) {
throw new CustError(400, 'Invalid deeplink: expected to end in the format presentationRequest/<uuid>.');
}
if (htmlBody && (typeof htmlBody !== 'string')) {
throw new CustError(400, 'Invalid htmlBody: expected string.');
}
};

@@ -65,13 +47,12 @@

* Handler to send an email using UnumID's SaaS.
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param subject
* @param textBody
* @param htmlBody
* @param deeplink
*/
export const sendEmail = async (authorization: string, to: string, subject: string, textBody?: string, htmlBody?: string): Promise<UnumDto<undefined>> => {
export const sendEmail = async (authorization: string, to: string, deeplink: string): Promise<UnumDto<undefined>> => {
try {
requireAuth(authorization);
const body: EmailRequestBody = { to, subject, textBody, htmlBody };
const body: MessageInput = { to, deeplink };
validateEmailRequestBody(body);

@@ -78,0 +59,0 @@

@@ -1,3 +0,2 @@

import { Request, Response } from 'express';
import { ParamsDictionary } from 'express-serve-static-core';
import { MessageInput } from '@unumid/types';

@@ -11,7 +10,2 @@ import { configData } from '../config';

interface SmsRequestBody {
to: string;
msg: string;
}
export interface SmsResponseBody {

@@ -21,5 +15,2 @@ success: boolean;

type SendSmsRequest = Request<ParamsDictionary, SmsResponseBody, SmsRequestBody>;
type SendSmsResponse = Response<SmsResponseBody>;
/**

@@ -29,4 +20,4 @@ * Validates the SmsRequestBody attributes.

*/
const validateSmsRequestBody = (body: SmsRequestBody): void => {
const { to, msg } = body;
const validateSmsRequestBody = (body: MessageInput): void => {
const { to, deeplink } = body;

@@ -37,4 +28,4 @@ if (!to) {

if (!msg) {
throw new CustError(400, 'msg is required.');
if (!deeplink) {
throw new CustError(400, 'deeplink is required.');
}

@@ -46,5 +37,9 @@

if (typeof msg !== 'string') {
throw new CustError(400, 'Invalid msg: expected string.');
if (typeof deeplink !== 'string') {
throw new CustError(400, 'Invalid deeplink: expected string.');
}
if (deeplink.split('presentationRequest/').length !== 2) {
throw new CustError(400, 'Invalid deeplink: expected to end in the format presentationRequest/<uuid>.');
}
};

@@ -54,11 +49,10 @@

* Handler to send a SMS using UnumID's SaaS.
* Designed to be used to present a deeplink.
*
* Designed to be used with a deeplink which creates a templated message.
* @param authorization
* @param to
* @param msg
* @param deeplink
*/
export const sendSms = async (authorization: string, to: string, msg: string): Promise<UnumDto<undefined>> => {
export const sendSms = async (authorization: string, to: string, deeplink: string): Promise<UnumDto<undefined>> => {
try {
const body = { to, msg };
const body = { to, deeplink };

@@ -65,0 +59,0 @@ requireAuth(authorization);

@@ -10,10 +10,5 @@ import fetch from 'node-fetch';

const mockFetch = fetch as unknown as jest.Mock;
const makeApiCall = async <T = undefined>(
to: string,
subject: string,
textBody: string | undefined,
htmlBody: string | undefined,
auth: string
): Promise<UnumDto<T>> => {
return sendEmail(auth, to, subject, textBody, htmlBody);
const makeApiCall = async <T = undefined>(to: string, deeplink: string, auth: string): Promise<UnumDto<T>> => {
return sendEmail(auth, to, deeplink);
};

@@ -24,5 +19,3 @@

const to = 'test+to@unumid.org';
const subject = 'subject';
const textBody = 'message';
const htmlBody = '<div>message</div>';
const deeplink = 'acme://unumid/presentationRequest/89a96361-c46c-4657-a04b-ca2c624e0b94';

@@ -45,3 +38,3 @@ afterEach(() => {

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall(to, subject, textBody, undefined, auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -54,4 +47,4 @@ });

method: 'POST',
body: JSON.stringify({ to, subject, textBody }),
headers: { Authorization: auth, 'Content-Type': 'application/json' }
body: JSON.stringify({ to, deeplink }),
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '1.0.0' }
};

@@ -73,3 +66,3 @@

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall(to, subject, textBody, undefined, auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -86,3 +79,3 @@ expect(apiResponseAuthToken).toEqual(auth);

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall(to, subject, textBody, undefined, auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -97,3 +90,3 @@ expect(apiResponseAuthToken).toBe(undefined);

try {
await makeApiCall<ErrorResponseBody>('', subject, textBody, undefined, auth);
await makeApiCall<ErrorResponseBody>('', deeplink, auth);
fail();

@@ -107,28 +100,17 @@ } catch (e) {

it('returns a CustError with a descriptive error message if subject is missing', async () => {
it('returns a CustError with a descriptive error message if deeplink is missing', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, '', textBody, undefined, auth);
await makeApiCall<ErrorResponseBody>(to, '', auth);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'subject is required.'));
expect(e).toEqual(new CustError(400, 'deeplink is required.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('subject is required.');
expect(e.message).toEqual('deeplink is required.');
}
});
it('returns a CustError with a descriptive error message if both textBody and htmlBody are missing', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, subject, undefined, undefined, auth);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'Either textBody or htmlBody is required.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Either textBody or htmlBody is required.');
}
});
// Wrong type request params
it('returns a CustError with a descriptive error message if to is not a string', async () => {
try {
await makeApiCall<ErrorResponseBody>({} as string, subject, textBody, undefined, auth);
await makeApiCall<ErrorResponseBody>({} as string, deeplink, auth);
fail();

@@ -142,39 +124,28 @@ } catch (e) {

it('returns a CustError with a descriptive error message if subject is not a string', async () => {
it('returns a CustError with a descriptive error message if deeplink is not a string', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, {} as string, textBody, undefined, auth);
await makeApiCall<ErrorResponseBody>(to, {} as string, auth);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'Invalid subject: expected string.'));
expect(e).toEqual(new CustError(400, 'Invalid deeplink: expected string.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Invalid subject: expected string.');
expect(e.message).toEqual('Invalid deeplink: expected string.');
}
});
it('returns a CustError with a descriptive error message if textBody is present and not a string', async () => {
it('returns a CustError with a descriptive error message if deeplink is improper format', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, subject, {} as string, undefined, auth);
await makeApiCall<ErrorResponseBody>(to, 'deeplink', auth);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'Invalid textBody: expected string.'));
expect(e).toEqual(new CustError(400, 'Invalid deeplink: expected to end in the format presentationRequest/<uuid>.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Invalid textBody: expected string.');
expect(e.message).toEqual('Invalid deeplink: expected to end in the format presentationRequest/<uuid>.');
}
});
it('returns a CustError with a descriptive error message if htmlBody is present and not a string', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, subject, undefined, {} as string, auth);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'Invalid htmlBody: expected string.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Invalid htmlBody: expected string.');
}
});
// Missing auth header
it('returns a CustError with a descriptive error message if authorization is missing', async () => {
try {
await makeApiCall<ErrorResponseBody>(to, subject, textBody, undefined, null as string);
await makeApiCall<ErrorResponseBody>(to, deeplink, null as string);
fail();

@@ -181,0 +152,0 @@ } catch (e) {

@@ -10,4 +10,4 @@ import fetch from 'node-fetch';

const mockFetch = fetch as unknown as jest.Mock;
const makeApiCall = async <T = undefined> (to: string, msg: string, auth: string): Promise<UnumDto<T>> => {
return sendSms(auth, to, msg);
const makeApiCall = async <T = undefined> (to: string, deeplink: string, auth: string): Promise<UnumDto<T>> => {
return sendSms(auth, to, deeplink);
};

@@ -18,3 +18,3 @@

const to = '5555555555';
const msg = 'test msg';
const deeplink = 'acme://unumid/presentationRequest/89a96361-c46c-4657-a04b-ca2c624e0b94';

@@ -37,3 +37,3 @@ afterEach(() => {

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall('5555555555', 'test msg', auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -46,4 +46,4 @@ });

method: 'POST',
body: JSON.stringify({ to, msg }),
headers: { Authorization: auth, 'Content-Type': 'application/json' }
body: JSON.stringify({ to, deeplink }),
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '1.0.0' }
};

@@ -70,3 +70,3 @@

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall('5555555555', 'test msg', auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -83,3 +83,3 @@ expect(apiResponseAuthToken).toEqual(auth);

mockFetch.mockResolvedValueOnce(mockSaasApiResponse);
apiResponse = await makeApiCall('5555555555', 'test msg', auth);
apiResponse = await makeApiCall(to, deeplink, auth);
apiResponseAuthToken = apiResponse.authToken;

@@ -94,3 +94,3 @@ expect(apiResponseAuthToken).toBe(undefined);

try {
await makeApiCall<ErrorResponseBody>(undefined as string, msg, auth);
await makeApiCall<ErrorResponseBody>(undefined as string, deeplink, auth);
fail();

@@ -109,5 +109,5 @@ } catch (e) {

} catch (e) {
expect(e).toEqual(new CustError(400, 'msg is required.'));
expect(e).toEqual(new CustError(400, 'deeplink is required.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('msg is required.');
expect(e.message).toEqual('deeplink is required.');
}

@@ -119,3 +119,3 @@ });

try {
await makeApiCall<ErrorResponseBody>({} as string, msg, auth);
await makeApiCall<ErrorResponseBody>({} as string, deeplink, auth);
fail();

@@ -129,3 +129,3 @@ } catch (e) {

it('returns a CustError with a descriptive error message if msg is not a string', async () => {
it('returns a CustError with a descriptive error message if deeplink is not a string', async () => {
try {

@@ -135,5 +135,5 @@ await makeApiCall<ErrorResponseBody>(to, {} as string, auth);

} catch (e) {
expect(e).toEqual(new CustError(400, 'Invalid msg: expected string.'));
expect(e).toEqual(new CustError(400, 'Invalid deeplink: expected string.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Invalid msg: expected string.');
expect(e.message).toEqual('Invalid deeplink: expected string.');
}

@@ -145,3 +145,3 @@ });

try {
await makeApiCall<ErrorResponseBody>(to, msg, null as string);
await makeApiCall<ErrorResponseBody>(to, deeplink, null as string);
fail();

@@ -148,0 +148,0 @@ } catch (e) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc