From feb53e1fec819ba88d903ddeafe9da43ca017832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Schoenenberger?= <54308193+hschoenenberger@users.noreply.github.com> Date: Thu, 30 May 2024 12:12:09 +0200 Subject: [PATCH] [ACCOUNT-2375] refactor: upgrade oauth2-prestashop & cleanup obsolete code (#396) * feat: automate build_front for version number * refactor: update oauth2-prestashop & cleanup obsolete code * feat: module stats --- Makefile | 36 +++++++++++++--------- README.md | 30 +++++++++---------- _dev/package.json | 2 +- composer.json | 4 +-- composer.lock | 28 ++++++++--------- config.xml | 2 +- ps_accounts.php | 4 +-- src/Provider/OAuth2/ShopProvider.php | 45 ---------------------------- 8 files changed, 55 insertions(+), 96 deletions(-) diff --git a/Makefile b/Makefile index c60028c1a..08b81523a 100644 --- a/Makefile +++ b/Makefile @@ -12,20 +12,17 @@ default: bundle help: @egrep "^# target" Makefile -clean: - git -c core.excludesfile=/dev/null clean -X -d -f - ########################################################## # target: version VERSION ?= $(shell git describe --tags | sed 's/^v//' | cut -d'-' -f1) version: - @echo "...$(VERSION)..." - sed -i -e "s/\(VERSION = \).*/\1\'${VERSION}\';/" ps_accounts.php - sed -i -e "s/\($this->version = \).*/\1\'${VERSION}\';/" ps_accounts.php - sed -i -e 's/\(<\/version>/\1'${VERSION}']]><\/version>/' config.xml - sed -i -e "s/\(\"version\"\: \).*/\1\"${VERSION}\",/" ./_dev/package.json + @echo "Setting up version number : $(VERSION)..." + @sed -i -e "s/\(VERSION = \).*/\1\'${VERSION}\';/" ps_accounts.php + @sed -i -e "s/\($this->version = \).*/\1\'${VERSION}\';/" ps_accounts.php + @sed -i -e 's/\(<\/version>/\1'${VERSION}']]><\/version>/' config.xml + @sed -i -e "s/\(\"version\"\: \).*/\1\"${VERSION}\",/" ./_dev/package.json ########################################################## # target: tests @@ -165,22 +162,30 @@ php-scoper: php-scoper-add-prefix php-scoper-dump-autoload php-scoper-fix-autolo BUNDLE_ENV ?= # ex: local|preprod|prod BUNDLE_ZIP ?= # ex: ps_accounts_flavor.zip +BUNDLE_VERSION ?= $(shell grep "" config.xml | sed 's/^.*\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/') +BUNDLE_JS ?= views/js/app.${BUNDLE_VERSION}.js -bundle: php-scoper config/config.yml +bundle: php-scoper config/config.yml build-front @./scripts/bundle-module.sh "${BUNDLE_ZIP}" "${BUNDLE_ENV}" -bundle-prod: php-scoper config/config.yml.prod +bundle-prod: php-scoper config/config.yml.prod build-front @./scripts/bundle-module.sh "ps_accounts.zip" "prod" -bundle-preprod: php-scoper config/config.yml.preprod +bundle-preprod: php-scoper config/config.yml.preprod build-front @./scripts/bundle-module.sh "ps_accounts_preprod.zip" "preprod" -build-front: +define build_front + yarn --cwd ./_dev --frozen-lockfile + yarn --cwd ./_dev build +endef + +${BUNDLE_JS}: ifndef YARN $(error "YARN is unavailable on your system, try `npm i -g yarn`") endif - yarn --cwd ./_dev --frozen-lockfile - yarn --cwd ./_dev build + $(call build_front) + +build-front: ${BUNDLE_JS} composer.phar: ifndef PHP @@ -188,6 +193,9 @@ ifndef PHP endif ./scripts/composer-install.sh +#clean: +# git -c core.excludesfile=/dev/null clean -X -d -f + ########################################################## # target: php-cs-fixer # target: autoindex diff --git a/README.md b/README.md index 77a7caaf2..c0ae44f26 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ + # PrestaShop Account +[![Source Code](https://img.shields.io/badge/source-PrestaShopCorp/ps_accounts-blue.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts) +[![Latest Version](https://img.shields.io/github/release/PrestaShopCorp/ps_accounts.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/releases) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/oauth2-prestashop/blob/main/LICENSE) +[![Build Status](https://img.shields.io/github/actions/workflow/status/PrestaShopCorp/ps_accounts/.github/workflows/php.yml?label=CI&logo=github&style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/actions?query=workflow%3ACI) +[![Total Downloads](https://img.shields.io/packagist/dt/PrestaShopCorp/ps_accounts.svg?style=flat-square)](https://packagist.org/packages/prestashopcorp/ps_accounts) + The module **ps_accounts** is the interface between your module and PrestaShop's services. It manages: - Shop association and dissociation processes. - Maintain secure communication between shop and Prestashop services. @@ -67,15 +74,15 @@ This modules manages the following tokens: This module has three parts: - [PS Accounts module](http://github.com/PrestaShopCorp/ps_accounts) - - This module must be installed. - - It's your interface between your module and PrestaShop Accounts service. + - This module must be installed. + - It's your interface between your module and PrestaShop Accounts service. - [PS Accounts Installer (Composer Library)](http://github.com/PrestaShopCorp/prestashop-accounts-installer) - - This library's role is here to compensate a lack of security between modules dependencies. If PS Accounts is removed while your module is still installed: it causes a crash of the PrestaShop module's page/feature. - - This library is here to install automatically PS Accounts if it's missing. - - It's your interface between your module and PrestaShop Accounts module - - You should never require directly PrestaShop\Module\PsAccounts namespace classes + - This library's role is here to compensate a lack of security between modules dependencies. If PS Accounts is removed while your module is still installed: it causes a crash of the PrestaShop module's page/feature. + - This library is here to install automatically PS Accounts if it's missing. + - It's your interface between your module and PrestaShop Accounts module + - You should never require directly PrestaShop\Module\PsAccounts namespace classes - [PrestaShop Accounts Vue Components](http://github.com/PrestaShopCorp/prestashop_accounts_vue_components) - - It's the front-end component you need to integrate into your module's configuration page. + - It's the front-end component you need to integrate into your module's configuration page. ## How to start working with PS Accounts as a PSx or Community Service developer? @@ -149,12 +156,3 @@ Those API has been removed: - `/orders` - `/products` - `/themes` - -## Custom hooks - -Here are listed custom hooks provided with this module : - -| Hook name | Payload | Description | -|------------------------------|------------------|------------------------------------------------------| -| actionShopAccountLinkAfter | shopId, shopUuid | Triggered after link has been acknowledged by shop | -| actionShopAccountUnlinkAfter | shopId, shopUuid | Triggered after unlink has been acknowledged by shop | diff --git a/_dev/package.json b/_dev/package.json index e9045e7e6..ecdef3d85 100644 --- a/_dev/package.json +++ b/_dev/package.json @@ -1,6 +1,6 @@ { "name": "ps_accounts", - "version": "7.0.1", + "version": "7.0.2", "private": true, "scripts": { "dev": "vite", diff --git a/composer.json b/composer.json index 2a6068d59..8feaf3f91 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "sentry/sentry": "^1.0", "segmentio/analytics-php": "^1.8", "ramsey/uuid": "^3.9", - "prestashopcorp/oauth2-prestashop": "dev-refactor/php-compat-range", + "prestashopcorp/oauth2-prestashop": "^2.0", "guzzlehttp/guzzle": "^6.0" }, "require-dev": { @@ -55,4 +55,4 @@ "author": "PrestaShop", "license": "AFL-3.0", "type": "prestashop-module" -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index da48fadbc..19138d50c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "156a8a7265bab31a90749944d2d56b30", + "content-hash": "98e8498a3566cb10fc3cb6e99e0441c9", "packages": [ { "name": "guzzlehttp/guzzle", @@ -803,16 +803,16 @@ }, { "name": "prestashopcorp/oauth2-prestashop", - "version": "dev-refactor/php-compat-range", + "version": "v2.0.0", "source": { "type": "git", "url": "https://github.com/PrestaShopCorp/oauth2-prestashop.git", - "reference": "eff1c2891a0815bd0df9c63c9f4fdd45a085146b" + "reference": "694ea5b33527f3d5d2ef91d3f7e040a5dd2ec048" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PrestaShopCorp/oauth2-prestashop/zipball/eff1c2891a0815bd0df9c63c9f4fdd45a085146b", - "reference": "eff1c2891a0815bd0df9c63c9f4fdd45a085146b", + "url": "https://api.github.com/repos/PrestaShopCorp/oauth2-prestashop/zipball/694ea5b33527f3d5d2ef91d3f7e040a5dd2ec048", + "reference": "694ea5b33527f3d5d2ef91d3f7e040a5dd2ec048", "shasum": "" }, "require": { @@ -853,9 +853,9 @@ ], "support": { "issues": "https://github.com/PrestaShopCorp/oauth2-prestashop/issues", - "source": "https://github.com/PrestaShopCorp/oauth2-prestashop/tree/refactor/php-compat-range" + "source": "https://github.com/PrestaShopCorp/oauth2-prestashop/tree/v2.0.0" }, - "time": "2024-03-05T08:20:27+00:00" + "time": "2024-05-22T12:33:38+00:00" }, { "name": "psr/cache", @@ -4404,16 +4404,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.0", + "version": "3.10.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + "reference": "57e09801c2fbae2d257b8b75bebb3deeb7e9deb2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/57e09801c2fbae2d257b8b75bebb3deeb7e9deb2", + "reference": "57e09801c2fbae2d257b8b75bebb3deeb7e9deb2", "shasum": "" }, "require": { @@ -4480,7 +4480,7 @@ "type": "open_collective" } ], - "time": "2024-02-16T15:06:51+00:00" + "time": "2024-05-20T08:11:32+00:00" }, { "name": "symfony/console", @@ -5096,9 +5096,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "prestashopcorp/oauth2-prestashop": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/config.xml b/config.xml index c610fd8f9..d6d699bc8 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_accounts - + diff --git a/ps_accounts.php b/ps_accounts.php index d0b7f9543..2abbf1edf 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -34,7 +34,7 @@ class Ps_accounts extends Module // Needed in order to retrieve the module version easier (in api call headers) than instanciate // the module each time to get the version - const VERSION = '7.0.1'; + const VERSION = '7.0.2'; /** * Admin tabs @@ -131,7 +131,7 @@ public function __construct() // We cannot use the const VERSION because the const is not computed by addons marketplace // when the zip is uploaded - $this->version = '7.0.1'; + $this->version = '7.0.2'; $this->module_key = 'abf2cd758b4d629b2944d3922ef9db73'; diff --git a/src/Provider/OAuth2/ShopProvider.php b/src/Provider/OAuth2/ShopProvider.php index 33ecd1642..a05e3c194 100644 --- a/src/Provider/OAuth2/ShopProvider.php +++ b/src/Provider/OAuth2/ShopProvider.php @@ -23,7 +23,6 @@ use PrestaShop\Module\PsAccounts\Adapter\Link; use PrestaShop\Module\PsAccounts\Vendor\League\OAuth2\Client\Provider\AbstractProvider; use PrestaShop\OAuth2\Client\Provider\PrestaShop; -use PrestaShop\OAuth2\Client\Provider\WellKnown; class ShopProvider extends PrestaShop { @@ -161,50 +160,6 @@ protected function getAuthorizationParameters(array $options) return parent::getAuthorizationParameters($options); } - /** - * @return WellKnown - */ - public function getWellKnown() - { - if (!isset($this->wellKnown)) { - try { - $this->wellKnown = new WellKnown( - $this->fetchWellKnown($this->getOauth2Url(), $this->verify) - ); - } catch (\Error $e) { - } catch (\Exception $e) { - } - if (isset($e)) { - $this->wellKnown = new WellKnown(); - } - } - - return $this->wellKnown; - } - - /** - * @param string $url - * @param bool $secure - * - * @return array - * - * @throws \Exception - */ - protected function fetchWellKnown($url, $secure = true) - { - $wellKnownUrl = $url; - if (strpos($wellKnownUrl, '/.well-known') === false) { - $wellKnownUrl = preg_replace('/\/?$/', '/.well-known/openid-configuration', $wellKnownUrl); - } - - return json_decode((string) \Tools::file_get_contents($wellKnownUrl, false, stream_context_create([ - 'ssl' => [ - 'verify_peer' => $secure, - 'verify_peer_name' => $secure, - ], - ])), true) ?: []; - } - /** * @return void */