zendesk_apps_support 1.19.0 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ace40b56ef156df8ee9d1d75701446de28de6f0
4
- data.tar.gz: 9646fb502276edd309aa2e4201ce3ddaa4ad8997
3
+ metadata.gz: 21a2a6da05c4d89d23d1322dfd5f279c3191381b
4
+ data.tar.gz: 3f48e22275d82ea5b2c4ecd444e4a362d81f4943
5
5
  SHA512:
6
- metadata.gz: df6abfa20f351c08abe3477bb01677c67e04a8d4e8331b7d99c8af19398b7b602bd0a4ab12f6272c296882286e724a9af8d9641d6214d49a6bcb70f23d9e2716
7
- data.tar.gz: baea6079f6fb78b82526593935424cb2c04ff104eb6432d02f3e81c3cbd30257cec00f4655280e8edd3507aa17e794ecbca8e874b491f34ca89f29cff1cf4e28
6
+ metadata.gz: 7fd547a41b3f5210d912bab54c0564747552fd0d03b787e7482c97257534199fb34367166edfc6e58e7000be07f65bc18b54bcef47c0f8a36b8add12f4916041
7
+ data.tar.gz: ac53d9ddc31416ed8f7381554c1efe5f50e10032c73c0ab7f91f6add6cf982232ac17802be5bac1175c48230e4a3cf7b670794ee2ac3ca3a3508ccb8fc891afe
@@ -1,4 +1,4 @@
1
- # This is a generated file. Please do not edit it.
1
+ # This file is generated by rake i18n:standardize. Do NOT edit it directly.
2
2
  ---
3
3
  en:
4
4
  txt:
@@ -17,6 +17,7 @@ en:
17
17
  app.js
18
18
  manifest_not_json: manifest is not proper JSON. %{errors}
19
19
  missing_manifest: Could not find manifest.json
20
+ symlink_in_zip: Symlinks are not allowed in the zip file
20
21
  missing_requirements: Could not find requirements.json
21
22
  manifest_keys:
22
23
  missing:
@@ -34,41 +35,41 @@ en:
34
35
  one: 'requirements.json contains an invalid type: %{invalid_types}'
35
36
  other: 'requirements.json contains invalid types: %{invalid_types}'
36
37
  banner:
37
- invalid_format: 'Banner image must be a PNG file'
38
- invalid_size: 'Invalid banner image dimensions. Must be %{required_banner_width}x%{required_banner_height}px'
38
+ invalid_format: Banner image must be a PNG file.
39
+ invalid_size: Invalid banner image dimensions. Must be %{required_banner_width}x%{required_banner_height}px.
39
40
  oauth_keys:
40
41
  missing:
41
42
  one: 'Missing required oauth field in manifest: %{missing_keys}'
42
43
  other: 'Missing required oauth fields in manifest: %{missing_keys}'
43
44
  missing_source: Could not find app.js
44
- style_in_template: <style> tag in %{template}. Use an app.css file instead.
45
- invalid_default_locale: '%{defaultLocale} is not a valid default locale.'
45
+ style_in_template: "<style> tag in %{template}. Use an app.css file instead."
46
+ invalid_default_locale: "%{defaultLocale} is not a valid default locale."
46
47
  missing_translation_file: 'Missing translation file for locale ''%{defaultLocale}''.
47
48
  Please read: http://developer.zendesk.com/documentation/apps/i18n.html'
48
- invalid_host: '%{host_name} is an invalid host for apps.'
49
+ invalid_host: "%{host_name} is an invalid host for apps."
49
50
  invalid_location:
50
- one: '%{invalid_locations} is an invalid location in %{host_name}.'
51
- other: '%{invalid_locations} are invalid locations in %{host_name}.'
51
+ one: "%{invalid_locations} is an invalid location in %{host_name}."
52
+ other: "%{invalid_locations} are invalid locations in %{host_name}."
52
53
  duplicate_location:
53
- one: '%{duplicate_locations} is a duplicate location.'
54
- other: '%{duplicate_locations} are duplicate locations.'
54
+ one: "%{duplicate_locations} is a duplicate location."
55
+ other: "%{duplicate_locations} are duplicate locations."
55
56
  name_as_parameter_name: Can't call a parameter 'name'
56
57
  invalid_hidden_parameter:
57
- one: '%{invalid_params} is set to hidden and cannot be required.'
58
- other: '%{invalid_params} are set to hidden and cannot be required.'
59
- invalid_version: '%{target_version} is not a valid framework version.
60
- Available versions are: %{available_versions}.'
58
+ one: "%{invalid_params} is set to hidden and cannot be required."
59
+ other: "%{invalid_params} are set to hidden and cannot be required."
60
+ invalid_version: "%{target_version} is not a valid framework version.
61
+ Available versions are: %{available_versions}."
61
62
  parameters_not_an_array: App parameters must be an array.
62
63
  duplicate_parameters: 'Duplicate app parameters defined: %{duplicate_parameters}'
63
64
  translation:
64
- invalid_locale: '%{file} is not a valid locale.'
65
- invalid_format: '%{field} is invalid for translation.'
66
- not_json: '%{file} is not valid JSON. %{errors}'
67
- not_json_object: '%{file} is not a JSON object.'
65
+ invalid_locale: "%{file} is not a valid locale."
66
+ invalid_format: "%{field} is invalid for translation."
67
+ not_json: "%{file} is not valid JSON. %{errors}"
68
+ not_json_object: "%{file} is not a JSON object."
68
69
  stylesheet_error: 'Sass error: %{sass_error}'
69
70
  invalid_type_parameter:
70
- one: '%{invalid_types} is an invalid parameter type.'
71
- other: '%{invalid_types} are invalid parameter types.'
71
+ one: "%{invalid_types} is an invalid parameter type."
72
+ other: "%{invalid_types} are invalid parameter types."
72
73
  warning:
73
74
  app_build:
74
75
  deprecated_version: You are targeting a deprecated version of the framework.
@@ -35,6 +35,10 @@ parts:
35
35
  key: "txt.apps.admin.error.app_build.missing_manifest"
36
36
  title: "App builder job: missing manifest error"
37
37
  value: "Could not find manifest.json"
38
+ - translation:
39
+ key: "txt.apps.admin.error.app_build.symlink_in_zip"
40
+ title: "App builder job: symlinks not allowed"
41
+ value: "Symlinks are not allowed in the zip file"
38
42
  - translation:
39
43
  key: "txt.apps.admin.error.app_build.missing_requirements"
40
44
  title: "App builder job: missing requirements error"
@@ -54,7 +58,7 @@ parts:
54
58
  - translation:
55
59
  key: "txt.apps.admin.error.app_build.excessive_requirements"
56
60
  title: "App builder job: requirements file contains too many requirements"
57
- value: "The requirements.json file contains too many requirements. The current limit is %{max} requirements."
61
+ value: "The requirements.json file contains too many requirements. The current limit is %{max} requirements. This app has %{count} requirements."
58
62
  - translation:
59
63
  key: "txt.apps.admin.error.app_build.missing_required_fields"
60
64
  title: "App builder job: required key missing in requirements, e.g. \"title\" is required in \"my_custom_email_target\""
@@ -75,6 +79,14 @@ parts:
75
79
  key: "txt.apps.admin.error.app_build.invalid_requirements_types.other"
76
80
  title: "App builder job: requirements file contains invalid types error"
77
81
  value: "requirements.json contains invalid types: %{invalid_types}"
82
+ - translation:
83
+ key: "txt.apps.admin.error.app_build.banner.invalid_format"
84
+ title: "App builder job: Banner image invalid format error"
85
+ value: "Banner image must be a PNG file."
86
+ - translation:
87
+ key: "txt.apps.admin.error.app_build.banner.invalid_size"
88
+ title: "App builder job: Banner image invalid size error"
89
+ value: "Invalid banner image dimensions. Must be %{required_banner_width}x%{required_banner_height}px."
78
90
  - translation:
79
91
  key: "txt.apps.admin.error.app_build.oauth_keys.missing.one"
80
92
  title: "App builder job: missing oauth fields error"
@@ -99,14 +111,18 @@ parts:
99
111
  key: "txt.apps.admin.error.app_build.missing_translation_file"
100
112
  title: "App builder job: missing translation file"
101
113
  value: "Missing translation file for locale '%{defaultLocale}'. Please read: http://developer.zendesk.com/documentation/apps/i18n.html"
114
+ - translation:
115
+ key: "txt.apps.admin.error.app_build.invalid_host"
116
+ title: "App builder job: invalid host application for apps"
117
+ value: "%{host_name} is an invalid host for apps."
102
118
  - translation:
103
119
  key: "txt.apps.admin.error.app_build.invalid_location.one"
104
120
  title: "App builder job: invalid locations"
105
- value: "%{invalid_locations} is an invalid location."
121
+ value: "%{invalid_locations} is an invalid location in %{host_name}."
106
122
  - translation:
107
123
  key: "txt.apps.admin.error.app_build.invalid_location.other"
108
124
  title: "App builder job: invalid locations"
109
- value: "%{invalid_locations} are invalid locations."
125
+ value: "%{invalid_locations} are invalid locations in %{host_name}."
110
126
  - translation:
111
127
  key: "txt.apps.admin.error.app_build.duplicate_location.one"
112
128
  title: "App builder job: duplicate locations"
@@ -0,0 +1,15 @@
1
+ (function() {
2
+ <% appsjs.each do |appjs| %>
3
+ <%= appjs %>
4
+ <% end %>
5
+
6
+ <% installations.each do |installation| %>
7
+ ZendeskApps[<%= installation.app_name.to_json %>].install(<%= installation.to_json %>);
8
+ <% end %>
9
+
10
+ <% installation_orders.each do |loc_name, installation_list| %>
11
+ ZendeskApps.sortAppsForSite(<%= loc_name.to_json %>, <%= installation_list.to_json %>);
12
+ <% end %>
13
+ }());
14
+
15
+ ZendeskApps.trigger && ZendeskApps.trigger('ready');
@@ -1,38 +1,32 @@
1
- (function() {
2
- with( ZendeskApps.AppScope.create() ) {
3
- <% unless modules.nil? %>
1
+ with( ZendeskApps.AppScope.create() ) {
2
+ <% unless modules.empty? %>
4
3
  require.modules = {
5
4
  <% modules.each do |path, content| %>
6
- '<%= path %>': function(exports, require, module) {
5
+ <%= path.to_json %>: function(exports, require, module) {
7
6
  <%= content %>
8
7
  },
9
8
  <% end %>
10
9
  eom: undefined
11
10
  };
12
- <% end %>
11
+ <% end %>
13
12
 
14
- var source = <%= source %>;
13
+ var source = <%= source %>;
15
14
 
16
- var app = ZendeskApps.defineApp(source)
17
- .reopenClass(<%= app_settings.to_json %>)
18
- .reopen({
19
- appName: <%= name.to_json %>,
20
- appVersion: <%= version.to_json %>,
21
- assetUrlPrefix: <%= asset_url_prefix.to_json %>,
22
- appClassName: <%= app_class_name.to_json %>,
23
- author: {
24
- name: <%= author[:name].to_json %>,
25
- email: <%= author[:email].to_json %>
26
- },
27
- translations: <%= translations.to_json %>,
28
- templates: <%= templates.to_json %>,
29
- frameworkVersion: <%= framework_version.to_json %>,
30
- });
31
-
32
- ZendeskApps[<%= name.to_json %>] = app;
33
- }
34
-
35
- ZendeskApps[<%= name.to_json %>].install({"id": <%= app_id %>, "app_id": <%= app_id %>, "settings": <%= settings.to_json %>});
36
- }());
15
+ var app = ZendeskApps.defineApp(source)
16
+ .reopenClass(<%= app_settings.to_json %>)
17
+ .reopen({
18
+ appName: <%= name.to_json %>,
19
+ appVersion: <%= version.to_json %>,
20
+ assetUrlPrefix: <%= asset_url_prefix.to_json %>,
21
+ appClassName: <%= app_class_name.to_json %>,
22
+ author: {
23
+ name: <%= author['name'].to_json %>,
24
+ email: <%= author['email'].to_json %>
25
+ },
26
+ translations: <%= translations.to_json %>,
27
+ templates: <%= templates.to_json %>,
28
+ frameworkVersion: <%= framework_version.to_json %>
29
+ });
37
30
 
38
- ZendeskApps.trigger && ZendeskApps.trigger('ready');
31
+ ZendeskApps[<%= name.to_json %>] = app;
32
+ }
@@ -0,0 +1,20 @@
1
+ module ZendeskAppsSupport
2
+ class Installation
3
+
4
+ attr_accessor :id, :app_id, :app_name, :requirements, :settings, :enabled, :updated_at, :created_at
5
+
6
+ def initialize(options)
7
+ options.each do |k, v|
8
+ public_send("#{k}=", v)
9
+ end
10
+ end
11
+
12
+ def to_json
13
+ hash = {}
14
+ self.instance_variables.each do |var|
15
+ hash[var.to_s.sub('@', '')] = self.instance_variable_get var
16
+ end
17
+ hash.to_json
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'erubis'
2
+
3
+ module ZendeskAppsSupport
4
+ class Installed
5
+ INSTALLED_TEMPLATE = Erubis::Eruby.new(File.read(File.expand_path('../assets/installed.js.erb', __FILE__)))
6
+
7
+ def initialize(appsjs, installations = [])
8
+ @appsjs = appsjs
9
+ @installations = installations
10
+ end
11
+
12
+ def compile_js(options = {})
13
+ installation_order = options.fetch(:installation_orders, {})
14
+
15
+ INSTALLED_TEMPLATE.result(
16
+ appsjs: @appsjs,
17
+ installations: @installations,
18
+ installation_orders: installation_order
19
+ )
20
+ end
21
+ end
22
+ end
@@ -6,29 +6,33 @@ module ZendeskAppsSupport
6
6
  class Package
7
7
  include ZendeskAppsSupport::BuildTranslation
8
8
 
9
+ REQUIREMENTS_FILENAME = "requirements.json"
10
+
9
11
  DEFAULT_LAYOUT = Erubis::Eruby.new(File.read(File.expand_path('../assets/default_template.html.erb', __FILE__)))
10
12
  DEFAULT_SCSS = File.read(File.expand_path('../assets/default_styles.scss', __FILE__))
11
13
  SRC_TEMPLATE = Erubis::Eruby.new(File.read(File.expand_path('../assets/src.js.erb', __FILE__)))
12
14
 
13
15
  attr_reader :lib_root, :root, :warnings
14
- attr_accessor :requirements_only
15
16
 
16
- def initialize(dir)
17
- @root = Pathname.new(File.expand_path(dir))
17
+ def initialize(dir, is_cached = true)
18
+ @root = Pathname.new(File.expand_path(dir))
18
19
  @lib_root = Pathname.new(File.join(@root, 'lib'))
20
+
21
+ @is_cached = is_cached #disabled by ZAT for development
19
22
  @warnings = []
20
- @requirements_only = false
21
23
  end
22
24
 
23
- def validate
25
+ def validate(marketplace: true)
24
26
  [].tap do |errors|
27
+ errors << Validations::Marketplace.call(self) if marketplace
28
+
25
29
  errors << Validations::Manifest.call(self)
26
30
 
27
31
  if has_manifest?
28
32
  errors << Validations::Source.call(self)
29
33
  errors << Validations::Translations.call(self)
30
34
 
31
- unless @requirements_only
35
+ unless manifest_json['requirementsOnly']
32
36
  errors << Validations::Templates.call(self)
33
37
  errors << Validations::Stylesheets.call(self)
34
38
  end
@@ -42,84 +46,75 @@ module ZendeskAppsSupport
42
46
  errors << Validations::Banner.call(self)
43
47
  end
44
48
 
45
- errors.flatten!
49
+ errors.flatten!.compact!
46
50
  end
47
51
  end
48
52
 
49
- def app_js
50
- read_file('app.js')
53
+ def validate!(marketplace: true)
54
+ errors = validate(marketplace: marketplace)
55
+ if errors.any?
56
+ raise errors.first
57
+ end
58
+ true
51
59
  end
52
60
 
53
- def commonjs_modules
54
- return unless has_lib_js?
55
-
56
- lib_files.each_with_object({}) do |file, modules|
57
- name = file.relative_path.gsub!(/^lib\//, '')
58
- content = file.read
59
- modules[name] = content
61
+ def assets
62
+ @assets ||= Dir.chdir(@root) do
63
+ Dir["assets/**/*"].select { |f| File.file?(f) }
60
64
  end
61
65
  end
62
66
 
63
- def files
64
- non_tmp_files
67
+ def path_to(file)
68
+ File.join(@root, file)
65
69
  end
66
70
 
67
- def lib_files
68
- @lib_files ||= files.select { |f| f =~ /^lib\/.*\.js$/ }
71
+ def requirements_path
72
+ path_to(REQUIREMENTS_FILENAME)
69
73
  end
70
74
 
71
- def template_files
72
- files.select { |f| f =~ /^templates\/.*\.hdbs$/ }
75
+ def locales
76
+ translations.keys
73
77
  end
74
78
 
75
- def no_template
76
- manifest = manifest_json
77
- if manifest['noTemplate'].is_a?(Array)
78
- false
79
- else
80
- !!manifest['noTemplate']
81
- end
79
+ def files
80
+ non_tmp_files
82
81
  end
83
82
 
84
- def translation_files
85
- files.select { |f| f =~ /^translations\// }
83
+ def lib_files
84
+ @lib_files ||= non_tmp_files.select { |f| f =~ /^lib\/.*\.js$/ }
86
85
  end
87
86
 
88
- def manifest_json
89
- read_json('manifest.json')
87
+ def template_files
88
+ files.select { |f| f =~ /^templates\/.*\.hdbs$/ }
90
89
  end
91
90
 
92
- def requirements_json
93
- read_json('requirements.json')
91
+ def translation_files
92
+ non_tmp_files.select { |f| f =~ /^translations\// }
94
93
  end
95
94
 
96
- def translations(locale)
97
- file_path = "translations/#{locale}.json"
98
- file_path = "translations/en.json" unless file_exists?(file_path)
99
- read_json(file_path, false)
100
- end
95
+ def compile_js(options)
96
+ begin
97
+ app_id = options.fetch(:app_id)
98
+ asset_url_prefix = options.fetch(:assets_dir)
99
+ name = options.fetch(:app_name)
100
+ rescue KeyError => e
101
+ raise ArgumentError, e.message
102
+ end
101
103
 
102
- def app_translations(locale)
103
- remove_zendesk_keys(translations(locale))
104
- end
104
+ locale = options.fetch(:locale, 'en')
105
105
 
106
- def readified_js(app_name, app_id, asset_url_prefix, settings = {}, locale = 'en')
107
- manifest = manifest_json
108
106
  source = app_js
109
- name = app_name || manifest[:name] || 'Local App'
110
- location = manifest[:location]
111
- version = manifest[:version]
107
+ location = manifest_json['location']
108
+ version = manifest_json['version']
112
109
  app_class_name = "app-#{app_id}"
113
- author = manifest[:author]
114
- framework_version = manifest[:frameworkVersion]
115
- single_install = manifest[:singleInstall] || false
116
- templates = no_template ? {} : compiled_templates(app_id, asset_url_prefix)
117
-
118
- settings['title'] = name
110
+ author = manifest_json['author']
111
+ framework_version = manifest_json['frameworkVersion']
112
+ single_install = manifest_json['singleInstall'] || false
113
+ templates = is_no_template ? {} : compiled_templates(app_id, asset_url_prefix)
119
114
 
120
115
  app_settings = {
121
116
  location: location,
122
- noTemplate: no_template,
117
+ noTemplate: is_no_template,
123
118
  singleInstall: single_install
124
119
  }.select { |_k, v| !v.nil? }
125
120
 
@@ -131,42 +126,64 @@ module ZendeskAppsSupport
131
126
  asset_url_prefix: asset_url_prefix,
132
127
  app_class_name: app_class_name,
133
128
  author: author,
134
- translations: app_translations(locale),
129
+ translations: translations_for(locale),
135
130
  framework_version: framework_version,
136
131
  templates: templates,
137
- settings: settings,
138
- app_id: app_id,
139
132
  modules: commonjs_modules
140
133
  )
141
134
  end
142
135
 
143
- def customer_css
144
- css_file = file_path('app.css')
145
- File.exist?(css_file) ? File.read(css_file) : ''
136
+ def manifest_json
137
+ @manifest ||= read_json('manifest.json')
146
138
  end
147
139
 
148
- def has_js?
149
- file_exists?('app.js')
140
+ def requirements_json
141
+ return nil unless has_requirements?
142
+ @requirements ||= read_json('requirements.json')
150
143
  end
151
144
 
152
- def has_lib_js?
153
- lib_files.any?
145
+ def is_no_template
146
+ if manifest_json['noTemplate'].is_a?(Array)
147
+ false
148
+ else
149
+ !!manifest_json['noTemplate']
150
+ end
154
151
  end
155
152
 
156
- def has_manifest?
157
- file_exists?('manifest.json')
153
+ def no_template_locations
154
+ if manifest_json['noTemplate'].is_a?(Array)
155
+ manifest_json['noTemplate']
156
+ else
157
+ !!manifest_json['noTemplate']
158
+ end
158
159
  end
159
160
 
160
- def has_location?
161
- manifest_json[:location]
161
+ def compiled_templates(app_id, asset_url_prefix)
162
+ compiled_css = ZendeskAppsSupport::StylesheetCompiler.new(DEFAULT_SCSS + app_css, app_id, asset_url_prefix).compile
163
+
164
+ layout = templates['layout'] || DEFAULT_LAYOUT.result
165
+
166
+ templates.tap do |templates|
167
+ templates['layout'] = "<style>\n#{compiled_css}</style>\n#{layout}"
168
+ end
162
169
  end
163
170
 
164
- def has_requirements?
165
- file_exists?('requirements.json')
171
+ def market_translations!(locale)
172
+ result = translations[locale].fetch('app', {})
173
+ result.delete('name')
174
+ result.delete('description')
175
+ result.delete('long_description')
176
+ result.delete('installation_instructions')
177
+ result
166
178
  end
167
179
 
168
- def has_banner?
169
- file_exists?('assets/banner.png')
180
+ def has_location?
181
+ manifest_json['location']
182
+ end
183
+
184
+ def app_css
185
+ css_file = file_path('app.css')
186
+ File.exist?(css_file) ? File.read(css_file) : ''
170
187
  end
171
188
 
172
189
  def file_path(path)
@@ -175,25 +192,73 @@ module ZendeskAppsSupport
175
192
 
176
193
  private
177
194
 
178
- def compiled_templates(app_id, asset_url_prefix)
179
- compiled_css = ZendeskAppsSupport::StylesheetCompiler.new(DEFAULT_SCSS + customer_css, app_id, asset_url_prefix).compile
180
-
181
- templates = begin
182
- Dir["#{root}/templates/*.hdbs"].inject({}) do |h, file|
183
- str = File.read(file)
184
- str.chomp!
185
- h[File.basename(file, File.extname(file))] = str
186
- h
187
- end
195
+ def templates
196
+ templates_dir = File.join(@root, 'templates')
197
+ Dir["#{templates_dir}/*.hdbs"].inject({}) do |memo, file|
198
+ str = File.read(file)
199
+ str.chomp!
200
+ memo[File.basename(file, File.extname(file))] = str
201
+ memo
188
202
  end
203
+ end
189
204
 
190
- layout = templates['layout'] || DEFAULT_LAYOUT.result
205
+ def translations_for(locale)
206
+ trans = translations
207
+ return trans[locale] if trans[locale]
208
+ trans[self.manifest_json['defaultLocale']]
209
+ end
191
210
 
192
- templates.tap do |templates|
193
- templates['layout'] = "<style>\n#{compiled_css}</style>\n#{layout}"
211
+ def translations
212
+ return @translations if @is_cached && @translations
213
+
214
+ @translations = begin
215
+ translation_dir = File.join(@root, 'translations')
216
+ return {} unless File.directory?(translation_dir)
217
+
218
+ locale_path = "#{translation_dir}/#{self.manifest_json['defaultLocale']}.json"
219
+ default_translations = process_translations(locale_path)
220
+
221
+ Dir["#{translation_dir}/*.json"].inject({}) do |memo, path|
222
+ locale = File.basename(path, File.extname(path))
223
+
224
+ locale_translations = if locale == self.manifest_json['defaultLocale']
225
+ default_translations
226
+ else
227
+ deep_merge_hash(default_translations, process_translations(path))
228
+ end
229
+
230
+ memo[locale] = locale_translations
231
+ memo
232
+ end
194
233
  end
195
234
  end
196
235
 
236
+ def process_translations(locale_path)
237
+ translations = File.exist?(locale_path) ? JSON.parse(File.read(locale_path)) : {}
238
+ translations['app'].delete('package') if translations.has_key?('app')
239
+ remove_zendesk_keys(translations)
240
+ end
241
+
242
+ def has_lib_js?
243
+ lib_files.any?
244
+ end
245
+
246
+ def has_manifest?
247
+ file_exists?('manifest.json')
248
+ end
249
+
250
+ def has_requirements?
251
+ file_exists?('requirements.json')
252
+ end
253
+
254
+ def has_banner?
255
+ file_exists?('assets/banner.png')
256
+ end
257
+
258
+ def app_js
259
+ read_file('app.js')
260
+ end
261
+
197
262
  def non_tmp_files
198
263
  files = []
199
264
  Dir[root.join('**/**')].each do |f|
@@ -205,18 +270,40 @@ module ZendeskAppsSupport
205
270
  files
206
271
  end
207
272
 
273
+ def commonjs_modules
274
+ return {} unless has_lib_js?
275
+
276
+ lib_files.each_with_object({}) do |file, modules|
277
+ name = file.relative_path.gsub(/^lib\//, '')
278
+ content = file.read
279
+ modules[name] = content
280
+ end
281
+ end
282
+
208
283
  def file_exists?(path)
209
284
  File.exist?(file_path(path))
210
285
  end
211
286
 
287
+ def deep_merge_hash(h, another_h)
288
+ result_h = h.dup
289
+ another_h.each do |key, value|
290
+ if h.has_key?(key) && h[key].is_a?(Hash) && value.is_a?(Hash)
291
+ result_h[key] = deep_merge_hash(h[key], value)
292
+ else
293
+ result_h[key] = value
294
+ end
295
+ end
296
+ result_h
297
+ end
298
+
212
299
  def read_file(path)
213
300
  File.read(file_path(path))
214
301
  end
215
302
 
216
- def read_json(path, symbolize_names = true)
303
+ def read_json(path)
217
304
  file = read_file(path)
218
305
  unless file.nil?
219
- JSON.parse(read_file(path), symbolize_names: symbolize_names)
306
+ JSON.parse(read_file(path))
220
307
  end
221
308
  end
222
309
  end
@@ -29,8 +29,6 @@ module ZendeskAppsSupport
29
29
  errors << name_as_parameter_name_error(manifest)
30
30
 
31
31
  if manifest['requirementsOnly']
32
- package.requirements_only = true
33
-
34
32
  errors << ban_location(manifest)
35
33
  errors << ban_framework_version(manifest)
36
34
  else
@@ -0,0 +1,20 @@
1
+ module ZendeskAppsSupport
2
+ module Validations
3
+ module Marketplace
4
+ class << self
5
+ def call(package)
6
+ [no_symlinks(package.root)].compact
7
+ end
8
+
9
+ private
10
+
11
+ def no_symlinks(path)
12
+ if Dir["#{path}/**/{*,.*}"].any? { |f| File.symlink?(f) }
13
+ return ValidationError.new(:symlink_in_zip)
14
+ end
15
+ nil
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -24,7 +24,7 @@ module ZendeskAppsSupport
24
24
  app = package.files.find { |file| file.relative_path == 'app.js' }
25
25
  files = package.lib_files << app
26
26
 
27
- if package.requirements_only
27
+ if package.manifest_json['requirementsOnly']
28
28
  return app ? [ValidationError.new(:no_app_js_required)] : []
29
29
  end
30
30
 
@@ -5,7 +5,7 @@ module ZendeskAppsSupport
5
5
  module Stylesheets
6
6
  class << self
7
7
  def call(package)
8
- if css_error = validate_styles(package.customer_css)
8
+ if css_error = validate_styles(package.app_css)
9
9
  [css_error]
10
10
  else
11
11
  []
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module ZendeskAppsSupport
4
4
  module Validations
5
- class ValidationError
5
+ class ValidationError < StandardError
6
6
  KEY_PREFIX = 'txt.apps.admin.error.app_build.'.freeze
7
7
 
8
8
  class DeserializationError < StandardError
@@ -6,6 +6,8 @@ module ZendeskAppsSupport
6
6
  autoload :BuildTranslation, 'zendesk_apps_support/build_translation'
7
7
  autoload :I18n, 'zendesk_apps_support/i18n'
8
8
  autoload :Package, 'zendesk_apps_support/package'
9
+ autoload :Installed, 'zendesk_apps_support/installed'
10
+ autoload :Installation, 'zendesk_apps_support/installation'
9
11
  autoload :AppRequirement, 'zendesk_apps_support/app_requirement'
10
12
  autoload :AppVersion, 'zendesk_apps_support/app_version'
11
13
  autoload :StylesheetCompiler, 'zendesk_apps_support/stylesheet_compiler'
@@ -13,6 +15,7 @@ module ZendeskAppsSupport
13
15
  module Validations
14
16
  autoload :ValidationError, 'zendesk_apps_support/validations/validation_error'
15
17
  autoload :Manifest, 'zendesk_apps_support/validations/manifest'
18
+ autoload :Marketplace, 'zendesk_apps_support/validations/marketplace'
16
19
  autoload :Source, 'zendesk_apps_support/validations/source'
17
20
  autoload :Templates, 'zendesk_apps_support/validations/templates'
18
21
  autoload :Translations, 'zendesk_apps_support/validations/translations'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_apps_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James A. Rosen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-06 00:00:00.000000000 Z
14
+ date: 2015-11-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n
@@ -156,15 +156,19 @@ files:
156
156
  - lib/zendesk_apps_support/app_version.rb
157
157
  - lib/zendesk_apps_support/assets/default_styles.scss
158
158
  - lib/zendesk_apps_support/assets/default_template.html.erb
159
+ - lib/zendesk_apps_support/assets/installed.js.erb
159
160
  - lib/zendesk_apps_support/assets/src.js.erb
160
161
  - lib/zendesk_apps_support/build_translation.rb
161
162
  - lib/zendesk_apps_support/engine.rb
162
163
  - lib/zendesk_apps_support/i18n.rb
164
+ - lib/zendesk_apps_support/installation.rb
165
+ - lib/zendesk_apps_support/installed.rb
163
166
  - lib/zendesk_apps_support/package.rb
164
167
  - lib/zendesk_apps_support/sass_functions.rb
165
168
  - lib/zendesk_apps_support/stylesheet_compiler.rb
166
169
  - lib/zendesk_apps_support/validations/banner.rb
167
170
  - lib/zendesk_apps_support/validations/manifest.rb
171
+ - lib/zendesk_apps_support/validations/marketplace.rb
168
172
  - lib/zendesk_apps_support/validations/requirements.rb
169
173
  - lib/zendesk_apps_support/validations/source.rb
170
174
  - lib/zendesk_apps_support/validations/stylesheets.rb