Skip to content

Commit f00b087

Browse files
feat: Setup bundle analytics header (box/box-codegen#949) (#1458)
1 parent 9761919 commit f00b087

4 files changed

Lines changed: 275 additions & 56 deletions

File tree

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "2492c3e", "specHash": "fa39a3f", "version": "10.9.0" }
1+
{ "engineHash": "2fabf30", "specHash": "576cd17", "version": "10.9.0" }

package-lock.json

Lines changed: 80 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/networking/boxNetworkClient.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ export class BoxNetworkClient implements NetworkClient {
433433
}
434434
}
435435

436+
function getBoxBundleVersion(): string | null {
437+
if (typeof process !== 'undefined' && process.env?.NPM_BOX_VERSION) {
438+
return process.env.NPM_BOX_VERSION;
439+
}
440+
441+
if (
442+
typeof globalThis !== 'undefined' &&
443+
(globalThis as any).__BOX_PACKAGE_VERSION
444+
) {
445+
return (globalThis as any).__BOX_PACKAGE_VERSION;
446+
}
447+
448+
return null;
449+
}
450+
436451
function constructBoxUAHeader() {
437452
const analyticsIdentifiers = {
438453
agent: `box-javascript-generated-sdk/${sdkVersion}`,
@@ -441,6 +456,12 @@ function constructBoxUAHeader() {
441456
: `Node/${process.version.replace('v', '')}`,
442457
} as Record<string, string>;
443458

459+
// Add bundle information if box-node-sdk is used through npm-box meta-package
460+
const bundleVersion = getBoxBundleVersion();
461+
if (bundleVersion) {
462+
analyticsIdentifiers['bundle'] = `box/${bundleVersion}`;
463+
}
464+
444465
return Object.keys(analyticsIdentifiers)
445466
.map((k) => `${k}=${analyticsIdentifiers[k]}`)
446467
.join('; ');

0 commit comments

Comments
 (0)