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

update/transport-library #182

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Unreleased

# 0.21.0 - 2024-02-05

- Changing `BasePlugin` \_transport property from `request/request-promise` lib to `got`.
- Exporting an `MicsApiError` class based on `got` RequestError for mediarithmics basePlugin requests.
- Declaring a `TransportErrorHandler` class based on `got` RequestError to handle external requests.

# 0.20.0 - 2023-11-29

- Make `UserIdentifierInfo` an union type, which will help infering type based on `type`.
Expand Down
5 changes: 5 additions & 0 deletions examples/activity-analyzer/src/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-argument */

import 'mocha';

import { core, helpers } from '@mediarithmics/plugins-nodejs-sdk';

import { MyActivityAnalyzerPlugin } from '../MyPluginImpl';

const PLUGIN_AUTHENTICATION_TOKEN = 'Manny';
Expand Down
2 changes: 1 addition & 1 deletion examples/bid-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@mediarithmics/plugins-nodejs-sdk": "^0.17.0"
"@mediarithmics/plugins-nodejs-sdk": "^0.20.0"
},
"devDependencies": {
"@types/chai": "^4.3.10",
Expand Down
2 changes: 2 additions & 0 deletions examples/bid-optimizer/src/MyPluginImpl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { core } from '@mediarithmics/plugins-nodejs-sdk';

export class MyBidOptimizerPlugin extends core.BidOptimizerPlugin {
Expand Down
33 changes: 11 additions & 22 deletions examples/bid-optimizer/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Test Example BidOptimizer', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/bid_optimizers\/(.){1,10}/) !== null;
}),
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Test Example BidOptimizer', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/bid_optimizers\/(.){1,10}\/properties/) !== null;
}),
Expand Down Expand Up @@ -160,30 +160,19 @@ describe('Test Example BidOptimizer', function () {
]
}`);

it('Check behavior of dummy bid optimizer', function (done) {
it('Check behavior of dummy bid optimizer', async function () {
// All the magic is here
const plugin = new MyBidOptimizerPlugin(false);
const runner = new core.TestingPluginRunner(plugin, rpMockup);

// Plugin log level to debug
request(runner.plugin.app)
.put('/v1/log_level')
.send({ level: 'debug' })
.end((err, res) => {
expect(res.status).to.equal(200);

// Activity to process
request(runner.plugin.app)
.post('/v1/bid_decisions')
.send(bidDecisionRequest)
.end((err, res) => {
expect(res.status).to.eq(200);

expect((JSON.parse(res.text) as core.BidOptimizerPluginResponse).bids[0].bid_price).to.be.eq(
bidDecisionRequest.campaign_info.max_bid_price,
);
done();
});
});
const res1 = await request(runner.plugin.app).put('/v1/log_level').send({ level: 'debug' });
expect(res1.status).to.equal(200);

const res2 = await request(runner.plugin.app).post('/v1/bid_decisions').send(bidDecisionRequest);
expect(res2.status).to.eq(200);
expect((JSON.parse(res2.text) as core.BidOptimizerPluginResponse).bids[0].bid_price).to.be.eq(
bidDecisionRequest.campaign_info.max_bid_price,
);
});
});
2 changes: 1 addition & 1 deletion examples/custom-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@mediarithmics/plugins-nodejs-sdk": "^0.17.0"
"@mediarithmics/plugins-nodejs-sdk": "^0.20.0"
},
"devDependencies": {
"@types/chai": "^4.3.10",
Expand Down
30 changes: 12 additions & 18 deletions examples/custom-action/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ const PLUGIN_WORKER_ID = 'Calavera';
process.env.PLUGIN_AUTHENTICATION_TOKEN = PLUGIN_AUTHENTICATION_TOKEN;
process.env.PLUGIN_WORKER_ID = PLUGIN_WORKER_ID;

describe.only('Test Custom Action example', function () {
describe('Test Custom Action example', function () {
// All the magic is here
const plugin = new MyCustomActionPlugin(false);
let runner: core.TestingPluginRunner;

it('Check the behavior of a dummy custom action', function (done) {
after(() => {
// We clear the cache so that we don't have any processing still running in the background
runner.plugin.pluginCache.clear();
});

it('Check the behavior of a dummy custom action', async function () {
const rpMockup: sinon.SinonStub = sinon.stub();

const customAction: core.DataResponse<core.CustomAction> = {
Expand All @@ -40,7 +45,7 @@ describe.only('Test Custom Action example', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/scenario_custom_actions\/(.){1,10}$/) !== null;
}),
Expand Down Expand Up @@ -68,7 +73,7 @@ describe.only('Test Custom Action example', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/scenario_custom_actions\/(.){1,10}\/properties/) !== null;
}),
Expand All @@ -86,19 +91,8 @@ describe.only('Test Custom Action example', function () {
scenario_id: '',
};

request(runner.plugin.app)
.post('/v1/scenario_custom_actions')
.send(customActionRequest)
.end(function (err, res) {
expect(res.status).to.equal(200);
expect(JSON.parse(res.text).status).to.be.eq('ok');

done();
});
});

afterEach(() => {
// We clear the cache so that we don't have any processing still running in the background
runner.plugin.pluginCache.clear();
const res = await request(runner.plugin.app).post('/v1/scenario_custom_actions').send(customActionRequest);
expect(res.status).to.equal(200);
expect(JSON.parse(res.text).status).to.be.eq('ok');
});
});
2 changes: 1 addition & 1 deletion examples/email-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@mediarithmics/plugins-nodejs-sdk": "^0.17.0",
"@mediarithmics/plugins-nodejs-sdk": "^0.20.0",
"mocha": "^10.2.0"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions examples/email-renderer/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ const PLUGIN_WORKER_ID = 'Calavera';
process.env.PLUGIN_AUTHENTICATION_TOKEN = PLUGIN_AUTHENTICATION_TOKEN;
process.env.PLUGIN_WORKER_ID = PLUGIN_WORKER_ID;

describe.only('Test Email Renderer example', function () {
describe('Test Email Renderer example', function () {
const plugin = new ExampleEmailRenderer(false);
let runner: core.TestingPluginRunner;

after(() => {
// We clear the cache so that we don't have any processing still running in the background
runner.plugin.pluginCache.clear();
});

it('Check the behavior of a dummy email renderer', async () => {
const rpMockup: sinon.SinonStub = sinon.stub();

Expand Down Expand Up @@ -51,7 +56,7 @@ describe.only('Test Email Renderer example', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/creatives\/(.){1,10}\/renderer_properties/) !== null;
}),
Expand Down Expand Up @@ -85,9 +90,4 @@ describe.only('Test Email Renderer example', function () {

request(runner.plugin.app).post('/v1/email_contents').send(emailRenderRequest).expect(200);
});

afterEach(() => {
// We clear the cache so that we don't have any processing still running in the background
runner.plugin.pluginCache.clear();
});
});
2 changes: 1 addition & 1 deletion examples/email_router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@mediarithmics/plugins-nodejs-sdk": "^0.17.0",
"@mediarithmics/plugins-nodejs-sdk": "^0.20.0",
"@types/express": "^4.17.21",
"express": "^4.18.2",
"mocha": "^10.2.0",
Expand Down
12 changes: 6 additions & 6 deletions examples/email_router/src/MyPluginImpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as express from 'express';
import * as rp from 'request-promise-native';
import * as retry from 'retry';
import * as express from 'express';

import { core } from '@mediarithmics/plugins-nodejs-sdk';

Expand Down Expand Up @@ -107,11 +107,11 @@ export class MySimpleEmailRouter extends core.EmailRouterPlugin {
'Mj-campaign': request.campaign_id,
};

const mailjetResponse: MailjetSentResponse = await this.requestGatewayHelper(
'POST',
`${this.outboundPlatformUrl}/v1/external_services/technical_name=mailjet/call`,
emailData,
);
const mailjetResponse: MailjetSentResponse = await this.requestGatewayHelper({
method: 'POST',
url: `${this.outboundPlatformUrl}/v1/external_services/technical_name=mailjet/call`,
body: emailData,
});

if (mailjetResponse.Sent.length === 0) {
this.logger.error('Mailjet sent an empty response, will retry');
Expand Down
52 changes: 15 additions & 37 deletions examples/email_router/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Test Example Email Router', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/email_routers\/(.){1,10}\/properties/) !== null;
}),
Expand All @@ -52,7 +52,7 @@ describe('Test Example Email Router', function () {
return rpMockup;
}

it('Check behavior of dummy Email Router', function (done) {
it('Check behavior of dummy Email Router', async function () {
// All the magic is here
const plugin = new MySimpleEmailRouter(false);
const rpMockup = buildRpMockup();
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('Test Example Email Router', function () {
rpMockup
.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/external_services\/technical_name=(.){1,20}\/call/) !== null;
}),
Expand All @@ -139,26 +139,15 @@ describe('Test Example Email Router', function () {
.returns(mjResponse);

// Plugin log level to debug
request(runner.plugin.app)
.put('/v1/log_level')
.send({ level: 'debug' })
.end((err, res) => {
expect(res.status).to.equal(200);
const res1 = await request(runner.plugin.app).put('/v1/log_level').send({ level: 'debug' });
expect(res1.status).to.equal(200);

// Activity to process
request(runner.plugin.app)
.post('/v1/email_routing')
.send(emailRoutingRequest)
.end((err, res) => {
expect(res.status).to.eq(200);

expect((JSON.parse(res.text) as core.EmailRoutingPluginResponse).result).to.be.true;
done();
});
});
const res2 = await request(runner.plugin.app).post('/v1/email_routing').send(emailRoutingRequest);
expect(res2.status).to.eq(200);
expect((JSON.parse(res2.text) as core.EmailRoutingPluginResponse).result).to.be.true;
});

it('Check the Email Routeur retry', function (done) {
it('Check the Email Routeur retry', async function () {
this.timeout(50000);

// All the magic is here
Expand Down Expand Up @@ -237,7 +226,7 @@ describe('Test Example Email Router', function () {

const mjMock = rpMockup.withArgs(
sinon.match.has(
'uri',
'url',
sinon.match(function (value: string) {
return value.match(/\/v1\/external_services\/technical_name=(.){1,20}\/call/) !== null;
}),
Expand All @@ -251,22 +240,11 @@ describe('Test Example Email Router', function () {
mjMock.onCall(3).returns(mjResponse);

// Plugin log level to debug
request(runner.plugin.app)
.put('/v1/log_level')
.send({ level: 'debug' })
.end((err, res) => {
expect(res.status).to.equal(200);

// Activity to process
request(runner.plugin.app)
.post('/v1/email_routing')
.send(emailRoutingRequest)
.end((err, res) => {
expect(res.status).to.eq(200);
const res1 = await request(runner.plugin.app).put('/v1/log_level').send({ level: 'debug' });
expect(res1.status).to.equal(200);

expect((JSON.parse(res.text) as core.EmailRoutingPluginResponse).result).to.be.true;
done();
});
});
const res2 = await request(runner.plugin.app).post('/v1/email_routing').send(emailRoutingRequest);
expect(res2.status).to.eq(200);
expect((JSON.parse(res2.text) as core.EmailRoutingPluginResponse).result).to.be.true;
});
});
2 changes: 1 addition & 1 deletion examples/handlebars-ad-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@mediarithmics/plugins-nodejs-sdk": "^0.17.0"
"@mediarithmics/plugins-nodejs-sdk": "^0.20.0"
},
"devDependencies": {
"@types/chai": "^4.3.10",
Expand Down
Loading