@wp-playground/client 0.2.0 → 0.3.1

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 +351 -33
  3. package/index.d.ts +177 -121
  4. package/index.js +2551 -2137
  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 {
@@ -1005,7 +1002,6 @@ export declare class UrlResource extends FetchResource {
1005
1002
  /** @inheritDoc */
1006
1003
  protected get caption(): string;
1007
1004
  }
1008
- export declare function setPluginProxyURL(url: string): void;
1009
1005
  /**
1010
1006
  * A `Resource` that represents a WordPress core theme.
1011
1007
  */
@@ -1064,6 +1060,15 @@ export declare class SemaphoreResource<T extends Resource> extends DecoratedReso
1064
1060
  }
1065
1061
  /**
1066
1062
  * @inheritDoc activatePlugin
1063
+ * @example
1064
+ *
1065
+ * <code>
1066
+ * {
1067
+ * "step": "activatePlugin",
1068
+ * "pluginName": "Gutenberg",
1069
+ * "pluginPath": "/wordpress/wp-content/plugins/gutenberg"
1070
+ * }
1071
+ * </code>
1067
1072
  */
1068
1073
  export interface ActivatePluginStep {
1069
1074
  step: "activatePlugin";
@@ -1089,6 +1094,8 @@ export interface ApplyWordPressPatchesStep {
1089
1094
  patchSecrets?: boolean;
1090
1095
  disableSiteHealth?: boolean;
1091
1096
  disableWpNewBlogNotification?: boolean;
1097
+ makeEditorFrameControlled?: boolean;
1098
+ prepareForRunningInsideWebBrowser?: boolean;
1092
1099
  }
1093
1100
  export declare const applyWordPressPatches: StepHandler<ApplyWordPressPatchesStep>;
1094
1101
  /**
@@ -1126,6 +1133,14 @@ export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
1126
1133
  export declare function zipEntireSite(playground: UniversalPHP): Promise<File>;
1127
1134
  /**
1128
1135
  * @inheritDoc replaceSite
1136
+ * @example
1137
+ *
1138
+ * <code>
1139
+ * {
1140
+ * "step": "replaceSite",
1141
+ * "fullSiteZip": "https://mysite.com/import.zip"
1142
+ * }
1143
+ * </code>
1129
1144
  */
1130
1145
  export interface ReplaceSiteStep<ResourceType> {
1131
1146
  step: "replaceSite";
@@ -1143,6 +1158,15 @@ export interface ReplaceSiteStep<ResourceType> {
1143
1158
  export declare const replaceSite: StepHandler<ReplaceSiteStep<File>>;
1144
1159
  /**
1145
1160
  * @inheritDoc unzip
1161
+ * @example
1162
+ *
1163
+ * <code>
1164
+ * {
1165
+ * "step": "unzip",
1166
+ * "zipPath": "/wordpress/data.zip",
1167
+ * "extractToPath": "/wordpress"
1168
+ * }
1169
+ * </code>
1146
1170
  */
1147
1171
  export interface UnzipStep {
1148
1172
  step: "unzip";
@@ -1161,6 +1185,14 @@ export interface UnzipStep {
1161
1185
  export declare const unzip: StepHandler<UnzipStep>;
1162
1186
  /**
1163
1187
  * @inheritDoc importFile
1188
+ * @example
1189
+ *
1190
+ * <code>
1191
+ * {
1192
+ * "step": "importFile",
1193
+ * "file": "https://mysite.com/import.WXR"
1194
+ * }
1195
+ * </code>
1164
1196
  */
1165
1197
  export interface ImportFileStep<ResourceType> {
1166
1198
  step: "importFile";
@@ -1381,225 +1413,225 @@ export interface UpdateUserMetaStep {
1381
1413
  */
1382
1414
  export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
1383
1415
  /**
1384
- * @inheritDoc runPHP
1416
+ * @inheritDoc rm
1385
1417
  * @hasRunnableExample
1418
+ * @landingPage /index.php
1386
1419
  * @example
1387
1420
  *
1388
1421
  * <code>
1389
1422
  * {
1390
- * "step": "runPHP",
1391
- * "code": "<?php echo 'Hello World'; ?>"
1423
+ * "step": "rm",
1424
+ * "path": "/wordpress/index.php"
1392
1425
  * }
1393
1426
  * </code>
1394
1427
  */
1395
- export interface RunPHPStep {
1396
- /** The step identifier. */
1397
- step: "runPHP";
1398
- /** The PHP code to run. */
1399
- code: string;
1428
+ export interface RmStep {
1429
+ step: "rm";
1430
+ /** The path to remove */
1431
+ path: string;
1400
1432
  }
1401
1433
  /**
1402
- * Runs PHP code.
1434
+ * Removes a file at the specified path.
1403
1435
  */
1404
- export declare const runPHP: StepHandler<RunPHPStep>;
1436
+ export declare const rm: StepHandler<RmStep>;
1405
1437
  /**
1406
- * @inheritDoc runPHP
1438
+ * @inheritDoc cp
1407
1439
  * @hasRunnableExample
1440
+ * @landingPage /index2.php
1408
1441
  * @example
1409
1442
  *
1410
1443
  * <code>
1411
1444
  * {
1412
- * "step": "runPHP",
1413
- * "options": {
1414
- * "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
1415
- * "headers": {
1416
- * "Content-type": "text/plain"
1417
- * }
1418
- * }
1445
+ * "step": "cp",
1446
+ * "fromPath": "/wordpress/index.php",
1447
+ * "toPath": "/wordpress/index2.php"
1419
1448
  * }
1420
1449
  * </code>
1421
1450
  */
1422
- export interface RunPHPWithOptionsStep {
1423
- step: "runPHPWithOptions";
1424
- /**
1425
- * Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
1426
- */
1427
- options: PHPRunOptions;
1451
+ export interface CpStep {
1452
+ step: "cp";
1453
+ /** Source path */
1454
+ fromPath: string;
1455
+ /** Target path */
1456
+ toPath: string;
1428
1457
  }
1429
1458
  /**
1430
- * Runs PHP code with the given options.
1459
+ * Copies a file from one path to another.
1431
1460
  */
1432
- export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
1461
+ export declare const cp: StepHandler<CpStep>;
1433
1462
  /**
1434
- * @inheritDoc setPhpIniEntry
1463
+ * @inheritDoc rmdir
1435
1464
  * @hasRunnableExample
1465
+ * @landingPage /wp-admin/
1436
1466
  * @example
1437
1467
  *
1438
1468
  * <code>
1439
1469
  * {
1440
- * "step": "setPhpIniEntry",
1441
- * "key": "display_errors",
1442
- * "value": "1"
1470
+ * "step": "rmdir",
1471
+ * "path": "/wordpress/wp-admin"
1443
1472
  * }
1444
1473
  * </code>
1445
1474
  */
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;
1475
+ export interface RmdirStep {
1476
+ step: "rmdir";
1477
+ /** The path to remove */
1478
+ path: string;
1452
1479
  }
1453
1480
  /**
1454
- * Sets a PHP ini entry.
1481
+ * Removes a directory at the specified path.
1455
1482
  */
1456
- export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
1483
+ export declare const rmdir: StepHandler<RmdirStep>;
1457
1484
  /**
1458
- * @inheritDoc request
1459
- * @needsLogin
1485
+ * @inheritDoc mkdir
1460
1486
  * @hasRunnableExample
1461
1487
  * @example
1462
1488
  *
1463
1489
  * <code>
1464
1490
  * {
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
- * }
1491
+ * "step": "mkdir",
1492
+ * "path": "/wordpress/my-new-folder"
1474
1493
  * }
1475
1494
  * </code>
1476
1495
  */
1477
- export interface RequestStep {
1478
- step: "request";
1479
- /**
1480
- * Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
1481
- */
1482
- request: PHPRequest;
1496
+ export interface MkdirStep {
1497
+ step: "mkdir";
1498
+ /** The path of the directory you want to create */
1499
+ path: string;
1483
1500
  }
1484
1501
  /**
1485
- * Sends a HTTP request to the Playground.
1502
+ * Creates a directory at the specified path.
1486
1503
  */
1487
- export declare const request: StepHandler<RequestStep>;
1504
+ export declare const mkdir: StepHandler<MkdirStep>;
1488
1505
  /**
1489
- * @inheritDoc cp
1506
+ * @inheritDoc mv
1490
1507
  * @hasRunnableExample
1491
1508
  * @landingPage /index2.php
1492
1509
  * @example
1493
1510
  *
1494
1511
  * <code>
1495
1512
  * {
1496
- * "step": "cp",
1513
+ * "step": "mv",
1497
1514
  * "fromPath": "/wordpress/index.php",
1498
1515
  * "toPath": "/wordpress/index2.php"
1499
1516
  * }
1500
1517
  * </code>
1501
1518
  */
1502
- export interface CpStep {
1503
- step: "cp";
1519
+ export interface MvStep {
1520
+ step: "mv";
1504
1521
  /** Source path */
1505
1522
  fromPath: string;
1506
1523
  /** Target path */
1507
1524
  toPath: string;
1508
1525
  }
1509
1526
  /**
1510
- * Copies a file from one path to another.
1527
+ * Moves a file or directory from one path to another.
1511
1528
  */
1512
- export declare const cp: StepHandler<CpStep>;
1529
+ export declare const mv: StepHandler<MvStep>;
1513
1530
  /**
1514
- * @inheritDoc mv
1531
+ * @inheritDoc setPhpIniEntry
1515
1532
  * @hasRunnableExample
1516
- * @landingPage /index2.php
1517
1533
  * @example
1518
1534
  *
1519
1535
  * <code>
1520
1536
  * {
1521
- * "step": "mv",
1522
- * "fromPath": "/wordpress/index.php",
1523
- * "toPath": "/wordpress/index2.php"
1537
+ * "step": "setPhpIniEntry",
1538
+ * "key": "display_errors",
1539
+ * "value": "1"
1524
1540
  * }
1525
1541
  * </code>
1526
1542
  */
1527
- export interface MvStep {
1528
- step: "mv";
1529
- /** Source path */
1530
- fromPath: string;
1531
- /** Target path */
1532
- toPath: string;
1543
+ export interface SetPhpIniEntryStep {
1544
+ step: "setPhpIniEntry";
1545
+ /** Entry name e.g. "display_errors" */
1546
+ key: string;
1547
+ /** Entry value as a string e.g. "1" */
1548
+ value: string;
1533
1549
  }
1534
1550
  /**
1535
- * Moves a file or directory from one path to another.
1551
+ * Sets a PHP ini entry.
1536
1552
  */
1537
- export declare const mv: StepHandler<MvStep>;
1553
+ export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
1538
1554
  /**
1539
- * @inheritDoc mkdir
1555
+ * @inheritDoc runPHP
1540
1556
  * @hasRunnableExample
1541
1557
  * @example
1542
1558
  *
1543
1559
  * <code>
1544
1560
  * {
1545
- * "step": "mkdir",
1546
- * "path": "/wordpress/my-new-folder"
1561
+ * "step": "runPHP",
1562
+ * "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
1563
  * }
1548
1564
  * </code>
1549
1565
  */
1550
- export interface MkdirStep {
1551
- step: "mkdir";
1552
- /** The path of the directory you want to create */
1553
- path: string;
1566
+ export interface RunPHPStep {
1567
+ /** The step identifier. */
1568
+ step: "runPHP";
1569
+ /** The PHP code to run. */
1570
+ code: string;
1554
1571
  }
1555
1572
  /**
1556
- * Creates a directory at the specified path.
1573
+ * Runs PHP code.
1557
1574
  */
1558
- export declare const mkdir: StepHandler<MkdirStep>;
1575
+ export declare const runPHP: StepHandler<RunPHPStep>;
1559
1576
  /**
1560
- * @inheritDoc rm
1577
+ * @inheritDoc runPHP
1561
1578
  * @hasRunnableExample
1562
- * @landingPage /index.php
1563
1579
  * @example
1564
1580
  *
1565
1581
  * <code>
1566
1582
  * {
1567
- * "step": "rm",
1568
- * "path": "/wordpress/index.php"
1583
+ * "step": "runPHP",
1584
+ * "options": {
1585
+ * "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
1586
+ * "headers": {
1587
+ * "Content-type": "text/plain"
1588
+ * }
1589
+ * }
1569
1590
  * }
1570
1591
  * </code>
1571
1592
  */
1572
- export interface RmStep {
1573
- step: "rm";
1574
- /** The path to remove */
1575
- path: string;
1593
+ export interface RunPHPWithOptionsStep {
1594
+ step: "runPHPWithOptions";
1595
+ /**
1596
+ * Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
1597
+ */
1598
+ options: PHPRunOptions;
1576
1599
  }
1577
1600
  /**
1578
- * Removes a file at the specified path.
1601
+ * Runs PHP code with the given options.
1579
1602
  */
1580
- export declare const rm: StepHandler<RmStep>;
1603
+ export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
1581
1604
  /**
1582
- * @inheritDoc rmdir
1605
+ * @inheritDoc request
1606
+ * @needsLogin
1583
1607
  * @hasRunnableExample
1584
- * @landingPage /wp-admin/
1585
1608
  * @example
1586
1609
  *
1587
1610
  * <code>
1588
1611
  * {
1589
- * "step": "rm",
1590
- * "path": "/wordpress/wp-admin"
1612
+ * "step": "request",
1613
+ * "request": {
1614
+ * "method": "POST",
1615
+ * "url": "/wp-admin/admin-ajax.php",
1616
+ * "formData": {
1617
+ * "action": "my_action",
1618
+ * "foo": "bar"
1619
+ * }
1620
+ * }
1591
1621
  * }
1592
1622
  * </code>
1593
1623
  */
1594
- export interface RmdirStep {
1595
- step: "rmdir";
1596
- /** The path to remove */
1597
- path: string;
1624
+ export interface RequestStep {
1625
+ step: "request";
1626
+ /**
1627
+ * Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
1628
+ */
1629
+ request: PHPRequest;
1598
1630
  }
1599
1631
  /**
1600
- * Removes a directory at the specified path.
1632
+ * Sends a HTTP request to the Playground.
1601
1633
  */
1602
- export declare const rmdir: StepHandler<RmdirStep>;
1634
+ export declare const request: StepHandler<RequestStep>;
1603
1635
  /**
1604
1636
  * @inheritDoc writeFile
1605
1637
  * @hasRunnableExample
@@ -1661,6 +1693,15 @@ export interface DefineWpConfigConstsStep {
1661
1693
  export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
1662
1694
  /**
1663
1695
  * @inheritDoc activateTheme
1696
+ * @example
1697
+ *
1698
+ * <code>
1699
+ * {
1700
+ * "step": "activateTheme",
1701
+ * "pluginName": "Storefront",
1702
+ * "pluginPath": "/wordpress/wp-content/themes/storefront"
1703
+ * }
1704
+ * </code>
1664
1705
  */
1665
1706
  export interface ActivateThemeStep {
1666
1707
  step: "activateTheme";
@@ -1720,26 +1761,24 @@ export interface Blueprint {
1720
1761
  */
1721
1762
  wp: string | "latest";
1722
1763
  };
1764
+ /**
1765
+ * The PHP extensions to use.
1766
+ */
1767
+ phpExtensionBundles?: SupportedPHPExtensionBundle[];
1723
1768
  /**
1724
1769
  * The steps to run.
1725
1770
  */
1726
1771
  steps?: Array<StepDefinition | string | undefined | false | null>;
1727
1772
  }
1728
1773
  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
1774
  export interface CompiledBlueprint {
1738
1775
  /** The requested versions of PHP and WordPress for the blueprint */
1739
1776
  versions: {
1740
1777
  php: SupportedPHPVersion;
1741
- wp: supportedWordPressVersion;
1778
+ wp: string;
1742
1779
  };
1780
+ /** The requested PHP extensions to load */
1781
+ phpExtensions: SupportedPHPExtension[];
1743
1782
  /** The compiled steps for the blueprint */
1744
1783
  run: (playground: UniversalPHP) => Promise<void>;
1745
1784
  }
@@ -1762,6 +1801,11 @@ export interface CompileBlueprintOptions {
1762
1801
  */
1763
1802
  export declare function compileBlueprint(blueprint: Blueprint, { progress, semaphore, onStepCompleted, }?: CompileBlueprintOptions): CompiledBlueprint;
1764
1803
  export declare function runBlueprintSteps(compiledBlueprint: CompiledBlueprint, playground: UniversalPHP): Promise<void>;
1804
+ /**
1805
+ * @deprecated This function is a no-op. Playground no longer uses a proxy to download plugins and themes.
1806
+ * To be removed in v0.3.0
1807
+ */
1808
+ export declare function setPluginProxyURL(): void;
1765
1809
  export type WithAPIState = {
1766
1810
  /**
1767
1811
  * Resolves to true when the remote API is ready for
@@ -1780,6 +1824,8 @@ export interface PHPWebLoaderOptions {
1780
1824
  downloadMonitor?: EmscriptenDownloadMonitor;
1781
1825
  requestHandler?: PHPRequestHandlerConfiguration;
1782
1826
  dataModules?: Array<DataModule | Promise<DataModule>>;
1827
+ /** @deprecated To be replaced with `extensions` in the future */
1828
+ loadAllExtensions?: boolean;
1783
1829
  }
1784
1830
  declare class WebPHP extends BasePHP {
1785
1831
  /**
@@ -1884,7 +1930,17 @@ declare class PlaygroundWorkerEndpoint extends WebPHPEndpoint {
1884
1930
  getWordPressModuleDetails(): Promise<{
1885
1931
  majorVersion: string;
1886
1932
  staticAssetsDirectory: string;
1887
- defaultTheme: any;
1933
+ }>;
1934
+ getSupportedWordPressVersions(): Promise<{
1935
+ all: {
1936
+ nightly: string;
1937
+ beta: string;
1938
+ "6.3": string;
1939
+ "6.2": string;
1940
+ "6.1": string;
1941
+ "6.0": string;
1942
+ };
1943
+ latest: string;
1888
1944
  }>;
1889
1945
  resetVirtualOpfs(): Promise<void>;
1890
1946
  reloadFilesFromOpfs(): Promise<void>;