@pinata/sdk 1.2.1 → 2.0.0-beta.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.
Files changed (74) hide show
  1. package/.babelrc +1 -1
  2. package/.eslintrc +7 -7
  3. package/.husky/pre-commit +6 -0
  4. package/.nvmrc +1 -1
  5. package/README.md +3 -3
  6. package/lib/pinata-sdk.js +494 -468
  7. package/lib/pinata-sdk.min.js +5 -5
  8. package/package.json +83 -71
  9. package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
  10. package/src/commands/data/index.ts +4 -0
  11. package/src/commands/data/pinList/pinList.ts +77 -0
  12. package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
  13. package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
  14. package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
  15. package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
  16. package/src/commands/pinning/index.ts +8 -0
  17. package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
  18. package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +27 -11
  19. package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +14 -19
  20. package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
  21. package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
  22. package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
  23. package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
  24. package/src/{constants.js → constants.ts} +0 -0
  25. package/src/index.ts +120 -0
  26. package/src/third-party/base-path-converter.d.ts +3 -0
  27. package/src/third-party/is-ipfs.d.ts +5 -0
  28. package/src/third-party/recursive-fs.d.ts +5 -0
  29. package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
  30. package/src/util/{validators.js → validators.ts} +14 -33
  31. package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
  32. package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
  33. package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
  34. package/test/commands/data/pinlist-sample-api.ts +540 -0
  35. package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
  36. package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
  37. package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
  38. package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
  39. package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +5 -7
  40. package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
  41. package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
  42. package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
  43. package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
  44. package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
  45. package/test/util/validators.test.ts +234 -0
  46. package/tsconfig.json +2 -2
  47. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
  48. package/types/commands/data/index.d.ts +4 -0
  49. package/types/commands/data/pinList/pinList.d.ts +45 -8
  50. package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
  51. package/types/commands/data/testAuthentication.d.ts +5 -7
  52. package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
  53. package/types/commands/pinning/hashMetadata.d.ts +3 -9
  54. package/types/commands/pinning/index.d.ts +8 -0
  55. package/types/commands/pinning/pinByHash.d.ts +14 -9
  56. package/types/commands/pinning/pinFileToIPFS.d.ts +25 -1
  57. package/types/commands/pinning/pinFromFS.d.ts +3 -9
  58. package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
  59. package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
  60. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
  61. package/types/commands/pinning/unpin.d.ts +2 -8
  62. package/types/constants.d.ts +2 -2
  63. package/types/index.d.ts +37 -165
  64. package/types/util/errorResponse.d.ts +1 -1
  65. package/types/util/validators.d.ts +20 -37
  66. package/webpack.config.js +50 -53
  67. package/src/commands/data/pinList/pinList.js +0 -34
  68. package/src/commands/pinning/hashPinPolicy.js +0 -51
  69. package/src/commands/pinning/userPinPolicy.js +0 -40
  70. package/src/index.js +0 -307
  71. package/test/commands/data/pinlist-sample-api.js +0 -540
  72. package/test/commands/pinning/hashPinPolicy.test.js +0 -65
  73. package/test/commands/pinning/userPinPolicy.test.js +0 -80
  74. package/test/util/validators.test.js +0 -234
@@ -1,3 +1,27 @@
1
+ import { PinataConfig } from '../..';
2
+ export interface PinataPinPolicyItem {
3
+ id: string;
4
+ desiredReplicationCount: number;
5
+ }
6
+ export interface PinataOptions {
7
+ hostNodes?: string[] | undefined;
8
+ cidVersion?: 0 | 1;
9
+ wrapWithDirectory?: boolean;
10
+ customPinPolicy?: {
11
+ regions: PinataPinPolicyItem[];
12
+ };
13
+ }
14
+ export interface PinataPinResponse {
15
+ IpfsHash: string;
16
+ PinSize: number;
17
+ Timestamp: string;
18
+ }
19
+ export interface PinataPinOptions {
20
+ pinataMetadata?: {
21
+ [key: string]: string | number | null;
22
+ };
23
+ pinataOptions?: PinataOptions | undefined;
24
+ }
1
25
  /**
2
26
  * Pin File to IPFS
3
27
  * @param {string} pinataApiKey
@@ -6,4 +30,4 @@
6
30
  * @param {*} options
7
31
  * @returns {Promise<unknown>}
8
32
  */
9
- export default function pinFileToIPFS(config: any, readStream: any, options: any): Promise<unknown>;
33
+ export default function pinFileToIPFS(config: PinataConfig, readStream: any, options?: PinataPinOptions): Promise<PinataPinResponse>;
@@ -1,9 +1,3 @@
1
- /**
2
- * PinFromFS
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {string} sourcePath
6
- * @param {*} options
7
- * @returns {Promise<unknown>}
8
- */
9
- export default function pinFromFS(config: any, sourcePath: string, options: any): Promise<unknown>;
1
+ import { PinataConfig } from '../..';
2
+ import { PinataPinOptions, PinataPinResponse } from './pinFileToIPFS';
3
+ export default function pinFromFS(config: PinataConfig, sourcePath: string, options?: PinataPinOptions): Promise<PinataPinResponse>;
@@ -1,9 +1,3 @@
1
- /**
2
- * Pin JSON to IPFS
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {*} body
6
- * @param {*} options
7
- * @returns {Promise<unknown>}
8
- */
9
- export default function pinJSONToIPFS(config: any, body: any, options: any): Promise<unknown>;
1
+ import { PinataConfig } from '../..';
2
+ import { PinataPinOptions, PinataPinResponse } from './pinFileToIPFS';
3
+ export default function pinJSONToIPFS(config: PinataConfig, body: any, options?: PinataPinOptions): Promise<PinataPinResponse>;
@@ -1,8 +1,20 @@
1
- /**
2
- * Pin Jobs
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {*} filters
6
- * @returns {Promise<unknown>}
7
- */
8
- export default function pinJobs(config: any, filters: any): Promise<unknown>;
1
+ import { PinataConfig } from '../../..';
2
+ export interface PinataPinJobsResponseRow {
3
+ id: number | string;
4
+ ipfs_pin_hash: string;
5
+ date_queued: string;
6
+ name: string | undefined | null;
7
+ status: string;
8
+ }
9
+ export interface PinataPinJobsResponse {
10
+ count: number;
11
+ rows: PinataPinJobsResponseRow[];
12
+ }
13
+ export interface PinataPinJobsFilterOptions {
14
+ sort: 'ASC' | 'DESC';
15
+ status?: string | undefined;
16
+ ipfs_pin_hash?: string | undefined;
17
+ limit?: number | undefined;
18
+ offset?: number | undefined;
19
+ }
20
+ export default function pinJobs(config: PinataConfig, filters?: PinataPinJobsFilterOptions): Promise<PinataPinJobsResponse>;
@@ -1,7 +1 @@
1
- /**
2
- * Query Buidler
3
- * @param {string} baseUrl
4
- * @param {*} filters
5
- * @returns {*}
6
- */
7
- export default function queryBuilder(baseUrl: string, filters: any): any;
1
+ export default function queryBuilder(baseUrl: string, filters?: any): string;
@@ -1,8 +1,2 @@
1
- /**
2
- * Unpin
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {string} hashToUnpin
6
- * @returns {Promise<unknown>}
7
- */
8
- export default function unpin(config: any, hashToUnpin: string): Promise<unknown>;
1
+ import { PinataConfig } from '../..';
2
+ export default function unpin(config: PinataConfig, hashToUnpin: string): Promise<unknown>;
@@ -1,2 +1,2 @@
1
- export const baseUrl: "https://api.pinata.cloud";
2
- export const ERROR_NO_CREDENTIALS_PROVIDED: "No credentials provided! Please provide your pinata api key and pinata secret api key or your pinata JWT key as an argument when you start this script";
1
+ export declare const baseUrl = "https://api.pinata.cloud";
2
+ export declare const ERROR_NO_CREDENTIALS_PROVIDED = "No credentials provided! Please provide your pinata api key and pinata secret api key or your pinata JWT key as an argument when you start this script";
package/types/index.d.ts CHANGED
@@ -1,166 +1,38 @@
1
- /**
2
- * Pinata Client
3
- *
4
- * @param {string | PinataConfig} [pinataApiKey]
5
- * @param {string} [pinataSecretApiKey]
6
- * @returns {PinataClient}
7
- */
8
- export default function pinataClient(pinataApiKey?: string | PinataConfig | undefined, pinataSecretApiKey?: string | undefined): PinataClient;
9
- export type PinataMetadata = Record<string, string | number | null>;
10
- export type PinataMetadataFilter = {
11
- name?: string | undefined;
12
- keyvalues: Record<string, {
13
- value: string;
14
- op: string;
15
- }>;
16
- };
17
- export type PinataPinPolicyItem = {
18
- id: string;
19
- desiredReplicationCount: number;
20
- };
21
- export type PinataPinByHashOptions = {
22
- hostNodes?: string[] | undefined;
23
- customPinPolicy?: {
24
- regions: PinataPinPolicyItem[];
25
- } | undefined;
26
- };
27
- export type PinataPinByHashPinOptions = {
28
- pinataMetadata?: Record<string, string | number | null> | undefined;
29
- pinataOptions?: PinataPinByHashOptions | undefined;
30
- };
31
- export type PinataOptions = {
32
- cidVersion?: 0 | 1 | undefined;
33
- wrapWithDirectory?: boolean | undefined;
34
- customPinPolicy?: {
35
- regions: PinataPinPolicyItem[];
36
- } | undefined;
37
- };
38
- export type PinataPinOptions = {
39
- pinataMetadata?: Record<string, string | number | null> | undefined;
40
- pinataOptions?: PinataOptions | undefined;
41
- };
42
- export type PinataPinJobsFilterOptions = {
43
- sort: 'ASC' | 'DESC';
44
- status?: string | undefined;
45
- ipfs_pin_hash?: string | undefined;
46
- limit?: number | undefined;
47
- offset?: number | undefined;
48
- };
49
- export type PinataPinListFilterOptions = {
50
- hashContains?: string | undefined;
51
- pinStart?: string | undefined;
52
- pinEnd?: string | undefined;
53
- unpinStart?: string | undefined;
54
- unpinEnd?: string | undefined;
55
- pinSizeMin?: number | undefined;
56
- pinSizeMax?: number | undefined;
57
- status?: string | undefined;
58
- pageLimit?: number | undefined;
59
- pageOffset?: number | undefined;
60
- metadata?: PinataMetadataFilter | undefined;
61
- };
62
- export type PinataPinByHashResponse = {
63
- id: number | string;
64
- ipfsHash: string;
65
- status: string;
66
- name: string;
67
- };
68
- export type PinataPinResponse = {
69
- IpfsHash: string;
70
- PinSize: number;
71
- Timestamp: string;
72
- };
73
- export type PinataPinJobsResponseRow = {
74
- id: number | string;
75
- ipfs_pin_hash: string;
76
- date_queued: string;
77
- name: string | undefined | null;
78
- status: string;
79
- };
80
- export type PinataPinJobsResponse = {
81
- count: number;
82
- rows: PinataPinJobsResponseRow[];
83
- };
84
- export type PinataPinListResponseRow = {
85
- id: number | string;
86
- ipfs_pin_hash: string;
87
- size: number;
88
- user_id: string | number;
89
- date_pinned: string;
90
- date_unpinned: string;
91
- metadata: PinataMetadata;
92
- };
93
- export type PinataPinListResponse = {
94
- count: number;
95
- rows: PinataPinListResponseRow[];
96
- };
97
- /**
98
- * Hash meta data
99
- */
100
- export type hashMetadata = (ipfsPinHash: string, metadata: PinataMetadata) => Promise<any>;
101
- /**
102
- * Pin by hash
103
- */
104
- export type pinByHash = (hashToPin: string, options?: PinataPinByHashPinOptions | undefined) => Promise<PinataPinByHashResponse>;
105
- /**
106
- * Pin file to IPFS
107
- */
108
- export type pinFileToIPFS = (readableStream: any, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
109
- /**
110
- * Pin from FS
111
- */
112
- export type pinFromFS = (sourcePath: string, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
113
- /**
114
- * Pin Jobs
115
- */
116
- export type pinJobs = (filters?: PinataPinJobsFilterOptions | undefined) => Promise<PinataPinJobsResponse>;
117
- /**
118
- * Pin JSON to IPFS
119
- */
120
- export type pinJSONToIPFS = (body: Object, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
121
- /**
122
- * Unpin
123
- */
124
- export type unpin = (hashToUnpin: string) => Promise<any>;
125
- /**
126
- * Test Authentication
127
- */
128
- export type testAuthentication = () => Promise<{
129
- authenticated: boolean;
130
- }>;
131
- /**
132
- * Pin List
133
- */
134
- export type pinList = (filters?: PinataPinListFilterOptions | undefined) => Promise<PinataPinListResponse>;
135
- /**
136
- * User Pinned Data Total
137
- */
138
- export type userPinnedDataTotal = () => Promise<number>;
139
- export type PinataConfig = {
140
- pinataApiKey?: string | undefined;
141
- pinataSecretApiKey?: string | undefined;
142
- pinataJWTKey?: string | undefined;
143
- };
144
- export type PinataClient = {
1
+ import { PinataPinByHashPinOptions } from './commands/pinning/pinByHash';
2
+ import { PinataPinOptions } from './commands/pinning/pinFileToIPFS';
3
+ import { PinataPinJobsFilterOptions } from './commands/pinning/pinJobs/pinJobs';
4
+ import { PinataMetadata, PinataPinListFilterOptions } from './commands/data/pinList/pinList';
5
+ export interface PinataConfig {
6
+ pinataApiKey?: string;
7
+ pinataSecretApiKey?: string;
8
+ pinataJWTKey?: string;
9
+ }
10
+ declare class PinataClient {
145
11
  config: PinataConfig;
146
- pinByHash: pinByHash;
147
- hashMetadata: hashMetadata;
148
- pinFileToIPFS: pinFileToIPFS;
149
- pinFromFS: pinFromFS;
150
- pinJSONToIPFS: pinJSONToIPFS;
151
- pinJobs: pinJobs;
152
- unpin: unpin;
153
- testAuthentication: testAuthentication;
154
- pinList: pinList;
155
- userPinnedDataTotal: userPinnedDataTotal;
156
- };
157
- import pinByHash from "./commands/pinning/pinByHash";
158
- import hashMetadata from "./commands/pinning/hashMetadata";
159
- import pinFileToIPFS from "./commands/pinning/pinFileToIPFS";
160
- import pinFromFS from "./commands/pinning/pinFromFS";
161
- import pinJSONToIPFS from "./commands/pinning/pinJSONToIPFS";
162
- import pinJobs from "./commands/pinning/pinJobs/pinJobs";
163
- import unpin from "./commands/pinning/unpin";
164
- import testAuthentication from "./commands/data/testAuthentication";
165
- import pinList from "./commands/data/pinList/pinList";
166
- import userPinnedDataTotal from "./commands/data/userPinnedDataTotal";
12
+ constructor(pinataApiKey?: string | PinataConfig, pinataSecretApiKey?: string);
13
+ pinByHash(hashToPin: string, options?: PinataPinByHashPinOptions): Promise<any>;
14
+ hashMetadata(ipfsPinHash: string, metadata: PinataMetadata): Promise<any>;
15
+ pinFileToIPFS(readableStream: any, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
16
+ pinFromFS(sourcePath: string, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
17
+ pinJSONToIPFS(body: any, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
18
+ pinJobs(filters?: PinataPinJobsFilterOptions): Promise<import("./commands/pinning").PinataPinJobsResponse>;
19
+ unpin(hashToUnpin: string): Promise<unknown>;
20
+ pinList(filters: PinataPinListFilterOptions): Promise<import("./commands/data").PinataPinListResponse>;
21
+ getFilesByCount(filters: PinataPinListFilterOptions, maxCount?: number): {
22
+ [Symbol.asyncIterator]: () => {
23
+ next(): Promise<{
24
+ value: import("./commands/data").PinataPin;
25
+ done: boolean;
26
+ }>;
27
+ return(): Promise<{
28
+ value: number;
29
+ done: boolean;
30
+ }>;
31
+ };
32
+ };
33
+ testAuthentication(): Promise<import("./commands/data").PinataTestAuthenticationResponse>;
34
+ userPinnedDataTotal(): Promise<number>;
35
+ }
36
+ export * from './commands/data';
37
+ export * from './commands/pinning';
38
+ export default PinataClient;
@@ -1 +1 @@
1
- export function handleError(error: any): any;
1
+ export declare const handleError: (error: any) => any;
@@ -1,14 +1,10 @@
1
- /**
2
- * Validate API Keys
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- */
6
- export function validateApiKeys(pinataApiKey: string, pinataSecretApiKey: string): void;
7
- export function createConfigForAxiosHeaders(config: any): {
1
+ import { PinataConfig } from '..';
2
+ export declare function validateApiKeys(pinataApiKey?: string, pinataSecretApiKey?: string): void;
3
+ export declare function createConfigForAxiosHeaders(config: PinataConfig): {
8
4
  withCredentials: boolean;
9
5
  headers: {
10
- pinata_api_key: any;
11
- pinata_secret_api_key: any;
6
+ pinata_api_key: string;
7
+ pinata_secret_api_key: string;
12
8
  Authorization?: undefined;
13
9
  };
14
10
  } | {
@@ -19,42 +15,29 @@ export function createConfigForAxiosHeaders(config: any): {
19
15
  };
20
16
  withCredentials?: undefined;
21
17
  };
22
- export function createConfigForAxiosHeadersWithFormData(config: any, boundaryValue: any): {
18
+ export declare function createConfigForAxiosHeadersWithFormData(config: PinataConfig, boundaryValue: string): {
23
19
  maxContentLength: number;
24
20
  maxBodyLength: number;
25
- withCredentials: boolean;
26
21
  headers: {
27
- pinata_api_key: any;
28
- pinata_secret_api_key: any;
29
- Authorization?: undefined;
22
+ 'Content-type': string;
30
23
  };
24
+ withCredentials: boolean;
31
25
  } | {
32
26
  maxContentLength: number;
33
27
  maxBodyLength: number;
34
28
  headers: {
35
- Authorization: string;
36
- pinata_api_key?: undefined;
37
- pinata_secret_api_key?: undefined;
29
+ 'Content-type': string;
38
30
  };
39
31
  withCredentials?: undefined;
40
32
  };
41
- /**
42
- * Validate host Nodes
43
- * @param {*} hostNodes
44
- */
45
- export function validateHostNodes(hostNodes: any): void;
46
- /**
47
- * Validate MetaData
48
- * @param {*} metadata
49
- */
50
- export function validateMetadata(metadata: any): void;
51
- /**
52
- * Validate Pin Policy Structure
53
- * @param {*} pinPolicy
54
- */
55
- export function validatePinPolicyStructure(pinPolicy: any): void;
56
- /**
57
- * Validate Pinata Options
58
- * @param {*} options
59
- */
60
- export function validatePinataOptions(options: any): void;
33
+ export declare function validateHostNodes(hostNodes: any): void;
34
+ export declare function validateMetadata(metadata: any): void;
35
+ export declare function validatePinPolicyStructure(pinPolicy: {
36
+ regions: any[];
37
+ }): void;
38
+ export declare function validatePinataOptions(options: {
39
+ cidVersion?: number;
40
+ wrapWithDirectory?: boolean;
41
+ hostNodes?: any;
42
+ customPinPolicy?: any;
43
+ }): void;
package/webpack.config.js CHANGED
@@ -1,61 +1,58 @@
1
- /* global __dirname, require, module*/
2
-
3
1
  const webpack = require('webpack');
4
2
  const path = require('path');
5
- const env = require('yargs').argv.env; // use --env with webpack 2
6
- const pkg = require('./package.json');
7
3
 
8
- let libraryName = 'pinata-sdk';
4
+ const libraryName = 'pinata-sdk';
9
5
 
10
- let outputFile, mode;
6
+ module.exports = (env) => {
7
+ let outputFile, mode;
11
8
 
12
- if (env === 'build') {
13
- mode = 'production';
14
- outputFile = libraryName + '.min.js';
15
- } else {
16
- mode = 'development';
17
- outputFile = libraryName + '.js';
18
- }
9
+ if (env === 'build') {
10
+ mode = 'production';
19
11
 
20
- const config = {
21
- mode: mode,
22
- entry: ['babel-polyfill', __dirname + '/src/index.js'],
23
- devtool: 'inline-source-map',
24
- output: {
25
- path: __dirname + '/lib',
26
- filename: outputFile,
27
- library: libraryName,
28
- libraryTarget: 'umd',
29
- umdNamedDefine: true,
30
- globalObject: 'typeof self !== \'undefined\' ? self : this'
31
- },
32
- module: {
33
- rules: [
34
- {
35
- test: /(\.jsx|\.js)$/,
36
- loader: 'babel-loader',
37
- exclude: /(node_modules|bower_components)/
38
- },
39
- {
40
- test: /(\.jsx|\.js)$/,
41
- loader: 'eslint-loader',
42
- exclude: /node_modules/
43
- }
44
- ]
45
- },
46
- target: 'node',
47
- node: {
48
- process: false
49
- },
50
- plugins: [
51
- new webpack.DefinePlugin({
52
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
53
- })
54
- ],
55
- resolve: {
56
- modules: [path.resolve('./node_modules'), path.resolve('./src')],
57
- extensions: ['.json', '.js']
12
+ outputFile = libraryName + '.min.js';
13
+ } else {
14
+ mode = 'development';
15
+ outputFile = libraryName + '.js';
58
16
  }
17
+ return {
18
+ mode: mode,
19
+ entry: ['babel-polyfill', __dirname + '/src/index.ts'],
20
+ devtool: 'inline-source-map',
21
+ output: {
22
+ path: __dirname + '/lib',
23
+ filename: outputFile,
24
+ library: libraryName,
25
+ libraryTarget: 'umd',
26
+ umdNamedDefine: true,
27
+ globalObject: "typeof self !== 'undefined' ? self : this"
28
+ },
29
+ module: {
30
+ rules: [
31
+ {
32
+ test: /\.ts?$/,
33
+ loader: 'babel-loader',
34
+ exclude: /(node_modules|bower_components)/
35
+ },
36
+ // {
37
+ // test: /\.ts?$/,
38
+ // loader: 'eslint-loader',
39
+ // exclude: /node_modules/,
40
+
41
+ // }
42
+ ]
43
+ },
44
+ target: 'node',
45
+ node: {
46
+ process: false
47
+ },
48
+ plugins: [
49
+ new webpack.DefinePlugin({
50
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
51
+ })
52
+ ],
53
+ resolve: {
54
+ modules: [path.resolve('./node_modules'), path.resolve('./src')],
55
+ extensions: ['.json', '.js', '.ts']
56
+ }
57
+ };
59
58
  };
60
-
61
- module.exports = config;
@@ -1,34 +0,0 @@
1
- import axios from 'axios';
2
- import { baseUrl } from './../../../constants';
3
- import { createConfigForAxiosHeaders } from '../../../util/validators';
4
- import { handleError } from '../../../util/errorResponse';
5
- import queryBuilder from './queryBuilder';
6
-
7
- /**
8
- * Pin List
9
- * @param {string} pinataApiKey
10
- * @param {string} pinataSecretApiKey
11
- * @param {any} filters
12
- * @returns {Promise<unknown>}
13
- */
14
- export default function pinList(config, filters = {}) {
15
- filters = {...filters, ...{includeCount: 'false' }};
16
-
17
- const baseEndpoint = `${baseUrl}/data/pinList`;
18
- const endpoint = queryBuilder(baseEndpoint, filters);
19
-
20
- return new Promise((resolve, reject) => {
21
- axios.get(
22
- endpoint,
23
- {...createConfigForAxiosHeaders(config)})
24
- .then(function (result) {
25
- if (result.status !== 200) {
26
- reject(new Error(`unknown server response while attempting to retrieve user pin list: ${result}`));
27
- }
28
- resolve(result.data);
29
- }).catch(function (error) {
30
- const formattedError = handleError(error);
31
- reject(formattedError);
32
- });
33
- });
34
- }
@@ -1,51 +0,0 @@
1
- import axios from 'axios';
2
- import { baseUrl } from './../../constants';
3
- import { createConfigForAxiosHeaders, validatePinPolicyStructure } from '../../util/validators';
4
- import isIPFS from 'is-ipfs';
5
- import { handleError } from '../../util/errorResponse';
6
-
7
- /**
8
- * Hash Pin Policy
9
- * @param {string} pinataApiKey
10
- * @param {string} pinataSecretApiKey
11
- * @param {*} ipfsPinHash
12
- * @param {*} newPinPolicy
13
- * @returns {Promise<unknown>}
14
- */
15
- export default function hashPinPolicy(config, ipfsPinHash, newPinPolicy) {
16
- validatePinPolicyStructure(newPinPolicy);
17
-
18
- if (!ipfsPinHash) {
19
- throw new Error('ipfsPinHash value is required for changing the pin policy of a pin');
20
- }
21
-
22
- if (!isIPFS.cid(ipfsPinHash)) {
23
- throw new Error('ipfsPinHash value is an invalid IPFS CID');
24
- }
25
-
26
- if (!newPinPolicy) {
27
- throw new Error('newPinPolicy is required for changing the pin policy of a pin');
28
- }
29
-
30
- const endpoint = `${baseUrl}/pinning/hashPinPolicy`;
31
- const body = {
32
- ipfsPinHash: ipfsPinHash,
33
- newPinPolicy: newPinPolicy
34
- };
35
-
36
- return new Promise((resolve, reject) => {
37
- axios.put(
38
- endpoint,
39
- body,
40
- {...createConfigForAxiosHeaders(config)})
41
- .then(function (result) {
42
- if (result.status !== 200) {
43
- reject(new Error(`unknown server response while changing pin policy for hash: ${result}`));
44
- }
45
- resolve(result.data);
46
- }).catch(function (error) {
47
- const formattedError = handleError(error);
48
- reject(formattedError);
49
- });
50
- });
51
- }
@@ -1,40 +0,0 @@
1
- import axios from 'axios';
2
- import { baseUrl } from './../../constants';
3
- import { createConfigForAxiosHeaders, validatePinPolicyStructure } from '../../util/validators';
4
- import { handleError } from '../../util/errorResponse';
5
-
6
- /**
7
- * User Pin Policy
8
- * @param {string} pinataApiKey
9
- * @param {string} pinataSecretApiKey
10
- * @param {*} newPinPolicy
11
- * @returns {Promise<unknown>}
12
- */
13
- export default function userPinPolicy(config, newPinPolicy) {
14
- validatePinPolicyStructure(newPinPolicy);
15
-
16
- if (!newPinPolicy) {
17
- throw new Error('newPinPolicy is required for changing the pin policy of a pin');
18
- }
19
-
20
- const endpoint = `${baseUrl}/pinning/userPinPolicy`;
21
- const body = {
22
- newPinPolicy: newPinPolicy
23
- };
24
-
25
- return new Promise((resolve, reject) => {
26
- axios.put(
27
- endpoint,
28
- body,
29
- {...createConfigForAxiosHeaders(config)})
30
- .then(function (result) {
31
- if (result.status !== 200) {
32
- reject(new Error(`unknown server response while changing pin policy for user: ${result}`));
33
- }
34
- resolve(result.data);
35
- }).catch(function (error) {
36
- const formattedError = handleError(error);
37
- reject(formattedError);
38
- });
39
- });
40
- }