@proveanything/smartlinks 2.1.22 → 2.1.23
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/adminCardsView.d.ts +1 -1
- package/dist/adminCardsView.js +70 -55
- package/dist/api/appObjects.d.ts +26 -0
- package/dist/api/appObjects.js +31 -1
- package/dist/api/conditions.d.ts +51 -0
- package/dist/api/conditions.js +57 -0
- package/dist/api/contact.d.ts +23 -0
- package/dist/api/contact.js +30 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/products.d.ts +22 -0
- package/dist/api/products.js +29 -0
- package/dist/api/proof.d.ts +30 -0
- package/dist/api/proof.js +37 -0
- package/dist/docs/API_SUMMARY.md +301 -172
- package/dist/docs/admin-cards.md +1 -1
- package/dist/docs/standard-query.md +187 -0
- package/dist/docs/utils.md +22 -8
- package/dist/openapi.yaml +428 -0
- package/dist/types/adminCards.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/query.d.ts +121 -0
- package/dist/types/query.js +5 -0
- package/dist/utils/conditions.d.ts +1 -1
- package/dist/utils/conditions.js +21 -6
- package/docs/API_SUMMARY.md +301 -172
- package/docs/admin-cards.md +1 -1
- package/docs/standard-query.md +187 -0
- package/docs/utils.md +22 -8
- package/openapi.yaml +428 -0
- package/package.json +1 -1
package/dist/utils/conditions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/utils/conditions.ts
|
|
2
|
+
import { request } from '../http.js';
|
|
2
3
|
/**
|
|
3
4
|
* Geographic region definitions for country-based conditions
|
|
4
5
|
*/
|
|
@@ -16,6 +17,15 @@ export const REGION_COUNTRIES = {
|
|
|
16
17
|
};
|
|
17
18
|
// Condition cache
|
|
18
19
|
const conditionCache = {};
|
|
20
|
+
/** The default loader: a collection's saved condition, from the public API; null when there isn't one. */
|
|
21
|
+
async function fetchSavedCondition(collectionId, conditionId) {
|
|
22
|
+
try {
|
|
23
|
+
return await request(`/public/collection/${encodeURIComponent(collectionId)}/condition/${encodeURIComponent(conditionId)}`);
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
19
29
|
const CONDITION_DEBUG_GLOBAL_KEY = 'SMARTLINKS_CONDITION_DEBUG';
|
|
20
30
|
function defaultConditionDebugLogger(...args) {
|
|
21
31
|
if (typeof console === 'undefined')
|
|
@@ -227,7 +237,7 @@ async function evaluateConditionEntry(condition, params) {
|
|
|
227
237
|
* ```
|
|
228
238
|
*/
|
|
229
239
|
export async function validateCondition(params) {
|
|
230
|
-
var _a, _b, _c;
|
|
240
|
+
var _a, _b, _c, _d;
|
|
231
241
|
const internalParams = params;
|
|
232
242
|
(_a = internalParams.__conditionDebugState) !== null && _a !== void 0 ? _a : (internalParams.__conditionDebugState = resolveConditionDebugState(params));
|
|
233
243
|
const debugState = internalParams.__conditionDebugState;
|
|
@@ -242,9 +252,9 @@ export async function validateCondition(params) {
|
|
|
242
252
|
// Check cache first
|
|
243
253
|
if (!conditionCache[params.conditionId]) {
|
|
244
254
|
logConditionDebug(debugState, 'Condition cache miss.', { conditionId: params.conditionId });
|
|
245
|
-
//
|
|
246
|
-
if (params.
|
|
247
|
-
const fetchedCond = await params.fetchCondition(params.collection.id, params.conditionId);
|
|
255
|
+
// Fetch it: the caller's own loader, else the collection's saved conditions
|
|
256
|
+
if (params.collection) {
|
|
257
|
+
const fetchedCond = await ((_b = params.fetchCondition) !== null && _b !== void 0 ? _b : fetchSavedCondition)(params.collection.id, params.conditionId);
|
|
248
258
|
if (fetchedCond) {
|
|
249
259
|
conditionCache[params.conditionId] = fetchedCond;
|
|
250
260
|
logConditionDebug(debugState, 'Fetched condition into cache.', {
|
|
@@ -259,7 +269,7 @@ export async function validateCondition(params) {
|
|
|
259
269
|
return true;
|
|
260
270
|
}
|
|
261
271
|
// Prevent infinite recursion
|
|
262
|
-
(
|
|
272
|
+
(_c = params.conditionStack) !== null && _c !== void 0 ? _c : (params.conditionStack = []);
|
|
263
273
|
params.conditionStack.push(params.conditionId);
|
|
264
274
|
cond = conditionCache[params.conditionId];
|
|
265
275
|
}
|
|
@@ -268,12 +278,17 @@ export async function validateCondition(params) {
|
|
|
268
278
|
conditionSet: cond ? summarizeConditionSet(cond) : 'none',
|
|
269
279
|
});
|
|
270
280
|
}
|
|
281
|
+
// A switched-off condition passes for everyone
|
|
282
|
+
if (cond === null || cond === void 0 ? void 0 : cond.disabled) {
|
|
283
|
+
logConditionDebug(debugState, 'Condition is switched off; passing.');
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
271
286
|
if (!cond) {
|
|
272
287
|
logConditionDebug(debugState, 'Resolved condition set is empty; passing by default.');
|
|
273
288
|
return true;
|
|
274
289
|
}
|
|
275
290
|
// Default to AND logic
|
|
276
|
-
const conditionType = (
|
|
291
|
+
const conditionType = (_d = cond.type) !== null && _d !== void 0 ? _d : 'and';
|
|
277
292
|
// Empty condition set passes
|
|
278
293
|
if (!cond.conditions || cond.conditions.length === 0) {
|
|
279
294
|
logConditionDebug(debugState, 'Condition set has no entries; passing by default.', {
|