modern-treasury 0.0.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 (169) hide show
  1. package/.eslintrc.js +10 -0
  2. package/.prettierrc +6 -0
  3. package/LICENSE +7 -0
  4. package/README.md +198 -0
  5. package/build +10 -0
  6. package/core.ts +746 -0
  7. package/dist/cjs/core.d.ts +215 -0
  8. package/dist/cjs/core.js +815 -0
  9. package/dist/cjs/core.js.map +1 -0
  10. package/dist/cjs/index.d.ts +118 -0
  11. package/dist/cjs/index.js +128 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/pagination.d.ts +14 -0
  14. package/dist/cjs/pagination.js +22 -0
  15. package/dist/cjs/pagination.js.map +1 -0
  16. package/dist/cjs/resource.d.ts +11 -0
  17. package/dist/cjs/resource.js +16 -0
  18. package/dist/cjs/resource.js.map +1 -0
  19. package/dist/cjs/resources/counterparties.d.ts +500 -0
  20. package/dist/cjs/resources/counterparties.js +57 -0
  21. package/dist/cjs/resources/counterparties.js.map +1 -0
  22. package/dist/cjs/resources/documents.d.ts +66 -0
  23. package/dist/cjs/resources/documents.js +23 -0
  24. package/dist/cjs/resources/documents.js.map +1 -0
  25. package/dist/cjs/resources/events.d.ts +53 -0
  26. package/dist/cjs/resources/events.js +22 -0
  27. package/dist/cjs/resources/events.js.map +1 -0
  28. package/dist/cjs/resources/expected-payments.d.ts +928 -0
  29. package/dist/cjs/resources/expected-payments.js +31 -0
  30. package/dist/cjs/resources/expected-payments.js.map +1 -0
  31. package/dist/cjs/resources/external-accounts.d.ts +597 -0
  32. package/dist/cjs/resources/external-accounts.js +51 -0
  33. package/dist/cjs/resources/external-accounts.js.map +1 -0
  34. package/dist/cjs/resources/incoming-payment-details.d.ts +487 -0
  35. package/dist/cjs/resources/incoming-payment-details.js +35 -0
  36. package/dist/cjs/resources/incoming-payment-details.js.map +1 -0
  37. package/dist/cjs/resources/index.d.ts +15 -0
  38. package/dist/cjs/resources/index.js +46 -0
  39. package/dist/cjs/resources/index.js.map +1 -0
  40. package/dist/cjs/resources/internal-accounts.d.ts +666 -0
  41. package/dist/cjs/resources/internal-accounts.js +31 -0
  42. package/dist/cjs/resources/internal-accounts.js.map +1 -0
  43. package/dist/cjs/resources/line-items.d.ts +90 -0
  44. package/dist/cjs/resources/line-items.js +38 -0
  45. package/dist/cjs/resources/line-items.js.map +1 -0
  46. package/dist/cjs/resources/paper-items.d.ts +279 -0
  47. package/dist/cjs/resources/paper-items.js +25 -0
  48. package/dist/cjs/resources/paper-items.js.map +1 -0
  49. package/dist/cjs/resources/payment-orders/index.d.ts +2 -0
  50. package/dist/cjs/resources/payment-orders/index.js +33 -0
  51. package/dist/cjs/resources/payment-orders/index.js.map +1 -0
  52. package/dist/cjs/resources/payment-orders/payment-orders.d.ts +2180 -0
  53. package/dist/cjs/resources/payment-orders/payment-orders.js +56 -0
  54. package/dist/cjs/resources/payment-orders/payment-orders.js.map +1 -0
  55. package/dist/cjs/resources/payment-orders/reversals.d.ts +46 -0
  56. package/dist/cjs/resources/payment-orders/reversals.js +23 -0
  57. package/dist/cjs/resources/payment-orders/reversals.js.map +1 -0
  58. package/dist/cjs/resources/returns.d.ts +487 -0
  59. package/dist/cjs/resources/returns.js +31 -0
  60. package/dist/cjs/resources/returns.js.map +1 -0
  61. package/dist/cjs/resources/top-level.d.ts +3 -0
  62. package/dist/cjs/resources/top-level.js +4 -0
  63. package/dist/cjs/resources/top-level.js.map +1 -0
  64. package/dist/cjs/resources/transactions.d.ts +377 -0
  65. package/dist/cjs/resources/transactions.js +31 -0
  66. package/dist/cjs/resources/transactions.js.map +1 -0
  67. package/dist/cjs/resources/validations.d.ts +97 -0
  68. package/dist/cjs/resources/validations.js +16 -0
  69. package/dist/cjs/resources/validations.js.map +1 -0
  70. package/dist/cjs/resources/webhooks.d.ts +31 -0
  71. package/dist/cjs/resources/webhooks.js +44 -0
  72. package/dist/cjs/resources/webhooks.js.map +1 -0
  73. package/dist/cjs/tests/api-resources/counterparties.test.d.ts +1 -0
  74. package/dist/cjs/tests/api-resources/counterparties.test.js +275 -0
  75. package/dist/cjs/tests/api-resources/counterparties.test.js.map +1 -0
  76. package/dist/cjs/tests/api-resources/documents.test.d.ts +1 -0
  77. package/dist/cjs/tests/api-resources/documents.test.js +78 -0
  78. package/dist/cjs/tests/api-resources/documents.test.js.map +1 -0
  79. package/dist/cjs/tests/api-resources/events.test.d.ts +1 -0
  80. package/dist/cjs/tests/api-resources/events.test.js +100 -0
  81. package/dist/cjs/tests/api-resources/events.test.js.map +1 -0
  82. package/dist/cjs/tests/api-resources/expected-payments.test.d.ts +1 -0
  83. package/dist/cjs/tests/api-resources/expected-payments.test.js +176 -0
  84. package/dist/cjs/tests/api-resources/expected-payments.test.js.map +1 -0
  85. package/dist/cjs/tests/api-resources/external-accounts.test.d.ts +1 -0
  86. package/dist/cjs/tests/api-resources/external-accounts.test.js +248 -0
  87. package/dist/cjs/tests/api-resources/external-accounts.test.js.map +1 -0
  88. package/dist/cjs/tests/api-resources/incoming-payment-details.test.d.ts +1 -0
  89. package/dist/cjs/tests/api-resources/incoming-payment-details.test.js +130 -0
  90. package/dist/cjs/tests/api-resources/incoming-payment-details.test.js.map +1 -0
  91. package/dist/cjs/tests/api-resources/internal-accounts.test.d.ts +1 -0
  92. package/dist/cjs/tests/api-resources/internal-accounts.test.js +144 -0
  93. package/dist/cjs/tests/api-resources/internal-accounts.test.js.map +1 -0
  94. package/dist/cjs/tests/api-resources/line-items.test.d.ts +1 -0
  95. package/dist/cjs/tests/api-resources/line-items.test.js +123 -0
  96. package/dist/cjs/tests/api-resources/line-items.test.js.map +1 -0
  97. package/dist/cjs/tests/api-resources/paper-items.test.d.ts +1 -0
  98. package/dist/cjs/tests/api-resources/paper-items.test.js +96 -0
  99. package/dist/cjs/tests/api-resources/paper-items.test.js.map +1 -0
  100. package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.d.ts +1 -0
  101. package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.js +77 -0
  102. package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.js.map +1 -0
  103. package/dist/cjs/tests/api-resources/returns.test.d.ts +1 -0
  104. package/dist/cjs/tests/api-resources/returns.test.js +116 -0
  105. package/dist/cjs/tests/api-resources/returns.test.js.map +1 -0
  106. package/dist/cjs/tests/api-resources/top-level.test.d.ts +1 -0
  107. package/dist/cjs/tests/api-resources/top-level.test.js +59 -0
  108. package/dist/cjs/tests/api-resources/top-level.test.js.map +1 -0
  109. package/dist/cjs/tests/api-resources/transactions.test.d.ts +1 -0
  110. package/dist/cjs/tests/api-resources/transactions.test.js +134 -0
  111. package/dist/cjs/tests/api-resources/transactions.test.js.map +1 -0
  112. package/dist/cjs/tests/api-resources/validations.test.d.ts +1 -0
  113. package/dist/cjs/tests/api-resources/validations.test.js +62 -0
  114. package/dist/cjs/tests/api-resources/validations.test.js.map +1 -0
  115. package/dist/cjs/tests/api-resources/webhooks.test.d.ts +1 -0
  116. package/dist/cjs/tests/api-resources/webhooks.test.js +100 -0
  117. package/dist/cjs/tests/api-resources/webhooks.test.js.map +1 -0
  118. package/dist/cjs/tests/form.test.d.ts +1 -0
  119. package/dist/cjs/tests/form.test.js +61 -0
  120. package/dist/cjs/tests/form.test.js.map +1 -0
  121. package/dist/cjs/tests/index.test.d.ts +1 -0
  122. package/dist/cjs/tests/index.test.js +57 -0
  123. package/dist/cjs/tests/index.test.js.map +1 -0
  124. package/dist/cjs/tests/responses.test.d.ts +1 -0
  125. package/dist/cjs/tests/responses.test.js +60 -0
  126. package/dist/cjs/tests/responses.test.js.map +1 -0
  127. package/index.ts +175 -0
  128. package/jest.config.js +8 -0
  129. package/package.json +47 -0
  130. package/pagination.ts +36 -0
  131. package/resource.ts +22 -0
  132. package/resources/counterparties.ts +666 -0
  133. package/resources/documents.ts +97 -0
  134. package/resources/events.ts +86 -0
  135. package/resources/expected-payments.ts +1016 -0
  136. package/resources/external-accounts.ts +762 -0
  137. package/resources/incoming-payment-details.ts +592 -0
  138. package/resources/index.ts +16 -0
  139. package/resources/internal-accounts.ts +774 -0
  140. package/resources/line-items.ts +138 -0
  141. package/resources/paper-items.ts +317 -0
  142. package/resources/payment-orders/index.ts +3 -0
  143. package/resources/payment-orders/payment-orders.ts +2486 -0
  144. package/resources/payment-orders/reversals.ts +72 -0
  145. package/resources/returns.ts +545 -0
  146. package/resources/top-level.ts +5 -0
  147. package/resources/transactions.ts +441 -0
  148. package/resources/validations.ts +115 -0
  149. package/resources/webhooks.ts +48 -0
  150. package/tests/api-resources/counterparties.test.ts +237 -0
  151. package/tests/api-resources/documents.test.ts +40 -0
  152. package/tests/api-resources/events.test.ts +62 -0
  153. package/tests/api-resources/expected-payments.test.ts +138 -0
  154. package/tests/api-resources/external-accounts.test.ts +210 -0
  155. package/tests/api-resources/incoming-payment-details.test.ts +92 -0
  156. package/tests/api-resources/internal-accounts.test.ts +103 -0
  157. package/tests/api-resources/line-items.test.ts +85 -0
  158. package/tests/api-resources/paper-items.test.ts +58 -0
  159. package/tests/api-resources/payment-orders/payment-orders.test.ts +39 -0
  160. package/tests/api-resources/returns.test.ts +78 -0
  161. package/tests/api-resources/top-level.test.ts +21 -0
  162. package/tests/api-resources/transactions.test.ts +96 -0
  163. package/tests/api-resources/validations.test.ts +24 -0
  164. package/tests/api-resources/webhooks.test.ts +102 -0
  165. package/tests/form.test.ts +27 -0
  166. package/tests/index.test.ts +62 -0
  167. package/tests/responses.test.ts +25 -0
  168. package/tsconfig.cjs.json +8 -0
  169. package/tsconfig.json +36 -0
@@ -0,0 +1,102 @@
1
+ // File generated from our OpenAPI spec by Stainless.
2
+
3
+ import ModernTreasury from '~/index';
4
+ const modernTreasury = new ModernTreasury({
5
+ apiKey: 'something1234',
6
+ baseURL: 'http://127.0.0.1:4010',
7
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
8
+ });
9
+
10
+ describe('resource webhooks', () => {
11
+ it.each([
12
+ ['foo', '08ba357e274f528065766c770a639abf6809b39ccfd37c2a3157c7f51954da0a'],
13
+ ['{"foo":"bar"}', '57e14f6f354543f0101fb06ea24df7731d90087b76651e3497345e22a3622940'],
14
+ [
15
+ '{"foo":"bar","bar":"baz","a": true}',
16
+ 'ec1c86d16075e6937fc26d55b7dc60bac9b1178a2f714312f7c5cb13a319b0ac',
17
+ ],
18
+ [
19
+ '{"a":{"b":{"c":{"d":[null,1,true,false,["foo",{"bar":[true, false]}]]}}}}',
20
+ '39b6fc0f5b02a5aefbdd7fb337245b4209036334e837d8c5b6a4092965ebc0a5',
21
+ ],
22
+ ])('getSignature', (payload, expected) => {
23
+ const signature = modernTreasury.webhooks.getSignature(payload, { key: 'foo' });
24
+ expect(signature).toEqual(expected);
25
+ });
26
+
27
+ it('getSignature: Throws an error when the key has not been set', () => {
28
+ const client = new ModernTreasury({
29
+ apiKey: 'something1234',
30
+ baseURL: 'http://127.0.0.1:4010',
31
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
32
+ });
33
+ expect(() => client.webhooks.getSignature('bar')).toThrowError(/webhook key/);
34
+ });
35
+
36
+ it('getSignature: Uses the webhook key set at the client level', () => {
37
+ const client = new ModernTreasury({
38
+ apiKey: 'something1234',
39
+ baseURL: 'http://127.0.0.1:4010',
40
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
41
+ webhookKey: 'hello, world',
42
+ });
43
+ const payload = '{"foo":"bar"}';
44
+ const signature = client.webhooks.getSignature(payload);
45
+ expect(signature).toEqual('07e118b4a9818c9242baf9009e76a78c29aeb015da93f600d514b77185247069');
46
+
47
+ const otherSignature = modernTreasury.webhooks.getSignature(payload, { key: 'foo' });
48
+ expect(otherSignature).not.toEqual(signature);
49
+ });
50
+
51
+ it('validateSignature: Throws an error when the X-Signature header is not present', () => {
52
+ expect(() =>
53
+ modernTreasury.webhooks.validateSignature('bar', /* headers */ {}, { key: 'foo' }),
54
+ ).toThrowError('Could not find an X-Signature header');
55
+ });
56
+
57
+ it('validateSignature: Correctly verifies against the expected signature', () => {
58
+ const payload = '{"foo":"bar"}';
59
+ expect(
60
+ modernTreasury.webhooks.validateSignature(
61
+ payload,
62
+ /* headers */ { 'X-Signature': '57e14f6f354543f0101fb06ea24df7731d90087b76651e3497345e22a3622940' },
63
+ {
64
+ key: 'foo',
65
+ },
66
+ ),
67
+ ).toBe(true);
68
+
69
+ // lowercased header
70
+ expect(
71
+ modernTreasury.webhooks.validateSignature(
72
+ payload,
73
+ /* headers */ { 'x-signature': '57e14f6f354543f0101fb06ea24df7731d90087b76651e3497345e22a3622940' },
74
+ {
75
+ key: 'foo',
76
+ },
77
+ ),
78
+ ).toBe(true);
79
+
80
+ // modified payload
81
+ expect(
82
+ modernTreasury.webhooks.validateSignature(
83
+ payload + 'foo',
84
+ /* headers */ { 'X-Signature': '57e14f6f354543f0101fb06ea24df7731d90087b76651e3497345e22a3622940' },
85
+ {
86
+ key: 'foo',
87
+ },
88
+ ),
89
+ ).toBe(false);
90
+
91
+ // modified signature
92
+ expect(
93
+ modernTreasury.webhooks.validateSignature(
94
+ payload,
95
+ /* headers */ { 'X-Signature': 'hello' },
96
+ {
97
+ key: 'foo',
98
+ },
99
+ ),
100
+ ).toBe(false);
101
+ });
102
+ });
@@ -0,0 +1,27 @@
1
+ import { multipartFormRequestOptions } from '~/core';
2
+ import { Blob } from 'formdata-node';
3
+ import { fileFromPath } from 'formdata-node/file-from-path';
4
+
5
+ describe('form data validation', () => {
6
+ test('valid values do not error', async () => {
7
+ multipartFormRequestOptions({
8
+ body: {
9
+ foo: 'foo',
10
+ string: 1,
11
+ bool: true,
12
+ file: await fileFromPath('README.md'),
13
+ blob: new Blob(['Some content'], { type: 'text/plain' }),
14
+ },
15
+ });
16
+ });
17
+
18
+ test('null', async () => {
19
+ expect(() =>
20
+ multipartFormRequestOptions({
21
+ body: {
22
+ null: null,
23
+ },
24
+ }),
25
+ ).toThrow(TypeError);
26
+ });
27
+ });
@@ -0,0 +1,62 @@
1
+ // File generated from our OpenAPI spec by Stainless.
2
+
3
+ import ModernTreasury from '../index';
4
+
5
+ describe('instantiate client', () => {
6
+ const env = process.env;
7
+
8
+ beforeEach(() => {
9
+ jest.resetModules();
10
+ process.env = { ...env };
11
+
12
+ console.warn = jest.fn();
13
+ });
14
+
15
+ afterEach(() => {
16
+ process.env = env;
17
+ });
18
+
19
+ test('with minimal arguments', () => {
20
+ // fails if no api key provided
21
+ expect(() => {
22
+ new ModernTreasury({ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa' });
23
+ }).toThrow();
24
+
25
+ // set api key via env var
26
+ process.env['MODERN_TREASURY_API_KEY'] = 'env var api key';
27
+ const client = new ModernTreasury({ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa' });
28
+ expect(client.apiKey).toBe('env var api key');
29
+ expect(client.organizationId).toBe('c40c0b40-11d3-42ee-8f2e-18ee8b8239aa');
30
+ });
31
+
32
+ test('with apiKey argument', () => {
33
+ process.env['MODERN_TREASURY_API_KEY'] = 'env var api key';
34
+
35
+ const client = new ModernTreasury({
36
+ apiKey: 'another api key',
37
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
38
+ });
39
+ expect(client.apiKey).toBe('another api key');
40
+ });
41
+
42
+ test('with options argument', () => {
43
+ process.env['MODERN_TREASURY_API_KEY'] = 'env var api key';
44
+
45
+ // apiKey and custom options
46
+ const client = new ModernTreasury({
47
+ apiKey: 'my api key',
48
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
49
+ });
50
+ expect(client.apiKey).toBe('my api key');
51
+ });
52
+
53
+ test('with disabled authentication', () => {
54
+ process.env['MODERN_TREASURY_API_KEY'] = 'env var api key';
55
+
56
+ const client = new ModernTreasury({
57
+ apiKey: null,
58
+ organizationId: 'c40c0b40-11d3-42ee-8f2e-18ee8b8239aa',
59
+ });
60
+ expect(client.apiKey).toBeNull();
61
+ });
62
+ });
@@ -0,0 +1,25 @@
1
+ import { createResponseHeaders } from '~/core';
2
+ import { Headers } from 'node-fetch';
3
+
4
+ describe('response parsing', () => {
5
+ // TODO: test unicode characters
6
+ test('headers are case agnostic', async () => {
7
+ const headers = createResponseHeaders(new Headers({ 'Content-Type': 'foo', Accept: 'text/plain' }));
8
+ expect(headers['content-type']).toEqual('foo');
9
+ expect(headers['Content-type']).toEqual('foo');
10
+ expect(headers['Content-Type']).toEqual('foo');
11
+ expect(headers['accept']).toEqual('text/plain');
12
+ expect(headers['Accept']).toEqual('text/plain');
13
+ expect(headers['Hello-World']).toBeUndefined();
14
+ });
15
+
16
+ test('duplicate headers are concatenated', () => {
17
+ const headers = createResponseHeaders(
18
+ new Headers([
19
+ ['Content-Type', 'text/xml'],
20
+ ['Content-Type', 'application/json'],
21
+ ]),
22
+ );
23
+ expect(headers['content-type']).toBe('text/xml, application/json');
24
+ });
25
+ });
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "es2016",
5
+ "module": "commonjs",
6
+ "outDir": "dist/cjs/"
7
+ }
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2019",
4
+ "lib": ["es2020"],
5
+ "module": "commonjs",
6
+ "moduleResolution": "node",
7
+ "esModuleInterop": true,
8
+ "rootDir": "./",
9
+ "baseUrl": "./",
10
+ "paths": {
11
+ "~/*": ["*"]
12
+ },
13
+
14
+ "declaration": true,
15
+ "outDir": "dist",
16
+ "pretty": true,
17
+ "sourceMap": true,
18
+
19
+ "forceConsistentCasingInFileNames": true,
20
+
21
+ "strict": true,
22
+ "noImplicitAny": true,
23
+ "strictNullChecks": true,
24
+ "strictFunctionTypes": true,
25
+ "strictBindCallApply": true,
26
+ "strictPropertyInitialization": true,
27
+ "noImplicitThis": true,
28
+ "alwaysStrict": true,
29
+ "exactOptionalPropertyTypes": true,
30
+ "noUncheckedIndexedAccess": true,
31
+ "noImplicitOverride": true,
32
+ "noPropertyAccessFromIndexSignature": true,
33
+
34
+ "skipLibCheck": true
35
+ }
36
+ }