@rdlabo/workers-hono-kit 0.6.10 → 0.6.11

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/index.d.ts CHANGED
@@ -47,7 +47,7 @@ export { KVCache } from './cache/kv-cache.js';
47
47
  export type { KVNamespace, KVCacheOptions } from './cache/kv-cache.js';
48
48
  export { createStripeClient, verifyStripeWebhook } from './stripe/client.js';
49
49
  export type { CreateStripeClientOptions } from './stripe/client.js';
50
- export { extractStripeFailureReason, stripeFailureMessageJa, serializePaymentFailure, parsePaymentFailure, PaymentDeclinedError, toPaymentDeclinedError, } from './stripe/failure.js';
50
+ export { extractStripeFailureReason, stripeFailureMessageJa, serializePaymentFailure, serializeIapFailureReason, parsePaymentFailure, PaymentDeclinedError, toPaymentDeclinedError, } from './stripe/failure.js';
51
51
  export type { StripeFailureReason, PaymentFailureSource, PaymentFailureRecord, PaymentFailureReason, IapFailureReason, PaymentDeclinedBody, } from './stripe/failure.js';
52
52
  export { classifyStripeReconcile } from './stripe/reconcile.js';
53
53
  export type { StripeReconcileAction } from './stripe/reconcile.js';
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ export { createSentryErrorReporter } from './http/http-error.js';
36
36
  export { KVCache } from './cache/kv-cache.js';
37
37
  // stripe
38
38
  export { createStripeClient, verifyStripeWebhook } from './stripe/client.js';
39
- export { extractStripeFailureReason, stripeFailureMessageJa, serializePaymentFailure, parsePaymentFailure, PaymentDeclinedError, toPaymentDeclinedError, } from './stripe/failure.js';
39
+ export { extractStripeFailureReason, stripeFailureMessageJa, serializePaymentFailure, serializeIapFailureReason, parsePaymentFailure, PaymentDeclinedError, toPaymentDeclinedError, } from './stripe/failure.js';
40
40
  export { classifyStripeReconcile } from './stripe/reconcile.js';
41
41
  // payment (provider-agnostic; web-standard only). reopenGuardedPaymentFailedSet is drizzle-based → './db'.
42
42
  export { paymentFailureMessageJa, iapFailureKey, UNRESOLVED_PAYMENT_STATUSES } from './payment/failure.js';
@@ -32,7 +32,7 @@ export function paymentFailureMessageJa(input) {
32
32
  if (input.status === 'failed' && (input.type === 'ios' || input.type === 'android')) {
33
33
  return IAP_FAILED_MESSAGE_JA[input.type];
34
34
  }
35
- const stripeReason = input.reason && !('provider' in input.reason) ? input.reason : null;
35
+ const stripeReason = input.type === 'ios' || input.type === 'android' ? null : (input.reason ?? null);
36
36
  return stripeFailureMessageJa(stripeReason);
37
37
  }
38
38
  /**
@@ -24,8 +24,6 @@ export interface StripeFailureReason {
24
24
  }
25
25
  /** Normalized reason persisted for an App Store / Google Play subscription failure. */
26
26
  export interface IapFailureReason {
27
- /** Provider discriminator. */
28
- provider: 'ios' | 'android';
29
27
  /** Stable machine-readable classification. */
30
28
  code: 'billing_retry' | 'auto_renew_off' | 'subscription_canceled' | 'subscription_gone';
31
29
  /** Provider response status code when present (Apple verifyReceipt status / Google error code). */
@@ -50,9 +48,10 @@ export type PaymentFailureSource = 'webhook.invoice.payment_failed' | 'webhook.i
50
48
  */
51
49
  export interface PaymentFailureRecord {
52
50
  reason: PaymentFailureReason;
53
- source: PaymentFailureSource;
51
+ /** Capture path. Optional for IAP because `payment_failed.type` already identifies the provider/path. */
52
+ source?: PaymentFailureSource;
54
53
  /** ISO 8601 timestamp of when the failure was captured. */
55
- occurredAt: string;
54
+ occurredAt?: string;
56
55
  }
57
56
  /**
58
57
  * Extract a normalized {@link StripeFailureReason} from a Stripe `PaymentIntent`, `Invoice`, a
@@ -86,6 +85,8 @@ export declare function stripeFailureMessageJa(reason: StripeFailureReason | nul
86
85
  * @returns A JSON string.
87
86
  */
88
87
  export declare function serializePaymentFailure(record: PaymentFailureRecord): string;
88
+ /** Serialize an IAP reason directly, without redundant provider/source/timestamp wrappers. */
89
+ export declare function serializeIapFailureReason(reason: IapFailureReason): string;
89
90
  /**
90
91
  * Parse a `payment_failed.receipt` value back into a {@link PaymentFailureRecord}.
91
92
  *
@@ -148,6 +148,10 @@ export function stripeFailureMessageJa(reason) {
148
148
  export function serializePaymentFailure(record) {
149
149
  return JSON.stringify(record);
150
150
  }
151
+ /** Serialize an IAP reason directly, without redundant provider/source/timestamp wrappers. */
152
+ export function serializeIapFailureReason(reason) {
153
+ return JSON.stringify(reason);
154
+ }
151
155
  /**
152
156
  * Parse a `payment_failed.receipt` value back into a {@link PaymentFailureRecord}.
153
157
  *
@@ -161,10 +165,21 @@ export function parsePaymentFailure(receipt) {
161
165
  try {
162
166
  const parsed = JSON.parse(receipt);
163
167
  const r = asRecord(parsed);
164
- if (!r || !asRecord(r.reason) || typeof r.source !== 'string' || typeof r.occurredAt !== 'string') {
168
+ if (!r) {
165
169
  return null;
166
170
  }
167
- return parsed;
171
+ if (asRecord(r.reason)) {
172
+ if ((r.source !== undefined && typeof r.source !== 'string') ||
173
+ (r.occurredAt !== undefined && typeof r.occurredAt !== 'string')) {
174
+ return null;
175
+ }
176
+ return parsed;
177
+ }
178
+ // IAP rows store the reason itself. `code` is required so arbitrary JSON is not accepted as a reason.
179
+ if (typeof r.code === 'string') {
180
+ return { reason: parsed };
181
+ }
182
+ return null;
168
183
  }
169
184
  catch {
170
185
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdlabo/workers-hono-kit",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"