@asd20/ui-next 2.2.2 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
1
  import axios from 'axios'
2
2
 
3
+ import { hasSearchProxyRuntime, resolveSearchProxyUrl } from './searchProxyUrl'
4
+ import { normalizeBaseUrl, resolveRuntimeConfigValue } from './runtimeConfig'
5
+
3
6
  /**
4
7
  * Creates a Azure Search payload
5
8
  *
@@ -83,22 +86,58 @@ export default async function queryMessages({
83
86
  organizationIds = [],
84
87
  categories = [],
85
88
  channels = [],
89
+ destinationIds = [],
90
+ destinationTitle = [],
86
91
  tags = [],
92
+ isInLeadershipGroup = false,
87
93
  limit = 5,
88
94
  requireKeywords = false,
89
95
  indexName = 'messages-index',
96
+ requestUrl = '',
97
+ runtimeConfig = null,
98
+ searchKey = '',
99
+ apiVersion = '',
100
+ searchEndpoint = '',
101
+ endpoint = '',
90
102
  }) {
91
- const env = {
92
- searchKey:
93
- process.env.VUE_APP_AZURE_SEARCH_MESSAGES_KEY ||
94
- process.env.GRIDSOME_AZURE_MESSAGES_SEARCH_KEY,
95
- apiVersion:
96
- process.env.VUE_APP_AZURE_SEARCH_API_VERSION ||
97
- process.env.GRIDSOME_AZURE_SEARCH_API_VERSION,
98
- endpoint:
99
- process.env.VUE_APP_AZURE_SEARCH_MESSAGES_ENDPOINT ||
100
- process.env.GRIDSOME_AZURE_MESSAGES_SEARCH_ENDPOINT,
101
- }
103
+ const resolvedSearchKey = resolveRuntimeConfigValue({
104
+ explicitValue: searchKey,
105
+ runtimeConfig,
106
+ runtimeConfigKeys: ['azureSearchMessagesKey', 'azureSearchKey'],
107
+ envKeys: [
108
+ 'VUE_APP_AZURE_SEARCH_MESSAGES_KEY',
109
+ 'GRIDSOME_AZURE_MESSAGES_SEARCH_KEY',
110
+ 'VUE_APP_AZURE_SEARCH_KEY',
111
+ 'GRIDSOME_AZURE_SEARCH_KEY',
112
+ ],
113
+ })
114
+ const resolvedApiVersion = resolveRuntimeConfigValue({
115
+ explicitValue: apiVersion,
116
+ runtimeConfig,
117
+ runtimeConfigKeys: ['azureSearchVersion'],
118
+ envKeys: [
119
+ 'VUE_APP_AZURE_SEARCH_API_VERSION',
120
+ 'GRIDSOME_AZURE_SEARCH_API_VERSION',
121
+ ],
122
+ })
123
+ const resolvedSearchEndpoint = resolveRuntimeConfigValue({
124
+ explicitValue: searchEndpoint || endpoint,
125
+ runtimeConfig,
126
+ runtimeConfigKeys: ['azureSearchMessagesEndpoint', 'azureSearchEndpoint'],
127
+ envKeys: [
128
+ 'VUE_APP_AZURE_SEARCH_MESSAGES_ENDPOINT',
129
+ 'GRIDSOME_AZURE_MESSAGES_SEARCH_ENDPOINT',
130
+ 'VUE_APP_AZURE_SEARCH_ENDPOINT',
131
+ 'GRIDSOME_AZURE_SEARCH_ENDPOINT',
132
+ ],
133
+ })
134
+ const resolvedRequestUrl =
135
+ typeof requestUrl === 'string' && requestUrl.trim()
136
+ ? requestUrl.trim()
137
+ : !resolvedSearchEndpoint &&
138
+ hasSearchProxyRuntime(runtimeConfig)
139
+ ? resolveSearchProxyUrl('messages', runtimeConfig)
140
+ : ''
102
141
 
103
142
  if (!keywords && requireKeywords)
104
143
  return {
@@ -106,29 +145,57 @@ export default async function queryMessages({
106
145
  facets: [],
107
146
  }
108
147
 
109
- let { data } = await axios({
110
- method: 'post',
111
- headers: {
112
- 'api-key': env.searchKey,
113
- },
114
- params: {
115
- 'api-version': env.apiVersion,
116
- },
117
- url: `${env.endpoint}/indexes/${indexName}/docs/search`,
118
- data: Object.assign(
119
- {},
120
- searchPayload({
121
- keywords,
122
- organizationIds,
123
- categories,
124
- channels,
125
- tags,
126
- enableFuzzySearch: true,
127
- limit,
128
- }),
129
- { top: limit }
130
- ),
131
- })
148
+ if (
149
+ !resolvedRequestUrl &&
150
+ (!resolvedSearchEndpoint || !resolvedSearchKey || !resolvedApiVersion)
151
+ ) {
152
+ throw new Error(
153
+ 'Azure Search or proxy configuration is required for queryMessages.'
154
+ )
155
+ }
156
+
157
+ const payload = {
158
+ keywords,
159
+ organizationIds,
160
+ destinationIds,
161
+ destinationTitle,
162
+ categories,
163
+ channels,
164
+ tags,
165
+ isInLeadershipGroup,
166
+ limit,
167
+ indexName,
168
+ }
169
+
170
+ const { data } = resolvedRequestUrl
171
+ ? await axios({
172
+ method: 'post',
173
+ url: resolvedRequestUrl,
174
+ data: payload,
175
+ })
176
+ : await axios({
177
+ method: 'post',
178
+ headers: {
179
+ 'api-key': resolvedSearchKey,
180
+ },
181
+ params: {
182
+ 'api-version': resolvedApiVersion,
183
+ },
184
+ url: `${normalizeBaseUrl(resolvedSearchEndpoint)}/indexes/${indexName}/docs/search`,
185
+ data: Object.assign(
186
+ {},
187
+ searchPayload({
188
+ keywords,
189
+ organizationIds,
190
+ categories,
191
+ channels,
192
+ tags,
193
+ enableFuzzySearch: true,
194
+ limit,
195
+ }),
196
+ { top: limit }
197
+ ),
198
+ })
132
199
 
133
200
  // Return results
134
201
  return {
@@ -1,6 +1,9 @@
1
1
  import axios from 'axios'
2
2
 
3
- const NO_PAGE_RESULTS_FALLBACKS = [
3
+ import { hasSearchProxyRuntime, resolveSearchProxyUrl } from './searchProxyUrl'
4
+ import { resolveRuntimeConfigValue } from './runtimeConfig'
5
+
6
+ export const NO_PAGE_RESULTS_FALLBACKS = [
4
7
  {
5
8
  id: 'calendar',
6
9
  slug: 'calendar',
@@ -106,6 +109,14 @@ export default async function queryPages({
106
109
  keywords = '',
107
110
  top = 25,
108
111
  requireKeywords = false,
112
+ organizations = [],
113
+ requestUrl = '',
114
+ runtimeConfig = null,
115
+ searchEndpoint = '',
116
+ endpoint = '',
117
+ searchKey = '',
118
+ apiVersion = '',
119
+ searchVersion = '',
109
120
  }) {
110
121
  if (!keywords && requireKeywords)
111
122
  return {
@@ -113,26 +124,82 @@ export default async function queryPages({
113
124
  facets: [],
114
125
  }
115
126
 
116
- let { data } = await axios({
117
- method: 'post',
118
- headers: {
119
- 'api-key': process.env.AZURE_SEARCH_KEY,
120
- },
121
- params: {
122
- 'api-version': process.env.AZURE_SEARCH_VERSION,
123
- },
124
- url: `${process.env.AZURE_SEARCH_ENDPOINT}`,
125
- data: Object.assign(
126
- {},
127
- searchPayload({
128
- keywords,
129
- enableFuzzySearch: true,
130
- }),
131
- {
132
- top,
133
- }
134
- ),
127
+ const resolvedSearchKey = resolveRuntimeConfigValue({
128
+ explicitValue: searchKey,
129
+ runtimeConfig,
130
+ runtimeConfigKeys: ['azureSearchKey'],
131
+ envKeys: [
132
+ 'AZURE_SEARCH_KEY',
133
+ 'VUE_APP_AZURE_SEARCH_KEY',
134
+ 'GRIDSOME_AZURE_SEARCH_KEY',
135
+ ],
136
+ })
137
+ const resolvedApiVersion = resolveRuntimeConfigValue({
138
+ explicitValue: apiVersion || searchVersion,
139
+ runtimeConfig,
140
+ runtimeConfigKeys: ['azureSearchVersion'],
141
+ envKeys: [
142
+ 'AZURE_SEARCH_VERSION',
143
+ 'VUE_APP_AZURE_SEARCH_API_VERSION',
144
+ 'GRIDSOME_AZURE_SEARCH_API_VERSION',
145
+ ],
146
+ })
147
+ const resolvedSearchEndpoint = resolveRuntimeConfigValue({
148
+ explicitValue: searchEndpoint || endpoint,
149
+ runtimeConfig,
150
+ runtimeConfigKeys: ['azureSearchEndpoint'],
151
+ envKeys: [
152
+ 'AZURE_SEARCH_ENDPOINT',
153
+ 'VUE_APP_AZURE_SEARCH_ENDPOINT',
154
+ 'GRIDSOME_AZURE_SEARCH_ENDPOINT',
155
+ ],
135
156
  })
157
+ const resolvedRequestUrl =
158
+ typeof requestUrl === 'string' && requestUrl.trim()
159
+ ? requestUrl.trim()
160
+ : !resolvedSearchEndpoint &&
161
+ hasSearchProxyRuntime(runtimeConfig)
162
+ ? resolveSearchProxyUrl('pages', runtimeConfig)
163
+ : ''
164
+
165
+ if (
166
+ !resolvedRequestUrl &&
167
+ (!resolvedSearchEndpoint || !resolvedSearchKey || !resolvedApiVersion)
168
+ ) {
169
+ throw new Error('Azure Search or proxy configuration is required for queryPages.')
170
+ }
171
+
172
+ const { data } = resolvedRequestUrl
173
+ ? await axios({
174
+ method: 'post',
175
+ url: resolvedRequestUrl,
176
+ data: {
177
+ keywords,
178
+ organizations,
179
+ top,
180
+ },
181
+ })
182
+ : await axios({
183
+ method: 'post',
184
+ headers: {
185
+ 'api-key': resolvedSearchKey,
186
+ },
187
+ params: {
188
+ 'api-version': resolvedApiVersion,
189
+ },
190
+ url: `${resolvedSearchEndpoint}`,
191
+ data: Object.assign(
192
+ {},
193
+ searchPayload({
194
+ keywords,
195
+ enableFuzzySearch: true,
196
+ organizations,
197
+ }),
198
+ {
199
+ top,
200
+ }
201
+ ),
202
+ })
136
203
 
137
204
  const pages = Array.isArray(data.value) ? data.value : []
138
205
  const resolvedPages = pages.length
@@ -0,0 +1,80 @@
1
+ function isPlainObject(value) {
2
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
3
+ }
4
+
5
+ function normalizeConfigValue(value) {
6
+ return typeof value === 'string' ? value.trim() : value
7
+ }
8
+
9
+ function hasConfigValue(value) {
10
+ if (typeof value === 'string') {
11
+ return value.trim().length > 0
12
+ }
13
+
14
+ return value !== null && value !== undefined
15
+ }
16
+
17
+ export function resolvePublicRuntimeConfig(runtimeConfig = {}) {
18
+ if (!isPlainObject(runtimeConfig)) {
19
+ return {}
20
+ }
21
+
22
+ if (isPlainObject(runtimeConfig.public)) {
23
+ return runtimeConfig.public
24
+ }
25
+
26
+ return runtimeConfig
27
+ }
28
+
29
+ export function resolveWindowPublicRuntimeConfig() {
30
+ if (typeof window === 'undefined' || !window.__NUXT__) {
31
+ return {}
32
+ }
33
+
34
+ return resolvePublicRuntimeConfig(window.__NUXT__.config)
35
+ }
36
+
37
+ export function resolveRuntimeConfigValue({
38
+ explicitValue = null,
39
+ runtimeConfig = {},
40
+ runtimeConfigKeys = [],
41
+ envKeys = [],
42
+ } = {}) {
43
+ const normalizedExplicitValue = normalizeConfigValue(explicitValue)
44
+ if (hasConfigValue(normalizedExplicitValue)) {
45
+ return normalizedExplicitValue
46
+ }
47
+
48
+ const sources = [
49
+ resolvePublicRuntimeConfig(runtimeConfig),
50
+ resolveWindowPublicRuntimeConfig(),
51
+ ]
52
+
53
+ for (const source of sources) {
54
+ for (const key of runtimeConfigKeys) {
55
+ const candidate = normalizeConfigValue(source[key])
56
+ if (hasConfigValue(candidate)) {
57
+ return candidate
58
+ }
59
+ }
60
+ }
61
+
62
+ if (typeof process !== 'undefined' && process && process.env) {
63
+ for (const key of envKeys) {
64
+ const candidate = normalizeConfigValue(process.env[key])
65
+ if (hasConfigValue(candidate)) {
66
+ return candidate
67
+ }
68
+ }
69
+ }
70
+
71
+ return null
72
+ }
73
+
74
+ export function normalizeBaseUrl(value) {
75
+ if (typeof value !== 'string') {
76
+ return ''
77
+ }
78
+
79
+ return value.trim().replace(/\/+$/, '')
80
+ }
@@ -0,0 +1,43 @@
1
+ import { normalizeBaseUrl, resolveRuntimeConfigValue } from './runtimeConfig'
2
+
3
+ const SEARCH_PROXY_PATHS = Object.freeze({
4
+ messages: '/api/search/messages',
5
+ pages: '/api/search/pages',
6
+ files: '/api/search/files',
7
+ events: '/api/search/events',
8
+ })
9
+
10
+ export function resolveSearchProxyPath(kind) {
11
+ return SEARCH_PROXY_PATHS[kind] || ''
12
+ }
13
+
14
+ export function hasSearchProxyRuntime(runtimeConfig = {}) {
15
+ const functionsEndpoint = resolveRuntimeConfigValue({
16
+ runtimeConfig,
17
+ runtimeConfigKeys: ['functionsEndpoint'],
18
+ envKeys: [],
19
+ })
20
+
21
+ if (functionsEndpoint) {
22
+ return true
23
+ }
24
+
25
+ return typeof window !== 'undefined' && !!window.__NUXT__
26
+ }
27
+
28
+ export function resolveSearchProxyUrl(kind, runtimeConfig = {}) {
29
+ const path = resolveSearchProxyPath(kind)
30
+
31
+ if (!path) {
32
+ throw new Error(`Unknown search proxy kind: ${String(kind)}`)
33
+ }
34
+
35
+ const functionsEndpoint = resolveRuntimeConfigValue({
36
+ runtimeConfig,
37
+ runtimeConfigKeys: ['functionsEndpoint'],
38
+ envKeys: ['FUNCTIONS_ENDPOINT', 'VUE_APP_FUNCTIONS_ENDPOINT'],
39
+ })
40
+ const baseUrl = normalizeBaseUrl(functionsEndpoint)
41
+
42
+ return baseUrl ? `${baseUrl}${path}` : path
43
+ }
@@ -1,14 +1,38 @@
1
1
  import axios from 'axios'
2
2
 
3
+ import { resolveRuntimeConfigValue } from './runtimeConfig'
4
+
3
5
  function issueIsValid(issue) {
4
6
  return !!issue.firstName && !!issue.lastName && !!issue.email && !!issue.issue
5
7
  }
6
8
 
7
- export default async function sendAccessibilityIssue(issue, endpoint, apiKey, authCode) {
9
+ export default async function sendAccessibilityIssue(
10
+ issue,
11
+ endpoint,
12
+ apiKey,
13
+ authCode,
14
+ options = {}
15
+ ) {
8
16
  if (!issueIsValid(issue)) {
9
17
  throw new Error('The issue object is incomplete or invalid.')
10
18
  }
11
19
 
20
+ const resolvedOptions =
21
+ options && typeof options === 'object' && !Array.isArray(options)
22
+ ? options
23
+ : {
24
+ categoryId: options,
25
+ }
26
+ const categoryId = resolveRuntimeConfigValue({
27
+ explicitValue: resolvedOptions.categoryId,
28
+ runtimeConfig: resolvedOptions.runtimeConfig,
29
+ runtimeConfigKeys: ['happyFoxCategoryId'],
30
+ envKeys: ['HAPPYFOX_CATEGORY_ID'],
31
+ })
32
+ if (!categoryId) {
33
+ throw new Error('happyFoxCategoryId is required to send an accessibility issue.')
34
+ }
35
+
12
36
  const payload = {
13
37
  name: `${issue.firstName} ${issue.lastName}`,
14
38
  email: issue.email,
@@ -20,7 +44,7 @@ export default async function sendAccessibilityIssue(issue, endpoint, apiKey, au
20
44
  <p><strong>Mailing Address:</strong> ${issue.address || 'Not provided'}</p>
21
45
  <p><strong>Organization:</strong> ${issue.organization || 'Not provided'}</p>
22
46
  `,
23
- category: Number(process.env.HAPPYFOX_CATEGORY_ID),
47
+ category: Number(categoryId),
24
48
  }
25
49
 
26
50
  try {
@@ -450,6 +450,9 @@ export default {
450
450
  this.desktop = window.innerWidth >= 1024
451
451
  window.addEventListener('resize', this.handleResize)
452
452
  },
453
+ beforeUnmount() {
454
+ window.removeEventListener('resize', this.handleResize)
455
+ },
453
456
  methods: {
454
457
  handleResize() {
455
458
  this.desktop = window.innerWidth >= 1024