Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

376 add bizproc scope support in services #377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7acaf7a
Add workflow services and update changelog
mesilov Mar 31, 2024
bca3649
Add Workflow service and associated classes
mesilov Mar 31, 2024
b23306f
Add workflow start methods and related classes
mesilov Apr 1, 2024
7cefd11
Add enum `DealSemanticStage` and update property types in `DealItemRe…
mesilov Apr 3, 2024
e752709
Merge branch 'refs/heads/371-publish-b24-php-sdk-beta-2' into 376-add…
mesilov Apr 11, 2024
acb3775
Add new specific workflow exceptions
mesilov Apr 20, 2024
7a74bcd
Add automation rule support for workflows
mesilov Apr 20, 2024
be9013c
Add functionality to handle Workflow Events
mesilov Apr 21, 2024
35d07bf
Update CHANGELOG.md for 2.0-beta.3 release
mesilov Apr 21, 2024
0be7858
Added new workflows and activities service functionalities
mesilov May 1, 2024
67f0abe
Update dependencies and enhance workflows in CHANGELOG
mesilov May 1, 2024
c90817a
Add workflow termination feature
mesilov May 1, 2024
7a18a3f
Add handling for 'access_denied' case in ErrorHandler
mesilov May 3, 2024
1f71b1a
Removed the integration.yml workflow
mesilov May 3, 2024
3ff8abf
Refactor Workflows services and add new features
mesilov May 3, 2024
1508d13
Add exception handling for empty updates and update service descriptions
mesilov May 4, 2024
ecb19e1
Add nesbot/carbon dependency
mesilov May 4, 2024
6a37629
Add workflow task service and related classes
mesilov May 4, 2024
5e5a7c4
Update PHPStan configuration and refactor Task service
mesilov May 5, 2024
2319b7c
Add support for completing workflow tasks
mesilov May 5, 2024
19feebe
Add Rector for static code analysis
mesilov May 23, 2024
0e2e38a
Refactor code for clarity and robustness
mesilov May 23, 2024
757a805
Add Rector to improve code quality and speed up releases
mesilov May 23, 2024
a46897b
Add new scope
mesilov May 23, 2024
fe37bee
Add workflow auth
mesilov May 24, 2024
0f9e84c
Fix type errors
mesilov May 24, 2024
248016c
Add IncomingRobotRequest.php and IncomingWorkflowRequest.php
mesilov May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 0 additions & 60 deletions .github/workflows/integration.yml

This file was deleted.

80 changes: 66 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
# bitrix24-php-sdk change log

## 2.0-beta.2 — 1.04.2024
## 2.0-beta.3 — 1.05.2024

### Added

* add dependencies
* `symfony/console` version `^6 || ^7`
* `symfony/dotenv` version `^6 || ^7`
* `symfony/filesystem` version `^6 || ^7`
* `symfony/mime` version `^6 || ^7`
* `nesbot/carbon` version `3.3.*`
* add scope `bizproc` and [services](https://github.com/mesilov/bitrix24-php-sdk/issues/376) for work with workflows:
* `Activity` – service for work with application activities:
* `add` – adds new activity to a workflow
* `delete` – delete an activity
* `list` – returns list of activities, installed by the application
* `log` – records data in the workflow log
* `update` – update activity fields
* `Robot` – service for work with application automation rules (robots):
* `add` – registers new automation rule
* `delete` – deletes registered automation rule
* `list` – returns list of automation rules, registered by the application
* `update` – updates fields of automation rules
* `Event` – service for work with return parameters¨
* `send` – Returns the output parameters to the activity
* `Providers` — deprecated methods, not implemented
* `Workflow` — service for work with workflow instances
* `instances` – returns list of launched workflows
* `kill` – delete a launched workflow
* `start` – launches a workflow
* `terminate` – stops an active workflow
* `Template` — service for work with workflow templates
* `add` – add a workflow template
* `delete` – delete workflow template
* `list` – returns list of workflow templates
* `update` – update workflow template
* `Tasks` — service for work with workflow tasks
* `complete` – Complete workflow task
* `list` – List of workflow tasks
* add `WorkflowActivityDocumentType`
* add method `Bitrix24\SDK\Core\Credentials\AccessToken::initFromWorkflowRequest`
* add `\Bitrix24\SDK\Infrastructure\Filesystem\Base64Encoder` for work with base64 encoding
* add `\Bitrix24\SDK\Core\Exceptions\FileNotFoundException` if file not found
* add `IncomingRobotRequest` wrapper for data from crm-robot request
* add `IncomingWorkflowRequest` wrapper for data from biz proc activity request
* add [Rector](https://github.com/rectorphp/rector) for improve code quality and speed up releases cycle

## 2.0-beta.2 — 1.04.2024

### Changed

* updated [dependencies versions](https://github.com/mesilov/bitrix24-php-sdk/issues/373):
* require
* `psr/log` `1.4.0` → `3.0.*`
* `moneyphp/money` `4.3.*` → `4.5.*`
* require-dev
* `monolog/monolog` `2.9.*` → `3.5.*`
* `phpunit/phpunit` `10.5.*` → `11.0.*`
### Bugfix
### etc
* require
* `psr/log` `1.4.0` → `3.0.*`
* `moneyphp/money` `4.3.*` → `4.5.*`
* require-dev
* `monolog/monolog` `2.9.*` → `3.5.*`
* `phpunit/phpunit` `10.5.*` → `11.0.*`
* added enum `DealSemanticStage` for deal field `STAGE_SEMANTIC_ID`

## 2.0-beta.1 — 18.02.2024

Expand All @@ -38,13 +83,13 @@
* add [crm item support](https://github.com/mesilov/bitrix24-php-sdk/issues/330)
* add enum `DealStageSemanticId`
* add Duplicate search support for `Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate`
* add `x-request-id` [header support](https://github.com/mesilov/bitrix24-php-sdk/issues/354)
* add `x-request-id` [header support](https://github.com/mesilov/bitrix24-php-sdk/issues/354)
* add CRM multifields support [header support](https://github.com/mesilov/bitrix24-php-sdk/issues/338)
* `Email`
* `Phone`
* `Website`
* `IM`
* add [Catalog](https://github.com/mesilov/bitrix24-php-sdk/issues/364) scope services support
* add [Catalog](https://github.com/mesilov/bitrix24-php-sdk/issues/364) scope services support

### Changed

Expand All @@ -59,7 +104,7 @@
to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnExternalCallStart\OnExternalCallStart`
* from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallEnd`
to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallEnd\OnVoximplantCallEnd`
* ❗Changes in `Bitrix24\SDK\Application\Contracts\Bitrix24Account\Bitrix24AccountInterface`:
* ❗Changes in `Bitrix24\SDK\Application\Contracts\Bitrix24Account\Bitrix24AccountInterface`:
* method `getContactPerson` renamed to `getContactPersonId`
* added method `getApplicationVersion`
* added method `updateApplicationVersion`
Expand All @@ -69,7 +114,7 @@
* added method `markAsDeactivated`
* added method `getBitrix24UserId`
* removed method `markAccountAsDeleted`
* changed method `markAsActive`
* changed method `markAsActive`
* ❗Changes in `Bitrix24\SDK\Application\Contracts\Bitrix24Account\Bitrix24AccountRepositoryInterface`:
* method `saveAccount` renamed to `save`
* method `deleteAccount` renamed to `delete`
Expand All @@ -85,7 +130,10 @@
* fix [typehint at ContactItemResult](https://github.com/mesilov/bitrix24-php-sdk/issues/320)
* fix [return types in DealCategoryItemResult](https://github.com/mesilov/bitrix24-php-sdk/issues/322)
* fix [add auth node in telephony voximplant events requests](https://github.com/mesilov/bitrix24-php-sdk/issues/331)
* fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335)
*

fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335)

* fix [add return type for crm multifields phone, email, im](https://github.com/mesilov/bitrix24-php-sdk/issues/338)
* fix errors in `ShowFieldsDescriptionCommand` metadata reader CLI command
* fix errors for `ApplicationProfile` with empty scope
Expand Down Expand Up @@ -158,9 +206,13 @@
are [consistent](https://github.com/mesilov/bitrix24-php-sdk/issues/303): `createFromWebhook`, `createFromOAuth`
, `createFromPlacementRequest`
*

❗️deleted [unused class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\ResponseDataCollection`

*

❗️deleted [redundant class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\Result`

* ❗️deleted [method](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `CoreBuilder::withWebhookUrl`, use
method `CoreBuilder::withCredentials`

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ default:
@egrep -e '^\S+' ./Makefile | grep -v default | sed -r 's/://' | sed -r 's/^/ - /'

phpstan:
vendor/bin/phpstan analyse
vendor/bin/phpstan --memory-limit=1G analyse
lint-rector:
vendor/bin/rector process --dry-run
lint-rector-fix:
vendor/bin/rector process

test-unit:
vendor/bin/phpunit --testsuite unit_tests
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
"psr/log": "^2 || ^3",
"fig/http-message-util": "1.1.*",
"ramsey/uuid": "^3 ||^4",
"nesbot/carbon": "3.3.*",
"moneyphp/money": "^3 || ^4",
"symfony/http-client": "^6 || ^7",
"symfony/console": "^6 || ^7",
"symfony/dotenv": "^6 || ^7",
"symfony/filesystem": "^6 || ^7",
"symfony/mime": "^6 || ^7",
"symfony/http-client-contracts": "^2 || ^3",
"symfony/http-foundation": "^6 || ^7",
"symfony/event-dispatcher": "^6 || ^7",
Expand All @@ -39,12 +44,11 @@
"monolog/monolog": "3.5.*",
"phpstan/phpstan": "1.10.*",
"phpunit/phpunit": "11.0.*",
"symfony/console": "7.0.*",
"symfony/dotenv": "7.0.*",
"symfony/debug-bundle": "7.0.*",
"symfony/stopwatch": "7.0.*",
"roave/security-advisories": "dev-master",
"fakerphp/faker": "1.23.*"
"fakerphp/faker": "1.23.*",
"rector/rector": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 7 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ parameters:
paths:
- src/
bootstrapFiles:
- tests/bootstrap.php
- tests/bootstrap.php
parallel:
jobSize: 20
maximumNumberOfProcesses: 8
minimumNumberOfJobsPerProcess: 2
editorUrlTitle: '%%relFile%%:%%line%%'
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
21 changes: 21 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src/Services/Workflows',
])
->withSets(
[DowngradeLevelSetList::DOWN_TO_PHP_82]
)
->withPhpSets(
php82: true // 8.2
)
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
]);
35 changes: 11 additions & 24 deletions src/Application/ApplicationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,17 @@ class ApplicationStatus
*/
public function __construct(string $statusShortCode)
{
switch ($statusShortCode) {
case self::STATUS_SHORT_FREE:
$this->statusCode = 'free';
break;
case self::STATUS_SHORT_DEMO:
$this->statusCode = 'demo';
break;
case self::STATUS_SHORT_TRIAL:
$this->statusCode = 'trial';
break;
case self::STATUS_SHORT_PAID:
$this->statusCode = 'paid';
break;
case self::STATUS_SHORT_LOCAL:
$this->statusCode = 'local';
break;
case self::STATUS_SHORT_SUBSCRIPTION:
$this->statusCode = 'subscription';
break;
default:
throw new InvalidArgumentException(
sprintf('unknown application status code %s', $statusShortCode)
);
}
$this->statusCode = match ($statusShortCode) {
self::STATUS_SHORT_FREE => 'free',
self::STATUS_SHORT_DEMO => 'demo',
self::STATUS_SHORT_TRIAL => 'trial',
self::STATUS_SHORT_PAID => 'paid',
self::STATUS_SHORT_LOCAL => 'local',
self::STATUS_SHORT_SUBSCRIPTION => 'subscription',
default => throw new InvalidArgumentException(
sprintf('unknown application status code %s', $statusShortCode)
),
};
}

/**
Expand Down
27 changes: 23 additions & 4 deletions src/Core/ApiLevelErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

namespace Bitrix24\SDK\Core;

use Bitrix24\SDK\Core\Exceptions\AuthForbiddenException;
use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
use Bitrix24\SDK\Core\Exceptions\MethodNotFoundException;
use Bitrix24\SDK\Core\Exceptions\OperationTimeLimitExceededException;
use Bitrix24\SDK\Core\Exceptions\QueryLimitExceededException;
use Bitrix24\SDK\Services\Workflows\Exceptions\ActivityOrRobotAlreadyInstalledException;
use Bitrix24\SDK\Services\Workflows\Exceptions\ActivityOrRobotValidationFailureException;
use Bitrix24\SDK\Services\Workflows\Exceptions\WorkflowTaskAlreadyCompletedException;
use Psr\Log\LoggerInterface;

/**
* Handle api-level errors and throw related exception
*
* Class ApiLevelErrorHandler
*
* @package Bitrix24\SDK\Core
*/
class ApiLevelErrorHandler
{
Expand Down Expand Up @@ -82,14 +83,32 @@ private function handleError(array $responseBody, ?string $batchCommandId = null
if ($batchCommandId !== null) {
$batchErrorPrefix = sprintf(' batch command id: %s', $batchCommandId);
}
// fix error code responses
if ($errorCode === '' && strtolower($errorDescription) === strtolower('You can delete ONLY templates created by current application')) {
$errorCode = 'bizproc_workflow_template_access_denied';
}
if ($errorCode === '' && strtolower($errorDescription) === strtolower('No fields to update.')) {
$errorCode = 'bad_request_no_fields_to_update';
}

switch ($errorCode) {
case 'error_task_completed':
throw new WorkflowTaskAlreadyCompletedException(sprintf('%s - %s', $errorCode, $errorDescription));
case 'bad_request_no_fields_to_update':
throw new InvalidArgumentException(sprintf('%s - %s', $errorCode, $errorDescription));
case 'access_denied':
case 'bizproc_workflow_template_access_denied':
throw new AuthForbiddenException(sprintf('%s - %s', $errorCode, $errorDescription));
case 'query_limit_exceeded':
throw new QueryLimitExceededException(sprintf('query limit exceeded - too many requests %s', $batchErrorPrefix));
case 'error_method_not_found':
throw new MethodNotFoundException(sprintf('api method not found %s %s', $errorDescription, $batchErrorPrefix));
case 'operation_time_limit':
throw new OperationTimeLimitExceededException(sprintf('operation time limit exceeded %s %s', $errorDescription, $batchErrorPrefix));
case 'error_activity_already_installed':
throw new ActivityOrRobotAlreadyInstalledException(sprintf('%s - %s', $errorCode, $errorDescription));
case 'error_activity_validation_failure':
throw new ActivityOrRobotValidationFailureException(sprintf('%s - %s', $errorCode, $errorDescription));
default:
throw new BaseException(sprintf('%s - %s %s', $errorCode, $errorDescription, $batchErrorPrefix));
}
Expand Down