MCPcopy
hub / github.com/CodeboxIDE/codebox / setup

Function setup

core/cb.hooks/main.js:7–128  ·  view source on GitHub ↗
(options, imports, register)

Source from the content-addressed store, hash-verified

5
6
7function setup(options, imports, register) {
8 var logger = imports.logger.namespace("hooks");
9 var settings = imports.settings;
10
11 // Defaults hooks
12 var baseHooks = _.defaults(options.hooks || {}, {
13 // Auth an user
14 'auth': function(data) {
15 if (!data.email
16 || !data.token) {
17 return Q.reject(new Error("Need 'token' and 'email' for auth hook"));
18 }
19
20 var userId = data.email;
21
22 return {
23 'userId': userId,
24 'name': userId,
25 'token': data.token,
26 'email': data.email
27 };
28 },
29
30 // Report list of events
31 'events': function() {},
32
33 // Store and valid user settings
34 'settings': function(data) {
35 settings.extend(data.auth.userId, {
36 'settings': data.settings
37 });
38 return settings.save().then(function() {
39 return data.settings;
40 })
41 },
42
43 // Valid installation of an addon
44 'addons': function(addon) {
45 return true;
46 }
47 });
48
49 // Post operations for hooks
50 // can be used for validation
51 var postHooks = {
52 'auth': function(data) {
53 // Valid data
54 if (!_.has(data, "userId") || !_.has(data, "name")
55 || !_.has(data, "token") || !_.has(data, "email")) {
56 return Q.reject(new Error("Invalid authentication data"));
57 }
58
59 // Load base settings if no settings
60 data.settings = data.settings || settings.get(data.userId, {}).settings || {};
61 return data;
62 }
63 };
64

Callers

nothing calls this directly

Calls 2

registerFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected