@xyo-network/rebilly-payment-card-authorization-plugin 4.1.1 → 5.0.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,69 +1,5 @@
1
- import { RebillyApiDomainSettings, RebillyPublishableApiSettings, RebillyOrganizationSettings } from '@xyo-network/rebilly-payment-payload-plugin';
2
- import { SentinelConfig, SentinelParams, SentinelModuleEventData, SentinelInstance } from '@xyo-network/sentinel-model';
3
- import { AnyConfigSchema } from '@xyo-network/module-model';
4
- import { Payload } from '@xyo-network/payload-model';
5
- import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
6
- import { AxiosRequestConfig } from 'axios';
7
-
8
- declare const RebillyPaymentCardAuthorizationSentinelConfigSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly.config";
9
- type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema;
10
- interface RebillyPaymentCardAuthorizationSentinelConfig extends SentinelConfig<{
11
- /**
12
- * The config schema
13
- */
14
- schema: RebillyPaymentCardAuthorizationSentinelConfigSchema;
15
- }>, Partial<RebillyApiDomainSettings> {
16
- }
17
-
18
- type RebillyPaymentCardAuthorizationParams = Partial<RebillyPublishableApiSettings & RebillyOrganizationSettings>;
19
- interface RebillyPaymentCardAuthorizationSentinelParams<TConfig extends AnyConfigSchema<RebillyPaymentCardAuthorizationSentinelConfig> = AnyConfigSchema<RebillyPaymentCardAuthorizationSentinelConfig>> extends SentinelParams<TConfig> {
20
- domain?: string;
21
- organizationId?: string;
22
- publishableApiKey?: string;
23
- }
24
-
25
- declare const RebillyPaymentCardAuthorizationSentinelSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly";
26
- type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema;
27
-
28
- declare class RebillyPaymentCardAuthorizationSentinel<TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
29
- static readonly configSchemas: string[];
30
- static readonly defaultConfigSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly.config";
31
- protected _apiRoot: string | undefined;
32
- protected _domain: string | undefined;
33
- protected _headers: AxiosRequestConfig['headers'] | undefined;
34
- protected _organizationId: string | undefined;
35
- protected _publishableApiKey: string | undefined;
36
- protected _tokenEndpoint: string | undefined;
37
- /**
38
- * The Rebilly Organization API root endpoint
39
- */
40
- protected get apiRoot(): string;
41
- /**
42
- * The Rebilly domain
43
- */
44
- protected get domain(): string;
45
- /**
46
- * The headers to be included in the request for each request
47
- */
48
- protected get headers(): AxiosRequestConfig['headers'];
49
- /**
50
- * True if the environment is sandbox (testing), false otherwise
51
- */
52
- protected get isSandboxEnvironment(): boolean;
53
- /**
54
- * The Rebilly organization ID
55
- */
56
- protected get organizationId(): string;
57
- /**
58
- * The Rebilly Publishable API key
59
- */
60
- protected get publishableApiKey(): string;
61
- /**
62
- * The Rebilly Organization token creation endpoint
63
- */
64
- protected get tokenEndpoint(): string;
65
- reportHandler(payloads?: Payload[]): Promise<Payload[]>;
66
- }
67
-
68
- export { RebillyPaymentCardAuthorizationSentinel, RebillyPaymentCardAuthorizationSentinelConfigSchema, RebillyPaymentCardAuthorizationSentinelSchema };
69
- export type { RebillyPaymentCardAuthorizationParams, RebillyPaymentCardAuthorizationSentinelConfig, RebillyPaymentCardAuthorizationSentinelParams };
1
+ export * from './Config.ts';
2
+ export * from './Params.ts';
3
+ export * from './Schema.ts';
4
+ export * from './Sentinel.ts';
5
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/rebilly-payment-card-authorization-plugin",
3
- "version": "4.1.1",
3
+ "version": "5.0.0",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -28,24 +28,27 @@
28
28
  },
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "src"
34
+ ],
31
35
  "dependencies": {
32
- "@xylabs/assert": "^4.13.23",
33
- "@xylabs/axios": "^4.13.23",
34
- "@xyo-network/module-model": "^4.1.7",
35
- "@xyo-network/payload-builder": "^4.1.7",
36
- "@xyo-network/payload-model": "^4.1.7",
37
- "@xyo-network/payment-payload-plugins": "^4.1.1",
38
- "@xyo-network/rebilly-payment-payload-plugin": "^4.1.1",
39
- "@xyo-network/sentinel-abstract": "^4.1.7",
40
- "@xyo-network/sentinel-model": "^4.1.7",
41
- "axios": "^1.10.0"
36
+ "@xylabs/assert": "^5.0.0",
37
+ "@xylabs/axios": "^5.0.0",
38
+ "@xyo-network/module-model": "^5.0.0",
39
+ "@xyo-network/payload-builder": "^5.0.0",
40
+ "@xyo-network/payload-model": "^5.0.0",
41
+ "@xyo-network/payment-payload-plugins": "^5.0.0",
42
+ "@xyo-network/rebilly-payment-payload-plugin": "^5.0.0",
43
+ "@xyo-network/sentinel-abstract": "^5.0.0",
44
+ "@xyo-network/sentinel-model": "^5.0.0",
45
+ "axios": "^1.11.0"
42
46
  },
43
47
  "devDependencies": {
44
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.24",
45
- "@xylabs/tsconfig": "^7.0.0-rc.24",
46
- "@xylabs/vitest-extended": "^4.13.23",
47
- "@xyo-network/boundwitness-model": "^4.1.7",
48
- "knip": "^5.62.0",
48
+ "@xylabs/ts-scripts-yarn3": "^7.0.2",
49
+ "@xylabs/tsconfig": "^7.0.2",
50
+ "@xylabs/vitest-extended": "^5.0.0",
51
+ "@xyo-network/boundwitness-model": "^5.0.0",
49
52
  "typescript": "^5.8.3",
50
53
  "vitest": "^3.2.4"
51
54
  },
@@ -0,0 +1,94 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { assertEx } from '@xylabs/assert'
4
+ import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
+ import { isBoundWitness } from '@xyo-network/boundwitness-model'
6
+ import { PayloadBuilder } from '@xyo-network/payload-builder'
7
+ import type { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'
8
+ import { BillingAddressSchema, PaymentCardSchema } from '@xyo-network/payment-payload-plugins'
9
+ import { isRebillyPaymentAuthorizationTokenWithSources } from '@xyo-network/rebilly-payment-payload-plugin'
10
+ import {
11
+ beforeAll, describe, expect,
12
+ it,
13
+ } from 'vitest'
14
+
15
+ import { RebillyPaymentCardAuthorizationSentinelConfigSchema } from '../Config.ts'
16
+ import type { RebillyPaymentCardAuthorizationSentinelParams } from '../Params.ts'
17
+ import { RebillyPaymentCardAuthorizationSentinel } from '../Sentinel.ts'
18
+
19
+ const getTestPaymentCardRequest = (cardNumber: string, cvv: string): [PaymentCard, BillingAddress] => {
20
+ const paymentCard: PaymentCard = {
21
+ cardNumber,
22
+ cvv,
23
+ expMonth: new Date().getMonth() + 1,
24
+ expYear: new Date().getFullYear() + 1,
25
+ schema: PaymentCardSchema,
26
+ }
27
+ // https://simpsons.fandom.com/wiki/123_Fake_Street
28
+ const billingAddress: BillingAddress = {
29
+ address: '123 Fake Street',
30
+ city: 'Oak Lawn',
31
+ country: 'US',
32
+ firstName: 'Marge',
33
+ lastName: 'Simpson',
34
+ postalCode: '60453',
35
+ region: 'IL',
36
+ schema: BillingAddressSchema,
37
+ }
38
+ return [paymentCard, billingAddress]
39
+ }
40
+
41
+ describe.skipIf(!process.env.REB_PUB_APIKEY)('RebillyPaymentCardAuthorizationSentinel', () => {
42
+ const publishableApiKey = assertEx(process.env.REB_PUB_APIKEY)
43
+ assertEx(publishableApiKey.includes('sandbox'), () => 'RebillyPaymentCardAuthorizationSentinel should only be tested in sandbox environment')
44
+ const organizationId = assertEx(process.env.REB_ORGANIZATION_ID)
45
+ let sentinel: RebillyPaymentCardAuthorizationSentinel
46
+ beforeAll(async () => {
47
+ const config = {
48
+ schema: RebillyPaymentCardAuthorizationSentinelConfigSchema, synchronous: true, tasks: [],
49
+ }
50
+ const domain = 'https://api-sandbox.rebilly.com'
51
+ sentinel = await RebillyPaymentCardAuthorizationSentinel.create({
52
+ account: 'random',
53
+ config,
54
+ domain,
55
+ organizationId,
56
+ publishableApiKey,
57
+ } as RebillyPaymentCardAuthorizationSentinelParams)
58
+ })
59
+
60
+ const cases = [
61
+ ['Visa', '4111111111111111', '123'],
62
+ ['Mastercard', '5555555555554444', '123'],
63
+ ['American Express', '378282246310005', '1234'],
64
+ ['Discover', '6011111111111117', '123'],
65
+ ]
66
+ describe('report', () => {
67
+ it.each(cases)('returns created payment token for %s', async (_, pan, cvv) => {
68
+ // Arrange
69
+ const [paymentCard, billingAddress] = getTestPaymentCardRequest(pan, cvv)
70
+
71
+ // Act
72
+ const response = await sentinel.report([paymentCard, billingAddress])
73
+
74
+ // Assert
75
+ expect(response).toBeDefined()
76
+ expect(response).toBeArray()
77
+ const [bw, ...payloads] = response
78
+ expect(bw).toBeDefined()
79
+ expect(isBoundWitness(bw)).toBeTrue()
80
+ const boundWitness: BoundWitness = assertEx([bw].find(isBoundWitness))
81
+ expect(boundWitness.addresses).toContain(sentinel.address)
82
+
83
+ expect(payloads).toBeArray()
84
+ expect(payloads.length).toBeGreaterThanOrEqual(1)
85
+
86
+ const payload = payloads.find(isRebillyPaymentAuthorizationTokenWithSources)
87
+ expect(payload).toBeDefined()
88
+ const token = assertEx(payload)
89
+ expect(token.id).toBeString()
90
+ expect(token.$sources).toBeArrayOfSize(2)
91
+ expect(token.$sources).toEqual(await PayloadBuilder.dataHashes([paymentCard, billingAddress]))
92
+ })
93
+ })
94
+ })
@@ -0,0 +1,22 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`toTokenRequest > convert a payment card and billing address to a token request 1`] = `
4
+ {
5
+ "billingAddress": {
6
+ "address": "123 Fake Street",
7
+ "city": "Oak Lawn",
8
+ "country": "US",
9
+ "firstName": "Marge",
10
+ "lastName": "Simpson",
11
+ "postalCode": "60453",
12
+ "region": "IL",
13
+ },
14
+ "method": "payment-card",
15
+ "paymentInstrument": {
16
+ "cvv": "123",
17
+ "expMonth": 1,
18
+ "expYear": 3030,
19
+ "pan": "4111111111111111",
20
+ },
21
+ }
22
+ `;
@@ -0,0 +1,37 @@
1
+ import type { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'
2
+ import { BillingAddressSchema, PaymentCardSchema } from '@xyo-network/payment-payload-plugins'
3
+ import {
4
+ describe, expect,
5
+ it,
6
+ } from 'vitest'
7
+
8
+ import { toTokenRequest } from '../toTokenRequest.ts'
9
+
10
+ describe('toTokenRequest', () => {
11
+ const cases: [PaymentCard, BillingAddress][] = [
12
+ [
13
+ {
14
+ cardNumber: '4111111111111111',
15
+ cvv: '123',
16
+ expMonth: 1,
17
+ expYear: 3030,
18
+ schema: PaymentCardSchema,
19
+ },
20
+ {
21
+ // https://simpsons.fandom.com/wiki/123_Fake_Street
22
+ address: '123 Fake Street',
23
+ city: 'Oak Lawn',
24
+ country: 'US',
25
+ firstName: 'Marge',
26
+ lastName: 'Simpson',
27
+ postalCode: '60453',
28
+ region: 'IL',
29
+ schema: BillingAddressSchema,
30
+ },
31
+ ],
32
+ ]
33
+ it.each(cases)('convert a payment card and billing address to a token request', (paymentCard, billingAddress) => {
34
+ const result = toTokenRequest(paymentCard, billingAddress)
35
+ expect(result).toMatchSnapshot()
36
+ })
37
+ })
package/typedoc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": ["./src/index.ts"],
4
- "tsconfig": "./tsconfig.typedoc.json"
5
- }
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- node: {},
6
- neutral: { src: true },
7
- },
8
- }
9
-
10
- export default config