Skip to content

Commit c168dbc

Browse files
committed
Initial Commits
0 parents commit c168dbc

File tree

17 files changed

+852
-0
lines changed

17 files changed

+852
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
composer.lock
3+
/phpunit.xml
4+
.phpunit.result.cache
5+
.idea

README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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.

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "schorpy/triggerdev-laravel",
3+
"description": "Laravel package for trigger.dev",
4+
"keywords": [
5+
"laravel",
6+
"triggerdev",
7+
"php",
8+
"saas"
9+
],
10+
"version": "1.0.0",
11+
"license": "MIT",
12+
"require": {
13+
"php": "~8.2.0|~8.3.0|~8.4.0",
14+
"guzzlehttp/guzzle": "^7.0",
15+
"firebase/php-jwt": "^6.11",
16+
"laravel/framework": "^11.0|^12.0"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Schorpy\\TriggerDev\\": "src/"
21+
}
22+
},
23+
"extra": {
24+
"laravel": {
25+
"providers": [
26+
"Schorpy\\TriggerDev\\TriggerServiceProvider"
27+
]
28+
}
29+
},
30+
"authors": [
31+
{
32+
"name": "schorpy",
33+
"email": "87610109+schorpy@users.noreply.github.com"
34+
}
35+
],
36+
"minimum-stability": "stable"
37+
}

config/triggerdev.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
return [
4+
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| TriggerDev Secret Key
9+
|--------------------------------------------------------------------------
10+
|
11+
| The TriggerDev Secret Key is used to call API from TriggerDev.
12+
| You can find your TriggerDev Secret Key in the TriggerDev dashboard.
13+
|
14+
*/
15+
16+
'secret_key' => env('TRIGGERDEV_SECRET_KEY'),
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| TriggerDev Url Path
21+
|--------------------------------------------------------------------------
22+
|
23+
| This is the base URI where routes from TriggerDev will be served
24+
| from. The URL built into TriggerDev is used by default; however,
25+
| you can modify this path as you see fit for your application.
26+
|
27+
*/
28+
29+
'path' => env('TRIGGERDEV_PATH', 'triggerdev'),
30+
31+
];
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('trigger_jobs', function (Blueprint $table) {
15+
$table->id();
16+
17+
// Unique identifier for the trigger job
18+
$table->uuid('uuid')->unique();
19+
20+
// Polymorphic relation to billable model (user/account/etc.)
21+
$table->string('billable_type');
22+
$table->unsignedBigInteger('billable_id');
23+
24+
25+
// Status of the job/event
26+
$table->enum('status', ['pending', 'running', 'completed', 'failed'])
27+
->default('pending');
28+
29+
// External Trigger.dev / Inngest job ID
30+
$table->string('run_id')->unique();
31+
32+
// Optional: store arbitrary job data
33+
$table->json('payload')->nullable();
34+
35+
$table->timestamps();
36+
37+
// Indexes for fast lookups
38+
$table->index(['billable_type', 'billable_id']);
39+
$table->index('status');
40+
});
41+
}
42+
43+
/**
44+
* Reverse the migrations.
45+
*/
46+
public function down(): void
47+
{
48+
Schema::dropIfExists('trigger_jobs');
49+
}
50+
};

routes/web.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
Route::post('webhook', 'WebhookController')->name('webhook');

src/EnvVars.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Schorpy\TriggerDev;
4+
5+
6+
class EnvVars
7+
{
8+
public static function list(string $projectRef, string $env): array
9+
{
10+
return TriggerDev::api('get', "projects/{$projectRef}/envvars/{$env}")->json();
11+
}
12+
13+
public static function upload(string $projectRef, string $env, array $variables, bool $override = false): array
14+
{
15+
return TriggerDev::api('post', "projects/{$projectRef}/envvars/{$env}/import", [
16+
'variables' => $variables, // e.g. [ ['name' => 'SLACK_API_KEY', 'value' => 'slack_123'] ]
17+
'override' => $override,
18+
])->json();
19+
}
20+
21+
public static function create(string $projectRef, string $env, string $name, string $value): array
22+
{
23+
return TriggerDev::api('post', "projects/{$projectRef}/envvars/{$env}", [
24+
'name' => $name,
25+
'value' => $value,
26+
])->json();
27+
}
28+
29+
public static function retrieve(string $projectRef, string $env, string $name): array
30+
{
31+
return TriggerDev::api('get', "projects/{$projectRef}/envvars/{$env}/{$name}")->json();
32+
}
33+
34+
public static function update(string $projectRef, string $env, string $name, string $value): array
35+
{
36+
return TriggerDev::api('put', "projects/{$projectRef}/envvars/{$env}/{$name}", [
37+
'value' => $value,
38+
])->json();
39+
}
40+
41+
public static function delete(string $projectRef, string $env, string $name): array
42+
{
43+
return TriggerDev::api('delete', "projects/{$projectRef}/envvars/{$env}/{$name}")->json();
44+
}
45+
}

src/Events/WebhookHandled.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Schorpy\TriggerDev\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class WebhookHandled
9+
{
10+
use Dispatchable;
11+
use SerializesModels;
12+
13+
public array $payload;
14+
15+
public function __construct(array $payload)
16+
{
17+
$this->payload = $payload;
18+
}
19+
}

src/Events/WebhookReceived.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Schorpy\TriggerDev\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class WebhookReceived
9+
{
10+
use Dispatchable;
11+
use SerializesModels;
12+
13+
/**
14+
* @var array
15+
*/
16+
public $payload;
17+
18+
/**
19+
* Create a new event instance.
20+
*
21+
* @param array $payload
22+
* @return void
23+
*/
24+
public function __construct(array $payload)
25+
{
26+
$this->payload = $payload;
27+
}
28+
}

0 commit comments

Comments
 (0)