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