@tern-secure/shared 1.3.0-canary.v20251030165007 → 1.3.0-canary.v20251125170702
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/chunk-B2SN66XE.mjs +25 -0
- package/dist/chunk-B2SN66XE.mjs.map +1 -0
- package/dist/{chunk-33U3M4YY.mjs → chunk-IGYBIQYE.mjs} +14 -7
- package/dist/chunk-IGYBIQYE.mjs.map +1 -0
- package/dist/chunk-N2V3PKFE.mjs +61 -0
- package/dist/chunk-N2V3PKFE.mjs.map +1 -0
- package/dist/cookie.js.map +1 -1
- package/dist/cookie.mjs.map +1 -1
- package/dist/date.d.mts +18 -0
- package/dist/date.d.ts +18 -0
- package/dist/date.js +98 -0
- package/dist/date.js.map +1 -0
- package/dist/date.mjs +69 -0
- package/dist/date.mjs.map +1 -0
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/loadScript.js +68 -6
- package/dist/loadScript.js.map +1 -1
- package/dist/loadScript.mjs +2 -1
- package/dist/loadTernUIScript.d.mts +14 -6
- package/dist/loadTernUIScript.d.ts +14 -6
- package/dist/loadTernUIScript.js +122 -29
- package/dist/loadTernUIScript.js.map +1 -1
- package/dist/loadTernUIScript.mjs +45 -25
- package/dist/loadTernUIScript.mjs.map +1 -1
- package/dist/ms.d.mts +52 -0
- package/dist/ms.d.ts +52 -0
- package/dist/ms.js +181 -0
- package/dist/ms.js.map +1 -0
- package/dist/ms.mjs +153 -0
- package/dist/ms.mjs.map +1 -0
- package/dist/react/index.d.mts +19 -1
- package/dist/react/index.d.ts +19 -1
- package/dist/react/index.js +26 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +23 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/resolveVersion.d.mts +2 -1
- package/dist/resolveVersion.d.ts +2 -1
- package/dist/resolveVersion.js +16 -2
- package/dist/resolveVersion.js.map +1 -1
- package/dist/resolveVersion.mjs +3 -1
- package/dist/retry.mjs +3 -56
- package/dist/retry.mjs.map +1 -1
- package/dist/url.d.mts +2 -1
- package/dist/url.d.ts +2 -1
- package/dist/url.js +4 -0
- package/dist/url.js.map +1 -1
- package/dist/url.mjs +3 -0
- package/dist/url.mjs.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-33U3M4YY.mjs.map +0 -1
- package/dist/chunk-PHCVLVZY.mjs +0 -12
- package/dist/chunk-PHCVLVZY.mjs.map +0 -1
package/dist/ms.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ms.ts
|
|
21
|
+
var ms_exports = {};
|
|
22
|
+
__export(ms_exports, {
|
|
23
|
+
format: () => format,
|
|
24
|
+
ms: () => ms,
|
|
25
|
+
parse: () => parse,
|
|
26
|
+
parseStrict: () => parseStrict
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(ms_exports);
|
|
29
|
+
var s = 1e3;
|
|
30
|
+
var m = s * 60;
|
|
31
|
+
var h = m * 60;
|
|
32
|
+
var d = h * 24;
|
|
33
|
+
var w = d * 7;
|
|
34
|
+
var y = d * 365.25;
|
|
35
|
+
var mo = y / 12;
|
|
36
|
+
function ms(value, options) {
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
return parse(value);
|
|
39
|
+
} else if (typeof value === "number") {
|
|
40
|
+
return format(value, options);
|
|
41
|
+
}
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function parse(str) {
|
|
47
|
+
if (typeof str !== "string" || str.length === 0 || str.length > 100) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(
|
|
53
|
+
str
|
|
54
|
+
);
|
|
55
|
+
if (!(match == null ? void 0 : match.groups)) {
|
|
56
|
+
return NaN;
|
|
57
|
+
}
|
|
58
|
+
const { value, unit = "ms" } = match.groups;
|
|
59
|
+
const n = parseFloat(value);
|
|
60
|
+
const matchUnit = unit.toLowerCase();
|
|
61
|
+
switch (matchUnit) {
|
|
62
|
+
case "years":
|
|
63
|
+
case "year":
|
|
64
|
+
case "yrs":
|
|
65
|
+
case "yr":
|
|
66
|
+
case "y":
|
|
67
|
+
return n * y;
|
|
68
|
+
case "months":
|
|
69
|
+
case "month":
|
|
70
|
+
case "mo":
|
|
71
|
+
return n * mo;
|
|
72
|
+
case "weeks":
|
|
73
|
+
case "week":
|
|
74
|
+
case "w":
|
|
75
|
+
return n * w;
|
|
76
|
+
case "days":
|
|
77
|
+
case "day":
|
|
78
|
+
case "d":
|
|
79
|
+
return n * d;
|
|
80
|
+
case "hours":
|
|
81
|
+
case "hour":
|
|
82
|
+
case "hrs":
|
|
83
|
+
case "hr":
|
|
84
|
+
case "h":
|
|
85
|
+
return n * h;
|
|
86
|
+
case "minutes":
|
|
87
|
+
case "minute":
|
|
88
|
+
case "mins":
|
|
89
|
+
case "min":
|
|
90
|
+
case "m":
|
|
91
|
+
return n * m;
|
|
92
|
+
case "seconds":
|
|
93
|
+
case "second":
|
|
94
|
+
case "secs":
|
|
95
|
+
case "sec":
|
|
96
|
+
case "s":
|
|
97
|
+
return n * s;
|
|
98
|
+
case "milliseconds":
|
|
99
|
+
case "millisecond":
|
|
100
|
+
case "msecs":
|
|
101
|
+
case "msec":
|
|
102
|
+
case "ms":
|
|
103
|
+
return n;
|
|
104
|
+
default:
|
|
105
|
+
matchUnit;
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Unknown unit "${matchUnit}" provided to ms.parse(). value=${JSON.stringify(str)}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function parseStrict(value) {
|
|
112
|
+
return parse(value);
|
|
113
|
+
}
|
|
114
|
+
function fmtShort(ms2) {
|
|
115
|
+
const msAbs = Math.abs(ms2);
|
|
116
|
+
if (msAbs >= y) {
|
|
117
|
+
return `${Math.round(ms2 / y)}y`;
|
|
118
|
+
}
|
|
119
|
+
if (msAbs >= mo) {
|
|
120
|
+
return `${Math.round(ms2 / mo)}mo`;
|
|
121
|
+
}
|
|
122
|
+
if (msAbs >= w) {
|
|
123
|
+
return `${Math.round(ms2 / w)}w`;
|
|
124
|
+
}
|
|
125
|
+
if (msAbs >= d) {
|
|
126
|
+
return `${Math.round(ms2 / d)}d`;
|
|
127
|
+
}
|
|
128
|
+
if (msAbs >= h) {
|
|
129
|
+
return `${Math.round(ms2 / h)}h`;
|
|
130
|
+
}
|
|
131
|
+
if (msAbs >= m) {
|
|
132
|
+
return `${Math.round(ms2 / m)}m`;
|
|
133
|
+
}
|
|
134
|
+
if (msAbs >= s) {
|
|
135
|
+
return `${Math.round(ms2 / s)}s`;
|
|
136
|
+
}
|
|
137
|
+
return `${ms2}ms`;
|
|
138
|
+
}
|
|
139
|
+
function fmtLong(ms2) {
|
|
140
|
+
const msAbs = Math.abs(ms2);
|
|
141
|
+
if (msAbs >= y) {
|
|
142
|
+
return plural(ms2, msAbs, y, "year");
|
|
143
|
+
}
|
|
144
|
+
if (msAbs >= mo) {
|
|
145
|
+
return plural(ms2, msAbs, mo, "month");
|
|
146
|
+
}
|
|
147
|
+
if (msAbs >= w) {
|
|
148
|
+
return plural(ms2, msAbs, w, "week");
|
|
149
|
+
}
|
|
150
|
+
if (msAbs >= d) {
|
|
151
|
+
return plural(ms2, msAbs, d, "day");
|
|
152
|
+
}
|
|
153
|
+
if (msAbs >= h) {
|
|
154
|
+
return plural(ms2, msAbs, h, "hour");
|
|
155
|
+
}
|
|
156
|
+
if (msAbs >= m) {
|
|
157
|
+
return plural(ms2, msAbs, m, "minute");
|
|
158
|
+
}
|
|
159
|
+
if (msAbs >= s) {
|
|
160
|
+
return plural(ms2, msAbs, s, "second");
|
|
161
|
+
}
|
|
162
|
+
return `${ms2} ms`;
|
|
163
|
+
}
|
|
164
|
+
function format(ms2, options) {
|
|
165
|
+
if (typeof ms2 !== "number" || !Number.isFinite(ms2)) {
|
|
166
|
+
throw new Error("Value provided to ms.format() must be of type number.");
|
|
167
|
+
}
|
|
168
|
+
return (options == null ? void 0 : options.long) ? fmtLong(ms2) : fmtShort(ms2);
|
|
169
|
+
}
|
|
170
|
+
function plural(ms2, msAbs, n, name) {
|
|
171
|
+
const isPlural = msAbs >= n * 1.5;
|
|
172
|
+
return `${Math.round(ms2 / n)} ${name}${isPlural ? "s" : ""}`;
|
|
173
|
+
}
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
format,
|
|
177
|
+
ms,
|
|
178
|
+
parse,
|
|
179
|
+
parseStrict
|
|
180
|
+
});
|
|
181
|
+
//# sourceMappingURL=ms.js.map
|
package/dist/ms.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ms.ts"],"sourcesContent":["const s = 1000;\nconst m = s * 60;\nconst h = m * 60;\nconst d = h * 24;\nconst w = d * 7;\nconst y = d * 365.25;\nconst mo = y / 12;\n\ntype Years = 'years' | 'year' | 'yrs' | 'yr' | 'y';\ntype Months = 'months' | 'month' | 'mo';\ntype Weeks = 'weeks' | 'week' | 'w';\ntype Days = 'days' | 'day' | 'd';\ntype Hours = 'hours' | 'hour' | 'hrs' | 'hr' | 'h';\ntype Minutes = 'minutes' | 'minute' | 'mins' | 'min' | 'm';\ntype Seconds = 'seconds' | 'second' | 'secs' | 'sec' | 's';\ntype Milliseconds = 'milliseconds' | 'millisecond' | 'msecs' | 'msec' | 'ms';\ntype Unit =\n | Years\n | Months\n | Weeks\n | Days\n | Hours\n | Minutes\n | Seconds\n | Milliseconds;\n\ntype UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Unit;\n\nexport type StringValue =\n | `${number}`\n | `${number}${UnitAnyCase}`\n | `${number} ${UnitAnyCase}`;\n\ninterface Options {\n /**\n * Set to `true` to use verbose formatting. Defaults to `false`.\n */\n long?: boolean;\n}\n\n/**\n * Parse or format the given value.\n *\n * @param value - The string or number to convert\n * @param options - Options for the conversion\n * @throws Error if `value` is not a non-empty string or a number\n */\nexport function ms(value: StringValue, options?: Options): number;\nexport function ms(value: number, options?: Options): string;\nexport function ms(\n value: StringValue | number,\n options?: Options,\n): number | string {\n if (typeof value === 'string') {\n return parse(value);\n } else if (typeof value === 'number') {\n return format(value, options);\n }\n throw new Error(\n `Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`,\n );\n}\n\n/**\n * Parse the given string and return milliseconds.\n *\n * @param str - A string to parse to milliseconds\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be\n * parsed\n */\nexport function parse(str: string): number {\n if (typeof str !== 'string' || str.length === 0 || str.length > 100) {\n throw new Error(\n `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`,\n );\n }\n const match =\n /^(?<value>-?\\d*\\.?\\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(\n str,\n );\n\n if (!match?.groups) {\n return NaN;\n }\n\n // Named capture groups need to be manually typed today.\n // https://github.com/microsoft/TypeScript/issues/32098\n const { value, unit = 'ms' } = match.groups as {\n value: string;\n unit: string | undefined;\n };\n\n const n = parseFloat(value);\n\n const matchUnit = unit.toLowerCase() as Lowercase<Unit>;\n\n /* istanbul ignore next - istanbul doesn't understand, but thankfully the TypeScript the exhaustiveness check in the default case keeps us type safe here */\n switch (matchUnit) {\n case 'years':\n case 'year':\n case 'yrs':\n case 'yr':\n case 'y':\n return n * y;\n case 'months':\n case 'month':\n case 'mo':\n return n * mo;\n case 'weeks':\n case 'week':\n case 'w':\n return n * w;\n case 'days':\n case 'day':\n case 'd':\n return n * d;\n case 'hours':\n case 'hour':\n case 'hrs':\n case 'hr':\n case 'h':\n return n * h;\n case 'minutes':\n case 'minute':\n case 'mins':\n case 'min':\n case 'm':\n return n * m;\n case 'seconds':\n case 'second':\n case 'secs':\n case 'sec':\n case 's':\n return n * s;\n case 'milliseconds':\n case 'millisecond':\n case 'msecs':\n case 'msec':\n case 'ms':\n return n;\n default:\n matchUnit satisfies never;\n throw new Error(\n `Unknown unit \"${matchUnit}\" provided to ms.parse(). value=${JSON.stringify(str)}`,\n );\n }\n}\n\n/**\n * Parse the given StringValue and return milliseconds.\n *\n * @param value - A typesafe StringValue to parse to milliseconds\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be\n * parsed\n */\nexport function parseStrict(value: StringValue): number {\n return parse(value);\n}\n\n/**\n * Short format for `ms`.\n */\nfunction fmtShort(ms: number): StringValue {\n const msAbs = Math.abs(ms);\n if (msAbs >= y) {\n return `${Math.round(ms / y)}y`;\n }\n if (msAbs >= mo) {\n return `${Math.round(ms / mo)}mo`;\n }\n if (msAbs >= w) {\n return `${Math.round(ms / w)}w`;\n }\n if (msAbs >= d) {\n return `${Math.round(ms / d)}d`;\n }\n if (msAbs >= h) {\n return `${Math.round(ms / h)}h`;\n }\n if (msAbs >= m) {\n return `${Math.round(ms / m)}m`;\n }\n if (msAbs >= s) {\n return `${Math.round(ms / s)}s`;\n }\n return `${ms}ms`;\n}\n\n/**\n * Long format for `ms`.\n */\nfunction fmtLong(ms: number): StringValue {\n const msAbs = Math.abs(ms);\n if (msAbs >= y) {\n return plural(ms, msAbs, y, 'year');\n }\n if (msAbs >= mo) {\n return plural(ms, msAbs, mo, 'month');\n }\n if (msAbs >= w) {\n return plural(ms, msAbs, w, 'week');\n }\n if (msAbs >= d) {\n return plural(ms, msAbs, d, 'day');\n }\n if (msAbs >= h) {\n return plural(ms, msAbs, h, 'hour');\n }\n if (msAbs >= m) {\n return plural(ms, msAbs, m, 'minute');\n }\n if (msAbs >= s) {\n return plural(ms, msAbs, s, 'second');\n }\n return `${ms} ms`;\n}\n\n/**\n * Format the given integer as a string.\n *\n * @param ms - milliseconds\n * @param options - Options for the conversion\n * @returns The formatted string\n */\nexport function format(ms: number, options?: Options): string {\n if (typeof ms !== 'number' || !Number.isFinite(ms)) {\n throw new Error('Value provided to ms.format() must be of type number.');\n }\n\n return options?.long ? fmtLong(ms) : fmtShort(ms);\n}\n\n/**\n * Pluralization helper.\n */\nfunction plural(\n ms: number,\n msAbs: number,\n n: number,\n name: string,\n): StringValue {\n const isPlural = msAbs >= n * 1.5;\n return `${Math.round(ms / n)} ${name}${isPlural ? 's' : ''}` as StringValue;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,IAAI;AACV,IAAM,IAAI,IA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AAA,EACpC;AACA,MAAI,SAAS,IAAI;AACf,WAAO,OAAOA,KAAI,OAAO,IAAI,OAAO;AAAA,EACtC;AACA,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,MAAM;AAAA,EACpC;AACA,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,KAAK;AAAA,EACnC;AACA,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,MAAM;AAAA,EACpC;AACA,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,QAAQ;AAAA,EACtC;AACA,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,QAAQ;AAAA,EACtC;AACA,SAAO,GAAGA,GAAE;AACd;AASO,SAAS,OAAOA,KAAY,SAA2B;AAC5D,MAAI,OAAOA,QAAO,YAAY,CAAC,OAAO,SAASA,GAAE,GAAG;AAClD,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,UAAO,mCAAS,QAAO,QAAQA,GAAE,IAAI,SAASA,GAAE;AAClD;AAKA,SAAS,OACPA,KACA,OACA,GACA,MACa;AACb,QAAM,WAAW,SAAS,IAAI;AAC9B,SAAO,GAAG,KAAK,MAAMA,MAAK,CAAC,CAAC,IAAI,IAAI,GAAG,WAAW,MAAM,EAAE;AAC5D;","names":["ms"]}
|
package/dist/ms.mjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// src/ms.ts
|
|
2
|
+
var s = 1e3;
|
|
3
|
+
var m = s * 60;
|
|
4
|
+
var h = m * 60;
|
|
5
|
+
var d = h * 24;
|
|
6
|
+
var w = d * 7;
|
|
7
|
+
var y = d * 365.25;
|
|
8
|
+
var mo = y / 12;
|
|
9
|
+
function ms(value, options) {
|
|
10
|
+
if (typeof value === "string") {
|
|
11
|
+
return parse(value);
|
|
12
|
+
} else if (typeof value === "number") {
|
|
13
|
+
return format(value, options);
|
|
14
|
+
}
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
function parse(str) {
|
|
20
|
+
if (typeof str !== "string" || str.length === 0 || str.length > 100) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(
|
|
26
|
+
str
|
|
27
|
+
);
|
|
28
|
+
if (!(match == null ? void 0 : match.groups)) {
|
|
29
|
+
return NaN;
|
|
30
|
+
}
|
|
31
|
+
const { value, unit = "ms" } = match.groups;
|
|
32
|
+
const n = parseFloat(value);
|
|
33
|
+
const matchUnit = unit.toLowerCase();
|
|
34
|
+
switch (matchUnit) {
|
|
35
|
+
case "years":
|
|
36
|
+
case "year":
|
|
37
|
+
case "yrs":
|
|
38
|
+
case "yr":
|
|
39
|
+
case "y":
|
|
40
|
+
return n * y;
|
|
41
|
+
case "months":
|
|
42
|
+
case "month":
|
|
43
|
+
case "mo":
|
|
44
|
+
return n * mo;
|
|
45
|
+
case "weeks":
|
|
46
|
+
case "week":
|
|
47
|
+
case "w":
|
|
48
|
+
return n * w;
|
|
49
|
+
case "days":
|
|
50
|
+
case "day":
|
|
51
|
+
case "d":
|
|
52
|
+
return n * d;
|
|
53
|
+
case "hours":
|
|
54
|
+
case "hour":
|
|
55
|
+
case "hrs":
|
|
56
|
+
case "hr":
|
|
57
|
+
case "h":
|
|
58
|
+
return n * h;
|
|
59
|
+
case "minutes":
|
|
60
|
+
case "minute":
|
|
61
|
+
case "mins":
|
|
62
|
+
case "min":
|
|
63
|
+
case "m":
|
|
64
|
+
return n * m;
|
|
65
|
+
case "seconds":
|
|
66
|
+
case "second":
|
|
67
|
+
case "secs":
|
|
68
|
+
case "sec":
|
|
69
|
+
case "s":
|
|
70
|
+
return n * s;
|
|
71
|
+
case "milliseconds":
|
|
72
|
+
case "millisecond":
|
|
73
|
+
case "msecs":
|
|
74
|
+
case "msec":
|
|
75
|
+
case "ms":
|
|
76
|
+
return n;
|
|
77
|
+
default:
|
|
78
|
+
matchUnit;
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Unknown unit "${matchUnit}" provided to ms.parse(). value=${JSON.stringify(str)}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function parseStrict(value) {
|
|
85
|
+
return parse(value);
|
|
86
|
+
}
|
|
87
|
+
function fmtShort(ms2) {
|
|
88
|
+
const msAbs = Math.abs(ms2);
|
|
89
|
+
if (msAbs >= y) {
|
|
90
|
+
return `${Math.round(ms2 / y)}y`;
|
|
91
|
+
}
|
|
92
|
+
if (msAbs >= mo) {
|
|
93
|
+
return `${Math.round(ms2 / mo)}mo`;
|
|
94
|
+
}
|
|
95
|
+
if (msAbs >= w) {
|
|
96
|
+
return `${Math.round(ms2 / w)}w`;
|
|
97
|
+
}
|
|
98
|
+
if (msAbs >= d) {
|
|
99
|
+
return `${Math.round(ms2 / d)}d`;
|
|
100
|
+
}
|
|
101
|
+
if (msAbs >= h) {
|
|
102
|
+
return `${Math.round(ms2 / h)}h`;
|
|
103
|
+
}
|
|
104
|
+
if (msAbs >= m) {
|
|
105
|
+
return `${Math.round(ms2 / m)}m`;
|
|
106
|
+
}
|
|
107
|
+
if (msAbs >= s) {
|
|
108
|
+
return `${Math.round(ms2 / s)}s`;
|
|
109
|
+
}
|
|
110
|
+
return `${ms2}ms`;
|
|
111
|
+
}
|
|
112
|
+
function fmtLong(ms2) {
|
|
113
|
+
const msAbs = Math.abs(ms2);
|
|
114
|
+
if (msAbs >= y) {
|
|
115
|
+
return plural(ms2, msAbs, y, "year");
|
|
116
|
+
}
|
|
117
|
+
if (msAbs >= mo) {
|
|
118
|
+
return plural(ms2, msAbs, mo, "month");
|
|
119
|
+
}
|
|
120
|
+
if (msAbs >= w) {
|
|
121
|
+
return plural(ms2, msAbs, w, "week");
|
|
122
|
+
}
|
|
123
|
+
if (msAbs >= d) {
|
|
124
|
+
return plural(ms2, msAbs, d, "day");
|
|
125
|
+
}
|
|
126
|
+
if (msAbs >= h) {
|
|
127
|
+
return plural(ms2, msAbs, h, "hour");
|
|
128
|
+
}
|
|
129
|
+
if (msAbs >= m) {
|
|
130
|
+
return plural(ms2, msAbs, m, "minute");
|
|
131
|
+
}
|
|
132
|
+
if (msAbs >= s) {
|
|
133
|
+
return plural(ms2, msAbs, s, "second");
|
|
134
|
+
}
|
|
135
|
+
return `${ms2} ms`;
|
|
136
|
+
}
|
|
137
|
+
function format(ms2, options) {
|
|
138
|
+
if (typeof ms2 !== "number" || !Number.isFinite(ms2)) {
|
|
139
|
+
throw new Error("Value provided to ms.format() must be of type number.");
|
|
140
|
+
}
|
|
141
|
+
return (options == null ? void 0 : options.long) ? fmtLong(ms2) : fmtShort(ms2);
|
|
142
|
+
}
|
|
143
|
+
function plural(ms2, msAbs, n, name) {
|
|
144
|
+
const isPlural = msAbs >= n * 1.5;
|
|
145
|
+
return `${Math.round(ms2 / n)} ${name}${isPlural ? "s" : ""}`;
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
format,
|
|
149
|
+
ms,
|
|
150
|
+
parse,
|
|
151
|
+
parseStrict
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=ms.mjs.map
|
package/dist/ms.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ms.ts"],"sourcesContent":["const s = 1000;\nconst m = s * 60;\nconst h = m * 60;\nconst d = h * 24;\nconst w = d * 7;\nconst y = d * 365.25;\nconst mo = y / 12;\n\ntype Years = 'years' | 'year' | 'yrs' | 'yr' | 'y';\ntype Months = 'months' | 'month' | 'mo';\ntype Weeks = 'weeks' | 'week' | 'w';\ntype Days = 'days' | 'day' | 'd';\ntype Hours = 'hours' | 'hour' | 'hrs' | 'hr' | 'h';\ntype Minutes = 'minutes' | 'minute' | 'mins' | 'min' | 'm';\ntype Seconds = 'seconds' | 'second' | 'secs' | 'sec' | 's';\ntype Milliseconds = 'milliseconds' | 'millisecond' | 'msecs' | 'msec' | 'ms';\ntype Unit =\n | Years\n | Months\n | Weeks\n | Days\n | Hours\n | Minutes\n | Seconds\n | Milliseconds;\n\ntype UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Unit;\n\nexport type StringValue =\n | `${number}`\n | `${number}${UnitAnyCase}`\n | `${number} ${UnitAnyCase}`;\n\ninterface Options {\n /**\n * Set to `true` to use verbose formatting. Defaults to `false`.\n */\n long?: boolean;\n}\n\n/**\n * Parse or format the given value.\n *\n * @param value - The string or number to convert\n * @param options - Options for the conversion\n * @throws Error if `value` is not a non-empty string or a number\n */\nexport function ms(value: StringValue, options?: Options): number;\nexport function ms(value: number, options?: Options): string;\nexport function ms(\n value: StringValue | number,\n options?: Options,\n): number | string {\n if (typeof value === 'string') {\n return parse(value);\n } else if (typeof value === 'number') {\n return format(value, options);\n }\n throw new Error(\n `Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`,\n );\n}\n\n/**\n * Parse the given string and return milliseconds.\n *\n * @param str - A string to parse to milliseconds\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be\n * parsed\n */\nexport function parse(str: string): number {\n if (typeof str !== 'string' || str.length === 0 || str.length > 100) {\n throw new Error(\n `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`,\n );\n }\n const match =\n /^(?<value>-?\\d*\\.?\\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(\n str,\n );\n\n if (!match?.groups) {\n return NaN;\n }\n\n // Named capture groups need to be manually typed today.\n // https://github.com/microsoft/TypeScript/issues/32098\n const { value, unit = 'ms' } = match.groups as {\n value: string;\n unit: string | undefined;\n };\n\n const n = parseFloat(value);\n\n const matchUnit = unit.toLowerCase() as Lowercase<Unit>;\n\n /* istanbul ignore next - istanbul doesn't understand, but thankfully the TypeScript the exhaustiveness check in the default case keeps us type safe here */\n switch (matchUnit) {\n case 'years':\n case 'year':\n case 'yrs':\n case 'yr':\n case 'y':\n return n * y;\n case 'months':\n case 'month':\n case 'mo':\n return n * mo;\n case 'weeks':\n case 'week':\n case 'w':\n return n * w;\n case 'days':\n case 'day':\n case 'd':\n return n * d;\n case 'hours':\n case 'hour':\n case 'hrs':\n case 'hr':\n case 'h':\n return n * h;\n case 'minutes':\n case 'minute':\n case 'mins':\n case 'min':\n case 'm':\n return n * m;\n case 'seconds':\n case 'second':\n case 'secs':\n case 'sec':\n case 's':\n return n * s;\n case 'milliseconds':\n case 'millisecond':\n case 'msecs':\n case 'msec':\n case 'ms':\n return n;\n default:\n matchUnit satisfies never;\n throw new Error(\n `Unknown unit \"${matchUnit}\" provided to ms.parse(). value=${JSON.stringify(str)}`,\n );\n }\n}\n\n/**\n * Parse the given StringValue and return milliseconds.\n *\n * @param value - A typesafe StringValue to parse to milliseconds\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be\n * parsed\n */\nexport function parseStrict(value: StringValue): number {\n return parse(value);\n}\n\n/**\n * Short format for `ms`.\n */\nfunction fmtShort(ms: number): StringValue {\n const msAbs = Math.abs(ms);\n if (msAbs >= y) {\n return `${Math.round(ms / y)}y`;\n }\n if (msAbs >= mo) {\n return `${Math.round(ms / mo)}mo`;\n }\n if (msAbs >= w) {\n return `${Math.round(ms / w)}w`;\n }\n if (msAbs >= d) {\n return `${Math.round(ms / d)}d`;\n }\n if (msAbs >= h) {\n return `${Math.round(ms / h)}h`;\n }\n if (msAbs >= m) {\n return `${Math.round(ms / m)}m`;\n }\n if (msAbs >= s) {\n return `${Math.round(ms / s)}s`;\n }\n return `${ms}ms`;\n}\n\n/**\n * Long format for `ms`.\n */\nfunction fmtLong(ms: number): StringValue {\n const msAbs = Math.abs(ms);\n if (msAbs >= y) {\n return plural(ms, msAbs, y, 'year');\n }\n if (msAbs >= mo) {\n return plural(ms, msAbs, mo, 'month');\n }\n if (msAbs >= w) {\n return plural(ms, msAbs, w, 'week');\n }\n if (msAbs >= d) {\n return plural(ms, msAbs, d, 'day');\n }\n if (msAbs >= h) {\n return plural(ms, msAbs, h, 'hour');\n }\n if (msAbs >= m) {\n return plural(ms, msAbs, m, 'minute');\n }\n if (msAbs >= s) {\n return plural(ms, msAbs, s, 'second');\n }\n return `${ms} ms`;\n}\n\n/**\n * Format the given integer as a string.\n *\n * @param ms - milliseconds\n * @param options - Options for the conversion\n * @returns The formatted string\n */\nexport function format(ms: number, options?: Options): string {\n if (typeof ms !== 'number' || !Number.isFinite(ms)) {\n throw new Error('Value provided to ms.format() must be of type number.');\n }\n\n return options?.long ? fmtLong(ms) : fmtShort(ms);\n}\n\n/**\n * Pluralization helper.\n */\nfunction plural(\n ms: number,\n msAbs: number,\n n: number,\n name: string,\n): StringValue {\n const isPlural = msAbs >= n * 1.5;\n return `${Math.round(ms / n)} ${name}${isPlural ? 's' : ''}` as StringValue;\n}"],"mappings":";AAAA,IAAM,IAAI;AACV,IAAM,IAAI,IAAI;AACd,IAAM,IAAI,IAAI;AACd,IAAM,IAAI,IAAI;AACd,IAAM,IAAI,IAAI;AACd,IAAM,IAAI,IAAI;AACd,IAAM,KAAK,IAAI;AA2CR,SAAS,GACd,OACA,SACiB;AACjB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,MAAM,KAAK;AAAA,EACpB,WAAW,OAAO,UAAU,UAAU;AACpC,WAAO,OAAO,OAAO,OAAO;AAAA,EAC9B;AACA,QAAM,IAAI;AAAA,IACR,4DAA4D,KAAK,UAAU,KAAK,CAAC;AAAA,EACnF;AACF;AASO,SAAS,MAAM,KAAqB;AACzC,MAAI,OAAO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A,MAAI,SAAS,GAAG;AACd,WAAO,OAAOA,KAAI,OAAO,GAAG,QAAQ;AAAA,EACtC;AACA,SAAO,GAAGA,GAAE;AACd;AASO,SAAS,OAAOA,KAAY,SAA2B;AAC5D,MAAI,OAAOA,QAAO,YAAY,CAAC,OAAO,SAASA,GAAE,GAAG;AAClD,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,UAAO,mCAAS,QAAO,QAAQA,GAAE,IAAI,SAASA,GAAE;AAClD;AAKA,SAAS,OACPA,KACA,OACA,GACA,MACa;AACb,QAAM,WAAW,SAAS,IAAI;AAC9B,SAAO,GAAG,KAAK,MAAMA,MAAK,CAAC,CAAC,IAAI,IAAI,GAAG,WAAW,MAAM,EAAE;AAC5D;","names":["ms"]}
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
2
|
import { TernSecureAuth, TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState } from '@tern-secure/types';
|
|
3
|
+
import { dequal } from 'dequal';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import react__default from 'react';
|
|
5
6
|
|
|
@@ -8,6 +9,23 @@ import react__default from 'react';
|
|
|
8
9
|
*/
|
|
9
10
|
declare const useTernSecure: () => TernSecureAuth;
|
|
10
11
|
|
|
12
|
+
type UseMemoFactory<T> = () => T;
|
|
13
|
+
type UseMemoDependencyArray = Exclude<Parameters<typeof react__default.useMemo>[1], 'undefined'>;
|
|
14
|
+
type UseDeepEqualMemo = <T>(factory: UseMemoFactory<T>, dependencyArray: UseMemoDependencyArray) => T;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare const useDeepEqualMemo: UseDeepEqualMemo;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
declare const isDeeplyEqual: typeof dequal;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const useSafeLayoutEffect: typeof react__default.useLayoutEffect;
|
|
28
|
+
|
|
11
29
|
type TernSecureAuthContextType = {
|
|
12
30
|
authProvider: TernSecureAuthProvider | null | undefined;
|
|
13
31
|
authState: TernSecureState;
|
|
@@ -60,4 +78,4 @@ declare const TernSecureAuthCtx: react.Context<{
|
|
|
60
78
|
declare const useTernSecureAuthCtx: () => TernSecureAuth;
|
|
61
79
|
declare function useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void;
|
|
62
80
|
|
|
63
|
-
export { SessionContext, TernSecureAuthContext, TernSecureAuthCtx, TernSecureInstanceContext, UserContext, assertContextExists, createContextAndHook, useAssertWrappedByTernSecureAuthProvider, useAssertWrappedByTernSecureProvider, useSessionContext, useTernSecure, useTernSecureAuthContext, useTernSecureAuthCtx, useTernSecureInstanceContext, useUserContext };
|
|
81
|
+
export { SessionContext, TernSecureAuthContext, TernSecureAuthCtx, TernSecureInstanceContext, UserContext, assertContextExists, createContextAndHook, isDeeplyEqual, useAssertWrappedByTernSecureAuthProvider, useAssertWrappedByTernSecureProvider, useDeepEqualMemo, useSafeLayoutEffect, useSessionContext, useTernSecure, useTernSecureAuthContext, useTernSecureAuthCtx, useTernSecureInstanceContext, useUserContext };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
2
|
import { TernSecureAuth, TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState } from '@tern-secure/types';
|
|
3
|
+
import { dequal } from 'dequal';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import react__default from 'react';
|
|
5
6
|
|
|
@@ -8,6 +9,23 @@ import react__default from 'react';
|
|
|
8
9
|
*/
|
|
9
10
|
declare const useTernSecure: () => TernSecureAuth;
|
|
10
11
|
|
|
12
|
+
type UseMemoFactory<T> = () => T;
|
|
13
|
+
type UseMemoDependencyArray = Exclude<Parameters<typeof react__default.useMemo>[1], 'undefined'>;
|
|
14
|
+
type UseDeepEqualMemo = <T>(factory: UseMemoFactory<T>, dependencyArray: UseMemoDependencyArray) => T;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare const useDeepEqualMemo: UseDeepEqualMemo;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
declare const isDeeplyEqual: typeof dequal;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
declare const useSafeLayoutEffect: typeof react__default.useLayoutEffect;
|
|
28
|
+
|
|
11
29
|
type TernSecureAuthContextType = {
|
|
12
30
|
authProvider: TernSecureAuthProvider | null | undefined;
|
|
13
31
|
authState: TernSecureState;
|
|
@@ -60,4 +78,4 @@ declare const TernSecureAuthCtx: react.Context<{
|
|
|
60
78
|
declare const useTernSecureAuthCtx: () => TernSecureAuth;
|
|
61
79
|
declare function useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void;
|
|
62
80
|
|
|
63
|
-
export { SessionContext, TernSecureAuthContext, TernSecureAuthCtx, TernSecureInstanceContext, UserContext, assertContextExists, createContextAndHook, useAssertWrappedByTernSecureAuthProvider, useAssertWrappedByTernSecureProvider, useSessionContext, useTernSecure, useTernSecureAuthContext, useTernSecureAuthCtx, useTernSecureInstanceContext, useUserContext };
|
|
81
|
+
export { SessionContext, TernSecureAuthContext, TernSecureAuthCtx, TernSecureInstanceContext, UserContext, assertContextExists, createContextAndHook, isDeeplyEqual, useAssertWrappedByTernSecureAuthProvider, useAssertWrappedByTernSecureProvider, useDeepEqualMemo, useSafeLayoutEffect, useSessionContext, useTernSecure, useTernSecureAuthContext, useTernSecureAuthCtx, useTernSecureInstanceContext, useUserContext };
|
package/dist/react/index.js
CHANGED
|
@@ -37,8 +37,11 @@ __export(react_exports, {
|
|
|
37
37
|
UserContext: () => UserContext,
|
|
38
38
|
assertContextExists: () => assertContextExists,
|
|
39
39
|
createContextAndHook: () => createContextAndHook,
|
|
40
|
+
isDeeplyEqual: () => isDeeplyEqual,
|
|
40
41
|
useAssertWrappedByTernSecureAuthProvider: () => useAssertWrappedByTernSecureAuthProvider,
|
|
41
42
|
useAssertWrappedByTernSecureProvider: () => useAssertWrappedByTernSecureProvider,
|
|
43
|
+
useDeepEqualMemo: () => useDeepEqualMemo,
|
|
44
|
+
useSafeLayoutEffect: () => useSafeLayoutEffect,
|
|
42
45
|
useSessionContext: () => useSessionContext,
|
|
43
46
|
useTernSecure: () => useTernSecure,
|
|
44
47
|
useTernSecureAuthContext: () => useTernSecureAuthContext,
|
|
@@ -93,7 +96,7 @@ Possible fixes:
|
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
// src/react/
|
|
99
|
+
// src/react/ternsecureProvider.tsx
|
|
97
100
|
var import_react3 = require("react");
|
|
98
101
|
var [TernSecureInstanceContext, useTernSecureInstanceContext] = createContextAndHook("TernSecureInstanceContext");
|
|
99
102
|
var [TernSecureAuthContext, useTernSecureAuthContext] = createContextAndHook("TernSecureAuthContext");
|
|
@@ -121,6 +124,25 @@ var useTernSecure = () => {
|
|
|
121
124
|
useAssertWrappedByTernSecureAuthProvider("useTernSecure");
|
|
122
125
|
return useTernSecureAuthCtx();
|
|
123
126
|
};
|
|
127
|
+
|
|
128
|
+
// src/react/hooks/useDeepEqualMemo.ts
|
|
129
|
+
var import_dequal = require("dequal");
|
|
130
|
+
var import_react4 = __toESM(require("react"));
|
|
131
|
+
var useDeepEqualMemoize = (value) => {
|
|
132
|
+
const ref = import_react4.default.useRef(value);
|
|
133
|
+
if (!(0, import_dequal.dequal)(value, ref.current)) {
|
|
134
|
+
ref.current = value;
|
|
135
|
+
}
|
|
136
|
+
return import_react4.default.useMemo(() => ref.current, [ref.current]);
|
|
137
|
+
};
|
|
138
|
+
var useDeepEqualMemo = (factory, dependencyArray) => {
|
|
139
|
+
return import_react4.default.useMemo(factory, useDeepEqualMemoize(dependencyArray));
|
|
140
|
+
};
|
|
141
|
+
var isDeeplyEqual = import_dequal.dequal;
|
|
142
|
+
|
|
143
|
+
// src/react/hooks/useSafeLayoutEffect.tsx
|
|
144
|
+
var import_react5 = __toESM(require("react"));
|
|
145
|
+
var useSafeLayoutEffect = typeof window !== "undefined" ? import_react5.default.useLayoutEffect : import_react5.default.useEffect;
|
|
124
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
147
|
0 && (module.exports = {
|
|
126
148
|
SessionContext,
|
|
@@ -130,8 +152,11 @@ var useTernSecure = () => {
|
|
|
130
152
|
UserContext,
|
|
131
153
|
assertContextExists,
|
|
132
154
|
createContextAndHook,
|
|
155
|
+
isDeeplyEqual,
|
|
133
156
|
useAssertWrappedByTernSecureAuthProvider,
|
|
134
157
|
useAssertWrappedByTernSecureProvider,
|
|
158
|
+
useDeepEqualMemo,
|
|
159
|
+
useSafeLayoutEffect,
|
|
135
160
|
useSessionContext,
|
|
136
161
|
useTernSecure,
|
|
137
162
|
useTernSecureAuthContext,
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/index.ts","../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/ternSecureProvider.tsx","../../src/react/hooks/useTernSecure.ts"],"sourcesContent":["export * from './hooks'\n\nexport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n SessionContext,\n UserContext,\n TernSecureAuthContext,\n TernSecureInstanceContext\n} from './ternSecureProvider'\n\nexport {\n assertContextExists,\n createContextAndHook\n} from './ternsecureCtx'\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider\n} from './ternSecureAuthProvider'","'use client'\n\nimport type { \n TernSecureAuth,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\n\nconst [TernSecureAuthCtx, useTernSecureAuthCtx] =\n createContextAndHook<TernSecureAuth>('TernSecureAuthCtx');\n\nfunction useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureAuthCtx);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n \n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider,\n};","'use client'\n\nimport React from 'react';\n\n/**\n * Assert that the context value exists, otherwise throw an error.\n *\n * @internal\n */\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextAndHook<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Create and return a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n *\n * The first hook returned guarantees that the context exists so the returned value is always `CtxValue`\n * The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`\n *\n * @internal\n */\n\nexport const createContextAndHook = <CtxValue>(\n displayName: string,\n options?: Options,\n): [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxValue } | undefined >(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `${displayName} not found`);\n return (ctx as any).value as CtxValue;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n return ctx ? ctx.value : {}\n };\n\n /**\n * Assert that the context value exists, otherwise throw an error.\n if (ctx === undefined) {\n throw new Error(`use${name} must be used within a ${name}Provider`);\n }\n return ctx.value;\n */\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n}","'use client'\n\nimport type { \n TernSecureAuthProvider,\n TernSecureInstanceTree,\n TernSecureState,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nexport type TernSecureAuthContextType = {\n authProvider: TernSecureAuthProvider | null | undefined;\n authState: TernSecureState;\n}\n\n\n// Create TernSecure instance context\nconst [TernSecureInstanceContext, useTernSecureInstanceContext] = \n createContextAndHook<TernSecureInstanceTree>('TernSecureInstanceContext');\n\nconst [TernSecureAuthContext, useTernSecureAuthContext] =\n createContextAndHook<TernSecureAuthContextType>('TernSecureAuthContext');\n\nconst [SessionContext, useSessionContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['session']>('SessionContext');\n\nconst [UserContext, useUserContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['user']>('UserContext');\n\n// Assert helper\nfunction useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureInstanceContext);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\nexport {\n TernSecureInstanceContext,\n TernSecureAuthContext,\n SessionContext,\n UserContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n useTernSecureInstanceContext,\n useAssertWrappedByTernSecureProvider\n};","import type { TernSecureAuth, TernSecureInstanceTree } from '@tern-secure/types';\n\nimport {\n useAssertWrappedByTernSecureAuthProvider,\n useTernSecureAuthCtx,\n} from '../ternSecureAuthProvider';\nimport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n} from '../ternSecureProvider';\n\n/**\n * @deprecated this was a previous version with cdn. now since in this package we dont use cdn, create a new hook that uuses TernSecureAuth and rename this to useTernSecure_Deprecated\n *\n */\nexport const useTernSecure_Deprecated = (): TernSecureInstanceTree => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureProvider('useTernSecure');\n return useTernSecureInstanceContext();\n};\n\n\n/**\n * New hook that uses TernSecureAuth\n */\nexport const useTernSecure = (): TernSecureAuth => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureAuthProvider('useTernSecure');\n return useTernSecureAuthCtx();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAAA,gBAA2B;;;ACH3B,mBAAkB;AAOX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAeO,IAAM,uBAAuB,CAClC,aACA,YAC2F;AAC3F,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,aAAAC,QAAM,cAAgD,MAAS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
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/ternsecureProvider.tsx","../../src/react/hooks/useTernSecure.ts","../../src/react/hooks/useDeepEqualMemo.ts","../../src/react/hooks/useSafeLayoutEffect.tsx"],"sourcesContent":["export * from './hooks'\n\nexport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n SessionContext,\n UserContext,\n TernSecureAuthContext,\n TernSecureInstanceContext\n} from './ternsecureProvider'\n\nexport {\n assertContextExists,\n createContextAndHook\n} from './ternsecureCtx'\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider\n} from './ternSecureAuthProvider'","'use client';\n\nimport type { TernSecureAuth } from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nconst [TernSecureAuthCtx, useTernSecureAuthCtx] =\n createContextAndHook<TernSecureAuth>('TernSecureAuthCtx');\n\nfunction useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureAuthCtx);\n\n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`,\n );\n }\n}\n\nexport { TernSecureAuthCtx, useTernSecureAuthCtx, useAssertWrappedByTernSecureAuthProvider };\n","'use client'\n\nimport React from 'react';\n\n/**\n * Assert that the context value exists, otherwise throw an error.\n *\n * @internal\n */\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextAndHook<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Create and return a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n *\n * The first hook returned guarantees that the context exists so the returned value is always `CtxValue`\n * The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`\n *\n * @internal\n */\n\nexport const createContextAndHook = <CtxValue>(\n displayName: string,\n options?: Options,\n): [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxValue } | undefined >(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `${displayName} not found`);\n return (ctx as any).value as CtxValue;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n return ctx ? ctx.value : {}\n };\n\n /**\n * Assert that the context value exists, otherwise throw an error.\n if (ctx === undefined) {\n throw new Error(`use${name} must be used within a ${name}Provider`);\n }\n return ctx.value;\n */\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n}","'use client'\n\nimport type { \n TernSecureAuthProvider,\n TernSecureInstanceTree,\n TernSecureState,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nexport type TernSecureAuthContextType = {\n authProvider: TernSecureAuthProvider | null | undefined;\n authState: TernSecureState;\n}\n\n\n// Create TernSecure instance context\nconst [TernSecureInstanceContext, useTernSecureInstanceContext] = \n createContextAndHook<TernSecureInstanceTree>('TernSecureInstanceContext');\n\nconst [TernSecureAuthContext, useTernSecureAuthContext] =\n createContextAndHook<TernSecureAuthContextType>('TernSecureAuthContext');\n\nconst [SessionContext, useSessionContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['session']>('SessionContext');\n\nconst [UserContext, useUserContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['user']>('UserContext');\n\n// Assert helper\nfunction useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureInstanceContext);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\nexport {\n TernSecureInstanceContext,\n TernSecureAuthContext,\n SessionContext,\n UserContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n useTernSecureInstanceContext,\n useAssertWrappedByTernSecureProvider\n};","import type { TernSecureAuth, TernSecureInstanceTree } from '@tern-secure/types';\n\nimport {\n useAssertWrappedByTernSecureAuthProvider,\n useTernSecureAuthCtx,\n} from '../ternSecureAuthProvider';\nimport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n} from '../ternsecureProvider';\n\n/**\n * @deprecated this was a previous version with cdn. now since in this package we dont use cdn, create a new hook that uuses TernSecureAuth and rename this to useTernSecure_Deprecated\n *\n */\nexport const useTernSecure_Deprecated = (): TernSecureInstanceTree => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureProvider('useTernSecure');\n return useTernSecureInstanceContext();\n};\n\n\n/**\n * New hook that uses TernSecureAuth\n */\nexport const useTernSecure = (): TernSecureAuth => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureAuthProvider('useTernSecure');\n return useTernSecureAuthCtx();\n};\n","import { dequal as deepEqual } from 'dequal';\nimport React from 'react';\n\ntype UseMemoFactory<T> = () => T;\ntype UseMemoDependencyArray = Exclude<Parameters<typeof React.useMemo>[1], 'undefined'>;\ntype UseDeepEqualMemo = <T>(factory: UseMemoFactory<T>, dependencyArray: UseMemoDependencyArray) => T;\n\nconst useDeepEqualMemoize = <T>(value: T) => {\n const ref = React.useRef<T>(value);\n if (!deepEqual(value, ref.current)) {\n ref.current = value;\n }\n return React.useMemo(() => ref.current, [ref.current]);\n};\n\n/**\n * @internal\n */\nexport const useDeepEqualMemo: UseDeepEqualMemo = (factory, dependencyArray) => {\n return React.useMemo(factory, useDeepEqualMemoize(dependencyArray));\n};\n\n/**\n * @internal\n */\nexport const isDeeplyEqual = deepEqual;\n","import React from 'react';\n\n/**\n * @internal\n */\nexport const useSafeLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAAA,gBAA2B;;;ACD3B,mBAAkB;AAOX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAeO,IAAM,uBAAuB,CAClC,aACA,YAC2F;AAC3F,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,aAAAC,QAAM,cAAgD,MAAS;AAC3E,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,aAAAA,QAAM,WAAW,GAAG;AAChC,gBAAY,KAAK,GAAG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AAC,cAAAC,QAAU,OAAO,IAAI,OAAO,GAAG;AAClC,QAAI,UAAU;AAAA,EAChB;AACA,SAAO,cAAAD,QAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,IAAI,OAAO,CAAC;AACvD;AAKO,IAAM,mBAAqC,CAAC,SAAS,oBAAoB;AAC9E,SAAO,cAAAA,QAAM,QAAQ,SAAS,oBAAoB,eAAe,CAAC;AACpE;AAKO,IAAM,gBAAgB,cAAAC;;;ACzB7B,IAAAC,gBAAkB;AAKX,IAAM,sBAAsB,OAAO,WAAW,cAAc,cAAAC,QAAM,kBAAkB,cAAAA,QAAM;","names":["import_react","React","import_react","import_react","React","deepEqual","import_react","React"]}
|
package/dist/react/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ Possible fixes:
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// src/react/
|
|
46
|
+
// src/react/ternsecureProvider.tsx
|
|
47
47
|
import { useContext as useContext2 } from "react";
|
|
48
48
|
var [TernSecureInstanceContext, useTernSecureInstanceContext] = createContextAndHook("TernSecureInstanceContext");
|
|
49
49
|
var [TernSecureAuthContext, useTernSecureAuthContext] = createContextAndHook("TernSecureAuthContext");
|
|
@@ -71,6 +71,25 @@ var useTernSecure = () => {
|
|
|
71
71
|
useAssertWrappedByTernSecureAuthProvider("useTernSecure");
|
|
72
72
|
return useTernSecureAuthCtx();
|
|
73
73
|
};
|
|
74
|
+
|
|
75
|
+
// src/react/hooks/useDeepEqualMemo.ts
|
|
76
|
+
import { dequal as deepEqual } from "dequal";
|
|
77
|
+
import React2 from "react";
|
|
78
|
+
var useDeepEqualMemoize = (value) => {
|
|
79
|
+
const ref = React2.useRef(value);
|
|
80
|
+
if (!deepEqual(value, ref.current)) {
|
|
81
|
+
ref.current = value;
|
|
82
|
+
}
|
|
83
|
+
return React2.useMemo(() => ref.current, [ref.current]);
|
|
84
|
+
};
|
|
85
|
+
var useDeepEqualMemo = (factory, dependencyArray) => {
|
|
86
|
+
return React2.useMemo(factory, useDeepEqualMemoize(dependencyArray));
|
|
87
|
+
};
|
|
88
|
+
var isDeeplyEqual = deepEqual;
|
|
89
|
+
|
|
90
|
+
// src/react/hooks/useSafeLayoutEffect.tsx
|
|
91
|
+
import React3 from "react";
|
|
92
|
+
var useSafeLayoutEffect = typeof window !== "undefined" ? React3.useLayoutEffect : React3.useEffect;
|
|
74
93
|
export {
|
|
75
94
|
SessionContext,
|
|
76
95
|
TernSecureAuthContext,
|
|
@@ -79,8 +98,11 @@ export {
|
|
|
79
98
|
UserContext,
|
|
80
99
|
assertContextExists,
|
|
81
100
|
createContextAndHook,
|
|
101
|
+
isDeeplyEqual,
|
|
82
102
|
useAssertWrappedByTernSecureAuthProvider,
|
|
83
103
|
useAssertWrappedByTernSecureProvider,
|
|
104
|
+
useDeepEqualMemo,
|
|
105
|
+
useSafeLayoutEffect,
|
|
84
106
|
useSessionContext,
|
|
85
107
|
useTernSecure,
|
|
86
108
|
useTernSecureAuthContext,
|
package/dist/react/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/
|
|
1
|
+
{"version":3,"sources":["../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/ternsecureProvider.tsx","../../src/react/hooks/useTernSecure.ts","../../src/react/hooks/useDeepEqualMemo.ts","../../src/react/hooks/useSafeLayoutEffect.tsx"],"sourcesContent":["'use client';\n\nimport type { TernSecureAuth } from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nconst [TernSecureAuthCtx, useTernSecureAuthCtx] =\n createContextAndHook<TernSecureAuth>('TernSecureAuthCtx');\n\nfunction useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureAuthCtx);\n\n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`,\n );\n }\n}\n\nexport { TernSecureAuthCtx, useTernSecureAuthCtx, useAssertWrappedByTernSecureAuthProvider };\n","'use client'\n\nimport React from 'react';\n\n/**\n * Assert that the context value exists, otherwise throw an error.\n *\n * @internal\n */\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextAndHook<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Create and return a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n *\n * The first hook returned guarantees that the context exists so the returned value is always `CtxValue`\n * The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`\n *\n * @internal\n */\n\nexport const createContextAndHook = <CtxValue>(\n displayName: string,\n options?: Options,\n): [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxValue } | undefined >(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `${displayName} not found`);\n return (ctx as any).value as CtxValue;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n return ctx ? ctx.value : {}\n };\n\n /**\n * Assert that the context value exists, otherwise throw an error.\n if (ctx === undefined) {\n throw new Error(`use${name} must be used within a ${name}Provider`);\n }\n return ctx.value;\n */\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n}","'use client'\n\nimport type { \n TernSecureAuthProvider,\n TernSecureInstanceTree,\n TernSecureState,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nexport type TernSecureAuthContextType = {\n authProvider: TernSecureAuthProvider | null | undefined;\n authState: TernSecureState;\n}\n\n\n// Create TernSecure instance context\nconst [TernSecureInstanceContext, useTernSecureInstanceContext] = \n createContextAndHook<TernSecureInstanceTree>('TernSecureInstanceContext');\n\nconst [TernSecureAuthContext, useTernSecureAuthContext] =\n createContextAndHook<TernSecureAuthContextType>('TernSecureAuthContext');\n\nconst [SessionContext, useSessionContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['session']>('SessionContext');\n\nconst [UserContext, useUserContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['user']>('UserContext');\n\n// Assert helper\nfunction useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureInstanceContext);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\nexport {\n TernSecureInstanceContext,\n TernSecureAuthContext,\n SessionContext,\n UserContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n useTernSecureInstanceContext,\n useAssertWrappedByTernSecureProvider\n};","import type { TernSecureAuth, TernSecureInstanceTree } from '@tern-secure/types';\n\nimport {\n useAssertWrappedByTernSecureAuthProvider,\n useTernSecureAuthCtx,\n} from '../ternSecureAuthProvider';\nimport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n} from '../ternsecureProvider';\n\n/**\n * @deprecated this was a previous version with cdn. now since in this package we dont use cdn, create a new hook that uuses TernSecureAuth and rename this to useTernSecure_Deprecated\n *\n */\nexport const useTernSecure_Deprecated = (): TernSecureInstanceTree => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureProvider('useTernSecure');\n return useTernSecureInstanceContext();\n};\n\n\n/**\n * New hook that uses TernSecureAuth\n */\nexport const useTernSecure = (): TernSecureAuth => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureAuthProvider('useTernSecure');\n return useTernSecureAuthCtx();\n};\n","import { dequal as deepEqual } from 'dequal';\nimport React from 'react';\n\ntype UseMemoFactory<T> = () => T;\ntype UseMemoDependencyArray = Exclude<Parameters<typeof React.useMemo>[1], 'undefined'>;\ntype UseDeepEqualMemo = <T>(factory: UseMemoFactory<T>, dependencyArray: UseMemoDependencyArray) => T;\n\nconst useDeepEqualMemoize = <T>(value: T) => {\n const ref = React.useRef<T>(value);\n if (!deepEqual(value, ref.current)) {\n ref.current = value;\n }\n return React.useMemo(() => ref.current, [ref.current]);\n};\n\n/**\n * @internal\n */\nexport const useDeepEqualMemo: UseDeepEqualMemo = (factory, dependencyArray) => {\n return React.useMemo(factory, useDeepEqualMemoize(dependencyArray));\n};\n\n/**\n * @internal\n */\nexport const isDeeplyEqual = deepEqual;\n","import React from 'react';\n\n/**\n * @internal\n */\nexport const useSafeLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n"],"mappings":";AAGA,SAAS,kBAAkB;;;ACD3B,OAAO,WAAW;AAOX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;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