pulse-ts-sdk 0.0.58 → 0.0.59

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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/BaseClient.d.ts +8 -2
  3. package/dist/cjs/BaseClient.js +14 -2
  4. package/dist/cjs/auth/HeaderAuthProvider.d.ts +16 -0
  5. package/dist/cjs/auth/HeaderAuthProvider.js +73 -0
  6. package/dist/cjs/auth/index.d.ts +1 -0
  7. package/dist/cjs/auth/index.js +5 -0
  8. package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
  9. package/dist/cjs/core/auth/AuthProvider.js +2 -0
  10. package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
  11. package/dist/cjs/core/auth/AuthRequest.js +2 -0
  12. package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
  13. package/dist/cjs/core/auth/BasicAuth.js +27 -0
  14. package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
  15. package/dist/cjs/core/auth/BearerToken.js +16 -0
  16. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
  17. package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
  18. package/dist/cjs/core/auth/index.d.ts +5 -0
  19. package/dist/cjs/core/auth/index.js +9 -0
  20. package/dist/cjs/core/base64.d.ts +2 -0
  21. package/dist/cjs/core/base64.js +26 -0
  22. package/dist/cjs/core/index.d.ts +2 -0
  23. package/dist/cjs/core/index.js +2 -0
  24. package/dist/cjs/version.d.ts +1 -1
  25. package/dist/cjs/version.js +1 -1
  26. package/dist/esm/BaseClient.d.mts +8 -2
  27. package/dist/esm/BaseClient.mjs +13 -2
  28. package/dist/esm/auth/HeaderAuthProvider.d.mts +16 -0
  29. package/dist/esm/auth/HeaderAuthProvider.mjs +36 -0
  30. package/dist/esm/auth/index.d.mts +1 -0
  31. package/dist/esm/auth/index.mjs +1 -0
  32. package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
  33. package/dist/esm/core/auth/AuthProvider.mjs +1 -0
  34. package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
  35. package/dist/esm/core/auth/AuthRequest.mjs +1 -0
  36. package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
  37. package/dist/esm/core/auth/BasicAuth.mjs +24 -0
  38. package/dist/esm/core/auth/BearerToken.d.mts +7 -0
  39. package/dist/esm/core/auth/BearerToken.mjs +13 -0
  40. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
  41. package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
  42. package/dist/esm/core/auth/index.d.mts +5 -0
  43. package/dist/esm/core/auth/index.mjs +3 -0
  44. package/dist/esm/core/base64.d.mts +2 -0
  45. package/dist/esm/core/base64.mjs +22 -0
  46. package/dist/esm/core/index.d.mts +2 -0
  47. package/dist/esm/core/index.mjs +2 -0
  48. package/dist/esm/version.d.mts +1 -1
  49. package/dist/esm/version.mjs +1 -1
  50. package/package.json +1 -1
package/README.md CHANGED
@@ -42,7 +42,7 @@ Instantiate and use the client with the following:
42
42
  import { createReadStream } from "fs";
43
43
  import { PulseClient } from "pulse-ts-sdk";
44
44
 
45
- const client = new PulseClient;
45
+ const client = new PulseClient({ apiKey: "YOUR_API_KEY" });
46
46
  await client.extract({});
47
47
  ```
48
48
 
@@ -87,7 +87,7 @@ You can upload files using the client:
87
87
  import { createReadStream } from "fs";
88
88
  import { PulseClient } from "pulse-ts-sdk";
89
89
 
90
- const client = new PulseClient;
90
+ const client = new PulseClient({ apiKey: "YOUR_API_KEY" });
91
91
  await client.extract({});
92
92
  ```
93
93
  The client accepts a variety of types for file upload parameters:
@@ -1,6 +1,7 @@
1
+ import { HeaderAuthProvider } from "./auth/HeaderAuthProvider.js";
1
2
  import * as core from "./core/index.js";
2
3
  import type * as environments from "./environments.js";
3
- export interface BaseClientOptions {
4
+ export type BaseClientOptions = {
4
5
  environment?: core.Supplier<environments.PulseEnvironment | string>;
5
6
  /** Specify a custom URL to connect the client to. */
6
7
  baseUrl?: core.Supplier<string>;
@@ -14,7 +15,7 @@ export interface BaseClientOptions {
14
15
  fetch?: typeof fetch;
15
16
  /** Configure logging for the client. */
16
17
  logging?: core.logging.LogConfig | core.logging.Logger;
17
- }
18
+ } & HeaderAuthProvider.AuthOptions;
18
19
  export interface BaseRequestOptions {
19
20
  /** The maximum time to wait for a response in seconds. */
20
21
  timeoutInSeconds?: number;
@@ -29,5 +30,10 @@ export interface BaseRequestOptions {
29
30
  }
30
31
  export type NormalizedClientOptions<T extends BaseClientOptions = BaseClientOptions> = T & {
31
32
  logging: core.logging.Logger;
33
+ authProvider?: core.AuthProvider;
34
+ };
35
+ export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions = BaseClientOptions> = NormalizedClientOptions<T> & {
36
+ authProvider: core.AuthProvider;
32
37
  };
33
38
  export declare function normalizeClientOptions<T extends BaseClientOptions = BaseClientOptions>(options: T): NormalizedClientOptions<T>;
39
+ export declare function normalizeClientOptionsWithAuth<T extends BaseClientOptions = BaseClientOptions>(options: T): NormalizedClientOptionsWithAuth<T>;
@@ -35,16 +35,28 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.normalizeClientOptions = normalizeClientOptions;
38
+ exports.normalizeClientOptionsWithAuth = normalizeClientOptionsWithAuth;
39
+ const HeaderAuthProvider_js_1 = require("./auth/HeaderAuthProvider.js");
38
40
  const headers_js_1 = require("./core/headers.js");
39
41
  const core = __importStar(require("./core/index.js"));
40
42
  function normalizeClientOptions(options) {
41
43
  const headers = (0, headers_js_1.mergeHeaders)({
42
44
  "X-Fern-Language": "JavaScript",
43
45
  "X-Fern-SDK-Name": "pulse-ts-sdk",
44
- "X-Fern-SDK-Version": "0.0.58",
45
- "User-Agent": "pulse-ts-sdk/0.0.58",
46
+ "X-Fern-SDK-Version": "0.0.59",
47
+ "User-Agent": "pulse-ts-sdk/0.0.59",
46
48
  "X-Fern-Runtime": core.RUNTIME.type,
47
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
48
50
  }, options === null || options === void 0 ? void 0 : options.headers);
49
51
  return Object.assign(Object.assign({}, options), { logging: core.logging.createLogger(options === null || options === void 0 ? void 0 : options.logging), headers });
50
52
  }
53
+ function normalizeClientOptionsWithAuth(options) {
54
+ var _a;
55
+ const normalized = normalizeClientOptions(options);
56
+ const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
57
+ (_a = normalized.authProvider) !== null && _a !== void 0 ? _a : (normalized.authProvider = new HeaderAuthProvider_js_1.HeaderAuthProvider(normalizedWithNoOpAuthProvider));
58
+ return normalized;
59
+ }
60
+ function withNoOpAuthProvider(options) {
61
+ return Object.assign(Object.assign({}, options), { authProvider: new core.NoOpAuthProvider() });
62
+ }
@@ -0,0 +1,16 @@
1
+ import * as core from "../core/index.js";
2
+ export declare namespace HeaderAuthProvider {
3
+ interface AuthOptions {
4
+ apiKey?: core.Supplier<string> | undefined;
5
+ }
6
+ interface Options extends AuthOptions {
7
+ }
8
+ }
9
+ export declare class HeaderAuthProvider implements core.AuthProvider {
10
+ private readonly headerValue;
11
+ constructor(options: HeaderAuthProvider.Options);
12
+ static canCreate(options: HeaderAuthProvider.Options): boolean;
13
+ getAuthRequest(_arg?: {
14
+ endpointMetadata?: core.EndpointMetadata;
15
+ }): Promise<core.AuthRequest>;
16
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.HeaderAuthProvider = void 0;
47
+ const core = __importStar(require("../core/index.js"));
48
+ const errors = __importStar(require("../errors/index.js"));
49
+ class HeaderAuthProvider {
50
+ constructor(options) {
51
+ this.headerValue = options.apiKey;
52
+ }
53
+ static canCreate(options) {
54
+ var _a;
55
+ return options.apiKey != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.PULSE_API_KEY) != null;
56
+ }
57
+ getAuthRequest(_arg) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ var _a, _b;
60
+ const apiKey = (_a = (yield core.Supplier.get(this.headerValue))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.PULSE_API_KEY;
61
+ if (apiKey == null) {
62
+ throw new errors.PulseError({
63
+ message: "Please specify a apiKey by either passing it in to the constructor or initializing a PULSE_API_KEY environment variable",
64
+ });
65
+ }
66
+ const headerValue = apiKey;
67
+ return {
68
+ headers: { "x-api-key": headerValue },
69
+ };
70
+ });
71
+ }
72
+ }
73
+ exports.HeaderAuthProvider = HeaderAuthProvider;
@@ -0,0 +1 @@
1
+ export { HeaderAuthProvider } from "./HeaderAuthProvider.js";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HeaderAuthProvider = void 0;
4
+ var HeaderAuthProvider_js_1 = require("./HeaderAuthProvider.js");
5
+ Object.defineProperty(exports, "HeaderAuthProvider", { enumerable: true, get: function () { return HeaderAuthProvider_js_1.HeaderAuthProvider; } });
@@ -0,0 +1,7 @@
1
+ import type { EndpointMetadata } from "../fetcher/EndpointMetadata.js";
2
+ import type { AuthRequest } from "./AuthRequest.js";
3
+ export interface AuthProvider {
4
+ getAuthRequest(arg?: {
5
+ endpointMetadata?: EndpointMetadata;
6
+ }): Promise<AuthRequest>;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Request parameters for authentication requests.
3
+ */
4
+ export interface AuthRequest {
5
+ /**
6
+ * The headers to be included in the request.
7
+ */
8
+ headers: Record<string, string>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface BasicAuth {
2
+ username: string;
3
+ password: string;
4
+ }
5
+ export declare const BasicAuth: {
6
+ toAuthorizationHeader: (basicAuth: BasicAuth | undefined) => string | undefined;
7
+ fromAuthorizationHeader: (header: string) => BasicAuth;
8
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicAuth = void 0;
4
+ const base64_js_1 = require("../base64.js");
5
+ const BASIC_AUTH_HEADER_PREFIX = /^Basic /i;
6
+ exports.BasicAuth = {
7
+ toAuthorizationHeader: (basicAuth) => {
8
+ if (basicAuth == null) {
9
+ return undefined;
10
+ }
11
+ const token = (0, base64_js_1.base64Encode)(`${basicAuth.username}:${basicAuth.password}`);
12
+ return `Basic ${token}`;
13
+ },
14
+ fromAuthorizationHeader: (header) => {
15
+ const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, "");
16
+ const decoded = (0, base64_js_1.base64Decode)(credentials);
17
+ const [username, ...passwordParts] = decoded.split(":");
18
+ const password = passwordParts.length > 0 ? passwordParts.join(":") : undefined;
19
+ if (username == null || password == null) {
20
+ throw new Error("Invalid basic auth");
21
+ }
22
+ return {
23
+ username,
24
+ password,
25
+ };
26
+ },
27
+ };
@@ -0,0 +1,7 @@
1
+ export type BearerToken = string;
2
+ declare function toAuthorizationHeader(token: string | undefined): string | undefined;
3
+ export declare const BearerToken: {
4
+ toAuthorizationHeader: typeof toAuthorizationHeader;
5
+ fromAuthorizationHeader: (header: string) => BearerToken;
6
+ };
7
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BearerToken = void 0;
4
+ const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
5
+ function toAuthorizationHeader(token) {
6
+ if (token == null) {
7
+ return undefined;
8
+ }
9
+ return `Bearer ${token}`;
10
+ }
11
+ exports.BearerToken = {
12
+ toAuthorizationHeader: toAuthorizationHeader,
13
+ fromAuthorizationHeader: (header) => {
14
+ return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
15
+ },
16
+ };
@@ -0,0 +1,5 @@
1
+ import type { AuthProvider } from "./AuthProvider.js";
2
+ import type { AuthRequest } from "./AuthRequest.js";
3
+ export declare class NoOpAuthProvider implements AuthProvider {
4
+ getAuthRequest(): Promise<AuthRequest>;
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoOpAuthProvider = void 0;
4
+ class NoOpAuthProvider {
5
+ getAuthRequest() {
6
+ return Promise.resolve({ headers: {} });
7
+ }
8
+ }
9
+ exports.NoOpAuthProvider = NoOpAuthProvider;
@@ -0,0 +1,5 @@
1
+ export type { AuthProvider } from "./AuthProvider.js";
2
+ export type { AuthRequest } from "./AuthRequest.js";
3
+ export { BasicAuth } from "./BasicAuth.js";
4
+ export { BearerToken } from "./BearerToken.js";
5
+ export { NoOpAuthProvider } from "./NoOpAuthProvider.js";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoOpAuthProvider = exports.BearerToken = exports.BasicAuth = void 0;
4
+ var BasicAuth_js_1 = require("./BasicAuth.js");
5
+ Object.defineProperty(exports, "BasicAuth", { enumerable: true, get: function () { return BasicAuth_js_1.BasicAuth; } });
6
+ var BearerToken_js_1 = require("./BearerToken.js");
7
+ Object.defineProperty(exports, "BearerToken", { enumerable: true, get: function () { return BearerToken_js_1.BearerToken; } });
8
+ var NoOpAuthProvider_js_1 = require("./NoOpAuthProvider.js");
9
+ Object.defineProperty(exports, "NoOpAuthProvider", { enumerable: true, get: function () { return NoOpAuthProvider_js_1.NoOpAuthProvider; } });
@@ -0,0 +1,2 @@
1
+ export declare function base64Encode(input: string): string;
2
+ export declare function base64Decode(input: string): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64Encode = base64Encode;
4
+ exports.base64Decode = base64Decode;
5
+ function base64ToBytes(base64) {
6
+ const binString = atob(base64);
7
+ return Uint8Array.from(binString, (m) => m.codePointAt(0));
8
+ }
9
+ function bytesToBase64(bytes) {
10
+ const binString = String.fromCodePoint(...bytes);
11
+ return btoa(binString);
12
+ }
13
+ function base64Encode(input) {
14
+ if (typeof Buffer !== "undefined") {
15
+ return Buffer.from(input, "utf8").toString("base64");
16
+ }
17
+ const bytes = new TextEncoder().encode(input);
18
+ return bytesToBase64(bytes);
19
+ }
20
+ function base64Decode(input) {
21
+ if (typeof Buffer !== "undefined") {
22
+ return Buffer.from(input, "base64").toString("utf8");
23
+ }
24
+ const bytes = base64ToBytes(input);
25
+ return new TextDecoder().decode(bytes);
26
+ }
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.js";
2
+ export * from "./base64.js";
1
3
  export * from "./fetcher/index.js";
2
4
  export * as file from "./file/index.js";
3
5
  export * from "./form-data-utils/index.js";
@@ -37,6 +37,8 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.url = exports.logging = exports.file = void 0;
40
+ __exportStar(require("./auth/index.js"), exports);
41
+ __exportStar(require("./base64.js"), exports);
40
42
  __exportStar(require("./fetcher/index.js"), exports);
41
43
  exports.file = __importStar(require("./file/index.js"));
42
44
  __exportStar(require("./form-data-utils/index.js"), exports);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.58";
1
+ export declare const SDK_VERSION = "0.0.59";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.0.58";
4
+ exports.SDK_VERSION = "0.0.59";
@@ -1,6 +1,7 @@
1
+ import { HeaderAuthProvider } from "./auth/HeaderAuthProvider.mjs";
1
2
  import * as core from "./core/index.mjs";
2
3
  import type * as environments from "./environments.mjs";
3
- export interface BaseClientOptions {
4
+ export type BaseClientOptions = {
4
5
  environment?: core.Supplier<environments.PulseEnvironment | string>;
5
6
  /** Specify a custom URL to connect the client to. */
6
7
  baseUrl?: core.Supplier<string>;
@@ -14,7 +15,7 @@ export interface BaseClientOptions {
14
15
  fetch?: typeof fetch;
15
16
  /** Configure logging for the client. */
16
17
  logging?: core.logging.LogConfig | core.logging.Logger;
17
- }
18
+ } & HeaderAuthProvider.AuthOptions;
18
19
  export interface BaseRequestOptions {
19
20
  /** The maximum time to wait for a response in seconds. */
20
21
  timeoutInSeconds?: number;
@@ -29,5 +30,10 @@ export interface BaseRequestOptions {
29
30
  }
30
31
  export type NormalizedClientOptions<T extends BaseClientOptions = BaseClientOptions> = T & {
31
32
  logging: core.logging.Logger;
33
+ authProvider?: core.AuthProvider;
34
+ };
35
+ export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions = BaseClientOptions> = NormalizedClientOptions<T> & {
36
+ authProvider: core.AuthProvider;
32
37
  };
33
38
  export declare function normalizeClientOptions<T extends BaseClientOptions = BaseClientOptions>(options: T): NormalizedClientOptions<T>;
39
+ export declare function normalizeClientOptionsWithAuth<T extends BaseClientOptions = BaseClientOptions>(options: T): NormalizedClientOptionsWithAuth<T>;
@@ -1,14 +1,25 @@
1
1
  // This file was auto-generated by Fern from our API Definition.
2
+ import { HeaderAuthProvider } from "./auth/HeaderAuthProvider.mjs";
2
3
  import { mergeHeaders } from "./core/headers.mjs";
3
4
  import * as core from "./core/index.mjs";
4
5
  export function normalizeClientOptions(options) {
5
6
  const headers = mergeHeaders({
6
7
  "X-Fern-Language": "JavaScript",
7
8
  "X-Fern-SDK-Name": "pulse-ts-sdk",
8
- "X-Fern-SDK-Version": "0.0.58",
9
- "User-Agent": "pulse-ts-sdk/0.0.58",
9
+ "X-Fern-SDK-Version": "0.0.59",
10
+ "User-Agent": "pulse-ts-sdk/0.0.59",
10
11
  "X-Fern-Runtime": core.RUNTIME.type,
11
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
12
13
  }, options === null || options === void 0 ? void 0 : options.headers);
13
14
  return Object.assign(Object.assign({}, options), { logging: core.logging.createLogger(options === null || options === void 0 ? void 0 : options.logging), headers });
14
15
  }
16
+ export function normalizeClientOptionsWithAuth(options) {
17
+ var _a;
18
+ const normalized = normalizeClientOptions(options);
19
+ const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
20
+ (_a = normalized.authProvider) !== null && _a !== void 0 ? _a : (normalized.authProvider = new HeaderAuthProvider(normalizedWithNoOpAuthProvider));
21
+ return normalized;
22
+ }
23
+ function withNoOpAuthProvider(options) {
24
+ return Object.assign(Object.assign({}, options), { authProvider: new core.NoOpAuthProvider() });
25
+ }
@@ -0,0 +1,16 @@
1
+ import * as core from "../core/index.mjs";
2
+ export declare namespace HeaderAuthProvider {
3
+ interface AuthOptions {
4
+ apiKey?: core.Supplier<string> | undefined;
5
+ }
6
+ interface Options extends AuthOptions {
7
+ }
8
+ }
9
+ export declare class HeaderAuthProvider implements core.AuthProvider {
10
+ private readonly headerValue;
11
+ constructor(options: HeaderAuthProvider.Options);
12
+ static canCreate(options: HeaderAuthProvider.Options): boolean;
13
+ getAuthRequest(_arg?: {
14
+ endpointMetadata?: core.EndpointMetadata;
15
+ }): Promise<core.AuthRequest>;
16
+ }
@@ -0,0 +1,36 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import * as core from "../core/index.mjs";
12
+ import * as errors from "../errors/index.mjs";
13
+ export class HeaderAuthProvider {
14
+ constructor(options) {
15
+ this.headerValue = options.apiKey;
16
+ }
17
+ static canCreate(options) {
18
+ var _a;
19
+ return options.apiKey != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.PULSE_API_KEY) != null;
20
+ }
21
+ getAuthRequest(_arg) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ const apiKey = (_a = (yield core.Supplier.get(this.headerValue))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.PULSE_API_KEY;
25
+ if (apiKey == null) {
26
+ throw new errors.PulseError({
27
+ message: "Please specify a apiKey by either passing it in to the constructor or initializing a PULSE_API_KEY environment variable",
28
+ });
29
+ }
30
+ const headerValue = apiKey;
31
+ return {
32
+ headers: { "x-api-key": headerValue },
33
+ };
34
+ });
35
+ }
36
+ }
@@ -0,0 +1 @@
1
+ export { HeaderAuthProvider } from "./HeaderAuthProvider.mjs";
@@ -0,0 +1 @@
1
+ export { HeaderAuthProvider } from "./HeaderAuthProvider.mjs";
@@ -0,0 +1,7 @@
1
+ import type { EndpointMetadata } from "../fetcher/EndpointMetadata.mjs";
2
+ import type { AuthRequest } from "./AuthRequest.mjs";
3
+ export interface AuthProvider {
4
+ getAuthRequest(arg?: {
5
+ endpointMetadata?: EndpointMetadata;
6
+ }): Promise<AuthRequest>;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Request parameters for authentication requests.
3
+ */
4
+ export interface AuthRequest {
5
+ /**
6
+ * The headers to be included in the request.
7
+ */
8
+ headers: Record<string, string>;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface BasicAuth {
2
+ username: string;
3
+ password: string;
4
+ }
5
+ export declare const BasicAuth: {
6
+ toAuthorizationHeader: (basicAuth: BasicAuth | undefined) => string | undefined;
7
+ fromAuthorizationHeader: (header: string) => BasicAuth;
8
+ };
@@ -0,0 +1,24 @@
1
+ import { base64Decode, base64Encode } from "../base64.mjs";
2
+ const BASIC_AUTH_HEADER_PREFIX = /^Basic /i;
3
+ export const BasicAuth = {
4
+ toAuthorizationHeader: (basicAuth) => {
5
+ if (basicAuth == null) {
6
+ return undefined;
7
+ }
8
+ const token = base64Encode(`${basicAuth.username}:${basicAuth.password}`);
9
+ return `Basic ${token}`;
10
+ },
11
+ fromAuthorizationHeader: (header) => {
12
+ const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, "");
13
+ const decoded = base64Decode(credentials);
14
+ const [username, ...passwordParts] = decoded.split(":");
15
+ const password = passwordParts.length > 0 ? passwordParts.join(":") : undefined;
16
+ if (username == null || password == null) {
17
+ throw new Error("Invalid basic auth");
18
+ }
19
+ return {
20
+ username,
21
+ password,
22
+ };
23
+ },
24
+ };
@@ -0,0 +1,7 @@
1
+ export type BearerToken = string;
2
+ declare function toAuthorizationHeader(token: string | undefined): string | undefined;
3
+ export declare const BearerToken: {
4
+ toAuthorizationHeader: typeof toAuthorizationHeader;
5
+ fromAuthorizationHeader: (header: string) => BearerToken;
6
+ };
7
+ export {};
@@ -0,0 +1,13 @@
1
+ const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
2
+ function toAuthorizationHeader(token) {
3
+ if (token == null) {
4
+ return undefined;
5
+ }
6
+ return `Bearer ${token}`;
7
+ }
8
+ export const BearerToken = {
9
+ toAuthorizationHeader: toAuthorizationHeader,
10
+ fromAuthorizationHeader: (header) => {
11
+ return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
12
+ },
13
+ };
@@ -0,0 +1,5 @@
1
+ import type { AuthProvider } from "./AuthProvider.mjs";
2
+ import type { AuthRequest } from "./AuthRequest.mjs";
3
+ export declare class NoOpAuthProvider implements AuthProvider {
4
+ getAuthRequest(): Promise<AuthRequest>;
5
+ }
@@ -0,0 +1,5 @@
1
+ export class NoOpAuthProvider {
2
+ getAuthRequest() {
3
+ return Promise.resolve({ headers: {} });
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export type { AuthProvider } from "./AuthProvider.mjs";
2
+ export type { AuthRequest } from "./AuthRequest.mjs";
3
+ export { BasicAuth } from "./BasicAuth.mjs";
4
+ export { BearerToken } from "./BearerToken.mjs";
5
+ export { NoOpAuthProvider } from "./NoOpAuthProvider.mjs";
@@ -0,0 +1,3 @@
1
+ export { BasicAuth } from "./BasicAuth.mjs";
2
+ export { BearerToken } from "./BearerToken.mjs";
3
+ export { NoOpAuthProvider } from "./NoOpAuthProvider.mjs";
@@ -0,0 +1,2 @@
1
+ export declare function base64Encode(input: string): string;
2
+ export declare function base64Decode(input: string): string;
@@ -0,0 +1,22 @@
1
+ function base64ToBytes(base64) {
2
+ const binString = atob(base64);
3
+ return Uint8Array.from(binString, (m) => m.codePointAt(0));
4
+ }
5
+ function bytesToBase64(bytes) {
6
+ const binString = String.fromCodePoint(...bytes);
7
+ return btoa(binString);
8
+ }
9
+ export function base64Encode(input) {
10
+ if (typeof Buffer !== "undefined") {
11
+ return Buffer.from(input, "utf8").toString("base64");
12
+ }
13
+ const bytes = new TextEncoder().encode(input);
14
+ return bytesToBase64(bytes);
15
+ }
16
+ export function base64Decode(input) {
17
+ if (typeof Buffer !== "undefined") {
18
+ return Buffer.from(input, "base64").toString("utf8");
19
+ }
20
+ const bytes = base64ToBytes(input);
21
+ return new TextDecoder().decode(bytes);
22
+ }
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as file from "./file/index.mjs";
3
5
  export * from "./form-data-utils/index.mjs";
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as file from "./file/index.mjs";
3
5
  export * from "./form-data-utils/index.mjs";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.58";
1
+ export declare const SDK_VERSION = "0.0.59";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.0.58";
1
+ export const SDK_VERSION = "0.0.59";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulse-ts-sdk",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",