feat(5g-api): Introduce 5G api

This commit is contained in:
Faruk AYDIN
2023-09-21 10:25:01 +02:00
parent 7a632c2ab9
commit 8f72c8c8fa
8 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import defineAction from '../../../../helpers/define-action';
export default defineAction({
name: 'Get Device Location',
key: 'getDeviceLocation',
description: 'Get the location of the device.',
arguments: [
{
label: 'MSISDN',
key: 'msisdn',
type: 'string' as const,
required: true,
description:
'Subscriber number in E.164 format (starting with country code). Optionally prefixed with ' +
'.',
variables: true,
},
{
label: 'Latitude',
key: 'latitude',
type: 'string' as const,
required: true,
description: 'Latitude component of location',
variables: true,
},
{
label: 'Longitude',
key: 'longitude',
type: 'string' as const,
required: true,
description: 'Longitude component of location',
variables: true,
},
{
label: 'Accuracy',
key: 'accuracy',
type: 'string' as const,
required: true,
description: 'Accuracy expected for location verification in km',
variables: true,
},
],
async run($) {
const payload = {
ueId: {
msisdn: $.step.parameters.msisdn,
},
latitude: $.step.parameters.latitude,
longitude: $.step.parameters.longitude,
accuracy: $.step.parameters.accuracy,
};
const response = await $.http.post(
'https://api-eu.vonage.com/camara/location/v0/verify',
payload
);
$.setActionItem({ raw: response.data });
},
});

View File

@@ -0,0 +1,3 @@
import getDeviceLocation from './get-device-location';
export default [getDeviceLocation];

View File

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 38" part="logo-svg" fill="#e20074" role="img" aria-labelledby="logo-title-2">
<path d="M7.6 25.1H0v-7.6h7.6v7.6ZM0 0v12.9h2.3v-.4c0-6.1 3.4-9.9 9.9-9.9h.4V30c0 3.8-1.5 5.3-5.3 5.3H6.1V38h19.8v-2.7h-1.1c-3.8 0-5.3-1.5-5.3-5.3V2.7h.4c6.5 0 9.9 3.8 9.9 9.9v.4h2.3V0H0Zm24.3 25.1h7.6v-7.6h-7.6v7.6Z">
</path>
</svg>

After

Width:  |  Height:  |  Size: 372 B

View File

@@ -0,0 +1,45 @@
import verifyCredentials from './verify-credentials';
// import isStillVerified from './is-still-verified';
// import refreshToken from './refresh-token';
export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'privateKey',
label: 'Private Key',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Private Key of your High Mobility OAuth app.',
clickToCopy: false,
},
{
key: 'applicationId',
label: 'Application ID',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'App ID of your High Mobility OAuth app.',
clickToCopy: false,
},
],
verifyCredentials,
// isStillVerified,
// refreshToken,
};

View File

@@ -0,0 +1,39 @@
import { IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
import jwt from 'jsonwebtoken';
import { v4 as uuidv4 } from 'uuid';
const verifyCredentials = async ($: IGlobalVariable) => {
const claims = {
application_id: $.auth.data.applicationId as string,
iat: Math.floor(new Date().getTime() / 1000),
exp: Math.floor(new Date().getTime() / 1000) + 24 * 60 * 60,
jti: uuidv4(),
};
const privateKey = ($.auth.data.privateKey as string).replaceAll('\\n', '\n');
const jwtToken = jwt.sign(claims, privateKey, {
algorithm: 'RS256',
});
const headers = {
Authorization: 'Bearer ' + jwtToken,
};
const response = await $.http.post(
'https://api.nexmo.com/oauth2/token?grant_type=client_credentials',
null,
{ headers }
);
const responseData = Object.fromEntries(new URLSearchParams(response.data));
await $.auth.set({
accessToken: responseData.access_token,
tokenType: responseData.token_type,
expiresIn: responseData.expires_in,
});
};
export default verifyCredentials;

View File

View File

@@ -0,0 +1,18 @@
import defineApp from '../../helpers/define-app';
// import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import actions from './actions';
export default defineApp({
name: '5G API',
key: '5g-api',
iconUrl: '{BASE_URL}/apps/5g-api/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/5g-api/connection',
supportsConnections: true,
baseUrl: 'https://developer.telekom.de',
apiBaseUrl: 'https://api.developer.telekom.de',
primaryColor: 'e20074',
// beforeRequest: [addAuthHeader],
auth,
actions,
});

View File