Skip to content

Commit 3f02372

Browse files
committed
feat(sdk): add x-pd-sdk-version header, etc
1 parent e2445aa commit 3f02372

File tree

8 files changed

+58
-11
lines changed

8 files changed

+58
-11
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
default:
2+
make -j2 server delayed-open
3+
4+
server:
5+
cd ../.. && python -m http.server
6+
7+
delayed-open:
8+
sleep 1 && xdg-open http://localhost:8000/examples/browser/index.html
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>Load SDK in browser</h1>
5+
<script type="importmap">
6+
{
7+
"imports": {
8+
"@rails/actioncable": "/node_modules/@rails/actioncable/app/assets/javascripts/actioncable.esm.js"
9+
}
10+
}
11+
</script>
12+
<script type="module">
13+
import { createFrontendClient } from "/dist/browser/browser/index.js"
14+
const client = createFrontendClient()
15+
const p = document.createElement("p")
16+
p.textContent = "sdk version: " + client.version
17+
document.body.appendChild(p)
18+
</script>
19+
</body>
20+
</html>

packages/sdk/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
"access": "public"
3636
},
3737
"scripts": {
38-
"prepublish": "rm -rf dist && pnpm run build",
39-
"build": "pnpm run build:node && pnpm run build:browser",
38+
"prepublish": "pnpm run build",
39+
"prebuild": "node scripts/updateVersion.mjs",
40+
"build": "rm -rf dist && pnpm run prebuild && pnpm run build:node && pnpm run build:browser",
4041
"build:node": "tsc -p tsconfig.node.json",
4142
"build:browser": "tsc -p tsconfig.browser.json",
4243
"test": "jest",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from "fs";
2+
import cp from "child_process";
3+
4+
if (!process.env.CI) {
5+
// make sure people building locally automatically do not track changes to version file
6+
cp.execSync("git update-index --skip-worktree src/version.ts");
7+
}
8+
9+
const pkg = JSON.parse(String(fs.readFileSync("./package.json", "utf8")))
10+
const versionTsPath = "./src/version.ts";
11+
const data = String(fs.readFileSync(versionTsPath, "utf8"));
12+
const newData = data.replace(/"(.*)"/, `"${pkg.version}"`);
13+
fs.writeFileSync(versionTsPath, newData);

packages/sdk/src/browser/async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AsyncResponseManager } from "../shared/async";
2-
import type { AsyncResponseManagerOpts } from "../shared/async";
1+
import { AsyncResponseManager } from "../shared/async.js";
2+
import type { AsyncResponseManagerOpts } from "../shared/async.js";
33

44
export type BrowserAsyncResponseManagerOpts = {
55
apiHost: string;

packages/sdk/src/browser/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
// operations, like connecting accounts via Pipedream Connect. See the server/
55
// directory for the server client.
66

7-
import { BrowserAsyncResponseManager } from "./async";
7+
import { BrowserAsyncResponseManager } from "./async.js";
88
import {
99
AccountsRequestResponse,
1010
BaseClient,
1111
GetAccountOpts,
1212
type ConnectTokenResponse,
13-
} from "../shared";
14-
export type * from "../shared";
13+
} from "../shared/index.js";
14+
export type * from "../shared/index.js";
1515

1616
/**
1717
* Options for creating a browser-side client. This is used to configure the

packages/sdk/src/shared/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// This code is meant to be shared between the browser and server.
2-
import { AsyncResponseManager } from "./async";
2+
import { AsyncResponseManager } from "./async.js";
33
import type {
44
AsyncResponse, AsyncErrorResponse,
5-
} from "./async";
6-
import type { V1Component } from "./component";
7-
export * from "./component";
5+
} from "./async.js";
6+
import type { V1Component } from "./component.js";
7+
export * from "./component.js";
8+
import { version as sdkVersion } from "../version.js";
89

910
type RequestInit = globalThis.RequestInit;
1011

@@ -290,6 +291,7 @@ export interface AsyncRequestOptions extends RequestOptions {
290291
* A client for interacting with the Pipedream Connect API on the server-side.
291292
*/
292293
export abstract class BaseClient {
294+
version = sdkVersion;
293295
protected apiHost: string;
294296
protected abstract asyncResponseManager: AsyncResponseManager;
295297
protected readonly baseApiUrl: string;
@@ -351,6 +353,7 @@ export abstract class BaseClient {
351353

352354
const headers: Record<string, string> = {
353355
...customHeaders,
356+
"X-PD-SDK-Version": sdkVersion,
354357
"X-PD-Environment": this.environment,
355358
};
356359

packages/sdk/src/version.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT, SET AT BUILD TIME
2+
export const version = "0.0.0"

0 commit comments

Comments
 (0)