Skip to content

Commit 59bd811

Browse files
authored
Merge pull request #3697 from bakaphp/development
Version 1.37.0
2 parents 829d559 + 0026e7f commit 59bd811

File tree

47 files changed

+1577
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1577
-986
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console\Commands\Connectors\NetSuite;
6+
7+
use Baka\Traits\KanvasJobsTrait;
8+
use Illuminate\Console\Command;
9+
use Kanvas\Apps\Models\Apps;
10+
use Kanvas\Companies\Models\Companies;
11+
use Kanvas\Connectors\NetSuite\Actions\PullNetSuiteProductPriceAction;
12+
use Kanvas\Connectors\NetSuite\Services\NetSuiteProductService;
13+
use Kanvas\Inventory\Variants\Services\VariantService;
14+
use League\Csv\Reader;
15+
16+
class NetSuiteSyncAllProductsCommand extends Command
17+
{
18+
use KanvasJobsTrait;
19+
20+
/**
21+
* The name and signature of the console command.
22+
*
23+
* @var string
24+
*/
25+
protected $signature = 'kanvas:netsuite-sync-products {app_id} {company_id} {filePath}';
26+
27+
/**
28+
* The console command description.
29+
*
30+
* @var string|null
31+
*/
32+
protected $description = 'Sync inventory for the company';
33+
34+
public function handle(): void
35+
{
36+
//@todo make this run for multiple apps by looking for them at apps settings flag
37+
$app = Apps::getById($this->argument('app_id'));
38+
$this->overwriteAppService($app);
39+
$company = Companies::getById($this->argument('company_id'));
40+
$companyUser = $company->users()->first();
41+
42+
$syncNetSuiteProduct = new PullNetSuiteProductPriceAction(
43+
$app,
44+
$company,
45+
$companyUser
46+
);
47+
48+
$csvFilePath = $this->argument('filePath');
49+
50+
$productList = $this->getProductList($csvFilePath);
51+
$barcodeList = array_keys($productList);
52+
$this->output->progressStart(count($barcodeList));
53+
foreach ($barcodeList as $barcode) {
54+
$code = (string) $barcode;
55+
$syncNetSuiteProduct->execute($code);
56+
$this->output->progressAdvance();
57+
}
58+
$this->output->progressFinish();
59+
}
60+
61+
private function getProductList(string $csvFilePath): array
62+
{
63+
$headerOffset = 0;
64+
$csv = Reader::createFromPath($csvFilePath);
65+
$csv->setHeaderOffset($headerOffset);
66+
$csv->skipEmptyRecords();
67+
$records = $csv->getRecords();
68+
69+
$productList = [];
70+
foreach ($records as $offset => $record) {
71+
if ($offset < $headerOffset) {
72+
continue;
73+
}
74+
75+
$barcode = $record['Copic Item No/ UPC'];
76+
$sku = $record["Macpherson Item #"];
77+
$productList[$barcode] = [
78+
"sku" => $sku,
79+
"name" => $record["Description"],
80+
"barcode" => $barcode
81+
];
82+
}
83+
84+
return $productList;
85+
}
86+
}

app/Console/Commands/Connectors/PromptMine/FixPromptDataCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Kanvas\Apps\Models\Apps;
1010
use Kanvas\Social\Messages\Models\Message;
1111
use Kanvas\Social\MessagesTypes\Models\MessageType;
12-
use EchoLabs\Prism\Enums\Provider;
13-
use EchoLabs\Prism\Prism;
12+
use Prism\Prism\Prism;
13+
use Prism\Prism\Enums\Provider;
1414
use Illuminate\Support\Facades\DB;
1515
use Kanvas\Social\Messages\Validations\MessageSchemaValidator;
1616
use Throwable;

app/Console/Commands/Connectors/PromptMine/PopulateTrendingFeedCommand.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public function handle()
4949
$populateTrendingFeedAction = new PopulateTrendingFeedAction($app, $company, true);
5050
$populateTrendingFeedAction->execute();
5151

52-
$tag = (new CreateTagAction(
53-
new Tag(
54-
$app,
55-
$company->user,
56-
$company,
57-
'trending'
58-
)
59-
))->execute();
60-
$tag->name = 'Trending';
61-
$tag->is_feature = 1;
62-
$tag->saveOrFail();
52+
/* $tag = (new CreateTagAction(
53+
new Tag(
54+
$app,
55+
$company->user,
56+
$company,
57+
'trending'
58+
)
59+
))->execute();
60+
$tag->name = 'Trending';
61+
$tag->is_feature = 1;
62+
$tag->saveOrFail(); */
6363

6464
return;
6565
}

app/Console/Commands/Connectors/PromptMine/PromptAgentEngagerCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Baka\Support\Str;
88
use Baka\Traits\KanvasJobsTrait;
9-
use EchoLabs\Prism\Enums\Provider;
10-
use EchoLabs\Prism\Prism;
9+
use Prism\Prism\Prism;
10+
use Prism\Prism\Enums\Provider;
1111
use GuzzleHttp\Client;
1212
use Illuminate\Console\Command;
1313
use Illuminate\Support\Facades\Redis;

app/Console/Commands/Connectors/PromptMine/PromptCreatorAgentCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Illuminate\Support\Facades\Mail;
1212
use Illuminate\Support\Facades\Redis;
1313
use Kanvas\Apps\Models\Apps;
14-
use EchoLabs\Prism\Enums\Provider;
15-
use EchoLabs\Prism\Prism;
14+
use Prism\Prism\Enums\Provider;
15+
use Prism\Prism\Prism;
1616

1717
class PromptCreatorAgentCommand extends Command
1818
{
@@ -291,7 +291,7 @@ protected function generateNugget(string $prompt): ?array
291291
$response = Prism::text()
292292
->using(Provider::Gemini, 'gemini-2.0-flash')
293293
->withPrompt($nuggetGenerator)
294-
->generate();
294+
->asText();
295295

296296
$responseText = str_replace(['```', 'json'], '', $response->text);
297297

app/Console/Commands/Social/SocialUserCounterResetCommand.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Baka\Traits\KanvasJobsTrait;
88
use Illuminate\Console\Command;
99
use Kanvas\Apps\Models\Apps;
10+
use Kanvas\Exceptions\ModelNotFoundException;
1011
use Kanvas\Users\Repositories\UserAppRepository;
1112

1213
class SocialUserCounterResetCommand extends Command
@@ -32,7 +33,14 @@ class SocialUserCounterResetCommand extends Command
3233
*/
3334
public function handle()
3435
{
35-
$app = Apps::getById($this->argument('app_id'));
36+
try {
37+
$app = Apps::getById($this->argument('app_id'));
38+
} catch (ModelNotFoundException $e) {
39+
$this->error('App not found with id ' . $this->argument('app_id'));
40+
41+
return;
42+
}
43+
3644
$this->overwriteAppService($app);
3745

3846
$this->info('Resetting social counter for app: ' . $this->argument('app_id'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\GraphQL\Directives;
6+
7+
use Kanvas\Enums\AppEnums;
8+
use Nuwave\Lighthouse\Auth\GuardDirective;
9+
use Nuwave\Lighthouse\Execution\ResolveInfo;
10+
use Nuwave\Lighthouse\Schema\Values\FieldValue;
11+
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
12+
use Override;
13+
14+
class GuardByKanvasIdentifierDirective extends GuardDirective
15+
{
16+
#[Override]
17+
public static function definition(): string
18+
{
19+
return /** @lang GraphQL */ <<<'GRAPHQL'
20+
directive @guardByKanvasIdentifier(
21+
"""
22+
Specify which guards to use, e.g. ["web"].
23+
When not defined, the default from `lighthouse.php` is used.
24+
"""
25+
with: [String!]
26+
) repeatable on FIELD_DEFINITION | OBJECT
27+
GRAPHQL;
28+
}
29+
30+
#[Override]
31+
public function handleField(FieldValue $fieldValue): void
32+
{
33+
$fieldValue->wrapResolver(
34+
fn (callable $previousResolver) => function (
35+
$root,
36+
array $args,
37+
GraphQLContext $context,
38+
ResolveInfo $resolveInfo
39+
) use ($previousResolver) {
40+
$request = $context->request();
41+
$kanvasIdentifier = AppEnums::KANVAS_IDENTIFIER->getValue();
42+
43+
if (! app()->bound($kanvasIdentifier)) {
44+
$this->unauthenticated(['No Cart Session Identifier']);
45+
}
46+
47+
return $previousResolver($root, $args, $context, $resolveInfo);
48+
}
49+
);
50+
}
51+
}

app/GraphQL/Souk/Mutations/Cart/CartManagementMutation.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,36 @@
55
namespace App\GraphQL\Souk\Mutations\Cart;
66

77
use Illuminate\Support\Facades\App;
8+
use Joelwmale\Cart\CartCondition;
89
use Kanvas\Apps\Models\Apps;
10+
use Kanvas\Companies\Models\CompaniesBranches;
11+
use Kanvas\Enums\AppEnums;
912
use Kanvas\Exceptions\ModelNotFoundException;
1013
use Kanvas\Souk\Cart\Actions\AddToCartAction;
1114
use Kanvas\Souk\Cart\Services\CartService;
12-
use Wearepixel\Cart\CartCondition;
1315

1416
class CartManagementMutation
1517
{
1618
public function add(mixed $root, array $request): array
1719
{
1820
$user = auth()->user();
19-
$company = $user->getCurrentCompany();
21+
$company = $user ? $user->getCurrentCompany() : app(CompaniesBranches::class)->company;
22+
23+
if (! $company) {
24+
throw new ModelNotFoundException('No company found');
25+
}
26+
2027
$currentUserCompany = $company;
2128
$app = app(Apps::class);
22-
$cart = app('cart')->session($user->getId());
23-
24-
$addToCartAction = new AddToCartAction($app, $user, $currentUserCompany);
29+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
30+
$addToCartAction = new AddToCartAction($app, $currentUserCompany, $user);
2531

2632
return $addToCartAction->execute($cart, $request['items']);
2733
}
2834

2935
public function update(mixed $root, array $request): array
3036
{
31-
$user = auth()->user();
32-
$cart = app('cart')->session($user->getId());
37+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
3338

3439
if (! $cart->has($request['variant_id'])) {
3540
return [];
@@ -45,7 +50,7 @@ public function update(mixed $root, array $request): array
4550
public function remove(mixed $root, array $request): array
4651
{
4752
$user = auth()->user();
48-
$cart = app('cart')->session($user->getId());
53+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
4954

5055
$cart->remove($request['variant_id']);
5156

@@ -55,7 +60,7 @@ public function remove(mixed $root, array $request): array
5560
public function discountCodesUpdate(mixed $root, array $request): array
5661
{
5762
$user = auth()->user();
58-
$cart = app('cart')->session($user->getId());
63+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
5964
$app = app(Apps::class);
6065

6166
/**
@@ -92,7 +97,7 @@ public function discountCodesUpdate(mixed $root, array $request): array
9297
public function clear(mixed $root, array $request): bool
9398
{
9499
$user = auth()->user();
95-
$cart = app('cart')->session($user->getId());
100+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
96101
$cart->clearAllConditions();
97102

98103
return $cart->clear();

app/GraphQL/Souk/Queries/Cart/CartQuery.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace App\GraphQL\Souk\Queries\Cart;
66

77
use Kanvas\Souk\Cart\Services\CartService;
8+
use Kanvas\Enums\AppEnums;
89

910
class CartQuery
1011
{
1112
public function index(): array
1213
{
1314
$user = auth()->user();
14-
$cart = app('cart')->session($user->getId());
15+
$cart = app('cart')->session(app(AppEnums::KANVAS_IDENTIFIER->getValue()));
1516

1617
$cartService = new CartService($cart);
1718

app/GraphQL/Workflow/Mutations/Integrations/IntegrationsMutation.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace App\GraphQL\Workflow\Mutations\Integrations;
66

7-
use Kanvas\Inventory\Status\Models\Status as StatusModel;
8-
use Kanvas\Workflow\Models\Integrations;
97
use Kanvas\Apps\Models\Apps;
108
use Kanvas\Companies\Repositories\CompaniesRepository;
119
use Kanvas\Exceptions\InternalServerErrorException;
@@ -16,16 +14,12 @@
1614
use Kanvas\Workflow\Integrations\Models\IntegrationsCompany as ModelsIntegrationsCompany;
1715
use Kanvas\Workflow\Integrations\Models\Status;
1816
use Kanvas\Workflow\Integrations\Validations\ConfigValidation;
17+
use Kanvas\Workflow\Models\Integrations;
1918

2019
class IntegrationsMutation
2120
{
2221
/**
2322
* create.
24-
*
25-
* @param mixed $rootValue
26-
* @param array $args
27-
*
28-
* @return StatusModel
2923
*/
3024
public function createIntegrationCompany(mixed $rootValue, array $request): ModelsIntegrationsCompany
3125
{

app/Http/Middleware/KanvasAppKeyMiddleware.php

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Http\Middleware;
66

7+
use Baka\Support\Str;
78
use Closure;
89
use Illuminate\Database\Eloquent\ModelNotFoundException;
910
use Illuminate\Http\Request;
@@ -29,6 +30,7 @@ public function handle(Request $request, Closure $next): Response
2930

3031
$this->handleCompanyBranch($request);
3132
$this->handleAppKey($request);
33+
$this->handleKanvasIdentifier($request);
3234

3335
return $next($request);
3436
}
@@ -61,6 +63,31 @@ private function handleCompanyBranch(Request $request): void
6163
}
6264
}
6365

66+
public function handleKanvasIdentifier(Request $request): void
67+
{
68+
$kanvasIdentifierHeader = AppEnums::KANVAS_IDENTIFIER->getValue();
69+
70+
try {
71+
if (auth()->user()) {
72+
// For logged-in users, use their ID
73+
$kanvasIdentifier = auth()->user()->getId();
74+
} else {
75+
// For non-logged-in users, get identifier from header and validate UUID format
76+
$kanvasIdentifier = $request->header($kanvasIdentifierHeader);
77+
78+
if ($kanvasIdentifier === null || empty($kanvasIdentifier) || ! Str::isUuid($kanvasIdentifier)) {
79+
return;
80+
}
81+
}
82+
83+
app()->scoped(AppEnums::KANVAS_IDENTIFIER->getValue(), fn () => $kanvasIdentifier);
84+
} catch (Throwable $e) {
85+
response()->json(['message' => 'No App configured with this key: ' . ($kanvasIdentifier ?? 'unknown')], 500)->send();
86+
87+
return;
88+
}
89+
}
90+
6491
private function handleAppKey(Request $request): void
6592
{
6693
$appKeyHeader = AppEnums::KANVAS_APP_KEY_HEADER->getValue();

0 commit comments

Comments
 (0)