@tyvm/knowhow-api-client 0.0.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.
@@ -0,0 +1,21 @@
1
+ export { KnowhowClientFactory } from "./client";
2
+ export type { ClientConfig, TokenStorage } from "./client";
3
+ export { BrowserTokenStorage, MemoryTokenStorage, EnvironmentTokenStorage } from "./storage";
4
+ export * from "./generated";
5
+ import { KnowhowClientFactory, ClientConfig } from "./client";
6
+ /**
7
+ * Create a client configured for browser use with localStorage token storage
8
+ */
9
+ export declare function createBrowserFactory(config: ClientConfig): KnowhowClientFactory;
10
+ /**
11
+ * Create a client configured for server/backend use with environment token storage
12
+ */
13
+ export declare function createEnvFactory(config: ClientConfig, envKey?: string): KnowhowClientFactory;
14
+ /**
15
+ * Create a client with in-memory token storage (useful for testing)
16
+ */
17
+ export declare function createInMemoryFactory(config: ClientConfig): KnowhowClientFactory;
18
+ /**
19
+ * Create a basic client without token storage
20
+ */
21
+ export declare function createBasicFactory(config: ClientConfig): KnowhowClientFactory;
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EnvironmentTokenStorage = exports.MemoryTokenStorage = exports.BrowserTokenStorage = exports.KnowhowClientFactory = void 0;
18
+ exports.createBrowserFactory = createBrowserFactory;
19
+ exports.createEnvFactory = createEnvFactory;
20
+ exports.createInMemoryFactory = createInMemoryFactory;
21
+ exports.createBasicFactory = createBasicFactory;
22
+ // Main client export
23
+ var client_1 = require("./client");
24
+ Object.defineProperty(exports, "KnowhowClientFactory", { enumerable: true, get: function () { return client_1.KnowhowClientFactory; } });
25
+ // Storage implementations
26
+ var storage_1 = require("./storage");
27
+ Object.defineProperty(exports, "BrowserTokenStorage", { enumerable: true, get: function () { return storage_1.BrowserTokenStorage; } });
28
+ Object.defineProperty(exports, "MemoryTokenStorage", { enumerable: true, get: function () { return storage_1.MemoryTokenStorage; } });
29
+ Object.defineProperty(exports, "EnvironmentTokenStorage", { enumerable: true, get: function () { return storage_1.EnvironmentTokenStorage; } });
30
+ // Generated types (re-exported through generated/index.ts)
31
+ __exportStar(require("./generated"), exports);
32
+ // Convenience factory functions
33
+ const client_2 = require("./client");
34
+ const storage_2 = require("./storage");
35
+ /**
36
+ * Create a client configured for browser use with localStorage token storage
37
+ */
38
+ function createBrowserFactory(config) {
39
+ const tokenStorage = new storage_2.BrowserTokenStorage();
40
+ return new client_2.KnowhowClientFactory(config, tokenStorage);
41
+ }
42
+ /**
43
+ * Create a client configured for server/backend use with environment token storage
44
+ */
45
+ function createEnvFactory(config, envKey) {
46
+ const tokenStorage = new storage_2.EnvironmentTokenStorage(envKey);
47
+ return new client_2.KnowhowClientFactory(config, tokenStorage);
48
+ }
49
+ /**
50
+ * Create a client with in-memory token storage (useful for testing)
51
+ */
52
+ function createInMemoryFactory(config) {
53
+ const tokenStorage = new storage_2.MemoryTokenStorage();
54
+ return new client_2.KnowhowClientFactory(config, tokenStorage);
55
+ }
56
+ /**
57
+ * Create a basic client without token storage
58
+ */
59
+ function createBasicFactory(config) {
60
+ return new client_2.KnowhowClientFactory(config);
61
+ }
@@ -0,0 +1,30 @@
1
+ import { TokenStorage } from "./client";
2
+ /**
3
+ * Browser-based token storage using localStorage
4
+ */
5
+ export declare class BrowserTokenStorage implements TokenStorage {
6
+ private tokenKey;
7
+ constructor(tokenKey?: string);
8
+ getToken(): string | null;
9
+ setToken(token: string): void;
10
+ clearToken(): void;
11
+ }
12
+ /**
13
+ * In-memory token storage for server-side or testing
14
+ */
15
+ export declare class MemoryTokenStorage implements TokenStorage {
16
+ private token;
17
+ getToken(): string | null;
18
+ setToken(token: string): void;
19
+ clearToken(): void;
20
+ }
21
+ /**
22
+ * Environment variable token storage for backend/server use
23
+ */
24
+ export declare class EnvironmentTokenStorage implements TokenStorage {
25
+ private envKey;
26
+ constructor(envKey?: string);
27
+ getToken(): string | null;
28
+ setToken(token: string): void;
29
+ clearToken(): void;
30
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnvironmentTokenStorage = exports.MemoryTokenStorage = exports.BrowserTokenStorage = void 0;
4
+ /**
5
+ * Browser-based token storage using localStorage
6
+ */
7
+ class BrowserTokenStorage {
8
+ constructor(tokenKey = "knowhow-jwt") {
9
+ this.tokenKey = tokenKey;
10
+ }
11
+ getToken() {
12
+ if (typeof window === "undefined") {
13
+ return null;
14
+ }
15
+ return localStorage.getItem(this.tokenKey);
16
+ }
17
+ setToken(token) {
18
+ if (typeof window !== "undefined") {
19
+ localStorage.setItem(this.tokenKey, token);
20
+ }
21
+ }
22
+ clearToken() {
23
+ if (typeof window !== "undefined") {
24
+ localStorage.removeItem(this.tokenKey);
25
+ }
26
+ }
27
+ }
28
+ exports.BrowserTokenStorage = BrowserTokenStorage;
29
+ /**
30
+ * In-memory token storage for server-side or testing
31
+ */
32
+ class MemoryTokenStorage {
33
+ constructor() {
34
+ this.token = null;
35
+ }
36
+ getToken() {
37
+ return this.token;
38
+ }
39
+ setToken(token) {
40
+ this.token = token;
41
+ }
42
+ clearToken() {
43
+ this.token = null;
44
+ }
45
+ }
46
+ exports.MemoryTokenStorage = MemoryTokenStorage;
47
+ /**
48
+ * Environment variable token storage for backend/server use
49
+ */
50
+ class EnvironmentTokenStorage {
51
+ constructor(envKey = "KNOWHOW_JWT_TOKEN") {
52
+ this.envKey = envKey;
53
+ }
54
+ getToken() {
55
+ return process.env[this.envKey] || null;
56
+ }
57
+ setToken(token) {
58
+ process.env[this.envKey] = token;
59
+ }
60
+ clearToken() {
61
+ delete process.env[this.envKey];
62
+ }
63
+ }
64
+ exports.EnvironmentTokenStorage = EnvironmentTokenStorage;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@tyvm/knowhow-api-client",
3
+ "version": "0.0.1",
4
+ "description": "API client for Knowhow backend",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc && npm run copy-types",
9
+ "dev": "tsc --watch",
10
+ "clean": "rm -rf dist",
11
+ "generate-types": "npx openapicmd typegen ../backend/build/swagger-patched.json > src/generated/openapi.d.ts",
12
+ "prebuild": "npm run clean && npm run generate-types",
13
+ "copy-types": "mkdir -p dist/generated && cp src/generated/openapi.d.ts dist/generated/ && cp src/generated/index.ts dist/generated/"
14
+ },
15
+ "files": [
16
+ "dist/**/*"
17
+ ],
18
+ "keywords": [
19
+ "api",
20
+ "client",
21
+ "knowhow",
22
+ "typescript"
23
+ ],
24
+ "author": "Micah Riggan",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "axios": ">=1.0.0",
28
+ "openapi-client-axios": ">=7.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^24.2.1",
32
+ "typescript": "^5.6.3"
33
+ },
34
+ "peerDependencies": {
35
+ "axios": ">=1.0.0",
36
+ "openapi-client-axios": ">=7.0.0"
37
+ }
38
+ }