oauth3.js/oauth3.domains.js

147 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-02-28 01:19:01 +00:00
;(function (exports) {
'use strict';
var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3;
OAUTH3.api['domains.checkAvailability'] = function (providerUri, opts) {
var session = opts.session;
var sld = opts.sld;
var tld = opts.tld;
return OAUTH3.request({
method: 'GET'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/check-availability/' + sld + '/' + tld
, session: session
}).then(function (res) {
return res;
});
};
2017-04-12 23:47:01 +00:00
OAUTH3.api['domains.purchase'] = function (providerUri, opts) {
var session = opts.session;
return OAUTH3.request({
method: 'POST'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/registrations'
, session: session
, data: opts.data
}).then(function (res) {
return res;
});
};
2017-02-28 01:19:01 +00:00
OAUTH3.api['domains.list'] = function (providerUri, opts) {
var session = opts.session;
return OAUTH3.request({
method: 'GET'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/registrations'
, session: session
}).then(function (res) {
2017-02-28 21:55:04 +00:00
return res.data.registrations || res.data.domains || res.data;
2017-02-28 01:19:01 +00:00
});
};
2017-06-20 22:24:13 +00:00
/* TODO: Manual Renew Function
OAUTH3.api['domains.extend'] = function (providerUri, opts) {
var session = opts.session;
return OAUTH3.request({
method: 'POST'
, url: OAUTH3.url.normalize(providerUri)
2017-06-23 21:01:19 +00:00
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/registrations/' + opts.tld + '/' + opts.sld + '/extend'
2017-06-20 22:24:13 +00:00
, session: session
, data: opts.data
}).then(function (res) {
return res;
});
};
*/
2017-04-06 21:14:17 +00:00
OAUTH3.api['ns.list'] = function (providerUri, opts) {
var session = opts.session;
var domain = opts.domain;
2017-04-06 21:14:17 +00:00
var nameArr = domain.split('.');
var reverseNameArr = nameArr.reverse();
var nameSubArr = reverseNameArr.slice(3);
var tld;
var sld;
var sub;
if (reverseNameArr[0] === 'me' && reverseNameArr[1] === 'daplie') {
tld = 'daplie.me';
sld = reverseNameArr[2];
sub = nameSubArr.reverse().join('.') || '';
} else {
tld = nameArr[0];
sld = nameArr[1];
sub = reverseNameArr.slice(2).reverse().join('.') || '';
}
return OAUTH3.request({
method: 'GET'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/ns/'
+ tld + '/' + sld + '/' + sub
, session: session
}).then(function (res) {
return res.data;
});
};
OAUTH3.api['ns.add'] = function (providerUri, opts) {
2017-06-21 22:52:30 +00:00
var session = opts.session;
var server = opts.server;
var tld = opts.tld;
var sld = opts.sld;
var sub = opts.sub;
return OAUTH3.request({
method: 'POST'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/ns/'
+ tld + '/' + sld + '/' + sub
, session: session
, data: { nameservers: [server] }
}).then(function (res) {
return res;
});
};
2017-04-06 21:14:17 +00:00
OAUTH3.api['glue.list'] = function (providerUri, opts) {
var session = opts.session;
return OAUTH3.request({
method: 'GET'
, url: OAUTH3.url.normalize(providerUri)
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/glue'
, session: session
}).then(function (res) {
return res.data;
});
};
OAUTH3.api['glue.add'] = function (providerUri, opts) {
var session = opts.session;
2017-04-07 16:09:29 +00:00
var ip = opts.ip;
2017-04-06 21:14:17 +00:00
var tld = opts.tld;
var sld = opts.sld;
var sub = (opts.sub || '@');
2017-04-06 21:14:17 +00:00
return OAUTH3.request({
method: 'POST'
, url: OAUTH3.url.normalize(providerUri)
2017-04-07 16:09:29 +00:00
+ '/api/com.daplie.domains/accounts/' + session.token.sub + '/glue/'
2017-04-06 21:14:17 +00:00
+ tld + '/' + sld + '/' + sub
, session: session
2017-04-07 16:09:29 +00:00
, data: { ip: ip }
2017-04-06 21:14:17 +00:00
}, {}).then(function (res) {
return res;
2017-04-06 21:14:17 +00:00
});
};
2017-02-28 01:19:01 +00:00
}('undefined' !== typeof exports ? exports : window));