@greensecurity/javascript-sdk 0.42.14-beta.0 → 0.43.1-beta.1

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.
Files changed (87) hide show
  1. package/README.md +18 -18
  2. package/dist/commonjs/__tests__/zones.test.js +2 -5
  3. package/dist/commonjs/__tests__/zones.test.js.map +1 -1
  4. package/dist/commonjs/lib/config.d.ts +3 -3
  5. package/dist/commonjs/lib/config.js +3 -3
  6. package/dist/commonjs/lib/config.js.map +1 -1
  7. package/dist/commonjs/lib/encodings.d.ts +1 -0
  8. package/dist/commonjs/lib/encodings.d.ts.map +1 -1
  9. package/dist/commonjs/lib/encodings.js +9 -0
  10. package/dist/commonjs/lib/encodings.js.map +1 -1
  11. package/dist/commonjs/models/components/mfarequiredresponse.d.ts +2 -8
  12. package/dist/commonjs/models/components/mfarequiredresponse.d.ts.map +1 -1
  13. package/dist/commonjs/models/components/mfarequiredresponse.js +2 -7
  14. package/dist/commonjs/models/components/mfarequiredresponse.js.map +1 -1
  15. package/dist/commonjs/models/components/passwordrequiredresponse.d.ts +1 -8
  16. package/dist/commonjs/models/components/passwordrequiredresponse.d.ts.map +1 -1
  17. package/dist/commonjs/models/components/passwordrequiredresponse.js +2 -8
  18. package/dist/commonjs/models/components/passwordrequiredresponse.js.map +1 -1
  19. package/dist/commonjs/models/components/samlloginrequiredresponse.d.ts +1 -8
  20. package/dist/commonjs/models/components/samlloginrequiredresponse.d.ts.map +1 -1
  21. package/dist/commonjs/models/components/samlloginrequiredresponse.js +2 -7
  22. package/dist/commonjs/models/components/samlloginrequiredresponse.js.map +1 -1
  23. package/dist/commonjs/models/operations/postauthenticate.d.ts +2 -14
  24. package/dist/commonjs/models/operations/postauthenticate.d.ts.map +1 -1
  25. package/dist/commonjs/models/operations/postauthenticate.js +6 -6
  26. package/dist/commonjs/models/operations/postauthenticate.js.map +1 -1
  27. package/dist/commonjs/types/defaultToZeroValue.d.ts +7 -1
  28. package/dist/commonjs/types/defaultToZeroValue.d.ts.map +1 -1
  29. package/dist/commonjs/types/defaultToZeroValue.js +9 -1
  30. package/dist/commonjs/types/defaultToZeroValue.js.map +1 -1
  31. package/dist/commonjs/types/smartUnion.d.ts.map +1 -1
  32. package/dist/commonjs/types/smartUnion.js +15 -6
  33. package/dist/commonjs/types/smartUnion.js.map +1 -1
  34. package/dist/commonjs/types/unrecognized.d.ts +7 -1
  35. package/dist/commonjs/types/unrecognized.d.ts.map +1 -1
  36. package/dist/commonjs/types/unrecognized.js +9 -1
  37. package/dist/commonjs/types/unrecognized.js.map +1 -1
  38. package/dist/esm/__tests__/zones.test.js +2 -5
  39. package/dist/esm/__tests__/zones.test.js.map +1 -1
  40. package/dist/esm/lib/config.d.ts +3 -3
  41. package/dist/esm/lib/config.js +3 -3
  42. package/dist/esm/lib/config.js.map +1 -1
  43. package/dist/esm/lib/encodings.d.ts +1 -0
  44. package/dist/esm/lib/encodings.d.ts.map +1 -1
  45. package/dist/esm/lib/encodings.js +9 -0
  46. package/dist/esm/lib/encodings.js.map +1 -1
  47. package/dist/esm/models/components/mfarequiredresponse.d.ts +2 -8
  48. package/dist/esm/models/components/mfarequiredresponse.d.ts.map +1 -1
  49. package/dist/esm/models/components/mfarequiredresponse.js +1 -6
  50. package/dist/esm/models/components/mfarequiredresponse.js.map +1 -1
  51. package/dist/esm/models/components/passwordrequiredresponse.d.ts +1 -8
  52. package/dist/esm/models/components/passwordrequiredresponse.d.ts.map +1 -1
  53. package/dist/esm/models/components/passwordrequiredresponse.js +1 -7
  54. package/dist/esm/models/components/passwordrequiredresponse.js.map +1 -1
  55. package/dist/esm/models/components/samlloginrequiredresponse.d.ts +1 -8
  56. package/dist/esm/models/components/samlloginrequiredresponse.d.ts.map +1 -1
  57. package/dist/esm/models/components/samlloginrequiredresponse.js +1 -6
  58. package/dist/esm/models/components/samlloginrequiredresponse.js.map +1 -1
  59. package/dist/esm/models/operations/postauthenticate.d.ts +2 -14
  60. package/dist/esm/models/operations/postauthenticate.d.ts.map +1 -1
  61. package/dist/esm/models/operations/postauthenticate.js +6 -6
  62. package/dist/esm/models/operations/postauthenticate.js.map +1 -1
  63. package/dist/esm/types/defaultToZeroValue.d.ts +7 -1
  64. package/dist/esm/types/defaultToZeroValue.d.ts.map +1 -1
  65. package/dist/esm/types/defaultToZeroValue.js +9 -1
  66. package/dist/esm/types/defaultToZeroValue.js.map +1 -1
  67. package/dist/esm/types/smartUnion.d.ts.map +1 -1
  68. package/dist/esm/types/smartUnion.js +15 -6
  69. package/dist/esm/types/smartUnion.js.map +1 -1
  70. package/dist/esm/types/unrecognized.d.ts +7 -1
  71. package/dist/esm/types/unrecognized.d.ts.map +1 -1
  72. package/dist/esm/types/unrecognized.js +9 -1
  73. package/dist/esm/types/unrecognized.js.map +1 -1
  74. package/examples/package-lock.json +1 -1
  75. package/jsr.json +1 -1
  76. package/package.json +1 -1
  77. package/src/__tests__/zones.test.ts +2 -5
  78. package/src/lib/config.ts +3 -3
  79. package/src/lib/encodings.ts +13 -0
  80. package/src/models/components/mfarequiredresponse.ts +3 -15
  81. package/src/models/components/passwordrequiredresponse.ts +2 -12
  82. package/src/models/components/samlloginrequiredresponse.ts +2 -15
  83. package/src/models/operations/postauthenticate.ts +12 -24
  84. package/src/types/defaultToZeroValue.ts +9 -1
  85. package/src/types/smartUnion.ts +17 -6
  86. package/src/types/unrecognized.ts +9 -1
  87. package/tsconfig.json +1 -2
@@ -1,6 +1,12 @@
1
1
  import { type Unrecognized } from "./unrecognized.js";
2
2
  export declare function defaultToZeroValue<T>(value: T): Unrecognized<T>;
3
3
  export declare function startCountingDefaultToZeroValue(): {
4
- end: () => number;
4
+ /**
5
+ * Ends counting and returns the delta.
6
+ * @param delta - If provided, only this amount is added to the parent counter
7
+ * (used for nested unions where we only want to record the winning option's count).
8
+ * If not provided, records all counts since start().
9
+ */
10
+ end: (delta?: number) => number;
5
11
  };
6
12
  //# sourceMappingURL=defaultToZeroValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaultToZeroValue.d.ts","sourceRoot":"","sources":["../../../src/types/defaultToZeroValue.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAKpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAG/D;AAED,wBAAgB,+BAA+B;;EAU9C"}
1
+ {"version":3,"file":"defaultToZeroValue.d.ts","sourceRoot":"","sources":["../../../src/types/defaultToZeroValue.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAKpE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAG/D;AAED,wBAAgB,+BAA+B;IAI3C;;;;;OAKG;kBACW,MAAM;EAQvB"}
@@ -12,8 +12,16 @@ export function startCountingDefaultToZeroValue() {
12
12
  refCount++;
13
13
  const start = globalCount;
14
14
  return {
15
- end: () => {
15
+ /**
16
+ * Ends counting and returns the delta.
17
+ * @param delta - If provided, only this amount is added to the parent counter
18
+ * (used for nested unions where we only want to record the winning option's count).
19
+ * If not provided, records all counts since start().
20
+ */
21
+ end: (delta) => {
16
22
  const count = globalCount - start;
23
+ // Reset globalCount back to start, then add only the specified delta
24
+ globalCount = start + (delta ?? count);
17
25
  if (--refCount === 0)
18
26
  globalCount = 0;
19
27
  return count;
@@ -1 +1 @@
1
- {"version":3,"file":"defaultToZeroValue.js","sourceRoot":"","sources":["../../../src/types/defaultToZeroValue.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEpE,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,MAAM,UAAU,kBAAkB,CAAI,KAAQ;IAC5C,WAAW,EAAE,CAAC;IACd,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,+BAA+B;IAC7C,QAAQ,EAAE,CAAC;IACX,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,OAAO;QACL,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;YAClC,IAAI,EAAE,QAAQ,KAAK,CAAC;gBAAE,WAAW,GAAG,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"defaultToZeroValue.js","sourceRoot":"","sources":["../../../src/types/defaultToZeroValue.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEpE,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,MAAM,UAAU,kBAAkB,CAAI,KAAQ;IAC5C,WAAW,EAAE,CAAC;IACd,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,+BAA+B;IAC7C,QAAQ,EAAE,CAAC;IACX,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,OAAO;QACL;;;;;WAKG;QACH,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE;YACtB,MAAM,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;YAClC,qEAAqE;YACrE,WAAW,GAAG,KAAK,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC;YACvC,IAAI,EAAE,QAAQ,KAAK,CAAC;gBAAE,WAAW,GAAG,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"smartUnion.d.ts","sourceRoot":"","sources":["../../../src/types/smartUnion.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAe5B;;;GAGG;AACH,wBAAgB,UAAU,CACxB,OAAO,SAAS,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,EAE/D,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,OAAO,CACV,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzB,CAAC,CAAC,UAAU,EACZ,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACzB,CA4CA"}
1
+ {"version":3,"file":"smartUnion.d.ts","sourceRoot":"","sources":["../../../src/types/smartUnion.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAe5B;;;GAGG;AACH,wBAAgB,UAAU,CACxB,OAAO,SAAS,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,EAE/D,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,OAAO,CACV,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzB,CAAC,CAAC,UAAU,EACZ,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACzB,CAuDA"}
@@ -14,16 +14,20 @@ export function smartUnion(options) {
14
14
  return z.unknown().transform((input, ctx) => {
15
15
  const candidates = [];
16
16
  const errors = options.map(() => []);
17
+ const parentUnrecognizedCtr = startCountingUnrecognized();
18
+ const parentZeroDefaultCtr = startCountingDefaultToZeroValue();
17
19
  // Filter out invalid options
18
20
  for (const [i, option] of options.entries()) {
19
21
  const unrecognizedCtr = startCountingUnrecognized();
20
22
  const zeroDefaultCtr = startCountingDefaultToZeroValue();
21
23
  const result = option.safeParse(input);
24
+ const inexactCount = unrecognizedCtr.end();
25
+ const zeroDefaultCount = zeroDefaultCtr.end();
22
26
  if (result.success) {
23
27
  candidates.push({
24
28
  data: result.data,
25
- inexactCount: unrecognizedCtr.end(),
26
- zeroDefaultCount: zeroDefaultCtr.end(),
29
+ inexactCount,
30
+ zeroDefaultCount,
27
31
  fieldCount: -1, // We'll count this later if needed
28
32
  });
29
33
  continue;
@@ -32,6 +36,8 @@ export function smartUnion(options) {
32
36
  }
33
37
  // No valid options
34
38
  if (candidates.length === 0) {
39
+ parentUnrecognizedCtr.end(0);
40
+ parentZeroDefaultCtr.end(0);
35
41
  ctx.addIssue({
36
42
  code: "invalid_union",
37
43
  unionErrors: errors.map(issues => new z.ZodError(issues)),
@@ -39,14 +45,17 @@ export function smartUnion(options) {
39
45
  return z.NEVER;
40
46
  }
41
47
  let best = candidates[0];
42
- // Just one valid option - short circuit
43
- if (candidates.length === 1)
44
- return best.data;
45
48
  // Find the best option
46
49
  for (const candidate of candidates) {
47
- candidate.fieldCount = countFieldsRecursive(candidate.data);
50
+ // Minor optimization to avoid counting fields if there's only one candidate
51
+ if (candidates.length > 1) {
52
+ candidate.fieldCount = countFieldsRecursive(candidate.data);
53
+ }
48
54
  best = better(candidate, best);
49
55
  }
56
+ // The cost of this union should be the cost of the best candidate not all the candidates
57
+ parentUnrecognizedCtr.end(best.inexactCount);
58
+ parentZeroDefaultCtr.end(best.zeroDefaultCount);
50
59
  return best.data;
51
60
  });
52
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"smartUnion.js","sourceRoot":"","sources":["../../../src/types/smartUnion.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,yBAAyB;AACzB,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAY9D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAGxB,OAAgB;I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AC,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS;QACX,CAAC;QAED,kCAAkC;QAClC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;QAC1B,IACE,KAAK,KAAK,IAAI;eACX,IAAI,KAAK,QAAQ;eACjB,IAAI,KAAK,QAAQ;eACjB,IAAI,KAAK,SAAS;eAClB,IAAI,KAAK,QAAQ;eACjB,KAAK,YAAY,IAAI;eACrB,KAAK,YAAY,OAAO,EAC3B,CAAC;YACD,UAAU,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QAED,gBAAgB;QAChB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;YACrB,SAAS;QACX,CAAC;QAED,iBAAiB;QACjB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -4,7 +4,13 @@ export type Unrecognized<T> = T & {
4
4
  };
5
5
  declare function unrecognized<T>(value: T): Unrecognized<T>;
6
6
  export declare function startCountingUnrecognized(): {
7
- end: () => number;
7
+ /**
8
+ * Ends counting and returns the delta.
9
+ * @param delta - If provided, only this amount is added to the parent counter
10
+ * (used for nested unions where we only want to record the winning option's count).
11
+ * If not provided, records all counts since start().
12
+ */
13
+ end: (delta?: number) => number;
8
14
  };
9
15
  export { unrecognized };
10
16
  //# sourceMappingURL=unrecognized.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unrecognized.d.ts","sourceRoot":"","sources":["../../../src/types/unrecognized.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,CAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE,iBAAS,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAGlD;AAID,wBAAgB,yBAAyB;;EAUxC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"unrecognized.d.ts","sourceRoot":"","sources":["../../../src/types/unrecognized.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,CAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE,iBAAS,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAGlD;AAID,wBAAgB,yBAAyB;IAIrC;;;;;OAKG;kBACW,MAAM;EAQvB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -11,8 +11,16 @@ export function startCountingUnrecognized() {
11
11
  refCount++;
12
12
  const start = globalCount;
13
13
  return {
14
- end: () => {
14
+ /**
15
+ * Ends counting and returns the delta.
16
+ * @param delta - If provided, only this amount is added to the parent counter
17
+ * (used for nested unions where we only want to record the winning option's count).
18
+ * If not provided, records all counts since start().
19
+ */
20
+ end: (delta) => {
15
21
  const count = globalCount - start;
22
+ // Reset globalCount back to start, then add only the specified delta
23
+ globalCount = start + (delta ?? count);
16
24
  if (--refCount === 0)
17
25
  globalCount = 0;
18
26
  return count;
@@ -1 +1 @@
1
- {"version":3,"file":"unrecognized.js","sourceRoot":"","sources":["../../../src/types/unrecognized.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,SAAS,YAAY,CAAI,KAAQ;IAC/B,WAAW,EAAE,CAAC;IACd,OAAO,KAAwB,CAAC;AAClC,CAAC;AAED,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,MAAM,UAAU,yBAAyB;IACvC,QAAQ,EAAE,CAAC;IACX,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,OAAO;QACL,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;YAClC,IAAI,EAAE,QAAQ,KAAK,CAAC;gBAAE,WAAW,GAAG,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"unrecognized.js","sourceRoot":"","sources":["../../../src/types/unrecognized.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,SAAS,YAAY,CAAI,KAAQ;IAC/B,WAAW,EAAE,CAAC;IACd,OAAO,KAAwB,CAAC;AAClC,CAAC;AAED,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,MAAM,UAAU,yBAAyB;IACvC,QAAQ,EAAE,CAAC;IACX,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,OAAO;QACL;;;;;WAKG;QACH,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE;YACtB,MAAM,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;YAClC,qEAAqE;YACrE,WAAW,GAAG,KAAK,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC;YACvC,IAAI,EAAE,QAAQ,KAAK,CAAC;gBAAE,WAAW,GAAG,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "..": {
20
20
  "name": "@greensecurity/javascript-sdk",
21
- "version": "0.42.13",
21
+ "version": "0.43.1-beta.0",
22
22
  "dependencies": {
23
23
  "zod": "^3.25.0 || ^4.0.0"
24
24
  },
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@greensecurity/javascript-sdk",
5
- "version": "0.42.13",
5
+ "version": "0.43.1-beta.0",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./models/errors": "./src/models/errors/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greensecurity/javascript-sdk",
3
- "version": "0.42.14-beta.0",
3
+ "version": "0.43.1-beta.1",
4
4
  "author": "Green Security LLC",
5
5
  "type": "module",
6
6
  "tshy": {
@@ -36,10 +36,7 @@ test("Zones List Or Search Security Zones", async () => {
36
36
  },
37
37
  items: [
38
38
  {
39
- facility: {
40
- contacts: null,
41
- vendorGuestPolicy: null,
42
- },
39
+ facility: {},
43
40
  },
44
41
  {
45
42
  facility: {},
@@ -61,7 +58,7 @@ test("Zones Security Zone Checkin", async () => {
61
58
 
62
59
  const result = await greenSecurity.zones.securityZoneCheckin({
63
60
  qrCode: "<value>",
64
- zoneId: 579390,
61
+ zoneId: 423655,
65
62
  });
66
63
  expect(result).toBeDefined();
67
64
  expect(result).toEqual({});
package/src/lib/config.ts CHANGED
@@ -80,8 +80,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
80
80
  export const SDK_METADATA = {
81
81
  language: "typescript",
82
82
  openapiDocVersion: "0.0.10",
83
- sdkVersion: "0.42.13",
84
- genVersion: "2.763.3",
83
+ sdkVersion: "0.43.1-beta.0",
84
+ genVersion: "2.773.3",
85
85
  userAgent:
86
- "speakeasy-sdk/typescript 0.42.13 2.763.3 0.0.10 @greensecurity/javascript-sdk",
86
+ "speakeasy-sdk/typescript 0.43.1-beta.0 2.773.3 0.0.10 @greensecurity/javascript-sdk",
87
87
  } as const;
@@ -427,6 +427,7 @@ export function queryJoin(...args: (string | undefined)[]): string {
427
427
  type QueryEncoderOptions = {
428
428
  explode?: boolean;
429
429
  charEncoding?: "percent" | "none";
430
+ allowEmptyValue?: string[];
430
431
  };
431
432
 
432
433
  type QueryEncoder = (
@@ -451,7 +452,19 @@ export function queryEncoder(f: QueryEncoder): BulkQueryEncoder {
451
452
  charEncoding: options?.charEncoding ?? "percent",
452
453
  };
453
454
 
455
+ const allowEmptySet = new Set(options?.allowEmptyValue ?? []);
456
+
454
457
  const encoded = Object.entries(values).map(([key, value]) => {
458
+ if (allowEmptySet.has(key)) {
459
+ if (
460
+ value === undefined
461
+ || value === null
462
+ || value === ""
463
+ || (Array.isArray(value) && value.length === 0)
464
+ ) {
465
+ return `${encodeURIComponent(key)}=`;
466
+ }
467
+ }
455
468
  return f(key, value, opts);
456
469
  });
457
470
  return queryJoin(...encoded);
@@ -6,18 +6,11 @@ import * as z from "zod/v3";
6
6
  import { remap as remap$ } from "../../lib/primitives.js";
7
7
  import { safeParse } from "../../lib/schemas.js";
8
8
  import * as openEnums from "../../types/enums.js";
9
- import { ClosedEnum, OpenEnum } from "../../types/enums.js";
9
+ import { OpenEnum } from "../../types/enums.js";
10
10
  import { Result as SafeParseResult } from "../../types/fp.js";
11
11
  import * as types from "../../types/primitives.js";
12
12
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
13
13
 
14
- export const MfaRequiredResponseRequires = {
15
- MfaCode: "mfa_code",
16
- } as const;
17
- export type MfaRequiredResponseRequires = ClosedEnum<
18
- typeof MfaRequiredResponseRequires
19
- >;
20
-
21
14
  export const MfaMethod = {
22
15
  Text: "text",
23
16
  Email: "email",
@@ -32,7 +25,7 @@ export type MfaMethod = OpenEnum<typeof MfaMethod>;
32
25
  * If the `mfa_method` is text or email, it's best to show helper text to the user to notify them that a code was sent via mobile or email and they should enter it to proceed.
33
26
  */
34
27
  export type MfaRequiredResponse = {
35
- requires: MfaRequiredResponseRequires;
28
+ requires: "mfa_code";
36
29
  success: boolean;
37
30
  /**
38
31
  * Error describing the exact condition of what further steps are needed to finish the login process.
@@ -45,11 +38,6 @@ export type MfaRequiredResponse = {
45
38
  mfaMethod?: MfaMethod | undefined;
46
39
  };
47
40
 
48
- /** @internal */
49
- export const MfaRequiredResponseRequires$inboundSchema: z.ZodNativeEnum<
50
- typeof MfaRequiredResponseRequires
51
- > = z.nativeEnum(MfaRequiredResponseRequires);
52
-
53
41
  /** @internal */
54
42
  export const MfaMethod$inboundSchema: z.ZodType<
55
43
  MfaMethod,
@@ -63,7 +51,7 @@ export const MfaRequiredResponse$inboundSchema: z.ZodType<
63
51
  z.ZodTypeDef,
64
52
  unknown
65
53
  > = z.object({
66
- requires: MfaRequiredResponseRequires$inboundSchema,
54
+ requires: types.literal("mfa_code"),
67
55
  success: types.boolean(),
68
56
  error: types.string(),
69
57
  mobile_phone: types.optional(types.string()),
@@ -4,21 +4,15 @@
4
4
 
5
5
  import * as z from "zod/v3";
6
6
  import { safeParse } from "../../lib/schemas.js";
7
- import { ClosedEnum } from "../../types/enums.js";
8
7
  import { Result as SafeParseResult } from "../../types/fp.js";
9
8
  import * as types from "../../types/primitives.js";
10
9
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
10
 
12
- export const Requires = {
13
- Password: "password",
14
- } as const;
15
- export type Requires = ClosedEnum<typeof Requires>;
16
-
17
11
  /**
18
12
  * The response is sent when the email address provided requires a password (no SAML login).
19
13
  */
20
14
  export type PasswordRequiredResponse = {
21
- requires: Requires;
15
+ requires: "password";
22
16
  success: boolean;
23
17
  /**
24
18
  * Error describing the exact condition of what further steps are needed to finish the login process.
@@ -26,17 +20,13 @@ export type PasswordRequiredResponse = {
26
20
  error: string;
27
21
  };
28
22
 
29
- /** @internal */
30
- export const Requires$inboundSchema: z.ZodNativeEnum<typeof Requires> = z
31
- .nativeEnum(Requires);
32
-
33
23
  /** @internal */
34
24
  export const PasswordRequiredResponse$inboundSchema: z.ZodType<
35
25
  PasswordRequiredResponse,
36
26
  z.ZodTypeDef,
37
27
  unknown
38
28
  > = z.object({
39
- requires: Requires$inboundSchema,
29
+ requires: types.literal("password"),
40
30
  success: types.boolean(),
41
31
  error: types.string(),
42
32
  });
@@ -5,18 +5,10 @@
5
5
  import * as z from "zod/v3";
6
6
  import { remap as remap$ } from "../../lib/primitives.js";
7
7
  import { safeParse } from "../../lib/schemas.js";
8
- import { ClosedEnum } from "../../types/enums.js";
9
8
  import { Result as SafeParseResult } from "../../types/fp.js";
10
9
  import * as types from "../../types/primitives.js";
11
10
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
12
11
 
13
- export const SamlLoginRequiredResponseRequires = {
14
- SamlLogin: "saml_login",
15
- } as const;
16
- export type SamlLoginRequiredResponseRequires = ClosedEnum<
17
- typeof SamlLoginRequiredResponseRequires
18
- >;
19
-
20
12
  /**
21
13
  * The email address provided must complete SAML authentication at the provided `sso_url` which encodes the `return_url` that was sent as part of the request.
22
14
  *
@@ -25,7 +17,7 @@ export type SamlLoginRequiredResponseRequires = ClosedEnum<
25
17
  * The user will complete their SAML login at the external IdP and the browser will be redirected to your selected `return_url` with an extra query string parameter called `user_token`. That token is equivalent to the user login and can be used in the `/users/me` endpoint to get user details.
26
18
  */
27
19
  export type SamlLoginRequiredResponse = {
28
- requires: SamlLoginRequiredResponseRequires;
20
+ requires: "saml_login";
29
21
  success: boolean;
30
22
  error: string;
31
23
  /**
@@ -38,18 +30,13 @@ export type SamlLoginRequiredResponse = {
38
30
  ssoUrl: string;
39
31
  };
40
32
 
41
- /** @internal */
42
- export const SamlLoginRequiredResponseRequires$inboundSchema: z.ZodNativeEnum<
43
- typeof SamlLoginRequiredResponseRequires
44
- > = z.nativeEnum(SamlLoginRequiredResponseRequires);
45
-
46
33
  /** @internal */
47
34
  export const SamlLoginRequiredResponse$inboundSchema: z.ZodType<
48
35
  SamlLoginRequiredResponse,
49
36
  z.ZodTypeDef,
50
37
  unknown
51
38
  > = z.object({
52
- requires: SamlLoginRequiredResponseRequires$inboundSchema,
39
+ requires: types.literal("saml_login"),
53
40
  success: types.boolean(),
54
41
  error: types.string(),
55
42
  sso_instructions: types.optional(types.string()),
@@ -20,15 +20,15 @@ export type PostAuthenticateRequestBody =
20
20
  * The request has been accepted for processing, but the processing has not been completed. The request might be processed later.
21
21
  */
22
22
  export type PostAuthenticateResponseBody =
23
- | (components.SamlLoginRequiredResponse & { requires: "saml_login" })
24
- | (components.MfaRequiredResponse & { requires: "mfa_code" })
25
- | (components.PasswordRequiredResponse & { requires: "password" });
23
+ | components.MfaRequiredResponse
24
+ | components.SamlLoginRequiredResponse
25
+ | components.PasswordRequiredResponse;
26
26
 
27
27
  export type PostAuthenticateResponse =
28
28
  | components.User
29
- | (components.SamlLoginRequiredResponse & { requires: "saml_login" })
30
- | (components.MfaRequiredResponse & { requires: "mfa_code" })
31
- | (components.PasswordRequiredResponse & { requires: "password" });
29
+ | components.MfaRequiredResponse
30
+ | components.SamlLoginRequiredResponse
31
+ | components.PasswordRequiredResponse;
32
32
 
33
33
  /** @internal */
34
34
  export type PostAuthenticateRequestBody$Outbound =
@@ -61,15 +61,9 @@ export const PostAuthenticateResponseBody$inboundSchema: z.ZodType<
61
61
  z.ZodTypeDef,
62
62
  unknown
63
63
  > = z.union([
64
- components.SamlLoginRequiredResponse$inboundSchema.and(
65
- z.object({ requires: z.literal("saml_login") }),
66
- ),
67
- components.MfaRequiredResponse$inboundSchema.and(
68
- z.object({ requires: z.literal("mfa_code") }),
69
- ),
70
- components.PasswordRequiredResponse$inboundSchema.and(
71
- z.object({ requires: z.literal("password") }),
72
- ),
64
+ components.MfaRequiredResponse$inboundSchema,
65
+ components.SamlLoginRequiredResponse$inboundSchema,
66
+ components.PasswordRequiredResponse$inboundSchema,
73
67
  ]);
74
68
 
75
69
  export function postAuthenticateResponseBodyFromJSON(
@@ -90,15 +84,9 @@ export const PostAuthenticateResponse$inboundSchema: z.ZodType<
90
84
  > = smartUnion([
91
85
  components.User$inboundSchema,
92
86
  z.union([
93
- components.SamlLoginRequiredResponse$inboundSchema.and(
94
- z.object({ requires: z.literal("saml_login") }),
95
- ),
96
- components.MfaRequiredResponse$inboundSchema.and(
97
- z.object({ requires: z.literal("mfa_code") }),
98
- ),
99
- components.PasswordRequiredResponse$inboundSchema.and(
100
- z.object({ requires: z.literal("password") }),
101
- ),
87
+ components.MfaRequiredResponse$inboundSchema,
88
+ components.SamlLoginRequiredResponse$inboundSchema,
89
+ components.PasswordRequiredResponse$inboundSchema,
102
90
  ]),
103
91
  ]);
104
92
 
@@ -16,8 +16,16 @@ export function startCountingDefaultToZeroValue() {
16
16
  refCount++;
17
17
  const start = globalCount;
18
18
  return {
19
- end: () => {
19
+ /**
20
+ * Ends counting and returns the delta.
21
+ * @param delta - If provided, only this amount is added to the parent counter
22
+ * (used for nested unions where we only want to record the winning option's count).
23
+ * If not provided, records all counts since start().
24
+ */
25
+ end: (delta?: number) => {
20
26
  const count = globalCount - start;
27
+ // Reset globalCount back to start, then add only the specified delta
28
+ globalCount = start + (delta ?? count);
21
29
  if (--refCount === 0) globalCount = 0;
22
30
  return count;
23
31
  },
@@ -35,16 +35,21 @@ export function smartUnion<
35
35
  const candidates: Candidate[] = [];
36
36
  const errors: z.ZodIssue[][] = options.map(() => []);
37
37
 
38
+ const parentUnrecognizedCtr = startCountingUnrecognized();
39
+ const parentZeroDefaultCtr = startCountingDefaultToZeroValue();
40
+
38
41
  // Filter out invalid options
39
42
  for (const [i, option] of options.entries()) {
40
43
  const unrecognizedCtr = startCountingUnrecognized();
41
44
  const zeroDefaultCtr = startCountingDefaultToZeroValue();
42
45
  const result = option.safeParse(input);
46
+ const inexactCount = unrecognizedCtr.end();
47
+ const zeroDefaultCount = zeroDefaultCtr.end();
43
48
  if (result.success) {
44
49
  candidates.push({
45
50
  data: result.data,
46
- inexactCount: unrecognizedCtr.end(),
47
- zeroDefaultCount: zeroDefaultCtr.end(),
51
+ inexactCount,
52
+ zeroDefaultCount,
48
53
  fieldCount: -1, // We'll count this later if needed
49
54
  });
50
55
  continue;
@@ -54,6 +59,8 @@ export function smartUnion<
54
59
 
55
60
  // No valid options
56
61
  if (candidates.length === 0) {
62
+ parentUnrecognizedCtr.end(0);
63
+ parentZeroDefaultCtr.end(0);
57
64
  ctx.addIssue({
58
65
  code: "invalid_union",
59
66
  unionErrors: errors.map(issues => new z.ZodError(issues)),
@@ -63,15 +70,19 @@ export function smartUnion<
63
70
 
64
71
  let best = candidates[0]!;
65
72
 
66
- // Just one valid option - short circuit
67
- if (candidates.length === 1) return best.data;
68
-
69
73
  // Find the best option
70
74
  for (const candidate of candidates) {
71
- candidate.fieldCount = countFieldsRecursive(candidate.data);
75
+ // Minor optimization to avoid counting fields if there's only one candidate
76
+ if (candidates.length > 1) {
77
+ candidate.fieldCount = countFieldsRecursive(candidate.data);
78
+ }
72
79
  best = better(candidate, best);
73
80
  }
74
81
 
82
+ // The cost of this union should be the cost of the best candidate not all the candidates
83
+ parentUnrecognizedCtr.end(best.inexactCount);
84
+ parentZeroDefaultCtr.end(best.zeroDefaultCount);
85
+
75
86
  return best.data;
76
87
  }) as any;
77
88
  }
@@ -16,8 +16,16 @@ export function startCountingUnrecognized() {
16
16
  refCount++;
17
17
  const start = globalCount;
18
18
  return {
19
- end: () => {
19
+ /**
20
+ * Ends counting and returns the delta.
21
+ * @param delta - If provided, only this amount is added to the parent counter
22
+ * (used for nested unions where we only want to record the winning option's count).
23
+ * If not provided, records all counts since start().
24
+ */
25
+ end: (delta?: number) => {
20
26
  const count = globalCount - start;
27
+ // Reset globalCount back to start, then add only the specified delta
28
+ globalCount = start + (delta ?? count);
21
29
  if (--refCount === 0) globalCount = 0;
22
30
  return count;
23
31
  },
package/tsconfig.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "incremental": true,
4
- "tsBuildInfoFile": ".tsbuildinfo",
3
+ "incremental": false,
5
4
  "target": "ES2020",
6
5
  "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
6
  "jsx": "react-jsx",