@opexa/portal-sdk 0.36.0 → 0.37.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.
- package/README.md +1624 -1624
- package/dist/index.cjs +53 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +53 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2818,18 +2818,27 @@ var AuthService = class {
|
|
|
2818
2818
|
}
|
|
2819
2819
|
};
|
|
2820
2820
|
|
|
2821
|
+
// src/utils/call-if-fn.ts
|
|
2822
|
+
function isFunction(value) {
|
|
2823
|
+
return typeof value === "function";
|
|
2824
|
+
}
|
|
2825
|
+
function callIfFn(value, ...args) {
|
|
2826
|
+
if (isFunction(value)) {
|
|
2827
|
+
return value(...args);
|
|
2828
|
+
} else {
|
|
2829
|
+
return value;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2821
2833
|
// src/services/cms-portal.service.ts
|
|
2822
2834
|
var CmsPortalService = class {
|
|
2823
|
-
|
|
2824
|
-
siteId;
|
|
2825
|
-
platformId;
|
|
2835
|
+
config;
|
|
2826
2836
|
constructor(config) {
|
|
2827
|
-
this.
|
|
2828
|
-
this.siteId = config.site;
|
|
2829
|
-
this.platformId = config.platform;
|
|
2837
|
+
this.config = config;
|
|
2830
2838
|
}
|
|
2831
2839
|
async self() {
|
|
2832
|
-
const
|
|
2840
|
+
const config = callIfFn(this.config);
|
|
2841
|
+
const res = await this.getJson(`/v1/sites/${config.site}`);
|
|
2833
2842
|
if (!res.ok) return res;
|
|
2834
2843
|
return {
|
|
2835
2844
|
ok: true,
|
|
@@ -2974,17 +2983,19 @@ var CmsPortalService = class {
|
|
|
2974
2983
|
};
|
|
2975
2984
|
}
|
|
2976
2985
|
async getJson(path, params) {
|
|
2977
|
-
const
|
|
2986
|
+
const config = callIfFn(this.config);
|
|
2987
|
+
const fetch_ = config.fetch ?? fetch;
|
|
2988
|
+
const req = new Request(`${config.url}${path}?${params?.toString() ?? ""}`, {
|
|
2978
2989
|
method: "GET",
|
|
2979
2990
|
headers: {
|
|
2980
2991
|
Accept: "application/json",
|
|
2981
2992
|
"Content-Type": "application/json",
|
|
2982
|
-
"Site-ID":
|
|
2983
|
-
"Platform-ID":
|
|
2993
|
+
"Site-ID": config.site,
|
|
2994
|
+
"Platform-ID": config.platform
|
|
2984
2995
|
}
|
|
2985
2996
|
});
|
|
2986
2997
|
try {
|
|
2987
|
-
const res = await
|
|
2998
|
+
const res = await fetch_(req);
|
|
2988
2999
|
if (!res.ok) {
|
|
2989
3000
|
return {
|
|
2990
3001
|
ok: false,
|
|
@@ -4087,21 +4098,24 @@ function arrayToObject(array) {
|
|
|
4087
4098
|
var GraphQLClient = class {
|
|
4088
4099
|
url;
|
|
4089
4100
|
config;
|
|
4090
|
-
constructor(url, config) {
|
|
4101
|
+
constructor(url, config = {}) {
|
|
4091
4102
|
this.url = url;
|
|
4092
|
-
this.config = config
|
|
4103
|
+
this.config = config;
|
|
4093
4104
|
}
|
|
4094
|
-
async request(query, variables,
|
|
4095
|
-
const
|
|
4096
|
-
const
|
|
4097
|
-
{
|
|
4098
|
-
|
|
4105
|
+
async request(query, variables, userOptions) {
|
|
4106
|
+
const config = callIfFn(this.config);
|
|
4107
|
+
const options = mergeFetchOptions(
|
|
4108
|
+
{
|
|
4109
|
+
...config?.fetchOptions,
|
|
4110
|
+
headers: new Headers(config?.fetchOptions?.headers)
|
|
4111
|
+
},
|
|
4112
|
+
userOptions
|
|
4099
4113
|
);
|
|
4100
4114
|
const body = JSON.stringify({
|
|
4101
4115
|
query,
|
|
4102
4116
|
variables
|
|
4103
4117
|
});
|
|
4104
|
-
const headers = new Headers(
|
|
4118
|
+
const headers = new Headers(options.headers);
|
|
4105
4119
|
headers.set("Content-Type", "application/json");
|
|
4106
4120
|
headers.set("Accept", "application/json");
|
|
4107
4121
|
const url = new URL(this.url);
|
|
@@ -4111,18 +4125,18 @@ var GraphQLClient = class {
|
|
|
4111
4125
|
}
|
|
4112
4126
|
const req = await this.runMiddlewares(
|
|
4113
4127
|
new Request(url, {
|
|
4114
|
-
...
|
|
4128
|
+
...options,
|
|
4115
4129
|
body,
|
|
4116
4130
|
headers,
|
|
4117
4131
|
method: "POST"
|
|
4118
4132
|
}),
|
|
4119
|
-
|
|
4133
|
+
config?.middlewares ?? []
|
|
4120
4134
|
);
|
|
4121
4135
|
return await this.exec(req);
|
|
4122
4136
|
}
|
|
4123
4137
|
/** Single file upload */
|
|
4124
4138
|
async upload(query, variables, options) {
|
|
4125
|
-
const cfg = this.config
|
|
4139
|
+
const cfg = callIfFn(this.config);
|
|
4126
4140
|
const opts = mergeFetchOptions(
|
|
4127
4141
|
{ ...cfg?.fetchOptions, headers: new Headers(cfg?.fetchOptions?.headers) },
|
|
4128
4142
|
options
|
|
@@ -4147,8 +4161,10 @@ var GraphQLClient = class {
|
|
|
4147
4161
|
return await this.exec(req);
|
|
4148
4162
|
}
|
|
4149
4163
|
async exec(request) {
|
|
4164
|
+
const config = callIfFn(this.config);
|
|
4165
|
+
const fetch_ = config.fetch ?? fetch;
|
|
4150
4166
|
try {
|
|
4151
|
-
const res = await
|
|
4167
|
+
const res = await fetch_(request);
|
|
4152
4168
|
if (!res.ok) {
|
|
4153
4169
|
return { ok: false, error: statusCodeToOperationError(res.status) };
|
|
4154
4170
|
}
|
|
@@ -4338,6 +4354,7 @@ var DomainManager = class {
|
|
|
4338
4354
|
"crazywin.ph": "587374767622209",
|
|
4339
4355
|
"crazywin.asia": "587374767622209",
|
|
4340
4356
|
"happybingo.ph": "617045164450475",
|
|
4357
|
+
"happybingo.games": "1387188208976275",
|
|
4341
4358
|
...this.environment === "production" && {
|
|
4342
4359
|
"crazywinph.ph": "587374767622209"
|
|
4343
4360
|
}
|
|
@@ -6069,11 +6086,13 @@ var Sdk = class {
|
|
|
6069
6086
|
const gameUrl = ENDPOINTS[environment].game;
|
|
6070
6087
|
const triggerUrl = ENDPOINTS[environment].trigger;
|
|
6071
6088
|
const cmsPortalUrl = ENDPOINTS[environment].cmsPortal;
|
|
6072
|
-
const cmsPortalService = new CmsPortalService({
|
|
6089
|
+
const cmsPortalService = new CmsPortalService(() => ({
|
|
6073
6090
|
url: cmsPortalUrl,
|
|
6074
6091
|
site,
|
|
6075
|
-
platform: sitePlatform
|
|
6076
|
-
|
|
6092
|
+
platform: sitePlatform,
|
|
6093
|
+
fetch: this.fetch
|
|
6094
|
+
}));
|
|
6095
|
+
this._fetch = config.fetch ?? null;
|
|
6077
6096
|
this._middleware = config.middleware ?? ((req) => req);
|
|
6078
6097
|
const graphqlClientConfig = () => ({
|
|
6079
6098
|
middlewares: [
|
|
@@ -6083,6 +6102,7 @@ var Sdk = class {
|
|
|
6083
6102
|
this.miscMiddleware,
|
|
6084
6103
|
this.middleware
|
|
6085
6104
|
],
|
|
6105
|
+
fetch: this.fetch,
|
|
6086
6106
|
fetchOptions: {
|
|
6087
6107
|
headers: {
|
|
6088
6108
|
Role: "MEMBER",
|
|
@@ -6141,7 +6161,14 @@ var Sdk = class {
|
|
|
6141
6161
|
logs
|
|
6142
6162
|
};
|
|
6143
6163
|
}
|
|
6164
|
+
_fetch = null;
|
|
6144
6165
|
_middleware;
|
|
6166
|
+
set fetch(value) {
|
|
6167
|
+
this._fetch = value;
|
|
6168
|
+
}
|
|
6169
|
+
get fetch() {
|
|
6170
|
+
return this._fetch;
|
|
6171
|
+
}
|
|
6145
6172
|
set middleware(value) {
|
|
6146
6173
|
this._middleware = value;
|
|
6147
6174
|
}
|