@opendatalabs/vana-sdk 3.8.1 → 3.8.2

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.
@@ -26,14 +26,17 @@ __export(scopes_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(scopes_exports);
28
28
  var import_zod = require("zod");
29
- const SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
29
+ const SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;
30
+ const TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
30
31
  const ScopeSchema = import_zod.z.string().refine(
31
32
  (scope) => {
32
33
  const parts = scope.split(".");
33
- return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
34
+ if (parts.length < 2 || parts.length > 3) return false;
35
+ const [source, ...tail] = parts;
36
+ return SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part));
34
37
  },
35
38
  {
36
- message: "Scope must be {source}.{category}[.{subcategory}] with lowercase alphanumeric segments (may start with a letter or digit)"
39
+ message: "Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)"
37
40
  }
38
41
  );
39
42
  function parseScope(scope) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/scopes.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;\n\nexport const ScopeSchema = z.string().refine(\n (scope) => {\n const parts = scope.split(\".\");\n return (\n parts.length >= 2 &&\n parts.length <= 3 &&\n parts.every((part) => SEGMENT_RE.test(part))\n );\n },\n {\n message:\n \"Scope must be {source}.{category}[.{subcategory}] with lowercase alphanumeric segments (may start with a letter or digit)\",\n },\n);\n\nexport type Scope = z.infer<typeof ScopeSchema>;\n\nexport interface ParsedScope {\n source: string;\n category: string;\n subcategory?: string;\n raw: string;\n}\n\nexport function parseScope(scope: string): ParsedScope {\n const validated = ScopeSchema.parse(scope);\n const parts = validated.split(\".\");\n return {\n source: parts[0],\n category: parts[1],\n subcategory: parts[2],\n raw: validated,\n };\n}\n\nexport function scopeToPathSegments(scope: string): string[] {\n const parsed = parseScope(scope);\n const segments = [parsed.source, parsed.category];\n if (parsed.subcategory) {\n segments.push(parsed.subcategory);\n }\n return segments;\n}\n\nexport function scopeMatchesPattern(\n requestedScope: string,\n grantPattern: string,\n): boolean {\n if (grantPattern === \"*\") return true;\n\n if (grantPattern.endsWith(\".*\")) {\n const prefix = grantPattern.slice(0, -1);\n return requestedScope.startsWith(prefix);\n }\n\n return requestedScope === grantPattern;\n}\n\nexport function scopeCoveredByGrant(\n requestedScope: string,\n grantedScopes: string[],\n): boolean {\n return grantedScopes.some((pattern) =>\n scopeMatchesPattern(requestedScope, pattern),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAElB,MAAM,aAAa;AAEZ,MAAM,cAAc,aAAE,OAAO,EAAE;AAAA,EACpC,CAAC,UAAU;AACT,UAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,WACE,MAAM,UAAU,KAChB,MAAM,UAAU,KAChB,MAAM,MAAM,CAAC,SAAS,WAAW,KAAK,IAAI,CAAC;AAAA,EAE/C;AAAA,EACA;AAAA,IACE,SACE;AAAA,EACJ;AACF;AAWO,SAAS,WAAW,OAA4B;AACrD,QAAM,YAAY,YAAY,MAAM,KAAK;AACzC,QAAM,QAAQ,UAAU,MAAM,GAAG;AACjC,SAAO;AAAA,IACL,QAAQ,MAAM,CAAC;AAAA,IACf,UAAU,MAAM,CAAC;AAAA,IACjB,aAAa,MAAM,CAAC;AAAA,IACpB,KAAK;AAAA,EACP;AACF;AAEO,SAAS,oBAAoB,OAAyB;AAC3D,QAAM,SAAS,WAAW,KAAK;AAC/B,QAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,QAAQ;AAChD,MAAI,OAAO,aAAa;AACtB,aAAS,KAAK,OAAO,WAAW;AAAA,EAClC;AACA,SAAO;AACT;AAEO,SAAS,oBACd,gBACA,cACS;AACT,MAAI,iBAAiB,IAAK,QAAO;AAEjC,MAAI,aAAa,SAAS,IAAI,GAAG;AAC/B,UAAM,SAAS,aAAa,MAAM,GAAG,EAAE;AACvC,WAAO,eAAe,WAAW,MAAM;AAAA,EACzC;AAEA,SAAO,mBAAmB;AAC5B;AAEO,SAAS,oBACd,gBACA,eACS;AACT,SAAO,cAAc;AAAA,IAAK,CAAC,YACzB,oBAAoB,gBAAgB,OAAO;AAAA,EAC7C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/protocol/scopes.ts"],"sourcesContent":["import { z } from \"zod\";\n\n// The source_id (first segment) must stay lowercase. Tail segments may keep\n// the historical camelCase form the contract-freeze spec explicitly preserves\n// (e.g. spotify.savedTracks, youtube.playlistItems) — the chain never validates\n// scope strings, so the SDK must not be stricter than the protocol.\nconst SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;\nconst TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;\n\nexport const ScopeSchema = z.string().refine(\n (scope) => {\n const parts = scope.split(\".\");\n if (parts.length < 2 || parts.length > 3) return false;\n const [source, ...tail] = parts;\n return (\n SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part))\n );\n },\n {\n message:\n \"Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)\",\n },\n);\n\nexport type Scope = z.infer<typeof ScopeSchema>;\n\nexport interface ParsedScope {\n source: string;\n category: string;\n subcategory?: string;\n raw: string;\n}\n\nexport function parseScope(scope: string): ParsedScope {\n const validated = ScopeSchema.parse(scope);\n const parts = validated.split(\".\");\n return {\n source: parts[0],\n category: parts[1],\n subcategory: parts[2],\n raw: validated,\n };\n}\n\nexport function scopeToPathSegments(scope: string): string[] {\n const parsed = parseScope(scope);\n const segments = [parsed.source, parsed.category];\n if (parsed.subcategory) {\n segments.push(parsed.subcategory);\n }\n return segments;\n}\n\nexport function scopeMatchesPattern(\n requestedScope: string,\n grantPattern: string,\n): boolean {\n if (grantPattern === \"*\") return true;\n\n if (grantPattern.endsWith(\".*\")) {\n const prefix = grantPattern.slice(0, -1);\n return requestedScope.startsWith(prefix);\n }\n\n return requestedScope === grantPattern;\n}\n\nexport function scopeCoveredByGrant(\n requestedScope: string,\n grantedScopes: string[],\n): boolean {\n return grantedScopes.some((pattern) =>\n scopeMatchesPattern(requestedScope, pattern),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAMlB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AAEjB,MAAM,cAAc,aAAE,OAAO,EAAE;AAAA,EACpC,CAAC,UAAU;AACT,UAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,QAAI,MAAM,SAAS,KAAK,MAAM,SAAS,EAAG,QAAO;AACjD,UAAM,CAAC,QAAQ,GAAG,IAAI,IAAI;AAC1B,WACE,UAAU,KAAK,MAAM,KAAK,KAAK,MAAM,CAAC,SAAS,gBAAgB,KAAK,IAAI,CAAC;AAAA,EAE7E;AAAA,EACA;AAAA,IACE,SACE;AAAA,EACJ;AACF;AAWO,SAAS,WAAW,OAA4B;AACrD,QAAM,YAAY,YAAY,MAAM,KAAK;AACzC,QAAM,QAAQ,UAAU,MAAM,GAAG;AACjC,SAAO;AAAA,IACL,QAAQ,MAAM,CAAC;AAAA,IACf,UAAU,MAAM,CAAC;AAAA,IACjB,aAAa,MAAM,CAAC;AAAA,IACpB,KAAK;AAAA,EACP;AACF;AAEO,SAAS,oBAAoB,OAAyB;AAC3D,QAAM,SAAS,WAAW,KAAK;AAC/B,QAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,QAAQ;AAChD,MAAI,OAAO,aAAa;AACtB,aAAS,KAAK,OAAO,WAAW;AAAA,EAClC;AACA,SAAO;AACT;AAEO,SAAS,oBACd,gBACA,cACS;AACT,MAAI,iBAAiB,IAAK,QAAO;AAEjC,MAAI,aAAa,SAAS,IAAI,GAAG;AAC/B,UAAM,SAAS,aAAa,MAAM,GAAG,EAAE;AACvC,WAAO,eAAe,WAAW,MAAM;AAAA,EACzC;AAEA,SAAO,mBAAmB;AAC5B;AAEO,SAAS,oBACd,gBACA,eACS;AACT,SAAO,cAAc;AAAA,IAAK,CAAC,YACzB,oBAAoB,gBAAgB,OAAO;AAAA,EAC7C;AACF;","names":[]}
@@ -1,12 +1,15 @@
1
1
  import { z } from "zod";
2
- const SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
2
+ const SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;
3
+ const TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
3
4
  const ScopeSchema = z.string().refine(
4
5
  (scope) => {
5
6
  const parts = scope.split(".");
6
- return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
7
+ if (parts.length < 2 || parts.length > 3) return false;
8
+ const [source, ...tail] = parts;
9
+ return SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part));
7
10
  },
8
11
  {
9
- message: "Scope must be {source}.{category}[.{subcategory}] with lowercase alphanumeric segments (may start with a letter or digit)"
12
+ message: "Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)"
10
13
  }
11
14
  );
12
15
  function parseScope(scope) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/scopes.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;\n\nexport const ScopeSchema = z.string().refine(\n (scope) => {\n const parts = scope.split(\".\");\n return (\n parts.length >= 2 &&\n parts.length <= 3 &&\n parts.every((part) => SEGMENT_RE.test(part))\n );\n },\n {\n message:\n \"Scope must be {source}.{category}[.{subcategory}] with lowercase alphanumeric segments (may start with a letter or digit)\",\n },\n);\n\nexport type Scope = z.infer<typeof ScopeSchema>;\n\nexport interface ParsedScope {\n source: string;\n category: string;\n subcategory?: string;\n raw: string;\n}\n\nexport function parseScope(scope: string): ParsedScope {\n const validated = ScopeSchema.parse(scope);\n const parts = validated.split(\".\");\n return {\n source: parts[0],\n category: parts[1],\n subcategory: parts[2],\n raw: validated,\n };\n}\n\nexport function scopeToPathSegments(scope: string): string[] {\n const parsed = parseScope(scope);\n const segments = [parsed.source, parsed.category];\n if (parsed.subcategory) {\n segments.push(parsed.subcategory);\n }\n return segments;\n}\n\nexport function scopeMatchesPattern(\n requestedScope: string,\n grantPattern: string,\n): boolean {\n if (grantPattern === \"*\") return true;\n\n if (grantPattern.endsWith(\".*\")) {\n const prefix = grantPattern.slice(0, -1);\n return requestedScope.startsWith(prefix);\n }\n\n return requestedScope === grantPattern;\n}\n\nexport function scopeCoveredByGrant(\n requestedScope: string,\n grantedScopes: string[],\n): boolean {\n return grantedScopes.some((pattern) =>\n scopeMatchesPattern(requestedScope, pattern),\n );\n}\n"],"mappings":"AAAA,SAAS,SAAS;AAElB,MAAM,aAAa;AAEZ,MAAM,cAAc,EAAE,OAAO,EAAE;AAAA,EACpC,CAAC,UAAU;AACT,UAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,WACE,MAAM,UAAU,KAChB,MAAM,UAAU,KAChB,MAAM,MAAM,CAAC,SAAS,WAAW,KAAK,IAAI,CAAC;AAAA,EAE/C;AAAA,EACA;AAAA,IACE,SACE;AAAA,EACJ;AACF;AAWO,SAAS,WAAW,OAA4B;AACrD,QAAM,YAAY,YAAY,MAAM,KAAK;AACzC,QAAM,QAAQ,UAAU,MAAM,GAAG;AACjC,SAAO;AAAA,IACL,QAAQ,MAAM,CAAC;AAAA,IACf,UAAU,MAAM,CAAC;AAAA,IACjB,aAAa,MAAM,CAAC;AAAA,IACpB,KAAK;AAAA,EACP;AACF;AAEO,SAAS,oBAAoB,OAAyB;AAC3D,QAAM,SAAS,WAAW,KAAK;AAC/B,QAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,QAAQ;AAChD,MAAI,OAAO,aAAa;AACtB,aAAS,KAAK,OAAO,WAAW;AAAA,EAClC;AACA,SAAO;AACT;AAEO,SAAS,oBACd,gBACA,cACS;AACT,MAAI,iBAAiB,IAAK,QAAO;AAEjC,MAAI,aAAa,SAAS,IAAI,GAAG;AAC/B,UAAM,SAAS,aAAa,MAAM,GAAG,EAAE;AACvC,WAAO,eAAe,WAAW,MAAM;AAAA,EACzC;AAEA,SAAO,mBAAmB;AAC5B;AAEO,SAAS,oBACd,gBACA,eACS;AACT,SAAO,cAAc;AAAA,IAAK,CAAC,YACzB,oBAAoB,gBAAgB,OAAO;AAAA,EAC7C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/protocol/scopes.ts"],"sourcesContent":["import { z } from \"zod\";\n\n// The source_id (first segment) must stay lowercase. Tail segments may keep\n// the historical camelCase form the contract-freeze spec explicitly preserves\n// (e.g. spotify.savedTracks, youtube.playlistItems) — the chain never validates\n// scope strings, so the SDK must not be stricter than the protocol.\nconst SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;\nconst TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;\n\nexport const ScopeSchema = z.string().refine(\n (scope) => {\n const parts = scope.split(\".\");\n if (parts.length < 2 || parts.length > 3) return false;\n const [source, ...tail] = parts;\n return (\n SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part))\n );\n },\n {\n message:\n \"Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)\",\n },\n);\n\nexport type Scope = z.infer<typeof ScopeSchema>;\n\nexport interface ParsedScope {\n source: string;\n category: string;\n subcategory?: string;\n raw: string;\n}\n\nexport function parseScope(scope: string): ParsedScope {\n const validated = ScopeSchema.parse(scope);\n const parts = validated.split(\".\");\n return {\n source: parts[0],\n category: parts[1],\n subcategory: parts[2],\n raw: validated,\n };\n}\n\nexport function scopeToPathSegments(scope: string): string[] {\n const parsed = parseScope(scope);\n const segments = [parsed.source, parsed.category];\n if (parsed.subcategory) {\n segments.push(parsed.subcategory);\n }\n return segments;\n}\n\nexport function scopeMatchesPattern(\n requestedScope: string,\n grantPattern: string,\n): boolean {\n if (grantPattern === \"*\") return true;\n\n if (grantPattern.endsWith(\".*\")) {\n const prefix = grantPattern.slice(0, -1);\n return requestedScope.startsWith(prefix);\n }\n\n return requestedScope === grantPattern;\n}\n\nexport function scopeCoveredByGrant(\n requestedScope: string,\n grantedScopes: string[],\n): boolean {\n return grantedScopes.some((pattern) =>\n scopeMatchesPattern(requestedScope, pattern),\n );\n}\n"],"mappings":"AAAA,SAAS,SAAS;AAMlB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AAEjB,MAAM,cAAc,EAAE,OAAO,EAAE;AAAA,EACpC,CAAC,UAAU;AACT,UAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,QAAI,MAAM,SAAS,KAAK,MAAM,SAAS,EAAG,QAAO;AACjD,UAAM,CAAC,QAAQ,GAAG,IAAI,IAAI;AAC1B,WACE,UAAU,KAAK,MAAM,KAAK,KAAK,MAAM,CAAC,SAAS,gBAAgB,KAAK,IAAI,CAAC;AAAA,EAE7E;AAAA,EACA;AAAA,IACE,SACE;AAAA,EACJ;AACF;AAWO,SAAS,WAAW,OAA4B;AACrD,QAAM,YAAY,YAAY,MAAM,KAAK;AACzC,QAAM,QAAQ,UAAU,MAAM,GAAG;AACjC,SAAO;AAAA,IACL,QAAQ,MAAM,CAAC;AAAA,IACf,UAAU,MAAM,CAAC;AAAA,IACjB,aAAa,MAAM,CAAC;AAAA,IACpB,KAAK;AAAA,EACP;AACF;AAEO,SAAS,oBAAoB,OAAyB;AAC3D,QAAM,SAAS,WAAW,KAAK;AAC/B,QAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,QAAQ;AAChD,MAAI,OAAO,aAAa;AACtB,aAAS,KAAK,OAAO,WAAW;AAAA,EAClC;AACA,SAAO;AACT;AAEO,SAAS,oBACd,gBACA,cACS;AACT,MAAI,iBAAiB,IAAK,QAAO;AAEjC,MAAI,aAAa,SAAS,IAAI,GAAG;AAC/B,UAAM,SAAS,aAAa,MAAM,GAAG,EAAE;AACvC,WAAO,eAAe,WAAW,MAAM;AAAA,EACzC;AAEA,SAAO,mBAAmB;AAC5B;AAEO,SAAS,oBACd,gBACA,eACS;AACT,SAAO,cAAc;AAAA,IAAK,CAAC,YACzB,oBAAoB,gBAAgB,OAAO;AAAA,EAC7C;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendatalabs/vana-sdk",
3
- "version": "3.8.1",
3
+ "version": "3.8.2",
4
4
  "description": "A TypeScript library for interacting with Vana Network smart contracts.",
5
5
  "publishConfig": {
6
6
  "access": "public"