kosmic 0.0.1 → 0.0.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kosmic",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A highly opinionated and strongly typed Koa web and api template.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/spence-s/kosmic/issues"
@@ -41,7 +41,7 @@
41
41
  "@fullhuman/postcss-purgecss": "^8.0.0",
42
42
  "@google/genai": "^1.50.1",
43
43
  "@kosmic/auth": "^0.0.1",
44
- "@kosmic/cli": "^0.0.1",
44
+ "@kosmic/cli": "^0.0.2",
45
45
  "@kosmic/config": "^0.0.1",
46
46
  "@kosmic/core": "^0.0.1",
47
47
  "@kosmic/db": "^0.0.1",
package/src/server.ts CHANGED
@@ -7,5 +7,3 @@ export const kosmicServer = new KosmicServer({
7
7
  sessionStore,
8
8
  passport,
9
9
  });
10
-
11
- export const getServer = (): KosmicServer => kosmicServer;
@@ -34,8 +34,7 @@ await describe('server integration', async () => {
34
34
 
35
35
  before(async () => {
36
36
  await migrator.migrateToLatest();
37
- const {getServer} = await import('../src/server.ts');
38
- const kosmicServer = getServer();
37
+ const {kosmicServer} = await import('../src/server.ts');
39
38
  server = await kosmicServer.listen(4567);
40
39
  });
41
40
 
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-await-in-loop */
3
- import process from 'node:process';
4
- import previewEmail from 'preview-email';
5
- import nodemailer from 'nodemailer';
6
- import { config } from '@kosmic/config';
7
- import { db } from '#db/index.js';
8
- import { jobsLogger as logger } from '#utils/logger.js';
9
- logger.info('Starting emails job');
10
- const transport = nodemailer.createTransport(config.nodeMailer);
11
- const unsentEmails = await db
12
- .selectFrom('emails')
13
- .selectAll()
14
- .where('sent_at', 'is', null)
15
- .execute();
16
- for (const email of unsentEmails) {
17
- logger.debug({ email }, 'Sending email');
18
- const { id, to, from, subject, html, text } = email;
19
- const message = {
20
- to: to ?? '',
21
- from: from ?? '',
22
- subject: subject ?? '',
23
- html: html ?? '',
24
- text: text ?? '',
25
- attachments: [],
26
- };
27
- try {
28
- await previewEmail(message);
29
- await transport.sendMail(message);
30
- await db
31
- .updateTable('emails')
32
- .where('id', '=', id)
33
- .set({
34
- sent_at: new Date(),
35
- status: 'sent',
36
- })
37
- .execute();
38
- logger.info({ id }, 'Email sent successfully');
39
- }
40
- catch (error) {
41
- await db
42
- .updateTable('emails')
43
- .where('id', '=', id)
44
- .set({
45
- sent_at: new Date(),
46
- status: 'failed',
47
- })
48
- .execute();
49
- logger.error(error, 'Error sending email');
50
- }
51
- }
52
- logger.info('Emails job completed successfully');
53
- process.exit(0);
54
- //# sourceMappingURL=emails.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emails.js","sourceRoot":"","sources":["../../../src/jobs/emails.ts"],"names":[],"mappings":";AACA,qCAAqC;AACrC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EAAC,UAAU,IAAI,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAEtD,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAEnC,MAAM,SAAS,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAEhE,MAAM,YAAY,GAAG,MAAM,EAAE;KAC1B,UAAU,CAAC,QAAQ,CAAC;KACpB,SAAS,EAAE;KACX,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC;KAC5B,OAAO,EAAE,CAAC;AAEb,KAAK,MAAM,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,CAAC,CAAC;AAEjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
package/dist/src/jobs.js DELETED
@@ -1,29 +0,0 @@
1
- import process from 'node:process';
2
- import { CronJob } from 'cron';
3
- import { execa } from 'execa';
4
- import { logger as serverLogger } from '#utils/logger.js';
5
- const logger = serverLogger.child({
6
- name: '~jobs~',
7
- });
8
- const $ = execa({ stdio: 'inherit', cwd: process.cwd() });
9
- const emailsJob = new CronJob('*/10 * * * * *', // => every 10s
10
- async function () {
11
- try {
12
- await $ `node ./dist/src/jobs/emails.js`;
13
- }
14
- catch (error) {
15
- logger.error(error, 'Error running cron job');
16
- }
17
- }, null, false, 'America/New_York');
18
- emailsJob.start();
19
- logger.info('Cron jobs started');
20
- // throw to bubble up to uncaughtException
21
- process.on('unhandledRejection', (error) => {
22
- throw error;
23
- });
24
- // exit on exception
25
- process.on('uncaughtException', (error) => {
26
- logger.error(error);
27
- process.exit(1);
28
- });
29
- //# sourceMappingURL=jobs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/jobs.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAC,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC;IAChC,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,GAAG,KAAK,CAAC,EAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAC,CAAC,CAAC;AAExD,MAAM,SAAS,GAAG,IAAI,OAAO,CAC3B,gBAAgB,EAAE,eAAe;AACjC,KAAK;IACH,IAAI,CAAC;QACH,MAAM,CAAC,CAAA,gCAAgC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IAChD,CAAC;AACH,CAAC,EACD,IAAI,EACJ,KAAK,EACL,kBAAkB,CACnB,CAAC;AAEF,SAAS,CAAC,KAAK,EAAE,CAAC;AAElB,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAEjC,0CAA0C;AAC1C,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;IACzC,MAAM,KAAK,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,oBAAoB;AACpB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-await-in-loop */
3
- import process from 'node:process';
4
- import previewEmail from 'preview-email';
5
- import nodemailer from 'nodemailer';
6
- import {config} from '@kosmic/config';
7
- import {db} from '#db/index.js';
8
- import {jobsLogger as logger} from '#utils/logger.js';
9
-
10
- logger.info('Starting emails job');
11
-
12
- const transport = nodemailer.createTransport(config.nodeMailer);
13
-
14
- const unsentEmails = await db
15
- .selectFrom('emails')
16
- .selectAll()
17
- .where('sent_at', 'is', null)
18
- .execute();
19
-
20
- for (const email of unsentEmails) {
21
- logger.debug({email}, 'Sending email');
22
-
23
- const {id, to, from, subject, html, text} = email;
24
-
25
- const message = {
26
- to: to ?? '',
27
- from: from ?? '',
28
- subject: subject ?? '',
29
- html: html ?? '',
30
- text: text ?? '',
31
- attachments: [],
32
- };
33
-
34
- try {
35
- await previewEmail(message);
36
- await transport.sendMail(message);
37
- await db
38
- .updateTable('emails')
39
- .where('id', '=', id)
40
- .set({
41
- sent_at: new Date(),
42
- status: 'sent',
43
- })
44
- .execute();
45
- logger.info({id}, 'Email sent successfully');
46
- } catch (error) {
47
- await db
48
- .updateTable('emails')
49
- .where('id', '=', id)
50
- .set({
51
- sent_at: new Date(),
52
- status: 'failed',
53
- })
54
- .execute();
55
- logger.error(error, 'Error sending email');
56
- }
57
- }
58
-
59
- logger.info('Emails job completed successfully');
60
-
61
- process.exit(0);
package/src/jobs.ts DELETED
@@ -1,39 +0,0 @@
1
- import process from 'node:process';
2
- import {CronJob} from 'cron';
3
- import {execa} from 'execa';
4
- import {logger as serverLogger} from '#utils/logger.js';
5
-
6
- const logger = serverLogger.child({
7
- name: '~jobs~',
8
- });
9
-
10
- const $ = execa({stdio: 'inherit', cwd: process.cwd()});
11
-
12
- const emailsJob = new CronJob(
13
- '*/10 * * * * *', // => every 10s
14
- async function () {
15
- try {
16
- await $`node ./dist/src/jobs/emails.js`;
17
- } catch (error) {
18
- logger.error(error, 'Error running cron job');
19
- }
20
- },
21
- null,
22
- false,
23
- 'America/New_York',
24
- );
25
-
26
- emailsJob.start();
27
-
28
- logger.info('Cron jobs started');
29
-
30
- // throw to bubble up to uncaughtException
31
- process.on('unhandledRejection', (error) => {
32
- throw error;
33
- });
34
-
35
- // exit on exception
36
- process.on('uncaughtException', (error) => {
37
- logger.error(error);
38
- process.exit(1);
39
- });