@saasquatch/vanilla-components 1.2.3 → 1.2.4-10

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-d7b870ce.js → WidgetHost-f349e877.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 +28 -23
  7. package/dist/cjs/{sqh-copy-button_12.cjs.entry.js → sqh-copy-button_14.cjs.entry.js} +2278 -1068
  8. package/dist/cjs/sqh-referral-code.cjs.entry.js +23 -23
  9. package/dist/cjs/sqh-rewards-actions.cjs.entry.js +27 -12
  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 -56
  13. package/dist/collection/components/copy-button/copy-button.js +389 -293
  14. package/dist/collection/components/copy-link-button/copy-link-button.js +236 -182
  15. package/dist/collection/components/cta-component/cta-component.css +6 -0
  16. package/dist/collection/components/cta-component/cta-component.js +393 -0
  17. package/dist/collection/components/global-container/global-container.js +170 -126
  18. package/dist/collection/components/image-component/image-component.js +178 -132
  19. package/dist/collection/components/partner-stat-component/partner-stat-component.js +199 -155
  20. package/dist/collection/components/progress-indicator/progress-indicator.css +73 -0
  21. package/dist/collection/components/progress-indicator/progress-indicator.js +554 -0
  22. package/dist/collection/components/referral-code/referral-code.js +36 -30
  23. package/dist/collection/components/referral-component/referral-component.js +255 -236
  24. package/dist/collection/components/referral-list/referral-list.js +935 -671
  25. package/dist/collection/components/rewards-actions/rewards-actions.js +105 -77
  26. package/dist/collection/components/share-button/share-button.js +310 -255
  27. package/dist/collection/components/share-button-container/share-button-container.js +2439 -1534
  28. package/dist/collection/components/stat-component/stat-component.js +200 -155
  29. package/dist/collection/components/stats-container/stats-container.js +210 -180
  30. package/dist/collection/components/text-component/text-component.js +304 -249
  31. package/dist/collection/entrypoint.js +32 -32
  32. package/dist/collection/global/global.js +4 -4
  33. package/dist/collection/services/FormatJs.js +15 -15
  34. package/dist/collection/services/WidgetHost.js +778 -621
  35. package/dist/collection/utilities.js +81 -81
  36. package/dist/esm/{WidgetHost-a27e693d.js → WidgetHost-c033b6ac.js} +772 -615
  37. package/dist/esm/{en-be593af0.js → en-a652ab83.js} +1 -1
  38. package/dist/esm/{index-8ea8b6d8.js → index-342d7c26.js} +54 -3
  39. package/dist/esm/loader.mjs +3 -3
  40. package/dist/esm/polyfills/core-js.js +0 -0
  41. package/dist/esm/polyfills/dom.js +0 -0
  42. package/dist/esm/polyfills/es5-html-element.js +0 -0
  43. package/dist/esm/polyfills/index.js +0 -0
  44. package/dist/esm/polyfills/system.js +0 -0
  45. package/dist/esm/sqh-close-button.entry.js +28 -23
  46. package/dist/esm/{sqh-copy-button_12.entry.js → sqh-copy-button_14.entry.js} +2275 -1067
  47. package/dist/esm/sqh-referral-code.entry.js +23 -23
  48. package/dist/esm/sqh-rewards-actions.entry.js +27 -12
  49. package/dist/esm/widget-components.mjs +3 -3
  50. package/dist/esm-es5/{WidgetHost-a27e693d.js → WidgetHost-c033b6ac.js} +9524 -9432
  51. package/dist/esm-es5/_commonjsHelpers-1d681858.js +17 -17
  52. package/dist/esm-es5/css-shim-a659079f.js +122 -122
  53. package/dist/esm-es5/dom-4061ceba.js +468 -468
  54. package/dist/esm-es5/{en-be593af0.js → en-a652ab83.js} +1471 -1471
  55. package/dist/esm-es5/{index-8ea8b6d8.js → index-342d7c26.js} +1808 -1758
  56. package/dist/esm-es5/loader.mjs +11 -11
  57. package/dist/esm-es5/sqh-close-button.entry.js +35 -30
  58. package/dist/esm-es5/{sqh-copy-button_12.entry.js → sqh-copy-button_14.entry.js} +10582 -9485
  59. package/dist/esm-es5/sqh-referral-code.entry.js +29 -29
  60. package/dist/esm-es5/sqh-rewards-actions.entry.js +31 -16
  61. package/dist/esm-es5/widget-components.mjs +6 -6
  62. package/dist/types/components/close-button/close-button.d.ts +18 -7
  63. package/dist/types/components/copy-button/copy-button.d.ts +93 -23
  64. package/dist/types/components/copy-link-button/copy-link-button.d.ts +55 -17
  65. package/dist/types/components/cta-component/cta-component.d.ts +89 -0
  66. package/dist/types/components/global-container/global-container.d.ts +43 -9
  67. package/dist/types/components/image-component/image-component.d.ts +46 -9
  68. package/dist/types/components/partner-stat-component/partner-stat-component.d.ts +52 -16
  69. package/dist/types/components/progress-indicator/progress-indicator.d.ts +91 -0
  70. package/dist/types/components/referral-code/referral-code.d.ts +12 -6
  71. package/dist/types/components/referral-component/referral-component.d.ts +46 -17
  72. package/dist/types/components/referral-list/referral-list.d.ts +242 -44
  73. package/dist/types/components/rewards-actions/rewards-actions.d.ts +25 -6
  74. package/dist/types/components/share-button/share-button.d.ts +80 -17
  75. package/dist/types/components/share-button-container/share-button-container.d.ts +611 -97
  76. package/dist/types/components/stat-component/stat-component.d.ts +50 -16
  77. package/dist/types/components/stats-container/stats-container.d.ts +47 -23
  78. package/dist/types/components/text-component/text-component.d.ts +74 -16
  79. package/dist/types/components.d.ts +2226 -2
  80. package/dist/types/global/global.d.ts +4 -4
  81. package/dist/types/saasquatch.d.ts +105 -103
  82. package/dist/types/services/FormatJs.d.ts +7 -7
  83. package/dist/types/services/WidgetHost.d.ts +51 -45
  84. package/dist/types/utilities.d.ts +7 -7
  85. package/dist/widget-components/entrypoint.js +32 -32
  86. package/dist/widget-components/p-0839fd2c.system.entry.js +10 -0
  87. package/dist/widget-components/{p-44a6559d.js → p-17d80384.js} +1 -1
  88. package/dist/widget-components/p-24fc4ba9.js +1 -1
  89. package/dist/widget-components/{p-650d012d.entry.js → p-3ba562d0.entry.js} +1 -1
  90. package/dist/widget-components/{p-d4b27c72.entry.js → p-4293e873.entry.js} +1 -1
  91. package/dist/widget-components/p-46109683.js +3 -3
  92. package/dist/widget-components/{p-9adc7c50.system.js → p-54e83dfb.system.js} +2 -2
  93. package/dist/widget-components/{p-e2b4739f.system.entry.js → p-665b8d42.system.entry.js} +1 -1
  94. package/dist/widget-components/{p-9525bf4a.js → p-6e753d23.js} +68 -3
  95. package/dist/widget-components/p-a952fcf2.entry.js +233 -0
  96. package/dist/widget-components/{p-a846f503.system.js → p-aaf44379.system.js} +1 -1
  97. package/dist/widget-components/{p-c0cdba77.system.entry.js → p-abf8a511.system.entry.js} +1 -1
  98. package/dist/widget-components/p-ad5121cf.system.js +1 -0
  99. package/dist/widget-components/{p-908068c2.system.entry.js → p-d9e9c55c.system.entry.js} +1 -1
  100. package/dist/widget-components/{p-58be1132.system.js → p-e82def83.system.js} +1 -1
  101. package/dist/widget-components/{p-9746ae26.entry.js → p-fb528be6.entry.js} +1 -1
  102. package/dist/widget-components/p-fbf0c7fe.js +1 -0
  103. package/dist/widget-components/widget-components.esm.js +1 -1
  104. package/dist/widget-components/widget-components.js +1 -1
  105. package/docs/raisins.json +1 -0
  106. package/package.json +97 -89
  107. package/readme.md +52 -52
  108. package/CHANGELOG.md +0 -143
  109. package/dist/widget-components/p-485eaf44.js +0 -1
  110. package/dist/widget-components/p-75ab4c57.entry.js +0 -148
  111. package/dist/widget-components/p-d2335c54.system.entry.js +0 -8
  112. package/dist/widget-components/p-e61a8100.system.js +0 -1
@@ -9910,621 +9910,778 @@ gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;
9910
9910
 
9911
9911
  var src = gql;
9912
9912
 
9913
- if (!window["widgetIdent"]) {
9914
- window["widgetIdent"] = {
9915
- env: "demo",
9916
- };
9917
- }
9918
- function widgetIdent() {
9919
- //@ts-ignore
9920
- return window.widgetIdent;
9921
- }
9922
- const today = new Date();
9923
- const demoUser = {
9924
- shareLink: "http://ssqt.co",
9925
- fueltankCode: "12AS3F",
9926
- referralcode: "RIDDIKULUS",
9927
- locale: "en_US",
9928
- messageLink: {
9929
- EMAIL: "http://short.staging.referralsaasquatch.com/mJjFXu",
9930
- FACEBOOK: "http://short.staging.referralsaasquatch.com/mwjFXu",
9931
- TWITTER: "http://short.staging.referralsaasquatch.com/mwjFXu",
9932
- SMS: "http://short.staging.referralsaasquatch.com/mwjFXu",
9933
- WHATSAPP: "http://short.staging.referralsaasquatch.com/mwjFXu",
9934
- LINKEDIN: "http://short.staging.referralsaasquatch.com/mwjFXu",
9935
- PINTEREST: "http://short.staging.referralsaasquatch.com/mwjFXu",
9936
- FBMESSENGER: "http://short.staging.referralsaasquatch.com/mwjFXu",
9937
- },
9938
- referrals: {
9939
- totalCount: 9,
9940
- data: [
9941
- {
9942
- dateReferralStarted: today.setDate(today.getDate() - 2),
9943
- referredUser: { firstName: "Remus", lastName: "Lupin" },
9944
- rewards: [
9945
- {
9946
- prettyValue: "$20.00",
9947
- dateExpires: today.setDate(today.getDate() + 4),
9948
- statuses: ["EXPIRED"],
9949
- meta: { message: "Applied to Invoice #1234" },
9950
- },
9951
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
9952
- { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
9953
- ],
9954
- },
9955
- {
9956
- dateReferralStarted: today.setDate(today.getDate() - 1),
9957
- referredUser: { firstName: "Gellert", lastName: "Grindelwald" },
9958
- rewards: [],
9959
- },
9960
- // Blank string becomes an unknown user, which is editable
9961
- {
9962
- dateReferralStarted: today.setDate(today.getDate() - 1),
9963
- referredUser: { firstName: "", lastName: "" },
9964
- rewards: [
9965
- {
9966
- prettyValue: "$20.00",
9967
- dateExpires: today.setDate(today.getDate() - 2),
9968
- statuses: ["EXPIRED"],
9969
- },
9970
- ],
9971
- },
9972
- {
9973
- dateReferralStarted: today.setDate(today.getDate() - 5),
9974
- referredUser: { firstName: "Lavender", lastName: "Brown" },
9975
- rewards: [{ prettyValue: "$20.00", statuses: ["CANCELLED"] }],
9976
- },
9977
- {
9978
- dateReferralStarted: today.setDate(today.getDate() - 4),
9979
- referredUser: { firstName: "Blaise", lastName: "Zabini" },
9980
- rewards: [
9981
- { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
9982
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
9983
- ],
9984
- },
9985
- {
9986
- dateReferralStarted: today.setDate(today.getDate() - 10),
9987
- referredUser: { firstName: "Argus", lastName: "Filch" },
9988
- rewards: [],
9989
- },
9990
- {
9991
- dateReferralStarted: today.setDate(today.getDate() - 15),
9992
- referredUser: { firstName: "Ron", lastName: "Weasley" },
9993
- rewards: [{ prettyValue: "$20.00", statuses: ["AVAILABLE"] }],
9994
- },
9995
- {
9996
- dateReferralStarted: today.setDate(today.getDate() - 2),
9997
- referredUser: { firstName: "Hermione", lastName: "Granger" },
9998
- rewards: [
9999
- { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
10000
- { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
10001
- { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
10002
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
10003
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
10004
- { prettyValue: "5%", statuses: ["AVAILABLE"] },
10005
- ],
10006
- },
10007
- {
10008
- dateConverted: 1606943971468,
10009
- dateReferralStarted: 1606943971468,
10010
- referredUser: {
10011
- imageUrl: "",
10012
- firstName: "Seamus",
10013
- lastName: "Finnigan",
10014
- },
10015
- rewards: [],
10016
- },
10017
- ],
10018
- },
10019
- referredByReferral: {
10020
- dateReferralStarted: today.setDate(today.getDate() - 2),
10021
- referrerUser: {
10022
- firstName: "Rubeus",
10023
- lastName: "Hagrid",
10024
- referralCode: "RUBEUSHAGRID12",
10025
- },
10026
- rewards: [
10027
- {
10028
- fuelTankCode: "CODE1234",
10029
- prettyValue: "$10.00",
10030
- statuses: ["AVAILABLE"],
10031
- },
10032
- ],
10033
- },
10034
- referralsMonth: { totalCount: 6 },
10035
- referralsWeek: { totalCount: 3 },
10036
- rewardsCount: { totalCount: 14 },
10037
- rewardsMonth: { totalCount: 7 },
10038
- rewardsWeek: { totalCount: 4 },
10039
- rewardBalancesGlobal: [
10040
- {
10041
- type: "CREDIT",
10042
- unit: "CENTS",
10043
- value: 17000,
10044
- prettyValue: "$170.00",
10045
- totalAssignedCredit: "17000",
10046
- totalRedeemedCredit: "1500",
10047
- prettyAssignedCredit: "$1000.00",
10048
- prettyRedeemedCredit: "$15.00",
10049
- },
10050
- { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
10051
- {
10052
- type: "CREDIT",
10053
- unit: "CASH/CAD",
10054
- count: 3,
10055
- totalPendingCredit: 20000,
10056
- totalAssignedCredit: 30000,
10057
- totalRedeemedCredit: 10000,
10058
- totalExpiredCredit: 0,
10059
- totalCancelledCredit: 0,
10060
- prettyPendingCredit: "$200.00",
10061
- prettyAssignedCredit: "$300.00",
10062
- prettyRedeemedCredit: "$100.00",
10063
- value: 30000,
10064
- prettyValue: "$300.00",
10065
- },
10066
- {
10067
- type: "CREDIT",
10068
- unit: "CASH/USD",
10069
- count: 6,
10070
- totalPendingCredit: 25000,
10071
- totalAssignedCredit: 40000,
10072
- totalRedeemedCredit: 10000,
10073
- totalExpiredCredit: 15000,
10074
- totalCancelledCredit: 10000,
10075
- prettyPendingCredit: "USD250.00",
10076
- prettyAssignedCredit: "USD400.00",
10077
- prettyRedeemedCredit: "USD150.00",
10078
- value: 40000,
10079
- prettyValue: "USD400.00",
10080
- },
10081
- ],
10082
- rewardBalances: [
10083
- {
10084
- type: "CREDIT",
10085
- unit: "CENTS",
10086
- value: 17000,
10087
- prettyValue: "$170.00",
10088
- totalAssignedCredit: "17000",
10089
- totalRedeemedCredit: "1500",
10090
- prettyAssignedCredit: "$170.00",
10091
- prettyRedeemedCredit: "$15.00",
10092
- },
10093
- { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
10094
- {
10095
- type: "CREDIT",
10096
- unit: "CASH/CAD",
10097
- count: 3,
10098
- totalPendingCredit: 20000,
10099
- totalAssignedCredit: 30000,
10100
- totalRedeemedCredit: 10000,
10101
- totalExpiredCredit: 0,
10102
- totalCancelledCredit: 0,
10103
- prettyPendingCredit: "$200.00",
10104
- prettyAssignedCredit: "$300.00",
10105
- prettyRedeemedCredit: "$100.00",
10106
- value: 30000,
10107
- prettyValue: "$300.00",
10108
- },
10109
- {
10110
- type: "CREDIT",
10111
- unit: "CASH/USD",
10112
- count: 6,
10113
- totalPendingCredit: 25000,
10114
- totalAssignedCredit: 40000,
10115
- totalRedeemedCredit: 10000,
10116
- totalExpiredCredit: 15000,
10117
- totalCancelledCredit: 10000,
10118
- prettyPendingCredit: "USD250.00",
10119
- prettyAssignedCredit: "USD400.00",
10120
- prettyRedeemedCredit: "USD150.00",
10121
- value: 40000,
10122
- prettyValue: "USD400.00",
10123
- },
10124
- ],
10125
- rewardBalanceDetails: [
10126
- {
10127
- prettyAvailableValue: "$5.00",
10128
- },
10129
- {
10130
- prettyAvailableValue: "18%",
10131
- },
10132
- ],
10133
- };
10134
- //@ts-ignore
10135
- const squatchJsApi = window.frameElement
10136
- ? window.frameElement.squatchJsApi
10137
- : {};
10138
- const apolloClient = () => {
10139
- const { tenantAlias, appDomain, token } = widgetIdent();
10140
- const uri = appDomain + "/api/v1/" + tenantAlias + "/graphql";
10141
- const headers = {
10142
- Authorization: `Bearer ${token}`,
10143
- };
10144
- const client = new ApolloClient({
10145
- link: new HttpLink({ uri, headers }),
10146
- cache: new InMemoryCache(),
10147
- });
10148
- return client;
10149
- };
10150
- const API = {
10151
- version: "Welcome to widget-host",
10152
- analytics: {
10153
- shareEvent(shareMedium) {
10154
- const widgetId = widgetIdent();
10155
- if (widgetId["env"] === "demo" || !widgetId)
10156
- return Promise.resolve({});
10157
- const { userId, accountId, programId = "classic", engagementMedium, } = widgetId;
10158
- const variables = {
10159
- eventMeta: {
10160
- id: userId,
10161
- accountId,
10162
- programId,
10163
- type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",
10164
- meta: {
10165
- engagementMedium,
10166
- shareMedium,
10167
- },
10168
- },
10169
- };
10170
- return apolloClient()
10171
- .mutate({
10172
- mutation: src `
10173
- mutation ($eventMeta: UserAnalyticsEvent!) {
10174
- createUserAnalyticsEvent(eventMeta: $eventMeta)
10175
- }
10176
- `,
10177
- variables,
10178
- })
10179
- .then((result) => {
10180
- return result.data.createUserAnalyticsEvent;
10181
- });
10182
- },
10183
- loadEvent() {
10184
- return Promise.resolve({ event: "loadEvent" });
10185
- },
10186
- },
10187
- graphql: {
10188
- getClient() {
10189
- return apolloClient();
10190
- },
10191
- getUserFragment(userFragment, fragmentVariables) {
10192
- const fragment = src `
10193
- fragment UserFragment on User {
10194
- ${userFragment}
10195
- }`;
10196
- const { userId, accountId } = widgetIdent();
10197
- const variables = Object.assign(Object.assign({}, fragmentVariables), { userId,
10198
- accountId });
10199
- return this.getClient().query({
10200
- query: src `
10201
- query ($userId: String!, $accountId: String!, $offset: Int) {
10202
- user(id: $userId, accountId: $accountId) {
10203
- ...UserFragment
10204
- }
10205
- }
10206
- ${fragment}
10207
- `,
10208
- variables,
10209
- });
10210
- },
10211
- getShareLink() {
10212
- const widgetId = widgetIdent();
10213
- if (widgetId["env"] === "demo" || !widgetId)
10214
- return Promise.resolve(demoUser.shareLink);
10215
- const { userId, accountId, programId = null, engagementMedium, } = widgetId;
10216
- const variables = {
10217
- userId,
10218
- accountId,
10219
- programId,
10220
- engagementMedium,
10221
- };
10222
- return this.getClient()
10223
- .query({
10224
- query: src `
10225
- query (
10226
- $userId: String!
10227
- $accountId: String!
10228
- $programId: ID
10229
- $engagementMedium: UserEngagementMedium!
10230
- ) {
10231
- user(id: $userId, accountId: $accountId) {
10232
- shareLink(
10233
- programId: $programId
10234
- engagementMedium: $engagementMedium
10235
- shareMedium: DIRECT
10236
- useCleanLink: true
10237
- )
10238
- }
10239
- }
10240
- `,
10241
- variables,
10242
- })
10243
- .then((res) => res.data.user.shareLink);
10244
- },
10245
- getReferrals(showReferrer, offset = 0, limit = 3) {
10246
- const widgetId = widgetIdent();
10247
- if (widgetId["env"] === "demo" || !widgetId) {
10248
- const { referrals: refs, referredByReferral, locale } = demoUser;
10249
- const referrals = {
10250
- totalCount: refs.totalCount,
10251
- data: refs.data.slice(offset, offset + limit),
10252
- };
10253
- const user = { referrals, referredByReferral, locale };
10254
- return Promise.resolve(user);
10255
- }
10256
- const { userId, accountId, programId = null } = widgetId;
10257
- const variables = {
10258
- limit,
10259
- offset,
10260
- userId,
10261
- accountId,
10262
- programId,
10263
- programId_exists: programId ? true : false,
10264
- };
10265
- return this.getClient()
10266
- .query({
10267
- query: src `
10268
- query (
10269
- $userId: String!
10270
- $accountId: String!
10271
- $offset: Int!
10272
- $limit: Int!
10273
- $programId: ID
10274
- $programId_exists: Boolean!
10275
- ) {
10276
- user(id: $userId, accountId: $accountId) {
10277
- locale
10278
- referrals(
10279
- limit: $limit
10280
- offset: $offset
10281
- filter: {
10282
- programId_eq: $programId
10283
- programId_exists: $programId_exists
10284
- }
10285
- ) {
10286
- totalCount
10287
- data {
10288
- dateConverted
10289
- dateReferralStarted
10290
- referredUser {
10291
- firstName
10292
- lastName
10293
- }
10294
- rewards(
10295
- filter: { userId_eq: $userId, accountId_eq: $accountId }
10296
- ) {
10297
- prettyValue
10298
- dateExpires
10299
- statuses
10300
- meta {
10301
- message
10302
- }
10303
- }
10304
- }
10305
- }
10306
- ${showReferrer
10307
- ? `referredByReferral(programId: $programId) {
10308
- referrerUser {
10309
- firstName
10310
- lastName
10311
- }
10312
- dateReferralStarted
10313
- rewards(
10314
- filter: { userId_eq: $userId, accountId_eq: $accountId }
10315
- ) {
10316
- prettyValue
10317
- statuses
10318
- }
10319
- }`
10320
- : ""}
10321
- }
10322
- }
10323
- `,
10324
- variables,
10325
- })
10326
- .then((res) => res.data.user);
10327
- },
10328
- getStats() {
10329
- const widgetId = widgetIdent();
10330
- if (widgetId["env"] === "demo" || !widgetId) {
10331
- const { referrals: referralsCount, referralsMonth, referralsWeek, rewardsCount, rewardsMonth, rewardsWeek, rewardBalances, rewardBalancesGlobal, } = demoUser;
10332
- const user = {
10333
- referralsCount,
10334
- referralsMonth,
10335
- referralsWeek,
10336
- rewardsCount,
10337
- rewardsMonth,
10338
- rewardsWeek,
10339
- rewardBalances,
10340
- rewardBalancesGlobal,
10341
- };
10342
- return Promise.resolve(user);
10343
- }
10344
- const { userId, accountId, programId = null } = widgetId;
10345
- const variables = {
10346
- userId,
10347
- accountId,
10348
- programId,
10349
- programId_exists: programId ? true : false,
10350
- };
10351
- return this.getClient()
10352
- .query({
10353
- query: src `
10354
- query (
10355
- $userId: String!
10356
- $accountId: String!
10357
- $programId: ID
10358
- $programId_exists: Boolean!
10359
- ) {
10360
- user(id: $userId, accountId: $accountId) {
10361
- referralsCount: referrals(
10362
- filter: {
10363
- programId_eq: $programId
10364
- programId_exists: $programId_exists
10365
- }
10366
- ) {
10367
- totalCount
10368
- }
10369
- referralsMonth: referrals(
10370
- filter: {
10371
- programId_eq: $programId
10372
- programId_exists: $programId_exists
10373
- dateReferralStarted_timeframe: "this_month"
10374
- }
10375
- ) {
10376
- totalCount
10377
- }
10378
- referralsWeek: referrals(
10379
- filter: {
10380
- programId_eq: $programId
10381
- programId_exists: $programId_exists
10382
- dateReferralStarted_timeframe: "this_week"
10383
- }
10384
- ) {
10385
- totalCount
10386
- }
10387
- rewardsCount: rewards(
10388
- filter: {
10389
- programId_eq: $programId
10390
- programId_exists: $programId_exists
10391
- }
10392
- ) {
10393
- totalCount
10394
- }
10395
- rewardsMonth: rewards(
10396
- filter: {
10397
- programId_eq: $programId
10398
- programId_exists: $programId_exists
10399
- dateGiven_timeframe: "this_month"
10400
- }
10401
- ) {
10402
- totalCount
10403
- }
10404
- rewardsWeek: rewards(
10405
- filter: {
10406
- programId_eq: $programId
10407
- programId_exists: $programId_exists
10408
- dateGiven_timeframe: "this_week"
10409
- }
10410
- ) {
10411
- totalCount
10412
- }
10413
- rewardBalances(programId: $programId)
10414
- rewardBalancesGlobal: rewardBalances
10415
- }
10416
- }
10417
- `,
10418
- variables,
10419
- })
10420
- .then((res) => res.data.user);
10421
- },
10422
- async getReferralCode() {
10423
- const widgetId = widgetIdent();
10424
- if (widgetId["env"] === "demo" || !widgetId)
10425
- return demoUser.referralcode;
10426
- const { userId, accountId, programId } = widgetId;
10427
- const variables = {
10428
- userId,
10429
- accountId,
10430
- programId,
10431
- };
10432
- return this.getClient()
10433
- .query({
10434
- query: src `
10435
- query ($userId: String!, $accountId: String!, $programId: ID!) {
10436
- user(id: $userId, accountId: $accountId) {
10437
- referralCode(programId: $programId)
10438
- }
10439
- }
10440
- `,
10441
- variables,
10442
- })
10443
- .then((res) => res.data.user.referralCode);
10444
- },
10445
- async getFueltankCode(rewardKey) {
10446
- const widgetId = widgetIdent();
10447
- if (widgetId["env"] === "demo" || !widgetId) {
10448
- return {
10449
- referredByReferral: demoUser.referredByReferral,
10450
- rewards: { data: demoUser.referredByReferral.rewards },
10451
- };
10452
- }
10453
- const { userId, accountId, programId } = widgetId;
10454
- const variables = {
10455
- userId,
10456
- accountId,
10457
- programId,
10458
- rewardKey,
10459
- };
10460
- return this.getClient()
10461
- .query({
10462
- query: src `
10463
- query (
10464
- $userId: String!
10465
- $accountId: String!
10466
- $programId: ID!
10467
- $rewardKey: String!
10468
- ) {
10469
- user(id: $userId, accountId: $accountId) {
10470
- referredByReferral(programId: $programId) {
10471
- referrerUser {
10472
- referralCode(programId: $programId)
10473
- }
10474
- }
10475
- rewards(
10476
- filter: {
10477
- programId_eq: $programId
10478
- programRewardKey_eq: $rewardKey
10479
- }
10480
- ) {
10481
- count
10482
- totalCount
10483
- data {
10484
- fuelTankCode
10485
- }
10486
- }
10487
- }
10488
- }
10489
- `,
10490
- variables,
10491
- })
10492
- .then((res) => res.data.user);
10493
- },
10494
- getMessageLinks(mediums) {
10495
- const widgetId = widgetIdent();
10496
- if (widgetId["env"] === "demo" || !widgetId)
10497
- return Promise.resolve(demoUser.messageLink);
10498
- const { userId, accountId, programId = null, engagementMedium, } = widgetId;
10499
- const variables = {
10500
- userId,
10501
- accountId,
10502
- programId,
10503
- engagementMedium,
10504
- };
10505
- return this.getClient()
10506
- .query({
10507
- query: src `
10508
- query($userId: String!, $accountId: String!, $programId: ID, $engagementMedium: UserEngagementMedium!) {
10509
- user(id: $userId, accountId: $accountId) {
10510
- ${mediums[0]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[0]})
10511
- ${mediums[1]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[1]})
10512
- ${mediums[2]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[2]})
10513
- ${mediums[3]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[3]})
10514
- ${mediums[4]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[4]})
10515
- ${mediums[5]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[5]})
10516
- ${mediums[6]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[6]})
10517
- ${mediums[7]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[7]})
10518
- ${mediums[8]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[8]})
10519
- }
10520
- }
10521
- `,
10522
- variables,
10523
- })
10524
- .then((res) => res.data.user);
10525
- },
10526
- },
10527
- ui: squatchJsApi,
9913
+ if (!window["widgetIdent"]) {
9914
+ window["widgetIdent"] = {
9915
+ env: "demo",
9916
+ };
9917
+ }
9918
+ function widgetIdent() {
9919
+ //@ts-ignore
9920
+ return window.widgetIdent;
9921
+ }
9922
+ const today = new Date();
9923
+ const demoUser = {
9924
+ shareLink: "http://ssqt.co",
9925
+ fueltankCode: "12AS3F",
9926
+ referralcode: "RIDDIKULUS",
9927
+ locale: "en_US",
9928
+ messageLink: {
9929
+ EMAIL: "http://short.staging.referralsaasquatch.com/mJjFXu",
9930
+ FACEBOOK: "http://short.staging.referralsaasquatch.com/mwjFXu",
9931
+ TWITTER: "http://short.staging.referralsaasquatch.com/mwjFXu",
9932
+ SMS: "http://short.staging.referralsaasquatch.com/mwjFXu",
9933
+ WHATSAPP: "http://short.staging.referralsaasquatch.com/mwjFXu",
9934
+ LINKEDIN: "http://short.staging.referralsaasquatch.com/mwjFXu",
9935
+ PINTEREST: "http://short.staging.referralsaasquatch.com/mwjFXu",
9936
+ FBMESSENGER: "http://short.staging.referralsaasquatch.com/mwjFXu",
9937
+ },
9938
+ referrals: {
9939
+ totalCount: 9,
9940
+ data: [
9941
+ {
9942
+ dateReferralStarted: today.setDate(today.getDate() - 2),
9943
+ referredUser: { firstName: "Remus", lastName: "Lupin" },
9944
+ rewards: [
9945
+ {
9946
+ prettyValue: "$20.00",
9947
+ dateExpires: today.setDate(today.getDate() + 4),
9948
+ statuses: ["EXPIRED"],
9949
+ meta: { message: "Applied to Invoice #1234" },
9950
+ },
9951
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
9952
+ { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
9953
+ ],
9954
+ },
9955
+ {
9956
+ dateReferralStarted: today.setDate(today.getDate() - 1),
9957
+ referredUser: { firstName: "Gellert", lastName: "Grindelwald" },
9958
+ rewards: [],
9959
+ },
9960
+ // Blank string becomes an unknown user, which is editable
9961
+ {
9962
+ dateReferralStarted: today.setDate(today.getDate() - 1),
9963
+ referredUser: { firstName: "", lastName: "" },
9964
+ rewards: [
9965
+ {
9966
+ prettyValue: "$20.00",
9967
+ dateExpires: today.setDate(today.getDate() - 2),
9968
+ statuses: ["EXPIRED"],
9969
+ },
9970
+ ],
9971
+ },
9972
+ {
9973
+ dateReferralStarted: today.setDate(today.getDate() - 5),
9974
+ referredUser: { firstName: "Lavender", lastName: "Brown" },
9975
+ rewards: [{ prettyValue: "$20.00", statuses: ["CANCELLED"] }],
9976
+ },
9977
+ {
9978
+ dateReferralStarted: today.setDate(today.getDate() - 4),
9979
+ referredUser: { firstName: "Blaise", lastName: "Zabini" },
9980
+ rewards: [
9981
+ { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
9982
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
9983
+ ],
9984
+ },
9985
+ {
9986
+ dateReferralStarted: today.setDate(today.getDate() - 10),
9987
+ referredUser: { firstName: "Argus", lastName: "Filch" },
9988
+ rewards: [],
9989
+ },
9990
+ {
9991
+ dateReferralStarted: today.setDate(today.getDate() - 15),
9992
+ referredUser: { firstName: "Ron", lastName: "Weasley" },
9993
+ rewards: [{ prettyValue: "$20.00", statuses: ["AVAILABLE"] }],
9994
+ },
9995
+ {
9996
+ dateReferralStarted: today.setDate(today.getDate() - 2),
9997
+ referredUser: { firstName: "Hermione", lastName: "Granger" },
9998
+ rewards: [
9999
+ { prettyValue: "$20.00", statuses: ["AVAILABLE"] },
10000
+ { prettyValue: "$10.00", statuses: ["AVAILABLE"] },
10001
+ { prettyValue: "$5.00", statuses: ["AVAILABLE"] },
10002
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
10003
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
10004
+ { prettyValue: "5%", statuses: ["AVAILABLE"] },
10005
+ ],
10006
+ },
10007
+ {
10008
+ dateConverted: 1606943971468,
10009
+ dateReferralStarted: 1606943971468,
10010
+ referredUser: {
10011
+ imageUrl: "",
10012
+ firstName: "Seamus",
10013
+ lastName: "Finnigan",
10014
+ },
10015
+ rewards: [],
10016
+ },
10017
+ ],
10018
+ },
10019
+ referredByReferral: {
10020
+ dateReferralStarted: today.setDate(today.getDate() - 2),
10021
+ referrerUser: {
10022
+ firstName: "Rubeus",
10023
+ lastName: "Hagrid",
10024
+ referralCode: "RUBEUSHAGRID12",
10025
+ },
10026
+ rewards: [
10027
+ {
10028
+ fuelTankCode: "CODE1234",
10029
+ prettyValue: "$10.00",
10030
+ statuses: ["AVAILABLE"],
10031
+ },
10032
+ ],
10033
+ },
10034
+ referralsMonth: { totalCount: 6 },
10035
+ referralsWeek: { totalCount: 3 },
10036
+ rewardsCount: { totalCount: 14 },
10037
+ rewardsMonth: { totalCount: 7 },
10038
+ rewardsWeek: { totalCount: 4 },
10039
+ rewardBalancesGlobal: [
10040
+ {
10041
+ type: "CREDIT",
10042
+ unit: "CENTS",
10043
+ value: 17000,
10044
+ prettyValue: "$170.00",
10045
+ totalAssignedCredit: "17000",
10046
+ totalRedeemedCredit: "1500",
10047
+ prettyAssignedCredit: "$1000.00",
10048
+ prettyRedeemedCredit: "$15.00",
10049
+ },
10050
+ { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
10051
+ {
10052
+ type: "CREDIT",
10053
+ unit: "CASH/CAD",
10054
+ count: 3,
10055
+ totalPendingCredit: 20000,
10056
+ totalAssignedCredit: 30000,
10057
+ totalRedeemedCredit: 10000,
10058
+ totalExpiredCredit: 0,
10059
+ totalCancelledCredit: 0,
10060
+ prettyPendingCredit: "$200.00",
10061
+ prettyAssignedCredit: "$300.00",
10062
+ prettyRedeemedCredit: "$100.00",
10063
+ value: 30000,
10064
+ prettyValue: "$300.00",
10065
+ },
10066
+ {
10067
+ type: "CREDIT",
10068
+ unit: "CASH/USD",
10069
+ count: 6,
10070
+ totalPendingCredit: 25000,
10071
+ totalAssignedCredit: 40000,
10072
+ totalRedeemedCredit: 10000,
10073
+ totalExpiredCredit: 15000,
10074
+ totalCancelledCredit: 10000,
10075
+ prettyPendingCredit: "USD250.00",
10076
+ prettyAssignedCredit: "USD400.00",
10077
+ prettyRedeemedCredit: "USD150.00",
10078
+ value: 40000,
10079
+ prettyValue: "USD400.00",
10080
+ },
10081
+ ],
10082
+ rewardBalances: [
10083
+ {
10084
+ type: "CREDIT",
10085
+ unit: "CENTS",
10086
+ value: 17000,
10087
+ prettyValue: "$170.00",
10088
+ totalAssignedCredit: "17000",
10089
+ totalRedeemedCredit: "1500",
10090
+ prettyAssignedCredit: "$170.00",
10091
+ prettyRedeemedCredit: "$15.00",
10092
+ },
10093
+ { type: "PCT_DISCOUNT", unit: "%", value: 15, prettyValue: "15%" },
10094
+ {
10095
+ type: "CREDIT",
10096
+ unit: "CASH/CAD",
10097
+ count: 3,
10098
+ totalPendingCredit: 20000,
10099
+ totalAssignedCredit: 30000,
10100
+ totalRedeemedCredit: 10000,
10101
+ totalExpiredCredit: 0,
10102
+ totalCancelledCredit: 0,
10103
+ prettyPendingCredit: "$200.00",
10104
+ prettyAssignedCredit: "$300.00",
10105
+ prettyRedeemedCredit: "$100.00",
10106
+ value: 30000,
10107
+ prettyValue: "$300.00",
10108
+ },
10109
+ {
10110
+ type: "CREDIT",
10111
+ unit: "CASH/USD",
10112
+ count: 6,
10113
+ totalPendingCredit: 25000,
10114
+ totalAssignedCredit: 40000,
10115
+ totalRedeemedCredit: 10000,
10116
+ totalExpiredCredit: 15000,
10117
+ totalCancelledCredit: 10000,
10118
+ prettyPendingCredit: "USD250.00",
10119
+ prettyAssignedCredit: "USD400.00",
10120
+ prettyRedeemedCredit: "USD150.00",
10121
+ value: 40000,
10122
+ prettyValue: "USD400.00",
10123
+ },
10124
+ ],
10125
+ rewardBalanceDetails: [
10126
+ {
10127
+ prettyAvailableValue: "$5.00",
10128
+ },
10129
+ {
10130
+ prettyAvailableValue: "18%",
10131
+ },
10132
+ ],
10133
+ };
10134
+ //@ts-ignore
10135
+ const squatchJsApi = window.frameElement
10136
+ ? window.frameElement.squatchJsApi
10137
+ : {};
10138
+ const apolloClient = () => {
10139
+ const { tenantAlias, appDomain, token } = widgetIdent();
10140
+ const uri = appDomain + "/api/v1/" + tenantAlias + "/graphql";
10141
+ const headers = {
10142
+ Authorization: `Bearer ${token}`,
10143
+ };
10144
+ const client = new ApolloClient({
10145
+ link: new HttpLink({ uri, headers }),
10146
+ cache: new InMemoryCache(),
10147
+ });
10148
+ return client;
10149
+ };
10150
+ const API = {
10151
+ version: "Welcome to widget-host",
10152
+ analytics: {
10153
+ shareEvent(shareMedium) {
10154
+ const widgetId = widgetIdent();
10155
+ if (widgetId["env"] === "demo" || !widgetId)
10156
+ return Promise.resolve({});
10157
+ const { userId, accountId, programId = "classic", engagementMedium, } = widgetId;
10158
+ const variables = {
10159
+ eventMeta: {
10160
+ id: userId,
10161
+ accountId,
10162
+ programId,
10163
+ type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",
10164
+ meta: {
10165
+ engagementMedium,
10166
+ shareMedium,
10167
+ },
10168
+ },
10169
+ };
10170
+ return apolloClient()
10171
+ .mutate({
10172
+ mutation: src `
10173
+ mutation ($eventMeta: UserAnalyticsEvent!) {
10174
+ createUserAnalyticsEvent(eventMeta: $eventMeta)
10175
+ }
10176
+ `,
10177
+ variables,
10178
+ })
10179
+ .then((result) => {
10180
+ return result.data.createUserAnalyticsEvent;
10181
+ });
10182
+ },
10183
+ loadEvent() {
10184
+ return Promise.resolve({ event: "loadEvent" });
10185
+ },
10186
+ },
10187
+ graphql: {
10188
+ getClient() {
10189
+ return apolloClient();
10190
+ },
10191
+ getUserFragment(userFragment, fragmentVariables) {
10192
+ const fragment = src `
10193
+ fragment UserFragment on User {
10194
+ ${userFragment}
10195
+ }`;
10196
+ const { userId, accountId } = widgetIdent();
10197
+ const variables = Object.assign(Object.assign({}, fragmentVariables), { userId,
10198
+ accountId });
10199
+ return this.getClient().query({
10200
+ query: src `
10201
+ query ($userId: String!, $accountId: String!, $offset: Int) {
10202
+ user(id: $userId, accountId: $accountId) {
10203
+ ...UserFragment
10204
+ }
10205
+ }
10206
+ ${fragment}
10207
+ `,
10208
+ variables,
10209
+ });
10210
+ },
10211
+ getShareLink() {
10212
+ const widgetId = widgetIdent();
10213
+ if (widgetId["env"] === "demo" || !widgetId)
10214
+ return Promise.resolve(demoUser.shareLink);
10215
+ const { userId, accountId, programId = null, engagementMedium, } = widgetId;
10216
+ const variables = {
10217
+ userId,
10218
+ accountId,
10219
+ programId,
10220
+ engagementMedium,
10221
+ };
10222
+ return this.getClient()
10223
+ .query({
10224
+ query: src `
10225
+ query (
10226
+ $userId: String!
10227
+ $accountId: String!
10228
+ $programId: ID
10229
+ $engagementMedium: UserEngagementMedium!
10230
+ ) {
10231
+ user(id: $userId, accountId: $accountId) {
10232
+ shareLink(
10233
+ programId: $programId
10234
+ engagementMedium: $engagementMedium
10235
+ shareMedium: DIRECT
10236
+ useCleanLink: true
10237
+ )
10238
+ }
10239
+ }
10240
+ `,
10241
+ variables,
10242
+ })
10243
+ .then((res) => res.data.user.shareLink);
10244
+ },
10245
+ getReferrals(showReferrer, offset = 0, limit = 3) {
10246
+ const widgetId = widgetIdent();
10247
+ if (widgetId["env"] === "demo" || !widgetId) {
10248
+ const { referrals: refs, referredByReferral, locale } = demoUser;
10249
+ const referrals = {
10250
+ totalCount: refs.totalCount,
10251
+ data: refs.data.slice(offset, offset + limit),
10252
+ };
10253
+ const user = { referrals, referredByReferral, locale };
10254
+ return Promise.resolve(user);
10255
+ }
10256
+ const { userId, accountId, programId = null } = widgetId;
10257
+ const variables = {
10258
+ limit,
10259
+ offset,
10260
+ userId,
10261
+ accountId,
10262
+ programId,
10263
+ programId_exists: programId ? true : false,
10264
+ };
10265
+ return this.getClient()
10266
+ .query({
10267
+ query: src `
10268
+ query (
10269
+ $userId: String!
10270
+ $accountId: String!
10271
+ $offset: Int!
10272
+ $limit: Int!
10273
+ $programId: ID
10274
+ $programId_exists: Boolean!
10275
+ ) {
10276
+ user(id: $userId, accountId: $accountId) {
10277
+ locale
10278
+ referrals(
10279
+ limit: $limit
10280
+ offset: $offset
10281
+ filter: {
10282
+ programId_eq: $programId
10283
+ programId_exists: $programId_exists
10284
+ }
10285
+ ) {
10286
+ totalCount
10287
+ data {
10288
+ dateConverted
10289
+ dateReferralStarted
10290
+ referredUser {
10291
+ firstName
10292
+ lastName
10293
+ }
10294
+ rewards(
10295
+ filter: { userId_eq: $userId, accountId_eq: $accountId }
10296
+ ) {
10297
+ prettyValue
10298
+ dateExpires
10299
+ statuses
10300
+ meta {
10301
+ message
10302
+ }
10303
+ }
10304
+ }
10305
+ }
10306
+ ${showReferrer
10307
+ ? `referredByReferral(programId: $programId) {
10308
+ referrerUser {
10309
+ firstName
10310
+ lastName
10311
+ }
10312
+ dateReferralStarted
10313
+ rewards(
10314
+ filter: { userId_eq: $userId, accountId_eq: $accountId }
10315
+ ) {
10316
+ prettyValue
10317
+ statuses
10318
+ }
10319
+ }`
10320
+ : ""}
10321
+ }
10322
+ }
10323
+ `,
10324
+ variables,
10325
+ })
10326
+ .then((res) => res.data.user);
10327
+ },
10328
+ getStats() {
10329
+ const widgetId = widgetIdent();
10330
+ if (widgetId["env"] === "demo" || !widgetId) {
10331
+ const { referrals: referralsCount, referralsMonth, referralsWeek, rewardsCount, rewardsMonth, rewardsWeek, rewardBalances, rewardBalancesGlobal, } = demoUser;
10332
+ const user = {
10333
+ referralsCount,
10334
+ referralsMonth,
10335
+ referralsWeek,
10336
+ rewardsCount,
10337
+ rewardsMonth,
10338
+ rewardsWeek,
10339
+ rewardBalances,
10340
+ rewardBalancesGlobal,
10341
+ };
10342
+ return Promise.resolve(user);
10343
+ }
10344
+ const { userId, accountId, programId = null } = widgetId;
10345
+ const variables = {
10346
+ userId,
10347
+ accountId,
10348
+ programId,
10349
+ programId_exists: programId ? true : false,
10350
+ };
10351
+ return this.getClient()
10352
+ .query({
10353
+ query: src `
10354
+ query (
10355
+ $userId: String!
10356
+ $accountId: String!
10357
+ $programId: ID
10358
+ $programId_exists: Boolean!
10359
+ ) {
10360
+ user(id: $userId, accountId: $accountId) {
10361
+ referralsCount: referrals(
10362
+ filter: {
10363
+ programId_eq: $programId
10364
+ programId_exists: $programId_exists
10365
+ }
10366
+ ) {
10367
+ totalCount
10368
+ }
10369
+ referralsMonth: referrals(
10370
+ filter: {
10371
+ programId_eq: $programId
10372
+ programId_exists: $programId_exists
10373
+ dateReferralStarted_timeframe: "this_month"
10374
+ }
10375
+ ) {
10376
+ totalCount
10377
+ }
10378
+ referralsWeek: referrals(
10379
+ filter: {
10380
+ programId_eq: $programId
10381
+ programId_exists: $programId_exists
10382
+ dateReferralStarted_timeframe: "this_week"
10383
+ }
10384
+ ) {
10385
+ totalCount
10386
+ }
10387
+ rewardsCount: rewards(
10388
+ filter: {
10389
+ programId_eq: $programId
10390
+ programId_exists: $programId_exists
10391
+ }
10392
+ ) {
10393
+ totalCount
10394
+ }
10395
+ rewardsMonth: rewards(
10396
+ filter: {
10397
+ programId_eq: $programId
10398
+ programId_exists: $programId_exists
10399
+ dateGiven_timeframe: "this_month"
10400
+ }
10401
+ ) {
10402
+ totalCount
10403
+ }
10404
+ rewardsWeek: rewards(
10405
+ filter: {
10406
+ programId_eq: $programId
10407
+ programId_exists: $programId_exists
10408
+ dateGiven_timeframe: "this_week"
10409
+ }
10410
+ ) {
10411
+ totalCount
10412
+ }
10413
+ rewardBalances(programId: $programId)
10414
+ rewardBalancesGlobal: rewardBalances
10415
+ }
10416
+ }
10417
+ `,
10418
+ variables,
10419
+ })
10420
+ .then((res) => res.data.user);
10421
+ },
10422
+ getBalanceDetails() {
10423
+ const widgetId = widgetIdent();
10424
+ if (widgetId["env"] === "demo" || !widgetId) {
10425
+ const { rewardBalanceDetails } = demoUser;
10426
+ const user = {
10427
+ rewardBalanceDetails
10428
+ };
10429
+ return Promise.resolve(user);
10430
+ }
10431
+ const { userId, accountId, programId = null, locale } = widgetId;
10432
+ const variables = {
10433
+ userId,
10434
+ accountId,
10435
+ programId,
10436
+ locale
10437
+ };
10438
+ return this.getClient().query({
10439
+ query: src `
10440
+ query(
10441
+ $userId: String!,
10442
+ $accountId: String!,
10443
+ $programId: ID,
10444
+ $locale: String!
10445
+ ) {
10446
+ user(id: $userId, accountId: $accountId) {
10447
+ rewardBalanceDetails(programId: $programId) {
10448
+ prettyAvailableValue
10449
+ unit
10450
+ ... on CreditRewardBalance {
10451
+ prettyAssignedCredit
10452
+ prettyRedeemedCredit
10453
+ rewardUnit {
10454
+ currency {
10455
+ displayName(locale: $locale)
10456
+ symbol(locale: $locale)
10457
+ currencyCode
10458
+ }
10459
+ }
10460
+ }
10461
+ }
10462
+ }
10463
+ }
10464
+ `,
10465
+ variables
10466
+ }).then(res => res.data.user);
10467
+ },
10468
+ getRewardExpiries() {
10469
+ const widgetId = widgetIdent();
10470
+ if (widgetId["env"] === "demo" || !widgetId) {
10471
+ const { rewardBalanceDetails } = demoUser;
10472
+ const user = {
10473
+ rewardBalanceDetails
10474
+ };
10475
+ return Promise.resolve(user);
10476
+ }
10477
+ const { userId, accountId, programId = null, locale } = widgetId;
10478
+ const variables = {
10479
+ userId,
10480
+ accountId,
10481
+ programId,
10482
+ locale
10483
+ };
10484
+ return this.getClient().query({
10485
+ query: src `
10486
+ query(
10487
+ $userId: String!,
10488
+ $accountId: String!,
10489
+ $programId: ID,
10490
+ $locale: String!
10491
+ ) {
10492
+ user(id: $userId, accountId: $accountId) {
10493
+ rewards(programId_eq: $programId) {
10494
+ data {
10495
+ dateCreated
10496
+ dateScheduledFor
10497
+ dateExpires
10498
+ prettyValue
10499
+ unit
10500
+ }
10501
+ }
10502
+ }
10503
+ }
10504
+ `,
10505
+ variables
10506
+ }).then(res => res.data.user);
10507
+ },
10508
+ async getReferralCode() {
10509
+ const widgetId = widgetIdent();
10510
+ if (widgetId["env"] === "demo" || !widgetId)
10511
+ return demoUser.referralcode;
10512
+ const { userId, accountId, programId } = widgetId;
10513
+ const variables = {
10514
+ userId,
10515
+ accountId,
10516
+ programId,
10517
+ };
10518
+ return this.getClient()
10519
+ .query({
10520
+ query: src `
10521
+ query ($userId: String!, $accountId: String!, $programId: ID!) {
10522
+ user(id: $userId, accountId: $accountId) {
10523
+ referralCode(programId: $programId)
10524
+ }
10525
+ }
10526
+ `,
10527
+ variables,
10528
+ })
10529
+ .then((res) => res.data.user.referralCode);
10530
+ },
10531
+ async getFueltankCode(rewardKey) {
10532
+ const widgetId = widgetIdent();
10533
+ if (widgetId["env"] === "demo" || !widgetId) {
10534
+ return {
10535
+ referredByReferral: demoUser.referredByReferral,
10536
+ rewards: { data: demoUser.referredByReferral.rewards },
10537
+ };
10538
+ }
10539
+ const { userId, accountId, programId } = widgetId;
10540
+ const variables = {
10541
+ userId,
10542
+ accountId,
10543
+ programId,
10544
+ rewardKey,
10545
+ };
10546
+ return this.getClient()
10547
+ .query({
10548
+ query: src `
10549
+ query (
10550
+ $userId: String!
10551
+ $accountId: String!
10552
+ $programId: ID!
10553
+ $rewardKey: String!
10554
+ ) {
10555
+ user(id: $userId, accountId: $accountId) {
10556
+ referredByReferral(programId: $programId) {
10557
+ referrerUser {
10558
+ referralCode(programId: $programId)
10559
+ }
10560
+ }
10561
+ rewards(
10562
+ filter: {
10563
+ programId_eq: $programId
10564
+ programRewardKey_eq: $rewardKey
10565
+ }
10566
+ ) {
10567
+ count
10568
+ totalCount
10569
+ data {
10570
+ fuelTankCode
10571
+ }
10572
+ }
10573
+ }
10574
+ }
10575
+ `,
10576
+ variables,
10577
+ })
10578
+ .then((res) => res.data.user);
10579
+ },
10580
+ getMessageLinks(mediums) {
10581
+ const widgetId = widgetIdent();
10582
+ if (widgetId["env"] === "demo" || !widgetId)
10583
+ return Promise.resolve(demoUser.messageLink);
10584
+ const { userId, accountId, programId = null, engagementMedium, } = widgetId;
10585
+ const variables = {
10586
+ userId,
10587
+ accountId,
10588
+ programId,
10589
+ engagementMedium,
10590
+ };
10591
+ return this.getClient()
10592
+ .query({
10593
+ query: src `
10594
+ query($userId: String!, $accountId: String!, $programId: ID, $engagementMedium: UserEngagementMedium!) {
10595
+ user(id: $userId, accountId: $accountId) {
10596
+ ${mediums[0]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[0]})
10597
+ ${mediums[1]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[1]})
10598
+ ${mediums[2]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[2]})
10599
+ ${mediums[3]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[3]})
10600
+ ${mediums[4]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[4]})
10601
+ ${mediums[5]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[5]})
10602
+ ${mediums[6]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[6]})
10603
+ ${mediums[7]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[7]})
10604
+ ${mediums[8]}:messageLink(programId: $programId, engagementMedium: $engagementMedium, shareMedium: ${mediums[8]})
10605
+ }
10606
+ }
10607
+ `,
10608
+ variables,
10609
+ })
10610
+ .then((res) => res.data.user);
10611
+ },
10612
+ getUserProgress() {
10613
+ const widgetId = widgetIdent();
10614
+ if (widgetId["env"] === "demo" || !widgetId) {
10615
+ const demoData = {
10616
+ customFields: { demo_totalValue: 16 },
10617
+ rewardBalanceDetails: [{
10618
+ prettyAvailableValue: "$10.00"
10619
+ }],
10620
+ rewards: { count: 1 }
10621
+ };
10622
+ return Promise.resolve(demoData);
10623
+ }
10624
+ const { userId, accountId, programId } = widgetId;
10625
+ const variables = {
10626
+ userId,
10627
+ accountId,
10628
+ programId,
10629
+ };
10630
+ return this.getClient().query({
10631
+ query: src `
10632
+ query($userId: String!, $accountId: String!, $programId: ID) {
10633
+ user(id: $userId, accountId: $accountId){
10634
+ customFields
10635
+ locale
10636
+ rewardBalanceDetails(programId: $programId) {
10637
+ prettyAvailableValue(formatType:UNIT_FORMATTED)
10638
+ }
10639
+ rewards(limit:1000,offset:0, filter:{programId_eq: $programId}){
10640
+ count
10641
+ }
10642
+ }
10643
+ }
10644
+ `,
10645
+ variables
10646
+ }).then(res => res.data.user);
10647
+ },
10648
+ getProgramRules() {
10649
+ const widgetId = widgetIdent();
10650
+ if (widgetId["env"] === "demo" || !widgetId) {
10651
+ const demoData = {
10652
+ id: "demo",
10653
+ name: "Demo Program",
10654
+ rules: {
10655
+ programWindow: "",
10656
+ rewardRules: {
10657
+ rewardRulesType: 1,
10658
+ rewardGoal: 24,
10659
+ isRecurring: 1,
10660
+ defaultCurrency: "CAD"
10661
+ }
10662
+ }
10663
+ };
10664
+ return Promise.resolve(demoData);
10665
+ }
10666
+ const { programId } = widgetId;
10667
+ const variables = {
10668
+ programId
10669
+ };
10670
+ return this.getClient().query({
10671
+ query: src `
10672
+ query($programId: ID!) {
10673
+ program(id:$programId){
10674
+ id
10675
+ name
10676
+ rules
10677
+ }
10678
+ }
10679
+ `,
10680
+ variables
10681
+ }).then(res => res.data.program);
10682
+ },
10683
+ },
10684
+ ui: squatchJsApi,
10528
10685
  };
10529
10686
 
10530
10687
  exports.API = API;