@xyo-network/rebilly-payment-card-authorization-plugin 5.3.1 → 5.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Sentinel.d.ts","sourceRoot":"","sources":["../../src/Sentinel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,4BAA4B,CAAA;AAItE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAC5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAK/C,OAAO,KAAK,EAAE,6CAA6C,EAAE,MAAM,aAAa,CAAA;AAShF,qBAAa,uCAAuC,CAClD,OAAO,SAAS,6CAA6C,GAAG,6CAA6C,EAC7G,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,gBAAyB,aAAa;;SAAwD;IAC9F,gBAAyB,mBAAmB;;MAAsD;IAElG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAY;IAClD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAY;IACjD,SAAS,CAAC,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAY;IACzE,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAY;IACzD,SAAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAY;IAC5D,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAY;IAExD;;OAEG;IACH,SAAS,KAAK,OAAO,WAGpB;IAED;;OAEG;IACH,SAAS,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SAAS,CAAY;IACzE,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAY;IACzD,SAAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAY;IAC5D,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAY;IAExD;;OAEG;IACH,SAAS,KAAK,OAAO,WAGpB;IAED;;OAEG;IACH,SAAS,KAAK,MAAM,WAGnB;IAED;;OAEG;IACH,SAAS,KAAK,OAAO,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAGrD;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,OAAO,CAE5C;IAED;;OAEG;IACH,SAAS,KAAK,cAAc,WAO3B;IAED;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAIxC;IAED;;OAEG;IACH,SAAS,KAAK,aAAa,WAG1B;IAEc,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAwBvE"}
@@ -9,11 +9,10 @@ var RebillyPaymentCardAuthorizationSentinelSchema = asSchema("network.xyo.sentin
9
9
  var RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema2(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true);
10
10
 
11
11
  // src/Sentinel.ts
12
- import { assertEx } from "@xylabs/assert";
13
- import { axiosJsonConfig } from "@xylabs/axios";
14
- import { PayloadBuilder } from "@xyo-network/payload-builder";
12
+ import { assertEx, axiosJsonConfig } from "@xylabs/sdk-js";
15
13
  import { isBillingAddress, isPaymentCard } from "@xyo-network/payment-payload-plugins";
16
14
  import { RebillyPaymentAuthorizationTokenSchema } from "@xyo-network/rebilly-payment-payload-plugin";
15
+ import { PayloadBuilder } from "@xyo-network/sdk-js";
17
16
  import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
18
17
  import { Axios, HttpStatusCode } from "axios";
19
18
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Config.ts","../../src/Schema.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["import { asSchema } from '@xyo-network/payload-model'\nimport type { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport type { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema.ts'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true)\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport interface RebillyPaymentCardAuthorizationSentinelConfig extends SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}>, Partial<RebillyApiDomainSettings> {}\n","import { asSchema } from '@xyo-network/payload-model'\n\nexport const RebillyPaymentCardAuthorizationSentinelSchema = asSchema('network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly', true)\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { assertEx } from '@xylabs/assert'\nimport { axiosJsonConfig } from '@xylabs/axios'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport type { RebillyPaymentAuthorizationToken } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\nimport type { AxiosRequestConfig } from 'axios'\nimport { Axios, HttpStatusCode } from 'axios'\n\nimport type { CreateTokenResponse } from './Api/index.ts'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config.ts'\nimport type { RebillyPaymentCardAuthorizationSentinelParams } from './Params.ts'\nimport { toTokenRequest } from './util/index.ts'\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 readonly configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override readonly 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 Axios(axiosJsonConfig({ 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({\n id, schema: RebillyPaymentAuthorizationTokenSchema, $sources,\n })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import type { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport type { CreatePaymentTokenRequest } from '../Api/index.ts'\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 {\n cvv, expMonth, expYear, cardNumber,\n } = paymentCard\n // 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\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: {\n cvv, expMonth, expYear, pan: cardNumber,\n },\n }\n}\n"],"mappings":";AAAA,SAAS,YAAAA,iBAAgB;;;ACAzB,SAAS,gBAAgB;AAElB,IAAM,gDAAgD,SAAS,+EAA+E,IAAI;;;ADIlJ,IAAM,sDAAsDC,UAAS,GAAG,6CAA6C,WAAW,IAAI;;;AEN3I,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB,qBAAqB;AAEhD,SAAS,8CAA8C;AACvD,SAAS,wBAAwB;AAGjC,SAAS,OAAO,sBAAsB;;;ACA/B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM;AAAA,IACJ;AAAA,IAAK;AAAA,IAAU;AAAA,IAAS;AAAA,EAC1B,IAAI;AAMJ,QAAM,EAAE,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAAE,GAAG,OAAO;AAAA,IAC5B,QAAQ;AAAA,IACR,mBAAmB;AAAA,MACjB;AAAA,MAAK;AAAA,MAAU;AAAA,MAAS,KAAK;AAAA,IAC/B;AAAA,EACF;AACF;;;ADVA,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,OAAyB,gBAAgB,CAAC,mDAAmD;AAAA,EAC7F,OAAyB,sBAAsB;AAAA,EAErC,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,KA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zB,UAAM,iBAAiB,UAAU,KAAK,gBAAgB;AACtD,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,QAAQ,IAAI,MAAM,gBAAgB,EAAE,SAAS,KAAK,QAAQ,CAAC,CAAC;AAClE,QAAI;AACF,YAAM,OAAO,eAAe,aAAa,cAAc;AACvD,YAAM,WAAW,MAAM,MAAM,KAA0B,KAAK,eAAe,IAAI;AAC/E,eAAS,SAAS,WAAW,eAAe,SAAS,MAAM,oCAAoC,SAAS,MAAM,EAAE;AAChH,YAAM,EAAE,GAAG,IAAI,SAAS;AACxB,YAAM,WAAW,MAAM,eAAe,WAAW,CAAC,aAAa,cAAc,CAAC;AAC9E,cAAQ,KAAK;AAAA,QACX;AAAA,QAAI,QAAQ;AAAA,QAAwC;AAAA,MACtD,CAAC;AAAA,IACH,SAAS,OAAO;AACd,WAAK,QAAQ,QAAQ,GAAG,UAAU,mCAAmC,KAAK,EAAE;AAAA,IAC9E;AACA,WAAO;AAAA,EACT;AACF;","names":["asSchema","asSchema"]}
1
+ {"version":3,"sources":["../../src/Config.ts","../../src/Schema.ts","../../src/Sentinel.ts","../../src/util/toTokenRequest.ts"],"sourcesContent":["import { asSchema } from '@xyo-network/payload-model'\nimport type { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'\nimport type { SentinelConfig } from '@xyo-network/sentinel-model'\n\nimport { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema.ts'\n\nexport const RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true)\nexport type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema\n\n/*\n * The Rebilly Payment Card Authorization Sentinel Config\n */\nexport interface RebillyPaymentCardAuthorizationSentinelConfig extends SentinelConfig<{\n /**\n * The config schema\n */\n schema: RebillyPaymentCardAuthorizationSentinelConfigSchema\n}>, Partial<RebillyApiDomainSettings> {}\n","import { asSchema } from '@xyo-network/payload-model'\n\nexport const RebillyPaymentCardAuthorizationSentinelSchema = asSchema('network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly', true)\nexport type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema\n","import { assertEx, axiosJsonConfig } from '@xylabs/sdk-js'\nimport type { Payload, WithSources } from '@xyo-network/payload-model'\nimport { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'\nimport type { RebillyPaymentAuthorizationToken } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'\nimport { PayloadBuilder } from '@xyo-network/sdk-js'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'\nimport type { AxiosRequestConfig } from 'axios'\nimport { Axios, HttpStatusCode } from 'axios'\n\nimport type { CreateTokenResponse } from './Api/index.ts'\nimport { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config.ts'\nimport type { RebillyPaymentCardAuthorizationSentinelParams } from './Params.ts'\nimport { toTokenRequest } from './util/index.ts'\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 readonly configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]\n static override readonly 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 Axios(axiosJsonConfig({ 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({\n id, schema: RebillyPaymentAuthorizationTokenSchema, $sources,\n })\n } catch (error) {\n this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)\n }\n return results\n }\n}\n","import type { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'\n\nimport type { CreatePaymentTokenRequest } from '../Api/index.ts'\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 {\n cvv, expMonth, expYear, cardNumber,\n } = paymentCard\n // 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\n const { schema: _, ...fields } = billingAddress\n return {\n billingAddress: { ...fields },\n method: 'payment-card',\n paymentInstrument: {\n cvv, expMonth, expYear, pan: cardNumber,\n },\n }\n}\n"],"mappings":";AAAA,SAAS,YAAAA,iBAAgB;;;ACAzB,SAAS,gBAAgB;AAElB,IAAM,gDAAgD,SAAS,+EAA+E,IAAI;;;ADIlJ,IAAM,sDAAsDC,UAAS,GAAG,6CAA6C,WAAW,IAAI;;;AEN3I,SAAS,UAAU,uBAAuB;AAE1C,SAAS,kBAAkB,qBAAqB;AAEhD,SAAS,8CAA8C;AACvD,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAGjC,SAAS,OAAO,sBAAsB;;;ACC/B,IAAM,iBAAiB,CAAC,aAA0B,mBAA8D;AACrH,QAAM;AAAA,IACJ;AAAA,IAAK;AAAA,IAAU;AAAA,IAAS;AAAA,EAC1B,IAAI;AAMJ,QAAM,EAAE,QA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9E;AACA,WAAO;AAAA,EACT;AACF;","names":["asSchema","asSchema"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/rebilly-payment-card-authorization-plugin",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,30 +30,38 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
- "!**/*.bench.*",
35
- "!**/*.spec.*",
36
- "!**/*.test.*"
33
+ "README.md"
37
34
  ],
38
35
  "dependencies": {
39
- "@xylabs/assert": "~5.0.64",
40
- "@xylabs/axios": "~5.0.64",
41
- "@xyo-network/module-model": "~5.3.2",
42
- "@xyo-network/payload-builder": "~5.3.2",
43
- "@xyo-network/payload-model": "~5.3.2",
44
- "@xyo-network/payment-payload-plugins": "5.3.1",
45
- "@xyo-network/rebilly-payment-payload-plugin": "5.3.1",
46
- "@xyo-network/sentinel-abstract": "~5.3.2",
47
- "@xyo-network/sentinel-model": "~5.3.2",
48
- "axios": "^1.13.4"
36
+ "@xyo-network/payment-payload-plugins": "workspace:^",
37
+ "@xyo-network/rebilly-payment-payload-plugin": "workspace:^"
49
38
  },
50
39
  "devDependencies": {
51
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
52
- "@xylabs/tsconfig": "~7.3.2",
53
- "@xylabs/vitest-extended": "~5.0.64",
54
- "@xyo-network/boundwitness-model": "~5.3.2",
40
+ "@xylabs/sdk-js": "^5.0.90",
41
+ "@xylabs/ts-scripts-common": "~7.5.10",
42
+ "@xylabs/ts-scripts-yarn3": "~7.5.10",
43
+ "@xylabs/tsconfig": "~7.5.10",
44
+ "@xylabs/vitest-extended": "~5.0.90",
45
+ "@xyo-network/boundwitness-model": "~5.3.5",
46
+ "@xyo-network/module-model": "~5.3.5",
47
+ "@xyo-network/payload-model": "~5.3.5",
48
+ "@xyo-network/sdk-js": "~5.3.5",
49
+ "@xyo-network/sentinel-abstract": "~5.3.5",
50
+ "@xyo-network/sentinel-model": "~5.3.5",
51
+ "axios": "^1.13.5",
55
52
  "typescript": "~5.9.3",
56
- "vitest": "~4.0.18"
53
+ "vitest": "~4.1.2",
54
+ "zod": "^4.3.6"
55
+ },
56
+ "peerDependencies": {
57
+ "@xylabs/sdk-js": "^5",
58
+ "@xyo-network/module-model": "^5",
59
+ "@xyo-network/payload-model": "^5",
60
+ "@xyo-network/sdk-js": "^5",
61
+ "@xyo-network/sentinel-abstract": "^5",
62
+ "@xyo-network/sentinel-model": "^5",
63
+ "axios": "^1",
64
+ "zod": "^4"
57
65
  },
58
66
  "publishConfig": {
59
67
  "access": "public"
@@ -1,238 +0,0 @@
1
- export interface ContactPhoneNumber {
2
- /**
3
- * Phone number label or name.
4
- * <= 45 characters
5
- */
6
- label: string
7
- /**
8
- * Specifies if the phone number is the contact's primary phone number.
9
- */
10
- primary?: boolean
11
- /**
12
- * Phone number value.
13
- * <= 50 characters
14
- */
15
- value: string
16
- }
17
-
18
- export interface ContactEmail {
19
- /**
20
- * Email label or name.
21
- * <= 45 characters
22
- */
23
- label: string
24
- /**
25
- * Specifies if the email address is the contact's primary email address.
26
- */
27
- primary?: boolean
28
- /**
29
- * Email address value.
30
- * <= 255 characters
31
- */
32
- value: string
33
- }
34
-
35
- /**
36
- * Billing address details associated with the payment token.
37
- */
38
- export interface RequestBillingAddress {
39
- /** Street address line 1. */
40
- address?: string
41
- /** Street address line 2. */
42
- address2?: string | null
43
- /** City of the billing address. */
44
- city?: string
45
- /** Country code of the billing address, ISO 3166-1 alpha-2 code. */
46
- country?: string
47
- /** Date of birth of the cardholder. */
48
- dob?: string
49
- /** Email addresses associated with the billing address. */
50
- emails?: ContactEmail[]
51
- /** First name of the cardholder. */
52
- firstName: string
53
- /** Job title of the cardholder. */
54
- jobTitle?: string | null
55
- /** Last name of the cardholder. */
56
- lastName: string
57
- /** Organization or company name associated with the billing address. */
58
- organization?: string | null
59
- /** Phone numbers associated with the billing address. */
60
- phoneNumbers?: ContactPhoneNumber[]
61
- /** Postal or ZIP code of the billing address. */
62
- postalCode?: string
63
- /** State or region of the billing address. */
64
- region?: string
65
- }
66
-
67
- export interface RequestPaymentCardInstrument {
68
- /**
69
- * Card Verification Value (CVV/CVC) of the payment card.
70
- */
71
- cvv: string
72
- /**
73
- * Expiration month of the payment card.
74
- */
75
- expMonth: number
76
- /**
77
- * Expiration year of the payment card.
78
- */
79
- expYear: number
80
- /**
81
- * Primary Account Number (PAN) of the payment card. This value is required to perform a payment.
82
- */
83
- pan: string
84
- }
85
-
86
- export type PaymentMethod
87
- // | 'ach'
88
- // | 'AdvCash'
89
- // | 'Alfa-click'
90
- // | 'Alipay'
91
- // | 'AstroPay Card'
92
- // | 'AstroPay-GO'
93
- // | 'Baloto'
94
- // | 'Bancontact-mobile'
95
- // | 'Bancontact'
96
- // | 'bank-transfer-2'
97
- // | 'bank-transfer-3'
98
- // | 'bank-transfer-4'
99
- // | 'bank-transfer-5'
100
- // | 'bank-transfer-6'
101
- // | 'bank-transfer-7'
102
- // | 'bank-transfer-8'
103
- // | 'bank-transfer-9'
104
- // | 'bank-transfer'
105
- // | 'BankReferenced'
106
- // | 'Beeline'
107
- // | 'Belfius-direct-net'
108
- // | 'bitcoin'
109
- // | 'Bizum'
110
- // | 'Boleto'
111
- // | 'cash-deposit'
112
- // | 'cash'
113
- // | 'CASHlib'
114
- // | 'CashToCode'
115
- // | 'check'
116
- // | 'China UnionPay'
117
- // | 'Cleo'
118
- // | 'CODVoucher'
119
- // | 'Conekta-oxxo'
120
- // | 'cryptocurrency'
121
- // | 'Cupon-de-pagos'
122
- // | 'digital-wallet'
123
- // | 'domestic-cards'
124
- // | 'echeck'
125
- // | 'ecoPayz'
126
- // | 'ecoVoucher'
127
- // | 'Efecty'
128
- // | 'ePay.bg'
129
- // | 'EPS'
130
- // | 'eZeeWallet'
131
- // | 'FasterPay'
132
- // | 'Flexepin'
133
- // | 'Giropay'
134
- // | 'Google Pay'
135
- // | 'Gpaysafe'
136
- // | 'iDEAL'
137
- // | 'iDebit'
138
- // | 'ING-homepay'
139
- // | 'INOVAPAY-pin'
140
- // | 'INOVAPAY-wallet'
141
- // | 'InstaDebit'
142
- // | 'instant-bank-transfer'
143
- // | 'InstantPayments'
144
- // | 'Interac-eTransfer'
145
- // | 'Interac-online'
146
- // | 'Interac'
147
- // | 'invoice'
148
- // | 'iWallet'
149
- // | 'Jeton'
150
- // | 'jpay'
151
- // | 'Khelocard'
152
- // | 'Klarna'
153
- // | 'KNOT'
154
- // | 'loonie'
155
- // | 'Matrix'
156
- // | 'MaxiCash'
157
- // | 'Megafon'
158
- // | 'MiFinity-eWallet'
159
- // | 'miscellaneous'
160
- // | 'MTS'
161
- // | 'MuchBetter'
162
- // | 'Multibanco'
163
- // | 'Neosurf'
164
- // | 'Netbanking'
165
- // | 'Neteller'
166
- // | 'Nordea-Solo'
167
- // | 'OchaPay'
168
- // | 'online-bank-transfer'
169
- // | 'Onlineueberweisen'
170
- // | 'oriental-wallet'
171
- // | 'OXXO'
172
- // | 'P24'
173
- // | 'Pagadito'
174
- // | 'PagoEffectivo'
175
- // | 'Pagsmile-deposit-express'
176
- // | 'Pagsmile-lottery'
177
- // | 'Pay4Fun'
178
- // | 'PayCash'
179
- // | 'Payeer'
180
- = 'payment-card'
181
- // | 'PaymentAsia-crypto'
182
- // | 'Paymero'
183
- // | 'Paynote'
184
- // | 'paypal'
185
- // | 'Paysafecard'
186
- // | 'Paysafecash'
187
- // | 'PayTabs'
188
- // | 'Perfect-money'
189
- // | 'phone'
190
- // | 'PhonePe'
191
- // | 'Piastrix'
192
- // | 'PinPay'
193
- // | 'plaid-account'
194
- // | 'POLi'
195
- // | 'PostFinance-card'
196
- // | 'PostFinance-e-finance'
197
- // | 'QIWI'
198
- // | 'QPay'
199
- // | 'QQPay'
200
- // | 'rapyd-checkout'
201
- // | 'Resurs'
202
- // | 'SafetyPay'
203
- // | 'SEPA'
204
- // | 'Skrill Rapid Transfer'
205
- // | 'Skrill'
206
- // | 'SMSVoucher'
207
- // | 'Sofort'
208
- // | 'SparkPay'
209
- // | 'swift-dbt'
210
- // | 'Tele2'
211
- // | 'Terminaly-RF'
212
- // | 'ToditoCash-card'
213
- // | 'Trustly'
214
- // | 'UPayCard'
215
- // | 'UPI'
216
- // | 'USD-coin'
217
- // | 'VCreditos'
218
- // | 'VenusPoint'
219
- // | 'voucher-2'
220
- // | 'voucher-3'
221
- // | 'voucher-4'
222
- // | 'voucher'
223
- // | 'Webmoney'
224
- // | 'Webpay Card'
225
- // | 'Webpay-2'
226
- // | 'Webpay'
227
- // | 'WeChat Pay'
228
- // | 'XPay-P2P'
229
- // | 'XPay-QR'
230
- // | 'Yandex-money'
231
- // | 'Zimpler'
232
- // | 'Zotapay'
233
-
234
- export interface CreatePaymentTokenRequest {
235
- billingAddress: RequestBillingAddress
236
- method: PaymentMethod
237
- paymentInstrument: RequestPaymentCardInstrument
238
- }
@@ -1,73 +0,0 @@
1
- import type { PaymentMethod, RequestBillingAddress } from './Request.ts'
2
-
3
- export interface ResponseBillingAddress extends RequestBillingAddress {
4
- hash?: string | null
5
- }
6
-
7
- /**
8
- * Main interface for API response encapsulating all relevant details.
9
- */
10
- export interface CreateTokenResponse {
11
- /** Hyperlinks to related API resources. */
12
- _links: Link[]
13
- /** Billing address associated with the payment token. */
14
- billingAddress: ResponseBillingAddress
15
- /** Card brand such as Visa or Mastercard. */
16
- brand: string
17
- /** An identifier for the browser data. */
18
- browserData: unknown | null
19
- /** Date and time when the token was created. */
20
- createdTime: string
21
- /** Expiration time of the token. */
22
- expirationTime: string | null
23
- /** Date and time when the token expired. */
24
- expiredTime: string | null
25
- /** An identifier for the fingerprint of the device used. */
26
- fingerprint: string | null
27
- /** An identifier of the token. */
28
- id: string
29
- /** Indicates if the token has been used. */
30
- isUsed: boolean
31
- /** The last four digits of the payment instrument. */
32
- last4: string
33
- /** Payment method such as 'payment-card'. */
34
- method: PaymentMethod
35
- /** Payment instrument details. */
36
- paymentInstrument: ResponsePaymentCardInstrument
37
- /** Metadata related to risk evaluation. */
38
- riskMetadata: unknown | null
39
- /** Date and time when the token was last updated. */
40
- updatedTime: string
41
- /** Usage time of the token. */
42
- usageTime: string | null
43
- /** Indicates if the token has already been used. */
44
- used: boolean
45
- /** Date and time when the token was first used. */
46
- usedTime: string | null
47
- }
48
-
49
- /**
50
- * Payment instrument details such as credit card information.
51
- */
52
- export interface ResponsePaymentCardInstrument {
53
- /** Bank identification number or issuer identification number of the card. */
54
- bin: string
55
- /** Card brand such as Visa or Mastercard. */
56
- brand: string
57
- /** Expiration month of the card. */
58
- expMonth: number
59
- /** Expiration year of the card. */
60
- expYear: number
61
- /** Last four digits of the card number. */
62
- last4: string
63
- }
64
-
65
- /**
66
- * Links structure for API navigation.
67
- */
68
- export interface Link {
69
- /** URL of the related resource. */
70
- href: string
71
- /** Relation type of the link. */
72
- rel: string
73
- }
@@ -1,2 +0,0 @@
1
- export * from './Request.ts'
2
- export * from './Response.ts'
package/src/Api/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './PaymentCardToken/index.ts'
package/src/Config.ts DELETED
@@ -1,18 +0,0 @@
1
- import { asSchema } from '@xyo-network/payload-model'
2
- import type { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'
3
- import type { SentinelConfig } from '@xyo-network/sentinel-model'
4
-
5
- import { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema.ts'
6
-
7
- export const RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true)
8
- export type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema
9
-
10
- /*
11
- * The Rebilly Payment Card Authorization Sentinel Config
12
- */
13
- export interface RebillyPaymentCardAuthorizationSentinelConfig extends SentinelConfig<{
14
- /**
15
- * The config schema
16
- */
17
- schema: RebillyPaymentCardAuthorizationSentinelConfigSchema
18
- }>, Partial<RebillyApiDomainSettings> {}
package/src/Params.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { AnyConfigSchema } from '@xyo-network/module-model'
2
- import type { RebillyOrganizationSettings, RebillyPublishableApiSettings } from '@xyo-network/rebilly-payment-payload-plugin'
3
- import type { SentinelParams } from '@xyo-network/sentinel-model'
4
-
5
- import type { RebillyPaymentCardAuthorizationSentinelConfig } from './Config.ts'
6
-
7
- export type RebillyPaymentCardAuthorizationParams = Partial<RebillyPublishableApiSettings & RebillyOrganizationSettings>
8
-
9
- export interface RebillyPaymentCardAuthorizationSentinelParams<
10
- TConfig extends AnyConfigSchema<RebillyPaymentCardAuthorizationSentinelConfig> = AnyConfigSchema<RebillyPaymentCardAuthorizationSentinelConfig>,
11
- > extends SentinelParams<TConfig> {
12
- domain?: string
13
- organizationId?: string
14
- publishableApiKey?: string
15
- }
package/src/Schema.ts DELETED
@@ -1,4 +0,0 @@
1
- import { asSchema } from '@xyo-network/payload-model'
2
-
3
- export const RebillyPaymentCardAuthorizationSentinelSchema = asSchema('network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly', true)
4
- export type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema
package/src/Sentinel.ts DELETED
@@ -1,122 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { axiosJsonConfig } from '@xylabs/axios'
3
- import { PayloadBuilder } from '@xyo-network/payload-builder'
4
- import type { Payload, WithSources } from '@xyo-network/payload-model'
5
- import { isBillingAddress, isPaymentCard } from '@xyo-network/payment-payload-plugins'
6
- import type { RebillyPaymentAuthorizationToken } from '@xyo-network/rebilly-payment-payload-plugin'
7
- import { RebillyPaymentAuthorizationTokenSchema } from '@xyo-network/rebilly-payment-payload-plugin'
8
- import { AbstractSentinel } from '@xyo-network/sentinel-abstract'
9
- import type { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model'
10
- import type { AxiosRequestConfig } from 'axios'
11
- import { Axios, HttpStatusCode } from 'axios'
12
-
13
- import type { CreateTokenResponse } from './Api/index.ts'
14
- import { RebillyPaymentCardAuthorizationSentinelConfigSchema } from './Config.ts'
15
- import type { RebillyPaymentCardAuthorizationSentinelParams } from './Params.ts'
16
- import { toTokenRequest } from './util/index.ts'
17
-
18
- const removePrefix = (str: string, prefix: string) => {
19
- const regex = new RegExp(`^${prefix}`)
20
- return str.replace(regex, '')
21
- }
22
-
23
- const moduleName = 'RebillyPaymentCardAuthorizationSentinel'
24
- export class RebillyPaymentCardAuthorizationSentinel<
25
- TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams,
26
- TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,
27
- > extends AbstractSentinel<TParams, TEventData> {
28
- static override readonly configSchemas = [RebillyPaymentCardAuthorizationSentinelConfigSchema]
29
- static override readonly defaultConfigSchema = RebillyPaymentCardAuthorizationSentinelConfigSchema
30
-
31
- protected _apiRoot: string | undefined = undefined
32
- protected _domain: string | undefined = undefined
33
- protected _headers: AxiosRequestConfig['headers'] | undefined = undefined
34
- protected _organizationId: string | undefined = undefined
35
- protected _publishableApiKey: string | undefined = undefined
36
- protected _tokenEndpoint: string | undefined = undefined
37
-
38
- /**
39
- * The Rebilly Organization API root endpoint
40
- */
41
- protected get apiRoot() {
42
- if (!this._apiRoot) this._apiRoot = `${this.domain}/organizations/${this.organizationId}`
43
- return this._apiRoot
44
- }
45
-
46
- /**
47
- * The Rebilly domain
48
- */
49
- protected get domain() {
50
- if (!this._domain) this._domain = assertEx(this.params.domain ?? this.config.domain, () => `${moduleName}: Missing domain in params/config`)
51
- return this._domain
52
- }
53
-
54
- /**
55
- * The headers to be included in the request for each request
56
- */
57
- protected get headers(): AxiosRequestConfig['headers'] {
58
- if (!this._headers) this._headers = { Authorization: this.publishableApiKey }
59
- return this._headers
60
- }
61
-
62
- /**
63
- * True if the environment is sandbox (testing), false otherwise
64
- */
65
- protected get isSandboxEnvironment(): boolean {
66
- return this.domain.includes('sandbox')
67
- }
68
-
69
- /**
70
- * The Rebilly organization ID
71
- */
72
- protected get organizationId() {
73
- if (!this._organizationId)
74
- this._organizationId = removePrefix(
75
- assertEx(this.params.organizationId, () => `${moduleName}: Missing organizationId in params`),
76
- 'org_',
77
- )
78
- return this._organizationId
79
- }
80
-
81
- /**
82
- * The Rebilly Publishable API key
83
- */
84
- protected get publishableApiKey(): string {
85
- if (!this._publishableApiKey)
86
- this._publishableApiKey = assertEx(this.params.publishableApiKey, () => `${moduleName}: Missing publishableApiKey in params`)
87
- return this._publishableApiKey
88
- }
89
-
90
- /**
91
- * The Rebilly Organization token creation endpoint
92
- */
93
- protected get tokenEndpoint() {
94
- if (!this._tokenEndpoint) this._tokenEndpoint = `${this.apiRoot}/tokens`
95
- return this._tokenEndpoint
96
- }
97
-
98
- override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {
99
- await this.started('throw')
100
- const results: WithSources<RebillyPaymentAuthorizationToken>[] = []
101
- // Verify necessary inputs and if nothing meets our criteria, bail early
102
- if (!payloads || payloads.length === 0) return results
103
- const paymentCard = payloads?.find(isPaymentCard)
104
- if (!paymentCard) return results
105
- const billingAddress = payloads?.find(isBillingAddress)
106
- if (!billingAddress) return results
107
- const axios = new Axios(axiosJsonConfig({ headers: this.headers }))
108
- try {
109
- const data = toTokenRequest(paymentCard, billingAddress)
110
- const response = await axios.post<CreateTokenResponse>(this.tokenEndpoint, data)
111
- assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`)
112
- const { id } = response.data
113
- const $sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress])
114
- results.push({
115
- id, schema: RebillyPaymentAuthorizationTokenSchema, $sources,
116
- })
117
- } catch (error) {
118
- this.logger?.error?.(`${moduleName}: Error creating payment token: ${error}`)
119
- }
120
- return results
121
- }
122
- }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './Config.ts'
2
- export * from './Params.ts'
3
- export * from './Schema.ts'
4
- export * from './Sentinel.ts'
package/src/util/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './toTokenRequest.ts'
@@ -1,28 +0,0 @@
1
- import type { BillingAddress, PaymentCard } from '@xyo-network/payment-payload-plugins'
2
-
3
- import type { CreatePaymentTokenRequest } from '../Api/index.ts'
4
-
5
- /**
6
- * Converts a payment card and billing address to a token request
7
- * @param paymentCard The payment card
8
- * @param billingAddress The billing address
9
- * @returns The token request
10
- */
11
- export const toTokenRequest = (paymentCard: PaymentCard, billingAddress: BillingAddress): CreatePaymentTokenRequest => {
12
- const {
13
- cvv, expMonth, expYear, cardNumber,
14
- } = paymentCard
15
- // We are destructuring all but the schema and passing it along to the billingAddress. This
16
- // is to allow for missing fields to be omitted rather than set to undefined and for any new fields
17
- // that might be added later to be automatically picked up on. It is fine to pass this along since
18
- // the user is supplying this data about themselves.
19
-
20
- const { schema: _, ...fields } = billingAddress
21
- return {
22
- billingAddress: { ...fields },
23
- method: 'payment-card',
24
- paymentInstrument: {
25
- cvv, expMonth, expYear, pan: cardNumber,
26
- },
27
- }
28
- }