@shware/purchase 4.0.0 → 4.0.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.
@@ -0,0 +1,35 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/app-store/handler.ts
3
+ /**
4
+ * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart
5
+ * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,
6
+ * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each
7
+ * handler: Apple subtypes share the handler's derived context and are usually a few lines each.
8
+ */
9
+ var AppStoreNotificationHandler = class AppStoreNotificationHandler {
10
+ handlers;
11
+ constructor() {
12
+ this.handlers = /* @__PURE__ */ new Map();
13
+ }
14
+ static create() {
15
+ return new AppStoreNotificationHandler();
16
+ }
17
+ on = (type, handler) => {
18
+ if (!this.handlers.has(type)) this.handlers.set(type, []);
19
+ this.handlers.get(type)?.push(handler);
20
+ return this;
21
+ };
22
+ process = async (event) => {
23
+ const type = event.payload.notificationType;
24
+ const handlers = type ? this.handlers.get(type) : void 0;
25
+ if (!handlers) {
26
+ console.error(`No app store notification handler found for type: ${type}`);
27
+ throw new Error(`No app store notification handler found for type: ${type}`);
28
+ }
29
+ await Promise.all(handlers.map((handler) => handler(event)));
30
+ };
31
+ };
32
+ //#endregion
33
+ exports.AppStoreNotificationHandler = AppStoreNotificationHandler;
34
+
35
+ //# sourceMappingURL=handler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.cjs","names":[],"sources":["../../src/app-store/handler.ts"],"sourcesContent":["import type {\n JWSRenewalInfoDecodedPayload,\n JWSTransactionDecodedPayload,\n NotificationTypeV2,\n ResponseBodyV2DecodedPayload,\n} from '@apple/app-store-server-library';\n\nexport interface AppStoreNotificationEvent {\n payload: ResponseBodyV2DecodedPayload;\n transaction: JWSTransactionDecodedPayload | null;\n renewalInfo: JWSRenewalInfoDecodedPayload | null;\n}\n\ntype NotificationHandlerFn = (event: AppStoreNotificationEvent) => Promise<void>;\n\n/**\n * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart\n * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,\n * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each\n * handler: Apple subtypes share the handler's derived context and are usually a few lines each.\n */\nexport class AppStoreNotificationHandler {\n private readonly handlers: Map<NotificationTypeV2, NotificationHandlerFn[]>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new AppStoreNotificationHandler();\n }\n\n on = (type: NotificationTypeV2, handler: NotificationHandlerFn) => {\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: AppStoreNotificationEvent): Promise<void> => {\n const type = event.payload.notificationType as NotificationTypeV2 | undefined;\n const handlers = type ? this.handlers.get(type) : undefined;\n if (!handlers) {\n console.error(`No app store notification handler found for type: ${type}`);\n throw new Error(`No app store notification handler found for type: ${type}`);\n }\n await Promise.all(handlers.map((handler) => handler(event)));\n };\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,8BAAb,MAAa,4BAA4B;CACvC;CAEA,cAAsB;EACpB,KAAK,2BAAW,IAAI,IAAI;CAC1B;CAEA,OAAO,SAAS;EACd,OAAO,IAAI,4BAA4B;CACzC;CAEA,MAAM,MAA0B,YAAmC;EACjE,IAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GACzB,KAAK,SAAS,IAAI,MAAM,CAAC,CAAC;EAG5B,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO;EACrC,OAAO;CACT;CAEA,UAAU,OAAO,UAAoD;EACnE,MAAM,OAAO,MAAM,QAAQ;EAC3B,MAAM,WAAW,OAAO,KAAK,SAAS,IAAI,IAAI,IAAI,KAAA;EAClD,IAAI,CAAC,UAAU;GACb,QAAQ,MAAM,qDAAqD,MAAM;GACzE,MAAM,IAAI,MAAM,qDAAqD,MAAM;EAC7E;EACA,MAAM,QAAQ,IAAI,SAAS,KAAK,YAAY,QAAQ,KAAK,CAAC,CAAC;CAC7D;AACF"}
@@ -0,0 +1,24 @@
1
+ import { JWSRenewalInfoDecodedPayload, JWSTransactionDecodedPayload, NotificationTypeV2, ResponseBodyV2DecodedPayload } from "@apple/app-store-server-library";
2
+ //#region src/app-store/handler.d.ts
3
+ interface AppStoreNotificationEvent {
4
+ payload: ResponseBodyV2DecodedPayload;
5
+ transaction: JWSTransactionDecodedPayload | null;
6
+ renewalInfo: JWSRenewalInfoDecodedPayload | null;
7
+ }
8
+ type NotificationHandlerFn = (event: AppStoreNotificationEvent) => Promise<void>;
9
+ /**
10
+ * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart
11
+ * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,
12
+ * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each
13
+ * handler: Apple subtypes share the handler's derived context and are usually a few lines each.
14
+ */
15
+ declare class AppStoreNotificationHandler {
16
+ private readonly handlers;
17
+ private constructor();
18
+ static create(): AppStoreNotificationHandler;
19
+ on: (type: NotificationTypeV2, handler: NotificationHandlerFn) => this;
20
+ process: (event: AppStoreNotificationEvent) => Promise<void>;
21
+ }
22
+ //#endregion
23
+ export { AppStoreNotificationEvent, AppStoreNotificationHandler };
24
+ //# sourceMappingURL=handler.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.cts","names":[],"sources":["../../src/app-store/handler.ts"],"mappings":";;UAOiB;EACf,SAAS;EACT,aAAa;EACb,aAAa;;KAGV,yBAAyB,OAAO,8BAA8B;;;;;;;cAQtD;mBACM;UAEV;SAIA,UAAM;EAIb,KAAE,MAAU,oBAAkB,SAAW;EASzC,UAAO,OAAiB,8BAA4B"}
@@ -0,0 +1,24 @@
1
+ import { JWSRenewalInfoDecodedPayload, JWSTransactionDecodedPayload, NotificationTypeV2, ResponseBodyV2DecodedPayload } from "@apple/app-store-server-library";
2
+ //#region src/app-store/handler.d.ts
3
+ interface AppStoreNotificationEvent {
4
+ payload: ResponseBodyV2DecodedPayload;
5
+ transaction: JWSTransactionDecodedPayload | null;
6
+ renewalInfo: JWSRenewalInfoDecodedPayload | null;
7
+ }
8
+ type NotificationHandlerFn = (event: AppStoreNotificationEvent) => Promise<void>;
9
+ /**
10
+ * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart
11
+ * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,
12
+ * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each
13
+ * handler: Apple subtypes share the handler's derived context and are usually a few lines each.
14
+ */
15
+ declare class AppStoreNotificationHandler {
16
+ private readonly handlers;
17
+ private constructor();
18
+ static create(): AppStoreNotificationHandler;
19
+ on: (type: NotificationTypeV2, handler: NotificationHandlerFn) => this;
20
+ process: (event: AppStoreNotificationEvent) => Promise<void>;
21
+ }
22
+ //#endregion
23
+ export { AppStoreNotificationEvent, AppStoreNotificationHandler };
24
+ //# sourceMappingURL=handler.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.mts","names":[],"sources":["../../src/app-store/handler.ts"],"mappings":";;UAOiB;EACf,SAAS;EACT,aAAa;EACb,aAAa;;KAGV,yBAAyB,OAAO,8BAA8B;;;;;;;cAQtD;mBACM;UAEV;SAIA,UAAM;EAIb,KAAE,MAAU,oBAAkB,SAAW;EASzC,UAAO,OAAiB,8BAA4B"}
@@ -0,0 +1,34 @@
1
+ //#region src/app-store/handler.ts
2
+ /**
3
+ * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart
4
+ * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,
5
+ * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each
6
+ * handler: Apple subtypes share the handler's derived context and are usually a few lines each.
7
+ */
8
+ var AppStoreNotificationHandler = class AppStoreNotificationHandler {
9
+ handlers;
10
+ constructor() {
11
+ this.handlers = /* @__PURE__ */ new Map();
12
+ }
13
+ static create() {
14
+ return new AppStoreNotificationHandler();
15
+ }
16
+ on = (type, handler) => {
17
+ if (!this.handlers.has(type)) this.handlers.set(type, []);
18
+ this.handlers.get(type)?.push(handler);
19
+ return this;
20
+ };
21
+ process = async (event) => {
22
+ const type = event.payload.notificationType;
23
+ const handlers = type ? this.handlers.get(type) : void 0;
24
+ if (!handlers) {
25
+ console.error(`No app store notification handler found for type: ${type}`);
26
+ throw new Error(`No app store notification handler found for type: ${type}`);
27
+ }
28
+ await Promise.all(handlers.map((handler) => handler(event)));
29
+ };
30
+ };
31
+ //#endregion
32
+ export { AppStoreNotificationHandler };
33
+
34
+ //# sourceMappingURL=handler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.mjs","names":[],"sources":["../../src/app-store/handler.ts"],"sourcesContent":["import type {\n JWSRenewalInfoDecodedPayload,\n JWSTransactionDecodedPayload,\n NotificationTypeV2,\n ResponseBodyV2DecodedPayload,\n} from '@apple/app-store-server-library';\n\nexport interface AppStoreNotificationEvent {\n payload: ResponseBodyV2DecodedPayload;\n transaction: JWSTransactionDecodedPayload | null;\n renewalInfo: JWSRenewalInfoDecodedPayload | null;\n}\n\ntype NotificationHandlerFn = (event: AppStoreNotificationEvent) => Promise<void>;\n\n/**\n * App Store Server Notification dispatcher keyed by notificationType, the app-store counterpart\n * of StripeEventHandler. The caller verifies and decodes the notification (payload, transaction,\n * renewalInfo) first and passes the decoded event in. Subtype branching stays inside each\n * handler: Apple subtypes share the handler's derived context and are usually a few lines each.\n */\nexport class AppStoreNotificationHandler {\n private readonly handlers: Map<NotificationTypeV2, NotificationHandlerFn[]>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new AppStoreNotificationHandler();\n }\n\n on = (type: NotificationTypeV2, handler: NotificationHandlerFn) => {\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: AppStoreNotificationEvent): Promise<void> => {\n const type = event.payload.notificationType as NotificationTypeV2 | undefined;\n const handlers = type ? this.handlers.get(type) : undefined;\n if (!handlers) {\n console.error(`No app store notification handler found for type: ${type}`);\n throw new Error(`No app store notification handler found for type: ${type}`);\n }\n await Promise.all(handlers.map((handler) => handler(event)));\n };\n}\n"],"mappings":";;;;;;;AAqBA,IAAa,8BAAb,MAAa,4BAA4B;CACvC;CAEA,cAAsB;EACpB,KAAK,2BAAW,IAAI,IAAI;CAC1B;CAEA,OAAO,SAAS;EACd,OAAO,IAAI,4BAA4B;CACzC;CAEA,MAAM,MAA0B,YAAmC;EACjE,IAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GACzB,KAAK,SAAS,IAAI,MAAM,CAAC,CAAC;EAG5B,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO;EACrC,OAAO;CACT;CAEA,UAAU,OAAO,UAAoD;EACnE,MAAM,OAAO,MAAM,QAAQ;EAC3B,MAAM,WAAW,OAAO,KAAK,SAAS,IAAI,IAAI,IAAI,KAAA;EAClD,IAAI,CAAC,UAAU;GACb,QAAQ,MAAM,qDAAqD,MAAM;GACzE,MAAM,IAAI,MAAM,qDAAqD,MAAM;EAC7E;EACA,MAAM,QAAQ,IAAI,SAAS,KAAK,YAAY,QAAQ,KAAK,CAAC,CAAC;CAC7D;AACF"}
@@ -1,3 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_app_store_config = require("./config.cjs");
3
+ const require_app_store_handler = require("./handler.cjs");
3
4
  exports.AppStoreConfig = require_app_store_config.AppStoreConfig;
5
+ exports.AppStoreNotificationHandler = require_app_store_handler.AppStoreNotificationHandler;
@@ -1,2 +1,3 @@
1
1
  import { AppStoreConfig } from "./config.cjs";
2
- export { AppStoreConfig };
2
+ import { AppStoreNotificationEvent, AppStoreNotificationHandler } from "./handler.cjs";
3
+ export { AppStoreConfig, type AppStoreNotificationEvent, AppStoreNotificationHandler };
@@ -1,2 +1,3 @@
1
1
  import { AppStoreConfig } from "./config.mjs";
2
- export { AppStoreConfig };
2
+ import { AppStoreNotificationEvent, AppStoreNotificationHandler } from "./handler.mjs";
3
+ export { AppStoreConfig, type AppStoreNotificationEvent, AppStoreNotificationHandler };
@@ -1,2 +1,3 @@
1
1
  import { AppStoreConfig } from "./config.mjs";
2
- export { AppStoreConfig };
2
+ import { AppStoreNotificationHandler } from "./handler.mjs";
3
+ export { AppStoreConfig, AppStoreNotificationHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/purchase",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,9 +68,13 @@
68
68
  "@repo/typescript-config": "0.0.0"
69
69
  },
70
70
  "peerDependencies": {
71
+ "@apple/app-store-server-library": "^3.1.0",
71
72
  "stripe": "^22.3.1"
72
73
  },
73
74
  "peerDependenciesMeta": {
75
+ "@apple/app-store-server-library": {
76
+ "optional": true
77
+ },
74
78
  "stripe": {
75
79
  "optional": true
76
80
  }