@shware/purchase 0.2.1 → 0.2.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.
- package/dist/stripe/handler.cjs +56 -0
- package/dist/stripe/handler.cjs.map +1 -0
- package/dist/stripe/handler.d.cts +15 -0
- package/dist/stripe/handler.d.ts +15 -0
- package/dist/stripe/handler.mjs +31 -0
- package/dist/stripe/handler.mjs.map +1 -0
- package/dist/stripe/index.cjs +3 -0
- package/dist/stripe/index.cjs.map +1 -1
- package/dist/stripe/index.d.cts +1 -0
- package/dist/stripe/index.d.ts +1 -0
- package/dist/stripe/index.mjs +2 -0
- package/dist/stripe/index.mjs.map +1 -1
- package/dist/stripe/mapper.cjs +2 -1
- package/dist/stripe/mapper.cjs.map +1 -1
- package/dist/stripe/mapper.d.cts +11 -0
- package/dist/stripe/mapper.d.ts +11 -0
- package/dist/stripe/mapper.mjs +2 -1
- package/dist/stripe/mapper.mjs.map +1 -1
- package/dist/stripe/schema.d.cts +1 -1
- package/dist/stripe/schema.d.ts +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/stripe/handler.ts
|
|
21
|
+
var handler_exports = {};
|
|
22
|
+
__export(handler_exports, {
|
|
23
|
+
StripeEventHandler: () => StripeEventHandler
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(handler_exports);
|
|
26
|
+
var StripeEventHandler = class _StripeEventHandler {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
handlers;
|
|
29
|
+
constructor() {
|
|
30
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
31
|
+
}
|
|
32
|
+
static create() {
|
|
33
|
+
return new _StripeEventHandler();
|
|
34
|
+
}
|
|
35
|
+
on = (type, handler) => {
|
|
36
|
+
if (!this.handlers.has(type)) {
|
|
37
|
+
this.handlers.set(type, []);
|
|
38
|
+
}
|
|
39
|
+
this.handlers.get(type)?.push(handler);
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
process = async (event) => {
|
|
43
|
+
const eventHandlers = this.handlers.get(event.type);
|
|
44
|
+
if (eventHandlers) {
|
|
45
|
+
await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
|
|
46
|
+
} else {
|
|
47
|
+
console.error(`No stripe event handler found for event type: ${event.type}`);
|
|
48
|
+
throw new Error(`No stripe event handler found for event type: ${event.type}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
StripeEventHandler
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=handler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import Stripe from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,IAAM,qBAAN,MAAM,oBAAmB;AAAA;AAAA,EAEb;AAAA,EAET,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,OAAO,SAAS;AACd,WAAO,IAAI,oBAAmB;AAAA,EAChC;AAAA,EAEA,KAAK,CAA8B,MAAS,YAA+B;AACzE,QAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GAAG;AAC5B,WAAK,SAAS,IAAI,MAAM,CAAC,CAAC;AAAA,IAC5B;AAEA,SAAK,SAAS,IAAI,IAAI,GAAG,KAAK,OAAO;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,OAAO,UAAuC;AACtD,UAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;AAClD,QAAI,eAAe;AACjB,YAAM,QAAQ,IAAI,cAAc,IAAI,CAAC,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;AAAA,IAC9E,OAAO;AACL,cAAQ,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAC3E,YAAM,IAAI,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
|
|
3
|
+
type StripeEventObject<T extends Stripe.Event.Type> = Extract<Stripe.Event, {
|
|
4
|
+
type: T;
|
|
5
|
+
}>['data']['object'];
|
|
6
|
+
type EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (object: StripeEventObject<T>) => Promise<void>;
|
|
7
|
+
declare class StripeEventHandler {
|
|
8
|
+
private readonly handlers;
|
|
9
|
+
private constructor();
|
|
10
|
+
static create(): StripeEventHandler;
|
|
11
|
+
on: <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => this;
|
|
12
|
+
process: (event: Stripe.Event) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { StripeEventHandler };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
|
|
3
|
+
type StripeEventObject<T extends Stripe.Event.Type> = Extract<Stripe.Event, {
|
|
4
|
+
type: T;
|
|
5
|
+
}>['data']['object'];
|
|
6
|
+
type EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (object: StripeEventObject<T>) => Promise<void>;
|
|
7
|
+
declare class StripeEventHandler {
|
|
8
|
+
private readonly handlers;
|
|
9
|
+
private constructor();
|
|
10
|
+
static create(): StripeEventHandler;
|
|
11
|
+
on: <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => this;
|
|
12
|
+
process: (event: Stripe.Event) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { StripeEventHandler };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/stripe/handler.ts
|
|
2
|
+
var StripeEventHandler = class _StripeEventHandler {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
handlers;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
static create() {
|
|
9
|
+
return new _StripeEventHandler();
|
|
10
|
+
}
|
|
11
|
+
on = (type, handler) => {
|
|
12
|
+
if (!this.handlers.has(type)) {
|
|
13
|
+
this.handlers.set(type, []);
|
|
14
|
+
}
|
|
15
|
+
this.handlers.get(type)?.push(handler);
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
process = async (event) => {
|
|
19
|
+
const eventHandlers = this.handlers.get(event.type);
|
|
20
|
+
if (eventHandlers) {
|
|
21
|
+
await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
|
|
22
|
+
} else {
|
|
23
|
+
console.error(`No stripe event handler found for event type: ${event.type}`);
|
|
24
|
+
throw new Error(`No stripe event handler found for event type: ${event.type}`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
StripeEventHandler
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import Stripe from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";AAWO,IAAM,qBAAN,MAAM,oBAAmB;AAAA;AAAA,EAEb;AAAA,EAET,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,OAAO,SAAS;AACd,WAAO,IAAI,oBAAmB;AAAA,EAChC;AAAA,EAEA,KAAK,CAA8B,MAAS,YAA+B;AACzE,QAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GAAG;AAC5B,WAAK,SAAS,IAAI,MAAM,CAAC,CAAC;AAAA,IAC5B;AAEA,SAAK,SAAS,IAAI,IAAI,GAAG,KAAK,OAAO;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,OAAO,UAAuC;AACtD,UAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;AAClD,QAAI,eAAe;AACjB,YAAM,QAAQ,IAAI,cAAc,IAAI,CAAC,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;AAAA,IAC9E,OAAO;AACL,cAAQ,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAC3E,YAAM,IAAI,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
|
package/dist/stripe/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var stripe_exports = {};
|
|
22
22
|
__export(stripe_exports, {
|
|
23
23
|
METADATA_KEYS: () => import_metadata.METADATA_KEYS,
|
|
24
|
+
StripeEventHandler: () => import_handler.StripeEventHandler,
|
|
24
25
|
cancellationDetailsSchema: () => import_schema.cancellationDetailsSchema,
|
|
25
26
|
checkoutSessionSchema: () => import_schema.checkoutSessionSchema,
|
|
26
27
|
getBeginCheckoutProperties: () => import_mapper.getBeginCheckoutProperties,
|
|
@@ -37,11 +38,13 @@ __export(stripe_exports, {
|
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(stripe_exports);
|
|
39
40
|
var import_mapper = require("./mapper.cjs");
|
|
41
|
+
var import_handler = require("./handler.cjs");
|
|
40
42
|
var import_schema = require("./schema.cjs");
|
|
41
43
|
var import_metadata = require("./metadata.cjs");
|
|
42
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
45
|
0 && (module.exports = {
|
|
44
46
|
METADATA_KEYS,
|
|
47
|
+
StripeEventHandler,
|
|
45
48
|
cancellationDetailsSchema,
|
|
46
49
|
checkoutSessionSchema,
|
|
47
50
|
getBeginCheckoutProperties,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,oBAIO;AAEP,sBAA8B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,qBAAmC;AACnC,oBAIO;AAEP,sBAA8B;","names":[]}
|
package/dist/stripe/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.cjs';
|
|
2
|
+
export { StripeEventHandler } from './handler.cjs';
|
|
2
3
|
export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.cjs';
|
|
3
4
|
export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.cjs';
|
|
4
5
|
export { METADATA_KEYS } from './metadata.cjs';
|
package/dist/stripe/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.js';
|
|
2
|
+
export { StripeEventHandler } from './handler.js';
|
|
2
3
|
export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.js';
|
|
3
4
|
export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.js';
|
|
4
5
|
export { METADATA_KEYS } from './metadata.js';
|
package/dist/stripe/index.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
getPurchaseProperties,
|
|
13
13
|
getBeginCheckoutProperties
|
|
14
14
|
} from "./mapper.mjs";
|
|
15
|
+
import { StripeEventHandler } from "./handler.mjs";
|
|
15
16
|
import {
|
|
16
17
|
cancellationDetailsSchema,
|
|
17
18
|
checkoutSessionSchema
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
import { METADATA_KEYS } from "./metadata.mjs";
|
|
20
21
|
export {
|
|
21
22
|
METADATA_KEYS,
|
|
23
|
+
StripeEventHandler,
|
|
22
24
|
cancellationDetailsSchema,
|
|
23
25
|
checkoutSessionSchema,
|
|
24
26
|
getBeginCheckoutProperties,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;","names":[]}
|
package/dist/stripe/mapper.cjs
CHANGED
|
@@ -121,7 +121,8 @@ function mapCharge(charge) {
|
|
|
121
121
|
receipt_number: charge.receipt_number,
|
|
122
122
|
receipt_url: charge.receipt_url,
|
|
123
123
|
status: charge.status,
|
|
124
|
-
created: charge.created
|
|
124
|
+
created: charge.created,
|
|
125
|
+
payment_intent: charge.payment_intent && typeof charge.payment_intent === "object" ? mapPaymentIntent(charge.payment_intent) : void 0
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
function mapSubscriptionStatus(status) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { SubscriptionStatus } from '../subscription/index';\nimport type Stripe from 'stripe';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n };\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAmC;AAG5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAEO,SAAS,YAAY,MAAuB;AACjD,SAAO;AAAA,IACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB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,QAAQ;AAAA,QACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { SubscriptionStatus } from '../subscription/index';\nimport type Stripe from 'stripe';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n };\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;;;;;;;;;;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AAC,MAAM,WAAW;AAAA,MAC/C;AAAA,MACA,SAAS,KAAK;AAAA,MACd,WAAW,KAAK,eAAe;AAAA,MAC/B,OAAO,MAAM,KAAK,cAAc,KAAK,QAAQ;AAAA,MAC7C,UAAU,KAAK,YAAY;AAAA,MAC3B,UAAU,MAAM,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IACrD,EAAE;AAAA,EACJ;AACF;AAEO,SAAS,2BAA2B,GAA0C;AACnF,SAAO;AAAA,IACL,UAAU,EAAE,SAAS,YAAY;AAAA,IACjC,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,IACtC,OAAO;AAAA,MACL;AAAA,QACE,SAAS,EAAE,QAAQ;AAAA,QACnB,WAAW,EAAE,QAAQ;AAAA,QACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/stripe/mapper.d.cts
CHANGED
|
@@ -79,6 +79,17 @@ declare function mapCharge(charge: Stripe.Charge): {
|
|
|
79
79
|
receipt_url: string | null;
|
|
80
80
|
status: Stripe.Charge.Status;
|
|
81
81
|
created: number;
|
|
82
|
+
payment_intent: {
|
|
83
|
+
id: string;
|
|
84
|
+
amount: number;
|
|
85
|
+
amount_capturable: number;
|
|
86
|
+
amount_received: number;
|
|
87
|
+
currency: string;
|
|
88
|
+
client_secret: string | null;
|
|
89
|
+
description: string | null;
|
|
90
|
+
status: Stripe.PaymentIntent.Status;
|
|
91
|
+
created: number;
|
|
92
|
+
} | undefined;
|
|
82
93
|
};
|
|
83
94
|
type CheckoutSession = ReturnType<typeof mapCheckoutSession>;
|
|
84
95
|
type ProductPrice = {
|
package/dist/stripe/mapper.d.ts
CHANGED
|
@@ -79,6 +79,17 @@ declare function mapCharge(charge: Stripe.Charge): {
|
|
|
79
79
|
receipt_url: string | null;
|
|
80
80
|
status: Stripe.Charge.Status;
|
|
81
81
|
created: number;
|
|
82
|
+
payment_intent: {
|
|
83
|
+
id: string;
|
|
84
|
+
amount: number;
|
|
85
|
+
amount_capturable: number;
|
|
86
|
+
amount_received: number;
|
|
87
|
+
currency: string;
|
|
88
|
+
client_secret: string | null;
|
|
89
|
+
description: string | null;
|
|
90
|
+
status: Stripe.PaymentIntent.Status;
|
|
91
|
+
created: number;
|
|
92
|
+
} | undefined;
|
|
82
93
|
};
|
|
83
94
|
type CheckoutSession = ReturnType<typeof mapCheckoutSession>;
|
|
84
95
|
type ProductPrice = {
|
package/dist/stripe/mapper.mjs
CHANGED
|
@@ -86,7 +86,8 @@ function mapCharge(charge) {
|
|
|
86
86
|
receipt_number: charge.receipt_number,
|
|
87
87
|
receipt_url: charge.receipt_url,
|
|
88
88
|
status: charge.status,
|
|
89
|
-
created: charge.created
|
|
89
|
+
created: charge.created,
|
|
90
|
+
payment_intent: charge.payment_intent && typeof charge.payment_intent === "object" ? mapPaymentIntent(charge.payment_intent) : void 0
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
function mapSubscriptionStatus(status) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { SubscriptionStatus } from '../subscription/index';\nimport type Stripe from 'stripe';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n };\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AAG5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAEO,SAAS,YAAY,MAAuB;AACjD,SAAO;AAAA,IACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;AAAA,IACT,UAAU,KAAK;AAAA,IACf,UAAU,KAAK;AAAA,IACf,aAAa,KAAK;AAAA,IAClB,YAAY,KAAK;AAAA,IACjB,cAAc,KAAK;AAAA,IACnB,iBAAiB,KAAK;AAAA,IACtB,iBAAiB,KAAK;AAAA,IACtB,OAAO,KAAK,QAAQ,EAAE,IAAI,KAAK,MAAM,GAAG,IAAI;AAAA,EAC9C;AACF;AAEO,SAAS,mBAAmB,SAAkC;AACnE,MAAI,SAA6B;AACjC,MAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;AACtE,UAAM,WAAW,QAAQ,UAAU,CAAC;AACpC,QAAI,SAAS,UAAU,OAAO,SAAS,WAAW,UAAU;AAC1D,eAAS,SAAS,OAAO;AAAA,IA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AW,QAAQ,aAAa,CAAC,GAAG,YAAY;AAAA,EAClD,OAAO;AACL,YAAQ,QAAQ;AAChB,eAAW,QAAQ;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,gBAAgB,QAAQ;AAAA,IACxB,OAAO,MAAM,OAAO,QAAQ;AAAA,IAC5B,UAAU,SAAS,YAAY;AAAA,IAC/B,QAAQ,QAAQ;AAAA,IAChB,OAAO,QAAQ,YAAY,IAAI,CAAC,MAAM,WAAW;AAAA,MAC/C;AAAA,MACA,SAAS,KAAK;AAAA,MACd,WAAW,KAAK,eAAe;AAAA,MAC/B,OAAO,MAAM,KAAK,cAAc,KAAK,QAAQ;AAAA,MAC7C,UAAU,KAAK,YAAY;AAAA,MAC3B,UAAU,MAAM,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IACrD,EAAE;AAAA,EACJ;AACF;AAEO,SAAS,2BAA2B,GAA0C;AACnF,SAAO;AAAA,IACL,UAAU,EAAE,SAAS,YAAY;AAAA,IACjC,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,IACtC,OAAO;AAAA,MACL;AAAA,QACE,SAAS,EAAE,QAAQ;AAAA,QACnB,WAAW,EAAE,QAAQ;AAAA,QACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { SubscriptionStatus } from '../subscription/index';\nimport type Stripe from 'stripe';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n };\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AAG5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAEO,SAAS,YAAY,MAAuB;AACjD,SAAO;AAAA,IACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;AAAA,IACT,UAAU,KAAK;AAAA,IACf,UAAU,KAAK;AAAA,IACf,aAAa,KAAK;AAAA,IAClB,YAAY,KAAK;AAAA,IACjB,cAAc,KAAK;AAAA,IACnB,iBAAiB,KAAK;AAAA,IACtB,iBAAiB,KAAK;AAAA,IACtB,OAAO,KAAK,QAAQ,EAAE,IAAI,KAAK,MAAM,GAAG,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@ import { ProductId } from './types.cjs';
|
|
|
6
6
|
declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
|
|
7
7
|
comment: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniString<string>>>;
|
|
8
8
|
feedback: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniEnum<{
|
|
9
|
+
other: "other";
|
|
9
10
|
customer_service: "customer_service";
|
|
10
11
|
low_quality: "low_quality";
|
|
11
12
|
missing_features: "missing_features";
|
|
@@ -13,7 +14,6 @@ declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
|
|
|
13
14
|
too_complex: "too_complex";
|
|
14
15
|
too_expensive: "too_expensive";
|
|
15
16
|
unused: "unused";
|
|
16
|
-
other: "other";
|
|
17
17
|
}>>>;
|
|
18
18
|
}, zod_v4_core.$strip>;
|
|
19
19
|
declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]): zod_mini.ZodMiniObject<{
|
package/dist/stripe/schema.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ProductId } from './types.js';
|
|
|
6
6
|
declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
|
|
7
7
|
comment: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniString<string>>>;
|
|
8
8
|
feedback: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniEnum<{
|
|
9
|
+
other: "other";
|
|
9
10
|
customer_service: "customer_service";
|
|
10
11
|
low_quality: "low_quality";
|
|
11
12
|
missing_features: "missing_features";
|
|
@@ -13,7 +14,6 @@ declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
|
|
|
13
14
|
too_complex: "too_complex";
|
|
14
15
|
too_expensive: "too_expensive";
|
|
15
16
|
unused: "unused";
|
|
16
|
-
other: "other";
|
|
17
17
|
}>>>;
|
|
18
18
|
}, zod_v4_core.$strip>;
|
|
19
19
|
declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]): zod_mini.ZodMiniObject<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/purchase",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^30.0.0",
|
|
42
|
-
"@types/node": "^24.
|
|
42
|
+
"@types/node": "^24.9.2",
|
|
43
43
|
"jest": "^30.2.0",
|
|
44
44
|
"ts-jest": "^29.4.5",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
|
-
"@repo/eslint-config": "0.0.
|
|
46
|
+
"@repo/eslint-config": "0.0.7",
|
|
47
47
|
"@repo/typescript-config": "0.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|