@snagsolutions/sdk 0.1.0-alpha.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 (342) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/LICENSE +201 -0
  3. package/README.md +297 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +241 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +908 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +876 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +47 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +113 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +97 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +126 -0
  87. package/index.d.ts +126 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +141 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +98 -0
  92. package/index.mjs.map +1 -0
  93. package/internal/qs/formats.d.ts +6 -0
  94. package/internal/qs/formats.d.ts.map +1 -0
  95. package/internal/qs/formats.js +11 -0
  96. package/internal/qs/formats.js.map +1 -0
  97. package/internal/qs/formats.mjs +8 -0
  98. package/internal/qs/formats.mjs.map +1 -0
  99. package/internal/qs/index.d.ts +10 -0
  100. package/internal/qs/index.d.ts.map +1 -0
  101. package/internal/qs/index.js +14 -0
  102. package/internal/qs/index.js.map +1 -0
  103. package/internal/qs/index.mjs +10 -0
  104. package/internal/qs/index.mjs.map +1 -0
  105. package/internal/qs/stringify.d.ts +3 -0
  106. package/internal/qs/stringify.d.ts.map +1 -0
  107. package/internal/qs/stringify.js +280 -0
  108. package/internal/qs/stringify.js.map +1 -0
  109. package/internal/qs/stringify.mjs +276 -0
  110. package/internal/qs/stringify.mjs.map +1 -0
  111. package/internal/qs/types.d.ts +57 -0
  112. package/internal/qs/types.d.ts.map +1 -0
  113. package/internal/qs/types.js +3 -0
  114. package/internal/qs/types.js.map +1 -0
  115. package/internal/qs/types.mjs +2 -0
  116. package/internal/qs/types.mjs.map +1 -0
  117. package/internal/qs/utils.d.ts +14 -0
  118. package/internal/qs/utils.d.ts.map +1 -0
  119. package/internal/qs/utils.js +229 -0
  120. package/internal/qs/utils.js.map +1 -0
  121. package/internal/qs/utils.mjs +217 -0
  122. package/internal/qs/utils.mjs.map +1 -0
  123. package/package.json +103 -0
  124. package/resource.d.ts +6 -0
  125. package/resource.d.ts.map +1 -0
  126. package/resource.js +11 -0
  127. package/resource.js.map +1 -0
  128. package/resource.mjs +7 -0
  129. package/resource.mjs.map +1 -0
  130. package/resources/assets.d.ts +50 -0
  131. package/resources/assets.d.ts.map +1 -0
  132. package/resources/assets.js +17 -0
  133. package/resources/assets.js.map +1 -0
  134. package/resources/assets.mjs +13 -0
  135. package/resources/assets.mjs.map +1 -0
  136. package/resources/auction-bids.d.ts +81 -0
  137. package/resources/auction-bids.d.ts.map +1 -0
  138. package/resources/auction-bids.js +30 -0
  139. package/resources/auction-bids.js.map +1 -0
  140. package/resources/auction-bids.mjs +26 -0
  141. package/resources/auction-bids.mjs.map +1 -0
  142. package/resources/drip/drip.d.ts +14 -0
  143. package/resources/drip/drip.d.ts.map +1 -0
  144. package/resources/drip/drip.js +43 -0
  145. package/resources/drip/drip.js.map +1 -0
  146. package/resources/drip/drip.mjs +16 -0
  147. package/resources/drip/drip.mjs.map +1 -0
  148. package/resources/drip/index.d.ts +4 -0
  149. package/resources/drip/index.d.ts.map +1 -0
  150. package/resources/drip/index.js +11 -0
  151. package/resources/drip/index.js.map +1 -0
  152. package/resources/drip/index.mjs +5 -0
  153. package/resources/drip/index.mjs.map +1 -0
  154. package/resources/drip/quests.d.ts +168 -0
  155. package/resources/drip/quests.d.ts.map +1 -0
  156. package/resources/drip/quests.js +17 -0
  157. package/resources/drip/quests.js.map +1 -0
  158. package/resources/drip/quests.mjs +13 -0
  159. package/resources/drip/quests.mjs.map +1 -0
  160. package/resources/drip/status.d.ts +26 -0
  161. package/resources/drip/status.d.ts.map +1 -0
  162. package/resources/drip/status.js +16 -0
  163. package/resources/drip/status.js.map +1 -0
  164. package/resources/drip/status.mjs +12 -0
  165. package/resources/drip/status.mjs.map +1 -0
  166. package/resources/index.d.ts +7 -0
  167. package/resources/index.d.ts.map +1 -0
  168. package/resources/index.js +17 -0
  169. package/resources/index.js.map +1 -0
  170. package/resources/index.mjs +8 -0
  171. package/resources/index.mjs.map +1 -0
  172. package/resources/loyalty/accounts.d.ts +157 -0
  173. package/resources/loyalty/accounts.d.ts.map +1 -0
  174. package/resources/loyalty/accounts.js +16 -0
  175. package/resources/loyalty/accounts.js.map +1 -0
  176. package/resources/loyalty/accounts.mjs +12 -0
  177. package/resources/loyalty/accounts.mjs.map +1 -0
  178. package/resources/loyalty/badges.d.ts +299 -0
  179. package/resources/loyalty/badges.d.ts.map +1 -0
  180. package/resources/loyalty/badges.js +46 -0
  181. package/resources/loyalty/badges.js.map +1 -0
  182. package/resources/loyalty/badges.mjs +42 -0
  183. package/resources/loyalty/badges.mjs.map +1 -0
  184. package/resources/loyalty/currencies.d.ts +252 -0
  185. package/resources/loyalty/currencies.d.ts.map +1 -0
  186. package/resources/loyalty/currencies.js +21 -0
  187. package/resources/loyalty/currencies.js.map +1 -0
  188. package/resources/loyalty/currencies.mjs +17 -0
  189. package/resources/loyalty/currencies.mjs.map +1 -0
  190. package/resources/loyalty/index.d.ts +9 -0
  191. package/resources/loyalty/index.d.ts.map +1 -0
  192. package/resources/loyalty/index.js +21 -0
  193. package/resources/loyalty/index.js.map +1 -0
  194. package/resources/loyalty/index.mjs +10 -0
  195. package/resources/loyalty/index.mjs.map +1 -0
  196. package/resources/loyalty/loyalty.d.ts +34 -0
  197. package/resources/loyalty/loyalty.d.ts.map +1 -0
  198. package/resources/loyalty/loyalty.js +63 -0
  199. package/resources/loyalty/loyalty.js.map +1 -0
  200. package/resources/loyalty/loyalty.mjs +36 -0
  201. package/resources/loyalty/loyalty.mjs.map +1 -0
  202. package/resources/loyalty/multipliers.d.ts +129 -0
  203. package/resources/loyalty/multipliers.d.ts.map +1 -0
  204. package/resources/loyalty/multipliers.js +34 -0
  205. package/resources/loyalty/multipliers.js.map +1 -0
  206. package/resources/loyalty/multipliers.mjs +30 -0
  207. package/resources/loyalty/multipliers.mjs.map +1 -0
  208. package/resources/loyalty/rule-edits.d.ts +330 -0
  209. package/resources/loyalty/rule-edits.d.ts.map +1 -0
  210. package/resources/loyalty/rule-edits.js +21 -0
  211. package/resources/loyalty/rule-edits.js.map +1 -0
  212. package/resources/loyalty/rule-edits.mjs +17 -0
  213. package/resources/loyalty/rule-edits.mjs.map +1 -0
  214. package/resources/loyalty/rules.d.ts +2430 -0
  215. package/resources/loyalty/rules.d.ts.map +1 -0
  216. package/resources/loyalty/rules.js +46 -0
  217. package/resources/loyalty/rules.js.map +1 -0
  218. package/resources/loyalty/rules.mjs +42 -0
  219. package/resources/loyalty/rules.mjs.map +1 -0
  220. package/resources/loyalty/transaction-entries.d.ts +175 -0
  221. package/resources/loyalty/transaction-entries.d.ts.map +1 -0
  222. package/resources/loyalty/transaction-entries.js +16 -0
  223. package/resources/loyalty/transaction-entries.js.map +1 -0
  224. package/resources/loyalty/transaction-entries.mjs +12 -0
  225. package/resources/loyalty/transaction-entries.mjs.map +1 -0
  226. package/resources/users/index.d.ts +4 -0
  227. package/resources/users/index.d.ts.map +1 -0
  228. package/resources/users/index.js +11 -0
  229. package/resources/users/index.js.map +1 -0
  230. package/resources/users/index.mjs +5 -0
  231. package/resources/users/index.mjs.map +1 -0
  232. package/resources/users/metadatas.d.ts +64 -0
  233. package/resources/users/metadatas.d.ts.map +1 -0
  234. package/resources/users/metadatas.js +16 -0
  235. package/resources/users/metadatas.js.map +1 -0
  236. package/resources/users/metadatas.mjs +12 -0
  237. package/resources/users/metadatas.mjs.map +1 -0
  238. package/resources/users/users.d.ts +14 -0
  239. package/resources/users/users.d.ts.map +1 -0
  240. package/resources/users/users.js +43 -0
  241. package/resources/users/users.js.map +1 -0
  242. package/resources/users/users.mjs +16 -0
  243. package/resources/users/users.mjs.map +1 -0
  244. package/resources/users/wallets.d.ts +193 -0
  245. package/resources/users/wallets.d.ts.map +1 -0
  246. package/resources/users/wallets.js +28 -0
  247. package/resources/users/wallets.js.map +1 -0
  248. package/resources/users/wallets.mjs +24 -0
  249. package/resources/users/wallets.mjs.map +1 -0
  250. package/resources/websites.d.ts +203 -0
  251. package/resources/websites.d.ts.map +1 -0
  252. package/resources/websites.js +22 -0
  253. package/resources/websites.js.map +1 -0
  254. package/resources/websites.mjs +18 -0
  255. package/resources/websites.mjs.map +1 -0
  256. package/shims/node.d.ts +30 -0
  257. package/shims/node.d.ts.map +1 -0
  258. package/shims/node.js +31 -0
  259. package/shims/node.js.map +1 -0
  260. package/shims/node.mjs +5 -0
  261. package/shims/node.mjs.map +1 -0
  262. package/shims/web.d.ts +26 -0
  263. package/shims/web.d.ts.map +1 -0
  264. package/shims/web.js +31 -0
  265. package/shims/web.js.map +1 -0
  266. package/shims/web.mjs +5 -0
  267. package/shims/web.mjs.map +1 -0
  268. package/src/_shims/MultipartBody.ts +9 -0
  269. package/src/_shims/README.md +46 -0
  270. package/src/_shims/auto/runtime-bun.ts +4 -0
  271. package/src/_shims/auto/runtime-node.ts +4 -0
  272. package/src/_shims/auto/runtime.ts +4 -0
  273. package/src/_shims/auto/types-node.ts +4 -0
  274. package/src/_shims/auto/types.d.ts +101 -0
  275. package/src/_shims/auto/types.js +3 -0
  276. package/src/_shims/auto/types.mjs +3 -0
  277. package/src/_shims/bun-runtime.ts +14 -0
  278. package/src/_shims/index.d.ts +81 -0
  279. package/src/_shims/index.js +13 -0
  280. package/src/_shims/index.mjs +7 -0
  281. package/src/_shims/manual-types.d.ts +12 -0
  282. package/src/_shims/manual-types.js +3 -0
  283. package/src/_shims/manual-types.mjs +3 -0
  284. package/src/_shims/node-runtime.ts +81 -0
  285. package/src/_shims/node-types.d.ts +42 -0
  286. package/src/_shims/node-types.js +3 -0
  287. package/src/_shims/node-types.mjs +3 -0
  288. package/src/_shims/registry.ts +67 -0
  289. package/src/_shims/web-runtime.ts +103 -0
  290. package/src/_shims/web-types.d.ts +83 -0
  291. package/src/_shims/web-types.js +3 -0
  292. package/src/_shims/web-types.mjs +3 -0
  293. package/src/core.ts +1201 -0
  294. package/src/error.ts +130 -0
  295. package/src/index.ts +235 -0
  296. package/src/internal/qs/LICENSE.md +13 -0
  297. package/src/internal/qs/README.md +3 -0
  298. package/src/internal/qs/formats.ts +9 -0
  299. package/src/internal/qs/index.ts +13 -0
  300. package/src/internal/qs/stringify.ts +388 -0
  301. package/src/internal/qs/types.ts +71 -0
  302. package/src/internal/qs/utils.ts +265 -0
  303. package/src/lib/.keep +4 -0
  304. package/src/resource.ts +11 -0
  305. package/src/resources/assets.ts +71 -0
  306. package/src/resources/auction-bids.ts +123 -0
  307. package/src/resources/drip/drip.ts +25 -0
  308. package/src/resources/drip/index.ts +5 -0
  309. package/src/resources/drip/quests.ts +210 -0
  310. package/src/resources/drip/status.ts +33 -0
  311. package/src/resources/index.ts +14 -0
  312. package/src/resources/loyalty/accounts.ts +199 -0
  313. package/src/resources/loyalty/badges.ts +435 -0
  314. package/src/resources/loyalty/currencies.ts +321 -0
  315. package/src/resources/loyalty/index.ts +61 -0
  316. package/src/resources/loyalty/loyalty.ts +159 -0
  317. package/src/resources/loyalty/multipliers.ts +238 -0
  318. package/src/resources/loyalty/rule-edits.ts +421 -0
  319. package/src/resources/loyalty/rules.ts +3513 -0
  320. package/src/resources/loyalty/transaction-entries.ts +229 -0
  321. package/src/resources/users/index.ts +12 -0
  322. package/src/resources/users/metadatas.ts +103 -0
  323. package/src/resources/users/users.ts +39 -0
  324. package/src/resources/users/wallets.ts +271 -0
  325. package/src/resources/websites.ts +259 -0
  326. package/src/shims/node.ts +50 -0
  327. package/src/shims/web.ts +50 -0
  328. package/src/tsconfig.json +11 -0
  329. package/src/uploads.ts +255 -0
  330. package/src/version.ts +1 -0
  331. package/uploads.d.ts +75 -0
  332. package/uploads.d.ts.map +1 -0
  333. package/uploads.js +171 -0
  334. package/uploads.js.map +1 -0
  335. package/uploads.mjs +158 -0
  336. package/uploads.mjs.map +1 -0
  337. package/version.d.ts +2 -0
  338. package/version.d.ts.map +1 -0
  339. package/version.js +5 -0
  340. package/version.js.map +1 -0
  341. package/version.mjs +2 -0
  342. package/version.mjs.map +1 -0
@@ -0,0 +1,388 @@
1
+ import { encode, is_buffer, maybe_map } from './utils';
2
+ import { default_format, formatters } from './formats';
3
+ import type { NonNullableProperties, StringifyOptions } from './types';
4
+
5
+ const has = Object.prototype.hasOwnProperty;
6
+
7
+ const array_prefix_generators = {
8
+ brackets(prefix: PropertyKey) {
9
+ return String(prefix) + '[]';
10
+ },
11
+ comma: 'comma',
12
+ indices(prefix: PropertyKey, key: string) {
13
+ return String(prefix) + '[' + key + ']';
14
+ },
15
+ repeat(prefix: PropertyKey) {
16
+ return String(prefix);
17
+ },
18
+ };
19
+
20
+ const is_array = Array.isArray;
21
+ const push = Array.prototype.push;
22
+ const push_to_array = function (arr: any[], value_or_array: any) {
23
+ push.apply(arr, is_array(value_or_array) ? value_or_array : [value_or_array]);
24
+ };
25
+
26
+ const to_ISO = Date.prototype.toISOString;
27
+
28
+ const defaults = {
29
+ addQueryPrefix: false,
30
+ allowDots: false,
31
+ allowEmptyArrays: false,
32
+ arrayFormat: 'indices',
33
+ charset: 'utf-8',
34
+ charsetSentinel: false,
35
+ delimiter: '&',
36
+ encode: true,
37
+ encodeDotInKeys: false,
38
+ encoder: encode,
39
+ encodeValuesOnly: false,
40
+ format: default_format,
41
+ formatter: formatters[default_format],
42
+ /** @deprecated */
43
+ indices: false,
44
+ serializeDate(date) {
45
+ return to_ISO.call(date);
46
+ },
47
+ skipNulls: false,
48
+ strictNullHandling: false,
49
+ } as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>;
50
+
51
+ function is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {
52
+ return (
53
+ typeof v === 'string' ||
54
+ typeof v === 'number' ||
55
+ typeof v === 'boolean' ||
56
+ typeof v === 'symbol' ||
57
+ typeof v === 'bigint'
58
+ );
59
+ }
60
+
61
+ const sentinel = {};
62
+
63
+ function inner_stringify(
64
+ object: any,
65
+ prefix: PropertyKey,
66
+ generateArrayPrefix: StringifyOptions['arrayFormat'] | ((prefix: string, key: string) => string),
67
+ commaRoundTrip: boolean,
68
+ allowEmptyArrays: boolean,
69
+ strictNullHandling: boolean,
70
+ skipNulls: boolean,
71
+ encodeDotInKeys: boolean,
72
+ encoder: StringifyOptions['encoder'],
73
+ filter: StringifyOptions['filter'],
74
+ sort: StringifyOptions['sort'],
75
+ allowDots: StringifyOptions['allowDots'],
76
+ serializeDate: StringifyOptions['serializeDate'],
77
+ format: StringifyOptions['format'],
78
+ formatter: StringifyOptions['formatter'],
79
+ encodeValuesOnly: boolean,
80
+ charset: StringifyOptions['charset'],
81
+ sideChannel: WeakMap<any, any>,
82
+ ) {
83
+ let obj = object;
84
+
85
+ let tmp_sc = sideChannel;
86
+ let step = 0;
87
+ let find_flag = false;
88
+ while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
89
+ // Where object last appeared in the ref tree
90
+ const pos = tmp_sc.get(object);
91
+ step += 1;
92
+ if (typeof pos !== 'undefined') {
93
+ if (pos === step) {
94
+ throw new RangeError('Cyclic object value');
95
+ } else {
96
+ find_flag = true; // Break while
97
+ }
98
+ }
99
+ if (typeof tmp_sc.get(sentinel) === 'undefined') {
100
+ step = 0;
101
+ }
102
+ }
103
+
104
+ if (typeof filter === 'function') {
105
+ obj = filter(prefix, obj);
106
+ } else if (obj instanceof Date) {
107
+ obj = serializeDate?.(obj);
108
+ } else if (generateArrayPrefix === 'comma' && is_array(obj)) {
109
+ obj = maybe_map(obj, function (value) {
110
+ if (value instanceof Date) {
111
+ return serializeDate?.(value);
112
+ }
113
+ return value;
114
+ });
115
+ }
116
+
117
+ if (obj === null) {
118
+ if (strictNullHandling) {
119
+ return encoder && !encodeValuesOnly ?
120
+ // @ts-expect-error
121
+ encoder(prefix, defaults.encoder, charset, 'key', format)
122
+ : prefix;
123
+ }
124
+
125
+ obj = '';
126
+ }
127
+
128
+ if (is_non_nullish_primitive(obj) || is_buffer(obj)) {
129
+ if (encoder) {
130
+ const key_value =
131
+ encodeValuesOnly ? prefix
132
+ // @ts-expect-error
133
+ : encoder(prefix, defaults.encoder, charset, 'key', format);
134
+ return [
135
+ formatter?.(key_value) +
136
+ '=' +
137
+ // @ts-expect-error
138
+ formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
139
+ ];
140
+ }
141
+ return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
142
+ }
143
+
144
+ const values: string[] = [];
145
+
146
+ if (typeof obj === 'undefined') {
147
+ return values;
148
+ }
149
+
150
+ let obj_keys;
151
+ if (generateArrayPrefix === 'comma' && is_array(obj)) {
152
+ // we need to join elements in
153
+ if (encodeValuesOnly && encoder) {
154
+ // @ts-expect-error values only
155
+ obj = maybe_map(obj, encoder);
156
+ }
157
+ obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
158
+ } else if (is_array(filter)) {
159
+ obj_keys = filter;
160
+ } else {
161
+ const keys = Object.keys(obj);
162
+ obj_keys = sort ? keys.sort(sort) : keys;
163
+ }
164
+
165
+ const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
166
+
167
+ const adjusted_prefix =
168
+ commaRoundTrip && is_array(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
169
+
170
+ if (allowEmptyArrays && is_array(obj) && obj.length === 0) {
171
+ return adjusted_prefix + '[]';
172
+ }
173
+
174
+ for (let j = 0; j < obj_keys.length; ++j) {
175
+ const key = obj_keys[j];
176
+ const value =
177
+ // @ts-ignore
178
+ typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any];
179
+
180
+ if (skipNulls && value === null) {
181
+ continue;
182
+ }
183
+
184
+ // @ts-ignore
185
+ const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key;
186
+ const key_prefix =
187
+ is_array(obj) ?
188
+ typeof generateArrayPrefix === 'function' ?
189
+ generateArrayPrefix(adjusted_prefix, encoded_key)
190
+ : adjusted_prefix
191
+ : adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
192
+
193
+ sideChannel.set(object, step);
194
+ const valueSideChannel = new WeakMap();
195
+ valueSideChannel.set(sentinel, sideChannel);
196
+ push_to_array(
197
+ values,
198
+ inner_stringify(
199
+ value,
200
+ key_prefix,
201
+ generateArrayPrefix,
202
+ commaRoundTrip,
203
+ allowEmptyArrays,
204
+ strictNullHandling,
205
+ skipNulls,
206
+ encodeDotInKeys,
207
+ // @ts-ignore
208
+ generateArrayPrefix === 'comma' && encodeValuesOnly && is_array(obj) ? null : encoder,
209
+ filter,
210
+ sort,
211
+ allowDots,
212
+ serializeDate,
213
+ format,
214
+ formatter,
215
+ encodeValuesOnly,
216
+ charset,
217
+ valueSideChannel,
218
+ ),
219
+ );
220
+ }
221
+
222
+ return values;
223
+ }
224
+
225
+ function normalize_stringify_options(
226
+ opts: StringifyOptions = defaults,
227
+ ): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {
228
+ if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
229
+ throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
230
+ }
231
+
232
+ if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
233
+ throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
234
+ }
235
+
236
+ if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
237
+ throw new TypeError('Encoder has to be a function.');
238
+ }
239
+
240
+ const charset = opts.charset || defaults.charset;
241
+ if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
242
+ throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
243
+ }
244
+
245
+ let format = default_format;
246
+ if (typeof opts.format !== 'undefined') {
247
+ if (!has.call(formatters, opts.format)) {
248
+ throw new TypeError('Unknown format option provided.');
249
+ }
250
+ format = opts.format;
251
+ }
252
+ const formatter = formatters[format];
253
+
254
+ let filter = defaults.filter;
255
+ if (typeof opts.filter === 'function' || is_array(opts.filter)) {
256
+ filter = opts.filter;
257
+ }
258
+
259
+ let arrayFormat: StringifyOptions['arrayFormat'];
260
+ if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
261
+ arrayFormat = opts.arrayFormat;
262
+ } else if ('indices' in opts) {
263
+ arrayFormat = opts.indices ? 'indices' : 'repeat';
264
+ } else {
265
+ arrayFormat = defaults.arrayFormat;
266
+ }
267
+
268
+ if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
269
+ throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
270
+ }
271
+
272
+ const allowDots =
273
+ typeof opts.allowDots === 'undefined' ?
274
+ !!opts.encodeDotInKeys === true ?
275
+ true
276
+ : defaults.allowDots
277
+ : !!opts.allowDots;
278
+
279
+ return {
280
+ addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
281
+ // @ts-ignore
282
+ allowDots: allowDots,
283
+ allowEmptyArrays:
284
+ typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
285
+ arrayFormat: arrayFormat,
286
+ charset: charset,
287
+ charsetSentinel:
288
+ typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
289
+ commaRoundTrip: !!opts.commaRoundTrip,
290
+ delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
291
+ encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
292
+ encodeDotInKeys:
293
+ typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
294
+ encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
295
+ encodeValuesOnly:
296
+ typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
297
+ filter: filter,
298
+ format: format,
299
+ formatter: formatter,
300
+ serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
301
+ skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
302
+ // @ts-ignore
303
+ sort: typeof opts.sort === 'function' ? opts.sort : null,
304
+ strictNullHandling:
305
+ typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
306
+ };
307
+ }
308
+
309
+ export function stringify(object: any, opts: StringifyOptions = {}) {
310
+ let obj = object;
311
+ const options = normalize_stringify_options(opts);
312
+
313
+ let obj_keys: PropertyKey[] | undefined;
314
+ let filter;
315
+
316
+ if (typeof options.filter === 'function') {
317
+ filter = options.filter;
318
+ obj = filter('', obj);
319
+ } else if (is_array(options.filter)) {
320
+ filter = options.filter;
321
+ obj_keys = filter;
322
+ }
323
+
324
+ const keys: string[] = [];
325
+
326
+ if (typeof obj !== 'object' || obj === null) {
327
+ return '';
328
+ }
329
+
330
+ const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
331
+ const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
332
+
333
+ if (!obj_keys) {
334
+ obj_keys = Object.keys(obj);
335
+ }
336
+
337
+ if (options.sort) {
338
+ obj_keys.sort(options.sort);
339
+ }
340
+
341
+ const sideChannel = new WeakMap();
342
+ for (let i = 0; i < obj_keys.length; ++i) {
343
+ const key = obj_keys[i]!;
344
+
345
+ if (options.skipNulls && obj[key] === null) {
346
+ continue;
347
+ }
348
+ push_to_array(
349
+ keys,
350
+ inner_stringify(
351
+ obj[key],
352
+ key,
353
+ // @ts-expect-error
354
+ generateArrayPrefix,
355
+ commaRoundTrip,
356
+ options.allowEmptyArrays,
357
+ options.strictNullHandling,
358
+ options.skipNulls,
359
+ options.encodeDotInKeys,
360
+ options.encode ? options.encoder : null,
361
+ options.filter,
362
+ options.sort,
363
+ options.allowDots,
364
+ options.serializeDate,
365
+ options.format,
366
+ options.formatter,
367
+ options.encodeValuesOnly,
368
+ options.charset,
369
+ sideChannel,
370
+ ),
371
+ );
372
+ }
373
+
374
+ const joined = keys.join(options.delimiter);
375
+ let prefix = options.addQueryPrefix === true ? '?' : '';
376
+
377
+ if (options.charsetSentinel) {
378
+ if (options.charset === 'iso-8859-1') {
379
+ // encodeURIComponent('&#10003;'), the "numeric entity" representation of a checkmark
380
+ prefix += 'utf8=%26%2310003%3B&';
381
+ } else {
382
+ // encodeURIComponent('✓')
383
+ prefix += 'utf8=%E2%9C%93&';
384
+ }
385
+ }
386
+
387
+ return joined.length > 0 ? prefix + joined : '';
388
+ }
@@ -0,0 +1,71 @@
1
+ export type Format = 'RFC1738' | 'RFC3986';
2
+
3
+ export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
4
+ export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string;
5
+
6
+ export type BooleanOptional = boolean | undefined;
7
+
8
+ export type StringifyBaseOptions = {
9
+ delimiter?: string;
10
+ allowDots?: boolean;
11
+ encodeDotInKeys?: boolean;
12
+ strictNullHandling?: boolean;
13
+ skipNulls?: boolean;
14
+ encode?: boolean;
15
+ encoder?: (
16
+ str: any,
17
+ defaultEncoder: DefaultEncoder,
18
+ charset: string,
19
+ type: 'key' | 'value',
20
+ format?: Format,
21
+ ) => string;
22
+ filter?: Array<PropertyKey> | ((prefix: PropertyKey, value: any) => any);
23
+ arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';
24
+ indices?: boolean;
25
+ sort?: ((a: PropertyKey, b: PropertyKey) => number) | null;
26
+ serializeDate?: (d: Date) => string;
27
+ format?: 'RFC1738' | 'RFC3986';
28
+ formatter?: (str: PropertyKey) => string;
29
+ encodeValuesOnly?: boolean;
30
+ addQueryPrefix?: boolean;
31
+ charset?: 'utf-8' | 'iso-8859-1';
32
+ charsetSentinel?: boolean;
33
+ allowEmptyArrays?: boolean;
34
+ commaRoundTrip?: boolean;
35
+ };
36
+
37
+ export type StringifyOptions = StringifyBaseOptions;
38
+
39
+ export type ParseBaseOptions = {
40
+ comma?: boolean;
41
+ delimiter?: string | RegExp;
42
+ depth?: number | false;
43
+ decoder?: (str: string, defaultDecoder: DefaultDecoder, charset: string, type: 'key' | 'value') => any;
44
+ arrayLimit?: number;
45
+ parseArrays?: boolean;
46
+ plainObjects?: boolean;
47
+ allowPrototypes?: boolean;
48
+ allowSparse?: boolean;
49
+ parameterLimit?: number;
50
+ strictDepth?: boolean;
51
+ strictNullHandling?: boolean;
52
+ ignoreQueryPrefix?: boolean;
53
+ charset?: 'utf-8' | 'iso-8859-1';
54
+ charsetSentinel?: boolean;
55
+ interpretNumericEntities?: boolean;
56
+ allowEmptyArrays?: boolean;
57
+ duplicates?: 'combine' | 'first' | 'last';
58
+ allowDots?: boolean;
59
+ decodeDotInKeys?: boolean;
60
+ };
61
+
62
+ export type ParseOptions = ParseBaseOptions;
63
+
64
+ export type ParsedQs = {
65
+ [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
66
+ };
67
+
68
+ // Type to remove null or undefined union from each property
69
+ export type NonNullableProperties<T> = {
70
+ [K in keyof T]-?: Exclude<T[K], undefined | null>;
71
+ };