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,4 @@
import listChannels from './list-channels/index.js';
import listUsers from './list-users/index.js';
export default [listChannels, listUsers];

View File

@@ -1,4 +0,0 @@
import listChannels from './list-channels';
import listUsers from './list-users';
export default [listChannels, listUsers];

View File

@@ -0,0 +1,43 @@
export default {
name: 'List channels',
key: 'listChannels',
async run($) {
const channels = {
data: [],
error: null,
};
let nextCursor;
do {
const response = await $.http.get('/conversations.list', {
params: {
types: 'public_channel,private_channel',
cursor: nextCursor,
limit: 1000,
},
});
nextCursor = response.data.response_metadata?.next_cursor;
if (response.data.error === 'missing_scope') {
throw new Error(
`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`
);
}
if (response.data.ok === false) {
throw new Error(JSON.stringify(response.data, null, 2));
}
for (const channel of response.data.channels) {
channels.data.push({
value: channel.id,
name: channel.name,
});
}
} while (nextCursor);
return channels;
},
};

View File

@@ -1,65 +0,0 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
type TChannel = {
id: string;
name: string;
}
type TConversationListResponseData = {
channels: TChannel[],
response_metadata?: {
next_cursor: string
};
needed?: string;
error?: string;
ok: boolean;
}
type TResponse = {
data: TConversationListResponseData;
}
export default {
name: 'List channels',
key: 'listChannels',
async run($: IGlobalVariable) {
const channels: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
let nextCursor;
do {
const response: TResponse = await $.http.get('/conversations.list', {
params: {
types: 'public_channel,private_channel',
cursor: nextCursor,
limit: 1000,
}
});
nextCursor = response.data.response_metadata?.next_cursor;
if (response.data.error === 'missing_scope') {
throw new Error(`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`);
}
if (response.data.ok === false) {
throw new Error(JSON.stringify(response.data, null, 2));
}
for (const channel of response.data.channels) {
channels.data.push({
value: channel.id as string,
name: channel.name as string,
});
}
} while (nextCursor);
return channels;
},
};

View File

@@ -0,0 +1,43 @@
export default {
name: 'List users',
key: 'listUsers',
async run($) {
const users = {
data: [],
error: null,
};
let nextCursor;
do {
const response = await $.http.get('/users.list', {
params: {
cursor: nextCursor,
limit: 1000,
},
});
nextCursor = response.data.response_metadata?.next_cursor;
if (response.data.error === 'missing_scope') {
throw new Error(
`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`
);
}
if (response.data.ok === false) {
throw new Error(JSON.stringify(response.data, null, 2));
}
for (const member of response.data.members) {
users.data.push({
value: member.id,
name: member.profile.real_name_normalized,
});
}
} while (nextCursor);
return users;
},
};

View File

@@ -1,66 +0,0 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
type TMember = {
id: string;
profile: {
real_name_normalized: string;
};
}
type TUserListResponseData = {
members: TMember[],
response_metadata?: {
next_cursor: string
};
needed?: string;
error?: string;
ok: boolean;
}
type TResponse = {
data: TUserListResponseData;
}
export default {
name: 'List users',
key: 'listUsers',
async run($: IGlobalVariable) {
const users: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
let nextCursor;
do {
const response: TResponse = await $.http.get('/users.list', {
params: {
cursor: nextCursor,
limit: 1000,
}
});
nextCursor = response.data.response_metadata?.next_cursor;
if (response.data.error === 'missing_scope') {
throw new Error(`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`);
}
if (response.data.ok === false) {
throw new Error(JSON.stringify(response.data, null, 2));
}
for (const member of response.data.members) {
users.data.push({
value: member.id as string,
name: member.profile.real_name_normalized as string,
});
}
} while (nextCursor);
return users;
},
};