@kasko/fe-webapp-utils-lib
Advanced tools
Comparing version 2.5.5 to 2.6.0
# Changelog | ||
## [v2.6.0](https://github.com/kasko/fe-webapp-utils-lib/compare/v2.5.5...v2.6.0) (2024-06-13) | ||
## Feature | ||
- Add support for fnol app endpoints; | ||
## [v2.5.5](https://github.com/kasko/fe-webapp-utils-lib/compare/v2.5.4...v2.5.5) (2024-03-06) | ||
@@ -4,0 +8,0 @@ ## Bugfix |
@@ -58,6 +58,6 @@ "use strict"; | ||
// src/utils/kasko-fetch.ts | ||
var import_util = require("util"); | ||
var import_node_util = require("node:util"); | ||
// package.json | ||
var version = "2.5.5"; | ||
var version = "2.6.0"; | ||
@@ -85,3 +85,3 @@ // src/utils/kasko-fetch.ts | ||
const statusText = response.statusText === "Not Allowed" ? `${response.statusText} (instance sleeping?)` : response.statusText; | ||
error = `${statusText} (${response.status}) ${(0, import_util.inspect)( | ||
error = `${statusText} (${response.status}) ${(0, import_node_util.inspect)( | ||
{ | ||
@@ -88,0 +88,0 @@ method: options?.method || "get", |
@@ -1,4 +0,4 @@ | ||
declare type Mode = 'fullscreen' | 'webview' | 'popup'; | ||
declare type App = 'webapp' | 'portal' | 'claimsapp'; | ||
declare type Device = 'mobile' | 'tablet' | 'desktop'; | ||
type Mode = 'fullscreen' | 'webview' | 'popup'; | ||
type App = 'webapp' | 'portal' | 'claimsapp'; | ||
type Device = 'mobile' | 'tablet' | 'desktop'; | ||
interface Config { | ||
@@ -5,0 +5,0 @@ header_visibility?: Device | Device[] | boolean; |
@@ -1,1 +0,1 @@ | ||
export {}; | ||
export type {}; |
@@ -185,6 +185,6 @@ "use strict"; | ||
// src/utils/kasko-fetch.ts | ||
var import_util = require("util"); | ||
var import_node_util = require("node:util"); | ||
// package.json | ||
var version = "2.5.5"; | ||
var version = "2.6.0"; | ||
@@ -212,3 +212,3 @@ // src/utils/kasko-fetch.ts | ||
const statusText = response.statusText === "Not Allowed" ? `${response.statusText} (instance sleeping?)` : response.statusText; | ||
error = `${statusText} (${response.status}) ${(0, import_util.inspect)( | ||
error = `${statusText} (${response.status}) ${(0, import_node_util.inspect)( | ||
{ | ||
@@ -870,2 +870,44 @@ method: options?.method || "get", | ||
}, | ||
"POST /v2/media": async (req, res, _params) => { | ||
const id = `med_${(0, import_node_crypto.randomUUID)().replace(/-/g, "")}`; | ||
const body = await getBody(req); | ||
res.writeHead(200, { "Content-Type": "application/json" }); | ||
res.end( | ||
JSON.stringify({ | ||
id, | ||
is_uploaded: false, | ||
designation: body.designation, | ||
name: body.name, | ||
mime_type: body.mime_type, | ||
file_size: body.file_size | ||
}) | ||
); | ||
}, | ||
"POST /v2/media/:id/content": async (_req, res, _params) => { | ||
res.writeHead(204); | ||
res.end(""); | ||
}, | ||
"POST /v2/auth/request_customer_otp": async (req, res, _params) => { | ||
const body = await getBody(req); | ||
const urlConfig = { | ||
customer_otp_token: "TEST_OTP_TOKEN", | ||
policy: { | ||
id: body.referrer.policy_id | ||
} | ||
}; | ||
console.log( | ||
` > OTP Login: ${blue( | ||
`http://${req.headers.host}/${body.referrer.integration_id}?config=${encodeURIComponent( | ||
JSON.stringify(urlConfig) | ||
)}` | ||
)}` | ||
); | ||
console.log(); | ||
res.writeHead(200, { "Content-Type": "application/json" }); | ||
res.end(JSON.stringify({})); | ||
}, | ||
"POST /v2/auth/customer_otp_login": async (_req, res, _params) => { | ||
res.writeHead(200, { "Content-Type": "application/json" }); | ||
res.end(JSON.stringify({ token: "TEST_CUSTOMER_TOKEN" })); | ||
}, | ||
"POST /claims": (_req, res, _params) => { | ||
@@ -979,3 +1021,3 @@ res.writeHead(200, { "Content-Type": "application/json" }); | ||
if (normalFilePath !== resolvedPath) { | ||
return (0, import_node_path3.join)("/", ...new Array(parseInt(depth, 10)).fill("_.._"), resolvedPath); | ||
return (0, import_node_path3.join)("/", ...new Array(Number.parseInt(depth, 10)).fill("_.._"), resolvedPath); | ||
} | ||
@@ -1227,2 +1269,15 @@ } | ||
res.end(JSON.stringify(response)); | ||
}, | ||
"GET /fnol_integrations/:in": async (req, res, params) => { | ||
const queryString = Object.fromEntries( | ||
new URLSearchParams(req.url.replace(/^[^\?]*/, "")) | ||
); | ||
const inEntry = entries[params.in].index; | ||
const index = await requireTypescript(inEntry, params.in); | ||
if (typeof index.response !== "function") { | ||
throw new Error("response must be a function"); | ||
} | ||
const response = await index.response({ index, queryString }); | ||
res.writeHead(200, { "Content-Type": "application/json" }); | ||
res.end(JSON.stringify(response)); | ||
} | ||
@@ -1229,0 +1284,0 @@ }, |
@@ -24,2 +24,8 @@ /// <reference types="node" /> | ||
}) => void; | ||
'POST /v2/media': (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, _params: {}) => Promise<void>; | ||
'POST /v2/media/:id/content': (_req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, _params: { | ||
id: string; | ||
}) => Promise<void>; | ||
'POST /v2/auth/request_customer_otp': (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, _params: {}) => Promise<void>; | ||
'POST /v2/auth/customer_otp_login': (_req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, _params: {}) => Promise<void>; | ||
'POST /claims': (_req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>, _params: {}) => void; | ||
@@ -26,0 +32,0 @@ 'POST /sales_leads': (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>) => Promise<void>; |
import type { HTMLElementSchema } from './load-html-file'; | ||
export declare type ApiKaskoPluginAssetsResponse = { | ||
export type ApiKaskoPluginAssetsResponse = { | ||
id: string; | ||
@@ -4,0 +4,0 @@ name: string; |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import type { WebappConfig } from '../server'; | ||
import { HTMLElementSchema } from './load-html-file'; | ||
import { type HTMLElementSchema } from './load-html-file'; | ||
export declare function serverMiddleware({ outbase, port, plugins, entries, inject: customInject, }: { | ||
@@ -8,0 +8,0 @@ outbase: string; |
/// <reference types="node" /> | ||
import type { IncomingMessage, ServerResponse } from 'node:http'; | ||
declare type PathSegments<Path extends string> = Path extends `${infer SegmentA}/${infer SegmentB}` ? ParamOnly<SegmentA> | PathSegments<SegmentB> : ParamOnly<Path>; | ||
declare type ParamOnly<Segment extends string> = Segment extends `:${infer Param}` ? Param : never; | ||
declare type RouteParams<Path extends string> = { | ||
type PathSegments<Path extends string> = Path extends `${infer SegmentA}/${infer SegmentB}` ? ParamOnly<SegmentA> | PathSegments<SegmentB> : ParamOnly<Path>; | ||
type ParamOnly<Segment extends string> = Segment extends `:${infer Param}` ? Param : never; | ||
type RouteParams<Path extends string> = { | ||
[Key in PathSegments<Path>]: string; | ||
}; | ||
export declare type MockedAPIMiddleware<Path extends string = string> = (req: IncomingMessage, res: ServerResponse<IncomingMessage>, params: RouteParams<Path>) => void | false | Promise<void | false>; | ||
declare type APIMiddleware = (req: IncomingMessage, res: ServerResponse<IncomingMessage>) => Promise<boolean>; | ||
export type MockedAPIMiddleware<Path extends string = string> = (req: IncomingMessage, res: ServerResponse<IncomingMessage>, params: RouteParams<Path>) => void | false | Promise<void | false>; | ||
type APIMiddleware = (req: IncomingMessage, res: ServerResponse<IncomingMessage>) => Promise<boolean>; | ||
export declare function mockApi<T extends { | ||
@@ -11,0 +11,0 @@ [Url in Extract<keyof T, string>]: MockedAPIMiddleware<Url>; |
{ | ||
"name": "@kasko/fe-webapp-utils-lib", | ||
"version": "2.5.5", | ||
"version": "2.6.0", | ||
"main": "./dist/index.js", | ||
@@ -41,3 +41,4 @@ "types": "./dist/index.d.ts", | ||
"test": "uvu -r tsm", | ||
"lint": "biome ci src" | ||
"lint": "biome ci src", | ||
"lint:apply": "biome check src --write --unsafe" | ||
}, | ||
@@ -44,0 +45,0 @@ "peerDependencies": { |
824365
22711