@saasquatch/vanilla-components 1.2.4-2 → 1.2.4-20

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 (112) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/{WidgetHost-71b013eb.js → WidgetHost-cee741d8.js} +772 -615
  3. package/dist/cjs/{en-a49a5ef5.js → en-3a7cb52e.js} +2 -2
  4. package/dist/cjs/{index-deb40352.js → index-09a04159.js} +54 -3
  5. package/dist/cjs/loader.cjs.js +3 -3
  6. package/dist/cjs/sqh-close-button.cjs.entry.js +26 -26
  7. package/dist/cjs/{sqh-copy-button_12.cjs.entry.js → sqh-copy-button_14.cjs.entry.js} +2362 -1121
  8. package/dist/cjs/sqh-referral-code.cjs.entry.js +23 -23
  9. package/dist/cjs/sqh-rewards-actions.cjs.entry.js +27 -27
  10. package/dist/cjs/widget-components.cjs.js +3 -3
  11. package/dist/collection/collection-manifest.json +2 -0
  12. package/dist/collection/components/close-button/close-button.js +70 -70
  13. package/dist/collection/components/copy-button/copy-button.js +380 -389
  14. package/dist/collection/components/copy-link-button/copy-link-button.js +230 -233
  15. package/dist/collection/components/cta-component/cta-component.css +6 -0
  16. package/dist/collection/components/cta-component/cta-component.js +396 -0
  17. package/dist/collection/components/global-container/global-container.js +158 -170
  18. package/dist/collection/components/image-component/image-component.js +175 -175
  19. package/dist/collection/components/partner-stat-component/partner-stat-component.js +196 -186
  20. package/dist/collection/components/progress-indicator/progress-indicator.css +73 -0
  21. package/dist/collection/components/progress-indicator/progress-indicator.js +557 -0
  22. package/dist/collection/components/referral-code/referral-code.js +36 -34
  23. package/dist/collection/components/referral-component/referral-component.js +255 -255
  24. package/dist/collection/components/referral-list/referral-list.js +911 -930
  25. package/dist/collection/components/rewards-actions/rewards-actions.js +105 -105
  26. package/dist/collection/components/share-button/share-button.js +301 -310
  27. package/dist/collection/components/share-button-container/share-button-container.js +2384 -2470
  28. package/dist/collection/components/stat-component/stat-component.js +197 -186
  29. package/dist/collection/components/stats-container/stats-container.js +210 -205
  30. package/dist/collection/components/text-component/text-component.js +301 -280
  31. package/dist/collection/global/global.js +4 -4
  32. package/dist/collection/services/FormatJs.js +15 -15
  33. package/dist/collection/services/WidgetHost.js +778 -621
  34. package/dist/collection/utilities.js +81 -81
  35. package/dist/esm/{WidgetHost-9c337319.js → WidgetHost-6cd6c29a.js} +772 -615
  36. package/dist/esm/{en-be593af0.js → en-a652ab83.js} +1 -1
  37. package/dist/esm/{index-8ea8b6d8.js → index-342d7c26.js} +54 -3
  38. package/dist/esm/loader.mjs +3 -3
  39. package/dist/esm/polyfills/core-js.js +0 -0
  40. package/dist/esm/polyfills/dom.js +0 -0
  41. package/dist/esm/polyfills/es5-html-element.js +0 -0
  42. package/dist/esm/polyfills/index.js +0 -0
  43. package/dist/esm/polyfills/system.js +0 -0
  44. package/dist/esm/sqh-close-button.entry.js +26 -26
  45. package/dist/esm/{sqh-copy-button_12.entry.js → sqh-copy-button_14.entry.js} +2361 -1122
  46. package/dist/esm/sqh-referral-code.entry.js +23 -23
  47. package/dist/esm/sqh-rewards-actions.entry.js +27 -27
  48. package/dist/esm/widget-components.mjs +3 -3
  49. package/dist/esm-es5/{WidgetHost-9c337319.js → WidgetHost-6cd6c29a.js} +9524 -9432
  50. package/dist/esm-es5/_commonjsHelpers-1d681858.js +17 -17
  51. package/dist/esm-es5/css-shim-a659079f.js +122 -122
  52. package/dist/esm-es5/dom-4061ceba.js +468 -468
  53. package/dist/esm-es5/{en-be593af0.js → en-a652ab83.js} +1471 -1471
  54. package/dist/esm-es5/{index-8ea8b6d8.js → index-342d7c26.js} +1808 -1758
  55. package/dist/esm-es5/loader.mjs +11 -11
  56. package/dist/esm-es5/sqh-close-button.entry.js +35 -35
  57. package/dist/esm-es5/{sqh-copy-button_12.entry.js → sqh-copy-button_14.entry.js} +10677 -9571
  58. package/dist/esm-es5/sqh-referral-code.entry.js +29 -29
  59. package/dist/esm-es5/sqh-rewards-actions.entry.js +31 -31
  60. package/dist/esm-es5/widget-components.mjs +6 -6
  61. package/dist/types/components/close-button/close-button.d.ts +18 -18
  62. package/dist/types/components/copy-button/copy-button.d.ts +90 -107
  63. package/dist/types/components/copy-link-button/copy-link-button.d.ts +53 -62
  64. package/dist/types/components/cta-component/cta-component.d.ts +95 -0
  65. package/dist/types/components/global-container/global-container.d.ts +39 -47
  66. package/dist/types/components/image-component/image-component.d.ts +45 -51
  67. package/dist/types/components/partner-stat-component/partner-stat-component.d.ts +51 -49
  68. package/dist/types/components/progress-indicator/progress-indicator.d.ts +94 -0
  69. package/dist/types/components/referral-code/referral-code.d.ts +12 -10
  70. package/dist/types/components/referral-component/referral-component.d.ts +46 -46
  71. package/dist/types/components/referral-list/referral-list.d.ts +234 -249
  72. package/dist/types/components/rewards-actions/rewards-actions.d.ts +25 -25
  73. package/dist/types/components/share-button/share-button.d.ts +77 -82
  74. package/dist/types/components/share-button-container/share-button-container.d.ts +593 -684
  75. package/dist/types/components/stat-component/stat-component.d.ts +49 -48
  76. package/dist/types/components/stats-container/stats-container.d.ts +47 -45
  77. package/dist/types/components/text-component/text-component.d.ts +73 -81
  78. package/dist/types/components.d.ts +646 -548
  79. package/dist/types/global/global.d.ts +4 -4
  80. package/dist/types/saasquatch.d.ts +105 -103
  81. package/dist/types/services/FormatJs.d.ts +7 -7
  82. package/dist/types/services/WidgetHost.d.ts +51 -45
  83. package/dist/types/utilities.d.ts +7 -7
  84. package/dist/widget-components/{p-44a6559d.js → p-17d80384.js} +1 -1
  85. package/dist/widget-components/{p-54ea7a00.entry.js → p-1dfd20e2.entry.js} +1 -1
  86. package/dist/widget-components/p-24fc4ba9.js +1 -1
  87. package/dist/widget-components/p-46109683.js +3 -3
  88. package/dist/widget-components/{p-edd43dbc.js → p-4b1ab75c.js} +68 -3
  89. package/dist/widget-components/{p-b17efca4.system.entry.js → p-599e6d35.system.entry.js} +1 -1
  90. package/dist/widget-components/{p-e2b4739f.system.entry.js → p-665b8d42.system.entry.js} +1 -1
  91. package/dist/widget-components/p-9fcf9906.entry.js +233 -0
  92. package/dist/widget-components/{p-366f1663.entry.js → p-9ffe6e46.entry.js} +1 -1
  93. package/dist/widget-components/{p-a846f503.system.js → p-aaf44379.system.js} +1 -1
  94. package/dist/widget-components/p-ad5121cf.system.js +1 -0
  95. package/dist/widget-components/{p-8e232564.system.js → p-b67d3319.system.js} +2 -2
  96. package/dist/widget-components/p-cdc72d95.system.entry.js +10 -0
  97. package/dist/widget-components/{p-58be1132.system.js → p-e82def83.system.js} +1 -1
  98. package/dist/widget-components/p-eeb2bfd4.system.entry.js +1 -0
  99. package/dist/widget-components/{p-9746ae26.entry.js → p-fb528be6.entry.js} +1 -1
  100. package/dist/widget-components/p-fbf0c7fe.js +1 -0
  101. package/dist/widget-components/widget-components.esm.js +1 -1
  102. package/dist/widget-components/widget-components.js +1 -1
  103. package/docs/raisins.json +1 -1
  104. package/package.json +98 -96
  105. package/readme.md +52 -52
  106. package/dist/collection/entrypoint.js +0 -32
  107. package/dist/widget-components/entrypoint.js +0 -32
  108. package/dist/widget-components/p-485eaf44.js +0 -1
  109. package/dist/widget-components/p-c8bc8c77.system.entry.js +0 -1
  110. package/dist/widget-components/p-d416634a.entry.js +0 -148
  111. package/dist/widget-components/p-d97c955d.system.entry.js +0 -8
  112. package/dist/widget-components/p-e61a8100.system.js +0 -1
@@ -1,621 +1,778 @@
1
- import { ApolloClient } from "apollo-client";
2
- import { HttpLink } from "apollo-link-http";
3
- import { InMemoryCache } from "apollo-cache-inmemory";
4
- import gql from "graphql-tag";
5
- if (!window["widgetIdent"]) {
6
- window["widgetIdent"] = {
7
- env: "demo",
8
- };
9
- }
10
- export function widgetIdent() {
11
- //@ts-ignore
12
- return window.widgetIdent;
13
- }
14
- const today = new Date();
15
- const demoUser = {
16
- shareLink: "http://ssqt.co",
17
- fueltankCode: "12AS3F",
18
- referralcode: "RIDDIKULUS",
19
- locale: "en_US",
20
- messageLink: {
21
- EMAIL: "http://short.staging.referralsaasquatch.com/mJjFXu",
22
- FACEBOOK: "http://short.staging.referralsaasquatch.com/mwjFXu",
23
- TWITTER: "http://short.staging.referralsaasquatch.com/mwjFXu",
24
- SMS: "http://short.staging.referralsaasquatch.com/mwjFXu",
25
- WHATSAPP: "http://short.staging.referralsaasquatch.com/mwjFXu",
26
- LINKEDIN: "http://short.staging.referralsaasquatch.com/mwjFXu",
27
- PINTEREST: "http://short.staging.referralsaasquatch.com/mwjFXu",
28
- FBMESSENGER: "http://short.staging.referralsaasquatch.com/mwjFXu",
29
- },
30
- referrals: {
31
- totalCount: 9,
32
- data: [
33
- {
34
- dateReferralStarted: today.setDate(today.getDate() - 2),
35
- referredUser: { firstName: "Remus", lastName: "Lupin" },
36
- rewards: [
37
- {
38
- prettyValue: "$20.00",
39
- dateExpires: today.setDate(today.getDate() + 4),
40
- statuses: ["EXPIRED"],
41
- meta: { message: "Applied to Invoice #1234" },
42
- },
43
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
44
- { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
45
- ],
46
- },
47
- {
48
- dateReferralStarted: today.setDate(today.getDate() - 1),
49
- referredUser: { firstName: "Gellert", lastName: "Grindelwald" },
50
- rewards: [],
51
- },
52
- // Blank string becomes an unknown user, which is editable
53
- {
54
- dateReferralStarted: today.setDate(today.getDate() - 1),
55
- referredUser: { firstName: "", lastName: "" },
56
- rewards: [
57
- {
58
- prettyValue: "$20.00",
59
- dateExpires: today.setDate(today.getDate() - 2),
60
- statuses: ["EXPIRED"],
61
- },
62
- ],
63
- },
64
- {
65
- dateReferralStarted: today.setDate(today.getDate() - 5),
66
- referredUser: { firstName: "Lavender", lastName: "Brown" },
67
- rewards: [{ prettyValue: "$20.00", statuses: ["CANCELLED"] }],
68
- },
69
- {
70
- dateReferralStarted: today.setDate(today.getDate() - 4),
71
- referredUser: { firstName: "Blaise", lastName: "Zabini" },
72
- rewards: [
73
- { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
74
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
75
- ],
76
- },
77
- {
78
- dateReferralStarted: today.setDate(today.getDate() - 10),
79
- referredUser: { firstName: "Argus", lastName: "Filch" },
80
- rewards: [],
81
- },
82
- {
83
- dateReferralStarted: today.setDate(today.getDate() - 15),
84
- referredUser: { firstName: "Ron", lastName: "Weasley" },
85
- rewards: [{ prettyValue: "$20.00", statuses: ["AVAILABLE"] }],
86
- },
87
- {
88
- dateReferralStarted: today.setDate(today.getDate() - 2),
89
- referredUser: { firstName: "Hermione", lastName: "Granger" },
90
- rewards: [
91
- { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
92
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
93
- { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
94
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
95
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
96
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
97
- ],
98
- },
99
- {
100
- dateConverted: 1606943971468,
101
- dateReferralStarted: 1606943971468,
102
- referredUser: {
103
- imageUrl: "",
104
- firstName: "Seamus",
105
- lastName: "Finnigan",
106
- },
107
- rewards: [],
108
- },
109
- ],
110
- },
111
- referredByReferral: {
112
- dateReferralStarted: today.setDate(today.getDate() - 2),
113
- referrerUser: {
114
- firstName: "Rubeus",
115
- lastName: "Hagrid",
116
- referralCode: "RUBEUSHAGRID12",
117
- },
118
- rewards: [
119
- {
120
- fuelTankCode: "CODE1234",
121
- prettyValue: "$10.00",
122
- statuses: ["AVAILABLE"],
123
- },
124
- ],
125
- },
126
- referralsMonth: { totalCount: 6 },
127
- referralsWeek: { totalCount: 3 },
128
- rewardsCount: { totalCount: 14 },
129
- rewardsMonth: { totalCount: 7 },
130
- rewardsWeek: { totalCount: 4 },
131
- rewardBalancesGlobal: [
132
- {
133
- type: "CREDIT",
134
- unit: "CENTS",
135
- value: 17000,
136
- prettyValue: "$170.00",
137
- totalAssignedCredit: "17000",
138
- totalRedeemedCredit: "1500",
139
- prettyAssignedCredit: "$1000.00",
140
- prettyRedeemedCredit: "$15.00",
141
- },
142
- { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
143
- {
144
- type: "CREDIT",
145
- unit: "CASH/CAD",
146
- count: 3,
147
- totalPendingCredit: 20000,
148
- totalAssignedCredit: 30000,
149
- totalRedeemedCredit: 10000,
150
- totalExpiredCredit: 0,
151
- totalCancelledCredit: 0,
152
- prettyPendingCredit: "$200.00",
153
- prettyAssignedCredit: "$300.00",
154
- prettyRedeemedCredit: "$100.00",
155
- value: 30000,
156
- prettyValue: "$300.00",
157
- },
158
- {
159
- type: "CREDIT",
160
- unit: "CASH/USD",
161
- count: 6,
162
- totalPendingCredit: 25000,
163
- totalAssignedCredit: 40000,
164
- totalRedeemedCredit: 10000,
165
- totalExpiredCredit: 15000,
166
- totalCancelledCredit: 10000,
167
- prettyPendingCredit: "USD250.00",
168
- prettyAssignedCredit: "USD400.00",
169
- prettyRedeemedCredit: "USD150.00",
170
- value: 40000,
171
- prettyValue: "USD400.00",
172
- },
173
- ],
174
- rewardBalances: [
175
- {
176
- type: "CREDIT",
177
- unit: "CENTS",
178
- value: 17000,
179
- prettyValue: "$170.00",
180
- totalAssignedCredit: "17000",
181
- totalRedeemedCredit: "1500",
182
- prettyAssignedCredit: "$170.00",
183
- prettyRedeemedCredit: "$15.00",
184
- },
185
- { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
186
- {
187
- type: "CREDIT",
188
- unit: "CASH/CAD",
189
- count: 3,
190
- totalPendingCredit: 20000,
191
- totalAssignedCredit: 30000,
192
- totalRedeemedCredit: 10000,
193
- totalExpiredCredit: 0,
194
- totalCancelledCredit: 0,
195
- prettyPendingCredit: "$200.00",
196
- prettyAssignedCredit: "$300.00",
197
- prettyRedeemedCredit: "$100.00",
198
- value: 30000,
199
- prettyValue: "$300.00",
200
- },
201
- {
202
- type: "CREDIT",
203
- unit: "CASH/USD",
204
- count: 6,
205
- totalPendingCredit: 25000,
206
- totalAssignedCredit: 40000,
207
- totalRedeemedCredit: 10000,
208
- totalExpiredCredit: 15000,
209
- totalCancelledCredit: 10000,
210
- prettyPendingCredit: "USD250.00",
211
- prettyAssignedCredit: "USD400.00",
212
- prettyRedeemedCredit: "USD150.00",
213
- value: 40000,
214
- prettyValue: "USD400.00",
215
- },
216
- ],
217
- rewardBalanceDetails: [
218
- {
219
- prettyAvailableValue: "$5.00",
220
- },
221
- {
222
- prettyAvailableValue: "18%",
223
- },
224
- ],
225
- };
226
- //@ts-ignore
227
- const squatchJsApi = window.frameElement
228
- ? window.frameElement.squatchJsApi
229
- : {};
230
- const apolloClient = () => {
231
- const { tenantAlias, appDomain, token } = widgetIdent();
232
- const uri = appDomain + "/api/v1/" + tenantAlias + "/graphql";
233
- const headers = {
234
- Authorization: `Bearer ${token}`,
235
- };
236
- const client = new ApolloClient({
237
- link: new HttpLink({ uri, headers }),
238
- cache: new InMemoryCache(),
239
- });
240
- return client;
241
- };
242
- const API = {
243
- version: "Welcome to widget-host",
244
- analytics: {
245
- shareEvent(shareMedium) {
246
- const widgetId = widgetIdent();
247
- if (widgetId["env"] === "demo" || !widgetId)
248
- return Promise.resolve({});
249
- const { userId, accountId, programId = "classic", engagementMedium, } = widgetId;
250
- const variables = {
251
- eventMeta: {
252
- id: userId,
253
- accountId,
254
- programId,
255
- type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",
256
- meta: {
257
- engagementMedium,
258
- shareMedium,
259
- },
260
- },
261
- };
262
- return apolloClient()
263
- .mutate({
264
- mutation: gql `
265
- mutation ($eventMeta: UserAnalyticsEvent!) {
266
- createUserAnalyticsEvent(eventMeta: $eventMeta)
267
- }
268
- `,
269
- variables,
270
- })
271
- .then((result) => {
272
- return result.data.createUserAnalyticsEvent;
273
- });
274
- },
275
- loadEvent() {
276
- return Promise.resolve({ event: "loadEvent" });
277
- },
278
- },
279
- graphql: {
280
- getClient() {
281
- return apolloClient();
282
- },
283
- getUserFragment(userFragment, fragmentVariables) {
284
- const fragment = gql `
285
- fragment UserFragment on User {
286
- ${userFragment}
287
- }`;
288
- const { userId, accountId } = widgetIdent();
289
- const variables = Object.assign(Object.assign({}, fragmentVariables), { userId,
290
- accountId });
291
- return this.getClient().query({
292
- query: gql `
293
- query ($userId: String!, $accountId: String!, $offset: Int) {
294
- user(id: $userId, accountId: $accountId) {
295
- ...UserFragment
296
- }
297
- }
298
- ${fragment}
299
- `,
300
- variables,
301
- });
302
- },
303
- getShareLink() {
304
- const widgetId = widgetIdent();
305
- if (widgetId["env"] === "demo" || !widgetId)
306
- return Promise.resolve(demoUser.shareLink);
307
- const { userId, accountId, programId = null, engagementMedium, } = widgetId;
308
- const variables = {
309
- userId,
310
- accountId,
311
- programId,
312
- engagementMedium,
313
- };
314
- return this.getClient()
315
- .query({
316
- query: gql `
317
- query (
318
- $userId: String!
319
- $accountId: String!
320
- $programId: ID
321
- $engagementMedium: UserEngagementMedium!
322
- ) {
323
- user(id: $userId, accountId: $accountId) {
324
- shareLink(
325
- programId: $programId
326
- engagementMedium: $engagementMedium
327
- shareMedium: DIRECT
328
- useCleanLink: true
329
- )
330
- }
331
- }
332
- `,
333
- variables,
334
- })
335
- .then((res) => res.data.user.shareLink);
336
- },
337
- getReferrals(showReferrer, offset = 0, limit = 3) {
338
- const widgetId = widgetIdent();
339
- if (widgetId["env"] === "demo" || !widgetId) {
340
- const { referrals: refs, referredByReferral, locale } = demoUser;
341
- const referrals = {
342
- totalCount: refs.totalCount,
343
- data: refs.data.slice(offset, offset + limit),
344
- };
345
- const user = { referrals, referredByReferral, locale };
346
- return Promise.resolve(user);
347
- }
348
- const { userId, accountId, programId = null } = widgetId;
349
- const variables = {
350
- limit,
351
- offset,
352
- userId,
353
- accountId,
354
- programId,
355
- programId_exists: programId ? true : false,
356
- };
357
- return this.getClient()
358
- .query({
359
- query: gql `
360
- query (
361
- $userId: String!
362
- $accountId: String!
363
- $offset: Int!
364
- $limit: Int!
365
- $programId: ID
366
- $programId_exists: Boolean!
367
- ) {
368
- user(id: $userId, accountId: $accountId) {
369
- locale
370
- referrals(
371
- limit: $limit
372
- offset: $offset
373
- filter: {
374
- programId_eq: $programId
375
- programId_exists: $programId_exists
376
- }
377
- ) {
378
- totalCount
379
- data {
380
- dateConverted
381
- dateReferralStarted
382
- referredUser {
383
- firstName
384
- lastName
385
- }
386
- rewards(
387
- filter: { userId_eq: $userId, accountId_eq: $accountId }
388
- ) {
389
- prettyValue
390
- dateExpires
391
- statuses
392
- meta {
393
- message
394
- }
395
- }
396
- }
397
- }
398
- ${showReferrer
399
- ? `referredByReferral(programId: $programId) {
400
- referrerUser {
401
- firstName
402
- lastName
403
- }
404
- dateReferralStarted
405
- rewards(
406
- filter: { userId_eq: $userId, accountId_eq: $accountId }
407
- ) {
408
- prettyValue
409
- statuses
410
- }
411
- }`
412
- : ""}
413
- }
414
- }
415
- `,
416
- variables,
417
- })
418
- .then((res) => res.data.user);
419
- },
420
- getStats() {
421
- const widgetId = widgetIdent();
422
- if (widgetId["env"] === "demo" || !widgetId) {
423
- const { referrals: referralsCount, referralsMonth, referralsWeek, rewardsCount, rewardsMonth, rewardsWeek, rewardBalances, rewardBalancesGlobal, } = demoUser;
424
- const user = {
425
- referralsCount,
426
- referralsMonth,
427
- referralsWeek,
428
- rewardsCount,
429
- rewardsMonth,
430
- rewardsWeek,
431
- rewardBalances,
432
- rewardBalancesGlobal,
433
- };
434
- return Promise.resolve(user);
435
- }
436
- const { userId, accountId, programId = null } = widgetId;
437
- const variables = {
438
- userId,
439
- accountId,
440
- programId,
441
- programId_exists: programId ? true : false,
442
- };
443
- return this.getClient()
444
- .query({
445
- query: gql `
446
- query (
447
- $userId: String!
448
- $accountId: String!
449
- $programId: ID
450
- $programId_exists: Boolean!
451
- ) {
452
- user(id: $userId, accountId: $accountId) {
453
- referralsCount: referrals(
454
- filter: {
455
- programId_eq: $programId
456
- programId_exists: $programId_exists
457
- }
458
- ) {
459
- totalCount
460
- }
461
- referralsMonth: referrals(
462
- filter: {
463
- programId_eq: $programId
464
- programId_exists: $programId_exists
465
- dateReferralStarted_timeframe: "this_month"
466
- }
467
- ) {
468
- totalCount
469
- }
470
- referralsWeek: referrals(
471
- filter: {
472
- programId_eq: $programId
473
- programId_exists: $programId_exists
474
- dateReferralStarted_timeframe: "this_week"
475
- }
476
- ) {
477
- totalCount
478
- }
479
- rewardsCount: rewards(
480
- filter: {
481
- programId_eq: $programId
482
- programId_exists: $programId_exists
483
- }
484
- ) {
485
- totalCount
486
- }
487
- rewardsMonth: rewards(
488
- filter: {
489
- programId_eq: $programId
490
- programId_exists: $programId_exists
491
- dateGiven_timeframe: "this_month"
492
- }
493
- ) {
494
- totalCount
495
- }
496
- rewardsWeek: rewards(
497
- filter: {
498
- programId_eq: $programId
499
- programId_exists: $programId_exists
500
- dateGiven_timeframe: "this_week"
501
- }
502
- ) {
503
- totalCount
504
- }
505
- rewardBalances(programId: $programId)
506
- rewardBalancesGlobal: rewardBalances
507
- }
508
- }
509
- `,
510
- variables,
511
- })
512
- .then((res) => res.data.user);
513
- },
514
- async getReferralCode() {
515
- const widgetId = widgetIdent();
516
- if (widgetId["env"] === "demo" || !widgetId)
517
- return demoUser.referralcode;
518
- const { userId, accountId, programId } = widgetId;
519
- const variables = {
520
- userId,
521
- accountId,
522
- programId,
523
- };
524
- return this.getClient()
525
- .query({
526
- query: gql `
527
- query ($userId: String!, $accountId: String!, $programId: ID!) {
528
- user(id: $userId, accountId: $accountId) {
529
- referralCode(programId: $programId)
530
- }
531
- }
532
- `,
533
- variables,
534
- })
535
- .then((res) => res.data.user.referralCode);
536
- },
537
- async getFueltankCode(rewardKey) {
538
- const widgetId = widgetIdent();
539
- if (widgetId["env"] === "demo" || !widgetId) {
540
- return {
541
- referredByReferral: demoUser.referredByReferral,
542
- rewards: { data: demoUser.referredByReferral.rewards },
543
- };
544
- }
545
- const { userId, accountId, programId } = widgetId;
546
- const variables = {
547
- userId,
548
- accountId,
549
- programId,
550
- rewardKey,
551
- };
552
- return this.getClient()
553
- .query({
554
- query: gql `
555
- query (
556
- $userId: String!
557
- $accountId: String!
558
- $programId: ID!
559
- $rewardKey: String!
560
- ) {
561
- user(id: $userId, accountId: $accountId) {
562
- referredByReferral(programId: $programId) {
563
- referrerUser {
564
- referralCode(programId: $programId)
565
- }
566
- }
567
- rewards(
568
- filter: {
569
- programId_eq: $programId
570
- programRewardKey_eq: $rewardKey
571
- }
572
- ) {
573
- count
574
- totalCount
575
- data {
576
- fuelTankCode
577
- }
578
- }
579
- }
580
- }
581
- `,
582
- variables,
583
- })
584
- .then((res) => res.data.user);
585
- },
586
- getMessageLinks(mediums) {
587
- const widgetId = widgetIdent();
588
- if (widgetId["env"] === "demo" || !widgetId)
589
- return Promise.resolve(demoUser.messageLink);
590
- const { userId, accountId, programId = null, engagementMedium, } = widgetId;
591
- const variables = {
592
- userId,
593
- accountId,
594
- programId,
595
- engagementMedium,
596
- };
597
- return this.getClient()
598
- .query({
599
- query: gql `
600
- query($userId: String!, $accountId: String!, $programId: ID, $engagementMedium: UserEngagementMedium!) {
601
- user(id: $userId, accountId: $accountId) {
602
- ${mediums[0]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[0]})
603
- ${mediums[1]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[1]})
604
- ${mediums[2]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[2]})
605
- ${mediums[3]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[3]})
606
- ${mediums[4]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[4]})
607
- ${mediums[5]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[5]})
608
- ${mediums[6]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[6]})
609
- ${mediums[7]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[7]})
610
- ${mediums[8]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[8]})
611
- }
612
- }
613
- `,
614
- variables,
615
- })
616
- .then((res) => res.data.user);
617
- },
618
- },
619
- ui: squatchJsApi,
620
- };
621
- export { API };
1
+ import { ApolloClient } from "apollo-client";
2
+ import { HttpLink } from "apollo-link-http";
3
+ import { InMemoryCache } from "apollo-cache-inmemory";
4
+ import gql from "graphql-tag";
5
+ if (!window["widgetIdent"]) {
6
+ window["widgetIdent"] = {
7
+ env: "demo",
8
+ };
9
+ }
10
+ export function widgetIdent() {
11
+ //@ts-ignore
12
+ return window.widgetIdent;
13
+ }
14
+ const today = new Date();
15
+ const demoUser = {
16
+ shareLink: "http://ssqt.co",
17
+ fueltankCode: "12AS3F",
18
+ referralcode: "RIDDIKULUS",
19
+ locale: "en_US",
20
+ messageLink: {
21
+ EMAIL: "http://short.staging.referralsaasquatch.com/mJjFXu",
22
+ FACEBOOK: "http://short.staging.referralsaasquatch.com/mwjFXu",
23
+ TWITTER: "http://short.staging.referralsaasquatch.com/mwjFXu",
24
+ SMS: "http://short.staging.referralsaasquatch.com/mwjFXu",
25
+ WHATSAPP: "http://short.staging.referralsaasquatch.com/mwjFXu",
26
+ LINKEDIN: "http://short.staging.referralsaasquatch.com/mwjFXu",
27
+ PINTEREST: "http://short.staging.referralsaasquatch.com/mwjFXu",
28
+ FBMESSENGER: "http://short.staging.referralsaasquatch.com/mwjFXu",
29
+ },
30
+ referrals: {
31
+ totalCount: 9,
32
+ data: [
33
+ {
34
+ dateReferralStarted: today.setDate(today.getDate() - 2),
35
+ referredUser: { firstName: "Remus", lastName: "Lupin" },
36
+ rewards: [
37
+ {
38
+ prettyValue: "$20.00",
39
+ dateExpires: today.setDate(today.getDate() + 4),
40
+ statuses: ["EXPIRED"],
41
+ meta: { message: "Applied to Invoice #1234" },
42
+ },
43
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
44
+ { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
45
+ ],
46
+ },
47
+ {
48
+ dateReferralStarted: today.setDate(today.getDate() - 1),
49
+ referredUser: { firstName: "Gellert", lastName: "Grindelwald" },
50
+ rewards: [],
51
+ },
52
+ // Blank string becomes an unknown user, which is editable
53
+ {
54
+ dateReferralStarted: today.setDate(today.getDate() - 1),
55
+ referredUser: { firstName: "", lastName: "" },
56
+ rewards: [
57
+ {
58
+ prettyValue: "$20.00",
59
+ dateExpires: today.setDate(today.getDate() - 2),
60
+ statuses: ["EXPIRED"],
61
+ },
62
+ ],
63
+ },
64
+ {
65
+ dateReferralStarted: today.setDate(today.getDate() - 5),
66
+ referredUser: { firstName: "Lavender", lastName: "Brown" },
67
+ rewards: [{ prettyValue: "$20.00", statuses: ["CANCELLED"] }],
68
+ },
69
+ {
70
+ dateReferralStarted: today.setDate(today.getDate() - 4),
71
+ referredUser: { firstName: "Blaise", lastName: "Zabini" },
72
+ rewards: [
73
+ { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
74
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
75
+ ],
76
+ },
77
+ {
78
+ dateReferralStarted: today.setDate(today.getDate() - 10),
79
+ referredUser: { firstName: "Argus", lastName: "Filch" },
80
+ rewards: [],
81
+ },
82
+ {
83
+ dateReferralStarted: today.setDate(today.getDate() - 15),
84
+ referredUser: { firstName: "Ron", lastName: "Weasley" },
85
+ rewards: [{ prettyValue: "$20.00", statuses: ["AVAILABLE"] }],
86
+ },
87
+ {
88
+ dateReferralStarted: today.setDate(today.getDate() - 2),
89
+ referredUser: { firstName: "Hermione", lastName: "Granger" },
90
+ rewards: [
91
+ { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
92
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
93
+ { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
94
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
95
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
96
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
97
+ ],
98
+ },
99
+ {
100
+ dateConverted: 1606943971468,
101
+ dateReferralStarted: 1606943971468,
102
+ referredUser: {
103
+ imageUrl: "",
104
+ firstName: "Seamus",
105
+ lastName: "Finnigan",
106
+ },
107
+ rewards: [],
108
+ },
109
+ ],
110
+ },
111
+ referredByReferral: {
112
+ dateReferralStarted: today.setDate(today.getDate() - 2),
113
+ referrerUser: {
114
+ firstName: "Rubeus",
115
+ lastName: "Hagrid",
116
+ referralCode: "RUBEUSHAGRID12",
117
+ },
118
+ rewards: [
119
+ {
120
+ fuelTankCode: "CODE1234",
121
+ prettyValue: "$10.00",
122
+ statuses: ["AVAILABLE"],
123
+ },
124
+ ],
125
+ },
126
+ referralsMonth: { totalCount: 6 },
127
+ referralsWeek: { totalCount: 3 },
128
+ rewardsCount: { totalCount: 14 },
129
+ rewardsMonth: { totalCount: 7 },
130
+ rewardsWeek: { totalCount: 4 },
131
+ rewardBalancesGlobal: [
132
+ {
133
+ type: "CREDIT",
134
+ unit: "CENTS",
135
+ value: 17000,
136
+ prettyValue: "$170.00",
137
+ totalAssignedCredit: "17000",
138
+ totalRedeemedCredit: "1500",
139
+ prettyAssignedCredit: "$1000.00",
140
+ prettyRedeemedCredit: "$15.00",
141
+ },
142
+ { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
143
+ {
144
+ type: "CREDIT",
145
+ unit: "CASH/CAD",
146
+ count: 3,
147
+ totalPendingCredit: 20000,
148
+ totalAssignedCredit: 30000,
149
+ totalRedeemedCredit: 10000,
150
+ totalExpiredCredit: 0,
151
+ totalCancelledCredit: 0,
152
+ prettyPendingCredit: "$200.00",
153
+ prettyAssignedCredit: "$300.00",
154
+ prettyRedeemedCredit: "$100.00",
155
+ value: 30000,
156
+ prettyValue: "$300.00",
157
+ },
158
+ {
159
+ type: "CREDIT",
160
+ unit: "CASH/USD",
161
+ count: 6,
162
+ totalPendingCredit: 25000,
163
+ totalAssignedCredit: 40000,
164
+ totalRedeemedCredit: 10000,
165
+ totalExpiredCredit: 15000,
166
+ totalCancelledCredit: 10000,
167
+ prettyPendingCredit: "USD250.00",
168
+ prettyAssignedCredit: "USD400.00",
169
+ prettyRedeemedCredit: "USD150.00",
170
+ value: 40000,
171
+ prettyValue: "USD400.00",
172
+ },
173
+ ],
174
+ rewardBalances: [
175
+ {
176
+ type: "CREDIT",
177
+ unit: "CENTS",
178
+ value: 17000,
179
+ prettyValue: "$170.00",
180
+ totalAssignedCredit: "17000",
181
+ totalRedeemedCredit: "1500",
182
+ prettyAssignedCredit: "$170.00",
183
+ prettyRedeemedCredit: "$15.00",
184
+ },
185
+ { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
186
+ {
187
+ type: "CREDIT",
188
+ unit: "CASH/CAD",
189
+ count: 3,
190
+ totalPendingCredit: 20000,
191
+ totalAssignedCredit: 30000,
192
+ totalRedeemedCredit: 10000,
193
+ totalExpiredCredit: 0,
194
+ totalCancelledCredit: 0,
195
+ prettyPendingCredit: "$200.00",
196
+ prettyAssignedCredit: "$300.00",
197
+ prettyRedeemedCredit: "$100.00",
198
+ value: 30000,
199
+ prettyValue: "$300.00",
200
+ },
201
+ {
202
+ type: "CREDIT",
203
+ unit: "CASH/USD",
204
+ count: 6,
205
+ totalPendingCredit: 25000,
206
+ totalAssignedCredit: 40000,
207
+ totalRedeemedCredit: 10000,
208
+ totalExpiredCredit: 15000,
209
+ totalCancelledCredit: 10000,
210
+ prettyPendingCredit: "USD250.00",
211
+ prettyAssignedCredit: "USD400.00",
212
+ prettyRedeemedCredit: "USD150.00",
213
+ value: 40000,
214
+ prettyValue: "USD400.00",
215
+ },
216
+ ],
217
+ rewardBalanceDetails: [
218
+ {
219
+ prettyAvailableValue: "$5.00",
220
+ },
221
+ {
222
+ prettyAvailableValue: "18%",
223
+ },
224
+ ],
225
+ };
226
+ //@ts-ignore
227
+ const squatchJsApi = window.frameElement
228
+ ? window.frameElement.squatchJsApi
229
+ : {};
230
+ const apolloClient = () => {
231
+ const { tenantAlias, appDomain, token } = widgetIdent();
232
+ const uri = appDomain + "/api/v1/" + tenantAlias + "/graphql";
233
+ const headers = {
234
+ Authorization: `Bearer ${token}`,
235
+ };
236
+ const client = new ApolloClient({
237
+ link: new HttpLink({ uri, headers }),
238
+ cache: new InMemoryCache(),
239
+ });
240
+ return client;
241
+ };
242
+ const API = {
243
+ version: "Welcome to widget-host",
244
+ analytics: {
245
+ shareEvent(shareMedium) {
246
+ const widgetId = widgetIdent();
247
+ if (widgetId["env"] === "demo" || !widgetId)
248
+ return Promise.resolve({});
249
+ const { userId, accountId, programId = "classic", engagementMedium, } = widgetId;
250
+ const variables = {
251
+ eventMeta: {
252
+ id: userId,
253
+ accountId,
254
+ programId,
255
+ type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",
256
+ meta: {
257
+ engagementMedium,
258
+ shareMedium,
259
+ },
260
+ },
261
+ };
262
+ return apolloClient()
263
+ .mutate({
264
+ mutation: gql `
265
+ mutation ($eventMeta: UserAnalyticsEvent!) {
266
+ createUserAnalyticsEvent(eventMeta: $eventMeta)
267
+ }
268
+ `,
269
+ variables,
270
+ })
271
+ .then((result) => {
272
+ return result.data.createUserAnalyticsEvent;
273
+ });
274
+ },
275
+ loadEvent() {
276
+ return Promise.resolve({ event: "loadEvent" });
277
+ },
278
+ },
279
+ graphql: {
280
+ getClient() {
281
+ return apolloClient();
282
+ },
283
+ getUserFragment(userFragment, fragmentVariables) {
284
+ const fragment = gql `
285
+ fragment UserFragment on User {
286
+ ${userFragment}
287
+ }`;
288
+ const { userId, accountId } = widgetIdent();
289
+ const variables = Object.assign(Object.assign({}, fragmentVariables), { userId,
290
+ accountId });
291
+ return this.getClient().query({
292
+ query: gql `
293
+ query ($userId: String!, $accountId: String!, $offset: Int) {
294
+ user(id: $userId, accountId: $accountId) {
295
+ ...UserFragment
296
+ }
297
+ }
298
+ ${fragment}
299
+ `,
300
+ variables,
301
+ });
302
+ },
303
+ getShareLink() {
304
+ const widgetId = widgetIdent();
305
+ if (widgetId["env"] === "demo" || !widgetId)
306
+ return Promise.resolve(demoUser.shareLink);
307
+ const { userId, accountId, programId = null, engagementMedium, } = widgetId;
308
+ const variables = {
309
+ userId,
310
+ accountId,
311
+ programId,
312
+ engagementMedium,
313
+ };
314
+ return this.getClient()
315
+ .query({
316
+ query: gql `
317
+ query (
318
+ $userId: String!
319
+ $accountId: String!
320
+ $programId: ID
321
+ $engagementMedium: UserEngagementMedium!
322
+ ) {
323
+ user(id: $userId, accountId: $accountId) {
324
+ shareLink(
325
+ programId: $programId
326
+ engagementMedium: $engagementMedium
327
+ shareMedium: DIRECT
328
+ useCleanLink: true
329
+ )
330
+ }
331
+ }
332
+ `,
333
+ variables,
334
+ })
335
+ .then((res) => res.data.user.shareLink);
336
+ },
337
+ getReferrals(showReferrer, offset = 0, limit = 3) {
338
+ const widgetId = widgetIdent();
339
+ if (widgetId["env"] === "demo" || !widgetId) {
340
+ const { referrals: refs, referredByReferral, locale } = demoUser;
341
+ const referrals = {
342
+ totalCount: refs.totalCount,
343
+ data: refs.data.slice(offset, offset + limit),
344
+ };
345
+ const user = { referrals, referredByReferral, locale };
346
+ return Promise.resolve(user);
347
+ }
348
+ const { userId, accountId, programId = null } = widgetId;
349
+ const variables = {
350
+ limit,
351
+ offset,
352
+ userId,
353
+ accountId,
354
+ programId,
355
+ programId_exists: programId ? true : false,
356
+ };
357
+ return this.getClient()
358
+ .query({
359
+ query: gql `
360
+ query (
361
+ $userId: String!
362
+ $accountId: String!
363
+ $offset: Int!
364
+ $limit: Int!
365
+ $programId: ID
366
+ $programId_exists: Boolean!
367
+ ) {
368
+ user(id: $userId, accountId: $accountId) {
369
+ locale
370
+ referrals(
371
+ limit: $limit
372
+ offset: $offset
373
+ filter: {
374
+ programId_eq: $programId
375
+ programId_exists: $programId_exists
376
+ }
377
+ ) {
378
+ totalCount
379
+ data {
380
+ dateConverted
381
+ dateReferralStarted
382
+ referredUser {
383
+ firstName
384
+ lastName
385
+ }
386
+ rewards(
387
+ filter: { userId_eq: $userId, accountId_eq: $accountId }
388
+ ) {
389
+ prettyValue
390
+ dateExpires
391
+ statuses
392
+ meta {
393
+ message
394
+ }
395
+ }
396
+ }
397
+ }
398
+ ${showReferrer
399
+ ? `referredByReferral(programId: $programId) {
400
+ referrerUser {
401
+ firstName
402
+ lastName
403
+ }
404
+ dateReferralStarted
405
+ rewards(
406
+ filter: { userId_eq: $userId, accountId_eq: $accountId }
407
+ ) {
408
+ prettyValue
409
+ statuses
410
+ }
411
+ }`
412
+ : ""}
413
+ }
414
+ }
415
+ `,
416
+ variables,
417
+ })
418
+ .then((res) => res.data.user);
419
+ },
420
+ getStats() {
421
+ const widgetId = widgetIdent();
422
+ if (widgetId["env"] === "demo" || !widgetId) {
423
+ const { referrals: referralsCount, referralsMonth, referralsWeek, rewardsCount, rewardsMonth, rewardsWeek, rewardBalances, rewardBalancesGlobal, } = demoUser;
424
+ const user = {
425
+ referralsCount,
426
+ referralsMonth,
427
+ referralsWeek,
428
+ rewardsCount,
429
+ rewardsMonth,
430
+ rewardsWeek,
431
+ rewardBalances,
432
+ rewardBalancesGlobal,
433
+ };
434
+ return Promise.resolve(user);
435
+ }
436
+ const { userId, accountId, programId = null } = widgetId;
437
+ const variables = {
438
+ userId,
439
+ accountId,
440
+ programId,
441
+ programId_exists: programId ? true : false,
442
+ };
443
+ return this.getClient()
444
+ .query({
445
+ query: gql `
446
+ query (
447
+ $userId: String!
448
+ $accountId: String!
449
+ $programId: ID
450
+ $programId_exists: Boolean!
451
+ ) {
452
+ user(id: $userId, accountId: $accountId) {
453
+ referralsCount: referrals(
454
+ filter: {
455
+ programId_eq: $programId
456
+ programId_exists: $programId_exists
457
+ }
458
+ ) {
459
+ totalCount
460
+ }
461
+ referralsMonth: referrals(
462
+ filter: {
463
+ programId_eq: $programId
464
+ programId_exists: $programId_exists
465
+ dateReferralStarted_timeframe: "this_month"
466
+ }
467
+ ) {
468
+ totalCount
469
+ }
470
+ referralsWeek: referrals(
471
+ filter: {
472
+ programId_eq: $programId
473
+ programId_exists: $programId_exists
474
+ dateReferralStarted_timeframe: "this_week"
475
+ }
476
+ ) {
477
+ totalCount
478
+ }
479
+ rewardsCount: rewards(
480
+ filter: {
481
+ programId_eq: $programId
482
+ programId_exists: $programId_exists
483
+ }
484
+ ) {
485
+ totalCount
486
+ }
487
+ rewardsMonth: rewards(
488
+ filter: {
489
+ programId_eq: $programId
490
+ programId_exists: $programId_exists
491
+ dateGiven_timeframe: "this_month"
492
+ }
493
+ ) {
494
+ totalCount
495
+ }
496
+ rewardsWeek: rewards(
497
+ filter: {
498
+ programId_eq: $programId
499
+ programId_exists: $programId_exists
500
+ dateGiven_timeframe: "this_week"
501
+ }
502
+ ) {
503
+ totalCount
504
+ }
505
+ rewardBalances(programId: $programId)
506
+ rewardBalancesGlobal: rewardBalances
507
+ }
508
+ }
509
+ `,
510
+ variables,
511
+ })
512
+ .then((res) => res.data.user);
513
+ },
514
+ getBalanceDetails() {
515
+ const widgetId = widgetIdent();
516
+ if (widgetId["env"] === "demo" || !widgetId) {
517
+ const { rewardBalanceDetails } = demoUser;
518
+ const user = {
519
+ rewardBalanceDetails
520
+ };
521
+ return Promise.resolve(user);
522
+ }
523
+ const { userId, accountId, programId = null, locale } = widgetId;
524
+ const variables = {
525
+ userId,
526
+ accountId,
527
+ programId,
528
+ locale
529
+ };
530
+ return this.getClient().query({
531
+ query: gql `
532
+ query(
533
+ $userId: String!,
534
+ $accountId: String!,
535
+ $programId: ID,
536
+ $locale: String!
537
+ ) {
538
+ user(id: $userId, accountId: $accountId) {
539
+ rewardBalanceDetails(programId: $programId) {
540
+ prettyAvailableValue
541
+ unit
542
+ ... on CreditRewardBalance {
543
+ prettyAssignedCredit
544
+ prettyRedeemedCredit
545
+ rewardUnit {
546
+ currency {
547
+ displayName(locale: $locale)
548
+ symbol(locale: $locale)
549
+ currencyCode
550
+ }
551
+ }
552
+ }
553
+ }
554
+ }
555
+ }
556
+ `,
557
+ variables
558
+ }).then(res => res.data.user);
559
+ },
560
+ getRewardExpiries() {
561
+ const widgetId = widgetIdent();
562
+ if (widgetId["env"] === "demo" || !widgetId) {
563
+ const { rewardBalanceDetails } = demoUser;
564
+ const user = {
565
+ rewardBalanceDetails
566
+ };
567
+ return Promise.resolve(user);
568
+ }
569
+ const { userId, accountId, programId = null, locale } = widgetId;
570
+ const variables = {
571
+ userId,
572
+ accountId,
573
+ programId,
574
+ locale
575
+ };
576
+ return this.getClient().query({
577
+ query: gql `
578
+ query(
579
+ $userId: String!,
580
+ $accountId: String!,
581
+ $programId: ID,
582
+ $locale: String!
583
+ ) {
584
+ user(id: $userId, accountId: $accountId) {
585
+ rewards(programId_eq: $programId) {
586
+ data {
587
+ dateCreated
588
+ dateScheduledFor
589
+ dateExpires
590
+ prettyValue
591
+ unit
592
+ }
593
+ }
594
+ }
595
+ }
596
+ `,
597
+ variables
598
+ }).then(res => res.data.user);
599
+ },
600
+ async getReferralCode() {
601
+ const widgetId = widgetIdent();
602
+ if (widgetId["env"] === "demo" || !widgetId)
603
+ return demoUser.referralcode;
604
+ const { userId, accountId, programId } = widgetId;
605
+ const variables = {
606
+ userId,
607
+ accountId,
608
+ programId,
609
+ };
610
+ return this.getClient()
611
+ .query({
612
+ query: gql `
613
+ query ($userId: String!, $accountId: String!, $programId: ID!) {
614
+ user(id: $userId, accountId: $accountId) {
615
+ referralCode(programId: $programId)
616
+ }
617
+ }
618
+ `,
619
+ variables,
620
+ })
621
+ .then((res) => res.data.user.referralCode);
622
+ },
623
+ async getFueltankCode(rewardKey) {
624
+ const widgetId = widgetIdent();
625
+ if (widgetId["env"] === "demo" || !widgetId) {
626
+ return {
627
+ referredByReferral: demoUser.referredByReferral,
628
+ rewards: { data: demoUser.referredByReferral.rewards },
629
+ };
630
+ }
631
+ const { userId, accountId, programId } = widgetId;
632
+ const variables = {
633
+ userId,
634
+ accountId,
635
+ programId,
636
+ rewardKey,
637
+ };
638
+ return this.getClient()
639
+ .query({
640
+ query: gql `
641
+ query (
642
+ $userId: String!
643
+ $accountId: String!
644
+ $programId: ID!
645
+ $rewardKey: String!
646
+ ) {
647
+ user(id: $userId, accountId: $accountId) {
648
+ referredByReferral(programId: $programId) {
649
+ referrerUser {
650
+ referralCode(programId: $programId)
651
+ }
652
+ }
653
+ rewards(
654
+ filter: {
655
+ programId_eq: $programId
656
+ programRewardKey_eq: $rewardKey
657
+ }
658
+ ) {
659
+ count
660
+ totalCount
661
+ data {
662
+ fuelTankCode
663
+ }
664
+ }
665
+ }
666
+ }
667
+ `,
668
+ variables,
669
+ })
670
+ .then((res) => res.data.user);
671
+ },
672
+ getMessageLinks(mediums) {
673
+ const widgetId = widgetIdent();
674
+ if (widgetId["env"] === "demo" || !widgetId)
675
+ return Promise.resolve(demoUser.messageLink);
676
+ const { userId, accountId, programId = null, engagementMedium, } = widgetId;
677
+ const variables = {
678
+ userId,
679
+ accountId,
680
+ programId,
681
+ engagementMedium,
682
+ };
683
+ return this.getClient()
684
+ .query({
685
+ query: gql `
686
+ query($userId: String!, $accountId: String!, $programId: ID, $engagementMedium: UserEngagementMedium!) {
687
+ user(id: $userId, accountId: $accountId) {
688
+ ${mediums[0]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[0]})
689
+ ${mediums[1]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[1]})
690
+ ${mediums[2]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[2]})
691
+ ${mediums[3]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[3]})
692
+ ${mediums[4]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[4]})
693
+ ${mediums[5]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[5]})
694
+ ${mediums[6]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[6]})
695
+ ${mediums[7]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[7]})
696
+ ${mediums[8]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[8]})
697
+ }
698
+ }
699
+ `,
700
+ variables,
701
+ })
702
+ .then((res) => res.data.user);
703
+ },
704
+ getUserProgress() {
705
+ const widgetId = widgetIdent();
706
+ if (widgetId["env"] === "demo" || !widgetId) {
707
+ const demoData = {
708
+ customFields: { demo_totalValue: 16 },
709
+ rewardBalanceDetails: [{
710
+ prettyAvailableValue: "$10.00"
711
+ }],
712
+ rewards: { count: 1 }
713
+ };
714
+ return Promise.resolve(demoData);
715
+ }
716
+ const { userId, accountId, programId } = widgetId;
717
+ const variables = {
718
+ userId,
719
+ accountId,
720
+ programId,
721
+ };
722
+ return this.getClient().query({
723
+ query: gql `
724
+ query($userId: String!, $accountId: String!, $programId: ID) {
725
+ user(id: $userId, accountId: $accountId){
726
+ customFields
727
+ locale
728
+ rewardBalanceDetails(programId: $programId) {
729
+ prettyAvailableValue(formatType:UNIT_FORMATTED)
730
+ }
731
+ rewards(limit:1000,offset:0, filter:{programId_eq: $programId}){
732
+ count
733
+ }
734
+ }
735
+ }
736
+ `,
737
+ variables
738
+ }).then(res => res.data.user);
739
+ },
740
+ getProgramRules() {
741
+ const widgetId = widgetIdent();
742
+ if (widgetId["env"] === "demo" || !widgetId) {
743
+ const demoData = {
744
+ id: "demo",
745
+ name: "Demo Program",
746
+ rules: {
747
+ programWindow: "",
748
+ rewardRules: {
749
+ rewardRulesType: 1,
750
+ rewardGoal: 24,
751
+ isRecurring: 1,
752
+ defaultCurrency: "CAD"
753
+ }
754
+ }
755
+ };
756
+ return Promise.resolve(demoData);
757
+ }
758
+ const { programId } = widgetId;
759
+ const variables = {
760
+ programId
761
+ };
762
+ return this.getClient().query({
763
+ query: gql `
764
+ query($programId: ID!) {
765
+ program(id:$programId){
766
+ id
767
+ name
768
+ rules
769
+ }
770
+ }
771
+ `,
772
+ variables
773
+ }).then(res => res.data.program);
774
+ },
775
+ },
776
+ ui: squatchJsApi,
777
+ };
778
+ export { API };