@axcode/axcloud-sdk 0.4.0-dev.f5f8764 → 0.4.0-dev.f9603ab

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
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
  */
@@ -1649,6 +1677,7 @@ exports.checkEligibility = checkEligibility;
1649
1677
  exports.checkVotingCode = checkVotingCode;
1650
1678
  exports.createFormHelper = createFormHelper;
1651
1679
  exports.getBallot = getBallot;
1680
+ exports.getMembershipSections = getMembershipSections;
1652
1681
  exports.getVotingReceipt = getVotingReceipt;
1653
1682
  exports.submitForm = submitForm;
1654
1683
  exports.useAuth = useAuth;