@0to1pay/fulfillment-sdk 2.0.0 → 2.2.0

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.
@@ -1,8 +1,4 @@
1
- import { createHash, randomUUID } from 'node:crypto';
2
1
  import canonicalizeModule from 'canonicalize';
3
- export const id = randomUUID;
4
- export const iso = (value) => new Date(value).toISOString();
5
- export const now = () => new Date().toISOString();
6
2
  export const canonical = (value) => {
7
3
  const stringify = canonicalizeModule;
8
4
  const result = stringify(value);
@@ -10,35 +6,3 @@ export const canonical = (value) => {
10
6
  throw new Error('Unable to canonicalize JSON');
11
7
  return result;
12
8
  };
13
- export const sha = (bytes) => createHash('sha256').update(bytes).digest();
14
- export const digest = (value) => sha(canonical(value));
15
- export const scope = (value) => ({
16
- merchant_id: value.merchant_id, project_id: value.project_id, environment: value.environment,
17
- });
18
- export const params = (value) => [value.merchant_id, value.project_id, value.environment];
19
- export const SCOPE = 'merchant_id=$1 AND project_id=$2 AND environment=$3';
20
- export const money = (asset, amount, scale) => ({ asset, amount_atomic: amount, scale });
21
- export class ApiError extends Error {
22
- status;
23
- code;
24
- constructor(status, code, message = code) {
25
- super(message);
26
- this.status = status;
27
- this.code = code;
28
- }
29
- }
30
- export function requireValue(value, code = 'NOT_FOUND') {
31
- if (value === undefined || value === null)
32
- throw new ApiError(404, code, 'Resource not found');
33
- return value;
34
- }
35
- export function requireCondition(condition, status, code, message) {
36
- if (!condition)
37
- throw new ApiError(status, code, message);
38
- }
39
- export const conflict = (condition, code = 'RESOURCE_CONFLICT') => requireCondition(condition, 409, code);
40
- export const invalid = (condition, code = 'INVALID_REQUEST') => requireCondition(condition, 400, code);
41
- export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
42
- export function isChainProvider(provider) {
43
- return provider === 'evm' || provider === 'solana' || provider === 'tron';
44
- }