@inferencebureau/apps-sdk 0.16.9 → 0.16.11

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/index.d.ts CHANGED
@@ -236,6 +236,64 @@ export interface ShopifyInstallSettings {
236
236
  * compare product bundles and their discounts". Required once an extension defines tools (at most 256 tokens).
237
237
  */
238
238
  sidekickSummary?: string;
239
+ /**
240
+ * The app's own metafield definitions, by owner (`product`, `variant`, `collection`, `customer`, `order`, `shop`, …)
241
+ * and key, in the `$app` namespace. Released to every store the app is on.
242
+ */
243
+ metafields?: Record<string, Record<string, ShopifyMetafieldDefinition>>;
244
+ /** The app's own metaobject definitions, by type (`$app:<type>` in references). Released to every store the app is on. */
245
+ metaobjects?: Record<string, ShopifyMetaobjectDefinition>;
246
+ }
247
+ /** Shopify's validation names and values, e.g. `{ min: "1", max: "5" }` or `{ choices: ["S", "M", "L"] }`. */
248
+ export type ShopifyValidations = Record<string, string | number | boolean | string[]>;
249
+ export interface ShopifyMetafieldDefinition {
250
+ /** A metafield type, e.g. `single_line_text_field`, `rating` or `metaobject_reference<$app:review>`. Can't change later. */
251
+ type: string;
252
+ /** The name the admin shows; the key when left out. */
253
+ name?: string;
254
+ description?: string;
255
+ validations?: ShopifyValidations;
256
+ access?: {
257
+ admin?: "merchant_read" | "merchant_read_write";
258
+ storefront?: "none" | "public_read";
259
+ customerAccount?: "none" | "read" | "read_write";
260
+ };
261
+ capabilities?: {
262
+ adminFilterable?: boolean;
263
+ uniqueValues?: boolean;
264
+ analyticsQueryable?: boolean;
265
+ cartToOrderCopyable?: boolean;
266
+ };
267
+ }
268
+ export interface ShopifyMetaobjectField {
269
+ type: string;
270
+ name?: string;
271
+ description?: string;
272
+ required?: boolean;
273
+ validations?: ShopifyValidations;
274
+ capabilities?: {
275
+ adminFilterable?: boolean;
276
+ };
277
+ }
278
+ export interface ShopifyMetaobjectDefinition {
279
+ /** The name the admin shows; the type when left out. */
280
+ name?: string;
281
+ description?: string;
282
+ /** The field whose value names an entry in the admin. */
283
+ displayNameField?: string;
284
+ /** Each field by key: its type, or the type with more. */
285
+ fields: Record<string, string | ShopifyMetaobjectField>;
286
+ access?: {
287
+ admin?: "merchant_read" | "merchant_read_write";
288
+ storefront?: "none" | "public_read";
289
+ };
290
+ capabilities?: {
291
+ publishable?: boolean;
292
+ translatable?: boolean;
293
+ renderable?: boolean;
294
+ renderableMetaTitleField?: string;
295
+ renderableMetaDescriptionField?: string;
296
+ };
239
297
  }
240
298
  export interface WebhookSetting {
241
299
  /** A Shopify webhook topic, e.g. orders/create. The app's scopes must allow it. */
@@ -1864,6 +1922,28 @@ export declare function parseDsn(dsn: string): {
1864
1922
  * take it. Never throws, and gives up after three seconds.
1865
1923
  */
1866
1924
  export declare function captureException(error: unknown, o?: CaptureOptions): Promise<string | null>;
1925
+ /** What Next.js passes onRequestError (instrumentation.ts), as far as the report reads it. */
1926
+ export interface RequestErrorRequest {
1927
+ path: string;
1928
+ method: string;
1929
+ headers: Record<string, string | string[] | undefined>;
1930
+ }
1931
+ export interface RequestErrorContext {
1932
+ routerKind?: string;
1933
+ routePath?: string;
1934
+ routeType?: string;
1935
+ }
1936
+ export interface ReportRequestErrorOptions {
1937
+ url?: string;
1938
+ token?: string;
1939
+ app?: string;
1940
+ environment?: string;
1941
+ fetch?: typeof fetch;
1942
+ }
1943
+ /** Reports an error the app threw handling a request to its Logs. Never throws, and gives up after three seconds. */
1944
+ export declare function reportRequestError(error: unknown, request: RequestErrorRequest, context?: RequestErrorContext, o?: ReportRequestErrorOptions): Promise<void>;
1945
+ /** Next.js's instrumentation hook: `export { onRequestError } from "@inferencebureau/apps-sdk"`. Builds add it for you. */
1946
+ export declare const onRequestError: (error: unknown, request: RequestErrorRequest, context: RequestErrorContext) => Promise<void>;
1867
1947
  export interface ShopifyPrivacyCustomer {
1868
1948
  id: number;
1869
1949
  email?: string | null;
package/dist/index.js CHANGED
@@ -1017,3 +1017,31 @@ export async function captureException(error, o = {}) {
1017
1017
  return null;
1018
1018
  }
1019
1019
  }
1020
+ /** Reports an error the app threw handling a request to its Logs. Never throws, and gives up after three seconds. */
1021
+ export async function reportRequestError(error, request, context = {}, o = {}) {
1022
+ const token = o.token ?? envVar("IB_ENVIRONMENT_TOKEN");
1023
+ const app = o.app ?? envVar("IB_APP");
1024
+ const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error));
1025
+ const id = request.headers["x-ib-request-id"];
1026
+ const digest = err.digest;
1027
+ const report = {
1028
+ requestId: typeof id === "string" ? id : null, method: request.method, path: String(request.path ?? "/").split("?")[0],
1029
+ message: err.message, name: err.name, digest: typeof digest === "string" ? digest : null,
1030
+ stack: err.stack ?? null, routerKind: context.routerKind === "Pages Router" ? "pages" : context.routerKind ? "app" : null,
1031
+ routePath: context.routePath ?? null, routeType: context.routeType ?? null,
1032
+ };
1033
+ const timeout = typeof AbortSignal.timeout === "function" ? { signal: AbortSignal.timeout(3000) } : {};
1034
+ const sends = [
1035
+ captureException(err, { handled: false, tags: { route: context.routePath, route_type: context.routeType, digest: report.digest }, ...(o.fetch ? { fetch: o.fetch } : {}) }),
1036
+ ];
1037
+ if (token && app) {
1038
+ const url = (o.url ?? envVar("IB_API_URL") ?? "https://api.inferencebureau.com").replace(/\/$/, "");
1039
+ const environment = o.environment ?? envVar("IB_ENVIRONMENT") ?? "development";
1040
+ sends.push((o.fetch ?? fetch)(`${url}/v1/apps/${encodeURIComponent(app)}/environments/${encodeURIComponent(environment)}/request-errors`, {
1041
+ method: "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, body: JSON.stringify(report), ...timeout,
1042
+ }));
1043
+ }
1044
+ await Promise.allSettled(sends);
1045
+ }
1046
+ /** Next.js's instrumentation hook: `export { onRequestError } from "@inferencebureau/apps-sdk"`. Builds add it for you. */
1047
+ export const onRequestError = (error, request, context) => reportRequestError(error, request, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencebureau/apps-sdk",
3
- "version": "0.16.9",
3
+ "version": "0.16.11",
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": [