@moonbase.sh/storefront-api 0.3.24 → 0.3.26

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/dist/index.cjs CHANGED
@@ -472,8 +472,11 @@ var IdentityEndpoints = class {
472
472
  this.tokenStore.setUser(response.data);
473
473
  return userSchema.parse(response.data);
474
474
  }
475
+ async signOut() {
476
+ this.tokenStore.clear();
477
+ }
475
478
  async update(name, email, emailConfirmationToken, communicationPreferences) {
476
- const response = await this.api.authenticatedFetch("/api/customer/identity", null, {
479
+ const response = await this.api.authenticatedFetch("/api/customer/identity", userSchema, {
477
480
  method: "PATCH",
478
481
  body: {
479
482
  name,
@@ -482,8 +485,10 @@ var IdentityEndpoints = class {
482
485
  communicationPreferences
483
486
  }
484
487
  });
488
+ this.tokenStore.setUser(response.data);
485
489
  return {
486
- needsEmailConfirmationToken: response.status === 201
490
+ needsEmailConfirmationToken: response.status === 201,
491
+ user: response.data
487
492
  };
488
493
  }
489
494
  async setPassword(currentPassword, newPassword) {
@@ -1099,28 +1104,39 @@ var _TokenStore = class _TokenStore {
1099
1104
  return ((_c = this.tokens) == null ? void 0 : _c.accessToken) || null;
1100
1105
  }
1101
1106
  setUser(user) {
1102
- if (user === null) {
1103
- this.tokens = null;
1104
- if (typeof window !== "undefined")
1105
- this.store.remove(_TokenStore.storageKey);
1107
+ const identity = user;
1108
+ if (!identity.accessToken || !identity.refreshToken) {
1109
+ if (!this.tokens) return null;
1110
+ this.tokens = {
1111
+ ...user,
1112
+ accessToken: this.tokens.accessToken,
1113
+ refreshToken: this.tokens.refreshToken,
1114
+ expiresAt: this.tokens.expiresAt
1115
+ };
1116
+ } else {
1117
+ this.tokens = {
1118
+ ...identity,
1119
+ // Hardcoded 15 minutes now, might want to check the JWT tho
1120
+ expiresAt: new Date((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3)
1121
+ };
1122
+ }
1123
+ this.store.set(_TokenStore.storageKey, this.tokens);
1124
+ if (typeof window !== "undefined") {
1106
1125
  if (this.refreshTimeoutId != null)
1107
1126
  window.clearTimeout(this.refreshTimeoutId);
1108
- return null;
1127
+ this.refreshTimeoutId = window.setTimeout(() => {
1128
+ this.refreshPromise = this.refreshTokens();
1129
+ }, 10 * 60 * 1e3);
1109
1130
  }
1110
- this.tokens = {
1111
- ...user,
1112
- // Hardcoded 15 minutes now, might want to check the JWT tho
1113
- expiresAt: new Date((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3)
1114
- };
1115
- if (typeof window !== "undefined")
1116
- this.store.set(_TokenStore.storageKey, this.tokens);
1117
- if (this.refreshTimeoutId != null)
1118
- window.clearTimeout(this.refreshTimeoutId);
1119
- this.refreshTimeoutId = window.setTimeout(() => {
1120
- this.refreshPromise = this.refreshTokens();
1121
- }, 10 * 60 * 1e3);
1122
1131
  return this.tokens;
1123
1132
  }
1133
+ clear() {
1134
+ this.tokens = null;
1135
+ this.store.remove(_TokenStore.storageKey);
1136
+ if (this.refreshTimeoutId != null && typeof window !== "undefined")
1137
+ window.clearTimeout(this.refreshTimeoutId);
1138
+ return null;
1139
+ }
1124
1140
  get isExpired() {
1125
1141
  return this.tokens != null && this.tokens.expiresAt < /* @__PURE__ */ new Date();
1126
1142
  }
@@ -1138,13 +1154,14 @@ var _TokenStore = class _TokenStore {
1138
1154
  });
1139
1155
  if (response.status !== 200) {
1140
1156
  if (response.status === 403 || response.status === 404) {
1141
- this.setUser(null);
1157
+ this.clear();
1142
1158
  return null;
1143
1159
  }
1144
1160
  throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
1145
1161
  }
1146
1162
  const result = identitySchema.parse(await response.json());
1147
- return this.setUser(result);
1163
+ this.setUser(result);
1164
+ return this.tokens;
1148
1165
  }
1149
1166
  handleStorageUpdate(updatedTokens) {
1150
1167
  this.tokens = updatedTokens;
package/dist/index.d.cts CHANGED
@@ -1,235 +1,13 @@
1
- import { z, ZodTypeAny } from 'zod';
1
+ import { ZodTypeAny, z } from 'zod';
2
2
 
3
- declare const addressSchema: z.ZodObject<{
4
- countryCode: z.ZodString;
5
- streetAddress1: z.ZodString;
6
- streetAddress2: z.ZodNullable<z.ZodString>;
7
- locality: z.ZodNullable<z.ZodString>;
8
- region: z.ZodNullable<z.ZodString>;
9
- postCode: z.ZodString;
10
- }, "strip", z.ZodTypeAny, {
11
- countryCode: string;
12
- streetAddress1: string;
13
- streetAddress2: string | null;
14
- locality: string | null;
15
- region: string | null;
16
- postCode: string;
17
- }, {
18
- countryCode: string;
19
- streetAddress1: string;
20
- streetAddress2: string | null;
21
- locality: string | null;
22
- region: string | null;
23
- postCode: string;
24
- }>;
25
- declare const communicationPreferencesSchema: z.ZodObject<{
26
- newsletterOptIn: z.ZodBoolean;
27
- }, "strip", z.ZodTypeAny, {
28
- newsletterOptIn: boolean;
29
- }, {
30
- newsletterOptIn: boolean;
31
- }>;
32
- declare const userSchema: z.ZodObject<{
33
- id: z.ZodString;
34
- email: z.ZodString;
35
- name: z.ZodString;
36
- tenantId: z.ZodString;
37
- address: z.ZodOptional<z.ZodObject<{
38
- countryCode: z.ZodString;
39
- streetAddress1: z.ZodString;
40
- streetAddress2: z.ZodNullable<z.ZodString>;
41
- locality: z.ZodNullable<z.ZodString>;
42
- region: z.ZodNullable<z.ZodString>;
43
- postCode: z.ZodString;
44
- }, "strip", z.ZodTypeAny, {
45
- countryCode: string;
46
- streetAddress1: string;
47
- streetAddress2: string | null;
48
- locality: string | null;
49
- region: string | null;
50
- postCode: string;
51
- }, {
52
- countryCode: string;
53
- streetAddress1: string;
54
- streetAddress2: string | null;
55
- locality: string | null;
56
- region: string | null;
57
- postCode: string;
58
- }>>;
59
- communicationPreferences: z.ZodObject<{
60
- newsletterOptIn: z.ZodBoolean;
61
- }, "strip", z.ZodTypeAny, {
62
- newsletterOptIn: boolean;
63
- }, {
64
- newsletterOptIn: boolean;
65
- }>;
66
- ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
67
- subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
68
- hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
69
- hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
70
- }, "strip", z.ZodTypeAny, {
71
- id: string;
72
- email: string;
73
- name: string;
74
- tenantId: string;
75
- communicationPreferences: {
76
- newsletterOptIn: boolean;
77
- };
78
- address?: {
79
- countryCode: string;
80
- streetAddress1: string;
81
- streetAddress2: string | null;
82
- locality: string | null;
83
- region: string | null;
84
- postCode: string;
85
- } | undefined;
86
- ownedProducts?: string[] | undefined;
87
- subscribedProducts?: string[] | undefined;
88
- hasProducts?: boolean | null | undefined;
89
- hasSubscriptions?: boolean | null | undefined;
90
- }, {
91
- id: string;
92
- email: string;
93
- name: string;
94
- tenantId: string;
95
- communicationPreferences: {
96
- newsletterOptIn: boolean;
97
- };
98
- address?: {
99
- countryCode: string;
100
- streetAddress1: string;
101
- streetAddress2: string | null;
102
- locality: string | null;
103
- region: string | null;
104
- postCode: string;
105
- } | undefined;
106
- ownedProducts?: string[] | undefined;
107
- subscribedProducts?: string[] | undefined;
108
- hasProducts?: boolean | null | undefined;
109
- hasSubscriptions?: boolean | null | undefined;
110
- }>;
111
- declare const identitySchema: z.ZodIntersection<z.ZodObject<{
112
- id: z.ZodString;
113
- email: z.ZodString;
114
- name: z.ZodString;
115
- tenantId: z.ZodString;
116
- address: z.ZodOptional<z.ZodObject<{
117
- countryCode: z.ZodString;
118
- streetAddress1: z.ZodString;
119
- streetAddress2: z.ZodNullable<z.ZodString>;
120
- locality: z.ZodNullable<z.ZodString>;
121
- region: z.ZodNullable<z.ZodString>;
122
- postCode: z.ZodString;
123
- }, "strip", z.ZodTypeAny, {
124
- countryCode: string;
125
- streetAddress1: string;
126
- streetAddress2: string | null;
127
- locality: string | null;
128
- region: string | null;
129
- postCode: string;
130
- }, {
131
- countryCode: string;
132
- streetAddress1: string;
133
- streetAddress2: string | null;
134
- locality: string | null;
135
- region: string | null;
136
- postCode: string;
137
- }>>;
138
- communicationPreferences: z.ZodObject<{
139
- newsletterOptIn: z.ZodBoolean;
140
- }, "strip", z.ZodTypeAny, {
141
- newsletterOptIn: boolean;
142
- }, {
143
- newsletterOptIn: boolean;
144
- }>;
145
- ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
146
- subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
147
- hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
148
- hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
149
- }, "strip", z.ZodTypeAny, {
150
- id: string;
151
- email: string;
152
- name: string;
153
- tenantId: string;
154
- communicationPreferences: {
155
- newsletterOptIn: boolean;
156
- };
157
- address?: {
158
- countryCode: string;
159
- streetAddress1: string;
160
- streetAddress2: string | null;
161
- locality: string | null;
162
- region: string | null;
163
- postCode: string;
164
- } | undefined;
165
- ownedProducts?: string[] | undefined;
166
- subscribedProducts?: string[] | undefined;
167
- hasProducts?: boolean | null | undefined;
168
- hasSubscriptions?: boolean | null | undefined;
169
- }, {
170
- id: string;
171
- email: string;
172
- name: string;
173
- tenantId: string;
174
- communicationPreferences: {
175
- newsletterOptIn: boolean;
176
- };
177
- address?: {
178
- countryCode: string;
179
- streetAddress1: string;
180
- streetAddress2: string | null;
181
- locality: string | null;
182
- region: string | null;
183
- postCode: string;
184
- } | undefined;
185
- ownedProducts?: string[] | undefined;
186
- subscribedProducts?: string[] | undefined;
187
- hasProducts?: boolean | null | undefined;
188
- hasSubscriptions?: boolean | null | undefined;
189
- }>, z.ZodObject<{
190
- accessToken: z.ZodString;
191
- refreshToken: z.ZodString;
192
- }, "strip", z.ZodTypeAny, {
193
- accessToken: string;
194
- refreshToken: string;
195
- }, {
196
- accessToken: string;
197
- refreshToken: string;
198
- }>>;
199
- declare const userAccountConfirmedSchema: z.ZodObject<{
200
- id: z.ZodString;
201
- name: z.ZodString;
202
- email: z.ZodString;
203
- resetPasswordToken: z.ZodNullable<z.ZodString>;
204
- }, "strip", z.ZodTypeAny, {
205
- id: string;
206
- email: string;
207
- name: string;
208
- resetPasswordToken: string | null;
209
- }, {
210
- id: string;
211
- email: string;
212
- name: string;
213
- resetPasswordToken: string | null;
214
- }>;
215
-
216
- declare const schemas$2_addressSchema: typeof addressSchema;
217
- declare const schemas$2_communicationPreferencesSchema: typeof communicationPreferencesSchema;
218
- declare const schemas$2_identitySchema: typeof identitySchema;
219
- declare const schemas$2_userAccountConfirmedSchema: typeof userAccountConfirmedSchema;
220
- declare const schemas$2_userSchema: typeof userSchema;
221
- declare namespace schemas$2 {
222
- export { schemas$2_addressSchema as addressSchema, schemas$2_communicationPreferencesSchema as communicationPreferencesSchema, schemas$2_identitySchema as identitySchema, schemas$2_userAccountConfirmedSchema as userAccountConfirmedSchema, schemas$2_userSchema as userSchema };
223
- }
224
-
225
- type Identity = z.infer<typeof identitySchema>;
226
3
  type IdentityWithExpiry = Identity & {
227
4
  expiresAt: Date;
228
5
  };
229
6
  interface ITokenStore {
230
7
  get user(): User | null;
231
8
  getAccessToken: () => Promise<string | null>;
232
- setUser: (user: Identity | null) => Identity | null;
9
+ setUser: (user: Identity | User) => User | null;
10
+ clear: () => void;
233
11
  }
234
12
  declare class TokenStore implements ITokenStore {
235
13
  private configuration;
@@ -241,7 +19,8 @@ declare class TokenStore implements ITokenStore {
241
19
  constructor(configuration: MoonbaseConfiguration);
242
20
  get user(): User | null;
243
21
  getAccessToken(): Promise<string | null>;
244
- setUser(user: Identity | null): IdentityWithExpiry | null;
22
+ setUser(user: Identity | User): IdentityWithExpiry | null;
23
+ clear(): null;
245
24
  private get isExpired();
246
25
  private refreshTokens;
247
26
  private handleStorageUpdate;
@@ -1086,8 +865,231 @@ declare class ActivationRequestEndpoints {
1086
865
  cancel(requestId: string): Promise<ActivationRequest>;
1087
866
  }
1088
867
 
868
+ declare const addressSchema: z.ZodObject<{
869
+ countryCode: z.ZodString;
870
+ streetAddress1: z.ZodString;
871
+ streetAddress2: z.ZodNullable<z.ZodString>;
872
+ locality: z.ZodNullable<z.ZodString>;
873
+ region: z.ZodNullable<z.ZodString>;
874
+ postCode: z.ZodString;
875
+ }, "strip", z.ZodTypeAny, {
876
+ countryCode: string;
877
+ streetAddress1: string;
878
+ streetAddress2: string | null;
879
+ locality: string | null;
880
+ region: string | null;
881
+ postCode: string;
882
+ }, {
883
+ countryCode: string;
884
+ streetAddress1: string;
885
+ streetAddress2: string | null;
886
+ locality: string | null;
887
+ region: string | null;
888
+ postCode: string;
889
+ }>;
890
+ declare const communicationPreferencesSchema: z.ZodObject<{
891
+ newsletterOptIn: z.ZodBoolean;
892
+ }, "strip", z.ZodTypeAny, {
893
+ newsletterOptIn: boolean;
894
+ }, {
895
+ newsletterOptIn: boolean;
896
+ }>;
897
+ declare const userSchema: z.ZodObject<{
898
+ id: z.ZodString;
899
+ email: z.ZodString;
900
+ name: z.ZodString;
901
+ tenantId: z.ZodString;
902
+ address: z.ZodOptional<z.ZodObject<{
903
+ countryCode: z.ZodString;
904
+ streetAddress1: z.ZodString;
905
+ streetAddress2: z.ZodNullable<z.ZodString>;
906
+ locality: z.ZodNullable<z.ZodString>;
907
+ region: z.ZodNullable<z.ZodString>;
908
+ postCode: z.ZodString;
909
+ }, "strip", z.ZodTypeAny, {
910
+ countryCode: string;
911
+ streetAddress1: string;
912
+ streetAddress2: string | null;
913
+ locality: string | null;
914
+ region: string | null;
915
+ postCode: string;
916
+ }, {
917
+ countryCode: string;
918
+ streetAddress1: string;
919
+ streetAddress2: string | null;
920
+ locality: string | null;
921
+ region: string | null;
922
+ postCode: string;
923
+ }>>;
924
+ communicationPreferences: z.ZodObject<{
925
+ newsletterOptIn: z.ZodBoolean;
926
+ }, "strip", z.ZodTypeAny, {
927
+ newsletterOptIn: boolean;
928
+ }, {
929
+ newsletterOptIn: boolean;
930
+ }>;
931
+ ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
932
+ subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
933
+ hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
934
+ hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
935
+ }, "strip", z.ZodTypeAny, {
936
+ id: string;
937
+ email: string;
938
+ name: string;
939
+ tenantId: string;
940
+ communicationPreferences: {
941
+ newsletterOptIn: boolean;
942
+ };
943
+ address?: {
944
+ countryCode: string;
945
+ streetAddress1: string;
946
+ streetAddress2: string | null;
947
+ locality: string | null;
948
+ region: string | null;
949
+ postCode: string;
950
+ } | undefined;
951
+ ownedProducts?: string[] | undefined;
952
+ subscribedProducts?: string[] | undefined;
953
+ hasProducts?: boolean | null | undefined;
954
+ hasSubscriptions?: boolean | null | undefined;
955
+ }, {
956
+ id: string;
957
+ email: string;
958
+ name: string;
959
+ tenantId: string;
960
+ communicationPreferences: {
961
+ newsletterOptIn: boolean;
962
+ };
963
+ address?: {
964
+ countryCode: string;
965
+ streetAddress1: string;
966
+ streetAddress2: string | null;
967
+ locality: string | null;
968
+ region: string | null;
969
+ postCode: string;
970
+ } | undefined;
971
+ ownedProducts?: string[] | undefined;
972
+ subscribedProducts?: string[] | undefined;
973
+ hasProducts?: boolean | null | undefined;
974
+ hasSubscriptions?: boolean | null | undefined;
975
+ }>;
976
+ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
977
+ id: z.ZodString;
978
+ email: z.ZodString;
979
+ name: z.ZodString;
980
+ tenantId: z.ZodString;
981
+ address: z.ZodOptional<z.ZodObject<{
982
+ countryCode: z.ZodString;
983
+ streetAddress1: z.ZodString;
984
+ streetAddress2: z.ZodNullable<z.ZodString>;
985
+ locality: z.ZodNullable<z.ZodString>;
986
+ region: z.ZodNullable<z.ZodString>;
987
+ postCode: z.ZodString;
988
+ }, "strip", z.ZodTypeAny, {
989
+ countryCode: string;
990
+ streetAddress1: string;
991
+ streetAddress2: string | null;
992
+ locality: string | null;
993
+ region: string | null;
994
+ postCode: string;
995
+ }, {
996
+ countryCode: string;
997
+ streetAddress1: string;
998
+ streetAddress2: string | null;
999
+ locality: string | null;
1000
+ region: string | null;
1001
+ postCode: string;
1002
+ }>>;
1003
+ communicationPreferences: z.ZodObject<{
1004
+ newsletterOptIn: z.ZodBoolean;
1005
+ }, "strip", z.ZodTypeAny, {
1006
+ newsletterOptIn: boolean;
1007
+ }, {
1008
+ newsletterOptIn: boolean;
1009
+ }>;
1010
+ ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1011
+ subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1012
+ hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1013
+ hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1014
+ }, "strip", z.ZodTypeAny, {
1015
+ id: string;
1016
+ email: string;
1017
+ name: string;
1018
+ tenantId: string;
1019
+ communicationPreferences: {
1020
+ newsletterOptIn: boolean;
1021
+ };
1022
+ address?: {
1023
+ countryCode: string;
1024
+ streetAddress1: string;
1025
+ streetAddress2: string | null;
1026
+ locality: string | null;
1027
+ region: string | null;
1028
+ postCode: string;
1029
+ } | undefined;
1030
+ ownedProducts?: string[] | undefined;
1031
+ subscribedProducts?: string[] | undefined;
1032
+ hasProducts?: boolean | null | undefined;
1033
+ hasSubscriptions?: boolean | null | undefined;
1034
+ }, {
1035
+ id: string;
1036
+ email: string;
1037
+ name: string;
1038
+ tenantId: string;
1039
+ communicationPreferences: {
1040
+ newsletterOptIn: boolean;
1041
+ };
1042
+ address?: {
1043
+ countryCode: string;
1044
+ streetAddress1: string;
1045
+ streetAddress2: string | null;
1046
+ locality: string | null;
1047
+ region: string | null;
1048
+ postCode: string;
1049
+ } | undefined;
1050
+ ownedProducts?: string[] | undefined;
1051
+ subscribedProducts?: string[] | undefined;
1052
+ hasProducts?: boolean | null | undefined;
1053
+ hasSubscriptions?: boolean | null | undefined;
1054
+ }>, z.ZodObject<{
1055
+ accessToken: z.ZodString;
1056
+ refreshToken: z.ZodString;
1057
+ }, "strip", z.ZodTypeAny, {
1058
+ accessToken: string;
1059
+ refreshToken: string;
1060
+ }, {
1061
+ accessToken: string;
1062
+ refreshToken: string;
1063
+ }>>;
1064
+ declare const userAccountConfirmedSchema: z.ZodObject<{
1065
+ id: z.ZodString;
1066
+ name: z.ZodString;
1067
+ email: z.ZodString;
1068
+ resetPasswordToken: z.ZodNullable<z.ZodString>;
1069
+ }, "strip", z.ZodTypeAny, {
1070
+ id: string;
1071
+ email: string;
1072
+ name: string;
1073
+ resetPasswordToken: string | null;
1074
+ }, {
1075
+ id: string;
1076
+ email: string;
1077
+ name: string;
1078
+ resetPasswordToken: string | null;
1079
+ }>;
1080
+
1081
+ declare const schemas$2_addressSchema: typeof addressSchema;
1082
+ declare const schemas$2_communicationPreferencesSchema: typeof communicationPreferencesSchema;
1083
+ declare const schemas$2_identitySchema: typeof identitySchema;
1084
+ declare const schemas$2_userAccountConfirmedSchema: typeof userAccountConfirmedSchema;
1085
+ declare const schemas$2_userSchema: typeof userSchema;
1086
+ declare namespace schemas$2 {
1087
+ export { schemas$2_addressSchema as addressSchema, schemas$2_communicationPreferencesSchema as communicationPreferencesSchema, schemas$2_identitySchema as identitySchema, schemas$2_userAccountConfirmedSchema as userAccountConfirmedSchema, schemas$2_userSchema as userSchema };
1088
+ }
1089
+
1089
1090
  type CommunicationPreferences = z.infer<typeof communicationPreferencesSchema>;
1090
1091
  type User = z.infer<typeof userSchema>;
1092
+ type Identity = z.infer<typeof identitySchema>;
1091
1093
  type Address = z.infer<typeof addressSchema>;
1092
1094
  type UserAccountConfirmed = z.infer<typeof userAccountConfirmedSchema>;
1093
1095
 
@@ -1098,8 +1100,30 @@ declare class IdentityEndpoints {
1098
1100
  get(): Promise<User>;
1099
1101
  signIn(email: string, password: string): Promise<User>;
1100
1102
  signUp(name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean, communicationOptIn?: boolean): Promise<User>;
1103
+ signOut(): Promise<void>;
1101
1104
  update(name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1102
1105
  needsEmailConfirmationToken: boolean;
1106
+ user: {
1107
+ id: string;
1108
+ email: string;
1109
+ name: string;
1110
+ tenantId: string;
1111
+ communicationPreferences: {
1112
+ newsletterOptIn: boolean;
1113
+ };
1114
+ address?: {
1115
+ countryCode: string;
1116
+ streetAddress1: string;
1117
+ streetAddress2: string | null;
1118
+ locality: string | null;
1119
+ region: string | null;
1120
+ postCode: string;
1121
+ } | undefined;
1122
+ ownedProducts?: string[] | undefined;
1123
+ subscribedProducts?: string[] | undefined;
1124
+ hasProducts?: boolean | null | undefined;
1125
+ hasSubscriptions?: boolean | null | undefined;
1126
+ };
1103
1127
  }>;
1104
1128
  setPassword(currentPassword: string, newPassword: string): Promise<void>;
1105
1129
  forgotPassword(email: string): Promise<void>;
@@ -22677,4 +22701,4 @@ declare class MoonbaseClient {
22677
22701
  orders: OrderEndpoints;
22678
22702
  }
22679
22703
 
22680
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, CycleLength, type Discount, type Download, type DownloadManifest, type IRecurrence, type IStore, type ITokenStore, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, type Money, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
22704
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, CycleLength, type Discount, type Download, type DownloadManifest, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, type Money, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
package/dist/index.d.ts CHANGED
@@ -1,235 +1,13 @@
1
- import { z, ZodTypeAny } from 'zod';
1
+ import { ZodTypeAny, z } from 'zod';
2
2
 
3
- declare const addressSchema: z.ZodObject<{
4
- countryCode: z.ZodString;
5
- streetAddress1: z.ZodString;
6
- streetAddress2: z.ZodNullable<z.ZodString>;
7
- locality: z.ZodNullable<z.ZodString>;
8
- region: z.ZodNullable<z.ZodString>;
9
- postCode: z.ZodString;
10
- }, "strip", z.ZodTypeAny, {
11
- countryCode: string;
12
- streetAddress1: string;
13
- streetAddress2: string | null;
14
- locality: string | null;
15
- region: string | null;
16
- postCode: string;
17
- }, {
18
- countryCode: string;
19
- streetAddress1: string;
20
- streetAddress2: string | null;
21
- locality: string | null;
22
- region: string | null;
23
- postCode: string;
24
- }>;
25
- declare const communicationPreferencesSchema: z.ZodObject<{
26
- newsletterOptIn: z.ZodBoolean;
27
- }, "strip", z.ZodTypeAny, {
28
- newsletterOptIn: boolean;
29
- }, {
30
- newsletterOptIn: boolean;
31
- }>;
32
- declare const userSchema: z.ZodObject<{
33
- id: z.ZodString;
34
- email: z.ZodString;
35
- name: z.ZodString;
36
- tenantId: z.ZodString;
37
- address: z.ZodOptional<z.ZodObject<{
38
- countryCode: z.ZodString;
39
- streetAddress1: z.ZodString;
40
- streetAddress2: z.ZodNullable<z.ZodString>;
41
- locality: z.ZodNullable<z.ZodString>;
42
- region: z.ZodNullable<z.ZodString>;
43
- postCode: z.ZodString;
44
- }, "strip", z.ZodTypeAny, {
45
- countryCode: string;
46
- streetAddress1: string;
47
- streetAddress2: string | null;
48
- locality: string | null;
49
- region: string | null;
50
- postCode: string;
51
- }, {
52
- countryCode: string;
53
- streetAddress1: string;
54
- streetAddress2: string | null;
55
- locality: string | null;
56
- region: string | null;
57
- postCode: string;
58
- }>>;
59
- communicationPreferences: z.ZodObject<{
60
- newsletterOptIn: z.ZodBoolean;
61
- }, "strip", z.ZodTypeAny, {
62
- newsletterOptIn: boolean;
63
- }, {
64
- newsletterOptIn: boolean;
65
- }>;
66
- ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
67
- subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
68
- hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
69
- hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
70
- }, "strip", z.ZodTypeAny, {
71
- id: string;
72
- email: string;
73
- name: string;
74
- tenantId: string;
75
- communicationPreferences: {
76
- newsletterOptIn: boolean;
77
- };
78
- address?: {
79
- countryCode: string;
80
- streetAddress1: string;
81
- streetAddress2: string | null;
82
- locality: string | null;
83
- region: string | null;
84
- postCode: string;
85
- } | undefined;
86
- ownedProducts?: string[] | undefined;
87
- subscribedProducts?: string[] | undefined;
88
- hasProducts?: boolean | null | undefined;
89
- hasSubscriptions?: boolean | null | undefined;
90
- }, {
91
- id: string;
92
- email: string;
93
- name: string;
94
- tenantId: string;
95
- communicationPreferences: {
96
- newsletterOptIn: boolean;
97
- };
98
- address?: {
99
- countryCode: string;
100
- streetAddress1: string;
101
- streetAddress2: string | null;
102
- locality: string | null;
103
- region: string | null;
104
- postCode: string;
105
- } | undefined;
106
- ownedProducts?: string[] | undefined;
107
- subscribedProducts?: string[] | undefined;
108
- hasProducts?: boolean | null | undefined;
109
- hasSubscriptions?: boolean | null | undefined;
110
- }>;
111
- declare const identitySchema: z.ZodIntersection<z.ZodObject<{
112
- id: z.ZodString;
113
- email: z.ZodString;
114
- name: z.ZodString;
115
- tenantId: z.ZodString;
116
- address: z.ZodOptional<z.ZodObject<{
117
- countryCode: z.ZodString;
118
- streetAddress1: z.ZodString;
119
- streetAddress2: z.ZodNullable<z.ZodString>;
120
- locality: z.ZodNullable<z.ZodString>;
121
- region: z.ZodNullable<z.ZodString>;
122
- postCode: z.ZodString;
123
- }, "strip", z.ZodTypeAny, {
124
- countryCode: string;
125
- streetAddress1: string;
126
- streetAddress2: string | null;
127
- locality: string | null;
128
- region: string | null;
129
- postCode: string;
130
- }, {
131
- countryCode: string;
132
- streetAddress1: string;
133
- streetAddress2: string | null;
134
- locality: string | null;
135
- region: string | null;
136
- postCode: string;
137
- }>>;
138
- communicationPreferences: z.ZodObject<{
139
- newsletterOptIn: z.ZodBoolean;
140
- }, "strip", z.ZodTypeAny, {
141
- newsletterOptIn: boolean;
142
- }, {
143
- newsletterOptIn: boolean;
144
- }>;
145
- ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
146
- subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
147
- hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
148
- hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
149
- }, "strip", z.ZodTypeAny, {
150
- id: string;
151
- email: string;
152
- name: string;
153
- tenantId: string;
154
- communicationPreferences: {
155
- newsletterOptIn: boolean;
156
- };
157
- address?: {
158
- countryCode: string;
159
- streetAddress1: string;
160
- streetAddress2: string | null;
161
- locality: string | null;
162
- region: string | null;
163
- postCode: string;
164
- } | undefined;
165
- ownedProducts?: string[] | undefined;
166
- subscribedProducts?: string[] | undefined;
167
- hasProducts?: boolean | null | undefined;
168
- hasSubscriptions?: boolean | null | undefined;
169
- }, {
170
- id: string;
171
- email: string;
172
- name: string;
173
- tenantId: string;
174
- communicationPreferences: {
175
- newsletterOptIn: boolean;
176
- };
177
- address?: {
178
- countryCode: string;
179
- streetAddress1: string;
180
- streetAddress2: string | null;
181
- locality: string | null;
182
- region: string | null;
183
- postCode: string;
184
- } | undefined;
185
- ownedProducts?: string[] | undefined;
186
- subscribedProducts?: string[] | undefined;
187
- hasProducts?: boolean | null | undefined;
188
- hasSubscriptions?: boolean | null | undefined;
189
- }>, z.ZodObject<{
190
- accessToken: z.ZodString;
191
- refreshToken: z.ZodString;
192
- }, "strip", z.ZodTypeAny, {
193
- accessToken: string;
194
- refreshToken: string;
195
- }, {
196
- accessToken: string;
197
- refreshToken: string;
198
- }>>;
199
- declare const userAccountConfirmedSchema: z.ZodObject<{
200
- id: z.ZodString;
201
- name: z.ZodString;
202
- email: z.ZodString;
203
- resetPasswordToken: z.ZodNullable<z.ZodString>;
204
- }, "strip", z.ZodTypeAny, {
205
- id: string;
206
- email: string;
207
- name: string;
208
- resetPasswordToken: string | null;
209
- }, {
210
- id: string;
211
- email: string;
212
- name: string;
213
- resetPasswordToken: string | null;
214
- }>;
215
-
216
- declare const schemas$2_addressSchema: typeof addressSchema;
217
- declare const schemas$2_communicationPreferencesSchema: typeof communicationPreferencesSchema;
218
- declare const schemas$2_identitySchema: typeof identitySchema;
219
- declare const schemas$2_userAccountConfirmedSchema: typeof userAccountConfirmedSchema;
220
- declare const schemas$2_userSchema: typeof userSchema;
221
- declare namespace schemas$2 {
222
- export { schemas$2_addressSchema as addressSchema, schemas$2_communicationPreferencesSchema as communicationPreferencesSchema, schemas$2_identitySchema as identitySchema, schemas$2_userAccountConfirmedSchema as userAccountConfirmedSchema, schemas$2_userSchema as userSchema };
223
- }
224
-
225
- type Identity = z.infer<typeof identitySchema>;
226
3
  type IdentityWithExpiry = Identity & {
227
4
  expiresAt: Date;
228
5
  };
229
6
  interface ITokenStore {
230
7
  get user(): User | null;
231
8
  getAccessToken: () => Promise<string | null>;
232
- setUser: (user: Identity | null) => Identity | null;
9
+ setUser: (user: Identity | User) => User | null;
10
+ clear: () => void;
233
11
  }
234
12
  declare class TokenStore implements ITokenStore {
235
13
  private configuration;
@@ -241,7 +19,8 @@ declare class TokenStore implements ITokenStore {
241
19
  constructor(configuration: MoonbaseConfiguration);
242
20
  get user(): User | null;
243
21
  getAccessToken(): Promise<string | null>;
244
- setUser(user: Identity | null): IdentityWithExpiry | null;
22
+ setUser(user: Identity | User): IdentityWithExpiry | null;
23
+ clear(): null;
245
24
  private get isExpired();
246
25
  private refreshTokens;
247
26
  private handleStorageUpdate;
@@ -1086,8 +865,231 @@ declare class ActivationRequestEndpoints {
1086
865
  cancel(requestId: string): Promise<ActivationRequest>;
1087
866
  }
1088
867
 
868
+ declare const addressSchema: z.ZodObject<{
869
+ countryCode: z.ZodString;
870
+ streetAddress1: z.ZodString;
871
+ streetAddress2: z.ZodNullable<z.ZodString>;
872
+ locality: z.ZodNullable<z.ZodString>;
873
+ region: z.ZodNullable<z.ZodString>;
874
+ postCode: z.ZodString;
875
+ }, "strip", z.ZodTypeAny, {
876
+ countryCode: string;
877
+ streetAddress1: string;
878
+ streetAddress2: string | null;
879
+ locality: string | null;
880
+ region: string | null;
881
+ postCode: string;
882
+ }, {
883
+ countryCode: string;
884
+ streetAddress1: string;
885
+ streetAddress2: string | null;
886
+ locality: string | null;
887
+ region: string | null;
888
+ postCode: string;
889
+ }>;
890
+ declare const communicationPreferencesSchema: z.ZodObject<{
891
+ newsletterOptIn: z.ZodBoolean;
892
+ }, "strip", z.ZodTypeAny, {
893
+ newsletterOptIn: boolean;
894
+ }, {
895
+ newsletterOptIn: boolean;
896
+ }>;
897
+ declare const userSchema: z.ZodObject<{
898
+ id: z.ZodString;
899
+ email: z.ZodString;
900
+ name: z.ZodString;
901
+ tenantId: z.ZodString;
902
+ address: z.ZodOptional<z.ZodObject<{
903
+ countryCode: z.ZodString;
904
+ streetAddress1: z.ZodString;
905
+ streetAddress2: z.ZodNullable<z.ZodString>;
906
+ locality: z.ZodNullable<z.ZodString>;
907
+ region: z.ZodNullable<z.ZodString>;
908
+ postCode: z.ZodString;
909
+ }, "strip", z.ZodTypeAny, {
910
+ countryCode: string;
911
+ streetAddress1: string;
912
+ streetAddress2: string | null;
913
+ locality: string | null;
914
+ region: string | null;
915
+ postCode: string;
916
+ }, {
917
+ countryCode: string;
918
+ streetAddress1: string;
919
+ streetAddress2: string | null;
920
+ locality: string | null;
921
+ region: string | null;
922
+ postCode: string;
923
+ }>>;
924
+ communicationPreferences: z.ZodObject<{
925
+ newsletterOptIn: z.ZodBoolean;
926
+ }, "strip", z.ZodTypeAny, {
927
+ newsletterOptIn: boolean;
928
+ }, {
929
+ newsletterOptIn: boolean;
930
+ }>;
931
+ ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
932
+ subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
933
+ hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
934
+ hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
935
+ }, "strip", z.ZodTypeAny, {
936
+ id: string;
937
+ email: string;
938
+ name: string;
939
+ tenantId: string;
940
+ communicationPreferences: {
941
+ newsletterOptIn: boolean;
942
+ };
943
+ address?: {
944
+ countryCode: string;
945
+ streetAddress1: string;
946
+ streetAddress2: string | null;
947
+ locality: string | null;
948
+ region: string | null;
949
+ postCode: string;
950
+ } | undefined;
951
+ ownedProducts?: string[] | undefined;
952
+ subscribedProducts?: string[] | undefined;
953
+ hasProducts?: boolean | null | undefined;
954
+ hasSubscriptions?: boolean | null | undefined;
955
+ }, {
956
+ id: string;
957
+ email: string;
958
+ name: string;
959
+ tenantId: string;
960
+ communicationPreferences: {
961
+ newsletterOptIn: boolean;
962
+ };
963
+ address?: {
964
+ countryCode: string;
965
+ streetAddress1: string;
966
+ streetAddress2: string | null;
967
+ locality: string | null;
968
+ region: string | null;
969
+ postCode: string;
970
+ } | undefined;
971
+ ownedProducts?: string[] | undefined;
972
+ subscribedProducts?: string[] | undefined;
973
+ hasProducts?: boolean | null | undefined;
974
+ hasSubscriptions?: boolean | null | undefined;
975
+ }>;
976
+ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
977
+ id: z.ZodString;
978
+ email: z.ZodString;
979
+ name: z.ZodString;
980
+ tenantId: z.ZodString;
981
+ address: z.ZodOptional<z.ZodObject<{
982
+ countryCode: z.ZodString;
983
+ streetAddress1: z.ZodString;
984
+ streetAddress2: z.ZodNullable<z.ZodString>;
985
+ locality: z.ZodNullable<z.ZodString>;
986
+ region: z.ZodNullable<z.ZodString>;
987
+ postCode: z.ZodString;
988
+ }, "strip", z.ZodTypeAny, {
989
+ countryCode: string;
990
+ streetAddress1: string;
991
+ streetAddress2: string | null;
992
+ locality: string | null;
993
+ region: string | null;
994
+ postCode: string;
995
+ }, {
996
+ countryCode: string;
997
+ streetAddress1: string;
998
+ streetAddress2: string | null;
999
+ locality: string | null;
1000
+ region: string | null;
1001
+ postCode: string;
1002
+ }>>;
1003
+ communicationPreferences: z.ZodObject<{
1004
+ newsletterOptIn: z.ZodBoolean;
1005
+ }, "strip", z.ZodTypeAny, {
1006
+ newsletterOptIn: boolean;
1007
+ }, {
1008
+ newsletterOptIn: boolean;
1009
+ }>;
1010
+ ownedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1011
+ subscribedProducts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1012
+ hasProducts: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1013
+ hasSubscriptions: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1014
+ }, "strip", z.ZodTypeAny, {
1015
+ id: string;
1016
+ email: string;
1017
+ name: string;
1018
+ tenantId: string;
1019
+ communicationPreferences: {
1020
+ newsletterOptIn: boolean;
1021
+ };
1022
+ address?: {
1023
+ countryCode: string;
1024
+ streetAddress1: string;
1025
+ streetAddress2: string | null;
1026
+ locality: string | null;
1027
+ region: string | null;
1028
+ postCode: string;
1029
+ } | undefined;
1030
+ ownedProducts?: string[] | undefined;
1031
+ subscribedProducts?: string[] | undefined;
1032
+ hasProducts?: boolean | null | undefined;
1033
+ hasSubscriptions?: boolean | null | undefined;
1034
+ }, {
1035
+ id: string;
1036
+ email: string;
1037
+ name: string;
1038
+ tenantId: string;
1039
+ communicationPreferences: {
1040
+ newsletterOptIn: boolean;
1041
+ };
1042
+ address?: {
1043
+ countryCode: string;
1044
+ streetAddress1: string;
1045
+ streetAddress2: string | null;
1046
+ locality: string | null;
1047
+ region: string | null;
1048
+ postCode: string;
1049
+ } | undefined;
1050
+ ownedProducts?: string[] | undefined;
1051
+ subscribedProducts?: string[] | undefined;
1052
+ hasProducts?: boolean | null | undefined;
1053
+ hasSubscriptions?: boolean | null | undefined;
1054
+ }>, z.ZodObject<{
1055
+ accessToken: z.ZodString;
1056
+ refreshToken: z.ZodString;
1057
+ }, "strip", z.ZodTypeAny, {
1058
+ accessToken: string;
1059
+ refreshToken: string;
1060
+ }, {
1061
+ accessToken: string;
1062
+ refreshToken: string;
1063
+ }>>;
1064
+ declare const userAccountConfirmedSchema: z.ZodObject<{
1065
+ id: z.ZodString;
1066
+ name: z.ZodString;
1067
+ email: z.ZodString;
1068
+ resetPasswordToken: z.ZodNullable<z.ZodString>;
1069
+ }, "strip", z.ZodTypeAny, {
1070
+ id: string;
1071
+ email: string;
1072
+ name: string;
1073
+ resetPasswordToken: string | null;
1074
+ }, {
1075
+ id: string;
1076
+ email: string;
1077
+ name: string;
1078
+ resetPasswordToken: string | null;
1079
+ }>;
1080
+
1081
+ declare const schemas$2_addressSchema: typeof addressSchema;
1082
+ declare const schemas$2_communicationPreferencesSchema: typeof communicationPreferencesSchema;
1083
+ declare const schemas$2_identitySchema: typeof identitySchema;
1084
+ declare const schemas$2_userAccountConfirmedSchema: typeof userAccountConfirmedSchema;
1085
+ declare const schemas$2_userSchema: typeof userSchema;
1086
+ declare namespace schemas$2 {
1087
+ export { schemas$2_addressSchema as addressSchema, schemas$2_communicationPreferencesSchema as communicationPreferencesSchema, schemas$2_identitySchema as identitySchema, schemas$2_userAccountConfirmedSchema as userAccountConfirmedSchema, schemas$2_userSchema as userSchema };
1088
+ }
1089
+
1089
1090
  type CommunicationPreferences = z.infer<typeof communicationPreferencesSchema>;
1090
1091
  type User = z.infer<typeof userSchema>;
1092
+ type Identity = z.infer<typeof identitySchema>;
1091
1093
  type Address = z.infer<typeof addressSchema>;
1092
1094
  type UserAccountConfirmed = z.infer<typeof userAccountConfirmedSchema>;
1093
1095
 
@@ -1098,8 +1100,30 @@ declare class IdentityEndpoints {
1098
1100
  get(): Promise<User>;
1099
1101
  signIn(email: string, password: string): Promise<User>;
1100
1102
  signUp(name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean, communicationOptIn?: boolean): Promise<User>;
1103
+ signOut(): Promise<void>;
1101
1104
  update(name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1102
1105
  needsEmailConfirmationToken: boolean;
1106
+ user: {
1107
+ id: string;
1108
+ email: string;
1109
+ name: string;
1110
+ tenantId: string;
1111
+ communicationPreferences: {
1112
+ newsletterOptIn: boolean;
1113
+ };
1114
+ address?: {
1115
+ countryCode: string;
1116
+ streetAddress1: string;
1117
+ streetAddress2: string | null;
1118
+ locality: string | null;
1119
+ region: string | null;
1120
+ postCode: string;
1121
+ } | undefined;
1122
+ ownedProducts?: string[] | undefined;
1123
+ subscribedProducts?: string[] | undefined;
1124
+ hasProducts?: boolean | null | undefined;
1125
+ hasSubscriptions?: boolean | null | undefined;
1126
+ };
1103
1127
  }>;
1104
1128
  setPassword(currentPassword: string, newPassword: string): Promise<void>;
1105
1129
  forgotPassword(email: string): Promise<void>;
@@ -22677,4 +22701,4 @@ declare class MoonbaseClient {
22677
22701
  orders: OrderEndpoints;
22678
22702
  }
22679
22703
 
22680
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, CycleLength, type Discount, type Download, type DownloadManifest, type IRecurrence, type IStore, type ITokenStore, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, type Money, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
22704
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CompletedOrder, CycleLength, type Discount, type Download, type DownloadManifest, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, type Money, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type Subscription, SubscriptionStatus, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type Vendor, type Voucher, problemDetailsSchema, schemas, utmToObject };
package/dist/index.js CHANGED
@@ -422,8 +422,11 @@ var IdentityEndpoints = class {
422
422
  this.tokenStore.setUser(response.data);
423
423
  return userSchema.parse(response.data);
424
424
  }
425
+ async signOut() {
426
+ this.tokenStore.clear();
427
+ }
425
428
  async update(name, email, emailConfirmationToken, communicationPreferences) {
426
- const response = await this.api.authenticatedFetch("/api/customer/identity", null, {
429
+ const response = await this.api.authenticatedFetch("/api/customer/identity", userSchema, {
427
430
  method: "PATCH",
428
431
  body: {
429
432
  name,
@@ -432,8 +435,10 @@ var IdentityEndpoints = class {
432
435
  communicationPreferences
433
436
  }
434
437
  });
438
+ this.tokenStore.setUser(response.data);
435
439
  return {
436
- needsEmailConfirmationToken: response.status === 201
440
+ needsEmailConfirmationToken: response.status === 201,
441
+ user: response.data
437
442
  };
438
443
  }
439
444
  async setPassword(currentPassword, newPassword) {
@@ -1049,28 +1054,39 @@ var _TokenStore = class _TokenStore {
1049
1054
  return ((_c = this.tokens) == null ? void 0 : _c.accessToken) || null;
1050
1055
  }
1051
1056
  setUser(user) {
1052
- if (user === null) {
1053
- this.tokens = null;
1054
- if (typeof window !== "undefined")
1055
- this.store.remove(_TokenStore.storageKey);
1057
+ const identity = user;
1058
+ if (!identity.accessToken || !identity.refreshToken) {
1059
+ if (!this.tokens) return null;
1060
+ this.tokens = {
1061
+ ...user,
1062
+ accessToken: this.tokens.accessToken,
1063
+ refreshToken: this.tokens.refreshToken,
1064
+ expiresAt: this.tokens.expiresAt
1065
+ };
1066
+ } else {
1067
+ this.tokens = {
1068
+ ...identity,
1069
+ // Hardcoded 15 minutes now, might want to check the JWT tho
1070
+ expiresAt: new Date((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3)
1071
+ };
1072
+ }
1073
+ this.store.set(_TokenStore.storageKey, this.tokens);
1074
+ if (typeof window !== "undefined") {
1056
1075
  if (this.refreshTimeoutId != null)
1057
1076
  window.clearTimeout(this.refreshTimeoutId);
1058
- return null;
1077
+ this.refreshTimeoutId = window.setTimeout(() => {
1078
+ this.refreshPromise = this.refreshTokens();
1079
+ }, 10 * 60 * 1e3);
1059
1080
  }
1060
- this.tokens = {
1061
- ...user,
1062
- // Hardcoded 15 minutes now, might want to check the JWT tho
1063
- expiresAt: new Date((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3)
1064
- };
1065
- if (typeof window !== "undefined")
1066
- this.store.set(_TokenStore.storageKey, this.tokens);
1067
- if (this.refreshTimeoutId != null)
1068
- window.clearTimeout(this.refreshTimeoutId);
1069
- this.refreshTimeoutId = window.setTimeout(() => {
1070
- this.refreshPromise = this.refreshTokens();
1071
- }, 10 * 60 * 1e3);
1072
1081
  return this.tokens;
1073
1082
  }
1083
+ clear() {
1084
+ this.tokens = null;
1085
+ this.store.remove(_TokenStore.storageKey);
1086
+ if (this.refreshTimeoutId != null && typeof window !== "undefined")
1087
+ window.clearTimeout(this.refreshTimeoutId);
1088
+ return null;
1089
+ }
1074
1090
  get isExpired() {
1075
1091
  return this.tokens != null && this.tokens.expiresAt < /* @__PURE__ */ new Date();
1076
1092
  }
@@ -1088,13 +1104,14 @@ var _TokenStore = class _TokenStore {
1088
1104
  });
1089
1105
  if (response.status !== 200) {
1090
1106
  if (response.status === 403 || response.status === 404) {
1091
- this.setUser(null);
1107
+ this.clear();
1092
1108
  return null;
1093
1109
  }
1094
1110
  throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
1095
1111
  }
1096
1112
  const result = identitySchema.parse(await response.json());
1097
- return this.setUser(result);
1113
+ this.setUser(result);
1114
+ return this.tokens;
1098
1115
  }
1099
1116
  handleStorageUpdate(updatedTokens) {
1100
1117
  this.tokens = updatedTokens;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.3.24",
4
+ "version": "0.3.26",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",