@wp-playground/client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +2 -1
  2. package/index.cjs +350 -32
  3. package/index.d.ts +172 -120
  4. package/index.js +2541 -2123
  5. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -668,6 +668,8 @@ export declare const SupportedPHPVersions: readonly [
668
668
  export declare const LatestSupportedPHPVersion: "8.2";
669
669
  export declare const SupportedPHPVersionsList: string[];
670
670
  export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
671
+ export type SupportedPHPExtension = "iconv" | "mbstring" | "xml-bundle" | "gd";
672
+ export type SupportedPHPExtensionBundle = "kitchen-sink";
671
673
  export interface PHPRequestHandlerConfiguration {
672
674
  /**
673
675
  * The directory in the PHP filesystem where the server will look
@@ -678,11 +680,6 @@ export interface PHPRequestHandlerConfiguration {
678
680
  * Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
679
681
  */
680
682
  absoluteUrl?: string;
681
- /**
682
- * Callback used by the PHPRequestHandler to decide whether
683
- * the requested path refers to a PHP file or a static file.
684
- */
685
- isStaticFilePath?: (path: string) => boolean;
686
683
  }
687
684
  /** @inheritDoc */
688
685
  export declare class PHPRequestHandler implements RequestHandler {
@@ -1064,6 +1061,15 @@ export declare class SemaphoreResource<T extends Resource> extends DecoratedReso
1064
1061
  }
1065
1062
  /**
1066
1063
  * @inheritDoc activatePlugin
1064
+ * @example
1065
+ *
1066
+ * <code>
1067
+ * {
1068
+ * "step": "activatePlugin",
1069
+ * "pluginName": "Gutenberg",
1070
+ * "pluginPath": "/wordpress/wp-content/plugins/gutenberg"
1071
+ * }
1072
+ * </code>
1067
1073
  */
1068
1074
  export interface ActivatePluginStep {
1069
1075
  step: "activatePlugin";
@@ -1089,6 +1095,8 @@ export interface ApplyWordPressPatchesStep {
1089
1095
  patchSecrets?: boolean;
1090
1096
  disableSiteHealth?: boolean;
1091
1097
  disableWpNewBlogNotification?: boolean;
1098
+ makeEditorFrameControlled?: boolean;
1099
+ prepareForRunningInsideWebBrowser?: boolean;
1092
1100
  }
1093
1101
  export declare const applyWordPressPatches: StepHandler<ApplyWordPressPatchesStep>;
1094
1102
  /**
@@ -1126,6 +1134,14 @@ export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
1126
1134
  export declare function zipEntireSite(playground: UniversalPHP): Promise<File>;
1127
1135
  /**
1128
1136
  * @inheritDoc replaceSite
1137
+ * @example
1138
+ *
1139
+ * <code>
1140
+ * {
1141
+ * "step": "replaceSite",
1142
+ * "fullSiteZip": "https://mysite.com/import.zip"
1143
+ * }
1144
+ * </code>
1129
1145
  */
1130
1146
  export interface ReplaceSiteStep<ResourceType> {
1131
1147
  step: "replaceSite";
@@ -1143,6 +1159,15 @@ export interface ReplaceSiteStep<ResourceType> {
1143
1159
  export declare const replaceSite: StepHandler<ReplaceSiteStep<File>>;
1144
1160
  /**
1145
1161
  * @inheritDoc unzip
1162
+ * @example
1163
+ *
1164
+ * <code>
1165
+ * {
1166
+ * "step": "unzip",
1167
+ * "zipPath": "/wordpress/data.zip",
1168
+ * "extractToPath": "/wordpress"
1169
+ * }
1170
+ * </code>
1146
1171
  */
1147
1172
  export interface UnzipStep {
1148
1173
  step: "unzip";
@@ -1161,6 +1186,14 @@ export interface UnzipStep {
1161
1186
  export declare const unzip: StepHandler<UnzipStep>;
1162
1187
  /**
1163
1188
  * @inheritDoc importFile
1189
+ * @example
1190
+ *
1191
+ * <code>
1192
+ * {
1193
+ * "step": "importFile",
1194
+ * "file": "https://mysite.com/import.WXR"
1195
+ * }
1196
+ * </code>
1164
1197
  */
1165
1198
  export interface ImportFileStep<ResourceType> {
1166
1199
  step: "importFile";
@@ -1381,225 +1414,225 @@ export interface UpdateUserMetaStep {
1381
1414
  */
1382
1415
  export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
1383
1416
  /**
1384
- * @inheritDoc runPHP
1417
+ * @inheritDoc rm
1385
1418
  * @hasRunnableExample
1419
+ * @landingPage /index.php
1386
1420
  * @example
1387
1421
  *
1388
1422
  * <code>
1389
1423
  * {
1390
- * "step": "runPHP",
1391
- * "code": "<?php echo 'Hello World'; ?>"
1424
+ * "step": "rm",
1425
+ * "path": "/wordpress/index.php"
1392
1426
  * }
1393
1427
  * </code>
1394
1428
  */
1395
- export interface RunPHPStep {
1396
- /** The step identifier. */
1397
- step: "runPHP";
1398
- /** The PHP code to run. */
1399
- code: string;
1429
+ export interface RmStep {
1430
+ step: "rm";
1431
+ /** The path to remove */
1432
+ path: string;
1400
1433
  }
1401
1434
  /**
1402
- * Runs PHP code.
1435
+ * Removes a file at the specified path.
1403
1436
  */
1404
- export declare const runPHP: StepHandler<RunPHPStep>;
1437
+ export declare const rm: StepHandler<RmStep>;
1405
1438
  /**
1406
- * @inheritDoc runPHP
1439
+ * @inheritDoc cp
1407
1440
  * @hasRunnableExample
1441
+ * @landingPage /index2.php
1408
1442
  * @example
1409
1443
  *
1410
1444
  * <code>
1411
1445
  * {
1412
- * "step": "runPHP",
1413
- * "options": {
1414
- * "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
1415
- * "headers": {
1416
- * "Content-type": "text/plain"
1417
- * }
1418
- * }
1446
+ * "step": "cp",
1447
+ * "fromPath": "/wordpress/index.php",
1448
+ * "toPath": "/wordpress/index2.php"
1419
1449
  * }
1420
1450
  * </code>
1421
1451
  */
1422
- export interface RunPHPWithOptionsStep {
1423
- step: "runPHPWithOptions";
1424
- /**
1425
- * Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
1426
- */
1427
- options: PHPRunOptions;
1452
+ export interface CpStep {
1453
+ step: "cp";
1454
+ /** Source path */
1455
+ fromPath: string;
1456
+ /** Target path */
1457
+ toPath: string;
1428
1458
  }
1429
1459
  /**
1430
- * Runs PHP code with the given options.
1460
+ * Copies a file from one path to another.
1431
1461
  */
1432
- export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
1462
+ export declare const cp: StepHandler<CpStep>;
1433
1463
  /**
1434
- * @inheritDoc setPhpIniEntry
1464
+ * @inheritDoc rmdir
1435
1465
  * @hasRunnableExample
1466
+ * @landingPage /wp-admin/
1436
1467
  * @example
1437
1468
  *
1438
1469
  * <code>
1439
1470
  * {
1440
- * "step": "setPhpIniEntry",
1441
- * "key": "display_errors",
1442
- * "value": "1"
1471
+ * "step": "rmdir",
1472
+ * "path": "/wordpress/wp-admin"
1443
1473
  * }
1444
1474
  * </code>
1445
1475
  */
1446
- export interface SetPhpIniEntryStep {
1447
- step: "setPhpIniEntry";
1448
- /** Entry name e.g. "display_errors" */
1449
- key: string;
1450
- /** Entry value as a string e.g. "1" */
1451
- value: string;
1476
+ export interface RmdirStep {
1477
+ step: "rmdir";
1478
+ /** The path to remove */
1479
+ path: string;
1452
1480
  }
1453
1481
  /**
1454
- * Sets a PHP ini entry.
1482
+ * Removes a directory at the specified path.
1455
1483
  */
1456
- export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
1484
+ export declare const rmdir: StepHandler<RmdirStep>;
1457
1485
  /**
1458
- * @inheritDoc request
1459
- * @needsLogin
1486
+ * @inheritDoc mkdir
1460
1487
  * @hasRunnableExample
1461
1488
  * @example
1462
1489
  *
1463
1490
  * <code>
1464
1491
  * {
1465
- * "step": "request",
1466
- * "request": {
1467
- * "method": "POST",
1468
- * "url": "/wp-admin/admin-ajax.php",
1469
- * "formData": {
1470
- * "action": "my_action",
1471
- * "foo": "bar"
1472
- * }
1473
- * }
1492
+ * "step": "mkdir",
1493
+ * "path": "/wordpress/my-new-folder"
1474
1494
  * }
1475
1495
  * </code>
1476
1496
  */
1477
- export interface RequestStep {
1478
- step: "request";
1479
- /**
1480
- * Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
1481
- */
1482
- request: PHPRequest;
1497
+ export interface MkdirStep {
1498
+ step: "mkdir";
1499
+ /** The path of the directory you want to create */
1500
+ path: string;
1483
1501
  }
1484
1502
  /**
1485
- * Sends a HTTP request to the Playground.
1503
+ * Creates a directory at the specified path.
1486
1504
  */
1487
- export declare const request: StepHandler<RequestStep>;
1505
+ export declare const mkdir: StepHandler<MkdirStep>;
1488
1506
  /**
1489
- * @inheritDoc cp
1507
+ * @inheritDoc mv
1490
1508
  * @hasRunnableExample
1491
1509
  * @landingPage /index2.php
1492
1510
  * @example
1493
1511
  *
1494
1512
  * <code>
1495
1513
  * {
1496
- * "step": "cp",
1514
+ * "step": "mv",
1497
1515
  * "fromPath": "/wordpress/index.php",
1498
1516
  * "toPath": "/wordpress/index2.php"
1499
1517
  * }
1500
1518
  * </code>
1501
1519
  */
1502
- export interface CpStep {
1503
- step: "cp";
1520
+ export interface MvStep {
1521
+ step: "mv";
1504
1522
  /** Source path */
1505
1523
  fromPath: string;
1506
1524
  /** Target path */
1507
1525
  toPath: string;
1508
1526
  }
1509
1527
  /**
1510
- * Copies a file from one path to another.
1528
+ * Moves a file or directory from one path to another.
1511
1529
  */
1512
- export declare const cp: StepHandler<CpStep>;
1530
+ export declare const mv: StepHandler<MvStep>;
1513
1531
  /**
1514
- * @inheritDoc mv
1532
+ * @inheritDoc setPhpIniEntry
1515
1533
  * @hasRunnableExample
1516
- * @landingPage /index2.php
1517
1534
  * @example
1518
1535
  *
1519
1536
  * <code>
1520
1537
  * {
1521
- * "step": "mv",
1522
- * "fromPath": "/wordpress/index.php",
1523
- * "toPath": "/wordpress/index2.php"
1538
+ * "step": "setPhpIniEntry",
1539
+ * "key": "display_errors",
1540
+ * "value": "1"
1524
1541
  * }
1525
1542
  * </code>
1526
1543
  */
1527
- export interface MvStep {
1528
- step: "mv";
1529
- /** Source path */
1530
- fromPath: string;
1531
- /** Target path */
1532
- toPath: string;
1544
+ export interface SetPhpIniEntryStep {
1545
+ step: "setPhpIniEntry";
1546
+ /** Entry name e.g. "display_errors" */
1547
+ key: string;
1548
+ /** Entry value as a string e.g. "1" */
1549
+ value: string;
1533
1550
  }
1534
1551
  /**
1535
- * Moves a file or directory from one path to another.
1552
+ * Sets a PHP ini entry.
1536
1553
  */
1537
- export declare const mv: StepHandler<MvStep>;
1554
+ export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
1538
1555
  /**
1539
- * @inheritDoc mkdir
1556
+ * @inheritDoc runPHP
1540
1557
  * @hasRunnableExample
1541
1558
  * @example
1542
1559
  *
1543
1560
  * <code>
1544
1561
  * {
1545
- * "step": "mkdir",
1546
- * "path": "/wordpress/my-new-folder"
1562
+ * "step": "runPHP",
1563
+ * "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post(array('post_title' => 'wp-load.php required for WP functionality', 'post_status' => 'publish')); ?>"
1547
1564
  * }
1548
1565
  * </code>
1549
1566
  */
1550
- export interface MkdirStep {
1551
- step: "mkdir";
1552
- /** The path of the directory you want to create */
1553
- path: string;
1567
+ export interface RunPHPStep {
1568
+ /** The step identifier. */
1569
+ step: "runPHP";
1570
+ /** The PHP code to run. */
1571
+ code: string;
1554
1572
  }
1555
1573
  /**
1556
- * Creates a directory at the specified path.
1574
+ * Runs PHP code.
1557
1575
  */
1558
- export declare const mkdir: StepHandler<MkdirStep>;
1576
+ export declare const runPHP: StepHandler<RunPHPStep>;
1559
1577
  /**
1560
- * @inheritDoc rm
1578
+ * @inheritDoc runPHP
1561
1579
  * @hasRunnableExample
1562
- * @landingPage /index.php
1563
1580
  * @example
1564
1581
  *
1565
1582
  * <code>
1566
1583
  * {
1567
- * "step": "rm",
1568
- * "path": "/wordpress/index.php"
1584
+ * "step": "runPHP",
1585
+ * "options": {
1586
+ * "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
1587
+ * "headers": {
1588
+ * "Content-type": "text/plain"
1589
+ * }
1590
+ * }
1569
1591
  * }
1570
1592
  * </code>
1571
1593
  */
1572
- export interface RmStep {
1573
- step: "rm";
1574
- /** The path to remove */
1575
- path: string;
1594
+ export interface RunPHPWithOptionsStep {
1595
+ step: "runPHPWithOptions";
1596
+ /**
1597
+ * Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
1598
+ */
1599
+ options: PHPRunOptions;
1576
1600
  }
1577
1601
  /**
1578
- * Removes a file at the specified path.
1602
+ * Runs PHP code with the given options.
1579
1603
  */
1580
- export declare const rm: StepHandler<RmStep>;
1604
+ export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
1581
1605
  /**
1582
- * @inheritDoc rmdir
1606
+ * @inheritDoc request
1607
+ * @needsLogin
1583
1608
  * @hasRunnableExample
1584
- * @landingPage /wp-admin/
1585
1609
  * @example
1586
1610
  *
1587
1611
  * <code>
1588
1612
  * {
1589
- * "step": "rm",
1590
- * "path": "/wordpress/wp-admin"
1613
+ * "step": "request",
1614
+ * "request": {
1615
+ * "method": "POST",
1616
+ * "url": "/wp-admin/admin-ajax.php",
1617
+ * "formData": {
1618
+ * "action": "my_action",
1619
+ * "foo": "bar"
1620
+ * }
1621
+ * }
1591
1622
  * }
1592
1623
  * </code>
1593
1624
  */
1594
- export interface RmdirStep {
1595
- step: "rmdir";
1596
- /** The path to remove */
1597
- path: string;
1625
+ export interface RequestStep {
1626
+ step: "request";
1627
+ /**
1628
+ * Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
1629
+ */
1630
+ request: PHPRequest;
1598
1631
  }
1599
1632
  /**
1600
- * Removes a directory at the specified path.
1633
+ * Sends a HTTP request to the Playground.
1601
1634
  */
1602
- export declare const rmdir: StepHandler<RmdirStep>;
1635
+ export declare const request: StepHandler<RequestStep>;
1603
1636
  /**
1604
1637
  * @inheritDoc writeFile
1605
1638
  * @hasRunnableExample
@@ -1661,6 +1694,15 @@ export interface DefineWpConfigConstsStep {
1661
1694
  export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
1662
1695
  /**
1663
1696
  * @inheritDoc activateTheme
1697
+ * @example
1698
+ *
1699
+ * <code>
1700
+ * {
1701
+ * "step": "activateTheme",
1702
+ * "pluginName": "Storefront",
1703
+ * "pluginPath": "/wordpress/wp-content/themes/storefront"
1704
+ * }
1705
+ * </code>
1664
1706
  */
1665
1707
  export interface ActivateThemeStep {
1666
1708
  step: "activateTheme";
@@ -1720,26 +1762,24 @@ export interface Blueprint {
1720
1762
  */
1721
1763
  wp: string | "latest";
1722
1764
  };
1765
+ /**
1766
+ * The PHP extensions to use.
1767
+ */
1768
+ phpExtensionBundles?: SupportedPHPExtensionBundle[];
1723
1769
  /**
1724
1770
  * The steps to run.
1725
1771
  */
1726
1772
  steps?: Array<StepDefinition | string | undefined | false | null>;
1727
1773
  }
1728
1774
  export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
1729
- declare const supportedWordPressVersions: readonly [
1730
- "6.2",
1731
- "6.1",
1732
- "6.0",
1733
- "5.9",
1734
- "nightly"
1735
- ];
1736
- export type supportedWordPressVersion = (typeof supportedWordPressVersions)[number];
1737
1775
  export interface CompiledBlueprint {
1738
1776
  /** The requested versions of PHP and WordPress for the blueprint */
1739
1777
  versions: {
1740
1778
  php: SupportedPHPVersion;
1741
- wp: supportedWordPressVersion;
1779
+ wp: string;
1742
1780
  };
1781
+ /** The requested PHP extensions to load */
1782
+ phpExtensions: SupportedPHPExtension[];
1743
1783
  /** The compiled steps for the blueprint */
1744
1784
  run: (playground: UniversalPHP) => Promise<void>;
1745
1785
  }
@@ -1780,6 +1820,8 @@ export interface PHPWebLoaderOptions {
1780
1820
  downloadMonitor?: EmscriptenDownloadMonitor;
1781
1821
  requestHandler?: PHPRequestHandlerConfiguration;
1782
1822
  dataModules?: Array<DataModule | Promise<DataModule>>;
1823
+ /** @deprecated To be replaced with `extensions` in the future */
1824
+ loadAllExtensions?: boolean;
1783
1825
  }
1784
1826
  declare class WebPHP extends BasePHP {
1785
1827
  /**
@@ -1884,7 +1926,17 @@ declare class PlaygroundWorkerEndpoint extends WebPHPEndpoint {
1884
1926
  getWordPressModuleDetails(): Promise<{
1885
1927
  majorVersion: string;
1886
1928
  staticAssetsDirectory: string;
1887
- defaultTheme: any;
1929
+ }>;
1930
+ getSupportedWordPressVersions(): Promise<{
1931
+ all: {
1932
+ nightly: string;
1933
+ beta: string;
1934
+ "6.3": string;
1935
+ "6.2": string;
1936
+ "6.1": string;
1937
+ "6.0": string;
1938
+ };
1939
+ latest: string;
1888
1940
  }>;
1889
1941
  resetVirtualOpfs(): Promise<void>;
1890
1942
  reloadFilesFromOpfs(): Promise<void>;