poad 2.1.1 → 2.5.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.
- package/package.json +10 -72
- package/poad.js +52 -0
- package/LICENSE +0 -21
- package/README.md +0 -63
- package/dist/main/OmneediaClient.d.ts +0 -28
- package/dist/main/OmneediaClient.d.ts.map +0 -1
- package/dist/main/OmneediaClient.js +0 -58
- package/dist/main/OmneediaClient.js.map +0 -1
- package/dist/main/env/prefix-dev.d.ts +0 -7
- package/dist/main/env/prefix-dev.d.ts.map +0 -1
- package/dist/main/env/prefix-dev.js +0 -8
- package/dist/main/env/prefix-dev.js.map +0 -1
- package/dist/main/env/prefix-prod.d.ts +0 -7
- package/dist/main/env/prefix-prod.d.ts.map +0 -1
- package/dist/main/env/prefix-prod.js +0 -8
- package/dist/main/env/prefix-prod.js.map +0 -1
- package/dist/main/env/prefix.d.ts +0 -7
- package/dist/main/env/prefix.d.ts.map +0 -1
- package/dist/main/env/prefix.js +0 -8
- package/dist/main/env/prefix.js.map +0 -1
- package/dist/main/index.d.ts +0 -11
- package/dist/main/index.d.ts.map +0 -1
- package/dist/main/index.js +0 -19
- package/dist/main/index.js.map +0 -1
- package/dist/main/lib/auth.d.ts +0 -22
- package/dist/main/lib/auth.d.ts.map +0 -1
- package/dist/main/lib/auth.js +0 -352
- package/dist/main/lib/auth.js.map +0 -1
- package/dist/main/lib/constants.d.ts +0 -8
- package/dist/main/lib/constants.d.ts.map +0 -1
- package/dist/main/lib/constants.js +0 -11
- package/dist/main/lib/constants.js.map +0 -1
- package/dist/main/lib/db.d.ts +0 -45
- package/dist/main/lib/db.d.ts.map +0 -1
- package/dist/main/lib/db.js +0 -252
- package/dist/main/lib/db.js.map +0 -1
- package/dist/main/lib/error-codes.d.ts +0 -7
- package/dist/main/lib/error-codes.d.ts.map +0 -1
- package/dist/main/lib/error-codes.js +0 -3
- package/dist/main/lib/error-codes.js.map +0 -1
- package/dist/main/lib/errors.d.ts +0 -96
- package/dist/main/lib/errors.d.ts.map +0 -1
- package/dist/main/lib/errors.js +0 -127
- package/dist/main/lib/errors.js.map +0 -1
- package/dist/main/lib/realtime.d.ts +0 -9
- package/dist/main/lib/realtime.d.ts.map +0 -1
- package/dist/main/lib/realtime.js +0 -36
- package/dist/main/lib/realtime.js.map +0 -1
- package/dist/main/lib/request.d.ts +0 -40
- package/dist/main/lib/request.d.ts.map +0 -1
- package/dist/main/lib/request.js +0 -237
- package/dist/main/lib/request.js.map +0 -1
- package/dist/main/lib/types.d.ts +0 -408
- package/dist/main/lib/types.d.ts.map +0 -1
- package/dist/main/lib/types.js +0 -11
- package/dist/main/lib/types.js.map +0 -1
- package/dist/main/lib/util.d.ts +0 -7
- package/dist/main/lib/util.d.ts.map +0 -1
- package/dist/main/lib/util.js +0 -90
- package/dist/main/lib/util.js.map +0 -1
- package/dist/main/lib copy/auth.d.ts +0 -22
- package/dist/main/lib copy/auth.d.ts.map +0 -1
- package/dist/main/lib copy/auth.js +0 -283
- package/dist/main/lib copy/auth.js.map +0 -1
- package/dist/main/lib copy/auth_api.d.ts +0 -23
- package/dist/main/lib copy/auth_api.d.ts.map +0 -1
- package/dist/main/lib copy/auth_api.js +0 -90
- package/dist/main/lib copy/auth_api.js.map +0 -1
- package/dist/main/lib copy/constants.d.ts +0 -8
- package/dist/main/lib copy/constants.d.ts.map +0 -1
- package/dist/main/lib copy/constants.js +0 -11
- package/dist/main/lib copy/constants.js.map +0 -1
- package/dist/main/lib copy/cookies.d.ts +0 -20
- package/dist/main/lib copy/cookies.d.ts.map +0 -1
- package/dist/main/lib copy/cookies.js +0 -144
- package/dist/main/lib copy/cookies.js.map +0 -1
- package/dist/main/lib copy/db.d.ts +0 -45
- package/dist/main/lib copy/db.d.ts.map +0 -1
- package/dist/main/lib copy/db.js +0 -252
- package/dist/main/lib copy/db.js.map +0 -1
- package/dist/main/lib copy/realtime.d.ts +0 -9
- package/dist/main/lib copy/realtime.d.ts.map +0 -1
- package/dist/main/lib copy/realtime.js +0 -36
- package/dist/main/lib copy/realtime.js.map +0 -1
- package/dist/main/lib copy/request.d.ts +0 -40
- package/dist/main/lib copy/request.d.ts.map +0 -1
- package/dist/main/lib copy/request.js +0 -206
- package/dist/main/lib copy/request.js.map +0 -1
- package/dist/main/lib copy/types.d.ts +0 -124
- package/dist/main/lib copy/types.d.ts.map +0 -1
- package/dist/main/lib copy/types.js +0 -3
- package/dist/main/lib copy/types.js.map +0 -1
- package/dist/main/lib copy/util.d.ts +0 -7
- package/dist/main/lib copy/util.d.ts.map +0 -1
- package/dist/main/lib copy/util.js +0 -90
- package/dist/main/lib copy/util.js.map +0 -1
- package/dist/module/OmneediaClient.d.ts +0 -28
- package/dist/module/OmneediaClient.d.ts.map +0 -1
- package/dist/module/OmneediaClient.js +0 -52
- package/dist/module/OmneediaClient.js.map +0 -1
- package/dist/module/env/prefix-dev.d.ts +0 -7
- package/dist/module/env/prefix-dev.d.ts.map +0 -1
- package/dist/module/env/prefix-dev.js +0 -6
- package/dist/module/env/prefix-dev.js.map +0 -1
- package/dist/module/env/prefix-prod.d.ts +0 -7
- package/dist/module/env/prefix-prod.d.ts.map +0 -1
- package/dist/module/env/prefix-prod.js +0 -6
- package/dist/module/env/prefix-prod.js.map +0 -1
- package/dist/module/env/prefix.d.ts +0 -7
- package/dist/module/env/prefix.d.ts.map +0 -1
- package/dist/module/env/prefix.js +0 -6
- package/dist/module/env/prefix.js.map +0 -1
- package/dist/module/index.d.ts +0 -11
- package/dist/module/index.d.ts.map +0 -1
- package/dist/module/index.js +0 -12
- package/dist/module/index.js.map +0 -1
- package/dist/module/lib/auth.d.ts +0 -22
- package/dist/module/lib/auth.d.ts.map +0 -1
- package/dist/module/lib/auth.js +0 -349
- package/dist/module/lib/auth.js.map +0 -1
- package/dist/module/lib/constants.d.ts +0 -8
- package/dist/module/lib/constants.d.ts.map +0 -1
- package/dist/module/lib/constants.js +0 -8
- package/dist/module/lib/constants.js.map +0 -1
- package/dist/module/lib/db.d.ts +0 -45
- package/dist/module/lib/db.d.ts.map +0 -1
- package/dist/module/lib/db.js +0 -246
- package/dist/module/lib/db.js.map +0 -1
- package/dist/module/lib/error-codes.d.ts +0 -7
- package/dist/module/lib/error-codes.d.ts.map +0 -1
- package/dist/module/lib/error-codes.js +0 -2
- package/dist/module/lib/error-codes.js.map +0 -1
- package/dist/module/lib/errors.d.ts +0 -96
- package/dist/module/lib/errors.d.ts.map +0 -1
- package/dist/module/lib/errors.js +0 -108
- package/dist/module/lib/errors.js.map +0 -1
- package/dist/module/lib/realtime.d.ts +0 -9
- package/dist/module/lib/realtime.d.ts.map +0 -1
- package/dist/module/lib/realtime.js +0 -33
- package/dist/module/lib/realtime.js.map +0 -1
- package/dist/module/lib/request.d.ts +0 -40
- package/dist/module/lib/request.d.ts.map +0 -1
- package/dist/module/lib/request.js +0 -231
- package/dist/module/lib/request.js.map +0 -1
- package/dist/module/lib/types.d.ts +0 -408
- package/dist/module/lib/types.d.ts.map +0 -1
- package/dist/module/lib/types.js +0 -8
- package/dist/module/lib/types.js.map +0 -1
- package/dist/module/lib/util.d.ts +0 -7
- package/dist/module/lib/util.d.ts.map +0 -1
- package/dist/module/lib/util.js +0 -81
- package/dist/module/lib/util.js.map +0 -1
- package/dist/module/lib copy/auth.d.ts +0 -22
- package/dist/module/lib copy/auth.d.ts.map +0 -1
- package/dist/module/lib copy/auth.js +0 -277
- package/dist/module/lib copy/auth.js.map +0 -1
- package/dist/module/lib copy/auth_api.d.ts +0 -23
- package/dist/module/lib copy/auth_api.d.ts.map +0 -1
- package/dist/module/lib copy/auth_api.js +0 -87
- package/dist/module/lib copy/auth_api.js.map +0 -1
- package/dist/module/lib copy/constants.d.ts +0 -8
- package/dist/module/lib copy/constants.d.ts.map +0 -1
- package/dist/module/lib copy/constants.js +0 -8
- package/dist/module/lib copy/constants.js.map +0 -1
- package/dist/module/lib copy/cookies.d.ts +0 -20
- package/dist/module/lib copy/cookies.d.ts.map +0 -1
- package/dist/module/lib copy/cookies.js +0 -137
- package/dist/module/lib copy/cookies.js.map +0 -1
- package/dist/module/lib copy/db.d.ts +0 -45
- package/dist/module/lib copy/db.d.ts.map +0 -1
- package/dist/module/lib copy/db.js +0 -246
- package/dist/module/lib copy/db.js.map +0 -1
- package/dist/module/lib copy/realtime.d.ts +0 -9
- package/dist/module/lib copy/realtime.d.ts.map +0 -1
- package/dist/module/lib copy/realtime.js +0 -33
- package/dist/module/lib copy/realtime.js.map +0 -1
- package/dist/module/lib copy/request.d.ts +0 -40
- package/dist/module/lib copy/request.d.ts.map +0 -1
- package/dist/module/lib copy/request.js +0 -200
- package/dist/module/lib copy/request.js.map +0 -1
- package/dist/module/lib copy/types.d.ts +0 -124
- package/dist/module/lib copy/types.d.ts.map +0 -1
- package/dist/module/lib copy/types.js +0 -2
- package/dist/module/lib copy/types.js.map +0 -1
- package/dist/module/lib copy/util.d.ts +0 -7
- package/dist/module/lib copy/util.d.ts.map +0 -1
- package/dist/module/lib copy/util.js +0 -81
- package/dist/module/lib copy/util.js.map +0 -1
- package/dist/umd/941.omneedia.js +0 -1
- package/dist/umd/omneedia.js +0 -2
- package/dist/umd/omneedia.js.LICENSE.txt +0 -1
- package/src/OmneediaClient.ts +0 -65
- package/src/env/prefix-dev.ts +0 -5
- package/src/env/prefix-prod.ts +0 -5
- package/src/env/prefix.ts +0 -5
- package/src/index.ts +0 -26
- package/src/lib/auth.ts +0 -306
- package/src/lib/constants.ts +0 -7
- package/src/lib/db.ts +0 -216
- package/src/lib/error-codes.ts +0 -71
- package/src/lib/errors.ts +0 -153
- package/src/lib/realtime.ts +0 -21
- package/src/lib/request.ts +0 -198
- package/src/lib/types.ts +0 -512
- package/src/lib/util.ts +0 -83
package/src/lib/errors.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
}
|
package/src/lib/realtime.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
package/src/lib/request.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
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
|
-
}
|