@rancher/shell 0.3.3 → 0.3.5

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.
Files changed (249) hide show
  1. package/assets/styles/app.scss +1 -1
  2. package/assets/styles/fonts/_fontstack.scss +11 -11
  3. package/assets/styles/vendor/vue-js-modal.scss +3 -3
  4. package/assets/translations/en-us.yaml +92 -22
  5. package/assets/translations/zh-hans.yaml +84 -15
  6. package/babel.config.js +13 -0
  7. package/chart/gatekeeper.vue +77 -0
  8. package/chart/istio.vue +108 -111
  9. package/chart/logging/index.vue +13 -4
  10. package/chart/monitoring/index.vue +15 -5
  11. package/chart/monitoring/steps/uninstall-v1.vue +2 -2
  12. package/chart/rancher-backup/index.vue +10 -3
  13. package/cloud-credential/aws.vue +1 -1
  14. package/cloud-credential/digitalocean.vue +1 -1
  15. package/cloud-credential/gcp.vue +1 -1
  16. package/cloud-credential/generic.vue +2 -2
  17. package/cloud-credential/linode.vue +1 -1
  18. package/cloud-credential/pnap.vue +1 -1
  19. package/components/ActionMenu.vue +3 -4
  20. package/components/AssignTo.vue +1 -1
  21. package/components/AsyncButton.vue +1 -1
  22. package/components/BannerGraphic.vue +1 -1
  23. package/components/ButtonDropdown.vue +2 -3
  24. package/components/ChartPsp.vue +76 -0
  25. package/components/CruResource.vue +6 -2
  26. package/components/DashboardMetrics.vue +12 -10
  27. package/components/DetailText.vue +1 -1
  28. package/components/DisableAuthProviderModal.vue +1 -1
  29. package/components/EmberPage.vue +1 -1
  30. package/components/EtcdInfoBanner.vue +5 -4
  31. package/components/ExplorerMembers.vue +1 -1
  32. package/components/ExplorerProjectsNamespaces.vue +15 -2
  33. package/components/FileDiff.vue +6 -7
  34. package/components/GrafanaDashboard.vue +18 -21
  35. package/components/LazyImage.vue +10 -12
  36. package/components/LogItem.vue +1 -1
  37. package/components/Markdown.vue +1 -1
  38. package/components/PromptRemove.vue +2 -2
  39. package/components/PromptRestore.vue +1 -1
  40. package/components/ResourceDetail/Masthead.vue +16 -0
  41. package/components/ResourceDetail/index.vue +21 -4
  42. package/components/ResourceList/index.vue +1 -1
  43. package/components/ResourceTable.vue +4 -1
  44. package/components/SingleClusterInfo.vue +2 -2
  45. package/components/SortableTable/THead.vue +1 -1
  46. package/components/SortableTable/index.vue +5 -2
  47. package/components/__tests__/AsyncButton.test.ts +3 -1
  48. package/components/__tests__/ChartPsp.test.ts +75 -0
  49. package/components/__tests__/CruResource.test.ts +3 -1
  50. package/components/auth/Principal.vue +1 -1
  51. package/components/fleet/FleetBundles.vue +3 -1
  52. package/components/fleet/FleetClusters.vue +1 -2
  53. package/components/fleet/FleetIntro.vue +9 -1
  54. package/components/fleet/FleetNoWorkspaces.vue +62 -0
  55. package/components/fleet/FleetSummary.vue +7 -1
  56. package/components/form/LabeledSelect.vue +14 -11
  57. package/components/form/MatchExpressions.vue +17 -2
  58. package/components/form/NameNsDescription.vue +31 -45
  59. package/components/form/ResourceSelector.vue +1 -1
  60. package/components/form/SecretSelector.vue +5 -1
  61. package/components/form/ServiceNameSelect.vue +1 -1
  62. package/components/form/SimpleSecretSelector.vue +9 -9
  63. package/components/form/__tests__/LabeledSelect.test.ts +138 -0
  64. package/components/form/__tests__/NameNsDescription.ts +32 -0
  65. package/components/formatter/InternalExternalIP.vue +6 -0
  66. package/components/formatter/InvolvedObjectLink.vue +54 -0
  67. package/components/formatter/Link.vue +20 -4
  68. package/components/formatter/LinkName.vue +6 -1
  69. package/components/formatter/ServiceTargets.vue +1 -1
  70. package/components/nav/Group.vue +2 -2
  71. package/components/nav/NamespaceFilter.vue +15 -11
  72. package/components/nav/TopLevelMenu.vue +2 -4
  73. package/components/nav/Type.vue +1 -1
  74. package/components/nav/WorkspaceSwitcher.vue +46 -5
  75. package/config/labels-annotations.js +17 -0
  76. package/config/product/auth.js +3 -2
  77. package/config/product/explorer.js +11 -4
  78. package/config/product/fleet.js +2 -0
  79. package/config/router.js +414 -0
  80. package/config/table-headers.js +10 -2
  81. package/config/types.js +11 -8
  82. package/config/uiplugins.js +30 -0
  83. package/content/docs/en-us/whats-new.md +10 -0
  84. package/content/docs/zh-hans/whats-new.md +11 -1
  85. package/core/plugin-helpers.js +64 -61
  86. package/core/plugin-routes.ts +23 -0
  87. package/creators/app/app.package.json +2 -1
  88. package/creators/app/files/.eslintrc.js +1 -1
  89. package/creators/app/files/babel.config.js +1 -18
  90. package/creators/app/files/vue.config.js +7 -0
  91. package/creators/app/init +5 -5
  92. package/creators/pkg/files/.github/workflows/build-extension.yml +111 -0
  93. package/creators/pkg/init +35 -4
  94. package/creators/update/init +1 -1
  95. package/detail/constraints.gatekeeper.sh.constraint.vue +20 -10
  96. package/detail/fleet.cattle.io.gitrepo.vue +19 -11
  97. package/detail/harvesterhci.io.management.cluster.vue +3 -3
  98. package/detail/provisioning.cattle.io.cluster.vue +54 -12
  99. package/detail/workload/index.vue +3 -3
  100. package/dialog/AddClusterMemberDialog.vue +1 -1
  101. package/dialog/AddProjectMemberDialog.vue +2 -2
  102. package/dialog/AddonConfigConfirmationDialog.vue +27 -15
  103. package/dialog/DiagnosticTimingsDialog.vue +1 -1
  104. package/dialog/ForceMachineRemoveDialog.vue +1 -1
  105. package/dialog/GenericPrompt.vue +18 -6
  106. package/dialog/RotateEncryptionKeyDialog.vue +1 -1
  107. package/dialog/SaveAsRKETemplateDialog.vue +1 -1
  108. package/dialog/ScaleMachineDownDialog.vue +1 -1
  109. package/edit/auth/github.vue +8 -8
  110. package/edit/auth/googleoauth.vue +5 -5
  111. package/edit/auth/ldap/index.vue +1 -1
  112. package/edit/auth/oidc.vue +1 -1
  113. package/edit/auth/saml.vue +1 -1
  114. package/edit/cis.cattle.io.clusterscan.vue +1 -1
  115. package/edit/fleet.cattle.io.clustergroup.vue +6 -4
  116. package/edit/fleet.cattle.io.gitrepo.vue +16 -3
  117. package/edit/helm.cattle.io.projecthelmchart.vue +5 -1
  118. package/edit/management.cattle.io.fleetworkspace.vue +141 -6
  119. package/edit/management.cattle.io.podsecurityadmissionconfigurationtemplate.vue +4 -1
  120. package/edit/management.cattle.io.setting.vue +1 -1
  121. package/edit/monitoring.coreos.com.alertmanagerconfig/types/webhook.vue +2 -2
  122. package/edit/monitoring.coreos.com.receiver/tls.vue +18 -18
  123. package/edit/monitoring.coreos.com.receiver/types/webhook.banner.vue +4 -4
  124. package/edit/monitoring.coreos.com.receiver/types/webhook.vue +1 -1
  125. package/edit/namespace.vue +2 -2
  126. package/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue +126 -45
  127. package/edit/networking.k8s.io.networkpolicy/index.vue +1 -1
  128. package/edit/provisioning.cattle.io.cluster/MachinePool.vue +10 -0
  129. package/edit/provisioning.cattle.io.cluster/RegistryConfigs.vue +1 -0
  130. package/edit/provisioning.cattle.io.cluster/__tests__/rke2.test.ts +202 -2
  131. package/edit/provisioning.cattle.io.cluster/rke2.vue +248 -84
  132. package/edit/resources.cattle.io.backup.vue +1 -1
  133. package/edit/service.vue +1 -1
  134. package/edit/storage.k8s.io.storageclass/provisioners/driver.harvesterhci.io.vue +2 -2
  135. package/edit/workload/__tests__/Job.test.ts +3 -1
  136. package/edit/workload/index.vue +8 -3
  137. package/edit/workload/mixins/workload.js +16 -0
  138. package/layouts/default.vue +7 -3
  139. package/list/fleet.cattle.io.bundle.vue +6 -3
  140. package/list/fleet.cattle.io.clusterregistrationtoken.vue +3 -1
  141. package/list/fleet.cattle.io.gitrepo.vue +44 -5
  142. package/list/management.cattle.io.fleetworkspace.vue +45 -0
  143. package/list/node.vue +69 -16
  144. package/list/provisioning.cattle.io.cluster.vue +30 -1
  145. package/machine-config/azure.vue +97 -38
  146. package/middleware/authenticated.js +34 -0
  147. package/mixins/chart.js +73 -2
  148. package/mixins/resource-fetch.js +2 -2
  149. package/models/apps.statefulset.js +28 -0
  150. package/models/cluster/node.js +23 -2
  151. package/models/cluster.x-k8s.io.machine.js +4 -2
  152. package/models/clusterroletemplatebinding.js +7 -0
  153. package/models/constraints.gatekeeper.sh.constraint.js +9 -0
  154. package/models/fleet.cattle.io.cluster.js +19 -10
  155. package/models/fleet.cattle.io.gitrepo.js +7 -2
  156. package/models/management.cattle.io.cluster.js +1 -1
  157. package/models/management.cattle.io.fleetworkspace.js +12 -0
  158. package/models/management.cattle.io.gitreporestriction.js +5 -0
  159. package/models/management.cattle.io.podsecurityadmissionconfigurationtemplate.js +3 -0
  160. package/models/namespace.js +5 -5
  161. package/models/provisioning.cattle.io.cluster.js +7 -5
  162. package/nuxt/App.js +210 -0
  163. package/nuxt/axios.js +186 -0
  164. package/nuxt/client.js +817 -0
  165. package/nuxt/components/nuxt-build-indicator.vue +143 -0
  166. package/nuxt/components/nuxt-child.js +122 -0
  167. package/nuxt/components/nuxt-error.vue +98 -0
  168. package/nuxt/components/nuxt-link.client.js +98 -0
  169. package/nuxt/components/nuxt-link.server.js +16 -0
  170. package/nuxt/components/nuxt-loading.vue +154 -0
  171. package/nuxt/components/nuxt.js +101 -0
  172. package/nuxt/cookie-universal-nuxt.js +9 -0
  173. package/nuxt/empty.js +1 -0
  174. package/nuxt/index.js +365 -0
  175. package/nuxt/jsonp.js +82 -0
  176. package/nuxt/loading.html +39 -0
  177. package/nuxt/middleware.js +12 -0
  178. package/nuxt/mixins/fetch.client.js +90 -0
  179. package/nuxt/mixins/fetch.server.js +69 -0
  180. package/nuxt/portal-vue.js +4 -0
  181. package/nuxt/server.js +312 -0
  182. package/nuxt/store.js +178 -0
  183. package/nuxt/utils.js +630 -0
  184. package/nuxt/views/app.template.html +9 -0
  185. package/nuxt/views/error.html +23 -0
  186. package/package.json +5 -9
  187. package/pages/auth/setup.vue +2 -2
  188. package/pages/c/_cluster/apps/charts/__tests__/install.helper.test.ts +33 -0
  189. package/pages/c/_cluster/apps/charts/chart.vue +4 -4
  190. package/pages/c/_cluster/apps/charts/install.helpers.js +26 -0
  191. package/pages/c/_cluster/apps/charts/install.vue +40 -66
  192. package/pages/c/_cluster/explorer/EventsTable.vue +5 -19
  193. package/pages/c/_cluster/explorer/index.vue +29 -25
  194. package/pages/c/_cluster/explorer/tools/index.vue +8 -8
  195. package/pages/c/_cluster/fleet/index.vue +95 -34
  196. package/pages/c/_cluster/gatekeeper/index.vue +1 -1
  197. package/pages/c/_cluster/istio/index.vue +5 -5
  198. package/pages/c/_cluster/manager/cloudCredential/index.vue +1 -1
  199. package/pages/c/_cluster/monitoring/index.vue +7 -0
  200. package/pages/c/_cluster/uiplugins/InstallDialog.vue +8 -8
  201. package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +20 -7
  202. package/pages/c/_cluster/uiplugins/index.vue +49 -17
  203. package/pages/home.vue +9 -4
  204. package/pages/index.vue +10 -1
  205. package/plugins/clean-html-directive.js +31 -0
  206. package/plugins/dashboard-store/actions.js +32 -9
  207. package/plugins/dashboard-store/mutations.js +5 -2
  208. package/plugins/dashboard-store/resource-class.js +8 -1
  209. package/plugins/steve/mutations.js +3 -2
  210. package/plugins/steve/steve-description-class.js +5 -1
  211. package/plugins/steve/subscribe.js +63 -54
  212. package/plugins/steve-create-worker.js +14 -0
  213. package/promptRemove/management.cattle.io.globalrole.vue +2 -2
  214. package/promptRemove/management.cattle.io.project.vue +2 -2
  215. package/promptRemove/management.cattle.io.roletemplate.vue +2 -2
  216. package/promptRemove/pod.vue +1 -1
  217. package/public/index.html +65 -0
  218. package/rancher-components/components/Banner/Banner.test.ts +9 -1
  219. package/rancher-components/components/Banner/Banner.vue +1 -1
  220. package/rancher-components/components/Form/Checkbox/Checkbox.vue +2 -0
  221. package/rancher-components/components/Form/Radio/RadioButton.vue +1 -1
  222. package/scripts/build-pkg.sh +1 -0
  223. package/scripts/clean +6 -0
  224. package/scripts/extension/bundle +58 -0
  225. package/scripts/extension/helmpatch +89 -0
  226. package/scripts/extension/publish +314 -0
  227. package/scripts/test-plugins-build.sh +4 -0
  228. package/store/__tests__/index.test.ts +110 -0
  229. package/store/index.js +145 -58
  230. package/store/type-map.js +26 -19
  231. package/tsconfig.default.json +36 -0
  232. package/tsconfig.json +24 -0
  233. package/types/shell/index.d.ts +420 -343
  234. package/utils/__tests__/string.test.ts +12 -0
  235. package/utils/auth.js +65 -0
  236. package/utils/monitoring.js +2 -1
  237. package/utils/position.js +5 -8
  238. package/utils/router.scrollBehavior.js +80 -0
  239. package/utils/select.js +1 -3
  240. package/utils/socket.js +1 -0
  241. package/utils/string.js +13 -0
  242. package/utils/time.js +9 -0
  243. package/vue.config.js +679 -0
  244. package/yarn-error.log +196 -0
  245. package/chart/rancher-alerting-drivers.vue +0 -53
  246. package/chart/rancher-gatekeeper.vue +0 -37
  247. package/creators/app/files/nuxt.config.js +0 -6
  248. package/models/management.cattle.io.podsecurityadmissionconfigurationtemplate.ts +0 -4
  249. package/nuxt.config.js +0 -798
package/nuxt/App.js ADDED
@@ -0,0 +1,210 @@
1
+ import Vue from 'vue'
2
+ import { decode, parsePath, withoutBase, withoutTrailingSlash, normalizeURL } from 'ufo'
3
+
4
+ import { getMatchedComponentsInstances, getChildrenComponentInstancesUsingFetch, promisify, globalHandleError, urlJoin, sanitizeComponent } from './utils'
5
+ import NuxtError from '../layouts/error.vue'
6
+ import NuxtLoading from '../components/nav/GlobalLoading.vue'
7
+ import NuxtBuildIndicator from './components/nuxt-build-indicator'
8
+
9
+ import '../assets/styles/app.scss'
10
+
11
+ import _77180f1e from '../layouts/blank.vue'
12
+ import _6f6c098b from '../layouts/default.vue'
13
+ import _2d2495d5 from '../layouts/home.vue'
14
+ import _77dd5794 from '../layouts/plain.vue'
15
+ import _44002f80 from '../layouts/unauthenticated.vue'
16
+
17
+ const layouts = { "_blank": sanitizeComponent(_77180f1e),"_default": sanitizeComponent(_6f6c098b),"_home": sanitizeComponent(_2d2495d5),"_plain": sanitizeComponent(_77dd5794),"_unauthenticated": sanitizeComponent(_44002f80) }
18
+
19
+ export default {
20
+ render (h, props) {
21
+ const loadingEl = h('NuxtLoading', { ref: 'loading' })
22
+
23
+ const layoutEl = h(this.layout || 'nuxt')
24
+ const templateEl = h('div', {
25
+ domProps: {
26
+ id: '__layout'
27
+ },
28
+ key: this.layoutName
29
+ }, [layoutEl])
30
+
31
+ const transitionEl = h('transition', {
32
+ props: {
33
+ name: 'layout',
34
+ mode: 'out-in'
35
+ },
36
+ on: {
37
+ beforeEnter (el) {
38
+ // Ensure to trigger scroll event after calling scrollBehavior
39
+ window.$nuxt.$nextTick(() => {
40
+ window.$nuxt.$emit('triggerScroll')
41
+ })
42
+ }
43
+ }
44
+ }, [templateEl])
45
+
46
+ return h('div', {
47
+ domProps: {
48
+ id: '__nuxt'
49
+ }
50
+ }, [
51
+ loadingEl,
52
+ //h(NuxtBuildIndicator), // The build indicator doesn't work as is right now and emits an error in the console so I'm leaving it out for now
53
+ transitionEl
54
+ ])
55
+ },
56
+
57
+ data: () => ({
58
+ isOnline: true,
59
+
60
+ layout: null,
61
+ layoutName: '',
62
+
63
+ nbFetching: 0
64
+ }),
65
+
66
+ beforeCreate () {
67
+ Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
68
+ },
69
+ created () {
70
+ // Add this.$nuxt in child instances
71
+ this.$root.$options.$nuxt = this
72
+
73
+ if (process.client) {
74
+ // add to window so we can listen when ready
75
+ window.$nuxt = this
76
+
77
+ this.refreshOnlineStatus()
78
+ // Setup the listeners
79
+ window.addEventListener('online', this.refreshOnlineStatus)
80
+ window.addEventListener('offline', this.refreshOnlineStatus)
81
+ }
82
+ // Add $nuxt.error()
83
+ this.error = this.nuxt.error
84
+ // Add $nuxt.context
85
+ this.context = this.$options.context
86
+ },
87
+
88
+ async mounted () {
89
+ this.$loading = this.$refs.loading
90
+ },
91
+
92
+ watch: {
93
+ 'nuxt.err': 'errorChanged'
94
+ },
95
+
96
+ computed: {
97
+ isOffline () {
98
+ return !this.isOnline
99
+ },
100
+
101
+ isFetching () {
102
+ return this.nbFetching > 0
103
+ },
104
+ },
105
+
106
+ methods: {
107
+ refreshOnlineStatus () {
108
+ if (process.client) {
109
+ if (typeof window.navigator.onLine === 'undefined') {
110
+ // If the browser doesn't support connection status reports
111
+ // assume that we are online because most apps' only react
112
+ // when they now that the connection has been interrupted
113
+ this.isOnline = true
114
+ } else {
115
+ this.isOnline = window.navigator.onLine
116
+ }
117
+ }
118
+ },
119
+
120
+ async refresh () {
121
+ const pages = getMatchedComponentsInstances(this.$route)
122
+
123
+ if (!pages.length) {
124
+ return
125
+ }
126
+ this.$loading.start()
127
+
128
+ const promises = pages.map((page) => {
129
+ const p = []
130
+
131
+ // Old fetch
132
+ if (page.$options.fetch && page.$options.fetch.length) {
133
+ p.push(promisify(page.$options.fetch, this.context))
134
+ }
135
+ if (page.$fetch) {
136
+ p.push(page.$fetch())
137
+ } else {
138
+ // Get all component instance to call $fetch
139
+ for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) {
140
+ p.push(component.$fetch())
141
+ }
142
+ }
143
+
144
+ if (page.$options.asyncData) {
145
+ p.push(
146
+ promisify(page.$options.asyncData, this.context)
147
+ .then((newData) => {
148
+ for (const key in newData) {
149
+ Vue.set(page.$data, key, newData[key])
150
+ }
151
+ })
152
+ )
153
+ }
154
+
155
+ return Promise.all(p)
156
+ })
157
+ try {
158
+ await Promise.all(promises)
159
+ } catch (error) {
160
+ this.$loading.fail(error)
161
+ globalHandleError(error)
162
+ this.error(error)
163
+ }
164
+ this.$loading.finish()
165
+ },
166
+ errorChanged () {
167
+ if (this.nuxt.err) {
168
+ if (this.$loading) {
169
+ if (this.$loading.fail) {
170
+ this.$loading.fail(this.nuxt.err)
171
+ }
172
+ if (this.$loading.finish) {
173
+ this.$loading.finish()
174
+ }
175
+ }
176
+
177
+ let errorLayout = (NuxtError.options || NuxtError).layout;
178
+
179
+ if (typeof errorLayout === 'function') {
180
+ errorLayout = errorLayout(this.context)
181
+ }
182
+
183
+ this.setLayout(errorLayout)
184
+ }
185
+ },
186
+
187
+ setLayout (layout) {
188
+ if(layout && typeof layout !== 'string') {
189
+ throw new Error('[nuxt] Avoid using non-string value as layout property.')
190
+ }
191
+
192
+ if (!layout || !layouts['_' + layout]) {
193
+ layout = 'default'
194
+ }
195
+ this.layoutName = layout
196
+ this.layout = layouts['_' + layout]
197
+ return this.layout
198
+ },
199
+ loadLayout (layout) {
200
+ if (!layout || !layouts['_' + layout]) {
201
+ layout = 'default'
202
+ }
203
+ return Promise.resolve(layouts['_' + layout])
204
+ },
205
+ },
206
+
207
+ components: {
208
+ NuxtLoading
209
+ }
210
+ }
package/nuxt/axios.js ADDED
@@ -0,0 +1,186 @@
1
+ import Axios from 'axios'
2
+ import defu from 'defu'
3
+ import axiosRetry from 'axios-retry'
4
+
5
+ // Axios.prototype cannot be modified
6
+ const axiosExtra = {
7
+ setBaseURL (baseURL) {
8
+ this.defaults.baseURL = baseURL
9
+ },
10
+ setHeader (name, value, scopes = 'common') {
11
+ for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
12
+ if (!value) {
13
+ delete this.defaults.headers[scope][name];
14
+ return
15
+ }
16
+ this.defaults.headers[scope][name] = value
17
+ }
18
+ },
19
+ setToken (token, type, scopes = 'common') {
20
+ const value = !token ? null : (type ? type + ' ' : '') + token
21
+ this.setHeader('Authorization', value, scopes)
22
+ },
23
+ onRequest(fn) {
24
+ this.interceptors.request.use(config => fn(config) || config)
25
+ },
26
+ onResponse(fn) {
27
+ this.interceptors.response.use(response => fn(response) || response)
28
+ },
29
+ onRequestError(fn) {
30
+ this.interceptors.request.use(undefined, error => fn(error) || Promise.reject(error))
31
+ },
32
+ onResponseError(fn) {
33
+ this.interceptors.response.use(undefined, error => fn(error) || Promise.reject(error))
34
+ },
35
+ onError(fn) {
36
+ this.onRequestError(fn)
37
+ this.onResponseError(fn)
38
+ },
39
+ create(options) {
40
+ return createAxiosInstance(defu(options, this.defaults))
41
+ }
42
+ }
43
+
44
+ // Request helpers ($get, $post, ...)
45
+ for (let method of ['request', 'delete', 'get', 'head', 'options', 'post', 'put', 'patch']) {
46
+ axiosExtra['$' + method] = function () { return this[method].apply(this, arguments).then(res => res && res.data) }
47
+ }
48
+
49
+ const extendAxiosInstance = axios => {
50
+ for (let key in axiosExtra) {
51
+ axios[key] = axiosExtra[key].bind(axios)
52
+ }
53
+ }
54
+
55
+ const createAxiosInstance = axiosOptions => {
56
+ // Create new axios instance
57
+ const axios = Axios.create(axiosOptions)
58
+ axios.CancelToken = Axios.CancelToken
59
+ axios.isCancel = Axios.isCancel
60
+
61
+ // Extend axios proto
62
+ extendAxiosInstance(axios)
63
+
64
+ // Setup interceptors
65
+
66
+ setupProgress(axios)
67
+ axiosRetry(axios, {"retries":0})
68
+
69
+ return axios
70
+ }
71
+
72
+ const setupProgress = (axios) => {
73
+ if (process.server) {
74
+ return
75
+ }
76
+
77
+ // A noop loading inteterface for when $nuxt is not yet ready
78
+ const noopLoading = {
79
+ finish: () => { },
80
+ start: () => { },
81
+ fail: () => { },
82
+ set: () => { }
83
+ }
84
+
85
+ const $loading = () => {
86
+ const $nuxt = typeof window !== 'undefined' && window['$nuxt']
87
+ return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
88
+ }
89
+
90
+ let currentRequests = 0
91
+
92
+ axios.onRequest(config => {
93
+ if (config && config.progress === false) {
94
+ return
95
+ }
96
+
97
+ currentRequests++
98
+ })
99
+
100
+ axios.onResponse(response => {
101
+ if (response && response.config && response.config.progress === false) {
102
+ return
103
+ }
104
+
105
+ currentRequests--
106
+ if (currentRequests <= 0) {
107
+ currentRequests = 0
108
+ $loading().finish()
109
+ }
110
+ })
111
+
112
+ axios.onError(error => {
113
+ if (error && error.config && error.config.progress === false) {
114
+ return
115
+ }
116
+
117
+ currentRequests--
118
+
119
+ if (Axios.isCancel(error)) {
120
+ return
121
+ }
122
+
123
+ $loading().fail()
124
+ $loading().finish()
125
+ })
126
+
127
+ const onProgress = e => {
128
+ if (!currentRequests) {
129
+ return
130
+ }
131
+ const progress = ((e.loaded * 100) / (e.total * currentRequests))
132
+ $loading().set(Math.min(100, progress))
133
+ }
134
+
135
+ axios.defaults.onUploadProgress = onProgress
136
+ axios.defaults.onDownloadProgress = onProgress
137
+ }
138
+
139
+ export default (ctx, inject) => {
140
+ // runtimeConfig
141
+ const runtimeConfig = ctx.$config && ctx.$config.axios || {}
142
+ // baseURL
143
+ const baseURL = process.browser
144
+ ? (runtimeConfig.browserBaseURL || runtimeConfig.baseURL || '/')
145
+ : (runtimeConfig.baseURL || process.env._AXIOS_BASE_URL_ || 'https://localhost:8005/')
146
+
147
+ // Create fresh objects for all default header scopes
148
+ // Axios creates only one which is shared across SSR requests!
149
+ // https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
150
+ const headers = {
151
+ "common": {
152
+ "Accept": "application/json, text/plain, */*"
153
+ },
154
+ "delete": {},
155
+ "get": {},
156
+ "head": {},
157
+ "post": {},
158
+ "put": {},
159
+ "patch": {}
160
+ }
161
+
162
+ const axiosOptions = {
163
+ baseURL,
164
+ headers
165
+ }
166
+
167
+ // Proxy SSR request headers headers
168
+ if (process.server && ctx.req && ctx.req.headers) {
169
+ const reqHeaders = { ...ctx.req.headers }
170
+ for (let h of ["accept","host","cf-ray","cf-connecting-ip","content-length","content-md5","content-type"]) {
171
+ delete reqHeaders[h]
172
+ }
173
+ axiosOptions.headers.common = { ...reqHeaders, ...axiosOptions.headers.common }
174
+ }
175
+
176
+ if (process.server) {
177
+ // Don't accept brotli encoding because Node can't parse it
178
+ axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate'
179
+ }
180
+
181
+ const axios = createAxiosInstance(axiosOptions)
182
+
183
+ // Inject axios to the context as $axios
184
+ ctx.$axios = axios
185
+ inject('axios', axios)
186
+ }