Update/implement connect to jetpack (#38674)

* Add install-and-activate-plugins-async action to onboarding

* Add label and learn_more_link types

* Use label and learn_more_link

* Remove unused imports

* ts fixes

* Visual changes on the plugin page

* Change CTA font size from 13px to 14px
* Change spacing between the chebox and logo to 24px
* Change heading font-weight to 500

* Fix css lint error

* Add back learn more link that was removed from rebase

* Add required packages

* Load Jetpack Config

* Add getJetpackAuthUrl to data/onboarding

* Add Connection Rest Auth -- seems like this is required for Jetpack to communicate back to the connected site

* Add jetpack-authorization-url REST API

* Redirect to Jetpack Auth page after the installatino process if jetpack was selected

* Require can_install_plugins permission for jetpack auth url endpoint

* Update packages/js/data/src/onboarding/resolvers.ts

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>

* Update plugins/woocommerce/src/Admin/API/OnboardingPlugins.php

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>

* Remove automattic/jetpack-sync and its config

* Support redirect_url and from params

* Do not redirect to Jetpack auth if it is already connected

* Add installed_ext_success=1

* Use woocommerce-core-profiler for from value

* Revert unrelated lock file changes

* Minor refactor

* Extracted out isJetpackConnected cond to a guard

* Added meta data for isJetpackConnected to prevent unwanted spinner

* Add Changelog

* Lint fix

* Move Jetpack Connection config init to class-woocommerce

* Add changelog

* Remove unnecessary require

* Note jetpack-authorization-url endpoint is experimental

* Fix broken test

* Add component to sendToJetPackAuthPage state

* Fix lint error

---------

Co-authored-by: rjchow <me@rjchow.com>
Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
This commit is contained in:
Moon 2023-06-15 20:28:18 -07:00 committed by GitHub
parent 950c25b4a0
commit 630faadb81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 635 additions and 26 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add Jetpack Connection Auth endpoint.

View File

@ -36,6 +36,7 @@ const TYPES = {
VISITED_TASK: 'VISITED_TASK',
KEEP_COMPLETED_TASKS_REQUEST: 'KEEP_COMPLETED_TASKS_REQUEST',
KEEP_COMPLETED_TASKS_SUCCESS: 'KEEP_COMPLETED_TASKS_SUCCESS',
SET_JETPACK_AUTH_URL: 'SET_JETPACK_AUTH_URL',
} as const;
export default TYPES;

View File

@ -488,6 +488,19 @@ export function* installAndActivatePluginsAsync(
}
}
export function setJetpackAuthUrl(
jetpackAuthUrl: string,
redirectUrl: string,
from = ''
) {
return {
type: TYPES.SET_JETPACK_AUTH_URL,
jetpackAuthUrl,
redirectUrl,
from,
};
}
export type Action = ReturnType<
| typeof getFreeExtensionsError
| typeof getFreeExtensionsSuccess
@ -524,4 +537,5 @@ export type Action = ReturnType<
| typeof actionTaskRequest
| typeof getProductTypesError
| typeof getProductTypesSuccess
| typeof setJetpackAuthUrl
>;

View File

@ -38,6 +38,7 @@ export const defaultState: OnboardingState = {
productTypes: {},
requesting: {},
taskLists: {},
jetpackAuthUrls: {},
};
const getUpdatedTaskLists = (
@ -428,6 +429,14 @@ const reducer: Reducer< OnboardingState, Action > = (
},
taskLists: getUpdatedTaskLists( state.taskLists, action.task ),
};
case TYPES.SET_JETPACK_AUTH_URL:
return {
...state,
jetpackAuthUrls: {
...state.jetpackAuthUrls,
[ action.redirectUrl ]: action.jetpackAuthUrl,
},
};
default:
return state;
}

View File

@ -20,6 +20,7 @@ import {
setEmailPrefill,
getProductTypesSuccess,
getProductTypesError,
setJetpackAuthUrl,
} from './actions';
import { DeprecatedTasks } from './deprecated-tasks';
import {
@ -136,3 +137,34 @@ export function* getProductTypes() {
yield getProductTypesError( error );
}
}
export function* getJetpackAuthUrl( query: {
redirectUrl: string;
from?: string;
} ) {
try {
let path =
WC_ADMIN_NAMESPACE +
'/onboarding/plugins/jetpack-authorization-url?redirect_url=' +
encodeURIComponent( query.redirectUrl );
if ( query.from ) {
path += '&from=' + query.from;
}
const results: {
url: string;
} = yield apiFetch( {
path,
method: 'GET',
} );
yield setJetpackAuthUrl(
results.url,
query.redirectUrl,
query.from ?? ''
);
} catch ( error ) {
yield setError( 'getJetpackAuthUrl', error );
}
}

View File

@ -95,6 +95,16 @@ export const getProductTypes = ( state: OnboardingState ) => {
return state.productTypes || {};
};
export const getJetpackAuthUrl = (
state: OnboardingState,
query: {
redirectUrl: string;
from?: string;
}
): string => {
return state.jetpackAuthUrls[ query.redirectUrl ] || '';
};
export type OnboardingSelectors = {
getProfileItems: () => ReturnType< typeof getProfileItems >;
getPaymentGatewaySuggestions: () => ReturnType<

View File

@ -57,6 +57,7 @@ describe( 'plugins reducer', () => {
emailPrefill: '',
errors: {},
requesting: {},
jetpackAuthUrls: {},
},
{
type: TYPES.SET_PROFILE_ITEMS,
@ -79,6 +80,7 @@ describe( 'plugins reducer', () => {
emailPrefill: '',
errors: {},
requesting: {},
jetpackAuthUrls: {},
},
{
type: TYPES.SET_PROFILE_ITEMS,

View File

@ -80,6 +80,7 @@ export type OnboardingState = {
// TODO clarify what the error record's type is
errors: Record< string, unknown >;
requesting: Record< string, boolean >;
jetpackAuthUrls: Record< string, string >;
};
export type Industry = {
@ -191,7 +192,7 @@ export type Extension = {
export type InstallAndActivatePluginsAsyncResponse = {
job_id: string;
status: 'pending' | 'in-progress' | 'completed' | 'failed';
status: 'pendi<ng' | 'in-progress' | 'completed' | 'failed';
plugins: Array< {
status: 'pending' | 'installing' | 'installed' | 'activated' | 'failed';
errors: string[];

View File

@ -20,6 +20,10 @@
margin-top: 6px;
}
.components-checkbox-control__input-container {
margin-top: 6px;
}
input {
margin: 3px 26px 0 0;
width: 20px;

View File

@ -25,9 +25,11 @@ import {
ONBOARDING_STORE_NAME,
Extension,
GeolocationResponse,
PLUGINS_STORE_NAME,
} from '@woocommerce/data';
import { initializeExPlat } from '@woocommerce/explat';
import { CountryStateOption } from '@woocommerce/onboarding';
import { getAdminLink } from '@woocommerce/settings';
/**
* Internal dependencies
@ -173,6 +175,7 @@ export type CoreProfilerStateMachineContext = {
stageIndex?: number;
};
onboardingProfile: OnboardingProfile;
jetpackAuthUrl?: string;
};
const getAllowTrackingOption = async () =>
@ -572,6 +575,7 @@ export const coreProfilerStateMachineDefinition = createMachine( {
pluginsSelected: [],
loader: {},
onboardingProfile: {} as OnboardingProfile,
jetpackAuthUrl: undefined,
} as CoreProfilerStateMachineContext,
states: {
navigate: {
@ -1170,8 +1174,59 @@ export const coreProfilerStateMachineDefinition = createMachine( {
completed: true,
} );
},
onDone: [
{
target: 'isJetpackConnected',
cond: 'hasJetpackSelected',
},
{ actions: 'redirectToWooHome' },
],
},
meta: {
component: Loader,
progress: 100,
},
},
isJetpackConnected: {
invoke: {
src: async () => {
return await resolveSelect(
PLUGINS_STORE_NAME
).isJetpackConnected();
},
onDone: [
{
target: 'sendToJetpackAuthPage',
cond: ( _context, event ) => {
return ! event.data;
},
},
{ actions: 'redirectToWooHome' },
],
},
meta: {
component: Loader,
progress: 100,
},
},
sendToJetpackAuthPage: {
invoke: {
src: async () =>
await resolveSelect(
ONBOARDING_STORE_NAME
).getJetpackAuthUrl( {
redirectUrl: getAdminLink(
'admin.php?page=wc-admin'
),
from: 'woocommerce-core-profiler',
} ),
onDone: {
actions: 'redirectToWooHome',
actions: [
( _context, event ) => {
window.location.href =
event.data + '&installed_ext_success=1';
},
],
},
},
meta: {
@ -1289,6 +1344,17 @@ export const CoreProfilerController = ( {
step === ( cond as { step: string | undefined } ).step
);
},
hasJetpackSelected: ( context ) => {
return (
context.pluginsSelected.find(
( plugin ) => plugin === 'jetpack'
) !== undefined ||
context.pluginsAvailable.find(
( plugin: Extension ) =>
plugin.key === 'jetpack' && plugin.is_activated
) !== undefined
);
},
},
} );
}, [ actionOverrides, servicesOverrides ] );

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add Jetpack Connection package

View File

@ -15,8 +15,10 @@
],
"require": {
"php": ">=7.3",
"automattic/jetpack-autoloader": "2.10.1",
"automattic/jetpack-constants": "1.5.1",
"automattic/jetpack-autoloader": "2.11.18",
"automattic/jetpack-config": "1.15.2",
"automattic/jetpack-connection": "1.51.7",
"automattic/jetpack-constants": "^1.6.22",
"composer/installers": "^1.9",
"maxmind-db/reader": "^1.11",
"pelago/emogrifier": "^6.0",

View File

@ -7,35 +7,136 @@
"content-hash": "b1d5a20abe69ad3d56826ed31d703360",
"packages": [
{
"name": "automattic/jetpack-autoloader",
"version": "2.10.1",
"name": "automattic/jetpack-a8c-mc-stats",
"version": "v1.4.20",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-autoloader.git",
"reference": "20393c4677765c3e737dcb5aee7a3f7b90dce4b3"
"url": "https://github.com/Automattic/jetpack-a8c-mc-stats.git",
"reference": "6743d34fe7556455e17cbe1b7c90ed39a1f69089"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/20393c4677765c3e737dcb5aee7a3f7b90dce4b3",
"reference": "20393c4677765c3e737dcb5aee7a3f7b90dce4b3",
"url": "https://api.github.com/repos/Automattic/jetpack-a8c-mc-stats/zipball/6743d34fe7556455e17cbe1b7c90ed39a1f69089",
"reference": "6743d34fe7556455e17cbe1b7c90ed39a1f69089",
"shasum": ""
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-a8c-mc-stats",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.4.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Used to record internal usage stats for Automattic. Not visible to site owners.",
"support": {
"source": "https://github.com/Automattic/jetpack-a8c-mc-stats/tree/v1.4.20"
},
"time": "2023-04-10T11:43:38+00:00"
},
{
"name": "automattic/jetpack-admin-ui",
"version": "v0.2.20",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-admin-ui.git",
"reference": "90f4de6c9d936bbf161f1c2356d98b00ba33576f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-admin-ui/zipball/90f4de6c9d936bbf161f1c2356d98b00ba33576f",
"reference": "90f4de6c9d936bbf161f1c2356d98b00ba33576f",
"shasum": ""
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/jetpack-logo": "^1.6.1",
"automattic/wordbless": "dev-master",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-admin-ui",
"textdomain": "jetpack-admin-ui",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-admin-ui/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "0.2.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-admin-menu.php"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Generic Jetpack wp-admin UI elements",
"support": {
"source": "https://github.com/Automattic/jetpack-admin-ui/tree/v0.2.20"
},
"time": "2023-04-25T15:05:53+00:00"
},
{
"name": "automattic/jetpack-autoloader",
"version": "v2.11.18",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-autoloader.git",
"reference": "53cbf0528fa6931c4fa6465bccd37514f9eda720"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/53cbf0528fa6931c4fa6465bccd37514f9eda720",
"reference": "53cbf0528fa6931c4fa6465bccd37514f9eda720",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.1 || ^2.0"
},
"require-dev": {
"automattic/jetpack-changelogger": "^1.1",
"yoast/phpunit-polyfills": "0.2.0"
"automattic/jetpack-changelogger": "^3.3.2",
"yoast/phpunit-polyfills": "1.0.4"
},
"type": "composer-plugin",
"extra": {
"autotagger": true,
"class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin",
"mirror-repo": "Automattic/jetpack-autoloader",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-autoloader/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-master": "2.10.x-dev"
"dev-trunk": "2.11.x-dev"
}
},
"autoload": {
@ -52,29 +153,153 @@
],
"description": "Creates a custom autoloader for a plugin or theme.",
"support": {
"source": "https://github.com/Automattic/jetpack-autoloader/tree/2.10.1"
"source": "https://github.com/Automattic/jetpack-autoloader/tree/v2.11.18"
},
"time": "2021-03-30T15:15:59+00:00"
"time": "2023-03-29T12:51:59+00:00"
},
{
"name": "automattic/jetpack-constants",
"version": "v1.5.1",
"name": "automattic/jetpack-config",
"version": "v1.15.2",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-constants.git",
"reference": "18f772daddc8be5df76c9f4a92e017a3c2569a5b"
"url": "https://github.com/Automattic/jetpack-config.git",
"reference": "f1fa6e24a89192336a1499968bf8c68e173b6e34"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/18f772daddc8be5df76c9f4a92e017a3c2569a5b",
"reference": "18f772daddc8be5df76c9f4a92e017a3c2569a5b",
"url": "https://api.github.com/repos/Automattic/jetpack-config/zipball/f1fa6e24a89192336a1499968bf8c68e173b6e34",
"reference": "f1fa6e24a89192336a1499968bf8c68e173b6e34",
"shasum": ""
},
"require-dev": {
"php-mock/php-mock": "^2.1",
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5"
"automattic/jetpack-changelogger": "^3.3.2"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-config",
"textdomain": "jetpack-config",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-config/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.15.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Jetpack configuration package that initializes other packages and configures Jetpack's functionality. Can be used as a base for all variants of Jetpack package usage.",
"support": {
"source": "https://github.com/Automattic/jetpack-config/tree/v1.15.2"
},
"time": "2023-04-10T11:43:31+00:00"
},
{
"name": "automattic/jetpack-connection",
"version": "v1.51.7",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-connection.git",
"reference": "4c4bae836858957d9aaf6854cf4e24c3261242c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-connection/zipball/4c4bae836858957d9aaf6854cf4e24c3261242c4",
"reference": "4c4bae836858957d9aaf6854cf4e24c3261242c4",
"shasum": ""
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.20",
"automattic/jetpack-admin-ui": "^0.2.19",
"automattic/jetpack-constants": "^1.6.22",
"automattic/jetpack-redirect": "^1.7.25",
"automattic/jetpack-roles": "^1.4.23",
"automattic/jetpack-status": "^1.16.4"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "@dev",
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-connection",
"textdomain": "jetpack-connection",
"version-constants": {
"::PACKAGE_VERSION": "src/class-package-version.php"
},
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.51.x-dev"
}
},
"autoload": {
"classmap": [
"legacy",
"src/",
"src/webhooks"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Everything needed to connect to the Jetpack infrastructure",
"support": {
"source": "https://github.com/Automattic/jetpack-connection/tree/v1.51.7"
},
"time": "2023-04-10T11:44:13+00:00"
},
{
"name": "automattic/jetpack-constants",
"version": "v1.6.22",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-constants.git",
"reference": "7b5c44d763c7b0dd7498be2b41a89bfefe84834c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/7b5c44d763c7b0dd7498be2b41a89bfefe84834c",
"reference": "7b5c44d763c7b0dd7498be2b41a89bfefe84834c",
"shasum": ""
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-constants",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-constants/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.6.x-dev"
}
},
"type": "library",
"autoload": {
"classmap": [
"src/"
@ -86,9 +311,160 @@
],
"description": "A wrapper for defining constants in a more testable way.",
"support": {
"source": "https://github.com/Automattic/jetpack-constants/tree/v1.5.1"
"source": "https://github.com/Automattic/jetpack-constants/tree/v1.6.22"
},
"time": "2020-10-28T19:00:31+00:00"
"time": "2023-04-10T11:43:45+00:00"
},
{
"name": "automattic/jetpack-redirect",
"version": "v1.7.25",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-redirect.git",
"reference": "67d7dce123d4af4fec4b4fe15e99aaad85308314"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-redirect/zipball/67d7dce123d4af4fec4b4fe15e99aaad85308314",
"reference": "67d7dce123d4af4fec4b4fe15e99aaad85308314",
"shasum": ""
},
"require": {
"automattic/jetpack-status": "^1.16.4"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-redirect",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-redirect/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.7.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Utilities to build URLs to the jetpack.com/redirect/ service",
"support": {
"source": "https://github.com/Automattic/jetpack-redirect/tree/v1.7.25"
},
"time": "2023-04-10T11:44:05+00:00"
},
{
"name": "automattic/jetpack-roles",
"version": "v1.4.23",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-roles.git",
"reference": "f147b3e8061fc0de2a892ddc4f4156eb995545f9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-roles/zipball/f147b3e8061fc0de2a892ddc4f4156eb995545f9",
"reference": "f147b3e8061fc0de2a892ddc4f4156eb995545f9",
"shasum": ""
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-roles",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-roles/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.4.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Utilities, related with user roles and capabilities.",
"support": {
"source": "https://github.com/Automattic/jetpack-roles/tree/v1.4.23"
},
"time": "2023-04-10T11:43:48+00:00"
},
{
"name": "automattic/jetpack-status",
"version": "v1.17.1",
"source": {
"type": "git",
"url": "https://github.com/Automattic/jetpack-status.git",
"reference": "0032ee4bce1d4644722ba46858c702a0afa76cff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/jetpack-status/zipball/0032ee4bce1d4644722ba46858c702a0afa76cff",
"reference": "0032ee4bce1d4644722ba46858c702a0afa76cff",
"shasum": ""
},
"require": {
"automattic/jetpack-constants": "^1.6.22"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/jetpack-ip": "^0.1.3",
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
},
"type": "jetpack-library",
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-status",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-status/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.17.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"description": "Used to retrieve information about the current status of Jetpack and the site overall.",
"support": {
"source": "https://github.com/Automattic/jetpack-status/tree/v1.17.1"
},
"time": "2023-05-11T05:50:45+00:00"
},
{
"name": "composer/installers",

View File

@ -204,6 +204,22 @@ final class WooCommerce {
do_action( 'woocommerce_loaded' );
}
/**
* Initiali Jetpack Connection Config.
*
* @return void
*/
public function init_jetpack_connection_config() {
$config = new Automattic\Jetpack\Config();
$config->ensure(
'connection',
array(
'slug' => 'woocommerce',
'name' => __( 'WooCommerce', 'woocommerce' ),
)
);
}
/**
* Hook into actions and filters.
*
@ -214,6 +230,7 @@ final class WooCommerce {
register_shutdown_function( array( $this, 'log_errors' ) );
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), -1 );
add_action( 'plugins_loaded', array( $this, 'init_jetpack_connection_config' ), 1 );
add_action( 'admin_notices', array( $this, 'build_dependencies_notice' ) );
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );

View File

@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API;
defined( 'ABSPATH' ) || exit;
use ActionScheduler;
use Automattic\Jetpack\Connection\Manager;
use Automattic\WooCommerce\Admin\PluginsHelper;
use Automattic\WooCommerce\Admin\PluginsInstallLoggers\AsynPluginsInstallLogger;
use WC_REST_Data_Controller;
@ -95,6 +96,34 @@ class OnboardingPlugins extends WC_REST_Data_Controller {
'schema' => array( $this, 'get_install_async_schema' ),
)
);
// This is an experimental endpoint and is subject to change in the future.
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/jetpack-authorization-url',
array(
array(
'methods' => 'GET',
'callback' => array( $this, 'get_jetpack_authorization_url' ),
'permission_callback' => array( $this, 'can_install_plugins' ),
'args' => array(
'redirect_url' => array(
'description' => 'The URL to redirect to after authorization',
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'required' => true,
),
'from' => array(
'description' => 'from value for the jetpack authorization page',
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'required' => false,
'default' => 'woocommerce-onboarding',
),
),
),
)
);
}
/**
@ -183,6 +212,39 @@ class OnboardingPlugins extends WC_REST_Data_Controller {
return $response;
}
/**
* Return Jetpack authorization URL.
*
* @param WP_REST_Request $request WP_REST_Request object.
*
* @return array
* @throws \Exception If there is an error registering the site.
*/
public function get_jetpack_authorization_url( WP_REST_Request $request ) {
$manager = new Manager( 'woocommerce' );
// Register the site to wp.com.
if ( ! $manager->is_connected() ) {
$result = $manager->try_registration();
if ( is_wp_error( $result ) ) {
throw new \Exception( $result->get_error_message() );
}
}
$redirect_url = $request->get_param( 'redirect_url' );
$calypso_env = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, [ 'development', 'wpcalypso', 'horizon', 'stage' ], true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production';
return [
'url' => add_query_arg(
[
'from' => $request->get_param( 'from' ),
'calypso_env' => $calypso_env,
],
$manager->get_authorization_url( null, $redirect_url )
),
];
}
/**
* Check whether the current user has permission to install plugins
*

View File

@ -60,3 +60,8 @@ function wc_get_container() {
// Global for backwards compatibility.
$GLOBALS['woocommerce'] = WC();
// Jetpack's Rest_Authentication needs to be initialized even before plugins_loaded.
if ( class_exists( \Automattic\Jetpack\Connection\Rest_Authentication::class ) ) {
\Automattic\Jetpack\Connection\Rest_Authentication::init();
}