@shdan/submesh 0.1.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.
Files changed (230) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/dist/contracts.d.ts +191 -0
  4. package/dist/contracts.d.ts.map +1 -0
  5. package/dist/contracts.js +2 -0
  6. package/dist/contracts.js.map +1 -0
  7. package/dist/drizzle/catalog-mapping-repository.d.ts +280 -0
  8. package/dist/drizzle/catalog-mapping-repository.d.ts.map +1 -0
  9. package/dist/drizzle/catalog-mapping-repository.js +62 -0
  10. package/dist/drizzle/catalog-mapping-repository.js.map +1 -0
  11. package/dist/drizzle/ensure-schema.d.ts +3 -0
  12. package/dist/drizzle/ensure-schema.d.ts.map +1 -0
  13. package/dist/drizzle/ensure-schema.js +100 -0
  14. package/dist/drizzle/ensure-schema.js.map +1 -0
  15. package/dist/drizzle/inbound-event-repository.d.ts +960 -0
  16. package/dist/drizzle/inbound-event-repository.d.ts.map +1 -0
  17. package/dist/drizzle/inbound-event-repository.js +148 -0
  18. package/dist/drizzle/inbound-event-repository.js.map +1 -0
  19. package/dist/drizzle/index.d.ts +40 -0
  20. package/dist/drizzle/index.d.ts.map +1 -0
  21. package/dist/drizzle/index.js +57 -0
  22. package/dist/drizzle/index.js.map +1 -0
  23. package/dist/drizzle/migrate.d.ts +11 -0
  24. package/dist/drizzle/migrate.d.ts.map +1 -0
  25. package/dist/drizzle/migrate.js +22 -0
  26. package/dist/drizzle/migrate.js.map +1 -0
  27. package/dist/drizzle/plan-repository.d.ts +497 -0
  28. package/dist/drizzle/plan-repository.d.ts.map +1 -0
  29. package/dist/drizzle/plan-repository.js +70 -0
  30. package/dist/drizzle/plan-repository.js.map +1 -0
  31. package/dist/drizzle/plugin-installation-repository.d.ts +26 -0
  32. package/dist/drizzle/plugin-installation-repository.d.ts.map +1 -0
  33. package/dist/drizzle/plugin-installation-repository.js +71 -0
  34. package/dist/drizzle/plugin-installation-repository.js.map +1 -0
  35. package/dist/drizzle/repository-set.d.ts +4 -0
  36. package/dist/drizzle/repository-set.d.ts.map +1 -0
  37. package/dist/drizzle/repository-set.js +19 -0
  38. package/dist/drizzle/repository-set.js.map +1 -0
  39. package/dist/drizzle/schema.d.ts +2370 -0
  40. package/dist/drizzle/schema.d.ts.map +1 -0
  41. package/dist/drizzle/schema.js +103 -0
  42. package/dist/drizzle/schema.js.map +1 -0
  43. package/dist/drizzle/subject-repository.d.ts +295 -0
  44. package/dist/drizzle/subject-repository.d.ts.map +1 -0
  45. package/dist/drizzle/subject-repository.js +76 -0
  46. package/dist/drizzle/subject-repository.js.map +1 -0
  47. package/dist/drizzle/subscription-repository.d.ts +60 -0
  48. package/dist/drizzle/subscription-repository.d.ts.map +1 -0
  49. package/dist/drizzle/subscription-repository.js +128 -0
  50. package/dist/drizzle/subscription-repository.js.map +1 -0
  51. package/dist/drizzle/summary-repository.d.ts +9 -0
  52. package/dist/drizzle/summary-repository.d.ts.map +1 -0
  53. package/dist/drizzle/summary-repository.js +25 -0
  54. package/dist/drizzle/summary-repository.js.map +1 -0
  55. package/dist/drizzle/types.d.ts +4 -0
  56. package/dist/drizzle/types.d.ts.map +1 -0
  57. package/dist/drizzle/types.js +2 -0
  58. package/dist/drizzle/types.js.map +1 -0
  59. package/dist/errors.d.ts +10 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +13 -0
  62. package/dist/errors.js.map +1 -0
  63. package/dist/hooks.d.ts +24 -0
  64. package/dist/hooks.d.ts.map +1 -0
  65. package/dist/hooks.js +2 -0
  66. package/dist/hooks.js.map +1 -0
  67. package/dist/index.d.ts +11 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +9 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/logger.d.ts +16 -0
  72. package/dist/logger.d.ts.map +1 -0
  73. package/dist/logger.js +8 -0
  74. package/dist/logger.js.map +1 -0
  75. package/dist/plugins/builtin-plugins.d.ts +3 -0
  76. package/dist/plugins/builtin-plugins.d.ts.map +1 -0
  77. package/dist/plugins/builtin-plugins.js +7 -0
  78. package/dist/plugins/builtin-plugins.js.map +1 -0
  79. package/dist/plugins/hash-payload.d.ts +2 -0
  80. package/dist/plugins/hash-payload.d.ts.map +1 -0
  81. package/dist/plugins/hash-payload.js +5 -0
  82. package/dist/plugins/hash-payload.js.map +1 -0
  83. package/dist/plugins/manual.d.ts +12 -0
  84. package/dist/plugins/manual.d.ts.map +1 -0
  85. package/dist/plugins/manual.js +87 -0
  86. package/dist/plugins/manual.js.map +1 -0
  87. package/dist/plugins/plan-provisioning.d.ts +18 -0
  88. package/dist/plugins/plan-provisioning.d.ts.map +1 -0
  89. package/dist/plugins/plan-provisioning.js +159 -0
  90. package/dist/plugins/plan-provisioning.js.map +1 -0
  91. package/dist/plugins/plugin-registry.d.ts +9 -0
  92. package/dist/plugins/plugin-registry.d.ts.map +1 -0
  93. package/dist/plugins/plugin-registry.js +18 -0
  94. package/dist/plugins/plugin-registry.js.map +1 -0
  95. package/dist/providers/apple/plugin/app-store-plan-sync.d.ts +4 -0
  96. package/dist/providers/apple/plugin/app-store-plan-sync.d.ts.map +1 -0
  97. package/dist/providers/apple/plugin/app-store-plan-sync.js +85 -0
  98. package/dist/providers/apple/plugin/app-store-plan-sync.js.map +1 -0
  99. package/dist/providers/apple/plugin/app-store.d.ts +20 -0
  100. package/dist/providers/apple/plugin/app-store.d.ts.map +1 -0
  101. package/dist/providers/apple/plugin/app-store.js +397 -0
  102. package/dist/providers/apple/plugin/app-store.js.map +1 -0
  103. package/dist/providers/apple/security/app-store-verification.d.ts +4 -0
  104. package/dist/providers/apple/security/app-store-verification.d.ts.map +1 -0
  105. package/dist/providers/apple/security/app-store-verification.js +100 -0
  106. package/dist/providers/apple/security/app-store-verification.js.map +1 -0
  107. package/dist/providers/apple/services/app-store-subscription-verification-service.d.ts +3 -0
  108. package/dist/providers/apple/services/app-store-subscription-verification-service.d.ts.map +1 -0
  109. package/dist/providers/apple/services/app-store-subscription-verification-service.js +155 -0
  110. package/dist/providers/apple/services/app-store-subscription-verification-service.js.map +1 -0
  111. package/dist/providers/google/plugin/play-plan-sync.d.ts +4 -0
  112. package/dist/providers/google/plugin/play-plan-sync.d.ts.map +1 -0
  113. package/dist/providers/google/plugin/play-plan-sync.js +270 -0
  114. package/dist/providers/google/plugin/play-plan-sync.js.map +1 -0
  115. package/dist/providers/google/plugin/play.d.ts +20 -0
  116. package/dist/providers/google/plugin/play.d.ts.map +1 -0
  117. package/dist/providers/google/plugin/play.js +460 -0
  118. package/dist/providers/google/plugin/play.js.map +1 -0
  119. package/dist/providers/google/security/oauth.d.ts +10 -0
  120. package/dist/providers/google/security/oauth.d.ts.map +1 -0
  121. package/dist/providers/google/security/oauth.js +116 -0
  122. package/dist/providers/google/security/oauth.js.map +1 -0
  123. package/dist/providers/google/security/pubsub-verification.d.ts +3 -0
  124. package/dist/providers/google/security/pubsub-verification.d.ts.map +1 -0
  125. package/dist/providers/google/security/pubsub-verification.js +229 -0
  126. package/dist/providers/google/security/pubsub-verification.js.map +1 -0
  127. package/dist/providers/google/services/play-subscription-verification-service.d.ts +3 -0
  128. package/dist/providers/google/services/play-subscription-verification-service.d.ts.map +1 -0
  129. package/dist/providers/google/services/play-subscription-verification-service.js +96 -0
  130. package/dist/providers/google/services/play-subscription-verification-service.js.map +1 -0
  131. package/dist/repositories/catalog-mapping-repository.d.ts +9 -0
  132. package/dist/repositories/catalog-mapping-repository.d.ts.map +1 -0
  133. package/dist/repositories/catalog-mapping-repository.js +2 -0
  134. package/dist/repositories/catalog-mapping-repository.js.map +1 -0
  135. package/dist/repositories/inbound-event-repository.d.ts +23 -0
  136. package/dist/repositories/inbound-event-repository.d.ts.map +1 -0
  137. package/dist/repositories/inbound-event-repository.js +2 -0
  138. package/dist/repositories/inbound-event-repository.js.map +1 -0
  139. package/dist/repositories/index.d.ts +30 -0
  140. package/dist/repositories/index.d.ts.map +1 -0
  141. package/dist/repositories/index.js +2 -0
  142. package/dist/repositories/index.js.map +1 -0
  143. package/dist/repositories/plan-repository.d.ts +10 -0
  144. package/dist/repositories/plan-repository.d.ts.map +1 -0
  145. package/dist/repositories/plan-repository.js +2 -0
  146. package/dist/repositories/plan-repository.js.map +1 -0
  147. package/dist/repositories/plugin-installation-repository.d.ts +13 -0
  148. package/dist/repositories/plugin-installation-repository.d.ts.map +1 -0
  149. package/dist/repositories/plugin-installation-repository.js +2 -0
  150. package/dist/repositories/plugin-installation-repository.js.map +1 -0
  151. package/dist/repositories/subject-repository.d.ts +10 -0
  152. package/dist/repositories/subject-repository.d.ts.map +1 -0
  153. package/dist/repositories/subject-repository.js +2 -0
  154. package/dist/repositories/subject-repository.js.map +1 -0
  155. package/dist/repositories/subscription-repository.d.ts +24 -0
  156. package/dist/repositories/subscription-repository.d.ts.map +1 -0
  157. package/dist/repositories/subscription-repository.js +2 -0
  158. package/dist/repositories/subscription-repository.js.map +1 -0
  159. package/dist/security/jwt.d.ts +22 -0
  160. package/dist/security/jwt.d.ts.map +1 -0
  161. package/dist/security/jwt.js +132 -0
  162. package/dist/security/jwt.js.map +1 -0
  163. package/dist/security/plugin-webhook-verification.d.ts +3 -0
  164. package/dist/security/plugin-webhook-verification.d.ts.map +1 -0
  165. package/dist/security/plugin-webhook-verification.js +44 -0
  166. package/dist/security/plugin-webhook-verification.js.map +1 -0
  167. package/dist/security/relay-signature.d.ts +12 -0
  168. package/dist/security/relay-signature.d.ts.map +1 -0
  169. package/dist/security/relay-signature.js +39 -0
  170. package/dist/security/relay-signature.js.map +1 -0
  171. package/dist/services/canonical-subscription-service.d.ts +4 -0
  172. package/dist/services/canonical-subscription-service.d.ts.map +1 -0
  173. package/dist/services/canonical-subscription-service.js +20 -0
  174. package/dist/services/canonical-subscription-service.js.map +1 -0
  175. package/dist/services/managed-subscription-service.d.ts +5 -0
  176. package/dist/services/managed-subscription-service.d.ts.map +1 -0
  177. package/dist/services/managed-subscription-service.js +24 -0
  178. package/dist/services/managed-subscription-service.js.map +1 -0
  179. package/dist/services/plan-provisioning-service.d.ts +5 -0
  180. package/dist/services/plan-provisioning-service.d.ts.map +1 -0
  181. package/dist/services/plan-provisioning-service.js +100 -0
  182. package/dist/services/plan-provisioning-service.js.map +1 -0
  183. package/dist/services/plan-resolution.d.ts +4 -0
  184. package/dist/services/plan-resolution.d.ts.map +1 -0
  185. package/dist/services/plan-resolution.js +33 -0
  186. package/dist/services/plan-resolution.js.map +1 -0
  187. package/dist/services/plugin-installation-service.d.ts +6 -0
  188. package/dist/services/plugin-installation-service.d.ts.map +1 -0
  189. package/dist/services/plugin-installation-service.js +19 -0
  190. package/dist/services/plugin-installation-service.js.map +1 -0
  191. package/dist/services/provider-subscription-sync-service.d.ts +4 -0
  192. package/dist/services/provider-subscription-sync-service.d.ts.map +1 -0
  193. package/dist/services/provider-subscription-sync-service.js +13 -0
  194. package/dist/services/provider-subscription-sync-service.js.map +1 -0
  195. package/dist/services/subject-resolution.d.ts +4 -0
  196. package/dist/services/subject-resolution.d.ts.map +1 -0
  197. package/dist/services/subject-resolution.js +48 -0
  198. package/dist/services/subject-resolution.js.map +1 -0
  199. package/dist/services/webhook-ingestion-service.d.ts +14 -0
  200. package/dist/services/webhook-ingestion-service.d.ts.map +1 -0
  201. package/dist/services/webhook-ingestion-service.js +149 -0
  202. package/dist/services/webhook-ingestion-service.js.map +1 -0
  203. package/dist/submesh.d.ts +265 -0
  204. package/dist/submesh.d.ts.map +1 -0
  205. package/dist/submesh.js +602 -0
  206. package/dist/submesh.js.map +1 -0
  207. package/dist/utils/canonical.d.ts +7 -0
  208. package/dist/utils/canonical.d.ts.map +1 -0
  209. package/dist/utils/canonical.js +8 -0
  210. package/dist/utils/canonical.js.map +1 -0
  211. package/dist/utils/parse.d.ts +42 -0
  212. package/dist/utils/parse.d.ts.map +1 -0
  213. package/dist/utils/parse.js +74 -0
  214. package/dist/utils/parse.js.map +1 -0
  215. package/dist/utils/records.d.ts +2 -0
  216. package/dist/utils/records.d.ts.map +1 -0
  217. package/dist/utils/records.js +7 -0
  218. package/dist/utils/records.js.map +1 -0
  219. package/dist/utils/time.d.ts +2 -0
  220. package/dist/utils/time.d.ts.map +1 -0
  221. package/dist/utils/time.js +4 -0
  222. package/dist/utils/time.js.map +1 -0
  223. package/dist/utils/validation.d.ts +10 -0
  224. package/dist/utils/validation.d.ts.map +1 -0
  225. package/dist/utils/validation.js +19 -0
  226. package/dist/utils/validation.js.map +1 -0
  227. package/drizzle/0000_cute_the_order.sql +94 -0
  228. package/drizzle/meta/0000_snapshot.json +559 -0
  229. package/drizzle/meta/_journal.json +13 -0
  230. package/package.json +54 -0
@@ -0,0 +1,48 @@
1
+ import { ConflictError, NotFoundError, ValidationError } from "../errors.js";
2
+ import { getExternalSubjectId } from "../utils/canonical.js";
3
+ function toIdentityInput(subjectId, input, externalSubjectId) {
4
+ return {
5
+ subjectId,
6
+ provider: input.pluginKey,
7
+ externalId: externalSubjectId,
8
+ metadata: {
9
+ sourceType: input.sourceType,
10
+ },
11
+ };
12
+ }
13
+ export async function resolveSubjectForRecord(repositories, input) {
14
+ const externalSubjectId = getExternalSubjectId(input);
15
+ if (input.subjectId) {
16
+ const subject = await repositories.subjects.upsert({
17
+ id: input.subjectId,
18
+ email: input.subject?.email,
19
+ name: input.subject?.name,
20
+ externalRef: input.subject?.externalRef,
21
+ metadata: input.subject?.metadata,
22
+ });
23
+ if (!externalSubjectId) {
24
+ return subject;
25
+ }
26
+ const existingIdentity = await repositories.subjects.findIdentity(input.pluginKey, externalSubjectId);
27
+ if (existingIdentity && existingIdentity.subjectId !== subject.id) {
28
+ throw new ConflictError(`Provider identity ${input.pluginKey}:${externalSubjectId} is already linked to another subject.`);
29
+ }
30
+ if (!existingIdentity) {
31
+ await repositories.subjects.upsertIdentity(toIdentityInput(subject.id, input, externalSubjectId));
32
+ }
33
+ return subject;
34
+ }
35
+ if (!externalSubjectId) {
36
+ throw new ValidationError("Canonical subscription input must include subjectId or an external subject identity.");
37
+ }
38
+ const identity = await repositories.subjects.findIdentity(input.pluginKey, externalSubjectId);
39
+ if (!identity) {
40
+ throw new NotFoundError(`No linked subject found for ${input.pluginKey}:${externalSubjectId}.`);
41
+ }
42
+ const subject = await repositories.subjects.getById(identity.subjectId);
43
+ if (!subject) {
44
+ throw new NotFoundError(`Linked subject ${identity.subjectId} was not found.`);
45
+ }
46
+ return subject;
47
+ }
48
+ //# sourceMappingURL=subject-resolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subject-resolution.js","sourceRoot":"","sources":["../../src/services/subject-resolution.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,SAAS,eAAe,CACtB,SAAiB,EACjB,KAAiC,EACjC,iBAAyB;IAEzB,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,KAAK,CAAC,SAAS;QACzB,UAAU,EAAE,iBAAiB;QAC7B,QAAQ,EAAE;YACR,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,YAA2B,EAC3B,KAAiC;IAEjC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAEtD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;YACjD,EAAE,EAAE,KAAK,CAAC,SAAS;YACnB,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK;YAC3B,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI;YACzB,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW;YACvC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ;SAClC,CAAC,CAAC;QAEH,IAAI,CAAC,iBA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
2
+ import type { PluginRegistry } from "../plugins/plugin-registry.js";
3
+ import type { SubmeshRepositories } from "../repositories/index.js";
4
+ import type { SubmeshLogger } from "../logger.js";
5
+ import type { SubmeshHooks } from "../hooks.js";
6
+ interface WebhookIngestionOptions {
7
+ repositories: SubmeshRepositories;
8
+ pluginRegistry: PluginRegistry;
9
+ logger: SubmeshLogger;
10
+ hooks: SubmeshHooks;
11
+ }
12
+ export declare function ingestWebhookEvent(options: WebhookIngestionOptions, pluginKey: string, body: unknown, headers: Record<string, string | string[] | undefined>, ingestOptions?: IngestWebhookOptions): Promise<IngestWebhookResult>;
13
+ export {};
14
+ //# sourceMappingURL=webhook-ingestion-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-ingestion-service.d.ts","sourceRoot":"","sources":["../../src/services/webhook-ingestion-service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAiB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,UAAU,uBAAuB;IAC/B,YAAY,EAAE,mBAAmB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACrB;AAyFD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,uBAAuB,EAChC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,EACtD,aAAa,GAAE,oBAAyB,GACvC,OAAO,CAAC,mBAAmB,CAAC,CAuG9B"}
@@ -0,0 +1,149 @@
1
+ import { ValidationError } from "../errors.js";
2
+ import { ingestCanonicalSubscription } from "./canonical-subscription-service.js";
3
+ const MAX_STORED_PAYLOAD_BYTES = 128 * 1024;
4
+ const PAYLOAD_PREVIEW_BYTES = 4096;
5
+ const MAX_STORED_ERROR_MESSAGE_LENGTH = 2048;
6
+ function truncate(value, maxLength) {
7
+ if (value.length <= maxLength) {
8
+ return value;
9
+ }
10
+ return `${value.slice(0, maxLength)}...[truncated]`;
11
+ }
12
+ function toPersistedPayload(body) {
13
+ const payload = body && typeof body === "object" && !Array.isArray(body)
14
+ ? body
15
+ : { value: body };
16
+ try {
17
+ const serialized = JSON.stringify(payload);
18
+ if (!serialized) {
19
+ return payload;
20
+ }
21
+ const size = Buffer.byteLength(serialized, "utf8");
22
+ if (size <= MAX_STORED_PAYLOAD_BYTES) {
23
+ return payload;
24
+ }
25
+ return {
26
+ _truncated: true,
27
+ _originalSizeBytes: size,
28
+ preview: truncate(serialized, PAYLOAD_PREVIEW_BYTES),
29
+ };
30
+ }
31
+ catch {
32
+ return {
33
+ _unserializable: true,
34
+ valueType: typeof body,
35
+ };
36
+ }
37
+ }
38
+ function toStoredErrorMessage(error) {
39
+ const message = error instanceof Error ? error.message : "Unknown webhook ingestion error.";
40
+ return truncate(message, MAX_STORED_ERROR_MESSAGE_LENGTH);
41
+ }
42
+ async function processParsedEvent(options, event, records) {
43
+ const transitions = [];
44
+ const subscriptions = await options.repositories.transaction(async (tx) => {
45
+ const created = [];
46
+ for (const record of records) {
47
+ const existing = await tx.subscriptions.getBySource(record.pluginKey, record.sourceRef);
48
+ const previousStatus = existing?.status ?? null;
49
+ const sub = await ingestCanonicalSubscription(tx, record);
50
+ created.push(sub);
51
+ if (previousStatus !== sub.status) {
52
+ transitions.push({ sub, previous: previousStatus });
53
+ }
54
+ }
55
+ return created;
56
+ });
57
+ await options.repositories.inboundEvents.markProcessed(event.id, subscriptions.length);
58
+ for (const t of transitions) {
59
+ if (options.hooks.onSubscriptionChanged) {
60
+ await Promise.resolve(options.hooks.onSubscriptionChanged(t.sub, t.previous)).catch((e) => options.logger.error("Error in onSubscriptionChanged hook", { error: e }));
61
+ }
62
+ }
63
+ return subscriptions;
64
+ }
65
+ export async function ingestWebhookEvent(options, pluginKey, body, headers, ingestOptions = {}) {
66
+ const plugin = options.pluginRegistry.get(pluginKey);
67
+ if (!plugin) {
68
+ throw new ValidationError(`Plugin ${pluginKey} is not registered.`);
69
+ }
70
+ const installations = await options.repositories.pluginInstallations.list();
71
+ const installation = installations.find((item) => item.pluginKey === pluginKey);
72
+ if (pluginKey !== "manual" && !installation?.enabled) {
73
+ throw new ValidationError(`Plugin ${pluginKey} is not installed or not enabled.`);
74
+ }
75
+ if (!plugin.parseWebhook) {
76
+ throw new ValidationError(`Plugin ${pluginKey} does not support webhook ingestion.`);
77
+ }
78
+ const receivedAt = new Date().toISOString();
79
+ const config = installation?.config ?? {};
80
+ const envelope = {
81
+ body,
82
+ headers,
83
+ receivedAt,
84
+ rawBody: ingestOptions.rawBody,
85
+ };
86
+ if (plugin.verifyWebhook) {
87
+ const verification = await plugin.verifyWebhook(envelope, { config });
88
+ if (!verification.verified) {
89
+ throw new ValidationError(`Webhook verification failed for ${pluginKey}.`);
90
+ }
91
+ }
92
+ const parsed = await plugin.parseWebhook({
93
+ ...envelope,
94
+ });
95
+ const events = Array.isArray(parsed) ? parsed : [parsed];
96
+ const subscriptions = [];
97
+ let processedEvents = 0;
98
+ let duplicateEvents = 0;
99
+ for (const event of events) {
100
+ const received = await options.repositories.inboundEvents.markReceived({
101
+ pluginKey,
102
+ eventKey: event.eventKey,
103
+ eventType: event.eventType,
104
+ sourceRef: event.sourceRef,
105
+ payload: toPersistedPayload(body),
106
+ });
107
+ if (!received.claimed) {
108
+ duplicateEvents += 1;
109
+ continue;
110
+ }
111
+ const inboundEvent = received.event;
112
+ if (event.records.length === 0) {
113
+ await options.repositories.inboundEvents.markIgnored(inboundEvent.id);
114
+ continue;
115
+ }
116
+ try {
117
+ const created = await processParsedEvent(options, inboundEvent, event.records);
118
+ subscriptions.push(...created);
119
+ processedEvents += 1;
120
+ }
121
+ catch (error) {
122
+ const message = toStoredErrorMessage(error);
123
+ await options.repositories.inboundEvents.markFailed(inboundEvent.id, message);
124
+ options.logger.error("Webhook ingestion failed for event", {
125
+ eventId: inboundEvent.id,
126
+ error,
127
+ });
128
+ if (options.hooks.onWebhookFailed) {
129
+ await Promise.resolve(options.hooks.onWebhookFailed(pluginKey, inboundEvent, error)).catch((e) => options.logger.error("Error in onWebhookFailed hook", { error: e }));
130
+ }
131
+ throw error;
132
+ }
133
+ }
134
+ const result = {
135
+ processedEvents,
136
+ duplicateEvents,
137
+ subscriptions,
138
+ };
139
+ options.logger.info("Webhook ingestion completed", {
140
+ pluginKey,
141
+ processedEvents,
142
+ duplicateEvents,
143
+ });
144
+ if (options.hooks.onWebhookProcessed) {
145
+ await Promise.resolve(options.hooks.onWebhookProcessed(pluginKey, result)).catch((e) => options.logger.error("Error in onWebhookProcessed hook", { error: e }));
146
+ }
147
+ return result;
148
+ }
149
+ //# sourceMappingURL=webhook-ingestion-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-ingestion-service.js","sourceRoot":"","sources":["../../src/services/webhook-ingestion-service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAWlF,MAAM,wBAAwB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC5C,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAE7C,SAAS,QAAQ,CAAC,KAAa,EAAE,SAAiB;IAChD,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,E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ccessDecision, type CanonicalSubscriptionInput, type CatalogMapping, type DashboardSummary, type InboundEvent, type Plan, type PluginInstallation, type Subject, type Subscription, type SubscriptionWithPlan } from "@shdan/submesh-core";
2
+ import type { CreateManagedSubscriptionInput, CreatePlanInput, IngestWebhookOptions, IngestWebhookResult, InstallPluginInput, LinkProviderIdentityInput, PluginListItem, SyncAppleAppStoreSubscriptionInput, SyncGooglePlaySubscriptionInput, SubmeshOptions, SyncedProviderSubscription, UpsertCatalogMappingInput, UpsertSubjectInput, VerifyAppleAppStoreSubscriptionInput, VerifyGooglePlaySubscriptionInput, UpdatePlanInput, UpdateSubscriptionInput, CancelSubscriptionOptions, VerifiedProviderSubscription } from "./contracts.js";
3
+ /**
4
+ * Main Submesh SDK client.
5
+ *
6
+ * Create one instance, then use it to manage subjects, plans, subscriptions,
7
+ * plugins, and provider sync flows.
8
+ */
9
+ export declare class Submesh {
10
+ private readonly repositories;
11
+ private readonly pluginRegistry;
12
+ private readonly ready;
13
+ private readyError;
14
+ private readonly logger;
15
+ private readonly hooks;
16
+ private ensureReady;
17
+ private getPluginConfig;
18
+ /**
19
+ * Creates a Submesh client.
20
+ *
21
+ * You can provide repositories directly, Drizzle options, or a Postgres
22
+ * connection string. Built-in plugins are registered by default.
23
+ *
24
+ * @param options Configuration for repositories, migrations, and plugins.
25
+ */
26
+ constructor(options?: SubmeshOptions);
27
+ /**
28
+ * Registers a plugin in memory so it can be installed and used.
29
+ *
30
+ * @param plugin Plugin definition to register.
31
+ */
32
+ registerPlugin(plugin: SubscriptionPlugin): void;
33
+ /**
34
+ * Saves plugin configuration and marks the plugin as installed.
35
+ *
36
+ * @param input Plugin key and installation config payload.
37
+ * @returns The stored plugin installation record.
38
+ */
39
+ installPlugin<K extends string>(input: InstallPluginInput<K>): Promise<PluginInstallation>;
40
+ /**
41
+ * Returns registered plugins with their current installation state.
42
+ *
43
+ * @returns Registered plugins enriched with installation status.
44
+ */
45
+ listPlugins(): Promise<PluginListItem[]>;
46
+ /**
47
+ * Disables an installed plugin.
48
+ *
49
+ * @param pluginKey The key of the plugin to disable.
50
+ */
51
+ disablePlugin(pluginKey: string): Promise<void>;
52
+ /**
53
+ * Returns all subjects.
54
+ *
55
+ * @returns All known subjects.
56
+ */
57
+ listSubjects(): Promise<Subject[]>;
58
+ /**
59
+ * Creates or updates a subject.
60
+ *
61
+ * @param input Subject payload to insert or update.
62
+ * @returns The created or updated subject.
63
+ */
64
+ upsertSubject(input: UpsertSubjectInput): Promise<Subject>;
65
+ /**
66
+ * Returns a subject by their ID.
67
+ *
68
+ * @param id The subject identifier.
69
+ * @returns The subject or undefined if not found.
70
+ */
71
+ getSubject(id: string): Promise<Subject | undefined>;
72
+ /**
73
+ * Links an external provider identity to a subject.
74
+ *
75
+ * @param input Provider identity details and target subject.
76
+ * @returns Resolves when the identity link is persisted.
77
+ */
78
+ linkProviderIdentity(input: LinkProviderIdentityInput): Promise<void>;
79
+ /**
80
+ * Returns all plans.
81
+ *
82
+ * @returns All plans in the catalog.
83
+ */
84
+ listPlans(): Promise<Plan[]>;
85
+ /**
86
+ * Creates a plan and runs plugin provisioning hooks.
87
+ *
88
+ * @param input Plan definition and entitlement data.
89
+ * @returns The newly created plan.
90
+ */
91
+ createPlan(input: CreatePlanInput): Promise<Plan>;
92
+ /**
93
+ * Updates a plan's details.
94
+ *
95
+ * @param code The unique code of the plan to update.
96
+ * @param input Data to update on the plan.
97
+ * @returns The updated plan.
98
+ */
99
+ updatePlan(code: string, input: UpdatePlanInput): Promise<Plan>;
100
+ /**
101
+ * Deletes a plan from the catalog.
102
+ *
103
+ * @param code The plan code to delete.
104
+ */
105
+ deletePlan(code: string): Promise<void>;
106
+ /**
107
+ * Returns catalog mappings from provider products to internal plan codes.
108
+ *
109
+ * @returns All configured catalog mappings.
110
+ */
111
+ listCatalogMappings(): Promise<CatalogMapping[]>;
112
+ /**
113
+ * Creates or updates a catalog mapping after validating the target plan.
114
+ *
115
+ * @param input Provider catalog identifier mapped to a plan code.
116
+ * @returns The created or updated mapping.
117
+ */
118
+ upsertCatalogMapping(input: UpsertCatalogMappingInput): Promise<CatalogMapping>;
119
+ /**
120
+ * Removes a catalog mapping.
121
+ *
122
+ * @param pluginKey Plugin key (e.g. google-play).
123
+ * @param externalProductId Product ID at the provider.
124
+ */
125
+ deleteCatalogMapping(pluginKey: string, externalProductId: string): Promise<void>;
126
+ /**
127
+ * Returns subscriptions with resolved plan details.
128
+ *
129
+ * @returns All subscriptions joined with plan details.
130
+ */
131
+ listSubscriptions(): Promise<SubscriptionWithPlan[]>;
132
+ /**
133
+ * Returns a subscription by its ID.
134
+ *
135
+ * @param id The subscription identifier.
136
+ */
137
+ getSubscription(id: string): Promise<SubscriptionWithPlan | undefined>;
138
+ /**
139
+ * Returns subscriptions for a specific subject.
140
+ *
141
+ * @param subjectId The subject identifier.
142
+ */
143
+ listSubscriptionsBySubject(subjectId: string): Promise<SubscriptionWithPlan[]>;
144
+ /**
145
+ * Creates a managed subscription.
146
+ *
147
+ * @param input Subscription payload for a subject and plan.
148
+ * @returns The created subscription.
149
+ */
150
+ createSubscription(input: CreateManagedSubscriptionInput): Promise<Subscription>;
151
+ /**
152
+ * Updates an existing subscription directly.
153
+ *
154
+ * @param id The subscription ID.
155
+ * @param input Data to update.
156
+ */
157
+ updateSubscription(id: string, input: UpdateSubscriptionInput): Promise<Subscription>;
158
+ /**
159
+ * Cancels a subscription. For manual subscriptions, updates local state.
160
+ *
161
+ * @param id Subscription ID.
162
+ * @param options Cancellation options.
163
+ */
164
+ cancelSubscription(id: string, options?: CancelSubscriptionOptions): Promise<Subscription>;
165
+ /**
166
+ * Checks whether a subject has access to an entitlement.
167
+ *
168
+ * @param subjectId Subject identifier to evaluate.
169
+ * @param entitlement Entitlement key to check.
170
+ * @returns Access decision with reason and optional matched subscription.
171
+ */
172
+ hasAccess(subjectId: string, entitlement: string, options?: EntitlementEvaluationOptions): Promise<AccessDecision>;
173
+ /**
174
+ * Returns all active entitlements for a subject.
175
+ *
176
+ * @param subjectId Subject identifier.
177
+ * @param options Execution options.
178
+ */
179
+ listEntitlements(subjectId: string, options?: EntitlementEvaluationOptions): Promise<string[]>;
180
+ /**
181
+ * Returns dashboard summary metrics.
182
+ *
183
+ * @returns Aggregate counts and metrics for dashboard views.
184
+ */
185
+ getSummary(): Promise<DashboardSummary>;
186
+ /**
187
+ * Returns recently ingested inbound events.
188
+ *
189
+ * @param limit Maximum number of events to return.
190
+ * @returns Most recent inbound events up to the requested limit.
191
+ */
192
+ listEvents(limit?: number): Promise<InboundEvent[]>;
193
+ /**
194
+ * Returns failed inbound events.
195
+ *
196
+ * @param limit Maximum number of events.
197
+ */
198
+ listFailedEvents(limit?: number): Promise<InboundEvent[]>;
199
+ /**
200
+ * Retry processing a failed event.
201
+ *
202
+ * @param eventId The event identifier.
203
+ */
204
+ retryEvent(eventId: string): Promise<IngestWebhookResult>;
205
+ /**
206
+ * Ingests a canonical subscription event.
207
+ *
208
+ * @param input Canonical subscription event payload.
209
+ * @returns The resulting subscription after ingestion.
210
+ */
211
+ ingestCanonicalEvent(input: CanonicalSubscriptionInput): Promise<Subscription>;
212
+ /**
213
+ * Ingests a plugin webhook payload and applies subscription updates.
214
+ *
215
+ * @param pluginKey Registered plugin key handling this webhook.
216
+ * @param body Raw webhook request body.
217
+ * @param headers Request headers used for verification and parsing.
218
+ * @param options Additional ingestion behavior options.
219
+ * @returns Ingestion result including dedupe and subscription update outcome.
220
+ */
221
+ ingestWebhook(pluginKey: string, body: unknown, headers?: Record<string, string | string[] | undefined>, options?: IngestWebhookOptions): Promise<IngestWebhookResult>;
222
+ /**
223
+ * Creates a Web API standard request handler for webhooks.
224
+ * Compatible with Next.js App Router, Cloudflare Workers, and standard Node >= 18.
225
+ *
226
+ * @param pluginKey The plugin to route webhooks to.
227
+ * @returns A function `(req: Request) => Promise<Response>`
228
+ */
229
+ createWebhookHandler(pluginKey: string): (req: Request) => Promise<Response>;
230
+ /**
231
+ * Verifies a Google Play purchase and returns canonical subscription data.
232
+ *
233
+ * @param input Google Play verification payload.
234
+ * @returns Verified provider response with canonical subscription data.
235
+ */
236
+ verifyGooglePlaySubscription(input: VerifyGooglePlaySubscriptionInput): Promise<VerifiedProviderSubscription>;
237
+ /**
238
+ * Verifies and syncs a Google Play subscription.
239
+ *
240
+ * @param input Google Play verification payload plus target subject.
241
+ * @returns Verified data plus the synchronized subscription record.
242
+ */
243
+ syncGooglePlaySubscription(input: SyncGooglePlaySubscriptionInput): Promise<SyncedProviderSubscription>;
244
+ /**
245
+ * Verifies an Apple App Store transaction and returns canonical data.
246
+ *
247
+ * @param input Apple App Store verification payload.
248
+ * @returns Verified provider response with canonical subscription data.
249
+ */
250
+ verifyAppleAppStoreSubscription(input: VerifyAppleAppStoreSubscriptionInput): Promise<VerifiedProviderSubscription>;
251
+ /**
252
+ * Verifies and syncs an Apple App Store subscription.
253
+ *
254
+ * @param input Apple verification payload plus target subject.
255
+ * @returns Verified data plus the synchronized subscription record.
256
+ */
257
+ syncAppleAppStoreSubscription(input: SyncAppleAppStoreSubscriptionInput): Promise<SyncedProviderSubscription>;
258
+ /**
259
+ * Closes underlying repository connections.
260
+ *
261
+ * @returns Resolves when repository connections are closed.
262
+ */
263
+ close(): Promise<void>;
264
+ }
265
+ //# sourceMappingURL=submesh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submesh.d.ts","sourceRoot":"","sources":["../src/submesh.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAE5B,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAC/B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,8BAA8B,EAC9B,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EA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