UNPKG

13.1 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7var __metadata = (this && this.__metadata) || function (k, v) {
8 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9};
10import { Auth, BasicAuthType, CombinedAuthTokenContext, CustomAuthType, FacebookAuth, FacebookAuthType, GithubAuthType, GoogleAuth, GoogleAuthType, InstagramAuthType, LinkedInAuthType, TwitterAuthType, } from './auth';
11import { Client } from './client';
12import { Config } from './config';
13import { Cordova } from './cordova';
14import { Core } from './core';
15import { Deploy } from './deploy/deploy';
16import { Device } from './device';
17import { EventEmitter } from './events';
18import { Insights } from './insights';
19import { Logger } from './logger';
20import { Push } from './push/push';
21import { Storage, LocalStorageStrategy, SessionStorageStrategy } from './storage';
22import { UserContext, SingleUserService } from './user/user';
23var modules = {};
24function cache(target, propertyKey, descriptor) {
25 var method = descriptor.get;
26 descriptor.get = function () {
27 if (typeof method !== 'undefined' && typeof modules[propertyKey] === 'undefined') {
28 var value = method.apply(this, arguments);
29 modules[propertyKey] = value;
30 }
31 return modules[propertyKey];
32 };
33 descriptor.set = function (value) { };
34}
35/**
36 * @hidden
37 */
38var Container = (function () {
39 function Container() {
40 }
41 Object.defineProperty(Container.prototype, "appStatus", {
42 get: function () {
43 return { 'asleep': false, 'closed': false };
44 },
45 enumerable: true,
46 configurable: true
47 });
48 Object.defineProperty(Container.prototype, "config", {
49 get: function () {
50 return new Config();
51 },
52 enumerable: true,
53 configurable: true
54 });
55 Object.defineProperty(Container.prototype, "eventEmitter", {
56 get: function () {
57 return new EventEmitter();
58 },
59 enumerable: true,
60 configurable: true
61 });
62 Object.defineProperty(Container.prototype, "logger", {
63 get: function () {
64 var config = this.config;
65 var c = {};
66 if (typeof config.settings !== 'undefined' && typeof config.settings.logger !== 'undefined') {
67 c = config.settings.logger;
68 }
69 return new Logger(c);
70 },
71 enumerable: true,
72 configurable: true
73 });
74 Object.defineProperty(Container.prototype, "localStorageStrategy", {
75 get: function () {
76 return new LocalStorageStrategy();
77 },
78 enumerable: true,
79 configurable: true
80 });
81 Object.defineProperty(Container.prototype, "sessionStorageStrategy", {
82 get: function () {
83 return new SessionStorageStrategy();
84 },
85 enumerable: true,
86 configurable: true
87 });
88 Object.defineProperty(Container.prototype, "authTokenContext", {
89 get: function () {
90 var label = 'auth_' + this.config.get('app_id');
91 return new CombinedAuthTokenContext({
92 'storage': new Storage({ 'strategy': this.localStorageStrategy }),
93 'tempStorage': new Storage({ 'strategy': this.sessionStorageStrategy })
94 }, label);
95 },
96 enumerable: true,
97 configurable: true
98 });
99 Object.defineProperty(Container.prototype, "client", {
100 get: function () {
101 return new Client(this.authTokenContext, this.config.getURL('api'));
102 },
103 enumerable: true,
104 configurable: true
105 });
106 Object.defineProperty(Container.prototype, "insights", {
107 get: function () {
108 var config = this.config;
109 var c = {};
110 if (typeof config.settings !== 'undefined' && typeof config.settings.insights !== 'undefined') {
111 c = config.settings.insights;
112 }
113 return new Insights({
114 'appStatus': this.appStatus,
115 'storage': new Storage({ 'strategy': this.localStorageStrategy }),
116 'config': this.config,
117 'client': this.client,
118 'device': this.device,
119 'logger': this.logger
120 }, c);
121 },
122 enumerable: true,
123 configurable: true
124 });
125 Object.defineProperty(Container.prototype, "core", {
126 get: function () {
127 return new Core({
128 'config': this.config,
129 'logger': this.logger,
130 'emitter': this.eventEmitter,
131 'insights': this.insights
132 });
133 },
134 enumerable: true,
135 configurable: true
136 });
137 Object.defineProperty(Container.prototype, "device", {
138 get: function () {
139 var cordovaDevice = window.device;
140 return new Device({ 'nativeDevice': cordovaDevice, 'emitter': this.eventEmitter });
141 },
142 enumerable: true,
143 configurable: true
144 });
145 Object.defineProperty(Container.prototype, "cordova", {
146 get: function () {
147 return new Cordova({
148 'appStatus': this.appStatus,
149 'device': this.device,
150 'emitter': this.eventEmitter,
151 'logger': this.logger
152 });
153 },
154 enumerable: true,
155 configurable: true
156 });
157 Object.defineProperty(Container.prototype, "userContext", {
158 get: function () {
159 return new UserContext({ 'storage': new Storage({ 'strategy': this.localStorageStrategy }), 'config': this.config });
160 },
161 enumerable: true,
162 configurable: true
163 });
164 Object.defineProperty(Container.prototype, "singleUserService", {
165 get: function () {
166 return new SingleUserService({ 'client': this.client, 'context': this.userContext });
167 },
168 enumerable: true,
169 configurable: true
170 });
171 Object.defineProperty(Container.prototype, "authModules", {
172 get: function () {
173 var authModuleDeps = {
174 'config': this.config,
175 'client': this.client,
176 'emitter': this.eventEmitter
177 };
178 return {
179 'basic': new BasicAuthType(authModuleDeps),
180 'custom': new CustomAuthType(authModuleDeps),
181 'twitter': new TwitterAuthType(authModuleDeps),
182 'facebook': new FacebookAuthType(authModuleDeps),
183 'github': new GithubAuthType(authModuleDeps),
184 'google': new GoogleAuthType(authModuleDeps),
185 'instagram': new InstagramAuthType(authModuleDeps),
186 'linkedin': new LinkedInAuthType(authModuleDeps)
187 };
188 },
189 enumerable: true,
190 configurable: true
191 });
192 Object.defineProperty(Container.prototype, "auth", {
193 get: function () {
194 return new Auth({
195 'config': this.config,
196 'emitter': this.eventEmitter,
197 'authModules': this.authModules,
198 'tokenContext': this.authTokenContext,
199 'userService': this.singleUserService,
200 'storage': new Storage({ 'strategy': this.localStorageStrategy })
201 });
202 },
203 enumerable: true,
204 configurable: true
205 });
206 Object.defineProperty(Container.prototype, "facebookAuth", {
207 get: function () {
208 return new FacebookAuth({
209 'config': this.config,
210 'client': this.client,
211 'userService': this.singleUserService,
212 'storage': new Storage({ 'strategy': this.localStorageStrategy }),
213 'tokenContext': this.authTokenContext,
214 'emitter': this.eventEmitter
215 });
216 },
217 enumerable: true,
218 configurable: true
219 });
220 Object.defineProperty(Container.prototype, "googleAuth", {
221 get: function () {
222 return new GoogleAuth({
223 'config': this.config,
224 'client': this.client,
225 'userService': this.singleUserService,
226 'storage': new Storage({ 'strategy': this.localStorageStrategy }),
227 'tokenContext': this.authTokenContext,
228 'emitter': this.eventEmitter
229 });
230 },
231 enumerable: true,
232 configurable: true
233 });
234 Object.defineProperty(Container.prototype, "push", {
235 get: function () {
236 var config = this.config;
237 var c = {};
238 if (typeof config.settings !== 'undefined' && typeof config.settings.push !== 'undefined') {
239 c = config.settings.push;
240 }
241 return new Push({
242 'config': config,
243 'auth': this.auth,
244 'userService': this.singleUserService,
245 'device': this.device,
246 'client': this.client,
247 'emitter': this.eventEmitter,
248 'storage': new Storage({ 'strategy': this.localStorageStrategy }),
249 'logger': this.logger
250 }, c);
251 },
252 enumerable: true,
253 configurable: true
254 });
255 Object.defineProperty(Container.prototype, "deploy", {
256 get: function () {
257 return new Deploy({
258 'config': this.config,
259 'emitter': this.eventEmitter,
260 'logger': this.logger
261 });
262 },
263 enumerable: true,
264 configurable: true
265 });
266 return Container;
267}());
268export { Container };
269__decorate([
270 cache,
271 __metadata("design:type", Object),
272 __metadata("design:paramtypes", [])
273], Container.prototype, "appStatus", null);
274__decorate([
275 cache,
276 __metadata("design:type", Object),
277 __metadata("design:paramtypes", [])
278], Container.prototype, "config", null);
279__decorate([
280 cache,
281 __metadata("design:type", Object),
282 __metadata("design:paramtypes", [])
283], Container.prototype, "eventEmitter", null);
284__decorate([
285 cache,
286 __metadata("design:type", Object),
287 __metadata("design:paramtypes", [])
288], Container.prototype, "logger", null);
289__decorate([
290 cache,
291 __metadata("design:type", Object),
292 __metadata("design:paramtypes", [])
293], Container.prototype, "localStorageStrategy", null);
294__decorate([
295 cache,
296 __metadata("design:type", Object),
297 __metadata("design:paramtypes", [])
298], Container.prototype, "sessionStorageStrategy", null);
299__decorate([
300 cache,
301 __metadata("design:type", Object),
302 __metadata("design:paramtypes", [])
303], Container.prototype, "authTokenContext", null);
304__decorate([
305 cache,
306 __metadata("design:type", Object),
307 __metadata("design:paramtypes", [])
308], Container.prototype, "client", null);
309__decorate([
310 cache,
311 __metadata("design:type", Object),
312 __metadata("design:paramtypes", [])
313], Container.prototype, "insights", null);
314__decorate([
315 cache,
316 __metadata("design:type", Object),
317 __metadata("design:paramtypes", [])
318], Container.prototype, "core", null);
319__decorate([
320 cache,
321 __metadata("design:type", Object),
322 __metadata("design:paramtypes", [])
323], Container.prototype, "device", null);
324__decorate([
325 cache,
326 __metadata("design:type", Object),
327 __metadata("design:paramtypes", [])
328], Container.prototype, "cordova", null);
329__decorate([
330 cache,
331 __metadata("design:type", Object),
332 __metadata("design:paramtypes", [])
333], Container.prototype, "userContext", null);
334__decorate([
335 cache,
336 __metadata("design:type", Object),
337 __metadata("design:paramtypes", [])
338], Container.prototype, "singleUserService", null);
339__decorate([
340 cache,
341 __metadata("design:type", Object),
342 __metadata("design:paramtypes", [])
343], Container.prototype, "authModules", null);
344__decorate([
345 cache,
346 __metadata("design:type", Object),
347 __metadata("design:paramtypes", [])
348], Container.prototype, "auth", null);
349__decorate([
350 cache,
351 __metadata("design:type", Object),
352 __metadata("design:paramtypes", [])
353], Container.prototype, "facebookAuth", null);
354__decorate([
355 cache,
356 __metadata("design:type", Object),
357 __metadata("design:paramtypes", [])
358], Container.prototype, "googleAuth", null);
359__decorate([
360 cache,
361 __metadata("design:type", Object),
362 __metadata("design:paramtypes", [])
363], Container.prototype, "push", null);
364__decorate([
365 cache,
366 __metadata("design:type", Object),
367 __metadata("design:paramtypes", [])
368], Container.prototype, "deploy", null);