@stancer/stancer 1.0.2 → 1.1.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 (184) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -1
  3. package/dist/api-endpoint/http/fetch-http-client.js +7 -1
  4. package/dist/api-endpoint/http/fetch-http-client.js.map +1 -1
  5. package/dist/core/common/handler/metadata-handler.d.ts +18 -0
  6. package/dist/core/common/handler/metadata-handler.d.ts.map +1 -0
  7. package/dist/core/common/handler/metadata-handler.js +19 -0
  8. package/dist/core/common/handler/metadata-handler.js.map +1 -0
  9. package/dist/event/model.d.ts +20 -0
  10. package/dist/event/model.d.ts.map +1 -0
  11. package/dist/event/model.js +30 -0
  12. package/dist/event/model.js.map +1 -0
  13. package/dist/index.d.ts +60 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +57 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/payment-intent/api-endpoint.d.ts +16 -1
  18. package/dist/payment-intent/api-endpoint.d.ts.map +1 -1
  19. package/dist/payment-intent/api-endpoint.js +2 -1
  20. package/dist/payment-intent/api-endpoint.js.map +1 -1
  21. package/dist/payment-intent/model.d.ts +3 -2
  22. package/dist/payment-intent/model.d.ts.map +1 -1
  23. package/dist/payment-intent/model.js +6 -0
  24. package/dist/payment-intent/model.js.map +1 -1
  25. package/dist/payment-intent/repository.d.ts +1 -1
  26. package/dist/payment-intent/repository.d.ts.map +1 -1
  27. package/dist/webhook/api-endpoint.d.ts +16 -0
  28. package/dist/webhook/api-endpoint.d.ts.map +1 -0
  29. package/dist/webhook/api-endpoint.js +33 -0
  30. package/dist/webhook/api-endpoint.js.map +1 -0
  31. package/dist/webhook/model.d.ts +35 -0
  32. package/dist/webhook/model.d.ts.map +1 -0
  33. package/dist/webhook/model.js +110 -0
  34. package/dist/webhook/model.js.map +1 -0
  35. package/dist/webhook/repository.d.ts +7 -0
  36. package/dist/webhook/repository.d.ts.map +1 -0
  37. package/dist/webhook/repository.js +10 -0
  38. package/dist/webhook/repository.js.map +1 -0
  39. package/dist/webhook/validator.d.ts +4 -0
  40. package/dist/webhook/validator.d.ts.map +1 -0
  41. package/dist/webhook/validator.js +16 -0
  42. package/dist/webhook/validator.js.map +1 -0
  43. package/package.json +33 -22
  44. package/dist/main.d.ts +0 -2
  45. package/dist/main.d.ts.map +0 -1
  46. package/dist/main.js +0 -2
  47. package/dist/main.js.map +0 -1
  48. package/reports/base.css +0 -362
  49. package/reports/block-navigation.js +0 -75
  50. package/reports/cobertura-coverage.xml +0 -18
  51. package/reports/favicon.png +0 -0
  52. package/reports/index.html +0 -177
  53. package/reports/junit.xml +0 -25
  54. package/reports/prettify.css +0 -101
  55. package/reports/prettify.js +0 -955
  56. package/reports/sort-arrow-sprite.png +0 -0
  57. package/reports/sorter.js +0 -205
  58. package/src/address/api-endpoint.ts +0 -30
  59. package/src/address/model.ts +0 -79
  60. package/src/address/repository.ts +0 -18
  61. package/src/address/validator.ts +0 -34
  62. package/src/api-endpoint/abstract-api-endpoint.ts +0 -310
  63. package/src/api-endpoint/configuration.ts +0 -125
  64. package/src/api-endpoint/http/fetch-http-client.ts +0 -29
  65. package/src/api-endpoint/http/http.ts +0 -75
  66. package/src/api-endpoint/http/index.ts +0 -2
  67. package/src/api-endpoint/version.ts +0 -4
  68. package/src/card/api-endpoint.ts +0 -39
  69. package/src/card/enum/funding.ts +0 -11
  70. package/src/card/enum/nature.ts +0 -7
  71. package/src/card/enum/network.ts +0 -16
  72. package/src/card/model.ts +0 -139
  73. package/src/card/repository.ts +0 -11
  74. package/src/card/validator.ts +0 -79
  75. package/src/core/abstract-model.ts +0 -126
  76. package/src/core/abstract-repository.ts +0 -201
  77. package/src/core/common/branded-type.ts +0 -15
  78. package/src/core/common/handler/date-handler.ts +0 -31
  79. package/src/core/common/handler/enum-handler.ts +0 -18
  80. package/src/core/common/handler/handler.ts +0 -64
  81. package/src/core/common/handler/id-handler.ts +0 -27
  82. package/src/core/common/id-validator.ts +0 -23
  83. package/src/core/common/mutation-tracked-object.ts +0 -49
  84. package/src/core/endpoint-interface.ts +0 -43
  85. package/src/core/error/base-error.ts +0 -1
  86. package/src/core/error/endpoint/api/api-conflict-error.ts +0 -7
  87. package/src/core/error/endpoint/api/api-error.ts +0 -10
  88. package/src/core/error/endpoint/api/api-not-found-error.ts +0 -7
  89. package/src/core/error/endpoint/api/api-unauthorized-error.ts +0 -7
  90. package/src/core/error/endpoint/api/api-unknown-error.ts +0 -7
  91. package/src/core/error/endpoint/api/api-validation-error.ts +0 -13
  92. package/src/core/error/endpoint/api/index.ts +0 -6
  93. package/src/core/error/endpoint/route-inaccessible-error.ts +0 -8
  94. package/src/core/error/unpopulated-error.ts +0 -3
  95. package/src/core/error/unsendable-error.ts +0 -3
  96. package/src/core/error/validation-error.ts +0 -3
  97. package/src/core/validator.ts +0 -129
  98. package/src/customer/api-endpoint.ts +0 -29
  99. package/src/customer/model.ts +0 -113
  100. package/src/customer/repository.ts +0 -14
  101. package/src/customer/validator.ts +0 -26
  102. package/src/payment/api-endpoint.ts +0 -118
  103. package/src/payment/enum/currency.ts +0 -14
  104. package/src/payment/enum/method.ts +0 -2
  105. package/src/payment/enum/status.ts +0 -21
  106. package/src/payment/model.ts +0 -378
  107. package/src/payment/repository.ts +0 -73
  108. package/src/payment/validator.ts +0 -96
  109. package/src/payment-intent/api-endpoint.ts +0 -123
  110. package/src/payment-intent/enum/status.ts +0 -21
  111. package/src/payment-intent/enum/threeds.ts +0 -2
  112. package/src/payment-intent/model.ts +0 -266
  113. package/src/payment-intent/repository.ts +0 -85
  114. package/src/payment-intent/validator.ts +0 -45
  115. package/src/payout/model.ts +0 -8
  116. package/src/refund/api-endpoint.ts +0 -33
  117. package/src/refund/enum/refund-status.ts +0 -11
  118. package/src/refund/model.ts +0 -90
  119. package/src/refund/repository.ts +0 -14
  120. package/src/refund/validator.ts +0 -44
  121. package/src/sepa/api-endpoint.ts +0 -26
  122. package/src/sepa/model.ts +0 -80
  123. package/src/sepa/repository.ts +0 -11
  124. package/src/sepa/validator.ts +0 -56
  125. package/test/fixtures/endpoint.stub.ts +0 -22
  126. package/test/fixtures/list-endpoint.stub.ts +0 -33
  127. package/test/fixtures/list-model.stub.ts +0 -24
  128. package/test/fixtures/model.stub.ts +0 -12
  129. package/test/functional/address.test.ts +0 -126
  130. package/test/functional/card.test.ts +0 -175
  131. package/test/functional/customer.test.ts +0 -174
  132. package/test/functional/payment-intent.test.ts +0 -215
  133. package/test/functional/payment.test.ts +0 -206
  134. package/test/functional/refund.test.ts +0 -112
  135. package/test/functional/sepa.test.ts +0 -136
  136. package/test/integration/stub-integration.test.ts +0 -88
  137. package/test/stub/stub-endpoint.ts +0 -42
  138. package/test/stub/stub-model.ts +0 -82
  139. package/test/stub/stub-repository.ts +0 -11
  140. package/test/test-helper.ts +0 -133
  141. package/test/unit/address/api-endpoint.test.ts +0 -134
  142. package/test/unit/address/fixtures.ts +0 -60
  143. package/test/unit/address/model.test.ts +0 -75
  144. package/test/unit/address/repository.test.ts +0 -148
  145. package/test/unit/address/validator.test.ts +0 -49
  146. package/test/unit/api-endpoint/http/fetch-http-client.test.ts +0 -44
  147. package/test/unit/api-endpoint/http/http.test.ts +0 -152
  148. package/test/unit/card/api-endpoint.test.ts +0 -170
  149. package/test/unit/card/card-helper.ts +0 -116
  150. package/test/unit/card/fixtures.ts +0 -87
  151. package/test/unit/card/model.test.ts +0 -167
  152. package/test/unit/card/repository.test.ts +0 -146
  153. package/test/unit/card/validator.test.ts +0 -96
  154. package/test/unit/core/common/mutation-tracked-object.test.ts +0 -24
  155. package/test/unit/customer/api-endpoint.test.ts +0 -143
  156. package/test/unit/customer/fixtures.ts +0 -73
  157. package/test/unit/customer/model.test.ts +0 -90
  158. package/test/unit/customer/repository.test.ts +0 -148
  159. package/test/unit/customer/validator.test.ts +0 -62
  160. package/test/unit/payment/api-endpoint.test.ts +0 -188
  161. package/test/unit/payment/fixtures.ts +0 -116
  162. package/test/unit/payment/model.test.ts +0 -240
  163. package/test/unit/payment/repository.test.ts +0 -270
  164. package/test/unit/payment/validator.test.ts +0 -137
  165. package/test/unit/payment-intent/api-endpoint.test.ts +0 -142
  166. package/test/unit/payment-intent/fixtures.ts +0 -94
  167. package/test/unit/payment-intent/model.test.ts +0 -157
  168. package/test/unit/payment-intent/repository.test.ts +0 -263
  169. package/test/unit/payment-intent/validator.test.ts +0 -136
  170. package/test/unit/refund/api-endpoint.test.ts +0 -129
  171. package/test/unit/refund/fixtures.ts +0 -58
  172. package/test/unit/refund/model.test.ts +0 -89
  173. package/test/unit/refund/repository.test.ts +0 -157
  174. package/test/unit/refund/validator.test.ts +0 -89
  175. package/test/unit/sepa/api-endpoint.test.ts +0 -170
  176. package/test/unit/sepa/fixture.ts +0 -62
  177. package/test/unit/sepa/model.test.ts +0 -86
  178. package/test/unit/sepa/repository.test.ts +0 -149
  179. package/test/unit/sepa/sepa-helper.ts +0 -71
  180. package/test/unit/sepa/validator.test.ts +0 -58
  181. package/test/unit/stub/stub-endpoint.test.ts +0 -236
  182. package/test/unit/stub/stub-list-endpoint.test.ts +0 -86
  183. package/test/unit/stub/stub-model.test.ts +0 -111
  184. package/test/unit/stub/stub-repository.test.ts +0 -144
@@ -0,0 +1,110 @@
1
+ import { createHmac, timingSafeEqual } from 'crypto';
2
+ import { Temporal } from 'temporal-polyfill';
3
+ import { AbstractModel } from '#core/abstract-model.js';
4
+ import { validateID } from '#core/common/id-validator.js';
5
+ import { StancerValidationError } from '#core/error/validation-error.js';
6
+ import { EventModel, idEvent } from '#event/model.js';
7
+ export const idWebhook = (id) => validateID(id, WebhookModel.regex);
8
+ const isEventData = (data) => {
9
+ if (!data || typeof data !== 'object') {
10
+ return false;
11
+ }
12
+ const properties = Object.getOwnPropertyNames(data);
13
+ if (!properties.includes('id') || !idEvent(data.id)) {
14
+ return false;
15
+ }
16
+ if (!properties.includes('type') ||
17
+ typeof data.type !== 'string' ||
18
+ data.type.indexOf('.') < 0) {
19
+ return false;
20
+ }
21
+ if (!properties.includes('data') || typeof data.data !== 'object') {
22
+ return false;
23
+ }
24
+ return true;
25
+ };
26
+ export class WebhookModel extends AbstractModel {
27
+ //#region static
28
+ static regex = /^we_[a-zA-Z0-9]{24}$/;
29
+ //#endregion
30
+ //#region getters
31
+ get enabled() {
32
+ return this._data.enabled;
33
+ }
34
+ get secret() {
35
+ return this._data.secret;
36
+ }
37
+ get url() {
38
+ return this._data.url;
39
+ }
40
+ //#endregion
41
+ //#region methods
42
+ checkHmac(data, hmac) {
43
+ if (!this.secret) {
44
+ return false;
45
+ }
46
+ const generatedHmac = createHmac('sha256', Buffer.from(this.secret, 'hex')).update(data).digest('hex');
47
+ return timingSafeEqual(Buffer.from(hmac), Buffer.from(generatedHmac));
48
+ }
49
+ checkPayload(signature, payload, time = {
50
+ now: Temporal.Now.instant(),
51
+ delta: new Temporal.Duration(0, 0, 0, 0, 0, 1),
52
+ }) {
53
+ const parsedSignature = this.parseSignature(signature);
54
+ const signatureTime = Temporal.Instant.fromEpochMilliseconds(Number(parsedSignature.timestamp) * 1000);
55
+ const deltaNow = time.now.subtract(time.delta);
56
+ if (Temporal.Instant.compare(deltaNow, signatureTime) > 0) {
57
+ throw new StancerValidationError('Expired signature');
58
+ }
59
+ const ok = this.checkHmac(`${parsedSignature.timestamp}.${payload}`, parsedSignature.expected);
60
+ if (!ok) {
61
+ throw new StancerValidationError('Invalid signature');
62
+ }
63
+ }
64
+ checkRequest(request, time) {
65
+ const signature = request.headers.get('stancer-signature');
66
+ if (!signature) {
67
+ throw new StancerValidationError('Invalid signature');
68
+ }
69
+ if (!request.body) {
70
+ throw new StancerValidationError('Invalid signature');
71
+ }
72
+ this.checkPayload(signature, request.body, time);
73
+ }
74
+ async getEvent(request, time) {
75
+ this.checkRequest(request, time);
76
+ const data = await request.json();
77
+ if (!isEventData(data)) {
78
+ throw new StancerValidationError('Event is malformed');
79
+ }
80
+ return new EventModel(data);
81
+ }
82
+ parseSignature(signature, version = 'v1') {
83
+ const tmp = signature.split(',');
84
+ const parts = {};
85
+ let timestamp = undefined;
86
+ for (const part of tmp) {
87
+ const subPart = part.split('=');
88
+ if (!subPart[0] || typeof subPart[0] !== 'string' || !subPart[1] || typeof subPart[1] !== 'string') {
89
+ throw new StancerValidationError('Invalid signature');
90
+ }
91
+ if (subPart[0] === 't') {
92
+ timestamp = Number(subPart[1]);
93
+ }
94
+ parts[subPart[0]] = subPart[1];
95
+ }
96
+ if (!timestamp || !parts[version]) {
97
+ throw new StancerValidationError('Invalid signature');
98
+ }
99
+ return { timestamp: timestamp, expected: parts[version] };
100
+ }
101
+ setEnabled(enabled) {
102
+ this._data.enabled = enabled;
103
+ return this;
104
+ }
105
+ setUrl(url) {
106
+ this._data.url = url;
107
+ return this;
108
+ }
109
+ }
110
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/webhook/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAkB,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGtE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,UAAU,CAAY,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;AASvF,MAAM,WAAW,GAAG,CAAC,IAAa,EAAqB,EAAE;IACvD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,KAAK,CAA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ACxD,CAAC;YACD,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACvB,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC;YACD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;IAC5D,CAAC;IAED,UAAU,CAAC,OAAgB;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;CAEF"}
@@ -0,0 +1,7 @@
1
+ import { AbstractRepository, type Repository } from '#core/abstract-repository.js';
2
+ import type { EndpointInterface } from '#core/endpoint-interface.js';
3
+ import { type WebhookData, WebhookModel } from '#webhook/model.js';
4
+ export declare class WebhookRepository extends AbstractRepository<WebhookData, WebhookModel> implements Repository<WebhookData, WebhookModel> {
5
+ constructor(endpoint?: EndpointInterface<WebhookData>);
6
+ }
7
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/webhook/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGnE,qBAAa,iBACX,SAAQ,kBAAkB,CAAC,WAAW,EAAE,YAAY,CACpD,YAAW,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC;IAEhD,YAAY,QAAQ,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,EAEpD;CACF"}
@@ -0,0 +1,10 @@
1
+ import { AbstractRepository } from '#core/abstract-repository.js';
2
+ import { WebhookApiEndpoint } from '#webhook/api-endpoint.js';
3
+ import { WebhookModel } from '#webhook/model.js';
4
+ import { webhookValidator } from '#webhook/validator.js';
5
+ export class WebhookRepository extends AbstractRepository {
6
+ constructor(endpoint) {
7
+ super({ endpoint: endpoint ?? new WebhookApiEndpoint(), validator: webhookValidator, model: WebhookModel });
8
+ }
9
+ }
10
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/webhook/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAmB,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAoB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,OAAO,iBACX,SAAQ,kBAA6C;IAGrD,YAAY,QAAyC;QACnD,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,IAAI,IAAI,kBAAkB,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IAC9G,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { type Validator } from '#core/validator.js';
2
+ import { type WebhookData } from './model.js';
3
+ export declare const webhookValidator: Validator<WebhookData>;
4
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/webhook/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAkB,KAAK,WAAW,EAAgB,MAAM,YAAY,CAAC;AAO5E,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,WAAW,CAOnD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { IdValidator } from '#core/common/id-validator.js';
2
+ import { goldilocksValidator } from '#core/validator.js';
3
+ import { WebhookModel } from './model.js';
4
+ const booleanValidator = (name) => ({
5
+ errorMessage: (value) => `${name} must be a boolean, ${value} given`,
6
+ validate: (value) => typeof value === 'boolean',
7
+ });
8
+ export const webhookValidator = {
9
+ id: IdValidator(WebhookModel.regex),
10
+ createdAt: true,
11
+ deleted: true,
12
+ enabled: booleanValidator('enabled'),
13
+ secret: true,
14
+ url: goldilocksValidator('url', { min: 1, max: 2048 }),
15
+ };
16
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/webhook/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAkB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAoC,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;IAC1C,YAAY,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,GAAG,IAAI,uBAAuB,KAAK,QAAQ;IAC7E,QAAQ,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS;CACzD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAA2B;IACtD,EAAE,EAAE,WAAW,CAAY,YAAY,CAAC,KAAK,CAAC;IAC9C,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;IACpC,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,mBAAmB,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;CACvD,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,43 @@
1
1
  {
2
2
  "name": "@stancer/stancer",
3
3
  "description": "Stancer node TypeScript SDK",
4
- "version": "1.0.2",
4
+ "version": "1.1.1",
5
5
  "license": "MIT",
6
6
  "engines": {
7
7
  "node": ">=22"
8
8
  },
9
+ "devEngines": {
10
+ "packageManager": {
11
+ "name": "pnpm",
12
+ "version": "^11.0.0",
13
+ "onFail": "download"
14
+ }
15
+ },
9
16
  "type": "module",
17
+ "imports": {
18
+ "#address/*": "./dist/address/*",
19
+ "#api/*": "./dist/api-endpoint/*",
20
+ "#card/*": "./dist/card/*",
21
+ "#core/*": "./dist/core/*",
22
+ "#customer/*": "./dist/customer/*",
23
+ "#error/*": "./dist/core/error/*",
24
+ "#event/*": "./dist/event/*",
25
+ "#payment-intent/*": "./dist/payment-intent/*",
26
+ "#payment/*": "./dist/payment/*",
27
+ "#payout/*": "./dist/payout/*",
28
+ "#refund/*": "./dist/refund/*",
29
+ "#sepa/*": "./dist/sepa/*",
30
+ "#test/*": "./test/*",
31
+ "#webhook/*": "./dist/webhook/*"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ }
38
+ },
39
+ "main": "./dist/index.js",
40
+ "types": "./dist/index.d.ts",
10
41
  "dependencies": {
11
42
  "temporal-polyfill": "^1.0.0"
12
43
  },
@@ -19,7 +50,7 @@
19
50
  "eslint": "^10.0.0",
20
51
  "eslint-formatter-junit": "^9.0.0",
21
52
  "globals": "^17.0.0",
22
- "libphonenumber-js": "^1.13.10",
53
+ "libphonenumber-js": "^1.0.0",
23
54
  "prettier": "^3.0.0",
24
55
  "typescript": "npm:@typescript/typescript6@^6.0.0",
25
56
  "typescript-eslint": "^8.0.0",
@@ -30,26 +61,6 @@
30
61
  "TypeScript",
31
62
  "Stancer"
32
63
  ],
33
- "devEngines": {
34
- "packageManager": {
35
- "name": "pnpm",
36
- "version": "^11.0.0",
37
- "onFail": "download"
38
- }
39
- },
40
- "imports": {
41
- "#api/*": "./src/api-endpoint/*",
42
- "#address/*": "./src/address/*",
43
- "#core/*": "./src/core/*",
44
- "#error/*": "./src/core/error/*",
45
- "#test/*": "./test/*",
46
- "#card/*": "./src/card/*",
47
- "#sepa/*": "./src/sepa/*",
48
- "#customer/*": "./src/customer/*",
49
- "#payment/*": "./src/payment/*",
50
- "#refund/*": "./src/refund/*",
51
- "#payment-intent/*": "./src/payment-intent/*"
52
- },
53
64
  "scripts": {
54
65
  "build": "tsc",
55
66
  "clean": "rm -rf dist/ node_modules/",
package/dist/main.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=main.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
package/dist/main.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
package/reports/base.css DELETED
@@ -1,362 +0,0 @@
1
- body,
2
- html {
3
- margin: 0;
4
- padding: 0;
5
- height: 100%;
6
- }
7
- body {
8
- color: #333;
9
- font-size: 14px;
10
- font-family:
11
- Helvetica Neue,
12
- Helvetica,
13
- Arial;
14
- }
15
- .small {
16
- font-size: 12px;
17
- }
18
- *,
19
- *:after,
20
- *:before {
21
- -webkit-box-sizing: border-box;
22
- -moz-box-sizing: border-box;
23
- box-sizing: border-box;
24
- }
25
- h1 {
26
- margin: 0;
27
- font-size: 20px;
28
- }
29
- h2 {
30
- font-size: 14px;
31
- }
32
- pre {
33
- margin: 0;
34
- padding: 0;
35
- font:
36
- 12px/1.4 Consolas,
37
- 'Liberation Mono',
38
- Menlo,
39
- Courier,
40
- monospace;
41
- -moz-tab-size: 2;
42
- -o-tab-size: 2;
43
- tab-size: 2;
44
- }
45
- a {
46
- color: #0074d9;
47
- text-decoration: none;
48
- }
49
- a:hover {
50
- text-decoration: underline;
51
- }
52
- .strong {
53
- font-weight: bold;
54
- }
55
- .space-top1 {
56
- padding: 10px 0 0 0;
57
- }
58
- .pad2y {
59
- padding: 20px 0;
60
- }
61
- .pad1y {
62
- padding: 10px 0;
63
- }
64
- .pad2x {
65
- padding: 0 20px;
66
- }
67
- .pad2 {
68
- padding: 20px;
69
- }
70
- .pad1 {
71
- padding: 10px;
72
- }
73
- .space-left2 {
74
- padding-left: 55px;
75
- }
76
- .space-right2 {
77
- padding-right: 20px;
78
- }
79
- .center {
80
- text-align: center;
81
- }
82
- .clearfix {
83
- display: block;
84
- }
85
- .clearfix:after {
86
- display: block;
87
- clear: both;
88
- visibility: hidden;
89
- height: 0;
90
- content: '';
91
- }
92
- .fl {
93
- float: left;
94
- }
95
- @media only screen and (max-width: 640px) {
96
- .col3 {
97
- width: 100%;
98
- max-width: 100%;
99
- }
100
- .hide-mobile {
101
- display: none !important;
102
- }
103
- }
104
-
105
- .quiet {
106
- color: #7f7f7f;
107
- color: rgba(0, 0, 0, 0.5);
108
- }
109
- .quiet a {
110
- opacity: 0.7;
111
- }
112
-
113
- .fraction {
114
- vertical-align: middle;
115
- border-radius: 3px;
116
- background: #e8e8e8;
117
- padding: 4px 5px;
118
- color: #555;
119
- font-size: 10px;
120
- font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
121
- }
122
-
123
- div.path a:link,
124
- div.path a:visited {
125
- color: #333;
126
- }
127
- table.coverage {
128
- margin: 10px 0 0 0;
129
- border-collapse: collapse;
130
- padding: 0;
131
- }
132
-
133
- table.coverage td {
134
- vertical-align: top;
135
- margin: 0;
136
- padding: 0;
137
- }
138
- table.coverage td.line-count {
139
- padding: 0 5px 0 20px;
140
- text-align: right;
141
- }
142
- table.coverage td.line-coverage {
143
- padding-right: 10px;
144
- min-width: 20px;
145
- text-align: right;
146
- }
147
-
148
- table.coverage td span.cline-any {
149
- display: inline-block;
150
- padding: 0 5px;
151
- width: 100%;
152
- }
153
- .missing-if-branch {
154
- display: inline-block;
155
- position: relative;
156
- margin-right: 5px;
157
- border-radius: 3px;
158
- background: #333;
159
- padding: 0 4px;
160
- color: yellow;
161
- }
162
-
163
- .skip-if-branch {
164
- display: none;
165
- position: relative;
166
- margin-right: 10px;
167
- background: #ccc;
168
- padding: 0 4px;
169
- color: white;
170
- }
171
- .missing-if-branch .typ,
172
- .skip-if-branch .typ {
173
- color: inherit !important;
174
- }
175
- .coverage-summary {
176
- border-collapse: collapse;
177
- width: 100%;
178
- }
179
- .coverage-summary tr {
180
- border-bottom: 1px solid #bbb;
181
- }
182
- .keyline-all {
183
- border: 1px solid #ddd;
184
- }
185
- .coverage-summary td,
186
- .coverage-summary th {
187
- padding: 10px;
188
- }
189
- .coverage-summary tbody {
190
- border: 1px solid #bbb;
191
- }
192
- .coverage-summary td {
193
- border-right: 1px solid #bbb;
194
- }
195
- .coverage-summary td:last-child {
196
- border-right: none;
197
- }
198
- .coverage-summary th {
199
- font-weight: normal;
200
- text-align: left;
201
- white-space: nowrap;
202
- }
203
- .coverage-summary th.file {
204
- border-right: none !important;
205
- }
206
- .coverage-summary th.pct {
207
- }
208
- .coverage-summary th.pic,
209
- .coverage-summary th.abs,
210
- .coverage-summary td.pct,
211
- .coverage-summary td.abs {
212
- text-align: right;
213
- }
214
- .coverage-summary td.file {
215
- white-space: nowrap;
216
- }
217
- .coverage-summary td.pic {
218
- min-width: 120px !important;
219
- }
220
- .coverage-summary tfoot td {
221
- }
222
-
223
- .coverage-summary .sorter {
224
- display: inline-block;
225
- margin-left: 0.5em;
226
- background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
227
- width: 7px;
228
- height: 10px;
229
- }
230
- .coverage-summary .sorted .sorter {
231
- background-position: 0 -20px;
232
- }
233
- .coverage-summary .sorted-desc .sorter {
234
- background-position: 0 -10px;
235
- }
236
- .status-line {
237
- height: 10px;
238
- }
239
- /* yellow */
240
- .cbranch-no {
241
- background: yellow !important;
242
- color: #111;
243
- }
244
- /* dark red */
245
- .red.solid,
246
- .status-line.low,
247
- .low .cover-fill {
248
- background: #c21f39;
249
- }
250
- .low .chart {
251
- border: 1px solid #c21f39;
252
- }
253
- .highlighted,
254
- .highlighted .cstat-no,
255
- .highlighted .fstat-no,
256
- .highlighted .cbranch-no {
257
- background: #c21f39 !important;
258
- }
259
- /* medium red */
260
- .cstat-no,
261
- .fstat-no,
262
- .cbranch-no,
263
- .cbranch-no {
264
- background: #f6c6ce;
265
- }
266
- /* light red */
267
- .low,
268
- .cline-no {
269
- background: #fce1e5;
270
- }
271
- /* light green */
272
- .high,
273
- .cline-yes {
274
- background: rgb(230, 245, 208);
275
- }
276
- /* medium green */
277
- .cstat-yes {
278
- background: rgb(161, 215, 106);
279
- }
280
- /* dark green */
281
- .status-line.high,
282
- .high .cover-fill {
283
- background: rgb(77, 146, 33);
284
- }
285
- .high .chart {
286
- border: 1px solid rgb(77, 146, 33);
287
- }
288
- /* dark yellow (gold) */
289
- .status-line.medium,
290
- .medium .cover-fill {
291
- background: #f9cd0b;
292
- }
293
- .medium .chart {
294
- border: 1px solid #f9cd0b;
295
- }
296
- /* light yellow */
297
- .medium {
298
- background: #fff4c2;
299
- }
300
-
301
- .cstat-skip {
302
- background: #ddd;
303
- color: #111;
304
- }
305
- .fstat-skip {
306
- background: #ddd;
307
- color: #111 !important;
308
- }
309
- .cbranch-skip {
310
- background: #ddd !important;
311
- color: #111;
312
- }
313
-
314
- span.cline-neutral {
315
- background: #eaeaea;
316
- }
317
-
318
- .coverage-summary td.empty {
319
- opacity: 0.5;
320
- padding-top: 4px;
321
- padding-bottom: 4px;
322
- color: #888;
323
- line-height: 1;
324
- }
325
-
326
- .cover-fill,
327
- .cover-empty {
328
- display: inline-block;
329
- height: 12px;
330
- }
331
- .chart {
332
- line-height: 0;
333
- }
334
- .cover-empty {
335
- background: white;
336
- }
337
- .cover-full {
338
- border-right: none !important;
339
- }
340
- pre.prettyprint {
341
- margin: 0 !important;
342
- border: none !important;
343
- padding: 0 !important;
344
- }
345
- .com {
346
- color: #999 !important;
347
- }
348
- .ignore-none {
349
- color: #999;
350
- font-weight: normal;
351
- }
352
-
353
- .wrapper {
354
- margin: 0 auto -48px;
355
- height: auto !important;
356
- height: 100%;
357
- min-height: 100%;
358
- }
359
- .footer,
360
- .push {
361
- height: 48px;
362
- }