@sakeetech/vendure-payment-viva 0.2.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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +952 -0
  3. package/dist/api/admin-internal.controller.d.ts +59 -0
  4. package/dist/api/admin-internal.controller.d.ts.map +1 -0
  5. package/dist/api/admin-internal.controller.js +229 -0
  6. package/dist/api/admin-internal.controller.js.map +1 -0
  7. package/dist/api/admin-onboarding.controller.d.ts +72 -0
  8. package/dist/api/admin-onboarding.controller.d.ts.map +1 -0
  9. package/dist/api/admin-onboarding.controller.js +496 -0
  10. package/dist/api/admin-onboarding.controller.js.map +1 -0
  11. package/dist/api/admin-sources.controller.d.ts +50 -0
  12. package/dist/api/admin-sources.controller.d.ts.map +1 -0
  13. package/dist/api/admin-sources.controller.js +283 -0
  14. package/dist/api/admin-sources.controller.js.map +1 -0
  15. package/dist/api/shop-api.extension.d.ts +15 -0
  16. package/dist/api/shop-api.extension.d.ts.map +1 -0
  17. package/dist/api/shop-api.extension.js +35 -0
  18. package/dist/api/shop-api.extension.js.map +1 -0
  19. package/dist/api/shop-api.resolver.d.ts +42 -0
  20. package/dist/api/shop-api.resolver.d.ts.map +1 -0
  21. package/dist/api/shop-api.resolver.js +256 -0
  22. package/dist/api/shop-api.resolver.js.map +1 -0
  23. package/dist/api/webhook.controller.d.ts +58 -0
  24. package/dist/api/webhook.controller.d.ts.map +1 -0
  25. package/dist/api/webhook.controller.js +204 -0
  26. package/dist/api/webhook.controller.js.map +1 -0
  27. package/dist/cli/bin.d.ts +28 -0
  28. package/dist/cli/bin.d.ts.map +1 -0
  29. package/dist/cli/bin.js +104 -0
  30. package/dist/cli/bin.js.map +1 -0
  31. package/dist/cli/plan.d.ts +41 -0
  32. package/dist/cli/plan.d.ts.map +1 -0
  33. package/dist/cli/plan.js +115 -0
  34. package/dist/cli/plan.js.map +1 -0
  35. package/dist/cli/register-webhooks.d.ts +45 -0
  36. package/dist/cli/register-webhooks.d.ts.map +1 -0
  37. package/dist/cli/register-webhooks.js +400 -0
  38. package/dist/cli/register-webhooks.js.map +1 -0
  39. package/dist/cli/types.d.ts +75 -0
  40. package/dist/cli/types.d.ts.map +1 -0
  41. package/dist/cli/types.js +10 -0
  42. package/dist/cli/types.js.map +1 -0
  43. package/dist/constants.d.ts +35 -0
  44. package/dist/constants.d.ts.map +1 -0
  45. package/dist/constants.js +40 -0
  46. package/dist/constants.js.map +1 -0
  47. package/dist/entities/index.d.ts +4 -0
  48. package/dist/entities/index.d.ts.map +1 -0
  49. package/dist/entities/index.js +3 -0
  50. package/dist/entities/index.js.map +1 -0
  51. package/dist/entities/viva-transaction.entity.d.ts +70 -0
  52. package/dist/entities/viva-transaction.entity.d.ts.map +1 -0
  53. package/dist/entities/viva-transaction.entity.js +133 -0
  54. package/dist/entities/viva-transaction.entity.js.map +1 -0
  55. package/dist/entities/viva-webhook-event.entity.d.ts +71 -0
  56. package/dist/entities/viva-webhook-event.entity.d.ts.map +1 -0
  57. package/dist/entities/viva-webhook-event.entity.js +138 -0
  58. package/dist/entities/viva-webhook-event.entity.js.map +1 -0
  59. package/dist/index.d.ts +27 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +23 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/jobs/process-viva-webhook.handler.d.ts +95 -0
  64. package/dist/jobs/process-viva-webhook.handler.d.ts.map +1 -0
  65. package/dist/jobs/process-viva-webhook.handler.js +530 -0
  66. package/dist/jobs/process-viva-webhook.handler.js.map +1 -0
  67. package/dist/jobs/queue-names.d.ts +18 -0
  68. package/dist/jobs/queue-names.d.ts.map +1 -0
  69. package/dist/jobs/queue-names.js +19 -0
  70. package/dist/jobs/queue-names.js.map +1 -0
  71. package/dist/jobs/retention-cleanup.handler.d.ts +31 -0
  72. package/dist/jobs/retention-cleanup.handler.d.ts.map +1 -0
  73. package/dist/jobs/retention-cleanup.handler.js +94 -0
  74. package/dist/jobs/retention-cleanup.handler.js.map +1 -0
  75. package/dist/loaders/bootstrap.d.ts +28 -0
  76. package/dist/loaders/bootstrap.d.ts.map +1 -0
  77. package/dist/loaders/bootstrap.js +90 -0
  78. package/dist/loaders/bootstrap.js.map +1 -0
  79. package/dist/migrations/1714000000000-create-viva-tables.d.ts +22 -0
  80. package/dist/migrations/1714000000000-create-viva-tables.d.ts.map +1 -0
  81. package/dist/migrations/1714000000000-create-viva-tables.js +105 -0
  82. package/dist/migrations/1714000000000-create-viva-tables.js.map +1 -0
  83. package/dist/observability/metrics-state.service.d.ts +43 -0
  84. package/dist/observability/metrics-state.service.d.ts.map +1 -0
  85. package/dist/observability/metrics-state.service.js +207 -0
  86. package/dist/observability/metrics-state.service.js.map +1 -0
  87. package/dist/payment-method-handler.d.ts +26 -0
  88. package/dist/payment-method-handler.d.ts.map +1 -0
  89. package/dist/payment-method-handler.js +693 -0
  90. package/dist/payment-method-handler.js.map +1 -0
  91. package/dist/plugin.d.ts +95 -0
  92. package/dist/plugin.d.ts.map +1 -0
  93. package/dist/plugin.js +241 -0
  94. package/dist/plugin.js.map +1 -0
  95. package/dist/providers/viva-oauth2-strategy.provider.d.ts +41 -0
  96. package/dist/providers/viva-oauth2-strategy.provider.d.ts.map +1 -0
  97. package/dist/providers/viva-oauth2-strategy.provider.js +60 -0
  98. package/dist/providers/viva-oauth2-strategy.provider.js.map +1 -0
  99. package/dist/services/connected-accounts.service.d.ts +53 -0
  100. package/dist/services/connected-accounts.service.d.ts.map +1 -0
  101. package/dist/services/connected-accounts.service.js +108 -0
  102. package/dist/services/connected-accounts.service.js.map +1 -0
  103. package/dist/services/per-merchant-semaphore.service.d.ts +49 -0
  104. package/dist/services/per-merchant-semaphore.service.d.ts.map +1 -0
  105. package/dist/services/per-merchant-semaphore.service.js +156 -0
  106. package/dist/services/per-merchant-semaphore.service.js.map +1 -0
  107. package/dist/services/state-machine.service.d.ts +100 -0
  108. package/dist/services/state-machine.service.d.ts.map +1 -0
  109. package/dist/services/state-machine.service.js +233 -0
  110. package/dist/services/state-machine.service.js.map +1 -0
  111. package/dist/types.d.ts +286 -0
  112. package/dist/types.d.ts.map +1 -0
  113. package/dist/types.js +23 -0
  114. package/dist/types.js.map +1 -0
  115. package/dist/util/currency.d.ts +32 -0
  116. package/dist/util/currency.d.ts.map +1 -0
  117. package/dist/util/currency.js +90 -0
  118. package/dist/util/currency.js.map +1 -0
  119. package/dist/util/error-envelope.d.ts +51 -0
  120. package/dist/util/error-envelope.d.ts.map +1 -0
  121. package/dist/util/error-envelope.js +157 -0
  122. package/dist/util/error-envelope.js.map +1 -0
  123. package/dist/util/ip-allowlist.d.ts +44 -0
  124. package/dist/util/ip-allowlist.d.ts.map +1 -0
  125. package/dist/util/ip-allowlist.js +139 -0
  126. package/dist/util/ip-allowlist.js.map +1 -0
  127. package/dist/util/normalize-options.d.ts +24 -0
  128. package/dist/util/normalize-options.d.ts.map +1 -0
  129. package/dist/util/normalize-options.js +189 -0
  130. package/dist/util/normalize-options.js.map +1 -0
  131. package/dist/util/url-template.d.ts +18 -0
  132. package/dist/util/url-template.d.ts.map +1 -0
  133. package/dist/util/url-template.js +22 -0
  134. package/dist/util/url-template.js.map +1 -0
  135. package/package.json +75 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * viva-transaction.entity.ts — TypeORM entity for Viva Wallet payment transactions.
3
+ *
4
+ * @see docs/plans/vendure-plugin-v0.md §"Data Model" lines 132-146
5
+ *
6
+ * Design notes:
7
+ * - Extends VendureEntity for Vendure-compatible `id` / `createdAt` / `updatedAt`.
8
+ * - `channelId` and `paymentId` use `@EntityId()` — Vendure resolves the column
9
+ * type at boot via its EntityIdStrategy (int or uuid depending on config).
10
+ * - `status` stored as varchar with TS literal union — avoids Postgres enum DDL
11
+ * migrations on value additions (matches Medusa convention).
12
+ * - `amountMinor` and `isvAmountMinor` are bigint columns; TypeORM returns bigint
13
+ * as string — typed as `string`, coerce in service layer.
14
+ * - Partial unique index on `vivaOrderCode WHERE viva_order_code IS NOT NULL` is
15
+ * declared here for documentation; the actual WHERE clause requires raw SQL in
16
+ * the migration (TypeORM decorator @Index doesn't support WHERE).
17
+ */
18
+ import { type ID, VendureEntity } from '@vendure/core';
19
+ export type VivaTransactionStatus = 'pending' | 'authorized' | 'captured' | 'refunded' | 'partially_refunded' | 'failed' | 'cancelled';
20
+ /**
21
+ * Composite unique index on (channel_id, payment_id) — one Viva transaction row
22
+ * per Vendure payment per channel.
23
+ */
24
+ export declare class VivaTransaction extends VendureEntity {
25
+ constructor(input?: Partial<VivaTransaction>);
26
+ /**
27
+ * Vendure Channel ID. Column type resolved by EntityIdStrategy at boot.
28
+ * Typically `int` (AutoIncrementIdStrategy) or `varchar(36)` (UuidIdStrategy).
29
+ */
30
+ channelId: ID;
31
+ /**
32
+ * Vendure Payment ID. Column type resolved by EntityIdStrategy at boot.
33
+ */
34
+ paymentId: ID;
35
+ /**
36
+ * Viva-side order code (numeric string). Nullable until `createPayment`
37
+ * receives the response from `POST /checkout/v2/isv/orders`.
38
+ */
39
+ vivaOrderCode: string | null;
40
+ /**
41
+ * Viva-side transaction ID. Populated after webhook 1796 + Retrieve-Transaction.
42
+ */
43
+ vivaTransactionId: string | null;
44
+ /**
45
+ * Payment lifecycle status. Stored as varchar — no Postgres enum DDL.
46
+ */
47
+ status: VivaTransactionStatus;
48
+ /**
49
+ * Order amount in minor units (e.g. pence for GBP).
50
+ * TypeORM returns bigint columns as strings — coerce with Number() / BigInt() in
51
+ * service layer.
52
+ */
53
+ amountMinor: string;
54
+ /**
55
+ * ISO 4217 currency code stored as 3-char string (e.g. 'GBP').
56
+ * Viva sends numeric currency codes outbound; we store the alpha code.
57
+ */
58
+ currencyCode: string;
59
+ /**
60
+ * ISV fee amount in minor units. Default 0. Must be < amountMinor (guarded in
61
+ * createPayment handler).
62
+ */
63
+ isvAmountMinor: string;
64
+ /**
65
+ * Free-form metadata bag (redirect URL, idempotency key, Viva error details,
66
+ * etc). Stored as jsonb.
67
+ */
68
+ metadata: Record<string, unknown>;
69
+ }
70
+ //# sourceMappingURL=viva-transaction.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viva-transaction.entity.d.ts","sourceRoot":"","sources":["../../src/entities/viva-transaction.entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,EAAE,KAAK,EAAE,EAAE,aAAa,EAAY,MAAM,eAAe,CAAC;AAMjE,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GACT,YAAY,GACZ,UAAU,GACV,UAAU,GACV,oBAAoB,GACpB,QAAQ,GACR,WAAW,CAAC;AAMhB;;;GAGG;AACH,qBAQa,eAAgB,SAAQ,aAAa;gBACpC,KAAK,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAI5C;;;OAGG;IAEH,SAAS,EAAG,EAAE,CAAC;IAEf;;OAEG;IAEH,SAAS,EAAG,EAAE,CAAC;IAEf;;;OAGG;IAEH,aAAa,EAAG,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IAEH,iBAAiB,EAAG,MAAM,GAAG,IAAI,CAAC;IAElC;;OAEG;IAEH,MAAM,EAAG,qBAAqB,CAAC;IAE/B;;;;OAIG;IAEH,WAAW,EAAG,MAAM,CAAC;IAErB;;;OAGG;IAEH,YAAY,EAAG,MAAM,CAAC;IAEtB;;;OAGG;IAEH,cAAc,EAAG,MAAM,CAAC;IAExB;;;OAGG;IAEH,QAAQ,EAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAGpC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * viva-transaction.entity.ts — TypeORM entity for Viva Wallet payment transactions.
3
+ *
4
+ * @see docs/plans/vendure-plugin-v0.md §"Data Model" lines 132-146
5
+ *
6
+ * Design notes:
7
+ * - Extends VendureEntity for Vendure-compatible `id` / `createdAt` / `updatedAt`.
8
+ * - `channelId` and `paymentId` use `@EntityId()` — Vendure resolves the column
9
+ * type at boot via its EntityIdStrategy (int or uuid depending on config).
10
+ * - `status` stored as varchar with TS literal union — avoids Postgres enum DDL
11
+ * migrations on value additions (matches Medusa convention).
12
+ * - `amountMinor` and `isvAmountMinor` are bigint columns; TypeORM returns bigint
13
+ * as string — typed as `string`, coerce in service layer.
14
+ * - Partial unique index on `vivaOrderCode WHERE viva_order_code IS NOT NULL` is
15
+ * declared here for documentation; the actual WHERE clause requires raw SQL in
16
+ * the migration (TypeORM decorator @Index doesn't support WHERE).
17
+ */
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __metadata = (this && this.__metadata) || function (k, v) {
25
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26
+ };
27
+ import { Column, Entity, Index, } from 'typeorm';
28
+ import { VendureEntity, EntityId } from '@vendure/core';
29
+ // ---------------------------------------------------------------------------
30
+ // Entity
31
+ // ---------------------------------------------------------------------------
32
+ /**
33
+ * Composite unique index on (channel_id, payment_id) — one Viva transaction row
34
+ * per Vendure payment per channel.
35
+ */
36
+ let VivaTransaction = class VivaTransaction extends VendureEntity {
37
+ constructor(input) {
38
+ super(input);
39
+ }
40
+ /**
41
+ * Vendure Channel ID. Column type resolved by EntityIdStrategy at boot.
42
+ * Typically `int` (AutoIncrementIdStrategy) or `varchar(36)` (UuidIdStrategy).
43
+ */
44
+ channelId;
45
+ /**
46
+ * Vendure Payment ID. Column type resolved by EntityIdStrategy at boot.
47
+ */
48
+ paymentId;
49
+ /**
50
+ * Viva-side order code (numeric string). Nullable until `createPayment`
51
+ * receives the response from `POST /checkout/v2/isv/orders`.
52
+ */
53
+ vivaOrderCode;
54
+ /**
55
+ * Viva-side transaction ID. Populated after webhook 1796 + Retrieve-Transaction.
56
+ */
57
+ vivaTransactionId;
58
+ /**
59
+ * Payment lifecycle status. Stored as varchar — no Postgres enum DDL.
60
+ */
61
+ status;
62
+ /**
63
+ * Order amount in minor units (e.g. pence for GBP).
64
+ * TypeORM returns bigint columns as strings — coerce with Number() / BigInt() in
65
+ * service layer.
66
+ */
67
+ amountMinor;
68
+ /**
69
+ * ISO 4217 currency code stored as 3-char string (e.g. 'GBP').
70
+ * Viva sends numeric currency codes outbound; we store the alpha code.
71
+ */
72
+ currencyCode;
73
+ /**
74
+ * ISV fee amount in minor units. Default 0. Must be < amountMinor (guarded in
75
+ * createPayment handler).
76
+ */
77
+ isvAmountMinor;
78
+ /**
79
+ * Free-form metadata bag (redirect URL, idempotency key, Viva error details,
80
+ * etc). Stored as jsonb.
81
+ */
82
+ metadata;
83
+ };
84
+ __decorate([
85
+ EntityId(),
86
+ __metadata("design:type", Object)
87
+ ], VivaTransaction.prototype, "channelId", void 0);
88
+ __decorate([
89
+ EntityId(),
90
+ __metadata("design:type", Object)
91
+ ], VivaTransaction.prototype, "paymentId", void 0);
92
+ __decorate([
93
+ Column({ type: 'varchar', nullable: true, name: 'viva_order_code' }),
94
+ __metadata("design:type", Object)
95
+ ], VivaTransaction.prototype, "vivaOrderCode", void 0);
96
+ __decorate([
97
+ Column({ type: 'varchar', nullable: true, name: 'viva_transaction_id' }),
98
+ __metadata("design:type", Object)
99
+ ], VivaTransaction.prototype, "vivaTransactionId", void 0);
100
+ __decorate([
101
+ Column({ type: 'varchar', name: 'status' }),
102
+ __metadata("design:type", String)
103
+ ], VivaTransaction.prototype, "status", void 0);
104
+ __decorate([
105
+ Column({ type: 'bigint', name: 'amount_minor' }),
106
+ __metadata("design:type", String)
107
+ ], VivaTransaction.prototype, "amountMinor", void 0);
108
+ __decorate([
109
+ Column({ type: 'varchar', length: 3, name: 'currency_code' }),
110
+ __metadata("design:type", String)
111
+ ], VivaTransaction.prototype, "currencyCode", void 0);
112
+ __decorate([
113
+ Column({ type: 'bigint', default: '0', name: 'isv_amount_minor' }),
114
+ __metadata("design:type", String)
115
+ ], VivaTransaction.prototype, "isvAmountMinor", void 0);
116
+ __decorate([
117
+ Column({ type: 'jsonb', default: '{}', name: 'metadata' }),
118
+ __metadata("design:type", Object)
119
+ ], VivaTransaction.prototype, "metadata", void 0);
120
+ VivaTransaction = __decorate([
121
+ Index('idx_viva_transaction_channel_payment', ['channelId', 'paymentId'], { unique: true })
122
+ /**
123
+ * Partial unique on viva_order_code WHERE viva_order_code IS NOT NULL.
124
+ * TypeORM decorator doesn't support WHERE; index created in raw SQL in migration.
125
+ * Declared here for discoverability; has no runtime effect on index creation.
126
+ */
127
+ ,
128
+ Index('idx_viva_transaction_order_code', ['vivaOrderCode'], { unique: true }),
129
+ Entity('viva_transaction'),
130
+ __metadata("design:paramtypes", [Object])
131
+ ], VivaTransaction);
132
+ export { VivaTransaction };
133
+ //# sourceMappingURL=viva-transaction.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viva-transaction.entity.js","sourceRoot":"","sources":["../../src/entities/viva-transaction.entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;AAEH,OAAO,EACL,MAAM,EACN,MAAM,EACN,KAAK,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAW,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAejE,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E;;;GAGG;AASI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,aAAa;IAChD,YAAY,KAAgC;QAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED;;;OAGG;IAEH,SAAS,CAAM;IAEf;;OAEG;IAEH,SAAS,CAAM;IAEf;;;OAGG;IAEH,aAAa,CA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EAAE,CAAC,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC7E,MAAM,CAAC,kBAAkB,CAAC;;GACd,eAAe,CAmE3B"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * viva-webhook-event.entity.ts — TypeORM entity for incoming Viva Wallet webhook events.
3
+ *
4
+ * @see docs/plans/vendure-plugin-v0.md §"Data Model" lines 148-161
5
+ *
6
+ * Design notes:
7
+ * - `messageId` is the primary key (envelope UUID). NOT auto-generated — Viva
8
+ * supplies it; we use it as the dedupe key (INSERT-OR-IGNORE on conflict).
9
+ * - Does NOT extend VendureEntity — Vendure's base entity adds a generated
10
+ * auto-increment/uuid `id` which conflicts with our natural PK design. We use
11
+ * plain TypeORM `@PrimaryColumn` instead.
12
+ * - Partial index on `(received_at) WHERE processed_at IS NULL` is declared as a
13
+ * standard @Index here for documentation; the WHERE clause requires raw SQL in
14
+ * the migration.
15
+ * - Composite non-unique index on `(merchant_id, event_type_id)` supports
16
+ * efficient A6 NULL-merchant re-walk queries.
17
+ */
18
+ /** Non-unique composite index for merchant-scoped event type queries. */
19
+ export declare class VivaWebhookEvent {
20
+ constructor(input?: Partial<VivaWebhookEvent>);
21
+ /**
22
+ * Envelope MessageId from Viva. UUIDv4. Natural primary key + dedupe key.
23
+ * INSERT-OR-IGNORE on conflict prevents double-processing.
24
+ */
25
+ messageId: string;
26
+ /**
27
+ * Viva event type code (1796, 1797, 1798, 4865, 8193, 8194, …).
28
+ */
29
+ eventTypeId: number;
30
+ /**
31
+ * Viva merchantId UUID from EventData.MerchantId. Nullable — absent for some
32
+ * event types and set to NULL on A6 unresolvable-channel fallback.
33
+ */
34
+ merchantId: string | null;
35
+ /**
36
+ * Viva TransactionId from EventData.TransactionId. Applicable to payment events.
37
+ */
38
+ transactionId: string | null;
39
+ /**
40
+ * Viva AccountId from EventData.AccountId. Applicable to onboarding events
41
+ * (8193, 8194).
42
+ */
43
+ accountId: string | null;
44
+ /**
45
+ * Correlation ID for distributed tracing (if present in event envelope).
46
+ */
47
+ correlationId: string | null;
48
+ /**
49
+ * Number of processing attempts. Incremented on each BullMQ retry.
50
+ */
51
+ retryCount: number;
52
+ /**
53
+ * Raw event payload. Stored as jsonb for querying EventData fields without
54
+ * schema migration.
55
+ */
56
+ payload: Record<string, unknown>;
57
+ /**
58
+ * Wall-clock time the POST /viva/webhook request was received.
59
+ * Partial index on this column WHERE processed_at IS NULL — see migration.
60
+ */
61
+ receivedAt: Date;
62
+ /**
63
+ * Set when the BullMQ job completes successfully. NULL = pending/failed.
64
+ */
65
+ processedAt: Date | null;
66
+ /**
67
+ * Last processing failure reason. Populated on job error; cleared on success.
68
+ */
69
+ error: string | null;
70
+ }
71
+ //# sourceMappingURL=viva-webhook-event.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viva-webhook-event.entity.d.ts","sourceRoot":"","sources":["../../src/entities/viva-webhook-event.entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAcH,yEAAyE;AACzE,qBAEa,gBAAgB;gBACf,KAAK,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAM7C;;;OAGG;IAEH,SAAS,EAAG,MAAM,CAAC;IAEnB;;OAEG;IAEH,WAAW,EAAG,MAAM,CAAC;IAErB;;;OAGG;IAEH,UAAU,EAAG,MAAM,GAAG,IAAI,CAAC;IAE3B;;OAEG;IAEH,aAAa,EAAG,MAAM,GAAG,IAAI,CAAC;IAE9B;;;OAGG;IAEH,SAAS,EAAG,MAAM,GAAG,IAAI,CAAC;IAE1B;;OAEG;IAEH,aAAa,EAAG,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IAEH,UAAU,EAAG,MAAM,CAAC;IAEpB;;;OAGG;IAEH,OAAO,EAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC;;;OAGG;IAEH,UAAU,EAAG,IAAI,CAAC;IAElB;;OAEG;IAEH,WAAW,EAAG,IAAI,GAAG,IAAI,CAAC;IAE1B;;OAEG;IAEH,KAAK,EAAG,MAAM,GAAG,IAAI,CAAC;CACvB"}
@@ -0,0 +1,138 @@
1
+ /**
2
+ * viva-webhook-event.entity.ts — TypeORM entity for incoming Viva Wallet webhook events.
3
+ *
4
+ * @see docs/plans/vendure-plugin-v0.md §"Data Model" lines 148-161
5
+ *
6
+ * Design notes:
7
+ * - `messageId` is the primary key (envelope UUID). NOT auto-generated — Viva
8
+ * supplies it; we use it as the dedupe key (INSERT-OR-IGNORE on conflict).
9
+ * - Does NOT extend VendureEntity — Vendure's base entity adds a generated
10
+ * auto-increment/uuid `id` which conflicts with our natural PK design. We use
11
+ * plain TypeORM `@PrimaryColumn` instead.
12
+ * - Partial index on `(received_at) WHERE processed_at IS NULL` is declared as a
13
+ * standard @Index here for documentation; the WHERE clause requires raw SQL in
14
+ * the migration.
15
+ * - Composite non-unique index on `(merchant_id, event_type_id)` supports
16
+ * efficient A6 NULL-merchant re-walk queries.
17
+ */
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __metadata = (this && this.__metadata) || function (k, v) {
25
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26
+ };
27
+ import { Column, CreateDateColumn, Entity, Index, PrimaryColumn, } from 'typeorm';
28
+ // ---------------------------------------------------------------------------
29
+ // Entity
30
+ // ---------------------------------------------------------------------------
31
+ /** Non-unique composite index for merchant-scoped event type queries. */
32
+ let VivaWebhookEvent = class VivaWebhookEvent {
33
+ constructor(input) {
34
+ if (input) {
35
+ Object.assign(this, input);
36
+ }
37
+ }
38
+ /**
39
+ * Envelope MessageId from Viva. UUIDv4. Natural primary key + dedupe key.
40
+ * INSERT-OR-IGNORE on conflict prevents double-processing.
41
+ */
42
+ messageId;
43
+ /**
44
+ * Viva event type code (1796, 1797, 1798, 4865, 8193, 8194, …).
45
+ */
46
+ eventTypeId;
47
+ /**
48
+ * Viva merchantId UUID from EventData.MerchantId. Nullable — absent for some
49
+ * event types and set to NULL on A6 unresolvable-channel fallback.
50
+ */
51
+ merchantId;
52
+ /**
53
+ * Viva TransactionId from EventData.TransactionId. Applicable to payment events.
54
+ */
55
+ transactionId;
56
+ /**
57
+ * Viva AccountId from EventData.AccountId. Applicable to onboarding events
58
+ * (8193, 8194).
59
+ */
60
+ accountId;
61
+ /**
62
+ * Correlation ID for distributed tracing (if present in event envelope).
63
+ */
64
+ correlationId;
65
+ /**
66
+ * Number of processing attempts. Incremented on each BullMQ retry.
67
+ */
68
+ retryCount;
69
+ /**
70
+ * Raw event payload. Stored as jsonb for querying EventData fields without
71
+ * schema migration.
72
+ */
73
+ payload;
74
+ /**
75
+ * Wall-clock time the POST /viva/webhook request was received.
76
+ * Partial index on this column WHERE processed_at IS NULL — see migration.
77
+ */
78
+ receivedAt;
79
+ /**
80
+ * Set when the BullMQ job completes successfully. NULL = pending/failed.
81
+ */
82
+ processedAt;
83
+ /**
84
+ * Last processing failure reason. Populated on job error; cleared on success.
85
+ */
86
+ error;
87
+ };
88
+ __decorate([
89
+ PrimaryColumn({ type: 'uuid', name: 'message_id' }),
90
+ __metadata("design:type", String)
91
+ ], VivaWebhookEvent.prototype, "messageId", void 0);
92
+ __decorate([
93
+ Column({ type: 'int', name: 'event_type_id' }),
94
+ __metadata("design:type", Number)
95
+ ], VivaWebhookEvent.prototype, "eventTypeId", void 0);
96
+ __decorate([
97
+ Column({ type: 'uuid', nullable: true, name: 'merchant_id' }),
98
+ __metadata("design:type", Object)
99
+ ], VivaWebhookEvent.prototype, "merchantId", void 0);
100
+ __decorate([
101
+ Column({ type: 'varchar', nullable: true, name: 'transaction_id' }),
102
+ __metadata("design:type", Object)
103
+ ], VivaWebhookEvent.prototype, "transactionId", void 0);
104
+ __decorate([
105
+ Column({ type: 'varchar', nullable: true, name: 'account_id' }),
106
+ __metadata("design:type", Object)
107
+ ], VivaWebhookEvent.prototype, "accountId", void 0);
108
+ __decorate([
109
+ Column({ type: 'varchar', nullable: true, name: 'correlation_id' }),
110
+ __metadata("design:type", Object)
111
+ ], VivaWebhookEvent.prototype, "correlationId", void 0);
112
+ __decorate([
113
+ Column({ type: 'int', default: 0, name: 'retry_count' }),
114
+ __metadata("design:type", Number)
115
+ ], VivaWebhookEvent.prototype, "retryCount", void 0);
116
+ __decorate([
117
+ Column({ type: 'jsonb', name: 'payload' }),
118
+ __metadata("design:type", Object)
119
+ ], VivaWebhookEvent.prototype, "payload", void 0);
120
+ __decorate([
121
+ CreateDateColumn({ name: 'received_at', type: 'timestamp with time zone' }),
122
+ __metadata("design:type", Date)
123
+ ], VivaWebhookEvent.prototype, "receivedAt", void 0);
124
+ __decorate([
125
+ Column({ type: 'timestamp with time zone', nullable: true, name: 'processed_at' }),
126
+ __metadata("design:type", Object)
127
+ ], VivaWebhookEvent.prototype, "processedAt", void 0);
128
+ __decorate([
129
+ Column({ type: 'text', nullable: true, name: 'error' }),
130
+ __metadata("design:type", Object)
131
+ ], VivaWebhookEvent.prototype, "error", void 0);
132
+ VivaWebhookEvent = __decorate([
133
+ Index('idx_viva_webhook_event_merchant_type', ['merchantId', 'eventTypeId']),
134
+ Entity('viva_webhook_event'),
135
+ __metadata("design:paramtypes", [Object])
136
+ ], VivaWebhookEvent);
137
+ export { VivaWebhookEvent };
138
+ //# sourceMappingURL=viva-webhook-event.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viva-webhook-event.entity.js","sourceRoot":"","sources":["../../src/entities/viva-webhook-event.entity.ts"],"names":[],"mappings":"AAAA;;;;;;;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,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;;mDACtC;AAM1B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;;uDACtC;AAM9B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;;oDACrC;AAOpB;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;iDACT;AAOlC;IADC,gBAAgB,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC;8BAC/D,IAAI;oDAAC;AAMlB;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;;qDACzD;AAM1B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;+CAClC;AA5EX,gBAAgB;IAF5B,KAAK,CAAC,sCAAsC,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IAC5E,MAAM,CAAC,oBAAoB,CAAC;;GAChB,gBAAgB,CA6E5B"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @sakeetech/vendure-payment-viva
3
+ *
4
+ * Vendure plugin for Viva Wallet (ISV multi-tenant).
5
+ *
6
+ * v0 skeleton — implementation begins in V3 (entities + migrations)
7
+ * through V11 (README + sandbox tests) per docs/plans/vendure-plugin-v0.md.
8
+ *
9
+ * @see docs/plans/vendure-plugin-v0.md
10
+ */
11
+ export { VivaPaymentPlugin } from './plugin.js';
12
+ export { VIVA_PLUGIN_OPTIONS, VIVA_PLUGIN_NAME, DEFAULT_SOURCE_CODE, DEFAULT_ISV_AMOUNT, } from './constants.js';
13
+ export type { VivaPaymentPluginOptions, VendureRequestContext, VendureOrder, RedlockClient, } from './types.js';
14
+ export { VivaTransaction, VivaWebhookEvent } from './entities/index.js';
15
+ export type { VivaTransactionStatus } from './entities/index.js';
16
+ export { VivaOAuth2StrategyProvider, InjectVivaOAuth2Strategy, VIVA_OAUTH2_STRATEGY_TOKEN } from './providers/viva-oauth2-strategy.provider.js';
17
+ export type { VivaOAuth2Strategy } from './providers/viva-oauth2-strategy.provider.js';
18
+ export { VivaBootstrap } from './loaders/bootstrap.js';
19
+ export { vivaPaymentMethodHandler } from './payment-method-handler.js';
20
+ export { StateMachineService } from './services/state-machine.service.js';
21
+ export { VivaPluginError } from './util/error-envelope.js';
22
+ export type { VivaErrorCode } from './util/error-envelope.js';
23
+ export { alphaToNumeric, numericToAlpha, coerceCurrencyCode } from './util/currency.js';
24
+ export { substitute } from './util/url-template.js';
25
+ export { MetricsStateService, ISV_API_DURATION_BUCKETS } from './observability/metrics-state.service.js';
26
+ export { AdminInternalController } from './api/admin-internal.controller.js';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAChJ,YAAY,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @sakeetech/vendure-payment-viva
3
+ *
4
+ * Vendure plugin for Viva Wallet (ISV multi-tenant).
5
+ *
6
+ * v0 skeleton — implementation begins in V3 (entities + migrations)
7
+ * through V11 (README + sandbox tests) per docs/plans/vendure-plugin-v0.md.
8
+ *
9
+ * @see docs/plans/vendure-plugin-v0.md
10
+ */
11
+ export { VivaPaymentPlugin } from './plugin.js';
12
+ export { VIVA_PLUGIN_OPTIONS, VIVA_PLUGIN_NAME, DEFAULT_SOURCE_CODE, DEFAULT_ISV_AMOUNT, } from './constants.js';
13
+ export { VivaTransaction, VivaWebhookEvent } from './entities/index.js';
14
+ export { VivaOAuth2StrategyProvider, InjectVivaOAuth2Strategy, VIVA_OAUTH2_STRATEGY_TOKEN } from './providers/viva-oauth2-strategy.provider.js';
15
+ export { VivaBootstrap } from './loaders/bootstrap.js';
16
+ export { vivaPaymentMethodHandler } from './payment-method-handler.js';
17
+ export { StateMachineService } from './services/state-machine.service.js';
18
+ export { VivaPluginError } from './util/error-envelope.js';
19
+ export { alphaToNumeric, numericToAlpha, coerceCurrencyCode } from './util/currency.js';
20
+ export { substitute } from './util/url-template.js';
21
+ export { MetricsStateService, ISV_API_DURATION_BUCKETS } from './observability/metrics-state.service.js';
22
+ export { AdminInternalController } from './api/admin-internal.controller.js';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAEhJ,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * jobs/process-viva-webhook.handler.ts — BullMQ webhook worker job handler.
3
+ *
4
+ * Registered with Vendure's JobQueueService at bootstrap. Processes one
5
+ * `viva_webhook_event` row per job execution.
6
+ *
7
+ * Process flow (see plan §"Webhook Design — Process flow"):
8
+ * 1. Load row by messageId. Already-processed or missing → no-op.
9
+ * 2. Resolve channel by EventData.MerchantId (60s LRU cache).
10
+ * If not found → A6 NULL-merchant fallback: schedule reprocess with backoff.
11
+ * 3. Acquire per-merchant in-process semaphore (5 permits).
12
+ * 4. Switch on eventTypeId:
13
+ * 1796 → Retrieve-Transaction → validate → settle
14
+ * 1798 → mark Declined, leave order in ArrangingPayment
15
+ * 1797 → audit log only
16
+ * 4865 → optional cancel detection
17
+ * 8193 → log only
18
+ * 8194 → write vivaMerchantId THEN vivaPayoutsEnabled
19
+ * 5. Release semaphore.
20
+ *
21
+ * @see docs/plans/vendure-plugin-v0.md §"Build Plan — V7"
22
+ * @see docs/plans/vendure-plugin-v0.md §"Webhook Design — Process flow"
23
+ * @see docs/VENDURE-CONTRACT.MD §4, §5, §10
24
+ */
25
+ import type { OnApplicationBootstrap } from '@nestjs/common';
26
+ import { JobQueueService, TransactionalConnection, RequestContextService, OrderService, ChannelService, PaymentService } from '@vendure/core';
27
+ import type { VivaPaymentPluginOptions } from '../types.js';
28
+ import type { VivaOAuth2Strategy } from '../providers/viva-oauth2-strategy.provider.js';
29
+ import { StateMachineService } from '../services/state-machine.service.js';
30
+ import { PerMerchantSemaphore } from '../services/per-merchant-semaphore.service.js';
31
+ import { ConnectedAccountsService } from '../services/connected-accounts.service.js';
32
+ import type { ProcessVivaWebhookJobData } from './queue-names.js';
33
+ export declare class ProcessVivaWebhookHandler implements OnApplicationBootstrap {
34
+ private readonly jobQueueService;
35
+ private readonly connection;
36
+ private readonly stateMachine;
37
+ private readonly semaphore;
38
+ private readonly connectedAccounts;
39
+ private readonly orderService;
40
+ private readonly paymentService;
41
+ private readonly channelService;
42
+ private readonly requestContextService;
43
+ private readonly options;
44
+ private readonly oauth2;
45
+ private queue;
46
+ constructor(jobQueueService: JobQueueService, connection: TransactionalConnection, stateMachine: StateMachineService, semaphore: PerMerchantSemaphore, connectedAccounts: ConnectedAccountsService, orderService: OrderService, paymentService: PaymentService, channelService: ChannelService, requestContextService: RequestContextService, options: VivaPaymentPluginOptions, oauth2: VivaOAuth2Strategy);
47
+ onApplicationBootstrap(): Promise<void>;
48
+ /**
49
+ * Enqueue a new webhook processing job.
50
+ * Called by the webhook controller (V6) after INSERT-OR-NOTHING succeeds.
51
+ */
52
+ enqueue(data: ProcessVivaWebhookJobData, delayMs?: number): Promise<void>;
53
+ private _processJob;
54
+ /**
55
+ * 1796 — Transaction Payment Created (settle path).
56
+ *
57
+ * a. Retrieve transaction from Viva.
58
+ * b. Validate orderCode, statusId='F', amount.
59
+ * c. Load order + payment, check current state.
60
+ * d. Settle (or re-walk if AddingItems).
61
+ * e. Update viva_transaction row.
62
+ * f. Mark event processed.
63
+ */
64
+ private _handle1796;
65
+ /**
66
+ * 1798 — Transaction Failed (declined-non-terminal).
67
+ *
68
+ * Mark payment Declined. Leave order in ArrangingPayment (per contract §4).
69
+ * Do NOT auto-rollback to AddingItems — customer retry on same orderCode may succeed.
70
+ */
71
+ private _handle1798;
72
+ /**
73
+ * 4865 — Order Updated (optional cancel detection).
74
+ *
75
+ * If payload indicates a user-initiated cancel (status suggests cancellation),
76
+ * invoke the cancel flow: cancelled status + Payment Cancelled + Order → AddingItems.
77
+ * Otherwise log + no-op.
78
+ */
79
+ private _handle4865;
80
+ /**
81
+ * 8194 — Account Verification Status Changed (THE gating signal).
82
+ *
83
+ * a. Retrieve connected account from Viva to get merchantId.
84
+ * b. Find channel by vivaAccountId.
85
+ * c. WRITE ORDER (mandatory per contract §10):
86
+ * i. Write vivaMerchantId FIRST.
87
+ * ii. Write vivaPayoutsEnabled=true LAST.
88
+ */
89
+ private _handle8194;
90
+ private _markProcessed;
91
+ private _loadChannel;
92
+ private _getIsvPayments;
93
+ private _getIsvAccounts;
94
+ }
95
+ //# sourceMappingURL=process-viva-webhook.handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-viva-webhook.handler.d.ts","sourceRoot":"","sources":["../../src/jobs/process-viva-webhook.handler.ts"],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