@stacksjs/scheduler 0.52.0
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/LICENSE.md +21 -0
- package/README.md +137 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.mjs +88 -0
- package/package.json +50 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Stacks SMS
|
|
2
|
+
|
|
3
|
+
Stacks SMS is driver system for sending SMS messages.
|
|
4
|
+
|
|
5
|
+
## โ๏ธ Features
|
|
6
|
+
|
|
7
|
+
- ๐ฆ Send SMS
|
|
8
|
+
|
|
9
|
+
## ๐ค Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm i -D @stacksjs/sms
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You may now use it in your project:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import * as sms from '@stacksjs/sms'
|
|
19
|
+
|
|
20
|
+
/* Then choose a driver. E.g for twilio */
|
|
21
|
+
const notification = sms.twilio
|
|
22
|
+
|
|
23
|
+
notification.send(SMSOptions)
|
|
24
|
+
|
|
25
|
+
interface SMSOptions {
|
|
26
|
+
to: string
|
|
27
|
+
content: string
|
|
28
|
+
from?: string
|
|
29
|
+
attachments?: AttachmentOptions[]
|
|
30
|
+
id?: string
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Drivers
|
|
35
|
+
|
|
36
|
+
Drivers are configured with the following environment variables:
|
|
37
|
+
|
|
38
|
+
#### Twilio
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
TWILIO_ACCOUNT_SID=ACtest
|
|
42
|
+
TWILIO_AUTH_TOKEN=testtoken
|
|
43
|
+
TWILIO_FROM_NUMBER=+112345
|
|
44
|
+
TWILIO_TO_NUMBER=+145678
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Nexmo
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
VONAGE_API_KEY=VN123
|
|
51
|
+
VONAGE_API_SECRET=testkey
|
|
52
|
+
VONAGE_FROM_NUMBER=+112345
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Gupshup
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
GUPSHUP_USER_ID=GU123
|
|
59
|
+
GUPSHUP_PASSWORD=password
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Plivo
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
PLIVO_ACCOUNT_ID=PA123
|
|
66
|
+
PLIVO_AUTH_TOKEN=testtoken
|
|
67
|
+
PLIVO_FROM_NUMBER=+112345
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### SMS77
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
SMS77_API_KEY=SA123
|
|
74
|
+
SMS77_FROM=from@example.com
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### SNS
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
SMS77_API_KEY=SA123
|
|
81
|
+
SMS77_FROM=from@example.com
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Telnyx
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
TELNYX_API_KEY=TA123
|
|
88
|
+
TELNYX_MESSAGE_PROFILE_ID=testprofileid
|
|
89
|
+
TELNYX_FROM=from@example.com
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Termii
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
TERMII_API_KEY=TermA123
|
|
96
|
+
TERMII_SENDER=from@example.com
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Learn more in the docs.
|
|
100
|
+
|
|
101
|
+
## ๐งช Testing
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pnpm test
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## ๐ Changelog
|
|
108
|
+
|
|
109
|
+
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
|
|
110
|
+
|
|
111
|
+
## ๐ Contributing
|
|
112
|
+
|
|
113
|
+
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
|
|
114
|
+
|
|
115
|
+
## ๐ Community
|
|
116
|
+
|
|
117
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
118
|
+
|
|
119
|
+
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
|
|
120
|
+
|
|
121
|
+
For casual chit-chat with others using this package:
|
|
122
|
+
|
|
123
|
+
[Join the Stacks Discord Server](https://discord.ow3.org)
|
|
124
|
+
|
|
125
|
+
## ๐๐ผ Credits
|
|
126
|
+
|
|
127
|
+
Many thanks to the following core technologies & people who have contributed to this package:
|
|
128
|
+
|
|
129
|
+
- [Chris Breuer](https://github.com/chrisbbreuer)
|
|
130
|
+
- [Novu](https://novu.co/)
|
|
131
|
+
- [All Contributors](../../contributors)
|
|
132
|
+
|
|
133
|
+
## ๐ License
|
|
134
|
+
|
|
135
|
+
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
|
|
136
|
+
|
|
137
|
+
Made with โค๏ธ
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Scheduler {
|
|
2
|
+
everySecond: () => void;
|
|
3
|
+
everySeconds: (seconds: number) => void;
|
|
4
|
+
everyMinute: () => void;
|
|
5
|
+
everyMinutes: (minutes: number) => void;
|
|
6
|
+
everyTwoMinutes: () => void;
|
|
7
|
+
everyThreeMinutes: () => void;
|
|
8
|
+
everyFourMinutes: () => void;
|
|
9
|
+
everyFiveMinutes: () => void;
|
|
10
|
+
everyTenMinutes: () => void;
|
|
11
|
+
everyFifteenMinutes: () => void;
|
|
12
|
+
everyThirtyMinutes: () => void;
|
|
13
|
+
hourly: () => void;
|
|
14
|
+
hourlyAt: (minute: number) => void;
|
|
15
|
+
everyOddHour: () => void;
|
|
16
|
+
everyHours: (hours: number) => void;
|
|
17
|
+
everyTwoHours: () => void;
|
|
18
|
+
everyThreeHours: () => void;
|
|
19
|
+
everyFourHours: () => void;
|
|
20
|
+
everySixHours: () => void;
|
|
21
|
+
daily: () => void;
|
|
22
|
+
dailyAt: (hour: number, minute: number) => void;
|
|
23
|
+
everyDays: (days: number) => void;
|
|
24
|
+
weekly: () => void;
|
|
25
|
+
quarterly: () => void;
|
|
26
|
+
yearly: () => void;
|
|
27
|
+
cron: (interval: string, timezone?: string) => void;
|
|
28
|
+
}
|
|
29
|
+
declare function run(callback: ((now: Date | 'manual' | 'init') => void) | string): Scheduler;
|
|
30
|
+
export declare function useScheduler(): {
|
|
31
|
+
run: typeof run;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import cron from "node-cron";
|
|
2
|
+
function run(callback) {
|
|
3
|
+
return {
|
|
4
|
+
everySecond: () => {
|
|
5
|
+
cron.schedule("* * * * * *", callback);
|
|
6
|
+
},
|
|
7
|
+
everySeconds: (seconds = 1) => {
|
|
8
|
+
cron.schedule(`*/${seconds} * * * * *`, callback);
|
|
9
|
+
},
|
|
10
|
+
everyMinute: () => {
|
|
11
|
+
cron.schedule("* * * * *", callback);
|
|
12
|
+
},
|
|
13
|
+
everyTwoMinutes: () => {
|
|
14
|
+
cron.schedule("*/2 * * * *", callback);
|
|
15
|
+
},
|
|
16
|
+
everyThreeMinutes: () => {
|
|
17
|
+
cron.schedule("*/3 * * * *", callback);
|
|
18
|
+
},
|
|
19
|
+
everyFourMinutes: () => {
|
|
20
|
+
cron.schedule("*/4 * * * *", callback);
|
|
21
|
+
},
|
|
22
|
+
everyFiveMinutes: () => {
|
|
23
|
+
cron.schedule("*/5 * * * *", callback);
|
|
24
|
+
},
|
|
25
|
+
everyTenMinutes: () => {
|
|
26
|
+
cron.schedule("*/10 * * * *", callback);
|
|
27
|
+
},
|
|
28
|
+
everyFifteenMinutes: () => {
|
|
29
|
+
cron.schedule("*/15 * * * *", callback);
|
|
30
|
+
},
|
|
31
|
+
everyThirtyMinutes: () => {
|
|
32
|
+
cron.schedule("*/30 * * * *", callback);
|
|
33
|
+
},
|
|
34
|
+
everyMinutes: (minutes) => {
|
|
35
|
+
cron.schedule(`*/${minutes} * * * *`, callback);
|
|
36
|
+
},
|
|
37
|
+
hourly: () => {
|
|
38
|
+
cron.schedule("0 * * * *", callback);
|
|
39
|
+
},
|
|
40
|
+
everyHours: (hours) => {
|
|
41
|
+
cron.schedule(`0 */${hours} * * *`, callback);
|
|
42
|
+
},
|
|
43
|
+
hourlyAt: (minute) => {
|
|
44
|
+
cron.schedule(`${minute} * * * *`, callback);
|
|
45
|
+
},
|
|
46
|
+
everyOddHour: () => {
|
|
47
|
+
cron.schedule("0 */2 * * *", callback);
|
|
48
|
+
},
|
|
49
|
+
everyTwoHours: () => {
|
|
50
|
+
cron.schedule("0 */2 * * *", callback);
|
|
51
|
+
},
|
|
52
|
+
everyThreeHours: () => {
|
|
53
|
+
cron.schedule("0 */3 * * *", callback);
|
|
54
|
+
},
|
|
55
|
+
everyFourHours: () => {
|
|
56
|
+
cron.schedule("0 */4 * * *", callback);
|
|
57
|
+
},
|
|
58
|
+
everySixHours: () => {
|
|
59
|
+
cron.schedule("0 */6 * * *", callback);
|
|
60
|
+
},
|
|
61
|
+
dailyAt: (hour, minute) => {
|
|
62
|
+
cron.schedule(`${minute} ${hour} * * *`, callback);
|
|
63
|
+
},
|
|
64
|
+
daily: () => {
|
|
65
|
+
cron.schedule("0 0 * * *", callback);
|
|
66
|
+
},
|
|
67
|
+
everyDays: (days) => {
|
|
68
|
+
cron.schedule(`0 0 */${days} * *`, callback);
|
|
69
|
+
},
|
|
70
|
+
weekly: () => {
|
|
71
|
+
cron.schedule("0 0 * * 0", callback);
|
|
72
|
+
},
|
|
73
|
+
quarterly: () => {
|
|
74
|
+
cron.schedule("0 0 1 */3 *", callback);
|
|
75
|
+
},
|
|
76
|
+
yearly: () => {
|
|
77
|
+
cron.schedule("0 0 1 1 *", callback);
|
|
78
|
+
},
|
|
79
|
+
cron: (interval, timezone) => {
|
|
80
|
+
timezone ? cron.schedule(interval, callback, { scheduled: true, timezone }) : cron.schedule(interval, callback);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function useScheduler() {
|
|
85
|
+
return {
|
|
86
|
+
run
|
|
87
|
+
};
|
|
88
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stacksjs/scheduler",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.52.0",
|
|
5
|
+
"packageManager": "pnpm@8.5.1",
|
|
6
|
+
"description": "The Stacks scheduler.",
|
|
7
|
+
"author": "Chris Breuer",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
|
+
"homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/scheduler#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
14
|
+
"directory": "./.stacks/core/scheduler"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/stacksjs/stacks/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"scheduler",
|
|
21
|
+
"stacks"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"module": "dist/index.mjs",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"contributors": [
|
|
32
|
+
"Chris Breuer <chris@ow3.org>"
|
|
33
|
+
],
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"node-cron": "3.0.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node-cron": "^3.0.7",
|
|
43
|
+
"@stacksjs/development": "0.52.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "unbuild",
|
|
47
|
+
"dev": "unbuild --stub",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
49
|
+
}
|
|
50
|
+
}
|