|
| 1 | +# Laravel TriggerDev Package |
| 2 | + |
| 3 | +A Laravel package to integrate **Trigger.Dev** APIs into your Laravel application, inspired by Laravel Cashier. |
| 4 | +It allows you to manage **Tasks, Runs, Schedules, and Environment Variables (EnvVars)** easily from your Laravel app. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- **Task Trigger**: Trigger individual tasks or batch tasks. |
| 11 | +- **Runs**: List, retrieve, replay, cancel, reschedule, and update metadata for runs. |
| 12 | +- **Schedules**: Create, update, activate, deactivate, and delete schedules. |
| 13 | +- **EnvVars**: List, create, upload, update, retrieve, and delete environment variables. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +# Usage |
| 18 | +### Task Trigger |
| 19 | + |
| 20 | +```php |
| 21 | +use Schorpy\TriggerDev\Task; |
| 22 | + |
| 23 | +// Trigger a single task |
| 24 | +$response = Task::trigger('hello-world', ['foo' => 'bar'], ['priority' => 1]); |
| 25 | + |
| 26 | +// Trigger a task with a public token |
| 27 | +$response = Task::triggerWithPublicToken( |
| 28 | + taskId: 'hello-world', |
| 29 | + payload: ['foo' => 'bar'], |
| 30 | + options: ['priority' => 1], |
| 31 | + ttl: '1h' |
| 32 | +); |
| 33 | + |
| 34 | +// Batch trigger multiple tasks |
| 35 | +$batchResponse = Task::batchTrigger([ |
| 36 | + ['task' => 'task-1', 'payload' => ['a' => 1]], |
| 37 | + ['task' => 'task-2', 'payload' => ['b' => 2]], |
| 38 | +]); |
| 39 | +``` |
| 40 | +### Runs |
| 41 | + |
| 42 | +```php |
| 43 | +use Schorpy\TriggerDev\Runs; |
| 44 | + |
| 45 | +// List all runs |
| 46 | +$runs = Runs::list(); |
| 47 | + |
| 48 | +// Retrieve a single run |
| 49 | +$run = Runs::retrieve('run_1234'); |
| 50 | + |
| 51 | +// Replay or cancel a run |
| 52 | +$replayed = Runs::replay('run_1234'); |
| 53 | +$canceled = Runs::cancel('run_1234'); |
| 54 | + |
| 55 | +// Reschedule a run |
| 56 | +$rescheduled = Runs::reschedule('run_1234', '2025-09-16T10:00:00Z'); |
| 57 | + |
| 58 | +// Update metadata |
| 59 | +$metadataUpdated = Runs::metadata('run_1234', [ |
| 60 | + 'key' => 'value', |
| 61 | + 'env' => 'production' |
| 62 | +]); |
| 63 | +``` |
| 64 | +### Schedules |
| 65 | +```php |
| 66 | +use Schorpy\TriggerDev\Schedules; |
| 67 | + |
| 68 | +// List schedules |
| 69 | +$schedules = Schedules::list(); |
| 70 | + |
| 71 | +// Create a schedule |
| 72 | +$newSchedule = Schedules::create('my-task', '0 0 * * *', 'external-id', 'America/New_York'); |
| 73 | + |
| 74 | +// Retrieve, update, or delete a schedule |
| 75 | +$schedule = Schedules::retrieve('sch_1234'); |
| 76 | +$updated = Schedules::update('sch_1234', 'my-updated-task', '0 0 * * *', 'external-id', 'America/New_York'); |
| 77 | +Schedules::delete('sch_1234'); |
| 78 | + |
| 79 | +// Activate or deactivate a schedule |
| 80 | +Schedules::activate('sch_1234'); |
| 81 | +Schedules::deactivate('sch_1234'); |
| 82 | +``` |
| 83 | +### EnvVars |
| 84 | + |
| 85 | +```php |
| 86 | +use Schorpy\TriggerDev\EnvVars; |
| 87 | + |
| 88 | +$project = 'proj_yubjwjsfkxnylobaqvqz'; |
| 89 | +$env = 'dev'; |
| 90 | + |
| 91 | +// List environment variables |
| 92 | +$vars = EnvVars::list($project, $env); |
| 93 | + |
| 94 | +// Upload multiple variables |
| 95 | +EnvVars::upload($project, $env, [ |
| 96 | + ['name' => 'SLACK_API_KEY', 'value' => 'slack_123456'], |
| 97 | + ['name' => 'API_SECRET', 'value' => 'secret_789'] |
| 98 | +], false); |
| 99 | + |
| 100 | +// Create a single variable |
| 101 | +EnvVars::create($project, $env, 'SLACK_API_KEY', 'slack_123456'); |
| 102 | + |
| 103 | +// Retrieve, update, or delete a variable |
| 104 | +$var = EnvVars::retrieve($project, $env, 'SLACK_API_KEY'); |
| 105 | +EnvVars::update($project, $env, 'SLACK_API_KEY', 'slack_new_987'); |
| 106 | +EnvVars::delete($project, $env, 'SLACK_API_KEY'); |
| 107 | +``` |
| 108 | + |
| 109 | +### Contributing |
| 110 | + |
| 111 | +We welcome contributions! Here's how to help: |
| 112 | + |
| 113 | +- Fork the repository to your GitHub account and clone it locally. |
| 114 | +- Create a feature branch for your changes. |
| 115 | +- Implement changes or add features. |
| 116 | +- Test thoroughly to ensure functionality. |
| 117 | +- Submit a pull request with a detailed description of your changes. |
0 commit comments