This repository was archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathTenant.js
More file actions
240 lines (222 loc) · 9.23 KB
/
Tenant.js
File metadata and controls
240 lines (222 loc) · 9.23 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
'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()}
*
* For convenience, some of these methods also exist on an instance of {@link Client},
* where they are bound to the current tenant, as identified by the API Key Pair
* that was passed to the Client constructor.
*
* @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);
/**
* Get the collection of {@link Account accounts} for this tenant.
*
* @param {CollectionQueryOptions} [options]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link Account} objects.
*/
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);
};
/**
* Get the collection of {@link Group groups} for this tenant.
*
* @param {CollectionQueryOptions} [options]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link Group} objects.
*/
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);
};
/**
* Get the collection of {@link Application applications} for this tenant.
*
* @param {CollectionQueryOptions} [options]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link Application} objects.
*/
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);
};
/**
* Get the collection of {@link Organization organizations} for this tenant.
*
* @param {CollectionQueryOptions} [options]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link Organization} objects.
*/
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);
};
/**
* Creates a new Application resource.
*
* @param {Object} application
* The {@link Application} resource to create.
*
* @param {ExpansionOptions} [options]
* Options to expand linked resources on the returned {@link Application}.
*
* @param {Function} callback
* Callback function, will be called with (err, {@link Application}).
*/
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);
};
/**
* Creates a new {@link Organization} resource. After creating a organization, you will
* likely want to map it to an {@link Application} using
* {@link Application#createAccountStoreMapping Application.createAccountStoreMapping()}.
*
* @param {Object} organization
* The {@link Organization} resource to create.
*
* @param {ExpansionOptions} [options]
* Options to expand linked resources on the returned {@link Organization}.
*
* @param {Function} callback
* Callback function, will be called with (err, {@link Organization}).
*/
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);
};
/**
* Get the collection of {@link Directory directories} for this tenant.
*
* @param {CollectionQueryOptions} [options]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link Directory} objects.
*/
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);
};
/*
* Creates a new {@link Directory} resource. After creating a directory, you will
* likely want to map it to an {@link Application} using
* {@link Application#createAccountStoreMapping Application.createAccountStoreMapping()}.
*
* @param {Object} directory
* The {@link Directory} resource to create.
*
* @param {ExpansionOptions} [options]
* Options to expand linked resources on the returned {@link Directory}.
*
* @param {Function} callback
* Callback function, will be called with (err, {@link Directory}).
*
*/
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 {@link CustomData} 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);
};
/**
* Retrieves all the {@link IdSite} resources for this resource.
*
* @param {CollectionQueryOptions} [collectionQueryOptions]
* Options for querying, paginating, and expanding the collection.
*
* @param {Function} callback
* The function to call when then the operation is complete. Will be called
* with the parameters (err, {@link CollectionResource}). The collection will
* be a list of {@link IdSite} objects.
*
*/
Tenant.prototype.getIdSites = function getTenantIdSites(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.idSites.href, args.options, require('./IdSite'), args.callback);
};
module.exports = Tenant;