From 618bc181d0a7e5fe9dfe1d54bc4be14f9b9ac9e0 Mon Sep 17 00:00:00 2001 From: mohsin-plivo Date: Thu, 12 Jan 2023 13:10:44 +0530 Subject: [PATCH 1/4] SMS-5025 Add requester_ip to GetMDR and ListMDR apis --- lib/resources/messages.js | 2 ++ lib/rest/request-test.js | 12 ++++++++---- test/messages.js | 15 +++++++++++++++ types/resources/messages.d.ts | 6 ++++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/resources/messages.js b/lib/resources/messages.js index a6f2c0d1..faad75cb 100644 --- a/lib/resources/messages.js +++ b/lib/resources/messages.js @@ -45,6 +45,7 @@ export class MessageGetResponse { this.totalRate = params.totalRate; this.units = params.units; this.powerpackID = params.powerpackId; + this.requesterIP = params.requesterIp; } } @@ -64,6 +65,7 @@ export class MessageListResponse { this.totalRate = params.totalRate; this.units = params.units; this.powerpackID = params.powerpackId; + this.requesterIP = params.requesterIp; } } diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index aff4f803..bd61c565 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -1695,7 +1695,8 @@ export function Request(config) { to_number: '19352326448', total_amount: '0.00000', total_rate: '0.00350', - units: 1 + units: 1, + requester_ip: "192.168.1.1" } }); } @@ -1936,7 +1937,8 @@ export function Request(config) { to_number: '19352326448', total_amount: '0.00000', total_rate: '0.00350', - units: 1 + units: 1, + requester_ip: '192.168.1.2' } }); } @@ -1964,7 +1966,8 @@ export function Request(config) { to_number: '19352326448', total_amount: '0.00000', total_rate: '0.00350', - units: 1 + units: 1, + requester_ip: "192.168.1.1" }, { error_code: '200', @@ -1978,7 +1981,8 @@ export function Request(config) { to_number: '19352326448', total_amount: '0.00000', total_rate: '0.00350', - units: 1 + units: 1, + requester_ip: "192.168.1.2" } ] } diff --git a/test/messages.js b/test/messages.js index cd10a364..52007a0c 100644 --- a/test/messages.js +++ b/test/messages.js @@ -17,6 +17,13 @@ describe('message', function () { }) }); + it('should get requester_ip', function () { + return client.messages.get(1) + .then(function (message) { + assert.equal(message.requesterIP, "192.168.1.2") + }) + }); + it('list messages', function () { return client.messages.list() .then(function (messages) { @@ -24,6 +31,14 @@ describe('message', function () { }) }); + it('should have requester_ip in listed messages', function () { + return client.messages.list() + .then(function (messages) { + assert.equal(messages[0].requesterIP, "192.168.1.1") + assert.equal(messages[1].requesterIP, "192.168.1.2") + }) + }); + it('should create message via interface', function () { return client.messages.create({src:'src', dst:'dst', text:'text',powerpackUUID: null}) .then(function (message) { diff --git a/types/resources/messages.d.ts b/types/resources/messages.d.ts index 7537e709..8910dc28 100644 --- a/types/resources/messages.d.ts +++ b/types/resources/messages.d.ts @@ -21,10 +21,11 @@ export class MessageGetResponse { totalRate: string; units: string; powerpackId: string; + requesterIp: string; } export class MessageListResponse { constructor(params: object); - errorCode: string; + errorCode: string; fromNumber: string; messageDirection: string; messageState: string; @@ -35,8 +36,9 @@ export class MessageListResponse { toNumber: string; totalAmount: string; totalRate: string; - units: string; + units: string; powerpackId: string; + requesterIp: string; } export class MMSMediaResponse { constructor(params: object); From 8b616c41ffa37e1b1b66731c3777754fb8513842 Mon Sep 17 00:00:00 2001 From: mohsin-plivo Date: Thu, 12 Jan 2023 15:03:29 +0530 Subject: [PATCH 2/4] Dockerisation for local development --- Dockerfile | 20 ++++++++++++++++++++ Makefile | 7 +++++++ docker-compose.yml | 18 ++++++++++++++++++ setup_sdk.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml create mode 100755 setup_sdk.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d938868b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:18.04 + +WORKDIR /usr/src/app +RUN apt-get update && apt-get install -y wget git vim + +# Install node using nvm +RUN mkdir -p /usr/src/.nvm +ENV NVM_DIR /usr/src/.nvm +RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | sh +ENV NODE_VERSION v14.0.0 +RUN /bin/sh -c ". $NVM_DIR/nvm.sh && nvm install $NODE_VERSION" + +ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules +ENV PATH $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH + +# Copy setup script +COPY setup_sdk.sh /usr/src/app/ +RUN chmod a+x /usr/src/app/setup_sdk.sh + +ENTRYPOINT [ "/usr/src/app/setup_sdk.sh" ] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..9fe8b1a2 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: build test + +build: + docker-compose up --build --remove-orphans + +test: + docker exec -it $$CONTAINER /bin/bash -c "npm install request --no-save && npm test" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..43a573bc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3' + +services: + + nodeSDK: + build: + context: . + image: nodesdk + container_name: nodeSDK + environment: + - PLIVO_AUTH_ID=${PLIVO_AUTH_ID} + - PLIVO_AUTH_TOKEN=${PLIVO_AUTH_TOKEN} + - PLIVO_API_DEV_HOST=${PLIVO_API_DEV_HOST} + - PLIVO_API_PROD_HOST=${PLIVO_API_PROD_HOST} + volumes: + - .:/usr/src/app + stdin_open: true + tty: true \ No newline at end of file diff --git a/setup_sdk.sh b/setup_sdk.sh new file mode 100755 index 00000000..2c1a2fcd --- /dev/null +++ b/setup_sdk.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +testDir="node-sdk-test" +GREEN="\033[0;32m" +NC="\033[0m" + +cd /usr/src/app + +echo "Setting plivo-api endpoint to dev..." +find /usr/src/app/lib/rest -type f -exec sed -i "s/$PLIVO_API_PROD_HOST/$PLIVO_API_DEV_HOST/g" {} \; + +echo "Packaging SDK..." +echo "npm install" && npm install +echo "npm run prepublish" && npm run prepublish +echo "npm pack | tail -n 1" && package=$( npm pack | tail -n 1 ) + +if [ ! -d $testDir ]; then + echo "Creating test dir..." + mkdir -p $testDir +fi + +if [ ! -f $testDir/test.js ]; then + echo "Creating test file..." + echo -e "let plivo = require('plivo')\n" > $testDir/test.js + echo -e "\nlet client = new plivo.Client(process.env.PLIVO_AUTH_ID, process.env.PLIVO_AUTH_TOKEN);" >> $testDir/test.js +fi + +echo "Installing dependencies for testing..." +mv $package $testDir +cd $testDir +rm -rf package*.json node_modules +npm init -y +npm install $package +rm $package + +echo -e "\n\nSDK setup complete!" +echo "To test your changes:" +echo -e "\t1. Add your test code in /$testDir/test.js on host (or /usr/src/app/$testDir/test.js in the container)" +echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC" +echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC" +echo -e "\t4. Run your test file: $GREEN node test.js$NC" +echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC" + +/bin/bash \ No newline at end of file From a5f3e4c250a2d2569972df3b168ad3b2b81ffd0e Mon Sep 17 00:00:00 2001 From: mohsin-plivo Date: Thu, 12 Jan 2023 16:05:15 +0530 Subject: [PATCH 3/4] Updated README --- .gitignore | 1 + README.md | 20 ++++++++++++++++++++ setup_sdk.sh | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/.gitignore b/.gitignore index 385e5082..d5b974df 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ docs/ node_modules coverage dist +node-sdk-test/ diff --git a/README.md b/README.md index ea53c392..18ee628e 100644 --- a/README.md +++ b/README.md @@ -129,3 +129,23 @@ More examples are available [here](https://github.com/plivo/plivo-examples-node) ## Reporting issues Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues). + +## Local Development +> Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running. +1. Export the following environment variables in your host machine: +```bash +export PLIVO_AUTH_ID= +export PLIVO_AUTH_TOKEN= +export PLIVO_API_DEV_HOST= +export PLIVO_API_PROD_HOST= +``` +2. Run `make build`. This will create a docker container in which the sdk will be setup and dependencies will be installed. +> The entrypoint of the docker container will be the `setup_sdk.sh` script. The script will handle all the necessary changes required for local development. It will also package the sdk and reinstall it as a dependecy for the test program. +3. The above command will print the docker container id (and instructions to connect to it) to stdout. +4. The testing code can be added to `/node-sdk-test/test.js` in host + (or `/usr/src/app/node-sdk-test/test.js` in container) +5. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container. However, when any change is made, the dependencies for the test program need to be re-installed. To do that: + * Either restart the docker container + * Or Run the `setup_sdk.sh` script +6. To run unit tests, run `make test CONTAINER=` in host, where `` is the docker container id created in 2. +(The docker container should be running) \ No newline at end of file diff --git a/setup_sdk.sh b/setup_sdk.sh index 2c1a2fcd..a1dd08d7 100755 --- a/setup_sdk.sh +++ b/setup_sdk.sh @@ -1,9 +1,15 @@ #!/bin/bash +set -e testDir="node-sdk-test" GREEN="\033[0;32m" NC="\033[0m" +if [ ! $PLIVO_API_PROD_HOST ] || [ ! $PLIVO_API_DEV_HOST ] || [ ! $PLIVO_AUTH_ID ] || [ ! $PLIVO_AUTH_TOKEN ]; then + echo "Environment variables not properly set! Please refer to Local Development section in README!" + exit 126 +fi + cd /usr/src/app echo "Setting plivo-api endpoint to dev..." @@ -41,4 +47,5 @@ echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC echo -e "\t4. Run your test file: $GREEN node test.js$NC" echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC" +# To keep the container running post setup /bin/bash \ No newline at end of file From 1b6cda12666b5ad4bf240d687ae2c6e2dfc35c1c Mon Sep 17 00:00:00 2001 From: mohsin-plivo Date: Wed, 25 Jan 2023 12:30:15 +0530 Subject: [PATCH 4/4] Bump Version and create message bug fix --- CHANGELOG.md | 5 +++++ lib/resources/messages.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d514db86..09abdfdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Change Log + +## [4.39.0](https://github.com/plivo/plivo-node/tree/v4.39.0) (2022-01-25) +**Feature - Added New Param(requesterIP) in Get Message and List Mssage APIs** +- Add `requesterIP` to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message) + ## [v4.38.0](https://github.com/plivo/plivo-node/tree/v4.38.0) (2023-01-18) **Feature - Added New Param(Message Expiry) in Send Message API** - Added new param(Message Expiry) in Send Message API diff --git a/lib/resources/messages.js b/lib/resources/messages.js index faad75cb..b38c037d 100644 --- a/lib/resources/messages.js +++ b/lib/resources/messages.js @@ -195,8 +195,8 @@ export class MessageInterface extends PlivoResourceInterface { var media_ids = src.media_ids; var log = src.log; var trackable = src.trackable; + var messageExpiry = src.messageExpiry; var src = src.src; - var messageExpiry = src.messageExpiry } let errors = validate([{ diff --git a/package.json b/package.json index fefebc85..384ba559 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.38.0", + "version": "4.39.0", "description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML", "homepage": "https://github.com/plivo/plivo-node", "files": [