@opexa/portal-sdk 0.59.144 → 0.59.146

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 (39) hide show
  1. package/README.md +1762 -1762
  2. package/dist/{chunk-BTV72WJH.js → chunk-77N5VUZS.js} +2 -2
  3. package/dist/chunk-77N5VUZS.js.map +1 -0
  4. package/dist/{chunk-7Y7FWND5.js → chunk-ZBLHFIBW.js} +3 -3
  5. package/dist/chunk-ZBLHFIBW.js.map +1 -0
  6. package/dist/{chunk-ITHR4H7D.js → chunk-ZTPPUUY7.js} +3 -3
  7. package/dist/chunk-ZTPPUUY7.js.map +1 -0
  8. package/dist/graphql-client-B_tCbUDO.d.cts +30 -0
  9. package/dist/graphql-client-CjJ2PWjG.d.ts +30 -0
  10. package/dist/index-L0Y9nBAa.d.cts +55 -0
  11. package/dist/index-L0Y9nBAa.d.ts +55 -0
  12. package/dist/index.cjs +103 -2
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +17 -5
  15. package/dist/index.d.ts +17 -5
  16. package/dist/index.js +105 -5
  17. package/dist/index.js.map +1 -1
  18. package/dist/services/index.cjs.map +1 -1
  19. package/dist/services/index.d.cts +4 -3
  20. package/dist/services/index.d.ts +4 -3
  21. package/dist/services/index.js +2 -2
  22. package/dist/types/index.cjs +4 -0
  23. package/dist/types/index.cjs.map +1 -0
  24. package/dist/types/index.d.cts +1 -0
  25. package/dist/types/index.d.ts +1 -0
  26. package/dist/types/index.js +3 -0
  27. package/dist/types/index.js.map +1 -0
  28. package/dist/{types-CTvTUz5S.d.cts → types-CxYSPGJU.d.ts} +3 -1
  29. package/dist/{types-mOrZJ_Qw.d.ts → types-ss9ZrvFO.d.cts} +3 -1
  30. package/dist/utils/index.cjs.map +1 -1
  31. package/dist/utils/index.d.cts +2 -1
  32. package/dist/utils/index.d.ts +2 -1
  33. package/dist/utils/index.js +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-7Y7FWND5.js.map +0 -1
  36. package/dist/chunk-BTV72WJH.js.map +0 -1
  37. package/dist/chunk-ITHR4H7D.js.map +0 -1
  38. package/dist/graphql-client-Cr5nXEyQ.d.cts +0 -58
  39. package/dist/graphql-client-Cr5nXEyQ.d.ts +0 -58
@@ -0,0 +1,30 @@
1
+ import { G as GenericObject, a as OperationResult } from './index-L0Y9nBAa.cjs';
2
+
3
+ type ModifiableKey = 'mode' | 'cache' | 'signal' | 'headers' | 'integrity' | 'keepalive' | 'credentials';
4
+ type Modifiable = {
5
+ [K in ModifiableKey]: Request[K];
6
+ };
7
+ interface ModifiedRequest extends Readonly<Omit<Request, ModifiableKey>>, Modifiable {
8
+ }
9
+ type GraphQLClientMiddleware = (request: ModifiedRequest) => ModifiedRequest | Promise<ModifiedRequest>;
10
+ interface GraphQLClientFetchOptions extends Omit<RequestInit, 'body'> {
11
+ }
12
+ interface GraphQLClientConfig {
13
+ fetch?: typeof globalThis.fetch | null;
14
+ fetchOptions?: GraphQLClientFetchOptions;
15
+ middlewares?: GraphQLClientMiddleware[];
16
+ }
17
+ type Getter<T> = () => T;
18
+ declare class GraphQLClient {
19
+ private url;
20
+ private config;
21
+ constructor(url: string, config?: Getter<GraphQLClientConfig> | GraphQLClientConfig);
22
+ request<Data, Variables extends GenericObject = GenericObject>(query: string, variables?: Variables, userOptions?: GraphQLClientFetchOptions): Promise<OperationResult<never, Data>>;
23
+ /** Single file upload */
24
+ upload<Data, Variables extends GenericObject = GenericObject>(query: string, variables: Variables, options?: GraphQLClientFetchOptions): Promise<OperationResult<never, Data>>;
25
+ private exec;
26
+ private runMiddlewares;
27
+ private createUploadBody;
28
+ }
29
+
30
+ export { type GraphQLClientMiddleware as G, type ModifiedRequest as M, GraphQLClient as a, type GraphQLClientFetchOptions as b, type GraphQLClientConfig as c };
@@ -0,0 +1,30 @@
1
+ import { G as GenericObject, a as OperationResult } from './index-L0Y9nBAa.js';
2
+
3
+ type ModifiableKey = 'mode' | 'cache' | 'signal' | 'headers' | 'integrity' | 'keepalive' | 'credentials';
4
+ type Modifiable = {
5
+ [K in ModifiableKey]: Request[K];
6
+ };
7
+ interface ModifiedRequest extends Readonly<Omit<Request, ModifiableKey>>, Modifiable {
8
+ }
9
+ type GraphQLClientMiddleware = (request: ModifiedRequest) => ModifiedRequest | Promise<ModifiedRequest>;
10
+ interface GraphQLClientFetchOptions extends Omit<RequestInit, 'body'> {
11
+ }
12
+ interface GraphQLClientConfig {
13
+ fetch?: typeof globalThis.fetch | null;
14
+ fetchOptions?: GraphQLClientFetchOptions;
15
+ middlewares?: GraphQLClientMiddleware[];
16
+ }
17
+ type Getter<T> = () => T;
18
+ declare class GraphQLClient {
19
+ private url;
20
+ private config;
21
+ constructor(url: string, config?: Getter<GraphQLClientConfig> | GraphQLClientConfig);
22
+ request<Data, Variables extends GenericObject = GenericObject>(query: string, variables?: Variables, userOptions?: GraphQLClientFetchOptions): Promise<OperationResult<never, Data>>;
23
+ /** Single file upload */
24
+ upload<Data, Variables extends GenericObject = GenericObject>(query: string, variables: Variables, options?: GraphQLClientFetchOptions): Promise<OperationResult<never, Data>>;
25
+ private exec;
26
+ private runMiddlewares;
27
+ private createUploadBody;
28
+ }
29
+
30
+ export { type GraphQLClientMiddleware as G, type ModifiedRequest as M, GraphQLClient as a, type GraphQLClientFetchOptions as b, type GraphQLClientConfig as c };
@@ -0,0 +1,55 @@
1
+ /** Site-specific catalogs are supplied by consumers, not bundled into the SDK. */
2
+ interface JourneyPolicy {
3
+ signupType: 'number_only' | 'regular';
4
+ kycRequired: boolean;
5
+ /** Minimum first-deposit amount in the catalog currency's major units. */
6
+ minimumFtd: number;
7
+ }
8
+ interface JourneyCatalog<Id extends string = string> {
9
+ version: number;
10
+ currency: string;
11
+ journeys: Record<Id, JourneyPolicy>;
12
+ }
13
+ interface SelectedJourney<Id extends string = string> extends JourneyPolicy {
14
+ id: Id;
15
+ version: number;
16
+ currency: string;
17
+ }
18
+ declare const USER_JOURNEY_STORAGE_KEY = "userJourney";
19
+ /** Validate external session data and return a detached snapshot of known fields. */
20
+ declare function parseSelectedJourney(value: unknown): SelectedJourney | null;
21
+ /** Validate a site's JSON catalog without adding any site-specific journey rules. */
22
+ declare function parseJourneyCatalog(value: unknown): JourneyCatalog | null;
23
+
24
+ type GenericObject = Record<string, any>;
25
+ type Assign<Target, Source> = Omit<Target, keyof Source> & Source;
26
+ type Alias<T> = T & {
27
+ _?: never;
28
+ };
29
+ type Maybe<T> = T | null | undefined;
30
+ type HttpError = /* 400 */ 'HttpBadRequest' | /* 401 */ 'HttpUnauthorized' | /* 403 */ 'HttpForbidden' | /* 404 */ 'HttpNotFound' | /* 408 */ 'HttpRequestTimeout' | /* 429 */ 'HttpTooManyRequests' | /* 500 */ 'HttpInternalServerError';
31
+ type OperationError<T extends string = string> = {
32
+ name: T;
33
+ message: string;
34
+ };
35
+ type OperationResult<Error extends string = never, Data = never> = [
36
+ Data
37
+ ] extends [never] ? {
38
+ ok: false;
39
+ data?: never;
40
+ error: [Error] extends [never] ? OperationError<HttpError | 'UnknownError'> : OperationError<Error> | OperationError<HttpError | 'UnknownError'>;
41
+ } | {
42
+ ok: true;
43
+ data?: never;
44
+ error?: never;
45
+ } : {
46
+ ok: false;
47
+ data?: never;
48
+ error: [Error] extends [never] ? OperationError<HttpError | 'UnknownError'> : OperationError<Error> | OperationError<HttpError | 'UnknownError'>;
49
+ } | {
50
+ ok: true;
51
+ data: Data;
52
+ error?: never;
53
+ };
54
+
55
+ export { type Assign as A, type GenericObject as G, type HttpError as H, type JourneyCatalog as J, type Maybe as M, type OperationError as O, type SelectedJourney as S, USER_JOURNEY_STORAGE_KEY as U, type OperationResult as a, type JourneyPolicy as b, parseJourneyCatalog as c, type Alias as d, parseSelectedJourney as p };
@@ -0,0 +1,55 @@
1
+ /** Site-specific catalogs are supplied by consumers, not bundled into the SDK. */
2
+ interface JourneyPolicy {
3
+ signupType: 'number_only' | 'regular';
4
+ kycRequired: boolean;
5
+ /** Minimum first-deposit amount in the catalog currency's major units. */
6
+ minimumFtd: number;
7
+ }
8
+ interface JourneyCatalog<Id extends string = string> {
9
+ version: number;
10
+ currency: string;
11
+ journeys: Record<Id, JourneyPolicy>;
12
+ }
13
+ interface SelectedJourney<Id extends string = string> extends JourneyPolicy {
14
+ id: Id;
15
+ version: number;
16
+ currency: string;
17
+ }
18
+ declare const USER_JOURNEY_STORAGE_KEY = "userJourney";
19
+ /** Validate external session data and return a detached snapshot of known fields. */
20
+ declare function parseSelectedJourney(value: unknown): SelectedJourney | null;
21
+ /** Validate a site's JSON catalog without adding any site-specific journey rules. */
22
+ declare function parseJourneyCatalog(value: unknown): JourneyCatalog | null;
23
+
24
+ type GenericObject = Record<string, any>;
25
+ type Assign<Target, Source> = Omit<Target, keyof Source> & Source;
26
+ type Alias<T> = T & {
27
+ _?: never;
28
+ };
29
+ type Maybe<T> = T | null | undefined;
30
+ type HttpError = /* 400 */ 'HttpBadRequest' | /* 401 */ 'HttpUnauthorized' | /* 403 */ 'HttpForbidden' | /* 404 */ 'HttpNotFound' | /* 408 */ 'HttpRequestTimeout' | /* 429 */ 'HttpTooManyRequests' | /* 500 */ 'HttpInternalServerError';
31
+ type OperationError<T extends string = string> = {
32
+ name: T;
33
+ message: string;
34
+ };
35
+ type OperationResult<Error extends string = never, Data = never> = [
36
+ Data
37
+ ] extends [never] ? {
38
+ ok: false;
39
+ data?: never;
40
+ error: [Error] extends [never] ? OperationError<HttpError | 'UnknownError'> : OperationError<Error> | OperationError<HttpError | 'UnknownError'>;
41
+ } | {
42
+ ok: true;
43
+ data?: never;
44
+ error?: never;
45
+ } : {
46
+ ok: false;
47
+ data?: never;
48
+ error: [Error] extends [never] ? OperationError<HttpError | 'UnknownError'> : OperationError<Error> | OperationError<HttpError | 'UnknownError'>;
49
+ } | {
50
+ ok: true;
51
+ data: Data;
52
+ error?: never;
53
+ };
54
+
55
+ export { type Assign as A, type GenericObject as G, type HttpError as H, type JourneyCatalog as J, type Maybe as M, type OperationError as O, type SelectedJourney as S, USER_JOURNEY_STORAGE_KEY as U, type OperationResult as a, type JourneyPolicy as b, parseJourneyCatalog as c, type Alias as d, parseSelectedJourney as p };
package/dist/index.cjs CHANGED
@@ -9,7 +9,51 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
10
  var cookies__default = /*#__PURE__*/_interopDefault(cookies);
11
11
 
12
- // src/sdk/object-id.ts
12
+ // src/sdk/journey.ts
13
+ var USER_JOURNEY_STORAGE_KEY = "userJourney";
14
+ function parseSelectedJourney(value) {
15
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
16
+ return null;
17
+ }
18
+ const candidate = value;
19
+ if (typeof candidate.id !== "string" || !candidate.id.trim() || typeof candidate.version !== "number" || !Number.isSafeInteger(candidate.version) || candidate.version <= 0 || typeof candidate.currency !== "string" || !candidate.currency.trim() || candidate.signupType !== "number_only" && candidate.signupType !== "regular" || typeof candidate.kycRequired !== "boolean" || typeof candidate.minimumFtd !== "number" || !Number.isFinite(candidate.minimumFtd) || candidate.minimumFtd <= 0) {
20
+ return null;
21
+ }
22
+ return {
23
+ id: candidate.id,
24
+ version: candidate.version,
25
+ currency: candidate.currency,
26
+ signupType: candidate.signupType,
27
+ kycRequired: candidate.kycRequired,
28
+ minimumFtd: candidate.minimumFtd
29
+ };
30
+ }
31
+ function parseJourneyCatalog(value) {
32
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
33
+ const catalog = value;
34
+ if (typeof catalog.version !== "number" || !Number.isSafeInteger(catalog.version) || catalog.version <= 0 || typeof catalog.currency !== "string" || !catalog.currency.trim() || !catalog.journeys || typeof catalog.journeys !== "object" || Array.isArray(catalog.journeys))
35
+ return null;
36
+ const entries = Object.entries(catalog.journeys);
37
+ if (!entries.length) return null;
38
+ const journeys = /* @__PURE__ */ Object.create(null);
39
+ for (const [id, policy] of entries) {
40
+ if (!policy || typeof policy !== "object" || Array.isArray(policy))
41
+ return null;
42
+ const parsed = parseSelectedJourney({
43
+ ...policy,
44
+ id,
45
+ version: catalog.version,
46
+ currency: catalog.currency
47
+ });
48
+ if (!parsed) return null;
49
+ journeys[id] = {
50
+ signupType: parsed.signupType,
51
+ kycRequired: parsed.kycRequired,
52
+ minimumFtd: parsed.minimumFtd
53
+ };
54
+ }
55
+ return { version: catalog.version, currency: catalog.currency, journeys };
56
+ }
13
57
 
14
58
  // src/sdk/object-type.ts
15
59
  var ObjectType = {
@@ -11220,11 +11264,13 @@ var Sdk = class {
11220
11264
  logger;
11221
11265
  cache;
11222
11266
  config;
11267
+ journeyCatalog;
11223
11268
  /**
11224
11269
  * Stores the member domain for use in future mutations/queries
11225
11270
  */
11226
11271
  memberDomain = null;
11227
11272
  constructor(config) {
11273
+ this.journeyCatalog = config.journeyCatalog;
11228
11274
  captureFingerprintPreference();
11229
11275
  const {
11230
11276
  /**/
@@ -11234,7 +11280,7 @@ var Sdk = class {
11234
11280
  environment,
11235
11281
  authApiBaseUrl,
11236
11282
  logs
11237
- } = Object.assign(defaultConfig, config);
11283
+ } = Object.assign({}, defaultConfig, config);
11238
11284
  const production = environment === "production";
11239
11285
  const logger = new Logger({
11240
11286
  enabled: logs
@@ -11267,6 +11313,7 @@ var Sdk = class {
11267
11313
  this._middleware = config.middleware ?? ((req) => req);
11268
11314
  const graphqlClientConfig = () => ({
11269
11315
  middlewares: [
11316
+ this.userJourneyMiddleware,
11270
11317
  /**/
11271
11318
  this.authMiddleware,
11272
11319
  this.fingerprintMiddleware,
@@ -11302,6 +11349,7 @@ var Sdk = class {
11302
11349
  const publicAccountService = new AccountService(
11303
11350
  new GraphQLClient(accountUrl, () => ({
11304
11351
  middlewares: [
11352
+ this.userJourneyMiddleware,
11305
11353
  this.fingerprintMiddleware,
11306
11354
  this.miscMiddleware,
11307
11355
  this.testHeaderMiddleware,
@@ -11381,6 +11429,56 @@ var Sdk = class {
11381
11429
  };
11382
11430
  this.collectMetaDetails();
11383
11431
  this.initMarketDomain();
11432
+ this.captureUserJourney();
11433
+ }
11434
+ /** Capture a valid URL journey for this browser tab, including SPA navigation. */
11435
+ captureUserJourney(url) {
11436
+ if (typeof window === "undefined") return;
11437
+ try {
11438
+ const id = new URL(
11439
+ url?.toString() ?? window.location.href,
11440
+ window.location.href
11441
+ ).searchParams.get("journey");
11442
+ if (id && this.findUserJourney(id)) {
11443
+ sessionStorage.setItem(USER_JOURNEY_STORAGE_KEY, id);
11444
+ }
11445
+ } catch {
11446
+ }
11447
+ }
11448
+ getUserJourneyRegType() {
11449
+ return this.readUserJourney()?.signupType ?? null;
11450
+ }
11451
+ getUserJourneyMinFTD() {
11452
+ return this.readUserJourney()?.minimumFtd ?? null;
11453
+ }
11454
+ getUserJourneyIsKycSkippable() {
11455
+ const journey = this.readUserJourney();
11456
+ return journey ? !journey.kycRequired : null;
11457
+ }
11458
+ findUserJourney(id) {
11459
+ const catalog = this.journeyCatalog;
11460
+ if (!catalog || !Object.hasOwn(catalog.journeys, id)) return null;
11461
+ return parseSelectedJourney({
11462
+ ...catalog.journeys[id],
11463
+ id,
11464
+ version: catalog.version,
11465
+ currency: catalog.currency
11466
+ });
11467
+ }
11468
+ readUserJourney() {
11469
+ if (typeof window === "undefined") return null;
11470
+ try {
11471
+ const id = sessionStorage.getItem(USER_JOURNEY_STORAGE_KEY);
11472
+ return id ? this.findUserJourney(id) : null;
11473
+ } catch {
11474
+ return null;
11475
+ }
11476
+ }
11477
+ get userJourneyMiddleware() {
11478
+ return (request) => {
11479
+ this.captureUserJourney();
11480
+ return request;
11481
+ };
11384
11482
  }
11385
11483
  _fetch = null;
11386
11484
  _middleware;
@@ -14189,5 +14287,8 @@ exports.ENDPOINTS = ENDPOINTS;
14189
14287
  exports.ObjectType = ObjectType;
14190
14288
  exports.Sdk = Sdk;
14191
14289
  exports.Transformer = Transformer;
14290
+ exports.USER_JOURNEY_STORAGE_KEY = USER_JOURNEY_STORAGE_KEY;
14291
+ exports.parseJourneyCatalog = parseJourneyCatalog;
14292
+ exports.parseSelectedJourney = parseSelectedJourney;
14192
14293
  //# sourceMappingURL=index.cjs.map
14193
14294
  //# sourceMappingURL=index.cjs.map