generated from mantinedev/vite-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: saving interactions for generate and copy locators
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
import { NetlifyFunctions } from "../constants"; | ||
|
||
export const dateFormatter = new Intl.DateTimeFormat("default", { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
}); | ||
|
||
export const netlifyFunctionInvoke = async ( | ||
name: NetlifyFunctions, | ||
headers = {}, | ||
body: Object | undefined, | ||
options = { method: "POST" } | ||
) => { | ||
let url = ""; | ||
// add host for local dev | ||
if (import.meta.env.DEV) { | ||
url += import.meta.env.VITE_NETLIFY_FUNCTIONS_LOCAL_SERVER; | ||
} | ||
// add netlify function path | ||
url += `/.netlify/functions/${name}`; | ||
|
||
const response = await fetch(url, { | ||
...options, | ||
headers, | ||
body: body ? JSON.stringify(body) : undefined, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
let content = await response.text(); | ||
|
||
try { | ||
content = JSON.parse(content); | ||
} catch (e) { | ||
// content is not JSON | ||
} | ||
|
||
return content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
/// <reference types="vite/client" /> | ||
declare const APP_VERSION: string; | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_NETLIFY_FUNCTIONS_LOCAL_SERVER: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |