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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import type { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin';
2
2
  import type { SentinelConfig } from '@xyo-network/sentinel-model';
3
- export declare const RebillyPaymentCardAuthorizationSentinelConfigSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly.config";
3
+ export declare const RebillyPaymentCardAuthorizationSentinelConfigSchema: string & {
4
+ readonly __schema: true;
5
+ };
4
6
  export type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema;
5
7
  export interface RebillyPaymentCardAuthorizationSentinelConfig extends SentinelConfig<{
6
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAIjE,eAAO,MAAM,mDAAmD,uFAA4D,CAAA;AAC5H,MAAM,MAAM,mDAAmD,GAAG,OAAO,mDAAmD,CAAA;AAK5H,MAAM,WAAW,6CAA8C,SAAQ,cAAc,CAAC;IACpF;;OAEG;IACH,MAAM,EAAE,mDAAmD,CAAA;CAC5D,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC;CAAG"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAIjE,eAAO,MAAM,mDAAmD;;CAA4E,CAAA;AAC5I,MAAM,MAAM,mDAAmD,GAAG,OAAO,mDAAmD,CAAA;AAK5H,MAAM,WAAW,6CAA8C,SAAQ,cAAc,CAAC;IACpF;;OAEG;IACH,MAAM,EAAE,mDAAmD,CAAA;CAC5D,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC;CAAG"}
@@ -1,3 +1,5 @@
1
- export declare const RebillyPaymentCardAuthorizationSentinelSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly";
1
+ export declare const RebillyPaymentCardAuthorizationSentinelSchema: "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly" & {
2
+ readonly __schema: true;
3
+ };
2
4
  export type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema;
3
5
  //# sourceMappingURL=Schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6CAA6C,gFAAgF,CAAA;AAC1I,MAAM,MAAM,6CAA6C,GAAG,OAAO,6CAA6C,CAAA"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6CAA6C;;CAAgG,CAAA;AAC1J,MAAM,MAAM,6CAA6C,GAAG,OAAO,6CAA6C,CAAA"}
@@ -4,8 +4,12 @@ import type { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sen
4
4
  import type { AxiosRequestConfig } from 'axios';
5
5
  import type { RebillyPaymentCardAuthorizationSentinelParams } from './Params.ts';
6
6
  export declare class RebillyPaymentCardAuthorizationSentinel<TParams extends RebillyPaymentCardAuthorizationSentinelParams = RebillyPaymentCardAuthorizationSentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
7
- static readonly configSchemas: string[];
8
- static readonly defaultConfigSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly.config";
7
+ static readonly configSchemas: (string & {
8
+ readonly __schema: true;
9
+ })[];
10
+ static readonly defaultConfigSchema: string & {
11
+ readonly __schema: true;
12
+ };
9
13
  protected _apiRoot: string | undefined;
10
14
  protected _domain: string | undefined;
11
15
  protected _headers: AxiosRequestConfig['headers'] | undefined;
@@ -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,WAAwD;IAC9F,gBAAyB,mBAAmB,wFAAsD;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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AY;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,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"}
@@ -1,8 +1,12 @@
1
+ // src/Config.ts
2
+ import { asSchema as asSchema2 } from "@xyo-network/payload-model";
3
+
1
4
  // src/Schema.ts
2
- var RebillyPaymentCardAuthorizationSentinelSchema = "network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly";
5
+ import { asSchema } from "@xyo-network/payload-model";
6
+ var RebillyPaymentCardAuthorizationSentinelSchema = asSchema("network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly", true);
3
7
 
4
8
  // src/Config.ts
5
- var RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`;
9
+ var RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema2(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true);
6
10
 
7
11
  // src/Sentinel.ts
8
12
  import { assertEx } from "@xylabs/assert";
@@ -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 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 = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`\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 { 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 billing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,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":[]}
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,m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rebilly-payment-card-authorization-plugin",
3
- "version": "5.2.3",
3
+ "version": "5.3.1",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -36,26 +36,26 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/assert": "~5.0.49",
40
- "@xylabs/axios": "~5.0.49",
41
- "@xyo-network/module-model": "~5.2.14",
42
- "@xyo-network/payload-builder": "~5.2.14",
43
- "@xyo-network/payload-model": "~5.2.14",
44
- "@xyo-network/payment-payload-plugins": "~5.2.3",
45
- "@xyo-network/rebilly-payment-payload-plugin": "~5.2.3",
46
- "@xyo-network/sentinel-abstract": "~5.2.14",
47
- "@xyo-network/sentinel-model": "~5.2.14",
48
- "axios": "^1.13.2"
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"
49
49
  },
50
50
  "devDependencies": {
51
- "@xylabs/ts-scripts-yarn3": "~7.2.8",
52
- "@xylabs/tsconfig": "~7.2.8",
53
- "@xylabs/vitest-extended": "~5.0.49",
54
- "@xyo-network/boundwitness-model": "~5.2.14",
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",
55
55
  "typescript": "~5.9.3",
56
- "vitest": "~4.0.15"
56
+ "vitest": "~4.0.18"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  }
61
- }
61
+ }
package/src/Config.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { asSchema } from '@xyo-network/payload-model'
1
2
  import type { RebillyApiDomainSettings } from '@xyo-network/rebilly-payment-payload-plugin'
2
3
  import type { SentinelConfig } from '@xyo-network/sentinel-model'
3
4
 
4
5
  import { RebillyPaymentCardAuthorizationSentinelSchema } from './Schema.ts'
5
6
 
6
- export const RebillyPaymentCardAuthorizationSentinelConfigSchema = `${RebillyPaymentCardAuthorizationSentinelSchema}.config`
7
+ export const RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true)
7
8
  export type RebillyPaymentCardAuthorizationSentinelConfigSchema = typeof RebillyPaymentCardAuthorizationSentinelConfigSchema
8
9
 
9
10
  /*
package/src/Schema.ts CHANGED
@@ -1,2 +1,4 @@
1
- export const RebillyPaymentCardAuthorizationSentinelSchema = 'network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly'
1
+ import { asSchema } from '@xyo-network/payload-model'
2
+
3
+ export const RebillyPaymentCardAuthorizationSentinelSchema = asSchema('network.xyo.sentinel.payments.payment.instrument.card.authorization.rebilly', true)
2
4
  export type RebillyPaymentCardAuthorizationSentinelSchema = typeof RebillyPaymentCardAuthorizationSentinelSchema