@nibgate/sdk 0.2.6 → 0.2.7

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/SKILL.md CHANGED
@@ -44,35 +44,30 @@ If the widget loads after app code, the SDK queues events and flushes them when
44
44
 
45
45
  ---
46
46
 
47
- ## 2. Resource Shape
47
+ ## 2. Resource Shape (Minimal)
48
48
 
49
- Define one stable resource per paid route, CMS row, media item, file, or API product:
49
+ The SDK auto-derives most fields from meta tags and defaults. You only need:
50
50
 
51
51
  ```ts
52
52
  const resource = {
53
53
  id: post.id,
54
- title: post.title,
55
- description: post.excerpt,
56
- type: 'article',
57
- price: '0.01',
58
- currency: 'USDC',
59
- recipient: post.creatorWallet,
54
+ title: post.title, // auto-fallsback to og:title → document.title
60
55
  path: `/posts/${post.slug}`,
61
- url: `https://creator.example/posts/${post.slug}`,
62
- tags: ['essay', 'research'],
63
- access: { humans: 'paid', agents: 'paid' },
64
- unlock: { mode: 'one_time' }
56
+ price: '0.01' // sets access: { humans: 'paid', agents: 'paid' } automatically
65
57
  }
66
58
  ```
67
59
 
68
- Allowed types: `article`, `image`, `music`, `video` (aliases like `audio→music`, `photo→image` are normalized). Use stable IDs — changing IDs breaks continuity for Explore, receipts, and reputation.
69
-
70
- **Auto-derived fields:** When running in a browser, the SDK auto-fills:
71
- - `url` from `window.location.origin + path` if `path` is provided but `url` is not
72
- - `imageUrl` from `<meta property="og:image">` if not explicitly set
73
- - `recipient` is **not required client-side** — the server's 402 payment challenge provides the canonical wallet address. Missing it generates a warning, not an error.
60
+ The rest fills in automatically from your page's HTML:
61
+ - `url` from `window.location.origin + path`
62
+ - `type` from `<meta property="og:type">` (defaults to `article`)
63
+ - `imageUrl` from `<meta property="og:image">`
64
+ - `description` from `<meta property="og:description">` `<meta name="description">`
65
+ - `tags` from `<meta name="keywords">`
66
+ - `currency` defaults to `USDC`
67
+ - `access` defaults to `paid` when `price > 0`, otherwise `free`
68
+ - `recipient` is optional (server's 402 challenge provides the real wallet)
74
69
 
75
- So a minimal client-side resource only needs `id`, `title`, `path`, and `price` — the rest is filled in automatically.
70
+ Allowed types: `article`, `image`, `music`, `video` (aliases like `audio→music`, `photo→image` are normalized). Use stable IDs changing IDs breaks continuity for Explore, receipts, and reputation.
76
71
 
77
72
  **Important:** The `image`, `description`, and `title` fields become the public thumbnail and card copy on the Explore page. Use a teaser preview, not the actual paid file.
78
73
 
package/dist/nibgate.js CHANGED
@@ -38,6 +38,27 @@ var Nibgate = (() => {
38
38
  __export(gateway_exports, {
39
39
  createCircleGatewayBrowserAdapter: () => createCircleGatewayBrowserAdapter
40
40
  });
41
+ async function getCircleClient(options = {}) {
42
+ if (cachedCircleModule) return cachedCircleModule;
43
+ if (options.clientModule) {
44
+ cachedCircleModule = options.clientModule;
45
+ return cachedCircleModule;
46
+ }
47
+ const moduleUrl = options.clientModuleUrl || "@circle-fin/x402-batching/client";
48
+ try {
49
+ cachedCircleModule = await import(moduleUrl);
50
+ return cachedCircleModule;
51
+ } catch (error) {
52
+ if (!options.clientModuleUrl) {
53
+ throw new Error(
54
+ `Could not load @circle-fin/x402-batching/client from node_modules. Provide a clientModuleUrl option (e.g. "https://esm.sh/@circle-fin/x402-batching@3.2.0/client?bundle") to load from CDN. Original error: ${error.message}`
55
+ );
56
+ }
57
+ throw new Error(
58
+ `Could not load Circle Gateway client from CDN: ${error.message}. Check that ${options.clientModuleUrl} is reachable.`
59
+ );
60
+ }
61
+ }
41
62
  function encodeBase64(value) {
42
63
  const text = typeof value === "string" ? value : stringifyJson(value);
43
64
  if (typeof Buffer !== "undefined") return Buffer.from(text).toString("base64");
@@ -52,7 +73,7 @@ var Nibgate = (() => {
52
73
  if (!signer?.address || typeof signer.signTypedData !== "function") {
53
74
  throw new Error("Circle Gateway browser adapter requires an EVM signer with address and signTypedData.");
54
75
  }
55
- const circleClientModule = options.clientModule || (options.clientModuleUrl ? await runtimeImport(options.clientModuleUrl) : await runtimeImport("@circle-fin/x402-batching/client"));
76
+ const circleClientModule = await getCircleClient(options);
56
77
  const { BatchEvmScheme } = circleClientModule;
57
78
  const scheme = new BatchEvmScheme(signer);
58
79
  const network = options.network || options.chainId && `eip155:${options.chainId}` || "eip155:5042002";
@@ -110,11 +131,11 @@ var Nibgate = (() => {
110
131
  }
111
132
  };
112
133
  }
113
- var runtimeImport;
134
+ var cachedCircleModule;
114
135
  var init_gateway = __esm({
115
136
  "src/browser/gateway.js"() {
116
137
  init_json();
117
- runtimeImport = new Function("specifier", "return import(specifier)");
138
+ cachedCircleModule = null;
118
139
  }
119
140
  });
120
141
 
@@ -314,7 +335,7 @@ var Nibgate = (() => {
314
335
  const normalized = normalizeResource(resource);
315
336
  const warnings = [];
316
337
  const errors = [];
317
- const required = options.required || ["id"];
338
+ const required = options.required || ["id", "type"];
318
339
  const recommended = options.recommended || ["title", "url", "description", "imageUrl", "tags"];
319
340
  for (const field of required) {
320
341
  if (!hasValue(normalized[field])) errors.push(`Missing required content metadata: ${field}`);
@@ -782,6 +803,7 @@ var Nibgate = (() => {
782
803
  const gateway = await Promise.resolve().then(() => (init_gateway(), gateway_exports));
783
804
  return gateway.createCircleGatewayBrowserAdapter(options);
784
805
  }
806
+ var DEFAULT_CIRCLE_CDN = "https://esm.sh/@circle-fin/x402-batching@3.2.0/client?bundle";
785
807
  function createEvmGatewayUnlock(resource, options = {}) {
786
808
  const item = createGate(resource, options.gateOptions || {});
787
809
  const win = browserWindow();
@@ -876,7 +898,7 @@ var Nibgate = (() => {
876
898
  signTypedData: (typedData) => evm.request({ method: "eth_signTypedData_v4", params: [walletAddress, stringifyJson(typedData)] })
877
899
  },
878
900
  clientModule: options.circleClientModule,
879
- clientModuleUrl: options.circleClientModuleUrl
901
+ clientModuleUrl: options.circleClientModuleUrl || DEFAULT_CIRCLE_CDN
880
902
  });
881
903
  return gatewayWallet.pay(input);
882
904
  }