@proveanything/smartlinks 2.1.22 → 2.1.24
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 +322 -172
- package/dist/docs/admin-cards.md +1 -1
- package/dist/docs/app-docs.md +73 -0
- package/dist/docs/app-manifest.md +20 -0
- package/dist/docs/standard-query.md +187 -0
- package/dist/docs/utils.md +22 -8
- package/dist/openapi.yaml +462 -0
- package/dist/types/adminCards.d.ts +2 -1
- package/dist/types/appManifest.d.ts +29 -0
- 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 +322 -172
- package/docs/admin-cards.md +1 -1
- package/docs/app-docs.md +73 -0
- package/docs/app-manifest.md +20 -0
- package/docs/standard-query.md +187 -0
- package/docs/utils.md +22 -8
- package/openapi.yaml +462 -0
- package/package.json +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** A value a field can be compared with. Dates are ISO 8601 strings. */
|
|
2
|
+
export type QueryValue = string | number | boolean;
|
|
3
|
+
/** How one field is tested. Several tests on one field must all hold. */
|
|
4
|
+
export interface QueryFieldTest {
|
|
5
|
+
eq?: QueryValue;
|
|
6
|
+
ne?: QueryValue;
|
|
7
|
+
gt?: QueryValue;
|
|
8
|
+
gte?: QueryValue;
|
|
9
|
+
lt?: QueryValue;
|
|
10
|
+
lte?: QueryValue;
|
|
11
|
+
/** One of these values (1 to 100). */
|
|
12
|
+
in?: QueryValue[];
|
|
13
|
+
/** None of these values (1 to 100). */
|
|
14
|
+
nin?: QueryValue[];
|
|
15
|
+
/** Text containing this, in any case. */
|
|
16
|
+
contains?: string;
|
|
17
|
+
/** Text starting with this, in any case. */
|
|
18
|
+
startsWith?: string;
|
|
19
|
+
/** true: the field is empty. false: it has a value. */
|
|
20
|
+
isNull?: boolean;
|
|
21
|
+
/** A list field (e.g. a contact's tags) holds this value. */
|
|
22
|
+
has?: string;
|
|
23
|
+
/** A list field holds at least one of these. */
|
|
24
|
+
hasAny?: string[];
|
|
25
|
+
/** A list field holds all of these. */
|
|
26
|
+
hasAll?: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A keyed field (e.g. a product's `facets`) is filtered key by key: `{ brand: "Breville" }` or
|
|
30
|
+
* `{ category: { in: ["Toasters", "Kettles"] } }`. Every key must match.
|
|
31
|
+
*/
|
|
32
|
+
export type QueryKeyedTest = Record<string, QueryValue | {
|
|
33
|
+
eq?: QueryValue;
|
|
34
|
+
in?: QueryValue[];
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* What to match. Each entry is `field: value` (equal to) or `field: { op: value }`; all entries must
|
|
38
|
+
* hold. `and`, `or` and `not` combine further conditions (nested up to 4 levels).
|
|
39
|
+
*
|
|
40
|
+
* A document field (an app record's `data`) is reached by path, as a field name: `"data.status"`.
|
|
41
|
+
*/
|
|
42
|
+
export interface QueryWhere {
|
|
43
|
+
and?: QueryWhere[];
|
|
44
|
+
or?: QueryWhere[];
|
|
45
|
+
not?: QueryWhere;
|
|
46
|
+
[field: string]: QueryValue | QueryFieldTest | QueryKeyedTest | QueryWhere | QueryWhere[] | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** One total. `count` counts rows; the others take a field (or a path into a document). */
|
|
49
|
+
export type QueryAggregate = {
|
|
50
|
+
count: true;
|
|
51
|
+
} | {
|
|
52
|
+
countDistinct: string;
|
|
53
|
+
} | {
|
|
54
|
+
sum: string;
|
|
55
|
+
} | {
|
|
56
|
+
avg: string;
|
|
57
|
+
} | {
|
|
58
|
+
min: string;
|
|
59
|
+
} | {
|
|
60
|
+
max: string;
|
|
61
|
+
};
|
|
62
|
+
/** The standard query body. Everything is optional: an empty query returns the first page. */
|
|
63
|
+
export interface StandardQuery {
|
|
64
|
+
where?: QueryWhere;
|
|
65
|
+
/** e.g. `[{ createdAt: "desc" }]`. Only fields that can be sorted on (never an empty-able one). */
|
|
66
|
+
orderBy?: Array<Record<string, 'asc' | 'desc'>>;
|
|
67
|
+
/** Rows per page (1 to 200, default 50), or groups (1 to 500) with groupBy / aggregates. */
|
|
68
|
+
limit?: number;
|
|
69
|
+
/** `nextCursor` from the previous page, with the same `where` and `orderBy`. */
|
|
70
|
+
cursor?: string | null;
|
|
71
|
+
/** Which fields to return. A path into a document can be selected: `"data.status"`. */
|
|
72
|
+
select?: string[];
|
|
73
|
+
/** Also return how many rows match `where` in all (not just this page). */
|
|
74
|
+
count?: boolean;
|
|
75
|
+
/** Group rows by up to 3 fields (or document paths). Returns groups, not rows. */
|
|
76
|
+
groupBy?: string[];
|
|
77
|
+
/** Named totals, e.g. `{ owners: { countDistinct: "userId" } }`. Returns groups, not rows. */
|
|
78
|
+
aggregates?: Record<string, QueryAggregate>;
|
|
79
|
+
/**
|
|
80
|
+
* Follow a link and return the linked thing inside each row: `["product", "owner"]`, or with the
|
|
81
|
+
* fields wanted `{ owner: ["firstName", "email"] }`. Rows only. Null where there is nothing linked.
|
|
82
|
+
*/
|
|
83
|
+
expand?: string[] | Record<string, string[] | true>;
|
|
84
|
+
}
|
|
85
|
+
/** A page of rows. */
|
|
86
|
+
export interface QueryRows<T = Record<string, unknown>> {
|
|
87
|
+
items: T[];
|
|
88
|
+
/** Pass as `cursor` for the next page; null on the last page. */
|
|
89
|
+
nextCursor: string | null;
|
|
90
|
+
/** Present when the query asked for `count: true`. */
|
|
91
|
+
count?: number;
|
|
92
|
+
}
|
|
93
|
+
/** The answer to a query with `groupBy` and/or `aggregates`. */
|
|
94
|
+
export interface QueryGroups<G = Record<string, unknown>> {
|
|
95
|
+
groups: G[];
|
|
96
|
+
/** True when there were more groups than `limit`. */
|
|
97
|
+
more: boolean;
|
|
98
|
+
}
|
|
99
|
+
export type QueryResult<T = Record<string, unknown>, G = Record<string, unknown>> = QueryRows<T> | QueryGroups<G>;
|
|
100
|
+
/** What a resource's query can use (from `GET …/query`). */
|
|
101
|
+
export interface QueryDescription {
|
|
102
|
+
name: string;
|
|
103
|
+
fields: Record<string, {
|
|
104
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'list' | 'keyed' | 'json';
|
|
105
|
+
about?: string;
|
|
106
|
+
can: string[];
|
|
107
|
+
}>;
|
|
108
|
+
count: boolean;
|
|
109
|
+
aggregates: boolean;
|
|
110
|
+
links: Record<string, {
|
|
111
|
+
to: string;
|
|
112
|
+
by: string;
|
|
113
|
+
about?: string;
|
|
114
|
+
}>;
|
|
115
|
+
limits: {
|
|
116
|
+
limit: number;
|
|
117
|
+
groups: number;
|
|
118
|
+
};
|
|
119
|
+
/** The query shape in a few lines of plain words. */
|
|
120
|
+
shape: string;
|
|
121
|
+
}
|
|
@@ -296,7 +296,7 @@ export interface ConditionParams {
|
|
|
296
296
|
itemContext?: ItemContext;
|
|
297
297
|
/** Statistics/tracking information */
|
|
298
298
|
stats?: StatsInfo;
|
|
299
|
-
/**
|
|
299
|
+
/** Load a saved condition by id (optional; by default the collection's saved conditions are read with `conditions.get`) */
|
|
300
300
|
fetchCondition?: (collectionId: string, conditionId: string) => Promise<ConditionSet | null>;
|
|
301
301
|
/** Function to get user's current location (optional) */
|
|
302
302
|
getLocation?: () => Promise<{
|
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.', {
|