@flintpay/node 0.3.0-beta.1 → 0.4.0-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flintpay/node",
3
- "version": "0.3.0-beta.1",
3
+ "version": "0.4.0-beta.1",
4
4
  "description": "Flint Public API server SDK",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/runtime.js CHANGED
@@ -1549,7 +1549,8 @@ export class Runtime {
1549
1549
  bad('input', 'expected an object');
1550
1550
  if (!options || typeof options !== 'object' || Array.isArray(options))
1551
1551
  bad('options', 'expected an object');
1552
- const op = this.contract.operations.find((v) => v.id === id);
1552
+ const { operations, apiVersion } = this.contract;
1553
+ const op = operations.find((v) => v.id === id);
1553
1554
  if (!op)
1554
1555
  return bad('operation', 'operation is not included in this SDK');
1555
1556
  const start = performance.now();
@@ -1591,7 +1592,20 @@ export class Runtime {
1591
1592
  op.idempotency?.header.toLowerCase() === p.name.toLowerCase()) {
1592
1593
  value =
1593
1594
  options.idempotencyKey ??
1594
- Object.entries(options.headers ?? {}).find(([name]) => name.toLowerCase() === p.name.toLowerCase())?.[1];
1595
+ Object.entries(options.headers ?? {}).find(([name]) => name.toLowerCase() === p.name.toLowerCase())?.[1] ??
1596
+ (op.idempotency?.auto ? randomUUID() : undefined);
1597
+ }
1598
+ if (p.in === 'header' &&
1599
+ [op.conditional?.header, apiVersion?.header].some((header) => header?.toLowerCase() === p.name.toLowerCase())) {
1600
+ // Match the final header precedence before validating the wire value.
1601
+ for (const [name, supplied] of Object.entries(options.headers ?? {}))
1602
+ if (name.toLowerCase() === p.name.toLowerCase())
1603
+ value = supplied;
1604
+ if (apiVersion?.header.toLowerCase() === p.name.toLowerCase())
1605
+ value = apiVersion.value;
1606
+ if (op.conditional?.header.toLowerCase() === p.name.toLowerCase() &&
1607
+ options.ifMatch !== undefined)
1608
+ value = options.ifMatch;
1595
1609
  }
1596
1610
  if (value === undefined) {
1597
1611
  if (p.required)
@@ -1679,8 +1693,8 @@ export class Runtime {
1679
1693
  throw new SdkError('authentication', 'Explicit API credentials are required');
1680
1694
  setHeader(this.contract.auth.header, this.contract.auth.type === 'bearer' ? `Bearer ${this.options.token}` : this.options.token);
1681
1695
  }
1682
- if (this.contract.apiVersion)
1683
- setHeader(this.contract.apiVersion.header, this.contract.apiVersion.value);
1696
+ if (apiVersion)
1697
+ setHeader(apiVersion.header, apiVersion.value);
1684
1698
  if (options.ifMatch !== undefined) {
1685
1699
  if (!op.conditional)
1686
1700
  bad('ifMatch', 'operation does not declare conditional requests');