@posthog/plugin-utils 1.0.1 → 1.1.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.
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAG/C;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC9C,MAAM,EAAE,CA0BV;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAQ3E;AAED;;GAEG;AACH,wBAAsB,eAAe,CACjC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACzD,OAAO,CAAC,IAAI,CAAC,CAgBf"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAG/C;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC9C,MAAM,EAAE,CA8BV;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAQ3E;AAED;;GAEG;AACH,wBAAsB,eAAe,CACjC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACzD,OAAO,CAAC,IAAI,CAAC,CAgBf"}
package/dist/cli.js CHANGED
@@ -38,6 +38,7 @@ function buildSourcemapCliArgs(config, mode) {
38
38
  else args.push('--directory', mode.directory);
39
39
  if (config.sourcemaps.releaseName) args.push('--release-name', config.sourcemaps.releaseName);
40
40
  if (config.sourcemaps.releaseVersion) args.push('--release-version', config.sourcemaps.releaseVersion);
41
+ if (void 0 !== config.sourcemaps.build && '' !== config.sourcemaps.build) args.push('--build', config.sourcemaps.build);
41
42
  if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
42
43
  if (config.sourcemaps.batchSize) args.push('--batch-size', config.sourcemaps.batchSize.toString());
43
44
  return args;
package/dist/cli.mjs CHANGED
@@ -8,6 +8,7 @@ function buildSourcemapCliArgs(config, mode) {
8
8
  else args.push('--directory', mode.directory);
9
9
  if (config.sourcemaps.releaseName) args.push('--release-name', config.sourcemaps.releaseName);
10
10
  if (config.sourcemaps.releaseVersion) args.push('--release-version', config.sourcemaps.releaseVersion);
11
+ if (void 0 !== config.sourcemaps.build && '' !== config.sourcemaps.build) args.push('--build', config.sourcemaps.build);
11
12
  if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
12
13
  if (config.sourcemaps.batchSize) args.push('--batch-size', config.sourcemaps.batchSize.toString());
13
14
  return args;
package/dist/config.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface PluginConfig {
15
15
  /** @deprecated Use releaseVersion instead */
16
16
  version?: string;
17
17
  releaseVersion?: string;
18
+ build?: string | number;
18
19
  deleteAfterUpload?: boolean;
19
20
  batchSize?: number;
20
21
  };
@@ -28,6 +29,7 @@ export interface ResolvedPluginConfig extends Omit<PluginConfig, 'envId' | 'proj
28
29
  enabled: boolean;
29
30
  releaseName?: string;
30
31
  releaseVersion?: string;
32
+ build?: string;
31
33
  deleteAfterUpload: boolean;
32
34
  batchSize?: number;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AAE,MAAM,CAAA;QACpB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,iBAAiB,EAAE,OAAO,CAAA;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;CACJ;AAED,MAAM,WAAW,oBAAoB;IACjC,sFAAsF;IACtF,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,CAyChH"}
package/dist/config.js CHANGED
@@ -27,9 +27,18 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  resolveConfig: ()=>resolveConfig
28
28
  });
29
29
  const external_utils_js_namespaceObject = require("./utils.js");
30
+ const DEFAULT_PLUGIN_HOST = 'https://us.i.posthog.com';
31
+ function normalizeApiKey(value) {
32
+ return 'string' == typeof value ? value.trim() : '';
33
+ }
34
+ function normalizeHost(value) {
35
+ const normalizedHost = 'string' == typeof value ? value.trim() : '';
36
+ return normalizedHost || DEFAULT_PLUGIN_HOST;
37
+ }
30
38
  function resolveConfig(options, resolveOptions) {
31
39
  const projectId = options.projectId ?? options.envId;
32
- const host = options.host ?? 'https://us.i.posthog.com';
40
+ const personalApiKey = normalizeApiKey(options.personalApiKey);
41
+ const host = normalizeHost(options.host);
33
42
  const logLevel = options.logLevel ?? 'info';
34
43
  const cwd = resolveOptions?.cwd ?? process.cwd();
35
44
  const cliBinaryPath = options.cliBinaryPath ?? (0, external_utils_js_namespaceObject.resolveBinaryPath)('posthog-cli', {
@@ -41,10 +50,10 @@ function resolveConfig(options, resolveOptions) {
41
50
  const enabled = userSourcemaps.enabled ?? defaultEnabled;
42
51
  if (enabled) {
43
52
  if (!projectId) throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)');
44
- if (!options.personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
53
+ if (!personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
45
54
  }
46
55
  return {
47
- personalApiKey: options.personalApiKey,
56
+ personalApiKey,
48
57
  projectId,
49
58
  host,
50
59
  logLevel,
@@ -53,6 +62,7 @@ function resolveConfig(options, resolveOptions) {
53
62
  enabled,
54
63
  releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
55
64
  releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
65
+ build: void 0 !== userSourcemaps.build ? String(userSourcemaps.build) : void 0,
56
66
  deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
57
67
  batchSize: userSourcemaps.batchSize
58
68
  }
package/dist/config.mjs CHANGED
@@ -1,7 +1,16 @@
1
1
  import { resolveBinaryPath } from "./utils.mjs";
2
+ const DEFAULT_PLUGIN_HOST = 'https://us.i.posthog.com';
3
+ function normalizeApiKey(value) {
4
+ return 'string' == typeof value ? value.trim() : '';
5
+ }
6
+ function normalizeHost(value) {
7
+ const normalizedHost = 'string' == typeof value ? value.trim() : '';
8
+ return normalizedHost || DEFAULT_PLUGIN_HOST;
9
+ }
2
10
  function resolveConfig(options, resolveOptions) {
3
11
  const projectId = options.projectId ?? options.envId;
4
- const host = options.host ?? 'https://us.i.posthog.com';
12
+ const personalApiKey = normalizeApiKey(options.personalApiKey);
13
+ const host = normalizeHost(options.host);
5
14
  const logLevel = options.logLevel ?? 'info';
6
15
  const cwd = resolveOptions?.cwd ?? process.cwd();
7
16
  const cliBinaryPath = options.cliBinaryPath ?? resolveBinaryPath('posthog-cli', {
@@ -13,10 +22,10 @@ function resolveConfig(options, resolveOptions) {
13
22
  const enabled = userSourcemaps.enabled ?? defaultEnabled;
14
23
  if (enabled) {
15
24
  if (!projectId) throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)');
16
- if (!options.personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
25
+ if (!personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
17
26
  }
18
27
  return {
19
- personalApiKey: options.personalApiKey,
28
+ personalApiKey,
20
29
  projectId,
21
30
  host,
22
31
  logLevel,
@@ -25,6 +34,7 @@ function resolveConfig(options, resolveOptions) {
25
34
  enabled,
26
35
  releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
27
36
  releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
37
+ build: void 0 !== userSourcemaps.build ? String(userSourcemaps.build) : void 0,
28
38
  deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
29
39
  batchSize: userSourcemaps.batchSize
30
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/plugin-utils",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Shared CLI and sourcemap utilities for PostHog build plugins",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/cli.ts CHANGED
@@ -24,6 +24,10 @@ export function buildSourcemapCliArgs(
24
24
  args.push('--release-version', config.sourcemaps.releaseVersion)
25
25
  }
26
26
 
27
+ if (config.sourcemaps.build !== undefined && config.sourcemaps.build !== '') {
28
+ args.push('--build', config.sourcemaps.build)
29
+ }
30
+
27
31
  if (config.sourcemaps.deleteAfterUpload) {
28
32
  args.push('--delete-after')
29
33
  }
package/src/config.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import { resolveBinaryPath } from './utils'
2
2
 
3
+ const DEFAULT_PLUGIN_HOST = 'https://us.i.posthog.com'
4
+
5
+ function normalizeApiKey(value?: unknown): string {
6
+ return typeof value === 'string' ? value.trim() : ''
7
+ }
8
+
9
+ function normalizeHost(value?: unknown): string {
10
+ const normalizedHost = typeof value === 'string' ? value.trim() : ''
11
+ return normalizedHost || DEFAULT_PLUGIN_HOST
12
+ }
13
+
3
14
  export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
4
15
 
5
16
  export interface PluginConfig {
@@ -18,6 +29,7 @@ export interface PluginConfig {
18
29
  /** @deprecated Use releaseVersion instead */
19
30
  version?: string
20
31
  releaseVersion?: string
32
+ build?: string | number
21
33
  deleteAfterUpload?: boolean
22
34
  batchSize?: number
23
35
  }
@@ -32,6 +44,7 @@ export interface ResolvedPluginConfig extends Omit<PluginConfig, 'envId' | 'proj
32
44
  enabled: boolean
33
45
  releaseName?: string
34
46
  releaseVersion?: string
47
+ build?: string
35
48
  deleteAfterUpload: boolean
36
49
  batchSize?: number
37
50
  }
@@ -46,7 +59,8 @@ export interface ResolveConfigOptions {
46
59
 
47
60
  export function resolveConfig(options: PluginConfig, resolveOptions?: ResolveConfigOptions): ResolvedPluginConfig {
48
61
  const projectId = options.projectId ?? options.envId
49
- const host = options.host ?? 'https://us.i.posthog.com'
62
+ const personalApiKey = normalizeApiKey(options.personalApiKey)
63
+ const host = normalizeHost(options.host)
50
64
  const logLevel = options.logLevel ?? 'info'
51
65
  const cwd = resolveOptions?.cwd ?? process.cwd()
52
66
  const cliBinaryPath =
@@ -64,13 +78,13 @@ export function resolveConfig(options: PluginConfig, resolveOptions?: ResolveCon
64
78
  if (!projectId) {
65
79
  throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)')
66
80
  }
67
- if (!options.personalApiKey) {
81
+ if (!personalApiKey) {
68
82
  throw new Error('personalApiKey is required when sourcemaps are enabled')
69
83
  }
70
84
  }
71
85
 
72
86
  return {
73
- personalApiKey: options.personalApiKey,
87
+ personalApiKey,
74
88
  projectId,
75
89
  host,
76
90
  logLevel,
@@ -79,6 +93,7 @@ export function resolveConfig(options: PluginConfig, resolveOptions?: ResolveCon
79
93
  enabled,
80
94
  releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
81
95
  releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
96
+ build: userSourcemaps.build !== undefined ? String(userSourcemaps.build) : undefined,
82
97
  deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
83
98
  batchSize: userSourcemaps.batchSize,
84
99
  },