This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Tenant.js
169 lines (151 loc) · 5.59 KB
/
Tenant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict';
var _ = require('underscore');
var InstanceResource = require('./InstanceResource');
var utils = require('../utils');
/**
* @class Tenant
*
* @description
*
* Encapsulates a Stormpath Tenant resource, which is the root node of all the
* resources for a given tenant. For full documentation of this resource,
* please see
* [REST API Reference: Tenant](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#tenant).
*
* This class should not be manually constructed. It should be obtained from one
* of these methods:
*
* - {@link Client#getCurrentTenant Client.getCurrentTenant()}
*
* @param {Object} tenantResource
*
* The JSON representation of this resource, retrieved the Stormpath REST API.
*
*/
function Tenant() {
Tenant.super_.apply(this, arguments);
}
utils.inherits(Tenant, InstanceResource);
/**
* Not documented as this is proxied by client.getAccounts()
*
* @private
*/
Tenant.prototype.getAccounts = function getTenantAccounts(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.accounts.href, args.options, require('./Account'), args.callback);
};
/**
* Not documented as this is proxied by client.getTenantGroups()
*
* @private
*/
Tenant.prototype.getGroups = function getTenantGroups(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.groups.href, args.options, require('./Group'), args.callback);
};
/**
* Not documented as this is proxied by client.getApplications()
*
* @private
*/
Tenant.prototype.getApplications = function getTenantApplications(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.applications.href, args.options, require('./Application'), args.callback);
};
/**
* Not documented as this is proxied by client.getOrganizations()
*
* @private
*/
Tenant.prototype.getOrganizations = function getTenantOrganizations(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.organizations.href, args.options, require('./Organization'), args.callback);
};
/**
* Not documented as this is proxied by client.createApplication()
*
* @private
*/
Tenant.prototype.createApplication = function createTenantApplication(/* app, [options,] callback */) {
var args = utils.resolveArgs(arguments, ['app', 'options', 'callback']);
this.dataStore.createResource('/applications', args.options, args.app, require('./Application'), args.callback);
};
/**
* Not documented as this is proxied by client.createOrganization()
*
* @private
*/
Tenant.prototype.createOrganization = function createTenantOrganization(/* app, [options,] callback */) {
var args = utils.resolveArgs(arguments, ['app', 'options', 'callback']);
this.dataStore.createResource('/organizations', args.options, args.app, require('./Organization'), args.callback);
};
/**
* Not documented as this is proxied by client.getDirectories()
*
* @private
*/
Tenant.prototype.getDirectories = function getTenantDirectories(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.directories.href, args.options, require('./Directory'), args.callback);
};
/**
* Not documented as this is proxied by client.createDirectory()
*
* @private
*/
Tenant.prototype.createDirectory = function createTenantDirectory(/* dir, [options,] callback */) {
var args = utils.resolveArgs(arguments, ['dir', 'options', 'callback']);
if (args.dir.provider){
args.options = _.extend(args.options || {}, {expand:'provider'});
}
this.dataStore.createResource('/directories', args.options, args.dir, require('./Directory'), args.callback);
};
/**
* Verifies an account-specific email verification token, obtaining the verified
* Account and providing it to the specified callback. This is the token that
* is sent to the user by email, so they need to click on the link and arrive on
* your site with this query parameter in the URL. Once you fetch the parameter
* from the URL you will call this function.
*
* @param {String} token The token that was sent to the user
* @param {Function} callback
* The function to call when then the operation is complete. Will be called
* with the parameters (err, {@link Account}).
*
* @example
*
* var token = '2QTr9Gzzq444ojxq3H9NQX';
*
* tenant.verifyAccountEmail(token, function(err, account) {
* console.log(account);
* });
*/
Tenant.prototype.verifyAccountEmail = function verifyAccountEmail(token, callback) {
var dataStore = this.dataStore;
var href = "/accounts/emailVerificationTokens/" + token;
return dataStore.createResource(href, null, null, function(err,result){
if(err){
callback(err);
}else{
dataStore._evict(result.href, function (err) {
if(err){
callback(err);
}else{
dataStore.getResource(result.href,{nocache:true},require('./Account'),callback);
}
});
}
});
};
/**
* Gets the custom data object for this resource.
*
* @param {Function} callback
* The callback that will be called with the parameters (err, {@link CustomData}).
*/
Tenant.prototype.getCustomData = function getCustomData(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.customData.href, args.options, require('./CustomData'), args.callback);
};
module.exports = Tenant;