@revenexx/sdk 0.0.2

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 (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/cjs/package.json +3 -0
  4. package/dist/cjs/sdk.js +16340 -0
  5. package/dist/cjs/sdk.js.map +1 -0
  6. package/dist/esm/package.json +3 -0
  7. package/dist/esm/sdk.js +16250 -0
  8. package/dist/esm/sdk.js.map +1 -0
  9. package/dist/iife/sdk.js +20101 -0
  10. package/package.json +56 -0
  11. package/src/channel.ts +158 -0
  12. package/src/client.ts +950 -0
  13. package/src/enums/adapter.ts +4 -0
  14. package/src/enums/attribute-boolean-status.ts +7 -0
  15. package/src/enums/attribute-datetime-status.ts +7 -0
  16. package/src/enums/attribute-email-status.ts +7 -0
  17. package/src/enums/attribute-enum-status.ts +7 -0
  18. package/src/enums/attribute-float-status.ts +7 -0
  19. package/src/enums/attribute-integer-status.ts +7 -0
  20. package/src/enums/attribute-ip-status.ts +7 -0
  21. package/src/enums/attribute-line-status.ts +7 -0
  22. package/src/enums/attribute-longtext-status.ts +7 -0
  23. package/src/enums/attribute-mediumtext-status.ts +7 -0
  24. package/src/enums/attribute-point-status.ts +7 -0
  25. package/src/enums/attribute-polygon-status.ts +7 -0
  26. package/src/enums/attribute-relationship-status.ts +7 -0
  27. package/src/enums/attribute-string-status.ts +7 -0
  28. package/src/enums/attribute-text-status.ts +7 -0
  29. package/src/enums/attribute-url-status.ts +7 -0
  30. package/src/enums/attribute-varchar-status.ts +7 -0
  31. package/src/enums/build-runtime.ts +73 -0
  32. package/src/enums/code.ts +16 -0
  33. package/src/enums/collection.ts +4 -0
  34. package/src/enums/column-boolean-status.ts +7 -0
  35. package/src/enums/column-datetime-status.ts +7 -0
  36. package/src/enums/column-email-status.ts +7 -0
  37. package/src/enums/column-enum-status.ts +7 -0
  38. package/src/enums/column-float-status.ts +7 -0
  39. package/src/enums/column-integer-status.ts +7 -0
  40. package/src/enums/column-ip-status.ts +7 -0
  41. package/src/enums/column-line-status.ts +7 -0
  42. package/src/enums/column-longtext-status.ts +7 -0
  43. package/src/enums/column-mediumtext-status.ts +7 -0
  44. package/src/enums/column-point-status.ts +7 -0
  45. package/src/enums/column-polygon-status.ts +7 -0
  46. package/src/enums/column-relationship-status.ts +7 -0
  47. package/src/enums/column-string-status.ts +7 -0
  48. package/src/enums/column-text-status.ts +7 -0
  49. package/src/enums/column-url-status.ts +7 -0
  50. package/src/enums/column-varchar-status.ts +7 -0
  51. package/src/enums/compression.ts +5 -0
  52. package/src/enums/database-type.ts +4 -0
  53. package/src/enums/deployment-status.ts +8 -0
  54. package/src/enums/execution-status.ts +7 -0
  55. package/src/enums/execution-trigger.ts +5 -0
  56. package/src/enums/framework.ts +17 -0
  57. package/src/enums/gravity.ts +11 -0
  58. package/src/enums/health-antivirus-status.ts +5 -0
  59. package/src/enums/health-status-status.ts +4 -0
  60. package/src/enums/index-status.ts +7 -0
  61. package/src/enums/message-status.ts +7 -0
  62. package/src/enums/method.ts +9 -0
  63. package/src/enums/output.ts +9 -0
  64. package/src/enums/permissions.ts +22 -0
  65. package/src/enums/priority.ts +4 -0
  66. package/src/enums/range.ts +5 -0
  67. package/src/enums/runtime.ts +73 -0
  68. package/src/enums/runtimes.ts +73 -0
  69. package/src/enums/scopes.ts +57 -0
  70. package/src/enums/theme.ts +4 -0
  71. package/src/enums/timezone.ts +421 -0
  72. package/src/enums/type.ts +5 -0
  73. package/src/enums/use-cases.ts +9 -0
  74. package/src/id.ts +47 -0
  75. package/src/index.ts +92 -0
  76. package/src/models.ts +6013 -0
  77. package/src/operator.ts +308 -0
  78. package/src/permission.ts +57 -0
  79. package/src/query.ts +576 -0
  80. package/src/role.ts +100 -0
  81. package/src/service.ts +30 -0
  82. package/src/services/apps.ts +2473 -0
  83. package/src/services/avatars.ts +744 -0
  84. package/src/services/carts.ts +1057 -0
  85. package/src/services/channels.ts +227 -0
  86. package/src/services/customers.ts +729 -0
  87. package/src/services/greetings.ts +294 -0
  88. package/src/services/locale.ts +198 -0
  89. package/src/services/markets.ts +796 -0
  90. package/src/services/messaging.ts +3463 -0
  91. package/src/services/products.ts +3100 -0
  92. package/src/services/realtime.ts +537 -0
  93. package/src/services/search.ts +346 -0
  94. package/src/services/sites.ts +1847 -0
  95. package/src/services/storage.ts +1076 -0
  96. package/src/services/tokens.ts +314 -0
  97. package/types/channel.d.ts +74 -0
  98. package/types/client.d.ts +211 -0
  99. package/types/enums/adapter.d.ts +4 -0
  100. package/types/enums/attribute-boolean-status.d.ts +7 -0
  101. package/types/enums/attribute-datetime-status.d.ts +7 -0
  102. package/types/enums/attribute-email-status.d.ts +7 -0
  103. package/types/enums/attribute-enum-status.d.ts +7 -0
  104. package/types/enums/attribute-float-status.d.ts +7 -0
  105. package/types/enums/attribute-integer-status.d.ts +7 -0
  106. package/types/enums/attribute-ip-status.d.ts +7 -0
  107. package/types/enums/attribute-line-status.d.ts +7 -0
  108. package/types/enums/attribute-longtext-status.d.ts +7 -0
  109. package/types/enums/attribute-mediumtext-status.d.ts +7 -0
  110. package/types/enums/attribute-point-status.d.ts +7 -0
  111. package/types/enums/attribute-polygon-status.d.ts +7 -0
  112. package/types/enums/attribute-relationship-status.d.ts +7 -0
  113. package/types/enums/attribute-string-status.d.ts +7 -0
  114. package/types/enums/attribute-text-status.d.ts +7 -0
  115. package/types/enums/attribute-url-status.d.ts +7 -0
  116. package/types/enums/attribute-varchar-status.d.ts +7 -0
  117. package/types/enums/build-runtime.d.ts +73 -0
  118. package/types/enums/code.d.ts +16 -0
  119. package/types/enums/collection.d.ts +4 -0
  120. package/types/enums/column-boolean-status.d.ts +7 -0
  121. package/types/enums/column-datetime-status.d.ts +7 -0
  122. package/types/enums/column-email-status.d.ts +7 -0
  123. package/types/enums/column-enum-status.d.ts +7 -0
  124. package/types/enums/column-float-status.d.ts +7 -0
  125. package/types/enums/column-integer-status.d.ts +7 -0
  126. package/types/enums/column-ip-status.d.ts +7 -0
  127. package/types/enums/column-line-status.d.ts +7 -0
  128. package/types/enums/column-longtext-status.d.ts +7 -0
  129. package/types/enums/column-mediumtext-status.d.ts +7 -0
  130. package/types/enums/column-point-status.d.ts +7 -0
  131. package/types/enums/column-polygon-status.d.ts +7 -0
  132. package/types/enums/column-relationship-status.d.ts +7 -0
  133. package/types/enums/column-string-status.d.ts +7 -0
  134. package/types/enums/column-text-status.d.ts +7 -0
  135. package/types/enums/column-url-status.d.ts +7 -0
  136. package/types/enums/column-varchar-status.d.ts +7 -0
  137. package/types/enums/compression.d.ts +5 -0
  138. package/types/enums/database-type.d.ts +4 -0
  139. package/types/enums/deployment-status.d.ts +8 -0
  140. package/types/enums/execution-status.d.ts +7 -0
  141. package/types/enums/execution-trigger.d.ts +5 -0
  142. package/types/enums/framework.d.ts +17 -0
  143. package/types/enums/gravity.d.ts +11 -0
  144. package/types/enums/health-antivirus-status.d.ts +5 -0
  145. package/types/enums/health-status-status.d.ts +4 -0
  146. package/types/enums/index-status.d.ts +7 -0
  147. package/types/enums/message-status.d.ts +7 -0
  148. package/types/enums/method.d.ts +9 -0
  149. package/types/enums/output.d.ts +9 -0
  150. package/types/enums/permissions.d.ts +22 -0
  151. package/types/enums/priority.d.ts +4 -0
  152. package/types/enums/range.d.ts +5 -0
  153. package/types/enums/runtime.d.ts +73 -0
  154. package/types/enums/runtimes.d.ts +73 -0
  155. package/types/enums/scopes.d.ts +57 -0
  156. package/types/enums/theme.d.ts +4 -0
  157. package/types/enums/timezone.d.ts +421 -0
  158. package/types/enums/type.d.ts +5 -0
  159. package/types/enums/use-cases.d.ts +9 -0
  160. package/types/id.d.ts +20 -0
  161. package/types/index.d.ts +92 -0
  162. package/types/models.d.ts +5830 -0
  163. package/types/operator.d.ts +180 -0
  164. package/types/permission.d.ts +43 -0
  165. package/types/query.d.ts +442 -0
  166. package/types/role.d.ts +70 -0
  167. package/types/service.d.ts +11 -0
  168. package/types/services/apps.d.ts +932 -0
  169. package/types/services/avatars.d.ts +318 -0
  170. package/types/services/carts.d.ts +352 -0
  171. package/types/services/channels.d.ts +75 -0
  172. package/types/services/customers.d.ts +231 -0
  173. package/types/services/greetings.d.ts +101 -0
  174. package/types/services/locale.d.ts +64 -0
  175. package/types/services/markets.d.ts +274 -0
  176. package/types/services/messaging.d.ts +1324 -0
  177. package/types/services/products.d.ts +1014 -0
  178. package/types/services/realtime.d.ts +134 -0
  179. package/types/services/search.d.ts +131 -0
  180. package/types/services/sites.d.ts +689 -0
  181. package/types/services/storage.d.ts +421 -0
  182. package/types/services/tokens.d.ts +119 -0
@@ -0,0 +1,308 @@
1
+ type OperatorValuesSingle = string | number | boolean;
2
+ export type OperatorValuesList = string[] | number[] | boolean[] | any[];
3
+ export type OperatorValues = OperatorValuesSingle | OperatorValuesList;
4
+
5
+ export enum Condition {
6
+ Equal = "equal",
7
+ NotEqual = "notEqual",
8
+ GreaterThan = "greaterThan",
9
+ GreaterThanEqual = "greaterThanEqual",
10
+ LessThan = "lessThan",
11
+ LessThanEqual = "lessThanEqual",
12
+ Contains = "contains",
13
+ IsNull = "isNull",
14
+ IsNotNull = "isNotNull",
15
+ }
16
+
17
+ /**
18
+ * Helper class to generate operator strings for atomic operations.
19
+ */
20
+ export class Operator {
21
+ method: string;
22
+ values: OperatorValuesList | undefined;
23
+
24
+ /**
25
+ * Constructor for Operator class.
26
+ *
27
+ * @param {string} method
28
+ * @param {OperatorValues} values
29
+ */
30
+ constructor(
31
+ method: string,
32
+ values?: OperatorValues
33
+ ) {
34
+ this.method = method;
35
+
36
+ if (values !== undefined) {
37
+ if (Array.isArray(values)) {
38
+ this.values = values;
39
+ } else {
40
+ this.values = [values] as OperatorValuesList;
41
+ }
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Convert the operator object to a JSON string.
47
+ *
48
+ * @returns {string}
49
+ */
50
+ toString(): string {
51
+ return JSON.stringify({
52
+ method: this.method,
53
+ values: this.values,
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Increment a numeric attribute by a specified value.
59
+ *
60
+ * @param {number} value
61
+ * @param {number} max
62
+ * @returns {string}
63
+ */
64
+ static increment = (value: number = 1, max?: number): string => {
65
+ if (isNaN(value) || !isFinite(value)) {
66
+ throw new Error("Value cannot be NaN or Infinity");
67
+ }
68
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
69
+ throw new Error("Max cannot be NaN or Infinity");
70
+ }
71
+ const values: any[] = [value];
72
+ if (max !== undefined) {
73
+ values.push(max);
74
+ }
75
+ return new Operator("increment", values).toString();
76
+ };
77
+
78
+ /**
79
+ * Decrement a numeric attribute by a specified value.
80
+ *
81
+ * @param {number} value
82
+ * @param {number} min
83
+ * @returns {string}
84
+ */
85
+ static decrement = (value: number = 1, min?: number): string => {
86
+ if (isNaN(value) || !isFinite(value)) {
87
+ throw new Error("Value cannot be NaN or Infinity");
88
+ }
89
+ if (min !== undefined && (isNaN(min) || !isFinite(min))) {
90
+ throw new Error("Min cannot be NaN or Infinity");
91
+ }
92
+ const values: any[] = [value];
93
+ if (min !== undefined) {
94
+ values.push(min);
95
+ }
96
+ return new Operator("decrement", values).toString();
97
+ };
98
+
99
+ /**
100
+ * Multiply a numeric attribute by a specified factor.
101
+ *
102
+ * @param {number} factor
103
+ * @param {number} max
104
+ * @returns {string}
105
+ */
106
+ static multiply = (factor: number, max?: number): string => {
107
+ if (isNaN(factor) || !isFinite(factor)) {
108
+ throw new Error("Factor cannot be NaN or Infinity");
109
+ }
110
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
111
+ throw new Error("Max cannot be NaN or Infinity");
112
+ }
113
+ const values: any[] = [factor];
114
+ if (max !== undefined) {
115
+ values.push(max);
116
+ }
117
+ return new Operator("multiply", values).toString();
118
+ };
119
+
120
+ /**
121
+ * Divide a numeric attribute by a specified divisor.
122
+ *
123
+ * @param {number} divisor
124
+ * @param {number} min
125
+ * @returns {string}
126
+ */
127
+ static divide = (divisor: number, min?: number): string => {
128
+ if (isNaN(divisor) || !isFinite(divisor)) {
129
+ throw new Error("Divisor cannot be NaN or Infinity");
130
+ }
131
+ if (min !== undefined && (isNaN(min) || !isFinite(min))) {
132
+ throw new Error("Min cannot be NaN or Infinity");
133
+ }
134
+ if (divisor === 0) {
135
+ throw new Error("Divisor cannot be zero");
136
+ }
137
+ const values: any[] = [divisor];
138
+ if (min !== undefined) {
139
+ values.push(min);
140
+ }
141
+ return new Operator("divide", values).toString();
142
+ };
143
+
144
+ /**
145
+ * Apply modulo operation on a numeric attribute.
146
+ *
147
+ * @param {number} divisor
148
+ * @returns {string}
149
+ */
150
+ static modulo = (divisor: number): string => {
151
+ if (isNaN(divisor) || !isFinite(divisor)) {
152
+ throw new Error("Divisor cannot be NaN or Infinity");
153
+ }
154
+ if (divisor === 0) {
155
+ throw new Error("Divisor cannot be zero");
156
+ }
157
+ return new Operator("modulo", [divisor]).toString();
158
+ };
159
+
160
+ /**
161
+ * Raise a numeric attribute to a specified power.
162
+ *
163
+ * @param {number} exponent
164
+ * @param {number} max
165
+ * @returns {string}
166
+ */
167
+ static power = (exponent: number, max?: number): string => {
168
+ if (isNaN(exponent) || !isFinite(exponent)) {
169
+ throw new Error("Exponent cannot be NaN or Infinity");
170
+ }
171
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
172
+ throw new Error("Max cannot be NaN or Infinity");
173
+ }
174
+ const values: any[] = [exponent];
175
+ if (max !== undefined) {
176
+ values.push(max);
177
+ }
178
+ return new Operator("power", values).toString();
179
+ };
180
+
181
+ /**
182
+ * Append values to an array attribute.
183
+ *
184
+ * @param {any[]} values
185
+ * @returns {string}
186
+ */
187
+ static arrayAppend = (values: any[]): string =>
188
+ new Operator("arrayAppend", values).toString();
189
+
190
+ /**
191
+ * Prepend values to an array attribute.
192
+ *
193
+ * @param {any[]} values
194
+ * @returns {string}
195
+ */
196
+ static arrayPrepend = (values: any[]): string =>
197
+ new Operator("arrayPrepend", values).toString();
198
+
199
+ /**
200
+ * Insert a value at a specific index in an array attribute.
201
+ *
202
+ * @param {number} index
203
+ * @param {any} value
204
+ * @returns {string}
205
+ */
206
+ static arrayInsert = (index: number, value: any): string =>
207
+ new Operator("arrayInsert", [index, value]).toString();
208
+
209
+ /**
210
+ * Remove a value from an array attribute.
211
+ *
212
+ * @param {any} value
213
+ * @returns {string}
214
+ */
215
+ static arrayRemove = (value: any): string =>
216
+ new Operator("arrayRemove", [value]).toString();
217
+
218
+ /**
219
+ * Remove duplicate values from an array attribute.
220
+ *
221
+ * @returns {string}
222
+ */
223
+ static arrayUnique = (): string =>
224
+ new Operator("arrayUnique", []).toString();
225
+
226
+ /**
227
+ * Keep only values that exist in both the current array and the provided array.
228
+ *
229
+ * @param {any[]} values
230
+ * @returns {string}
231
+ */
232
+ static arrayIntersect = (values: any[]): string =>
233
+ new Operator("arrayIntersect", values).toString();
234
+
235
+ /**
236
+ * Remove values from the array that exist in the provided array.
237
+ *
238
+ * @param {any[]} values
239
+ * @returns {string}
240
+ */
241
+ static arrayDiff = (values: any[]): string =>
242
+ new Operator("arrayDiff", values).toString();
243
+
244
+ /**
245
+ * Filter array values based on a condition.
246
+ *
247
+ * @param {Condition} condition
248
+ * @param {any} value
249
+ * @returns {string}
250
+ */
251
+ static arrayFilter = (condition: Condition, value?: any): string => {
252
+ const values: any[] = [condition as string, value === undefined ? null : value];
253
+ return new Operator("arrayFilter", values).toString();
254
+ };
255
+
256
+ /**
257
+ * Concatenate a value to a string or array attribute.
258
+ *
259
+ * @param {any} value
260
+ * @returns {string}
261
+ */
262
+ static stringConcat = (value: any): string =>
263
+ new Operator("stringConcat", [value]).toString();
264
+
265
+ /**
266
+ * Replace occurrences of a search string with a replacement string.
267
+ *
268
+ * @param {string} search
269
+ * @param {string} replace
270
+ * @returns {string}
271
+ */
272
+ static stringReplace = (search: string, replace: string): string =>
273
+ new Operator("stringReplace", [search, replace]).toString();
274
+
275
+ /**
276
+ * Toggle a boolean attribute.
277
+ *
278
+ * @returns {string}
279
+ */
280
+ static toggle = (): string =>
281
+ new Operator("toggle", []).toString();
282
+
283
+ /**
284
+ * Add days to a date attribute.
285
+ *
286
+ * @param {number} days
287
+ * @returns {string}
288
+ */
289
+ static dateAddDays = (days: number): string =>
290
+ new Operator("dateAddDays", [days]).toString();
291
+
292
+ /**
293
+ * Subtract days from a date attribute.
294
+ *
295
+ * @param {number} days
296
+ * @returns {string}
297
+ */
298
+ static dateSubDays = (days: number): string =>
299
+ new Operator("dateSubDays", [days]).toString();
300
+
301
+ /**
302
+ * Set a date attribute to the current date and time.
303
+ *
304
+ * @returns {string}
305
+ */
306
+ static dateSetNow = (): string =>
307
+ new Operator("dateSetNow", []).toString();
308
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Helper class to generate permission strings for resources.
3
+ */
4
+ export class Permission {
5
+ /**
6
+ * Generate read permission string for the provided role.
7
+ *
8
+ * @param {string} role
9
+ * @returns {string}
10
+ */
11
+ static read = (role: string): string => {
12
+ return `read("${role}")`;
13
+ }
14
+
15
+ /**
16
+ * Generate write permission string for the provided role.
17
+ *
18
+ * This is an alias of update, delete, and possibly create.
19
+ * Don't use write in combination with update, delete, or create.
20
+ *
21
+ * @param {string} role
22
+ * @returns {string}
23
+ */
24
+ static write = (role: string): string => {
25
+ return `write("${role}")`;
26
+ }
27
+
28
+ /**
29
+ * Generate create permission string for the provided role.
30
+ *
31
+ * @param {string} role
32
+ * @returns {string}
33
+ */
34
+ static create = (role: string): string => {
35
+ return `create("${role}")`;
36
+ }
37
+
38
+ /**
39
+ * Generate update permission string for the provided role.
40
+ *
41
+ * @param {string} role
42
+ * @returns {string}
43
+ */
44
+ static update = (role: string): string => {
45
+ return `update("${role}")`;
46
+ }
47
+
48
+ /**
49
+ * Generate delete permission string for the provided role.
50
+ *
51
+ * @param {string} role
52
+ * @returns {string}
53
+ */
54
+ static delete = (role: string): string => {
55
+ return `delete("${role}")`;
56
+ }
57
+ }