feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -0,0 +1,3 @@
import sendMessage from './send-message/index.js';
export default [sendMessage];

View File

@@ -1,3 +0,0 @@
import sendMessage from './send-message';
export default [sendMessage];

View File

@@ -1,5 +1,5 @@
import qs from 'qs';
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Send message',
@@ -9,7 +9,7 @@ export default defineAction({
{
label: 'Topic',
key: 'topic',
type: 'string' as const,
type: 'string',
required: true,
description: 'Target topic name.',
variables: true,
@@ -17,15 +17,16 @@ export default defineAction({
{
label: 'Message body',
key: 'message',
type: 'string' as const,
type: 'string',
required: true,
description: 'Message body to be sent, set to triggered if empty or not passed.',
description:
'Message body to be sent, set to triggered if empty or not passed.',
variables: true,
},
{
label: 'Title',
key: 'title',
type: 'string' as const,
type: 'string',
required: false,
description: 'Message title.',
variables: true,
@@ -33,7 +34,7 @@ export default defineAction({
{
label: 'Email',
key: 'email',
type: 'string' as const,
type: 'string',
required: false,
description: 'E-mail address for e-mail notifications.',
variables: true,
@@ -41,7 +42,7 @@ export default defineAction({
{
label: 'Click URL',
key: 'click',
type: 'string' as const,
type: 'string',
required: false,
description: 'Website opened when notification is clicked.',
variables: true,
@@ -49,7 +50,7 @@ export default defineAction({
{
label: 'Attach file by URL',
key: 'attach',
type: 'string' as const,
type: 'string',
required: false,
description: 'URL of an attachment.',
variables: true,
@@ -57,7 +58,7 @@ export default defineAction({
{
label: 'Filename',
key: 'filename',
type: 'string' as const,
type: 'string',
required: false,
description: 'File name of the attachment.',
variables: true,
@@ -65,24 +66,17 @@ export default defineAction({
{
label: 'Delay',
key: 'delay',
type: 'string' as const,
type: 'string',
required: false,
description: 'Timestamp or duration for delayed delivery. For example, 30min or 9am.',
description:
'Timestamp or duration for delayed delivery. For example, 30min or 9am.',
variables: true,
},
],
async run($) {
const {
topic,
message,
title,
email,
click,
attach,
filename,
delay
} = $.step.parameters;
const { topic, message, title, email, click, attach, filename, delay } =
$.step.parameters;
const payload = {
topic,
message,
@@ -91,7 +85,7 @@ export default defineAction({
click,
attach,
filename,
delay
delay,
};
const response = await $.http.post('/', payload);

View File

@@ -1,12 +1,12 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
export default {
fields: [
{
key: 'serverUrl',
label: 'Server URL',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: 'https://ntfy.sh',
@@ -17,22 +17,24 @@ export default {
{
key: 'username',
label: 'Username',
type: 'string' as const,
type: 'string',
required: false,
readOnly: false,
placeholder: null,
clickToCopy: false,
description: 'You may need to provide your username if your installation requires authentication.',
description:
'You may need to provide your username if your installation requires authentication.',
},
{
key: 'password',
label: 'Password',
type: 'string' as const,
type: 'string',
required: false,
readOnly: false,
placeholder: null,
clickToCopy: false,
description: 'You may need to provide your password if your installation requires authentication.',
description:
'You may need to provide your password if your installation requires authentication.',
},
],

View File

@@ -0,0 +1,8 @@
import verifyCredentials from './verify-credentials.js';
const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,9 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,11 +1,9 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
const verifyCredentials = async ($) => {
await $.http.post('/', { topic: 'automatisch' });
let screenName = $.auth.data.serverUrl;
if ($.auth.data.username) {
screenName = `${$.auth.data.username} @ ${screenName}`
screenName = `${$.auth.data.username} @ ${screenName}`;
}
await $.auth.set({

View File

@@ -0,0 +1,16 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data.serverUrl) {
requestConfig.baseURL = $.auth.data.serverUrl;
}
if ($.auth.data?.username && $.auth.data?.password) {
requestConfig.auth = {
username: $.auth.data.username,
password: $.auth.data.password,
};
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -1,18 +0,0 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if ($.auth.data.serverUrl) {
requestConfig.baseURL = $.auth.data.serverUrl as string;
}
if ($.auth.data?.username && $.auth.data?.password) {
requestConfig.auth = {
username: $.auth.data.username as string,
password: $.auth.data.password as string,
}
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -1,7 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import actions from './actions';
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import actions from './actions/index.js';
export default defineApp({
name: 'Ntfy',