@inferencebureau/apps-sdk 0.13.0 → 0.14.0
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/README.md +1 -2
- package/dist/index.d.ts +13 -0
- package/dist/test.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
What an Inference Bureau app's code imports: types for the metadata files (`schema.ib.ts`, `permissions.ib.ts`,
|
|
4
4
|
`settings.ib.ts`), the helpers an action's `run` uses (`applyParams`, `save`, `deleteRecord`), the records API client,
|
|
5
|
-
request checks for Shopify session tokens and app proxies, and a harness for testing actions.
|
|
6
|
-
now.
|
|
5
|
+
request checks for Shopify session tokens and app proxies, and a harness for testing actions.
|
|
7
6
|
|
|
8
7
|
```sh
|
|
9
8
|
npm install @inferencebureau/apps-sdk
|
package/dist/index.d.ts
CHANGED
|
@@ -133,8 +133,15 @@ export interface AppSettings {
|
|
|
133
133
|
shopify?: ShopifyInstallSettings;
|
|
134
134
|
/** Other sites' pages that may call the app's routes from the browser. */
|
|
135
135
|
cors?: CorsSetting;
|
|
136
|
+
/**
|
|
137
|
+
* The integrations the app's code needs set up in Settings · Integrations: Problems warns while production has
|
|
138
|
+
* no credentials for one. Inference Bureau's `ai` client is always on and needs no entry.
|
|
139
|
+
*/
|
|
140
|
+
integrations?: IntegrationSetting[];
|
|
136
141
|
[key: string]: unknown;
|
|
137
142
|
}
|
|
143
|
+
/** `resend`: the app's email through the team's own Resend account, as RESEND_API_KEY and EMAIL_FROM. */
|
|
144
|
+
export type IntegrationSetting = "resend";
|
|
138
145
|
/**
|
|
139
146
|
* Which other sites' pages may call the app's routes from the browser. Inference Bureau answers for the app: it
|
|
140
147
|
* answers preflights itself and puts the CORS headers on every response, including the page shown while a development
|
|
@@ -232,7 +239,13 @@ export interface FindManyOptions<M extends ModelTypes = UntypedModel, S extends
|
|
|
232
239
|
filter?: Filter<M["filter"]>;
|
|
233
240
|
sort?: SortOf<M> | SortOf<M>[];
|
|
234
241
|
first?: number;
|
|
242
|
+
/** The `endCursor` of the page before: the fast way to page on. */
|
|
235
243
|
after?: string | null;
|
|
244
|
+
/**
|
|
245
|
+
* Records to pass over first, after the filter and sort, for a page by number (`skip: (page - 1) * first`) or a
|
|
246
|
+
* library that asks for an offset; at most 10,000, and not with `after`. Cursors are faster for reading every page.
|
|
247
|
+
*/
|
|
248
|
+
skip?: number;
|
|
236
249
|
/** Words to find in the model's text fields: records holding every one (any case, part of a word counts), those holding the whole phrase first unless sorted. */
|
|
237
250
|
search?: string;
|
|
238
251
|
/** Which fields to read, and which related records with them (SelectOf); every field and no related records when left out. */
|
package/dist/test.js
CHANGED
|
@@ -24,6 +24,7 @@ import { runAction as runPhase } from "./runtime.js";
|
|
|
24
24
|
const STORED = new Set(["string", "richText", "email", "url", "color", "number", "dateTime", "enum", "boolean", "roleList", "json", "belongsTo", "password", "encryptedString", "file"]);
|
|
25
25
|
const SYSTEM = ["id", "createdAt", "updatedAt"];
|
|
26
26
|
const MAX_PAGE = 250;
|
|
27
|
+
const MAX_SKIP = 10_000;
|
|
27
28
|
const MAX_RECORD_BYTES = 256 * 1024;
|
|
28
29
|
const invalid = (problems) => new ApiError(problems.map((p) => `${p.field}: ${p.message}`).join("; "), 400, "invalid_request", problems);
|
|
29
30
|
/** A related filter's or sort's problems, named from the relationship: `product.vendor`. */
|
|
@@ -993,7 +994,7 @@ class Records {
|
|
|
993
994
|
const m = this.model(model);
|
|
994
995
|
const plan = this.plan(m, o.select);
|
|
995
996
|
const first = Math.min(Math.max(1, Math.floor(o.first ?? 50)), MAX_PAGE);
|
|
996
|
-
const offset =
|
|
997
|
+
const offset = startOf(o);
|
|
997
998
|
const ctx = { ...CTX, readable: o.readable };
|
|
998
999
|
let rows = [...this.table(m).values()].filter((r) => this.matches(m, r, o.filter, ctx));
|
|
999
1000
|
let distances = null;
|
|
@@ -1377,6 +1378,18 @@ function offsetOf(cursor) {
|
|
|
1377
1378
|
throw invalid([{ field: "after", message: "isn't a cursor from this API" }]);
|
|
1378
1379
|
return Number(m[1]);
|
|
1379
1380
|
}
|
|
1381
|
+
/** As the API's: `after`'s cursor or `skip`, one or the other, and `skip` at most MAX_SKIP. */
|
|
1382
|
+
function startOf(o) {
|
|
1383
|
+
if (o.skip === undefined)
|
|
1384
|
+
return offsetOf(o.after);
|
|
1385
|
+
if (o.after)
|
|
1386
|
+
throw invalid([{ field: "skip", message: "can't be given with after; use one or the other" }]);
|
|
1387
|
+
if (typeof o.skip !== "number" || !Number.isInteger(o.skip) || o.skip < 0)
|
|
1388
|
+
throw invalid([{ field: "skip", message: "must be a whole number, 0 or more" }]);
|
|
1389
|
+
if (o.skip > MAX_SKIP)
|
|
1390
|
+
throw invalid([{ field: "skip", message: `must be at most ${MAX_SKIP}; page further with after, the endCursor of the page before` }]);
|
|
1391
|
+
return o.skip;
|
|
1392
|
+
}
|
|
1380
1393
|
// ---- Shopify ----
|
|
1381
1394
|
/** The store a test app installs on and runs as, unless a test names another. */
|
|
1382
1395
|
export const TEST_SHOP = "test-shop.myshopify.com";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inferencebureau/apps-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "The SDK an Inference Bureau app's code imports: action helpers, metadata types, the records API client, React hooks with AutoTable and AutoForm, and a test harness for its actions.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"keywords": [
|