@xyo-network/rebilly-payment-card-authorization-plugin 2.95.5 → 2.96.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/browser/index.cjs +7 -14
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +7 -14
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +7 -14
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +7 -14
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +7 -14
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +7 -14
- package/dist/node/index.js.map +1 -1
- package/package.json +12 -12
package/dist/browser/index.cjs
CHANGED
|
@@ -70,24 +70,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
70
70
|
* The Rebilly Organization API root endpoint
|
|
71
71
|
*/
|
|
72
72
|
get apiRoot() {
|
|
73
|
-
if (!this._apiRoot)
|
|
74
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
73
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
75
74
|
return this._apiRoot;
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
77
|
* The Rebilly domain
|
|
79
78
|
*/
|
|
80
79
|
get domain() {
|
|
81
|
-
if (!this._domain)
|
|
82
|
-
this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
80
|
+
if (!this._domain) this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
83
81
|
return this._domain;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* The headers to be included in the request for each request
|
|
87
85
|
*/
|
|
88
86
|
get headers() {
|
|
89
|
-
if (!this._headers)
|
|
90
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
87
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
91
88
|
return this._headers;
|
|
92
89
|
}
|
|
93
90
|
/**
|
|
@@ -119,21 +116,17 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
119
116
|
* The Rebilly Organization token creation endpoint
|
|
120
117
|
*/
|
|
121
118
|
get tokenEndpoint() {
|
|
122
|
-
if (!this._tokenEndpoint)
|
|
123
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
119
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
124
120
|
return this._tokenEndpoint;
|
|
125
121
|
}
|
|
126
122
|
async reportHandler(payloads) {
|
|
127
123
|
await this.started("throw");
|
|
128
124
|
const results = [];
|
|
129
|
-
if (!payloads || payloads.length === 0)
|
|
130
|
-
return results;
|
|
125
|
+
if (!payloads || payloads.length === 0) return results;
|
|
131
126
|
const paymentCard = payloads?.find(import_payment_payload_plugins.isPaymentCard);
|
|
132
|
-
if (!paymentCard)
|
|
133
|
-
return results;
|
|
127
|
+
if (!paymentCard) return results;
|
|
134
128
|
const billingAddress = payloads?.find(import_payment_payload_plugins.isBillingAddress);
|
|
135
|
-
if (!billingAddress)
|
|
136
|
-
return results;
|
|
129
|
+
if (!billingAddress) return results;
|
|
137
130
|
const axios = new import_axios.AxiosJson({ headers: this.headers });
|
|
138
131
|
try {
|
|
139
132
|
const data = toTokenRequest(paymentCard, billingAddress);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,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C,KAAK;AACR,WAAK,yBAAqB,wBAAS,KAAK,OAAO,mBAAmB,MAAM,GAAG,UAAU,uCAAuC;AAC9H,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAc,gBAAgB;AAC5B,QAAI,CAAC,KAAK,eAAgB,MAAK,iBAAiB,GAAG,KAAK,OAAO;AAC/D,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAe,cAAc,UAA0C;AACrE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,UAA2D,CAAC;AAElE,QAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;AAC/C,UAAM,cAAc,UAAU,KAAK,4CAAa;AAChD,QAAI,CAAC,YAAa,QAAO;AACzB,UAAM,iBAAiB,UAAU,KAAK,+CAAgB;AACtD,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,QAAQ,IAAI,uBAAU,EAAE,SAAS,KAAK,QAAQ,CAAC;AACrD,QAAI;AACF,YAAM,OAAO,eAAe,aAAa,cAAc;AACvD,YAAM,WAAW,MAAM,MAAM,KAA0B,KAAK,eAAe,IAAI;AAC/E,kCAAS,SAAS,WAAW,4BAAe,SAAS,MAAM,oCAAoC,SAAS,MAAM,EAAE;AAChH,YAAM,EAAE,GAAG,IAAI,SAAS;AACxB,YAAM,UAAU,MAAM,sCAAe,WAAW,CAAC,aAAa,cAAc,CAAC;AAC7E,cAAQ,KAAK,EAAE,IAAI,QAAQ,8EAAwC,QAAQ,CAAC;AAAA,IAC9E,SAAS,OAAO;AACd,WAAK,QAAQ,QAAQ,GAAG,UAAU,mCAAmC,KAAK,EAAE;AAAA,IAC9E;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/browser/index.js
CHANGED
|
@@ -42,24 +42,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
42
42
|
* The Rebilly Organization API root endpoint
|
|
43
43
|
*/
|
|
44
44
|
get apiRoot() {
|
|
45
|
-
if (!this._apiRoot)
|
|
46
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
45
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
47
46
|
return this._apiRoot;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* The Rebilly domain
|
|
51
50
|
*/
|
|
52
51
|
get domain() {
|
|
53
|
-
if (!this._domain)
|
|
54
|
-
this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
52
|
+
if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
55
53
|
return this._domain;
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* The headers to be included in the request for each request
|
|
59
57
|
*/
|
|
60
58
|
get headers() {
|
|
61
|
-
if (!this._headers)
|
|
62
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
59
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
63
60
|
return this._headers;
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
@@ -91,21 +88,17 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
91
88
|
* The Rebilly Organization token creation endpoint
|
|
92
89
|
*/
|
|
93
90
|
get tokenEndpoint() {
|
|
94
|
-
if (!this._tokenEndpoint)
|
|
95
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
91
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
96
92
|
return this._tokenEndpoint;
|
|
97
93
|
}
|
|
98
94
|
async reportHandler(payloads) {
|
|
99
95
|
await this.started("throw");
|
|
100
96
|
const results = [];
|
|
101
|
-
if (!payloads || payloads.length === 0)
|
|
102
|
-
return results;
|
|
97
|
+
if (!payloads || payloads.length === 0) return results;
|
|
103
98
|
const paymentCard = payloads?.find(isPaymentCard);
|
|
104
|
-
if (!paymentCard)
|
|
105
|
-
return results;
|
|
99
|
+
if (!paymentCard) return results;
|
|
106
100
|
const billingAddress = payloads?.find(isBillingAddress);
|
|
107
|
-
if (!billingAddress)
|
|
108
|
-
return results;
|
|
101
|
+
if (!billingAddress) return results;
|
|
109
102
|
const axios = new AxiosJson({ headers: this.headers });
|
|
110
103
|
try {
|
|
111
104
|
const data = toTokenRequest(paymentCard, billingAddress);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,SAAS,gBAAgB;AACzB,SAAS,WAA+B,sBAAsB;AAC9D,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAChD,SAA2C,8CAA8C;AACzF,SAAS,wBAAwB;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH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,eAAe,WAAW,CAAC,aAAa,cAAc,CAAC;AAC7E,cAAQ,KAAK,EAAE,IAAI,QAAQ,wCAAwC,QAAQ,CAAC;AAAA,IAC9E,SAAS,OAAO;AACd,WAAK,QAAQ,QAAQ,GAAG,UAAU,mCAAmC,KAAK,EAAE;AAAA,IAC9E;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -70,24 +70,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
70
70
|
* The Rebilly Organization API root endpoint
|
|
71
71
|
*/
|
|
72
72
|
get apiRoot() {
|
|
73
|
-
if (!this._apiRoot)
|
|
74
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
73
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
75
74
|
return this._apiRoot;
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
77
|
* The Rebilly domain
|
|
79
78
|
*/
|
|
80
79
|
get domain() {
|
|
81
|
-
if (!this._domain)
|
|
82
|
-
this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
80
|
+
if (!this._domain) this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
83
81
|
return this._domain;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* The headers to be included in the request for each request
|
|
87
85
|
*/
|
|
88
86
|
get headers() {
|
|
89
|
-
if (!this._headers)
|
|
90
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
87
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
91
88
|
return this._headers;
|
|
92
89
|
}
|
|
93
90
|
/**
|
|
@@ -119,21 +116,17 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
119
116
|
* The Rebilly Organization token creation endpoint
|
|
120
117
|
*/
|
|
121
118
|
get tokenEndpoint() {
|
|
122
|
-
if (!this._tokenEndpoint)
|
|
123
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
119
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
124
120
|
return this._tokenEndpoint;
|
|
125
121
|
}
|
|
126
122
|
async reportHandler(payloads) {
|
|
127
123
|
await this.started("throw");
|
|
128
124
|
const results = [];
|
|
129
|
-
if (!payloads || payloads.length === 0)
|
|
130
|
-
return results;
|
|
125
|
+
if (!payloads || payloads.length === 0) return results;
|
|
131
126
|
const paymentCard = payloads?.find(import_payment_payload_plugins.isPaymentCard);
|
|
132
|
-
if (!paymentCard)
|
|
133
|
-
return results;
|
|
127
|
+
if (!paymentCard) return results;
|
|
134
128
|
const billingAddress = payloads?.find(import_payment_payload_plugins.isBillingAddress);
|
|
135
|
-
if (!billingAddress)
|
|
136
|
-
return results;
|
|
129
|
+
if (!billingAddress) return results;
|
|
137
130
|
const axios = new import_axios.AxiosJson({ headers: this.headers });
|
|
138
131
|
try {
|
|
139
132
|
const data = toTokenRequest(paymentCard, billingAddress);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,0CAAsC;AA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iB,GAAG,KAAK,OAAO;AAC/D,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAe,cAAc,UAA0C;AACrE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,UAA2D,CAAC;AAElE,QAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;AAC/C,UAAM,cAAc,UAAU,KAAK,4CAAa;AAChD,QAAI,CAAC,YAAa,QAAO;AACzB,UAAM,iBAAiB,UAAU,KAAK,+CAAgB;AACtD,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,QAAQ,IAAI,uBAAU,EAAE,SAAS,KAAK,QAAQ,CAAC;AACrD,QAAI;AACF,YAAM,OAAO,eAAe,aAAa,cAAc;AACvD,YAAM,WAAW,MAAM,MAAM,KAA0B,KAAK,eAAe,IAAI;AAC/E,kCAAS,SAAS,WAAW,4BAAe,SAAS,MAAM,oCAAoC,SAAS,MAAM,EAAE;AAChH,YAAM,EAAE,GAAG,IAAI,SAAS;AACxB,YAAM,UAAU,MAAM,sCAAe,WAAW,CAAC,aAAa,cAAc,CAAC;AAC7E,cAAQ,KAAK,EAAE,IAAI,QAAQ,8EAAwC,QAAQ,CAAC;AAAA,IAC9E,SAAS,OAAO;AACd,WAAK,QAAQ,QAAQ,GAAG,UAAU,mCAAmC,KAAK,EAAE;AAAA,IAC9E;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -42,24 +42,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
42
42
|
* The Rebilly Organization API root endpoint
|
|
43
43
|
*/
|
|
44
44
|
get apiRoot() {
|
|
45
|
-
if (!this._apiRoot)
|
|
46
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
45
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
47
46
|
return this._apiRoot;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* The Rebilly domain
|
|
51
50
|
*/
|
|
52
51
|
get domain() {
|
|
53
|
-
if (!this._domain)
|
|
54
|
-
this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
52
|
+
if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
55
53
|
return this._domain;
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* The headers to be included in the request for each request
|
|
59
57
|
*/
|
|
60
58
|
get headers() {
|
|
61
|
-
if (!this._headers)
|
|
62
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
59
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
63
60
|
return this._headers;
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
@@ -91,21 +88,17 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
91
88
|
* The Rebilly Organization token creation endpoint
|
|
92
89
|
*/
|
|
93
90
|
get tokenEndpoint() {
|
|
94
|
-
if (!this._tokenEndpoint)
|
|
95
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
91
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
96
92
|
return this._tokenEndpoint;
|
|
97
93
|
}
|
|
98
94
|
async reportHandler(payloads) {
|
|
99
95
|
await this.started("throw");
|
|
100
96
|
const results = [];
|
|
101
|
-
if (!payloads || payloads.length === 0)
|
|
102
|
-
return results;
|
|
97
|
+
if (!payloads || payloads.length === 0) return results;
|
|
103
98
|
const paymentCard = payloads?.find(isPaymentCard);
|
|
104
|
-
if (!paymentCard)
|
|
105
|
-
return results;
|
|
99
|
+
if (!paymentCard) return results;
|
|
106
100
|
const billingAddress = payloads?.find(isBillingAddress);
|
|
107
|
-
if (!billingAddress)
|
|
108
|
-
return results;
|
|
101
|
+
if (!billingAddress) return results;
|
|
109
102
|
const axios = new AxiosJson({ headers: this.headers });
|
|
110
103
|
try {
|
|
111
104
|
const data = toTokenRequest(paymentCard, billingAddress);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,SAAS,gBAAgB;AACzB,SAAS,WAA+B,sBAAsB;AAC9D,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAChD,SAA2C,8CAA8C;AACzF,SAAS,wBAAwB;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,SAAS,gBAAgB;AACzB,SAAS,WAA+B,sBAAsB;AAC9D,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAChD,SAA2C,8CAA8C;AACzF,SAAS,wBAAwB;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAA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,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/node/index.cjs
CHANGED
|
@@ -70,24 +70,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
70
70
|
* The Rebilly Organization API root endpoint
|
|
71
71
|
*/
|
|
72
72
|
get apiRoot() {
|
|
73
|
-
if (!this._apiRoot)
|
|
74
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
73
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
75
74
|
return this._apiRoot;
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
77
|
* The Rebilly domain
|
|
79
78
|
*/
|
|
80
79
|
get domain() {
|
|
81
|
-
if (!this._domain)
|
|
82
|
-
this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
80
|
+
if (!this._domain) this._domain = (0, import_assert.assertEx)(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
83
81
|
return this._domain;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* The headers to be included in the request for each request
|
|
87
85
|
*/
|
|
88
86
|
get headers() {
|
|
89
|
-
if (!this._headers)
|
|
90
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
87
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
91
88
|
return this._headers;
|
|
92
89
|
}
|
|
93
90
|
/**
|
|
@@ -119,22 +116,18 @@ var RebillyPaymentCardAuthorizationSentinel = class extends import_sentinel_abst
|
|
|
119
116
|
* The Rebilly Organization token creation endpoint
|
|
120
117
|
*/
|
|
121
118
|
get tokenEndpoint() {
|
|
122
|
-
if (!this._tokenEndpoint)
|
|
123
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
119
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
124
120
|
return this._tokenEndpoint;
|
|
125
121
|
}
|
|
126
122
|
async reportHandler(payloads) {
|
|
127
123
|
var _a, _b;
|
|
128
124
|
await this.started("throw");
|
|
129
125
|
const results = [];
|
|
130
|
-
if (!payloads || payloads.length === 0)
|
|
131
|
-
return results;
|
|
126
|
+
if (!payloads || payloads.length === 0) return results;
|
|
132
127
|
const paymentCard = payloads == null ? void 0 : payloads.find(import_payment_payload_plugins.isPaymentCard);
|
|
133
|
-
if (!paymentCard)
|
|
134
|
-
return results;
|
|
128
|
+
if (!paymentCard) return results;
|
|
135
129
|
const billingAddress = payloads == null ? void 0 : payloads.find(import_payment_payload_plugins.isBillingAddress);
|
|
136
|
-
if (!billingAddress)
|
|
137
|
-
return results;
|
|
130
|
+
if (!billingAddress) return results;
|
|
138
131
|
const axios = new import_axios.AxiosJson({ headers: this.headers });
|
|
139
132
|
try {
|
|
140
133
|
const data = toTokenRequest(paymentCard, billingAddress);
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export * from './Config'\nexport * from './Params'\nexport * from './Schema'\nexport * from './Sentinel'\n","export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,oBAAyB;AACzB,mBAA8D;AAC9D,6BAA+B;AAE/B,qCAAgD;AAChD,4CAAyF;AACzF,+BAAiC;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAs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1B,UAAM,UAA2D,CAAC;AAElE,QAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;AAC/C,UAAM,cAAc,qCAAU,KAAK;AACnC,QAAI,CAAC,YAAa,QAAO;AACzB,UAAM,iBAAiB,qCAAU,KAAK;AACtC,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,QAAQ,IAAI,uBAAU,EAAE,SAAS,KAAK,QAAQ,CAAC;AACrD,QAAI;AACF,YAAM,OAAO,eAAe,aAAa,cAAc;AACvD,YAAM,WAAW,MAAM,MAAM,KAA0B,KAAK,eAAe,IAAI;AAC/E,kCAAS,SAAS,WAAW,4BAAe,SAAS,MAAM,oCAAoC,SAAS,MAAM,EAAE;AAChH,YAAM,EAAE,GAAG,IAAI,SAAS;AACxB,YAAM,UAAU,MAAM,sCAAe,WAAW,CAAC,aAAa,cAAc,CAAC;AAC7E,cAAQ,KAAK,EAAE,IAAI,QAAQ,8EAAwC,QAAQ,CAAC;AAAA,IAC9E,SAAS,OAAO;AACd,uBAAK,WAAL,mBAAa,UAAb,4BAAqB,GAAG,UAAU,mCAAmC,KAAK;AAAA,IAC5E;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -42,24 +42,21 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
42
42
|
* The Rebilly Organization API root endpoint
|
|
43
43
|
*/
|
|
44
44
|
get apiRoot() {
|
|
45
|
-
if (!this._apiRoot)
|
|
46
|
-
this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
45
|
+
if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`;
|
|
47
46
|
return this._apiRoot;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* The Rebilly domain
|
|
51
50
|
*/
|
|
52
51
|
get domain() {
|
|
53
|
-
if (!this._domain)
|
|
54
|
-
this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
52
|
+
if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`);
|
|
55
53
|
return this._domain;
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* The headers to be included in the request for each request
|
|
59
57
|
*/
|
|
60
58
|
get headers() {
|
|
61
|
-
if (!this._headers)
|
|
62
|
-
this._headers = { Authorization: this.publishableApiKey };
|
|
59
|
+
if (!this._headers) this._headers = { Authorization: this.publishableApiKey };
|
|
63
60
|
return this._headers;
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
@@ -91,22 +88,18 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
|
|
|
91
88
|
* The Rebilly Organization token creation endpoint
|
|
92
89
|
*/
|
|
93
90
|
get tokenEndpoint() {
|
|
94
|
-
if (!this._tokenEndpoint)
|
|
95
|
-
this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
91
|
+
if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`;
|
|
96
92
|
return this._tokenEndpoint;
|
|
97
93
|
}
|
|
98
94
|
async reportHandler(payloads) {
|
|
99
95
|
var _a, _b;
|
|
100
96
|
await this.started("throw");
|
|
101
97
|
const results = [];
|
|
102
|
-
if (!payloads || payloads.length === 0)
|
|
103
|
-
return results;
|
|
98
|
+
if (!payloads || payloads.length === 0) return results;
|
|
104
99
|
const paymentCard = payloads == null ? void 0 : payloads.find(isPaymentCard);
|
|
105
|
-
if (!paymentCard)
|
|
106
|
-
return results;
|
|
100
|
+
if (!paymentCard) return results;
|
|
107
101
|
const billingAddress = payloads == null ? void 0 : payloads.find(isBillingAddress);
|
|
108
|
-
if (!billingAddress)
|
|
109
|
-
return results;
|
|
102
|
+
if (!billingAddress) return results;
|
|
110
103
|
const axios = new AxiosJson({ headers: this.headers });
|
|
111
104
|
try {
|
|
112
105
|
const data = toTokenRequest(paymentCard, billingAddress);
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,SAAS,gBAAgB;AACzB,SAAS,WAA+B,sBAAsB;AAC9D,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAChD,SAA2C,8CAA8C;AACzF,SAAS,wBAAwB;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB,EAAE,KAAK,UAAU,SAAS,KAAK,WAAW;AAAA,EAC/D;AACF;;;ADTA,IAAM,eAAe,CAAC,KAAa,WAAmB;AACpD,QAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;AACrC,SAAO,IAAI,QAAQ,OAAO,EAAE;AAC9B;AAEA,IAAM,aAAa;AACZ,IAAM,0CAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,mDAAmD;AAAA,EACpF,OAAgB,sBAAsB;AAAA,EAE5B,WAA+B;AAAA,EAC/B,UAA8B;AAAA,EAC9B,WAAsD;AAAA,EACtD,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport type RebillyPaymentCardAuthorizationSentinelConfig = SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}> &\n Partial<RebillyApiDomainSettings>\n","import { assertEx } from '@xylabs/assert'\nimport { AxiosJson, AxiosRequestConfig, HttpStatusCode } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport { RebillyPaymentAuthorizationToken, RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\n\nimport { CreateTokenResponse } from './Api'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config'\nimport { RebillyPaymentCardAuthorizationSentinelParams } from './Params'\nimport { toTokenRequest } from './util'\n\nconst removePrefix = (str: string, prefix: string) => {\n const regex = new RegExp(`^${prefix}`)\n return str.replace(regex, '')\n}\n\nconst moduleName = 'RebillyPaymentCardAuthorizationSentinel'\nexport class RebillyPaymentCardAuthorizationSentinel<\n TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n protected _apiRoot: string | undefined = undefined\n protected _domain: string | undefined = undefined\n protected _headers: AxiosRequestConfig['headers'] | undefined = undefined\n protected _organizationId: string | undefined = undefined\n protected _publishableApiKey: string | undefined = undefined\n protected _tokenEndpoint: string | undefined = undefined\n\n /**\n * The Rebilly Organization API root endpoint\n */\n protected get apiRoot() {\n if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`\n return this._apiRoot\n }\n\n /**\n * The Rebilly domain\n */\n protected get domain() {\n if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)\n return this._domain\n }\n\n /**\n * The headers to be included in the request for each request\n */\n protected get headers(): AxiosRequestConfig['headers'] {\n if (!this._headers) this._headers = { Authorization: this.publishableApiKey }\n return this._headers\n }\n\n /**\n * True if the environment is sandbox (testing), false otherwise\n */\n protected get isSandboxEnvironment(): boolean {\n return this.domain.includes('sandbox')\n }\n\n /**\n * The Rebilly organization ID\n */\n protected get organizationId() {\n if (!this._organizationId)\n this._organizationId = removePrefix(\n assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),\n 'org_',\n )\n return this._organizationId\n }\n\n /**\n * The Rebilly Publishable API key\n */\n protected get publishableApiKey(): string {\n if (!this._publishableApiKey)\n this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)\n return this._publishableApiKey\n }\n\n /**\n * The Rebilly Organization token creation endpoint\n */\n protected get tokenEndpoint() {\n if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`\n return this._tokenEndpoint\n }\n\n override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {\n await this.started('throw')\n const results: WithSources<RebillyPaymentAuthorizationToken>[] = []\n // Verify necessary inputs and if nothing meets our criteria, bail early\n if (!payloads || payloads.length === 0) return results\n const paymentCard = payloads?.find(isPaymentCard)\n if (!paymentCard) return results\n const billingAddress = payloads?.find(isBillingAddress)\n if (!billingAddress) return results\n const axios = new AxiosJson({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = response.data\n const sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])\n results.push({ id, schema: RebillyPaymentAuthorizationTokenSchema, sources })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport { CreatePaymentTokenRequest } from '../Api'\n\n/**\n * Converts a payment card and billing address to a token request\n * @param paymentCard The payment card\n * @param billingAddress The billing address\n * @returns The token request\n */\nexport const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {\n const { cvv, expMonth, expYear, cardNumber } = paymentCard\n // NOTE: We are destructuring all but the schema and passing it along to the billingAddress. This\n // is to allow for missing fields to be omitted rather than set to undefined and for any new fields\n // that might be added later to be automatically picked up on. It is fine to pass this along since\n // the user is supplying this data about themselves.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: { cvv, expMonth, expYear, pan: cardNumber },\n }\n}\n"],"mappings":";AAAO,IAAM,gDAAgD;;;ACKtD,IAAM,sDAAsD,GAAG,6CAA6C;;;ACLnH,SAAS,gBAAgB;AACzB,SAAS,WAA+B,sBAAsB;AAC9D,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAChD,SAA2C,8CAA8C;AACzF,SAAS,wBAAwB;;;ACI1B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM,EAAE,KAAK,UAAU,SAAS,WAAW,IAAI;AAM/C,QAAM,EAAE,QA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|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^3.
|
|
14
|
-
"@xylabs/axios": "^3.
|
|
15
|
-
"@xyo-network/module-model": "^2.
|
|
16
|
-
"@xyo-network/payload-builder": "^2.
|
|
17
|
-
"@xyo-network/payload-model": "^2.
|
|
18
|
-
"@xyo-network/payment-payload-plugins": "~2.
|
|
19
|
-
"@xyo-network/rebilly-payment-payload-plugin": "~2.
|
|
20
|
-
"@xyo-network/sentinel-abstract": "^2.
|
|
21
|
-
"@xyo-network/sentinel-model": "^2.
|
|
13
|
+
"@xylabs/assert": "^3.5.1",
|
|
14
|
+
"@xylabs/axios": "^3.5.1",
|
|
15
|
+
"@xyo-network/module-model": "^2.105.0",
|
|
16
|
+
"@xyo-network/payload-builder": "^2.105.0",
|
|
17
|
+
"@xyo-network/payload-model": "^2.105.0",
|
|
18
|
+
"@xyo-network/payment-payload-plugins": "~2.96.0",
|
|
19
|
+
"@xyo-network/rebilly-payment-payload-plugin": "~2.96.0",
|
|
20
|
+
"@xyo-network/sentinel-abstract": "^2.105.0",
|
|
21
|
+
"@xyo-network/sentinel-model": "^2.105.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@xylabs/jest-helpers": "^3.
|
|
24
|
+
"@xylabs/jest-helpers": "^3.5.1",
|
|
25
25
|
"@xylabs/ts-scripts-yarn3": "^3.10.4",
|
|
26
26
|
"@xylabs/tsconfig": "^3.10.4",
|
|
27
|
-
"@xyo-network/boundwitness-model": "^2.
|
|
27
|
+
"@xyo-network/boundwitness-model": "^2.105.0",
|
|
28
28
|
"jest": "^29.7.0",
|
|
29
29
|
"typescript": "^5.4.5"
|
|
30
30
|
},
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
68
68
|
},
|
|
69
69
|
"sideEffects": false,
|
|
70
|
-
"version": "2.
|
|
70
|
+
"version": "2.96.0",
|
|
71
71
|
"type": "module"
|
|
72
72
|
}
|