@orderlyshop/core-client 0.1.0

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.
@@ -0,0 +1,107 @@
1
+ import { O as OAuthResponse, bm as AuthenticationRequestSchema, kN as PhoneNumberSchema, cp as ChallengeResonse, bn as AuthenticationResponse, bi as AuthResponse, ig as Login, p6 as ServiceDescriptors } from './services-DxuDjYkk.cjs';
2
+ import { MessageInitShape } from '@bufbuild/protobuf';
3
+ import { Client } from '@connectrpc/connect';
4
+
5
+ type MaybePromise<T> = T | Promise<T>;
6
+ interface TokenStore {
7
+ get(): MaybePromise<OAuthResponse | undefined>;
8
+ set(token: OAuthResponse): MaybePromise<void>;
9
+ clear(): MaybePromise<void>;
10
+ }
11
+ interface CachedIdentity {
12
+ userId: string;
13
+ displayName?: string;
14
+ updatedAt: string;
15
+ }
16
+ interface IdentityStore {
17
+ get(): MaybePromise<CachedIdentity | undefined>;
18
+ set(identity: CachedIdentity): MaybePromise<void>;
19
+ clear(): MaybePromise<void>;
20
+ }
21
+ declare function createMemoryTokenStore(initialToken?: OAuthResponse): TokenStore;
22
+ declare function createMemoryIdentityStore(initialIdentity?: CachedIdentity): IdentityStore;
23
+ interface BrowserIdentityStoreOptions {
24
+ storageKey?: string;
25
+ }
26
+ declare const defaultBrowserIdentityStorageKey = "orderly.identity";
27
+ declare function createBrowserLocalStorageIdentityStore(options?: BrowserIdentityStoreOptions): IdentityStore;
28
+ declare function sanitizeCachedIdentity(identity: Partial<CachedIdentity> | undefined | null): CachedIdentity | undefined;
29
+
30
+ type OrderlyServices = {
31
+ readonly [K in keyof ServiceDescriptors]: Client<ServiceDescriptors[K]>;
32
+ };
33
+ type PhoneNumberInput = MessageInitShape<typeof PhoneNumberSchema>;
34
+ type AuthenticationRequestInput = MessageInitShape<typeof AuthenticationRequestSchema>;
35
+ type OrderlyAuthConfig = {
36
+ type: "none";
37
+ } | {
38
+ type: "apiKey";
39
+ apiKey: string;
40
+ } | {
41
+ type: "bearer";
42
+ token: string;
43
+ } | {
44
+ type: "oauth";
45
+ token: OAuthResponse;
46
+ } | {
47
+ type: "cookie";
48
+ };
49
+ interface CreateChallengeOptions {
50
+ phoneNumber: PhoneNumberInput;
51
+ apiKey?: string;
52
+ }
53
+ interface SmsChallengeOptions {
54
+ phoneNumber: PhoneNumberInput;
55
+ code: string;
56
+ }
57
+ interface PasswordCredentialsOptions {
58
+ username: string;
59
+ password: string;
60
+ }
61
+ interface AccessKeyCredentialsOptions {
62
+ key: string;
63
+ }
64
+ interface PinCodeCredentialsOptions {
65
+ employeeId: string;
66
+ pin: number;
67
+ }
68
+ interface OrderlyAuthHelpers {
69
+ createChallenge(options: CreateChallengeOptions): Promise<ChallengeResonse>;
70
+ authenticate(request: AuthenticationRequestInput): Promise<AuthenticationResponse>;
71
+ authenticateWithSmsChallenge(options: SmsChallengeOptions): Promise<AuthenticationResponse>;
72
+ authenticateWithPassword(options: PasswordCredentialsOptions): Promise<AuthenticationResponse>;
73
+ authenticateWithAccessKey(options: AccessKeyCredentialsOptions): Promise<AuthenticationResponse>;
74
+ authenticateWithPinCode(options: PinCodeCredentialsOptions): Promise<AuthenticationResponse>;
75
+ acceptChallengeLegacy(options: SmsChallengeOptions): Promise<AuthResponse>;
76
+ refresh(): Promise<OAuthResponse | undefined>;
77
+ logout(): Promise<void>;
78
+ getCachedIdentity(): Promise<CachedIdentity | undefined>;
79
+ getCurrentLogin(): Promise<Login>;
80
+ verifySession(): Promise<boolean>;
81
+ }
82
+ interface OrderlyClient {
83
+ services: OrderlyServices;
84
+ auth: OrderlyAuthHelpers;
85
+ setApiKey(apiKey: string): Promise<void>;
86
+ setBearerToken(token: string): Promise<void>;
87
+ setOAuthResponse(token: OAuthResponse): Promise<void>;
88
+ clearAuth(): Promise<void>;
89
+ getOAuthResponse(): Promise<OAuthResponse | undefined>;
90
+ getCachedIdentity(): Promise<CachedIdentity | undefined>;
91
+ getCurrentLogin(): Promise<Login>;
92
+ }
93
+ interface BaseOrderlyClientOptions {
94
+ baseUrl: string;
95
+ auth?: OrderlyAuthConfig;
96
+ headers?: HeadersInit;
97
+ tokenStore?: TokenStore;
98
+ identityStore?: IdentityStore;
99
+ }
100
+ interface CreateOrderlyNodeClientOptions extends BaseOrderlyClientOptions {
101
+ protocol?: "grpc" | "grpc-web";
102
+ }
103
+ interface CreateOrderlyWebClientOptions extends BaseOrderlyClientOptions {
104
+ credentials?: RequestCredentials;
105
+ }
106
+
107
+ export { type AccessKeyCredentialsOptions as A, type BaseOrderlyClientOptions as B, type CreateOrderlyNodeClientOptions as C, type IdentityStore as I, type MaybePromise as M, type OrderlyClient as O, type PasswordCredentialsOptions as P, type SmsChallengeOptions as S, type TokenStore as T, type CreateOrderlyWebClientOptions as a, type OrderlyServices as b, type AuthenticationRequestInput as c, type BrowserIdentityStoreOptions as d, type CachedIdentity as e, type CreateChallengeOptions as f, type OrderlyAuthConfig as g, type OrderlyAuthHelpers as h, type PhoneNumberInput as i, type PinCodeCredentialsOptions as j, createBrowserLocalStorageIdentityStore as k, createMemoryIdentityStore as l, createMemoryTokenStore as m, defaultBrowserIdentityStorageKey as n, sanitizeCachedIdentity as s };
@@ -0,0 +1,107 @@
1
+ import { O as OAuthResponse, bm as AuthenticationRequestSchema, kN as PhoneNumberSchema, cp as ChallengeResonse, bn as AuthenticationResponse, bi as AuthResponse, ig as Login, p6 as ServiceDescriptors } from './services-DxuDjYkk.js';
2
+ import { MessageInitShape } from '@bufbuild/protobuf';
3
+ import { Client } from '@connectrpc/connect';
4
+
5
+ type MaybePromise<T> = T | Promise<T>;
6
+ interface TokenStore {
7
+ get(): MaybePromise<OAuthResponse | undefined>;
8
+ set(token: OAuthResponse): MaybePromise<void>;
9
+ clear(): MaybePromise<void>;
10
+ }
11
+ interface CachedIdentity {
12
+ userId: string;
13
+ displayName?: string;
14
+ updatedAt: string;
15
+ }
16
+ interface IdentityStore {
17
+ get(): MaybePromise<CachedIdentity | undefined>;
18
+ set(identity: CachedIdentity): MaybePromise<void>;
19
+ clear(): MaybePromise<void>;
20
+ }
21
+ declare function createMemoryTokenStore(initialToken?: OAuthResponse): TokenStore;
22
+ declare function createMemoryIdentityStore(initialIdentity?: CachedIdentity): IdentityStore;
23
+ interface BrowserIdentityStoreOptions {
24
+ storageKey?: string;
25
+ }
26
+ declare const defaultBrowserIdentityStorageKey = "orderly.identity";
27
+ declare function createBrowserLocalStorageIdentityStore(options?: BrowserIdentityStoreOptions): IdentityStore;
28
+ declare function sanitizeCachedIdentity(identity: Partial<CachedIdentity> | undefined | null): CachedIdentity | undefined;
29
+
30
+ type OrderlyServices = {
31
+ readonly [K in keyof ServiceDescriptors]: Client<ServiceDescriptors[K]>;
32
+ };
33
+ type PhoneNumberInput = MessageInitShape<typeof PhoneNumberSchema>;
34
+ type AuthenticationRequestInput = MessageInitShape<typeof AuthenticationRequestSchema>;
35
+ type OrderlyAuthConfig = {
36
+ type: "none";
37
+ } | {
38
+ type: "apiKey";
39
+ apiKey: string;
40
+ } | {
41
+ type: "bearer";
42
+ token: string;
43
+ } | {
44
+ type: "oauth";
45
+ token: OAuthResponse;
46
+ } | {
47
+ type: "cookie";
48
+ };
49
+ interface CreateChallengeOptions {
50
+ phoneNumber: PhoneNumberInput;
51
+ apiKey?: string;
52
+ }
53
+ interface SmsChallengeOptions {
54
+ phoneNumber: PhoneNumberInput;
55
+ code: string;
56
+ }
57
+ interface PasswordCredentialsOptions {
58
+ username: string;
59
+ password: string;
60
+ }
61
+ interface AccessKeyCredentialsOptions {
62
+ key: string;
63
+ }
64
+ interface PinCodeCredentialsOptions {
65
+ employeeId: string;
66
+ pin: number;
67
+ }
68
+ interface OrderlyAuthHelpers {
69
+ createChallenge(options: CreateChallengeOptions): Promise<ChallengeResonse>;
70
+ authenticate(request: AuthenticationRequestInput): Promise<AuthenticationResponse>;
71
+ authenticateWithSmsChallenge(options: SmsChallengeOptions): Promise<AuthenticationResponse>;
72
+ authenticateWithPassword(options: PasswordCredentialsOptions): Promise<AuthenticationResponse>;
73
+ authenticateWithAccessKey(options: AccessKeyCredentialsOptions): Promise<AuthenticationResponse>;
74
+ authenticateWithPinCode(options: PinCodeCredentialsOptions): Promise<AuthenticationResponse>;
75
+ acceptChallengeLegacy(options: SmsChallengeOptions): Promise<AuthResponse>;
76
+ refresh(): Promise<OAuthResponse | undefined>;
77
+ logout(): Promise<void>;
78
+ getCachedIdentity(): Promise<CachedIdentity | undefined>;
79
+ getCurrentLogin(): Promise<Login>;
80
+ verifySession(): Promise<boolean>;
81
+ }
82
+ interface OrderlyClient {
83
+ services: OrderlyServices;
84
+ auth: OrderlyAuthHelpers;
85
+ setApiKey(apiKey: string): Promise<void>;
86
+ setBearerToken(token: string): Promise<void>;
87
+ setOAuthResponse(token: OAuthResponse): Promise<void>;
88
+ clearAuth(): Promise<void>;
89
+ getOAuthResponse(): Promise<OAuthResponse | undefined>;
90
+ getCachedIdentity(): Promise<CachedIdentity | undefined>;
91
+ getCurrentLogin(): Promise<Login>;
92
+ }
93
+ interface BaseOrderlyClientOptions {
94
+ baseUrl: string;
95
+ auth?: OrderlyAuthConfig;
96
+ headers?: HeadersInit;
97
+ tokenStore?: TokenStore;
98
+ identityStore?: IdentityStore;
99
+ }
100
+ interface CreateOrderlyNodeClientOptions extends BaseOrderlyClientOptions {
101
+ protocol?: "grpc" | "grpc-web";
102
+ }
103
+ interface CreateOrderlyWebClientOptions extends BaseOrderlyClientOptions {
104
+ credentials?: RequestCredentials;
105
+ }
106
+
107
+ export { type AccessKeyCredentialsOptions as A, type BaseOrderlyClientOptions as B, type CreateOrderlyNodeClientOptions as C, type IdentityStore as I, type MaybePromise as M, type OrderlyClient as O, type PasswordCredentialsOptions as P, type SmsChallengeOptions as S, type TokenStore as T, type CreateOrderlyWebClientOptions as a, type OrderlyServices as b, type AuthenticationRequestInput as c, type BrowserIdentityStoreOptions as d, type CachedIdentity as e, type CreateChallengeOptions as f, type OrderlyAuthConfig as g, type OrderlyAuthHelpers as h, type PhoneNumberInput as i, type PinCodeCredentialsOptions as j, createBrowserLocalStorageIdentityStore as k, createMemoryIdentityStore as l, createMemoryTokenStore as m, defaultBrowserIdentityStorageKey as n, sanitizeCachedIdentity as s };