cloudcommerce 0.1.0 → 0.1.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 (107) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/ecomplus-stores/monocard/.vscode/settings.json +5 -1
  3. package/ecomplus-stores/monocard/functions/core/package.json +1 -1
  4. package/ecomplus-stores/monocard/functions/events/package.json +2 -2
  5. package/ecomplus-stores/monocard/functions/modules/package.json +2 -2
  6. package/ecomplus-stores/monocard/functions/passport/package.json +2 -2
  7. package/ecomplus-stores/monocard/functions/ssr/package.json +15 -11
  8. package/ecomplus-stores/monocard/functions/ssr/src/pages/_vue.ts +3 -0
  9. package/ecomplus-stores/monocard/package.json +1 -1
  10. package/ecomplus-stores/tia-sonia/.firebaserc +5 -0
  11. package/ecomplus-stores/tia-sonia/.vscode/settings.json +5 -1
  12. package/ecomplus-stores/tia-sonia/functions/config.json +2 -2
  13. package/ecomplus-stores/tia-sonia/functions/core/package.json +1 -1
  14. package/ecomplus-stores/tia-sonia/functions/events/package.json +2 -2
  15. package/ecomplus-stores/tia-sonia/functions/modules/package.json +2 -2
  16. package/ecomplus-stores/tia-sonia/functions/passport/package.json +2 -2
  17. package/ecomplus-stores/tia-sonia/functions/ssr/package.json +15 -7
  18. package/ecomplus-stores/tia-sonia/functions/ssr/src/pages/_vue.ts +3 -0
  19. package/ecomplus-stores/tia-sonia/functions/ssr/src/scripts/InlineScripts.astro +6 -7
  20. package/ecomplus-stores/tia-sonia/package.json +1 -1
  21. package/package.json +1 -1
  22. package/packages/api/package.json +1 -1
  23. package/packages/apps/correios/package.json +1 -1
  24. package/packages/apps/custom-payment/package.json +1 -1
  25. package/packages/apps/custom-shipping/package.json +1 -1
  26. package/packages/apps/discounts/package.json +1 -1
  27. package/packages/apps/emails/package.json +1 -1
  28. package/packages/apps/frenet/package.json +1 -1
  29. package/packages/apps/galaxpay/package.json +1 -1
  30. package/packages/apps/infinitepay/package.json +1 -1
  31. package/packages/apps/jadlog/package.json +1 -1
  32. package/packages/apps/loyalty-points/CHANGELOG.md +1 -0
  33. package/packages/apps/loyalty-points/README.md +1 -0
  34. package/packages/apps/loyalty-points/events.js +1 -0
  35. package/packages/apps/loyalty-points/lib/functions-lib/get-program-id.d.ts +5 -0
  36. package/packages/apps/loyalty-points/lib/functions-lib/get-program-id.js +20 -0
  37. package/packages/apps/loyalty-points/lib/functions-lib/get-program-id.js.map +1 -0
  38. package/packages/apps/loyalty-points/lib/functions-lib/handle-loyalty-points-event.d.ts +3 -0
  39. package/packages/apps/loyalty-points/lib/functions-lib/handle-loyalty-points-event.js +172 -0
  40. package/packages/apps/loyalty-points/lib/functions-lib/handle-loyalty-points-event.js.map +1 -0
  41. package/packages/apps/loyalty-points/lib/index.d.ts +1 -0
  42. package/packages/apps/loyalty-points/lib/index.js +2 -0
  43. package/packages/apps/loyalty-points/lib/index.js.map +1 -0
  44. package/packages/apps/loyalty-points/lib/loyalty-create-transaction.d.ts +76 -0
  45. package/packages/apps/loyalty-points/lib/loyalty-create-transaction.js +210 -0
  46. package/packages/apps/loyalty-points/lib/loyalty-create-transaction.js.map +1 -0
  47. package/packages/apps/loyalty-points/lib/loyalty-list-payments.d.ts +3 -0
  48. package/packages/apps/loyalty-points/lib/loyalty-list-payments.js +44 -0
  49. package/packages/apps/loyalty-points/lib/loyalty-list-payments.js.map +1 -0
  50. package/packages/apps/loyalty-points/lib/loyalty-points-events.d.ts +4 -0
  51. package/packages/apps/loyalty-points/lib/loyalty-points-events.js +28 -0
  52. package/packages/apps/loyalty-points/lib/loyalty-points-events.js.map +1 -0
  53. package/packages/apps/loyalty-points/lib/loyalty-points.d.ts +77 -0
  54. package/packages/apps/loyalty-points/lib/loyalty-points.js +12 -0
  55. package/packages/apps/loyalty-points/lib/loyalty-points.js.map +1 -0
  56. package/packages/apps/loyalty-points/package.json +32 -0
  57. package/packages/apps/loyalty-points/src/functions-lib/get-program-id.ts +23 -0
  58. package/packages/apps/loyalty-points/src/functions-lib/handle-loyalty-points-event.ts +207 -0
  59. package/packages/apps/loyalty-points/src/index.ts +1 -0
  60. package/packages/apps/loyalty-points/src/loyalty-create-transaction.ts +241 -0
  61. package/packages/apps/loyalty-points/src/loyalty-list-payments.ts +55 -0
  62. package/packages/apps/loyalty-points/src/loyalty-points-events.ts +41 -0
  63. package/packages/apps/loyalty-points/src/loyalty-points.ts +12 -0
  64. package/packages/apps/loyalty-points/tsconfig.json +6 -0
  65. package/packages/apps/mercadopago/package.json +1 -1
  66. package/packages/apps/pagarme/package.json +1 -1
  67. package/packages/apps/pix/package.json +1 -1
  68. package/packages/apps/tiny-erp/package.json +1 -1
  69. package/packages/cli/package.json +1 -1
  70. package/packages/config/package.json +1 -1
  71. package/packages/emails/package.json +1 -1
  72. package/packages/events/lib/firebase.js +2 -0
  73. package/packages/events/lib/firebase.js.map +1 -1
  74. package/packages/events/package.json +2 -1
  75. package/packages/events/src/firebase.ts +2 -0
  76. package/packages/firebase/lib/config.d.ts +4 -0
  77. package/packages/firebase/lib/config.js +8 -0
  78. package/packages/firebase/lib/config.js.map +1 -1
  79. package/packages/firebase/package.json +1 -1
  80. package/packages/firebase/src/config.ts +9 -0
  81. package/packages/i18n/package.json +1 -1
  82. package/packages/modules/lib/firebase/call-app-module.js +12 -0
  83. package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
  84. package/packages/modules/package.json +2 -1
  85. package/packages/modules/src/firebase/call-app-module.ts +12 -0
  86. package/packages/passport/package.json +1 -1
  87. package/packages/ssr/package.json +1 -1
  88. package/packages/storefront/dist/client/HeaderButtons.8acf8a3b.js +1 -0
  89. package/packages/storefront/dist/client/Prices.9099fe99.js +1 -0
  90. package/packages/storefront/dist/client/{ProductCard.f477b7a1.js → ProductCard.7b68cc35.js} +1 -1
  91. package/packages/storefront/dist/client/assets/{_...slug_.15766f41.css → _...slug_.f19a16ca.css} +1 -1
  92. package/packages/storefront/dist/client/assets/server.55b8d73d.css +1 -0
  93. package/packages/storefront/dist/client/chunks/{HeaderButtons.27ab2180.js → HeaderButtons.cbbb059d.js} +1 -1
  94. package/packages/storefront/dist/client/chunks/{LoginForm.36774236.js → LoginForm.ac2f1b1f.js} +1 -1
  95. package/packages/storefront/dist/client/chunks/{Prices.vue_vue_type_script_setup_true_lang.522e4ac4.js → Prices.vue_vue_type_script_setup_true_lang.c37148c1.js} +1 -1
  96. package/packages/storefront/dist/client/chunks/{_plugin-vue_export-helper.979dc9e3.js → _plugin-vue_export-helper.5ccc5d75.js} +1 -1
  97. package/packages/storefront/dist/client/chunks/{runtime-core.esm-bundler.6c012e5d.js → runtime-core.esm-bundler.d5646b29.js} +1 -1
  98. package/packages/storefront/dist/client/client.9783ef49.js +1 -0
  99. package/packages/storefront/dist/client/sw.js +1 -1
  100. package/packages/storefront/dist/server/entry.mjs +1544 -28
  101. package/packages/storefront/package.json +1 -1
  102. package/packages/storefront/src/lib/pages/_vue.ts +1 -1
  103. package/packages/types/package.json +1 -1
  104. package/packages/storefront/dist/client/HeaderButtons.f1c92fd8.js +0 -1
  105. package/packages/storefront/dist/client/Prices.795d082c.js +0 -1
  106. package/packages/storefront/dist/client/assets/server.4d9646d8.css +0 -1
  107. package/packages/storefront/dist/client/client.8b4e336b.js +0 -1
@@ -0,0 +1,76 @@
1
+ import type { AppModuleBody } from '@cloudcommerce/types';
2
+ declare const _default: (appData: AppModuleBody) => Promise<{
3
+ status: number;
4
+ redirect_to_payment: boolean;
5
+ transaction: {
6
+ payment_link?: string | undefined;
7
+ payment_instructions?: string | undefined;
8
+ intermediator?: {
9
+ transaction_id?: string | undefined;
10
+ transaction_code?: string | undefined;
11
+ transaction_reference?: string | undefined;
12
+ payment_method?: {
13
+ code: string;
14
+ name?: string | undefined;
15
+ } | undefined;
16
+ buyer_id?: string | undefined;
17
+ } | undefined;
18
+ credit_card?: {
19
+ holder_name?: string | undefined;
20
+ avs_result_code?: string | null | undefined;
21
+ cvv_result_code?: string | null | undefined;
22
+ bin?: number | undefined;
23
+ company?: string | undefined;
24
+ last_digits?: string | undefined;
25
+ token?: string | undefined;
26
+ error_code?: "incorrect_number" | "invalid_number" | "invalid_expiry_date" | "invalid_cvc" | "expired_card" | "incorrect_cvc" | "incorrect_zip" | "incorrect_address" | "card_declined" | "processing_error" | "call_issuer" | "pick_up_card" | undefined;
27
+ } | undefined;
28
+ banking_billet?: {
29
+ code?: string | undefined;
30
+ valid_thru?: string | undefined;
31
+ text_lines?: string[] | undefined;
32
+ link?: string | undefined;
33
+ } | undefined;
34
+ loyalty_points?: {
35
+ name?: string | undefined;
36
+ program_id: string;
37
+ points_value: number;
38
+ ratio?: number | undefined;
39
+ } | undefined;
40
+ currency_id?: string | undefined;
41
+ currency_symbol?: string | undefined;
42
+ discount?: number | undefined;
43
+ amount: number;
44
+ installments?: {
45
+ number: number;
46
+ value?: number | undefined;
47
+ tax?: boolean | undefined;
48
+ total?: number | undefined;
49
+ } | undefined;
50
+ creditor_fees?: {
51
+ installment?: number | undefined;
52
+ operational?: number | undefined;
53
+ intermediation?: number | undefined;
54
+ other?: number | undefined;
55
+ } | undefined;
56
+ status?: {
57
+ updated_at?: string | undefined;
58
+ current: "authorized" | "unauthorized" | "pending" | "under_analysis" | "paid" | "in_dispute" | "refunded" | "voided" | "unknown";
59
+ } | undefined;
60
+ flags?: string[] | undefined;
61
+ custom_fields?: {
62
+ field: string;
63
+ value: string;
64
+ }[] | undefined;
65
+ notes?: string | undefined;
66
+ };
67
+ error?: undefined;
68
+ message?: undefined;
69
+ } | {
70
+ error: string;
71
+ message: any;
72
+ status?: undefined;
73
+ redirect_to_payment?: undefined;
74
+ transaction?: undefined;
75
+ }>;
76
+ export default _default;
@@ -0,0 +1,210 @@
1
+ import api from '@cloudcommerce/api';
2
+ import { getFirestore } from 'firebase-admin/firestore';
3
+ import logger from 'firebase-functions/logger';
4
+ import getProgramId from './functions-lib/get-program-id.js';
5
+
6
+ const collectionRef = getFirestore().collection('billedPoints');
7
+ const updateTransactionStatus = (orderId) => {
8
+ setTimeout(async () => {
9
+ const order = (await api.get(`orders/${orderId}`)).data;
10
+ // appSdk.apiRequest(storeId, `/orders/${orderId}.json`).then(({ response }) => {
11
+ const { transactions } = order;
12
+ if (transactions) {
13
+ const transaction = transactions.find((transactionFound) => {
14
+ return transactionFound.payment_method.code === 'loyalty_points';
15
+ });
16
+ if (transaction) {
17
+ const bodyPaymentHistory = {
18
+ transaction_id: transaction._id,
19
+ date_time: new Date().toISOString(),
20
+ status: 'paid',
21
+ customer_notified: true,
22
+ }; // TODO: incompatible type=> amount and status;
23
+ await api.post(`orders/${orderId}/payments_history`, bodyPaymentHistory);
24
+ }
25
+ }
26
+ }, 500);
27
+ };
28
+ const handleUpdatedPoints = (
29
+ endpoint, // TODO: endpoint type not string compatible
30
+ body,
31
+ orderId,
32
+ usedPointsEntries,
33
+ timeout = 400,
34
+ isLastRequest = false,
35
+ ) => {
36
+ setTimeout(async () => {
37
+ await api.patch(endpoint, body);
38
+ // appSdk.apiRequest(storeId, endpoint, 'PATCH', data).then(() => {
39
+ logger.log(`#(App Loyalty Points): ${orderId} ${endpoint} => ${JSON.stringify(body)}`);
40
+ if (isLastRequest) {
41
+ updateTransactionStatus(orderId);
42
+ collectionRef.doc(orderId).set({ usedPointsEntries });
43
+ }
44
+ // });
45
+ }, timeout);
46
+ };
47
+
48
+ export default async (appData) => {
49
+ const { application, storeId } = appData;
50
+ const { params } = appData;
51
+ // app configured options
52
+ const appConfig = { ...application.data, ...application.hidden_data };
53
+ const { lang, amount } = params;
54
+ // setup required `transaction` response object
55
+ const transaction = {
56
+ amount: amount.total,
57
+ };
58
+ if (params.payment_method.code === 'loyalty_points') {
59
+ const pointsApplied = params.loyalty_points_applied;
60
+ const programsRules = appConfig.programs_rules;
61
+ if (pointsApplied && Array.isArray(programsRules) && programsRules.length) {
62
+ // for (const programId in pointsApplied) {
63
+ Object.keys(pointsApplied).forEach((programId) => {
64
+ const pointsValue = pointsApplied[programId];
65
+ if (pointsValue > 0) {
66
+ const programRule = programsRules.find((programRuleFound, index) => {
67
+ if (programRuleFound) {
68
+ programRuleFound.program_id = getProgramId(programRuleFound, index);
69
+ return programId === programRuleFound.program_id;
70
+ }
71
+ return false;
72
+ });
73
+ if (programRule) {
74
+ const ratio = programRule.ratio || 1;
75
+ transaction.loyalty_points = {
76
+ name: programRule.name,
77
+ program_id: programRule.program_id,
78
+ ratio,
79
+ points_value: programRule.max_points < pointsValue
80
+ ? programRule.max_points
81
+ : pointsValue,
82
+ };
83
+ transaction.amount = pointsValue * ratio;
84
+ }
85
+ }
86
+ });
87
+ }
88
+ }
89
+ if (transaction.amount) {
90
+ const loyaltyPoints = transaction.loyalty_points;
91
+ const customerId = params.buyer.customer_id;
92
+ const orderId = params.order_id;
93
+ const usedPointsEntries = [];
94
+ try {
95
+ const customer = (await api.get(`customers/${customerId}`)).data;
96
+ // return appSdk.apiRequest(storeId, `/customers/${customerId}.json`)
97
+ // .then(({ response }) => {
98
+ const pointsEntries = customer.loyalty_points_entries;
99
+ let pointsToConsume = loyaltyPoints?.points_value;
100
+ if (pointsEntries && pointsToConsume) {
101
+ pointsEntries.sort((a, b) => {
102
+ let value = 0;
103
+ if (a.valid_thru && b.valid_thru) {
104
+ if (a.valid_thru < b.valid_thru) {
105
+ value = -1;
106
+ } else if (a.valid_thru > b.valid_thru) {
107
+ value = 1;
108
+ }
109
+ }
110
+ return value;
111
+ });
112
+ for (let i = 0; i < pointsEntries.length; i++) {
113
+ if (pointsToConsume <= 0) {
114
+ break;
115
+ }
116
+ const pointsEntry = pointsEntries[i];
117
+ if (pointsEntry.program_id === loyaltyPoints?.program_id) {
118
+ const validThru = pointsEntry.valid_thru;
119
+ const activePoints = pointsEntry.active_points;
120
+ if (activePoints > 0 && (!validThru || new Date(validThru).getTime() >= Date.now())) {
121
+ const pointsDiff = activePoints - pointsToConsume;
122
+ if (pointsDiff > 0 && pointsDiff < 0.01) {
123
+ pointsToConsume = activePoints;
124
+ }
125
+ if (pointsToConsume >= activePoints) {
126
+ pointsToConsume -= activePoints;
127
+ pointsEntry.active_points = 0;
128
+ if (pointsToConsume < 0.02) {
129
+ pointsToConsume = 0;
130
+ }
131
+ } else {
132
+ pointsEntry.active_points -= pointsToConsume;
133
+ pointsToConsume = 0;
134
+ }
135
+ usedPointsEntries.push({
136
+ ...pointsEntry,
137
+ original_active_points: activePoints,
138
+ });
139
+ }
140
+ }
141
+ }
142
+ if (pointsToConsume <= 0) {
143
+ if (usedPointsEntries.length <= 3) {
144
+ usedPointsEntries.forEach((pointsEntry, i) => {
145
+ /* Obs:
146
+ Store api v2 => loyalty_points_entries do not have id,
147
+ but change can be done by index
148
+ */
149
+ const endpoint = `customers/${customerId}/loyalty_points_entries/${i}`;
150
+ const body = {
151
+ active_points: pointsEntry.active_points,
152
+ };
153
+ handleUpdatedPoints(endpoint, body, orderId, usedPointsEntries, (i + 1) * 400, i + 1 === usedPointsEntries.length);
154
+ });
155
+ } else {
156
+ const endpoint = `customers/${customerId}`;
157
+ const body = {
158
+ loyalty_points_entries: pointsEntries,
159
+ };
160
+ handleUpdatedPoints(endpoint, body, orderId, usedPointsEntries, 400, true);
161
+ }
162
+ }
163
+ }
164
+ transaction.status = {
165
+ current: pointsToConsume && pointsToConsume <= 0 ? 'authorized' : 'unauthorized',
166
+ };
167
+ return {
168
+ status: 200,
169
+ redirect_to_payment: false,
170
+ transaction,
171
+ };
172
+ } catch (error) {
173
+ // try to debug request error
174
+ const errCode = 'POINTS_TRANSACTION_ERR';
175
+ let { message } = error;
176
+ const err = {
177
+ message: `CREATE_TRANSACTION_ERR #${storeId} - ${orderId} => ${message}`,
178
+ payment: '',
179
+ status: 0,
180
+ response: '',
181
+ usedPointsEntries,
182
+ };
183
+ if (error.response) {
184
+ const { status, data } = error.response;
185
+ err.status = status;
186
+ if (status !== 401 && status !== 403) {
187
+ if (typeof data === 'object' && data) {
188
+ err.response = JSON.stringify(data);
189
+ } else {
190
+ err.response = data;
191
+ }
192
+ }
193
+ if (data && data.user_message) {
194
+ message = lang ? data.user_message[lang] : data.user_message.en_us;
195
+ }
196
+ }
197
+ logger.error(err);
198
+ return {
199
+ error: errCode,
200
+ message,
201
+ };
202
+ }
203
+ }
204
+ return {
205
+ status: 200,
206
+ redirect_to_payment: false,
207
+ transaction,
208
+ };
209
+ };
210
+ // # sourceMappingURL=loyalty-create-transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loyalty-create-transaction.js","sourceRoot":"","sources":["../src/loyalty-create-transaction.ts"],"names":[],"mappings":"AAMA,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAK1D,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AAEhE,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,EAAE;IAClD,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAExD,iFAAiF;QACjF,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;QAC/B,IAAI,YAAY,EAAE;YAChB,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE;gBACzD,OAAO,gBAAgB,CAAC,cAAc,CAAC,IAAI,KAAK,gBAAgB,CAAC;YACnE,CAAC,CAAC,CAAC;YACH,IAAI,WAAW,EAAE;gBACf,MAAM,kBAAkB,GAAG;oBACzB,cAAc,EAAE,WAAW,CAAC,GAAG;oBAC/B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACnC,MAAM,EAAE,MAAM;oBACd,iBAAiB,EAAE,IAAI;iBACjB,CAAC,CAAC,+CAA+C;gBACzD,MA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AAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;iBACpE;aACF;YAED,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAElB,OAAO;gBACL,KAAK,EAAE,OAAO;gBACd,OAAO;aACR,CAAC;SACH;KACF;IAED,OAAO;QACL,MAAM,EAAE,GAAG;QACX,mBAAmB,EAAE,KAAK;QAC1B,WAAW;KACZ,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AppModuleBody, ListPaymentsResponse } from '@cloudcommerce/types';
2
+ declare const _default: (data: AppModuleBody) => ListPaymentsResponse;
3
+ export default _default;
@@ -0,0 +1,44 @@
1
+ import getProgramId from './functions-lib/get-program-id.js';
2
+
3
+ export default (data) => {
4
+ const { application } = data;
5
+ const { params } = data;
6
+ const appData = {
7
+ ...application.data,
8
+ ...application.hidden_data,
9
+ };
10
+ // const { storeId } = req
11
+ // setup basic required response object
12
+ const response = {
13
+ payment_gateways: [],
14
+ };
15
+ const label = params.lang === 'pt_br' || !params.lang
16
+ ? 'Pontos de fidelidade'
17
+ : 'Loyalty points';
18
+ response.payment_gateways.push({
19
+ type: 'payment',
20
+ payment_method: {
21
+ code: 'loyalty_points',
22
+ name: label,
23
+ },
24
+ label,
25
+ });
26
+ if (Array.isArray(appData.programs_rules)) {
27
+ const pointsPrograms = {};
28
+ appData.programs_rules.forEach((programRule, index) => {
29
+ const programId = getProgramId(programRule, index);
30
+ pointsPrograms[programId] = {
31
+ name: programRule.name,
32
+ ratio: programRule.ratio || 1,
33
+ max_points: programRule.max_points,
34
+ min_subtotal_to_earn: programRule.min_subtotal_to_earn,
35
+ earn_percentage: programRule.earn_percentage,
36
+ };
37
+ });
38
+ if (Object.keys(pointsPrograms).length) {
39
+ response.loyalty_points_programs = pointsPrograms;
40
+ }
41
+ }
42
+ return response;
43
+ };
44
+ // # sourceMappingURL=loyalty-list-payments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loyalty-list-payments.js","sourceRoot":"","sources":["../src/loyalty-list-payments.ts"],"names":[],"mappings":"AAKA,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAE1D,eAAe,CAAC,IAAmB,EAAE,EAAE;IACrC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAC;IAEjD,MAAM,OAAO,GAAG;QACd,GAAG,WAAW,CAAC,IAAI;QACnB,GAAG,WAAW,CAAC,WAAW;KAC3B,CAAC;IAEF,0BAA0B;IAC1B,uCAAuC;IACvC,MAAM,QAAQ,GAAyB;QACrC,gBAAgB,EAAE,EAAE;KACrB,CAAC;IAEF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;QACnD,CAAC,CAAC,sBAAsB;QACxB,CAAC,CAAC,gBAAgB,CAAC;IAErB,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC;QAC7B,IAAI,EAAE,SAAS;QACf,cAAc,EAAE;YACd,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,KAAK;SACZ;QACD,KAAK;KACN,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QACzC,MAAM,cAAc,GAAG,EAAE,CAAC;QAC1B,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;YACpD,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YACnD,cAAc,CAAC,SAAS,CAAC,GAAG;gBAC1B,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC;gBAC7B,UAAU,EAAE,WAAW,CAAC,UAAU;gBAClC,oBAAoB,EAAE,WAAW,CAAC,oBAAoB;gBACtD,eAAe,EAAE,WAAW,CAAC,eAAe;aAC7C,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE;YACtC,QAAQ,CAAC,uBAAuB,GAAG,cAAc,CAAC;SACnD;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import '@cloudcommerce/firebase/lib/init';
2
+ export declare const loyaltypoints: {
3
+ onStoreEvent: any;
4
+ };
@@ -0,0 +1,28 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import '@cloudcommerce/firebase/lib/init';
3
+ import { createAppEventsFunction } from '@cloudcommerce/firebase/lib/helpers/pubsub';
4
+ import logger from 'firebase-functions/logger';
5
+ import handleLoyaltyPointsEvent from './functions-lib/handle-loyalty-points-event.js';
6
+
7
+ const handleApiEvent = async ({
8
+ evName, apiEvent, apiDoc, app,
9
+ }) => {
10
+ const resourceId = apiEvent.resource_id;
11
+ logger.info('>> ', resourceId, ' - Action: ', apiEvent.action);
12
+ const key = `${evName}_${resourceId}`;
13
+ const appData = { ...app.data, ...app.hidden_data };
14
+ const programRules = appData.programs_rules;
15
+ if ((Array.isArray(appData.ignore_events)
16
+ && appData.ignore_events.includes(evName))
17
+ || (!Array.isArray(programRules) || !programRules.length)) {
18
+ logger.info('>> ', key, ' - Ignored event');
19
+ return null;
20
+ }
21
+ logger.info(`> Webhook ${resourceId} [${evName}]`);
22
+ return handleLoyaltyPointsEvent(apiDoc, programRules);
23
+ };
24
+
25
+ export const loyaltypoints = {
26
+ onStoreEvent: createAppEventsFunction('loyaltyPoints', handleApiEvent),
27
+ };
28
+ // # sourceMappingURL=loyalty-points-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loyalty-points-events.js","sourceRoot":"","sources":["../src/loyalty-points-events.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO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
2
+ import type { AppModuleBody } from '@cloudcommerce/types';
3
+ export declare const listPayments: (modBody: AppModuleBody) => Promise<import("@cloudcommerce/types").ListPaymentsResponse>;
4
+ export declare const createTransaction: (modBody: AppModuleBody) => Promise<{
5
+ status: number;
6
+ redirect_to_payment: boolean;
7
+ transaction: {
8
+ payment_link?: string | undefined;
9
+ payment_instructions?: string | undefined;
10
+ intermediator?: {
11
+ transaction_id?: string | undefined;
12
+ transaction_code?: string | undefined;
13
+ transaction_reference?: string | undefined;
14
+ payment_method?: {
15
+ code: string;
16
+ name?: string | undefined;
17
+ } | undefined;
18
+ buyer_id?: string | undefined;
19
+ } | undefined;
20
+ credit_card?: {
21
+ holder_name?: string | undefined;
22
+ avs_result_code?: string | null | undefined;
23
+ cvv_result_code?: string | null | undefined;
24
+ bin?: number | undefined;
25
+ company?: string | undefined;
26
+ last_digits?: string | undefined;
27
+ token?: string | undefined;
28
+ error_code?: "incorrect_number" | "invalid_number" | "invalid_expiry_date" | "invalid_cvc" | "expired_card" | "incorrect_cvc" | "incorrect_zip" | "incorrect_address" | "card_declined" | "processing_error" | "call_issuer" | "pick_up_card" | undefined;
29
+ } | undefined;
30
+ banking_billet?: {
31
+ code?: string | undefined;
32
+ valid_thru?: string | undefined;
33
+ text_lines?: string[] | undefined;
34
+ link?: string | undefined;
35
+ } | undefined;
36
+ loyalty_points?: {
37
+ name?: string | undefined;
38
+ program_id: string;
39
+ points_value: number;
40
+ ratio?: number | undefined;
41
+ } | undefined;
42
+ currency_id?: string | undefined;
43
+ currency_symbol?: string | undefined;
44
+ discount?: number | undefined;
45
+ amount: number;
46
+ installments?: {
47
+ number: number;
48
+ value?: number | undefined;
49
+ tax?: boolean | undefined;
50
+ total?: number | undefined;
51
+ } | undefined;
52
+ creditor_fees?: {
53
+ installment?: number | undefined;
54
+ operational?: number | undefined;
55
+ intermediation?: number | undefined;
56
+ other?: number | undefined;
57
+ } | undefined;
58
+ status?: {
59
+ updated_at?: string | undefined;
60
+ current: "authorized" | "unauthorized" | "pending" | "under_analysis" | "paid" | "in_dispute" | "refunded" | "voided" | "unknown";
61
+ } | undefined;
62
+ flags?: string[] | undefined;
63
+ custom_fields?: {
64
+ field: string;
65
+ value: string;
66
+ }[] | undefined;
67
+ notes?: string | undefined;
68
+ };
69
+ error?: undefined;
70
+ message?: undefined;
71
+ } | {
72
+ error: string;
73
+ message: any;
74
+ status?: undefined;
75
+ redirect_to_payment?: undefined;
76
+ transaction?: undefined;
77
+ }>;
@@ -0,0 +1,12 @@
1
+ import '@cloudcommerce/firebase/lib/init';
2
+ import handleListPayments from './loyalty-list-payments.js';
3
+ import handleCreateTransaction from './loyalty-create-transaction.js';
4
+
5
+ export const listPayments = async (modBody) => {
6
+ return handleListPayments(modBody);
7
+ };
8
+
9
+ export const createTransaction = async (modBody) => {
10
+ return handleCreateTransaction(modBody);
11
+ };
12
+ // # sourceMappingURL=loyalty-points.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loyalty-points.js","sourceRoot":"","sources":["../src/loyalty-points.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAC3D,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAChE,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@cloudcommerce/app-loyalty-points",
3
+ "type": "module",
4
+ "version": "0.1.1",
5
+ "description": "E-Com Plus Cloud Commerce app to handle simple loyalty points programs",
6
+ "main": "lib/loyalty-points.js",
7
+ "exports": {
8
+ ".": "./lib/loyalty-points.js",
9
+ "./events": "./lib/loyalty-points-events.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ecomplus/cloud-commerce.git",
14
+ "directory": "packages/loyalty-points"
15
+ },
16
+ "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
+ "license": "Apache 2.0 with Commons Clause",
18
+ "bugs": {
19
+ "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
+ },
21
+ "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/loyalty-points#readme",
22
+ "scripts": {
23
+ "build": "sh ../../../scripts/build-lib.sh"
24
+ },
25
+ "dependencies": {
26
+ "@cloudcommerce/api": "workspace:*",
27
+ "@cloudcommerce/firebase": "workspace:*"
28
+ },
29
+ "devDependencies": {
30
+ "@cloudcommerce/types": "workspace:*"
31
+ }
32
+ }
@@ -0,0 +1,23 @@
1
+ export default (
2
+ programRule: { program_id: string; name: string; },
3
+ index: number,
4
+ ) => {
5
+ let programId = `lpt__${index}`;
6
+ if (programRule.program_id) {
7
+ programId = programRule.program_id;
8
+ } else if (programRule.name && typeof programRule.name === 'string') {
9
+ programId = (`p0_${programRule.name.toLowerCase()}`)
10
+ .replace(/\n\s/g, '_')
11
+ .replace(/__/g, '_')
12
+ .replace(/áàãâ/g, 'a')
13
+ .replace(/éê/g, 'e')
14
+ .replace(/óõô/g, 'o')
15
+ .replace(/í/g, 'e')
16
+ .replace(/ú/g, 'u')
17
+ .replace(/ç/g, 'c')
18
+ .replace(/[^a-z0-9_]/g, '')
19
+ .substring(0, 30);
20
+ }
21
+
22
+ return programId;
23
+ };