aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workflowengine/src/helpers')
-rw-r--r--apps/workflowengine/src/helpers/api.js17
-rw-r--r--apps/workflowengine/src/helpers/validators.js38
-rw-r--r--apps/workflowengine/src/helpers/window.js30
3 files changed, 85 insertions, 0 deletions
diff --git a/apps/workflowengine/src/helpers/api.js b/apps/workflowengine/src/helpers/api.js
new file mode 100644
index 00000000000..c91bbb5f75c
--- /dev/null
+++ b/apps/workflowengine/src/helpers/api.js
@@ -0,0 +1,17 @@
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { loadState } from '@nextcloud/initial-state'
+import { generateOcsUrl } from '@nextcloud/router'
+
+const scopeValue = loadState('workflowengine', 'scope') === 0 ? 'global' : 'user'
+
+const getApiUrl = (url) => {
+ return generateOcsUrl('apps/workflowengine/api/v1/workflows/{scopeValue}', { scopeValue }) + url + '?format=json'
+}
+
+export {
+ getApiUrl,
+}
diff --git a/apps/workflowengine/src/helpers/validators.js b/apps/workflowengine/src/helpers/validators.js
new file mode 100644
index 00000000000..0f2ca9e41b7
--- /dev/null
+++ b/apps/workflowengine/src/helpers/validators.js
@@ -0,0 +1,38 @@
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+const regexRegex = /^\/(.*)\/([gui]{0,3})$/
+const regexIPv4 = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[1-2][0-9]|[1-9])$/
+const regexIPv6 = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9])$/
+
+const validateRegex = function(string) {
+ if (!string) {
+ return false
+ }
+ return regexRegex.exec(string) !== null
+}
+
+const validateIPv4 = function(string) {
+ if (!string) {
+ return false
+ }
+ return regexIPv4.exec(string) !== null
+}
+
+const validateIPv6 = function(string) {
+ if (!string) {
+ return false
+ }
+ return regexIPv6.exec(string) !== null
+}
+
+const stringValidator = (check) => {
+ if (check.operator === 'matches' || check.operator === '!matches') {
+ return validateRegex(check.value)
+ }
+ return true
+}
+
+export { validateRegex, stringValidator, validateIPv4, validateIPv6 }
diff --git a/apps/workflowengine/src/helpers/window.js b/apps/workflowengine/src/helpers/window.js
new file mode 100644
index 00000000000..9538c4706d0
--- /dev/null
+++ b/apps/workflowengine/src/helpers/window.js
@@ -0,0 +1,30 @@
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import wrap from '@vue/web-component-wrapper'
+import Vue from 'vue'
+
+/**
+ *
+ * @param VueComponent {Object} The Vue component to turn into a Web Components custom element.
+ * @param customElementId {string} The element name, it must be unique. Recommended pattern oca-$appid-(checks|operations)-$use_case, example: oca-my_app-checks-request_user_agent
+ */
+function registerCustomElement(VueComponent, customElementId) {
+ const WrappedComponent = wrap(Vue, VueComponent)
+ if (window.customElements.get(customElementId)) {
+ console.error('Custom element with ID ' + customElementId + ' is already defined!')
+ throw new Error('Custom element with ID ' + customElementId + ' is already defined!')
+ }
+ window.customElements.define(customElementId, WrappedComponent)
+
+ // In Vue 2, wrap doesn't support disabling shadow :(
+ // Disable with a hack
+ Object.defineProperty(WrappedComponent.prototype, 'attachShadow', { value() { return this } })
+ Object.defineProperty(WrappedComponent.prototype, 'shadowRoot', { get() { return this } })
+
+ return customElementId
+}
+
+export { registerCustomElement }