Skip to content

Commit 0a1cead

Browse files
committed
Audio bump deploy
1 parent e4b17b1 commit 0a1cead

10 files changed

Lines changed: 266 additions & 118 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ on:
1111

1212
jobs:
1313
publish:
14+
if: ${{ github.actor != 'github-actions[bot]' }}
1415
runs-on: ubuntu-latest
1516
permissions:
16-
contents: read
17+
contents: write
1718
id-token: write
1819
steps:
1920
- name: Check out repo
@@ -31,23 +32,113 @@ jobs:
3132
- name: Install dependencies
3233
run: npm ci
3334

34-
- name: Decide whether to publish
35-
id: should_publish
35+
- name: Decide version
36+
id: version
3637
run: |
3738
current=$(node -p "require('./package.json').version")
3839
published=$(npm view diffio version 2>/dev/null || true)
3940
echo "current=$current"
4041
echo "published=$published"
41-
if [ "$current" = "$published" ]; then
42-
echo "publish=false" >> "$GITHUB_OUTPUT"
42+
CURRENT="$current" PUBLISHED="$published" node - <<'NODE'
43+
const fs = require("fs");
44+
const current = process.env.CURRENT;
45+
const published = process.env.PUBLISHED;
46+
47+
const parse = (value) => {
48+
const core = value.split("-")[0].split("+")[0];
49+
const parts = core.split(".").map((item) => parseInt(item, 10));
50+
while (parts.length < 3) {
51+
parts.push(0);
52+
}
53+
return parts.slice(0, 3);
54+
};
55+
56+
const compare = (left, right) => {
57+
const a = parse(left);
58+
const b = parse(right);
59+
for (let i = 0; i < 3; i += 1) {
60+
if (a[i] > b[i]) return 1;
61+
if (a[i] < b[i]) return -1;
62+
}
63+
return 0;
64+
};
65+
66+
const bumpPatch = (value) => {
67+
const [major, minor, patch] = parse(value);
68+
return `${major}.${minor}.${patch + 1}`;
69+
};
70+
71+
let nextVersion = current;
72+
let bumpNeeded = false;
73+
if (published) {
74+
const comparison = compare(current, published);
75+
if (comparison <= 0) {
76+
nextVersion = bumpPatch(comparison === 0 ? current : published);
77+
bumpNeeded = true;
78+
}
79+
}
80+
81+
const publish =
82+
!published || (published && compare(nextVersion, published) > 0);
83+
84+
const output = process.env.GITHUB_OUTPUT;
85+
if (output) {
86+
fs.appendFileSync(output, `next_version=${nextVersion}\n`);
87+
fs.appendFileSync(
88+
output,
89+
`bump_needed=${bumpNeeded ? "true" : "false"}\n`
90+
);
91+
fs.appendFileSync(
92+
output,
93+
`publish=${publish ? "true" : "false"}\n`
94+
);
95+
}
96+
NODE
97+
98+
- name: Bump package.json version
99+
if: ${{ steps.version.outputs.bump_needed == 'true' }}
100+
run: npm version "${{ steps.version.outputs.next_version }}" --no-git-tag-version
101+
102+
- name: Sync SDK version constant
103+
id: sync_version
104+
env:
105+
NEXT_VERSION: ${{ steps.version.outputs.next_version }}
106+
run: |
107+
node - <<'NODE'
108+
const fs = require("fs");
109+
const path = "src/version.ts";
110+
const nextVersion = process.env.NEXT_VERSION;
111+
if (!nextVersion) {
112+
process.exit(0);
113+
}
114+
const contents = fs.readFileSync(path, "utf8");
115+
const updated = contents.replace(
116+
/DIFFIO_SDK_VERSION\s*=\s*["'][^"']+["']/,
117+
`DIFFIO_SDK_VERSION = "${nextVersion}"`
118+
);
119+
if (updated !== contents) {
120+
fs.writeFileSync(path, updated);
121+
}
122+
NODE
123+
if git diff --quiet -- package.json package-lock.json src/version.ts; then
124+
echo "changed=false" >> "$GITHUB_OUTPUT"
43125
else
44-
echo "publish=true" >> "$GITHUB_OUTPUT"
126+
echo "changed=true" >> "$GITHUB_OUTPUT"
45127
fi
46128
129+
- name: Commit version update
130+
if: ${{ steps.sync_version.outputs.changed == 'true' }}
131+
run: |
132+
git config user.name "github-actions[bot]"
133+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
134+
git add package.json package-lock.json src/version.ts
135+
git commit -m "chore(release): bump JS SDK to ${{ steps.version.outputs.next_version }}"
136+
git push origin "HEAD:${GITHUB_REF_NAME}"
137+
47138
- name: Build
48-
if: ${{ steps.should_publish.outputs.publish == 'true' }}
139+
if: ${{ steps.version.outputs.publish == 'true' }}
49140
run: npm run build
50141

51142
- name: Publish to npm
52-
if: ${{ steps.should_publish.outputs.publish == 'true' }}
143+
if: ${{ steps.version.outputs.publish == 'true' }}
53144
run: npm publish --access public

README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ npm install
1717

1818
## Configuration
1919

20-
Set the API key with `DIFFIO_API_KEY`. You can also override the base URL with `DIFFIO_API_BASE_URL`.
20+
Set the API key with `DIFFIO_API_KEY`. If you need to set the base URL explicitly, use the production endpoint with `DIFFIO_API_BASE_URL`.
2121

2222
```bash
2323
export DIFFIO_API_KEY="diffio_live_..."
24-
export DIFFIO_API_BASE_URL="https://us-central1-diffioai.cloudfunctions.net"
25-
```
26-
27-
For emulators, set the base URL to the Functions emulator host.
28-
29-
```bash
30-
export DIFFIO_API_BASE_URL="http://127.0.0.1:5001/diffioai/us-central1"
24+
export DIFFIO_API_BASE_URL="https://us-central1-diffioai.cloudfunctions.net/v1"
3125
```
3226

3327
## Request options
@@ -166,16 +160,6 @@ for (const generation of generations.generations) {
166160
}
167161
```
168162

169-
## Webhooks portal access
170-
171-
```ts
172-
import { DiffioClient } from "diffio";
173-
174-
const client = new DiffioClient({ apiKey: "diffio_live_..." });
175-
const portal = await client.webhooks.getPortalAccess({ mode: "test" });
176-
console.log(portal.portalUrl);
177-
```
178-
179163
## Send a test webhook event
180164

181165
```ts
@@ -184,13 +168,46 @@ import { DiffioClient } from "diffio";
184168
const client = new DiffioClient({ apiKey: "diffio_live_..." });
185169
const event = await client.webhooks.sendTestEvent({
186170
eventType: "generation.completed",
187-
mode: "test",
171+
mode: "live",
188172
samplePayload: { apiProjectId: "proj_123" }
189173
});
190174

191175
console.log(event.svixMessageId);
192176
```
193177

178+
## Verify webhook signatures
179+
180+
Use the raw request body (not parsed JSON) plus the `svix-*` headers and your webhook signing secret.
181+
182+
```ts
183+
import express from "express";
184+
import { DiffioClient } from "diffio";
185+
186+
const app = express();
187+
const client = new DiffioClient({ apiKey: process.env.DIFFIO_API_KEY });
188+
189+
app.post("/webhooks/diffio", express.raw({ type: "application/json" }), (req, res) => {
190+
const payload = req.body;
191+
const headers = {
192+
"svix-id": req.header("svix-id"),
193+
"svix-timestamp": req.header("svix-timestamp"),
194+
"svix-signature": req.header("svix-signature")
195+
};
196+
197+
try {
198+
const event = client.webhooks.verifySignature({
199+
payload,
200+
headers,
201+
secret: process.env.DIFFIO_WEBHOOK_SECRET
202+
});
203+
console.log("Webhook received", event.eventType);
204+
res.status(200).send("ok");
205+
} catch (err) {
206+
res.status(400).send("Invalid signature");
207+
}
208+
});
209+
```
210+
194211
## Runtime compatibility
195212

196213
Use Node 18 or later so `fetch` is available without extra packages.

package-lock.json

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"test:wire": "jest --selectProjects wire"
2323
},
2424
"dependencies": {
25-
"mime-types": "^2.1.35"
25+
"mime-types": "^2.1.35",
26+
"svix": "^1.84.1"
2627
},
2728
"devDependencies": {
2829
"@types/jest": "^29.5.14",

src/Client.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
parseGenerationProgressResponse,
1414
parseListProjectGenerationsResponse,
1515
parseListProjectsResponse,
16-
parseWebhookPortalResponse,
1716
parseWebhookTestEventResponse
1817
} from "./api/serialization";
1918
import type {
@@ -25,7 +24,6 @@ import type {
2524
ListProjectGenerationsResponse,
2625
ListProjectsResponse,
2726
RestoreMetadata,
28-
WebhookPortalResponse,
2927
WebhookTestEventResponse
3028
} from "./api/types";
3129
import { AudioIsolationClient, GenerationsClient, ProjectsClient, WebhooksClient } from "./api/resources";
@@ -290,25 +288,6 @@ export class DiffioClient {
290288
return parseGenerationDownloadResponse(response);
291289
}
292290

293-
async getWebhooksPortalAccess(options: {
294-
mode: string;
295-
apiKeyId?: string;
296-
requestOptions?: DiffioClient.RequestOptions;
297-
}): Promise<WebhookPortalResponse> {
298-
const { mode, apiKeyId, requestOptions } = options;
299-
if (!WEBHOOK_MODES.includes(mode)) {
300-
throw new DiffioApiError("mode must be test or live");
301-
}
302-
303-
const payload: Record<string, unknown> = { mode };
304-
if (apiKeyId != null) {
305-
payload.apiKeyId = apiKeyId;
306-
}
307-
308-
const response = await this._requestJson("POST", "webhooks/app_portal_access", payload, requestOptions);
309-
return parseWebhookPortalResponse(response);
310-
}
311-
312291
async sendWebhookTestEvent(options: {
313292
eventType: string;
314293
mode: string;

0 commit comments

Comments
 (0)