@criipto/signatures 1.0.0 → 1.1.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.
- package/dist/graphql-sdk.d.ts +5 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -1
- package/dist/json-serializer.d.ts +3 -0
- package/dist/json-serializer.js +58 -0
- package/package.json +10 -8
- package/codegen.ts +0 -29
- package/tsconfig.json +0 -10
package/dist/graphql-sdk.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
/// <reference types="whatwg-fetch" />
|
|
2
3
|
import { GraphQLClient } from 'graphql-request';
|
|
3
4
|
import * as Dom from 'graphql-request/dist/types.dom';
|
|
@@ -21,7 +22,7 @@ export type Scalars = {
|
|
|
21
22
|
Boolean: boolean;
|
|
22
23
|
Int: number;
|
|
23
24
|
Float: number;
|
|
24
|
-
Blob:
|
|
25
|
+
Blob: Buffer;
|
|
25
26
|
Date: string;
|
|
26
27
|
DateTime: string;
|
|
27
28
|
URI: string;
|
|
@@ -769,7 +770,7 @@ export type BasicDocumentFragment = {
|
|
|
769
770
|
};
|
|
770
771
|
export type SignedDocumentFragment = {
|
|
771
772
|
__typename?: 'PdfDocument';
|
|
772
|
-
blob?:
|
|
773
|
+
blob?: Buffer | null;
|
|
773
774
|
signatures?: Array<{
|
|
774
775
|
__typename: 'DrawableSignature';
|
|
775
776
|
signatory?: {
|
|
@@ -1144,7 +1145,7 @@ export type CloseSignatureOrderMutation = {
|
|
|
1144
1145
|
documents: Array<{
|
|
1145
1146
|
__typename: 'PdfDocument';
|
|
1146
1147
|
id: string;
|
|
1147
|
-
blob?:
|
|
1148
|
+
blob?: Buffer | null;
|
|
1148
1149
|
signatures?: Array<{
|
|
1149
1150
|
__typename: 'DrawableSignature';
|
|
1150
1151
|
signatory?: {
|
|
@@ -1391,7 +1392,7 @@ export type SignatureOrderWithDocumentsQuery = {
|
|
|
1391
1392
|
documents: Array<{
|
|
1392
1393
|
__typename: 'PdfDocument';
|
|
1393
1394
|
id: string;
|
|
1394
|
-
blob?:
|
|
1395
|
+
blob?: Buffer | null;
|
|
1395
1396
|
signatures?: Array<{
|
|
1396
1397
|
__typename: 'DrawableSignature';
|
|
1397
1398
|
signatory?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { GraphQLClient } from 'graphql-request';
|
|
2
3
|
import { AddSignatoriesInput, AddSignatoryInput, ChangeSignatoryInput, CloseSignatureOrderInput, CreateSignatureOrderInput, Sdk, SignActingAsInput } from './graphql-sdk';
|
|
3
4
|
import * as Types from './graphql-sdk';
|
|
@@ -167,7 +168,7 @@ export declare class CriiptoSignatures {
|
|
|
167
168
|
documents: {
|
|
168
169
|
__typename: "PdfDocument";
|
|
169
170
|
id: string;
|
|
170
|
-
blob?:
|
|
171
|
+
blob?: Buffer | null | undefined;
|
|
171
172
|
signatures?: ({
|
|
172
173
|
__typename: "DrawableSignature";
|
|
173
174
|
signatory?: {
|
package/dist/index.js
CHANGED
|
@@ -22,19 +22,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
exports.CriiptoSignatures = exports.CriiptoSignaturesTypes = void 0;
|
|
27
30
|
const graphql_request_1 = require("graphql-request");
|
|
28
31
|
const graphql_sdk_1 = require("./graphql-sdk");
|
|
29
32
|
const Types = __importStar(require("./graphql-sdk"));
|
|
30
33
|
exports.CriiptoSignaturesTypes = Types;
|
|
34
|
+
const json_serializer_1 = __importDefault(require("./json-serializer"));
|
|
31
35
|
class CriiptoSignatures {
|
|
32
36
|
constructor(clientId, clientSecret) {
|
|
33
37
|
this.client = new graphql_request_1.GraphQLClient('https://signatures-api.criipto.com/v1/graphql', {
|
|
34
38
|
headers: {
|
|
35
39
|
Authorization: `Basic ${Buffer.from(clientId + ':' + clientSecret).toString('base64')}`,
|
|
36
40
|
"Criipto-Sdk": "criipto-signatures-nodejs"
|
|
37
|
-
}
|
|
41
|
+
},
|
|
42
|
+
jsonSerializer: json_serializer_1.default
|
|
38
43
|
});
|
|
39
44
|
this.sdk = (0, graphql_sdk_1.getSdk)(this.client);
|
|
40
45
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function tryBase64Decode(input) {
|
|
4
|
+
try {
|
|
5
|
+
const decoded = Buffer.from(input, 'base64');
|
|
6
|
+
if (decoded.toString('base64') === input)
|
|
7
|
+
return decoded;
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function parseBlobs(input) {
|
|
15
|
+
if (Array.isArray(input)) {
|
|
16
|
+
return input.map(i => parseBlobs(i));
|
|
17
|
+
}
|
|
18
|
+
if (input instanceof Object && !Array.isArray(input)) {
|
|
19
|
+
return Object.keys(input).reduce((memo, key) => {
|
|
20
|
+
if (key === 'blob') {
|
|
21
|
+
const decoded = tryBase64Decode(input[key]);
|
|
22
|
+
if (decoded) {
|
|
23
|
+
memo[key] = decoded;
|
|
24
|
+
return memo;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (input[key] instanceof Object) {
|
|
28
|
+
memo[key] = parseBlobs(input[key]);
|
|
29
|
+
return memo;
|
|
30
|
+
}
|
|
31
|
+
memo[key] = input[key];
|
|
32
|
+
return memo;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
return input;
|
|
36
|
+
}
|
|
37
|
+
const jsonSerializer = {
|
|
38
|
+
stringify(obj) {
|
|
39
|
+
return JSON.stringify(obj, (key, value) => {
|
|
40
|
+
if (value instanceof Object && !Array.isArray(value)) {
|
|
41
|
+
return Object.keys(value).reduce((memo, key) => {
|
|
42
|
+
if (Buffer.isBuffer(value[key])) {
|
|
43
|
+
memo[key] = value[key].toString('base64');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
memo[key] = value[key];
|
|
47
|
+
}
|
|
48
|
+
return memo;
|
|
49
|
+
}, {});
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
parse(obj) {
|
|
55
|
+
return parseBlobs(JSON.parse(obj));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.default = jsonSerializer;
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criipto/signatures",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Node.js SDK for Criipto Signatures",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"codegen": "graphql-codegen",
|
|
10
|
-
"test": "npm run test:integration",
|
|
11
|
-
"test:integration": "npm run build && cp src/test/integration/sample.pdf dist/test/integration/sample.pdf && ava dist/test
|
|
10
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
11
|
+
"test:integration": "npm run build && cp src/test/integration/sample.pdf dist/test/integration/sample.pdf && ava dist/test/integration/*.test.js --timeout=60s --verbose",
|
|
12
|
+
"test:unit": "npm run build && ava dist/test/unit/*.test.js",
|
|
12
13
|
"clean": "rm -rf dist/",
|
|
14
|
+
"check": "tsc --noEmit",
|
|
13
15
|
"build": "tsc"
|
|
14
16
|
},
|
|
15
17
|
"repository": {
|
|
@@ -47,10 +49,10 @@
|
|
|
47
49
|
},
|
|
48
50
|
"ava": {
|
|
49
51
|
"typescript": {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
"rewritePaths": {
|
|
53
|
+
"test/": "dist/test/"
|
|
54
|
+
},
|
|
55
|
+
"compile": false
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
}
|
package/codegen.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
2
|
-
|
|
3
|
-
const config: CodegenConfig = {
|
|
4
|
-
schema: 'https://signatures-api.criipto.com/v1/graphql',
|
|
5
|
-
generates: {
|
|
6
|
-
'src/graphql-sdk.ts': {
|
|
7
|
-
documents: './src/*.graphql',
|
|
8
|
-
plugins: [
|
|
9
|
-
'typescript',
|
|
10
|
-
'typescript-operations',
|
|
11
|
-
'typescript-graphql-request'
|
|
12
|
-
],
|
|
13
|
-
config: {
|
|
14
|
-
strictScalars: true,
|
|
15
|
-
namingConvention: {
|
|
16
|
-
enumValues: 'keep'
|
|
17
|
-
},
|
|
18
|
-
enumsAsTypes: true,
|
|
19
|
-
scalars: {
|
|
20
|
-
Blob: 'string',
|
|
21
|
-
Date: 'string',
|
|
22
|
-
DateTime: 'string',
|
|
23
|
-
URI: 'string'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export default config;
|