UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 7.97 kB
{"version":3,"file":"types.js","names":[],"sources":["esm/platform/notifications/types.js"],"sourcesContent":["function fromNativeAuthorizationStatus(status) {\n if (typeof status === \"string\") return status;\n switch (status) {\n case 0:\n return \"notDetermined\";\n case 1:\n return \"denied\";\n case 2:\n return \"authorized\";\n case 3:\n return \"provisional\";\n case 4:\n return \"ephemeral\";\n default:\n return \"notDetermined\";\n }\n}\nconst importanceToInt = {\n none: 0,\n min: 1,\n low: 2,\n default: 3,\n high: 4,\n max: 5\n};\nfunction toNativeImportance(value) {\n if (typeof value === \"number\") {\n if (!Number.isInteger(value) || value < 0 || value > 5) {\n throw new Error(\n \"Notifications.setChannel: importance must be one of none, min, low, default, high, max\"\n );\n }\n return value;\n }\n const mapped = importanceToInt[value];\n if (mapped === void 0) {\n throw new Error(\n \"Notifications.setChannel: importance must be one of none, min, low, default, high, max\"\n );\n }\n return mapped;\n}\nfunction fromNativeImportance(value) {\n switch (value) {\n case 0:\n return \"none\";\n case 1:\n return \"min\";\n case 2:\n return \"low\";\n case 3:\n return \"default\";\n case 4:\n return \"high\";\n case 5:\n return \"max\";\n default:\n return \"default\";\n }\n}\nconst DEFAULT_ACTION_IDENTIFIER = \"expo.modules.notifications.actions.DEFAULT\";\nfunction assertCategoryIdentifier(identifier, verb) {\n if (typeof identifier !== \"string\" || identifier.length === 0) {\n throw new Error(`Notifications.${verb}: identifier must be a non-empty string`);\n }\n if (identifier.includes(\":\") || identifier.includes(\"-\")) {\n throw new Error(\n `Notifications.${verb}: identifier must not contain ':' or '-'`\n );\n }\n}\nfunction assertBooleans(verb, what, value, fields) {\n if (value === void 0) return;\n for (const field of fields) {\n const entry = value[field];\n if (entry !== void 0 && typeof entry !== \"boolean\") {\n throw new Error(`Notifications.${verb}: ${what}.${field} must be a boolean`);\n }\n }\n}\nfunction assertCategoryActions(actions, verb) {\n if (!Array.isArray(actions)) {\n throw new Error(`Notifications.${verb}: actions must be an array`);\n }\n for (const action of actions) {\n if (!action || typeof action !== \"object\") {\n throw new Error(`Notifications.${verb}: each action must be an object`);\n }\n const { identifier, buttonTitle, options, textInput } = action;\n if (typeof identifier !== \"string\" || identifier.length === 0) {\n throw new Error(`Notifications.${verb}: each action needs a non-empty identifier`);\n }\n if (typeof buttonTitle !== \"string\" || buttonTitle.length === 0) {\n throw new Error(`Notifications.${verb}: each action needs a non-empty buttonTitle`);\n }\n if (options !== void 0 && (typeof options !== \"object\" || options === null)) {\n throw new Error(`Notifications.${verb}: action options must be an object`);\n }\n assertBooleans(verb, \"action options\", options, [\n \"isAuthenticationRequired\",\n \"isDestructive\",\n \"opensAppToForeground\"\n ]);\n if (textInput !== void 0) {\n if (typeof textInput !== \"object\" || textInput === null) {\n throw new Error(`Notifications.${verb}: action textInput must be an object`);\n }\n const { placeholder, submitButtonTitle } = textInput;\n if (typeof placeholder !== \"string\" || placeholder.length === 0) {\n throw new Error(`Notifications.${verb}: action textInput needs a non-empty placeholder`);\n }\n if (submitButtonTitle !== void 0 && typeof submitButtonTitle !== \"string\") {\n throw new Error(`Notifications.${verb}: action textInput.submitButtonTitle must be a string`);\n }\n }\n }\n}\nfunction assertCategoryOptions(options, verb) {\n if (options === void 0) return;\n if (!options || typeof options !== \"object\") {\n throw new Error(`Notifications.${verb}: options must be an object`);\n }\n assertBooleans(verb, \"options\", options, [\n \"allowInCarPlay\",\n \"allowAnnouncement\",\n \"customDismissAction\",\n \"showTitle\",\n \"showSubtitle\"\n ]);\n if (options.categorySummaryFormat !== void 0 && typeof options.categorySummaryFormat !== \"string\") {\n throw new Error(`Notifications.${verb}: options.categorySummaryFormat must be a string`);\n }\n if (options.previewPlaceholder !== void 0 && typeof options.previewPlaceholder !== \"string\") {\n throw new Error(`Notifications.${verb}: options.previewPlaceholder must be a string`);\n }\n if (options.intentIdentifiers !== void 0) {\n if (!Array.isArray(options.intentIdentifiers) || options.intentIdentifiers.some((entry) => typeof entry !== \"string\")) {\n throw new Error(`Notifications.${verb}: options.intentIdentifiers must be string[]`);\n }\n }\n}\nexport {\n DEFAULT_ACTION_IDENTIFIER,\n assertCategoryActions,\n assertCategoryIdentifier,\n assertCategoryOptions,\n fromNativeAuthorizationStatus,\n fromNativeImportance,\n toNativeImportance\n};\n//# sourceMappingURL=types.js.map\n"],"mappings":";AAAA,SAAS,8BAA8B,QAAQ;CAC7C,IAAI,OAAO,WAAW,UAAU,OAAO;CACvC,QAAQ,QAAR;EACE,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AACA,MAAM,kBAAkB;CACtB,MAAM;CACN,KAAK;CACL,KAAK;CACL,SAAS;CACT,MAAM;CACN,KAAK;AACP;AACA,SAAS,mBAAmB,OAAO;CACjC,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG;GACtD,MAAM,IAAI,MACR,wFACF;EACF;EACA,OAAO;CACT;CACA,MAAM,SAAS,gBAAgB;CAC/B,IAAI,WAAW,KAAK,GAAG;EACrB,MAAM,IAAI,MACR,wFACF;CACF;CACA,OAAO;AACT;AACA,SAAS,qBAAqB,OAAO;CACnC,QAAQ,OAAR;EACE,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,KAAK,GACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AACA,MAAM,4BAA4B;AAClC,SAAS,yBAAyB,YAAY,MAAM;CAClD,IAAI,OAAO,eAAe,YAAY,WAAW,WAAW,GAAG;EAC7D,MAAM,IAAI,MAAM,iBAAiB,KAAK,wCAAwC;CAChF;CACA,IAAI,WAAW,SAAS,GAAG,KAAK,WAAW,SAAS,GAAG,GAAG;EACxD,MAAM,IAAI,MACR,iBAAi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