@wishknish/knishio-client-ts 0.9.5 → 0.9.6

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.js CHANGED
@@ -2172,11 +2172,9 @@ function verifyOTSSignature(otsFragments, molecularHash, signingAddress) {
2172
2172
  const base17Hash = convertToBase17(molecularHash);
2173
2173
  const enumerated = enumerateMolecularHash(base17Hash);
2174
2174
  const normalized = normalizeMolecularHash(enumerated);
2175
- let ots = otsFragments;
2175
+ const ots = otsFragments;
2176
2176
  if (ots.length !== 2048) {
2177
- if (ots.length !== 2048) {
2178
- return false;
2179
- }
2177
+ return false;
2180
2178
  }
2181
2179
  const otsChunks = [];
2182
2180
  for (let i = 0; i < ots.length; i += CRYPTO_CONSTANTS.KEY_FRAGMENT_SIZE) {
@@ -2679,6 +2677,123 @@ var Meta = class {
2679
2677
  });
2680
2678
  }
2681
2679
  };
2680
+
2681
+ // src/libraries/array.ts
2682
+ function deepCloning(o, h) {
2683
+ let i;
2684
+ let r;
2685
+ let x;
2686
+ const t = [Array, Date, Number, String, Boolean];
2687
+ const s = Object.prototype.toString;
2688
+ h = h || [];
2689
+ for (i = 0; i < h.length; i += 2) {
2690
+ if (o === h[i]) {
2691
+ return h[i + 1];
2692
+ }
2693
+ }
2694
+ if (!r && o && typeof o === "object") {
2695
+ r = {};
2696
+ for (i = 0; i < t.length; i++) {
2697
+ if (s.call(o) === s.call(x = new t[i](o))) {
2698
+ r = i ? x : [];
2699
+ }
2700
+ }
2701
+ h.push(o, r);
2702
+ for (i in o) {
2703
+ if (Object.prototype.hasOwnProperty.call(o, i)) {
2704
+ r[i] = deepCloning(o[i], h);
2705
+ }
2706
+ }
2707
+ }
2708
+ return r || o;
2709
+ }
2710
+ function chunkArray(arr, size) {
2711
+ const chunks = [];
2712
+ for (let i = 0; i < arr.length; i += size) {
2713
+ chunks.push(arr.slice(i, i + size));
2714
+ }
2715
+ return chunks;
2716
+ }
2717
+ function diff(...arrays) {
2718
+ return [].concat(...arrays.map((arr, i) => {
2719
+ const others = arrays.slice(0);
2720
+ others.splice(i, 1);
2721
+ const unique = [...new Set([].concat(...others))];
2722
+ return arr.filter((item) => !unique.includes(item));
2723
+ }));
2724
+ }
2725
+ function intersect(...arrays) {
2726
+ if (arrays.length === 0) return [];
2727
+ if (arrays.length === 1) return arrays[0];
2728
+ return arrays.reduce(
2729
+ (first, second) => first.filter((item) => second.includes(item))
2730
+ );
2731
+ }
2732
+
2733
+ // src/core/PolicyMeta.ts
2734
+ var PolicyMeta = class _PolicyMeta {
2735
+ policy;
2736
+ /**
2737
+ * Create new PolicyMeta instance
2738
+ * Matches JavaScript SDK constructor signature exactly
2739
+ */
2740
+ constructor(policy = {}, metaKeys = []) {
2741
+ this.policy = _PolicyMeta.normalizePolicy(policy);
2742
+ this.fillDefault(metaKeys);
2743
+ }
2744
+ /**
2745
+ * Normalize policy object structure
2746
+ * Matches JavaScript SDK normalizePolicy method exactly
2747
+ */
2748
+ static normalizePolicy(policy = {}) {
2749
+ const policyMeta = {};
2750
+ for (const [policyKey, value] of Object.entries(policy)) {
2751
+ if (value !== null && ["read", "write"].includes(policyKey)) {
2752
+ policyMeta[policyKey] = {};
2753
+ for (const [key, content] of Object.entries(value)) {
2754
+ policyMeta[policyKey][key] = content;
2755
+ }
2756
+ }
2757
+ }
2758
+ return policyMeta;
2759
+ }
2760
+ /**
2761
+ * Fill default policy values for metadata keys
2762
+ * Matches JavaScript SDK fillDefault method exactly
2763
+ */
2764
+ fillDefault(metaKeys = []) {
2765
+ const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
2766
+ const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
2767
+ for (const [type, value] of Object.entries({
2768
+ read: readPolicy,
2769
+ write: writePolicy
2770
+ })) {
2771
+ const policyKey = value.map((item) => item.key);
2772
+ if (!this.policy[type]) {
2773
+ this.policy[type] = {};
2774
+ }
2775
+ for (const key of diff(metaKeys, policyKey)) {
2776
+ if (!this.policy[type][key]) {
2777
+ this.policy[type][key] = type === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
2778
+ }
2779
+ }
2780
+ }
2781
+ }
2782
+ /**
2783
+ * Get the policy object
2784
+ * Matches JavaScript SDK get method exactly
2785
+ */
2786
+ get() {
2787
+ return this.policy;
2788
+ }
2789
+ /**
2790
+ * Convert policy to JSON string
2791
+ * Matches JavaScript SDK toJson method exactly
2792
+ */
2793
+ toJson() {
2794
+ return JSON.stringify(this.get());
2795
+ }
2796
+ };
2682
2797
  var AtomMeta = class _AtomMeta {
2683
2798
  meta;
2684
2799
  /**
@@ -2774,8 +2889,9 @@ var AtomMeta = class _AtomMeta {
2774
2889
  * @return This instance for chaining
2775
2890
  */
2776
2891
  addPolicy(policy) {
2892
+ const policyMeta = new PolicyMeta(policy, Object.keys(this.meta));
2777
2893
  this.merge({
2778
- policy: JSON.stringify(policy)
2894
+ policy: policyMeta.toJson()
2779
2895
  });
2780
2896
  return this;
2781
2897
  }
@@ -3408,6 +3524,87 @@ function createMolecularHash(value) {
3408
3524
  }
3409
3525
  return value;
3410
3526
  }
3527
+
3528
+ // src/core/TokenUnit.ts
3529
+ var TokenUnit = class _TokenUnit {
3530
+ id;
3531
+ name;
3532
+ metas;
3533
+ /**
3534
+ * Create new TokenUnit instance
3535
+ * Matches JavaScript SDK constructor signature exactly
3536
+ */
3537
+ constructor(id, name, metas) {
3538
+ this.id = id;
3539
+ this.name = name;
3540
+ this.metas = metas || {};
3541
+ }
3542
+ /**
3543
+ * Create TokenUnit from GraphQL response data
3544
+ * Matches JavaScript SDK createFromGraphQL method exactly
3545
+ */
3546
+ static createFromGraphQL(data) {
3547
+ let metas = data.metas || {};
3548
+ if (Array.isArray(metas) && metas.length) {
3549
+ try {
3550
+ metas = JSON.parse(metas);
3551
+ if (!metas) {
3552
+ metas = {};
3553
+ }
3554
+ } catch (error) {
3555
+ metas = {};
3556
+ }
3557
+ }
3558
+ return new _TokenUnit(
3559
+ data.id,
3560
+ data.name,
3561
+ metas
3562
+ );
3563
+ }
3564
+ /**
3565
+ * Create TokenUnit from database array data
3566
+ * Matches JavaScript SDK createFromDB method exactly
3567
+ */
3568
+ static createFromDB(data) {
3569
+ return new _TokenUnit(
3570
+ data[0],
3571
+ data[1],
3572
+ data.length > 2 ? data[2] : {}
3573
+ );
3574
+ }
3575
+ /**
3576
+ * Get fragment zone from metadata
3577
+ * Matches JavaScript SDK getFragmentZone method exactly
3578
+ */
3579
+ getFragmentZone() {
3580
+ return this.metas.fragmentZone || null;
3581
+ }
3582
+ /**
3583
+ * Get fused token units from metadata
3584
+ * Matches JavaScript SDK getFusedTokenUnits method exactly
3585
+ */
3586
+ getFusedTokenUnits() {
3587
+ return this.metas.fusedTokenUnits || null;
3588
+ }
3589
+ /**
3590
+ * Convert to data array format
3591
+ * Matches JavaScript SDK toData method exactly
3592
+ */
3593
+ toData() {
3594
+ return [this.id, this.name, this.metas];
3595
+ }
3596
+ /**
3597
+ * Convert to GraphQL response format
3598
+ * Matches JavaScript SDK toGraphQLResponse method exactly
3599
+ */
3600
+ toGraphQLResponse() {
3601
+ return {
3602
+ id: this.id,
3603
+ name: this.name,
3604
+ metas: JSON.stringify(this.metas)
3605
+ };
3606
+ }
3607
+ };
3411
3608
  var Wallet = class _Wallet {
3412
3609
  token;
3413
3610
  balance;
@@ -3548,11 +3745,13 @@ var Wallet = class _Wallet {
3548
3745
  return typeof maybeBundleHash === "string" && isBundleHash(maybeBundleHash);
3549
3746
  }
3550
3747
  /**
3551
- * Get formatted token units from raw data
3552
- * Stub implementation for now
3748
+ * Map raw token-unit tuples to TokenUnit instances.
3749
+ * Matches JS SDK Wallet.getTokenUnits (Wallet.js:190-196). The serialised shape reaches hashed
3750
+ * atom meta via AtomMeta.setAtomWallet -> JSON.stringify(getTokenUnitsData()), so returning raw
3751
+ * tuples here would diverge from every other SDK.
3553
3752
  */
3554
3753
  static getTokenUnits(unitsData) {
3555
- return unitsData;
3754
+ return unitsData.map((unitData) => TokenUnit.createFromDB(unitData));
3556
3755
  }
3557
3756
  /**
3558
3757
  * Create a remainder wallet for transactions
@@ -3849,7 +4048,7 @@ z.string().regex(base17HashRegex, "Molecular hash must be base17 format (0-9,a-g
3849
4048
  var TokenSlugSchema = z.string().min(1, "Token slug cannot be empty").max(64, "Token slug cannot exceed 64 characters").transform((val) => val.toUpperCase()).brand();
3850
4049
  var MetaTypeSchema = z.string().min(1, "Meta type cannot be empty").max(256, "Meta type cannot exceed 256 characters").brand();
3851
4050
  var MetaIdSchema = z.string().min(1, "Meta ID cannot be empty").brand();
3852
- var BatchIdSchema = z.string().min(1, "Batch ID cannot be empty").brand();
4051
+ var BatchIdSchema = z.string().regex(/^[0-9a-fA-F]{64}$/, "Batch ID must be 64 hexadecimal characters").brand();
3853
4052
  var CellSlugSchema = z.string().min(1, "Cell slug cannot be empty").max(64, "Cell slug cannot exceed 64 characters").brand();
3854
4053
  var AtomIsotopeSchema = z.enum(["C", "V", "U", "T", "M", "I", "R", "B", "F"], {
3855
4054
  error: "Invalid atom isotope. Must be one of: C, V, U, T, M, I, R, B, F"
@@ -4173,58 +4372,6 @@ var RuleArgumentException = class extends BaseException {
4173
4372
  };
4174
4373
  var RuleArgumentException_default = RuleArgumentException;
4175
4374
 
4176
- // src/libraries/array.ts
4177
- function deepCloning(o, h) {
4178
- let i;
4179
- let r;
4180
- let x;
4181
- const t = [Array, Date, Number, String, Boolean];
4182
- const s = Object.prototype.toString;
4183
- h = h || [];
4184
- for (i = 0; i < h.length; i += 2) {
4185
- if (o === h[i]) {
4186
- return h[i + 1];
4187
- }
4188
- }
4189
- if (!r && o && typeof o === "object") {
4190
- r = {};
4191
- for (i = 0; i < t.length; i++) {
4192
- if (s.call(o) === s.call(x = new t[i](o))) {
4193
- r = i ? x : [];
4194
- }
4195
- }
4196
- h.push(o, r);
4197
- for (i in o) {
4198
- if (Object.prototype.hasOwnProperty.call(o, i)) {
4199
- r[i] = deepCloning(o[i], h);
4200
- }
4201
- }
4202
- }
4203
- return r || o;
4204
- }
4205
- function chunkArray(arr, size) {
4206
- const chunks = [];
4207
- for (let i = 0; i < arr.length; i += size) {
4208
- chunks.push(arr.slice(i, i + size));
4209
- }
4210
- return chunks;
4211
- }
4212
- function diff(...arrays) {
4213
- return [].concat(...arrays.map((arr, i) => {
4214
- const others = arrays.slice(0);
4215
- others.splice(i, 1);
4216
- const unique = [...new Set([].concat(...others))];
4217
- return arr.filter((item) => !unique.includes(item));
4218
- }));
4219
- }
4220
- function intersect(...arrays) {
4221
- if (arrays.length === 0) return [];
4222
- if (arrays.length === 1) return arrays[0];
4223
- return arrays.reduce(
4224
- (first, second) => first.filter((item) => second.includes(item))
4225
- );
4226
- }
4227
-
4228
4375
  // src/instance/rules/Callback.ts
4229
4376
  init_exception();
4230
4377
  var CallbackParamsSchema = z.object({
@@ -5555,6 +5702,51 @@ var Molecule = class _Molecule {
5555
5702
  }));
5556
5703
  return this;
5557
5704
  }
5705
+ /**
5706
+ * Replenishes non-finite token supplies.
5707
+ * Matches JS SDK Molecule.replenishToken (Molecule.js:521-566) exactly.
5708
+ *
5709
+ * Two orderings here are load-bearing for the molecular hash and must not be reordered:
5710
+ * the remainder balance is computed BEFORE the source balance is overwritten, and the
5711
+ * source V-atom is added BEFORE the remainder V-atom.
5712
+ */
5713
+ replenishToken({
5714
+ amount,
5715
+ units = []
5716
+ }) {
5717
+ if (amount < 0) {
5718
+ throw new NegativeAmountException("Molecule::replenishToken() - Amount to replenish must be positive!");
5719
+ }
5720
+ if (!this.sourceWallet || !this.remainderWallet) {
5721
+ throw new Error("Source and remainder wallets required for token replenishment");
5722
+ }
5723
+ if (units.length) {
5724
+ const formatted = Wallet.getTokenUnits(units);
5725
+ this.remainderWallet.tokenUnits = this.sourceWallet.tokenUnits;
5726
+ for (const unit of formatted) {
5727
+ this.remainderWallet.tokenUnits.push(unit);
5728
+ }
5729
+ this.remainderWallet.balance = String(this.remainderWallet.tokenUnits.length);
5730
+ this.sourceWallet.tokenUnits = formatted;
5731
+ this.sourceWallet.balance = String(this.sourceWallet.tokenUnits.length);
5732
+ } else {
5733
+ this.remainderWallet.balance = String(Number(this.sourceWallet.balance) + amount);
5734
+ this.sourceWallet.balance = String(amount);
5735
+ }
5736
+ this.addAtom(Atom.create({
5737
+ isotope: "V",
5738
+ wallet: this.sourceWallet,
5739
+ value: Number(this.sourceWallet.balance)
5740
+ }));
5741
+ this.addAtom(Atom.create({
5742
+ isotope: "V",
5743
+ wallet: this.remainderWallet,
5744
+ value: Number(this.remainderWallet.balance),
5745
+ metaType: "walletBundle",
5746
+ metaId: this.remainderWallet.bundle
5747
+ }));
5748
+ return this;
5749
+ }
5558
5750
  /**
5559
5751
  * Initialize authorization request
5560
5752
  * Creates U-isotope (authorization) atom for requesting auth token
@@ -6089,16 +6281,27 @@ var GraphQLClient = class {
6089
6281
  return createClient$1({
6090
6282
  url: serverUri,
6091
6283
  exchanges,
6092
- // PQ-transport Phase E: when encryption is on, route fetch through the CipherHash wrapper
6093
- // (encrypt the request body to the validator's ML-KEM pubkey, decrypt the response).
6094
- // Omitted → urql uses the global fetch (plaintext).
6095
- ...this.cipherLink ? { fetch: ((input, init) => this.cipherFetch(input, init)) } : {},
6284
+ // urql 5 had no default and always POSTed; urql 6 defaults to 'within-url-limit', which
6285
+ // URL-encodes short queries and sends NO body. That would silently disable the CipherHash
6286
+ // envelope below — cipherFetch's `typeof init.body === 'string'` guard fails on a GET, so
6287
+ // the query would leave as plaintext URL parameters with no error. Pin POST explicitly.
6288
+ preferGetMethod: false,
6289
+ // Always route through our own fetch. Two reasons: (1) PQ-transport Phase E — when
6290
+ // encryption is on, cipherFetch wraps the request body in the CipherHash envelope and
6291
+ // decrypts the response; (2) the 60s timeout. urql's makeFetchSource unconditionally
6292
+ // overwrites init.signal with its own AbortController, so a signal returned from
6293
+ // fetchOptions() is discarded and never fired. Combining it here is the only place it
6294
+ // survives.
6295
+ fetch: ((input, init) => {
6296
+ const timeoutSignal = AbortSignal.timeout(6e4);
6297
+ const signal = init?.signal && typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeoutSignal]) : init?.signal ?? timeoutSignal;
6298
+ const timedInit = { ...init, signal };
6299
+ return this.cipherLink ? this.cipherFetch(input, timedInit) : fetch(input, timedInit);
6300
+ }),
6096
6301
  fetchOptions: () => ({
6097
6302
  headers: {
6098
6303
  "X-Auth-Token": this.$__authToken
6099
- },
6100
- // Add 60 second timeout
6101
- signal: AbortSignal.timeout(6e4)
6304
+ }
6102
6305
  })
6103
6306
  });
6104
6307
  }
@@ -6611,12 +6814,12 @@ var TokenSlugSchema2 = createBrandedSchema(
6611
6814
  );
6612
6815
  var BatchIdSchema2 = createBrandedSchema(
6613
6816
  "BatchId",
6614
- // v3's `.uuid()` regex, inlined verbatim. Zod 4's `z.uuid()` additionally enforces the
6615
- // RFC 9562 version/variant nibbles and would reject batch IDs v3 accepted.
6616
- z.string().regex(
6617
- /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
6618
- "Invalid batch ID format"
6619
- )
6817
+ // 64 hex characters. generateBatchId (src/libraries/crypto.ts) returns either
6818
+ // shake256(molecularHash + index, 256) — 256 bits, 64 hex chars — or randomString(64) over the
6819
+ // alphabet 'abcdef0123456789'. A UUID shape matches nothing this SDK can produce, so the
6820
+ // previous 8-4-4-4-12 regex rejected every real batch ID. Agrees with isBatchId in
6821
+ // src/types/guards.ts.
6822
+ z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid batch ID format")
6620
6823
  );
6621
6824
  var CellSlugSchema2 = createBrandedSchema(
6622
6825
  "CellSlug",
@@ -7519,89 +7722,6 @@ var ConfigValidator = class _ConfigValidator {
7519
7722
 
7520
7723
  // src/response/ResponseBalance.ts
7521
7724
  init_Response();
7522
-
7523
- // src/core/TokenUnit.ts
7524
- var TokenUnit = class _TokenUnit {
7525
- id;
7526
- name;
7527
- metas;
7528
- /**
7529
- * Create new TokenUnit instance
7530
- * Matches JavaScript SDK constructor signature exactly
7531
- */
7532
- constructor(id, name, metas) {
7533
- this.id = id;
7534
- this.name = name;
7535
- this.metas = metas || {};
7536
- }
7537
- /**
7538
- * Create TokenUnit from GraphQL response data
7539
- * Matches JavaScript SDK createFromGraphQL method exactly
7540
- */
7541
- static createFromGraphQL(data) {
7542
- let metas = data.metas || {};
7543
- if (Array.isArray(metas) && metas.length) {
7544
- try {
7545
- metas = JSON.parse(metas);
7546
- if (!metas) {
7547
- metas = {};
7548
- }
7549
- } catch (error) {
7550
- metas = {};
7551
- }
7552
- }
7553
- return new _TokenUnit(
7554
- data.id,
7555
- data.name,
7556
- metas
7557
- );
7558
- }
7559
- /**
7560
- * Create TokenUnit from database array data
7561
- * Matches JavaScript SDK createFromDB method exactly
7562
- */
7563
- static createFromDB(data) {
7564
- return new _TokenUnit(
7565
- data[0],
7566
- data[1],
7567
- data.length > 2 ? data[2] : {}
7568
- );
7569
- }
7570
- /**
7571
- * Get fragment zone from metadata
7572
- * Matches JavaScript SDK getFragmentZone method exactly
7573
- */
7574
- getFragmentZone() {
7575
- return this.metas.fragmentZone || null;
7576
- }
7577
- /**
7578
- * Get fused token units from metadata
7579
- * Matches JavaScript SDK getFusedTokenUnits method exactly
7580
- */
7581
- getFusedTokenUnits() {
7582
- return this.metas.fusedTokenUnits || null;
7583
- }
7584
- /**
7585
- * Convert to data array format
7586
- * Matches JavaScript SDK toData method exactly
7587
- */
7588
- toData() {
7589
- return [this.id, this.name, this.metas];
7590
- }
7591
- /**
7592
- * Convert to GraphQL response format
7593
- * Matches JavaScript SDK toGraphQLResponse method exactly
7594
- */
7595
- toGraphQLResponse() {
7596
- return {
7597
- id: this.id,
7598
- name: this.name,
7599
- metas: JSON.stringify(this.metas)
7600
- };
7601
- }
7602
- };
7603
-
7604
- // src/response/ResponseBalance.ts
7605
7725
  var ResponseBalance = class _ResponseBalance extends Response2 {
7606
7726
  /**
7607
7727
  * Class constructor
@@ -10110,6 +10230,12 @@ var MutationAppendRequest = class extends MutationProposeMolecule {
10110
10230
  }
10111
10231
  };
10112
10232
 
10233
+ // src/mutation/MutationReplenishToken.ts
10234
+ var MutationReplenishToken = class extends MutationProposeMolecule {
10235
+ fillMolecule() {
10236
+ }
10237
+ };
10238
+
10113
10239
  // src/subscribe/Subscribe.ts
10114
10240
  init_exception();
10115
10241
  var Subscribe = class {
@@ -11543,20 +11669,42 @@ var KnishIOClient = class {
11543
11669
  return response;
11544
11670
  }
11545
11671
  /**
11546
- * Replenish tokens
11672
+ * Replenish a non-finite token supply.
11673
+ * Matches JS SDK KnishIOClient.replenishToken (KnishIOClient.js:2195-2231).
11547
11674
  */
11548
11675
  async replenishToken({
11549
11676
  token,
11550
11677
  amount = null,
11551
11678
  units = null,
11552
- sourceWallet: _sourceWallet = null
11679
+ sourceWallet = null
11553
11680
  }) {
11554
11681
  this.log("info", `KnishIOClient::replenishToken() - Replenishing ${amount || "units"} of ${token}...`);
11555
- return this.requestTokens({
11556
- token,
11557
- amount,
11558
- units
11682
+ if (!sourceWallet) {
11683
+ sourceWallet = (await this.queryBalance({ token }))?.payload();
11684
+ }
11685
+ if (!sourceWallet) {
11686
+ throw new TransferBalanceException("Source wallet is missing or invalid.");
11687
+ }
11688
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret());
11689
+ const molecule = await this.createMolecule({
11690
+ sourceWallet,
11691
+ remainderWallet
11559
11692
  });
11693
+ molecule.replenishToken({
11694
+ amount: Number(amount ?? 0),
11695
+ units: units ?? []
11696
+ });
11697
+ molecule.sign({ bundle: this.getBundle() });
11698
+ molecule.check();
11699
+ const mutation = await this.createMoleculeMutation({
11700
+ mutationClass: MutationReplenishToken,
11701
+ molecule
11702
+ });
11703
+ const response = await this.executeQuery(mutation);
11704
+ if (!response) {
11705
+ throw new CodeException("Token replenishment failed");
11706
+ }
11707
+ return response;
11560
11708
  }
11561
11709
  /**
11562
11710
  * Fuse token units
@@ -12007,75 +12155,8 @@ var KnishIOClient = class {
12007
12155
 
12008
12156
  // src/index.ts
12009
12157
  init_Response();
12010
-
12011
- // src/core/PolicyMeta.ts
12012
- var PolicyMeta = class _PolicyMeta {
12013
- policy;
12014
- /**
12015
- * Create new PolicyMeta instance
12016
- * Matches JavaScript SDK constructor signature exactly
12017
- */
12018
- constructor(policy = {}, metaKeys = []) {
12019
- this.policy = _PolicyMeta.normalizePolicy(policy);
12020
- this.fillDefault(metaKeys);
12021
- }
12022
- /**
12023
- * Normalize policy object structure
12024
- * Matches JavaScript SDK normalizePolicy method exactly
12025
- */
12026
- static normalizePolicy(policy = {}) {
12027
- const policyMeta = {};
12028
- for (const [policyKey, value] of Object.entries(policy)) {
12029
- if (value !== null && ["read", "write"].includes(policyKey)) {
12030
- policyMeta[policyKey] = {};
12031
- for (const [key, content] of Object.entries(value)) {
12032
- policyMeta[policyKey][key] = content;
12033
- }
12034
- }
12035
- }
12036
- return policyMeta;
12037
- }
12038
- /**
12039
- * Fill default policy values for metadata keys
12040
- * Matches JavaScript SDK fillDefault method exactly
12041
- */
12042
- fillDefault(metaKeys = []) {
12043
- const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
12044
- const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
12045
- for (const [type, value] of Object.entries({
12046
- read: readPolicy,
12047
- write: writePolicy
12048
- })) {
12049
- const policyKey = value.map((item) => item.key);
12050
- if (!this.policy[type]) {
12051
- this.policy[type] = {};
12052
- }
12053
- for (const key of diff(metaKeys, policyKey)) {
12054
- if (!this.policy[type][key]) {
12055
- this.policy[type][key] = type === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
12056
- }
12057
- }
12058
- }
12059
- }
12060
- /**
12061
- * Get the policy object
12062
- * Matches JavaScript SDK get method exactly
12063
- */
12064
- get() {
12065
- return this.policy;
12066
- }
12067
- /**
12068
- * Convert policy to JSON string
12069
- * Matches JavaScript SDK toJson method exactly
12070
- */
12071
- toJson() {
12072
- return JSON.stringify(this.get());
12073
- }
12074
- };
12075
-
12076
- // src/index.ts
12077
12158
  init_exception();
12078
- var SDK_VERSION = "0.9.5";
12159
+ var SDK_VERSION = "0.9.6";
12079
12160
  var SDK_NAME = "KnishIO-Client-TS";
12080
12161
  var COMPATIBLE_SERVER_VERSIONS = [4, 5];
12081
12162
  var SDK_INFO = {