poad 2.1.1

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/main/OmneediaClient.d.ts +28 -0
  4. package/dist/main/OmneediaClient.d.ts.map +1 -0
  5. package/dist/main/OmneediaClient.js +58 -0
  6. package/dist/main/OmneediaClient.js.map +1 -0
  7. package/dist/main/env/prefix-dev.d.ts +7 -0
  8. package/dist/main/env/prefix-dev.d.ts.map +1 -0
  9. package/dist/main/env/prefix-dev.js +8 -0
  10. package/dist/main/env/prefix-dev.js.map +1 -0
  11. package/dist/main/env/prefix-prod.d.ts +7 -0
  12. package/dist/main/env/prefix-prod.d.ts.map +1 -0
  13. package/dist/main/env/prefix-prod.js +8 -0
  14. package/dist/main/env/prefix-prod.js.map +1 -0
  15. package/dist/main/env/prefix.d.ts +7 -0
  16. package/dist/main/env/prefix.d.ts.map +1 -0
  17. package/dist/main/env/prefix.js +8 -0
  18. package/dist/main/env/prefix.js.map +1 -0
  19. package/dist/main/index.d.ts +11 -0
  20. package/dist/main/index.d.ts.map +1 -0
  21. package/dist/main/index.js +19 -0
  22. package/dist/main/index.js.map +1 -0
  23. package/dist/main/lib/auth.d.ts +22 -0
  24. package/dist/main/lib/auth.d.ts.map +1 -0
  25. package/dist/main/lib/auth.js +352 -0
  26. package/dist/main/lib/auth.js.map +1 -0
  27. package/dist/main/lib/constants.d.ts +8 -0
  28. package/dist/main/lib/constants.d.ts.map +1 -0
  29. package/dist/main/lib/constants.js +11 -0
  30. package/dist/main/lib/constants.js.map +1 -0
  31. package/dist/main/lib/db.d.ts +45 -0
  32. package/dist/main/lib/db.d.ts.map +1 -0
  33. package/dist/main/lib/db.js +252 -0
  34. package/dist/main/lib/db.js.map +1 -0
  35. package/dist/main/lib/error-codes.d.ts +7 -0
  36. package/dist/main/lib/error-codes.d.ts.map +1 -0
  37. package/dist/main/lib/error-codes.js +3 -0
  38. package/dist/main/lib/error-codes.js.map +1 -0
  39. package/dist/main/lib/errors.d.ts +96 -0
  40. package/dist/main/lib/errors.d.ts.map +1 -0
  41. package/dist/main/lib/errors.js +127 -0
  42. package/dist/main/lib/errors.js.map +1 -0
  43. package/dist/main/lib/realtime.d.ts +9 -0
  44. package/dist/main/lib/realtime.d.ts.map +1 -0
  45. package/dist/main/lib/realtime.js +36 -0
  46. package/dist/main/lib/realtime.js.map +1 -0
  47. package/dist/main/lib/request.d.ts +40 -0
  48. package/dist/main/lib/request.d.ts.map +1 -0
  49. package/dist/main/lib/request.js +237 -0
  50. package/dist/main/lib/request.js.map +1 -0
  51. package/dist/main/lib/types.d.ts +408 -0
  52. package/dist/main/lib/types.d.ts.map +1 -0
  53. package/dist/main/lib/types.js +11 -0
  54. package/dist/main/lib/types.js.map +1 -0
  55. package/dist/main/lib/util.d.ts +7 -0
  56. package/dist/main/lib/util.d.ts.map +1 -0
  57. package/dist/main/lib/util.js +90 -0
  58. package/dist/main/lib/util.js.map +1 -0
  59. package/dist/main/lib copy/auth.d.ts +22 -0
  60. package/dist/main/lib copy/auth.d.ts.map +1 -0
  61. package/dist/main/lib copy/auth.js +283 -0
  62. package/dist/main/lib copy/auth.js.map +1 -0
  63. package/dist/main/lib copy/auth_api.d.ts +23 -0
  64. package/dist/main/lib copy/auth_api.d.ts.map +1 -0
  65. package/dist/main/lib copy/auth_api.js +90 -0
  66. package/dist/main/lib copy/auth_api.js.map +1 -0
  67. package/dist/main/lib copy/constants.d.ts +8 -0
  68. package/dist/main/lib copy/constants.d.ts.map +1 -0
  69. package/dist/main/lib copy/constants.js +11 -0
  70. package/dist/main/lib copy/constants.js.map +1 -0
  71. package/dist/main/lib copy/cookies.d.ts +20 -0
  72. package/dist/main/lib copy/cookies.d.ts.map +1 -0
  73. package/dist/main/lib copy/cookies.js +144 -0
  74. package/dist/main/lib copy/cookies.js.map +1 -0
  75. package/dist/main/lib copy/db.d.ts +45 -0
  76. package/dist/main/lib copy/db.d.ts.map +1 -0
  77. package/dist/main/lib copy/db.js +252 -0
  78. package/dist/main/lib copy/db.js.map +1 -0
  79. package/dist/main/lib copy/realtime.d.ts +9 -0
  80. package/dist/main/lib copy/realtime.d.ts.map +1 -0
  81. package/dist/main/lib copy/realtime.js +36 -0
  82. package/dist/main/lib copy/realtime.js.map +1 -0
  83. package/dist/main/lib copy/request.d.ts +40 -0
  84. package/dist/main/lib copy/request.d.ts.map +1 -0
  85. package/dist/main/lib copy/request.js +206 -0
  86. package/dist/main/lib copy/request.js.map +1 -0
  87. package/dist/main/lib copy/types.d.ts +124 -0
  88. package/dist/main/lib copy/types.d.ts.map +1 -0
  89. package/dist/main/lib copy/types.js +3 -0
  90. package/dist/main/lib copy/types.js.map +1 -0
  91. package/dist/main/lib copy/util.d.ts +7 -0
  92. package/dist/main/lib copy/util.d.ts.map +1 -0
  93. package/dist/main/lib copy/util.js +90 -0
  94. package/dist/main/lib copy/util.js.map +1 -0
  95. package/dist/module/OmneediaClient.d.ts +28 -0
  96. package/dist/module/OmneediaClient.d.ts.map +1 -0
  97. package/dist/module/OmneediaClient.js +52 -0
  98. package/dist/module/OmneediaClient.js.map +1 -0
  99. package/dist/module/env/prefix-dev.d.ts +7 -0
  100. package/dist/module/env/prefix-dev.d.ts.map +1 -0
  101. package/dist/module/env/prefix-dev.js +6 -0
  102. package/dist/module/env/prefix-dev.js.map +1 -0
  103. package/dist/module/env/prefix-prod.d.ts +7 -0
  104. package/dist/module/env/prefix-prod.d.ts.map +1 -0
  105. package/dist/module/env/prefix-prod.js +6 -0
  106. package/dist/module/env/prefix-prod.js.map +1 -0
  107. package/dist/module/env/prefix.d.ts +7 -0
  108. package/dist/module/env/prefix.d.ts.map +1 -0
  109. package/dist/module/env/prefix.js +6 -0
  110. package/dist/module/env/prefix.js.map +1 -0
  111. package/dist/module/index.d.ts +11 -0
  112. package/dist/module/index.d.ts.map +1 -0
  113. package/dist/module/index.js +12 -0
  114. package/dist/module/index.js.map +1 -0
  115. package/dist/module/lib/auth.d.ts +22 -0
  116. package/dist/module/lib/auth.d.ts.map +1 -0
  117. package/dist/module/lib/auth.js +349 -0
  118. package/dist/module/lib/auth.js.map +1 -0
  119. package/dist/module/lib/constants.d.ts +8 -0
  120. package/dist/module/lib/constants.d.ts.map +1 -0
  121. package/dist/module/lib/constants.js +8 -0
  122. package/dist/module/lib/constants.js.map +1 -0
  123. package/dist/module/lib/db.d.ts +45 -0
  124. package/dist/module/lib/db.d.ts.map +1 -0
  125. package/dist/module/lib/db.js +246 -0
  126. package/dist/module/lib/db.js.map +1 -0
  127. package/dist/module/lib/error-codes.d.ts +7 -0
  128. package/dist/module/lib/error-codes.d.ts.map +1 -0
  129. package/dist/module/lib/error-codes.js +2 -0
  130. package/dist/module/lib/error-codes.js.map +1 -0
  131. package/dist/module/lib/errors.d.ts +96 -0
  132. package/dist/module/lib/errors.d.ts.map +1 -0
  133. package/dist/module/lib/errors.js +108 -0
  134. package/dist/module/lib/errors.js.map +1 -0
  135. package/dist/module/lib/realtime.d.ts +9 -0
  136. package/dist/module/lib/realtime.d.ts.map +1 -0
  137. package/dist/module/lib/realtime.js +33 -0
  138. package/dist/module/lib/realtime.js.map +1 -0
  139. package/dist/module/lib/request.d.ts +40 -0
  140. package/dist/module/lib/request.d.ts.map +1 -0
  141. package/dist/module/lib/request.js +231 -0
  142. package/dist/module/lib/request.js.map +1 -0
  143. package/dist/module/lib/types.d.ts +408 -0
  144. package/dist/module/lib/types.d.ts.map +1 -0
  145. package/dist/module/lib/types.js +8 -0
  146. package/dist/module/lib/types.js.map +1 -0
  147. package/dist/module/lib/util.d.ts +7 -0
  148. package/dist/module/lib/util.d.ts.map +1 -0
  149. package/dist/module/lib/util.js +81 -0
  150. package/dist/module/lib/util.js.map +1 -0
  151. package/dist/module/lib copy/auth.d.ts +22 -0
  152. package/dist/module/lib copy/auth.d.ts.map +1 -0
  153. package/dist/module/lib copy/auth.js +277 -0
  154. package/dist/module/lib copy/auth.js.map +1 -0
  155. package/dist/module/lib copy/auth_api.d.ts +23 -0
  156. package/dist/module/lib copy/auth_api.d.ts.map +1 -0
  157. package/dist/module/lib copy/auth_api.js +87 -0
  158. package/dist/module/lib copy/auth_api.js.map +1 -0
  159. package/dist/module/lib copy/constants.d.ts +8 -0
  160. package/dist/module/lib copy/constants.d.ts.map +1 -0
  161. package/dist/module/lib copy/constants.js +8 -0
  162. package/dist/module/lib copy/constants.js.map +1 -0
  163. package/dist/module/lib copy/cookies.d.ts +20 -0
  164. package/dist/module/lib copy/cookies.d.ts.map +1 -0
  165. package/dist/module/lib copy/cookies.js +137 -0
  166. package/dist/module/lib copy/cookies.js.map +1 -0
  167. package/dist/module/lib copy/db.d.ts +45 -0
  168. package/dist/module/lib copy/db.d.ts.map +1 -0
  169. package/dist/module/lib copy/db.js +246 -0
  170. package/dist/module/lib copy/db.js.map +1 -0
  171. package/dist/module/lib copy/realtime.d.ts +9 -0
  172. package/dist/module/lib copy/realtime.d.ts.map +1 -0
  173. package/dist/module/lib copy/realtime.js +33 -0
  174. package/dist/module/lib copy/realtime.js.map +1 -0
  175. package/dist/module/lib copy/request.d.ts +40 -0
  176. package/dist/module/lib copy/request.d.ts.map +1 -0
  177. package/dist/module/lib copy/request.js +200 -0
  178. package/dist/module/lib copy/request.js.map +1 -0
  179. package/dist/module/lib copy/types.d.ts +124 -0
  180. package/dist/module/lib copy/types.d.ts.map +1 -0
  181. package/dist/module/lib copy/types.js +2 -0
  182. package/dist/module/lib copy/types.js.map +1 -0
  183. package/dist/module/lib copy/util.d.ts +7 -0
  184. package/dist/module/lib copy/util.d.ts.map +1 -0
  185. package/dist/module/lib copy/util.js +81 -0
  186. package/dist/module/lib copy/util.js.map +1 -0
  187. package/dist/umd/941.omneedia.js +1 -0
  188. package/dist/umd/omneedia.js +2 -0
  189. package/dist/umd/omneedia.js.LICENSE.txt +1 -0
  190. package/package.json +80 -0
  191. package/src/OmneediaClient.ts +65 -0
  192. package/src/env/prefix-dev.ts +5 -0
  193. package/src/env/prefix-prod.ts +5 -0
  194. package/src/env/prefix.ts +5 -0
  195. package/src/index.ts +26 -0
  196. package/src/lib/auth.ts +306 -0
  197. package/src/lib/constants.ts +7 -0
  198. package/src/lib/db.ts +216 -0
  199. package/src/lib/error-codes.ts +71 -0
  200. package/src/lib/errors.ts +153 -0
  201. package/src/lib/realtime.ts +21 -0
  202. package/src/lib/request.ts +198 -0
  203. package/src/lib/types.ts +512 -0
  204. package/src/lib/util.ts +83 -0
@@ -0,0 +1,153 @@
1
+ import { WeakPasswordReasons } from './types'
2
+ import { ErrorCode } from './error-codes'
3
+
4
+ export class AuthError extends Error {
5
+ /**
6
+ * Error code associated with the error. Most errors coming from
7
+ * HTTP responses will have a code, though some errors that occur
8
+ * before a response is received will not have one present. In that
9
+ * case {@link #status} will also be undefined.
10
+ */
11
+ code: ErrorCode | string | undefined
12
+
13
+ /** HTTP status code that caused the error. */
14
+ status: number | undefined
15
+
16
+ protected __isAuthError = true
17
+
18
+ constructor(message: string, status?: number, code?: string) {
19
+ super(message)
20
+ this.name = 'AuthError'
21
+ this.status = status
22
+ this.code = code
23
+ }
24
+ }
25
+
26
+ export function isAuthError(error: unknown): error is AuthError {
27
+ return typeof error === 'object' && error !== null && '__isAuthError' in error
28
+ }
29
+
30
+ export class AuthApiError extends AuthError {
31
+ status: number
32
+
33
+ constructor(message: string, status: number, code: string | undefined) {
34
+ super(message, status, code)
35
+ this.name = 'AuthApiError'
36
+ this.status = status
37
+ this.code = code
38
+ }
39
+ }
40
+
41
+ export function isAuthApiError(error: unknown): error is AuthApiError {
42
+ return isAuthError(error) && error.name === 'AuthApiError'
43
+ }
44
+
45
+ export class AuthUnknownError extends AuthError {
46
+ originalError: unknown
47
+
48
+ constructor(message: string, originalError: unknown) {
49
+ super(message)
50
+ this.name = 'AuthUnknownError'
51
+ this.originalError = originalError
52
+ }
53
+ }
54
+
55
+ export class CustomAuthError extends AuthError {
56
+ name: string
57
+ status: number
58
+
59
+ constructor(message: string, name: string, status: number, code: string | undefined) {
60
+ super(message, status, code)
61
+ this.name = name
62
+ this.status = status
63
+ }
64
+ }
65
+
66
+ export class AuthSessionMissingError extends CustomAuthError {
67
+ constructor() {
68
+ super('Auth session missing!', 'AuthSessionMissingError', 400, undefined)
69
+ }
70
+ }
71
+
72
+ export function isAuthSessionMissingError(error: any): error is AuthSessionMissingError {
73
+ return isAuthError(error) && error.name === 'AuthSessionMissingError'
74
+ }
75
+
76
+ export class AuthInvalidTokenResponseError extends CustomAuthError {
77
+ constructor() {
78
+ super('Auth session or user missing', 'AuthInvalidTokenResponseError', 500, undefined)
79
+ }
80
+ }
81
+
82
+ export class AuthInvalidCredentialsError extends CustomAuthError {
83
+ constructor(message: string) {
84
+ super(message, 'AuthInvalidCredentialsError', 400, undefined)
85
+ }
86
+ }
87
+
88
+ export class AuthImplicitGrantRedirectError extends CustomAuthError {
89
+ details: { error: string; code: string } | null = null
90
+ constructor(message: string, details: { error: string; code: string } | null = null) {
91
+ super(message, 'AuthImplicitGrantRedirectError', 500, undefined)
92
+ this.details = details
93
+ }
94
+
95
+ toJSON() {
96
+ return {
97
+ name: this.name,
98
+ message: this.message,
99
+ status: this.status,
100
+ details: this.details,
101
+ }
102
+ }
103
+ }
104
+
105
+ export class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
106
+ details: { error: string; code: string } | null = null
107
+
108
+ constructor(message: string, details: { error: string; code: string } | null = null) {
109
+ super(message, 'AuthPKCEGrantCodeExchangeError', 500, undefined)
110
+ this.details = details
111
+ }
112
+
113
+ toJSON() {
114
+ return {
115
+ name: this.name,
116
+ message: this.message,
117
+ status: this.status,
118
+ details: this.details,
119
+ }
120
+ }
121
+ }
122
+
123
+ export class AuthRetryableFetchError extends CustomAuthError {
124
+ constructor(message: string, status: number) {
125
+ super(message, 'AuthRetryableFetchError', status, undefined)
126
+ }
127
+ }
128
+
129
+ export function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError {
130
+ return isAuthError(error) && error.name === 'AuthRetryableFetchError'
131
+ }
132
+
133
+ /**
134
+ * This error is thrown on certain methods when the password used is deemed
135
+ * weak. Inspect the reasons to identify what password strength rules are
136
+ * inadequate.
137
+ */
138
+ export class AuthWeakPasswordError extends CustomAuthError {
139
+ /**
140
+ * Reasons why the password is deemed weak.
141
+ */
142
+ reasons: WeakPasswordReasons[]
143
+
144
+ constructor(message: string, status: number, reasons: string[]) {
145
+ super(message, 'AuthWeakPasswordError', status, 'weak_password')
146
+
147
+ this.reasons = reasons
148
+ }
149
+ }
150
+
151
+ export function isAuthWeakPasswordError(error: unknown): error is AuthWeakPasswordError {
152
+ return isAuthError(error) && error.name === 'AuthWeakPasswordError'
153
+ }
@@ -0,0 +1,21 @@
1
+ export default class OmneediaRealtime {
2
+ protected Channel: string = ''
3
+ protected ref: any = null
4
+ constructor(channel: string, ref: any) {
5
+ this.Channel = channel
6
+ this.ref = ref
7
+ }
8
+ public async send(message: any) {
9
+ this.ref.socket.emit(this.Channel + '::' + message.type + '::' + message.event, message.payload)
10
+ return this
11
+ }
12
+ public on(type: string, event: any, cb: Function) {
13
+ this.ref.socket.on(`${this.Channel}::${type}::${event.event}`, cb)
14
+ return this
15
+ }
16
+ public subscribe(callback: Function) {
17
+ this.ref.socket.on(`${this.Channel}:SUBSCRIBED`, callback)
18
+ this.ref.socket.emit('subscribe', this.Channel)
19
+ return this
20
+ }
21
+ }
@@ -0,0 +1,198 @@
1
+ import { isBrowser } from './util'
2
+ import fetch from 'cross-fetch'
3
+
4
+ export interface TResponse {
5
+ data: undefined | {}
6
+ error: undefined | {}
7
+ statusText: string
8
+ status: BigInteger
9
+ }
10
+
11
+ export default class OmneediaRequest {
12
+ private url: string = ''
13
+ private options?: any
14
+ private ref?: any
15
+ private fetch: any
16
+ constructor(ref: any) {
17
+ this.ref = ref
18
+ if (isBrowser()) {
19
+ this.fetch = globalThis.fetch.bind(globalThis)
20
+ } else {
21
+ this.fetch = fetch
22
+ }
23
+ }
24
+ async get(uri: string, o: any) {
25
+ if (uri.indexOf('://') > -1) var url = `${uri}`
26
+ else var url = `${this.ref.omneediaUrl}${uri}`
27
+ let headers = this.ref.headers()
28
+ if (isBrowser()) {
29
+ if (localStorage.getItem('omneedia.auth.token')) {
30
+ headers.Authorization = 'Bearer ' + localStorage.getItem('omneedia.auth.token')
31
+ }
32
+ headers.redirect_to = window.location.origin + window.location.pathname
33
+ } else {
34
+ // use cookie
35
+ const token = this.ref.options.cookies.getAll()
36
+ if (token) {
37
+ const bearer = token.find((el: any) => el.name === 'omneedia.auth.token')
38
+ if (bearer) headers.Authorization = 'Bearer ' + bearer.value
39
+ }
40
+ }
41
+ var res = await this.fetch(url, {
42
+ headers: headers,
43
+ credentials: 'include',
44
+ })
45
+
46
+ var body = await res.json()
47
+ var response = {
48
+ data: null,
49
+ error: null,
50
+ statusText: res.statusText,
51
+ status: res.status,
52
+ }
53
+ if (res.ok) response.data = body
54
+ else response.error = body
55
+ return response
56
+ }
57
+ async delete(uri: string, o: any) {
58
+ let data = []
59
+ if (uri.indexOf('://') > -1) var url = `${uri}`
60
+ else var url = `${this.ref.omneediaUrl}${uri}`
61
+
62
+ let headers = this.ref.headers()
63
+ if (isBrowser()) {
64
+ if (localStorage.getItem('omneedia.auth.token')) {
65
+ headers.Authorization = 'Bearer ' + localStorage.getItem('omneedia.auth.token')
66
+ }
67
+ headers.redirect_to = window.location.origin + window.location.pathname
68
+ } else {
69
+ // use cookie
70
+ const token = this.ref.options.cookies.getAll()
71
+ if (token) {
72
+ const bearer = token.find((el: any) => el.name === 'omneedia.auth.token')
73
+ if (bearer) headers.Authorization = 'Bearer ' + bearer.value
74
+ }
75
+ }
76
+
77
+ var res = await this.fetch(url, {
78
+ method: 'DELETE',
79
+ credentials: 'include',
80
+ headers: headers,
81
+ })
82
+ try {
83
+ data = await res.json()
84
+ } catch (e) {
85
+ data = []
86
+ }
87
+ return {
88
+ data: data,
89
+ statusText: res.statusText,
90
+ status: res.status,
91
+ }
92
+ }
93
+ async patch(uri: string, o: any) {
94
+ let data = []
95
+ if (uri.indexOf('://') > -1) var url = `${uri}`
96
+ else var url = `${this.ref.omneediaUrl}${uri}`
97
+ let headers = this.ref.headers()
98
+ if (isBrowser()) {
99
+ headers.redirect_to = window.location.origin + window.location.pathname
100
+ if (localStorage.getItem('omneedia.auth.token')) {
101
+ headers.Authorization = 'Bearer ' + localStorage.getItem('omneedia.auth.token')
102
+ }
103
+ } else {
104
+ // use cookie
105
+ const token = this.ref.options.cookies.getAll()
106
+ if (token) {
107
+ const bearer = token.find((el: any) => el.name === 'omneedia.auth.token')
108
+ if (bearer) headers.Authorization = 'Bearer ' + bearer.value
109
+ }
110
+ }
111
+ var res = await this.fetch(url, {
112
+ method: 'PATCH',
113
+ credentials: 'include',
114
+ headers: headers,
115
+ body: JSON.stringify(o),
116
+ })
117
+ try {
118
+ data = await res.json()
119
+ } catch (e) {
120
+ data = []
121
+ }
122
+ return {
123
+ data: await data,
124
+ statusText: res.statusText,
125
+ status: res.status,
126
+ }
127
+ }
128
+ async put(uri: string, o: any) {
129
+ let data = []
130
+ if (uri.indexOf('://') > -1) var url = `${uri}`
131
+ else var url = `${this.ref.omneediaUrl}${uri}`
132
+ let headers = this.ref.headers()
133
+ if (isBrowser()) {
134
+ headers.redirect_to = window.location.origin + window.location.pathname
135
+ if (localStorage.getItem('omneedia.auth.token')) {
136
+ headers.Authorization = 'Bearer ' + localStorage.getItem('omneedia.auth.token')
137
+ }
138
+ } else {
139
+ // use cookie
140
+ const token = this.ref.options.cookies.getAll()
141
+ if (token) {
142
+ const bearer = token.find((el: any) => el.name === 'omneedia.auth.token')
143
+ if (bearer) headers.Authorization = 'Bearer ' + bearer.value
144
+ }
145
+ }
146
+ var res = await this.fetch(url, {
147
+ method: 'PUT',
148
+ credentials: 'include',
149
+ headers: headers,
150
+ body: JSON.stringify(o),
151
+ })
152
+ try {
153
+ data = await res.json()
154
+ } catch (e) {
155
+ data = []
156
+ }
157
+ return {
158
+ data: await data,
159
+ statusText: res.statusText,
160
+ status: res.status,
161
+ }
162
+ }
163
+ async post(uri: string, o: any) {
164
+ let data = []
165
+ if (uri.indexOf('://') > -1) var url = `${uri}`
166
+ else var url = `${this.ref.omneediaUrl}${uri}`
167
+ let headers = this.ref.headers()
168
+ if (isBrowser()) {
169
+ headers.redirect_to = window.location.origin + window.location.pathname
170
+ if (localStorage.getItem('omneedia.auth.token')) {
171
+ headers.Authorization = 'Bearer ' + localStorage.getItem('omneedia.auth.token')
172
+ }
173
+ } else {
174
+ // use cookie
175
+ const token = this.ref.options.cookies.getAll()
176
+ if (token) {
177
+ const bearer = token.find((el: any) => el.name === 'omneedia.auth.token')
178
+ if (bearer) headers.Authorization = 'Bearer ' + bearer.value
179
+ }
180
+ }
181
+ var res = await this.fetch(url, {
182
+ method: 'POST',
183
+ credentials: 'include',
184
+ headers: headers,
185
+ body: JSON.stringify(o),
186
+ })
187
+ try {
188
+ data = await res.json()
189
+ } catch (e) {
190
+ data = []
191
+ }
192
+ return {
193
+ data: data,
194
+ statusText: res.statusText,
195
+ status: res.status,
196
+ }
197
+ }
198
+ }