diff options
Diffstat (limited to 'src/models/Recipe.ts')
-rw-r--r-- | src/models/Recipe.ts | 93 |
1 files changed, 56 insertions, 37 deletions
diff --git a/src/models/Recipe.ts b/src/models/Recipe.ts index eb8b0b1ff..a171a288a 100644 --- a/src/models/Recipe.ts +++ b/src/models/Recipe.ts | |||
@@ -4,7 +4,7 @@ import { join } from 'path'; | |||
4 | import { DEFAULT_SERVICE_SETTINGS } from '../config'; | 4 | import { DEFAULT_SERVICE_SETTINGS } from '../config'; |
5 | import { ifUndefined } from '../jsUtils'; | 5 | import { ifUndefined } from '../jsUtils'; |
6 | 6 | ||
7 | interface IRecipe { | 7 | interface RecipeData { |
8 | id: string; | 8 | id: string; |
9 | name: string; | 9 | name: string; |
10 | version: string; | 10 | version: string; |
@@ -29,67 +29,86 @@ interface IRecipe { | |||
29 | }; | 29 | }; |
30 | } | 30 | } |
31 | 31 | ||
32 | export default class Recipe { | 32 | export interface IRecipe { |
33 | id: string = ''; | 33 | id: string; |
34 | name: string; | ||
35 | description: string; | ||
36 | version: string; | ||
37 | aliases: string[]; | ||
38 | serviceURL: string; | ||
39 | hasDirectMessages: boolean; | ||
40 | hasIndirectMessages: boolean; | ||
41 | hasNotificationSound: boolean; | ||
42 | hasTeamId: boolean; | ||
43 | hasCustomUrl: boolean; | ||
44 | hasHostedOption: boolean; | ||
45 | urlInputPrefix: string; | ||
46 | urlInputSuffix: string; | ||
47 | message: string; | ||
48 | allowFavoritesDelineationInUnreadCount: boolean; | ||
49 | disablewebsecurity: boolean; | ||
50 | autoHibernate: boolean; | ||
51 | path: string; | ||
52 | partition: string; | ||
53 | local: boolean; | ||
54 | |||
55 | readonly overrideUserAgent?: null | Function; | ||
56 | readonly buildUrl?: null | Function; | ||
57 | readonly modifyRequestHeaders?: null | Function; | ||
58 | readonly knownCertificateHosts?: null | Function; | ||
59 | readonly events?: null | { (key: string): string }; | ||
60 | } | ||
61 | |||
62 | export default class Recipe implements IRecipe { | ||
63 | id = ''; | ||
34 | 64 | ||
35 | name: string = ''; | 65 | name = ''; |
36 | 66 | ||
37 | description: string = ''; | 67 | description = ''; |
38 | 68 | ||
39 | version: string = ''; | 69 | version = ''; |
40 | 70 | ||
71 | // Removing this specific type will cause a typescript error | ||
72 | // even while it's the exact same as the interface | ||
41 | aliases: string[] = []; | 73 | aliases: string[] = []; |
42 | 74 | ||
43 | serviceURL: string = ''; | 75 | serviceURL = ''; |
44 | 76 | ||
45 | hasDirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; | 77 | hasDirectMessages = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; |
46 | 78 | ||
47 | hasIndirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; | 79 | hasIndirectMessages = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; |
48 | 80 | ||
49 | hasNotificationSound: boolean = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; | 81 | hasNotificationSound = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; |
50 | 82 | ||
51 | hasTeamId: boolean = DEFAULT_SERVICE_SETTINGS.hasTeamId; | 83 | hasTeamId = DEFAULT_SERVICE_SETTINGS.hasTeamId; |
52 | 84 | ||
53 | hasCustomUrl: boolean = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; | 85 | hasCustomUrl = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; |
54 | 86 | ||
55 | hasHostedOption: boolean = DEFAULT_SERVICE_SETTINGS.hasHostedOption; | 87 | hasHostedOption = DEFAULT_SERVICE_SETTINGS.hasHostedOption; |
56 | 88 | ||
57 | urlInputPrefix: string = ''; | 89 | urlInputPrefix = ''; |
58 | 90 | ||
59 | urlInputSuffix: string = ''; | 91 | urlInputSuffix = ''; |
60 | 92 | ||
61 | message: string = ''; | 93 | message = ''; |
62 | 94 | ||
63 | allowFavoritesDelineationInUnreadCount: boolean = | 95 | allowFavoritesDelineationInUnreadCount = |
64 | DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; | 96 | DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; |
65 | 97 | ||
66 | disablewebsecurity: boolean = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; | 98 | disablewebsecurity = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; |
67 | 99 | ||
68 | // TODO: Is this even used? | 100 | // TODO: Is this even used? |
69 | autoHibernate: boolean = DEFAULT_SERVICE_SETTINGS.autoHibernate; | 101 | autoHibernate = DEFAULT_SERVICE_SETTINGS.autoHibernate; |
70 | 102 | ||
71 | path: string = ''; | 103 | path = ''; |
72 | 104 | ||
73 | partition: string = ''; | 105 | partition = ''; |
74 | 106 | ||
75 | // TODO: Is this being used? | 107 | // TODO: Is this being used? |
76 | local: boolean = false; | 108 | local = false; |
77 | |||
78 | // TODO Add types for this once we know if they are neccesary to pass | ||
79 | // on to the initialize-recipe ipc event. | ||
80 | overrideUserAgent: any; | ||
81 | |||
82 | buildUrl: any; | ||
83 | |||
84 | modifyRequestHeaders: any; | ||
85 | |||
86 | knownCertificateHosts: any; | ||
87 | |||
88 | events: any; | ||
89 | // End todo. | ||
90 | 109 | ||
91 | // TODO: Need to reconcile which of these are optional/mandatory | 110 | // TODO: Need to reconcile which of these are optional/mandatory |
92 | constructor(data: IRecipe) { | 111 | constructor(data: RecipeData) { |
93 | if (!data) { | 112 | if (!data) { |
94 | throw new Error('Recipe config not valid'); | 113 | throw new Error('Recipe config not valid'); |
95 | } | 114 | } |
@@ -109,7 +128,7 @@ export default class Recipe { | |||
109 | this.id = ifUndefined<string>(data.id, this.id); | 128 | this.id = ifUndefined<string>(data.id, this.id); |
110 | this.name = ifUndefined<string>(data.name, this.name); | 129 | this.name = ifUndefined<string>(data.name, this.name); |
111 | this.version = ifUndefined<string>(data.version, this.version); | 130 | this.version = ifUndefined<string>(data.version, this.version); |
112 | this.aliases = data.aliases || this.aliases; | 131 | this.aliases = ifUndefined<Array<string>>(data.aliases, this.aliases); |
113 | this.serviceURL = ifUndefined<string>( | 132 | this.serviceURL = ifUndefined<string>( |
114 | data.config.serviceURL, | 133 | data.config.serviceURL, |
115 | this.serviceURL, | 134 | this.serviceURL, |