@xyo-network/rebilly-payment-card-authorization-plugin 5.4.10 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import type { Payload } from '@xyo-network/payload-model';
2
2
  import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
3
3
  import type { SentinelInstance, SentinelModuleEventData } from '@xyo-network/sentinel-model';
4
- import type { AxiosRequestConfig } from 'axios';
4
+ type RequestHeaders = Record<string, string>;
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
7
  static readonly configSchemas: (string & {
@@ -12,7 +12,7 @@ export declare class RebillyPaymentCardAuthorizationSentinel<TParams extends Reb
12
12
  };
13
13
  protected _apiRoot: string | undefined;
14
14
  protected _domain: string | undefined;
15
- protected _headers: AxiosRequestConfig['headers'] | undefined;
15
+ protected _headers: RequestHeaders | undefined;
16
16
  protected _organizationId: string | undefined;
17
17
  protected _publishableApiKey: string | undefined;
18
18
  protected _tokenEndpoint: string | undefined;
@@ -27,7 +27,7 @@ export declare class RebillyPaymentCardAuthorizationSentinel<TParams extends Reb
27
27
  /**
28
28
  * The headers to be included in the request for each request
29
29
  */
30
- protected get headers(): AxiosRequestConfig['headers'];
30
+ protected get headers(): RequestHeaders;
31
31
  /**
32
32
  * True if the environment is sandbox (testing), false otherwise
33
33
  */
@@ -46,4 +46,5 @@ export declare class RebillyPaymentCardAuthorizationSentinel<TParams extends Reb
46
46
  protected get tokenEndpoint(): string;
47
47
  reportHandler(payloads?: Payload[]): Promise<Payload[]>;
48
48
  }
49
+ export {};
49
50
  //# sourceMappingURL=Sentinel.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AAS,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,cAAc,CAGtC;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,12 +9,11 @@ var RebillyPaymentCardAuthorizationSentinelSchema = asSchema("network.xyo.sentin
9
9
  var RebillyPaymentCardAuthorizationSentinelConfigSchema = asSchema2(`${RebillyPaymentCardAuthorizationSentinelSchema}.config`, true);
10
10
 
11
11
  // src/Sentinel.ts
12
- import { assertEx, axiosJsonConfig } from "@xylabs/sdk-js";
12
+ import { assertEx, FetchJsonClient } from "@xylabs/sdk-js";
13
13
  import { isBillingAddress, isPaymentCard } from "@xyo-network/payment-payload-plugins";
14
14
  import { RebillyPaymentAuthorizationTokenSchema } from "@xyo-network/rebilly-payment-payload-plugin";
15
15
  import { PayloadBuilder } from "@xyo-network/sdk-js";
16
16
  import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
17
- import { Axios, HttpStatusCode } from "axios";
18
17
 
19
18
  // src/util/toTokenRequest.ts
20
19
  var toTokenRequest = (paymentCard, billingAddress) => {
@@ -38,6 +37,7 @@ var toTokenRequest = (paymentCard, billingAddress) => {
38
37
  };
39
38
 
40
39
  // src/Sentinel.ts
40
+ var HTTP_STATUS_CREATED = 201;
41
41
  var removePrefix = (str, prefix) => {
42
42
  const regex = new RegExp(`^${prefix}`);
43
43
  return str.replace(regex, "");
@@ -113,12 +113,12 @@ var RebillyPaymentCardAuthorizationSentinel = class extends AbstractSentinel {
113
113
  if (!paymentCard) return results;
114
114
  const billingAddress = payloads?.find(isBillingAddress);
115
115
  if (!billingAddress) return results;
116
- const axios = new Axios(axiosJsonConfig({ headers: this.headers }));
116
+ const client = new FetchJsonClient({ headers: this.headers });
117
117
  try {
118
118
  const data = toTokenRequest(paymentCard, billingAddress);
119
- const response = await axios.post(this.tokenEndpoint, data);
120
- assertEx(response.status === HttpStatusCode.Created, () => `Failed to tokenize payment card: ${response.status}`);
121
- const { id } = response.data;
119
+ const response = await client.post(this.tokenEndpoint, data);
120
+ assertEx(response.status === HTTP_STATUS_CREATED, () => `Failed to tokenize payment card: ${response.status}`);
121
+ const { id } = assertEx(response.data, () => "Empty Rebilly response body");
122
122
  const $sources = await PayloadBuilder.dataHashes([paymentCard, billingAddress]);
123
123
  results.push({
124
124
  id,
@@ -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, 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,QAAQ,GAAG,GAAG,OAAO,IAAI;AACjC,SAAO;AAAA,IACL,gBAAgB,EAA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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, FetchJsonClient } 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'\n\nconst HTTP_STATUS_CREATED = 201\n\ntype RequestHeaders = Record<string, string>\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: RequestHeaders | 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(): RequestHeaders {\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 client = new FetchJsonClient({ headers: this.headers })\n try {\n const data = toTokenRequest(paymentCard, billingAddress)\n const response = await client.post<CreateTokenResponse>(this.tokenEndpoint, data)\n assertEx(response.status === HTTP_STATUS_CREATED, () => `Failed to tokenize payment card: ${response.status}`)\n const { id } = assertEx(response.data, () => 'Empty Rebilly response body')\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;;;ACI1B,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;;;ADlBA,IAAM,sBAAsB;AAS5B,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,WAAuC;AAAA,EACvC,kBAAsC;AAAA,EACtC,qBAAyC;AAAA,EACzC,iBAAqC;AAAA;AAAA;AAAA;AAAA,EAK/C,IAAc,UAAU;AACtB,QAAI,CAAC,KAAK,SAAU,MAAK,WA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UAAU,KAAK,gBAAgB;AACtD,QAAI,CAAC,eAAgB,QAAO;AAC5B,UAAM,SAAS,IAAI,gBAAgB,EAAE,SAAS,KAAK,QAAQ,CAAC;AAC5D,QAAI;AACF,YAAM,OAAO,eAAe,aAAa,cAAc;AACvD,YAAM,WAAW,MAAM,OAAO,KAA0B,KAAK,eAAe,IAAI;AAChF,eAAS,SAAS,WAAW,qBAAqB,MAAM,oCAAoC,SAAS,MAAM,EAAE;AAC7G,YAAM,EAAE,GAAG,IAAI,SAAS,SAAS,MAAM,MAAM,6BAA6B;AAC1E,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/rebilly-payment-card-authorization-plugin",
3
- "version": "5.4.10",
3
+ "version": "5.5.0",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -31,25 +31,24 @@
31
31
  "README.md"
32
32
  ],
33
33
  "dependencies": {
34
- "@xyo-network/rebilly-payment-payload-plugin": "~5.4.10",
35
- "@xyo-network/payment-payload-plugins": "~5.4.10"
34
+ "@xyo-network/rebilly-payment-payload-plugin": "~5.5.0",
35
+ "@xyo-network/payment-payload-plugins": "~5.5.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@bitauth/libauth": "~3.0.0",
39
39
  "@metamask/providers": "^22.1.1",
40
40
  "@opentelemetry/api": "^1.9.1",
41
- "@opentelemetry/sdk-trace-base": "^2.7.0",
41
+ "@opentelemetry/sdk-trace-base": "^2.7.1",
42
42
  "@scure/base": "^2.2.0",
43
43
  "@scure/bip39": "~2.2.0",
44
44
  "@types/node": "^25.6.0",
45
- "@xylabs/crypto": "^5.0.101",
46
- "@xylabs/geo": "^5.0.101",
47
- "@xylabs/sdk-js": "^5.0.100",
48
- "@xylabs/threads": "^5.0.100",
49
- "@xylabs/toolchain": "~7.11.12",
50
- "@xylabs/tsconfig": "~7.11.12",
51
- "@xylabs/vitest-extended": "~5.0.100",
52
- "@xylabs/vitest-matchers": "~5.0.100",
45
+ "@xylabs/crypto": "^5.1.0",
46
+ "@xylabs/geo": "^5.1.0",
47
+ "@xylabs/sdk-js": "^5.1.0",
48
+ "@xylabs/threads": "^5.1.0",
49
+ "@xylabs/toolchain": "~7.12.3",
50
+ "@xylabs/tsconfig": "~7.12.3",
51
+ "@xylabs/vitest-extended": "~5.1.0",
53
52
  "@xyo-network/account": "~5.5.2",
54
53
  "@xyo-network/account-model": "^5.5.2",
55
54
  "@xyo-network/api": "~5.5.2",
@@ -59,38 +58,37 @@
59
58
  "@xyo-network/boundwitness-validator": "^5.5.2",
60
59
  "@xyo-network/boundwitness-wrapper": "~5.5.2",
61
60
  "@xyo-network/config-payload-plugin": "~5.5.2",
62
- "@xyo-network/diviner-hash-lease": "^5.5.6",
63
- "@xyo-network/diviner-model": "^5.5.6",
61
+ "@xyo-network/diviner-hash-lease": "^5.6.2",
62
+ "@xyo-network/diviner-model": "^5.6.2",
64
63
  "@xyo-network/huri": "~5.5.2",
65
64
  "@xyo-network/manifest-model": "~5.5.2",
66
- "@xyo-network/module-model": "^5.5.6",
65
+ "@xyo-network/module-model": "^5.6.2",
67
66
  "@xyo-network/payload-builder": "~5.5.2",
68
67
  "@xyo-network/payload-model": "^5.5.2",
69
68
  "@xyo-network/payload-plugin": "~5.5.2",
70
69
  "@xyo-network/payload-wrapper": "~5.5.2",
71
70
  "@xyo-network/query-payload-plugin": "~5.5.2",
72
- "@xyo-network/sdk-js": "^5.5.6",
71
+ "@xyo-network/sdk-js": "^5.6.2",
73
72
  "@xyo-network/sdk-protocol-js": "~5.5.2",
74
- "@xyo-network/sentinel-abstract": "~5.5.6",
75
- "@xyo-network/sentinel-model": "~5.5.6",
73
+ "@xyo-network/sentinel-abstract": "~5.6.2",
74
+ "@xyo-network/sentinel-model": "~5.6.2",
76
75
  "@xyo-network/wallet": "~5.5.2",
77
76
  "@xyo-network/wallet-model": "~5.5.2",
78
- "@xyo-network/witness-model": "^5.5.6",
79
- "ajv": "^8.18.0",
77
+ "@xyo-network/witness-model": "^5.6.2",
78
+ "ajv": "^8.20.0",
80
79
  "async-mutex": "^0.5.0",
81
- "axios": "^1.15.2",
82
80
  "bn.js": "^5.2.3",
83
81
  "buffer": "^6.0.3",
84
82
  "chalk": "^5.6.2",
85
83
  "crypto-js": "~4.2.0",
86
84
  "debug": "~4.4.3",
87
85
  "esbuild": "~0.28.0",
88
- "eslint": "^10.2.1",
86
+ "eslint": "^10.3.0",
89
87
  "ethers": "^6.16.0",
90
88
  "hash-wasm": "^4.12.0",
91
89
  "idb": "^8.0.3",
92
- "lru-cache": "^11.3.5",
93
- "mapbox-gl": "^3.22.0",
90
+ "lru-cache": "^11.3.6",
91
+ "mapbox-gl": "~3.23.1",
94
92
  "observable-fns": "~0.6.1",
95
93
  "pako": "~2.1.0",
96
94
  "store2": "~2.14.4",
@@ -99,25 +97,24 @@
99
97
  "vitest": "^4.1.5",
100
98
  "wasm-feature-detect": "~1.8.0",
101
99
  "webextension-polyfill": "^0.12.0",
102
- "zod": "^4.3.6"
100
+ "zod": "^4.4.3"
103
101
  },
104
102
  "peerDependencies": {
105
- "@xylabs/crypto": ">=5.0.101 <6",
106
- "@xylabs/sdk-js": ">=5.0.100 <6",
103
+ "@xylabs/crypto": ">=5.1.0 <6",
104
+ "@xylabs/sdk-js": ">=5.1.0 <6",
107
105
  "@xyo-network/account-model": ">=5.5.2 <6",
108
- "@xyo-network/boundwitness-builder": ">=5.5.2 <6",
106
+ "@xyo-network/boundwitness-builder": ">=5.5.2 <5.6",
109
107
  "@xyo-network/boundwitness-model": ">=5.5.2 <6",
110
108
  "@xyo-network/boundwitness-validator": ">=5.5.2 <6",
111
- "@xyo-network/diviner-hash-lease": ">=5.5.6 <6",
112
- "@xyo-network/diviner-model": ">=5.5.6 <6",
113
- "@xyo-network/module-model": ">=5.5.6 <6",
109
+ "@xyo-network/diviner-hash-lease": ">=5.6.2 <6",
110
+ "@xyo-network/diviner-model": ">=5.6.2 <6",
111
+ "@xyo-network/module-model": ">=5.6.2 <6",
114
112
  "@xyo-network/payload-model": ">=5.5.2 <6",
115
- "@xyo-network/sdk-js": ">=5.5.6 <6",
116
- "@xyo-network/sentinel-abstract": ">=5.5.6 <6",
117
- "@xyo-network/sentinel-model": ">=5.5.6 <6",
118
- "@xyo-network/witness-model": ">=5.5.6 <6",
119
- "axios": ">=1.15.2 <2",
120
- "zod": ">=4.3.6 <5"
113
+ "@xyo-network/sdk-js": ">=5.6.2 <6",
114
+ "@xyo-network/sentinel-abstract": ">=5.6.2 <5.7",
115
+ "@xyo-network/sentinel-model": ">=5.6.2 <5.7",
116
+ "@xyo-network/witness-model": ">=5.6.2 <6",
117
+ "zod": ">=4.4.3 <5"
121
118
  },
122
119
  "publishConfig": {
123
120
  "access": "public"