@axcode/axcloud-sdk 0.4.0-dev.bf5c2c0 → 0.4.0-dev.c93de93

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 CHANGED
@@ -441,6 +441,32 @@ function Dashboard() {
441
441
  }
442
442
  ```
443
443
 
444
+ ### 8. Membership applications with a section choice
445
+
446
+ ```tsx
447
+ import { createFormHelper } from '@axcode/axcloud-sdk';
448
+
449
+ const forms = createFormHelper({
450
+ apiUrl: 'https://api.axcloud.app/forms',
451
+ apiKey: import.meta.env.VITE_AXCLOUD_FORMS_API_KEY, // forms:submit only
452
+ site: 'example.org',
453
+ });
454
+
455
+ // Sections the organization ticked as selectable, e.g. [{ id: 'section_x', name: 'SAS' }]
456
+ const sections = await forms.getMembershipSections();
457
+
458
+ // Either the chosen section…
459
+ await forms.submitMembership(email, { firstName, lastName, sectionId: sections[0].id });
460
+ // …or a company without a section of its own.
461
+ await forms.submitMembership(email, { firstName, lastName, company: 'Example Air' });
462
+ ```
463
+
464
+ The API refuses a `sectionId` that is not in the list. The approval in the console invites
465
+ the applicant into the chosen section. `getMembershipSections` throws when the API refuses
466
+ (for example when the membership form is not enabled), so a site can fall back to a free-text
467
+ company field. The call is checked with the forms key like a submission but does not count toward
468
+ the key's rate limit, and browsers may keep the answer for five minutes.
469
+
444
470
  ## API Reference
445
471
 
446
472
  ### Provider
@@ -617,7 +643,7 @@ The SDK uses two types of credentials:
617
643
  | Public content | API key (x-api-key header) | `/content/public/{orgId}/news` |
618
644
  | Member content | JWT Bearer token | `/content/members/{orgId}/news` |
619
645
  | User data | JWT Bearer token | `/api/users/me` |
620
- | Admin | JWT Bearer token + role | `/api/admin/forms/submissions` |
646
+ | Admin | JWT Bearer token + role | `/forms/admin/submissions` |
621
647
 
622
648
  ## Error Handling
623
649
 
package/dist/index.d.mts CHANGED
@@ -55,6 +55,29 @@ interface FormSubmissionResponse {
55
55
  /** Unique submission ID */
56
56
  submissionId: string;
57
57
  }
58
+ /**
59
+ * A section an organization offers in its public membership application,
60
+ * typically an airline or other employer with a section of its own
61
+ */
62
+ interface MembershipSection {
63
+ /** Send as `sectionId` in the membership application data */
64
+ id: string;
65
+ /** The name to show the applicant */
66
+ name: string;
67
+ }
68
+ /**
69
+ * Membership application data. Name the applicant's section with `sectionId`
70
+ * (one of {@link getMembershipSections}); for a company without a section of
71
+ * its own, send its name as `company` instead.
72
+ */
73
+ interface MembershipApplicationData {
74
+ firstName?: string;
75
+ lastName?: string;
76
+ phone?: string;
77
+ sectionId?: string;
78
+ company?: string;
79
+ [key: string]: unknown;
80
+ }
58
81
  /**
59
82
  * Form submission stored in database
60
83
  */
@@ -138,6 +161,34 @@ interface FormSubmissionsResponse {
138
161
  * ```
139
162
  */
140
163
  declare function submitForm(apiUrl: string, submission: FormSubmission): Promise<FormSubmissionResponse>;
164
+ /**
165
+ * List the sections an organization offers in its public membership application
166
+ *
167
+ * Uses the same public forms API key and site as a submission, but does not
168
+ * count toward the key's rate limit, so asking on every page view never uses
169
+ * up what submissions need. Only sections the organization has made
170
+ * selectable are returned; the list is empty when there are none.
171
+ * Throws when the API refuses, for example when the membership form is not
172
+ * enabled, so a site can fall back to a free-text company field.
173
+ *
174
+ * @param apiUrl - AxCloud Forms API base URL (e.g., 'https://api.axcloud.app/forms')
175
+ * @param options - The public forms API key and the site domain
176
+ * @returns The sections, sorted by the name the applicant sees
177
+ *
178
+ * @example
179
+ * ```tsx
180
+ * const sections = await getMembershipSections('https://api.axcloud.app/forms', {
181
+ * apiKey: 'your-org-forms-key',
182
+ * site: 'example.org'
183
+ * })
184
+ * // [{ id: 'section_x', name: 'SAS' }, ...]
185
+ * ```
186
+ */
187
+ declare function getMembershipSections(apiUrl: string, options: {
188
+ apiKey: string;
189
+ site: string;
190
+ signal?: AbortSignal;
191
+ }): Promise<MembershipSection[]>;
141
192
  /**
142
193
  * Create a form submission helper with pre-configured API URL, API key, and site
143
194
  *
@@ -178,12 +229,13 @@ declare function createFormHelper(config: {
178
229
  /**
179
230
  * Submit a membership application
180
231
  */
181
- submitMembership: (email: string, data: {
182
- firstName?: string;
183
- lastName?: string;
184
- phone?: string;
185
- [key: string]: unknown;
186
- }) => Promise<FormSubmissionResponse>;
232
+ submitMembership: (email: string, data: MembershipApplicationData) => Promise<FormSubmissionResponse>;
233
+ /**
234
+ * List the sections offered in the membership application
235
+ */
236
+ getMembershipSections: (options?: {
237
+ signal?: AbortSignal;
238
+ }) => Promise<MembershipSection[]>;
187
239
  /**
188
240
  * Generic submit function
189
241
  */
@@ -1408,4 +1460,4 @@ interface LinkedAccountsListProps {
1408
1460
  */
1409
1461
  declare function LinkedAccountsList({ providers, showConnectButtons, className, onUnlink, onLinkInitiated, renderIdentity, renderAvailableProvider, }: LinkedAccountsListProps): React.JSX.Element;
1410
1462
 
1411
- export { type Auth0ClientState, type AuthUser, type AvailableProvider, AxCloudAnalyticsOptions, AxCloudError, type AxCloudErrorCode, AxCloudModule, AxCloudProvider, type Ballot, type BallotCandidate, type BallotOption, type BallotSeat, type CastVoteResult, type CodeEligibility, ContentListResponse, ContentQueryOptions, DocumentFolder, DocumentFolderListResponse, DocumentItem, DocumentListResponse, DocumentQueryOptions, type EmailVerificationResult, type FormStatsResponse, type FormSubmission, type FormSubmissionRecord, type FormSubmissionResponse, type FormSubmissionsResponse, LinkedAccountsList, type LinkedAccountsListProps, type LinkedIdentity, LoginButton, LogoutButton, MediaItem, MediaListResponse, ModuleGate, type MyProfileResponse, NewsItem, Organization, OrganizationBranding, ProtectedRoute, Section, SignedDocumentUrl, SignedMediaUrl, type UpdateMyProfileInput, type UseAuthReturn, type UseLinkedAccountsReturn, User$1 as User, type UserApiResponse, type UserOrganizationMembership, type UserOrganizationSection, UserRole, type VoteReceipt, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getVotingReceipt, isAxCloudError, submitForm, useAuth, useAvatar, useBranding, useCodeBallot, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUpdateMyProfile, useUser };
1463
+ export { type Auth0ClientState, type AuthUser, type AvailableProvider, AxCloudAnalyticsOptions, AxCloudError, type AxCloudErrorCode, AxCloudModule, AxCloudProvider, type Ballot, type BallotCandidate, type BallotOption, type BallotSeat, type CastVoteResult, type CodeEligibility, ContentListResponse, ContentQueryOptions, DocumentFolder, DocumentFolderListResponse, DocumentItem, DocumentListResponse, DocumentQueryOptions, type EmailVerificationResult, type FormStatsResponse, type FormSubmission, type FormSubmissionRecord, type FormSubmissionResponse, type FormSubmissionsResponse, LinkedAccountsList, type LinkedAccountsListProps, type LinkedIdentity, LoginButton, LogoutButton, MediaItem, MediaListResponse, type MembershipApplicationData, type MembershipSection, ModuleGate, type MyProfileResponse, NewsItem, Organization, OrganizationBranding, ProtectedRoute, Section, SignedDocumentUrl, SignedMediaUrl, type UpdateMyProfileInput, type UseAuthReturn, type UseLinkedAccountsReturn, User$1 as User, type UserApiResponse, type UserOrganizationMembership, type UserOrganizationSection, UserRole, type VoteReceipt, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getMembershipSections, getVotingReceipt, isAxCloudError, submitForm, useAuth, useAvatar, useBranding, useCodeBallot, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUpdateMyProfile, useUser };
package/dist/index.d.ts CHANGED
@@ -55,6 +55,29 @@ interface FormSubmissionResponse {
55
55
  /** Unique submission ID */
56
56
  submissionId: string;
57
57
  }
58
+ /**
59
+ * A section an organization offers in its public membership application,
60
+ * typically an airline or other employer with a section of its own
61
+ */
62
+ interface MembershipSection {
63
+ /** Send as `sectionId` in the membership application data */
64
+ id: string;
65
+ /** The name to show the applicant */
66
+ name: string;
67
+ }
68
+ /**
69
+ * Membership application data. Name the applicant's section with `sectionId`
70
+ * (one of {@link getMembershipSections}); for a company without a section of
71
+ * its own, send its name as `company` instead.
72
+ */
73
+ interface MembershipApplicationData {
74
+ firstName?: string;
75
+ lastName?: string;
76
+ phone?: string;
77
+ sectionId?: string;
78
+ company?: string;
79
+ [key: string]: unknown;
80
+ }
58
81
  /**
59
82
  * Form submission stored in database
60
83
  */
@@ -138,6 +161,34 @@ interface FormSubmissionsResponse {
138
161
  * ```
139
162
  */
140
163
  declare function submitForm(apiUrl: string, submission: FormSubmission): Promise<FormSubmissionResponse>;
164
+ /**
165
+ * List the sections an organization offers in its public membership application
166
+ *
167
+ * Uses the same public forms API key and site as a submission, but does not
168
+ * count toward the key's rate limit, so asking on every page view never uses
169
+ * up what submissions need. Only sections the organization has made
170
+ * selectable are returned; the list is empty when there are none.
171
+ * Throws when the API refuses, for example when the membership form is not
172
+ * enabled, so a site can fall back to a free-text company field.
173
+ *
174
+ * @param apiUrl - AxCloud Forms API base URL (e.g., 'https://api.axcloud.app/forms')
175
+ * @param options - The public forms API key and the site domain
176
+ * @returns The sections, sorted by the name the applicant sees
177
+ *
178
+ * @example
179
+ * ```tsx
180
+ * const sections = await getMembershipSections('https://api.axcloud.app/forms', {
181
+ * apiKey: 'your-org-forms-key',
182
+ * site: 'example.org'
183
+ * })
184
+ * // [{ id: 'section_x', name: 'SAS' }, ...]
185
+ * ```
186
+ */
187
+ declare function getMembershipSections(apiUrl: string, options: {
188
+ apiKey: string;
189
+ site: string;
190
+ signal?: AbortSignal;
191
+ }): Promise<MembershipSection[]>;
141
192
  /**
142
193
  * Create a form submission helper with pre-configured API URL, API key, and site
143
194
  *
@@ -178,12 +229,13 @@ declare function createFormHelper(config: {
178
229
  /**
179
230
  * Submit a membership application
180
231
  */
181
- submitMembership: (email: string, data: {
182
- firstName?: string;
183
- lastName?: string;
184
- phone?: string;
185
- [key: string]: unknown;
186
- }) => Promise<FormSubmissionResponse>;
232
+ submitMembership: (email: string, data: MembershipApplicationData) => Promise<FormSubmissionResponse>;
233
+ /**
234
+ * List the sections offered in the membership application
235
+ */
236
+ getMembershipSections: (options?: {
237
+ signal?: AbortSignal;
238
+ }) => Promise<MembershipSection[]>;
187
239
  /**
188
240
  * Generic submit function
189
241
  */
@@ -1408,4 +1460,4 @@ interface LinkedAccountsListProps {
1408
1460
  */
1409
1461
  declare function LinkedAccountsList({ providers, showConnectButtons, className, onUnlink, onLinkInitiated, renderIdentity, renderAvailableProvider, }: LinkedAccountsListProps): React.JSX.Element;
1410
1462
 
1411
- export { type Auth0ClientState, type AuthUser, type AvailableProvider, AxCloudAnalyticsOptions, AxCloudError, type AxCloudErrorCode, AxCloudModule, AxCloudProvider, type Ballot, type BallotCandidate, type BallotOption, type BallotSeat, type CastVoteResult, type CodeEligibility, ContentListResponse, ContentQueryOptions, DocumentFolder, DocumentFolderListResponse, DocumentItem, DocumentListResponse, DocumentQueryOptions, type EmailVerificationResult, type FormStatsResponse, type FormSubmission, type FormSubmissionRecord, type FormSubmissionResponse, type FormSubmissionsResponse, LinkedAccountsList, type LinkedAccountsListProps, type LinkedIdentity, LoginButton, LogoutButton, MediaItem, MediaListResponse, ModuleGate, type MyProfileResponse, NewsItem, Organization, OrganizationBranding, ProtectedRoute, Section, SignedDocumentUrl, SignedMediaUrl, type UpdateMyProfileInput, type UseAuthReturn, type UseLinkedAccountsReturn, User$1 as User, type UserApiResponse, type UserOrganizationMembership, type UserOrganizationSection, UserRole, type VoteReceipt, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getVotingReceipt, isAxCloudError, submitForm, useAuth, useAvatar, useBranding, useCodeBallot, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUpdateMyProfile, useUser };
1463
+ export { type Auth0ClientState, type AuthUser, type AvailableProvider, AxCloudAnalyticsOptions, AxCloudError, type AxCloudErrorCode, AxCloudModule, AxCloudProvider, type Ballot, type BallotCandidate, type BallotOption, type BallotSeat, type CastVoteResult, type CodeEligibility, ContentListResponse, ContentQueryOptions, DocumentFolder, DocumentFolderListResponse, DocumentItem, DocumentListResponse, DocumentQueryOptions, type EmailVerificationResult, type FormStatsResponse, type FormSubmission, type FormSubmissionRecord, type FormSubmissionResponse, type FormSubmissionsResponse, LinkedAccountsList, type LinkedAccountsListProps, type LinkedIdentity, LoginButton, LogoutButton, MediaItem, MediaListResponse, type MembershipApplicationData, type MembershipSection, ModuleGate, type MyProfileResponse, NewsItem, Organization, OrganizationBranding, ProtectedRoute, Section, SignedDocumentUrl, SignedMediaUrl, type UpdateMyProfileInput, type UseAuthReturn, type UseLinkedAccountsReturn, User$1 as User, type UserApiResponse, type UserOrganizationMembership, type UserOrganizationSection, UserRole, type VoteReceipt, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getMembershipSections, getVotingReceipt, isAxCloudError, submitForm, useAuth, useAvatar, useBranding, useCodeBallot, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUpdateMyProfile, useUser };
package/dist/index.js CHANGED
@@ -77,6 +77,26 @@ async function submitForm(apiUrl, submission) {
77
77
  throw primaryError;
78
78
  }
79
79
  }
80
+ async function getMembershipSections(apiUrl, options) {
81
+ const baseUrl = apiUrl.replace(/\/$/, "");
82
+ const response = await fetch(
83
+ `${baseUrl}/public/membership-sections?site=${encodeURIComponent(options.site)}`,
84
+ {
85
+ method: "GET",
86
+ headers: { "X-Api-Key": options.apiKey },
87
+ signal: options.signal
88
+ }
89
+ );
90
+ if (!response.ok) {
91
+ const error = await response.json().catch(() => ({}));
92
+ throw new Error(error.message || `Membership sections request failed (${response.status})`);
93
+ }
94
+ const result = await response.json().catch(() => ({}));
95
+ const sections = Array.isArray(result?.sections) ? result.sections : [];
96
+ return sections.filter(
97
+ (section) => !!section && typeof section.id === "string" && typeof section.name === "string"
98
+ ).map(({ id, name }) => ({ id, name }));
99
+ }
80
100
  function createFormHelper(config) {
81
101
  return {
82
102
  /**
@@ -109,6 +129,14 @@ function createFormHelper(config) {
109
129
  email,
110
130
  data
111
131
  }),
132
+ /**
133
+ * List the sections offered in the membership application
134
+ */
135
+ getMembershipSections: (options = {}) => getMembershipSections(config.apiUrl, {
136
+ apiKey: config.apiKey,
137
+ site: config.site,
138
+ signal: options.signal
139
+ }),
112
140
  /**
113
141
  * Generic submit function
114
142
  */
@@ -859,17 +887,18 @@ function useSections() {
859
887
  refetch: query.refetch
860
888
  };
861
889
  }
890
+ var FORMS_ADMIN_PATH = "/forms/admin";
862
891
  function useForms(options = {}) {
863
- const { client, stage } = chunk7K5N3DQ4_js.useAxCloudContext();
892
+ const { client, orgId } = chunk7K5N3DQ4_js.useAxCloudContext();
864
893
  const { formType, status, limit = 50, cursor } = options;
865
894
  const query = reactQuery.useQuery({
866
- queryKey: ["axcloud", "forms", "submissions", stage, formType, status, limit, cursor],
895
+ queryKey: ["axcloud", "forms", "submissions", orgId, formType, status, limit, cursor],
867
896
  queryFn: async () => {
868
- const params = { limit };
897
+ const params = { org_id: orgId, limit };
869
898
  if (formType) params.form_type = formType;
870
899
  if (status) params.status = status;
871
900
  if (cursor) params.cursor = cursor;
872
- return client.get(`/${stage}/api/admin/forms/submissions`, params);
901
+ return client.get(`${FORMS_ADMIN_PATH}/submissions`, params);
873
902
  },
874
903
  staleTime: 1e3 * 30
875
904
  // 30 seconds
@@ -886,12 +915,12 @@ function useForms(options = {}) {
886
915
  };
887
916
  }
888
917
  function useFormStats(options = {}) {
889
- const { client, stage } = chunk7K5N3DQ4_js.useAxCloudContext();
918
+ const { client, orgId } = chunk7K5N3DQ4_js.useAxCloudContext();
890
919
  const { days = 30 } = options;
891
920
  const query = reactQuery.useQuery({
892
- queryKey: ["axcloud", "forms", "stats", stage, days],
921
+ queryKey: ["axcloud", "forms", "stats", orgId, days],
893
922
  queryFn: async () => {
894
- return client.get(`/${stage}/api/admin/forms/stats`, { days });
923
+ return client.get(`${FORMS_ADMIN_PATH}/stats`, { org_id: orgId, days });
895
924
  },
896
925
  staleTime: 1e3 * 60 * 5
897
926
  // 5 minutes
@@ -907,7 +936,7 @@ function useFormStats(options = {}) {
907
936
  };
908
937
  }
909
938
  function useUpdateFormSubmission() {
910
- const { client, stage } = chunk7K5N3DQ4_js.useAxCloudContext();
939
+ const { client, orgId } = chunk7K5N3DQ4_js.useAxCloudContext();
911
940
  const queryClient = reactQuery.useQueryClient();
912
941
  return reactQuery.useMutation({
913
942
  mutationFn: async ({
@@ -915,7 +944,10 @@ function useUpdateFormSubmission() {
915
944
  status,
916
945
  notes
917
946
  }) => {
918
- return client.patch(`/${stage}/api/admin/forms/submissions/${submissionId}`, { status, notes });
947
+ return client.patch(
948
+ `${FORMS_ADMIN_PATH}/submissions/${encodeURIComponent(submissionId)}?org_id=${encodeURIComponent(orgId)}`,
949
+ { status, notes }
950
+ );
919
951
  },
920
952
  onSuccess: () => {
921
953
  queryClient.invalidateQueries({ queryKey: ["axcloud", "forms"] });
@@ -1645,6 +1677,7 @@ exports.checkEligibility = checkEligibility;
1645
1677
  exports.checkVotingCode = checkVotingCode;
1646
1678
  exports.createFormHelper = createFormHelper;
1647
1679
  exports.getBallot = getBallot;
1680
+ exports.getMembershipSections = getMembershipSections;
1648
1681
  exports.getVotingReceipt = getVotingReceipt;
1649
1682
  exports.submitForm = submitForm;
1650
1683
  exports.useAuth = useAuth;