unihub-community-sdk 0.1.4 → 0.1.5
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/CHANGELOG.md +20 -0
- package/README.md +39 -12
- package/dist/index.d.mts +21 -7
- package/dist/index.d.ts +21 -7
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/starter/index.html +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ All notable changes to `unihub-community-sdk` are recorded here. The format foll
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/). While the version is `0.x`, a minor release
|
|
6
6
|
(`0.2.0`) may contain breaking changes; each one is listed here.
|
|
7
7
|
|
|
8
|
+
## [0.1.5] — 2026-11-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Private events for members: while a visitor is signed in, `events.list` and `events.get` send
|
|
13
|
+
the session, so an approved member of a hosting club also gets the club's private events.
|
|
14
|
+
Signed-out reads are unchanged. Needs the UniHub backend of 2026-11-21 or later.
|
|
15
|
+
- `EventSummary.visibility` (and so `EventDetail.visibility`): `'PUBLIC' | 'PRIVATE'`, with the
|
|
16
|
+
new `EventVisibility` type. `'PUBLIC'` when the server does not send it.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Reads made with a session bypass the HTTP cache (`cache: 'no-store'`).
|
|
21
|
+
- An expired or refused session no longer matters to a read: the server answers it as signed
|
|
22
|
+
out (public events only), and the SDK keeps the session.
|
|
23
|
+
- The lists also include events the club co-hosts (a backend change; no SDK change).
|
|
24
|
+
- README: "Üyelere özel etkinlikler" (re-list from `auth.onChange` — the SDK does not refresh a
|
|
25
|
+
list by itself) and a link to the developer terms, https://www.unihub.tr/gelistiriciler/kosullar.
|
|
26
|
+
- Starter template: an "Üyelere özel" badge on private events.
|
|
27
|
+
|
|
8
28
|
## [0.1.4] — 2026-11-08
|
|
9
29
|
|
|
10
30
|
No API change.
|
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
> **English summary.** `unihub-community-sdk` connects a university club's own website to
|
|
7
|
-
> UniHub: list the club's
|
|
7
|
+
> UniHub: list the club's events (private ones only to signed-in members), let visitors sign in with UniHub (on UniHub's page,
|
|
8
8
|
> popup or redirect), and join, leave, apply to and get tickets for events. It runs in the
|
|
9
9
|
> browser, has no runtime dependencies, and ships ESM, CommonJS and a `<script>` build.
|
|
10
10
|
> The guide below is in Turkish; the code samples read the same in any language.
|
|
11
11
|
|
|
12
12
|
## 📌 Nedir Bu Paket?
|
|
13
|
-
Bu kütüphane, üniversite topluluklarının (Google Developer Groups, IEEE vb.) kendi geliştirdikleri bağımsız web sitelerini **UniHub**'a bağlar: kulübün
|
|
13
|
+
Bu kütüphane, üniversite topluluklarının (Google Developer Groups, IEEE vb.) kendi geliştirdikleri bağımsız web sitelerini **UniHub**'a bağlar: kulübün etkinliklerini listeler (üyelere özel olanları yalnızca giriş yapmış üyelere), ziyaretçinin "UniHub ile giriş" yapmasını sağlar ve etkinliğe katılım, ayrılma, başvuru formu ve bilet işlemlerini yapar.
|
|
14
14
|
|
|
15
15
|
## 📖 Geliştirici Kılavuzu
|
|
16
16
|
Bu README, SDK'nın kılavuzudur. Güncel sürümü her zaman npm sayfasındadır:
|
|
@@ -32,8 +32,8 @@ Derleme adımı olmayan sayfalar için (`<script>` etiketi, `window.UniHub`):
|
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
34
|
<script
|
|
35
|
-
src="https://cdn.jsdelivr.net/npm/unihub-community-sdk@0.1.
|
|
36
|
-
integrity="sha384-
|
|
35
|
+
src="https://cdn.jsdelivr.net/npm/unihub-community-sdk@0.1.5/dist/index.global.js"
|
|
36
|
+
integrity="sha384-XAazEzzGjjYp4VJnuvoJlcvHsg59RbOO270Se3umlce7JEf9+kUCt/GAydeYkB4R"
|
|
37
37
|
crossorigin="anonymous"></script>
|
|
38
38
|
<script>
|
|
39
39
|
const unihub = UniHub.createUniHub({ key: "uhpk_live_sizin_topluluk_anahtariniz" });
|
|
@@ -41,7 +41,7 @@ Derleme adımı olmayan sayfalar için (`<script>` etiketi, `window.UniHub`):
|
|
|
41
41
|
</script>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
- Adresteki sürümü (`@0.1.
|
|
44
|
+
- Adresteki sürümü (`@0.1.5`) **sabit** tutun; `@latest` ya da `@0` kullanmayın. `integrity`
|
|
45
45
|
değeri yalnızca o sürümün dosyasına uyar: dosya değişirse tarayıcı betiği çalıştırmaz.
|
|
46
46
|
- Sürüm yükseltirken adresi ve `integrity` değerini birlikte, bu README'nin o sürümdeki
|
|
47
47
|
hâlinden alın.
|
|
@@ -55,7 +55,7 @@ Kod yazmadan başlamak için: **tek bir `index.html`**, derleme adımı ve sunuc
|
|
|
55
55
|
etkinliklerini listeler, ayrıntılarını gösterir, "UniHub ile giriş" yaptırır; ziyaretçi katılır,
|
|
56
56
|
başvuru formunu doldurur ve biletini (QR) görür. Arayüz Türkçedir.
|
|
57
57
|
|
|
58
|
-
👉 **[Şablonu indirin](https://cdn.jsdelivr.net/npm/unihub-community-sdk@0.1.
|
|
58
|
+
👉 **[Şablonu indirin](https://cdn.jsdelivr.net/npm/unihub-community-sdk@0.1.5/starter/index.html)**
|
|
59
59
|
(sayfayı "Farklı kaydet" ile `index.html` olarak kaydedin; pakette `starter/index.html`).
|
|
60
60
|
|
|
61
61
|
1. **Ayarlayın.** Dosyanın başındaki `CONFIG.key` alanına yayınlanabilir anahtarınızı
|
|
@@ -95,10 +95,11 @@ const unihub = createUniHub({
|
|
|
95
95
|
locale: "tr" // hata mesajlarının dili: "tr" (varsayılan) veya "en"
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
// 2. Kulübünüzün
|
|
98
|
+
// 2. Kulübünüzün etkinliklerini listeleyin (sayfa 0'dan başlar, en fazla 50)
|
|
99
99
|
const page = await unihub.events.list({ when: "upcoming", page: 0, size: 20 });
|
|
100
100
|
for (const e of page.items) {
|
|
101
101
|
console.log(e.title, e.startsAt, e.location); // startsAt: "2026-11-01T19:00:00+03:00" veya null
|
|
102
|
+
// e.visibility: "PUBLIC" ya da "PRIVATE" (yalnızca giriş yapmış üyeye gelir, aşağıya bakın)
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
// 3. Tek bir etkinliğin ayrıntıları
|
|
@@ -107,10 +108,35 @@ const detail = await unihub.events.get(page.items[0].id);
|
|
|
107
108
|
// detail.requiresForm, detail.verifiedOnly, detail.approvalRequired
|
|
108
109
|
```
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
Liste, kulübünüzün **ortak düzenlediği** (co-host olarak kabul ettiği) etkinlikleri de içerir.
|
|
112
|
+
SDK, bir sayfadaki istekleri sırayla ve aralarında en az 210 ms bırakarak gönderir: sunucu aynı
|
|
113
|
+
anahtar ve ziyaretçiden 200 ms içinde gelen ikinci isteği reddediyor. Aynı anda birkaç çağrı
|
|
114
|
+
yapmak (`Promise.all`) güvenlidir.
|
|
115
|
+
|
|
116
|
+
### Üyelere özel etkinlikler
|
|
117
|
+
|
|
118
|
+
Özel (private) bir etkinlik — etkinliğin kendisi, düzenleyen kulüp ya da sitenizin kulübü özelse —
|
|
119
|
+
yalnızca **UniHub ile giriş yapmış ve düzenleyen kulüplerden birinin onaylı üyesi olan**
|
|
120
|
+
ziyaretçiye gelir; `visibility: "PRIVATE"` taşır. Diğer herkes için listede yoktur, `get` de
|
|
121
|
+
`EVENT_NOT_FOUND` döner. Bunun için ayrı bir ayar yoktur: oturum açıkken `events.list` ve
|
|
122
|
+
`events.get` oturumu kendiliğinden gönderir, neyin görüneceğine sunucu karar verir.
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
async function reload() {
|
|
126
|
+
const page = await unihub.events.list();
|
|
127
|
+
render(page.items.map((e) => ({ ...e, badge: e.visibility === "PRIVATE" ? "Üyelere özel" : null })));
|
|
128
|
+
}
|
|
129
|
+
unihub.auth.onChange(() => reload()); // giriş ve çıkışta listeyi yeniden çekin
|
|
130
|
+
await reload();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **Liste kendiliğinden yenilenmez.** Giriş, çıkış ya da oturumun bitmesinden sonra yukarıdaki
|
|
134
|
+
gibi `auth.onChange` içinde yeniden listeleyin; yoksa çıkış yapan ziyaretçi özel etkinlikleri
|
|
135
|
+
görmeye devam eder.
|
|
136
|
+
- **Süresi dolmuş ya da sunucunun kabul etmediği oturum** okumayı bozmaz: istek girişsiz
|
|
137
|
+
sayılır ve yalnızca herkese açık etkinlikler gelir.
|
|
138
|
+
- Oturumla yapılan okumalar tarayıcı önbelleğine yazılmaz (`cache: "no-store"`). Özel bir
|
|
139
|
+
etkinliği kendi sunucunuzda ya da sayfanızda önbelleğe almayın, başka bir yere kopyalamayın.
|
|
114
140
|
|
|
115
141
|
## 🗝️ Anahtar ve izinli adresler (origin)
|
|
116
142
|
|
|
@@ -233,7 +259,8 @@ onu kullanır: `qrcode(0, "M")`, `addData(qrPayload)`, `make()`, `createDataURL(
|
|
|
233
259
|
|
|
234
260
|
- **Anahtar verilmeden önce** kulübünüzün sahibi (OWNER) ya da yöneticisi (MANAGER),
|
|
235
261
|
UniHub'ın sürümlü **geliştirici koşullarını** kabul eder ve sitenizin **gizlilik
|
|
236
|
-
politikası adresini** verir. Koşulların metni
|
|
262
|
+
politikası adresini** verir. Koşulların metni:
|
|
263
|
+
[unihub.tr/gelistiriciler/kosullar](https://www.unihub.tr/gelistiriciler/kosullar); koşullar
|
|
237
264
|
güncellendiğinde yeni sürümün yeniden kabul edilmesi gerekebilir. Ayrıntılar
|
|
238
265
|
[geliştirici sayfasındadır](https://www.unihub.tr/gelistiriciler).
|
|
239
266
|
- **Siteniz UniHub'da barındırılıyorsa** sitenizdeki ziyaretçi verilerinin **veri sorumlusu
|
package/dist/index.d.mts
CHANGED
|
@@ -175,8 +175,14 @@ interface ApplyResult {
|
|
|
175
175
|
}
|
|
176
176
|
type EventStatus = 'UPCOMING' | 'PAST';
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
178
|
+
* `PRIVATE`: the event, its host club or this site's club is private. Only a signed-in
|
|
179
|
+
* approved member of a hosting club gets such an event; everyone else never sees it.
|
|
180
|
+
*/
|
|
181
|
+
type EventVisibility = 'PUBLIC' | 'PRIVATE';
|
|
182
|
+
/**
|
|
183
|
+
* One event of the key's club the visitor may see, as listed (also an event the club
|
|
184
|
+
* co-hosts). Times are ISO-8601 strings with the Europe/Istanbul offset
|
|
185
|
+
* (e.g. `2026-11-01T19:00:00+03:00`), passed through unparsed.
|
|
180
186
|
*/
|
|
181
187
|
interface EventSummary {
|
|
182
188
|
id: number;
|
|
@@ -188,6 +194,8 @@ interface EventSummary {
|
|
|
188
194
|
status: EventStatus;
|
|
189
195
|
/** Last moment to join; the event's own time when no separate deadline was set. */
|
|
190
196
|
registrationDeadline: string | null;
|
|
197
|
+
/** `PUBLIC` when the server does not say (an older backend serves public events only). */
|
|
198
|
+
visibility: EventVisibility;
|
|
191
199
|
}
|
|
192
200
|
interface EventDetail extends EventSummary {
|
|
193
201
|
description: string;
|
|
@@ -218,10 +226,15 @@ interface ListEventsOptions {
|
|
|
218
226
|
/** Items per page, 1–50. Default 20. */
|
|
219
227
|
size?: number;
|
|
220
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Reads send the visitor's session when one is live, so an approved member also gets the
|
|
231
|
+
* club's private events. The list does not refresh itself on sign-in or sign-out: re-list
|
|
232
|
+
* from `auth.onChange`. An expired or refused session reads as signed out (public only).
|
|
233
|
+
*/
|
|
221
234
|
interface EventsApi {
|
|
222
|
-
/**
|
|
235
|
+
/** Events of the key's club the visitor may see. */
|
|
223
236
|
list(options?: ListEventsOptions): Promise<Page<EventSummary>>;
|
|
224
|
-
/** One
|
|
237
|
+
/** One event of the key's club the visitor may see; anything else rejects `EVENT_NOT_FOUND`. */
|
|
225
238
|
get(id: number): Promise<EventDetail>;
|
|
226
239
|
}
|
|
227
240
|
interface UniHub {
|
|
@@ -233,11 +246,12 @@ interface UniHub {
|
|
|
233
246
|
declare const DEFAULT_BASE_URL = "https://api.unihub.tr/api/v1/community";
|
|
234
247
|
/**
|
|
235
248
|
* Entry point for a community website: `createUniHub({ key: 'uhpk_live_…' })`.
|
|
236
|
-
*
|
|
249
|
+
* The key names the club. Reads show its public events, and also its private ones while an
|
|
250
|
+
* approved member is signed in.
|
|
237
251
|
*/
|
|
238
252
|
declare function createUniHub(config: UniHubConfig): UniHub;
|
|
239
253
|
|
|
240
254
|
/** This package's version, sent as `X-SDK-Version`. Kept equal to package.json by a test. */
|
|
241
|
-
declare const SDK_VERSION = "0.1.
|
|
255
|
+
declare const SDK_VERSION = "0.1.5";
|
|
242
256
|
|
|
243
|
-
export { type ApplyResult, type AttendanceApi, type AttendanceStatus, type AttendanceStatusResult, type AuthApi, DEFAULT_BASE_URL, ERROR_CODES, type EventDetail, type EventForm, type EventStatus, type EventSummary, type EventsApi, type FormAnswer, type FormQuestion, type FormQuestionType, type JoinResult, type JoinStatus, type ListEventsOptions, type Locale, type Page, SDK_VERSION, type SessionPersistence, type SignInOptions, type Ticket, type UniHub, UniHubApiError, type UniHubConfig, UniHubError, type UniHubErrorCode, type UniHubErrorDetails, type Visitor, createUniHub };
|
|
257
|
+
export { type ApplyResult, type AttendanceApi, type AttendanceStatus, type AttendanceStatusResult, type AuthApi, DEFAULT_BASE_URL, ERROR_CODES, type EventDetail, type EventForm, type EventStatus, type EventSummary, type EventVisibility, type EventsApi, type FormAnswer, type FormQuestion, type FormQuestionType, type JoinResult, type JoinStatus, type ListEventsOptions, type Locale, type Page, SDK_VERSION, type SessionPersistence, type SignInOptions, type Ticket, type UniHub, UniHubApiError, type UniHubConfig, UniHubError, type UniHubErrorCode, type UniHubErrorDetails, type Visitor, createUniHub };
|
package/dist/index.d.ts
CHANGED
|
@@ -175,8 +175,14 @@ interface ApplyResult {
|
|
|
175
175
|
}
|
|
176
176
|
type EventStatus = 'UPCOMING' | 'PAST';
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
178
|
+
* `PRIVATE`: the event, its host club or this site's club is private. Only a signed-in
|
|
179
|
+
* approved member of a hosting club gets such an event; everyone else never sees it.
|
|
180
|
+
*/
|
|
181
|
+
type EventVisibility = 'PUBLIC' | 'PRIVATE';
|
|
182
|
+
/**
|
|
183
|
+
* One event of the key's club the visitor may see, as listed (also an event the club
|
|
184
|
+
* co-hosts). Times are ISO-8601 strings with the Europe/Istanbul offset
|
|
185
|
+
* (e.g. `2026-11-01T19:00:00+03:00`), passed through unparsed.
|
|
180
186
|
*/
|
|
181
187
|
interface EventSummary {
|
|
182
188
|
id: number;
|
|
@@ -188,6 +194,8 @@ interface EventSummary {
|
|
|
188
194
|
status: EventStatus;
|
|
189
195
|
/** Last moment to join; the event's own time when no separate deadline was set. */
|
|
190
196
|
registrationDeadline: string | null;
|
|
197
|
+
/** `PUBLIC` when the server does not say (an older backend serves public events only). */
|
|
198
|
+
visibility: EventVisibility;
|
|
191
199
|
}
|
|
192
200
|
interface EventDetail extends EventSummary {
|
|
193
201
|
description: string;
|
|
@@ -218,10 +226,15 @@ interface ListEventsOptions {
|
|
|
218
226
|
/** Items per page, 1–50. Default 20. */
|
|
219
227
|
size?: number;
|
|
220
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Reads send the visitor's session when one is live, so an approved member also gets the
|
|
231
|
+
* club's private events. The list does not refresh itself on sign-in or sign-out: re-list
|
|
232
|
+
* from `auth.onChange`. An expired or refused session reads as signed out (public only).
|
|
233
|
+
*/
|
|
221
234
|
interface EventsApi {
|
|
222
|
-
/**
|
|
235
|
+
/** Events of the key's club the visitor may see. */
|
|
223
236
|
list(options?: ListEventsOptions): Promise<Page<EventSummary>>;
|
|
224
|
-
/** One
|
|
237
|
+
/** One event of the key's club the visitor may see; anything else rejects `EVENT_NOT_FOUND`. */
|
|
225
238
|
get(id: number): Promise<EventDetail>;
|
|
226
239
|
}
|
|
227
240
|
interface UniHub {
|
|
@@ -233,11 +246,12 @@ interface UniHub {
|
|
|
233
246
|
declare const DEFAULT_BASE_URL = "https://api.unihub.tr/api/v1/community";
|
|
234
247
|
/**
|
|
235
248
|
* Entry point for a community website: `createUniHub({ key: 'uhpk_live_…' })`.
|
|
236
|
-
*
|
|
249
|
+
* The key names the club. Reads show its public events, and also its private ones while an
|
|
250
|
+
* approved member is signed in.
|
|
237
251
|
*/
|
|
238
252
|
declare function createUniHub(config: UniHubConfig): UniHub;
|
|
239
253
|
|
|
240
254
|
/** This package's version, sent as `X-SDK-Version`. Kept equal to package.json by a test. */
|
|
241
|
-
declare const SDK_VERSION = "0.1.
|
|
255
|
+
declare const SDK_VERSION = "0.1.5";
|
|
242
256
|
|
|
243
|
-
export { type ApplyResult, type AttendanceApi, type AttendanceStatus, type AttendanceStatusResult, type AuthApi, DEFAULT_BASE_URL, ERROR_CODES, type EventDetail, type EventForm, type EventStatus, type EventSummary, type EventsApi, type FormAnswer, type FormQuestion, type FormQuestionType, type JoinResult, type JoinStatus, type ListEventsOptions, type Locale, type Page, SDK_VERSION, type SessionPersistence, type SignInOptions, type Ticket, type UniHub, UniHubApiError, type UniHubConfig, UniHubError, type UniHubErrorCode, type UniHubErrorDetails, type Visitor, createUniHub };
|
|
257
|
+
export { type ApplyResult, type AttendanceApi, type AttendanceStatus, type AttendanceStatusResult, type AuthApi, DEFAULT_BASE_URL, ERROR_CODES, type EventDetail, type EventForm, type EventStatus, type EventSummary, type EventVisibility, type EventsApi, type FormAnswer, type FormQuestion, type FormQuestionType, type JoinResult, type JoinStatus, type ListEventsOptions, type Locale, type Page, SDK_VERSION, type SessionPersistence, type SignInOptions, type Ticket, type UniHub, UniHubApiError, type UniHubConfig, UniHubError, type UniHubErrorCode, type UniHubErrorDetails, type Visitor, createUniHub };
|
package/dist/index.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var UniHub=(()=>{var A=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of te(t))!ne.call(e,s)&&s!==n&&A(e,s,{get:()=>t[s],enumerable:!(r=ee(t,s))||r.enumerable});return e};var ie=e=>oe(A({},"__esModule",{value:!0}),e);var Te={};re(Te,{DEFAULT_BASE_URL:()=>Z,ERROR_CODES:()=>S,SDK_VERSION:()=>w,UniHubApiError:()=>se,UniHubError:()=>f,createUniHub:()=>_e});var O={tr:{INVALID_ARGUMENT:"Ge\xE7ersiz parametre.",KEY_INVALID:"UniHub anahtar\u0131 ge\xE7ersiz veya devre d\u0131\u015F\u0131.",ORIGIN_NOT_ALLOWED:"Bu web sitesi, bu UniHub anahtar\u0131n\u0131 kullanmaya yetkili de\u011Fil.",RATE_LIMITED:"\xC7ok fazla istek g\xF6nderildi. L\xFCtfen biraz bekleyip tekrar deneyin.",NOT_SIGNED_IN:"Bu i\u015Flem i\xE7in UniHub hesab\u0131n\u0131zla giri\u015F yapmal\u0131s\u0131n\u0131z.",NOT_REGISTERED:"Bu hesab\u0131n bir UniHub profili yok. \xD6nce UniHub\u2019a kay\u0131t olun.",EMAIL_NOT_VERIFIED:"Bu etkinli\u011Fe kat\u0131lmak i\xE7in e-posta adresinizi do\u011Frulaman\u0131z gerekiyor.",VERIFIED_MEMBERS_ONLY:"Bu kul\xFCb\xFCn etkinliklerine yaln\u0131zca e-postas\u0131 do\u011Frulanm\u0131\u015F \xFCyeler kat\u0131labilir.",MEMBERS_ONLY:"Bu etkinli\u011Fe yaln\u0131zca kul\xFCb\xFCn onayl\u0131 \xFCyeleri kat\u0131labilir.",EVENT_FULL:"Etkinli\u011Fin kontenjan\u0131 dolmu\u015Ftur.",EVENT_CLOSED:"Bu etkinlik i\xE7in son kat\u0131l\u0131m tarihi ge\xE7mi\u015Ftir.",EVENT_NOT_FOUND:"Etkinlik bulunamad\u0131.",ALREADY_JOINED:"Bu etkinli\u011Fe zaten kat\u0131ld\u0131n\u0131z.",FORM_REQUIRED:"Bu etkinli\u011Fe kat\u0131lmak i\xE7in \xF6nce ba\u015Fvuru formunu doldurmal\u0131s\u0131n\u0131z.",TICKET_UNAVAILABLE:"Bu etkinlik i\xE7in biletiniz yok: kat\u0131l\u0131m\u0131n\u0131z hen\xFCz onaylanmad\u0131.",APP_REQUIRED:"Bu etkinli\u011Fin ba\u015Fvuru formu belge istiyor; ba\u015Fvuruyu UniHub uygulamas\u0131ndan yap\u0131n.",SIGN_IN_CANCELLED:"UniHub ile giri\u015F tamamlanmad\u0131.",POPUP_BLOCKED:"UniHub giri\u015F penceresi a\xE7\u0131lamad\u0131. Taray\u0131c\u0131n\u0131z a\xE7\u0131l\u0131r pencereleri engelliyor olabilir.",NETWORK:"UniHub sunucusuna ula\u015F\u0131lamad\u0131. \u0130nternet ba\u011Flant\u0131n\u0131z\u0131 kontrol edin.",UNKNOWN:"Beklenmeyen bir hata olu\u015Ftu."},en:{INVALID_ARGUMENT:"Invalid argument.",KEY_INVALID:"The UniHub key is invalid or disabled.",ORIGIN_NOT_ALLOWED:"This website is not allowed to use this UniHub key.",RATE_LIMITED:"Too many requests. Please wait a moment and try again.",NOT_SIGNED_IN:"Sign in with your UniHub account to do this.",NOT_REGISTERED:"This account has no UniHub profile yet. Register with UniHub first.",EMAIL_NOT_VERIFIED:"Verify your email address to join this event.",VERIFIED_MEMBERS_ONLY:"Only members with a verified email can join this club\u2019s events.",MEMBERS_ONLY:"Only approved members of the club can join this event.",EVENT_FULL:"This event is full.",EVENT_CLOSED:"Registration for this event has closed.",EVENT_NOT_FOUND:"Event not found.",ALREADY_JOINED:"You have already joined this event.",FORM_REQUIRED:"This event requires an application form first.",TICKET_UNAVAILABLE:"There is no ticket for you yet: your attendance is not approved.",APP_REQUIRED:"This event's application form asks for a document. Apply in the UniHub app.",SIGN_IN_CANCELLED:"UniHub sign-in was not completed.",POPUP_BLOCKED:"The UniHub sign-in window could not be opened. Your browser may be blocking pop-ups.",NETWORK:"Could not reach the UniHub server. Check your internet connection.",UNKNOWN:"An unexpected error occurred."}};function v(e,t="tr"){return(O[t]??O.tr)[e]}var S=["INVALID_ARGUMENT","KEY_INVALID","ORIGIN_NOT_ALLOWED","RATE_LIMITED","NOT_SIGNED_IN","NOT_REGISTERED","EMAIL_NOT_VERIFIED","VERIFIED_MEMBERS_ONLY","MEMBERS_ONLY","EVENT_FULL","EVENT_CLOSED","EVENT_NOT_FOUND","ALREADY_JOINED","FORM_REQUIRED","TICKET_UNAVAILABLE","APP_REQUIRED","SIGN_IN_CANCELLED","POPUP_BLOCKED","NETWORK","UNKNOWN"],f=class extends Error{code;status;details;constructor(t,n,r={}){super(r.message??v(t,r.locale)),this.name="UniHubError",this.code=t,this.status=n,this.details=r.details??{},Object.setPrototypeOf(this,new.target.prototype)}},se=f;var w="0.1.4";var ae=210,ue=250,ce=2e3,D=300,P=e=>new Promise(t=>setTimeout(t,e));function C(e){let{baseUrl:t,key:n,locale:r}=e,s=(...m)=>(e.fetch??globalThis.fetch)(...m),u=Promise.resolve(),d=Number.NEGATIVE_INFINITY;function c(m,y){let o=u.then(async()=>{let l=d+ae-Date.now();l>0&&await P(l);try{return await s(m,y)}catch(p){throw new f("NETWORK",0,{locale:r,details:{backendMessage:String(p?.message??p)}})}finally{d=Date.now()}});return u=o.catch(()=>{}),o}return{async request(m,y){let o=new Headers({[n.header]:n.value,"X-SDK-Version":w});y.body!==void 0&&o.set("Content-Type","application/json"),y.token&&o.set("Authorization",`Bearer ${y.token}`);let l={method:y.method,headers:o,body:y.body===void 0?void 0:JSON.stringify(y.body)};y.noStore&&(l.cache="no-store");let p=`${t}${m}${le(y.query)}`,a;try{a=await c(p,l)}catch(E){if(y.method!=="GET"||!(E instanceof f)||E.code!=="NETWORK")throw E;a=await c(p,l)}a.status===429&&y.method==="GET"&&(await P(Math.min(M(a)??ue,ce)),a=await c(p,l));let i=await a.text().catch(()=>""),g=pe(i);if(a.ok)return g;throw ye(a,g,i,r)}}}function le(e){if(!e)return"";let t=new URLSearchParams;for(let[r,s]of Object.entries(e))s!==void 0&&t.set(r,String(s));let n=t.toString();return n?`?${n}`:""}function pe(e){if(e)try{return JSON.parse(e)}catch{return e}}function I(e,t){if(!e||typeof e!="object")return;let n=e[t];return typeof n=="string"?n:void 0}function de(e,t){let n=I(e,"message")??I(e,"error");if(n!==void 0)return n;if(t)return t.length>D?`${t.slice(0,D)}\u2026`:t}function me(e){let t=/^\d{3} [A-Z_]+ "([\s\S]*)"$/.exec(e.trim());return(t?t[1]:e).trim()}var fe=new Set(["NETWORK","SIGN_IN_CANCELLED","POPUP_BLOCKED"]),ge=new Set(S.filter(e=>!fe.has(e)));function M(e){let t=e.headers.get("Retry-After");if(!t)return;let n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);let r=Date.parse(t);return Number.isNaN(r)?void 0:Math.max(0,r-Date.now())}function ye(e,t,n,r){let s=de(t,n),u=s===void 0?void 0:me(s),d=I(t,"code"),c,m;return e.status===429?c="RATE_LIMITED":d!==void 0&&ge.has(d)?c=d:d!==void 0?(c="UNKNOWN",m=d):c=e.status===401?"KEY_INVALID":"UNKNOWN",new f(c,e.status,{locale:r,details:{backendMessage:u,backendCode:m,retryAfterMs:e.status===429?M(e):void 0}})}var x=50;function B(e,t){let n=r=>new f("INVALID_ARGUMENT",0,{locale:t,message:`unihub-community-sdk: ${r}`});return{async list(r={}){let{when:s="upcoming",page:u,size:d}=r;if(s!=="upcoming"&&s!=="past")throw n("'when' must be 'upcoming' or 'past'.");if(u!==void 0&&!(Number.isInteger(u)&&u>=0))throw n("'page' must be an integer >= 0.");if(d!==void 0&&!(Number.isInteger(d)&&d>=1&&d<=x))throw n(`'size' must be an integer from 1 to ${x}.`);let c=await e.request("/events",{method:"GET",query:{when:s,page:u,size:d}});if(!c||!Array.isArray(c.items))throw new f("UNKNOWN",200,{locale:t,details:{backendMessage:"event list without items"}});return{items:c.items.map(V),page:c.page??0,size:c.size??c.items.length,totalItems:c.totalItems??c.items.length,totalPages:c.totalPages??0}},async get(r){if(!(Number.isSafeInteger(r)&&r>0))throw n("event id must be a positive integer.");let s=await e.request(`/events/${r}`,{method:"GET"});return{...V(s??{}),description:s?.description??"",capacity:s?.capacity??null,requiresForm:s?.requiresForm??!1,membersOnly:s?.membersOnly??!1,verifiedOnly:s?.verifiedOnly??!1,approvalRequired:s?.approvalRequired??!1}}}}function V(e){return{id:e.id,title:e.title??"",startsAt:e.startsAt??null,location:e.location??null,imageUrl:e.imageUrl??null,status:e.status==="PAST"?"PAST":"UPCOMING",registrationDeadline:e.registrationDeadline??null}}function G(){let e;try{e=globalThis.window}catch{return null}if(!e||typeof e.open!="function"||!e.location||typeof e.addEventListener!="function")return null;let t=null;try{let n=e.crypto;n&&typeof n.getRandomValues=="function"&&n.subtle&&typeof n.subtle.digest=="function"&&(t=n)}catch{t=null}return{origin:e.location.origin,href:()=>e.location.href,assign:n=>e.location.assign(n),replaceState:n=>e.history.replaceState(e.history.state,"",n),open:(n,r,s)=>e.open(n,r,s),onMessage(n){let r=s=>n({origin:s.origin,source:s.source,data:s.data});return e.addEventListener("message",r),()=>e.removeEventListener("message",r)},crypto:t,storage(n){try{let r=e[n];return r&&typeof r.getItem=="function"?r:null}catch{return null}}}}function q(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function H(e,t){return q(e.getRandomValues(new Uint8Array(t)))}async function k(e,t){let n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return q(new Uint8Array(await e.subtle.digest("SHA-256",n)))}function L(e){return{verifier:H(e,32),state:H(e,16)}}var Ee="https://www.unihub.tr/connect",he="https://www.unihub.tr",be="unihub-connect",we="popup,width=480,height=720",Ne=500,Ae=["unihub_code","unihub_error","state"];function F(e){let t=new URLSearchParams({client:e.key,origin:e.origin,state:e.state,code_challenge:e.challenge,mode:e.mode});return e.mode==="redirect"&&e.returnUrl&&t.set("return",e.returnUrl),`${Ee}?${t.toString()}`}var R=e=>new f("SIGN_IN_CANCELLED",0,{locale:e});function N(e,t){if(e.crypto)return e.crypto;throw new f("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: sign-in needs Web Crypto (a secure context: https, or http://localhost)."})}function K(e,t){let n=e.open("",be,we);if(!n)throw new f("POPUP_BLOCKED",0,{locale:t});return n}function $(e,t,n,r){let s=N(e,r),{verifier:u,state:d}=L(s);return new Promise((c,m)=>{let y=!1,o=i=>{y||(y=!0,p(),clearInterval(a),i())},l=i=>o(()=>{try{t.close()}catch{}m(i)}),p=e.onMessage(i=>{if(i.origin!==he||i.source!==t)return;let g=i.data;if(!(!g||typeof g!="object"||g.type!=="unihub:connect"||g.state!==d))if(typeof g.code=="string"&&g.code){let E=g.code;o(()=>c({code:E,verifier:u}))}else o(()=>m(R(r)))}),a=setInterval(()=>{let i=!1;try{i=t.closed}catch{i=!1}i&&o(()=>m(R(r)))},Ne);k(s,u).then(i=>{if(!y)try{t.location.href=F({key:n,origin:e.origin,state:d,challenge:i,mode:"popup"})}catch(g){l(g)}},()=>l(new f("INVALID_ARGUMENT",0,{locale:r,message:"unihub-community-sdk: Web Crypto refused SHA-256."})))})}function _(e){return`unihub:connect:${e}`}function W(e){let t=new URL(e);for(let n of Ae)t.searchParams.delete(n);return t}async function z(e,t,n,r){let s=N(e,n),u;try{u=r===void 0?W(e.href()):new URL(r,e.href())}catch{u=new URL("about:invalid")}if(u.origin!==e.origin)throw new f("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: returnUrl must be on the same origin as this page."});let d=e.storage("sessionStorage");if(!d)throw new f("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: redirect sign-in needs sessionStorage; use the popup."});let{verifier:c,state:m}=L(s),y=await k(s,c),o={verifier:c,state:m,returnUrl:u.toString()};return d.setItem(_(t),JSON.stringify(o)),e.assign(F({key:t,origin:e.origin,state:m,challenge:y,mode:"redirect",returnUrl:o.returnUrl})),new Promise(()=>{})}function Y(e,t,n){let r=new URL(e.href()),s=r.searchParams.get("unihub_code"),u=r.searchParams.get("unihub_error");if(s===null&&u===null)return null;let d=r.searchParams.get("state");e.replaceState(W(r.toString()).toString());let c=e.storage("sessionStorage"),m=null;try{let y=c?.getItem(_(t))??null;c?.removeItem(_(t));let o=y?JSON.parse(y):null;o&&typeof o.verifier=="string"&&typeof o.state=="string"&&(m=o)}catch{m=null}if(!m||d!==m.state||u!==null||!s)throw R(n);return{code:s,verifier:m.verifier}}function T(e){return`unihub:session:${e}`}function U(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.userId=="number"&&typeof t.displayName=="string"&&(t.avatarUrl===null||typeof t.avatarUrl=="string")&&typeof t.emailVerified=="boolean"}function Se(e){if(!e)return null;try{let t=JSON.parse(e);return typeof t.token!="string"||!t.token.startsWith("uhct_")||typeof t.expiresAt!="number"||!Number.isFinite(t.expiresAt)||!U(t.visitor)?null:{token:t.token,expiresAt:t.expiresAt,visitor:t.visitor}}catch{return null}}function J(e,t,n){let r=new Set,s=!1,u=null,d,c=()=>t==="memory"?null:n()?.storage(t)??null;function m(i){for(let g of[...r])try{g(i)}catch{}}function y(){d!==void 0&&clearTimeout(d),d=void 0}function o(){if(y(),!u)return;let i=u.token;d=setTimeout(()=>{d=void 0,a(i)},Math.min(Math.max(0,u.expiresAt-Date.now()),2147483647))}function l(i){let g=c();if(g)try{i?g.setItem(T(e),JSON.stringify(i)):g.removeItem(T(e))}catch{}}function p(){if(s)return;s=!0;let i=c();if(!i)return;let g=null;try{g=i.getItem(T(e))}catch{return}let E=Se(g);if(!E||E.expiresAt<=Date.now()){g!==null&&l(null);return}u=E,o()}function a(i){p(),!(!u||i!==void 0&&u.token!==i)&&(u=null,y(),l(null),m(null))}return{get(){return p(),u&&u.expiresAt<=Date.now()&&a(u.token),u},set(i){p(),u=i,l(i),o(),m(i.visitor)},clear:a,onChange(i){return p(),r.add(i),()=>{r.delete(i)}}}}function j(e,t,n,r,s=G){let u,d=()=>(u===void 0&&(u=s()),u),c=J(t,r,d),m=null;function y(){let a=d();if(a)return a;throw new f("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: sign-in runs only in a browser."})}async function o(a){let i=await e.request("/connect/token",{method:"POST",body:{code:a.code,codeVerifier:a.verifier}}),g=typeof i?.expiresAt=="string"?Date.parse(i.expiresAt):NaN,E=i?.visitor;if(typeof i?.token!="string"||!i.token.startsWith("uhct_")||!Number.isFinite(g)||!U(E))throw new f("UNKNOWN",200,{locale:n,details:{backendMessage:"Unexpected /connect/token response."}});let h={userId:E.userId,displayName:E.displayName,avatarUrl:E.avatarUrl,emailVerified:E.emailVerified};return c.set({token:i.token,expiresAt:g,visitor:h}),h}function l(a){try{let i=a?.mode??"popup";if(i!=="popup"&&i!=="redirect")throw new f("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: mode must be 'popup' or 'redirect'."});let g=y();if(N(g,n),i==="redirect")return z(g,t,n,a?.returnUrl);if(m&&!m.popup.closed){try{m.popup.focus()}catch{}return m.promise}let E=K(g,n),h=$(g,E,t,n).then(o).finally(()=>{m?.promise===h&&(m=null)});return m={popup:E,promise:h},h}catch(i){return Promise.reject(i)}}return{api:{signIn:l,register:a=>l(a),async handleRedirect(){let a=d();if(!a)return null;let i=Y(a,t,n);return i?o(i):null},current:()=>c.get()?.visitor??null,onChange:a=>c.onChange(a),async signOut(){let a=c.get();if(a){try{await e.request("/session",{method:"DELETE",token:a.token})}catch{}c.clear(a.token)}}},session:c}}var Ie=new Set(["JOINED","PENDING_APPROVAL","ALREADY_JOINED"]),ke=new Set(["NOT_JOINED","PENDING_APPROVAL","JOINED"]),Le=new Set(["JOINED","PENDING_APPROVAL"]),X=1024,b=e=>typeof e=="object"&&e!==null;function Q(e,t,n){let r=o=>new f("INVALID_ARGUMENT",0,{locale:n,message:`unihub-community-sdk: ${o}`}),s=o=>new f("UNKNOWN",200,{locale:n,details:{backendMessage:o}});function u(o){if(!Number.isSafeInteger(o)||o<=0)throw r(`eventId must be a positive integer: ${String(o)}`)}async function d(o,l,p){u(o);let a=t.get();if(!a)throw new f("NOT_SIGNED_IN",0,{locale:n});try{return await e.request(`/events/${o}/${l}`,{...p,token:a.token})}catch(i){throw i instanceof f&&i.code==="NOT_SIGNED_IN"&&t.clear(a.token),i}}function c(o,l){let p=b(o)?o.status:void 0;if(typeof p!="string"||!l.has(p))throw s(typeof p=="string"?p:void 0);return p}function m(o){if(!b(o)||!Number.isSafeInteger(o.id)||typeof o.type!="string"||typeof o.label!="string"||!(o.options===null||o.options===void 0||Array.isArray(o.options)&&o.options.every(l=>typeof l=="string")))throw s("Unexpected form question.");return{id:o.id,type:o.type,label:o.label,required:o.required===!0,options:Array.isArray(o.options)?[...o.options]:null}}function y(o){if(!Array.isArray(o))throw r("answers must be an array.");let l=new Set;return o.map((p,a)=>{if(!b(p)||!Number.isSafeInteger(p.questionId)||p.questionId<=0)throw r(`answers[${a}].questionId must be a positive integer.`);if(typeof p.answer!="string")throw r(`answers[${a}].answer must be a string.`);if(p.answer.length>X)throw r(`answers[${a}].answer is longer than ${X} characters.`);if(l.has(p.questionId))throw r(`question ${p.questionId} is answered twice.`);return l.add(p.questionId),{questionId:p.questionId,answerText:p.answer}})}return{async join(o){let l=await d(o,"join",{method:"POST"});return{status:c(l,Ie)}},async status(o){let l=await d(o,"status",{method:"GET"});return{status:c(l,ke)}},async leave(o){await d(o,"attendance",{method:"DELETE"})},async ticket(o){let l=await d(o,"ticket",{method:"GET",noStore:!0}),p=b(l)?l.qrPayload:void 0;if(typeof p!="string"||p==="")throw s("Unexpected ticket response.");return{qrPayload:p}},async form(o){let l=await d(o,"form",{method:"GET"});if(!b(l)||!Array.isArray(l.questions)||typeof l.appRequired!="boolean")throw s("Unexpected form response.");return{questions:l.questions.map(m),appRequired:l.appRequired}},async apply(o,l){u(o);let p=y(l),a=await d(o,"apply",{method:"POST",body:{answers:p}});return{status:c(a,Le)}}}}var Z="https://api.unihub.tr/api/v1/community";function Re(e,t){let n;try{n=new URL(e)}catch{throw new f("INVALID_ARGUMENT",0,{locale:t,message:`unihub-community-sdk: baseUrl is not a URL: ${e}`})}let r=n.hostname==="localhost"||n.hostname==="127.0.0.1";if(n.protocol!=="https:"&&!(n.protocol==="http:"&&r))throw new f("INVALID_ARGUMENT",0,{locale:t,message:`unihub-community-sdk: baseUrl must use https (http is allowed only for localhost): ${e}`});return e.replace(/\/+$/,"")}function _e(e){let t=e?.locale??"tr",n=e?.key;if(!n)throw new f("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'key' is required."});if(typeof n!="string"||!n.startsWith("uhpk_"))throw new f("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'key' must be a publishable community key (uhpk_\u2026). Never put a master key or any other secret in a web page."});let r=e.session??"memory";if(r!=="memory"&&r!=="sessionStorage"&&r!=="localStorage")throw new f("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'session' must be 'memory', 'sessionStorage' or 'localStorage'."});let s=C({baseUrl:Re(e.baseUrl??Z,t),key:{header:"X-Community-Key",value:n},locale:t,fetch:e.fetch}),u=j(s,n,t,r);return{events:B(s,t),auth:u.api,attendance:Q(s,u.session,t)}}return ie(Te);})();
|
|
1
|
+
"use strict";var UniHub=(()=>{var A=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of te(t))!ne.call(e,a)&&a!==n&&A(e,a,{get:()=>t[a],enumerable:!(o=ee(t,a))||o.enumerable});return e};var ie=e=>oe(A({},"__esModule",{value:!0}),e);var Te={};re(Te,{DEFAULT_BASE_URL:()=>Z,ERROR_CODES:()=>S,SDK_VERSION:()=>w,UniHubApiError:()=>se,UniHubError:()=>g,createUniHub:()=>_e});var O={tr:{INVALID_ARGUMENT:"Ge\xE7ersiz parametre.",KEY_INVALID:"UniHub anahtar\u0131 ge\xE7ersiz veya devre d\u0131\u015F\u0131.",ORIGIN_NOT_ALLOWED:"Bu web sitesi, bu UniHub anahtar\u0131n\u0131 kullanmaya yetkili de\u011Fil.",RATE_LIMITED:"\xC7ok fazla istek g\xF6nderildi. L\xFCtfen biraz bekleyip tekrar deneyin.",NOT_SIGNED_IN:"Bu i\u015Flem i\xE7in UniHub hesab\u0131n\u0131zla giri\u015F yapmal\u0131s\u0131n\u0131z.",NOT_REGISTERED:"Bu hesab\u0131n bir UniHub profili yok. \xD6nce UniHub\u2019a kay\u0131t olun.",EMAIL_NOT_VERIFIED:"Bu etkinli\u011Fe kat\u0131lmak i\xE7in e-posta adresinizi do\u011Frulaman\u0131z gerekiyor.",VERIFIED_MEMBERS_ONLY:"Bu kul\xFCb\xFCn etkinliklerine yaln\u0131zca e-postas\u0131 do\u011Frulanm\u0131\u015F \xFCyeler kat\u0131labilir.",MEMBERS_ONLY:"Bu etkinli\u011Fe yaln\u0131zca kul\xFCb\xFCn onayl\u0131 \xFCyeleri kat\u0131labilir.",EVENT_FULL:"Etkinli\u011Fin kontenjan\u0131 dolmu\u015Ftur.",EVENT_CLOSED:"Bu etkinlik i\xE7in son kat\u0131l\u0131m tarihi ge\xE7mi\u015Ftir.",EVENT_NOT_FOUND:"Etkinlik bulunamad\u0131.",ALREADY_JOINED:"Bu etkinli\u011Fe zaten kat\u0131ld\u0131n\u0131z.",FORM_REQUIRED:"Bu etkinli\u011Fe kat\u0131lmak i\xE7in \xF6nce ba\u015Fvuru formunu doldurmal\u0131s\u0131n\u0131z.",TICKET_UNAVAILABLE:"Bu etkinlik i\xE7in biletiniz yok: kat\u0131l\u0131m\u0131n\u0131z hen\xFCz onaylanmad\u0131.",APP_REQUIRED:"Bu etkinli\u011Fin ba\u015Fvuru formu belge istiyor; ba\u015Fvuruyu UniHub uygulamas\u0131ndan yap\u0131n.",SIGN_IN_CANCELLED:"UniHub ile giri\u015F tamamlanmad\u0131.",POPUP_BLOCKED:"UniHub giri\u015F penceresi a\xE7\u0131lamad\u0131. Taray\u0131c\u0131n\u0131z a\xE7\u0131l\u0131r pencereleri engelliyor olabilir.",NETWORK:"UniHub sunucusuna ula\u015F\u0131lamad\u0131. \u0130nternet ba\u011Flant\u0131n\u0131z\u0131 kontrol edin.",UNKNOWN:"Beklenmeyen bir hata olu\u015Ftu."},en:{INVALID_ARGUMENT:"Invalid argument.",KEY_INVALID:"The UniHub key is invalid or disabled.",ORIGIN_NOT_ALLOWED:"This website is not allowed to use this UniHub key.",RATE_LIMITED:"Too many requests. Please wait a moment and try again.",NOT_SIGNED_IN:"Sign in with your UniHub account to do this.",NOT_REGISTERED:"This account has no UniHub profile yet. Register with UniHub first.",EMAIL_NOT_VERIFIED:"Verify your email address to join this event.",VERIFIED_MEMBERS_ONLY:"Only members with a verified email can join this club\u2019s events.",MEMBERS_ONLY:"Only approved members of the club can join this event.",EVENT_FULL:"This event is full.",EVENT_CLOSED:"Registration for this event has closed.",EVENT_NOT_FOUND:"Event not found.",ALREADY_JOINED:"You have already joined this event.",FORM_REQUIRED:"This event requires an application form first.",TICKET_UNAVAILABLE:"There is no ticket for you yet: your attendance is not approved.",APP_REQUIRED:"This event's application form asks for a document. Apply in the UniHub app.",SIGN_IN_CANCELLED:"UniHub sign-in was not completed.",POPUP_BLOCKED:"The UniHub sign-in window could not be opened. Your browser may be blocking pop-ups.",NETWORK:"Could not reach the UniHub server. Check your internet connection.",UNKNOWN:"An unexpected error occurred."}};function v(e,t="tr"){return(O[t]??O.tr)[e]}var S=["INVALID_ARGUMENT","KEY_INVALID","ORIGIN_NOT_ALLOWED","RATE_LIMITED","NOT_SIGNED_IN","NOT_REGISTERED","EMAIL_NOT_VERIFIED","VERIFIED_MEMBERS_ONLY","MEMBERS_ONLY","EVENT_FULL","EVENT_CLOSED","EVENT_NOT_FOUND","ALREADY_JOINED","FORM_REQUIRED","TICKET_UNAVAILABLE","APP_REQUIRED","SIGN_IN_CANCELLED","POPUP_BLOCKED","NETWORK","UNKNOWN"],g=class extends Error{code;status;details;constructor(t,n,o={}){super(o.message??v(t,o.locale)),this.name="UniHubError",this.code=t,this.status=n,this.details=o.details??{},Object.setPrototypeOf(this,new.target.prototype)}},se=g;var w="0.1.5";var ae=210,ue=250,ce=2e3,P=300,D=e=>new Promise(t=>setTimeout(t,e));function C(e){let{baseUrl:t,key:n,locale:o}=e,a=(...p)=>(e.fetch??globalThis.fetch)(...p),s=Promise.resolve(),u=Number.NEGATIVE_INFINITY;function f(p,m){let r=s.then(async()=>{let l=u+ae-Date.now();l>0&&await D(l);try{return await a(p,m)}catch(d){throw new g("NETWORK",0,{locale:o,details:{backendMessage:String(d?.message??d)}})}finally{u=Date.now()}});return s=r.catch(()=>{}),r}return{async request(p,m){let r=new Headers({[n.header]:n.value,"X-SDK-Version":w});m.body!==void 0&&r.set("Content-Type","application/json"),m.token&&r.set("Authorization",`Bearer ${m.token}`);let l={method:m.method,headers:r,body:m.body===void 0?void 0:JSON.stringify(m.body)};m.noStore&&(l.cache="no-store");let d=`${t}${p}${le(m.query)}`,c;try{c=await f(d,l)}catch(E){if(m.method!=="GET"||!(E instanceof g)||E.code!=="NETWORK")throw E;c=await f(d,l)}c.status===429&&m.method==="GET"&&(await D(Math.min(M(c)??ue,ce)),c=await f(d,l));let i=await c.text().catch(()=>""),y=pe(i);if(c.ok)return y;throw ye(c,y,i,o)}}}function le(e){if(!e)return"";let t=new URLSearchParams;for(let[o,a]of Object.entries(e))a!==void 0&&t.set(o,String(a));let n=t.toString();return n?`?${n}`:""}function pe(e){if(e)try{return JSON.parse(e)}catch{return e}}function I(e,t){if(!e||typeof e!="object")return;let n=e[t];return typeof n=="string"?n:void 0}function de(e,t){let n=I(e,"message")??I(e,"error");if(n!==void 0)return n;if(t)return t.length>P?`${t.slice(0,P)}\u2026`:t}function me(e){let t=/^\d{3} [A-Z_]+ "([\s\S]*)"$/.exec(e.trim());return(t?t[1]:e).trim()}var fe=new Set(["NETWORK","SIGN_IN_CANCELLED","POPUP_BLOCKED"]),ge=new Set(S.filter(e=>!fe.has(e)));function M(e){let t=e.headers.get("Retry-After");if(!t)return;let n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);let o=Date.parse(t);return Number.isNaN(o)?void 0:Math.max(0,o-Date.now())}function ye(e,t,n,o){let a=de(t,n),s=a===void 0?void 0:me(a),u=I(t,"code"),f,p;return e.status===429?f="RATE_LIMITED":u!==void 0&&ge.has(u)?f=u:u!==void 0?(f="UNKNOWN",p=u):f=e.status===401?"KEY_INVALID":"UNKNOWN",new g(f,e.status,{locale:o,details:{backendMessage:s,backendCode:p,retryAfterMs:e.status===429?M(e):void 0}})}var x=50;function B(e,t,n){let o=s=>new g("INVALID_ARGUMENT",0,{locale:n,message:`unihub-community-sdk: ${s}`});function a(){let s=t.get();return s?{token:s.token,noStore:!0}:{}}return{async list(s={}){let{when:u="upcoming",page:f,size:p}=s;if(u!=="upcoming"&&u!=="past")throw o("'when' must be 'upcoming' or 'past'.");if(f!==void 0&&!(Number.isInteger(f)&&f>=0))throw o("'page' must be an integer >= 0.");if(p!==void 0&&!(Number.isInteger(p)&&p>=1&&p<=x))throw o(`'size' must be an integer from 1 to ${x}.`);let m=await e.request("/events",{method:"GET",query:{when:u,page:f,size:p},...a()});if(!m||!Array.isArray(m.items))throw new g("UNKNOWN",200,{locale:n,details:{backendMessage:"event list without items"}});return{items:m.items.map(V),page:m.page??0,size:m.size??m.items.length,totalItems:m.totalItems??m.items.length,totalPages:m.totalPages??0}},async get(s){if(!(Number.isSafeInteger(s)&&s>0))throw o("event id must be a positive integer.");let u=await e.request(`/events/${s}`,{method:"GET",...a()});return{...V(u??{}),description:u?.description??"",capacity:u?.capacity??null,requiresForm:u?.requiresForm??!1,membersOnly:u?.membersOnly??!1,verifiedOnly:u?.verifiedOnly??!1,approvalRequired:u?.approvalRequired??!1}}}}function V(e){return{id:e.id,title:e.title??"",startsAt:e.startsAt??null,location:e.location??null,imageUrl:e.imageUrl??null,status:e.status==="PAST"?"PAST":"UPCOMING",registrationDeadline:e.registrationDeadline??null,visibility:e.visibility==="PRIVATE"?"PRIVATE":"PUBLIC"}}function G(){let e;try{e=globalThis.window}catch{return null}if(!e||typeof e.open!="function"||!e.location||typeof e.addEventListener!="function")return null;let t=null;try{let n=e.crypto;n&&typeof n.getRandomValues=="function"&&n.subtle&&typeof n.subtle.digest=="function"&&(t=n)}catch{t=null}return{origin:e.location.origin,href:()=>e.location.href,assign:n=>e.location.assign(n),replaceState:n=>e.history.replaceState(e.history.state,"",n),open:(n,o,a)=>e.open(n,o,a),onMessage(n){let o=a=>n({origin:a.origin,source:a.source,data:a.data});return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},crypto:t,storage(n){try{let o=e[n];return o&&typeof o.getItem=="function"?o:null}catch{return null}}}}function q(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function H(e,t){return q(e.getRandomValues(new Uint8Array(t)))}async function k(e,t){let n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return q(new Uint8Array(await e.subtle.digest("SHA-256",n)))}function L(e){return{verifier:H(e,32),state:H(e,16)}}var Ee="https://www.unihub.tr/connect",he="https://www.unihub.tr",be="unihub-connect",we="popup,width=480,height=720",Ne=500,Ae=["unihub_code","unihub_error","state"];function F(e){let t=new URLSearchParams({client:e.key,origin:e.origin,state:e.state,code_challenge:e.challenge,mode:e.mode});return e.mode==="redirect"&&e.returnUrl&&t.set("return",e.returnUrl),`${Ee}?${t.toString()}`}var R=e=>new g("SIGN_IN_CANCELLED",0,{locale:e});function N(e,t){if(e.crypto)return e.crypto;throw new g("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: sign-in needs Web Crypto (a secure context: https, or http://localhost)."})}function K(e,t){let n=e.open("",be,we);if(!n)throw new g("POPUP_BLOCKED",0,{locale:t});return n}function $(e,t,n,o){let a=N(e,o),{verifier:s,state:u}=L(a);return new Promise((f,p)=>{let m=!1,r=i=>{m||(m=!0,d(),clearInterval(c),i())},l=i=>r(()=>{try{t.close()}catch{}p(i)}),d=e.onMessage(i=>{if(i.origin!==he||i.source!==t)return;let y=i.data;if(!(!y||typeof y!="object"||y.type!=="unihub:connect"||y.state!==u))if(typeof y.code=="string"&&y.code){let E=y.code;r(()=>f({code:E,verifier:s}))}else r(()=>p(R(o)))}),c=setInterval(()=>{let i=!1;try{i=t.closed}catch{i=!1}i&&r(()=>p(R(o)))},Ne);k(a,s).then(i=>{if(!m)try{t.location.href=F({key:n,origin:e.origin,state:u,challenge:i,mode:"popup"})}catch(y){l(y)}},()=>l(new g("INVALID_ARGUMENT",0,{locale:o,message:"unihub-community-sdk: Web Crypto refused SHA-256."})))})}function _(e){return`unihub:connect:${e}`}function W(e){let t=new URL(e);for(let n of Ae)t.searchParams.delete(n);return t}async function z(e,t,n,o){let a=N(e,n),s;try{s=o===void 0?W(e.href()):new URL(o,e.href())}catch{s=new URL("about:invalid")}if(s.origin!==e.origin)throw new g("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: returnUrl must be on the same origin as this page."});let u=e.storage("sessionStorage");if(!u)throw new g("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: redirect sign-in needs sessionStorage; use the popup."});let{verifier:f,state:p}=L(a),m=await k(a,f),r={verifier:f,state:p,returnUrl:s.toString()};return u.setItem(_(t),JSON.stringify(r)),e.assign(F({key:t,origin:e.origin,state:p,challenge:m,mode:"redirect",returnUrl:r.returnUrl})),new Promise(()=>{})}function Y(e,t,n){let o=new URL(e.href()),a=o.searchParams.get("unihub_code"),s=o.searchParams.get("unihub_error");if(a===null&&s===null)return null;let u=o.searchParams.get("state");e.replaceState(W(o.toString()).toString());let f=e.storage("sessionStorage"),p=null;try{let m=f?.getItem(_(t))??null;f?.removeItem(_(t));let r=m?JSON.parse(m):null;r&&typeof r.verifier=="string"&&typeof r.state=="string"&&(p=r)}catch{p=null}if(!p||u!==p.state||s!==null||!a)throw R(n);return{code:a,verifier:p.verifier}}function T(e){return`unihub:session:${e}`}function U(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.userId=="number"&&typeof t.displayName=="string"&&(t.avatarUrl===null||typeof t.avatarUrl=="string")&&typeof t.emailVerified=="boolean"}function Se(e){if(!e)return null;try{let t=JSON.parse(e);return typeof t.token!="string"||!t.token.startsWith("uhct_")||typeof t.expiresAt!="number"||!Number.isFinite(t.expiresAt)||!U(t.visitor)?null:{token:t.token,expiresAt:t.expiresAt,visitor:t.visitor}}catch{return null}}function J(e,t,n){let o=new Set,a=!1,s=null,u,f=()=>t==="memory"?null:n()?.storage(t)??null;function p(i){for(let y of[...o])try{y(i)}catch{}}function m(){u!==void 0&&clearTimeout(u),u=void 0}function r(){if(m(),!s)return;let i=s.token;u=setTimeout(()=>{u=void 0,c(i)},Math.min(Math.max(0,s.expiresAt-Date.now()),2147483647))}function l(i){let y=f();if(y)try{i?y.setItem(T(e),JSON.stringify(i)):y.removeItem(T(e))}catch{}}function d(){if(a)return;a=!0;let i=f();if(!i)return;let y=null;try{y=i.getItem(T(e))}catch{return}let E=Se(y);if(!E||E.expiresAt<=Date.now()){y!==null&&l(null);return}s=E,r()}function c(i){d(),!(!s||i!==void 0&&s.token!==i)&&(s=null,m(),l(null),p(null))}return{get(){return d(),s&&s.expiresAt<=Date.now()&&c(s.token),s},set(i){d(),s=i,l(i),r(),p(i.visitor)},clear:c,onChange(i){return d(),o.add(i),()=>{o.delete(i)}}}}function j(e,t,n,o,a=G){let s,u=()=>(s===void 0&&(s=a()),s),f=J(t,o,u),p=null;function m(){let c=u();if(c)return c;throw new g("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: sign-in runs only in a browser."})}async function r(c){let i=await e.request("/connect/token",{method:"POST",body:{code:c.code,codeVerifier:c.verifier}}),y=typeof i?.expiresAt=="string"?Date.parse(i.expiresAt):NaN,E=i?.visitor;if(typeof i?.token!="string"||!i.token.startsWith("uhct_")||!Number.isFinite(y)||!U(E))throw new g("UNKNOWN",200,{locale:n,details:{backendMessage:"Unexpected /connect/token response."}});let h={userId:E.userId,displayName:E.displayName,avatarUrl:E.avatarUrl,emailVerified:E.emailVerified};return f.set({token:i.token,expiresAt:y,visitor:h}),h}function l(c){try{let i=c?.mode??"popup";if(i!=="popup"&&i!=="redirect")throw new g("INVALID_ARGUMENT",0,{locale:n,message:"unihub-community-sdk: mode must be 'popup' or 'redirect'."});let y=m();if(N(y,n),i==="redirect")return z(y,t,n,c?.returnUrl);if(p&&!p.popup.closed){try{p.popup.focus()}catch{}return p.promise}let E=K(y,n),h=$(y,E,t,n).then(r).finally(()=>{p?.promise===h&&(p=null)});return p={popup:E,promise:h},h}catch(i){return Promise.reject(i)}}return{api:{signIn:l,register:c=>l(c),async handleRedirect(){let c=u();if(!c)return null;let i=Y(c,t,n);return i?r(i):null},current:()=>f.get()?.visitor??null,onChange:c=>f.onChange(c),async signOut(){let c=f.get();if(c){try{await e.request("/session",{method:"DELETE",token:c.token})}catch{}f.clear(c.token)}}},session:f}}var Ie=new Set(["JOINED","PENDING_APPROVAL","ALREADY_JOINED"]),ke=new Set(["NOT_JOINED","PENDING_APPROVAL","JOINED"]),Le=new Set(["JOINED","PENDING_APPROVAL"]),X=1024,b=e=>typeof e=="object"&&e!==null;function Q(e,t,n){let o=r=>new g("INVALID_ARGUMENT",0,{locale:n,message:`unihub-community-sdk: ${r}`}),a=r=>new g("UNKNOWN",200,{locale:n,details:{backendMessage:r}});function s(r){if(!Number.isSafeInteger(r)||r<=0)throw o(`eventId must be a positive integer: ${String(r)}`)}async function u(r,l,d){s(r);let c=t.get();if(!c)throw new g("NOT_SIGNED_IN",0,{locale:n});try{return await e.request(`/events/${r}/${l}`,{...d,token:c.token})}catch(i){throw i instanceof g&&i.code==="NOT_SIGNED_IN"&&t.clear(c.token),i}}function f(r,l){let d=b(r)?r.status:void 0;if(typeof d!="string"||!l.has(d))throw a(typeof d=="string"?d:void 0);return d}function p(r){if(!b(r)||!Number.isSafeInteger(r.id)||typeof r.type!="string"||typeof r.label!="string"||!(r.options===null||r.options===void 0||Array.isArray(r.options)&&r.options.every(l=>typeof l=="string")))throw a("Unexpected form question.");return{id:r.id,type:r.type,label:r.label,required:r.required===!0,options:Array.isArray(r.options)?[...r.options]:null}}function m(r){if(!Array.isArray(r))throw o("answers must be an array.");let l=new Set;return r.map((d,c)=>{if(!b(d)||!Number.isSafeInteger(d.questionId)||d.questionId<=0)throw o(`answers[${c}].questionId must be a positive integer.`);if(typeof d.answer!="string")throw o(`answers[${c}].answer must be a string.`);if(d.answer.length>X)throw o(`answers[${c}].answer is longer than ${X} characters.`);if(l.has(d.questionId))throw o(`question ${d.questionId} is answered twice.`);return l.add(d.questionId),{questionId:d.questionId,answerText:d.answer}})}return{async join(r){let l=await u(r,"join",{method:"POST"});return{status:f(l,Ie)}},async status(r){let l=await u(r,"status",{method:"GET"});return{status:f(l,ke)}},async leave(r){await u(r,"attendance",{method:"DELETE"})},async ticket(r){let l=await u(r,"ticket",{method:"GET",noStore:!0}),d=b(l)?l.qrPayload:void 0;if(typeof d!="string"||d==="")throw a("Unexpected ticket response.");return{qrPayload:d}},async form(r){let l=await u(r,"form",{method:"GET"});if(!b(l)||!Array.isArray(l.questions)||typeof l.appRequired!="boolean")throw a("Unexpected form response.");return{questions:l.questions.map(p),appRequired:l.appRequired}},async apply(r,l){s(r);let d=m(l),c=await u(r,"apply",{method:"POST",body:{answers:d}});return{status:f(c,Le)}}}}var Z="https://api.unihub.tr/api/v1/community";function Re(e,t){let n;try{n=new URL(e)}catch{throw new g("INVALID_ARGUMENT",0,{locale:t,message:`unihub-community-sdk: baseUrl is not a URL: ${e}`})}let o=n.hostname==="localhost"||n.hostname==="127.0.0.1";if(n.protocol!=="https:"&&!(n.protocol==="http:"&&o))throw new g("INVALID_ARGUMENT",0,{locale:t,message:`unihub-community-sdk: baseUrl must use https (http is allowed only for localhost): ${e}`});return e.replace(/\/+$/,"")}function _e(e){let t=e?.locale??"tr",n=e?.key;if(!n)throw new g("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'key' is required."});if(typeof n!="string"||!n.startsWith("uhpk_"))throw new g("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'key' must be a publishable community key (uhpk_\u2026). Never put a master key or any other secret in a web page."});let o=e.session??"memory";if(o!=="memory"&&o!=="sessionStorage"&&o!=="localStorage")throw new g("INVALID_ARGUMENT",0,{locale:t,message:"unihub-community-sdk: 'session' must be 'memory', 'sessionStorage' or 'localStorage'."});let a=C({baseUrl:Re(e.baseUrl??Z,t),key:{header:"X-Community-Key",value:n},locale:t,fetch:e.fetch}),s=j(a,n,t,o);return{events:B(a,s.session,t),auth:s.api,attendance:Q(a,s.session,t)}}return ie(Te);})();
|
|
2
2
|
/*!
|
|
3
3
|
* UniHub Community Framework SDK
|
|
4
4
|
* Copyright (c) UniHub
|