Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynect

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynect

Dynect API connector for node.js

  • 0.1.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Dynect API connector for node.js.

the node.js Dynect module provides a simple interface for making synchronous (by design and specification) calls to the Dynect API.

although API calls are synchronous, this is facilitated using an asynchronous queue so calls are still non-blocking.

it is a work in progress and further functionality and examples will be provided soon.

contributions are welcome of course.

example 1 :

add A record www.example.com (address '123.45.67.89')

	var Dynect = require('dynect');

	// open Dynect API session
	var dynect = new Dynect('customername', 'username', 'password');

	dynect.on('connected', function () {
		var zone = 'example.com';

		// add A record with 5 min TTL
		dynect.addRecord('A', zone, 'www.example.com', {
			address: '123.45.67.89'
		}, 300, function (addResponse) {
			console.log(addResponse);
		});

		//publish zone
		dynect.publishZone(zone, function (publishResponse) {
			console.log(publishResponse);
		});

		// close Dynect API session
		dynect.disconnect();
	});

	dynect.connect();

example 2 :

add CNAME record www.example.com (cname 'example.mydomain.com')

	var Dynect = require('dynect');

	// open Dynect API session and send keepalive every 5mins
	var dynect = new Dynect('customername', 'username', 'password', 300000);

	dynect.on('connected', function () {
		var zone = 'example.com';

		// add CNAME record with default TTL
		dynect.addRecord('CNAME', zone, 'www.example.com', {
			cname: 'example.mydomain.com'
		}, 0, function (addResponse) {
			console.log(addResponse);
		});

		// publish zone
		dynect.publishZone(zone, function (publishResponse) {
			console.log(publishResponse);
		});

		// do not disconnect because session is kept alive
	});

	dynect.connect();

example 3 (advanced) :

get all SRV records for '_sip._tcp.example.com' and remove any record with matching target 'voip.mydomain.com'

	var Dynect = require('dynect');

	// open Dynect API session
	var dynect = new Dynect('customername', 'username', 'password');
	var zone = 'example.com';
	var fqdn = '_sip._tcp.example.com';
	var srvTarget = 'voip.mydomain.com';
	var ports = [5060, 5070];

	dynect.on('connected', function () {
		addSrvRecords(zone, fqdn, srvTarget, ports, function () {
			dynect.publishZone(zone, function () {
				if (callback) {
					callback();
				}
			});

			// close Dynect API session
			dynect.disconnect();
		});
	})

	dynect.connect();
	
	function addSrvRecords(zone, fqdn, srvTarget, ports, callback) {
		dynect.getRecordSet('SRV', zone, fqdn, function (response) {
			if (ports !== null && response.status === 'failure' && response.msgs[0].ERR_CD === 'NOT_FOUND') {
				// SRV records not found

				//{ status: 'failure',
				//	data: {},
				//	job_id: 187775860,
				//	msgs:
				//	[ { INFO: 'node: Not in zone',
				//		SOURCE: 'BLL',
				//		ERR_CD: 'NOT_FOUND',
				//		LVL: 'ERROR' },
				//	  { INFO: 'detail: Host is not in this zone',
				//	  	SOURCE: 'BLL',
				//	  	ERR_CD: null,
				//	  	LVL: 'INFO' } ] }

				newSrvRecords(zone, fqdn, srvTarget, ports, callback);
			}
			else {			
				// SRV records found

				for (var i = 0; i < response.data.length; i++) {
					var uri = response.data[i];
					var parts = uri.split('/');
					var recordId = parts[parts.length - 1];

					dynect.getRecord('SRV', zone, fqdn, recordId, function (response) {
						if (response.data.rdata.target === srvTarget + '.') {
							// SRV record for target exists so remove

							dynect.removeRecord('SRV', zone, fqdn, recordId);
						}
					});
				}

				if (ports !== null) {
					newSrvRecords(zone, fqdn, srvTarget, ports, callback);
				}
				else {
					callback();
				}
			}
		});
	}

	function newSrvRecords(zone, fqdn, srvTarget, ports, callback) {
		// add a new SRV record for each port

		for (var i = 0; i < ports.length; i++) {
			dynect.addRecord('SRV', zone, fqdn, {
				port: ports[i],
				priority: 10,
				target: srvTarget,
				weight: 1
			}, 60);
		}

		callback();
	}

installation

  npm install dynect

enjoy

the frisB.com team :)

Keywords

FAQs

Package last updated on 01 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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