pulse-ts-sdk 0.0.58 → 0.0.60
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/README.md +2 -2
- package/dist/cjs/BaseClient.d.ts +8 -2
- package/dist/cjs/BaseClient.js +14 -2
- package/dist/cjs/auth/HeaderAuthProvider.d.ts +16 -0
- package/dist/cjs/auth/HeaderAuthProvider.js +71 -0
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +5 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
- package/dist/cjs/core/auth/AuthProvider.js +2 -0
- package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
- package/dist/cjs/core/auth/AuthRequest.js +2 -0
- package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
- package/dist/cjs/core/auth/BasicAuth.js +27 -0
- package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
- package/dist/cjs/core/auth/BearerToken.js +16 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +5 -0
- package/dist/cjs/core/auth/index.js +9 -0
- package/dist/cjs/core/base64.d.ts +2 -0
- package/dist/cjs/core/base64.js +26 -0
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.js +2 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +8 -2
- package/dist/esm/BaseClient.mjs +13 -2
- package/dist/esm/auth/HeaderAuthProvider.d.mts +16 -0
- package/dist/esm/auth/HeaderAuthProvider.mjs +34 -0
- package/dist/esm/auth/index.d.mts +1 -0
- package/dist/esm/auth/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
- package/dist/esm/core/auth/AuthProvider.mjs +1 -0
- package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
- package/dist/esm/core/auth/AuthRequest.mjs +1 -0
- package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
- package/dist/esm/core/auth/BasicAuth.mjs +24 -0
- package/dist/esm/core/auth/BearerToken.d.mts +7 -0
- package/dist/esm/core/auth/BearerToken.mjs +13 -0
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +5 -0
- package/dist/esm/core/auth/index.mjs +3 -0
- package/dist/esm/core/base64.d.mts +2 -0
- package/dist/esm/core/base64.mjs +22 -0
- package/dist/esm/core/index.d.mts +2 -0
- package/dist/esm/core/index.mjs +2 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- 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:
|
package/dist/cjs/BaseClient.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -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.
|
|
45
|
-
"User-Agent": "pulse-ts-sdk/0.0.
|
|
46
|
+
"X-Fern-SDK-Version": "0.0.60",
|
|
47
|
+
"User-Agent": "pulse-ts-sdk/0.0.60",
|
|
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>;
|
|
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,71 @@
|
|
|
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
|
+
return options.apiKey != null;
|
|
55
|
+
}
|
|
56
|
+
getAuthRequest(_arg) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const apiKey = yield core.Supplier.get(this.headerValue);
|
|
59
|
+
if (apiKey == null) {
|
|
60
|
+
throw new errors.PulseError({
|
|
61
|
+
message: "Please specify a apiKey by passing it in to the constructor",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const headerValue = apiKey;
|
|
65
|
+
return {
|
|
66
|
+
headers: { X_API_KEY: headerValue },
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
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,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,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,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
|
+
}
|
package/dist/cjs/core/index.d.ts
CHANGED
package/dist/cjs/core/index.js
CHANGED
|
@@ -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);
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0.
|
|
1
|
+
export declare const SDK_VERSION = "0.0.60";
|
package/dist/cjs/version.js
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -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.
|
|
9
|
-
"User-Agent": "pulse-ts-sdk/0.0.
|
|
9
|
+
"X-Fern-SDK-Version": "0.0.60",
|
|
10
|
+
"User-Agent": "pulse-ts-sdk/0.0.60",
|
|
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>;
|
|
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,34 @@
|
|
|
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
|
+
return options.apiKey != null;
|
|
19
|
+
}
|
|
20
|
+
getAuthRequest(_arg) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const apiKey = yield core.Supplier.get(this.headerValue);
|
|
23
|
+
if (apiKey == null) {
|
|
24
|
+
throw new errors.PulseError({
|
|
25
|
+
message: "Please specify a apiKey by passing it in to the constructor",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const headerValue = apiKey;
|
|
29
|
+
return {
|
|
30
|
+
headers: { X_API_KEY: headerValue },
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HeaderAuthProvider } from "./HeaderAuthProvider.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HeaderAuthProvider } from "./HeaderAuthProvider.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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
|
+
}
|
package/dist/esm/core/index.mjs
CHANGED
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0.
|
|
1
|
+
export declare const SDK_VERSION = "0.0.60";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.0.
|
|
1
|
+
export const SDK_VERSION = "0.0.60";
|