Allow usage of analytics adapter (#2327)
* Allow usage of analytics adapter * Use promises in controller
This commit is contained in:
committed by
Florent Vilmart
parent
02edf27f05
commit
d1a6caeee3
11
src/Adapters/Analytics/AnalyticsAdapter.js
Normal file
11
src/Adapters/Analytics/AnalyticsAdapter.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export class AnalyticsAdapter {
|
||||||
|
appOpened(parameters, req) {
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
|
|
||||||
|
trackEvent(eventName, parameters, req) {
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AnalyticsAdapter;
|
||||||
@@ -41,6 +41,7 @@ export class Config {
|
|||||||
this.emailVerifyTokenValidityDuration = cacheInfo.emailVerifyTokenValidityDuration;
|
this.emailVerifyTokenValidityDuration = cacheInfo.emailVerifyTokenValidityDuration;
|
||||||
this.appName = cacheInfo.appName;
|
this.appName = cacheInfo.appName;
|
||||||
|
|
||||||
|
this.analyticsController = cacheInfo.analyticsController;
|
||||||
this.cacheController = cacheInfo.cacheController;
|
this.cacheController = cacheInfo.cacheController;
|
||||||
this.hooksController = cacheInfo.hooksController;
|
this.hooksController = cacheInfo.hooksController;
|
||||||
this.filesController = cacheInfo.filesController;
|
this.filesController = cacheInfo.filesController;
|
||||||
|
|||||||
28
src/Controllers/AnalyticsController.js
Normal file
28
src/Controllers/AnalyticsController.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import AdaptableController from './AdaptableController';
|
||||||
|
import { AnalyticsAdapter } from '../Adapters/Analytics/AnalyticsAdapter';
|
||||||
|
|
||||||
|
export class AnalyticsController extends AdaptableController {
|
||||||
|
appOpened(req) {
|
||||||
|
return this.adapter.appOpened(req.body, req).then(
|
||||||
|
function(response) {
|
||||||
|
return { response: response };
|
||||||
|
}).catch((err) => {
|
||||||
|
return { response: {} };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
trackEvent(req) {
|
||||||
|
return this.adapter.trackEvent(req.params.eventName, req.body, req).then(
|
||||||
|
function(response) {
|
||||||
|
return { response: response };
|
||||||
|
}).catch((err) => {
|
||||||
|
return { response: {} };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedAdapterType() {
|
||||||
|
return AnalyticsAdapter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AnalyticsController;
|
||||||
@@ -25,7 +25,9 @@ import { AnalyticsRouter } from './Routers/AnalyticsRouter';
|
|||||||
import { ClassesRouter } from './Routers/ClassesRouter';
|
import { ClassesRouter } from './Routers/ClassesRouter';
|
||||||
import { FeaturesRouter } from './Routers/FeaturesRouter';
|
import { FeaturesRouter } from './Routers/FeaturesRouter';
|
||||||
import { InMemoryCacheAdapter } from './Adapters/Cache/InMemoryCacheAdapter';
|
import { InMemoryCacheAdapter } from './Adapters/Cache/InMemoryCacheAdapter';
|
||||||
|
import { AnalyticsController } from './Controllers/AnalyticsController';
|
||||||
import { CacheController } from './Controllers/CacheController';
|
import { CacheController } from './Controllers/CacheController';
|
||||||
|
import { AnalyticsAdapter } from './Adapters/Analytics/AnalyticsAdapter';
|
||||||
import { FileLoggerAdapter } from './Adapters/Logger/FileLoggerAdapter';
|
import { FileLoggerAdapter } from './Adapters/Logger/FileLoggerAdapter';
|
||||||
import { FilesController } from './Controllers/FilesController';
|
import { FilesController } from './Controllers/FilesController';
|
||||||
import { FilesRouter } from './Routers/FilesRouter';
|
import { FilesRouter } from './Routers/FilesRouter';
|
||||||
@@ -65,6 +67,7 @@ const requiredUserFields = { fields: { ...SchemaController.defaultColumns._Defau
|
|||||||
|
|
||||||
// ParseServer works like a constructor of an express app.
|
// ParseServer works like a constructor of an express app.
|
||||||
// The args that we understand are:
|
// The args that we understand are:
|
||||||
|
// "analyticsAdapter": an adapter class for analytics
|
||||||
// "filesAdapter": a class like GridStoreAdapter providing create, get,
|
// "filesAdapter": a class like GridStoreAdapter providing create, get,
|
||||||
// and delete
|
// and delete
|
||||||
// "loggerAdapter": a class like FileLoggerAdapter providing info, error,
|
// "loggerAdapter": a class like FileLoggerAdapter providing info, error,
|
||||||
@@ -96,6 +99,7 @@ class ParseServer {
|
|||||||
appId = requiredParameter('You must provide an appId!'),
|
appId = requiredParameter('You must provide an appId!'),
|
||||||
masterKey = requiredParameter('You must provide a masterKey!'),
|
masterKey = requiredParameter('You must provide a masterKey!'),
|
||||||
appName,
|
appName,
|
||||||
|
analyticsAdapter = undefined,
|
||||||
filesAdapter,
|
filesAdapter,
|
||||||
push,
|
push,
|
||||||
loggerAdapter,
|
loggerAdapter,
|
||||||
@@ -140,7 +144,6 @@ class ParseServer {
|
|||||||
// Initialize the node client SDK automatically
|
// Initialize the node client SDK automatically
|
||||||
Parse.initialize(appId, javascriptKey || 'unused', masterKey);
|
Parse.initialize(appId, javascriptKey || 'unused', masterKey);
|
||||||
Parse.serverURL = serverURL;
|
Parse.serverURL = serverURL;
|
||||||
|
|
||||||
if ((databaseOptions || databaseURI || collectionPrefix !== '') && databaseAdapter) {
|
if ((databaseOptions || databaseURI || collectionPrefix !== '') && databaseAdapter) {
|
||||||
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/connectionPrefix.';
|
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/connectionPrefix.';
|
||||||
} else if (!databaseAdapter) {
|
} else if (!databaseAdapter) {
|
||||||
@@ -184,6 +187,7 @@ class ParseServer {
|
|||||||
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
|
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
|
||||||
const emailControllerAdapter = loadAdapter(emailAdapter);
|
const emailControllerAdapter = loadAdapter(emailAdapter);
|
||||||
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});
|
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});
|
||||||
|
const analyticsControllerAdapter = loadAdapter(analyticsAdapter, AnalyticsAdapter);
|
||||||
|
|
||||||
// We pass the options and the base class for the adatper,
|
// We pass the options and the base class for the adatper,
|
||||||
// Note that passing an instance would work too
|
// Note that passing an instance would work too
|
||||||
@@ -195,6 +199,7 @@ class ParseServer {
|
|||||||
const cacheController = new CacheController(cacheControllerAdapter, appId);
|
const cacheController = new CacheController(cacheControllerAdapter, appId);
|
||||||
const databaseController = new DatabaseController(databaseAdapter);
|
const databaseController = new DatabaseController(databaseAdapter);
|
||||||
const hooksController = new HooksController(appId, databaseController, webhookKey);
|
const hooksController = new HooksController(appId, databaseController, webhookKey);
|
||||||
|
const analyticsController = new AnalyticsController(analyticsControllerAdapter);
|
||||||
|
|
||||||
// TODO: create indexes on first creation of a _User object. Otherwise it's impossible to
|
// TODO: create indexes on first creation of a _User object. Otherwise it's impossible to
|
||||||
// have a Parse app without it having a _User collection.
|
// have a Parse app without it having a _User collection.
|
||||||
@@ -227,6 +232,7 @@ class ParseServer {
|
|||||||
webhookKey: webhookKey,
|
webhookKey: webhookKey,
|
||||||
fileKey: fileKey,
|
fileKey: fileKey,
|
||||||
facebookAppIds: facebookAppIds,
|
facebookAppIds: facebookAppIds,
|
||||||
|
analyticsController: analyticsController,
|
||||||
cacheController: cacheController,
|
cacheController: cacheController,
|
||||||
filesController: filesController,
|
filesController: filesController,
|
||||||
pushController: pushController,
|
pushController: pushController,
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
// AnalyticsRouter.js
|
// AnalyticsRouter.js
|
||||||
import PromiseRouter from '../PromiseRouter';
|
import PromiseRouter from '../PromiseRouter';
|
||||||
|
|
||||||
// Returns a promise that resolves to an empty object response
|
function appOpened(req) {
|
||||||
function ignoreAndSucceed(req) {
|
const analyticsController = req.config.analyticsController;
|
||||||
return Promise.resolve({
|
return analyticsController.appOpened(req);
|
||||||
response: {}
|
}
|
||||||
});
|
|
||||||
|
function trackEvent(req) {
|
||||||
|
const analyticsController = req.config.analyticsController;
|
||||||
|
return analyticsController.trackEvent(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class AnalyticsRouter extends PromiseRouter {
|
export class AnalyticsRouter extends PromiseRouter {
|
||||||
mountRoutes() {
|
mountRoutes() {
|
||||||
this.route('POST','/events/AppOpened', ignoreAndSucceed);
|
this.route('POST','/events/AppOpened', appOpened);
|
||||||
this.route('POST','/events/:eventName', ignoreAndSucceed);
|
this.route('POST','/events/:eventName', trackEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user