@pdfvector/util 0.0.24 → 0.0.26

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.
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../lib/environment.ts"],"names":[],"mappings":"AAyDA,eAAO,MAAM,IAAI,SAAoC,CAAC;AACtD,eAAO,MAAM,OAAO,SAA0C,CAAC;AAC/D,eAAO,MAAM,MAAM,SAAW,CAAC"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../lib/environment.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,IAAI,SAAiB,CAAC;AACnC,eAAO,MAAM,OAAO,SAAoB,CAAC;AACzC,eAAO,MAAM,MAAM,SAAW,CAAC"}
@@ -1,56 +1,21 @@
1
- function getWithBun(name) {
2
- try {
3
- return Bun.env[name];
4
- }
5
- catch {
6
- return undefined;
7
- }
8
- }
9
- function getWithNode(name) {
10
- try {
11
- return process.env[name];
12
- }
13
- catch {
14
- return undefined;
15
- }
16
- }
17
- function getCIWithNext() {
18
- try {
19
- return process.env["NEXT_PUBLIC_CI"];
20
- }
21
- catch {
22
- return undefined;
23
- }
24
- }
25
- function getCIWithVite() {
26
- try {
27
- return import.meta.env["VITE_CI"];
28
- }
29
- catch {
30
- return undefined;
31
- }
32
- }
33
- function getLocalWithNext() {
34
- try {
35
- return process.env["NEXT_PUBLIC_PDFVECTOR_LOCAL"];
36
- }
37
- catch {
38
- return undefined;
39
- }
40
- }
41
- function getLocalWithVite() {
42
- try {
43
- return import.meta.env["VITE_PDFVECTOR_LOCAL"];
44
- }
45
- catch {
46
- return undefined;
47
- }
48
- }
49
- const envCI = getWithBun("CI") ?? getWithNode("CI") ?? getCIWithNext() ?? getCIWithVite();
50
- const envLocal = getWithBun("PDFVECTOR_LOCAL") ??
51
- getWithNode("PDFVECTOR_LOCAL") ??
52
- getLocalWithNext() ??
53
- getLocalWithVite();
54
- export const isCI = envCI === "1" || envCI === "true";
55
- export const isLocal = envLocal === "1" || envLocal === "true";
1
+ import { readRuntimeEnvironment, safelyReadEnvironment, } from "./read-runtime-environment.js";
2
+ import { resolveEnvironment, runtimeFlags } from "./resolve-environment.js";
3
+ const bunEnvironment = readRuntimeEnvironment(Reflect.get(globalThis, "Bun"));
4
+ const nodeEnvironment = readRuntimeEnvironment(Reflect.get(globalThis, "process"));
5
+ const nextPublicEnvironment = safelyReadEnvironment(() => ({
6
+ NEXT_PUBLIC_CI: process.env["NEXT_PUBLIC_CI"],
7
+ NEXT_PUBLIC_PDFVECTOR_LOCAL: process.env["NEXT_PUBLIC_PDFVECTOR_LOCAL"],
8
+ }));
9
+ const viteEnvironment = safelyReadEnvironment(() => ({
10
+ VITE_CI: import.meta.env["VITE_CI"],
11
+ VITE_PDFVECTOR_LOCAL: import.meta.env["VITE_PDFVECTOR_LOCAL"],
12
+ }));
13
+ const environment = resolveEnvironment([
14
+ runtimeFlags(bunEnvironment),
15
+ runtimeFlags(nodeEnvironment),
16
+ nextPublicEnvironment,
17
+ viteEnvironment,
18
+ ]);
19
+ export const isCI = environment.ci;
20
+ export const isLocal = environment.local;
56
21
  export const isLive = !isLocal;
@@ -1,14 +1,15 @@
1
1
  export * from "./api-source.js";
2
- export * from "./capture-error.js";
3
2
  export * from "./date.js";
4
3
  export * from "./environment.js";
5
- export * from "./error-service.js";
6
4
  export * from "./format.js";
7
5
  export * from "./free-tier.js";
8
6
  export * from "./get-error-message.js";
9
7
  export * from "./plan.js";
10
8
  export * from "./ports.js";
11
9
  export * from "./product-title.js";
10
+ export * from "./sentry-distribution.js";
11
+ export * from "./sentry-release.js";
12
+ export * from "./service-logger.js";
12
13
  export * from "./tier.js";
13
14
  export * from "./urls.js";
14
15
  export * from "./usage-status.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
package/.tsc/lib/index.js CHANGED
@@ -1,14 +1,15 @@
1
1
  export * from "./api-source.js";
2
- export * from "./capture-error.js";
3
2
  export * from "./date.js";
4
3
  export * from "./environment.js";
5
- export * from "./error-service.js";
6
4
  export * from "./format.js";
7
5
  export * from "./free-tier.js";
8
6
  export * from "./get-error-message.js";
9
7
  export * from "./plan.js";
10
8
  export * from "./ports.js";
11
9
  export * from "./product-title.js";
10
+ export * from "./sentry-distribution.js";
11
+ export * from "./sentry-release.js";
12
+ export * from "./service-logger.js";
12
13
  export * from "./tier.js";
13
14
  export * from "./urls.js";
14
15
  export * from "./usage-status.js";
@@ -0,0 +1,5 @@
1
+ type Environment = Readonly<Record<string, string | undefined>>;
2
+ export declare function safelyReadEnvironment(read: () => Environment): Environment | undefined;
3
+ export declare function readRuntimeEnvironment(value: unknown): Environment | undefined;
4
+ export {};
5
+ //# sourceMappingURL=read-runtime-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-runtime-environment.d.ts","sourceRoot":"","sources":["../../lib/read-runtime-environment.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAEhE,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,WAAW,GACrB,WAAW,GAAG,SAAS,CAMzB;AAaD,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,OAAO,GACZ,WAAW,GAAG,SAAS,CAOzB"}
@@ -0,0 +1,21 @@
1
+ export function safelyReadEnvironment(read) {
2
+ try {
3
+ return read();
4
+ }
5
+ catch {
6
+ return undefined;
7
+ }
8
+ }
9
+ function isEnvironment(value) {
10
+ return (typeof value === "object" &&
11
+ value !== null &&
12
+ !Array.isArray(value) &&
13
+ Object.values(value).every((entry) => typeof entry === "string" || entry === undefined));
14
+ }
15
+ export function readRuntimeEnvironment(value) {
16
+ if (typeof value !== "object" || value === null || !("env" in value)) {
17
+ return undefined;
18
+ }
19
+ const environment = value.env;
20
+ return isEnvironment(environment) ? environment : undefined;
21
+ }
@@ -0,0 +1,9 @@
1
+ type Environment = Readonly<Record<string, string | undefined>> | undefined;
2
+ interface ResolvedEnvironment {
3
+ ci: boolean;
4
+ local: boolean;
5
+ }
6
+ export declare function runtimeFlags(environment: Environment): Environment;
7
+ export declare function resolveEnvironment(environments: readonly Environment[]): ResolvedEnvironment;
8
+ export {};
9
+ //# sourceMappingURL=resolve-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-environment.d.ts","sourceRoot":"","sources":["../../lib/resolve-environment.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;AAE5E,UAAU,mBAAmB;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;CACf;AAID,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,CAMlE;AAeD,wBAAgB,kBAAkB,CACjC,YAAY,EAAE,SAAS,WAAW,EAAE,GAClC,mBAAmB,CAYrB"}
@@ -0,0 +1,31 @@
1
+ const enabledValues = new Set(["1", "true"]);
2
+ export function runtimeFlags(environment) {
3
+ if (!environment)
4
+ return undefined;
5
+ return {
6
+ CI: environment["CI"],
7
+ PDFVECTOR_LOCAL: environment["PDFVECTOR_LOCAL"],
8
+ };
9
+ }
10
+ function findValue(environments, keys) {
11
+ for (const environment of environments) {
12
+ for (const key of keys) {
13
+ const value = environment?.[key];
14
+ if (value !== undefined)
15
+ return value;
16
+ }
17
+ }
18
+ return undefined;
19
+ }
20
+ export function resolveEnvironment(environments) {
21
+ const ci = findValue(environments, ["CI", "NEXT_PUBLIC_CI", "VITE_CI"]);
22
+ const local = findValue(environments, [
23
+ "PDFVECTOR_LOCAL",
24
+ "NEXT_PUBLIC_PDFVECTOR_LOCAL",
25
+ "VITE_PDFVECTOR_LOCAL",
26
+ ]);
27
+ return {
28
+ ci: ci !== undefined && enabledValues.has(ci),
29
+ local: local !== undefined && enabledValues.has(local),
30
+ };
31
+ }
@@ -0,0 +1,4 @@
1
+ type Environment = Record<string, string | undefined>;
2
+ export declare function sentryDistribution(service: string, environment: Environment): string | undefined;
3
+ export {};
4
+ //# sourceMappingURL=sentry-distribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentry-distribution.d.ts","sourceRoot":"","sources":["../../lib/sentry-distribution.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEtD,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GACtB,MAAM,GAAG,SAAS,CAOpB"}
@@ -0,0 +1,6 @@
1
+ export function sentryDistribution(service, environment) {
2
+ const artifact = environment["VERCEL_DEPLOYMENT_ID"]?.trim() ||
3
+ environment["VERCEL_GIT_COMMIT_SHA"]?.trim() ||
4
+ environment["GITHUB_SHA"]?.trim();
5
+ return artifact ? `${service}:${artifact}` : undefined;
6
+ }
@@ -0,0 +1,4 @@
1
+ type Environment = Record<string, string | undefined>;
2
+ export declare function sentryRelease(environment: Environment): string | undefined;
3
+ export {};
4
+ //# sourceMappingURL=sentry-release.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentry-release.d.ts","sourceRoot":"","sources":["../../lib/sentry-release.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEtD,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAM1E"}
@@ -0,0 +1,5 @@
1
+ export function sentryRelease(environment) {
2
+ const commit = environment["VERCEL_GIT_COMMIT_SHA"]?.trim() ||
3
+ environment["GITHUB_SHA"]?.trim();
4
+ return commit ? `pdfvector@${commit}` : undefined;
5
+ }
@@ -0,0 +1,6 @@
1
+ type ErrorContext = Record<string, unknown>;
2
+ export declare const serviceLogger: {
3
+ error(error: unknown, context?: ErrorContext): void;
4
+ };
5
+ export {};
6
+ //# sourceMappingURL=service-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-logger.d.ts","sourceRoot":"","sources":["../../lib/service-logger.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5C,eAAO,MAAM,aAAa;IACzB,KAAK,QAAQ,OAAO,YAAY,YAAY,GAAG,IAAI;CAOnD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { captureException, getClient } from "@sentry/core";
2
+ export const serviceLogger = {
3
+ error(error, context) {
4
+ console.error(error, context);
5
+ if (getClient()) {
6
+ captureException(error, context ? { extra: context } : undefined);
7
+ }
8
+ },
9
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @pdfvector/util
2
2
 
3
+ ## 0.0.26
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#315](https://github.com/phuctm97/pdfvector/pull/315) [`f57dec5`](https://github.com/phuctm97/pdfvector/commit/f57dec52443fa66b91bf747b4373c0f8ed026ef4) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Use commit-wide Sentry releases, artifact-specific distributions, and a shared
9
+ service logger for handled errors.
10
+
11
+ ## 0.0.25
12
+ ### Patch Changes
13
+
14
+
15
+
16
+ - Add complete unit coverage, strengthen release automation, and remove the legacy E2E workspace.
17
+
3
18
  ## 0.0.24
4
19
  ### Patch Changes
5
20
 
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@pdfvector/util",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "main": ".tsc/lib/index.js",
6
+ "exports": {
7
+ ".": "./lib/index.ts",
8
+ "./sentry-distribution": "./lib/sentry-distribution.ts",
9
+ "./sentry-release": "./lib/sentry-release.ts",
10
+ "./service-logger": "./lib/service-logger.ts"
11
+ },
12
+ "dependencies": {
13
+ "@sentry/core": "^10.67.0"
14
+ },
6
15
  "files": [
7
16
  ".tsc",
8
17
  "CHANGELOG.md"
@@ -1,2 +0,0 @@
1
- export declare function captureError(error: unknown): void;
2
- //# sourceMappingURL=capture-error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capture-error.d.ts","sourceRoot":"","sources":["../../lib/capture-error.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEjD"}
@@ -1,4 +0,0 @@
1
- import { errorService } from "./error-service.js";
2
- export function captureError(error) {
3
- errorService.captureError(error);
4
- }
@@ -1,5 +0,0 @@
1
- export interface ErrorService {
2
- captureError: (error: unknown) => void;
3
- }
4
- export declare const errorService: ErrorService;
5
- //# sourceMappingURL=error-service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-service.d.ts","sourceRoot":"","sources":["../../lib/error-service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC5B,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC;AAED,eAAO,MAAM,YAAY,EAAE,YAI1B,CAAC"}
@@ -1,5 +0,0 @@
1
- export const errorService = {
2
- captureError: (error) => {
3
- console.error(error);
4
- },
5
- };