@8ms/helpers 2.3.26 → 2.3.27
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/dist/_class/index.d.mts +2 -0
- package/dist/_class/index.mjs +61 -0
- package/dist/adverity/index.d.mts +2 -0
- package/dist/adverity/index.mjs +64 -0
- package/dist/adverity/server/index.d.mts +18 -0
- package/dist/adverity/server/index.mjs +25 -0
- package/dist/api/index.d.mts +2 -0
- package/dist/api/index.mjs +3 -0
- package/dist/api-DGKJDAfb.mjs +139 -0
- package/dist/array/index.d.mts +11 -0
- package/dist/array/index.mjs +12 -0
- package/dist/atInternet/index.d.mts +20 -0
- package/dist/atInternet/index.mjs +18 -0
- package/dist/aws/ec2/server/index.d.mts +18 -0
- package/dist/aws/ec2/server/index.mjs +48 -0
- package/dist/aws/ecs/server/index.d.mts +59 -0
- package/dist/aws/ecs/server/index.mjs +113 -0
- package/dist/aws/glue/server/index.d.mts +19 -0
- package/dist/aws/glue/server/index.mjs +36 -0
- package/dist/aws/lambda/server/index.d.mts +28 -0
- package/dist/aws/lambda/server/index.mjs +57 -0
- package/dist/aws/s3/server/index.d.mts +124 -0
- package/dist/aws/s3/server/index.mjs +360 -0
- package/dist/aws/server/index.d.mts +2 -0
- package/dist/aws/server/index.mjs +3 -0
- package/dist/aws/ses/server/index.d.mts +105 -0
- package/dist/aws/ses/server/index.mjs +268 -0
- package/dist/aws/sqs/server/index.d.mts +41 -0
- package/dist/aws/sqs/server/index.mjs +56 -0
- package/dist/aws/ssm/server/index.d.mts +18 -0
- package/dist/aws/ssm/server/index.mjs +47 -0
- package/dist/axios/index.d.mts +22 -0
- package/dist/axios/index.mjs +50 -0
- package/dist/boolean/index.d.mts +7 -0
- package/dist/boolean/index.mjs +13 -0
- package/dist/brightData/serpApi/server/index.d.mts +93 -0
- package/dist/brightData/serpApi/server/index.mjs +229 -0
- package/dist/brightData/server/index.d.mts +2 -0
- package/dist/brightData/server/index.mjs +18 -0
- package/dist/brightData/webScraperIde/server/index.d.mts +19 -0
- package/dist/brightData/webScraperIde/server/index.mjs +50 -0
- package/dist/cache/server/index.d.mts +10 -0
- package/dist/cache/server/index.mjs +31 -0
- package/dist/chunk-DDarj8oW.mjs +7 -0
- package/dist/crud/index.d.mts +10 -0
- package/dist/crud/index.mjs +10 -0
- package/dist/crypto/index.d.mts +25 -0
- package/dist/crypto/index.mjs +57 -0
- package/dist/date/index.d.mts +2 -0
- package/dist/date/index.mjs +471 -0
- package/dist/drizzle/server/index.d.mts +22 -0
- package/dist/drizzle/server/index.mjs +69 -0
- package/dist/environment/index.d.mts +37 -0
- package/dist/environment/index.mjs +60 -0
- package/dist/eskimi/index.d.mts +52 -0
- package/dist/eskimi/index.mjs +90 -0
- package/dist/eskimi/server/index.d.mts +25 -0
- package/dist/eskimi/server/index.mjs +50 -0
- package/dist/file/index.d.mts +7 -0
- package/dist/file/index.mjs +20 -0
- package/dist/file/server/index.d.mts +8 -0
- package/dist/file/server/index.mjs +16 -0
- package/dist/geo/index.d.mts +26 -0
- package/dist/geo/index.mjs +1591 -0
- package/dist/getDecimal-CafxtLhH.mjs +40 -0
- package/dist/googleAds/keywordPlanner/server/index.d.mts +45 -0
- package/dist/googleAds/keywordPlanner/server/index.mjs +51 -0
- package/dist/googleAds/server/index.d.mts +27 -0
- package/dist/googleAds/server/index.mjs +48 -0
- package/dist/googleCloud/bigquery/server/index.d.mts +82 -0
- package/dist/googleCloud/bigquery/server/index.mjs +133 -0
- package/dist/googleCloud/server/index.d.mts +2 -0
- package/dist/googleCloud/server/index.mjs +24 -0
- package/dist/googleCloud/sheets/server/index.d.mts +22 -0
- package/dist/googleCloud/sheets/server/index.mjs +31 -0
- package/dist/googleCloud/storage/server/index.d.mts +31 -0
- package/dist/googleCloud/storage/server/index.mjs +79 -0
- package/dist/googlePageSpeed/server/index.d.mts +34 -0
- package/dist/googlePageSpeed/server/index.mjs +53 -0
- package/dist/googleSearchIncidents/server/index.d.mts +73 -0
- package/dist/googleSearchIncidents/server/index.mjs +55 -0
- package/dist/greenDomain/server/index.d.mts +25 -0
- package/dist/greenDomain/server/index.mjs +31 -0
- package/dist/index-1fBbJGQz.d.mts +246 -0
- package/dist/index-BHuvb_7y.d.mts +116 -0
- package/dist/index-BfyGIdDD.d.mts +18 -0
- package/dist/index-CqTOMR8f.d.mts +17 -0
- package/dist/index-DW9yJLtI.d.mts +67 -0
- package/dist/index-DmCSxHCc.d.mts +32 -0
- package/dist/index-DwB8X1lz.d.mts +32 -0
- package/dist/inngest/index.d.mts +10 -0
- package/dist/inngest/index.mjs +10 -0
- package/dist/json/index.d.mts +7 -0
- package/dist/json/index.mjs +27 -0
- package/dist/littleWarden/server/index.d.mts +56 -0
- package/dist/littleWarden/server/index.mjs +79 -0
- package/dist/lodash/index.d.mts +45 -0
- package/dist/lodash/index.mjs +176 -0
- package/dist/lumar/api/server/index.d.mts +66 -0
- package/dist/lumar/api/server/index.mjs +111 -0
- package/dist/lumar/graphql/server/index.d.mts +308 -0
- package/dist/lumar/graphql/server/index.mjs +172 -0
- package/dist/myTarget/server/index.d.mts +9 -0
- package/dist/myTarget/server/index.mjs +16 -0
- package/dist/nextAuth/index.d.mts +12 -0
- package/dist/nextAuth/index.mjs +15 -0
- package/dist/nextJs/client/index.d.mts +10 -0
- package/dist/nextJs/client/index.mjs +12 -0
- package/dist/nextJs/index.d.mts +19 -0
- package/dist/nextJs/index.mjs +12 -0
- package/dist/number/index.d.mts +54 -0
- package/dist/number/index.mjs +75 -0
- package/dist/object/index.d.mts +8 -0
- package/dist/object/index.mjs +22 -0
- package/dist/onePassword/server/index.d.mts +24 -0
- package/dist/onePassword/server/index.mjs +50 -0
- package/dist/openAi/server/index.d.mts +20 -0
- package/dist/openAi/server/index.mjs +46 -0
- package/dist/prisma/index.d.mts +7 -0
- package/dist/prisma/index.mjs +15 -0
- package/dist/prisma/server/index.d.mts +31 -0
- package/dist/prisma/server/index.mjs +64 -0
- package/dist/server-Bwy4JI8Z.mjs +33 -0
- package/dist/snapchat/server/index.d.mts +25 -0
- package/dist/snapchat/server/index.mjs +39 -0
- package/dist/sorting/index.d.mts +25 -0
- package/dist/sorting/index.mjs +50 -0
- package/dist/stream/server/index.d.mts +15 -0
- package/dist/stream/server/index.mjs +48 -0
- package/dist/string/index.d.mts +107 -0
- package/dist/string/index.mjs +187 -0
- package/dist/swr/client/index.d.mts +46 -0
- package/dist/swr/client/index.mjs +40 -0
- package/dist/upTimeRobot/server/index.d.mts +72 -0
- package/dist/upTimeRobot/server/index.mjs +82 -0
- package/dist/url/index.d.mts +29 -0
- package/dist/url/index.mjs +52 -0
- package/dist/url/server/index.d.mts +9 -0
- package/dist/url/server/index.mjs +35 -0
- package/dist/util/index.d.mts +50 -0
- package/dist/util/index.mjs +107 -0
- package/dist/util/server/index.d.mts +27 -0
- package/dist/util/server/index.mjs +61 -0
- package/dist/webWorker/index.d.mts +11 -0
- package/dist/webWorker/index.mjs +11 -0
- package/dist/xml/server/index.d.mts +4 -0
- package/dist/xml/server/index.mjs +17 -0
- package/package.json +189 -118
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/nextJs/nextJs.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Get the user's remote IP Address
|
|
4
|
+
*/
|
|
5
|
+
declare const getIp: ({
|
|
6
|
+
req
|
|
7
|
+
}: {
|
|
8
|
+
req: any;
|
|
9
|
+
}) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Get the user's User Agent
|
|
12
|
+
*/
|
|
13
|
+
declare const getUserAgent: ({
|
|
14
|
+
req
|
|
15
|
+
}: {
|
|
16
|
+
req: any;
|
|
17
|
+
}) => string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getIp, getUserAgent };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/nextJs/nextJs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Get the user's remote IP Address
|
|
4
|
+
*/
|
|
5
|
+
const getIp = ({ req }) => String(req.headers?.["x-real-ip"] || "unset");
|
|
6
|
+
/**
|
|
7
|
+
* Get the user's User Agent
|
|
8
|
+
*/
|
|
9
|
+
const getUserAgent = ({ req }) => String(req.headers["user-agent"] || "unset");
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getIp, getUserAgent };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/number/format.d.ts
|
|
2
|
+
type FormatProps = {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
input: any;
|
|
5
|
+
locale?: string;
|
|
6
|
+
minDp?: number;
|
|
7
|
+
maxDp?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Take a given number and format it.
|
|
11
|
+
*/
|
|
12
|
+
declare const format: (props: FormatProps) => string;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/number/formatCurrency.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Use the International number formatting to return the currency value.
|
|
17
|
+
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
18
|
+
*/
|
|
19
|
+
declare const formatCurrency: (input: any, locale?: string, currency?: string) => string;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/number/getDecimal.d.ts
|
|
22
|
+
/**
|
|
23
|
+
* Return a decimal number after rounding.
|
|
24
|
+
*/
|
|
25
|
+
declare const getDecimal: (input: any, dp?: number) => number;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/number/getSafeDivide.d.ts
|
|
28
|
+
type GetSafeDivideProps = {
|
|
29
|
+
defaultValue?: number;
|
|
30
|
+
dp?: number;
|
|
31
|
+
divisor: any;
|
|
32
|
+
numerator: any;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
36
|
+
*/
|
|
37
|
+
declare const getSafeDivide: (props: GetSafeDivideProps) => number;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/number/getPercent.d.ts
|
|
40
|
+
declare const getPercent: (numerator: any, divisor: any, dp?: number) => number;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/number/getNumber.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* Take an input and return a number.
|
|
45
|
+
*/
|
|
46
|
+
declare const getNumber: (input: any, defaultValue?: number) => number;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/number/getPercentIncrease.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Formula to work out the percentage increase/decrease.
|
|
51
|
+
*/
|
|
52
|
+
declare const getPercentIncrease: (current: any, comparison: any, defaultValue: number) => number;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { format, formatCurrency, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { n as getNumber, t as getDecimal } from "../getDecimal-CafxtLhH.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/number/format.ts
|
|
4
|
+
/**
|
|
5
|
+
* Take a given number and format it.
|
|
6
|
+
*/
|
|
7
|
+
const format = (props) => {
|
|
8
|
+
const minDp = props?.minDp ?? 0;
|
|
9
|
+
const maxDp = props?.maxDp ?? 2;
|
|
10
|
+
const compact = props?.compact || false;
|
|
11
|
+
const inputValue = getNumber(props.input);
|
|
12
|
+
return Intl.NumberFormat(props?.locale || "en-GB", {
|
|
13
|
+
minimumFractionDigits: minDp,
|
|
14
|
+
maximumFractionDigits: maxDp,
|
|
15
|
+
notation: compact ? "compact" : "standard"
|
|
16
|
+
}).format(inputValue);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/number/formatCurrency.ts
|
|
21
|
+
/**
|
|
22
|
+
* Use the International number formatting to return the currency value.
|
|
23
|
+
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
24
|
+
*/
|
|
25
|
+
const formatCurrency = (input, locale = "en-GB", currency = "GBP") => {
|
|
26
|
+
const value = Number(input);
|
|
27
|
+
const currencyClean = currency.toUpperCase().trim();
|
|
28
|
+
let formatted = new Intl.NumberFormat(locale, {
|
|
29
|
+
style: "currency",
|
|
30
|
+
currency: currencyClean
|
|
31
|
+
}).format(value);
|
|
32
|
+
if ("USD" === currencyClean) formatted = formatted.replace("US$", "$");
|
|
33
|
+
return formatted;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/number/getSafeDivide.ts
|
|
38
|
+
/**
|
|
39
|
+
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
40
|
+
*/
|
|
41
|
+
const getSafeDivide = (props) => {
|
|
42
|
+
const numeratorInt = getNumber(props.numerator);
|
|
43
|
+
if (numeratorInt === 0) return 0;
|
|
44
|
+
const divisorInt = getNumber(props.divisor);
|
|
45
|
+
if (divisorInt === 0 || !Number.isFinite(divisorInt)) return props?.defaultValue ?? 0;
|
|
46
|
+
return getDecimal(numeratorInt / divisorInt, props?.dp);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/number/getPercent.ts
|
|
51
|
+
const getPercent = (numerator, divisor, dp) => {
|
|
52
|
+
const finalNumerator = Number(numerator);
|
|
53
|
+
const finalDivisor = Number(divisor);
|
|
54
|
+
const finalDp = Number(dp || 1);
|
|
55
|
+
return Number((getSafeDivide({
|
|
56
|
+
defaultValue: 0,
|
|
57
|
+
numerator: finalNumerator,
|
|
58
|
+
divisor: finalDivisor
|
|
59
|
+
}) * 100).toFixed(finalDp));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/number/getPercentIncrease.ts
|
|
64
|
+
/**
|
|
65
|
+
* Formula to work out the percentage increase/decrease.
|
|
66
|
+
*/
|
|
67
|
+
const getPercentIncrease = (current, comparison, defaultValue) => {
|
|
68
|
+
const currentValue = getNumber(current);
|
|
69
|
+
const comparisonValue = getNumber(comparison);
|
|
70
|
+
if (0 === comparisonValue) return defaultValue;
|
|
71
|
+
return (currentValue - comparisonValue) / comparisonValue * 100;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { format, formatCurrency, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/object/replaceKeys.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Iteratively replace all the keys in an object.
|
|
4
|
+
* https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
|
|
5
|
+
*/
|
|
6
|
+
declare const replaceKeys: (instance: any, getNewKey: Function) => object;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { replaceKeys };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/object/replaceKeys.ts
|
|
2
|
+
/**
|
|
3
|
+
* Iteratively replace all the keys in an object.
|
|
4
|
+
* https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
|
|
5
|
+
*/
|
|
6
|
+
const replaceKeys = (instance, getNewKey) => {
|
|
7
|
+
let response = instance;
|
|
8
|
+
if (Array.Array.isArray(instance)) {
|
|
9
|
+
response = [];
|
|
10
|
+
for (let i = 0; i < instance.length; i++) response[i] = replaceKeys(instance[i], getNewKey);
|
|
11
|
+
} else if ("object" === typeof instance) {
|
|
12
|
+
response = {};
|
|
13
|
+
for (const key in instance) {
|
|
14
|
+
const newKey = getNewKey(key);
|
|
15
|
+
response[newKey] = replaceKeys(instance[key], getNewKey);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return response;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { replaceKeys };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
|
|
2
|
+
import * as _1password_sdk0 from "@1password/sdk";
|
|
3
|
+
import { Client } from "@1password/sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/onePassword/server/OnePasswordNamespace.d.ts
|
|
6
|
+
declare class OnePasswordNamespace extends BaseNamespace {
|
|
7
|
+
client: Client;
|
|
8
|
+
config: OnePasswordConfig;
|
|
9
|
+
ensureInit: () => Promise<void>;
|
|
10
|
+
listVaults: () => Promise<_1password_sdk0.VaultOverview[]>;
|
|
11
|
+
getItem: (vaultId: string, itemId: string) => Promise<_1password_sdk0.Item>;
|
|
12
|
+
getJsonNote: (vaultId: string, itemId: string) => Promise<any>;
|
|
13
|
+
listItems: (vaultId: string) => Promise<_1password_sdk0.ItemOverview[]>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/onePassword/server/onePassword.d.ts
|
|
17
|
+
type OnePasswordConfig = {
|
|
18
|
+
serviceAccountToken: string;
|
|
19
|
+
integrationName?: string;
|
|
20
|
+
integrationVersion?: string;
|
|
21
|
+
};
|
|
22
|
+
declare const onePasswordClient: (key?: string, config?: OnePasswordConfig) => Promise<OnePasswordNamespace>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { OnePasswordConfig, type OnePasswordNamespace, onePasswordClient };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class/index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/onePassword/server/OnePasswordNamespace.ts
|
|
4
|
+
var OnePasswordNamespace = class extends BaseNamespace {
|
|
5
|
+
ensureInit = async () => {
|
|
6
|
+
if (!this.client) try {
|
|
7
|
+
const { createClient } = await import("@1password/sdk");
|
|
8
|
+
this.client = await createClient({
|
|
9
|
+
auth: this.config.serviceAccountToken,
|
|
10
|
+
integrationName: this.config.integrationName || "8MS Helper TS",
|
|
11
|
+
integrationVersion: this.config.integrationVersion || "v1.0.0"
|
|
12
|
+
});
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw new Error("1Password SDK not installed");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
listVaults = async () => {
|
|
18
|
+
await this.ensureInit();
|
|
19
|
+
return this.client.vaults.list();
|
|
20
|
+
};
|
|
21
|
+
getItem = async (vaultId, itemId) => {
|
|
22
|
+
await this.ensureInit();
|
|
23
|
+
return this.client.items.get(vaultId, itemId);
|
|
24
|
+
};
|
|
25
|
+
getJsonNote = async (vaultId, itemId) => {
|
|
26
|
+
let response = null;
|
|
27
|
+
const item = await this.getItem(vaultId, itemId);
|
|
28
|
+
if (item && "undefined" !== typeof item.notes) response = JSON.parse(item.notes);
|
|
29
|
+
return response;
|
|
30
|
+
};
|
|
31
|
+
listItems = async (vaultId) => {
|
|
32
|
+
await this.ensureInit();
|
|
33
|
+
return this.client.items.list(vaultId);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/onePassword/server/onePassword.ts
|
|
39
|
+
const onePasswordNamespaces = /* @__PURE__ */ new Map();
|
|
40
|
+
const onePasswordClient = async (key = "default", config) => {
|
|
41
|
+
if (onePasswordNamespaces.has(key)) return onePasswordNamespaces.get(key);
|
|
42
|
+
if (!config) if (key === "default") config = { serviceAccountToken: process.env.ONEPASSWORD_SERVICE_TOKEN };
|
|
43
|
+
else throw new Error(`Config required for namespace '${key}'`);
|
|
44
|
+
const namespace = new OnePasswordNamespace(key, config);
|
|
45
|
+
onePasswordNamespaces.set(key, namespace);
|
|
46
|
+
return namespace;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { OnePasswordNamespace, onePasswordClient };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/openAi/server/OpenAiNamespace.d.ts
|
|
4
|
+
declare class OpenAiNamespace extends BaseNamespace {
|
|
5
|
+
client: boolean;
|
|
6
|
+
config: OpenAiConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Renew the access token as it expires every 3 hours.
|
|
9
|
+
*/
|
|
10
|
+
ensureInit: () => Promise<void>;
|
|
11
|
+
completion: (prompt: string, temperature?: number, maxTokens?: number, model?: string) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/openAi/server/openAi.d.ts
|
|
15
|
+
type OpenAiConfig = {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
};
|
|
18
|
+
declare const openAiClient: (key?: string, config?: OpenAiConfig, vaultId?: string, itemId?: string) => Promise<OpenAiNamespace>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { OpenAiConfig, type OpenAiNamespace, openAiClient };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class/index.mjs";
|
|
2
|
+
import "../../api-DGKJDAfb.mjs";
|
|
3
|
+
import { post } from "../../axios/index.mjs";
|
|
4
|
+
import { onePasswordClient } from "../../onePassword/server/index.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/openAi/server/OpenAiNamespace.ts
|
|
7
|
+
var OpenAiNamespace = class extends BaseNamespace {
|
|
8
|
+
/**
|
|
9
|
+
* Renew the access token as it expires every 3 hours.
|
|
10
|
+
*/
|
|
11
|
+
ensureInit = async () => {
|
|
12
|
+
if (!this.client) this.client = true;
|
|
13
|
+
};
|
|
14
|
+
completion = async (prompt, temperature = 1, maxTokens = null, model = "gpt-3.5-turbo") => {
|
|
15
|
+
let response = null;
|
|
16
|
+
const apiResponse = await post(`https://api.openai.com/v1/chat/completions`, {
|
|
17
|
+
max_tokens: maxTokens,
|
|
18
|
+
model,
|
|
19
|
+
messages: [{
|
|
20
|
+
role: "user",
|
|
21
|
+
content: prompt
|
|
22
|
+
}],
|
|
23
|
+
temperature: 1
|
|
24
|
+
}, { headers: { Authorization: `Bearer ${this.config.apiKey}` } });
|
|
25
|
+
if (apiResponse.isSuccess()) response = apiResponse.getBody();
|
|
26
|
+
return response;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/openAi/server/openAi.ts
|
|
32
|
+
const openAiNamespaces = /* @__PURE__ */ new Map();
|
|
33
|
+
const openAiClient = async (key = "default", config, vaultId, itemId) => {
|
|
34
|
+
if (openAiNamespaces.has(key)) return openAiNamespaces.get(key);
|
|
35
|
+
let instanceConfig;
|
|
36
|
+
if (config) instanceConfig = config;
|
|
37
|
+
else if (vaultId && itemId) instanceConfig = await (await onePasswordClient()).getJsonNote(vaultId, itemId);
|
|
38
|
+
else if (process.env.OPEN_AI_VAULT_ID && process.env.OPEN_AI_ITEM_ID) instanceConfig = await (await onePasswordClient()).getJsonNote(process.env.OPEN_AI_VAULT_ID, process.env.OPEN_AI_ITEM_ID);
|
|
39
|
+
else throw new Error(`Config required for namespace '${key}'`);
|
|
40
|
+
const namespace = new OpenAiNamespace(key, instanceConfig);
|
|
41
|
+
openAiNamespaces.set(key, namespace);
|
|
42
|
+
return namespace;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { OpenAiNamespace, openAiClient };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as getDecimal$1 } from "../getDecimal-CafxtLhH.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/prisma/getDecimal.ts
|
|
4
|
+
/**
|
|
5
|
+
* Fetch the number from a prisma decimal (comes through as an object).
|
|
6
|
+
*/
|
|
7
|
+
const getDecimal = (input, dp = 2) => {
|
|
8
|
+
let numberString = "";
|
|
9
|
+
if (Array.isArray(input?.d)) numberString = input.absoluteValue();
|
|
10
|
+
else numberString = input.toString();
|
|
11
|
+
return getDecimal$1(numberString, dp);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getDecimal };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/prisma/server/PrismaNamespace.d.ts
|
|
4
|
+
declare class PrismaNamespace extends BaseNamespace {
|
|
5
|
+
client: PrismaClientLike;
|
|
6
|
+
config: PrismaConfig;
|
|
7
|
+
ensureInit: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/prisma/server/prisma.d.ts
|
|
11
|
+
type PrismaConfig = {
|
|
12
|
+
url: string;
|
|
13
|
+
isDebug: boolean;
|
|
14
|
+
isPlanetScale: boolean;
|
|
15
|
+
isMysql: boolean;
|
|
16
|
+
isPostgres: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Minimal interface representing a Prisma Client instance.
|
|
20
|
+
* Consumers of this library will have their own generated PrismaClient
|
|
21
|
+
* that satisfies this interface.
|
|
22
|
+
*/
|
|
23
|
+
interface PrismaClientLike {
|
|
24
|
+
$connect(): Promise<void>;
|
|
25
|
+
$disconnect(): Promise<void>;
|
|
26
|
+
$transaction(...args: any[]): Promise<any>;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
declare const prismaClient: (key?: string, config?: PrismaConfig) => Promise<PrismaNamespace>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { PrismaClientLike, PrismaConfig, PrismaNamespace, prismaClient };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getError } from "../../util/index.mjs";
|
|
2
|
+
import { BaseNamespace } from "../../_class/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/prisma/server/PrismaNamespace.ts
|
|
5
|
+
var PrismaNamespace = class extends BaseNamespace {
|
|
6
|
+
ensureInit = async () => {
|
|
7
|
+
if (!this.client) {
|
|
8
|
+
let adapter = null;
|
|
9
|
+
if (this.config.isPlanetScale) try {
|
|
10
|
+
const { PrismaPlanetScale } = await import("@prisma/adapter-planetscale");
|
|
11
|
+
adapter = new PrismaPlanetScale({ url: this.config.url });
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw new Error(`PlanetScale adapter not installed - ${getError(e)}`);
|
|
14
|
+
}
|
|
15
|
+
if (this.config.isMysql) try {
|
|
16
|
+
const { PrismaMariaDb } = await import("@prisma/adapter-mariadb");
|
|
17
|
+
adapter = new PrismaMariaDb(this.config.url);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw new Error(`MariaDB adapter not installed - ${getError(e)}`);
|
|
20
|
+
}
|
|
21
|
+
if (this.config.isPostgres) try {
|
|
22
|
+
const { PrismaPg } = await import("@prisma/adapter-pg");
|
|
23
|
+
adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error(`Postgres adapter not installed - ${getError(e)}`);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const { PrismaClient } = await import("@prisma/client");
|
|
29
|
+
if (this.config.isDebug) this.client = new PrismaClient({
|
|
30
|
+
adapter,
|
|
31
|
+
log: [{
|
|
32
|
+
emit: "event",
|
|
33
|
+
level: "query"
|
|
34
|
+
}]
|
|
35
|
+
});
|
|
36
|
+
else this.client = new PrismaClient({ adapter });
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw new Error(`Prisma Client not installed - ${getError(e)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/prisma/server/prisma.ts
|
|
46
|
+
const prismaNamespaces = /* @__PURE__ */ new Map();
|
|
47
|
+
const prismaClient = async (key = "default", config) => {
|
|
48
|
+
if (prismaNamespaces.has(key)) return prismaNamespaces.get(key);
|
|
49
|
+
if (!config) if (key === "default") config = {
|
|
50
|
+
url: process.env.DATABASE_URL,
|
|
51
|
+
isDebug: "true" === process.env.DATABASE_IS_DEBUG,
|
|
52
|
+
isPlanetScale: "true" === process.env.DATABASE_IS_PLANETSCALE,
|
|
53
|
+
isMysql: "true" === process.env.DATABASE_IS_MYSQL,
|
|
54
|
+
isPostgres: "true" === process.env.DATABASE_IS_POSTGRES
|
|
55
|
+
};
|
|
56
|
+
else throw new Error(`Config required for namespace '${key}'`);
|
|
57
|
+
const namespace = new PrismaNamespace(key, config);
|
|
58
|
+
await namespace.ensureInit();
|
|
59
|
+
prismaNamespaces.set(key, namespace);
|
|
60
|
+
return namespace;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { PrismaNamespace, prismaClient };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defaultTo } from "./util/index.mjs";
|
|
2
|
+
import { onePasswordClient } from "./onePassword/server/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/aws/server/isResponse200.ts
|
|
5
|
+
/**
|
|
6
|
+
* Was the API response a 200?
|
|
7
|
+
*/
|
|
8
|
+
const isResponse200 = (apiResponse) => {
|
|
9
|
+
let response = false;
|
|
10
|
+
if (200 === defaultTo(apiResponse, ["$metadata", "httpStatusCode"], 0)) response = true;
|
|
11
|
+
return response;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/aws/server/aws.ts
|
|
16
|
+
const getConfig = async (key, config, vaultId, itemId) => {
|
|
17
|
+
let response;
|
|
18
|
+
if (config) response = config;
|
|
19
|
+
else if (vaultId && itemId) response = await (await onePasswordClient()).getJsonNote(vaultId, itemId);
|
|
20
|
+
else if (process.env.AWS_VAULT_ID && process.env.AWS_ITEM_ID) response = await (await onePasswordClient()).getJsonNote(process.env.AWS_VAULT_ID, process.env.AWS_ITEM_ID);
|
|
21
|
+
else if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_REGION && process.env.AWS_SECRET_ACCESS_KEY) response = {
|
|
22
|
+
region: process.env.AWS_REGION,
|
|
23
|
+
credentials: {
|
|
24
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
25
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
else throw new Error(`Config required for namespace '${key}'`);
|
|
29
|
+
return response;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { isResponse200 as n, getConfig as t };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/snapchat/server/SnapchatNamespace.d.ts
|
|
4
|
+
type Client = {
|
|
5
|
+
expires: number;
|
|
6
|
+
refreshToken: string;
|
|
7
|
+
};
|
|
8
|
+
declare class SnapchatNamespace extends BaseNamespace {
|
|
9
|
+
client: Client;
|
|
10
|
+
config: SnapchatConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Renew the access token as it expires every 3 hours.
|
|
13
|
+
*/
|
|
14
|
+
ensureInit: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/snapchat/server/snapchat.d.ts
|
|
18
|
+
type SnapchatConfig = {
|
|
19
|
+
clientId: string;
|
|
20
|
+
clientSecret: string;
|
|
21
|
+
refreshToken: string;
|
|
22
|
+
};
|
|
23
|
+
declare const snapchatClient: (key?: string, config?: SnapchatConfig, vaultId?: string, itemId?: string) => Promise<SnapchatNamespace>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SnapchatConfig, SnapchatNamespace, snapchatClient };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class/index.mjs";
|
|
2
|
+
import "../../api-DGKJDAfb.mjs";
|
|
3
|
+
import { post } from "../../axios/index.mjs";
|
|
4
|
+
import { onePasswordClient } from "../../onePassword/server/index.mjs";
|
|
5
|
+
import { DateTime } from "luxon";
|
|
6
|
+
|
|
7
|
+
//#region src/snapchat/server/SnapchatNamespace.ts
|
|
8
|
+
var SnapchatNamespace = class extends BaseNamespace {
|
|
9
|
+
/**
|
|
10
|
+
* Renew the access token as it expires every 3 hours.
|
|
11
|
+
*/
|
|
12
|
+
ensureInit = async () => {
|
|
13
|
+
if (!this.client) {
|
|
14
|
+
const apiResponse = await post(`https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`);
|
|
15
|
+
if (apiResponse.isSuccess()) this.client = {
|
|
16
|
+
expires: DateTime.now().toUnixInteger() + 10800 * 1e3,
|
|
17
|
+
refreshToken: apiResponse.getBodyDefaultTo(["data", "access_token"], null)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/snapchat/server/snapchat.ts
|
|
25
|
+
const snapchatNamespaces = /* @__PURE__ */ new Map();
|
|
26
|
+
const snapchatClient = async (key = "default", config, vaultId, itemId) => {
|
|
27
|
+
if (snapchatNamespaces.has(key)) return snapchatNamespaces.get(key);
|
|
28
|
+
let instanceConfig;
|
|
29
|
+
if (config) instanceConfig = config;
|
|
30
|
+
else if (vaultId && itemId) instanceConfig = await (await onePasswordClient()).getJsonNote(vaultId, itemId);
|
|
31
|
+
else if (process.env.SNAPCHAT_VAULT_ID && process.env.SNAPCHAT_ITEM_ID) instanceConfig = await (await onePasswordClient()).getJsonNote(process.env.SNAPCHAT_VAULT_ID, process.env.SNAPCHAT_ITEM_ID);
|
|
32
|
+
else throw new Error(`Config required for namespace '${key}'`);
|
|
33
|
+
const namespace = new SnapchatNamespace(key, instanceConfig);
|
|
34
|
+
snapchatNamespaces.set(key, namespace);
|
|
35
|
+
return namespace;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { SnapchatNamespace, snapchatClient };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/sorting/byNumberAscending.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Take two values, ensure they are numbers and return the sorting value.
|
|
4
|
+
*/
|
|
5
|
+
declare const byNumberAscending: (valueA: any, valueB: any) => number;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/sorting/byNumberDescending.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Take two values, ensure they are numbers and return the sorting value.
|
|
10
|
+
*/
|
|
11
|
+
declare const byNumberDescending: (valueA: any, valueB: any) => number;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/sorting/byStringAscending.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Take two values, clean the strings and return the sorting value.
|
|
16
|
+
*/
|
|
17
|
+
declare const byStringAscending: (valueA: any, valueB: any) => string;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/sorting/byStringDescending.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Take two values, clean the strings and return the sorting value.
|
|
22
|
+
*/
|
|
23
|
+
declare const byStringDescending: (valueA: any, valueB: any) => string;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { byNumberAscending, byNumberDescending, byStringAscending, byStringDescending };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/sorting/byNumberAscending.ts
|
|
2
|
+
/**
|
|
3
|
+
* Take two values, ensure they are numbers and return the sorting value.
|
|
4
|
+
*/
|
|
5
|
+
const byNumberAscending = (valueA, valueB) => {
|
|
6
|
+
const a = Number(valueA);
|
|
7
|
+
const b = Number(valueB);
|
|
8
|
+
if (isNaN(a) && isNaN(b)) return 0;
|
|
9
|
+
if (isNaN(a)) return 1;
|
|
10
|
+
if (isNaN(b)) return -1;
|
|
11
|
+
return a - b;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/sorting/byNumberDescending.ts
|
|
16
|
+
/**
|
|
17
|
+
* Take two values, ensure they are numbers and return the sorting value.
|
|
18
|
+
*/
|
|
19
|
+
const byNumberDescending = (valueA, valueB) => {
|
|
20
|
+
const a = Number(valueA);
|
|
21
|
+
const b = Number(valueB);
|
|
22
|
+
if (isNaN(a) && isNaN(b)) return 0;
|
|
23
|
+
if (isNaN(a)) return 1;
|
|
24
|
+
if (isNaN(b)) return -1;
|
|
25
|
+
return b - a;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/sorting/byStringAscending.ts
|
|
30
|
+
/**
|
|
31
|
+
* Take two values, clean the strings and return the sorting value.
|
|
32
|
+
*/
|
|
33
|
+
const byStringAscending = (valueA, valueB) => {
|
|
34
|
+
const valueAClean = valueA.toString().trim().toLowerCase();
|
|
35
|
+
const valueBClean = valueB.toString().trim().toLowerCase();
|
|
36
|
+
return valueAClean.localeCompare(valueBClean);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/sorting/byStringDescending.ts
|
|
41
|
+
/**
|
|
42
|
+
* Take two values, clean the strings and return the sorting value.
|
|
43
|
+
*/
|
|
44
|
+
const byStringDescending = (valueA, valueB) => {
|
|
45
|
+
const valueAClean = valueA.toString().trim().toLowerCase();
|
|
46
|
+
return valueB.toString().trim().toLowerCase().localeCompare(valueAClean);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { byNumberAscending, byNumberDescending, byStringAscending, byStringDescending };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/stream/server/sort.d.ts
|
|
2
|
+
declare const Transform: any;
|
|
3
|
+
/**
|
|
4
|
+
* Batch sort stream without overloading the memory limit.
|
|
5
|
+
* https://www.npmjs.com/package/fast-stream-sort
|
|
6
|
+
*/
|
|
7
|
+
declare class SortStreamer extends Transform {
|
|
8
|
+
constructor(options: any, comp: any);
|
|
9
|
+
_transform(data: any, _: any, callback: any): void;
|
|
10
|
+
_flush(): void;
|
|
11
|
+
fullflush(): void;
|
|
12
|
+
}
|
|
13
|
+
declare const sort: (comp: any, options: any) => SortStreamer;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { sort };
|