@sendoracloud/sdk-react-native 0.18.3 → 0.18.4

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
@@ -2020,6 +2020,57 @@ var SendoraSDK = class {
2020
2020
  }
2021
2021
  };
2022
2022
  }
2023
+ /**
2024
+ * Surveys namespace — fetch + submit NPS / CSAT / custom surveys
2025
+ * from inside the app. Mirrors backend `/surveys/:id/config` +
2026
+ * `/surveys/responses` SDK routes + the web SDK's
2027
+ * `sendora.surveys.showSurvey()` + `submitResponse()` shape.
2028
+ *
2029
+ * Typical use:
2030
+ * const survey = await SendoraCloud.surveys.fetchConfig("survey_nps_2026");
2031
+ * if (survey) {
2032
+ * // render survey.questions[] in your UI
2033
+ * await SendoraCloud.surveys.submitResponse({
2034
+ * surveyId: survey.id,
2035
+ * answers: { q1: 9, q2: "Loving it" },
2036
+ * completed: true,
2037
+ * });
2038
+ * }
2039
+ *
2040
+ * fetchConfig returns null when the survey is inactive / not found
2041
+ * (backend returns 404; SDK normalizes to null so callers can `if (!survey) return`).
2042
+ */
2043
+ get surveys() {
2044
+ const self = this;
2045
+ return {
2046
+ fetchConfig: async (surveyId) => {
2047
+ if (!self.config) throw new Error("[sendoracloud] init() must complete before surveys.fetchConfig().");
2048
+ if (typeof surveyId !== "string" || surveyId.length === 0) return null;
2049
+ const url = `${self.config.apiUrl}/api/v1/surveys/${encodeURIComponent(surveyId)}/config`;
2050
+ const res = await fetch(url, {
2051
+ method: "GET",
2052
+ headers: { "x-api-key": self.config.publicKey }
2053
+ });
2054
+ if (res.status === 404) return null;
2055
+ if (!res.ok) throw new Error(`[sendoracloud] surveys.fetchConfig failed (${res.status})`);
2056
+ const parsed = await res.json();
2057
+ if (!parsed.success || !parsed.data) return null;
2058
+ return parsed.data;
2059
+ },
2060
+ submitResponse: async (input) => {
2061
+ if (!self.config) throw new Error("[sendoracloud] init() must complete before surveys.submitResponse().");
2062
+ const res = await post(
2063
+ { apiUrl: self.config.apiUrl, publicKey: self.config.publicKey, debug: self.debug },
2064
+ "/surveys/responses",
2065
+ { completed: true, ...input }
2066
+ );
2067
+ if (!res || !res.ok) throw new Error(`[sendoracloud] surveys.submitResponse failed (${res?.status ?? "network"})`);
2068
+ const parsed = await res.json();
2069
+ if (!parsed.success || !parsed.data) throw new Error("[sendoracloud] surveys.submitResponse: bad response");
2070
+ return parsed.data;
2071
+ }
2072
+ };
2073
+ }
2023
2074
  /**
2024
2075
  * Clear identity + rotate the anonymous id. Call on logout. Awaits
2025
2076
  * the AsyncStorage writes so a caller who kills the app immediately
package/dist/index.d.cts CHANGED
@@ -934,6 +934,55 @@ declare class SendoraSDK {
934
934
  createdAt: string;
935
935
  }>;
936
936
  };
937
+ /**
938
+ * Surveys namespace — fetch + submit NPS / CSAT / custom surveys
939
+ * from inside the app. Mirrors backend `/surveys/:id/config` +
940
+ * `/surveys/responses` SDK routes + the web SDK's
941
+ * `sendora.surveys.showSurvey()` + `submitResponse()` shape.
942
+ *
943
+ * Typical use:
944
+ * const survey = await SendoraCloud.surveys.fetchConfig("survey_nps_2026");
945
+ * if (survey) {
946
+ * // render survey.questions[] in your UI
947
+ * await SendoraCloud.surveys.submitResponse({
948
+ * surveyId: survey.id,
949
+ * answers: { q1: 9, q2: "Loving it" },
950
+ * completed: true,
951
+ * });
952
+ * }
953
+ *
954
+ * fetchConfig returns null when the survey is inactive / not found
955
+ * (backend returns 404; SDK normalizes to null so callers can `if (!survey) return`).
956
+ */
957
+ get surveys(): {
958
+ fetchConfig: (surveyId: string) => Promise<{
959
+ id: string;
960
+ name: string;
961
+ questions: Array<{
962
+ id: string;
963
+ type: string;
964
+ label: string;
965
+ required?: boolean;
966
+ options?: string[];
967
+ scale?: {
968
+ min: number;
969
+ max: number;
970
+ };
971
+ }>;
972
+ [key: string]: unknown;
973
+ } | null>;
974
+ submitResponse: (input: {
975
+ surveyId: string;
976
+ answers: Record<string, unknown>;
977
+ completed?: boolean;
978
+ entityId?: string;
979
+ userId?: string;
980
+ metadata?: Record<string, unknown>;
981
+ }) => Promise<{
982
+ id: string;
983
+ submittedAt: string;
984
+ }>;
985
+ };
937
986
  /**
938
987
  * Clear identity + rotate the anonymous id. Call on logout. Awaits
939
988
  * the AsyncStorage writes so a caller who kills the app immediately
package/dist/index.d.ts CHANGED
@@ -934,6 +934,55 @@ declare class SendoraSDK {
934
934
  createdAt: string;
935
935
  }>;
936
936
  };
937
+ /**
938
+ * Surveys namespace — fetch + submit NPS / CSAT / custom surveys
939
+ * from inside the app. Mirrors backend `/surveys/:id/config` +
940
+ * `/surveys/responses` SDK routes + the web SDK's
941
+ * `sendora.surveys.showSurvey()` + `submitResponse()` shape.
942
+ *
943
+ * Typical use:
944
+ * const survey = await SendoraCloud.surveys.fetchConfig("survey_nps_2026");
945
+ * if (survey) {
946
+ * // render survey.questions[] in your UI
947
+ * await SendoraCloud.surveys.submitResponse({
948
+ * surveyId: survey.id,
949
+ * answers: { q1: 9, q2: "Loving it" },
950
+ * completed: true,
951
+ * });
952
+ * }
953
+ *
954
+ * fetchConfig returns null when the survey is inactive / not found
955
+ * (backend returns 404; SDK normalizes to null so callers can `if (!survey) return`).
956
+ */
957
+ get surveys(): {
958
+ fetchConfig: (surveyId: string) => Promise<{
959
+ id: string;
960
+ name: string;
961
+ questions: Array<{
962
+ id: string;
963
+ type: string;
964
+ label: string;
965
+ required?: boolean;
966
+ options?: string[];
967
+ scale?: {
968
+ min: number;
969
+ max: number;
970
+ };
971
+ }>;
972
+ [key: string]: unknown;
973
+ } | null>;
974
+ submitResponse: (input: {
975
+ surveyId: string;
976
+ answers: Record<string, unknown>;
977
+ completed?: boolean;
978
+ entityId?: string;
979
+ userId?: string;
980
+ metadata?: Record<string, unknown>;
981
+ }) => Promise<{
982
+ id: string;
983
+ submittedAt: string;
984
+ }>;
985
+ };
937
986
  /**
938
987
  * Clear identity + rotate the anonymous id. Call on logout. Awaits
939
988
  * the AsyncStorage writes so a caller who kills the app immediately
package/dist/index.js CHANGED
@@ -1982,6 +1982,57 @@ var SendoraSDK = class {
1982
1982
  }
1983
1983
  };
1984
1984
  }
1985
+ /**
1986
+ * Surveys namespace — fetch + submit NPS / CSAT / custom surveys
1987
+ * from inside the app. Mirrors backend `/surveys/:id/config` +
1988
+ * `/surveys/responses` SDK routes + the web SDK's
1989
+ * `sendora.surveys.showSurvey()` + `submitResponse()` shape.
1990
+ *
1991
+ * Typical use:
1992
+ * const survey = await SendoraCloud.surveys.fetchConfig("survey_nps_2026");
1993
+ * if (survey) {
1994
+ * // render survey.questions[] in your UI
1995
+ * await SendoraCloud.surveys.submitResponse({
1996
+ * surveyId: survey.id,
1997
+ * answers: { q1: 9, q2: "Loving it" },
1998
+ * completed: true,
1999
+ * });
2000
+ * }
2001
+ *
2002
+ * fetchConfig returns null when the survey is inactive / not found
2003
+ * (backend returns 404; SDK normalizes to null so callers can `if (!survey) return`).
2004
+ */
2005
+ get surveys() {
2006
+ const self = this;
2007
+ return {
2008
+ fetchConfig: async (surveyId) => {
2009
+ if (!self.config) throw new Error("[sendoracloud] init() must complete before surveys.fetchConfig().");
2010
+ if (typeof surveyId !== "string" || surveyId.length === 0) return null;
2011
+ const url = `${self.config.apiUrl}/api/v1/surveys/${encodeURIComponent(surveyId)}/config`;
2012
+ const res = await fetch(url, {
2013
+ method: "GET",
2014
+ headers: { "x-api-key": self.config.publicKey }
2015
+ });
2016
+ if (res.status === 404) return null;
2017
+ if (!res.ok) throw new Error(`[sendoracloud] surveys.fetchConfig failed (${res.status})`);
2018
+ const parsed = await res.json();
2019
+ if (!parsed.success || !parsed.data) return null;
2020
+ return parsed.data;
2021
+ },
2022
+ submitResponse: async (input) => {
2023
+ if (!self.config) throw new Error("[sendoracloud] init() must complete before surveys.submitResponse().");
2024
+ const res = await post(
2025
+ { apiUrl: self.config.apiUrl, publicKey: self.config.publicKey, debug: self.debug },
2026
+ "/surveys/responses",
2027
+ { completed: true, ...input }
2028
+ );
2029
+ if (!res || !res.ok) throw new Error(`[sendoracloud] surveys.submitResponse failed (${res?.status ?? "network"})`);
2030
+ const parsed = await res.json();
2031
+ if (!parsed.success || !parsed.data) throw new Error("[sendoracloud] surveys.submitResponse: bad response");
2032
+ return parsed.data;
2033
+ }
2034
+ };
2035
+ }
1985
2036
  /**
1986
2037
  * Clear identity + rotate the anonymous id. Call on logout. Awaits
1987
2038
  * the AsyncStorage writes so a caller who kills the app immediately
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendoracloud/sdk-react-native",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "description": "Sendora Cloud React Native + Expo SDK — analytics, identity, push-token registration, auth, deep links (Branch / Firebase Dynamic Links parity). Auth + analytics + deep links work in Expo Go; push token registration requires a Dev Client (EAS Build or `npx expo prebuild`).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",