@gofynd/fdk-client-javascript 0.1.35

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 (277) hide show
  1. package/.github/workflows/on_create_release.yml +23 -0
  2. package/.github/workflows/on_merge_main.yml +38 -0
  3. package/.github/workflows/on_pull_request.yml +35 -0
  4. package/.prettierrc +5 -0
  5. package/LICENSE +21 -0
  6. package/README.md +118 -0
  7. package/application.d.ts +3 -0
  8. package/application.js +6 -0
  9. package/common.d.ts +4 -0
  10. package/common.js +9 -0
  11. package/documentation/application/CART.md +7290 -0
  12. package/documentation/application/CATALOG.md +9570 -0
  13. package/documentation/application/COMMON.md +448 -0
  14. package/documentation/application/COMMUNICATION.md +463 -0
  15. package/documentation/application/CONFIGURATION.md +2902 -0
  16. package/documentation/application/CONTENT.md +3350 -0
  17. package/documentation/application/FILESTORAGE.md +491 -0
  18. package/documentation/application/LEAD.md +1891 -0
  19. package/documentation/application/LOGISTIC.md +439 -0
  20. package/documentation/application/ORDER.md +3428 -0
  21. package/documentation/application/PAYMENT.md +5035 -0
  22. package/documentation/application/POSCART.md +7889 -0
  23. package/documentation/application/README.md +21 -0
  24. package/documentation/application/REWARDS.md +714 -0
  25. package/documentation/application/SHARE.md +729 -0
  26. package/documentation/application/THEME.md +5796 -0
  27. package/documentation/application/USER.md +4326 -0
  28. package/documentation/platform/ANALYTICS.md +1150 -0
  29. package/documentation/platform/AUDITTRAIL.md +572 -0
  30. package/documentation/platform/BILLING.md +2396 -0
  31. package/documentation/platform/CART.md +5539 -0
  32. package/documentation/platform/CATALOG.md +21624 -0
  33. package/documentation/platform/COMMON.md +448 -0
  34. package/documentation/platform/COMMUNICATION.md +5714 -0
  35. package/documentation/platform/COMPANYPROFILE.md +2141 -0
  36. package/documentation/platform/CONFIGURATION.md +7335 -0
  37. package/documentation/platform/CONTENT.md +8989 -0
  38. package/documentation/platform/DISCOUNT.md +773 -0
  39. package/documentation/platform/FILESTORAGE.md +994 -0
  40. package/documentation/platform/INVENTORY.md +1775 -0
  41. package/documentation/platform/LEAD.md +4736 -0
  42. package/documentation/platform/ORDER.md +3764 -0
  43. package/documentation/platform/PARTNER.md +216 -0
  44. package/documentation/platform/PAYMENT.md +3444 -0
  45. package/documentation/platform/README.md +27 -0
  46. package/documentation/platform/REWARDS.md +871 -0
  47. package/documentation/platform/SHARE.md +602 -0
  48. package/documentation/platform/THEME.md +35725 -0
  49. package/documentation/platform/USER.md +2305 -0
  50. package/documentation/platform/WEBHOOK.md +587 -0
  51. package/documentation/public/CONFIGURATION.md +448 -0
  52. package/documentation/public/INVENTORY.md +686 -0
  53. package/documentation/public/WEBHOOK.md +348 -0
  54. package/index.d.ts +10 -0
  55. package/index.js +18 -0
  56. package/jest.config.d.ts +4 -0
  57. package/jest.config.js +6 -0
  58. package/package.json +35 -0
  59. package/platform.d.ts +3 -0
  60. package/platform.js +6 -0
  61. package/public.d.ts +3 -0
  62. package/public.js +6 -0
  63. package/sdk/application/ApplicationAPIClient.d.ts +11 -0
  64. package/sdk/application/ApplicationAPIClient.js +44 -0
  65. package/sdk/application/ApplicationClient.d.ts +40 -0
  66. package/sdk/application/ApplicationClient.js +84 -0
  67. package/sdk/application/ApplicationConfig.d.ts +19 -0
  68. package/sdk/application/ApplicationConfig.js +55 -0
  69. package/sdk/application/ApplicationModels.d.ts +826 -0
  70. package/sdk/application/ApplicationModels.js +10474 -0
  71. package/sdk/application/client/CartApplicationClient.d.ts +432 -0
  72. package/sdk/application/client/CartApplicationClient.js +1066 -0
  73. package/sdk/application/client/CatalogApplicationClient.d.ts +694 -0
  74. package/sdk/application/client/CatalogApplicationClient.js +1629 -0
  75. package/sdk/application/client/CommonApplicationClient.d.ts +38 -0
  76. package/sdk/application/client/CommonApplicationClient.js +105 -0
  77. package/sdk/application/client/CommunicationApplicationClient.d.ts +39 -0
  78. package/sdk/application/client/CommunicationApplicationClient.js +131 -0
  79. package/sdk/application/client/ConfigurationApplicationClient.d.ts +210 -0
  80. package/sdk/application/client/ConfigurationApplicationClient.js +649 -0
  81. package/sdk/application/client/ContentApplicationClient.d.ts +256 -0
  82. package/sdk/application/client/ContentApplicationClient.js +785 -0
  83. package/sdk/application/client/FileStorageApplicationClient.d.ts +88 -0
  84. package/sdk/application/client/FileStorageApplicationClient.js +214 -0
  85. package/sdk/application/client/LeadApplicationClient.d.ts +90 -0
  86. package/sdk/application/client/LeadApplicationClient.js +264 -0
  87. package/sdk/application/client/LogisticApplicationClient.d.ts +42 -0
  88. package/sdk/application/client/LogisticApplicationClient.js +128 -0
  89. package/sdk/application/client/OrderApplicationClient.d.ts +190 -0
  90. package/sdk/application/client/OrderApplicationClient.js +479 -0
  91. package/sdk/application/client/PaymentApplicationClient.d.ts +454 -0
  92. package/sdk/application/client/PaymentApplicationClient.js +1378 -0
  93. package/sdk/application/client/PosCartApplicationClient.d.ts +449 -0
  94. package/sdk/application/client/PosCartApplicationClient.js +1123 -0
  95. package/sdk/application/client/RewardsApplicationClient.d.ts +93 -0
  96. package/sdk/application/client/RewardsApplicationClient.js +293 -0
  97. package/sdk/application/client/ShareApplicationClient.d.ts +87 -0
  98. package/sdk/application/client/ShareApplicationClient.js +268 -0
  99. package/sdk/application/client/ThemeApplicationClient.d.ts +52 -0
  100. package/sdk/application/client/ThemeApplicationClient.js +161 -0
  101. package/sdk/application/client/UserApplicationClient.d.ts +446 -0
  102. package/sdk/application/client/UserApplicationClient.js +1275 -0
  103. package/sdk/application/constructUrl.d.ts +5 -0
  104. package/sdk/application/constructUrl.js +13 -0
  105. package/sdk/application/index.d.ts +2 -0
  106. package/sdk/application/index.js +4 -0
  107. package/sdk/application/models/CartValidator.d.ts +29 -0
  108. package/sdk/application/models/CartValidator.js +223 -0
  109. package/sdk/application/models/CatalogValidator.d.ts +33 -0
  110. package/sdk/application/models/CatalogValidator.js +233 -0
  111. package/sdk/application/models/CommonValidator.d.ts +5 -0
  112. package/sdk/application/models/CommonValidator.js +18 -0
  113. package/sdk/application/models/CommunicationValidator.d.ts +6 -0
  114. package/sdk/application/models/CommunicationValidator.js +20 -0
  115. package/sdk/application/models/ConfigurationValidator.d.ts +19 -0
  116. package/sdk/application/models/ConfigurationValidator.js +88 -0
  117. package/sdk/application/models/ContentValidator.d.ts +22 -0
  118. package/sdk/application/models/ContentValidator.js +106 -0
  119. package/sdk/application/models/FileStorageValidator.d.ts +6 -0
  120. package/sdk/application/models/FileStorageValidator.js +24 -0
  121. package/sdk/application/models/LeadValidator.d.ts +10 -0
  122. package/sdk/application/models/LeadValidator.js +48 -0
  123. package/sdk/application/models/LogisticValidator.d.ts +6 -0
  124. package/sdk/application/models/LogisticValidator.js +22 -0
  125. package/sdk/application/models/OrderValidator.d.ts +15 -0
  126. package/sdk/application/models/OrderValidator.js +87 -0
  127. package/sdk/application/models/PaymentValidator.d.ts +40 -0
  128. package/sdk/application/models/PaymentValidator.js +235 -0
  129. package/sdk/application/models/PosCartValidator.d.ts +30 -0
  130. package/sdk/application/models/PosCartValidator.js +232 -0
  131. package/sdk/application/models/RewardsValidator.d.ts +10 -0
  132. package/sdk/application/models/RewardsValidator.js +43 -0
  133. package/sdk/application/models/ShareValidator.d.ts +10 -0
  134. package/sdk/application/models/ShareValidator.js +44 -0
  135. package/sdk/application/models/ThemeValidator.d.ts +7 -0
  136. package/sdk/application/models/ThemeValidator.js +27 -0
  137. package/sdk/application/models/UserValidator.d.ts +38 -0
  138. package/sdk/application/models/UserValidator.js +233 -0
  139. package/sdk/common/AxiosHelper.d.ts +1 -0
  140. package/sdk/common/AxiosHelper.js +141 -0
  141. package/sdk/common/Constant.d.ts +294 -0
  142. package/sdk/common/Constant.js +332 -0
  143. package/sdk/common/FDKError.d.ts +26 -0
  144. package/sdk/common/FDKError.js +51 -0
  145. package/sdk/common/Logger.d.ts +2 -0
  146. package/sdk/common/Logger.js +85 -0
  147. package/sdk/common/Paginator.d.ts +16 -0
  148. package/sdk/common/Paginator.js +26 -0
  149. package/sdk/common/RequestSigner.d.ts +1 -0
  150. package/sdk/common/RequestSigner.js +306 -0
  151. package/sdk/common/Utility.d.ts +9 -0
  152. package/sdk/common/Utility.js +86 -0
  153. package/sdk/common/utils.d.ts +14 -0
  154. package/sdk/common/utils.js +165 -0
  155. package/sdk/platform/OAuthClient.d.ts +26 -0
  156. package/sdk/platform/OAuthClient.js +221 -0
  157. package/sdk/platform/PlatformAPIClient.d.ts +12 -0
  158. package/sdk/platform/PlatformAPIClient.js +43 -0
  159. package/sdk/platform/PlatformApplicationClient.d.ts +24398 -0
  160. package/sdk/platform/PlatformApplicationClient.js +23185 -0
  161. package/sdk/platform/PlatformApplicationModels.d.ts +333 -0
  162. package/sdk/platform/PlatformApplicationModels.js +21262 -0
  163. package/sdk/platform/PlatformClient.d.ts +9535 -0
  164. package/sdk/platform/PlatformClient.js +12336 -0
  165. package/sdk/platform/PlatformConfig.d.ts +29 -0
  166. package/sdk/platform/PlatformConfig.js +36 -0
  167. package/sdk/platform/PlatformModels.d.ts +1396 -0
  168. package/sdk/platform/PlatformModels.js +19222 -0
  169. package/sdk/platform/client/AnalyticsPlatformClient.d.ts +84 -0
  170. package/sdk/platform/client/AnalyticsPlatformClient.js +215 -0
  171. package/sdk/platform/client/AuditTrailPlatformClient.d.ts +38 -0
  172. package/sdk/platform/client/AuditTrailPlatformClient.js +133 -0
  173. package/sdk/platform/client/BillingPlatformClient.d.ts +109 -0
  174. package/sdk/platform/client/BillingPlatformClient.js +381 -0
  175. package/sdk/platform/client/CatalogPlatformClient.d.ts +806 -0
  176. package/sdk/platform/client/CatalogPlatformClient.js +2462 -0
  177. package/sdk/platform/client/CommonPlatformClient.d.ts +30 -0
  178. package/sdk/platform/client/CommonPlatformClient.js +84 -0
  179. package/sdk/platform/client/CommunicationPlatformClient.d.ts +26 -0
  180. package/sdk/platform/client/CommunicationPlatformClient.js +72 -0
  181. package/sdk/platform/client/CompanyProfilePlatformClient.d.ts +182 -0
  182. package/sdk/platform/client/CompanyProfilePlatformClient.js +540 -0
  183. package/sdk/platform/client/ConfigurationPlatformClient.d.ts +277 -0
  184. package/sdk/platform/client/ConfigurationPlatformClient.js +806 -0
  185. package/sdk/platform/client/DiscountPlatformClient.d.ts +118 -0
  186. package/sdk/platform/client/DiscountPlatformClient.js +364 -0
  187. package/sdk/platform/client/FileStoragePlatformClient.d.ts +111 -0
  188. package/sdk/platform/client/FileStoragePlatformClient.js +268 -0
  189. package/sdk/platform/client/InventoryPlatformClient.d.ts +125 -0
  190. package/sdk/platform/client/InventoryPlatformClient.js +409 -0
  191. package/sdk/platform/client/LeadPlatformClient.d.ts +150 -0
  192. package/sdk/platform/client/LeadPlatformClient.js +439 -0
  193. package/sdk/platform/client/OrderPlatformClient.d.ts +190 -0
  194. package/sdk/platform/client/OrderPlatformClient.js +521 -0
  195. package/sdk/platform/client/PaymentPlatformClient.d.ts +98 -0
  196. package/sdk/platform/client/PaymentPlatformClient.js +331 -0
  197. package/sdk/platform/client/WebhookPlatformClient.d.ts +64 -0
  198. package/sdk/platform/client/WebhookPlatformClient.js +207 -0
  199. package/sdk/platform/index.d.ts +2 -0
  200. package/sdk/platform/index.js +4 -0
  201. package/sdk/platform/models/AnalyticsValidator.d.ts +7 -0
  202. package/sdk/platform/models/AnalyticsValidator.js +36 -0
  203. package/sdk/platform/models/AuditTrailValidator.d.ts +7 -0
  204. package/sdk/platform/models/AuditTrailValidator.js +26 -0
  205. package/sdk/platform/models/BillingValidator.d.ts +15 -0
  206. package/sdk/platform/models/BillingValidator.js +72 -0
  207. package/sdk/platform/models/CartValidator.d.ts +0 -0
  208. package/sdk/platform/models/CartValidator.js +0 -0
  209. package/sdk/platform/models/CatalogValidator.d.ts +74 -0
  210. package/sdk/platform/models/CatalogValidator.js +484 -0
  211. package/sdk/platform/models/CommonValidator.d.ts +5 -0
  212. package/sdk/platform/models/CommonValidator.js +18 -0
  213. package/sdk/platform/models/CommunicationValidator.d.ts +4 -0
  214. package/sdk/platform/models/CommunicationValidator.js +11 -0
  215. package/sdk/platform/models/CompanyProfileValidator.d.ts +17 -0
  216. package/sdk/platform/models/CompanyProfileValidator.js +93 -0
  217. package/sdk/platform/models/ConfigurationValidator.d.ts +21 -0
  218. package/sdk/platform/models/ConfigurationValidator.js +134 -0
  219. package/sdk/platform/models/ContentValidator.d.ts +0 -0
  220. package/sdk/platform/models/ContentValidator.js +0 -0
  221. package/sdk/platform/models/DiscountValidator.d.ts +13 -0
  222. package/sdk/platform/models/DiscountValidator.js +75 -0
  223. package/sdk/platform/models/FileStorageValidator.d.ts +9 -0
  224. package/sdk/platform/models/FileStorageValidator.js +44 -0
  225. package/sdk/platform/models/InventoryValidator.d.ts +15 -0
  226. package/sdk/platform/models/InventoryValidator.js +81 -0
  227. package/sdk/platform/models/LeadValidator.d.ts +14 -0
  228. package/sdk/platform/models/LeadValidator.js +78 -0
  229. package/sdk/platform/models/OrderValidator.d.ts +14 -0
  230. package/sdk/platform/models/OrderValidator.js +110 -0
  231. package/sdk/platform/models/PartnerValidator.d.ts +0 -0
  232. package/sdk/platform/models/PartnerValidator.js +0 -0
  233. package/sdk/platform/models/PaymentValidator.d.ts +13 -0
  234. package/sdk/platform/models/PaymentValidator.js +65 -0
  235. package/sdk/platform/models/RewardsValidator.d.ts +0 -0
  236. package/sdk/platform/models/RewardsValidator.js +0 -0
  237. package/sdk/platform/models/ShareValidator.d.ts +0 -0
  238. package/sdk/platform/models/ShareValidator.js +0 -0
  239. package/sdk/platform/models/ThemeValidator.d.ts +0 -0
  240. package/sdk/platform/models/ThemeValidator.js +0 -0
  241. package/sdk/platform/models/UserValidator.d.ts +0 -0
  242. package/sdk/platform/models/UserValidator.js +0 -0
  243. package/sdk/platform/models/WebhookValidator.d.ts +9 -0
  244. package/sdk/platform/models/WebhookValidator.js +42 -0
  245. package/sdk/public/PublicAPIClient.d.ts +11 -0
  246. package/sdk/public/PublicAPIClient.js +38 -0
  247. package/sdk/public/PublicClient.d.ts +12 -0
  248. package/sdk/public/PublicClient.js +24 -0
  249. package/sdk/public/PublicConfig.d.ts +10 -0
  250. package/sdk/public/PublicConfig.js +12 -0
  251. package/sdk/public/PublicModels.d.ts +50 -0
  252. package/sdk/public/PublicModels.js +712 -0
  253. package/sdk/public/client/ConfigurationPublicClient.d.ts +38 -0
  254. package/sdk/public/client/ConfigurationPublicClient.js +102 -0
  255. package/sdk/public/client/InventoryPublicClient.d.ts +81 -0
  256. package/sdk/public/client/InventoryPublicClient.js +239 -0
  257. package/sdk/public/client/WebhookPublicClient.d.ts +28 -0
  258. package/sdk/public/client/WebhookPublicClient.js +92 -0
  259. package/sdk/public/constructUrl.d.ts +5 -0
  260. package/sdk/public/constructUrl.js +13 -0
  261. package/sdk/public/index.d.ts +2 -0
  262. package/sdk/public/index.js +4 -0
  263. package/sdk/public/models/ConfigurationValidator.d.ts +5 -0
  264. package/sdk/public/models/ConfigurationValidator.js +18 -0
  265. package/sdk/public/models/InventoryValidator.d.ts +9 -0
  266. package/sdk/public/models/InventoryValidator.js +43 -0
  267. package/sdk/public/models/WebhookValidator.d.ts +5 -0
  268. package/sdk/public/models/WebhookValidator.js +14 -0
  269. package/tests/application/catalog.spec.js +47 -0
  270. package/tests/common/action-url.spec.js +35 -0
  271. package/tests/common/schema/action-url.json +163 -0
  272. package/tests/common/schema/url-action.json +667 -0
  273. package/tests/common/url-action.spec.js +48 -0
  274. package/tests/helpers/cookie.helper.js +31 -0
  275. package/tests/helpers/oauth.helper.js +43 -0
  276. package/tests/platform/catalog.spec.js +49 -0
  277. package/tests/public/location.spec.js +39 -0
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+
3
+ const url = require("url");
4
+ const querystring = require("query-string");
5
+ const sha256 = require("crypto-js/sha256");
6
+ const hmacSHA256 = require("crypto-js/hmac-sha256");
7
+
8
+ function hmac(key, string, encoding) {
9
+ return hmacSHA256(string, key).toString();
10
+ }
11
+ function hash(string, encoding) {
12
+ return sha256(string).toString();
13
+ }
14
+
15
+ // This function assumes the string has already been percent encoded
16
+ function encodeRfc3986(urlEncodedString) {
17
+ return urlEncodedString.replace(/[!'()*]/g, function (c) {
18
+ return "%" + c.charCodeAt(0).toString(16).toUpperCase();
19
+ });
20
+ }
21
+
22
+ function encodeRfc3986Full(str) {
23
+ return str;
24
+ // return encodeRfc3986(encodeURIComponent(str));
25
+ }
26
+
27
+ const HEADERS_TO_IGNORE = {
28
+ authorization: true,
29
+ connection: true,
30
+ "x-amzn-trace-id": true,
31
+ "user-agent": true,
32
+ expect: true,
33
+ "presigned-expires": true,
34
+ range: true,
35
+ };
36
+
37
+ const HEADERS_TO_INCLUDE = ["x-fp-.*", "host"];
38
+
39
+ // request: { path | body, [host], [method], [headers], [service], [region] }
40
+ class RequestSigner {
41
+ constructor(request) {
42
+ if (typeof request === "string") {
43
+ request = url.parse(request);
44
+ }
45
+
46
+ let headers = (request.headers = request.headers || {});
47
+ this.request = request;
48
+
49
+ if (!request.method && request.body) {
50
+ request.method = "POST";
51
+ }
52
+
53
+ if (!headers.Host && !headers.host) {
54
+ headers.Host = request.hostname || request.host;
55
+
56
+ // If a port is specified explicitly, use it as is
57
+ if (request.port) {
58
+ headers.Host += ":" + request.port;
59
+ }
60
+ }
61
+ if (!request.hostname && !request.host) {
62
+ request.hostname = headers.Host || headers.host;
63
+ }
64
+ }
65
+
66
+ prepareRequest() {
67
+ this.parsePath();
68
+
69
+ let request = this.request;
70
+ let headers = request.headers;
71
+ let query;
72
+
73
+ if (request.signQuery) {
74
+ this.parsedPath.query = query = this.parsedPath.query || {};
75
+
76
+ if (query["x-fp-date"]) {
77
+ this.datetime = query["x-fp-date"];
78
+ } else {
79
+ query["x-fp-date"] = this.getDateTime();
80
+ }
81
+ } else {
82
+ if (!request.doNotModifyHeaders) {
83
+ if (headers["x-fp-date"]) {
84
+ this.datetime = headers["x-fp-date"] || headers["x-fp-date"];
85
+ } else {
86
+ headers["x-fp-date"] = this.getDateTime();
87
+ }
88
+ }
89
+
90
+ delete headers["x-fp-signature"];
91
+ delete headers["X-Fp-Signature"];
92
+ }
93
+ }
94
+
95
+ sign() {
96
+ if (!this.parsedPath) {
97
+ this.prepareRequest();
98
+ }
99
+ if (this.request.signQuery) {
100
+ this.parsedPath.query["x-fp-signature"] = this.signature();
101
+ } else {
102
+ this.request.headers["x-fp-signature"] = this.signature();
103
+ }
104
+ this.request.path = this.formatPath();
105
+ return this.request;
106
+ }
107
+
108
+ getDateTime() {
109
+ if (!this.datetime) {
110
+ let headers = this.request.headers;
111
+ let date = new Date(headers.Date || headers.date || new Date());
112
+
113
+ this.datetime = date.toISOString().replace(/[:\-]|\.\d{3}/g, "");
114
+ }
115
+ return this.datetime;
116
+ }
117
+
118
+ getDate() {
119
+ return this.getDateTime().substr(0, 8);
120
+ }
121
+
122
+ signature() {
123
+ let kCredentials = "1234567";
124
+ let strTosign = this.stringToSign();
125
+ // console.log(strTosign);
126
+ return `v1.1:${hmac(kCredentials, strTosign, "hex")}`;
127
+ }
128
+
129
+ stringToSign() {
130
+ return [this.getDateTime(), hash(this.canonicalString(), "hex")].join("\n");
131
+ }
132
+
133
+ canonicalString() {
134
+ if (!this.parsedPath) {
135
+ this.prepareRequest();
136
+ }
137
+
138
+ let pathStr = this.parsedPath.path;
139
+ let query = this.parsedPath.query;
140
+ let headers = this.request.headers;
141
+ let queryStr = "";
142
+ let normalizePath = true;
143
+ let decodePath = this.request.doNotEncodePath;
144
+ let decodeSlashesInPath = false;
145
+ let firstValOnly = false;
146
+ let bodyHash = hash(this.request.body || "", "hex");
147
+ if (query) {
148
+ let reducedQuery = Object.keys(query).reduce(function (obj, key) {
149
+ if (!key) {
150
+ return obj;
151
+ }
152
+ obj[encodeRfc3986Full(key)] = !Array.isArray(query[key])
153
+ ? query[key]
154
+ : firstValOnly
155
+ ? query[key][0]
156
+ : query[key];
157
+ return obj;
158
+ }, {});
159
+ let encodedQueryPieces = [];
160
+ Object.keys(reducedQuery)
161
+ .sort()
162
+ .forEach(function (key) {
163
+ if (!Array.isArray(reducedQuery[key])) {
164
+ encodedQueryPieces.push(
165
+ key + "=" + encodeRfc3986Full(reducedQuery[key])
166
+ );
167
+ } else {
168
+ reducedQuery[key]
169
+ .map(encodeRfc3986Full)
170
+ .sort()
171
+ .forEach(function (val) {
172
+ encodedQueryPieces.push(key + "=" + val);
173
+ });
174
+ }
175
+ });
176
+ queryStr = encodedQueryPieces.join("&");
177
+ }
178
+ if (pathStr !== "/") {
179
+ if (normalizePath) {
180
+ pathStr = pathStr.replace(/\/{2,}/g, "/");
181
+ }
182
+ pathStr = pathStr
183
+ .split("/")
184
+ .reduce(function (path, piece) {
185
+ if (normalizePath && piece === "..") {
186
+ path.pop();
187
+ } else if (!normalizePath || piece !== ".") {
188
+ if (decodePath)
189
+ piece = decodeURIComponent(piece.replace(/\+/g, " "));
190
+ path.push(encodeRfc3986Full(piece));
191
+ }
192
+ return path;
193
+ }, [])
194
+ .join("/");
195
+ if (pathStr[0] !== "/") pathStr = "/" + pathStr;
196
+ if (decodeSlashesInPath) pathStr = pathStr.replace(/%2F/g, "/");
197
+ }
198
+
199
+ let canonicalReq = [
200
+ this.request.method || "GET",
201
+ pathStr,
202
+ queryStr,
203
+ this.canonicalHeaders() + "\n",
204
+ this.signedHeaders(),
205
+ bodyHash,
206
+ ].join("\n");
207
+ return canonicalReq;
208
+ }
209
+
210
+ canonicalHeaders() {
211
+ let headers = this.request.headers;
212
+
213
+ function trimAll(header) {
214
+ return header.toString().trim().replace(/\s+/g, " ");
215
+ }
216
+ return Object.keys(headers)
217
+ .filter(function (key) {
218
+ let notInIgnoreHeader = HEADERS_TO_IGNORE[key.toLowerCase()] == null;
219
+ if (notInIgnoreHeader) {
220
+ let foundMatch = false;
221
+ for (let t in HEADERS_TO_INCLUDE) {
222
+ foundMatch =
223
+ foundMatch || new RegExp(HEADERS_TO_INCLUDE[t], "ig").test(key);
224
+ }
225
+ return foundMatch;
226
+ } else {
227
+ return false;
228
+ }
229
+ })
230
+ .sort(function (a, b) {
231
+ return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
232
+ })
233
+ .map(function (key) {
234
+ return key.toLowerCase() + ":" + trimAll(headers[key]);
235
+ })
236
+ .join("\n");
237
+ }
238
+
239
+ signedHeaders() {
240
+ return Object.keys(this.request.headers)
241
+ .map(function (key) {
242
+ return key.toLowerCase();
243
+ })
244
+ .filter(function (key) {
245
+ let notInIgnoreHeader = HEADERS_TO_IGNORE[key.toLowerCase()] == null;
246
+ if (notInIgnoreHeader) {
247
+ let foundMatch = false;
248
+ for (let t in HEADERS_TO_INCLUDE) {
249
+ foundMatch =
250
+ foundMatch || new RegExp(HEADERS_TO_INCLUDE[t], "ig").test(key);
251
+ }
252
+ return foundMatch;
253
+ } else {
254
+ return false;
255
+ }
256
+ })
257
+ .sort()
258
+ .join(";");
259
+ }
260
+
261
+ parsePath() {
262
+ let path = this.request.path || "/";
263
+ let queryIx = path.indexOf("?");
264
+ let query = null;
265
+
266
+ if (queryIx >= 0) {
267
+ query = querystring.parse(path.slice(queryIx + 1));
268
+ path = path.slice(0, queryIx);
269
+ }
270
+ path = path
271
+ .split("/")
272
+ .map((t) => {
273
+ return encodeURIComponent(decodeURIComponent(t));
274
+ })
275
+ .join("/");
276
+
277
+ this.parsedPath = {
278
+ path: path,
279
+ query: query,
280
+ };
281
+ }
282
+
283
+ formatPath() {
284
+ let path = this.parsedPath.path;
285
+ let query = this.parsedPath.query;
286
+
287
+ if (!query) {
288
+ return path;
289
+ }
290
+
291
+ // Services don't support empty query string keys
292
+ if (query[""] != null) {
293
+ delete query[""];
294
+ }
295
+
296
+ return path + "?" + encodeRfc3986(querystring.stringify(query));
297
+ }
298
+ }
299
+
300
+ function sign(request) {
301
+ return new RequestSigner(request).sign();
302
+ }
303
+
304
+ module.exports = {
305
+ sign: sign,
306
+ };
@@ -0,0 +1,9 @@
1
+ export function convertActionToUrl(action: any): any;
2
+ export function convertUrlToAction(url: any): {
3
+ type: string;
4
+ page: {
5
+ type: any;
6
+ query: {};
7
+ params: {};
8
+ };
9
+ };
@@ -0,0 +1,86 @@
1
+ const utils = require("./utils");
2
+ const Constant = require("./Constant");
3
+
4
+ function convertUrlToAction(url) {
5
+ if (url) {
6
+ const path = utils.trimChar(url);
7
+ const query = utils.getQuery(path);
8
+ const pathname = utils.validURL(path)
9
+ ? new URL(path).pathname
10
+ : path.split("?")[0];
11
+ const allNavigations = Object.assign({}, Constant.NAVIGATORS);
12
+ const typeLink = {};
13
+ for (nav in allNavigations) {
14
+ let { link, params } = allNavigations[nav];
15
+ typeLink[link] = nav;
16
+ if (params) {
17
+ params.forEach((param) => {
18
+ if (param.required == false) {
19
+ let modifiedLink = link.slice(0, link.indexOf(param.key) - 1);
20
+ typeLink[modifiedLink] = nav;
21
+ }
22
+ });
23
+ }
24
+ }
25
+ const allLinks = Object.keys(typeLink);
26
+ allLinks.sort(function (a, b) {
27
+ return b.length - a.length;
28
+ });
29
+ const bestMatchingLink = utils.findBestMatchingLink(allLinks, pathname);
30
+ const closestMatchingNavLink = Object.keys(typeLink).find((pageType) => {
31
+ return utils.trimChar(pageType) === bestMatchingLink.value;
32
+ });
33
+ const closestMatchingNavKey = typeLink[closestMatchingNavLink];
34
+ if (!closestMatchingNavKey) {
35
+ closestMatchingNavKey = "home";
36
+ }
37
+ return {
38
+ type: "page",
39
+ page: {
40
+ type: closestMatchingNavKey,
41
+ query: query,
42
+ params: bestMatchingLink.params,
43
+ },
44
+ };
45
+ } else {
46
+ return {
47
+ type: "page",
48
+ page: {
49
+ type: "home",
50
+ query: {},
51
+ params: {},
52
+ },
53
+ };
54
+ }
55
+ }
56
+
57
+ function convertActionToUrl(action) {
58
+ if (action && action.page && action.page.type) {
59
+ switch (action.type) {
60
+ case utils.NAV_TYPE.PAGE: {
61
+ const item = Object.assign({}, Constant.NAVIGATORS[action.page.type]);
62
+ if (item) {
63
+ //get param
64
+ item.link = utils.generateUrlWithParams(item, action.page.params);
65
+ //get query
66
+ if (action.page.query && Object.keys(action.page.query).length > 0) {
67
+ item.link +=
68
+ "/?" + utils.transformRequestOptions(action.page.query);
69
+ }
70
+ return item.link;
71
+ }
72
+ return "";
73
+ }
74
+ case utils.NAV_TYPE.POPUP: {
75
+ break;
76
+ }
77
+ }
78
+ } else {
79
+ return "";
80
+ }
81
+ }
82
+
83
+ module.exports = {
84
+ convertActionToUrl,
85
+ convertUrlToAction,
86
+ };
@@ -0,0 +1,14 @@
1
+ export function transformRequestOptions(params: any): string;
2
+ export function getParamsFromItem(params: any): string;
3
+ export function getQuery(path: any): {};
4
+ export function trimChar(string?: string, charToRemove?: string): string;
5
+ export function generateUrlWithParams(item: {}, params: any): string;
6
+ export function findBestMatchingLink(allLinks?: any[], pathname?: string): {
7
+ value: string;
8
+ params: {};
9
+ };
10
+ export function validURL(str: any): boolean;
11
+ export namespace NAV_TYPE {
12
+ const PAGE: string;
13
+ const POPUP: string;
14
+ }
@@ -0,0 +1,165 @@
1
+ const SLUG_DELIMETER = ":::";
2
+ const transformRequestOptions = (params) => {
3
+ let options = "";
4
+
5
+ for (const key in params) {
6
+ if (typeof params[key] !== "object" && params[key]) {
7
+ const encodeVal = encodeURIComponent(params[key]);
8
+ options += `${key}=${encodeVal}&`;
9
+ } else if (Array.isArray(params[key])) {
10
+ params[key].forEach((el) => {
11
+ const encodeVal = encodeURIComponent(el);
12
+ options += `${key}=${encodeVal}&`;
13
+ });
14
+ } else if (typeof params[key] === "object" && params[key]) {
15
+ options += transformRequestOptions(params[key]);
16
+ }
17
+ }
18
+ return options ? options.slice(0, -1) : options;
19
+ };
20
+
21
+ const getParamsFromItem = (params) => {
22
+ let strParam = "";
23
+ for (let key in params) {
24
+ if (Array.isArray(params[key])) {
25
+ for (let index = 0; index < params[key].length; index++) {
26
+ strParam +=
27
+ index === params[key].length - 1
28
+ ? params[key][index]
29
+ : params[key][index] + SLUG_DELIMETER;
30
+ }
31
+ return strParam;
32
+ }
33
+ }
34
+ return strParam;
35
+ };
36
+ const generateUrlWithParams = (item = {}, params) => {
37
+ if (!item || !item.link) return "";
38
+ if (!params) return `/${trimChar(item.link.split(":")[0])}`;
39
+ const joinedParamsObj = {};
40
+ for (let key in params) {
41
+ if (Array.isArray(params[key])) {
42
+ let joinedParams = "";
43
+ for (let index = 0; index < params[key].length; index++) {
44
+ joinedParams +=
45
+ index === params[key].length - 1
46
+ ? params[key][index]
47
+ : params[key][index] + SLUG_DELIMETER;
48
+ }
49
+ joinedParamsObj[key] = joinedParams;
50
+ }
51
+ }
52
+ item.link = trimChar(item.link);
53
+
54
+ let linkArr = item.link.split("/");
55
+ let url = "";
56
+ for (let linkSubString of linkArr) {
57
+ if (linkSubString.startsWith(":")) {
58
+ linkSubString = linkSubString.slice(1);
59
+ url += `${joinedParamsObj[linkSubString]}`;
60
+ } else url += `${linkSubString}`;
61
+ url += "/";
62
+ }
63
+ url = trimChar(url);
64
+ return `/${url}`;
65
+ };
66
+ const getQuery = (path) => {
67
+ let parseUrl = path.split("?");
68
+ if (parseUrl.length > 1) {
69
+ const searchParams = new URLSearchParams(parseUrl[1]);
70
+ let queryResult = {};
71
+ for (let item of searchParams) {
72
+ let key = item[0],
73
+ value = item[1];
74
+
75
+ queryResult[key] = queryResult[key]
76
+ ? [...queryResult[key], value]
77
+ : [value];
78
+ }
79
+ return queryResult;
80
+ }
81
+ return {};
82
+ };
83
+ const trimChar = (string = "", charToRemove = "/") => {
84
+ while (string.charAt(0) == charToRemove) {
85
+ string = string.substring(1);
86
+ }
87
+
88
+ while (string.charAt(string.length - 1) == charToRemove) {
89
+ string = string.substring(0, string.length - 1);
90
+ }
91
+
92
+ return string;
93
+ };
94
+
95
+ function validURL(str) {
96
+ var pattern = new RegExp(
97
+ "^(https?:\\/\\/)?" + // protocol
98
+ "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
99
+ "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
100
+ "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
101
+ "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
102
+ "(\\#[-a-z\\d_]*)?$",
103
+ "i"
104
+ ); // fragment locator
105
+ return !!pattern.test(str);
106
+ }
107
+
108
+ const findBestMatchingLink = (allLinks = [], pathname = "/") => {
109
+ let bestMatch = { value: "", params: {} };
110
+ pathname = trimChar(pathname); // -> product/test-product-tag/reviews
111
+ for (let i = 0; i < allLinks.length; i++) {
112
+ let link = trimChar(allLinks[i]); // -> product/:slug/add-reviews
113
+ if (new RegExp(`^${trimChar(link)}`).test(pathname)) {
114
+ bestMatch.value = link;
115
+ break;
116
+ }
117
+ const linkArr = link.split("/"); // -> [ 'product', ':slug', 'add-reviews' ]
118
+ const pathArr = pathname.split("/"); // -> [ 'product', 'test-product-tag', 'reviews' ]
119
+ if (linkArr.length === pathArr.length) {
120
+ // some match
121
+ let j;
122
+ bestMatch = { value: "", params: {} };
123
+ for (j = 0; j < linkArr.length; ++j) {
124
+ if (linkArr[j].startsWith(":")) {
125
+ // this will be :slug & test-slug
126
+ let arrParams = [];
127
+ if (pathArr[j].includes(SLUG_DELIMETER)) {
128
+ // if link container multiple path params eg test-slug--test-slug-123
129
+ arrParams = pathArr[j].split(SLUG_DELIMETER); // split it into array
130
+ } else arrParams = [pathArr[j]]; // else assign
131
+ if (bestMatch.params[linkArr[j].slice(1)]) {
132
+ // if params is already present in best match object spread new params
133
+ arrParams = [
134
+ ...bestMatch.params[linkArr[j].slice(1)],
135
+ ...arrParams,
136
+ ];
137
+ }
138
+ bestMatch.params[linkArr[j].slice(1)] = arrParams; // else assign
139
+ } else if (linkArr[j] !== pathArr[j]) break; // if path and link params not match and are not :slug type break and move to next link
140
+ }
141
+ if (j === linkArr.length) {
142
+ // if all paths match and j is not 0 coz 'about-us' & 'notification' have same length and in that case j will be 0. This type of matching is handled in Regex on line #100
143
+ bestMatch.value = link;
144
+ break;
145
+ }
146
+ }
147
+ }
148
+ return bestMatch;
149
+ };
150
+
151
+ const NAV_TYPE = {
152
+ PAGE: "page",
153
+ POPUP: "popup",
154
+ };
155
+
156
+ module.exports = {
157
+ transformRequestOptions,
158
+ getParamsFromItem,
159
+ getQuery,
160
+ trimChar,
161
+ generateUrlWithParams,
162
+ findBestMatchingLink,
163
+ validURL,
164
+ NAV_TYPE,
165
+ };
@@ -0,0 +1,26 @@
1
+ export = OAuthClient;
2
+ declare class OAuthClient {
3
+ constructor(config: any);
4
+ config: any;
5
+ token: any;
6
+ refreshToken: any;
7
+ retryOAuthTokenTimer: NodeJS.Timeout;
8
+ raw_token: any;
9
+ token_expires_in: any;
10
+ token_expires_at: number;
11
+ useAutoRenewTimer: any;
12
+ getAccessToken(): Promise<any>;
13
+ isTokenExpired(ttl?: number): boolean;
14
+ setToken(token: any): void;
15
+ retryOAuthToken(expires_in: any): void;
16
+ startAuthorization(options: any): string;
17
+ verifyCallback(query: any): Promise<void>;
18
+ renewAccessToken(isOfflineToken?: boolean): Promise<any>;
19
+ getAccesstokenObj({ grant_type, refresh_token, code }: {
20
+ grant_type: any;
21
+ refresh_token: any;
22
+ code: any;
23
+ }): Promise<any>;
24
+ getOfflineAccessToken(scopes: any, code: any): Promise<any>;
25
+ getOfflineAccessTokenObj(scopes: any, code: any): Promise<any>;
26
+ }