@inferencebureau/apps-sdk 0.16.10 → 0.16.12

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. */
package/dist/runtime.d.ts CHANGED
@@ -53,11 +53,12 @@ export type ActionResponse = ({
53
53
  } & Traced);
54
54
  /**
55
55
  * One call the action made while it ran, for its trace in Logs: what it was, when it started (ms into the phase) and
56
- * how long it took to answer. Calls to Inference Bureau are named by what they did (a record read, a Shopify query);
57
- * anything else is an outbound `fetch`, named by its method, host and path (never its query string).
56
+ * how long it took to answer. Calls to Inference Bureau are named by what they did (a record read, a Shopify query),
57
+ * calls to Stripe's API by their method and path; anything else is an outbound `fetch`, named by its method, host and
58
+ * path (never its query string).
58
59
  */
59
60
  export interface Span {
60
- kind: "read" | "write" | "action" | "job" | "shopify" | "ai" | "api" | "fetch";
61
+ kind: "read" | "write" | "action" | "job" | "shopify" | "ai" | "api" | "stripe" | "fetch";
61
62
  name: string;
62
63
  at: number;
63
64
  ms: number;
@@ -66,7 +67,7 @@ export interface Span {
66
67
  }
67
68
  /** The most spans a phase reports; past it they're counted, not kept. */
68
69
  export declare const MAX_SPANS = 200;
69
- /** What a call was, from where it went: the records API, Shopify, jobs and models by their route, anything else as fetch. */
70
+ /** What a call was, from where it went: the records API, Shopify, jobs and models by their route, Stripe's API, anything else as fetch. */
70
71
  export declare function spanOf(input: string | URL | Request, init?: RequestInit): Pick<Span, "kind" | "name">;
71
72
  /** The signature Inference Bureau sends: HMAC-SHA256 of `<timestamp>.<body>` with the environment's token, hex. */
72
73
  export declare function sign(token: string, timestamp: string, body: string): Promise<string>;
package/dist/runtime.js CHANGED
@@ -21,10 +21,12 @@ function bodyJson(init) {
21
21
  return {};
22
22
  }
23
23
  }
24
- /** What a call was, from where it went: the records API, Shopify, jobs and models by their route, anything else as fetch. */
24
+ /** What a call was, from where it went: the records API, Shopify, jobs and models by their route, Stripe's API, anything else as fetch. */
25
25
  export function spanOf(input, init) {
26
26
  const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
27
27
  const method = (init?.method ?? (typeof input === "object" && "method" in input ? input.method : "GET")).toUpperCase();
28
+ if (url.host === "api.stripe.com")
29
+ return { kind: "stripe", name: `${method} ${url.pathname.replace(/^\/v1\//, "")}` };
28
30
  const m = IB_PATH.exec(url.pathname);
29
31
  if (!m)
30
32
  return { kind: "fetch", name: `${method} ${url.host}${url.pathname}` };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The app's own Stripe account (Settings · Integrations · Stripe): `stripe()` is Stripe's Node client bound to the
3
+ * environment's STRIPE_SECRET_KEY, a sandbox key in development and the live key in production. Take payments through
4
+ * Stripe's hosted pages: create a Checkout Session (or a customer portal session) and redirect to its `url`, so the
5
+ * app never handles a card and needs no publishable key.
6
+ *
7
+ * Its calls go through `fetch`, so inside an action each one is a `stripe` call in the run's trace in Logs. It uses the
8
+ * API version of the `stripe` package the app installs (`npm install stripe`), so the types match what Stripe answers.
9
+ *
10
+ * import { stripe } from "@inferencebureau/apps-sdk/stripe";
11
+ * const session = await stripe().checkout.sessions.create({ mode: "subscription", line_items: [{ price, quantity: 1 }], success_url, cancel_url });
12
+ */
13
+ import Stripe from "stripe";
14
+ /**
15
+ * The Stripe client for the environment's key, made once per key. `apiKey` overrides STRIPE_SECRET_KEY (a connected
16
+ * account's, say). Throws when there's no key: connect Stripe in Settings → Integrations.
17
+ */
18
+ export declare function stripe(o?: {
19
+ apiKey?: string;
20
+ }): Stripe;
21
+ export type { Stripe };
package/dist/stripe.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The app's own Stripe account (Settings · Integrations · Stripe): `stripe()` is Stripe's Node client bound to the
3
+ * environment's STRIPE_SECRET_KEY, a sandbox key in development and the live key in production. Take payments through
4
+ * Stripe's hosted pages: create a Checkout Session (or a customer portal session) and redirect to its `url`, so the
5
+ * app never handles a card and needs no publishable key.
6
+ *
7
+ * Its calls go through `fetch`, so inside an action each one is a `stripe` call in the run's trace in Logs. It uses the
8
+ * API version of the `stripe` package the app installs (`npm install stripe`), so the types match what Stripe answers.
9
+ *
10
+ * import { stripe } from "@inferencebureau/apps-sdk/stripe";
11
+ * const session = await stripe().checkout.sessions.create({ mode: "subscription", line_items: [{ price, quantity: 1 }], success_url, cancel_url });
12
+ */
13
+ import Stripe from "stripe";
14
+ const envVar = (name) => globalThis.process?.env?.[name];
15
+ const clients = new Map();
16
+ /**
17
+ * The Stripe client for the environment's key, made once per key. `apiKey` overrides STRIPE_SECRET_KEY (a connected
18
+ * account's, say). Throws when there's no key: connect Stripe in Settings → Integrations.
19
+ */
20
+ export function stripe(o = {}) {
21
+ const key = o.apiKey ?? envVar("STRIPE_SECRET_KEY");
22
+ if (!key)
23
+ throw new Error("STRIPE_SECRET_KEY isn't set. Connect Stripe in Settings → Integrations, a sandbox for development and your live account for production.");
24
+ let client = clients.get(key);
25
+ if (!client) {
26
+ // The global fetch looked up at each call, not now: the action runtime wraps it to time the run's calls.
27
+ client = new Stripe(key, {
28
+ httpClient: Stripe.createFetchHttpClient(((input, init) => globalThis.fetch(input, init))),
29
+ maxNetworkRetries: 2,
30
+ appInfo: { name: "Inference Bureau Apps", url: "https://inferencebureau.com" },
31
+ });
32
+ clients.set(key, client);
33
+ }
34
+ return client;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencebureau/apps-sdk",
3
- "version": "0.16.10",
3
+ "version": "0.16.12",
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": [
@@ -48,6 +48,11 @@
48
48
  "import": "./dist/test.js",
49
49
  "default": "./dist/test.js"
50
50
  },
51
+ "./stripe": {
52
+ "types": "./dist/stripe.d.ts",
53
+ "import": "./dist/stripe.js",
54
+ "default": "./dist/stripe.js"
55
+ },
51
56
  "./package.json": "./package.json"
52
57
  },
53
58
  "main": "./dist/index.js",
@@ -75,15 +80,20 @@
75
80
  "happy-dom": "^20.14.6",
76
81
  "react": "^19.1.0",
77
82
  "react-dom": "^19.1.0",
83
+ "stripe": "^18.0.0",
78
84
  "typescript": "^5.8.0",
79
85
  "vitest": "^3.2.0"
80
86
  },
81
87
  "peerDependencies": {
82
- "react": ">=18"
88
+ "react": ">=18",
89
+ "stripe": ">=18"
83
90
  },
84
91
  "peerDependenciesMeta": {
85
92
  "react": {
86
93
  "optional": true
94
+ },
95
+ "stripe": {
96
+ "optional": true
87
97
  }
88
98
  }
89
99
  }