UNPKG

10.9 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 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;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var __metadata = (this && this.__metadata) || function (k, v) {
9 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10};
11var auth_1 = require('./auth');
12var client_1 = require('./client');
13var config_1 = require('./config');
14var cordova_1 = require('./cordova');
15var core_1 = require('./core');
16var deploy_1 = require('./deploy/deploy');
17var device_1 = require('./device');
18var events_1 = require('./events');
19var insights_1 = require('./insights');
20var logger_1 = require('./logger');
21var push_1 = require('./push/push');
22var storage_1 = require('./storage');
23var user_1 = require('./user/user');
24var modules = {};
25function cache(target, propertyKey, descriptor) {
26 var method = descriptor.get;
27 descriptor.get = function () {
28 if (typeof modules[propertyKey] === 'undefined') {
29 var value = method.apply(this, arguments);
30 modules[propertyKey] = value;
31 }
32 return modules[propertyKey];
33 };
34 descriptor.set = function (value) { };
35}
36/**
37 * @hidden
38 */
39var Container = (function () {
40 function Container() {
41 }
42 Object.defineProperty(Container.prototype, "appStatus", {
43 get: function () {
44 return { 'asleep': false, 'closed': false };
45 },
46 enumerable: true,
47 configurable: true
48 });
49 Object.defineProperty(Container.prototype, "config", {
50 get: function () {
51 return new config_1.Config();
52 },
53 enumerable: true,
54 configurable: true
55 });
56 Object.defineProperty(Container.prototype, "eventEmitter", {
57 get: function () {
58 return new events_1.EventEmitter();
59 },
60 enumerable: true,
61 configurable: true
62 });
63 Object.defineProperty(Container.prototype, "logger", {
64 get: function () {
65 var config = this.config;
66 var c = {};
67 if (typeof config.settings !== 'undefined') {
68 c = config.settings.logger;
69 }
70 return new logger_1.Logger(c);
71 },
72 enumerable: true,
73 configurable: true
74 });
75 Object.defineProperty(Container.prototype, "localStorageStrategy", {
76 get: function () {
77 return new storage_1.LocalStorageStrategy();
78 },
79 enumerable: true,
80 configurable: true
81 });
82 Object.defineProperty(Container.prototype, "sessionStorageStrategy", {
83 get: function () {
84 return new storage_1.SessionStorageStrategy();
85 },
86 enumerable: true,
87 configurable: true
88 });
89 Object.defineProperty(Container.prototype, "authTokenContext", {
90 get: function () {
91 var label = 'auth_' + this.config.get('app_id');
92 return new auth_1.CombinedAuthTokenContext({
93 'storage': new storage_1.Storage({ 'strategy': this.localStorageStrategy }),
94 'tempStorage': new storage_1.Storage({ 'strategy': this.sessionStorageStrategy })
95 }, label);
96 },
97 enumerable: true,
98 configurable: true
99 });
100 Object.defineProperty(Container.prototype, "client", {
101 get: function () {
102 return new client_1.Client(this.authTokenContext, this.config.getURL('api'));
103 },
104 enumerable: true,
105 configurable: true
106 });
107 Object.defineProperty(Container.prototype, "insights", {
108 get: function () {
109 return new insights_1.Insights({
110 'appStatus': this.appStatus,
111 'storage': new storage_1.Storage({ 'strategy': this.localStorageStrategy }),
112 'config': this.config,
113 'client': this.client,
114 'logger': this.logger
115 });
116 },
117 enumerable: true,
118 configurable: true
119 });
120 Object.defineProperty(Container.prototype, "core", {
121 get: function () {
122 return new core_1.Core({
123 'config': this.config,
124 'logger': this.logger,
125 'emitter': this.eventEmitter,
126 'insights': this.insights
127 });
128 },
129 enumerable: true,
130 configurable: true
131 });
132 Object.defineProperty(Container.prototype, "device", {
133 get: function () {
134 return new device_1.Device({ 'emitter': this.eventEmitter });
135 },
136 enumerable: true,
137 configurable: true
138 });
139 Object.defineProperty(Container.prototype, "cordova", {
140 get: function () {
141 return new cordova_1.Cordova({
142 'appStatus': this.appStatus,
143 'device': this.device,
144 'emitter': this.eventEmitter,
145 'logger': this.logger
146 });
147 },
148 enumerable: true,
149 configurable: true
150 });
151 Object.defineProperty(Container.prototype, "userContext", {
152 get: function () {
153 return new user_1.UserContext({ 'storage': new storage_1.Storage({ 'strategy': this.localStorageStrategy }), 'config': this.config });
154 },
155 enumerable: true,
156 configurable: true
157 });
158 Object.defineProperty(Container.prototype, "singleUserService", {
159 get: function () {
160 return new user_1.SingleUserService({ 'client': this.client, 'context': this.userContext });
161 },
162 enumerable: true,
163 configurable: true
164 });
165 Object.defineProperty(Container.prototype, "authModules", {
166 get: function () {
167 return {
168 'basic': new auth_1.BasicAuth({ 'config': this.config, 'client': this.client }),
169 'custom': new auth_1.CustomAuth({ 'config': this.config, 'client': this.client }),
170 'twitter': new auth_1.TwitterAuth({ 'config': this.config, 'client': this.client }),
171 'facebook': new auth_1.FacebookAuth({ 'config': this.config, 'client': this.client }),
172 'github': new auth_1.GithubAuth({ 'config': this.config, 'client': this.client }),
173 'google': new auth_1.GoogleAuth({ 'config': this.config, 'client': this.client }),
174 'instagram': new auth_1.InstagramAuth({ 'config': this.config, 'client': this.client }),
175 'linkedin': new auth_1.LinkedInAuth({ 'config': this.config, 'client': this.client })
176 };
177 },
178 enumerable: true,
179 configurable: true
180 });
181 Object.defineProperty(Container.prototype, "auth", {
182 get: function () {
183 return new auth_1.Auth({
184 'config': this.config,
185 'emitter': this.eventEmitter,
186 'authModules': this.authModules,
187 'tokenContext': this.authTokenContext,
188 'userService': this.singleUserService,
189 'storage': new storage_1.Storage({ 'strategy': this.localStorageStrategy })
190 });
191 },
192 enumerable: true,
193 configurable: true
194 });
195 Object.defineProperty(Container.prototype, "push", {
196 get: function () {
197 var config = this.config;
198 var c = {};
199 if (typeof config.settings !== 'undefined') {
200 c = config.settings.push;
201 }
202 return new push_1.Push({
203 'config': config,
204 'auth': this.auth,
205 'userService': this.singleUserService,
206 'device': this.device,
207 'client': this.client,
208 'emitter': this.eventEmitter,
209 'storage': new storage_1.Storage({ 'strategy': this.localStorageStrategy }),
210 'logger': this.logger
211 }, c);
212 },
213 enumerable: true,
214 configurable: true
215 });
216 Object.defineProperty(Container.prototype, "deploy", {
217 get: function () {
218 return new deploy_1.Deploy({
219 'config': this.config,
220 'emitter': this.eventEmitter,
221 'logger': this.logger
222 });
223 },
224 enumerable: true,
225 configurable: true
226 });
227 __decorate([
228 cache,
229 __metadata('design:type', Object)
230 ], Container.prototype, "appStatus", null);
231 __decorate([
232 cache,
233 __metadata('design:type', Object)
234 ], Container.prototype, "config", null);
235 __decorate([
236 cache,
237 __metadata('design:type', Object)
238 ], Container.prototype, "eventEmitter", null);
239 __decorate([
240 cache,
241 __metadata('design:type', Object)
242 ], Container.prototype, "logger", null);
243 __decorate([
244 cache,
245 __metadata('design:type', Object)
246 ], Container.prototype, "localStorageStrategy", null);
247 __decorate([
248 cache,
249 __metadata('design:type', Object)
250 ], Container.prototype, "sessionStorageStrategy", null);
251 __decorate([
252 cache,
253 __metadata('design:type', Object)
254 ], Container.prototype, "authTokenContext", null);
255 __decorate([
256 cache,
257 __metadata('design:type', Object)
258 ], Container.prototype, "client", null);
259 __decorate([
260 cache,
261 __metadata('design:type', Object)
262 ], Container.prototype, "insights", null);
263 __decorate([
264 cache,
265 __metadata('design:type', Object)
266 ], Container.prototype, "core", null);
267 __decorate([
268 cache,
269 __metadata('design:type', Object)
270 ], Container.prototype, "device", null);
271 __decorate([
272 cache,
273 __metadata('design:type', Object)
274 ], Container.prototype, "cordova", null);
275 __decorate([
276 cache,
277 __metadata('design:type', Object)
278 ], Container.prototype, "userContext", null);
279 __decorate([
280 cache,
281 __metadata('design:type', Object)
282 ], Container.prototype, "singleUserService", null);
283 __decorate([
284 cache,
285 __metadata('design:type', Object)
286 ], Container.prototype, "authModules", null);
287 __decorate([
288 cache,
289 __metadata('design:type', Object)
290 ], Container.prototype, "auth", null);
291 __decorate([
292 cache,
293 __metadata('design:type', Object)
294 ], Container.prototype, "push", null);
295 __decorate([
296 cache,
297 __metadata('design:type', Object)
298 ], Container.prototype, "deploy", null);
299 return Container;
300}());
301exports.Container = Container;