Zapier integration (#491)

* create zapier app

* install sanctum

* move OAuthProviderController

* make `api-external` middleware

* add zapier endpoints

* add tests

* token management

* zapier event handler

* add policy

* use `slug` instead of `id`

* wip

* check policies

* change api prefix to `external`

* ui tweaks

* validate token abilities

* open zapier URL

* zapier ui tweaks

* update zap

* Fix linting

* Added sample endpoints + minor UI changes

* Run PHP code linter

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Boris Lepikhin
2024-08-12 02:14:02 -07:00
committed by GitHub
parent 7ad62fb3ea
commit 517bccc695
61 changed files with 5799 additions and 51 deletions

View File

@@ -9,6 +9,12 @@ class FormSubmissionDataFactory
{
private ?Faker\Generator $faker;
/**
* If true, then format expected by answer endpoint
* otherwise, format of answer as we store it in the FormSubmission's data
*/
private bool $answerFormat = true;
public function __construct(private Form $form)
{
$this->faker = Faker\Factory::create();
@@ -19,6 +25,12 @@ class FormSubmissionDataFactory
return (new self($form))->createSubmissionData($data);
}
public function asFormSubmissionData()
{
$this->answerFormat = false;
return $this;
}
public function createSubmissionData($mergeData = [])
{
$data = [];
@@ -68,9 +80,23 @@ class FormSubmissionDataFactory
$data[$property['id']] = $value;
});
if (!$this->answerFormat) {
$data = $this->formatAsSubmissionData($data);
}
return array_merge($data, $mergeData);
}
private function formatAsSubmissionData($data)
{
collect($this->form->properties)->each(function ($property) use (&$data) {
if ($property['type'] === 'phone_number') {
$data[$property['id']] = '+33749119783';
}
});
return $data;
}
private function generateSelectValue($property)
{
$values = [];